@innovastudio/contentbox-runtime 1.0.27 → 1.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12891,7 +12891,7 @@ class Hr {
12891
12891
  let a = r.nextElementSibling;
12892
12892
  return a ? a.classList.contains("is-section") ? a : t(a) : !1;
12893
12893
  };
12894
- document.querySelectorAll(".is-arrow-down a").forEach(function(r) {
12894
+ document.querySelectorAll(".is-arrow-down a").forEach((r) => {
12895
12895
  r.addEventListener("click", (a) => {
12896
12896
  let l = a.target.closest(".is-section");
12897
12897
  if (l) {
@@ -13023,7 +13023,7 @@ class Hr {
13023
13023
  }
13024
13024
  inViewSetup() {
13025
13025
  document.querySelectorAll(".is-overlay-content").forEach((i) => {
13026
- i.querySelector("video.is-video-bg") && i.setAttribute("data-scroll", "");
13026
+ (i.querySelector("video.is-video-bg") || i.querySelector('[data-cb-type="video-background"]')) && i.setAttribute("data-scroll", "");
13027
13027
  }), document.querySelectorAll(".is-container video").forEach((i) => {
13028
13028
  i.parentNode.setAttribute("data-scroll", "");
13029
13029
  });
@@ -13055,7 +13055,7 @@ class Hr {
13055
13055
  },
13056
13056
  out: (i) => {
13057
13057
  i.element.querySelectorAll("video").forEach((r) => {
13058
- !r.paused && !r.closest("[data-html]") && r.pause();
13058
+ r.paused || r.pause();
13059
13059
  });
13060
13060
  }
13061
13061
  }
@@ -533,4 +533,4 @@ ${R.data}
533
533
  `}}this.tokenInput+=_,this.tokenOutput+=f}return!0}catch(o){return o.name==="AbortError"?this.settings.consoleLog&&console.log("Request aborted by user."):console.error("Error:",o),!1}}async assistant(e,t,s,i){this.controller=new AbortController,this.signal=this.controller.signal;let n=.6,r=.9,a=1;i||(i=[]);let l=this.settings.model;i.length>0&&(l=this.settings.model2);const c={assistantId:this.settings.assistantId,question:e,context:t,system:s,functs:i,temperature:n,topP:r,num:a,model:l,customData:this.settings.customData};try{let u={"Content-Type":"application/json",...this.settings.headers},h=await(await fetch(this.settings.assistantUrl,{signal:this.signal,method:"POST",headers:u,body:JSON.stringify(c)})).json();return h.error?(console.log(`Error:
534
534
  `+h.error),!1):(h.usage&&(this.tokenInput+=h.usage.prompt_tokens,this.tokenOutput+=h.usage.completion_tokens),h.answer.content[0].text.value)}catch(u){return u.name==="AbortError"?this.settings.consoleLog&&console.log("Request aborted by user."):console.error("Error:",u),!1}}async assistantStream(e,t,s,i,n){this.controller=new AbortController,this.signal=this.controller.signal;let r=.6,a=.9,l=1;i||(i=[]);const c={assistantId:this.settings.assistantId,question:e,context:t,system:s,functs:i,temperature:r,topP:a,num:l,model:this.settings.model,customData:this.settings.customData};try{let u={"Content-Type":"application/json",...this.settings.headers};const o=await fetch(this.settings.assistantStreamUrl,{signal:this.signal,method:"POST",headers:u,body:JSON.stringify(c)});if(!o.ok)return console.error("Error:",o.statusText),!1;const h=o.body.getReader(),p=new TextDecoder;let g="",w=!1;for(;!w;){const{done:S,value:b}=await h.read();if(w=S,w)break;const x=p.decode(b,{stream:!0});g+=x;const m=g.split(`
535
535
  `);g="";for(const v of m)if(v.trim()!=="")if(v.startsWith("data:")){const _=v.slice(5).trim();_==="[DONE]"&&this.settings.consoleLog&&console.log("Stream completed.");try{const f=JSON.parse(_);if(f.choices&&f.choices[0].delta&&f.choices[0].delta.content){const y=f.choices[0].delta.content;n&&n(y)}}catch{g+=v+`
536
- `}}else{const _=JSON.parse(v);this.tokenInput+=_.prompt_tokens,this.tokenOutput+=_.completion_tokens;break}}return!0}catch(u){return u.name==="AbortError"?this.settings.consoleLog&&console.log("Request aborted by user."):console.error("Error:",u),!1}}hexToRgb(e){const t=e.replace("#",""),s=parseInt(t,16),i=s>>16&255,n=s>>8&255,r=s&255;return{red:i,green:n,blue:r}}getId(e="id"){return`${e}-${Math.random().toString(36).substr(2,9)}`}appendHtml(e,t){e&&t&&e.insertAdjacentHTML("beforeend",t)}cleanup(){if(this.element){let e=this.element.querySelectorAll('input[type="text"], input[type="number"], input[type="email"], input[type="tel"], input[type="url"], textarea');e.forEach(t=>{t.removeEventListener("input",this.inputListener)}),e=this.element.querySelectorAll('input[type="date"], input[type="radio"], input[type="checkbox"]'),e.forEach(t=>{t.removeEventListener("change",this.changeListener)}),this.debounceTimeout&&(clearTimeout(this.debounceTimeout),this.debounceTimeout=null)}}destroy(){try{if(this._scrollListener){let e;this.settings.isBuilder?e=document.querySelector(this.settings.previewSelector):e=this.element;const t=e.querySelector(".submit-container"),s=this.getScrollableParent(t);s?s.removeEventListener("scroll",this._scrollListener):window.removeEventListener("scroll",this._scrollListener),window.removeEventListener("resize",this._scrollListener)}}catch{}this.element&&(this.cleanup(),this.element.innerHTML="",this.element=null);for(const e in this.listeners)this.listeners[e].clear();this.listeners={}}out(e){let t=this.settings.lang[e];return t||e}}class qr{addClass(e,t){e&&(this.hasClass(e,t)||(e.classList.length===0?e.className=t:e.className=e.className+" "+t,e.className=e.className.replace(/ +/g," ")))}removeClass(e,t){if(e&&e.classList.length>0){let s,i,n,r,a=t.split(" ");for(s=0,n=a.length;s<n;++s){if(!a[s])continue;let l=a[s],c="",u=e.className.split(" ");for(i=0,r=u.length;i<r;++i)u[i]&&u[i]!==l&&(c+=u[i]+" ");e.className=c.trim()}e.className===""&&e.removeAttribute("class")}}hasClass(e,t){if(!e)return!1;try{let s=e.getAttribute("class");return new RegExp("\\b"+t+"\\b").test(s)}catch{}}}const F=new qr;class Ir{constructor(e={}){const t={};this.settings=Object.assign(this,t,e)}init(){const e=h=>{const p=h.parentNode,g=h.nextElementSibling;if(F.hasClass(g,"is-menu-links")){let S=g.querySelectorAll("li");S.forEach(b=>{if(b!==p){const x=b.querySelector("ul");F.removeClass(x,"active")}}),S=document.querySelectorAll(".is-menu > ul > li ul"),S.forEach(b=>{const x=b.querySelector("ul");F.removeClass(x,"active")})}F.hasClass(g,"active")&&!F.hasClass(g,"is-menu-links")&&g.querySelectorAll("li").forEach(b=>{if(b!==p){const x=b.querySelector("ul");F.removeClass(x,"active")}});const w=p.querySelector("ul");w&&F.addClass(w,"active")},t=h=>{if(h.nextElementSibling){const p=h.nextElementSibling;if(p)if(F.hasClass(p,"active"))F.removeClass(p,"active"),h.focus();else{const w=h.parentNode.parentNode;F.removeClass(w,"active"),w.previousElementSibling.focus()}else{const w=h.parentNode.parentNode;F.removeClass(w,"active"),w.previousElementSibling.focus()}}else{const g=h.parentNode.parentNode;F.removeClass(g,"active"),g.previousElementSibling.focus()}},s=h=>{const p=h.target;if(h.keyCode===27)t(h.target);else if(h.keyCode===13)h.target.nextElementSibling&&(h.target.getAttribute("href")===""||h.target.getAttribute("href")==="javascript:")&&(e(h.target),h.preventDefault());else if(h.keyCode===32)h.target.nextElementSibling&&(e(h.target),h.preventDefault());else if(h.keyCode===40)if(p.nextElementSibling)if(p.nextElementSibling.classList.contains("active"))p.nextElementSibling.querySelector("a").focus(),h.preventDefault();else if(p.parentNode.nextElementSibling)p.parentNode.nextElementSibling.querySelector("a").focus(),h.preventDefault();else{const w=p.parentNode.parentNode;w.classList.contains("active")&&(w.classList.remove("active"),w.previousElementSibling.focus(),h.preventDefault())}else if(p.parentNode.nextElementSibling)p.parentNode.nextElementSibling.querySelector("a").focus(),h.preventDefault();else{const w=p.parentNode.parentNode;w.classList.contains("active")&&(w.classList.remove("active"),w.previousElementSibling.focus(),h.preventDefault())}else if(h.keyCode===38)if(p.nextElementSibling)if(p.nextElementSibling.classList.contains("active"))p.nextElementSibling.classList.remove("active");else{const g=p.parentNode.previousElementSibling;g&&g.querySelector("a").focus()}else if(p.parentNode.previousElementSibling)p.parentNode.previousElementSibling.querySelector("a").focus();else{const w=p.parentNode.parentNode;w.classList.contains("active")&&w.classList.remove("active"),w.previousElementSibling.focus()}else if(h.which===9&&!h.shiftKey)if(p.nextElementSibling)if(p.nextElementSibling.classList.contains("active"))p.nextElementSibling.querySelector("a").focus(),h.preventDefault();else if(p.parentNode.nextElementSibling)p.parentNode.nextElementSibling.querySelector("a").focus(),h.preventDefault();else{const w=p.parentNode.parentNode;w.classList.contains("active")&&(w.classList.remove("active"),w.previousElementSibling.focus(),h.preventDefault())}else if(p.parentNode.nextElementSibling)p.parentNode.nextElementSibling.querySelector("a").focus(),h.preventDefault();else{const w=p.parentNode.parentNode;w.classList.contains("active")&&(w.classList.remove("active"),w.previousElementSibling.focus(),h.preventDefault())}else if(h.which===9&&h.shiftKey){if(p.nextElementSibling)p.nextElementSibling.classList.contains("active")&&p.nextElementSibling.classList.remove("active");else if(!p.parentNode.previousElementSibling){const w=p.parentNode.parentNode;w.classList.contains("active")&&w.classList.remove("active")}}};document.querySelectorAll(".is-menu li a").forEach(h=>{h.addEventListener("keydown",s)}),document.querySelectorAll(".is-menu li").forEach(h=>{const p=h.querySelector("span");p&&p.addEventListener("click",g=>{if(window.innerWidth>=1024)return;const b=g.target.closest("li").querySelector("ul");b&&(F.hasClass(b,"active")?(F.removeClass(b,"active"),b.style.display=""):F.addClass(b,"active")),g.preventDefault(),g.stopImmediatePropagation()}),h.addEventListener("click",g=>{const w=h.querySelector("ul"),S=window.innerWidth;let b=g.target.tagName.toLowerCase();if(S>1024){if((b==="a"||b==="i")&&!g.target.getAttribute("href")){g.preventDefault(),g.stopImmediatePropagation();return}}else{let x=!0;if((b==="a"||b==="i")&&(g.target.getAttribute("href")||(g.preventDefault(),x=!1)),x){const m=document.querySelector(".is-menu");if(m.style.right==="0px"){F.removeClass(r,"active"),m.style.right="-1000px";const v=document.querySelector(".is-menu-overlay");F.removeClass(v,"active"),document.querySelector(".is-topbar-menu").style.paddingRight="0px",document.body.style.overflowY="auto"}}}w&&(F.hasClass(w,"active")?(F.removeClass(w,"active"),w.style.display=""):(F.addClass(w,"active"),setTimeout(()=>{},0)))}),h.addEventListener("mouseleave",g=>{window.innerWidth<=1024||(this.timer=setTimeout(()=>{const S=h.querySelector("ul");S&&F.removeClass(S,"active")},200),g.preventDefault(),g.stopImmediatePropagation())}),h.addEventListener("mouseenter",g=>{const w=window.innerWidth;if(w<=1024||this.staticClose)return;const S=document.querySelector(".is-menu-search-input");if(F.hasClass(S,"active"))return;clearTimeout(this.timer);const b=h.closest("ul");if(!h.querySelector("ul"))return b.querySelectorAll("li").forEach(v=>{const _=v.querySelector("ul");F.removeClass(_,"active")}),!0;if(F.hasClass(b,"is-menu-links")){let m=b.querySelectorAll("li");m.forEach(v=>{if(v!==h){const _=v.querySelector("ul");F.removeClass(_,"active")}}),m=document.querySelectorAll(".is-menu > ul > li ul"),m.forEach(v=>{const _=v.querySelector("ul");F.removeClass(_,"active")})}F.hasClass(b,"active")&&!F.hasClass(b,"is-menu-links")&&b.querySelectorAll("li").forEach(v=>{if(v!==h){const _=v.querySelector("ul");F.removeClass(_,"active")}});const x=h.querySelector("ul");if(x&&F.addClass(x,"active"),x.style.right="",x.classList.contains("active")){const m=x.getBoundingClientRect();m.left+m.width>w&&(x.style.right=0)}g.preventDefault(),g.stopImmediatePropagation()})});const r=document.querySelector("#is-menu-toggle");r.addEventListener("click",h=>{const p=document.querySelector(".is-menu");if(p.style.right==="0px"){F.removeClass(r,"active"),p.style.right="-1000px";const g=document.querySelector(".is-menu-overlay");F.removeClass(g,"active"),document.querySelector(".is-topbar-menu").style.paddingRight="0px",document.body.style.overflowY="auto"}else{F.addClass(r,"active"),document.querySelector(".is-menu-links .is-menu-search")?(document.querySelector(".is-menu-search-input").style.display="",document.querySelector(".is-menu-links").style.marginTop=""):(document.querySelector(".is-menu-search-input").style.display="none",document.querySelector(".is-menu-links").style.marginTop="70px"),p.style.right="0px";const w=document.querySelector(".is-menu-overlay");F.addClass(w,"active"),document.querySelector(".is-topbar-menu").style.paddingRight=this.getScrollbarWidth()+"px",document.body.style.overflowY="hidden"}h.stopImmediatePropagation(),h.preventDefault()}),document.querySelector(".is-menu-overlay").addEventListener("click",h=>{document.querySelector("#is-menu-toggle").click(),h.stopImmediatePropagation(),h.preventDefault()}),window.addEventListener("resize",()=>{document.body.style.overflowY="auto",document.querySelector(".is-topbar-menu").style.paddingRight="0px";const h=document.querySelector("#is-menu-toggle");F.removeClass(h,"active"),document.querySelectorAll(".is-menu li ul").forEach(S=>{F.removeClass(S,"active")});const g=document.querySelector(".is-menu");if(g.style.transition="none",window.innerWidth>1024){g.style.right="0px",document.querySelectorAll(".is-menu li ul").forEach(x=>{x.style.display=""});const b=document.querySelector(".is-menu-overlay");F.removeClass(b,"active"),document.querySelector(".is-menu-search-input").style.display="",document.querySelector(".is-menu-links").style.marginTop=""}else g.style.right="-1000px";setTimeout(()=>{g.style.transition=""},30)}),window.addEventListener("scroll",()=>{var h=100,p=this.getCurrentScroll();p>=h?F.addClass(document.querySelector(".is-topbar"),"shrink"):F.removeClass(document.querySelector(".is-topbar"),"shrink"),window.innerWidth>=1024&&document.querySelector(".is-topbar.static")&&(p>30?this.staticClose||(document.querySelectorAll(".is-menu li ul").forEach(S=>{F.removeClass(S,"active")}),this.staticClose=!0):this.staticClose=!1)});const l=h=>{const p=document.querySelector(".is-menu-search-input");F.addClass(p,"active"),p.querySelector("input").focus(),document.querySelectorAll(".is-menu li ul").forEach(S=>{F.removeClass(S,"active")}),h.preventDefault(),h.stopImmediatePropagation()},c=document.querySelector(".is-menu-search");c&&(c.addEventListener("click",h=>{l(h)}),c.addEventListener("keydown",h=>{(h.keyCode===13||h.keyCode===32)&&l(h)})),document.addEventListener("click",h=>{const p=h.target;if(!F.hasClass(p,"is-menu-search")&&p.getAttribute("id")!=="is_btnSearch"&&p.getAttribute("id")!=="is_txtSearch"){const g=document.querySelector(".is-menu-search-input");F.removeClass(g,"active")}});const u=document.querySelector("#is_txtSearch");u.addEventListener("keydown",h=>{if(h.which==13&&this.settings.onSearch(u.value),h.which==27){const p=document.querySelector(".is-menu-search-input");F.removeClass(p,"active"),document.querySelector(".is-menu-search").focus()}}),document.querySelector("#is_btnSearch").addEventListener("click",()=>{this.settings.onSearch(u.value)})}getScrollbarWidth(){return window.innerWidth-document.documentElement.clientWidth}getCurrentScroll(){return window.pageYOffset||document.documentElement.scrollTop}}class jr{constructor(e={}){this.config={plugins:{},autoLoad:!0,pluginBaseUrl:"",allowExternalPlugins:!0,trustedDomains:[],onReInit:()=>{},...e},this.plugins=new Map,this.loadedStyles=new Set,this.components=new Map,this.externalPlugins=new Map}async autoLoadPlugins(){const t=this.detectComponentTypes().filter(s=>this.config.plugins[s]&&!this.plugins.has(s));return t.length>0&&await Promise.all(t.map(s=>this.loadPlugin(s))),t}detectComponentTypes(){const e=new Set;return document.querySelectorAll("[data-cb-type]").forEach(t=>{e.add(t.dataset.cbType)}),document.querySelectorAll('[class*="cb-"]').forEach(t=>{t.classList.forEach(s=>{if(s.startsWith("cb-")){const i=s.replace("cb-","");e.add(i)}})}),Array.from(e)}async loadPlugin(e){if(this.plugins.has(e))return this.plugins.get(e);const t=this.config.plugins[e];if(!t)return console.warn(`[PluginManager] Plugin "${e}" not found in registry`),null;try{t.css&&this.loadCSS(this.resolveUrl(t.css));const s=this.resolveUrl(t.url),i=await this.importModule(s),n=i.default||i;return this.plugins.set(e,n),typeof n.init=="function"&&await n.init(this),this.emit("plugin-loaded",{name:e,plugin:n}),n}catch(s){return console.error(`[PluginManager] Failed to load plugin "${e}":`,s),null}}async importModule(e){return import(e)}loadCSS(e){if(this.loadedStyles.has(e))return;const t=document.createElement("link");t.rel="stylesheet",t.href=e,t.onload=()=>{this.emit("css-loaded",{url:e})},t.onerror=()=>{console.error(`[PluginManager] Failed to load CSS: ${e}`)},document.head.appendChild(t),this.loadedStyles.add(e)}resolveUrl(e){return e.startsWith("http://")||e.startsWith("https://")||e.startsWith("//")?e:this.config.pluginBaseUrl+e}initializeComponents(){return document.querySelectorAll("[data-cb-type]").forEach((t,s)=>{const i=t.dataset.cbType,n=this.plugins.get(i);if(n&&typeof n.mount=="function")try{const r=this.parseOptions(t);let a=t.querySelector(".grid-sortable");a||t.classList.contains("grid-sortable")&&(a=t),a&&Array.from(a.children).forEach((u,o)=>{u.nodeType===1&&u.tagName!=="STYLE"&&u.tagName!=="SCRIPT"&&u.setAttribute("data-index",o)}),t.querySelectorAll(".edit").forEach((u,o)=>{const h=`content-${Date.now()}-${s}-${o}`;u.setAttribute("data-edit-id",h)}),t.hasAttribute("data-cb-original-content")||t.setAttribute("data-cb-original-content",t.innerHTML);const c=n.mount(t,r);this.components.set(t,c),this.setupInlineEditing(t,r),t.setAttribute("data-cb-loaded","true"),typeof t.mount=="function"&&t.mount()}catch(r){console.error(`[PluginManager] Failed to mount component "${i}":`,r)}}),this.components.size}parseOptions(e){const t={};return Array.from(e.attributes).forEach(s=>{if(s.name.startsWith("data-cb-")){const i=s.name.replace("data-cb-","").replace(/-([a-z])/g,(n,r)=>r.toUpperCase());t[i]=this.parseValue(s.value)}}),t}parseValue(e){if(e==="true")return!0;if(e==="false")return!1;if(!isNaN(e)&&e!=="")return Number(e);try{return JSON.parse(e)}catch{return e}}setupInlineEditing(e,t){if(!e.closest(".data-editor"))return;const s=e.querySelectorAll(".edit[data-edit-id]");if(s.length===0)return;e.querySelectorAll('.edit[contenteditable="true"]').forEach(r=>{r.removeAttribute("contenteditable"),r._cbObserver&&(r._cbObserver.disconnect(),delete r._cbObserver),r._cbKeydownHandler&&(r.removeEventListener("keydown",r._cbKeydownHandler),delete r._cbKeydownHandler)});const n=(r,a)=>{const l=e.getAttribute("data-cb-original-content");if(!l)return;const c=document.createElement("template");c.innerHTML=l.trim();const o=c.content.querySelector(`[data-edit-id="${r}"]`);if(o){o.innerHTML=a;const h=c.innerHTML;e.setAttribute("data-cb-original-content",h)}};s.forEach(r=>{r.setAttribute("contenteditable","true");const a=u=>{var o=document.createRange();o.selectNodeContents(u);var h=window.getSelection();h.removeAllRanges(),h.addRange(o)},l=u=>{if((u.ctrlKey||u.metaKey)&&u.which===65){let o;try{window.getSelection?o=window.getSelection().getRangeAt(0).commonAncestorContainer.parentNode:document.selection&&(o=document.selection.createRange().parentElement()),a(o),u.preventDefault(),u.stopImmediatePropagation()}catch{}}};r.addEventListener("keydown",l),r._cbKeydownHandler=l;const c=new MutationObserver(()=>{const u=r.getAttribute("data-edit-id"),o=r.innerHTML;n(u,o)});c.observe(r,{childList:!0,characterData:!0,subtree:!0,attributes:!0}),r._cbObserver=c})}async use(e){return await this.loadPlugin(e)}getPlugin(e){return this.plugins.get(e)}getAllPlugins(){return Array.from(this.plugins.entries())}hasPlugin(e){return this.plugins.has(e)}getComponent(e){return this.components.get(e)}async reinitialize(e=document){if(this.reinitializeInProgress)return clearTimeout(this.pendingReinitialize),new Promise(t=>{this.pendingReinitialize=setTimeout(async()=>{this.pendingReinitialize=null;const s=await this.reinitialize(e);t(s)},100)});this.reinitializeInProgress=!0;try{const t=[];this.components.forEach((a,l)=>{(e===document||e.contains(l))&&t.push({element:l,instance:a})}),t.forEach(({element:a,instance:l})=>{const c=a.dataset.cbType,u=this.plugins.get(c);u&&typeof u.unmount=="function"&&u.unmount(a,l),this.components.delete(a)});const i=this.detectComponentTypesInContainer(e).filter(a=>this.config.plugins[a]&&!this.plugins.has(a));i.length>0&&await Promise.all(i.map(a=>this.loadPlugin(a)));const n=e.querySelectorAll("[data-cb-type]");let r=0;for(const a of n){const l=a.dataset.cbType,c=this.plugins.get(l);if(c&&typeof c.mount=="function")try{const u=this.parseOptions(a);let o=a.querySelector(".grid-sortable");if(o||a.classList.contains("grid-sortable")&&(o=a),o&&Array.from(o.children).forEach((g,w)=>{g.nodeType===1&&g.tagName!=="STYLE"&&g.tagName!=="SCRIPT"&&g.setAttribute("data-index",w)}),a.querySelectorAll(".edit").forEach((g,w)=>{const S=`content-${Date.now()}-${r}-${w}`;g.setAttribute("data-edit-id",S)}),!a.hasAttribute("data-cb-original-content"))a.setAttribute("data-cb-original-content",a.innerHTML);else{let g=document.createRange();a.innerHTML="",a.appendChild(g.createContextualFragment(a.getAttribute("data-cb-original-content")))}const p=await c.mount(a,u);this.components.set(a,p),this.setupInlineEditing(a,u),a.setAttribute("data-cb-loaded","true"),typeof a.mount=="function"&&a.mount(),r++}catch(u){console.error(`[PluginManager] Failed to mount component "${l}":`,u)}}return typeof this.config.onReInit=="function"&&this.config.onReInit(),this.emit("reinitialized",{container:e,count:r}),r}finally{this.reinitializeInProgress=!1}}detectComponentTypesInContainer(e){const t=new Set;return e.querySelectorAll("[data-cb-type]").forEach(i=>{t.add(i.dataset.cbType)}),Array.from(t)}async loadExternalPlugin(e,t){if(!e||typeof e!="string")throw new Error("Plugin ID is required and must be a string");if(!t.url)throw new Error("Plugin URL is required");if(this.plugins.has(e))return console.warn(`[PluginManager] Plugin "${e}" is already loaded`),this.plugins.get(e);const s=this.validatePluginSource(t.url);if(!s.allowed)throw new Error(`Security: ${s.reason}`);s.warning&&(console.warn(`[PluginManager] ${s.warning}`),this.emit("plugin-security-warning",{pluginId:e,url:t.url,warning:s.warning}));try{this.config.plugins[e]={url:t.url,css:t.css||null,source:"external",loadedAt:new Date().toISOString()},this.externalPlugins.set(e,this.config.plugins[e]);const i=await this.loadPlugin(e);return this.emit("external-plugin-loaded",{pluginId:e,url:t.url}),i}catch(i){throw delete this.config.plugins[e],this.externalPlugins.delete(e),console.error(`[PluginManager] Failed to load external plugin "${e}":`,i),i}}validatePluginSource(e){const t=e.includes("localhost")||e.includes("127.0.0.1");if(!e.startsWith("https://")&&!t)return{allowed:!1,reason:"Only HTTPS URLs are allowed (except localhost for development)"};if(!this.config.allowExternalPlugins)return{allowed:!1,reason:"External plugins are disabled. Enable allowExternalPlugins in configuration."};if(this.config.trustedDomains.length>0){const i=new URL(e).hostname;if(!this.config.trustedDomains.some(r=>{if(r.startsWith("*.")){const a=r.slice(2);return i===a||i.endsWith("."+a)}return i===r}))return{allowed:!0,warning:`Loading plugin from external domain: ${i}. Only add plugins from sources you trust.`}}else return{allowed:!0,warning:`Loading external plugin from: ${new URL(e).hostname}. This plugin will have full access to your page.`};return{allowed:!0}}async loadExternalPlugins(e){const t=[];for(const[s,i]of Object.entries(e))try{const n=await this.loadExternalPlugin(s,i);t.push({pluginId:s,success:!0,plugin:n})}catch(n){t.push({pluginId:s,success:!1,error:n.message}),console.error(`[PluginManager] Failed to load external plugin "${s}":`,n)}return t}unregisterPlugin(e){if(!this.externalPlugins.has(e))return console.warn(`[PluginManager] Plugin "${e}" is not an external plugin`),!1;const t=this.plugins.get(e),s=[];return this.components.forEach((i,n)=>{n.dataset.cbType===e&&s.push({element:n,instance:i})}),s.forEach(({element:i,instance:n})=>{t&&typeof t.unmount=="function"&&t.unmount(i,n),this.components.delete(i)}),t&&typeof t.destroy=="function"&&t.destroy(this),this.plugins.delete(e),this.externalPlugins.delete(e),delete this.config.plugins[e],this.emit("plugin-unregistered",{pluginId:e}),!0}getExternalPlugins(){return Array.from(this.externalPlugins.entries()).map(([e,t])=>({id:e,...t}))}isExternalPlugin(e){return this.externalPlugins.has(e)}destroy(){this.components.forEach((e,t)=>{const s=t.dataset.cbType,i=this.plugins.get(s);i&&typeof i.unmount=="function"&&i.unmount(t,e)}),this.components.forEach((e,t)=>{t.querySelectorAll('.edit[contenteditable="true"]').forEach(i=>{i.removeAttribute("contenteditable"),i._cbObserver&&(i._cbObserver.disconnect(),delete i._cbObserver),i._cbKeydownHandler&&(i.removeEventListener("keydown",i._cbKeydownHandler),delete i._cbKeydownHandler)})}),this.plugins.forEach((e,t)=>{typeof e.destroy=="function"&&e.destroy(this)}),this.components.clear(),this.plugins.clear()}emit(e,t){if(this.runtime&&typeof this.runtime.emit=="function")this.runtime.emit(e,t);else{const s=new CustomEvent(`contentbox:${e}`,{detail:t});document.dispatchEvent(s)}}setRuntime(e){this.runtime=e}}class Nr{constructor(e={}){const t={skin:"light",smoothScroll:!0,plugins:{},autoLoadPlugins:!0,pluginBaseUrl:"",allowExternalPlugins:!0,trustedDomains:[]};this.settings={...t,...e},this.initialized=!1,this.pluginManager=new jr({plugins:this.settings.plugins,autoLoad:this.settings.autoLoadPlugins,pluginBaseUrl:this.settings.pluginBaseUrl,allowExternalPlugins:this.settings.allowExternalPlugins,trustedDomains:this.settings.trustedDomains,onReInit:()=>{this.functionLightboxInit()}}),this.pluginManager.setRuntime(this),window.Glide=Wn,window.FormViewer=Rr,window.NavBar=Ir,window.pageReRender=()=>{this.pageReRender()}}async use(e){return await this.pluginManager.use(e)}getPlugin(e){return this.pluginManager.getPlugin(e)}getPlugins(){return this.pluginManager.getAllPlugins()}hasPlugin(e){return this.pluginManager.hasPlugin(e)}getComponent(e){return this.pluginManager.getComponent(e)}getComponents(){return this.pluginManager.components}async reinitialize(e){return await this.pluginManager.reinitialize(e)}async loadExternalPlugin(e,t){return await this.pluginManager.loadExternalPlugin(e,t)}async loadExternalPlugins(e){return await this.pluginManager.loadExternalPlugins(e)}unregisterPlugin(e){return this.pluginManager.unregisterPlugin(e)}emit(e,t){const s=new CustomEvent(`contentbox:${e}`,{detail:t});document.dispatchEvent(s)}on(e,t){document.addEventListener(`contentbox:${e}`,t)}off(e,t){document.removeEventListener(`contentbox:${e}`,t)}async init(){this.initialized||(this.initCore(),this.initPlugins(),this.initialized=!0,this.emit("init"))}async initPlugins(){this.settings.autoLoadPlugins&&await this.pluginManager.autoLoadPlugins(),this.pluginManager.initializeComponents()}initCore(){this.prepareContent(),this.updateOnResize(),this.blockInit(),this.initeSkrollrr(),this.contentBoxOnRenderUpdate(),this.functionLightboxInit(),this.inViewSetup(),setTimeout(()=>{ks.init({duration:1200})},300),this.settings.smoothScroll&&new Qs}prepareContent(){const e=document.querySelector(".is-wrapper");e.classList.add("box-v2");const t=function(r){let a=r.nextElementSibling;return a?a.classList.contains("is-section")?a:t(a):!1};document.querySelectorAll(".is-arrow-down a").forEach(function(r){r.addEventListener("click",a=>{let l=a.target.closest(".is-section");if(l){let c=t(l);c&&this.scrollIt(c,1e3,"easeInQuad")}a.preventDefault(),a.stopImmediatePropagation()})}),e&&(e.classList.contains("is-edit")||e.querySelectorAll("a").forEach(a=>{a.addEventListener("click",l=>{let c=a.getAttribute("href");if(c&&c.indexOf("#")===0)if(c.indexOf("#section")===0){let u=c.replace("#section","");if(!isNaN(parseInt(u))){let o=document.querySelectorAll(".is-section"),h,p=0;o.forEach(function(g){g.classList.contains("is-section-navbar")||(p===u-1&&(h=g),p++)}),h&&this.scrollIt(h,1e3,"easeInQuad"),l.preventDefault()}}else try{let u=document.querySelector(c);u&&(this.scrollIt(u,1e3,"easeInQuad"),l.preventDefault())}catch{}})})),document.querySelectorAll(".section-inview").forEach(function(r){r.classList.remove("section-inview")});let n=document.querySelectorAll(".is-animated,.is-scale-animated");n.forEach(function(r){r.classList.contains("once")?(r.removeAttribute("data-scroll",""),r.setAttribute("data-scroll-once","")):(r.removeAttribute("data-scroll-once",""),r.setAttribute("data-scroll",""))}),n=document.querySelectorAll(".is-container > div"),n.forEach(function(r){let a=r.querySelectorAll(".is-animated[data-scroll],.is-animated[data-scroll-once]"),l=0;a.length>1&&a.forEach(function(c){c.className.indexOf("delay-")===-1&&(l>0&&(c.style.transitionDelay=l+"s",c.style.animationDelay=l+"s"),l=l+.2)})}),this.skrollrSetup(),this.adjustBgPos()}updateOnResize(){function e(s){var i;return function(n){i&&clearTimeout(i),i=setTimeout(s,100,n)}}const t=document.querySelector(".is-wrapper");window.addEventListener("resize",e(s=>{document.body.classList.contains("data-editor")&&(t.querySelector(".pin-wrap")&&!window.noRender?this.pageReRender():window.skrollrr&&window.skrollrr.refresh(),window.noRender=!1,this.adjustBgPos())})),t.classList.contains("is-edit")&&(window.onbeforeunload=function(s){localStorage.setItem("_lastscrollpos",document.documentElement.scrollTop),window.scrollTo(0,0)},setTimeout(()=>{localStorage.getItem("_lastscrollpos")&&window.scrollTo(0,localStorage.getItem("_lastscrollpos"))},300))}initeSkrollrr(){var e=document.querySelectorAll(".is-overlay-bg");e.forEach(s=>{s.style&&s.style.filter&&s.style.filter.indexOf("grayscale")!==-1&&(s.parentNode.style.filter="grayscale(1)")});const t=new Ts({transition:"all 0.3s ease-out"});t.init(),window.skrollrr=t}_scrollTo(e,t=0){const s=e.getBoundingClientRect().top+window.pageYOffset+t;window.scrollTo({top:s,behavior:"smooth"})}scrollIt(e,t=200,s="linear",i){this._scrollTo(e)}skrollrSetup(){document.querySelectorAll(".pin-wrap").forEach(a=>{const l=a.firstElementChild;a.after(l),a.parentNode.removeChild(a)}),document.querySelectorAll(".is-section").forEach(a=>{a.hasAttribute("data-section-clone")&&a.parentNode.removeChild(a),a.hasAttribute("data-section-original")&&(a.style.display="",a.removeAttribute("data-section-original"))});let s=window.innerWidth;s<=760&&document.querySelectorAll(".section-wrap").forEach(l=>{l.outerHTML=l.innerHTML});const i=window.self!==window.top;let n;i?n=document.querySelectorAll(".is-wrapper .section-pin"):n=document.querySelectorAll(".is-wrapper:not(.is-edit) .section-pin"),n.length>0&&window.scrollTo(0,0),n.forEach(function(a){s<=970&&a.querySelector(".is-box")&&(a.querySelectorAll(".is-box").forEach(c=>{const u=a.cloneNode(!1);c.getAttributeNames().map(o=>{o.indexOf("data-")!==-1&&u.setAttribute(o,c.getAttribute(o))}),u.classList.add("is-box"),c.classList.forEach(o=>{(o.indexOf("is-box-")!==-1||o.indexOf("is-content-")!==-1||o.indexOf("box-autofit")!==-1||o.indexOf("is-light-text")!==-1||o.indexOf("is-dark-text")!==-1||o.indexOf("is-align-")!==-1||o.indexOf("type-")!==-1||o.indexOf("block-click")!==-1||o.indexOf("hover-zoom")!==-1)&&u.classList.add(o)}),u.setAttribute("data-section-clone",""),u.innerHTML=c.innerHTML,a.parentNode.insertBefore(u,a)}),a.setAttribute("data-section-original",""),a.style.display="none")}),i?n=document.querySelectorAll(".is-wrapper .section-pin"):n=document.querySelectorAll(".is-wrapper:not(.is-edit) .section-pin"),n.forEach(function(a){if(a.parentNode.closest(".section-wrap")||s<=970&&a.hasAttribute("data-section-original"))return;const l=document.createElement("div");l.classList.add("pin-wrap"),a.classList.contains("m-skrollrr-off")&&l.classList.add("m-skrollrr-off"),a.classList.contains("pin-space-lg")&&l.classList.add("pin-space-lg"),a.classList.contains("pin-space-xl")&&l.classList.add("pin-space-xl"),a.classList.contains("xs-hidden")&&l.classList.add("xs-hidden"),a.classList.contains("sm-hidden")&&l.classList.add("sm-hidden"),a.classList.contains("desktop-hidden")&&l.classList.add("desktop-hidden"),a.after(l),l.appendChild(a)});const r=a=>{document.querySelectorAll(".is-section").forEach(c=>{const u=c.getBoundingClientRect().top;let o,h;c.parentNode.classList.contains("pin-wrap")?(o=c.parentNode.nextElementSibling,h=c.parentNode.previousElementSibling):(o=c.nextElementSibling,h=c.previousElementSibling),o&&o.classList.contains("pin-wrap")&&(o=o.querySelector(".is-section")),h&&h.classList.contains("pin-wrap")&&(h=h.querySelector(".is-section")),u<=0&&((c.classList.contains("no-spacing")||c.classList.contains("pin-overlap"))&&c.classList.add("section-inview"),document.querySelectorAll(".is-section").forEach(g=>{g!==c&&g.classList.remove("section-inview")}))})};setTimeout(()=>{(!document.querySelector(".is-wrapper").classList.contains("is-edit")||i)&&!window.funcScroll&&(window.addEventListener("scroll",r),window.funcScroll=!0)},300)}adjustBgPos(){const e=n=>{const r=document.createElement("div");r.style.backgroundPositionX=n.style.backgroundPositionX,r.style.backgroundPositionY=n.style.backgroundPositionY,r.style.backgroundSize=n.style.backgroundSize,n.hasAttribute("data-bg-ori")||n.setAttribute("data-bg-ori",r.style.cssText)},t=n=>{if(n.hasAttribute("data-bg-ori")){const r=document.createElement("div");r.style.cssText=n.getAttribute("data-bg-ori"),n.style.backgroundPositionX=r.style.backgroundPositionX,n.style.backgroundPositionY=r.style.backgroundPositionY,n.style.backgroundSize=r.style.backgroundSize,n.removeAttribute("data-bg-ori")}};let s=window.innerWidth;document.querySelectorAll("[data-bg-xs],[data-bg-sm],[data-bg-md],[data-bg-lg]").forEach(n=>{e(n),s<=760&&(n.hasAttribute("data-bg-xs")?n.style.cssText=n.style.cssText+";"+n.getAttribute("data-bg-xs"):t(n)),s>760&&s<=970&&(n.hasAttribute("data-bg-sm")?n.style.cssText=n.style.cssText+";"+n.getAttribute("data-bg-sm"):t(n)),s>970&&s<=1280&&(n.hasAttribute("data-bg-md")?n.style.cssText=n.style.cssText+";"+n.getAttribute("data-bg-md"):t(n)),s>1280&&(n.hasAttribute("data-bg-lg")?n.style.cssText=n.style.cssText+";"+n.getAttribute("data-bg-lg"):t(n))})}inViewSetup(){document.querySelectorAll(".is-overlay-content").forEach(i=>{i.querySelector("video.is-video-bg")&&i.setAttribute("data-scroll","")}),document.querySelectorAll(".is-container video").forEach(i=>{i.parentNode.setAttribute("data-scroll","")});const s=new qs({trigger:{once:!0,offset:{element:{x:0,y:(i,n,r)=>.1},viewport:{x:0,y:(i,n,r)=>i.visible?0:.1}},toggle:{class:{in:"is-inview",out:[""]},callback:{in:i=>{i.element.querySelectorAll("video").forEach(r=>{if(r.innerHTML.trim()==="")return;let a=r.parentNode.querySelector(".video-bg-play");r.autoplay?a?a.innerHTML.indexOf("play")===-1&&r.play():r.play():a&&a.innerHTML.indexOf("play")===-1&&r.play()})},out:i=>{i.element.querySelectorAll("video").forEach(r=>{!r.paused&&!r.closest("[data-html]")&&r.pause()})}}}}});s.add("[data-scroll-once]"),s.add("[data-scroll]",{once:!1}),window.trigger=s}contentBoxOnRenderUpdate(){try{if(window.contentbox||parent.contentbox){let e;window.contentbox?e=window.contentbox.onRender:parent.contentbox&&(e=parent.contentbox.onRender);const t=()=>{e.call(this);try{window.trigger&&window.trigger.kill()}catch{}let s=document.querySelectorAll(".is-animated,.is-scale-animated");s.forEach(function(i){i.classList.contains("once")?(i.removeAttribute("data-scroll",""),i.setAttribute("data-scroll-once","")):(i.removeAttribute("data-scroll-once",""),i.setAttribute("data-scroll",""))}),s=document.querySelectorAll(".is-container > div"),s.forEach(function(i){let n=i.querySelectorAll(".is-animated[data-scroll],.is-animated[data-scroll-once]"),r=0;n.length>1&&n.forEach(function(a){a.className.indexOf("delay-")===-1&&(r>0&&(a.style.transitionDelay=r+"s",a.style.animationDelay=r+"s"),r=r+.2)})}),setTimeout(()=>{this.inViewSetup()},100)};window.contentbox?window.contentbox.onRender=t:parent.contentbox&&(parent.contentbox.onRender=t)}}catch{}}functionLightboxInit(){const e={touchNavigation:!0,selector:".glightbox",loop:!0,autoplayVideos:!0,zoomable:!0,slideEffect:"slide",descPosition:"bottom",skin:this.settings.skin};this.refreshLightbox(e),document.querySelectorAll(".is-lightbox,.block-click").forEach(s=>{const i=n=>{let r=s.getAttribute("href")||s.getAttribute("data-modal-url");this.openLightbox(r,s,e),n.preventDefault(),n.stopImmediatePropagation()};s.addEventListener("click",i),s._lightboxHandler=i})}refreshLightbox(e){this.glightbox&&this.glightbox.destroy(),this.glightbox=new Fi(e),window.GLightbox=Fi.default}openLightbox(e,t,s){let i=[],n=0;if(t){const a=t.closest("[data-gallery]");let l=[];a?l=a.querySelectorAll(".is-lightbox"):document.querySelectorAll(".is-lightbox,.block-click").forEach(u=>{u.closest("[data-gallery]")||l.push(u)}),l.forEach((c,u)=>{let o=c.getAttribute("href");o||(o=c.getAttribute("data-modal-url")),i.push({href:o}),e===o&&(n=u)})}const r=document.activeElement;r?.blur(),i.length>0?(this.glightbox.setElements(i),this.glightbox.openAt(n)):(this.glightbox.setElements([{href:e}]),this.glightbox.open()),this.glightbox.on("close",()=>{this.refreshLightbox(s),r?.focus()})}blockInit(){const e={start:()=>{document.querySelectorAll(".is-block").forEach(i=>{i.hasAttribute("data--t")||i.setAttribute("data--t",i.style.top),i.hasAttribute("data--l")||i.setAttribute("data--l",i.style.left),i.hasAttribute("data--b")||i.setAttribute("data--b",i.style.bottom),i.hasAttribute("data--r")||i.setAttribute("data--r",i.style.right),i.hasAttribute("data--w")||i.setAttribute("data--w",i.style.width),i.hasAttribute("data--h")||i.setAttribute("data--h",i.style.height),i.removeAttribute("data-prev"),i.removeAttribute("data-fluid"),i.removeAttribute("data-fluid-val"),i.classList.remove("fluid"),i.style.transition=""})},apply:(i,n,r)=>{if(n&&i.getAttribute("data-prev")!==n+""){if(r||(i.style.transition="all 0.35s ease"),n!==1e4){if(i.setAttribute("data-breakpoint",n),i.hasAttribute("data--t-"+n)){let a=i.getAttribute("data--t-"+n);i.style.top=a}if(i.hasAttribute("data--l-"+n)){let a=i.getAttribute("data--l-"+n);i.style.left=a}if(i.hasAttribute("data--b-"+n)){let a=i.getAttribute("data--b-"+n);i.style.bottom=a}if(i.hasAttribute("data--r-"+n)){let a=i.getAttribute("data--r-"+n);i.style.right=a}if(i.hasAttribute("data--w-"+n)){let a=i.getAttribute("data--w-"+n);i.style.width=a}if(i.hasAttribute("data--h-"+n)){let a=i.getAttribute("data--h-"+n);i.style.height=a}if(i.hasAttribute("data--transform-"+n)){let a=i.getAttribute("data--transform-"+n);i.style.transform=a,i.setAttribute("data--transform-val",n)}}else{if(i.removeAttribute("data-breakpoint"),i.hasAttribute("data--t")){let a=i.getAttribute("data--t");i.style.top=a}if(i.hasAttribute("data--l")){let a=i.getAttribute("data--l");i.style.left=a}if(i.hasAttribute("data--b")){let a=i.getAttribute("data--b");i.style.bottom=a}if(i.hasAttribute("data--r")){let a=i.getAttribute("data--r");i.style.right=a}if(i.hasAttribute("data--w")){let a=i.getAttribute("data--w");i.style.width=a}if(i.hasAttribute("data--h")){let a=i.getAttribute("data--h");i.style.height=a}if(i.hasAttribute("data--transform")){let a=i.getAttribute("data--transform");i.style.transform=a,i.setAttribute("data--transform-val","")}}i.setAttribute("data-prev",n),setTimeout(()=>{r||(i.style.transition="")},400)}},applyFluid:(i,n)=>{i.classList.toggle("fluid",n==="yes"),i.setAttribute("data-fluid",n)},resize:i=>{const n=window.innerWidth;document.querySelectorAll(".is-box").forEach(r=>{let a=[];const l=r.attributes;for(let c=0;c<l.length;c++){let o=l[c].name.match(/^data--h-(\d+)$/);if(o){const h=parseInt(o[1],10);a.push(h)}}a=[...new Set(a)],a.sort((c,u)=>u-c);for(let c=0;c<a.length;c++){const u=a[c];if(c===0){if(n>u){let o=r.getAttribute("data--h");o?r.style.height=o:r.style.height=""}}else{const o=a[c-1];if(o>=n&&n>u){let h=r.getAttribute("data--h-"+o);h&&(r.style.height=h)}}}if(a.length>0&&a[a.length-1]>=n){const u=a[a.length-1];let o=r.getAttribute("data--h-"+u);o&&(r.style.height=o)}}),document.querySelectorAll(".is-block").forEach(r=>{if(!r.classList.contains("locked")){r.offsetWidth+0>n&&!r.classList.contains("fluid")&&(r.setAttribute("data-fluid-val",r.offsetWidth),e.applyFluid(r,"yes"));let c=r.getAttribute("data-fluid-val");c&&parseInt(c)+0<=n&&r.classList.contains("fluid")&&e.applyFluid(r,"no")}let a=[];const l=r.attributes;for(let c=0;c<l.length;c++){const u=l[c].name;let o=u.match(/^data--t-(\d+)$/);if(o){const h=parseInt(o[1],10);a.push(h)}if(o=u.match(/^data--w-(\d+)$/),o){const h=parseInt(o[1],10);a.push(h)}if(o=u.match(/^data--transform-(\d+)$/),o){const h=parseInt(o[1],10);a.push(h)}}a=[...new Set(a)],a.sort((c,u)=>u-c);for(let c=0;c<a.length;c++){const u=a[c];if(c===0)n>u&&e.apply(r,1e4,i);else{const o=a[c-1];o>=n&&n>u&&e.apply(r,o,i)}}if(a.length>0){const c=a[a.length-1];c>=n&&e.apply(r,c,i)}})},render:()=>{e.start(),e.resize(!0)}},s=((i,n)=>{let r;return(...a)=>{clearTimeout(r),r=setTimeout(()=>i(...a),n)}})(()=>{e.resize()},0);window.addEventListener("resize",s),e.start(),e.resize(!0),this.Block=e}pageReRender(){this.prepareContent(),this.contentBoxOnRenderUpdate(),window.skrollrr?window.skrollrr.refresh():this.initeSkrollrr(),this.functionLightboxInit(),this.inViewSetup(),this.Block.start(),this.Block.resize()}destroy(){this.glightbox&&(this.glightbox.destroy(),this.glightbox=null),document.querySelectorAll(".is-lightbox,.block-click").forEach(t=>{t._lightboxHandler&&(t.removeEventListener("click",t._lightboxHandler),delete t._lightboxHandler)}),this.pluginManager.destroy(),this.initialized=!1,this.emit("destroy")}}return Nr})();
536
+ `}}else{const _=JSON.parse(v);this.tokenInput+=_.prompt_tokens,this.tokenOutput+=_.completion_tokens;break}}return!0}catch(u){return u.name==="AbortError"?this.settings.consoleLog&&console.log("Request aborted by user."):console.error("Error:",u),!1}}hexToRgb(e){const t=e.replace("#",""),s=parseInt(t,16),i=s>>16&255,n=s>>8&255,r=s&255;return{red:i,green:n,blue:r}}getId(e="id"){return`${e}-${Math.random().toString(36).substr(2,9)}`}appendHtml(e,t){e&&t&&e.insertAdjacentHTML("beforeend",t)}cleanup(){if(this.element){let e=this.element.querySelectorAll('input[type="text"], input[type="number"], input[type="email"], input[type="tel"], input[type="url"], textarea');e.forEach(t=>{t.removeEventListener("input",this.inputListener)}),e=this.element.querySelectorAll('input[type="date"], input[type="radio"], input[type="checkbox"]'),e.forEach(t=>{t.removeEventListener("change",this.changeListener)}),this.debounceTimeout&&(clearTimeout(this.debounceTimeout),this.debounceTimeout=null)}}destroy(){try{if(this._scrollListener){let e;this.settings.isBuilder?e=document.querySelector(this.settings.previewSelector):e=this.element;const t=e.querySelector(".submit-container"),s=this.getScrollableParent(t);s?s.removeEventListener("scroll",this._scrollListener):window.removeEventListener("scroll",this._scrollListener),window.removeEventListener("resize",this._scrollListener)}}catch{}this.element&&(this.cleanup(),this.element.innerHTML="",this.element=null);for(const e in this.listeners)this.listeners[e].clear();this.listeners={}}out(e){let t=this.settings.lang[e];return t||e}}class qr{addClass(e,t){e&&(this.hasClass(e,t)||(e.classList.length===0?e.className=t:e.className=e.className+" "+t,e.className=e.className.replace(/ +/g," ")))}removeClass(e,t){if(e&&e.classList.length>0){let s,i,n,r,a=t.split(" ");for(s=0,n=a.length;s<n;++s){if(!a[s])continue;let l=a[s],c="",u=e.className.split(" ");for(i=0,r=u.length;i<r;++i)u[i]&&u[i]!==l&&(c+=u[i]+" ");e.className=c.trim()}e.className===""&&e.removeAttribute("class")}}hasClass(e,t){if(!e)return!1;try{let s=e.getAttribute("class");return new RegExp("\\b"+t+"\\b").test(s)}catch{}}}const F=new qr;class Ir{constructor(e={}){const t={};this.settings=Object.assign(this,t,e)}init(){const e=h=>{const p=h.parentNode,g=h.nextElementSibling;if(F.hasClass(g,"is-menu-links")){let S=g.querySelectorAll("li");S.forEach(b=>{if(b!==p){const x=b.querySelector("ul");F.removeClass(x,"active")}}),S=document.querySelectorAll(".is-menu > ul > li ul"),S.forEach(b=>{const x=b.querySelector("ul");F.removeClass(x,"active")})}F.hasClass(g,"active")&&!F.hasClass(g,"is-menu-links")&&g.querySelectorAll("li").forEach(b=>{if(b!==p){const x=b.querySelector("ul");F.removeClass(x,"active")}});const w=p.querySelector("ul");w&&F.addClass(w,"active")},t=h=>{if(h.nextElementSibling){const p=h.nextElementSibling;if(p)if(F.hasClass(p,"active"))F.removeClass(p,"active"),h.focus();else{const w=h.parentNode.parentNode;F.removeClass(w,"active"),w.previousElementSibling.focus()}else{const w=h.parentNode.parentNode;F.removeClass(w,"active"),w.previousElementSibling.focus()}}else{const g=h.parentNode.parentNode;F.removeClass(g,"active"),g.previousElementSibling.focus()}},s=h=>{const p=h.target;if(h.keyCode===27)t(h.target);else if(h.keyCode===13)h.target.nextElementSibling&&(h.target.getAttribute("href")===""||h.target.getAttribute("href")==="javascript:")&&(e(h.target),h.preventDefault());else if(h.keyCode===32)h.target.nextElementSibling&&(e(h.target),h.preventDefault());else if(h.keyCode===40)if(p.nextElementSibling)if(p.nextElementSibling.classList.contains("active"))p.nextElementSibling.querySelector("a").focus(),h.preventDefault();else if(p.parentNode.nextElementSibling)p.parentNode.nextElementSibling.querySelector("a").focus(),h.preventDefault();else{const w=p.parentNode.parentNode;w.classList.contains("active")&&(w.classList.remove("active"),w.previousElementSibling.focus(),h.preventDefault())}else if(p.parentNode.nextElementSibling)p.parentNode.nextElementSibling.querySelector("a").focus(),h.preventDefault();else{const w=p.parentNode.parentNode;w.classList.contains("active")&&(w.classList.remove("active"),w.previousElementSibling.focus(),h.preventDefault())}else if(h.keyCode===38)if(p.nextElementSibling)if(p.nextElementSibling.classList.contains("active"))p.nextElementSibling.classList.remove("active");else{const g=p.parentNode.previousElementSibling;g&&g.querySelector("a").focus()}else if(p.parentNode.previousElementSibling)p.parentNode.previousElementSibling.querySelector("a").focus();else{const w=p.parentNode.parentNode;w.classList.contains("active")&&w.classList.remove("active"),w.previousElementSibling.focus()}else if(h.which===9&&!h.shiftKey)if(p.nextElementSibling)if(p.nextElementSibling.classList.contains("active"))p.nextElementSibling.querySelector("a").focus(),h.preventDefault();else if(p.parentNode.nextElementSibling)p.parentNode.nextElementSibling.querySelector("a").focus(),h.preventDefault();else{const w=p.parentNode.parentNode;w.classList.contains("active")&&(w.classList.remove("active"),w.previousElementSibling.focus(),h.preventDefault())}else if(p.parentNode.nextElementSibling)p.parentNode.nextElementSibling.querySelector("a").focus(),h.preventDefault();else{const w=p.parentNode.parentNode;w.classList.contains("active")&&(w.classList.remove("active"),w.previousElementSibling.focus(),h.preventDefault())}else if(h.which===9&&h.shiftKey){if(p.nextElementSibling)p.nextElementSibling.classList.contains("active")&&p.nextElementSibling.classList.remove("active");else if(!p.parentNode.previousElementSibling){const w=p.parentNode.parentNode;w.classList.contains("active")&&w.classList.remove("active")}}};document.querySelectorAll(".is-menu li a").forEach(h=>{h.addEventListener("keydown",s)}),document.querySelectorAll(".is-menu li").forEach(h=>{const p=h.querySelector("span");p&&p.addEventListener("click",g=>{if(window.innerWidth>=1024)return;const b=g.target.closest("li").querySelector("ul");b&&(F.hasClass(b,"active")?(F.removeClass(b,"active"),b.style.display=""):F.addClass(b,"active")),g.preventDefault(),g.stopImmediatePropagation()}),h.addEventListener("click",g=>{const w=h.querySelector("ul"),S=window.innerWidth;let b=g.target.tagName.toLowerCase();if(S>1024){if((b==="a"||b==="i")&&!g.target.getAttribute("href")){g.preventDefault(),g.stopImmediatePropagation();return}}else{let x=!0;if((b==="a"||b==="i")&&(g.target.getAttribute("href")||(g.preventDefault(),x=!1)),x){const m=document.querySelector(".is-menu");if(m.style.right==="0px"){F.removeClass(r,"active"),m.style.right="-1000px";const v=document.querySelector(".is-menu-overlay");F.removeClass(v,"active"),document.querySelector(".is-topbar-menu").style.paddingRight="0px",document.body.style.overflowY="auto"}}}w&&(F.hasClass(w,"active")?(F.removeClass(w,"active"),w.style.display=""):(F.addClass(w,"active"),setTimeout(()=>{},0)))}),h.addEventListener("mouseleave",g=>{window.innerWidth<=1024||(this.timer=setTimeout(()=>{const S=h.querySelector("ul");S&&F.removeClass(S,"active")},200),g.preventDefault(),g.stopImmediatePropagation())}),h.addEventListener("mouseenter",g=>{const w=window.innerWidth;if(w<=1024||this.staticClose)return;const S=document.querySelector(".is-menu-search-input");if(F.hasClass(S,"active"))return;clearTimeout(this.timer);const b=h.closest("ul");if(!h.querySelector("ul"))return b.querySelectorAll("li").forEach(v=>{const _=v.querySelector("ul");F.removeClass(_,"active")}),!0;if(F.hasClass(b,"is-menu-links")){let m=b.querySelectorAll("li");m.forEach(v=>{if(v!==h){const _=v.querySelector("ul");F.removeClass(_,"active")}}),m=document.querySelectorAll(".is-menu > ul > li ul"),m.forEach(v=>{const _=v.querySelector("ul");F.removeClass(_,"active")})}F.hasClass(b,"active")&&!F.hasClass(b,"is-menu-links")&&b.querySelectorAll("li").forEach(v=>{if(v!==h){const _=v.querySelector("ul");F.removeClass(_,"active")}});const x=h.querySelector("ul");if(x&&F.addClass(x,"active"),x.style.right="",x.classList.contains("active")){const m=x.getBoundingClientRect();m.left+m.width>w&&(x.style.right=0)}g.preventDefault(),g.stopImmediatePropagation()})});const r=document.querySelector("#is-menu-toggle");r.addEventListener("click",h=>{const p=document.querySelector(".is-menu");if(p.style.right==="0px"){F.removeClass(r,"active"),p.style.right="-1000px";const g=document.querySelector(".is-menu-overlay");F.removeClass(g,"active"),document.querySelector(".is-topbar-menu").style.paddingRight="0px",document.body.style.overflowY="auto"}else{F.addClass(r,"active"),document.querySelector(".is-menu-links .is-menu-search")?(document.querySelector(".is-menu-search-input").style.display="",document.querySelector(".is-menu-links").style.marginTop=""):(document.querySelector(".is-menu-search-input").style.display="none",document.querySelector(".is-menu-links").style.marginTop="70px"),p.style.right="0px";const w=document.querySelector(".is-menu-overlay");F.addClass(w,"active"),document.querySelector(".is-topbar-menu").style.paddingRight=this.getScrollbarWidth()+"px",document.body.style.overflowY="hidden"}h.stopImmediatePropagation(),h.preventDefault()}),document.querySelector(".is-menu-overlay").addEventListener("click",h=>{document.querySelector("#is-menu-toggle").click(),h.stopImmediatePropagation(),h.preventDefault()}),window.addEventListener("resize",()=>{document.body.style.overflowY="auto",document.querySelector(".is-topbar-menu").style.paddingRight="0px";const h=document.querySelector("#is-menu-toggle");F.removeClass(h,"active"),document.querySelectorAll(".is-menu li ul").forEach(S=>{F.removeClass(S,"active")});const g=document.querySelector(".is-menu");if(g.style.transition="none",window.innerWidth>1024){g.style.right="0px",document.querySelectorAll(".is-menu li ul").forEach(x=>{x.style.display=""});const b=document.querySelector(".is-menu-overlay");F.removeClass(b,"active"),document.querySelector(".is-menu-search-input").style.display="",document.querySelector(".is-menu-links").style.marginTop=""}else g.style.right="-1000px";setTimeout(()=>{g.style.transition=""},30)}),window.addEventListener("scroll",()=>{var h=100,p=this.getCurrentScroll();p>=h?F.addClass(document.querySelector(".is-topbar"),"shrink"):F.removeClass(document.querySelector(".is-topbar"),"shrink"),window.innerWidth>=1024&&document.querySelector(".is-topbar.static")&&(p>30?this.staticClose||(document.querySelectorAll(".is-menu li ul").forEach(S=>{F.removeClass(S,"active")}),this.staticClose=!0):this.staticClose=!1)});const l=h=>{const p=document.querySelector(".is-menu-search-input");F.addClass(p,"active"),p.querySelector("input").focus(),document.querySelectorAll(".is-menu li ul").forEach(S=>{F.removeClass(S,"active")}),h.preventDefault(),h.stopImmediatePropagation()},c=document.querySelector(".is-menu-search");c&&(c.addEventListener("click",h=>{l(h)}),c.addEventListener("keydown",h=>{(h.keyCode===13||h.keyCode===32)&&l(h)})),document.addEventListener("click",h=>{const p=h.target;if(!F.hasClass(p,"is-menu-search")&&p.getAttribute("id")!=="is_btnSearch"&&p.getAttribute("id")!=="is_txtSearch"){const g=document.querySelector(".is-menu-search-input");F.removeClass(g,"active")}});const u=document.querySelector("#is_txtSearch");u.addEventListener("keydown",h=>{if(h.which==13&&this.settings.onSearch(u.value),h.which==27){const p=document.querySelector(".is-menu-search-input");F.removeClass(p,"active"),document.querySelector(".is-menu-search").focus()}}),document.querySelector("#is_btnSearch").addEventListener("click",()=>{this.settings.onSearch(u.value)})}getScrollbarWidth(){return window.innerWidth-document.documentElement.clientWidth}getCurrentScroll(){return window.pageYOffset||document.documentElement.scrollTop}}class jr{constructor(e={}){this.config={plugins:{},autoLoad:!0,pluginBaseUrl:"",allowExternalPlugins:!0,trustedDomains:[],onReInit:()=>{},...e},this.plugins=new Map,this.loadedStyles=new Set,this.components=new Map,this.externalPlugins=new Map}async autoLoadPlugins(){const t=this.detectComponentTypes().filter(s=>this.config.plugins[s]&&!this.plugins.has(s));return t.length>0&&await Promise.all(t.map(s=>this.loadPlugin(s))),t}detectComponentTypes(){const e=new Set;return document.querySelectorAll("[data-cb-type]").forEach(t=>{e.add(t.dataset.cbType)}),document.querySelectorAll('[class*="cb-"]').forEach(t=>{t.classList.forEach(s=>{if(s.startsWith("cb-")){const i=s.replace("cb-","");e.add(i)}})}),Array.from(e)}async loadPlugin(e){if(this.plugins.has(e))return this.plugins.get(e);const t=this.config.plugins[e];if(!t)return console.warn(`[PluginManager] Plugin "${e}" not found in registry`),null;try{t.css&&this.loadCSS(this.resolveUrl(t.css));const s=this.resolveUrl(t.url),i=await this.importModule(s),n=i.default||i;return this.plugins.set(e,n),typeof n.init=="function"&&await n.init(this),this.emit("plugin-loaded",{name:e,plugin:n}),n}catch(s){return console.error(`[PluginManager] Failed to load plugin "${e}":`,s),null}}async importModule(e){return import(e)}loadCSS(e){if(this.loadedStyles.has(e))return;const t=document.createElement("link");t.rel="stylesheet",t.href=e,t.onload=()=>{this.emit("css-loaded",{url:e})},t.onerror=()=>{console.error(`[PluginManager] Failed to load CSS: ${e}`)},document.head.appendChild(t),this.loadedStyles.add(e)}resolveUrl(e){return e.startsWith("http://")||e.startsWith("https://")||e.startsWith("//")?e:this.config.pluginBaseUrl+e}initializeComponents(){return document.querySelectorAll("[data-cb-type]").forEach((t,s)=>{const i=t.dataset.cbType,n=this.plugins.get(i);if(n&&typeof n.mount=="function")try{const r=this.parseOptions(t);let a=t.querySelector(".grid-sortable");a||t.classList.contains("grid-sortable")&&(a=t),a&&Array.from(a.children).forEach((u,o)=>{u.nodeType===1&&u.tagName!=="STYLE"&&u.tagName!=="SCRIPT"&&u.setAttribute("data-index",o)}),t.querySelectorAll(".edit").forEach((u,o)=>{const h=`content-${Date.now()}-${s}-${o}`;u.setAttribute("data-edit-id",h)}),t.hasAttribute("data-cb-original-content")||t.setAttribute("data-cb-original-content",t.innerHTML);const c=n.mount(t,r);this.components.set(t,c),this.setupInlineEditing(t,r),t.setAttribute("data-cb-loaded","true"),typeof t.mount=="function"&&t.mount()}catch(r){console.error(`[PluginManager] Failed to mount component "${i}":`,r)}}),this.components.size}parseOptions(e){const t={};return Array.from(e.attributes).forEach(s=>{if(s.name.startsWith("data-cb-")){const i=s.name.replace("data-cb-","").replace(/-([a-z])/g,(n,r)=>r.toUpperCase());t[i]=this.parseValue(s.value)}}),t}parseValue(e){if(e==="true")return!0;if(e==="false")return!1;if(!isNaN(e)&&e!=="")return Number(e);try{return JSON.parse(e)}catch{return e}}setupInlineEditing(e,t){if(!e.closest(".data-editor"))return;const s=e.querySelectorAll(".edit[data-edit-id]");if(s.length===0)return;e.querySelectorAll('.edit[contenteditable="true"]').forEach(r=>{r.removeAttribute("contenteditable"),r._cbObserver&&(r._cbObserver.disconnect(),delete r._cbObserver),r._cbKeydownHandler&&(r.removeEventListener("keydown",r._cbKeydownHandler),delete r._cbKeydownHandler)});const n=(r,a)=>{const l=e.getAttribute("data-cb-original-content");if(!l)return;const c=document.createElement("template");c.innerHTML=l.trim();const o=c.content.querySelector(`[data-edit-id="${r}"]`);if(o){o.innerHTML=a;const h=c.innerHTML;e.setAttribute("data-cb-original-content",h)}};s.forEach(r=>{r.setAttribute("contenteditable","true");const a=u=>{var o=document.createRange();o.selectNodeContents(u);var h=window.getSelection();h.removeAllRanges(),h.addRange(o)},l=u=>{if((u.ctrlKey||u.metaKey)&&u.which===65){let o;try{window.getSelection?o=window.getSelection().getRangeAt(0).commonAncestorContainer.parentNode:document.selection&&(o=document.selection.createRange().parentElement()),a(o),u.preventDefault(),u.stopImmediatePropagation()}catch{}}};r.addEventListener("keydown",l),r._cbKeydownHandler=l;const c=new MutationObserver(()=>{const u=r.getAttribute("data-edit-id"),o=r.innerHTML;n(u,o)});c.observe(r,{childList:!0,characterData:!0,subtree:!0,attributes:!0}),r._cbObserver=c})}async use(e){return await this.loadPlugin(e)}getPlugin(e){return this.plugins.get(e)}getAllPlugins(){return Array.from(this.plugins.entries())}hasPlugin(e){return this.plugins.has(e)}getComponent(e){return this.components.get(e)}async reinitialize(e=document){if(this.reinitializeInProgress)return clearTimeout(this.pendingReinitialize),new Promise(t=>{this.pendingReinitialize=setTimeout(async()=>{this.pendingReinitialize=null;const s=await this.reinitialize(e);t(s)},100)});this.reinitializeInProgress=!0;try{const t=[];this.components.forEach((a,l)=>{(e===document||e.contains(l))&&t.push({element:l,instance:a})}),t.forEach(({element:a,instance:l})=>{const c=a.dataset.cbType,u=this.plugins.get(c);u&&typeof u.unmount=="function"&&u.unmount(a,l),this.components.delete(a)});const i=this.detectComponentTypesInContainer(e).filter(a=>this.config.plugins[a]&&!this.plugins.has(a));i.length>0&&await Promise.all(i.map(a=>this.loadPlugin(a)));const n=e.querySelectorAll("[data-cb-type]");let r=0;for(const a of n){const l=a.dataset.cbType,c=this.plugins.get(l);if(c&&typeof c.mount=="function")try{const u=this.parseOptions(a);let o=a.querySelector(".grid-sortable");if(o||a.classList.contains("grid-sortable")&&(o=a),o&&Array.from(o.children).forEach((g,w)=>{g.nodeType===1&&g.tagName!=="STYLE"&&g.tagName!=="SCRIPT"&&g.setAttribute("data-index",w)}),a.querySelectorAll(".edit").forEach((g,w)=>{const S=`content-${Date.now()}-${r}-${w}`;g.setAttribute("data-edit-id",S)}),!a.hasAttribute("data-cb-original-content"))a.setAttribute("data-cb-original-content",a.innerHTML);else{let g=document.createRange();a.innerHTML="",a.appendChild(g.createContextualFragment(a.getAttribute("data-cb-original-content")))}const p=await c.mount(a,u);this.components.set(a,p),this.setupInlineEditing(a,u),a.setAttribute("data-cb-loaded","true"),typeof a.mount=="function"&&a.mount(),r++}catch(u){console.error(`[PluginManager] Failed to mount component "${l}":`,u)}}return typeof this.config.onReInit=="function"&&this.config.onReInit(),this.emit("reinitialized",{container:e,count:r}),r}finally{this.reinitializeInProgress=!1}}detectComponentTypesInContainer(e){const t=new Set;return e.querySelectorAll("[data-cb-type]").forEach(i=>{t.add(i.dataset.cbType)}),Array.from(t)}async loadExternalPlugin(e,t){if(!e||typeof e!="string")throw new Error("Plugin ID is required and must be a string");if(!t.url)throw new Error("Plugin URL is required");if(this.plugins.has(e))return console.warn(`[PluginManager] Plugin "${e}" is already loaded`),this.plugins.get(e);const s=this.validatePluginSource(t.url);if(!s.allowed)throw new Error(`Security: ${s.reason}`);s.warning&&(console.warn(`[PluginManager] ${s.warning}`),this.emit("plugin-security-warning",{pluginId:e,url:t.url,warning:s.warning}));try{this.config.plugins[e]={url:t.url,css:t.css||null,source:"external",loadedAt:new Date().toISOString()},this.externalPlugins.set(e,this.config.plugins[e]);const i=await this.loadPlugin(e);return this.emit("external-plugin-loaded",{pluginId:e,url:t.url}),i}catch(i){throw delete this.config.plugins[e],this.externalPlugins.delete(e),console.error(`[PluginManager] Failed to load external plugin "${e}":`,i),i}}validatePluginSource(e){const t=e.includes("localhost")||e.includes("127.0.0.1");if(!e.startsWith("https://")&&!t)return{allowed:!1,reason:"Only HTTPS URLs are allowed (except localhost for development)"};if(!this.config.allowExternalPlugins)return{allowed:!1,reason:"External plugins are disabled. Enable allowExternalPlugins in configuration."};if(this.config.trustedDomains.length>0){const i=new URL(e).hostname;if(!this.config.trustedDomains.some(r=>{if(r.startsWith("*.")){const a=r.slice(2);return i===a||i.endsWith("."+a)}return i===r}))return{allowed:!0,warning:`Loading plugin from external domain: ${i}. Only add plugins from sources you trust.`}}else return{allowed:!0,warning:`Loading external plugin from: ${new URL(e).hostname}. This plugin will have full access to your page.`};return{allowed:!0}}async loadExternalPlugins(e){const t=[];for(const[s,i]of Object.entries(e))try{const n=await this.loadExternalPlugin(s,i);t.push({pluginId:s,success:!0,plugin:n})}catch(n){t.push({pluginId:s,success:!1,error:n.message}),console.error(`[PluginManager] Failed to load external plugin "${s}":`,n)}return t}unregisterPlugin(e){if(!this.externalPlugins.has(e))return console.warn(`[PluginManager] Plugin "${e}" is not an external plugin`),!1;const t=this.plugins.get(e),s=[];return this.components.forEach((i,n)=>{n.dataset.cbType===e&&s.push({element:n,instance:i})}),s.forEach(({element:i,instance:n})=>{t&&typeof t.unmount=="function"&&t.unmount(i,n),this.components.delete(i)}),t&&typeof t.destroy=="function"&&t.destroy(this),this.plugins.delete(e),this.externalPlugins.delete(e),delete this.config.plugins[e],this.emit("plugin-unregistered",{pluginId:e}),!0}getExternalPlugins(){return Array.from(this.externalPlugins.entries()).map(([e,t])=>({id:e,...t}))}isExternalPlugin(e){return this.externalPlugins.has(e)}destroy(){this.components.forEach((e,t)=>{const s=t.dataset.cbType,i=this.plugins.get(s);i&&typeof i.unmount=="function"&&i.unmount(t,e)}),this.components.forEach((e,t)=>{t.querySelectorAll('.edit[contenteditable="true"]').forEach(i=>{i.removeAttribute("contenteditable"),i._cbObserver&&(i._cbObserver.disconnect(),delete i._cbObserver),i._cbKeydownHandler&&(i.removeEventListener("keydown",i._cbKeydownHandler),delete i._cbKeydownHandler)})}),this.plugins.forEach((e,t)=>{typeof e.destroy=="function"&&e.destroy(this)}),this.components.clear(),this.plugins.clear()}emit(e,t){if(this.runtime&&typeof this.runtime.emit=="function")this.runtime.emit(e,t);else{const s=new CustomEvent(`contentbox:${e}`,{detail:t});document.dispatchEvent(s)}}setRuntime(e){this.runtime=e}}class Nr{constructor(e={}){const t={skin:"light",smoothScroll:!0,plugins:{},autoLoadPlugins:!0,pluginBaseUrl:"",allowExternalPlugins:!0,trustedDomains:[]};this.settings={...t,...e},this.initialized=!1,this.pluginManager=new jr({plugins:this.settings.plugins,autoLoad:this.settings.autoLoadPlugins,pluginBaseUrl:this.settings.pluginBaseUrl,allowExternalPlugins:this.settings.allowExternalPlugins,trustedDomains:this.settings.trustedDomains,onReInit:()=>{this.functionLightboxInit()}}),this.pluginManager.setRuntime(this),window.Glide=Wn,window.FormViewer=Rr,window.NavBar=Ir,window.pageReRender=()=>{this.pageReRender()}}async use(e){return await this.pluginManager.use(e)}getPlugin(e){return this.pluginManager.getPlugin(e)}getPlugins(){return this.pluginManager.getAllPlugins()}hasPlugin(e){return this.pluginManager.hasPlugin(e)}getComponent(e){return this.pluginManager.getComponent(e)}getComponents(){return this.pluginManager.components}async reinitialize(e){return await this.pluginManager.reinitialize(e)}async loadExternalPlugin(e,t){return await this.pluginManager.loadExternalPlugin(e,t)}async loadExternalPlugins(e){return await this.pluginManager.loadExternalPlugins(e)}unregisterPlugin(e){return this.pluginManager.unregisterPlugin(e)}emit(e,t){const s=new CustomEvent(`contentbox:${e}`,{detail:t});document.dispatchEvent(s)}on(e,t){document.addEventListener(`contentbox:${e}`,t)}off(e,t){document.removeEventListener(`contentbox:${e}`,t)}async init(){this.initialized||(this.initCore(),this.initPlugins(),this.initialized=!0,this.emit("init"))}async initPlugins(){this.settings.autoLoadPlugins&&await this.pluginManager.autoLoadPlugins(),this.pluginManager.initializeComponents()}initCore(){this.prepareContent(),this.updateOnResize(),this.blockInit(),this.initeSkrollrr(),this.contentBoxOnRenderUpdate(),this.functionLightboxInit(),this.inViewSetup(),setTimeout(()=>{ks.init({duration:1200})},300),this.settings.smoothScroll&&new Qs}prepareContent(){const e=document.querySelector(".is-wrapper");e.classList.add("box-v2");const t=function(r){let a=r.nextElementSibling;return a?a.classList.contains("is-section")?a:t(a):!1};document.querySelectorAll(".is-arrow-down a").forEach(r=>{r.addEventListener("click",a=>{let l=a.target.closest(".is-section");if(l){let c=t(l);c&&this.scrollIt(c,1e3,"easeInQuad")}a.preventDefault(),a.stopImmediatePropagation()})}),e&&(e.classList.contains("is-edit")||e.querySelectorAll("a").forEach(a=>{a.addEventListener("click",l=>{let c=a.getAttribute("href");if(c&&c.indexOf("#")===0)if(c.indexOf("#section")===0){let u=c.replace("#section","");if(!isNaN(parseInt(u))){let o=document.querySelectorAll(".is-section"),h,p=0;o.forEach(function(g){g.classList.contains("is-section-navbar")||(p===u-1&&(h=g),p++)}),h&&this.scrollIt(h,1e3,"easeInQuad"),l.preventDefault()}}else try{let u=document.querySelector(c);u&&(this.scrollIt(u,1e3,"easeInQuad"),l.preventDefault())}catch{}})})),document.querySelectorAll(".section-inview").forEach(function(r){r.classList.remove("section-inview")});let n=document.querySelectorAll(".is-animated,.is-scale-animated");n.forEach(function(r){r.classList.contains("once")?(r.removeAttribute("data-scroll",""),r.setAttribute("data-scroll-once","")):(r.removeAttribute("data-scroll-once",""),r.setAttribute("data-scroll",""))}),n=document.querySelectorAll(".is-container > div"),n.forEach(function(r){let a=r.querySelectorAll(".is-animated[data-scroll],.is-animated[data-scroll-once]"),l=0;a.length>1&&a.forEach(function(c){c.className.indexOf("delay-")===-1&&(l>0&&(c.style.transitionDelay=l+"s",c.style.animationDelay=l+"s"),l=l+.2)})}),this.skrollrSetup(),this.adjustBgPos()}updateOnResize(){function e(s){var i;return function(n){i&&clearTimeout(i),i=setTimeout(s,100,n)}}const t=document.querySelector(".is-wrapper");window.addEventListener("resize",e(s=>{document.body.classList.contains("data-editor")&&(t.querySelector(".pin-wrap")&&!window.noRender?this.pageReRender():window.skrollrr&&window.skrollrr.refresh(),window.noRender=!1,this.adjustBgPos())})),t.classList.contains("is-edit")&&(window.onbeforeunload=function(s){localStorage.setItem("_lastscrollpos",document.documentElement.scrollTop),window.scrollTo(0,0)},setTimeout(()=>{localStorage.getItem("_lastscrollpos")&&window.scrollTo(0,localStorage.getItem("_lastscrollpos"))},300))}initeSkrollrr(){var e=document.querySelectorAll(".is-overlay-bg");e.forEach(s=>{s.style&&s.style.filter&&s.style.filter.indexOf("grayscale")!==-1&&(s.parentNode.style.filter="grayscale(1)")});const t=new Ts({transition:"all 0.3s ease-out"});t.init(),window.skrollrr=t}_scrollTo(e,t=0){const s=e.getBoundingClientRect().top+window.pageYOffset+t;window.scrollTo({top:s,behavior:"smooth"})}scrollIt(e,t=200,s="linear",i){this._scrollTo(e)}skrollrSetup(){document.querySelectorAll(".pin-wrap").forEach(a=>{const l=a.firstElementChild;a.after(l),a.parentNode.removeChild(a)}),document.querySelectorAll(".is-section").forEach(a=>{a.hasAttribute("data-section-clone")&&a.parentNode.removeChild(a),a.hasAttribute("data-section-original")&&(a.style.display="",a.removeAttribute("data-section-original"))});let s=window.innerWidth;s<=760&&document.querySelectorAll(".section-wrap").forEach(l=>{l.outerHTML=l.innerHTML});const i=window.self!==window.top;let n;i?n=document.querySelectorAll(".is-wrapper .section-pin"):n=document.querySelectorAll(".is-wrapper:not(.is-edit) .section-pin"),n.length>0&&window.scrollTo(0,0),n.forEach(function(a){s<=970&&a.querySelector(".is-box")&&(a.querySelectorAll(".is-box").forEach(c=>{const u=a.cloneNode(!1);c.getAttributeNames().map(o=>{o.indexOf("data-")!==-1&&u.setAttribute(o,c.getAttribute(o))}),u.classList.add("is-box"),c.classList.forEach(o=>{(o.indexOf("is-box-")!==-1||o.indexOf("is-content-")!==-1||o.indexOf("box-autofit")!==-1||o.indexOf("is-light-text")!==-1||o.indexOf("is-dark-text")!==-1||o.indexOf("is-align-")!==-1||o.indexOf("type-")!==-1||o.indexOf("block-click")!==-1||o.indexOf("hover-zoom")!==-1)&&u.classList.add(o)}),u.setAttribute("data-section-clone",""),u.innerHTML=c.innerHTML,a.parentNode.insertBefore(u,a)}),a.setAttribute("data-section-original",""),a.style.display="none")}),i?n=document.querySelectorAll(".is-wrapper .section-pin"):n=document.querySelectorAll(".is-wrapper:not(.is-edit) .section-pin"),n.forEach(function(a){if(a.parentNode.closest(".section-wrap")||s<=970&&a.hasAttribute("data-section-original"))return;const l=document.createElement("div");l.classList.add("pin-wrap"),a.classList.contains("m-skrollrr-off")&&l.classList.add("m-skrollrr-off"),a.classList.contains("pin-space-lg")&&l.classList.add("pin-space-lg"),a.classList.contains("pin-space-xl")&&l.classList.add("pin-space-xl"),a.classList.contains("xs-hidden")&&l.classList.add("xs-hidden"),a.classList.contains("sm-hidden")&&l.classList.add("sm-hidden"),a.classList.contains("desktop-hidden")&&l.classList.add("desktop-hidden"),a.after(l),l.appendChild(a)});const r=a=>{document.querySelectorAll(".is-section").forEach(c=>{const u=c.getBoundingClientRect().top;let o,h;c.parentNode.classList.contains("pin-wrap")?(o=c.parentNode.nextElementSibling,h=c.parentNode.previousElementSibling):(o=c.nextElementSibling,h=c.previousElementSibling),o&&o.classList.contains("pin-wrap")&&(o=o.querySelector(".is-section")),h&&h.classList.contains("pin-wrap")&&(h=h.querySelector(".is-section")),u<=0&&((c.classList.contains("no-spacing")||c.classList.contains("pin-overlap"))&&c.classList.add("section-inview"),document.querySelectorAll(".is-section").forEach(g=>{g!==c&&g.classList.remove("section-inview")}))})};setTimeout(()=>{(!document.querySelector(".is-wrapper").classList.contains("is-edit")||i)&&!window.funcScroll&&(window.addEventListener("scroll",r),window.funcScroll=!0)},300)}adjustBgPos(){const e=n=>{const r=document.createElement("div");r.style.backgroundPositionX=n.style.backgroundPositionX,r.style.backgroundPositionY=n.style.backgroundPositionY,r.style.backgroundSize=n.style.backgroundSize,n.hasAttribute("data-bg-ori")||n.setAttribute("data-bg-ori",r.style.cssText)},t=n=>{if(n.hasAttribute("data-bg-ori")){const r=document.createElement("div");r.style.cssText=n.getAttribute("data-bg-ori"),n.style.backgroundPositionX=r.style.backgroundPositionX,n.style.backgroundPositionY=r.style.backgroundPositionY,n.style.backgroundSize=r.style.backgroundSize,n.removeAttribute("data-bg-ori")}};let s=window.innerWidth;document.querySelectorAll("[data-bg-xs],[data-bg-sm],[data-bg-md],[data-bg-lg]").forEach(n=>{e(n),s<=760&&(n.hasAttribute("data-bg-xs")?n.style.cssText=n.style.cssText+";"+n.getAttribute("data-bg-xs"):t(n)),s>760&&s<=970&&(n.hasAttribute("data-bg-sm")?n.style.cssText=n.style.cssText+";"+n.getAttribute("data-bg-sm"):t(n)),s>970&&s<=1280&&(n.hasAttribute("data-bg-md")?n.style.cssText=n.style.cssText+";"+n.getAttribute("data-bg-md"):t(n)),s>1280&&(n.hasAttribute("data-bg-lg")?n.style.cssText=n.style.cssText+";"+n.getAttribute("data-bg-lg"):t(n))})}inViewSetup(){document.querySelectorAll(".is-overlay-content").forEach(i=>{(i.querySelector("video.is-video-bg")||i.querySelector('[data-cb-type="video-background"]'))&&i.setAttribute("data-scroll","")}),document.querySelectorAll(".is-container video").forEach(i=>{i.parentNode.setAttribute("data-scroll","")});const s=new qs({trigger:{once:!0,offset:{element:{x:0,y:(i,n,r)=>.1},viewport:{x:0,y:(i,n,r)=>i.visible?0:.1}},toggle:{class:{in:"is-inview",out:[""]},callback:{in:i=>{i.element.querySelectorAll("video").forEach(r=>{if(r.innerHTML.trim()==="")return;let a=r.parentNode.querySelector(".video-bg-play");r.autoplay?a?a.innerHTML.indexOf("play")===-1&&r.play():r.play():a&&a.innerHTML.indexOf("play")===-1&&r.play()})},out:i=>{i.element.querySelectorAll("video").forEach(r=>{r.paused||r.pause()})}}}}});s.add("[data-scroll-once]"),s.add("[data-scroll]",{once:!1}),window.trigger=s}contentBoxOnRenderUpdate(){try{if(window.contentbox||parent.contentbox){let e;window.contentbox?e=window.contentbox.onRender:parent.contentbox&&(e=parent.contentbox.onRender);const t=()=>{e.call(this);try{window.trigger&&window.trigger.kill()}catch{}let s=document.querySelectorAll(".is-animated,.is-scale-animated");s.forEach(function(i){i.classList.contains("once")?(i.removeAttribute("data-scroll",""),i.setAttribute("data-scroll-once","")):(i.removeAttribute("data-scroll-once",""),i.setAttribute("data-scroll",""))}),s=document.querySelectorAll(".is-container > div"),s.forEach(function(i){let n=i.querySelectorAll(".is-animated[data-scroll],.is-animated[data-scroll-once]"),r=0;n.length>1&&n.forEach(function(a){a.className.indexOf("delay-")===-1&&(r>0&&(a.style.transitionDelay=r+"s",a.style.animationDelay=r+"s"),r=r+.2)})}),setTimeout(()=>{this.inViewSetup()},100)};window.contentbox?window.contentbox.onRender=t:parent.contentbox&&(parent.contentbox.onRender=t)}}catch{}}functionLightboxInit(){const e={touchNavigation:!0,selector:".glightbox",loop:!0,autoplayVideos:!0,zoomable:!0,slideEffect:"slide",descPosition:"bottom",skin:this.settings.skin};this.refreshLightbox(e),document.querySelectorAll(".is-lightbox,.block-click").forEach(s=>{const i=n=>{let r=s.getAttribute("href")||s.getAttribute("data-modal-url");this.openLightbox(r,s,e),n.preventDefault(),n.stopImmediatePropagation()};s.addEventListener("click",i),s._lightboxHandler=i})}refreshLightbox(e){this.glightbox&&this.glightbox.destroy(),this.glightbox=new Fi(e),window.GLightbox=Fi.default}openLightbox(e,t,s){let i=[],n=0;if(t){const a=t.closest("[data-gallery]");let l=[];a?l=a.querySelectorAll(".is-lightbox"):document.querySelectorAll(".is-lightbox,.block-click").forEach(u=>{u.closest("[data-gallery]")||l.push(u)}),l.forEach((c,u)=>{let o=c.getAttribute("href");o||(o=c.getAttribute("data-modal-url")),i.push({href:o}),e===o&&(n=u)})}const r=document.activeElement;r?.blur(),i.length>0?(this.glightbox.setElements(i),this.glightbox.openAt(n)):(this.glightbox.setElements([{href:e}]),this.glightbox.open()),this.glightbox.on("close",()=>{this.refreshLightbox(s),r?.focus()})}blockInit(){const e={start:()=>{document.querySelectorAll(".is-block").forEach(i=>{i.hasAttribute("data--t")||i.setAttribute("data--t",i.style.top),i.hasAttribute("data--l")||i.setAttribute("data--l",i.style.left),i.hasAttribute("data--b")||i.setAttribute("data--b",i.style.bottom),i.hasAttribute("data--r")||i.setAttribute("data--r",i.style.right),i.hasAttribute("data--w")||i.setAttribute("data--w",i.style.width),i.hasAttribute("data--h")||i.setAttribute("data--h",i.style.height),i.removeAttribute("data-prev"),i.removeAttribute("data-fluid"),i.removeAttribute("data-fluid-val"),i.classList.remove("fluid"),i.style.transition=""})},apply:(i,n,r)=>{if(n&&i.getAttribute("data-prev")!==n+""){if(r||(i.style.transition="all 0.35s ease"),n!==1e4){if(i.setAttribute("data-breakpoint",n),i.hasAttribute("data--t-"+n)){let a=i.getAttribute("data--t-"+n);i.style.top=a}if(i.hasAttribute("data--l-"+n)){let a=i.getAttribute("data--l-"+n);i.style.left=a}if(i.hasAttribute("data--b-"+n)){let a=i.getAttribute("data--b-"+n);i.style.bottom=a}if(i.hasAttribute("data--r-"+n)){let a=i.getAttribute("data--r-"+n);i.style.right=a}if(i.hasAttribute("data--w-"+n)){let a=i.getAttribute("data--w-"+n);i.style.width=a}if(i.hasAttribute("data--h-"+n)){let a=i.getAttribute("data--h-"+n);i.style.height=a}if(i.hasAttribute("data--transform-"+n)){let a=i.getAttribute("data--transform-"+n);i.style.transform=a,i.setAttribute("data--transform-val",n)}}else{if(i.removeAttribute("data-breakpoint"),i.hasAttribute("data--t")){let a=i.getAttribute("data--t");i.style.top=a}if(i.hasAttribute("data--l")){let a=i.getAttribute("data--l");i.style.left=a}if(i.hasAttribute("data--b")){let a=i.getAttribute("data--b");i.style.bottom=a}if(i.hasAttribute("data--r")){let a=i.getAttribute("data--r");i.style.right=a}if(i.hasAttribute("data--w")){let a=i.getAttribute("data--w");i.style.width=a}if(i.hasAttribute("data--h")){let a=i.getAttribute("data--h");i.style.height=a}if(i.hasAttribute("data--transform")){let a=i.getAttribute("data--transform");i.style.transform=a,i.setAttribute("data--transform-val","")}}i.setAttribute("data-prev",n),setTimeout(()=>{r||(i.style.transition="")},400)}},applyFluid:(i,n)=>{i.classList.toggle("fluid",n==="yes"),i.setAttribute("data-fluid",n)},resize:i=>{const n=window.innerWidth;document.querySelectorAll(".is-box").forEach(r=>{let a=[];const l=r.attributes;for(let c=0;c<l.length;c++){let o=l[c].name.match(/^data--h-(\d+)$/);if(o){const h=parseInt(o[1],10);a.push(h)}}a=[...new Set(a)],a.sort((c,u)=>u-c);for(let c=0;c<a.length;c++){const u=a[c];if(c===0){if(n>u){let o=r.getAttribute("data--h");o?r.style.height=o:r.style.height=""}}else{const o=a[c-1];if(o>=n&&n>u){let h=r.getAttribute("data--h-"+o);h&&(r.style.height=h)}}}if(a.length>0&&a[a.length-1]>=n){const u=a[a.length-1];let o=r.getAttribute("data--h-"+u);o&&(r.style.height=o)}}),document.querySelectorAll(".is-block").forEach(r=>{if(!r.classList.contains("locked")){r.offsetWidth+0>n&&!r.classList.contains("fluid")&&(r.setAttribute("data-fluid-val",r.offsetWidth),e.applyFluid(r,"yes"));let c=r.getAttribute("data-fluid-val");c&&parseInt(c)+0<=n&&r.classList.contains("fluid")&&e.applyFluid(r,"no")}let a=[];const l=r.attributes;for(let c=0;c<l.length;c++){const u=l[c].name;let o=u.match(/^data--t-(\d+)$/);if(o){const h=parseInt(o[1],10);a.push(h)}if(o=u.match(/^data--w-(\d+)$/),o){const h=parseInt(o[1],10);a.push(h)}if(o=u.match(/^data--transform-(\d+)$/),o){const h=parseInt(o[1],10);a.push(h)}}a=[...new Set(a)],a.sort((c,u)=>u-c);for(let c=0;c<a.length;c++){const u=a[c];if(c===0)n>u&&e.apply(r,1e4,i);else{const o=a[c-1];o>=n&&n>u&&e.apply(r,o,i)}}if(a.length>0){const c=a[a.length-1];c>=n&&e.apply(r,c,i)}})},render:()=>{e.start(),e.resize(!0)}},s=((i,n)=>{let r;return(...a)=>{clearTimeout(r),r=setTimeout(()=>i(...a),n)}})(()=>{e.resize()},0);window.addEventListener("resize",s),e.start(),e.resize(!0),this.Block=e}pageReRender(){this.prepareContent(),this.contentBoxOnRenderUpdate(),window.skrollrr?window.skrollrr.refresh():this.initeSkrollrr(),this.functionLightboxInit(),this.inViewSetup(),this.Block.start(),this.Block.resize()}destroy(){this.glightbox&&(this.glightbox.destroy(),this.glightbox=null),document.querySelectorAll(".is-lightbox,.block-click").forEach(t=>{t._lightboxHandler&&(t.removeEventListener("click",t._lightboxHandler),delete t._lightboxHandler)}),this.pluginManager.destroy(),this.initialized=!1,this.emit("destroy")}}return Nr})();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@innovastudio/contentbox-runtime",
3
3
  "type": "module",
4
- "version": "1.0.27",
4
+ "version": "1.0.28",
5
5
  "description": "Runtime libraries for ContentBox generated content",
6
6
  "main": "dist/contentbox-runtime.esm.js",
7
7
  "module": "dist/contentbox-runtime.esm.js",