File: /var/www/html/wptoho/wp-content/themes/themify-ultra/themify/js/admin/modules/lottie-library.js
let TF_LottieLibrary;((t,i,e,s)=>{"use strict";let o,n,a,l,r=new WeakMap;try{l=window.top.document}catch(t){l=window.document}const f=()=>l.createDocumentFragment();TF_LottieLibrary={run(t,i,e){return this.input=t,this.bg=s,this.nonce=e,this.labels=i,this.show(t.value)},async render(){if(!this.el){const s=t.click,a=l.createElement("button"),f=l.createElement("input"),h=l.createElement("div"),c=l.createElement("div"),_=l.createElement("div"),d=l.createElement("div"),w=l.createElement("a"),u=l.createElement("ul"),b=l.createElement("span"),p=l.createElement("div"),v=l.createElement("div"),m=[this.getJson()];this.el=l.createElement("div"),this.el.className="lightbox tf_hide",d.className="cat_wrap flex",w.href="javascript:;",w.className="menu_icon flex tf_rel",u.className="menu tf_box tf_hidden tf_opacity tf_scrollbar",b.className="selected_cat",b.textContent=this.labels.all,f.type="search",f.className="search tf_box",f.required=!0,f.setAttribute("inputmode","search"),a.className="tf_close",_.className="menu_wrap flex tf_rel",p.className="container tf_scrollbar",p.style.display="none",v.className="pagination flex",(t=>{o||(o=new IntersectionObserver(((t,i)=>{for(let i=t.length-1;i>-1;--i){let e=t[i].target,s=r.get(e);if(1!=s){let o=s?.player||null;if(t[i].isIntersecting)if(e.style.contentVisibility="",o)t[i].intersectionRatio>=.1?o.isPaused&&(o.show(),o.play()):o.isPaused||(o.pause(),o.hide());else{let t=new TF_Lottie(e.tfClass("lottie")[0],{type:"svg",actions:[{state:"none",path:e.dataset.id}]});r.set(e,1),t.run().then((()=>{if(!t.player||!TF_LottieLibrary.el)throw"";e.tfClass("tf_loader")[0].remove(),r.set(e,t),t.player.loop=!0,t.player.play()})).catch((()=>{r.delete(e,t),t.destroy(!0),e.remove()}))}else e.style.contentVisibility="hidden",o&&!o.isPaused&&(o.pause(),o.hide())}}}),{threshold:[0,.05,.1,.3,.5,.7,.8,.9,1],rootMargin:"150px 0px 150px 0px",root:t}))})(p);let g=l.tfId("tf_lottie_root");if(g)g.style.display="none",g.shadowRoot.appendChild(this.el),await e.all(m);else{g=l.createElement("div");const i=l.createElement("div");g.id="tf_lottie_root",g.style.display="none",i.className="overlay tf_abs_t tf_opacity tf_w tf_h tf_opacity tf_hide",i.tfOn(s,(t=>{t.stopPropagation(),this.close()}),{passive:!0}),g.attachShadow({mode:"open"}).append(this.el,i),l.body.appendChild(g),m.push(t.loadCss(t.url+"css/base.min","tf_base-css",!1,this.el),t.loadCss(t.url+"css/admin/lottie-library","tf_lottie-library",!1,this.el),t.loadJs("https://cdnjs.cloudflare.com/ajax/libs/lottie-web/5.12.2/lottie.min.js",!!window.lottie,!1),t.loadJs("lottie",!!window.TF_Lottie),t.fonts(["ti-download","ti-file"])),await e.all(m),this.el.before(l.tfId("tf_svg").cloneNode(!0)),t.loadJs(t.url+"js/admin/notification",!!window.TF_Notification)}const y=Object.keys(n);y.unshift("All");for(let t=0;t<y.length;++t){let i=l.createElement("li");0===t&&(i.dataset.all=1,i.classList.add("current")),i.textContent=y[t],u.appendChild(i)}h.className="bg_global bg_wrap tf_box",c.className="bg flex";for(let t=0,i=this.getBg();t<i.length;++t){let e=l.createElement("button");e.className=i[t],e.dataset.bg=t,e.type="button","white"===i[t]&&(e.className+=" selected_bg"),c.appendChild(e)}let x,T;w.appendChild(b),d.append(w,u),h.append(l.createTextNode(this.labels.bg),c,f),_.append(d,h),this.el.append(_,p,v,a),this.renderItems(),g.style.display="",a.tfOn(s,(t=>{t.stopPropagation(),this.close()}),{passive:!0}),v.tfOn(s,(t=>{t.stopPropagation();let i=t.target.textContent;if(i&&"."!==i[0]){const t=this.el.tfClass("current")[0];this.renderItems(t.dataset.all?"":t.textContent,f.value,parseInt(i))}}),{passive:!0}),c.tfOn(s,(t=>{t.stopPropagation();const i=t.target;if(i&&i!==t.currentTarget){const t=i.dataset.bg,e=this.getBg(),s=this.getBg(t);for(let i=this.el.tfClass("bg"),e=i.length-1;e>-1;--e)for(let s=i[e].children,o=s.length-1;o>-1;--o)s[o].classList.toggle("selected_bg",t===s[o].dataset.bg);for(let t=this.el.tfClass("lottie"),i=t.length-1;i>-1;--i){let o=t[i].classList;for(let t=e.length;t>-1;--t)o.remove(e[t]);o.add(s)}this.bg=parseInt(t)}}),{passive:!0}),p.tfOn(s,(async i=>{i.stopPropagation();const e=i.target,s=e.closest(".lottie"),o=e.closest(".bg");if(e.closest(".dbtn")){const t=e.closest(".item"),i=t.dataset.id,s=await TF_Lottie.getJson(i),o=t.tfClass("title")[0].innerHTML.replaceAll(" ","-"),n=l.createElement("a"),a=new Blob([JSON.stringify(s)],{type:"application/json"});n.href=URL.createObjectURL(a),n.download=o+"-"+i,n.click()}else if(s)try{const i=this.input,e=s.closest(".item");i.value=await this.confirm(e.dataset.id,e.tfClass("title")[0].innerHTML),await this.close(),t.triggerEvent(i,"change")}catch(i){}else if(o&&o!==e){const t=o.closest(".item").tfClass("lottie")[0];for(let i=o.children,s=i.length-1;s>-1;--s)i[s].classList.toggle("selected_bg",e===i[s]),t.classList.remove(this.getBg(i[s].dataset.bg));t.classList.add(this.getBg(e.dataset.bg))}}),{passive:!0}),u.tfOn(s,(t=>{t.stopPropagation();const i=t.target,e=t.currentTarget;if(i.parentNode===e){const t=e.tfClass("current")[0],s=i.textContent;(t!==i||f.value)&&(f.value="",t.classList.remove("current"),i.classList.add("current"),this.el.tfClass("selected_cat")[0].textContent=s,this.renderItems(i.dataset.all?"":s))}}),{passive:!0}),f.tfOn("input",(t=>{t.stopPropagation(),cancelAnimationFrame(x),clearTimeout(T),T=i((()=>{x=requestAnimationFrame((()=>{x=null;const t=this.el.tfClass("current")[0];this.renderItems(t.dataset.all?"":t.textContent,f.value.trim())}))}),100)}),{passive:!0}),p.style.display=""}},getBg(t){const i=["white","grey","black","red","green","blue"];return t!==s?i[t]:i},renderItems(i,e,a=1){const h=navigator.hardwareConcurrency,c=t.isTouch||!h||h<16?32:h>=16?48:40,_=(a-1)*c,d=this.el.tfClass("container")[0],w=this.el.tfClass("pagination")[0],u=f(),b=new Set,p=i?[i]:Object.keys(n);let v=[];e&&(e=e.toLowerCase()),d.style.scrollBehavior="auto",d.scrollTop=0,d.style.scrollBehavior="";for(let t=0;t<p.length;++t)for(let i in n[p[t]])if(!b.has(i)){b.add(i);let o,a=n[p[t]][i],l=a;if("string"!=typeof a&&(l=a.n,o=a.bg),!e||l.toLowerCase().includes(e)){let t={id:i,n:l};o!==s&&(t.bg=parseInt(o)),v.push(t)}}b.clear();const m=v.length,g=this.getBg();v=v.slice(_,_+c);for(let t=0;t<v.length;++t){let i=l.createElement("div"),e=l.createElement("div"),n=l.createElement("div"),a=l.createElement("div"),r=l.createElement("div"),f=l.createElement("div"),h=l.createElement("div"),c=l.createElement("button"),_=v[t],d=this.bg??_.bg;e.className="tf_loader",n.className="lottie flex tf_w tf_h ",n.className+=d!==s?this.getBg(d):"white",a.className="bg_wrap tf_box tf_w",r.className="bg flex";for(let t=0;t<g.length;++t){let i=l.createElement("button");i.className=g[t],i.dataset.bg=t,i.type="button",(d===t||d===s&&"white"===g[t])&&(i.className+=" selected_bg"),r.appendChild(i)}f.textContent=_.n,f.className="title tf_overflow tf_box tf_w tf_h tf_mw",_.n.length>26&&(f.title=_.n),h.className="download flex tf_abs_t",c.className="dbtn",c.title="Download",c.type="button",c.appendChild(this.getIcon("ti-download")),i.dataset.id=_.id,i.className="item tf_box",n.appendChild(e),a.append(l.createTextNode(this.labels.bg),r),h.appendChild(c),i.append(n,a,f,h),u.appendChild(i),o.observe(i)}v=null;for(let t=d.children,i=t.length-1;i>-1;--i){let e=r.get(t[i]);e&&(r.delete(e),1!=e&&e.destroy(!0)),o.unobserve(t[i]),t[i].remove()}d.appendChild(u),w.replaceChildren(this.getPagination(m,a,c))},getPagination(t,i,e){const s=f();if(t>e){const o=Math.ceil(t/e),n=t=>{const e=l.createElement("span");return e.textContent=t,t===i&&(e.className="selected_page"),e},a=t=>{let i=" ... ";return 0===t?i="":1===t?i=" ":t<=10?i=" . ":t<=100&&(i=" .. "),l.createTextNode(i)},r=3;let h=1,c=i,_=1,d=i,w=r+1,u=r+1,b=f(),p=f(),v=1;while(1)if(w>=u?(b.append(a(_-h),n(_,i)),h=_,_+=v,--w):(p.prepend(n(d,i),a(c-d)),c=d,d-=v,--u),0===u&&(v*=10,_+=v-1,_-=_%v,d-=d%v,w=u=r),_>d){if(s.append(b,a(c-h),p),c>i||i>=o)break;h=i,c=d=o,_=i+1,w=r,u=r+1,v=1}}return s},destroy(){const e=this.el.tfClass("item");for(let t=e.length-1;t>-1;--t){let i=r.get(e[t]);i&&(1!=i&&i.destroy(!0),r.delete(i))}o.disconnect(),this.el.remove(),r=new WeakMap,t.isTouch?n=null:a=i((()=>{n=a=null}),6e4),o=this.el=this.input=this.bg=this.labels=this.nonce=null},show(t){return new e((async e=>{this.el||await this.render(t),a&&(clearTimeout(a),a=null);const s=this.el.getRootNode().querySelector(".overlay");s.classList.remove("tf_hide"),this.el.classList.remove("tf_hide"),requestAnimationFrame((()=>{this.el.tfOn("transitionend",e,{passive:!0,once:!0}),s.classList.remove("tf_opacity"),i((()=>{this.el.classList.add("show")}),10)}))}))},confirm(i,s){return new e(((e,o)=>{const n=l.createElement("div"),a=l.createElement("div"),r=l.createElement("div"),f=l.createElement("div"),h=l.createElement("button"),c=l.createElement("button"),_=l.createElement("button"),d=t.click,w=t=>{n.remove(),f.remove(),t?e(t):o()};a.className="msg",a.textContent=this.labels.msg,c.type=h.type=_.type="button",c.textContent=this.labels.upload_btn,_.textContent=this.labels.external_btn,h.className="tf_close",r.className="confirm_buttons flex",n.tfOn(d,(async t=>{t.stopPropagation();let e=t.target,o="";if(!h.contains(e))if(e===c)o=await this.upload(i,s);else{if(e!==_)return;o=i}w(o)}),{passive:!0}).className="confirm flex tf_abs_c tf_textc tf_box",f.tfOn(d,(t=>{t.stopPropagation(),w("")}),{passive:!0}).className="overlay confirm_overlay tf_abs_t tf_w tf_h",r.append(c,_),n.append(a,r,h),this.el.after(n,f)}))},close(){return new e((t=>{this.el.getRootNode().querySelector(".overlay").tfOn("transitionend",(function(){this.classList.add("tf_hide"),this.classList.remove("tf_opacity")}),{passive:!0,once:!0}).classList.add("tf_opacity"),this.el.tfOn("transitionend",(i=>{i.currentTarget.classList.add("tf_hide"),this.destroy(),t()}),{passive:!0,once:!0}).classList.remove("show")}))},getIcon(t,i){t="tf-"+t.trim().replace(" ","-");const e="http://www.w3.org/2000/svg",s=l.createElementNS(e,"use"),o=l.createElementNS(e,"svg");let n="tf_fa "+t;return i&&(n+=" "+i),o.setAttribute("class",n),s.setAttributeNS(null,"href","#"+t),o.appendChild(s),o},async upload(i,e){await TF_Notification.show("info",this.labels.upload_msg.replaceAll("%title%",e));const s=await TF_Lottie.getJson(i),o={action:"themify_upload_json",file:i,title:e||"",nonce:this.nonce,data:JSON.stringify(s)};let n;try{if(n=await t.fetch(o),!n.success)throw""}catch(i){try{if(o.data=new Blob([o.data],{type:"text/plain"}),n=await t.fetch(o),!n.success)throw n.data}catch(t){throw await TF_Notification.showHide("error",this.labels.upload_fail.replaceAll("%msg%",t)),t}}return await TF_Notification.showHide("done","",1e3),n.data},async getJson(){n||(n=await t.fetch("","json",{credentials:"omit",method:"GET",mode:"cors"},"https://themify.org/public-api/lottie/index.json"))}}})(Themify,setTimeout,Promise,void 0);