@innovastudio/contentbuilder-interactive-runtime 1.0.29 → 1.0.31

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.
@@ -1,4 +1,4 @@
1
- var ContentBuilderRuntime=(function(){"use strict";const Rt=Date.now();function fe(){let c={},e=!0,t=0,i=arguments.length;Object.prototype.toString.call(arguments[0])==="[object Boolean]"&&(e=arguments[0],t++);let s=n=>{for(let r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e&&Object.prototype.toString.call(n[r])==="[object Object]"?c[r]=fe(!0,c[r],n[r]):c[r]=n[r])};for(;t<i;t++){let n=arguments[t];s(n)}return c}function V(c,e){if((ge(c)||c===window||c===document)&&(c=[c]),!Ot(c)&&!Ce(c)&&(c=[c]),$t(c)!=0){if(Ot(c)&&!Ce(c)){let t=c.length,i=0;for(;i<t&&e.call(c[i],c[i],i,c)!==!1;i++);}else if(Ce(c)){for(let t in c)if(Z(c,t)&&e.call(c[t],c[t],t,c)===!1)break}}}function Mt(c,e=null,t=null){const i=c[Rt]=c[Rt]||[],s={all:i,evt:null,found:null};return e&&t&&$t(i)>0&&V(i,(n,r)=>{if(n.eventName==e&&n.fn.toString()==t.toString())return s.found=!0,s.evt=r,!1}),s}function oe(c,{onElement:e,withCallback:t,avoidDuplicate:i=!0,once:s=!1,useCapture:n=!1}={},r){let o=e||[];Ae(o)&&(o=document.querySelectorAll(o));function a(d){F(t)&&t.call(r,d,this),s&&a.destroy()}return a.destroy=function(){V(o,d=>{const u=Mt(d,c,a);u.found&&u.all.splice(u.evt,1),d.removeEventListener&&d.removeEventListener(c,a,n)})},V(o,d=>{const u=Mt(d,c,a);(d.addEventListener&&i&&!u.found||!i)&&(d.addEventListener(c,a,n),u.all.push({eventName:c,fn:a}))}),a}function H(c,e){V(e.split(" "),t=>c.classList.add(t))}function J(c,e){V(e.split(" "),t=>c.classList.remove(t))}function ee(c,e){return c.classList.contains(e)}function ce(c,e){for(;c!==document.body;){if(c=c.parentElement,!c)return!1;if(typeof c.matches=="function"?c.matches(e):c.msMatchesSelector(e))return c}}function Ee(c,e="",t=!1){if(!c||e==="")return!1;if(e==="none")return F(t)&&t(),!1;const i=yi(),s=e.split(" ");V(s,n=>{H(c,"g"+n)}),oe(i,{onElement:c,avoidDuplicate:!1,once:!0,withCallback:(n,r)=>{V(s,o=>{J(r,"g"+o)}),F(t)&&t()}})}function ze(c,e=""){if(e==="")return c.style.webkitTransform="",c.style.MozTransform="",c.style.msTransform="",c.style.OTransform="",c.style.transform="",!1;c.style.webkitTransform=e,c.style.MozTransform=e,c.style.msTransform=e,c.style.OTransform=e,c.style.transform=e}function At(c){c.style.display="block"}function rt(c){c.style.display="none"}function xe(c){let e=document.createDocumentFragment(),t=document.createElement("div");for(t.innerHTML=c;t.firstChild;)e.appendChild(t.firstChild);return e}function qt(){return{width:window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,height:window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight}}function yi(){let c,e=document.createElement("fakeelement"),t={animation:"animationend",OAnimation:"oAnimationEnd",MozAnimation:"animationend",WebkitAnimation:"webkitAnimationEnd"};for(c in t)if(e.style[c]!==void 0)return t[c]}function vi(){let c,e=document.createElement("fakeelement");const t={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(c in t)if(e.style[c]!==void 0)return t[c]}function wi(c){let{url:e,allow:t,callback:i,appendTo:s}=c,n=document.createElement("iframe");return n.className="vimeo-video gvideo",n.src=e,n.style.width="100%",n.style.height="100%",t&&n.setAttribute("allow",t),n.onload=function(){n.onload=null,H(n,"node-ready"),F(i)&&i()},s&&s.appendChild(n),n}function ot(c,e,t,i){if(c()){e();return}t||(t=100);let s=setInterval(()=>{c()&&(clearInterval(s),e())},t)}function Pt(c,e,t){if(ne(c)){console.error("Inject assets error");return}if(F(e)&&(t=e,e=!1),Ae(e)&&e in window){F(t)&&t();return}let i;if(c.indexOf(".css")!==-1){if(i=document.querySelectorAll('link[href="'+c+'"]'),i&&i.length>0){F(t)&&t();return}const n=document.getElementsByTagName("head")[0],r=n.querySelectorAll('link[rel="stylesheet"]'),o=document.createElement("link");o.rel="stylesheet",o.type="text/css",o.href=c,o.media="all",r?n.insertBefore(o,r[0]):n.appendChild(o),F(t)&&t();return}if(i=document.querySelectorAll('script[src="'+c+'"]'),i&&i.length>0){if(F(t)){if(Ae(e))return ot(()=>typeof window[e]<"u",()=>{t()}),!1;t()}return}let s=document.createElement("script");s.type="text/javascript",s.src=c,s.onload=()=>{if(F(t)){if(Ae(e))return ot(()=>typeof window[e]<"u",()=>{t()}),!1;t()}},document.body.appendChild(s)}function lt(){return typeof window>"u"?!1:"navigator"in window&&window.navigator.userAgent.match(/(iPad)|(iPhone)|(iPod)|(Android)|(PlayBook)|(BB10)|(BlackBerry)|(Opera Mini)|(IEMobile)|(webOS)|(MeeGo)/i)}function xi(){return typeof document>"u"?!1:lt()!==null||document.createTouch!==void 0||"ontouchstart"in window||"onmsgesturechange"in window||navigator.msMaxTouchPoints}function F(c){return typeof c=="function"}function Ae(c){return typeof c=="string"}function ge(c){return!!(c&&c.nodeType&&c.nodeType==1)}function It(c){return Array.isArray(c)}function Ot(c){return c&&c.length&&isFinite(c.length)}function Ce(c){return typeof c==="object"&&c!=null&&!F(c)&&!It(c)}function ne(c){return c==null}function Z(c,e){return c!==null&&hasOwnProperty.call(c,e)}function $t(c){if(Ce(c)){if(c.keys)return c.keys().length;let e=0;for(let t in c)Z(c,t)&&e++;return e}else return c.length}function Ue(c){return!isNaN(parseFloat(c))&&isFinite(c)}function Nt(c=-1){const e=document.querySelectorAll(".gbtn[data-taborder]:not(.disabled)");if(!e.length)return!1;if(e.length==1)return e[0];typeof c=="string"&&(c=parseInt(c));const t=[];V(e,o=>{t.push(o.getAttribute("data-taborder"))});const i=Math.max.apply(Math,t.map(o=>parseInt(o)));let s=c<0?1:c+1;s>i&&(s="1");const r=t.filter(o=>o>=parseInt(s)).sort()[0];return document.querySelector(`.gbtn[data-taborder="${r}"]`)}function ki(c){if(c.events.hasOwnProperty("keyboard"))return!1;c.events.keyboard=oe("keydown",{onElement:window,withCallback:(e,t)=>{e=e||window.event;const i=e.keyCode;if(i==9){const s=document.querySelector(".gbtn.focused");if(!s){const a=document.activeElement&&document.activeElement.nodeName?document.activeElement.nodeName.toLocaleLowerCase():!1;if(a=="input"||a=="textarea"||a=="button")return}e.preventDefault();const n=document.querySelectorAll(".gbtn[data-taborder]");if(!n||n.length<=0)return;if(!s){const a=Nt();a&&(a.focus(),H(a,"focused"));return}let r=s.getAttribute("data-taborder"),o=Nt(r);J(s,"focused"),o&&(o.focus(),H(o,"focused"))}i==39&&c.nextSlide(),i==37&&c.prevSlide(),i==27&&c.close()}})}function je(c){return Math.sqrt(c.x*c.x+c.y*c.y)}function _i(c,e){return c.x*e.x+c.y*e.y}function Si(c,e){var t=je(c)*je(e);if(t===0)return 0;var i=_i(c,e)/t;return i>1&&(i=1),Math.acos(i)}function Ti(c,e){return c.x*e.y-e.x*c.y}function Ei(c,e){var t=Si(c,e);return Ti(c,e)>0&&(t*=-1),t*180/Math.PI}class Ci{constructor(e){this.handlers=[],this.el=e}add(e){this.handlers.push(e)}del(e){e||(this.handlers=[]);for(var t=this.handlers.length;t>=0;t--)this.handlers[t]===e&&this.handlers.splice(t,1)}dispatch(){for(var e=0,t=this.handlers.length;e<t;e++){var i=this.handlers[e];typeof i=="function"&&i.apply(this.el,arguments)}}}function te(c,e){var t=new Ci(c);return t.add(e),t}class Li{constructor(e,t){this.element=typeof e=="string"?document.querySelector(e):e,this.start=this.start.bind(this),this.move=this.move.bind(this),this.end=this.end.bind(this),this.cancel=this.cancel.bind(this),this.element.addEventListener("touchstart",this.start,!1),this.element.addEventListener("touchmove",this.move,!1),this.element.addEventListener("touchend",this.end,!1),this.element.addEventListener("touchcancel",this.cancel,!1),this.preV={x:null,y:null},this.pinchStartLen=null,this.zoom=1,this.isDoubleTap=!1;var i=function(){};this.rotate=te(this.element,t.rotate||i),this.touchStart=te(this.element,t.touchStart||i),this.multipointStart=te(this.element,t.multipointStart||i),this.multipointEnd=te(this.element,t.multipointEnd||i),this.pinch=te(this.element,t.pinch||i),this.swipe=te(this.element,t.swipe||i),this.tap=te(this.element,t.tap||i),this.doubleTap=te(this.element,t.doubleTap||i),this.longTap=te(this.element,t.longTap||i),this.singleTap=te(this.element,t.singleTap||i),this.pressMove=te(this.element,t.pressMove||i),this.twoFingerPressMove=te(this.element,t.twoFingerPressMove||i),this.touchMove=te(this.element,t.touchMove||i),this.touchEnd=te(this.element,t.touchEnd||i),this.touchCancel=te(this.element,t.touchCancel||i),this.translateContainer=this.element,this._cancelAllHandler=this.cancelAll.bind(this),window.addEventListener("scroll",this._cancelAllHandler),this.delta=null,this.last=null,this.now=null,this.tapTimeout=null,this.singleTapTimeout=null,this.longTapTimeout=null,this.swipeTimeout=null,this.x1=this.x2=this.y1=this.y2=null,this.preTapPosition={x:null,y:null}}start(e){if(!e.touches)return;const t=["a","button","input"];if(e.target&&e.target.nodeName&&t.indexOf(e.target.nodeName.toLowerCase())>=0){console.log("ignore drag for this touched element",e.target.nodeName.toLowerCase());return}this.now=Date.now(),this.x1=e.touches[0].pageX,this.y1=e.touches[0].pageY,this.delta=this.now-(this.last||this.now),this.touchStart.dispatch(e,this.element),this.preTapPosition.x!==null&&(this.isDoubleTap=this.delta>0&&this.delta<=250&&Math.abs(this.preTapPosition.x-this.x1)<30&&Math.abs(this.preTapPosition.y-this.y1)<30,this.isDoubleTap&&clearTimeout(this.singleTapTimeout)),this.preTapPosition.x=this.x1,this.preTapPosition.y=this.y1,this.last=this.now;var i=this.preV,s=e.touches.length;if(s>1){this._cancelLongTap(),this._cancelSingleTap();var n={x:e.touches[1].pageX-this.x1,y:e.touches[1].pageY-this.y1};i.x=n.x,i.y=n.y,this.pinchStartLen=je(i),this.multipointStart.dispatch(e,this.element)}this._preventTap=!1,this.longTapTimeout=setTimeout((function(){this.longTap.dispatch(e,this.element),this._preventTap=!0}).bind(this),750)}move(e){if(e.touches){var t=this.preV,i=e.touches.length,s=e.touches[0].pageX,n=e.touches[0].pageY;if(this.isDoubleTap=!1,i>1){var r=e.touches[1].pageX,o=e.touches[1].pageY,a={x:e.touches[1].pageX-s,y:e.touches[1].pageY-n};t.x!==null&&(this.pinchStartLen>0&&(e.zoom=je(a)/this.pinchStartLen,this.pinch.dispatch(e,this.element)),e.angle=Ei(a,t),this.rotate.dispatch(e,this.element)),t.x=a.x,t.y=a.y,this.x2!==null&&this.sx2!==null?(e.deltaX=(s-this.x2+r-this.sx2)/2,e.deltaY=(n-this.y2+o-this.sy2)/2):(e.deltaX=0,e.deltaY=0),this.twoFingerPressMove.dispatch(e,this.element),this.sx2=r,this.sy2=o}else{if(this.x2!==null){e.deltaX=s-this.x2,e.deltaY=n-this.y2;var d=Math.abs(this.x1-this.x2),u=Math.abs(this.y1-this.y2);(d>10||u>10)&&(this._preventTap=!0)}else e.deltaX=0,e.deltaY=0;this.pressMove.dispatch(e,this.element)}this.touchMove.dispatch(e,this.element),this._cancelLongTap(),this.x2=s,this.y2=n,i>1&&e.preventDefault()}}end(e){if(e.changedTouches){this._cancelLongTap();var t=this;e.touches.length<2&&(this.multipointEnd.dispatch(e,this.element),this.sx2=this.sy2=null),this.x2&&Math.abs(this.x1-this.x2)>30||this.y2&&Math.abs(this.y1-this.y2)>30?(e.direction=this._swipeDirection(this.x1,this.x2,this.y1,this.y2),this.swipeTimeout=setTimeout(function(){t.swipe.dispatch(e,t.element)},0)):(this.tapTimeout=setTimeout(function(){t._preventTap||t.tap.dispatch(e,t.element),t.isDoubleTap&&(t.doubleTap.dispatch(e,t.element),t.isDoubleTap=!1)},0),t.isDoubleTap||(t.singleTapTimeout=setTimeout(function(){t.singleTap.dispatch(e,t.element)},250))),this.touchEnd.dispatch(e,this.element),this.preV.x=0,this.preV.y=0,this.zoom=1,this.pinchStartLen=null,this.x1=this.x2=this.y1=this.y2=null}}cancelAll(){this._preventTap=!0,clearTimeout(this.singleTapTimeout),clearTimeout(this.tapTimeout),clearTimeout(this.longTapTimeout),clearTimeout(this.swipeTimeout)}cancel(e){this.cancelAll(),this.touchCancel.dispatch(e,this.element)}_cancelLongTap(){clearTimeout(this.longTapTimeout)}_cancelSingleTap(){clearTimeout(this.singleTapTimeout)}_swipeDirection(e,t,i,s){return Math.abs(e-t)>=Math.abs(i-s)?e-t>0?"Left":"Right":i-s>0?"Up":"Down"}on(e,t){this[e]&&this[e].add(t)}off(e,t){this[e]&&this[e].del(t)}destroy(){return this.singleTapTimeout&&clearTimeout(this.singleTapTimeout),this.tapTimeout&&clearTimeout(this.tapTimeout),this.longTapTimeout&&clearTimeout(this.longTapTimeout),this.swipeTimeout&&clearTimeout(this.swipeTimeout),this.element.removeEventListener("touchstart",this.start),this.element.removeEventListener("touchmove",this.move),this.element.removeEventListener("touchend",this.end),this.element.removeEventListener("touchcancel",this.cancel),this.rotate.del(),this.touchStart.del(),this.multipointStart.del(),this.multipointEnd.del(),this.pinch.del(),this.swipe.del(),this.tap.del(),this.doubleTap.del(),this.longTap.del(),this.singleTap.del(),this.pressMove.del(),this.twoFingerPressMove.del(),this.touchMove.del(),this.touchEnd.del(),this.touchCancel.del(),this.preV=this.pinchStartLen=this.zoom=this.isDoubleTap=this.delta=this.last=this.now=this.tapTimeout=this.singleTapTimeout=this.longTapTimeout=this.swipeTimeout=this.x1=this.x2=this.y1=this.y2=this.preTapPosition=this.rotate=this.touchStart=this.multipointStart=this.multipointEnd=this.pinch=this.swipe=this.tap=this.doubleTap=this.longTap=this.singleTap=this.pressMove=this.touchMove=this.touchEnd=this.touchCancel=this.twoFingerPressMove=null,window.removeEventListener("scroll",this._cancelAllHandler),null}}function at(c){const e=vi(),t=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth;let i=ee(c,"gslide-media")?c:c.querySelector(".gslide-media"),s=ce(i,".ginner-container"),n=c.querySelector(".gslide-description");t>769&&(i=s),H(i,"greset"),ze(i,"translate3d(0, 0, 0)"),oe(e,{onElement:i,once:!0,withCallback:(r,o)=>{J(i,"greset")}}),i.style.opacity="",n&&(n.style.opacity="")}function Ri(c){if(c.events.hasOwnProperty("touch"))return!1;let e=qt(),t=e.width,i=e.height,s=!1,n=null,r=null,o=null,a=!1,d=1,u=4.5,l=1,h=!1,p=!1,b=null,w=null,_=null,g=null,v,f,m=0,y=0,k=!1,x=!1,S={},E={},C=0,A=0,L;const D=document.getElementById("glightbox-slider"),I=document.querySelector(".goverlay"),O=new Li(D,{touchStart:R=>{if(s=!0,(ee(R.targetTouches[0].target,"ginner-container")||ce(R.targetTouches[0].target,".gslide-desc")||R.targetTouches[0].target.nodeName.toLowerCase()=="a")&&(s=!1),ce(R.targetTouches[0].target,".gslide-inline")&&!ee(R.targetTouches[0].target.parentNode,"gslide-inline")&&(s=!1),s){if(E=R.targetTouches[0],S.pageX=R.targetTouches[0].pageX,S.pageY=R.targetTouches[0].pageY,C=R.targetTouches[0].clientX,A=R.targetTouches[0].clientY,n=c.activeSlide,r=n.querySelector(".gslide-media"),L=n.querySelector(".gslide-inline"),o=null,ee(r,"gslide-image")&&(o=r.querySelector("img")),(window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth)>769&&(r=n.querySelector(".ginner-container")),J(I,"greset"),R.pageX>20&&R.pageX<window.innerWidth-20)return;R.preventDefault()}},touchMove:R=>{if(!s||(E=R.targetTouches[0],h||p))return;if(L&&L.offsetHeight>i){const U=S.pageX-E.pageX;if(Math.abs(U)<=13)return!1}a=!0;let q=R.targetTouches[0].clientX,M=R.targetTouches[0].clientY,T=C-q,$=A-M;Math.abs(T)>Math.abs($)?(k=!1,x=!0):(x=!1,k=!0),v=E.pageX-S.pageX,m=v*100/t,f=E.pageY-S.pageY,y=f*100/i;let N;if(k&&o&&(N=1-Math.abs(f)/i,I.style.opacity=N,c.settings.touchFollowAxis&&(m=0)),x&&(N=1-Math.abs(v)/t,r.style.opacity=N,c.settings.touchFollowAxis&&(y=0)),!o)return ze(r,`translate3d(${m}%, 0, 0)`);ze(r,`translate3d(${m}%, ${y}%, 0)`)},touchEnd:()=>{if(!s)return;if(a=!1,p||h){_=b,g=w;return}const R=Math.abs(parseInt(y)),q=Math.abs(parseInt(m));if(R>29&&o){c.close();return}if(R<29&&q<25)return H(I,"greset"),I.style.opacity=1,at(r)},multipointEnd:()=>{setTimeout(()=>{h=!1},50)},multipointStart:()=>{h=!0,d=l||1},pinch:R=>{if(!o||a)return!1;h=!0,o.scaleX=o.scaleY=d*R.zoom;let q=d*R.zoom;if(p=!0,q<=1){p=!1,q=1,g=null,_=null,b=null,w=null,o.setAttribute("style","");return}q>u&&(q=u),o.style.transform=`scale3d(${q}, ${q}, 1)`,l=q},pressMove:R=>{if(p&&!h){var q=E.pageX-S.pageX,M=E.pageY-S.pageY;_&&(q=q+_),g&&(M=M+g),b=q,w=M;let T=`translate3d(${q}px, ${M}px, 0)`;l&&(T+=` scale3d(${l}, ${l}, 1)`),ze(o,T)}},swipe:R=>{if(!p){if(h){h=!1;return}if(R.direction=="Left"){if(c.index==c.elements.length-1)return at(r);c.nextSlide()}if(R.direction=="Right"){if(c.index==0)return at(r);c.prevSlide()}}}});c.events.touch=O}class Mi{constructor(e,t,i=null){if(this.img=e,this.slide=t,this.onclose=i,this.img.setZoomEvents)return!1;this.active=!1,this.zoomedIn=!1,this.dragging=!1,this.currentX=null,this.currentY=null,this.initialX=null,this.initialY=null,this.xOffset=0,this.yOffset=0,this.img.addEventListener("mousedown",s=>this.dragStart(s),!1),this.img.addEventListener("mouseup",s=>this.dragEnd(s),!1),this.img.addEventListener("mousemove",s=>this.drag(s),!1),this.img.addEventListener("click",s=>{if(this.slide.classList.contains("dragging-nav"))return this.zoomOut(),!1;if(!this.zoomedIn)return this.zoomIn();this.zoomedIn&&!this.dragging&&this.zoomOut()},!1),this.img.setZoomEvents=!0}zoomIn(){let e=this.widowWidth();if(this.zoomedIn||e<=768)return;const t=this.img;if(t.setAttribute("data-style",t.getAttribute("style")),t.style.maxWidth=t.naturalWidth+"px",t.style.maxHeight=t.naturalHeight+"px",t.naturalWidth>e){let i=e/2-t.naturalWidth/2;this.setTranslate(this.img.parentNode,i,0)}this.slide.classList.add("zoomed"),this.zoomedIn=!0}zoomOut(){this.img.parentNode.setAttribute("style",""),this.img.setAttribute("style",this.img.getAttribute("data-style")),this.slide.classList.remove("zoomed"),this.zoomedIn=!1,this.currentX=null,this.currentY=null,this.initialX=null,this.initialY=null,this.xOffset=0,this.yOffset=0,this.onclose&&typeof this.onclose=="function"&&this.onclose()}dragStart(e){if(e.preventDefault(),!this.zoomedIn){this.active=!1;return}e.type==="touchstart"?(this.initialX=e.touches[0].clientX-this.xOffset,this.initialY=e.touches[0].clientY-this.yOffset):(this.initialX=e.clientX-this.xOffset,this.initialY=e.clientY-this.yOffset),e.target===this.img&&(this.active=!0,this.img.classList.add("dragging"))}dragEnd(e){e.preventDefault(),this.initialX=this.currentX,this.initialY=this.currentY,this.active=!1,setTimeout(()=>{this.dragging=!1,this.img.isDragging=!1,this.img.classList.remove("dragging")},100)}drag(e){this.active&&(e.preventDefault(),e.type==="touchmove"?(this.currentX=e.touches[0].clientX-this.initialX,this.currentY=e.touches[0].clientY-this.initialY):(this.currentX=e.clientX-this.initialX,this.currentY=e.clientY-this.initialY),this.xOffset=this.currentX,this.yOffset=this.currentY,this.img.isDragging=!0,this.dragging=!0,this.setTranslate(this.img,this.currentX,this.currentY))}onMove(e){if(!this.zoomedIn)return;let t=e.clientX-this.img.naturalWidth/2,i=e.clientY-this.img.naturalHeight/2;this.setTranslate(this.img,t,i)}setTranslate(e,t,i){e.style.transform="translate3d("+t+"px, "+i+"px, 0)"}widowWidth(){return window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth}}class Dt{constructor(e={}){let{dragEl:t,toleranceX:i=40,toleranceY:s=65,slide:n=null,instance:r=null}=e;this.el=t,this.active=!1,this.dragging=!1,this.currentX=null,this.currentY=null,this.initialX=null,this.initialY=null,this.xOffset=0,this.yOffset=0,this.direction=null,this.lastDirection=null,this.toleranceX=i,this.toleranceY=s,this.toleranceReached=!1,this.dragContainer=this.el,this.slide=n,this.instance=r,this.el.addEventListener("mousedown",o=>this.dragStart(o),!1),this.el.addEventListener("mouseup",o=>this.dragEnd(o),!1),this.el.addEventListener("mousemove",o=>this.drag(o),!1)}dragStart(e){if(this.slide.classList.contains("zoomed")){this.active=!1;return}e.type==="touchstart"?(this.initialX=e.touches[0].clientX-this.xOffset,this.initialY=e.touches[0].clientY-this.yOffset):(this.initialX=e.clientX-this.xOffset,this.initialY=e.clientY-this.yOffset);let t=e.target.nodeName.toLowerCase(),i=["input","select","textarea","button","a"];if(e.target.classList.contains("nodrag")||ce(e.target,".nodrag")||i.indexOf(t)!==-1){this.active=!1;return}e.preventDefault(),(e.target===this.el||t!=="img"&&ce(e.target,".gslide-inline"))&&(this.active=!0,this.el.classList.add("dragging"),this.dragContainer=ce(e.target,".ginner-container"))}dragEnd(e){e&&e.preventDefault(),this.initialX=0,this.initialY=0,this.currentX=null,this.currentY=null,this.initialX=null,this.initialY=null,this.xOffset=0,this.yOffset=0,this.active=!1,this.doSlideChange&&(this.instance.preventOutsideClick=!0,this.doSlideChange=="right"&&this.instance.prevSlide(),this.doSlideChange=="left"&&this.instance.nextSlide()),this.doSlideClose&&this.instance.close(),this.toleranceReached||this.setTranslate(this.dragContainer,0,0,!0),setTimeout(()=>{this.instance.preventOutsideClick=!1,this.toleranceReached=!1,this.lastDirection=null,this.dragging=!1,this.el.isDragging=!1,this.el.classList.remove("dragging"),this.slide.classList.remove("dragging-nav"),this.dragContainer.style.transform="",this.dragContainer.style.transition=""},100)}drag(e){if(this.active){e.preventDefault(),this.slide.classList.add("dragging-nav"),e.type==="touchmove"?(this.currentX=e.touches[0].clientX-this.initialX,this.currentY=e.touches[0].clientY-this.initialY):(this.currentX=e.clientX-this.initialX,this.currentY=e.clientY-this.initialY),this.xOffset=this.currentX,this.yOffset=this.currentY,this.el.isDragging=!0,this.dragging=!0,this.doSlideChange=!1,this.doSlideClose=!1;let t=Math.abs(this.currentX),i=Math.abs(this.currentY);if(t>0&&t>=Math.abs(this.currentY)&&(!this.lastDirection||this.lastDirection=="x")){this.yOffset=0,this.lastDirection="x",this.setTranslate(this.dragContainer,this.currentX,0);let s=this.shouldChange();if(!this.instance.settings.dragAutoSnap&&s&&(this.doSlideChange=s),this.instance.settings.dragAutoSnap&&s){this.instance.preventOutsideClick=!0,this.toleranceReached=!0,this.active=!1,this.instance.preventOutsideClick=!0,this.dragEnd(null),s=="right"&&this.instance.prevSlide(),s=="left"&&this.instance.nextSlide();return}}if(this.toleranceY>0&&i>0&&i>=t&&(!this.lastDirection||this.lastDirection=="y")){this.xOffset=0,this.lastDirection="y",this.setTranslate(this.dragContainer,0,this.currentY);let s=this.shouldClose();!this.instance.settings.dragAutoSnap&&s&&(this.doSlideClose=!0),this.instance.settings.dragAutoSnap&&s&&this.instance.close();return}}}shouldChange(){let e=!1;if(Math.abs(this.currentX)>=this.toleranceX){let i=this.currentX>0?"right":"left";(i=="left"&&this.slide!==this.slide.parentNode.lastChild||i=="right"&&this.slide!==this.slide.parentNode.firstChild)&&(e=i)}return e}shouldClose(){let e=!1;return Math.abs(this.currentY)>=this.toleranceY&&(e=!0),e}setTranslate(e,t,i,s=!1){s?e.style.transition="all .2s ease":e.style.transition="",e.style.transform=`translate3d(${t}px, ${i}px, 0)`}}function Ai(c,e,t,i){const s=c.querySelector(".gslide-media");let n=new Image,r="gSlideTitle_"+t,o="gSlideDesc_"+t;n.addEventListener("load",()=>{F(i)&&i()},!1),n.src=e.href,e.sizes!=""&&e.srcset!=""&&(n.sizes=e.sizes,n.srcset=e.srcset),n.alt="",!ne(e.alt)&&e.alt!==""&&(n.alt=e.alt),e.title!==""&&n.setAttribute("aria-labelledby",r),e.description!==""&&n.setAttribute("aria-describedby",o),e.hasOwnProperty("_hasCustomWidth")&&e._hasCustomWidth&&(n.style.width=e.width),e.hasOwnProperty("_hasCustomHeight")&&e._hasCustomHeight&&(n.style.height=e.height),s.insertBefore(n,s.firstChild)}function qi(c,e,t,i){const s=c.querySelector(".ginner-container"),n="gvideo"+t,r=c.querySelector(".gslide-media"),o=this.getAllPlayers();H(s,"gvideo-container"),r.insertBefore(xe('<div class="gvideo-wrapper"></div>'),r.firstChild);const a=c.querySelector(".gvideo-wrapper");Pt(this.settings.plyr.css,"Plyr");let d=e.href,u=e?.videoProvider,l=!1;r.style.maxWidth=e.width,Pt(this.settings.plyr.js,"Plyr",()=>{if(!u&&d.match(/vimeo\.com\/([0-9]*)/)&&(u="vimeo"),!u&&(d.match(/(youtube\.com|youtube-nocookie\.com)\/watch\?v=([a-zA-Z0-9\-_]+)/)||d.match(/youtu\.be\/([a-zA-Z0-9\-_]+)/)||d.match(/(youtube\.com|youtube-nocookie\.com)\/embed\/([a-zA-Z0-9\-_]+)/))&&(u="youtube"),u==="local"||!u){u="local";let w='<video id="'+n+'" ';w+=`style="background:#000; max-width: ${e.width};" `,w+='preload="metadata" ',w+='x-webkit-airplay="allow" ',w+="playsinline ",w+="controls ",w+='class="gvideo-local">',w+=`<source src="${d}">`,w+="</video>",l=xe(w)}const h=l||xe(`<div id="${n}" data-plyr-provider="${u}" data-plyr-embed-id="${d}"></div>`);H(a,`${u}-video gvideo`),a.appendChild(h),a.setAttribute("data-id",n),a.setAttribute("data-index",t);const p=Z(this.settings.plyr,"config")?this.settings.plyr.config:{},b=new Plyr("#"+n,p);b.on("ready",w=>{o[n]=w.detail.plyr,F(i)&&i()}),ot(()=>c.querySelector("iframe")&&c.querySelector("iframe").dataset.ready=="true",()=>{this.resize(c)}),b.on("enterfullscreen",Ht),b.on("exitfullscreen",Ht)})}function Ht(c){const e=ce(c.target,".gslide-media");c.type==="enterfullscreen"&&H(e,"fullscreen"),c.type==="exitfullscreen"&&J(e,"fullscreen")}function Pi(c,e,t,i){const s=c.querySelector(".gslide-media"),n=Z(e,"href")&&e.href?e.href.split("#").pop().trim():!1,r=Z(e,"content")&&e.content?e.content:!1;let o;if(r&&(Ae(r)&&(o=xe(`<div class="ginlined-content">${r}</div>`)),ge(r))){r.style.display=="none"&&(r.style.display="block");const a=document.createElement("div");a.className="ginlined-content",a.appendChild(r),o=a}if(n){let a=document.getElementById(n);if(!a)return!1;const d=a.cloneNode(!0);d.style.height=e.height,d.style.maxWidth=e.width,H(d,"ginlined-content"),o=d}if(!o)return console.error("Unable to append inline slide content",e),!1;s.style.height=e.height,s.style.width=e.width,s.appendChild(o),this.events["inlineclose"+n]=oe("click",{onElement:s.querySelectorAll(".gtrigger-close"),withCallback:a=>{a.preventDefault(),this.close()}}),F(i)&&i()}function Ii(c,e,t,i){const s=c.querySelector(".gslide-media"),n=wi({url:e.href,callback:i});s.parentNode.style.maxWidth=e.width,s.parentNode.style.height=e.height,s.appendChild(n)}class Oi{constructor(e={}){this.defaults={href:"",sizes:"",srcset:"",title:"",type:"",videoProvider:"",description:"",alt:"",descPosition:"bottom",effect:"",width:"",height:"",content:!1,zoomable:!0,draggable:!0},Ce(e)&&(this.defaults=fe(this.defaults,e))}sourceType(e){let t=e;return e=e.toLowerCase(),e.match(/\.(jpeg|jpg|jpe|gif|png|apn|webp|avif|svg)/)!==null?"image":e.match(/(youtube\.com|youtube-nocookie\.com)\/watch\?v=([a-zA-Z0-9\-_]+)/)||e.match(/youtu\.be\/([a-zA-Z0-9\-_]+)/)||e.match(/(youtube\.com|youtube-nocookie\.com)\/embed\/([a-zA-Z0-9\-_]+)/)||e.match(/vimeo\.com\/([0-9]*)/)||e.match(/\.(mp4|ogg|webm|mov)/)!==null?"video":e.match(/\.(mp3|wav|wma|aac|ogg)/)!==null?"audio":e.indexOf("#")>-1&&t.split("#").pop().trim()!==""?"inline":e.indexOf("goajax=true")>-1?"ajax":"external"}parseConfig(e,t){let i=fe({descPosition:t.descPosition},this.defaults);if(Ce(e)&&!ge(e)){Z(e,"type")||(Z(e,"content")&&e.content?e.type="inline":Z(e,"href")&&(e.type=this.sourceType(e.href)));let o=fe(i,e);return this.setSize(o,t),o}let s="",n=e.getAttribute("data-glightbox"),r=e.nodeName.toLowerCase();if(r==="a"&&(s=e.href),r==="img"&&(s=e.src,i.alt=e.alt),i.href=s,V(i,(o,a)=>{Z(t,a)&&a!=="width"&&(i[a]=t[a]);const d=e.dataset[a];ne(d)||(i[a]=this.sanitizeValue(d))}),i.content&&(i.type="inline"),!i.type&&s&&(i.type=this.sourceType(s)),ne(n)){if(!i.title&&r=="a"){let o=e.title;!ne(o)&&o!==""&&(i.title=o)}if(!i.title&&r=="img"){let o=e.alt;!ne(o)&&o!==""&&(i.title=o)}}else{let o=[];V(i,(a,d)=>{o.push(";\\s?"+d)}),o=o.join("\\s?:|"),n.trim()!==""&&V(i,(a,d)=>{const u=n,l="s?"+d+"s?:s?(.*?)("+o+"s?:|$)",h=new RegExp(l),p=u.match(h);if(p&&p.length&&p[1]){const b=p[1].trim().replace(/;\s*$/,"");i[d]=this.sanitizeValue(b)}})}if(i.description&&i.description.substring(0,1)==="."){let o;try{o=document.querySelector(i.description).innerHTML}catch(a){if(!(a instanceof DOMException))throw a}o&&(i.description=o)}if(!i.description){let o=e.querySelector(".glightbox-desc");o&&(i.description=o.innerHTML)}return this.setSize(i,t,e),this.slideConfig=i,i}setSize(e,t,i=null){const s=e.type=="video"?this.checkSize(t.videosWidth):this.checkSize(t.width),n=this.checkSize(t.height);return e.width=Z(e,"width")&&e.width!==""?this.checkSize(e.width):s,e.height=Z(e,"height")&&e.height!==""?this.checkSize(e.height):n,i&&e.type=="image"&&(e._hasCustomWidth=!!i.dataset.width,e._hasCustomHeight=!!i.dataset.height),e}checkSize(e){return Ue(e)?`${e}px`:e}sanitizeValue(e){return e!=="true"&&e!=="false"?e:e==="true"}}class Be{constructor(e,t,i){this.element=e,this.instance=t,this.index=i}setContent(e=null,t=!1){if(ee(e,"loaded"))return!1;const i=this.instance.settings,s=this.slideConfig,n=lt();F(i.beforeSlideLoad)&&i.beforeSlideLoad({index:this.index,slide:e,player:!1});let r=s.type,o=s.descPosition,a=e.querySelector(".gslide-media"),d=e.querySelector(".gslide-title"),u=e.querySelector(".gslide-desc"),l=e.querySelector(".gdesc-inner"),h=t,p="gSlideTitle_"+this.index,b="gSlideDesc_"+this.index;if(F(i.afterSlideLoad)&&(h=()=>{F(t)&&t(),i.afterSlideLoad({index:this.index,slide:e,player:this.instance.getSlidePlayerInstance(this.index)})}),s.title==""&&s.description==""?l&&l.parentNode.parentNode.removeChild(l.parentNode):(d&&s.title!==""?(d.id=p,d.innerHTML=s.title):d.parentNode.removeChild(d),u&&s.description!==""?(u.id=b,n&&i.moreLength>0?(s.smallDescription=this.slideShortDesc(s.description,i.moreLength,i.moreText),u.innerHTML=s.smallDescription,this.descriptionEvents(u,s)):u.innerHTML=s.description):u.parentNode.removeChild(u),H(a.parentNode,`desc-${o}`),H(l.parentNode,`description-${o}`)),H(a,`gslide-${r}`),H(e,"loaded"),r==="video"){qi.apply(this.instance,[e,s,this.index,h]);return}if(r==="external"){Ii.apply(this,[e,s,this.index,h]);return}if(r==="inline"){Pi.apply(this.instance,[e,s,this.index,h]),s.draggable&&new Dt({dragEl:e.querySelector(".gslide-inline"),toleranceX:i.dragToleranceX,toleranceY:i.dragToleranceY,slide:e,instance:this.instance});return}if(r==="image"){Ai(e,s,this.index,()=>{const w=e.querySelector("img");s.draggable&&new Dt({dragEl:w,toleranceX:i.dragToleranceX,toleranceY:i.dragToleranceY,slide:e,instance:this.instance}),s.zoomable&&w.naturalWidth>w.offsetWidth&&(H(w,"zoomable"),new Mi(w,e,()=>{this.instance.resize()})),F(h)&&h()});return}F(h)&&h()}slideShortDesc(e,t=50,i=!1){let s=document.createElement("div");s.innerHTML=e;let n=s.innerText,r=i;if(e=n.trim(),e.length<=t)return e;let o=e.substr(0,t-1);return r?(s=null,o+'... <a href="#" class="desc-more">'+i+"</a>"):o}descriptionEvents(e,t){let i=e.querySelector(".desc-more");if(!i)return!1;oe("click",{onElement:i,withCallback:(s,n)=>{s.preventDefault();const r=document.body;let o=ce(n,".gslide-desc");if(!o)return!1;o.innerHTML=t.description,H(r,"gdesc-open");let a=oe("click",{onElement:[r,ce(o,".gslide-description")],withCallback:(d,u)=>{d.target.nodeName.toLowerCase()!=="a"&&(J(r,"gdesc-open"),H(r,"gdesc-closed"),o.innerHTML=t.smallDescription,this.descriptionEvents(o,t),setTimeout(()=>{J(r,"gdesc-closed")},400),a.destroy())}})}})}create(){return xe(this.instance.settings.slideHTML)}getConfig(){!ge(this.element)&&!this.element.hasOwnProperty("draggable")&&(this.element.draggable=this.instance.settings.draggable);const e=new Oi(this.instance.settings.slideExtraAttributes);return this.slideConfig=e.parseConfig(this.element,this.instance.settings),this.slideConfig}}const $i="3.2.0",zt=lt(),Ut=xi();let ct;typeof document>"u"||(ct=document.getElementsByTagName("html")[0]);const ut={selector:".glightbox",elements:null,skin:"clean",theme:"clean",closeButton:!0,startAt:null,autoplayVideos:!0,autofocusVideos:!0,descPosition:"bottom",width:"900px",height:"506px",videosWidth:"960px",beforeSlideChange:null,afterSlideChange:null,beforeSlideLoad:null,afterSlideLoad:null,slideInserted:null,slideRemoved:null,slideExtraAttributes:null,onOpen:null,onClose:null,loop:!1,zoomable:!0,draggable:!0,dragAutoSnap:!1,dragToleranceX:40,dragToleranceY:65,preload:!0,oneSlidePerOpen:!1,touchNavigation:!0,touchFollowAxis:!0,keyboardNavigation:!0,closeOnOutsideClick:!0,plugins:!1,plyr:{css:"https://cdn.plyr.io/3.6.12/plyr.css",js:"https://cdn.plyr.io/3.6.12/plyr.js",config:{ratio:"16:9",fullscreen:{enabled:!0,iosNative:!0},youtube:{noCookie:!0,rel:0,showinfo:0,iv_load_policy:3},vimeo:{byline:!1,portrait:!1,title:!1,transparent:!1}}},openEffect:"zoom",closeEffect:"zoom",slideEffect:"slide",moreText:"See more",moreLength:60,cssEfects:{fade:{in:"fadeIn",out:"fadeOut"},zoom:{in:"zoomIn",out:"zoomOut"},slide:{in:"slideInRight",out:"slideOutLeft"},slideBack:{in:"slideInLeft",out:"slideOutRight"},none:{in:"none",out:"none"}},svg:{close:'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 512 512" xml:space="preserve"><g><g><path d="M505.943,6.058c-8.077-8.077-21.172-8.077-29.249,0L6.058,476.693c-8.077,8.077-8.077,21.172,0,29.249C10.096,509.982,15.39,512,20.683,512c5.293,0,10.586-2.019,14.625-6.059L505.943,35.306C514.019,27.23,514.019,14.135,505.943,6.058z"/></g></g><g><g><path d="M505.942,476.694L35.306,6.059c-8.076-8.077-21.172-8.077-29.248,0c-8.077,8.076-8.077,21.171,0,29.248l470.636,470.636c4.038,4.039,9.332,6.058,14.625,6.058c5.293,0,10.587-2.019,14.624-6.057C514.018,497.866,514.018,484.771,505.942,476.694z"/></g></g></svg>',next:'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 477.175 477.175" xml:space="preserve"> <g><path d="M360.731,229.075l-225.1-225.1c-5.3-5.3-13.8-5.3-19.1,0s-5.3,13.8,0,19.1l215.5,215.5l-215.5,215.5c-5.3,5.3-5.3,13.8,0,19.1c2.6,2.6,6.1,4,9.5,4c3.4,0,6.9-1.3,9.5-4l225.1-225.1C365.931,242.875,365.931,234.275,360.731,229.075z"/></g></svg>',prev:'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 477.175 477.175" xml:space="preserve"><g><path d="M145.188,238.575l215.5-215.5c5.3-5.3,5.3-13.8,0-19.1s-13.8-5.3-19.1,0l-225.1,225.1c-5.3,5.3-5.3,13.8,0,19.1l225.1,225c2.6,2.6,6.1,4,9.5,4s6.9-1.3,9.5-4c5.3-5.3,5.3-13.8,0-19.1L145.188,238.575z"/></g></svg>'}};ut.slideHTML=`<div class="gslide">
1
+ var ContentBuilderRuntime=(function(){"use strict";const Rt=Date.now();function fe(){let c={},e=!0,t=0,i=arguments.length;Object.prototype.toString.call(arguments[0])==="[object Boolean]"&&(e=arguments[0],t++);let s=n=>{for(let r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e&&Object.prototype.toString.call(n[r])==="[object Object]"?c[r]=fe(!0,c[r],n[r]):c[r]=n[r])};for(;t<i;t++){let n=arguments[t];s(n)}return c}function V(c,e){if((ge(c)||c===window||c===document)&&(c=[c]),!Ot(c)&&!Ce(c)&&(c=[c]),$t(c)!=0){if(Ot(c)&&!Ce(c)){let t=c.length,i=0;for(;i<t&&e.call(c[i],c[i],i,c)!==!1;i++);}else if(Ce(c)){for(let t in c)if(Z(c,t)&&e.call(c[t],c[t],t,c)===!1)break}}}function Mt(c,e=null,t=null){const i=c[Rt]=c[Rt]||[],s={all:i,evt:null,found:null};return e&&t&&$t(i)>0&&V(i,(n,r)=>{if(n.eventName==e&&n.fn.toString()==t.toString())return s.found=!0,s.evt=r,!1}),s}function oe(c,{onElement:e,withCallback:t,avoidDuplicate:i=!0,once:s=!1,useCapture:n=!1}={},r){let o=e||[];Ae(o)&&(o=document.querySelectorAll(o));function a(d){F(t)&&t.call(r,d,this),s&&a.destroy()}return a.destroy=function(){V(o,d=>{const u=Mt(d,c,a);u.found&&u.all.splice(u.evt,1),d.removeEventListener&&d.removeEventListener(c,a,n)})},V(o,d=>{const u=Mt(d,c,a);(d.addEventListener&&i&&!u.found||!i)&&(d.addEventListener(c,a,n),u.all.push({eventName:c,fn:a}))}),a}function H(c,e){V(e.split(" "),t=>c.classList.add(t))}function J(c,e){V(e.split(" "),t=>c.classList.remove(t))}function ee(c,e){return c.classList.contains(e)}function ce(c,e){for(;c!==document.body;){if(c=c.parentElement,!c)return!1;if(typeof c.matches=="function"?c.matches(e):c.msMatchesSelector(e))return c}}function Ee(c,e="",t=!1){if(!c||e==="")return!1;if(e==="none")return F(t)&&t(),!1;const i=yi(),s=e.split(" ");V(s,n=>{H(c,"g"+n)}),oe(i,{onElement:c,avoidDuplicate:!1,once:!0,withCallback:(n,r)=>{V(s,o=>{J(r,"g"+o)}),F(t)&&t()}})}function ze(c,e=""){if(e==="")return c.style.webkitTransform="",c.style.MozTransform="",c.style.msTransform="",c.style.OTransform="",c.style.transform="",!1;c.style.webkitTransform=e,c.style.MozTransform=e,c.style.msTransform=e,c.style.OTransform=e,c.style.transform=e}function At(c){c.style.display="block"}function rt(c){c.style.display="none"}function xe(c){let e=document.createDocumentFragment(),t=document.createElement("div");for(t.innerHTML=c;t.firstChild;)e.appendChild(t.firstChild);return e}function qt(){return{width:window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,height:window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight}}function yi(){let c,e=document.createElement("fakeelement"),t={animation:"animationend",OAnimation:"oAnimationEnd",MozAnimation:"animationend",WebkitAnimation:"webkitAnimationEnd"};for(c in t)if(e.style[c]!==void 0)return t[c]}function vi(){let c,e=document.createElement("fakeelement");const t={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(c in t)if(e.style[c]!==void 0)return t[c]}function wi(c){let{url:e,allow:t,callback:i,appendTo:s}=c,n=document.createElement("iframe");return n.className="vimeo-video gvideo",n.src=e,n.style.width="100%",n.style.height="100%",t&&n.setAttribute("allow",t),n.onload=function(){n.onload=null,H(n,"node-ready"),F(i)&&i()},s&&s.appendChild(n),n}function ot(c,e,t,i){if(c()){e();return}t||(t=100);let s=setInterval(()=>{c()&&(clearInterval(s),e())},t)}function Pt(c,e,t){if(ne(c)){console.error("Inject assets error");return}if(F(e)&&(t=e,e=!1),Ae(e)&&e in window){F(t)&&t();return}let i;if(c.indexOf(".css")!==-1){if(i=document.querySelectorAll('link[href="'+c+'"]'),i&&i.length>0){F(t)&&t();return}const n=document.getElementsByTagName("head")[0],r=n.querySelectorAll('link[rel="stylesheet"]'),o=document.createElement("link");o.rel="stylesheet",o.type="text/css",o.href=c,o.media="all",r?n.insertBefore(o,r[0]):n.appendChild(o),F(t)&&t();return}if(i=document.querySelectorAll('script[src="'+c+'"]'),i&&i.length>0){if(F(t)){if(Ae(e))return ot(()=>typeof window[e]<"u",()=>{t()}),!1;t()}return}let s=document.createElement("script");s.type="text/javascript",s.src=c,s.onload=()=>{if(F(t)){if(Ae(e))return ot(()=>typeof window[e]<"u",()=>{t()}),!1;t()}},document.body.appendChild(s)}function lt(){return typeof window>"u"?!1:"navigator"in window&&window.navigator.userAgent.match(/(iPad)|(iPhone)|(iPod)|(Android)|(PlayBook)|(BB10)|(BlackBerry)|(Opera Mini)|(IEMobile)|(webOS)|(MeeGo)/i)}function xi(){return typeof document>"u"?!1:lt()!==null||document.createTouch!==void 0||"ontouchstart"in window||"onmsgesturechange"in window||navigator.msMaxTouchPoints}function F(c){return typeof c=="function"}function Ae(c){return typeof c=="string"}function ge(c){return!!(c&&c.nodeType&&c.nodeType==1)}function It(c){return Array.isArray(c)}function Ot(c){return c&&c.length&&isFinite(c.length)}function Ce(c){return typeof c==="object"&&c!=null&&!F(c)&&!It(c)}function ne(c){return c==null}function Z(c,e){return c!==null&&hasOwnProperty.call(c,e)}function $t(c){if(Ce(c)){if(c.keys)return c.keys().length;let e=0;for(let t in c)Z(c,t)&&e++;return e}else return c.length}function Ue(c){return!isNaN(parseFloat(c))&&isFinite(c)}function Nt(c=-1){const e=document.querySelectorAll(".gbtn[data-taborder]:not(.disabled)");if(!e.length)return!1;if(e.length==1)return e[0];typeof c=="string"&&(c=parseInt(c));const t=[];V(e,o=>{t.push(o.getAttribute("data-taborder"))});const i=Math.max.apply(Math,t.map(o=>parseInt(o)));let s=c<0?1:c+1;s>i&&(s="1");const r=t.filter(o=>o>=parseInt(s)).sort()[0];return document.querySelector(`.gbtn[data-taborder="${r}"]`)}function ki(c){if(c.events.hasOwnProperty("keyboard"))return!1;c.events.keyboard=oe("keydown",{onElement:window,withCallback:(e,t)=>{e=e||window.event;const i=e.keyCode;if(i==9){const s=document.querySelector(".gbtn.focused");if(!s){const a=document.activeElement&&document.activeElement.nodeName?document.activeElement.nodeName.toLocaleLowerCase():!1;if(a=="input"||a=="textarea"||a=="button")return}e.preventDefault();const n=document.querySelectorAll(".gbtn[data-taborder]");if(!n||n.length<=0)return;if(!s){const a=Nt();a&&(a.focus(),H(a,"focused"));return}let r=s.getAttribute("data-taborder"),o=Nt(r);J(s,"focused"),o&&(o.focus(),H(o,"focused"))}i==39&&c.nextSlide(),i==37&&c.prevSlide(),i==27&&c.close()}})}function je(c){return Math.sqrt(c.x*c.x+c.y*c.y)}function _i(c,e){return c.x*e.x+c.y*e.y}function Si(c,e){var t=je(c)*je(e);if(t===0)return 0;var i=_i(c,e)/t;return i>1&&(i=1),Math.acos(i)}function Ti(c,e){return c.x*e.y-e.x*c.y}function Ei(c,e){var t=Si(c,e);return Ti(c,e)>0&&(t*=-1),t*180/Math.PI}class Ci{constructor(e){this.handlers=[],this.el=e}add(e){this.handlers.push(e)}del(e){e||(this.handlers=[]);for(var t=this.handlers.length;t>=0;t--)this.handlers[t]===e&&this.handlers.splice(t,1)}dispatch(){for(var e=0,t=this.handlers.length;e<t;e++){var i=this.handlers[e];typeof i=="function"&&i.apply(this.el,arguments)}}}function te(c,e){var t=new Ci(c);return t.add(e),t}class Li{constructor(e,t){this.element=typeof e=="string"?document.querySelector(e):e,this.start=this.start.bind(this),this.move=this.move.bind(this),this.end=this.end.bind(this),this.cancel=this.cancel.bind(this),this.element.addEventListener("touchstart",this.start,!1),this.element.addEventListener("touchmove",this.move,!1),this.element.addEventListener("touchend",this.end,!1),this.element.addEventListener("touchcancel",this.cancel,!1),this.preV={x:null,y:null},this.pinchStartLen=null,this.zoom=1,this.isDoubleTap=!1;var i=function(){};this.rotate=te(this.element,t.rotate||i),this.touchStart=te(this.element,t.touchStart||i),this.multipointStart=te(this.element,t.multipointStart||i),this.multipointEnd=te(this.element,t.multipointEnd||i),this.pinch=te(this.element,t.pinch||i),this.swipe=te(this.element,t.swipe||i),this.tap=te(this.element,t.tap||i),this.doubleTap=te(this.element,t.doubleTap||i),this.longTap=te(this.element,t.longTap||i),this.singleTap=te(this.element,t.singleTap||i),this.pressMove=te(this.element,t.pressMove||i),this.twoFingerPressMove=te(this.element,t.twoFingerPressMove||i),this.touchMove=te(this.element,t.touchMove||i),this.touchEnd=te(this.element,t.touchEnd||i),this.touchCancel=te(this.element,t.touchCancel||i),this.translateContainer=this.element,this._cancelAllHandler=this.cancelAll.bind(this),window.addEventListener("scroll",this._cancelAllHandler),this.delta=null,this.last=null,this.now=null,this.tapTimeout=null,this.singleTapTimeout=null,this.longTapTimeout=null,this.swipeTimeout=null,this.x1=this.x2=this.y1=this.y2=null,this.preTapPosition={x:null,y:null}}start(e){if(!e.touches)return;const t=["a","button","input"];if(e.target&&e.target.nodeName&&t.indexOf(e.target.nodeName.toLowerCase())>=0){console.log("ignore drag for this touched element",e.target.nodeName.toLowerCase());return}this.now=Date.now(),this.x1=e.touches[0].pageX,this.y1=e.touches[0].pageY,this.delta=this.now-(this.last||this.now),this.touchStart.dispatch(e,this.element),this.preTapPosition.x!==null&&(this.isDoubleTap=this.delta>0&&this.delta<=250&&Math.abs(this.preTapPosition.x-this.x1)<30&&Math.abs(this.preTapPosition.y-this.y1)<30,this.isDoubleTap&&clearTimeout(this.singleTapTimeout)),this.preTapPosition.x=this.x1,this.preTapPosition.y=this.y1,this.last=this.now;var i=this.preV,s=e.touches.length;if(s>1){this._cancelLongTap(),this._cancelSingleTap();var n={x:e.touches[1].pageX-this.x1,y:e.touches[1].pageY-this.y1};i.x=n.x,i.y=n.y,this.pinchStartLen=je(i),this.multipointStart.dispatch(e,this.element)}this._preventTap=!1,this.longTapTimeout=setTimeout((function(){this.longTap.dispatch(e,this.element),this._preventTap=!0}).bind(this),750)}move(e){if(e.touches){var t=this.preV,i=e.touches.length,s=e.touches[0].pageX,n=e.touches[0].pageY;if(this.isDoubleTap=!1,i>1){var r=e.touches[1].pageX,o=e.touches[1].pageY,a={x:e.touches[1].pageX-s,y:e.touches[1].pageY-n};t.x!==null&&(this.pinchStartLen>0&&(e.zoom=je(a)/this.pinchStartLen,this.pinch.dispatch(e,this.element)),e.angle=Ei(a,t),this.rotate.dispatch(e,this.element)),t.x=a.x,t.y=a.y,this.x2!==null&&this.sx2!==null?(e.deltaX=(s-this.x2+r-this.sx2)/2,e.deltaY=(n-this.y2+o-this.sy2)/2):(e.deltaX=0,e.deltaY=0),this.twoFingerPressMove.dispatch(e,this.element),this.sx2=r,this.sy2=o}else{if(this.x2!==null){e.deltaX=s-this.x2,e.deltaY=n-this.y2;var d=Math.abs(this.x1-this.x2),u=Math.abs(this.y1-this.y2);(d>10||u>10)&&(this._preventTap=!0)}else e.deltaX=0,e.deltaY=0;this.pressMove.dispatch(e,this.element)}this.touchMove.dispatch(e,this.element),this._cancelLongTap(),this.x2=s,this.y2=n,i>1&&e.preventDefault()}}end(e){if(e.changedTouches){this._cancelLongTap();var t=this;e.touches.length<2&&(this.multipointEnd.dispatch(e,this.element),this.sx2=this.sy2=null),this.x2&&Math.abs(this.x1-this.x2)>30||this.y2&&Math.abs(this.y1-this.y2)>30?(e.direction=this._swipeDirection(this.x1,this.x2,this.y1,this.y2),this.swipeTimeout=setTimeout(function(){t.swipe.dispatch(e,t.element)},0)):(this.tapTimeout=setTimeout(function(){t._preventTap||t.tap.dispatch(e,t.element),t.isDoubleTap&&(t.doubleTap.dispatch(e,t.element),t.isDoubleTap=!1)},0),t.isDoubleTap||(t.singleTapTimeout=setTimeout(function(){t.singleTap.dispatch(e,t.element)},250))),this.touchEnd.dispatch(e,this.element),this.preV.x=0,this.preV.y=0,this.zoom=1,this.pinchStartLen=null,this.x1=this.x2=this.y1=this.y2=null}}cancelAll(){this._preventTap=!0,clearTimeout(this.singleTapTimeout),clearTimeout(this.tapTimeout),clearTimeout(this.longTapTimeout),clearTimeout(this.swipeTimeout)}cancel(e){this.cancelAll(),this.touchCancel.dispatch(e,this.element)}_cancelLongTap(){clearTimeout(this.longTapTimeout)}_cancelSingleTap(){clearTimeout(this.singleTapTimeout)}_swipeDirection(e,t,i,s){return Math.abs(e-t)>=Math.abs(i-s)?e-t>0?"Left":"Right":i-s>0?"Up":"Down"}on(e,t){this[e]&&this[e].add(t)}off(e,t){this[e]&&this[e].del(t)}destroy(){return this.singleTapTimeout&&clearTimeout(this.singleTapTimeout),this.tapTimeout&&clearTimeout(this.tapTimeout),this.longTapTimeout&&clearTimeout(this.longTapTimeout),this.swipeTimeout&&clearTimeout(this.swipeTimeout),this.element.removeEventListener("touchstart",this.start),this.element.removeEventListener("touchmove",this.move),this.element.removeEventListener("touchend",this.end),this.element.removeEventListener("touchcancel",this.cancel),this.rotate.del(),this.touchStart.del(),this.multipointStart.del(),this.multipointEnd.del(),this.pinch.del(),this.swipe.del(),this.tap.del(),this.doubleTap.del(),this.longTap.del(),this.singleTap.del(),this.pressMove.del(),this.twoFingerPressMove.del(),this.touchMove.del(),this.touchEnd.del(),this.touchCancel.del(),this.preV=this.pinchStartLen=this.zoom=this.isDoubleTap=this.delta=this.last=this.now=this.tapTimeout=this.singleTapTimeout=this.longTapTimeout=this.swipeTimeout=this.x1=this.x2=this.y1=this.y2=this.preTapPosition=this.rotate=this.touchStart=this.multipointStart=this.multipointEnd=this.pinch=this.swipe=this.tap=this.doubleTap=this.longTap=this.singleTap=this.pressMove=this.touchMove=this.touchEnd=this.touchCancel=this.twoFingerPressMove=null,window.removeEventListener("scroll",this._cancelAllHandler),null}}function at(c){const e=vi(),t=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth;let i=ee(c,"gslide-media")?c:c.querySelector(".gslide-media"),s=ce(i,".ginner-container"),n=c.querySelector(".gslide-description");t>769&&(i=s),H(i,"greset"),ze(i,"translate3d(0, 0, 0)"),oe(e,{onElement:i,once:!0,withCallback:(r,o)=>{J(i,"greset")}}),i.style.opacity="",n&&(n.style.opacity="")}function Ri(c){if(c.events.hasOwnProperty("touch"))return!1;let e=qt(),t=e.width,i=e.height,s=!1,n=null,r=null,o=null,a=!1,d=1,u=4.5,l=1,h=!1,p=!1,b=null,w=null,_=null,g=null,y,f,m=0,v=0,k=!1,x=!1,S={},E={},C=0,A=0,L;const D=document.getElementById("glightbox-slider"),I=document.querySelector(".goverlay"),O=new Li(D,{touchStart:R=>{if(s=!0,(ee(R.targetTouches[0].target,"ginner-container")||ce(R.targetTouches[0].target,".gslide-desc")||R.targetTouches[0].target.nodeName.toLowerCase()=="a")&&(s=!1),ce(R.targetTouches[0].target,".gslide-inline")&&!ee(R.targetTouches[0].target.parentNode,"gslide-inline")&&(s=!1),s){if(E=R.targetTouches[0],S.pageX=R.targetTouches[0].pageX,S.pageY=R.targetTouches[0].pageY,C=R.targetTouches[0].clientX,A=R.targetTouches[0].clientY,n=c.activeSlide,r=n.querySelector(".gslide-media"),L=n.querySelector(".gslide-inline"),o=null,ee(r,"gslide-image")&&(o=r.querySelector("img")),(window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth)>769&&(r=n.querySelector(".ginner-container")),J(I,"greset"),R.pageX>20&&R.pageX<window.innerWidth-20)return;R.preventDefault()}},touchMove:R=>{if(!s||(E=R.targetTouches[0],h||p))return;if(L&&L.offsetHeight>i){const U=S.pageX-E.pageX;if(Math.abs(U)<=13)return!1}a=!0;let q=R.targetTouches[0].clientX,M=R.targetTouches[0].clientY,T=C-q,$=A-M;Math.abs(T)>Math.abs($)?(k=!1,x=!0):(x=!1,k=!0),y=E.pageX-S.pageX,m=y*100/t,f=E.pageY-S.pageY,v=f*100/i;let N;if(k&&o&&(N=1-Math.abs(f)/i,I.style.opacity=N,c.settings.touchFollowAxis&&(m=0)),x&&(N=1-Math.abs(y)/t,r.style.opacity=N,c.settings.touchFollowAxis&&(v=0)),!o)return ze(r,`translate3d(${m}%, 0, 0)`);ze(r,`translate3d(${m}%, ${v}%, 0)`)},touchEnd:()=>{if(!s)return;if(a=!1,p||h){_=b,g=w;return}const R=Math.abs(parseInt(v)),q=Math.abs(parseInt(m));if(R>29&&o){c.close();return}if(R<29&&q<25)return H(I,"greset"),I.style.opacity=1,at(r)},multipointEnd:()=>{setTimeout(()=>{h=!1},50)},multipointStart:()=>{h=!0,d=l||1},pinch:R=>{if(!o||a)return!1;h=!0,o.scaleX=o.scaleY=d*R.zoom;let q=d*R.zoom;if(p=!0,q<=1){p=!1,q=1,g=null,_=null,b=null,w=null,o.setAttribute("style","");return}q>u&&(q=u),o.style.transform=`scale3d(${q}, ${q}, 1)`,l=q},pressMove:R=>{if(p&&!h){var q=E.pageX-S.pageX,M=E.pageY-S.pageY;_&&(q=q+_),g&&(M=M+g),b=q,w=M;let T=`translate3d(${q}px, ${M}px, 0)`;l&&(T+=` scale3d(${l}, ${l}, 1)`),ze(o,T)}},swipe:R=>{if(!p){if(h){h=!1;return}if(R.direction=="Left"){if(c.index==c.elements.length-1)return at(r);c.nextSlide()}if(R.direction=="Right"){if(c.index==0)return at(r);c.prevSlide()}}}});c.events.touch=O}class Mi{constructor(e,t,i=null){if(this.img=e,this.slide=t,this.onclose=i,this.img.setZoomEvents)return!1;this.active=!1,this.zoomedIn=!1,this.dragging=!1,this.currentX=null,this.currentY=null,this.initialX=null,this.initialY=null,this.xOffset=0,this.yOffset=0,this.img.addEventListener("mousedown",s=>this.dragStart(s),!1),this.img.addEventListener("mouseup",s=>this.dragEnd(s),!1),this.img.addEventListener("mousemove",s=>this.drag(s),!1),this.img.addEventListener("click",s=>{if(this.slide.classList.contains("dragging-nav"))return this.zoomOut(),!1;if(!this.zoomedIn)return this.zoomIn();this.zoomedIn&&!this.dragging&&this.zoomOut()},!1),this.img.setZoomEvents=!0}zoomIn(){let e=this.widowWidth();if(this.zoomedIn||e<=768)return;const t=this.img;if(t.setAttribute("data-style",t.getAttribute("style")),t.style.maxWidth=t.naturalWidth+"px",t.style.maxHeight=t.naturalHeight+"px",t.naturalWidth>e){let i=e/2-t.naturalWidth/2;this.setTranslate(this.img.parentNode,i,0)}this.slide.classList.add("zoomed"),this.zoomedIn=!0}zoomOut(){this.img.parentNode.setAttribute("style",""),this.img.setAttribute("style",this.img.getAttribute("data-style")),this.slide.classList.remove("zoomed"),this.zoomedIn=!1,this.currentX=null,this.currentY=null,this.initialX=null,this.initialY=null,this.xOffset=0,this.yOffset=0,this.onclose&&typeof this.onclose=="function"&&this.onclose()}dragStart(e){if(e.preventDefault(),!this.zoomedIn){this.active=!1;return}e.type==="touchstart"?(this.initialX=e.touches[0].clientX-this.xOffset,this.initialY=e.touches[0].clientY-this.yOffset):(this.initialX=e.clientX-this.xOffset,this.initialY=e.clientY-this.yOffset),e.target===this.img&&(this.active=!0,this.img.classList.add("dragging"))}dragEnd(e){e.preventDefault(),this.initialX=this.currentX,this.initialY=this.currentY,this.active=!1,setTimeout(()=>{this.dragging=!1,this.img.isDragging=!1,this.img.classList.remove("dragging")},100)}drag(e){this.active&&(e.preventDefault(),e.type==="touchmove"?(this.currentX=e.touches[0].clientX-this.initialX,this.currentY=e.touches[0].clientY-this.initialY):(this.currentX=e.clientX-this.initialX,this.currentY=e.clientY-this.initialY),this.xOffset=this.currentX,this.yOffset=this.currentY,this.img.isDragging=!0,this.dragging=!0,this.setTranslate(this.img,this.currentX,this.currentY))}onMove(e){if(!this.zoomedIn)return;let t=e.clientX-this.img.naturalWidth/2,i=e.clientY-this.img.naturalHeight/2;this.setTranslate(this.img,t,i)}setTranslate(e,t,i){e.style.transform="translate3d("+t+"px, "+i+"px, 0)"}widowWidth(){return window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth}}class Dt{constructor(e={}){let{dragEl:t,toleranceX:i=40,toleranceY:s=65,slide:n=null,instance:r=null}=e;this.el=t,this.active=!1,this.dragging=!1,this.currentX=null,this.currentY=null,this.initialX=null,this.initialY=null,this.xOffset=0,this.yOffset=0,this.direction=null,this.lastDirection=null,this.toleranceX=i,this.toleranceY=s,this.toleranceReached=!1,this.dragContainer=this.el,this.slide=n,this.instance=r,this.el.addEventListener("mousedown",o=>this.dragStart(o),!1),this.el.addEventListener("mouseup",o=>this.dragEnd(o),!1),this.el.addEventListener("mousemove",o=>this.drag(o),!1)}dragStart(e){if(this.slide.classList.contains("zoomed")){this.active=!1;return}e.type==="touchstart"?(this.initialX=e.touches[0].clientX-this.xOffset,this.initialY=e.touches[0].clientY-this.yOffset):(this.initialX=e.clientX-this.xOffset,this.initialY=e.clientY-this.yOffset);let t=e.target.nodeName.toLowerCase(),i=["input","select","textarea","button","a"];if(e.target.classList.contains("nodrag")||ce(e.target,".nodrag")||i.indexOf(t)!==-1){this.active=!1;return}e.preventDefault(),(e.target===this.el||t!=="img"&&ce(e.target,".gslide-inline"))&&(this.active=!0,this.el.classList.add("dragging"),this.dragContainer=ce(e.target,".ginner-container"))}dragEnd(e){e&&e.preventDefault(),this.initialX=0,this.initialY=0,this.currentX=null,this.currentY=null,this.initialX=null,this.initialY=null,this.xOffset=0,this.yOffset=0,this.active=!1,this.doSlideChange&&(this.instance.preventOutsideClick=!0,this.doSlideChange=="right"&&this.instance.prevSlide(),this.doSlideChange=="left"&&this.instance.nextSlide()),this.doSlideClose&&this.instance.close(),this.toleranceReached||this.setTranslate(this.dragContainer,0,0,!0),setTimeout(()=>{this.instance.preventOutsideClick=!1,this.toleranceReached=!1,this.lastDirection=null,this.dragging=!1,this.el.isDragging=!1,this.el.classList.remove("dragging"),this.slide.classList.remove("dragging-nav"),this.dragContainer.style.transform="",this.dragContainer.style.transition=""},100)}drag(e){if(this.active){e.preventDefault(),this.slide.classList.add("dragging-nav"),e.type==="touchmove"?(this.currentX=e.touches[0].clientX-this.initialX,this.currentY=e.touches[0].clientY-this.initialY):(this.currentX=e.clientX-this.initialX,this.currentY=e.clientY-this.initialY),this.xOffset=this.currentX,this.yOffset=this.currentY,this.el.isDragging=!0,this.dragging=!0,this.doSlideChange=!1,this.doSlideClose=!1;let t=Math.abs(this.currentX),i=Math.abs(this.currentY);if(t>0&&t>=Math.abs(this.currentY)&&(!this.lastDirection||this.lastDirection=="x")){this.yOffset=0,this.lastDirection="x",this.setTranslate(this.dragContainer,this.currentX,0);let s=this.shouldChange();if(!this.instance.settings.dragAutoSnap&&s&&(this.doSlideChange=s),this.instance.settings.dragAutoSnap&&s){this.instance.preventOutsideClick=!0,this.toleranceReached=!0,this.active=!1,this.instance.preventOutsideClick=!0,this.dragEnd(null),s=="right"&&this.instance.prevSlide(),s=="left"&&this.instance.nextSlide();return}}if(this.toleranceY>0&&i>0&&i>=t&&(!this.lastDirection||this.lastDirection=="y")){this.xOffset=0,this.lastDirection="y",this.setTranslate(this.dragContainer,0,this.currentY);let s=this.shouldClose();!this.instance.settings.dragAutoSnap&&s&&(this.doSlideClose=!0),this.instance.settings.dragAutoSnap&&s&&this.instance.close();return}}}shouldChange(){let e=!1;if(Math.abs(this.currentX)>=this.toleranceX){let i=this.currentX>0?"right":"left";(i=="left"&&this.slide!==this.slide.parentNode.lastChild||i=="right"&&this.slide!==this.slide.parentNode.firstChild)&&(e=i)}return e}shouldClose(){let e=!1;return Math.abs(this.currentY)>=this.toleranceY&&(e=!0),e}setTranslate(e,t,i,s=!1){s?e.style.transition="all .2s ease":e.style.transition="",e.style.transform=`translate3d(${t}px, ${i}px, 0)`}}function Ai(c,e,t,i){const s=c.querySelector(".gslide-media");let n=new Image,r="gSlideTitle_"+t,o="gSlideDesc_"+t;n.addEventListener("load",()=>{F(i)&&i()},!1),n.src=e.href,e.sizes!=""&&e.srcset!=""&&(n.sizes=e.sizes,n.srcset=e.srcset),n.alt="",!ne(e.alt)&&e.alt!==""&&(n.alt=e.alt),e.title!==""&&n.setAttribute("aria-labelledby",r),e.description!==""&&n.setAttribute("aria-describedby",o),e.hasOwnProperty("_hasCustomWidth")&&e._hasCustomWidth&&(n.style.width=e.width),e.hasOwnProperty("_hasCustomHeight")&&e._hasCustomHeight&&(n.style.height=e.height),s.insertBefore(n,s.firstChild)}function qi(c,e,t,i){const s=c.querySelector(".ginner-container"),n="gvideo"+t,r=c.querySelector(".gslide-media"),o=this.getAllPlayers();H(s,"gvideo-container"),r.insertBefore(xe('<div class="gvideo-wrapper"></div>'),r.firstChild);const a=c.querySelector(".gvideo-wrapper");Pt(this.settings.plyr.css,"Plyr");let d=e.href,u=e?.videoProvider,l=!1;r.style.maxWidth=e.width,Pt(this.settings.plyr.js,"Plyr",()=>{if(!u&&d.match(/vimeo\.com\/([0-9]*)/)&&(u="vimeo"),!u&&(d.match(/(youtube\.com|youtube-nocookie\.com)\/watch\?v=([a-zA-Z0-9\-_]+)/)||d.match(/youtu\.be\/([a-zA-Z0-9\-_]+)/)||d.match(/(youtube\.com|youtube-nocookie\.com)\/embed\/([a-zA-Z0-9\-_]+)/))&&(u="youtube"),u==="local"||!u){u="local";let w='<video id="'+n+'" ';w+=`style="background:#000; max-width: ${e.width};" `,w+='preload="metadata" ',w+='x-webkit-airplay="allow" ',w+="playsinline ",w+="controls ",w+='class="gvideo-local">',w+=`<source src="${d}">`,w+="</video>",l=xe(w)}const h=l||xe(`<div id="${n}" data-plyr-provider="${u}" data-plyr-embed-id="${d}"></div>`);H(a,`${u}-video gvideo`),a.appendChild(h),a.setAttribute("data-id",n),a.setAttribute("data-index",t);const p=Z(this.settings.plyr,"config")?this.settings.plyr.config:{},b=new Plyr("#"+n,p);b.on("ready",w=>{o[n]=w.detail.plyr,F(i)&&i()}),ot(()=>c.querySelector("iframe")&&c.querySelector("iframe").dataset.ready=="true",()=>{this.resize(c)}),b.on("enterfullscreen",Ht),b.on("exitfullscreen",Ht)})}function Ht(c){const e=ce(c.target,".gslide-media");c.type==="enterfullscreen"&&H(e,"fullscreen"),c.type==="exitfullscreen"&&J(e,"fullscreen")}function Pi(c,e,t,i){const s=c.querySelector(".gslide-media"),n=Z(e,"href")&&e.href?e.href.split("#").pop().trim():!1,r=Z(e,"content")&&e.content?e.content:!1;let o;if(r&&(Ae(r)&&(o=xe(`<div class="ginlined-content">${r}</div>`)),ge(r))){r.style.display=="none"&&(r.style.display="block");const a=document.createElement("div");a.className="ginlined-content",a.appendChild(r),o=a}if(n){let a=document.getElementById(n);if(!a)return!1;const d=a.cloneNode(!0);d.style.height=e.height,d.style.maxWidth=e.width,H(d,"ginlined-content"),o=d}if(!o)return console.error("Unable to append inline slide content",e),!1;s.style.height=e.height,s.style.width=e.width,s.appendChild(o),this.events["inlineclose"+n]=oe("click",{onElement:s.querySelectorAll(".gtrigger-close"),withCallback:a=>{a.preventDefault(),this.close()}}),F(i)&&i()}function Ii(c,e,t,i){const s=c.querySelector(".gslide-media"),n=wi({url:e.href,callback:i});s.parentNode.style.maxWidth=e.width,s.parentNode.style.height=e.height,s.appendChild(n)}class Oi{constructor(e={}){this.defaults={href:"",sizes:"",srcset:"",title:"",type:"",videoProvider:"",description:"",alt:"",descPosition:"bottom",effect:"",width:"",height:"",content:!1,zoomable:!0,draggable:!0},Ce(e)&&(this.defaults=fe(this.defaults,e))}sourceType(e){let t=e;return e=e.toLowerCase(),e.match(/\.(jpeg|jpg|jpe|gif|png|apn|webp|avif|svg)/)!==null?"image":e.match(/(youtube\.com|youtube-nocookie\.com)\/watch\?v=([a-zA-Z0-9\-_]+)/)||e.match(/youtu\.be\/([a-zA-Z0-9\-_]+)/)||e.match(/(youtube\.com|youtube-nocookie\.com)\/embed\/([a-zA-Z0-9\-_]+)/)||e.match(/vimeo\.com\/([0-9]*)/)||e.match(/\.(mp4|ogg|webm|mov)/)!==null?"video":e.match(/\.(mp3|wav|wma|aac|ogg)/)!==null?"audio":e.indexOf("#")>-1&&t.split("#").pop().trim()!==""?"inline":e.indexOf("goajax=true")>-1?"ajax":"external"}parseConfig(e,t){let i=fe({descPosition:t.descPosition},this.defaults);if(Ce(e)&&!ge(e)){Z(e,"type")||(Z(e,"content")&&e.content?e.type="inline":Z(e,"href")&&(e.type=this.sourceType(e.href)));let o=fe(i,e);return this.setSize(o,t),o}let s="",n=e.getAttribute("data-glightbox"),r=e.nodeName.toLowerCase();if(r==="a"&&(s=e.href),r==="img"&&(s=e.src,i.alt=e.alt),i.href=s,V(i,(o,a)=>{Z(t,a)&&a!=="width"&&(i[a]=t[a]);const d=e.dataset[a];ne(d)||(i[a]=this.sanitizeValue(d))}),i.content&&(i.type="inline"),!i.type&&s&&(i.type=this.sourceType(s)),ne(n)){if(!i.title&&r=="a"){let o=e.title;!ne(o)&&o!==""&&(i.title=o)}if(!i.title&&r=="img"){let o=e.alt;!ne(o)&&o!==""&&(i.title=o)}}else{let o=[];V(i,(a,d)=>{o.push(";\\s?"+d)}),o=o.join("\\s?:|"),n.trim()!==""&&V(i,(a,d)=>{const u=n,l="s?"+d+"s?:s?(.*?)("+o+"s?:|$)",h=new RegExp(l),p=u.match(h);if(p&&p.length&&p[1]){const b=p[1].trim().replace(/;\s*$/,"");i[d]=this.sanitizeValue(b)}})}if(i.description&&i.description.substring(0,1)==="."){let o;try{o=document.querySelector(i.description).innerHTML}catch(a){if(!(a instanceof DOMException))throw a}o&&(i.description=o)}if(!i.description){let o=e.querySelector(".glightbox-desc");o&&(i.description=o.innerHTML)}return this.setSize(i,t,e),this.slideConfig=i,i}setSize(e,t,i=null){const s=e.type=="video"?this.checkSize(t.videosWidth):this.checkSize(t.width),n=this.checkSize(t.height);return e.width=Z(e,"width")&&e.width!==""?this.checkSize(e.width):s,e.height=Z(e,"height")&&e.height!==""?this.checkSize(e.height):n,i&&e.type=="image"&&(e._hasCustomWidth=!!i.dataset.width,e._hasCustomHeight=!!i.dataset.height),e}checkSize(e){return Ue(e)?`${e}px`:e}sanitizeValue(e){return e!=="true"&&e!=="false"?e:e==="true"}}class Be{constructor(e,t,i){this.element=e,this.instance=t,this.index=i}setContent(e=null,t=!1){if(ee(e,"loaded"))return!1;const i=this.instance.settings,s=this.slideConfig,n=lt();F(i.beforeSlideLoad)&&i.beforeSlideLoad({index:this.index,slide:e,player:!1});let r=s.type,o=s.descPosition,a=e.querySelector(".gslide-media"),d=e.querySelector(".gslide-title"),u=e.querySelector(".gslide-desc"),l=e.querySelector(".gdesc-inner"),h=t,p="gSlideTitle_"+this.index,b="gSlideDesc_"+this.index;if(F(i.afterSlideLoad)&&(h=()=>{F(t)&&t(),i.afterSlideLoad({index:this.index,slide:e,player:this.instance.getSlidePlayerInstance(this.index)})}),s.title==""&&s.description==""?l&&l.parentNode.parentNode.removeChild(l.parentNode):(d&&s.title!==""?(d.id=p,d.innerHTML=s.title):d.parentNode.removeChild(d),u&&s.description!==""?(u.id=b,n&&i.moreLength>0?(s.smallDescription=this.slideShortDesc(s.description,i.moreLength,i.moreText),u.innerHTML=s.smallDescription,this.descriptionEvents(u,s)):u.innerHTML=s.description):u.parentNode.removeChild(u),H(a.parentNode,`desc-${o}`),H(l.parentNode,`description-${o}`)),H(a,`gslide-${r}`),H(e,"loaded"),r==="video"){qi.apply(this.instance,[e,s,this.index,h]);return}if(r==="external"){Ii.apply(this,[e,s,this.index,h]);return}if(r==="inline"){Pi.apply(this.instance,[e,s,this.index,h]),s.draggable&&new Dt({dragEl:e.querySelector(".gslide-inline"),toleranceX:i.dragToleranceX,toleranceY:i.dragToleranceY,slide:e,instance:this.instance});return}if(r==="image"){Ai(e,s,this.index,()=>{const w=e.querySelector("img");s.draggable&&new Dt({dragEl:w,toleranceX:i.dragToleranceX,toleranceY:i.dragToleranceY,slide:e,instance:this.instance}),s.zoomable&&w.naturalWidth>w.offsetWidth&&(H(w,"zoomable"),new Mi(w,e,()=>{this.instance.resize()})),F(h)&&h()});return}F(h)&&h()}slideShortDesc(e,t=50,i=!1){let s=document.createElement("div");s.innerHTML=e;let n=s.innerText,r=i;if(e=n.trim(),e.length<=t)return e;let o=e.substr(0,t-1);return r?(s=null,o+'... <a href="#" class="desc-more">'+i+"</a>"):o}descriptionEvents(e,t){let i=e.querySelector(".desc-more");if(!i)return!1;oe("click",{onElement:i,withCallback:(s,n)=>{s.preventDefault();const r=document.body;let o=ce(n,".gslide-desc");if(!o)return!1;o.innerHTML=t.description,H(r,"gdesc-open");let a=oe("click",{onElement:[r,ce(o,".gslide-description")],withCallback:(d,u)=>{d.target.nodeName.toLowerCase()!=="a"&&(J(r,"gdesc-open"),H(r,"gdesc-closed"),o.innerHTML=t.smallDescription,this.descriptionEvents(o,t),setTimeout(()=>{J(r,"gdesc-closed")},400),a.destroy())}})}})}create(){return xe(this.instance.settings.slideHTML)}getConfig(){!ge(this.element)&&!this.element.hasOwnProperty("draggable")&&(this.element.draggable=this.instance.settings.draggable);const e=new Oi(this.instance.settings.slideExtraAttributes);return this.slideConfig=e.parseConfig(this.element,this.instance.settings),this.slideConfig}}const $i="3.2.0",zt=lt(),Ut=xi();let ct;typeof document>"u"||(ct=document.getElementsByTagName("html")[0]);const ut={selector:".glightbox",elements:null,skin:"clean",theme:"clean",closeButton:!0,startAt:null,autoplayVideos:!0,autofocusVideos:!0,descPosition:"bottom",width:"900px",height:"506px",videosWidth:"960px",beforeSlideChange:null,afterSlideChange:null,beforeSlideLoad:null,afterSlideLoad:null,slideInserted:null,slideRemoved:null,slideExtraAttributes:null,onOpen:null,onClose:null,loop:!1,zoomable:!0,draggable:!0,dragAutoSnap:!1,dragToleranceX:40,dragToleranceY:65,preload:!0,oneSlidePerOpen:!1,touchNavigation:!0,touchFollowAxis:!0,keyboardNavigation:!0,closeOnOutsideClick:!0,plugins:!1,plyr:{css:"https://cdn.plyr.io/3.6.12/plyr.css",js:"https://cdn.plyr.io/3.6.12/plyr.js",config:{ratio:"16:9",fullscreen:{enabled:!0,iosNative:!0},youtube:{noCookie:!0,rel:0,showinfo:0,iv_load_policy:3},vimeo:{byline:!1,portrait:!1,title:!1,transparent:!1}}},openEffect:"zoom",closeEffect:"zoom",slideEffect:"slide",moreText:"See more",moreLength:60,cssEfects:{fade:{in:"fadeIn",out:"fadeOut"},zoom:{in:"zoomIn",out:"zoomOut"},slide:{in:"slideInRight",out:"slideOutLeft"},slideBack:{in:"slideInLeft",out:"slideOutRight"},none:{in:"none",out:"none"}},svg:{close:'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 512 512" xml:space="preserve"><g><g><path d="M505.943,6.058c-8.077-8.077-21.172-8.077-29.249,0L6.058,476.693c-8.077,8.077-8.077,21.172,0,29.249C10.096,509.982,15.39,512,20.683,512c5.293,0,10.586-2.019,14.625-6.059L505.943,35.306C514.019,27.23,514.019,14.135,505.943,6.058z"/></g></g><g><g><path d="M505.942,476.694L35.306,6.059c-8.076-8.077-21.172-8.077-29.248,0c-8.077,8.076-8.077,21.171,0,29.248l470.636,470.636c4.038,4.039,9.332,6.058,14.625,6.058c5.293,0,10.587-2.019,14.624-6.057C514.018,497.866,514.018,484.771,505.942,476.694z"/></g></g></svg>',next:'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 477.175 477.175" xml:space="preserve"> <g><path d="M360.731,229.075l-225.1-225.1c-5.3-5.3-13.8-5.3-19.1,0s-5.3,13.8,0,19.1l215.5,215.5l-215.5,215.5c-5.3,5.3-5.3,13.8,0,19.1c2.6,2.6,6.1,4,9.5,4c3.4,0,6.9-1.3,9.5-4l225.1-225.1C365.931,242.875,365.931,234.275,360.731,229.075z"/></g></svg>',prev:'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 477.175 477.175" xml:space="preserve"><g><path d="M145.188,238.575l215.5-215.5c5.3-5.3,5.3-13.8,0-19.1s-13.8-5.3-19.1,0l-225.1,225.1c-5.3,5.3-5.3,13.8,0,19.1l225.1,225c2.6,2.6,6.1,4,9.5,4s6.9-1.3,9.5-4c5.3-5.3,5.3-13.8,0-19.1L145.188,238.575z"/></g></svg>'}};ut.slideHTML=`<div class="gslide">
2
2
  <div class="gslide-inner-content">
3
3
  <div class="ginner-container">
4
4
  <div class="gslide-media">
@@ -24,7 +24,7 @@ var ContentBuilderRuntime=(function(){"use strict";const Rt=Date.now();function
24
24
  * Glide.js v3.7.1
25
25
  * (c) 2013-2024 Jędrzej Chałubek (https://github.com/jedrzejchalubek/)
26
26
  * Released under the MIT License.
27
- */function Bt(c,e){var t=Object.keys(c);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(c);e&&(i=i.filter(function(s){return Object.getOwnPropertyDescriptor(c,s).enumerable})),t.push.apply(t,i)}return t}function Ft(c){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?Bt(Object(t),!0).forEach(function(i){Di(c,i,t[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(c,Object.getOwnPropertyDescriptors(t)):Bt(Object(t)).forEach(function(i){Object.defineProperty(c,i,Object.getOwnPropertyDescriptor(t,i))})}return c}function Fe(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Fe=function(e){return typeof e}:Fe=function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Fe(c)}function Ge(c,e){if(!(c instanceof e))throw new TypeError("Cannot call a class as a function")}function Ni(c,e){for(var t=0;t<e.length;t++){var i=e[t];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(c,i.key,i)}}function We(c,e,t){return e&&Ni(c.prototype,e),c}function Di(c,e,t){return e in c?Object.defineProperty(c,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):c[e]=t,c}function Hi(c,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(e&&e.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),e&&dt(c,e)}function Le(c){return Le=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},Le(c)}function dt(c,e){return dt=Object.setPrototypeOf||function(i,s){return i.__proto__=s,i},dt(c,e)}function zi(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Ui(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function ji(c,e){if(e&&(typeof e=="object"||typeof e=="function"))return e;if(e!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return Ui(c)}function Bi(c){var e=zi();return function(){var i=Le(c),s;if(e){var n=Le(this).constructor;s=Reflect.construct(i,arguments,n)}else s=i.apply(this,arguments);return ji(this,s)}}function Fi(c,e){for(;!Object.prototype.hasOwnProperty.call(c,e)&&(c=Le(c),c!==null););return c}function Ve(){return typeof Reflect<"u"&&Reflect.get?Ve=Reflect.get:Ve=function(e,t,i){var s=Fi(e,t);if(s){var n=Object.getOwnPropertyDescriptor(s,t);return n.get?n.get.call(arguments.length<3?e:i):n.value}},Ve.apply(this,arguments)}var Gi={type:"slider",startAt:0,perView:1,focusAt:0,gap:10,autoplay:!1,hoverpause:!0,keyboard:!0,bound:!1,swipeThreshold:80,dragThreshold:120,perSwipe:"",touchRatio:.5,touchAngle:45,animationDuration:400,rewind:!0,rewindDuration:800,animationTimingFunc:"cubic-bezier(.165, .840, .440, 1)",waitForTransition:!0,throttle:10,direction:"ltr",peek:0,cloningRatio:1,breakpoints:{},classes:{swipeable:"glide--swipeable",dragging:"glide--dragging",direction:{ltr:"glide--ltr",rtl:"glide--rtl"},type:{slider:"glide--slider",carousel:"glide--carousel"},slide:{clone:"glide__slide--clone",active:"glide__slide--active"},arrow:{disabled:"glide__arrow--disabled"},nav:{active:"glide__bullet--active"}}};function me(c){console.error("[Glide warn]: ".concat(c))}function Q(c){return parseInt(c)}function Wi(c){return parseFloat(c)}function ht(c){return typeof c=="string"}function Re(c){var e=Fe(c);return e==="function"||e==="object"&&!!c}function Ye(c){return typeof c=="function"}function Gt(c){return typeof c>"u"}function pt(c){return c.constructor===Array}function Vi(c,e,t){var i={};for(var s in e)Ye(e[s])?i[s]=e[s](c,i,t):me("Extension must be a function");for(var n in i)Ye(i[n].mount)&&i[n].mount();return i}function W(c,e,t){Object.defineProperty(c,e,t)}function Yi(c){return Object.keys(c).sort().reduce(function(e,t){return e[t]=c[t],e[t],e},{})}function ft(c,e){var t=Object.assign({},c,e);if(e.hasOwnProperty("classes")){t.classes=Object.assign({},c.classes,e.classes);var i=["direction","type","slide","arrow","nav"];i.forEach(function(s){e.classes.hasOwnProperty(s)&&(t.classes[s]=Ft(Ft({},c.classes[s]),e.classes[s]))})}return e.hasOwnProperty("breakpoints")&&(t.breakpoints=Object.assign({},c.breakpoints,e.breakpoints)),t}var Xi=(function(){function c(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Ge(this,c),this.events=e,this.hop=e.hasOwnProperty}return We(c,[{key:"on",value:function(t,i){if(pt(t)){for(var s=0;s<t.length;s++)this.on(t[s],i);return}this.hop.call(this.events,t)||(this.events[t]=[]);var n=this.events[t].push(i)-1;return{remove:function(){delete this.events[t][n]}}}},{key:"emit",value:function(t,i){if(pt(t)){for(var s=0;s<t.length;s++)this.emit(t[s],i);return}this.hop.call(this.events,t)&&this.events[t].forEach(function(n){n(i||{})})}}]),c})(),Ji=(function(){function c(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};Ge(this,c),this._c={},this._t=[],this._e=new Xi,this.disabled=!1,this.selector=e,this.settings=ft(Gi,t),this.index=this.settings.startAt}return We(c,[{key:"mount",value:function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return this._e.emit("mount.before"),Re(t)?this._c=Vi(this,t,this._e):me("You need to provide a object on `mount()`"),this._e.emit("mount.after"),this}},{key:"mutate",value:function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return pt(t)?this._t=t:me("You need to provide a array on `mutate()`"),this}},{key:"update",value:function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return this.settings=ft(this.settings,t),t.hasOwnProperty("startAt")&&(this.index=t.startAt),this._e.emit("update"),this}},{key:"go",value:function(t){return this._c.Run.make(t),this}},{key:"move",value:function(t){return this._c.Transition.disable(),this._c.Move.make(t),this}},{key:"destroy",value:function(){return this._e.emit("destroy"),this}},{key:"play",value:function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!1;return t&&(this.settings.autoplay=t),this._e.emit("play"),this}},{key:"pause",value:function(){return this._e.emit("pause"),this}},{key:"disable",value:function(){return this.disabled=!0,this}},{key:"enable",value:function(){return this.disabled=!1,this}},{key:"on",value:function(t,i){return this._e.on(t,i),this}},{key:"isType",value:function(t){return this.settings.type===t}},{key:"settings",get:function(){return this._o},set:function(t){Re(t)?this._o=t:me("Options must be an `object` instance.")}},{key:"index",get:function(){return this._i},set:function(t){this._i=Q(t)}},{key:"type",get:function(){return this.settings.type}},{key:"disabled",get:function(){return this._d},set:function(t){this._d=!!t}}]),c})();function Zi(c,e,t){var i={mount:function(){this._o=!1},make:function(d){var u=this;c.disabled||(!c.settings.waitForTransition||c.disable(),this.move=d,t.emit("run.before",this.move),this.calculate(),t.emit("run",this.move),e.Transition.after(function(){u.isStart()&&t.emit("run.start",u.move),u.isEnd()&&t.emit("run.end",u.move),u.isOffset()&&(u._o=!1,t.emit("run.offset",u.move)),t.emit("run.after",u.move),c.enable()}))},calculate:function(){var d=this.move,u=this.length,l=d.steps,h=d.direction,p=1;if(h==="="){if(c.settings.bound&&Q(l)>u){c.index=u;return}c.index=l;return}if(h===">"&&l===">"){c.index=u;return}if(h==="<"&&l==="<"){c.index=0;return}if(h==="|"&&(p=c.settings.perView||1),h===">"||h==="|"&&l===">"){var b=s(p);b>u&&(this._o=!0),c.index=n(b,p);return}if(h==="<"||h==="|"&&l==="<"){var w=r(p);w<0&&(this._o=!0),c.index=o(w,p);return}me("Invalid direction pattern [".concat(h).concat(l,"] has been used"))},isStart:function(){return c.index<=0},isEnd:function(){return c.index>=this.length},isOffset:function(){var d=arguments.length>0&&arguments[0]!==void 0?arguments[0]:void 0;return d?this._o?d==="|>"?this.move.direction==="|"&&this.move.steps===">":d==="|<"?this.move.direction==="|"&&this.move.steps==="<":this.move.direction===d:!1:this._o},isBound:function(){return c.isType("slider")&&c.settings.focusAt!=="center"&&c.settings.bound}};function s(a){var d=c.index;return c.isType("carousel")?d+a:d+(a-d%a)}function n(a,d){var u=i.length;return a<=u?a:c.isType("carousel")?a-(u+1):c.settings.rewind?i.isBound()&&!i.isEnd()?u:0:i.isBound()?u:Math.floor(u/d)*d}function r(a){var d=c.index;if(c.isType("carousel"))return d-a;var u=Math.ceil(d/a);return(u-1)*a}function o(a,d){var u=i.length;return a>=0?a:c.isType("carousel")?a+(u+1):c.settings.rewind?i.isBound()&&i.isStart()?u:Math.floor(u/d)*d:0}return W(i,"move",{get:function(){return this._m},set:function(d){var u=d.substr(1);this._m={direction:d.substr(0,1),steps:u?Q(u)?Q(u):u:0}}}),W(i,"length",{get:function(){var d=c.settings,u=e.Html.slides.length;return this.isBound()?u-1-(Q(d.perView)-1)+Q(d.focusAt):u-1}}),W(i,"offset",{get:function(){return this._o}}),i}function Wt(){return new Date().getTime()}function Xe(c,e){var t=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},i,s,n,r,o=0,a=function(){o=t.leading===!1?0:Wt(),i=null,r=c.apply(s,n),i||(s=n=null)},d=function(){var l=Wt();!o&&t.leading===!1&&(o=l);var h=e-(l-o);return s=this,n=arguments,h<=0||h>e?(i&&(clearTimeout(i),i=null),o=l,r=c.apply(s,n),i||(s=n=null)):!i&&t.trailing!==!1&&(i=setTimeout(a,h)),r};return d.cancel=function(){clearTimeout(i),o=0,i=s=n=null},d}var Je={ltr:["marginLeft","marginRight"],rtl:["marginRight","marginLeft"]};function Qi(c,e,t){var i={apply:function(n){for(var r=0,o=n.length;r<o;r++){var a=n[r].style,d=e.Direction.value;r!==0?a[Je[d][0]]="".concat(this.value/2,"px"):a[Je[d][0]]="",r!==n.length-1?a[Je[d][1]]="".concat(this.value/2,"px"):a[Je[d][1]]=""}},remove:function(n){for(var r=0,o=n.length;r<o;r++){var a=n[r].style;a.marginLeft="",a.marginRight=""}}};return W(i,"value",{get:function(){return Q(c.settings.gap)}}),W(i,"grow",{get:function(){return i.value*e.Sizes.length}}),W(i,"reductor",{get:function(){var n=c.settings.perView;return i.value*(n-1)/n}}),t.on(["build.after","update"],Xe(function(){i.apply(e.Html.wrapper.children)},30)),t.on("destroy",function(){i.remove(e.Html.wrapper.children)}),i}function Vt(c){if(c&&c.parentNode){for(var e=c.parentNode.firstChild,t=[];e;e=e.nextSibling)e.nodeType===1&&e!==c&&t.push(e);return t}return[]}function gt(c){return Array.prototype.slice.call(c)}var Ki='[data-glide-el="track"]';function es(c,e,t){var i={mount:function(){this.root=c.selector,this.track=this.root.querySelector(Ki),this.collectSlides()},collectSlides:function(){this.slides=gt(this.wrapper.children).filter(function(n){return!n.classList.contains(c.settings.classes.slide.clone)})}};return W(i,"root",{get:function(){return i._r},set:function(n){ht(n)&&(n=document.querySelector(n)),n!==null?i._r=n:me("Root element must be a existing Html node")}}),W(i,"track",{get:function(){return i._t},set:function(n){i._t=n}}),W(i,"wrapper",{get:function(){return i.track.children[0]}}),t.on("update",function(){i.collectSlides()}),i}function ts(c,e,t){var i={mount:function(){this.value=c.settings.peek}};return W(i,"value",{get:function(){return i._v},set:function(n){Re(n)?(n.before=Q(n.before),n.after=Q(n.after)):n=Q(n),i._v=n}}),W(i,"reductor",{get:function(){var n=i.value,r=c.settings.perView;return Re(n)?n.before/r+n.after/r:n*2/r}}),t.on(["resize","update"],function(){i.mount()}),i}function is(c,e,t){var i={mount:function(){this._o=0},make:function(){var n=this,r=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0;this.offset=r,t.emit("move",{movement:this.value}),e.Transition.after(function(){t.emit("move.after",{movement:n.value})})}};return W(i,"offset",{get:function(){return i._o},set:function(n){i._o=Gt(n)?0:Q(n)}}),W(i,"translate",{get:function(){return e.Sizes.slideWidth*c.index}}),W(i,"value",{get:function(){var n=this.offset,r=this.translate;return e.Direction.is("rtl")?r+n:r-n}}),t.on(["build.before","run"],function(){i.make()}),i}function ss(c,e,t){var i={setupSlides:function(){for(var n="".concat(this.slideWidth,"px"),r=e.Html.slides,o=0;o<r.length;o++)r[o].style.width=n},setupWrapper:function(){e.Html.wrapper.style.width="".concat(this.wrapperSize,"px")},remove:function(){for(var n=e.Html.slides,r=0;r<n.length;r++)n[r].style.width="";e.Html.wrapper.style.width=""}};return W(i,"length",{get:function(){return e.Html.slides.length}}),W(i,"width",{get:function(){return e.Html.track.offsetWidth}}),W(i,"wrapperSize",{get:function(){return i.slideWidth*i.length+e.Gaps.grow+e.Clones.grow}}),W(i,"slideWidth",{get:function(){return i.width/c.settings.perView-e.Peek.reductor-e.Gaps.reductor}}),t.on(["build.before","resize","update"],function(){i.setupSlides(),i.setupWrapper()}),t.on("destroy",function(){i.remove()}),i}function ns(c,e,t){var i={mount:function(){t.emit("build.before"),this.typeClass(),this.activeClass(),t.emit("build.after")},typeClass:function(){e.Html.root.classList.add(c.settings.classes.type[c.settings.type])},activeClass:function(){var n=c.settings.classes,r=e.Html.slides[c.index];r&&(r.classList.add(n.slide.active),Vt(r).forEach(function(o){o.classList.remove(n.slide.active)}))},removeClasses:function(){var n=c.settings.classes,r=n.type,o=n.slide;e.Html.root.classList.remove(r[c.settings.type]),e.Html.slides.forEach(function(a){a.classList.remove(o.active)})}};return t.on(["destroy","update"],function(){i.removeClasses()}),t.on(["resize","update"],function(){i.mount()}),t.on("move.after",function(){i.activeClass()}),i}function rs(c,e,t){var i={mount:function(){this.items=[],c.isType("carousel")&&(this.items=this.collect())},collect:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],r=e.Html.slides,o=c.settings,a=o.perView,d=o.classes,u=o.cloningRatio;if(r.length>0)for(var l=+!!c.settings.peek,h=a+l+Math.round(a/2),p=r.slice(0,h).reverse(),b=r.slice(h*-1),w=0;w<Math.max(u,Math.floor(a/r.length));w++){for(var _=0;_<p.length;_++){var g=p[_].cloneNode(!0);g.classList.add(d.slide.clone),n.push(g)}for(var v=0;v<b.length;v++){var f=b[v].cloneNode(!0);f.classList.add(d.slide.clone),n.unshift(f)}}return n},append:function(){for(var n=this.items,r=e.Html,o=r.wrapper,a=r.slides,d=Math.floor(n.length/2),u=n.slice(0,d).reverse(),l=n.slice(d*-1).reverse(),h="".concat(e.Sizes.slideWidth,"px"),p=0;p<l.length;p++)o.appendChild(l[p]);for(var b=0;b<u.length;b++)o.insertBefore(u[b],a[0]);for(var w=0;w<n.length;w++)n[w].style.width=h},remove:function(){for(var n=this.items,r=0;r<n.length;r++)e.Html.wrapper.removeChild(n[r])}};return W(i,"grow",{get:function(){return(e.Sizes.slideWidth+e.Gaps.value)*i.items.length}}),t.on("update",function(){i.remove(),i.mount(),i.append()}),t.on("build.before",function(){c.isType("carousel")&&i.append()}),t.on("destroy",function(){i.remove()}),i}var be=(function(){function c(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Ge(this,c),this.listeners=e}return We(c,[{key:"on",value:function(t,i,s){var n=arguments.length>3&&arguments[3]!==void 0?arguments[3]:!1;ht(t)&&(t=[t]);for(var r=0;r<t.length;r++)this.listeners[t[r]]=s,i.addEventListener(t[r],this.listeners[t[r]],n)}},{key:"off",value:function(t,i){var s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!1;ht(t)&&(t=[t]);for(var n=0;n<t.length;n++)i.removeEventListener(t[n],this.listeners[t[n]],s)}},{key:"destroy",value:function(){delete this.listeners}}]),c})();function os(c,e,t){var i=new be,s={mount:function(){this.bind()},bind:function(){i.on("resize",window,Xe(function(){t.emit("resize")},c.settings.throttle))},unbind:function(){i.off("resize",window)}};return t.on("destroy",function(){s.unbind(),i.destroy()}),s}var ls=["ltr","rtl"],as={">":"<","<":">","=":"="};function cs(c,e,t){var i={mount:function(){this.value=c.settings.direction},resolve:function(n){var r=n.slice(0,1);return this.is("rtl")?n.split(r).join(as[r]):n},is:function(n){return this.value===n},addClass:function(){e.Html.root.classList.add(c.settings.classes.direction[this.value])},removeClass:function(){e.Html.root.classList.remove(c.settings.classes.direction[this.value])}};return W(i,"value",{get:function(){return i._v},set:function(n){ls.indexOf(n)>-1?i._v=n:me("Direction value must be `ltr` or `rtl`")}}),t.on(["destroy","update"],function(){i.removeClass()}),t.on("update",function(){i.mount()}),t.on(["build.before","update"],function(){i.addClass()}),i}function us(c,e){return{modify:function(i){return e.Direction.is("rtl")?-i:i}}}function ds(c,e){return{modify:function(i){var s=Math.floor(i/e.Sizes.slideWidth);return i+e.Gaps.value*s}}}function hs(c,e){return{modify:function(i){return i+e.Clones.grow/2}}}function ps(c,e){return{modify:function(i){if(c.settings.focusAt>=0){var s=e.Peek.value;return Re(s)?i-s.before:i-s}return i}}}function fs(c,e){return{modify:function(i){var s=e.Gaps.value,n=e.Sizes.width,r=c.settings.focusAt,o=e.Sizes.slideWidth;return r==="center"?i-(n/2-o/2):i-o*r-s*r}}}function gs(c,e,t){var i=[ds,hs,ps,fs].concat(c._t,[us]);return{mutate:function(n){for(var r=0;r<i.length;r++){var o=i[r];Ye(o)&&Ye(o().modify)?n=o(c,e,t).modify(n):me("Transformer should be a function that returns an object with `modify()` method")}return n}}}function ms(c,e,t){var i={set:function(n){var r=gs(c,e).mutate(n),o="translate3d(".concat(-1*r,"px, 0px, 0px)");e.Html.wrapper.style.mozTransform=o,e.Html.wrapper.style.webkitTransform=o,e.Html.wrapper.style.transform=o},remove:function(){e.Html.wrapper.style.transform=""},getStartIndex:function(){var n=e.Sizes.length,r=c.index,o=c.settings.perView;return e.Run.isOffset(">")||e.Run.isOffset("|>")?n+(r-o):(r+o)%n},getTravelDistance:function(){var n=e.Sizes.slideWidth*c.settings.perView;return e.Run.isOffset(">")||e.Run.isOffset("|>")?n*-1:n}};return t.on("move",function(s){if(!c.isType("carousel")||!e.Run.isOffset())return i.set(s.movement);e.Transition.after(function(){t.emit("translate.jump"),i.set(e.Sizes.slideWidth*c.index)});var n=e.Sizes.slideWidth*e.Translate.getStartIndex();return i.set(n-e.Translate.getTravelDistance())}),t.on("destroy",function(){i.remove()}),i}function bs(c,e,t){var i=!1,s={compose:function(r){var o=c.settings;return i?"".concat(r," 0ms ").concat(o.animationTimingFunc):"".concat(r," ").concat(this.duration,"ms ").concat(o.animationTimingFunc)},set:function(){var r=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"transform";e.Html.wrapper.style.transition=this.compose(r)},remove:function(){e.Html.wrapper.style.transition=""},after:function(r){setTimeout(function(){r()},this.duration)},enable:function(){i=!1,this.set()},disable:function(){i=!0,this.set()}};return W(s,"duration",{get:function(){var r=c.settings;return c.isType("slider")&&e.Run.offset?r.rewindDuration:r.animationDuration}}),t.on("move",function(){s.set()}),t.on(["build.before","resize","translate.jump"],function(){s.disable()}),t.on("run",function(){s.enable()}),t.on("destroy",function(){s.remove()}),s}var Yt=!1;try{var Xt=Object.defineProperty({},"passive",{get:function(){Yt=!0}});window.addEventListener("testPassive",null,Xt),window.removeEventListener("testPassive",null,Xt)}catch{}var mt=Yt,Ze=["touchstart","mousedown"],Jt=["touchmove","mousemove"],Zt=["touchend","touchcancel","mouseup","mouseleave"],Qt=["mousedown","mousemove","mouseup","mouseleave"];function ys(c,e,t){var i=new be,s=0,n=0,r=0,o=!1,a=mt?{passive:!0}:!1,d={mount:function(){this.bindSwipeStart()},start:function(l){if(!o&&!c.disabled){this.disable();var h=this.touches(l);s=null,n=Q(h.pageX),r=Q(h.pageY),this.bindSwipeMove(),this.bindSwipeEnd(),t.emit("swipe.start")}},move:function(l){if(!c.disabled){var h=c.settings,p=h.touchAngle,b=h.touchRatio,w=h.classes,_=this.touches(l),g=Q(_.pageX)-n,v=Q(_.pageY)-r,f=Math.abs(g<<2),m=Math.abs(v<<2),y=Math.sqrt(f+m),k=Math.sqrt(m);if(s=Math.asin(k/y),s*180/Math.PI<p)l.stopPropagation(),e.Move.make(g*Wi(b)),e.Html.root.classList.add(w.dragging),t.emit("swipe.move");else return!1}},end:function(l){if(!c.disabled){var h=c.settings,p=h.perSwipe,b=h.touchAngle,w=h.classes,_=this.touches(l),g=this.threshold(l),v=_.pageX-n,f=s*180/Math.PI;this.enable(),v>g&&f<b?e.Run.make(e.Direction.resolve("".concat(p,"<"))):v<-g&&f<b?e.Run.make(e.Direction.resolve("".concat(p,">"))):e.Move.make(),e.Html.root.classList.remove(w.dragging),this.unbindSwipeMove(),this.unbindSwipeEnd(),t.emit("swipe.end")}},bindSwipeStart:function(){var l=this,h=c.settings,p=h.swipeThreshold,b=h.dragThreshold;p&&i.on(Ze[0],e.Html.wrapper,function(w){l.start(w)},a),b&&i.on(Ze[1],e.Html.wrapper,function(w){l.start(w)},a)},unbindSwipeStart:function(){i.off(Ze[0],e.Html.wrapper,a),i.off(Ze[1],e.Html.wrapper,a)},bindSwipeMove:function(){var l=this;i.on(Jt,e.Html.wrapper,Xe(function(h){l.move(h)},c.settings.throttle),a)},unbindSwipeMove:function(){i.off(Jt,e.Html.wrapper,a)},bindSwipeEnd:function(){var l=this;i.on(Zt,e.Html.wrapper,function(h){l.end(h)})},unbindSwipeEnd:function(){i.off(Zt,e.Html.wrapper)},touches:function(l){return Qt.indexOf(l.type)>-1?l:l.touches[0]||l.changedTouches[0]},threshold:function(l){var h=c.settings;return Qt.indexOf(l.type)>-1?h.dragThreshold:h.swipeThreshold},enable:function(){return o=!1,e.Transition.enable(),this},disable:function(){return o=!0,e.Transition.disable(),this}};return t.on("build.after",function(){e.Html.root.classList.add(c.settings.classes.swipeable)}),t.on("destroy",function(){d.unbindSwipeStart(),d.unbindSwipeMove(),d.unbindSwipeEnd(),i.destroy()}),d}function vs(c,e,t){var i=new be,s={mount:function(){this.bind()},bind:function(){i.on("dragstart",e.Html.wrapper,this.dragstart)},unbind:function(){i.off("dragstart",e.Html.wrapper)},dragstart:function(r){r.preventDefault()}};return t.on("destroy",function(){s.unbind(),i.destroy()}),s}function ws(c,e,t){var i=new be,s=!1,n=!1,r={mount:function(){this._a=e.Html.wrapper.querySelectorAll("a"),this.bind()},bind:function(){i.on("click",e.Html.wrapper,this.click)},unbind:function(){i.off("click",e.Html.wrapper)},click:function(a){n&&(a.stopPropagation(),a.preventDefault())},detach:function(){if(n=!0,!s){for(var a=0;a<this.items.length;a++)this.items[a].draggable=!1;s=!0}return this},attach:function(){if(n=!1,s){for(var a=0;a<this.items.length;a++)this.items[a].draggable=!0;s=!1}return this}};return W(r,"items",{get:function(){return r._a}}),t.on("swipe.move",function(){r.detach()}),t.on("swipe.end",function(){e.Transition.after(function(){r.attach()})}),t.on("destroy",function(){r.attach(),r.unbind(),i.destroy()}),r}var xs='[data-glide-el="controls[nav]"]',bt='[data-glide-el^="controls"]',ks="".concat(bt,' [data-glide-dir*="<"]'),_s="".concat(bt,' [data-glide-dir*=">"]');function Ss(c,e,t){var i=new be,s=mt?{passive:!0}:!1,n={mount:function(){this._n=e.Html.root.querySelectorAll(xs),this._c=e.Html.root.querySelectorAll(bt),this._arrowControls={previous:e.Html.root.querySelectorAll(ks),next:e.Html.root.querySelectorAll(_s)},this.addBindings()},setActive:function(){for(var o=0;o<this._n.length;o++)this.addClass(this._n[o].children)},removeActive:function(){for(var o=0;o<this._n.length;o++)this.removeClass(this._n[o].children)},addClass:function(o){var a=c.settings,d=o[c.index];d&&(d.classList.add(a.classes.nav.active),Vt(d).forEach(function(u){u.classList.remove(a.classes.nav.active)}))},removeClass:function(o){var a=o[c.index];a?.classList.remove(c.settings.classes.nav.active)},setArrowState:function(){if(!c.settings.rewind){var o=n._arrowControls.next,a=n._arrowControls.previous;this.resetArrowState(o,a),c.index===0&&this.disableArrow(a),c.index===e.Run.length&&this.disableArrow(o)}},resetArrowState:function(){for(var o=c.settings,a=arguments.length,d=new Array(a),u=0;u<a;u++)d[u]=arguments[u];d.forEach(function(l){gt(l).forEach(function(h){h.classList.remove(o.classes.arrow.disabled)})})},disableArrow:function(){for(var o=c.settings,a=arguments.length,d=new Array(a),u=0;u<a;u++)d[u]=arguments[u];d.forEach(function(l){gt(l).forEach(function(h){h.classList.add(o.classes.arrow.disabled)})})},addBindings:function(){for(var o=0;o<this._c.length;o++)this.bind(this._c[o].children)},removeBindings:function(){for(var o=0;o<this._c.length;o++)this.unbind(this._c[o].children)},bind:function(o){for(var a=0;a<o.length;a++)i.on("click",o[a],this.click),i.on("touchstart",o[a],this.click,s)},unbind:function(o){for(var a=0;a<o.length;a++)i.off(["click","touchstart"],o[a])},click:function(o){!mt&&o.type==="touchstart"&&o.preventDefault();var a=o.currentTarget.getAttribute("data-glide-dir");e.Run.make(e.Direction.resolve(a))}};return W(n,"items",{get:function(){return n._c}}),t.on(["mount.after","move.after"],function(){n.setActive()}),t.on(["mount.after","run"],function(){n.setArrowState()}),t.on("destroy",function(){n.removeBindings(),n.removeActive(),i.destroy()}),n}function Ts(c,e,t){var i=new be,s={mount:function(){c.settings.keyboard&&this.bind()},bind:function(){i.on("keyup",document,this.press)},unbind:function(){i.off("keyup",document)},press:function(r){var o=c.settings.perSwipe,a={ArrowRight:">",ArrowLeft:"<"};["ArrowRight","ArrowLeft"].includes(r.code)&&e.Run.make(e.Direction.resolve("".concat(o).concat(a[r.code])))}};return t.on(["destroy","update"],function(){s.unbind()}),t.on("update",function(){s.mount()}),t.on("destroy",function(){i.destroy()}),s}function Es(c,e,t){var i=new be,s={mount:function(){this.enable(),this.start(),c.settings.hoverpause&&this.bind()},enable:function(){this._e=!0},disable:function(){this._e=!1},start:function(){var r=this;this._e&&(this.enable(),c.settings.autoplay&&Gt(this._i)&&(this._i=setInterval(function(){r.stop(),e.Run.make(">"),r.start(),t.emit("autoplay")},this.time)))},stop:function(){this._i=clearInterval(this._i)},bind:function(){var r=this;i.on("mouseover",e.Html.root,function(){r._e&&r.stop()}),i.on("mouseout",e.Html.root,function(){r._e&&r.start()})},unbind:function(){i.off(["mouseover","mouseout"],e.Html.root)}};return W(s,"time",{get:function(){var r=e.Html.slides[c.index].getAttribute("data-glide-autoplay");return Q(r||c.settings.autoplay)}}),t.on(["destroy","update"],function(){s.unbind()}),t.on(["run.before","swipe.start","update"],function(){s.stop()}),t.on(["pause","destroy"],function(){s.disable(),s.stop()}),t.on(["run.after","swipe.end"],function(){s.start()}),t.on(["play"],function(){s.enable(),s.start()}),t.on("update",function(){s.mount()}),t.on("destroy",function(){i.destroy()}),s}function Kt(c){return Re(c)?Yi(c):(me("Breakpoints option must be an object"),{})}function Cs(c,e,t){var i=new be,s=c.settings,n=Kt(s.breakpoints),r=Object.assign({},s),o={match:function(d){if(typeof window.matchMedia<"u"){for(var u in d)if(d.hasOwnProperty(u)&&window.matchMedia("(max-width: ".concat(u,"px)")).matches)return d[u]}return r}};return Object.assign(s,o.match(n)),i.on("resize",window,Xe(function(){c.settings=ft(s,o.match(n))},c.settings.throttle)),t.on("update",function(){n=Kt(n),r=Object.assign({},s)}),t.on("destroy",function(){i.off("resize",window)}),o}var Ls={Html:es,Translate:ms,Transition:bs,Direction:cs,Peek:ts,Sizes:ss,Gaps:Qi,Move:is,Clones:rs,Resize:os,Build:ns,Run:Zi,Swipe:ys,Images:vs,Anchors:ws,Controls:Ss,Keyboard:Ts,Autoplay:Es,Breakpoints:Cs},Rs=(function(c){Hi(t,c);var e=Bi(t);function t(){return Ge(this,t),e.apply(this,arguments)}return We(t,[{key:"mount",value:function(){var s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return Ve(Le(t.prototype),"mount",this).call(this,Object.assign({},Ls,s))}}]),t})(Ji);function yt(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}let ke=yt();function ei(c){ke=c}const qe={exec:()=>null};function B(c,e=""){let t=typeof c=="string"?c:c.source;const i={replace:(s,n)=>{let r=typeof n=="string"?n:n.source;return r=r.replace(ie.caret,"$1"),t=t.replace(s,r),i},getRegex:()=>new RegExp(t,e)};return i}const ie={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] /,listReplaceTask:/^\[[ xX]\] +/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:c=>new RegExp(`^( {0,3}${c})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:c=>new RegExp(`^ {0,${Math.min(3,c-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:c=>new RegExp(`^ {0,${Math.min(3,c-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:c=>new RegExp(`^ {0,${Math.min(3,c-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:c=>new RegExp(`^ {0,${Math.min(3,c-1)}}#`),htmlBeginRegex:c=>new RegExp(`^ {0,${Math.min(3,c-1)}}<(?:[a-z].*>|!--)`,"i")},Ms=/^(?:[ \t]*(?:\n|$))+/,As=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,qs=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,Pe=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Ps=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,vt=/(?:[*+-]|\d{1,9}[.)])/,ti=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,ii=B(ti).replace(/bull/g,vt).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),Is=B(ti).replace(/bull/g,vt).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),wt=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,Os=/^[^\n]+/,xt=/(?!\s*\])(?:\\.|[^\[\]\\])+/,$s=B(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",xt).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Ns=B(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,vt).getRegex(),Qe="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",kt=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,Ds=B("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",kt).replace("tag",Qe).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),si=B(wt).replace("hr",Pe).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Qe).getRegex(),_t={blockquote:B(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",si).getRegex(),code:As,def:$s,fences:qs,heading:Ps,hr:Pe,html:Ds,lheading:ii,list:Ns,newline:Ms,paragraph:si,table:qe,text:Os},ni=B("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",Pe).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Qe).getRegex(),Hs={..._t,lheading:Is,table:ni,paragraph:B(wt).replace("hr",Pe).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",ni).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Qe).getRegex()},zs={..._t,html:B(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",kt).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:qe,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:B(wt).replace("hr",Pe).replace("heading",` *#{1,6} *[^
27
+ */function Bt(c,e){var t=Object.keys(c);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(c);e&&(i=i.filter(function(s){return Object.getOwnPropertyDescriptor(c,s).enumerable})),t.push.apply(t,i)}return t}function Ft(c){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?Bt(Object(t),!0).forEach(function(i){Di(c,i,t[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(c,Object.getOwnPropertyDescriptors(t)):Bt(Object(t)).forEach(function(i){Object.defineProperty(c,i,Object.getOwnPropertyDescriptor(t,i))})}return c}function Fe(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Fe=function(e){return typeof e}:Fe=function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Fe(c)}function Ge(c,e){if(!(c instanceof e))throw new TypeError("Cannot call a class as a function")}function Ni(c,e){for(var t=0;t<e.length;t++){var i=e[t];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(c,i.key,i)}}function We(c,e,t){return e&&Ni(c.prototype,e),c}function Di(c,e,t){return e in c?Object.defineProperty(c,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):c[e]=t,c}function Hi(c,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(e&&e.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),e&&dt(c,e)}function Le(c){return Le=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},Le(c)}function dt(c,e){return dt=Object.setPrototypeOf||function(i,s){return i.__proto__=s,i},dt(c,e)}function zi(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Ui(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function ji(c,e){if(e&&(typeof e=="object"||typeof e=="function"))return e;if(e!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return Ui(c)}function Bi(c){var e=zi();return function(){var i=Le(c),s;if(e){var n=Le(this).constructor;s=Reflect.construct(i,arguments,n)}else s=i.apply(this,arguments);return ji(this,s)}}function Fi(c,e){for(;!Object.prototype.hasOwnProperty.call(c,e)&&(c=Le(c),c!==null););return c}function Ve(){return typeof Reflect<"u"&&Reflect.get?Ve=Reflect.get:Ve=function(e,t,i){var s=Fi(e,t);if(s){var n=Object.getOwnPropertyDescriptor(s,t);return n.get?n.get.call(arguments.length<3?e:i):n.value}},Ve.apply(this,arguments)}var Gi={type:"slider",startAt:0,perView:1,focusAt:0,gap:10,autoplay:!1,hoverpause:!0,keyboard:!0,bound:!1,swipeThreshold:80,dragThreshold:120,perSwipe:"",touchRatio:.5,touchAngle:45,animationDuration:400,rewind:!0,rewindDuration:800,animationTimingFunc:"cubic-bezier(.165, .840, .440, 1)",waitForTransition:!0,throttle:10,direction:"ltr",peek:0,cloningRatio:1,breakpoints:{},classes:{swipeable:"glide--swipeable",dragging:"glide--dragging",direction:{ltr:"glide--ltr",rtl:"glide--rtl"},type:{slider:"glide--slider",carousel:"glide--carousel"},slide:{clone:"glide__slide--clone",active:"glide__slide--active"},arrow:{disabled:"glide__arrow--disabled"},nav:{active:"glide__bullet--active"}}};function me(c){console.error("[Glide warn]: ".concat(c))}function Q(c){return parseInt(c)}function Wi(c){return parseFloat(c)}function ht(c){return typeof c=="string"}function Re(c){var e=Fe(c);return e==="function"||e==="object"&&!!c}function Ye(c){return typeof c=="function"}function Gt(c){return typeof c>"u"}function pt(c){return c.constructor===Array}function Vi(c,e,t){var i={};for(var s in e)Ye(e[s])?i[s]=e[s](c,i,t):me("Extension must be a function");for(var n in i)Ye(i[n].mount)&&i[n].mount();return i}function W(c,e,t){Object.defineProperty(c,e,t)}function Yi(c){return Object.keys(c).sort().reduce(function(e,t){return e[t]=c[t],e[t],e},{})}function ft(c,e){var t=Object.assign({},c,e);if(e.hasOwnProperty("classes")){t.classes=Object.assign({},c.classes,e.classes);var i=["direction","type","slide","arrow","nav"];i.forEach(function(s){e.classes.hasOwnProperty(s)&&(t.classes[s]=Ft(Ft({},c.classes[s]),e.classes[s]))})}return e.hasOwnProperty("breakpoints")&&(t.breakpoints=Object.assign({},c.breakpoints,e.breakpoints)),t}var Xi=(function(){function c(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Ge(this,c),this.events=e,this.hop=e.hasOwnProperty}return We(c,[{key:"on",value:function(t,i){if(pt(t)){for(var s=0;s<t.length;s++)this.on(t[s],i);return}this.hop.call(this.events,t)||(this.events[t]=[]);var n=this.events[t].push(i)-1;return{remove:function(){delete this.events[t][n]}}}},{key:"emit",value:function(t,i){if(pt(t)){for(var s=0;s<t.length;s++)this.emit(t[s],i);return}this.hop.call(this.events,t)&&this.events[t].forEach(function(n){n(i||{})})}}]),c})(),Ji=(function(){function c(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};Ge(this,c),this._c={},this._t=[],this._e=new Xi,this.disabled=!1,this.selector=e,this.settings=ft(Gi,t),this.index=this.settings.startAt}return We(c,[{key:"mount",value:function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return this._e.emit("mount.before"),Re(t)?this._c=Vi(this,t,this._e):me("You need to provide a object on `mount()`"),this._e.emit("mount.after"),this}},{key:"mutate",value:function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return pt(t)?this._t=t:me("You need to provide a array on `mutate()`"),this}},{key:"update",value:function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return this.settings=ft(this.settings,t),t.hasOwnProperty("startAt")&&(this.index=t.startAt),this._e.emit("update"),this}},{key:"go",value:function(t){return this._c.Run.make(t),this}},{key:"move",value:function(t){return this._c.Transition.disable(),this._c.Move.make(t),this}},{key:"destroy",value:function(){return this._e.emit("destroy"),this}},{key:"play",value:function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!1;return t&&(this.settings.autoplay=t),this._e.emit("play"),this}},{key:"pause",value:function(){return this._e.emit("pause"),this}},{key:"disable",value:function(){return this.disabled=!0,this}},{key:"enable",value:function(){return this.disabled=!1,this}},{key:"on",value:function(t,i){return this._e.on(t,i),this}},{key:"isType",value:function(t){return this.settings.type===t}},{key:"settings",get:function(){return this._o},set:function(t){Re(t)?this._o=t:me("Options must be an `object` instance.")}},{key:"index",get:function(){return this._i},set:function(t){this._i=Q(t)}},{key:"type",get:function(){return this.settings.type}},{key:"disabled",get:function(){return this._d},set:function(t){this._d=!!t}}]),c})();function Zi(c,e,t){var i={mount:function(){this._o=!1},make:function(d){var u=this;c.disabled||(!c.settings.waitForTransition||c.disable(),this.move=d,t.emit("run.before",this.move),this.calculate(),t.emit("run",this.move),e.Transition.after(function(){u.isStart()&&t.emit("run.start",u.move),u.isEnd()&&t.emit("run.end",u.move),u.isOffset()&&(u._o=!1,t.emit("run.offset",u.move)),t.emit("run.after",u.move),c.enable()}))},calculate:function(){var d=this.move,u=this.length,l=d.steps,h=d.direction,p=1;if(h==="="){if(c.settings.bound&&Q(l)>u){c.index=u;return}c.index=l;return}if(h===">"&&l===">"){c.index=u;return}if(h==="<"&&l==="<"){c.index=0;return}if(h==="|"&&(p=c.settings.perView||1),h===">"||h==="|"&&l===">"){var b=s(p);b>u&&(this._o=!0),c.index=n(b,p);return}if(h==="<"||h==="|"&&l==="<"){var w=r(p);w<0&&(this._o=!0),c.index=o(w,p);return}me("Invalid direction pattern [".concat(h).concat(l,"] has been used"))},isStart:function(){return c.index<=0},isEnd:function(){return c.index>=this.length},isOffset:function(){var d=arguments.length>0&&arguments[0]!==void 0?arguments[0]:void 0;return d?this._o?d==="|>"?this.move.direction==="|"&&this.move.steps===">":d==="|<"?this.move.direction==="|"&&this.move.steps==="<":this.move.direction===d:!1:this._o},isBound:function(){return c.isType("slider")&&c.settings.focusAt!=="center"&&c.settings.bound}};function s(a){var d=c.index;return c.isType("carousel")?d+a:d+(a-d%a)}function n(a,d){var u=i.length;return a<=u?a:c.isType("carousel")?a-(u+1):c.settings.rewind?i.isBound()&&!i.isEnd()?u:0:i.isBound()?u:Math.floor(u/d)*d}function r(a){var d=c.index;if(c.isType("carousel"))return d-a;var u=Math.ceil(d/a);return(u-1)*a}function o(a,d){var u=i.length;return a>=0?a:c.isType("carousel")?a+(u+1):c.settings.rewind?i.isBound()&&i.isStart()?u:Math.floor(u/d)*d:0}return W(i,"move",{get:function(){return this._m},set:function(d){var u=d.substr(1);this._m={direction:d.substr(0,1),steps:u?Q(u)?Q(u):u:0}}}),W(i,"length",{get:function(){var d=c.settings,u=e.Html.slides.length;return this.isBound()?u-1-(Q(d.perView)-1)+Q(d.focusAt):u-1}}),W(i,"offset",{get:function(){return this._o}}),i}function Wt(){return new Date().getTime()}function Xe(c,e){var t=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},i,s,n,r,o=0,a=function(){o=t.leading===!1?0:Wt(),i=null,r=c.apply(s,n),i||(s=n=null)},d=function(){var l=Wt();!o&&t.leading===!1&&(o=l);var h=e-(l-o);return s=this,n=arguments,h<=0||h>e?(i&&(clearTimeout(i),i=null),o=l,r=c.apply(s,n),i||(s=n=null)):!i&&t.trailing!==!1&&(i=setTimeout(a,h)),r};return d.cancel=function(){clearTimeout(i),o=0,i=s=n=null},d}var Je={ltr:["marginLeft","marginRight"],rtl:["marginRight","marginLeft"]};function Qi(c,e,t){var i={apply:function(n){for(var r=0,o=n.length;r<o;r++){var a=n[r].style,d=e.Direction.value;r!==0?a[Je[d][0]]="".concat(this.value/2,"px"):a[Je[d][0]]="",r!==n.length-1?a[Je[d][1]]="".concat(this.value/2,"px"):a[Je[d][1]]=""}},remove:function(n){for(var r=0,o=n.length;r<o;r++){var a=n[r].style;a.marginLeft="",a.marginRight=""}}};return W(i,"value",{get:function(){return Q(c.settings.gap)}}),W(i,"grow",{get:function(){return i.value*e.Sizes.length}}),W(i,"reductor",{get:function(){var n=c.settings.perView;return i.value*(n-1)/n}}),t.on(["build.after","update"],Xe(function(){i.apply(e.Html.wrapper.children)},30)),t.on("destroy",function(){i.remove(e.Html.wrapper.children)}),i}function Vt(c){if(c&&c.parentNode){for(var e=c.parentNode.firstChild,t=[];e;e=e.nextSibling)e.nodeType===1&&e!==c&&t.push(e);return t}return[]}function gt(c){return Array.prototype.slice.call(c)}var Ki='[data-glide-el="track"]';function es(c,e,t){var i={mount:function(){this.root=c.selector,this.track=this.root.querySelector(Ki),this.collectSlides()},collectSlides:function(){this.slides=gt(this.wrapper.children).filter(function(n){return!n.classList.contains(c.settings.classes.slide.clone)})}};return W(i,"root",{get:function(){return i._r},set:function(n){ht(n)&&(n=document.querySelector(n)),n!==null?i._r=n:me("Root element must be a existing Html node")}}),W(i,"track",{get:function(){return i._t},set:function(n){i._t=n}}),W(i,"wrapper",{get:function(){return i.track.children[0]}}),t.on("update",function(){i.collectSlides()}),i}function ts(c,e,t){var i={mount:function(){this.value=c.settings.peek}};return W(i,"value",{get:function(){return i._v},set:function(n){Re(n)?(n.before=Q(n.before),n.after=Q(n.after)):n=Q(n),i._v=n}}),W(i,"reductor",{get:function(){var n=i.value,r=c.settings.perView;return Re(n)?n.before/r+n.after/r:n*2/r}}),t.on(["resize","update"],function(){i.mount()}),i}function is(c,e,t){var i={mount:function(){this._o=0},make:function(){var n=this,r=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0;this.offset=r,t.emit("move",{movement:this.value}),e.Transition.after(function(){t.emit("move.after",{movement:n.value})})}};return W(i,"offset",{get:function(){return i._o},set:function(n){i._o=Gt(n)?0:Q(n)}}),W(i,"translate",{get:function(){return e.Sizes.slideWidth*c.index}}),W(i,"value",{get:function(){var n=this.offset,r=this.translate;return e.Direction.is("rtl")?r+n:r-n}}),t.on(["build.before","run"],function(){i.make()}),i}function ss(c,e,t){var i={setupSlides:function(){for(var n="".concat(this.slideWidth,"px"),r=e.Html.slides,o=0;o<r.length;o++)r[o].style.width=n},setupWrapper:function(){e.Html.wrapper.style.width="".concat(this.wrapperSize,"px")},remove:function(){for(var n=e.Html.slides,r=0;r<n.length;r++)n[r].style.width="";e.Html.wrapper.style.width=""}};return W(i,"length",{get:function(){return e.Html.slides.length}}),W(i,"width",{get:function(){return e.Html.track.offsetWidth}}),W(i,"wrapperSize",{get:function(){return i.slideWidth*i.length+e.Gaps.grow+e.Clones.grow}}),W(i,"slideWidth",{get:function(){return i.width/c.settings.perView-e.Peek.reductor-e.Gaps.reductor}}),t.on(["build.before","resize","update"],function(){i.setupSlides(),i.setupWrapper()}),t.on("destroy",function(){i.remove()}),i}function ns(c,e,t){var i={mount:function(){t.emit("build.before"),this.typeClass(),this.activeClass(),t.emit("build.after")},typeClass:function(){e.Html.root.classList.add(c.settings.classes.type[c.settings.type])},activeClass:function(){var n=c.settings.classes,r=e.Html.slides[c.index];r&&(r.classList.add(n.slide.active),Vt(r).forEach(function(o){o.classList.remove(n.slide.active)}))},removeClasses:function(){var n=c.settings.classes,r=n.type,o=n.slide;e.Html.root.classList.remove(r[c.settings.type]),e.Html.slides.forEach(function(a){a.classList.remove(o.active)})}};return t.on(["destroy","update"],function(){i.removeClasses()}),t.on(["resize","update"],function(){i.mount()}),t.on("move.after",function(){i.activeClass()}),i}function rs(c,e,t){var i={mount:function(){this.items=[],c.isType("carousel")&&(this.items=this.collect())},collect:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],r=e.Html.slides,o=c.settings,a=o.perView,d=o.classes,u=o.cloningRatio;if(r.length>0)for(var l=+!!c.settings.peek,h=a+l+Math.round(a/2),p=r.slice(0,h).reverse(),b=r.slice(h*-1),w=0;w<Math.max(u,Math.floor(a/r.length));w++){for(var _=0;_<p.length;_++){var g=p[_].cloneNode(!0);g.classList.add(d.slide.clone),n.push(g)}for(var y=0;y<b.length;y++){var f=b[y].cloneNode(!0);f.classList.add(d.slide.clone),n.unshift(f)}}return n},append:function(){for(var n=this.items,r=e.Html,o=r.wrapper,a=r.slides,d=Math.floor(n.length/2),u=n.slice(0,d).reverse(),l=n.slice(d*-1).reverse(),h="".concat(e.Sizes.slideWidth,"px"),p=0;p<l.length;p++)o.appendChild(l[p]);for(var b=0;b<u.length;b++)o.insertBefore(u[b],a[0]);for(var w=0;w<n.length;w++)n[w].style.width=h},remove:function(){for(var n=this.items,r=0;r<n.length;r++)e.Html.wrapper.removeChild(n[r])}};return W(i,"grow",{get:function(){return(e.Sizes.slideWidth+e.Gaps.value)*i.items.length}}),t.on("update",function(){i.remove(),i.mount(),i.append()}),t.on("build.before",function(){c.isType("carousel")&&i.append()}),t.on("destroy",function(){i.remove()}),i}var be=(function(){function c(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Ge(this,c),this.listeners=e}return We(c,[{key:"on",value:function(t,i,s){var n=arguments.length>3&&arguments[3]!==void 0?arguments[3]:!1;ht(t)&&(t=[t]);for(var r=0;r<t.length;r++)this.listeners[t[r]]=s,i.addEventListener(t[r],this.listeners[t[r]],n)}},{key:"off",value:function(t,i){var s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!1;ht(t)&&(t=[t]);for(var n=0;n<t.length;n++)i.removeEventListener(t[n],this.listeners[t[n]],s)}},{key:"destroy",value:function(){delete this.listeners}}]),c})();function os(c,e,t){var i=new be,s={mount:function(){this.bind()},bind:function(){i.on("resize",window,Xe(function(){t.emit("resize")},c.settings.throttle))},unbind:function(){i.off("resize",window)}};return t.on("destroy",function(){s.unbind(),i.destroy()}),s}var ls=["ltr","rtl"],as={">":"<","<":">","=":"="};function cs(c,e,t){var i={mount:function(){this.value=c.settings.direction},resolve:function(n){var r=n.slice(0,1);return this.is("rtl")?n.split(r).join(as[r]):n},is:function(n){return this.value===n},addClass:function(){e.Html.root.classList.add(c.settings.classes.direction[this.value])},removeClass:function(){e.Html.root.classList.remove(c.settings.classes.direction[this.value])}};return W(i,"value",{get:function(){return i._v},set:function(n){ls.indexOf(n)>-1?i._v=n:me("Direction value must be `ltr` or `rtl`")}}),t.on(["destroy","update"],function(){i.removeClass()}),t.on("update",function(){i.mount()}),t.on(["build.before","update"],function(){i.addClass()}),i}function us(c,e){return{modify:function(i){return e.Direction.is("rtl")?-i:i}}}function ds(c,e){return{modify:function(i){var s=Math.floor(i/e.Sizes.slideWidth);return i+e.Gaps.value*s}}}function hs(c,e){return{modify:function(i){return i+e.Clones.grow/2}}}function ps(c,e){return{modify:function(i){if(c.settings.focusAt>=0){var s=e.Peek.value;return Re(s)?i-s.before:i-s}return i}}}function fs(c,e){return{modify:function(i){var s=e.Gaps.value,n=e.Sizes.width,r=c.settings.focusAt,o=e.Sizes.slideWidth;return r==="center"?i-(n/2-o/2):i-o*r-s*r}}}function gs(c,e,t){var i=[ds,hs,ps,fs].concat(c._t,[us]);return{mutate:function(n){for(var r=0;r<i.length;r++){var o=i[r];Ye(o)&&Ye(o().modify)?n=o(c,e,t).modify(n):me("Transformer should be a function that returns an object with `modify()` method")}return n}}}function ms(c,e,t){var i={set:function(n){var r=gs(c,e).mutate(n),o="translate3d(".concat(-1*r,"px, 0px, 0px)");e.Html.wrapper.style.mozTransform=o,e.Html.wrapper.style.webkitTransform=o,e.Html.wrapper.style.transform=o},remove:function(){e.Html.wrapper.style.transform=""},getStartIndex:function(){var n=e.Sizes.length,r=c.index,o=c.settings.perView;return e.Run.isOffset(">")||e.Run.isOffset("|>")?n+(r-o):(r+o)%n},getTravelDistance:function(){var n=e.Sizes.slideWidth*c.settings.perView;return e.Run.isOffset(">")||e.Run.isOffset("|>")?n*-1:n}};return t.on("move",function(s){if(!c.isType("carousel")||!e.Run.isOffset())return i.set(s.movement);e.Transition.after(function(){t.emit("translate.jump"),i.set(e.Sizes.slideWidth*c.index)});var n=e.Sizes.slideWidth*e.Translate.getStartIndex();return i.set(n-e.Translate.getTravelDistance())}),t.on("destroy",function(){i.remove()}),i}function bs(c,e,t){var i=!1,s={compose:function(r){var o=c.settings;return i?"".concat(r," 0ms ").concat(o.animationTimingFunc):"".concat(r," ").concat(this.duration,"ms ").concat(o.animationTimingFunc)},set:function(){var r=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"transform";e.Html.wrapper.style.transition=this.compose(r)},remove:function(){e.Html.wrapper.style.transition=""},after:function(r){setTimeout(function(){r()},this.duration)},enable:function(){i=!1,this.set()},disable:function(){i=!0,this.set()}};return W(s,"duration",{get:function(){var r=c.settings;return c.isType("slider")&&e.Run.offset?r.rewindDuration:r.animationDuration}}),t.on("move",function(){s.set()}),t.on(["build.before","resize","translate.jump"],function(){s.disable()}),t.on("run",function(){s.enable()}),t.on("destroy",function(){s.remove()}),s}var Yt=!1;try{var Xt=Object.defineProperty({},"passive",{get:function(){Yt=!0}});window.addEventListener("testPassive",null,Xt),window.removeEventListener("testPassive",null,Xt)}catch{}var mt=Yt,Ze=["touchstart","mousedown"],Jt=["touchmove","mousemove"],Zt=["touchend","touchcancel","mouseup","mouseleave"],Qt=["mousedown","mousemove","mouseup","mouseleave"];function ys(c,e,t){var i=new be,s=0,n=0,r=0,o=!1,a=mt?{passive:!0}:!1,d={mount:function(){this.bindSwipeStart()},start:function(l){if(!o&&!c.disabled){this.disable();var h=this.touches(l);s=null,n=Q(h.pageX),r=Q(h.pageY),this.bindSwipeMove(),this.bindSwipeEnd(),t.emit("swipe.start")}},move:function(l){if(!c.disabled){var h=c.settings,p=h.touchAngle,b=h.touchRatio,w=h.classes,_=this.touches(l),g=Q(_.pageX)-n,y=Q(_.pageY)-r,f=Math.abs(g<<2),m=Math.abs(y<<2),v=Math.sqrt(f+m),k=Math.sqrt(m);if(s=Math.asin(k/v),s*180/Math.PI<p)l.stopPropagation(),e.Move.make(g*Wi(b)),e.Html.root.classList.add(w.dragging),t.emit("swipe.move");else return!1}},end:function(l){if(!c.disabled){var h=c.settings,p=h.perSwipe,b=h.touchAngle,w=h.classes,_=this.touches(l),g=this.threshold(l),y=_.pageX-n,f=s*180/Math.PI;this.enable(),y>g&&f<b?e.Run.make(e.Direction.resolve("".concat(p,"<"))):y<-g&&f<b?e.Run.make(e.Direction.resolve("".concat(p,">"))):e.Move.make(),e.Html.root.classList.remove(w.dragging),this.unbindSwipeMove(),this.unbindSwipeEnd(),t.emit("swipe.end")}},bindSwipeStart:function(){var l=this,h=c.settings,p=h.swipeThreshold,b=h.dragThreshold;p&&i.on(Ze[0],e.Html.wrapper,function(w){l.start(w)},a),b&&i.on(Ze[1],e.Html.wrapper,function(w){l.start(w)},a)},unbindSwipeStart:function(){i.off(Ze[0],e.Html.wrapper,a),i.off(Ze[1],e.Html.wrapper,a)},bindSwipeMove:function(){var l=this;i.on(Jt,e.Html.wrapper,Xe(function(h){l.move(h)},c.settings.throttle),a)},unbindSwipeMove:function(){i.off(Jt,e.Html.wrapper,a)},bindSwipeEnd:function(){var l=this;i.on(Zt,e.Html.wrapper,function(h){l.end(h)})},unbindSwipeEnd:function(){i.off(Zt,e.Html.wrapper)},touches:function(l){return Qt.indexOf(l.type)>-1?l:l.touches[0]||l.changedTouches[0]},threshold:function(l){var h=c.settings;return Qt.indexOf(l.type)>-1?h.dragThreshold:h.swipeThreshold},enable:function(){return o=!1,e.Transition.enable(),this},disable:function(){return o=!0,e.Transition.disable(),this}};return t.on("build.after",function(){e.Html.root.classList.add(c.settings.classes.swipeable)}),t.on("destroy",function(){d.unbindSwipeStart(),d.unbindSwipeMove(),d.unbindSwipeEnd(),i.destroy()}),d}function vs(c,e,t){var i=new be,s={mount:function(){this.bind()},bind:function(){i.on("dragstart",e.Html.wrapper,this.dragstart)},unbind:function(){i.off("dragstart",e.Html.wrapper)},dragstart:function(r){r.preventDefault()}};return t.on("destroy",function(){s.unbind(),i.destroy()}),s}function ws(c,e,t){var i=new be,s=!1,n=!1,r={mount:function(){this._a=e.Html.wrapper.querySelectorAll("a"),this.bind()},bind:function(){i.on("click",e.Html.wrapper,this.click)},unbind:function(){i.off("click",e.Html.wrapper)},click:function(a){n&&(a.stopPropagation(),a.preventDefault())},detach:function(){if(n=!0,!s){for(var a=0;a<this.items.length;a++)this.items[a].draggable=!1;s=!0}return this},attach:function(){if(n=!1,s){for(var a=0;a<this.items.length;a++)this.items[a].draggable=!0;s=!1}return this}};return W(r,"items",{get:function(){return r._a}}),t.on("swipe.move",function(){r.detach()}),t.on("swipe.end",function(){e.Transition.after(function(){r.attach()})}),t.on("destroy",function(){r.attach(),r.unbind(),i.destroy()}),r}var xs='[data-glide-el="controls[nav]"]',bt='[data-glide-el^="controls"]',ks="".concat(bt,' [data-glide-dir*="<"]'),_s="".concat(bt,' [data-glide-dir*=">"]');function Ss(c,e,t){var i=new be,s=mt?{passive:!0}:!1,n={mount:function(){this._n=e.Html.root.querySelectorAll(xs),this._c=e.Html.root.querySelectorAll(bt),this._arrowControls={previous:e.Html.root.querySelectorAll(ks),next:e.Html.root.querySelectorAll(_s)},this.addBindings()},setActive:function(){for(var o=0;o<this._n.length;o++)this.addClass(this._n[o].children)},removeActive:function(){for(var o=0;o<this._n.length;o++)this.removeClass(this._n[o].children)},addClass:function(o){var a=c.settings,d=o[c.index];d&&(d.classList.add(a.classes.nav.active),Vt(d).forEach(function(u){u.classList.remove(a.classes.nav.active)}))},removeClass:function(o){var a=o[c.index];a?.classList.remove(c.settings.classes.nav.active)},setArrowState:function(){if(!c.settings.rewind){var o=n._arrowControls.next,a=n._arrowControls.previous;this.resetArrowState(o,a),c.index===0&&this.disableArrow(a),c.index===e.Run.length&&this.disableArrow(o)}},resetArrowState:function(){for(var o=c.settings,a=arguments.length,d=new Array(a),u=0;u<a;u++)d[u]=arguments[u];d.forEach(function(l){gt(l).forEach(function(h){h.classList.remove(o.classes.arrow.disabled)})})},disableArrow:function(){for(var o=c.settings,a=arguments.length,d=new Array(a),u=0;u<a;u++)d[u]=arguments[u];d.forEach(function(l){gt(l).forEach(function(h){h.classList.add(o.classes.arrow.disabled)})})},addBindings:function(){for(var o=0;o<this._c.length;o++)this.bind(this._c[o].children)},removeBindings:function(){for(var o=0;o<this._c.length;o++)this.unbind(this._c[o].children)},bind:function(o){for(var a=0;a<o.length;a++)i.on("click",o[a],this.click),i.on("touchstart",o[a],this.click,s)},unbind:function(o){for(var a=0;a<o.length;a++)i.off(["click","touchstart"],o[a])},click:function(o){!mt&&o.type==="touchstart"&&o.preventDefault();var a=o.currentTarget.getAttribute("data-glide-dir");e.Run.make(e.Direction.resolve(a))}};return W(n,"items",{get:function(){return n._c}}),t.on(["mount.after","move.after"],function(){n.setActive()}),t.on(["mount.after","run"],function(){n.setArrowState()}),t.on("destroy",function(){n.removeBindings(),n.removeActive(),i.destroy()}),n}function Ts(c,e,t){var i=new be,s={mount:function(){c.settings.keyboard&&this.bind()},bind:function(){i.on("keyup",document,this.press)},unbind:function(){i.off("keyup",document)},press:function(r){var o=c.settings.perSwipe,a={ArrowRight:">",ArrowLeft:"<"};["ArrowRight","ArrowLeft"].includes(r.code)&&e.Run.make(e.Direction.resolve("".concat(o).concat(a[r.code])))}};return t.on(["destroy","update"],function(){s.unbind()}),t.on("update",function(){s.mount()}),t.on("destroy",function(){i.destroy()}),s}function Es(c,e,t){var i=new be,s={mount:function(){this.enable(),this.start(),c.settings.hoverpause&&this.bind()},enable:function(){this._e=!0},disable:function(){this._e=!1},start:function(){var r=this;this._e&&(this.enable(),c.settings.autoplay&&Gt(this._i)&&(this._i=setInterval(function(){r.stop(),e.Run.make(">"),r.start(),t.emit("autoplay")},this.time)))},stop:function(){this._i=clearInterval(this._i)},bind:function(){var r=this;i.on("mouseover",e.Html.root,function(){r._e&&r.stop()}),i.on("mouseout",e.Html.root,function(){r._e&&r.start()})},unbind:function(){i.off(["mouseover","mouseout"],e.Html.root)}};return W(s,"time",{get:function(){var r=e.Html.slides[c.index].getAttribute("data-glide-autoplay");return Q(r||c.settings.autoplay)}}),t.on(["destroy","update"],function(){s.unbind()}),t.on(["run.before","swipe.start","update"],function(){s.stop()}),t.on(["pause","destroy"],function(){s.disable(),s.stop()}),t.on(["run.after","swipe.end"],function(){s.start()}),t.on(["play"],function(){s.enable(),s.start()}),t.on("update",function(){s.mount()}),t.on("destroy",function(){i.destroy()}),s}function Kt(c){return Re(c)?Yi(c):(me("Breakpoints option must be an object"),{})}function Cs(c,e,t){var i=new be,s=c.settings,n=Kt(s.breakpoints),r=Object.assign({},s),o={match:function(d){if(typeof window.matchMedia<"u"){for(var u in d)if(d.hasOwnProperty(u)&&window.matchMedia("(max-width: ".concat(u,"px)")).matches)return d[u]}return r}};return Object.assign(s,o.match(n)),i.on("resize",window,Xe(function(){c.settings=ft(s,o.match(n))},c.settings.throttle)),t.on("update",function(){n=Kt(n),r=Object.assign({},s)}),t.on("destroy",function(){i.off("resize",window)}),o}var Ls={Html:es,Translate:ms,Transition:bs,Direction:cs,Peek:ts,Sizes:ss,Gaps:Qi,Move:is,Clones:rs,Resize:os,Build:ns,Run:Zi,Swipe:ys,Images:vs,Anchors:ws,Controls:Ss,Keyboard:Ts,Autoplay:Es,Breakpoints:Cs},Rs=(function(c){Hi(t,c);var e=Bi(t);function t(){return Ge(this,t),e.apply(this,arguments)}return We(t,[{key:"mount",value:function(){var s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return Ve(Le(t.prototype),"mount",this).call(this,Object.assign({},Ls,s))}}]),t})(Ji);function yt(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}let ke=yt();function ei(c){ke=c}const qe={exec:()=>null};function B(c,e=""){let t=typeof c=="string"?c:c.source;const i={replace:(s,n)=>{let r=typeof n=="string"?n:n.source;return r=r.replace(ie.caret,"$1"),t=t.replace(s,r),i},getRegex:()=>new RegExp(t,e)};return i}const ie={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] /,listReplaceTask:/^\[[ xX]\] +/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:c=>new RegExp(`^( {0,3}${c})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:c=>new RegExp(`^ {0,${Math.min(3,c-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:c=>new RegExp(`^ {0,${Math.min(3,c-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:c=>new RegExp(`^ {0,${Math.min(3,c-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:c=>new RegExp(`^ {0,${Math.min(3,c-1)}}#`),htmlBeginRegex:c=>new RegExp(`^ {0,${Math.min(3,c-1)}}<(?:[a-z].*>|!--)`,"i")},Ms=/^(?:[ \t]*(?:\n|$))+/,As=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,qs=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,Pe=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Ps=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,vt=/(?:[*+-]|\d{1,9}[.)])/,ti=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,ii=B(ti).replace(/bull/g,vt).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),Is=B(ti).replace(/bull/g,vt).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),wt=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,Os=/^[^\n]+/,xt=/(?!\s*\])(?:\\.|[^\[\]\\])+/,$s=B(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",xt).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Ns=B(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,vt).getRegex(),Qe="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",kt=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,Ds=B("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",kt).replace("tag",Qe).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),si=B(wt).replace("hr",Pe).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Qe).getRegex(),_t={blockquote:B(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",si).getRegex(),code:As,def:$s,fences:qs,heading:Ps,hr:Pe,html:Ds,lheading:ii,list:Ns,newline:Ms,paragraph:si,table:qe,text:Os},ni=B("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",Pe).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Qe).getRegex(),Hs={..._t,lheading:Is,table:ni,paragraph:B(wt).replace("hr",Pe).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",ni).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Qe).getRegex()},zs={..._t,html:B(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",kt).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:qe,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:B(wt).replace("hr",Pe).replace("heading",` *#{1,6} *[^
28
28
  ]`).replace("lheading",ii).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},Us=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,js=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,ri=/^( {2,}|\\)\n(?!\s*$)/,Bs=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,Ke=/[\p{P}\p{S}]/u,St=/[\s\p{P}\p{S}]/u,oi=/[^\s\p{P}\p{S}]/u,Fs=B(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,St).getRegex(),li=/(?!~)[\p{P}\p{S}]/u,Gs=/(?!~)[\s\p{P}\p{S}]/u,Ws=/(?:[^\s\p{P}\p{S}]|~)/u,Vs=/\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g,ai=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,Ys=B(ai,"u").replace(/punct/g,Ke).getRegex(),Xs=B(ai,"u").replace(/punct/g,li).getRegex(),ci="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",Js=B(ci,"gu").replace(/notPunctSpace/g,oi).replace(/punctSpace/g,St).replace(/punct/g,Ke).getRegex(),Zs=B(ci,"gu").replace(/notPunctSpace/g,Ws).replace(/punctSpace/g,Gs).replace(/punct/g,li).getRegex(),Qs=B("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,oi).replace(/punctSpace/g,St).replace(/punct/g,Ke).getRegex(),Ks=B(/\\(punct)/,"gu").replace(/punct/g,Ke).getRegex(),en=B(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),tn=B(kt).replace("(?:-->|$)","-->").getRegex(),sn=B("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",tn).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),et=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,nn=B(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",et).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),ui=B(/^!?\[(label)\]\[(ref)\]/).replace("label",et).replace("ref",xt).getRegex(),di=B(/^!?\[(ref)\](?:\[\])?/).replace("ref",xt).getRegex(),rn=B("reflink|nolink(?!\\()","g").replace("reflink",ui).replace("nolink",di).getRegex(),Tt={_backpedal:qe,anyPunctuation:Ks,autolink:en,blockSkip:Vs,br:ri,code:js,del:qe,emStrongLDelim:Ys,emStrongRDelimAst:Js,emStrongRDelimUnd:Qs,escape:Us,link:nn,nolink:di,punctuation:Fs,reflink:ui,reflinkSearch:rn,tag:sn,text:Bs,url:qe},on={...Tt,link:B(/^!?\[(label)\]\((.*?)\)/).replace("label",et).getRegex(),reflink:B(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",et).getRegex()},Et={...Tt,emStrongRDelimAst:Zs,emStrongLDelim:Xs,url:B(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,"i").replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\.|[^\\])*?(?:\\.|[^\s~\\]))\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},ln={...Et,br:B(ri).replace("{2,}","*").getRegex(),text:B(Et.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},tt={normal:_t,gfm:Hs,pedantic:zs},Ie={normal:Tt,gfm:Et,breaks:ln,pedantic:on},an={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},hi=c=>an[c];function de(c,e){if(e){if(ie.escapeTest.test(c))return c.replace(ie.escapeReplace,hi)}else if(ie.escapeTestNoEncode.test(c))return c.replace(ie.escapeReplaceNoEncode,hi);return c}function pi(c){try{c=encodeURI(c).replace(ie.percentDecode,"%")}catch{return null}return c}function fi(c,e){const t=c.replace(ie.findPipe,(n,r,o)=>{let a=!1,d=r;for(;--d>=0&&o[d]==="\\";)a=!a;return a?"|":" |"}),i=t.split(ie.splitPipe);let s=0;if(i[0].trim()||i.shift(),i.length>0&&!i.at(-1)?.trim()&&i.pop(),e)if(i.length>e)i.splice(e);else for(;i.length<e;)i.push("");for(;s<i.length;s++)i[s]=i[s].trim().replace(ie.slashPipe,"|");return i}function Oe(c,e,t){const i=c.length;if(i===0)return"";let s=0;for(;s<i&&c.charAt(i-s-1)===e;)s++;return c.slice(0,i-s)}function cn(c,e){if(c.indexOf(e[1])===-1)return-1;let t=0;for(let i=0;i<c.length;i++)if(c[i]==="\\")i++;else if(c[i]===e[0])t++;else if(c[i]===e[1]&&(t--,t<0))return i;return t>0?-2:-1}function gi(c,e,t,i,s){const n=e.href,r=e.title||null,o=c[1].replace(s.other.outputLinkReplace,"$1");i.state.inLink=!0;const a={type:c[0].charAt(0)==="!"?"image":"link",raw:t,href:n,title:r,text:o,tokens:i.inlineTokens(o)};return i.state.inLink=!1,a}function un(c,e,t){const i=c.match(t.other.indentCodeCompensation);if(i===null)return e;const s=i[1];return e.split(`
29
29
  `).map(n=>{const r=n.match(t.other.beginningSpace);if(r===null)return n;const[o]=r;return o.length>=s.length?n.slice(s.length):n}).join(`
30
30
  `)}class it{options;rules;lexer;constructor(e){this.options=e||ke}space(e){const t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}code(e){const t=this.rules.block.code.exec(e);if(t){const i=t[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:t[0],codeBlockStyle:"indented",text:this.options.pedantic?i:Oe(i,`
@@ -41,11 +41,11 @@ ${l}`:l;const h=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.block
41
41
  `+i.join(`
42
42
  `),_=this.list(w);r[r.length-1]=_,s=s.substring(0,s.length-p.raw.length)+_.raw,n=n.substring(0,n.length-b.raw.length)+_.raw,i=w.substring(r.at(-1).raw.length).split(`
43
43
  `);continue}}return{type:"blockquote",raw:s,tokens:r,text:n}}}list(e){let t=this.rules.block.list.exec(e);if(t){let i=t[1].trim();const s=i.length>1,n={type:"list",raw:"",ordered:s,start:s?+i.slice(0,-1):"",loose:!1,items:[]};i=s?`\\d{1,9}\\${i.slice(-1)}`:`\\${i}`,this.options.pedantic&&(i=s?i:"[*+-]");const r=this.rules.other.listItemRegex(i);let o=!1;for(;e;){let d=!1,u="",l="";if(!(t=r.exec(e))||this.rules.block.hr.test(e))break;u=t[0],e=e.substring(u.length);let h=t[2].split(`
44
- `,1)[0].replace(this.rules.other.listReplaceTabs,v=>" ".repeat(3*v.length)),p=e.split(`
44
+ `,1)[0].replace(this.rules.other.listReplaceTabs,y=>" ".repeat(3*y.length)),p=e.split(`
45
45
  `,1)[0],b=!h.trim(),w=0;if(this.options.pedantic?(w=2,l=h.trimStart()):b?w=t[1].length+1:(w=t[2].search(this.rules.other.nonSpaceChar),w=w>4?1:w,l=h.slice(w),w+=t[1].length),b&&this.rules.other.blankLine.test(p)&&(u+=p+`
46
- `,e=e.substring(p.length+1),d=!0),!d){const v=this.rules.other.nextBulletRegex(w),f=this.rules.other.hrRegex(w),m=this.rules.other.fencesBeginRegex(w),y=this.rules.other.headingBeginRegex(w),k=this.rules.other.htmlBeginRegex(w);for(;e;){const x=e.split(`
47
- `,1)[0];let S;if(p=x,this.options.pedantic?(p=p.replace(this.rules.other.listReplaceNesting," "),S=p):S=p.replace(this.rules.other.tabCharGlobal," "),m.test(p)||y.test(p)||k.test(p)||v.test(p)||f.test(p))break;if(S.search(this.rules.other.nonSpaceChar)>=w||!p.trim())l+=`
48
- `+S.slice(w);else{if(b||h.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||m.test(h)||y.test(h)||f.test(h))break;l+=`
46
+ `,e=e.substring(p.length+1),d=!0),!d){const y=this.rules.other.nextBulletRegex(w),f=this.rules.other.hrRegex(w),m=this.rules.other.fencesBeginRegex(w),v=this.rules.other.headingBeginRegex(w),k=this.rules.other.htmlBeginRegex(w);for(;e;){const x=e.split(`
47
+ `,1)[0];let S;if(p=x,this.options.pedantic?(p=p.replace(this.rules.other.listReplaceNesting," "),S=p):S=p.replace(this.rules.other.tabCharGlobal," "),m.test(p)||v.test(p)||k.test(p)||y.test(p)||f.test(p))break;if(S.search(this.rules.other.nonSpaceChar)>=w||!p.trim())l+=`
48
+ `+S.slice(w);else{if(b||h.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||m.test(h)||v.test(h)||f.test(h))break;l+=`
49
49
  `+p}!b&&!p.trim()&&(b=!0),u+=x+`
50
50
  `,e=e.substring(x.length+1),h=S.slice(w)}}n.loose||(o?n.loose=!0:this.rules.other.doubleBlankLine.test(u)&&(o=!0));let _=null,g;this.options.gfm&&(_=this.rules.other.listIsTask.exec(l),_&&(g=_[0]!=="[ ] ",l=l.replace(this.rules.other.listReplaceTask,""))),n.items.push({type:"list_item",raw:u,task:!!_,checked:g,loose:!1,text:l,tokens:[]}),n.raw+=u}const a=n.items.at(-1);if(a)a.raw=a.raw.trimEnd(),a.text=a.text.trimEnd();else return;n.raw=n.raw.trimEnd();for(let d=0;d<n.items.length;d++)if(this.lexer.state.top=!1,n.items[d].tokens=this.lexer.blockTokens(n.items[d].text,[]),!n.loose){const u=n.items[d].tokens.filter(h=>h.type==="space"),l=u.length>0&&u.some(h=>this.rules.other.anyLine.test(h.raw));n.loose=l}if(n.loose)for(let d=0;d<n.items.length;d++)n.items[d].loose=!0;return n}}html(e){const t=this.rules.block.html.exec(e);if(t)return{type:"html",block:!0,raw:t[0],pre:t[1]==="pre"||t[1]==="script"||t[1]==="style",text:t[0]}}def(e){const t=this.rules.block.def.exec(e);if(t){const i=t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),s=t[2]?t[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",n=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):t[3];return{type:"def",tag:i,raw:t[0],href:s,title:n}}}table(e){const t=this.rules.block.table.exec(e);if(!t||!this.rules.other.tableDelimiter.test(t[2]))return;const i=fi(t[1]),s=t[2].replace(this.rules.other.tableAlignChars,"").split("|"),n=t[3]?.trim()?t[3].replace(this.rules.other.tableRowBlankLine,"").split(`
51
51
  `):[],r={type:"table",raw:t[0],header:[],align:[],rows:[]};if(i.length===s.length){for(const o of s)this.rules.other.tableAlignRight.test(o)?r.align.push("right"):this.rules.other.tableAlignCenter.test(o)?r.align.push("center"):this.rules.other.tableAlignLeft.test(o)?r.align.push("left"):r.align.push(null);for(let o=0;o<i.length;o++)r.header.push({text:i[o],tokens:this.lexer.inline(i[o]),header:!0,align:r.align[o]});for(const o of n)r.rows.push(fi(o,r.header.length).map((a,d)=>({text:a,tokens:this.lexer.inline(a),header:!1,align:r.align[d]})));return r}}lheading(e){const t=this.rules.block.lheading.exec(e);if(t)return{type:"heading",raw:t[0],depth:t[2].charAt(0)==="="?1:2,text:t[1],tokens:this.lexer.inline(t[1])}}paragraph(e){const t=this.rules.block.paragraph.exec(e);if(t){const i=t[1].charAt(t[1].length-1)===`
@@ -258,16 +258,16 @@ Check the information and return the details.
258
258
  `,n+=`![](${u.url})`,r.push(u.url),o.push(u.file_url),d=!0)}),d&&(s=`<div class="image-container">${s}</div>`)}else typeof e=="string"&&(s=`
259
259
  <p>
260
260
  ${e}
261
- </p>`,n=e);return i?(t.innerHTML="",t.remove()):(t.innerHTML=s,this.builder.outputHtml+=`<div class="result-container">${s}</div>`),{markdown:n,output:r,output2:o}}async generateReplicate(e,t,i){let s,n={};const r="replicate";if(e.text_to_image_generation){let a=this.validateModel(e.model,r,"text_to_image_generation");if(!a)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};let d=e.prompt;if(!d)return{mediaGenerated:!1,status:"error",message:this.out("Please input a prompt.")};let u=e.aspect_ratio||"16:9",l=e.num_images||1;l>4&&(l=4),s={prompt:d,aspect_ratio:u,num_outputs:l},n.model=a,n.customData=this.builder.settings.customData}else if(e.edit_area_in_image){let a=this.validateModel(e.model,l,"edit_area_in_image");if(!a)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};let d=e.prompt;if(!d)return{mediaGenerated:!1,status:"error",message:this.out("Please input a prompt.")};if(!e.image_url)return{mediaGenerated:!1,status:"error",message:this.out("Image reference not found.")};let l="replicate";const h=await this.builder.upload.getInputURLs(l,!0);if(h.error)return{mediaGenerated:!1,status:"error",message:h.error};let p=h[e.image_url],b=h[e.image_url+"_mask"];if(!b)return{mediaGenerated:!1,status:"error",message:this.out("Image mask not found.")};s={prompt:d,image:p,mask:b},n.model=a,n.customData=this.builder.settings.customData}else if(e.text_to_digital_illustration_generation){let a=this.validateModel(e.model,r,"text_to_digital_illustration_generation");if(!a)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};let d=e.prompt;if(!d)return{mediaGenerated:!1,status:"error",message:this.out("Please input a prompt.")};let u=e.width||1280,l=e.height||768;e.num_images,s={prompt:d,size:`${u}x${l}`,style:"digital_illustration"},n.model=a,n.customData=this.builder.settings.customData}else if(e.upscale_image){let a=this.validateModel(e.model,u,"upscale_image");if(!a)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};if(!e.image_url)return{mediaGenerated:!1,status:"error",message:this.out("Image reference not found.")};let u="replicate";const l=await this.builder.upload.getInputURLs(u);if(l.error)return{mediaGenerated:!1,status:"error",message:l.error};let h=l[e.image_url];if(!h)return{mediaGenerated:!1,status:"error",message:this.out("Image not provided.")};s={image:h},n.model=a,n.customData=this.builder.settings.customData}else if(e.describe_image){let a=this.validateModel(e.model,l,"describe_image");if(!a)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};let d=e.prompt;if(!d)return{mediaGenerated:!1,status:"error",message:this.out("Please input a prompt.")};if(!e.image_url)return{mediaGenerated:!1,status:"error",message:this.out("Image reference not found.")};let l="replicate";const h=await this.builder.upload.getInputURLs(l);if(h.error)return{mediaGenerated:!1,status:"error",message:h.error};let p=h[e.image_url];if(!p)return{mediaGenerated:!1,status:"error",message:this.out("Image not provided.")};s={image:p,prompt:`${d}. No talk. Answer only.`},n.model=a,n.customData=this.builder.settings.customData}else if(e.image_to_video_generation){let a=this.validateModel(e.model,l,"image_to_video_generation");if(!a)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};let d=e.prompt||"stunning video",u=e.duration||5;u>10&&(u=5);let l="replicate";const h=await this.builder.upload.getInputURLs(l);if(h.error)return{mediaGenerated:!1,status:"error",message:h.error};let p=h[e.image_url];if(!p)return{mediaGenerated:!1,status:"error",message:this.out("Image reference not found.")};a==="kwaivgi/kling-v1.6-pro"&&(s={start_image:p,prompt:d,duration:u}),a==="kwaivgi/kling-v1.6-standard"&&(s={start_image:p,prompt:d,duration:u}),a==="minimax/video-01-live"&&(s={first_frame_image:p,prompt:d}),a==="luma/ray"&&(s={start_image_url:p,prompt:d}),n.model=a,n.customData=this.builder.settings.customData}else if(e.text_to_video_generation){let a=this.validateModel(e.model,r,"text_to_video_generation");if(!a)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};let d=e.prompt;if(!d)return{mediaGenerated:!1,status:"error",message:this.out("Please input a prompt.")};let u=e.duration||5;u>10&&(u=5),a==="kwaivgi/kling-v1.6-standard"&&(s={prompt:d,duration:u}),a==="minimax/video-01"&&(s={prompt:d}),a==="luma/ray"&&(s={prompt:d}),n.model=a,n.customData=this.builder.settings.customData}else if(e.text_to_speech){let a=this.validateModel(e.model,r,"text_to_speech");if(!a)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};if(e.text.length>this.builder.settings.ttsMaxCharacters)return{mediaGenerated:!1,status:"error",message:this.out("The text exceeds the allowed limit.")};s={text:e.text,voice:e.voice||"af_nicole",speed:parseFloat(e.speed)||1},n.model=a,n.customData=this.builder.settings.customData}if(n.model.indexOf(":")!==-1){const d=n.model.split(":")[1];n.version=d;let u=this.builder.settings.replicateEndpoint1;n.endpoint=u,n.payload=s,this.builder.settings.consoleLog&&console.log("PAYLOAD 1")}else{let a=this.builder.settings.replicateEndpoint2;a=a.replace("{MODEL}",n.model),n.endpoint=a,n.payload=s,this.builder.settings.consoleLog&&console.log("PAYLOAD 2")}this.builder.payloads.push(n),this.builder.settings.consoleLog&&console.log(n);let o=!1;if(this.builder.settings.generateMediaUrl_Replicate&&(o=!0),o){let a=this.builder.settings.generateMediaUrl_Replicate;if(!a)return{mediaGenerated:!1,status:"error",message:this.out("Endpoint not configured.")};let d,u={"Content-Type":"application/json",...this.builder.settings.headers},h=await(await fetch(a,{signal:this.builder.mediaSignal,method:"POST",headers:u,body:JSON.stringify(n)})).json();if(h.ok){if(d=h.data.id,!d)return{mediaGenerated:!1,status:"error",message:h.data&&h.data.detail}}else return{mediaGenerated:!1,status:"error",message:h.error};const p=this.waitingReplicate(n,d,t,i);return this.builder.isMediaGenerating=!1,p}else{let a=this.builder.settings.generateMediaUrl;if(!a)return{mediaGenerated:!1,status:"error",message:this.out("Endpoint not configured: generateMediaUrl.")};let d={"Content-Type":"application/json",...this.builder.settings.headers};const l=await(await fetch(a,{signal:this.builder.mediaSignal,method:"POST",headers:d,body:JSON.stringify(n)})).json();if(this.builder.isMediaGenerating=!1,l.error)return this.builder.settings.consoleLog&&console.log(l.error),{mediaGenerated:!1,status:"error",message:l.error};{const h=l.data;let p=this.renderResult(h,t,i);return{mediaGenerated:!0,status:"success",markdown:p.markdown,output:p.output,output2:p.output2}}}}async generateOpenAI(e,t,i){let s,n={},o=this.validateModel(e.model,"openai","image_generation"),a=e.prompt;if(!a)return{mediaGenerated:!1,status:"error",message:this.out("Please input a prompt.")};const d=new FormData;d.append("customData",JSON.stringify(this.builder.settings.customData)),d.append("model",o),d.append("prompt",a);let u=!1,l=this.builder.getFormValues();for(const f of l){if(f.value instanceof FileList&&f.type==="multifile"){const m=f.value;if(m.length>0)for(const y of m)d.append("file[]",y),u=!0}if(f.value instanceof FileList&&f.type==="file"){const m=f.value;if(m.length>0){const y=m[0];d.append("file[]",y),u=!0}}if(typeof f.value=="string"&&f.value.indexOf("base64")!==-1){let m=f.value.replace(/^data:image\/(png|svg\+xml|jpeg|gif|webp);base64,/,"");d.append("mask",m)}}if(this.builder.selectedFiles&&this.builder.selectedFiles.length>0)for(let f=0;f<this.builder.selectedFiles.length;f++){const m=this.builder.selectedFiles[f];d.append("file[]",m),u=!0}let h,p=e.size||"auto",b=e.quality||"auto",w=e.num_images||1;if(u){d.append("size",p),d.append("n",w),d.append("quality",b),s={prompt:a,size:p,quality:b,n:w},n.model=o,n.customData=this.builder.settings.customData,n.payload=s,this.builder.payloads.push(n);let f=this.builder.settings.generateMediaUrl_OpenAI_CreateImageEdit;h=await fetch(f,{method:"POST",body:d})}else{let f=e.background||"auto",m=e.output_format||"png";s={prompt:a,background:f,output_format:m,size:p,quality:b,n:w},n.model=o,n.customData=this.builder.settings.customData,n.payload=s,this.builder.payloads.push(n),this.builder.settings.consoleLog&&console.log(n);const y=this.builder.settings.generateMediaUrl_OpenAI_CreateImage;let k={"Content-Type":"application/json",...this.builder.settings.headers};h=await fetch(y,{signal:this.builder.mediaSignal,method:"POST",headers:k,body:JSON.stringify(n)})}const _=await h.json();this.builder.settings.consoleLog&&console.log(_),this.builder.isMediaGenerating=!1;const g=_.data;this.builder.output.push(_);let v=this.renderResult(g,t,i);return{mediaGenerated:!0,status:"success",markdown:v.markdown,output:v.output,output2:v.output2}}async generateGoogle(e,t,i){let s,n={},o=this.validateModel(e.model,"google","edit_area_in_image");if(!o)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};let a=e.prompt;if(!a)return{mediaGenerated:!1,status:"error",message:this.out("Please input a prompt.")};let d=[];d.push({text:a});let u=this.builder.getFormValues();if(!(u&&Object.keys(u).length===0)){for(const g of u)if(g.value instanceof FileList&&g.type==="multifile"){const v=g.value;if(v.length>0)for(const f of v){const m=await new Promise((y,k)=>{const x=new FileReader;x.onload=S=>{const E=S.target.result.split(",")[1];y(E)},x.onerror=k,x.readAsDataURL(f)});d.push({inlineData:{mimeType:"image/png",data:m}})}}}s={contents:d},n.model=o,n.customData=this.builder.settings.customData,n.payload=s,this.builder.payloads.push(n),this.builder.settings.consoleLog&&console.log(n);const l=this.builder.settings.generateMediaUrl_Google;let h={"Content-Type":"application/json",...this.builder.settings.headers};const b=await(await fetch(l,{signal:this.builder.mediaSignal,method:"POST",headers:h,body:JSON.stringify(n)})).json();this.builder.settings.consoleLog&&console.log(b),this.builder.isMediaGenerating=!1;const w=b.data;let _=this.renderResult(w,t,i);return{mediaGenerated:!0,status:"success",markdown:_.markdown,output:_.output,output2:_.output2}}async generateFal(e,t,i){let s="fal",n,r={};if(e.text_to_image_generation){let b=this.validateModel(e.model,s,"text_to_image_generation");if(!b)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};let w=e.prompt;if(!w)return{mediaGenerated:!1,status:"error",message:this.out("Please input a prompt.")};let _=e.width||1280,g=e.height||768,v=e.aspect_ratio,f=e.num_images||1;if(f>4&&(f=4),v){let{w:U,h:G}=this.getDimension(v);_=U,g=G}let m=e.color1_red,y=e.color1_green,k=e.color1_blue,x=e.color2_red,S=e.color2_green,E=e.color2_blue,C=e.color3_red,A=e.color3_green,L=e.color3_blue,D=e.color4_red,I=e.color4_green,O=e.color4_blue,R=e.color5_red,q=e.color5_green,M=e.color5_blue,T=[];m&&y&&k&&!(m==="0"&&y==="0"&&k==="0")&&T.push({r:m,g:y,b:k}),x&&S&&E&&!(x==="0"&&S==="0"&&E==="0")&&T.push({r:x,g:S,b:E}),C&&A&&L&&!(C==="0"&&A==="0"&&L==="0")&&T.push({r:C,g:A,b:L}),D&&I&&O&&!(D==="0"&&I==="0"&&O==="0")&&T.push({r:D,g:I,b:O}),R&&q&&M&&!(R==="0"&&q==="0"&&M==="0")&&T.push({r:R,g:q,b:M});let N=await(async()=>{let U=[],G=this.builder.getFormValues();for(const Y of G)if(Y.value instanceof FileList&&Y.type==="multifile"){const he=Y.value;if(he.length>0){let re=0;for(const ye of he){re++;const Me=new FormData;Me.append("file",ye),Me.append("customData",this.builder.settings.customData);let $e=this.builder.settings.uploadMediaUrl_Fal;const Ne=await(await fetch($e,{method:"POST",body:Me})).json();if(Ne.ok){const De=Ne.url;U.push(De),this.builder.filesUploaded["file_"+re]=De}}}}return U})();n={prompt:w,image_size:{width:_,height:g},num_images:f},b.indexOf("gemini")!==-1&&(n={prompt:w,input_image_urls:N}),b==="fal-ai/ideogram/v2a"&&(v=this.getClosestAspectRatio(_,g),n={prompt:w,aspect_ratio:v,num_images:f}),b.indexOf("recraft")!==-1&&(n={prompt:w,image_size:{width:_,height:g},num_images:f,colors:T}),r.model=b,r.customData=this.builder.settings.customData}else if(e.edit_area_in_image){let b=this.validateModel(e.model,s,"edit_area_in_image");if(!b)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};let w=e.prompt;if(!w)return{mediaGenerated:!1,status:"error",message:this.out("Please input a prompt.")};if(!e.image_url)return{mediaGenerated:!1,status:"error",message:this.out("Image reference not found.")};const g=await this.builder.upload.getInputURLs(s);if(g.error)return{mediaGenerated:!1,status:"error",message:g.error};let v=g[e.image_url],f=g[e.image_url+"_mask"];if(n={image_url:v,mask_url:f,prompt:w},r.model=b,!f){n={image_url:v,prompt:w};let m=this.validateModel(e.model,s,"edit_image");r.model=m}r.customData=this.builder.settings.customData}else if(e.text_to_2d_illustration_generation){let b=this.validateModel(e.model,s,"text_to_2d_illustration_generation");if(!b)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};let w=e.prompt;if(!w)return{mediaGenerated:!1,status:"error",message:this.out("Please input a prompt.")};let _=e.width||1280,g=e.height||768,v=e.num_images||1;v>4&&(v=4);let f=e.style||"any",m=e.style_id||this.builder.settings._2dIllustrationStyleId,y=e.color1_red,k=e.color1_green,x=e.color1_blue,S=e.color2_red,E=e.color2_green,C=e.color2_blue,A=e.color3_red,L=e.color3_green,D=e.color3_blue,I=e.color4_red,O=e.color4_green,R=e.color4_blue,q=e.color5_red,M=e.color5_green,T=e.color5_blue,$=[];y&&k&&x&&!(y==="0"&&k==="0"&&x==="0")&&$.push({r:y,g:k,b:x}),S&&E&&C&&!(S==="0"&&E==="0"&&C==="0")&&$.push({r:S,g:E,b:C}),A&&L&&D&&!(A==="0"&&L==="0"&&D==="0")&&$.push({r:A,g:L,b:D}),I&&O&&R&&!(I==="0"&&O==="0"&&R==="0")&&$.push({r:I,g:O,b:R}),q&&M&&T&&!(q==="0"&&M==="0"&&T==="0")&&$.push({r:q,g:M,b:T}),n={prompt:w,image_size:{width:_,height:g},num_images:v,style:f,style_id:m,colors:$},r.model=b,r.customData=this.builder.settings.customData}else if(e.text_to_digital_illustration_generation){let b=this.validateModel(e.model,s,"text_to_digital_illustration_generation");if(!b)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};let w=e.prompt;if(!w)return{mediaGenerated:!1,status:"error",message:this.out("Please input a prompt.")};let _=e.width||1280,g=e.height||768,v=e.num_images||1;v>4&&(v=4);let f=e.style||"digital_illustration",m=e.color1_red,y=e.color1_green,k=e.color1_blue,x=e.color2_red,S=e.color2_green,E=e.color2_blue,C=e.color3_red,A=e.color3_green,L=e.color3_blue,D=e.color4_red,I=e.color4_green,O=e.color4_blue,R=e.color5_red,q=e.color5_green,M=e.color5_blue,T=[];m&&y&&k&&!(m==="0"&&y==="0"&&k==="0")&&T.push({r:m,g:y,b:k}),x&&S&&E&&!(x==="0"&&S==="0"&&E==="0")&&T.push({r:x,g:S,b:E}),C&&A&&L&&!(C==="0"&&A==="0"&&L==="0")&&T.push({r:C,g:A,b:L}),D&&I&&O&&!(D==="0"&&I==="0"&&O==="0")&&T.push({r:D,g:I,b:O}),R&&q&&M&&!(R==="0"&&q==="0"&&M==="0")&&T.push({r:R,g:q,b:M}),n={prompt:w,image_size:{width:_,height:g},num_images:v,style:f,colors:T},r.model=b,r.customData=this.builder.settings.customData}else if(e.text_to_book_cover_generation){let b=this.validateModel(e.model,s,"text_to_book_cover_generation");if(!b)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};let w=e.prompt;if(!w)return{mediaGenerated:!1,status:"error",message:this.out("Please input a prompt.")};let _=e.width||1024,g=e.height||1365,v=e.num_images||1;v>4&&(v=1);let f="digital_illustration/cover",m=e.color1_red,y=e.color1_green,k=e.color1_blue,x=e.color2_red,S=e.color2_green,E=e.color2_blue,C=e.color3_red,A=e.color3_green,L=e.color3_blue,D=e.color4_red,I=e.color4_green,O=e.color4_blue,R=e.color5_red,q=e.color5_green,M=e.color5_blue,T=[];m&&y&&k&&!(m==="0"&&y==="0"&&k==="0")&&T.push({r:m,g:y,b:k}),x&&S&&E&&!(x==="0"&&S==="0"&&E==="0")&&T.push({r:x,g:S,b:E}),C&&A&&L&&!(C==="0"&&A==="0"&&L==="0")&&T.push({r:C,g:A,b:L}),D&&I&&O&&!(D==="0"&&I==="0"&&O==="0")&&T.push({r:D,g:I,b:O}),R&&q&&M&&!(R==="0"&&q==="0"&&M==="0")&&T.push({r:R,g:q,b:M}),n={prompt:w,image_size:{width:_,height:g},num_images:v,style:f,colors:T},r.model=b,r.customData=this.builder.settings.customData}else if(e.upscale_image){let b=this.validateModel(e.model,s,"upscale_image");if(!b)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};if(!e.image_url)return{mediaGenerated:!1,status:"error",message:this.out("Image reference not found.")};const _=await this.builder.upload.getInputURLs(s);if(_.error)return{mediaGenerated:!1,status:"error",message:_.error};let g=_[e.image_url];if(!g)return{mediaGenerated:!1,status:"error",message:this.out("Image not provided.")};n={image_url:g,upscale_factor:2},r.model=b,r.customData=this.builder.settings.customData}else if(e.describe_image){let b=this.validateModel(e.model,s,"describe_image");if(!b)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};let w=e.prompt;if(!w)return{mediaGenerated:!1,status:"error",message:this.out("Please input a prompt.")};if(!e.image_url)return{mediaGenerated:!1,status:"error",message:this.out("Image reference not found.")};const g=await this.builder.upload.getInputURLs(s);if(g.error)return{mediaGenerated:!1,status:"error",message:g.error};let v=g[e.image_url];if(!v)return{mediaGenerated:!1,status:"error",message:this.out("Image not provided.")};n={image_url:v,prompt:`${w}. No talk. Answer only.`},r.model=b,r.customData=this.builder.settings.customData}else if(e.image_to_video_generation){let b=this.validateModel(e.model,s,"image_to_video_generation");if(!b)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};let w=e.prompt;w=e.prompt||"stunning video";let _=e.duration||5;_>10&&(_=5);const g=await this.builder.upload.getInputURLs(s);if(g.error)return{mediaGenerated:!1,status:"error",message:g.error};let v=g[e.image_url];if(!v)return{mediaGenerated:!1,status:"error",message:this.out("Image reference not found.")};n={prompt:w,image_url:v,duration:_,aspect_ratio:"16:9"},b.indexOf("fal-ai/luma-dream-machine")!==-1&&delete n.duration,r.model=b,r.customData=this.builder.settings.customData}else if(e.text_to_video_generation){let b=this.validateModel(e.model,s,"text_to_video_generation");if(!b)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};let w=e.prompt;if(!w)return{mediaGenerated:!1,status:"error",message:this.out("Please input a prompt.")};let _=e.duration||5;_>10&&(_=5),n={prompt:w,duration:_,aspect_ratio:"16:9"},b.indexOf("fal-ai/luma-dream-machine")!==-1&&delete n.duration,r.model=b,r.customData=this.builder.settings.customData}else if(e.text_to_speech){let b=this.validateModel(e.model,s,"text_to_speech");if(!b)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};if(e.text.length>this.builder.settings.ttsMaxCharacters)return{mediaGenerated:!1,status:"error",message:this.out("The text exceeds the allowed limit.")};n={text:e.text,voice:e.voice||"Matilda"},r.model=b,r.customData=this.builder.settings.customData}let o=`https://queue.fal.run/${r.model}`;r.endpoint=o,r.payload=n,this.builder.payloads.push(r),this.builder.settings.consoleLog&&console.log(r);let a=this.builder.settings.generateMediaUrl_Fal;if(!a)return{mediaGenerated:!1,status:"error",message:this.out("Endpoint not configured: generateMediaUrl_Fal.")};let d,u={"Content-Type":"application/json",...this.builder.settings.headers},h=await(await fetch(a,{signal:this.builder.mediaSignal,method:"POST",headers:u,body:JSON.stringify(r)})).json();if(h.ok)d=h.request_id;else return{mediaGenerated:!1,status:"error",message:h.error};const p=this.waitingFal(r,d,t,i);return this.builder.isMediaGenerating=!1,p}validateModel(e,t,i){const n=this.builder.settings.defaultModels[i][t];return this.builder.settings.modelFallback?n.length===1?(this.builder.settings.consoleLog&&console.log("Fixed model: "+n[0]),n[0]):e&&n&&n.includes(e)?(this.builder.settings.consoleLog&&console.log("Model is valid: "+e),e):n.length>=1?(this.builder.settings.consoleLog&&console.log("Use default: "+n[0]),n[0]):!1:e?e&&n&&n.includes(e)?(this.builder.settings.consoleLog&&console.log("Model is valid: "+e),e):!1:(this.builder.settings.consoleLog&&console.log("Fixed model: "+n[0]),n[0])}async generate_GoogleMediaByJSON(e,t,i,s){this.builder.isMediaGenerating=!0,this.mediaController=new AbortController,this.builder.mediaSignal=this.mediaController.signal;let n;if(e.trim().startsWith("{"))try{n=JSON.parse(e)}catch{return{mediaGenerated:!1,status:"error",message:this.out("Incorrect JSON format.")}}let r=t.trim();if(!r)return{mediaGenerated:!1,status:"error",message:this.out("Please provide model information in the context.")};let o={};o.model=r,o.customData=this.builder.settings.customData,o.payload=n,this.builder.payloads.push(o),this.builder.settings.consoleLog&&console.log(o);const a=this.builder.settings.generateMediaUrl_Google;let d={"Content-Type":"application/json",...this.builder.settings.headers};const l=await(await fetch(a,{signal:this.builder.mediaSignal,method:"POST",headers:d,body:JSON.stringify(o)})).json();this.builder.settings.consoleLog&&console.log(l);const h=l.data;let p=this.renderResult(h,i,s);return{mediaGenerated:!0,status:"success",markdown:p.markdown,output:p.output,output2:p.output2}}async uploadMultiple(){let e=[],t=this.builder.getFormValues();for(const i of t)if(i.value instanceof FileList&&i.type==="multifile"){const s={};if(s.name=i.name,s.files=[],this.builder.selectedFiles&&this.builder.selectedFiles.length>0){const r=[];for(let o=0;o<this.builder.selectedFiles.length;o++){const a=this.builder.selectedFiles[o],d=new FormData;d.append("file",a),d.append("customData",this.builder.settings.customData);let u=this.builder.settings.uploadMediaUrl_Fal;const h=await(await fetch(u,{method:"POST",body:d})).json();if(h.ok){const p=h.url;s.files.push(p),this.builder.filesUploaded["file_"+o]=p}r.push(s)}return r}const n=i.value;if(n.length>0){let r=0;for(const o of n){r++;const a=new FormData;a.append("file",o),a.append("customData",this.builder.settings.customData);let d=this.builder.settings.uploadMediaUrl_Fal;const l=await(await fetch(d,{method:"POST",body:a})).json();if(l.ok){const h=l.url;s.files.push(h),this.builder.filesUploaded["file_"+r]=h}}}e.push(s)}return e}async generate(e,t,i,s,n,r,o){if(i=i||this.builder.settings.defaultMediaGenerationProvider,i==="google"&&e.trim().startsWith("{"))return this.generate_GoogleMediaByJSON(e,t,r,o);this.builder.isMediaGenerating=!0,this.mediaController=new AbortController,this.builder.mediaSignal=this.mediaController.signal;let a,d=!1,u;if(e.trim().startsWith("{"))try{u=JSON.parse(e),u&&typeof u=="object"&&(d=!0)}catch{return{mediaGenerated:!1,status:"error",message:this.out("Incorrect JSON format.")}}if(d){let l=t.trim();if(!l)return{mediaGenerated:!1,status:"error",message:this.out("Please provide model information in the context.")};let h=await this.uploadMultiple();((g,v)=>{const f=m=>{if(Array.isArray(m)){const y=m[0],k=v.find(x=>x.name===y);if(k&&m.every(x=>x===y))return k.files;for(let x=0;x<m.length;x++)m[x]=f(m[x])}else if(typeof m=="object"&&m!==null)for(let y in m)m[y]=f(m[y]);return m};return f(g)})(u,h),i||(l.startsWith("fal")?i="fal":i="replicate");const b=g=>typeof g=="object"&&g!==null&&!Array.isArray(g),w=await this.builder.upload.getInputURLs(i);if(w.error)return{mediaGenerated:!1,status:"error",message:w.error};Object.keys(u).forEach(g=>{Object.keys(w).forEach(v=>{if(u[g]===v){let f=w[v];u[g]=f}if(Array.isArray(u[g])){for(let f=0;f<u[g].length;f++)if(u[g][f]===v){let m=w[v];u[g][f]=m}}})}),Object.keys(u).forEach(g=>{let v=u[g];if(b(v))for(const f in v)Object.prototype.hasOwnProperty.call(v,f)&&Object.keys(w).forEach(m=>{if(v[f]===m){let y=w[m];v[f]=y,m===y&&!y.startsWith("http")&&(v[f]="")}});if(Array.isArray(v)){for(let f=0;f<v.length;f++)if(b(v[f]))for(const m in v[f])Object.prototype.hasOwnProperty.call(v[f],m)&&Object.keys(w).forEach(y=>{if(v[f][m]===y){let k=w[y];v[f][m]=k,y===k&&!k.startsWith("http")&&(v[f][m]="")}});u[g]=[...v.filter(f=>f!=="")]}});let _={};if(_.model=l,_.customData=this.builder.settings.customData,i==="replicate"&&l.indexOf(":")!==-1){const g=l.split(":");_.version=g[1]}if(i==="replicate")if(l.indexOf(":")!==-1){let g=this.builder.settings.replicateEndpoint1;_.endpoint=g,_.payload=u,this.builder.settings.consoleLog&&console.log("JSON PAYLOAD 1")}else{let g=this.builder.settings.replicateEndpoint2;g=g.replace("{MODEL}",_.model),_.endpoint=g,_.payload=u,this.builder.settings.consoleLog&&console.log("JSON PAYLOAD 2")}else if(i==="fal"){let g=`https://queue.fal.run/${_.model}`;_.endpoint=g,_.payload=u,this.builder.settings.consoleLog&&console.log("JSON PAYLOAD")}return this.builder.payloads.push(_),this.builder.settings.consoleLog&&console.log(_),this.generateMediaByJSON(_,i,r,o)}try{if(a=await this.checkIntent(e,i,n),this.builder.settings.consoleLog&&console.log(a),!a)return{mediaGenerated:!1,status:"aborted",message:this.out("Request aborted.")};if(a.minimize_image){if(!a.image_url)return{mediaGenerated:!1,status:"error",message:this.out("Image reference not found.")};const h=await this.builder.upload.getInputURLs();if(h.error)return{mediaGenerated:!1,status:"error",message:h.error};let b={image_url:h[a.image_url]||a.image_url,customData:this.builder.settings.customData};this.builder.payloads.push(b),this.builder.settings.consoleLog&&console.log(b);let w={"Content-Type":"application/json",...this.builder.settings.headers};const g=await(await fetch(this.builder.settings.minimizeImageUrl,{signal:this.builder.mediaSignal,method:"POST",headers:w,body:JSON.stringify(b)})).json();if(this.builder.output.push(g),g.error)return this.builder.settings.consoleLog&&console.log(g.error),this.builder.isMediaGenerating=!1,{mediaGenerated:!1,status:"error",message:g.error};{const v=g.url,f=`
261
+ </p>`,n=e);return i?(t.innerHTML="",t.remove()):(t.innerHTML=s,this.builder.outputHtml+=`<div class="result-container">${s}</div>`),{markdown:n,output:r,output2:o}}async generateReplicate(e,t,i){let s,n={};const r="replicate";if(e.text_to_image_generation){let a=this.validateModel(e.model,r,"text_to_image_generation");if(!a)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};let d=e.prompt;if(!d)return{mediaGenerated:!1,status:"error",message:this.out("Please input a prompt.")};let u=e.aspect_ratio||"16:9",l=e.num_images||1;l>4&&(l=4),s={prompt:d,aspect_ratio:u,num_outputs:l},n.model=a,n.customData=this.builder.settings.customData}else if(e.edit_area_in_image){let a=this.validateModel(e.model,l,"edit_area_in_image");if(!a)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};let d=e.prompt;if(!d)return{mediaGenerated:!1,status:"error",message:this.out("Please input a prompt.")};if(!e.image_url)return{mediaGenerated:!1,status:"error",message:this.out("Image reference not found.")};let l="replicate";const h=await this.builder.upload.getInputURLs(l,!0);if(h.error)return{mediaGenerated:!1,status:"error",message:h.error};let p=h[e.image_url],b=h[e.image_url+"_mask"];if(!b)return{mediaGenerated:!1,status:"error",message:this.out("Image mask not found.")};s={prompt:d,image:p,mask:b},n.model=a,n.customData=this.builder.settings.customData}else if(e.text_to_digital_illustration_generation){let a=this.validateModel(e.model,r,"text_to_digital_illustration_generation");if(!a)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};let d=e.prompt;if(!d)return{mediaGenerated:!1,status:"error",message:this.out("Please input a prompt.")};let u=e.width||1280,l=e.height||768;e.num_images,s={prompt:d,size:`${u}x${l}`,style:"digital_illustration"},n.model=a,n.customData=this.builder.settings.customData}else if(e.upscale_image){let a=this.validateModel(e.model,u,"upscale_image");if(!a)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};if(!e.image_url)return{mediaGenerated:!1,status:"error",message:this.out("Image reference not found.")};let u="replicate";const l=await this.builder.upload.getInputURLs(u);if(l.error)return{mediaGenerated:!1,status:"error",message:l.error};let h=l[e.image_url];if(!h)return{mediaGenerated:!1,status:"error",message:this.out("Image not provided.")};s={image:h},n.model=a,n.customData=this.builder.settings.customData}else if(e.describe_image){let a=this.validateModel(e.model,l,"describe_image");if(!a)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};let d=e.prompt;if(!d)return{mediaGenerated:!1,status:"error",message:this.out("Please input a prompt.")};if(!e.image_url)return{mediaGenerated:!1,status:"error",message:this.out("Image reference not found.")};let l="replicate";const h=await this.builder.upload.getInputURLs(l);if(h.error)return{mediaGenerated:!1,status:"error",message:h.error};let p=h[e.image_url];if(!p)return{mediaGenerated:!1,status:"error",message:this.out("Image not provided.")};s={image:p,prompt:`${d}. No talk. Answer only.`},n.model=a,n.customData=this.builder.settings.customData}else if(e.image_to_video_generation){let a=this.validateModel(e.model,l,"image_to_video_generation");if(!a)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};let d=e.prompt||"stunning video",u=e.duration||5;u>10&&(u=5);let l="replicate";const h=await this.builder.upload.getInputURLs(l);if(h.error)return{mediaGenerated:!1,status:"error",message:h.error};let p=h[e.image_url];if(!p)return{mediaGenerated:!1,status:"error",message:this.out("Image reference not found.")};a==="kwaivgi/kling-v1.6-pro"&&(s={start_image:p,prompt:d,duration:u}),a==="kwaivgi/kling-v1.6-standard"&&(s={start_image:p,prompt:d,duration:u}),a==="minimax/video-01-live"&&(s={first_frame_image:p,prompt:d}),a==="luma/ray"&&(s={start_image_url:p,prompt:d}),n.model=a,n.customData=this.builder.settings.customData}else if(e.text_to_video_generation){let a=this.validateModel(e.model,r,"text_to_video_generation");if(!a)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};let d=e.prompt;if(!d)return{mediaGenerated:!1,status:"error",message:this.out("Please input a prompt.")};let u=e.duration||5;u>10&&(u=5),a==="kwaivgi/kling-v1.6-standard"&&(s={prompt:d,duration:u}),a==="minimax/video-01"&&(s={prompt:d}),a==="luma/ray"&&(s={prompt:d}),n.model=a,n.customData=this.builder.settings.customData}else if(e.text_to_speech){let a=this.validateModel(e.model,r,"text_to_speech");if(!a)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};if(e.text.length>this.builder.settings.ttsMaxCharacters)return{mediaGenerated:!1,status:"error",message:this.out("The text exceeds the allowed limit.")};s={text:e.text,voice:e.voice||"af_nicole",speed:parseFloat(e.speed)||1},n.model=a,n.customData=this.builder.settings.customData}if(n.model.indexOf(":")!==-1){const d=n.model.split(":")[1];n.version=d;let u=this.builder.settings.replicateEndpoint1;n.endpoint=u,n.payload=s,this.builder.settings.consoleLog&&console.log("PAYLOAD 1")}else{let a=this.builder.settings.replicateEndpoint2;a=a.replace("{MODEL}",n.model),n.endpoint=a,n.payload=s,this.builder.settings.consoleLog&&console.log("PAYLOAD 2")}this.builder.payloads.push(n),this.builder.settings.consoleLog&&console.log(n);let o=!1;if(this.builder.settings.generateMediaUrl_Replicate&&(o=!0),o){let a=this.builder.settings.generateMediaUrl_Replicate;if(!a)return{mediaGenerated:!1,status:"error",message:this.out("Endpoint not configured.")};let d,u={"Content-Type":"application/json",...this.builder.settings.headers},h=await(await fetch(a,{signal:this.builder.mediaSignal,method:"POST",headers:u,body:JSON.stringify(n)})).json();if(h.ok){if(d=h.data.id,!d)return{mediaGenerated:!1,status:"error",message:h.data&&h.data.detail}}else return{mediaGenerated:!1,status:"error",message:h.error};const p=this.waitingReplicate(n,d,t,i);return this.builder.isMediaGenerating=!1,p}else{let a=this.builder.settings.generateMediaUrl;if(!a)return{mediaGenerated:!1,status:"error",message:this.out("Endpoint not configured: generateMediaUrl.")};let d={"Content-Type":"application/json",...this.builder.settings.headers};const l=await(await fetch(a,{signal:this.builder.mediaSignal,method:"POST",headers:d,body:JSON.stringify(n)})).json();if(this.builder.isMediaGenerating=!1,l.error)return this.builder.settings.consoleLog&&console.log(l.error),{mediaGenerated:!1,status:"error",message:l.error};{const h=l.data;let p=this.renderResult(h,t,i);return{mediaGenerated:!0,status:"success",markdown:p.markdown,output:p.output,output2:p.output2}}}}async generateOpenAI(e,t,i){let s,n={},o=this.validateModel(e.model,"openai","image_generation"),a=e.prompt;if(!a)return{mediaGenerated:!1,status:"error",message:this.out("Please input a prompt.")};const d=new FormData;d.append("customData",JSON.stringify(this.builder.settings.customData)),d.append("model",o),d.append("prompt",a);let u=!1,l=this.builder.getFormValues();for(const f of l){if(f.value instanceof FileList&&f.type==="multifile"){const m=f.value;if(m.length>0)for(const v of m)d.append("file[]",v),u=!0}if(f.value instanceof FileList&&f.type==="file"){const m=f.value;if(m.length>0){const v=m[0];d.append("file[]",v),u=!0}}if(typeof f.value=="string"&&f.value.indexOf("base64")!==-1){let m=f.value.replace(/^data:image\/(png|svg\+xml|jpeg|gif|webp);base64,/,"");d.append("mask",m)}}if(this.builder.selectedFiles&&this.builder.selectedFiles.length>0)for(let f=0;f<this.builder.selectedFiles.length;f++){const m=this.builder.selectedFiles[f];d.append("file[]",m),u=!0}let h,p=e.size||"auto",b=e.quality||"auto",w=e.num_images||1;if(u){d.append("size",p),d.append("n",w),d.append("quality",b),s={prompt:a,size:p,quality:b,n:w},n.model=o,n.customData=this.builder.settings.customData,n.payload=s,this.builder.payloads.push(n);let f=this.builder.settings.generateMediaUrl_OpenAI_CreateImageEdit;h=await fetch(f,{method:"POST",body:d})}else{let f=e.background||"auto",m=e.output_format||"png";s={prompt:a,background:f,output_format:m,size:p,quality:b,n:w},n.model=o,n.customData=this.builder.settings.customData,n.payload=s,this.builder.payloads.push(n),this.builder.settings.consoleLog&&console.log(n);const v=this.builder.settings.generateMediaUrl_OpenAI_CreateImage;let k={"Content-Type":"application/json",...this.builder.settings.headers};h=await fetch(v,{signal:this.builder.mediaSignal,method:"POST",headers:k,body:JSON.stringify(n)})}const _=await h.json();this.builder.settings.consoleLog&&console.log(_),this.builder.isMediaGenerating=!1;const g=_.data;this.builder.output.push(_);let y=this.renderResult(g,t,i);return{mediaGenerated:!0,status:"success",markdown:y.markdown,output:y.output,output2:y.output2}}async generateGoogle(e,t,i){let s,n={},o=this.validateModel(e.model,"google","edit_area_in_image");if(!o)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};let a=e.prompt;if(!a)return{mediaGenerated:!1,status:"error",message:this.out("Please input a prompt.")};let d=[];d.push({text:a});let u=this.builder.getFormValues();if(!(u&&Object.keys(u).length===0)){for(const g of u)if(g.value instanceof FileList&&g.type==="multifile"){const y=g.value;if(y.length>0)for(const f of y){const m=await new Promise((v,k)=>{const x=new FileReader;x.onload=S=>{const E=S.target.result.split(",")[1];v(E)},x.onerror=k,x.readAsDataURL(f)});d.push({inlineData:{mimeType:"image/png",data:m}})}}}s={contents:d},n.model=o,n.customData=this.builder.settings.customData,n.payload=s,this.builder.payloads.push(n),this.builder.settings.consoleLog&&console.log(n);const l=this.builder.settings.generateMediaUrl_Google;let h={"Content-Type":"application/json",...this.builder.settings.headers};const b=await(await fetch(l,{signal:this.builder.mediaSignal,method:"POST",headers:h,body:JSON.stringify(n)})).json();this.builder.settings.consoleLog&&console.log(b),this.builder.isMediaGenerating=!1;const w=b.data;let _=this.renderResult(w,t,i);return{mediaGenerated:!0,status:"success",markdown:_.markdown,output:_.output,output2:_.output2}}async generateFal(e,t,i){let s="fal",n,r={};if(e.text_to_image_generation){let b=this.validateModel(e.model,s,"text_to_image_generation");if(!b)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};let w=e.prompt;if(!w)return{mediaGenerated:!1,status:"error",message:this.out("Please input a prompt.")};let _=e.width||1280,g=e.height||768,y=e.aspect_ratio,f=e.num_images||1;if(f>4&&(f=4),y){let{w:U,h:G}=this.getDimension(y);_=U,g=G}let m=e.color1_red,v=e.color1_green,k=e.color1_blue,x=e.color2_red,S=e.color2_green,E=e.color2_blue,C=e.color3_red,A=e.color3_green,L=e.color3_blue,D=e.color4_red,I=e.color4_green,O=e.color4_blue,R=e.color5_red,q=e.color5_green,M=e.color5_blue,T=[];m&&v&&k&&!(m==="0"&&v==="0"&&k==="0")&&T.push({r:m,g:v,b:k}),x&&S&&E&&!(x==="0"&&S==="0"&&E==="0")&&T.push({r:x,g:S,b:E}),C&&A&&L&&!(C==="0"&&A==="0"&&L==="0")&&T.push({r:C,g:A,b:L}),D&&I&&O&&!(D==="0"&&I==="0"&&O==="0")&&T.push({r:D,g:I,b:O}),R&&q&&M&&!(R==="0"&&q==="0"&&M==="0")&&T.push({r:R,g:q,b:M});let N=await(async()=>{let U=[],G=this.builder.getFormValues();for(const Y of G)if(Y.value instanceof FileList&&Y.type==="multifile"){const he=Y.value;if(he.length>0){let re=0;for(const ye of he){re++;const Me=new FormData;Me.append("file",ye),Me.append("customData",this.builder.settings.customData);let $e=this.builder.settings.uploadMediaUrl_Fal;const Ne=await(await fetch($e,{method:"POST",body:Me})).json();if(Ne.ok){const De=Ne.url;U.push(De),this.builder.filesUploaded["file_"+re]=De}}}}return U})();n={prompt:w,image_size:{width:_,height:g},num_images:f},b.indexOf("gemini")!==-1&&(n={prompt:w,input_image_urls:N}),b==="fal-ai/ideogram/v2a"&&(y=this.getClosestAspectRatio(_,g),n={prompt:w,aspect_ratio:y,num_images:f}),b.indexOf("recraft")!==-1&&(n={prompt:w,image_size:{width:_,height:g},num_images:f,colors:T}),r.model=b,r.customData=this.builder.settings.customData}else if(e.edit_area_in_image){let b=this.validateModel(e.model,s,"edit_area_in_image");if(!b)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};let w=e.prompt;if(!w)return{mediaGenerated:!1,status:"error",message:this.out("Please input a prompt.")};if(!e.image_url)return{mediaGenerated:!1,status:"error",message:this.out("Image reference not found.")};const g=await this.builder.upload.getInputURLs(s);if(g.error)return{mediaGenerated:!1,status:"error",message:g.error};let y=g[e.image_url],f=g[e.image_url+"_mask"];if(n={image_url:y,mask_url:f,prompt:w},r.model=b,!f){n={image_url:y,prompt:w};let m=this.validateModel(e.model,s,"edit_image");r.model=m}r.customData=this.builder.settings.customData}else if(e.text_to_2d_illustration_generation){let b=this.validateModel(e.model,s,"text_to_2d_illustration_generation");if(!b)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};let w=e.prompt;if(!w)return{mediaGenerated:!1,status:"error",message:this.out("Please input a prompt.")};let _=e.width||1280,g=e.height||768,y=e.num_images||1;y>4&&(y=4);let f=e.style||"any",m=e.style_id||this.builder.settings._2dIllustrationStyleId,v=e.color1_red,k=e.color1_green,x=e.color1_blue,S=e.color2_red,E=e.color2_green,C=e.color2_blue,A=e.color3_red,L=e.color3_green,D=e.color3_blue,I=e.color4_red,O=e.color4_green,R=e.color4_blue,q=e.color5_red,M=e.color5_green,T=e.color5_blue,$=[];v&&k&&x&&!(v==="0"&&k==="0"&&x==="0")&&$.push({r:v,g:k,b:x}),S&&E&&C&&!(S==="0"&&E==="0"&&C==="0")&&$.push({r:S,g:E,b:C}),A&&L&&D&&!(A==="0"&&L==="0"&&D==="0")&&$.push({r:A,g:L,b:D}),I&&O&&R&&!(I==="0"&&O==="0"&&R==="0")&&$.push({r:I,g:O,b:R}),q&&M&&T&&!(q==="0"&&M==="0"&&T==="0")&&$.push({r:q,g:M,b:T}),n={prompt:w,image_size:{width:_,height:g},num_images:y,style:f,style_id:m,colors:$},r.model=b,r.customData=this.builder.settings.customData}else if(e.text_to_digital_illustration_generation){let b=this.validateModel(e.model,s,"text_to_digital_illustration_generation");if(!b)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};let w=e.prompt;if(!w)return{mediaGenerated:!1,status:"error",message:this.out("Please input a prompt.")};let _=e.width||1280,g=e.height||768,y=e.num_images||1;y>4&&(y=4);let f=e.style||"digital_illustration",m=e.color1_red,v=e.color1_green,k=e.color1_blue,x=e.color2_red,S=e.color2_green,E=e.color2_blue,C=e.color3_red,A=e.color3_green,L=e.color3_blue,D=e.color4_red,I=e.color4_green,O=e.color4_blue,R=e.color5_red,q=e.color5_green,M=e.color5_blue,T=[];m&&v&&k&&!(m==="0"&&v==="0"&&k==="0")&&T.push({r:m,g:v,b:k}),x&&S&&E&&!(x==="0"&&S==="0"&&E==="0")&&T.push({r:x,g:S,b:E}),C&&A&&L&&!(C==="0"&&A==="0"&&L==="0")&&T.push({r:C,g:A,b:L}),D&&I&&O&&!(D==="0"&&I==="0"&&O==="0")&&T.push({r:D,g:I,b:O}),R&&q&&M&&!(R==="0"&&q==="0"&&M==="0")&&T.push({r:R,g:q,b:M}),n={prompt:w,image_size:{width:_,height:g},num_images:y,style:f,colors:T},r.model=b,r.customData=this.builder.settings.customData}else if(e.text_to_book_cover_generation){let b=this.validateModel(e.model,s,"text_to_book_cover_generation");if(!b)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};let w=e.prompt;if(!w)return{mediaGenerated:!1,status:"error",message:this.out("Please input a prompt.")};let _=e.width||1024,g=e.height||1365,y=e.num_images||1;y>4&&(y=1);let f="digital_illustration/cover",m=e.color1_red,v=e.color1_green,k=e.color1_blue,x=e.color2_red,S=e.color2_green,E=e.color2_blue,C=e.color3_red,A=e.color3_green,L=e.color3_blue,D=e.color4_red,I=e.color4_green,O=e.color4_blue,R=e.color5_red,q=e.color5_green,M=e.color5_blue,T=[];m&&v&&k&&!(m==="0"&&v==="0"&&k==="0")&&T.push({r:m,g:v,b:k}),x&&S&&E&&!(x==="0"&&S==="0"&&E==="0")&&T.push({r:x,g:S,b:E}),C&&A&&L&&!(C==="0"&&A==="0"&&L==="0")&&T.push({r:C,g:A,b:L}),D&&I&&O&&!(D==="0"&&I==="0"&&O==="0")&&T.push({r:D,g:I,b:O}),R&&q&&M&&!(R==="0"&&q==="0"&&M==="0")&&T.push({r:R,g:q,b:M}),n={prompt:w,image_size:{width:_,height:g},num_images:y,style:f,colors:T},r.model=b,r.customData=this.builder.settings.customData}else if(e.upscale_image){let b=this.validateModel(e.model,s,"upscale_image");if(!b)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};if(!e.image_url)return{mediaGenerated:!1,status:"error",message:this.out("Image reference not found.")};const _=await this.builder.upload.getInputURLs(s);if(_.error)return{mediaGenerated:!1,status:"error",message:_.error};let g=_[e.image_url];if(!g)return{mediaGenerated:!1,status:"error",message:this.out("Image not provided.")};n={image_url:g,upscale_factor:2},r.model=b,r.customData=this.builder.settings.customData}else if(e.describe_image){let b=this.validateModel(e.model,s,"describe_image");if(!b)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};let w=e.prompt;if(!w)return{mediaGenerated:!1,status:"error",message:this.out("Please input a prompt.")};if(!e.image_url)return{mediaGenerated:!1,status:"error",message:this.out("Image reference not found.")};const g=await this.builder.upload.getInputURLs(s);if(g.error)return{mediaGenerated:!1,status:"error",message:g.error};let y=g[e.image_url];if(!y)return{mediaGenerated:!1,status:"error",message:this.out("Image not provided.")};n={image_url:y,prompt:`${w}. No talk. Answer only.`},r.model=b,r.customData=this.builder.settings.customData}else if(e.image_to_video_generation){let b=this.validateModel(e.model,s,"image_to_video_generation");if(!b)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};let w=e.prompt;w=e.prompt||"stunning video";let _=e.duration||5;_>10&&(_=5);const g=await this.builder.upload.getInputURLs(s);if(g.error)return{mediaGenerated:!1,status:"error",message:g.error};let y=g[e.image_url];if(!y)return{mediaGenerated:!1,status:"error",message:this.out("Image reference not found.")};n={prompt:w,image_url:y,duration:_,aspect_ratio:"16:9"},b.indexOf("fal-ai/luma-dream-machine")!==-1&&delete n.duration,r.model=b,r.customData=this.builder.settings.customData}else if(e.text_to_video_generation){let b=this.validateModel(e.model,s,"text_to_video_generation");if(!b)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};let w=e.prompt;if(!w)return{mediaGenerated:!1,status:"error",message:this.out("Please input a prompt.")};let _=e.duration||5;_>10&&(_=5),n={prompt:w,duration:_,aspect_ratio:"16:9"},b.indexOf("fal-ai/luma-dream-machine")!==-1&&delete n.duration,r.model=b,r.customData=this.builder.settings.customData}else if(e.text_to_speech){let b=this.validateModel(e.model,s,"text_to_speech");if(!b)return{mediaGenerated:!1,status:"error",message:this.out("Model not found.")};if(e.text.length>this.builder.settings.ttsMaxCharacters)return{mediaGenerated:!1,status:"error",message:this.out("The text exceeds the allowed limit.")};n={text:e.text,voice:e.voice||"Matilda"},r.model=b,r.customData=this.builder.settings.customData}let o=`https://queue.fal.run/${r.model}`;r.endpoint=o,r.payload=n,this.builder.payloads.push(r),this.builder.settings.consoleLog&&console.log(r);let a=this.builder.settings.generateMediaUrl_Fal;if(!a)return{mediaGenerated:!1,status:"error",message:this.out("Endpoint not configured: generateMediaUrl_Fal.")};let d,u={"Content-Type":"application/json",...this.builder.settings.headers},h=await(await fetch(a,{signal:this.builder.mediaSignal,method:"POST",headers:u,body:JSON.stringify(r)})).json();if(h.ok)d=h.request_id;else return{mediaGenerated:!1,status:"error",message:h.error};const p=this.waitingFal(r,d,t,i);return this.builder.isMediaGenerating=!1,p}validateModel(e,t,i){const n=this.builder.settings.defaultModels[i][t];return this.builder.settings.modelFallback?n.length===1?(this.builder.settings.consoleLog&&console.log("Fixed model: "+n[0]),n[0]):e&&n&&n.includes(e)?(this.builder.settings.consoleLog&&console.log("Model is valid: "+e),e):n.length>=1?(this.builder.settings.consoleLog&&console.log("Use default: "+n[0]),n[0]):!1:e?e&&n&&n.includes(e)?(this.builder.settings.consoleLog&&console.log("Model is valid: "+e),e):!1:(this.builder.settings.consoleLog&&console.log("Fixed model: "+n[0]),n[0])}async generate_GoogleMediaByJSON(e,t,i,s){this.builder.isMediaGenerating=!0,this.mediaController=new AbortController,this.builder.mediaSignal=this.mediaController.signal;let n;if(e.trim().startsWith("{"))try{n=JSON.parse(e)}catch{return{mediaGenerated:!1,status:"error",message:this.out("Incorrect JSON format.")}}let r=t.trim();if(!r)return{mediaGenerated:!1,status:"error",message:this.out("Please provide model information in the context.")};let o={};o.model=r,o.customData=this.builder.settings.customData,o.payload=n,this.builder.payloads.push(o),this.builder.settings.consoleLog&&console.log(o);const a=this.builder.settings.generateMediaUrl_Google;let d={"Content-Type":"application/json",...this.builder.settings.headers};const l=await(await fetch(a,{signal:this.builder.mediaSignal,method:"POST",headers:d,body:JSON.stringify(o)})).json();this.builder.settings.consoleLog&&console.log(l);const h=l.data;let p=this.renderResult(h,i,s);return{mediaGenerated:!0,status:"success",markdown:p.markdown,output:p.output,output2:p.output2}}async uploadMultiple(){let e=[],t=this.builder.getFormValues();for(const i of t)if(i.value instanceof FileList&&i.type==="multifile"){const s={};if(s.name=i.name,s.files=[],this.builder.selectedFiles&&this.builder.selectedFiles.length>0){const r=[];for(let o=0;o<this.builder.selectedFiles.length;o++){const a=this.builder.selectedFiles[o],d=new FormData;d.append("file",a),d.append("customData",this.builder.settings.customData);let u=this.builder.settings.uploadMediaUrl_Fal;const h=await(await fetch(u,{method:"POST",body:d})).json();if(h.ok){const p=h.url;s.files.push(p),this.builder.filesUploaded["file_"+o]=p}r.push(s)}return r}const n=i.value;if(n.length>0){let r=0;for(const o of n){r++;const a=new FormData;a.append("file",o),a.append("customData",this.builder.settings.customData);let d=this.builder.settings.uploadMediaUrl_Fal;const l=await(await fetch(d,{method:"POST",body:a})).json();if(l.ok){const h=l.url;s.files.push(h),this.builder.filesUploaded["file_"+r]=h}}}e.push(s)}return e}async generate(e,t,i,s,n,r,o){if(i=i||this.builder.settings.defaultMediaGenerationProvider,i==="google"&&e.trim().startsWith("{"))return this.generate_GoogleMediaByJSON(e,t,r,o);this.builder.isMediaGenerating=!0,this.mediaController=new AbortController,this.builder.mediaSignal=this.mediaController.signal;let a,d=!1,u;if(e.trim().startsWith("{"))try{u=JSON.parse(e),u&&typeof u=="object"&&(d=!0)}catch{return{mediaGenerated:!1,status:"error",message:this.out("Incorrect JSON format.")}}if(d){let l=t.trim();if(!l)return{mediaGenerated:!1,status:"error",message:this.out("Please provide model information in the context.")};let h=await this.uploadMultiple();((g,y)=>{const f=m=>{if(Array.isArray(m)){const v=m[0],k=y.find(x=>x.name===v);if(k&&m.every(x=>x===v))return k.files;for(let x=0;x<m.length;x++)m[x]=f(m[x])}else if(typeof m=="object"&&m!==null)for(let v in m)m[v]=f(m[v]);return m};return f(g)})(u,h),i||(l.startsWith("fal")?i="fal":i="replicate");const b=g=>typeof g=="object"&&g!==null&&!Array.isArray(g),w=await this.builder.upload.getInputURLs(i);if(w.error)return{mediaGenerated:!1,status:"error",message:w.error};Object.keys(u).forEach(g=>{Object.keys(w).forEach(y=>{if(u[g]===y){let f=w[y];u[g]=f}if(Array.isArray(u[g])){for(let f=0;f<u[g].length;f++)if(u[g][f]===y){let m=w[y];u[g][f]=m}}})}),Object.keys(u).forEach(g=>{let y=u[g];if(b(y))for(const f in y)Object.prototype.hasOwnProperty.call(y,f)&&Object.keys(w).forEach(m=>{if(y[f]===m){let v=w[m];y[f]=v,m===v&&!v.startsWith("http")&&(y[f]="")}});if(Array.isArray(y)){for(let f=0;f<y.length;f++)if(b(y[f]))for(const m in y[f])Object.prototype.hasOwnProperty.call(y[f],m)&&Object.keys(w).forEach(v=>{if(y[f][m]===v){let k=w[v];y[f][m]=k,v===k&&!k.startsWith("http")&&(y[f][m]="")}});u[g]=[...y.filter(f=>f!=="")]}});let _={};if(_.model=l,_.customData=this.builder.settings.customData,i==="replicate"&&l.indexOf(":")!==-1){const g=l.split(":");_.version=g[1]}if(i==="replicate")if(l.indexOf(":")!==-1){let g=this.builder.settings.replicateEndpoint1;_.endpoint=g,_.payload=u,this.builder.settings.consoleLog&&console.log("JSON PAYLOAD 1")}else{let g=this.builder.settings.replicateEndpoint2;g=g.replace("{MODEL}",_.model),_.endpoint=g,_.payload=u,this.builder.settings.consoleLog&&console.log("JSON PAYLOAD 2")}else if(i==="fal"){let g=`https://queue.fal.run/${_.model}`;_.endpoint=g,_.payload=u,this.builder.settings.consoleLog&&console.log("JSON PAYLOAD")}return this.builder.payloads.push(_),this.builder.settings.consoleLog&&console.log(_),this.generateMediaByJSON(_,i,r,o)}try{if(a=await this.checkIntent(e,i,n),this.builder.settings.consoleLog&&console.log(a),!a)return{mediaGenerated:!1,status:"aborted",message:this.out("Request aborted.")};if(a.minimize_image){if(!a.image_url)return{mediaGenerated:!1,status:"error",message:this.out("Image reference not found.")};const h=await this.builder.upload.getInputURLs();if(h.error)return{mediaGenerated:!1,status:"error",message:h.error};let b={image_url:h[a.image_url]||a.image_url,customData:this.builder.settings.customData};this.builder.payloads.push(b),this.builder.settings.consoleLog&&console.log(b);let w={"Content-Type":"application/json",...this.builder.settings.headers};const g=await(await fetch(this.builder.settings.minimizeImageUrl,{signal:this.builder.mediaSignal,method:"POST",headers:w,body:JSON.stringify(b)})).json();if(this.builder.output.push(g),g.error)return this.builder.settings.consoleLog&&console.log(g.error),this.builder.isMediaGenerating=!1,{mediaGenerated:!1,status:"error",message:g.error};{const y=g.url,f=`
262
262
  <div class="image-container">
263
263
  <div>
264
- <img src="${v}" />
264
+ <img src="${y}" />
265
265
  <div>
266
- <a class="link-view" href="${v}" target="_blank" rel="noopener noreferrer">${this.out("View")}</a>
267
- <a class="link-download" href="${v}" download>${this.out("Download")}</a>
266
+ <a class="link-view" href="${y}" target="_blank" rel="noopener noreferrer">${this.out("View")}</a>
267
+ <a class="link-download" href="${y}" download>${this.out("Download")}</a>
268
268
  </div>
269
269
  </div>
270
- </div>`;let m=`![](${v})`;return o?(r.innerHTML="",r.remove()):(r.innerHTML=f,this.builder.outputHtml+=`<div class="result-container">${f}</div>`),this.builder.isMediaGenerating=!1,{mediaGenerated:!0,status:"success",markdown:m,output:[v]}}}else{if(i==="fal")return this.generateFal(a,r,o);if(i==="replicate")return this.generateReplicate(a,r,o);if(i==="google")return this.generateGoogle(a,r,o);if(i==="openai")return this.generateOpenAI(a,r,o)}}catch(l){return this.builder.settings.consoleLog&&console.log(l),this.builder.isMediaGenerating=!1,l.name==="AbortError"?{mediaGenerated:!1,status:"aborted",message:this.out("Request aborted.")}:{mediaGenerated:!1,status:"error",message:this.out("Request failed.")}}return this.builder.isMediaGenerating=!1,{mediaGenerated:!1,status:"error",message:this.out("Request failed.")}}async generateMediaByJSON(e,t,i,s){let n,r=!1;if(t==="replicate"&&this.builder.settings.generateMediaUrl){if(n=this.builder.settings.generateMediaUrl,!n)return{mediaGenerated:!1,status:"error",message:this.out("Endpoint not configured: generateMediaUrl.")}}else if(t==="replicate"&&this.builder.settings.generateMediaUrl_Replicate){if(n=this.builder.settings.generateMediaUrl_Replicate,!n)return{mediaGenerated:!1,status:"error",message:this.out("Endpoint not configured: generateMediaUrl_Replicate.")};r=!0}else if(t==="fal"&&(n=this.builder.settings.generateMediaUrl_Fal,!n))return{mediaGenerated:!1,status:"error",message:this.out("Endpoint not configured: generateMediaUrl_Fal.")};let o={"Content-Type":"application/json",...this.builder.settings.headers};const d=await(await fetch(n,{signal:this.builder.mediaSignal,method:"POST",headers:o,body:JSON.stringify(e)})).json();if(this.builder.isMediaGenerating=!1,t==="fal"){let u=d.request_id;return this.waitingFal(e,u,i,s)}if(d.error)return this.builder.settings.consoleLog&&console.log(d.error),{mediaGenerated:!1,status:"error",message:d.error};if(r){let u;if(d.ok){if(u=d.data.id,!u)return{mediaGenerated:!1,status:"error",message:d.data&&d.data.detail}}else return{mediaGenerated:!1,status:"error",message:d.error};return this.waitingReplicate(e,u,i,s)}else{const u=d.data;let l=this.renderResult(u,i,s);return{mediaGenerated:!0,status:"success",markdown:l.markdown,output:l.output,output2:l.output2}}}getClosestAspectRatio(e,t){if(t===0)return"3:2";const i=e/t,s=[{aspect:"10:16",ratio:10/16},{aspect:"16:10",ratio:16/10},{aspect:"9:16",ratio:9/16},{aspect:"16:9",ratio:16/9},{aspect:"4:3",ratio:4/3},{aspect:"3:4",ratio:3/4},{aspect:"1:1",ratio:1},{aspect:"1:3",ratio:1/3},{aspect:"3:1",ratio:3},{aspect:"3:2",ratio:3/2},{aspect:"2:3",ratio:2/3}];let n=s[0],r=Math.abs(i-s[0].ratio);for(let o=1;o<s.length;o++){const a=Math.abs(i-s[o].ratio);a<r&&(r=a,n=s[o])}return n.aspect}out(e){if(this.opts.lang){let t=this.opts.lang[e];return t||e}else return e}}class pn{constructor(e={},t){const i={lang:[]};this.builder=t,this.opts=Object.assign({},i,e)}async getInputURLs(e){let t=this.builder.getFormValues();const i=this.builder.filesUploaded;if(Object.keys(i).length!==0)return i;for(const s of t)if(s.value instanceof FileList){let n=await this.processMediaInput(s.name,e),r=n.url;s.name===n.url&&(r=""),i[s.name]=r}else{if(s.name.indexOf("_mask")!==-1){let n=await this.processMaskInput(s.name,e);if(n.error)return{error:n.error};{let r=n.url;i[s.name]=r}}if(s.name.indexOf("__url")!==-1){let n;this.builder.settings.isBuilder?n=document.querySelector(this.builder.settings.previewSelector):n=this.builder.element;const r=n.querySelector(`input[name="${s.name}"]`);if(r){const o=r.value;i[s.name]=o}}}return Object.keys(i).forEach(s=>{if(s.endsWith("__url")){const n=s.replace("__url","");Object.prototype.hasOwnProperty.call(i,n)&&(i[n]=i[s]),delete i[s]}}),i}async processMaskInput(e,t){let i;if(this.builder.settings.isBuilder){if(!this.builder.settings.previewSelector)return{error:this.out("previewSelector not set.")};i=document.querySelector(this.builder.settings.previewSelector)}else i=this.builder.element;const s=i.querySelector(`input[type="hidden"][name="${e}"]`);if(!s)return{error:this.out("Unable to perform the request.")};if(s.value==="")return{error:this.out("Please brush the area you want to edit.")};let n=s.value.replace(/^data:image\/(png|svg\+xml|jpeg|gif|webp);base64,/,"");if(n==="")return{error:this.out("Please brush over the areas to remove objects before continuing.")};let r,o=this.builder.getId(),a={image:n,filename:`${e}_${o}.png`,customData:this.builder.settings.customData},d;t==="replicate"?d=this.builder.settings.uploadBase64Url:t==="fal"?d=this.builder.settings.uploadBase64Url_Fal:d=this.builder.settings.uploadBase64Url_Fal||this.builder.settings.uploadBase64Url;let u={"Content-Type":"application/json",...this.builder.settings.headers},h=await(await fetch(d,{signal:this.builder.mediaSignal,method:"POST",headers:u,body:JSON.stringify(a)})).json();return h.ok&&(r=h.url),r?{url:r}:{error:this.out("Upload mask failed.")}}async processMediaInput(e,t){if(!e)return!1;let i;if(!this.isFullUrl(e)){let r=e;i=this.getFileInput(r)||this.getFileInput()}let s="",n;if(this.builder.photoBlob[e]){let r=this.builder.getId();const o=new FormData;o.append("file",this.builder.photoBlob[e],`photo_${r}.jpg`),o.append("customData",this.builder.settings.customData);let a;t==="replicate"?a=this.builder.settings.uploadMediaUrl:t==="fal"?a=this.builder.settings.uploadMediaUrl_Fal:a=this.builder.settings.uploadMediaUrl_Fal||this.builder.settings.uploadMediaUrl;const u=await(await fetch(a,{method:"POST",body:o})).json();return u.ok?(n=u.url,s=u.filename,{filename:s,url:n}):{error:this.out("Upload file failed.")}}if(this.builder.selectedFiles&&this.builder.selectedFiles.length>0){const r=new FormData;r.append("file",this.builder.selectedFiles[0]),r.append("customData",this.builder.settings.customData);let o;t==="replicate"?o=this.builder.settings.uploadMediaUrl:t==="fal"?o=this.builder.settings.uploadMediaUrl_Fal:o=this.builder.settings.uploadMediaUrl_Fal||this.builder.settings.uploadMediaUrl;const d=await(await fetch(o,{method:"POST",body:r})).json();return d.ok?(n=d.url,s=d.filename,{filename:s,url:n}):{error:this.out("Upload file failed.")}}if(i){const r=i.files[0];if(r){s=r.name;const o=new FormData;o.append("file",r),o.append("customData",this.builder.settings.customData);let a;t==="replicate"?a=this.builder.settings.uploadMediaUrl:t==="fal"?a=this.builder.settings.uploadMediaUrl_Fal:a=this.builder.settings.uploadMediaUrl_Fal||this.builder.settings.uploadMediaUrl;const u=await(await fetch(a,{method:"POST",body:o})).json();if(u.ok)n=u.url,s=u.filename;else return{error:this.out("Upload file failed.")}}else n=e}else n=e;return{filename:s,url:n}}getFileInput(e){let t;if(this.builder.settings.isBuilder){if(!this.builder.settings.previewSelector)return console.log("previewSelector not set."),null;t=document.querySelector(this.builder.settings.previewSelector)}else t=this.builder.element;return t?e?t.querySelector(`input[type="file"][name="${e}"]`):t.querySelector('input[type="file"]'):null}isFullUrl(e){return e.indexOf("/")!==-1}out(e){if(this.opts.lang){let t=this.opts.lang[e];return t||e}else return e}}class fn{constructor(e,t={}){const i={lang:[]};this.settings=Object.assign({},i,t),this.empty=!0,this.element=e,this.init()}loadUrl(e){const t=this.element.querySelector("img");t.src=e,this.loaded()}loadImage(e){if(e){const t=new FileReader;t.onload=i=>{this.element.querySelector("img").setAttribute("src",i.target.result)},t.readAsDataURL(e)}}setImage(e){if(e){const t=this.element.querySelector("img");t.src=e}}clearImage(){this.element.style.display=""}out(e){let t=this.settings.lang[e];return t||e}init(){const e=this.element;e.className="imagemask-wrapper";const t=document.createElement("div");t.className="imagemask-overlay",e.appendChild(t);const i=document.createElement("button");i.className="btn-close-imagemask",i.title=this.out("Close"),i.innerHTML=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24"
270
+ </div>`;let m=`![](${y})`;return o?(r.innerHTML="",r.remove()):(r.innerHTML=f,this.builder.outputHtml+=`<div class="result-container">${f}</div>`),this.builder.isMediaGenerating=!1,{mediaGenerated:!0,status:"success",markdown:m,output:[y]}}}else{if(i==="fal")return this.generateFal(a,r,o);if(i==="replicate")return this.generateReplicate(a,r,o);if(i==="google")return this.generateGoogle(a,r,o);if(i==="openai")return this.generateOpenAI(a,r,o)}}catch(l){return this.builder.settings.consoleLog&&console.log(l),this.builder.isMediaGenerating=!1,l.name==="AbortError"?{mediaGenerated:!1,status:"aborted",message:this.out("Request aborted.")}:{mediaGenerated:!1,status:"error",message:this.out("Request failed.")}}return this.builder.isMediaGenerating=!1,{mediaGenerated:!1,status:"error",message:this.out("Request failed.")}}async generateMediaByJSON(e,t,i,s){let n,r=!1;if(t==="replicate"&&this.builder.settings.generateMediaUrl){if(n=this.builder.settings.generateMediaUrl,!n)return{mediaGenerated:!1,status:"error",message:this.out("Endpoint not configured: generateMediaUrl.")}}else if(t==="replicate"&&this.builder.settings.generateMediaUrl_Replicate){if(n=this.builder.settings.generateMediaUrl_Replicate,!n)return{mediaGenerated:!1,status:"error",message:this.out("Endpoint not configured: generateMediaUrl_Replicate.")};r=!0}else if(t==="fal"&&(n=this.builder.settings.generateMediaUrl_Fal,!n))return{mediaGenerated:!1,status:"error",message:this.out("Endpoint not configured: generateMediaUrl_Fal.")};let o={"Content-Type":"application/json",...this.builder.settings.headers};const d=await(await fetch(n,{signal:this.builder.mediaSignal,method:"POST",headers:o,body:JSON.stringify(e)})).json();if(this.builder.isMediaGenerating=!1,t==="fal"){let u=d.request_id;return this.waitingFal(e,u,i,s)}if(d.error)return this.builder.settings.consoleLog&&console.log(d.error),{mediaGenerated:!1,status:"error",message:d.error};if(r){let u;if(d.ok){if(u=d.data.id,!u)return{mediaGenerated:!1,status:"error",message:d.data&&d.data.detail}}else return{mediaGenerated:!1,status:"error",message:d.error};return this.waitingReplicate(e,u,i,s)}else{const u=d.data;let l=this.renderResult(u,i,s);return{mediaGenerated:!0,status:"success",markdown:l.markdown,output:l.output,output2:l.output2}}}getClosestAspectRatio(e,t){if(t===0)return"3:2";const i=e/t,s=[{aspect:"10:16",ratio:10/16},{aspect:"16:10",ratio:16/10},{aspect:"9:16",ratio:9/16},{aspect:"16:9",ratio:16/9},{aspect:"4:3",ratio:4/3},{aspect:"3:4",ratio:3/4},{aspect:"1:1",ratio:1},{aspect:"1:3",ratio:1/3},{aspect:"3:1",ratio:3},{aspect:"3:2",ratio:3/2},{aspect:"2:3",ratio:2/3}];let n=s[0],r=Math.abs(i-s[0].ratio);for(let o=1;o<s.length;o++){const a=Math.abs(i-s[o].ratio);a<r&&(r=a,n=s[o])}return n.aspect}out(e){if(this.opts.lang){let t=this.opts.lang[e];return t||e}else return e}}class pn{constructor(e={},t){const i={lang:[]};this.builder=t,this.opts=Object.assign({},i,e)}async getInputURLs(e){let t=this.builder.getFormValues();const i=this.builder.filesUploaded;if(Object.keys(i).length!==0)return i;for(const s of t)if(s.value instanceof FileList){let n=await this.processMediaInput(s.name,e),r=n.url;s.name===n.url&&(r=""),i[s.name]=r}else{if(s.name.indexOf("_mask")!==-1){let n=await this.processMaskInput(s.name,e);if(n.error)return{error:n.error};{let r=n.url;i[s.name]=r}}if(s.name.indexOf("__url")!==-1){let n;this.builder.settings.isBuilder?n=document.querySelector(this.builder.settings.previewSelector):n=this.builder.element;const r=n.querySelector(`input[name="${s.name}"]`);if(r){const o=r.value;i[s.name]=o}}}return Object.keys(i).forEach(s=>{if(s.endsWith("__url")){const n=s.replace("__url","");Object.prototype.hasOwnProperty.call(i,n)&&(i[n]=i[s]),delete i[s]}}),i}async processMaskInput(e,t){let i;if(this.builder.settings.isBuilder){if(!this.builder.settings.previewSelector)return{error:this.out("previewSelector not set.")};i=document.querySelector(this.builder.settings.previewSelector)}else i=this.builder.element;const s=i.querySelector(`input[type="hidden"][name="${e}"]`);if(!s)return{error:this.out("Unable to perform the request.")};if(s.value==="")return{error:this.out("Please brush the area you want to edit.")};let n=s.value.replace(/^data:image\/(png|svg\+xml|jpeg|gif|webp);base64,/,"");if(n==="")return{error:this.out("Please brush over the areas to remove objects before continuing.")};let r,o=this.builder.getId(),a={image:n,filename:`${e}_${o}.png`,customData:this.builder.settings.customData},d;t==="replicate"?d=this.builder.settings.uploadBase64Url:t==="fal"?d=this.builder.settings.uploadBase64Url_Fal:d=this.builder.settings.uploadBase64Url_Fal||this.builder.settings.uploadBase64Url;let u={"Content-Type":"application/json",...this.builder.settings.headers},h=await(await fetch(d,{signal:this.builder.mediaSignal,method:"POST",headers:u,body:JSON.stringify(a)})).json();return h.ok&&(r=h.url),r?{url:r}:{error:this.out("Upload mask failed.")}}async processMediaInput(e,t){if(!e)return!1;let i;if(!this.isFullUrl(e)){let r=e;i=this.getFileInput(r)||this.getFileInput()}let s="",n;if(this.builder.photoBlob[e]){let r=this.builder.getId();const o=new FormData;o.append("file",this.builder.photoBlob[e],`photo_${r}.jpg`),o.append("customData",this.builder.settings.customData);let a;t==="replicate"?a=this.builder.settings.uploadMediaUrl:t==="fal"?a=this.builder.settings.uploadMediaUrl_Fal:a=this.builder.settings.uploadMediaUrl_Fal||this.builder.settings.uploadMediaUrl;const u=await(await fetch(a,{method:"POST",body:o})).json();return u.ok?(n=u.url,s=u.filename,{filename:s,url:n}):{error:this.out("Upload file failed.")}}if(this.builder.selectedFiles&&this.builder.selectedFiles.length>0){const r=new FormData;r.append("file",this.builder.selectedFiles[0]),r.append("customData",this.builder.settings.customData);let o;t==="replicate"?o=this.builder.settings.uploadMediaUrl:t==="fal"?o=this.builder.settings.uploadMediaUrl_Fal:o=this.builder.settings.uploadMediaUrl_Fal||this.builder.settings.uploadMediaUrl;const d=await(await fetch(o,{method:"POST",body:r})).json();return d.ok?(n=d.url,s=d.filename,{filename:s,url:n}):{error:this.out("Upload file failed.")}}if(i){const r=i.files[0];if(r){s=r.name;const o=new FormData;o.append("file",r),o.append("customData",this.builder.settings.customData);let a;t==="replicate"?a=this.builder.settings.uploadMediaUrl:t==="fal"?a=this.builder.settings.uploadMediaUrl_Fal:a=this.builder.settings.uploadMediaUrl_Fal||this.builder.settings.uploadMediaUrl;const u=await(await fetch(a,{method:"POST",body:o})).json();if(u.ok)n=u.url,s=u.filename;else return{error:this.out("Upload file failed.")}}else n=e}else n=e;return{filename:s,url:n}}getFileInput(e){let t;if(this.builder.settings.isBuilder){if(!this.builder.settings.previewSelector)return console.log("previewSelector not set."),null;t=document.querySelector(this.builder.settings.previewSelector)}else t=this.builder.element;return t?e?t.querySelector(`input[type="file"][name="${e}"]`):t.querySelector('input[type="file"]'):null}isFullUrl(e){return e.indexOf("/")!==-1}out(e){if(this.opts.lang){let t=this.opts.lang[e];return t||e}else return e}}class fn{constructor(e,t={}){const i={lang:[]};this.settings=Object.assign({},i,t),this.empty=!0,this.element=e,this.init()}loadUrl(e){const t=this.element.querySelector("img");t.src=e,this.loaded()}loadImage(e){if(e){const t=new FileReader;t.onload=i=>{this.element.querySelector("img").setAttribute("src",i.target.result)},t.readAsDataURL(e)}}setImage(e){if(e){const t=this.element.querySelector("img");t.src=e}}clearImage(){this.element.style.display=""}out(e){let t=this.settings.lang[e];return t||e}init(){const e=this.element;e.className="imagemask-wrapper";const t=document.createElement("div");t.className="imagemask-overlay",e.appendChild(t);const i=document.createElement("button");i.className="btn-close-imagemask",i.title=this.out("Close"),i.innerHTML=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24"
271
271
  viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.2" stroke-linecap="round"
272
272
  stroke-linejoin="round" class="icon-close">
273
273
  <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
@@ -300,7 +300,7 @@ Check the information and return the details.
300
300
  <path d="M8 20l-4 0l0 -4" /><path d="M4 20l6 -6" />
301
301
  <path d="M16 20l4 0l0 -4" /><path d="M14 14l6 6" />
302
302
  <path d="M8 4l-4 0l0 4" /><path d="M4 4l6 6" />
303
- </svg>`,r.appendChild(h);const p=document.createElement("input");p.type="hidden",p.name=this.settings.name,p.className="inp-imagemask",p.value="",s.appendChild(p);const b=document.createElement("canvas");b.className="imagemask";const w=b.getContext("2d",{willReadFrequently:!0}),_=document.createElement("canvas"),g=_.getContext("2d",{willReadFrequently:!0}),v=this.element.querySelector(".inp-imagemask"),f=T=>{const $=document.createElement("canvas"),N=$.getContext("2d",{willReadFrequently:!0});$.width=T.width,$.height=T.height,N.clearRect(0,0,T.width,T.height),N.fillStyle="black",N.fillRect(0,0,T.width,T.height),N.drawImage(T,0,0);const U=$.toDataURL("image/png");let G=document.querySelector(".imagemask-output");G||(G=document.createElement("img"),G.className="imagemask-output",document.body.appendChild(G)),G.src=U,this.empty||(v.value=U)};let m=[],y=[];const k=()=>{m.push(_.toDataURL()),m.length>10&&m.shift(),y=[]},x=T=>{const $=new Image;$.src=T,$.onload=()=>{w.clearRect(0,0,b.width,b.height),w.drawImage($,0,0,b.width,b.height),g.clearRect(0,0,_.width,_.height),g.drawImage($,0,0,_.width,_.height),f(_)}};b.addEventListener("mousedown",()=>{k()}),d.addEventListener("click",T=>{T.preventDefault(),m.length>0&&(y.push(b.toDataURL()),x(m.pop()))}),u.addEventListener("click",T=>{T.preventDefault(),y.length>0&&(m.push(b.toDataURL()),x(y.pop()))});const S=document.createElement("img");n.appendChild(S),n.appendChild(b),this.loaded=()=>{n.style.display="flex";const T=document.querySelector(".imagemask-controls");T.style.display="flex",e.style.display="flex",A(),m=[],y=[],w.clearRect(0,0,b.width,b.height),g.clearRect(0,0,_.width,_.height),this.empty=!0,v.value="";try{f(_)}catch{}},S.onload=()=>{this.loaded()};let E=null,C=null;const A=()=>{b.width>0&&b.height>0&&(E=w.getImageData(0,0,b.width,b.height),C=g.getImageData(0,0,_.width,_.height));const T=S.offsetWidth,$=S.offsetHeight,N=window.devicePixelRatio||1;b.width=T*N,b.height=$*N,w.scale(N,N),b.style.width=`${T}px`,b.style.height=`${$}px`;const U=S.naturalWidth,G=S.naturalHeight;if(_.width=U*N,_.height=G*N,g.scale(N,N),_.style.width=`${U}px`,_.style.height=`${G}px`,E){const Y=document.createElement("canvas");Y.width=E.width,Y.height=E.height,Y.getContext("2d").putImageData(E,0,0);const re=document.createElement("canvas");re.width=C.width,re.height=C.height,re.getContext("2d").putImageData(C,0,0),w.drawImage(Y,0,0,E.width,E.height,0,0,b.width,b.height),g.drawImage(re,0,0,C.width,C.height,0,0,_.width,_.height)}};let L=!1,D=parseInt(a.value,10);a.addEventListener("input",T=>{D=parseInt(T.target.value,10)});const I=T=>{const $=b.getBoundingClientRect();if(T.touches){const N=T.touches[0];return{x:N.clientX-$.left,y:N.clientY-$.top}}return{x:T.clientX-$.left,y:T.clientY-$.top}},O=T=>{L=!0,q(T)},R=()=>{L=!1,w.beginPath(),this.empty=!1,f(_)},q=T=>{if(!L)return;const{x:$,y:N}=I(T),U=_.width/b.width,G=_.height/b.height,Y=$*U,he=N*G;w.fillStyle="rgb(255, 255, 255)",w.beginPath(),w.arc($,N,D/2,0,Math.PI*2),w.fill(),g.fillStyle="rgb(255, 255, 255)",g.beginPath(),g.arc(Y,he,D/2*U,0,Math.PI*2),g.fill()};b.addEventListener("mousedown",O),b.addEventListener("mouseup",R),b.addEventListener("mousemove",q),b.addEventListener("touchstart",T=>{O(T),T.preventDefault()},{passive:!1}),b.addEventListener("touchend",T=>{R(),T.preventDefault()}),b.addEventListener("touchmove",T=>{q(T),T.preventDefault()},{passive:!1}),l.addEventListener("click",T=>{T.preventDefault(),k(),w.clearRect(0,0,b.width,b.height),g.clearRect(0,0,_.width,_.height),this.empty=!0,v.value="",f(_)}),window.addEventListener("resize",A);const M=T=>{T?(e.setAttribute("aria-modal","true"),e.setAttribute("role","dialog"),e.classList.add("fullscreen"),t.style.display="block",i.style.display="flex",h.style.display="none"):(e.removeAttribute("aria-modal"),e.removeAttribute("role"),e.classList.remove("fullscreen"),t.style.display="none",i.style.display="none",h.style.display=""),A()};h.addEventListener("click",T=>{T.preventDefault(),M(!0)}),i.addEventListener("click",T=>{T.preventDefault(),M(!1)}),document.addEventListener("keydown",T=>{T.key==="Escape"&&M(!1)})}}class gn{constructor(e,t={}){const i={lang:[],headers:{},fileUploadText:"Drag and drop your file here.",multiFileUploadText:"Drag and drop your files here.",model:"gpt-4o-mini",model2:"gpt-4o-mini",sendCommandUrl:"/sendcommand",sendCommandStreamUrl:"/getstream",consoleLog:!1,saveResults:!1,disableMediaGeneration:!1,disableMediaGenerationTitle:"Demo Info",disableMediaGenerationMessage:"This is an online demo and media generation is currently disabled. Get the full version for complete functionality.",submitText:"Submit",resetText:"Reset",scrapeProvider:"firecrawl",scrapeLimit:6,scrapeExclude:["youtube.com","reddit.com","microsoft.com","mozilla.org"],inputCost:.15,outputCost:.6,_2dIllustrationStyleId:"bcaa0104-98ef-4cb8-a012-124dad015756",templateFilters:["all","image","video","audio","text"],templatesConfig:{fal:!0,replicate:!1,web:!1},defaultMediaGenerationProvider:"fal",replicateEndpoint1:"https://api.replicate.com/v1/predictions",replicateEndpoint2:"https://api.replicate.com/v1/models/{MODEL}/predictions",falStatusEndpoint:"https://queue.fal.run/{MODEL}/requests/{REQUEST_ID}/status",falResultEndpoint:"https://queue.fal.run/{MODEL}/requests/{REQUEST_ID}",replicateStatusEndpoint:"https://api.replicate.com/v1/predictions/{REQUEST_ID}",modelFallback:!1,defaultModels:{image_generation:{openai:["gpt-image-1"]},image_variation_generation:{openai:["gpt-image-1"]},text_to_image_generation:{fal:["fal-ai/flux-1/schnell","fal-ai/flux-1/dev","fal-ai/flux-pro/v1.1","fal-ai/flux-pro/v1.1-ultra","fal-ai/recraft-v3","fal-ai/recraft-20b","fal-ai/ideogram/v2a","fal-ai/hidream-i1-fast","fal-ai/hidream-i1-dev","fal-ai/hidream-i1-full","fal-ai/gemini-flash-edit/multi"],replicate:["black-forest-labs/flux-schnell","black-forest-labs/flux-dev","black-forest-labs/flux-1.1-pro","black-forest-labs/flux-1.1-pro-ultra","recraft-ai/recraft-v3","ideogram-ai/ideogram-v2a"],google:["gemini-2.0-flash-exp-image-generation"],openai:["gpt-image-1"]},image_to_video_generation:{fal:["fal-ai/kling-video/v1.6/standard/image-to-video","fal-ai/kling-video/v1.6/pro/image-to-video","fal-ai/kling-video/v2.1/standard/image-to-video","fal-ai/kling-video/v2.1/pro/image-to-video","fal-ai/kling-video/v2.1/master/image-to-video","fal-ai/minimax/video-01-live/image-to-video","fal-ai/luma-dream-machine/ray-2/image-to-video"],replicate:["kwaivgi/kling-v1.6-standard","kwaivgi/kling-v1.6-pro","minimax/video-01-live","luma/ray"]},text_to_video_generation:{fal:["fal-ai/kling-video/v1.6/standard/text-to-video","fal-ai/kling-video/v2.1/master/text-to-video","fal-ai/minimax/video-01-live ","fal-ai/luma-dream-machine/ray-2"],replicate:["kwaivgi/kling-v1.6-standard","minimax/video-01","luma/ray"]},upscale_image:{fal:["fal-ai/clarity-upscaler"],replicate:["recraft-ai/recraft-crisp-upscale"]},describe_image:{fal:["fal-ai/any-llm/vision"],replicate:[]},edit_area_in_image:{fal:["fal-ai/flux-pro/v1/fill"],replicate:["black-forest-labs/flux-fill-pro"],google:["gemini-2.0-flash-exp-image-generation"],openai:["gpt-image-1"]},edit_image:{fal:["fal-ai/gemini-flash-edit"],replicate:[],openai:["gpt-image-1"]},text_to_2d_illustration_generation:{fal:["fal-ai/recraft-v3"],replicate:[]},text_to_digital_illustration_generation:{fal:["fal-ai/recraft-v3"],replicate:["recraft-ai/recraft-v3"]},text_to_book_cover_generation:{fal:["fal-ai/recraft-v3"],replicate:[]},text_to_speech:{fal:["fal-ai/elevenlabs/tts/multilingual-v2"],replicate:["jaaari/kokoro-82m:f559560eb822dc509045f3921a1921234918b91739db4bf3daab2169b71c7a13"]}},ttsMaxCharacters:3e3,alwaysVisibleSubmit:!1};this.settings=Object.assign({},i,t),this.listeners={},window._txt&&(this.settings.lang=window._txt),this.steps=[];let s=this.settings.onChange;if(this.settings.onChange=n=>{s&&s.call(this,n)},!e)throw new Error("A valid DOM element is required.");e.classList.add("formview-container"),e.classList.add("fb-ui"),this.element=e,this.media=new hn({lang:this.settings.lang},this),this.upload=new pn({lang:this.settings.lang},this)}on(e,t){return this.listeners[e]||(this.listeners[e]=new Set),this.listeners[e].add(t),this}off(e,t){this.listeners[e]&&this.listeners[e].delete(t)}trigger(e,t){this.listeners[e]&&this.listeners[e].forEach(i=>i(t))}async loadTemplates(){if(!this.settings.templatesUrl){console.log(this.out("Template URL is not set."));return}let e=document.querySelector(this.settings.templatesSelector);if(e){e.classList.remove("hidden"),e.classList.add("formtemplates-container"),e.classList.add("fb-ui");let s=(await(await fetch(this.settings.templatesUrl,{method:"GET"})).json()).data;e.innerHTML="",s=s.filter(l=>{const h=l.supports||[];if(h.length===0)return!0;const{fal:p,replicate:b,web:w,openai:_,google:g}=this.settings.templatesConfig;return!w&&h.includes("web")||!g&&h.includes("google")||!_&&h.includes("openai")?!1:!p&&!b?!(h.includes("fal")||h.includes("replicate")):!p&&h.includes("fal")?h.includes("replicate"):!b&&h.includes("replicate")?h.includes("fal"):!0});const r=this.settings.templateFilters,o={all:{desc:this.out("All")},image:{desc:this.out("Image")},video:{desc:this.out("Video")},audio:{desc:this.out("Audio")},web:{desc:this.out("Web")},text:{desc:this.out("Text")}},a=document.createElement("div");a.className="app-filters",e.appendChild(a);const d=document.createElement("ul");d.className="app-list",e.appendChild(d);const u=l=>{let h=s.filter(b=>l==="all"||b.categories.includes(l));const p=this.settings.templateOutput||["image","video","audio","text"];h=h.filter(b=>b.categories.every(w=>p.includes(w))),this.renderList(h,d)};r.forEach(l=>{const h=document.createElement("button");h.textContent=o[l].desc,h.setAttribute("data-value",l),l==="all"&&h.classList.add("active"),h.addEventListener("click",()=>{a.querySelectorAll("button").forEach(b=>b.classList.remove("active")),h.classList.add("active"),u(l)}),a.appendChild(h)}),u("all")}}async selectFile(e){const t=this.element.querySelector(".file-input-wrapper");if(!t)return;const i=t.querySelector('input[type="file"]');if(!i||!this.acceptsImagesOnly(i))return;let s;e.startsWith("http")?s=this.settings.viewFileUrl+"?url="+e:s=e;const r=await(await fetch(s)).blob(),o=new File([r],e.split("/").pop(),{type:r.type});this.element.querySelector(".div-selected-preview")||(this.selectedFiles=[]),i&&i.hasAttribute("multiple")?this.selectedFiles.some(u=>u.name===o.name)||this.selectedFiles.push(o):this.selectedFiles=[o],this.setSelectedFiles(this.selectedFiles),this.renderSelectedFiles(),t.closest(".image-mask")&&this.objImageMask&&this.objImageMask.loadImage(o)}setSelectedFiles(e){this.selectedFiles=e;const t=this.element.querySelector('input[type="file"]');t&&t.removeAttribute("required")}renderSelectedFiles(){const e=this.element.querySelector(".file-input-wrapper");if(!e)return;let t=this.element.querySelector(".div-selected-preview");t?t.innerHTML="":(t=document.createElement("div"),t.classList.add("div-selected-preview"),e.appendChild(t)),this.clearFileInput(),this.selectedFiles&&this.selectedFiles.forEach((i,s)=>{const n=document.createElement("div"),r=document.createElement("img");r.src=URL.createObjectURL(i);const o=document.createElement("button");o.innerHTML=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round" class="">
303
+ </svg>`,r.appendChild(h);const p=document.createElement("input");p.type="hidden",p.name=this.settings.name,p.className="inp-imagemask",p.value="",s.appendChild(p);const b=document.createElement("canvas");b.className="imagemask";const w=b.getContext("2d",{willReadFrequently:!0}),_=document.createElement("canvas"),g=_.getContext("2d",{willReadFrequently:!0}),y=this.element.querySelector(".inp-imagemask"),f=T=>{const $=document.createElement("canvas"),N=$.getContext("2d",{willReadFrequently:!0});$.width=T.width,$.height=T.height,N.clearRect(0,0,T.width,T.height),N.fillStyle="black",N.fillRect(0,0,T.width,T.height),N.drawImage(T,0,0);const U=$.toDataURL("image/png");let G=document.querySelector(".imagemask-output");G||(G=document.createElement("img"),G.className="imagemask-output",document.body.appendChild(G)),G.src=U,this.empty||(y.value=U)};let m=[],v=[];const k=()=>{m.push(_.toDataURL()),m.length>10&&m.shift(),v=[]},x=T=>{const $=new Image;$.src=T,$.onload=()=>{w.clearRect(0,0,b.width,b.height),w.drawImage($,0,0,b.width,b.height),g.clearRect(0,0,_.width,_.height),g.drawImage($,0,0,_.width,_.height),f(_)}};b.addEventListener("mousedown",()=>{k()}),d.addEventListener("click",T=>{T.preventDefault(),m.length>0&&(v.push(b.toDataURL()),x(m.pop()))}),u.addEventListener("click",T=>{T.preventDefault(),v.length>0&&(m.push(b.toDataURL()),x(v.pop()))});const S=document.createElement("img");n.appendChild(S),n.appendChild(b),this.loaded=()=>{n.style.display="flex";const T=document.querySelector(".imagemask-controls");T.style.display="flex",e.style.display="flex",A(),m=[],v=[],w.clearRect(0,0,b.width,b.height),g.clearRect(0,0,_.width,_.height),this.empty=!0,y.value="";try{f(_)}catch{}},S.onload=()=>{this.loaded()};let E=null,C=null;const A=()=>{b.width>0&&b.height>0&&(E=w.getImageData(0,0,b.width,b.height),C=g.getImageData(0,0,_.width,_.height));const T=S.offsetWidth,$=S.offsetHeight,N=window.devicePixelRatio||1;b.width=T*N,b.height=$*N,w.scale(N,N),b.style.width=`${T}px`,b.style.height=`${$}px`;const U=S.naturalWidth,G=S.naturalHeight;if(_.width=U*N,_.height=G*N,g.scale(N,N),_.style.width=`${U}px`,_.style.height=`${G}px`,E){const Y=document.createElement("canvas");Y.width=E.width,Y.height=E.height,Y.getContext("2d").putImageData(E,0,0);const re=document.createElement("canvas");re.width=C.width,re.height=C.height,re.getContext("2d").putImageData(C,0,0),w.drawImage(Y,0,0,E.width,E.height,0,0,b.width,b.height),g.drawImage(re,0,0,C.width,C.height,0,0,_.width,_.height)}};let L=!1,D=parseInt(a.value,10);a.addEventListener("input",T=>{D=parseInt(T.target.value,10)});const I=T=>{const $=b.getBoundingClientRect();if(T.touches){const N=T.touches[0];return{x:N.clientX-$.left,y:N.clientY-$.top}}return{x:T.clientX-$.left,y:T.clientY-$.top}},O=T=>{L=!0,q(T)},R=()=>{L=!1,w.beginPath(),this.empty=!1,f(_)},q=T=>{if(!L)return;const{x:$,y:N}=I(T),U=_.width/b.width,G=_.height/b.height,Y=$*U,he=N*G;w.fillStyle="rgb(255, 255, 255)",w.beginPath(),w.arc($,N,D/2,0,Math.PI*2),w.fill(),g.fillStyle="rgb(255, 255, 255)",g.beginPath(),g.arc(Y,he,D/2*U,0,Math.PI*2),g.fill()};b.addEventListener("mousedown",O),b.addEventListener("mouseup",R),b.addEventListener("mousemove",q),b.addEventListener("touchstart",T=>{O(T),T.preventDefault()},{passive:!1}),b.addEventListener("touchend",T=>{R(),T.preventDefault()}),b.addEventListener("touchmove",T=>{q(T),T.preventDefault()},{passive:!1}),l.addEventListener("click",T=>{T.preventDefault(),k(),w.clearRect(0,0,b.width,b.height),g.clearRect(0,0,_.width,_.height),this.empty=!0,y.value="",f(_)}),window.addEventListener("resize",A);const M=T=>{T?(e.setAttribute("aria-modal","true"),e.setAttribute("role","dialog"),e.classList.add("fullscreen"),t.style.display="block",i.style.display="flex",h.style.display="none"):(e.removeAttribute("aria-modal"),e.removeAttribute("role"),e.classList.remove("fullscreen"),t.style.display="none",i.style.display="none",h.style.display=""),A()};h.addEventListener("click",T=>{T.preventDefault(),M(!0)}),i.addEventListener("click",T=>{T.preventDefault(),M(!1)}),document.addEventListener("keydown",T=>{T.key==="Escape"&&M(!1)})}}class gn{constructor(e,t={}){const i={lang:[],headers:{},fileUploadText:"Drag and drop your file here.",multiFileUploadText:"Drag and drop your files here.",model:"gpt-4o-mini",model2:"gpt-4o-mini",sendCommandUrl:"/sendcommand",sendCommandStreamUrl:"/getstream",consoleLog:!1,saveResults:!1,disableMediaGeneration:!1,disableMediaGenerationTitle:"Demo Info",disableMediaGenerationMessage:"This is an online demo and media generation is currently disabled. Get the full version for complete functionality.",submitText:"Submit",resetText:"Reset",scrapeProvider:"firecrawl",scrapeLimit:6,scrapeExclude:["youtube.com","reddit.com","microsoft.com","mozilla.org"],inputCost:.15,outputCost:.6,_2dIllustrationStyleId:"bcaa0104-98ef-4cb8-a012-124dad015756",templateFilters:["all","image","video","audio","text"],templatesConfig:{fal:!0,replicate:!1,web:!1},defaultMediaGenerationProvider:"fal",replicateEndpoint1:"https://api.replicate.com/v1/predictions",replicateEndpoint2:"https://api.replicate.com/v1/models/{MODEL}/predictions",falStatusEndpoint:"https://queue.fal.run/{MODEL}/requests/{REQUEST_ID}/status",falResultEndpoint:"https://queue.fal.run/{MODEL}/requests/{REQUEST_ID}",replicateStatusEndpoint:"https://api.replicate.com/v1/predictions/{REQUEST_ID}",modelFallback:!1,defaultModels:{image_generation:{openai:["gpt-image-1"]},image_variation_generation:{openai:["gpt-image-1"]},text_to_image_generation:{fal:["fal-ai/flux-1/schnell","fal-ai/flux-1/dev","fal-ai/flux-pro/v1.1","fal-ai/flux-pro/v1.1-ultra","fal-ai/recraft-v3","fal-ai/recraft-20b","fal-ai/ideogram/v2a","fal-ai/hidream-i1-fast","fal-ai/hidream-i1-dev","fal-ai/hidream-i1-full","fal-ai/gemini-flash-edit/multi"],replicate:["black-forest-labs/flux-schnell","black-forest-labs/flux-dev","black-forest-labs/flux-1.1-pro","black-forest-labs/flux-1.1-pro-ultra","recraft-ai/recraft-v3","ideogram-ai/ideogram-v2a"],google:["gemini-2.0-flash-exp-image-generation"],openai:["gpt-image-1"]},image_to_video_generation:{fal:["fal-ai/kling-video/v1.6/standard/image-to-video","fal-ai/kling-video/v1.6/pro/image-to-video","fal-ai/kling-video/v2.1/standard/image-to-video","fal-ai/kling-video/v2.1/pro/image-to-video","fal-ai/kling-video/v2.1/master/image-to-video","fal-ai/minimax/video-01-live/image-to-video","fal-ai/luma-dream-machine/ray-2/image-to-video"],replicate:["kwaivgi/kling-v1.6-standard","kwaivgi/kling-v1.6-pro","minimax/video-01-live","luma/ray"]},text_to_video_generation:{fal:["fal-ai/kling-video/v1.6/standard/text-to-video","fal-ai/kling-video/v2.1/master/text-to-video","fal-ai/minimax/video-01-live ","fal-ai/luma-dream-machine/ray-2"],replicate:["kwaivgi/kling-v1.6-standard","minimax/video-01","luma/ray"]},upscale_image:{fal:["fal-ai/clarity-upscaler"],replicate:["recraft-ai/recraft-crisp-upscale"]},describe_image:{fal:["fal-ai/any-llm/vision"],replicate:[]},edit_area_in_image:{fal:["fal-ai/flux-pro/v1/fill"],replicate:["black-forest-labs/flux-fill-pro"],google:["gemini-2.0-flash-exp-image-generation"],openai:["gpt-image-1"]},edit_image:{fal:["fal-ai/gemini-flash-edit"],replicate:[],openai:["gpt-image-1"]},text_to_2d_illustration_generation:{fal:["fal-ai/recraft-v3"],replicate:[]},text_to_digital_illustration_generation:{fal:["fal-ai/recraft-v3"],replicate:["recraft-ai/recraft-v3"]},text_to_book_cover_generation:{fal:["fal-ai/recraft-v3"],replicate:[]},text_to_speech:{fal:["fal-ai/elevenlabs/tts/multilingual-v2"],replicate:["jaaari/kokoro-82m:f559560eb822dc509045f3921a1921234918b91739db4bf3daab2169b71c7a13"]}},ttsMaxCharacters:3e3,alwaysVisibleSubmit:!1};this.settings=Object.assign({},i,t),this.listeners={},window._txt&&(this.settings.lang=window._txt),this.steps=[];let s=this.settings.onChange;if(this.settings.onChange=n=>{s&&s.call(this,n)},!e)throw new Error("A valid DOM element is required.");e.classList.add("formview-container"),e.classList.add("fb-ui"),this.element=e,this.media=new hn({lang:this.settings.lang},this),this.upload=new pn({lang:this.settings.lang},this)}on(e,t){return this.listeners[e]||(this.listeners[e]=new Set),this.listeners[e].add(t),this}off(e,t){this.listeners[e]&&this.listeners[e].delete(t)}trigger(e,t){this.listeners[e]&&this.listeners[e].forEach(i=>i(t))}async loadTemplates(){if(!this.settings.templatesUrl){console.log(this.out("Template URL is not set."));return}let e=document.querySelector(this.settings.templatesSelector);if(e){e.classList.remove("hidden"),e.classList.add("formtemplates-container"),e.classList.add("fb-ui");let s=(await(await fetch(this.settings.templatesUrl,{method:"GET"})).json()).data;e.innerHTML="",s=s.filter(l=>{const h=l.supports||[];if(h.length===0)return!0;const{fal:p,replicate:b,web:w,openai:_,google:g}=this.settings.templatesConfig;return!w&&h.includes("web")||!g&&h.includes("google")||!_&&h.includes("openai")?!1:!p&&!b?!(h.includes("fal")||h.includes("replicate")):!p&&h.includes("fal")?h.includes("replicate"):!b&&h.includes("replicate")?h.includes("fal"):!0});const r=this.settings.templateFilters,o={all:{desc:this.out("All")},image:{desc:this.out("Image")},video:{desc:this.out("Video")},audio:{desc:this.out("Audio")},web:{desc:this.out("Web")},text:{desc:this.out("Text")}},a=document.createElement("div");a.className="app-filters",e.appendChild(a);const d=document.createElement("ul");d.className="app-list",e.appendChild(d);const u=l=>{let h=s.filter(b=>l==="all"||b.categories.includes(l));const p=this.settings.templateOutput||["image","video","audio","text"];h=h.filter(b=>b.categories.every(w=>p.includes(w))),this.renderList(h,d)};r.forEach(l=>{const h=document.createElement("button");h.textContent=o[l].desc,h.setAttribute("data-value",l),l==="all"&&h.classList.add("active"),h.addEventListener("click",()=>{a.querySelectorAll("button").forEach(b=>b.classList.remove("active")),h.classList.add("active"),u(l)}),a.appendChild(h)}),u("all")}}async selectFile(e){const t=this.element.querySelector(".file-input-wrapper");if(!t)return;const i=t.querySelector('input[type="file"]');if(!i||!this.acceptsImagesOnly(i))return;let s;e.startsWith("http")?s=this.settings.viewFileUrl+"?url="+e:s=e;const r=await(await fetch(s)).blob(),o=new File([r],e.split("/").pop(),{type:r.type});this.element.querySelector(".div-selected-preview")||(this.selectedFiles=[]),i&&i.hasAttribute("multiple")?this.selectedFiles.some(u=>u.name===o.name)||this.selectedFiles.push(o):this.selectedFiles=[o],this.setSelectedFiles(this.selectedFiles),this.renderSelectedFiles(),t.closest(".image-mask")&&this.objImageMask&&this.objImageMask.loadImage(o)}setSelectedFiles(e){this.selectedFiles=e;const t=this.element.querySelector('input[type="file"]');t&&t.removeAttribute("required")}renderSelectedFiles(){const e=this.element.querySelector(".file-input-wrapper");if(!e)return;let t=this.element.querySelector(".div-selected-preview");t?t.innerHTML="":(t=document.createElement("div"),t.classList.add("div-selected-preview"),e.appendChild(t)),this.clearFileInput(),this.selectedFiles&&this.selectedFiles.forEach((i,s)=>{const n=document.createElement("div"),r=document.createElement("img");r.src=URL.createObjectURL(i);const o=document.createElement("button");o.innerHTML=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round" class="">
304
304
  <path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M4 7l16 0" /><path d="M10 11l0 6" /><path d="M14 11l0 6" /><path d="M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l1 -12" /><path d="M9 7v-3a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3" />
305
305
  </svg>`,o.addEventListener("click",()=>{this.selectedFiles.splice(s,1),this.setSelectedFiles(this.selectedFiles),this.renderSelectedFiles(),e.closest(".image-mask")&&this.objImageMask&&this.objImageMask.clearImage()}),n.appendChild(r),n.appendChild(o),t.appendChild(n)})}clearSelectedFiles(){this.selectedFiles=[],this.setSelectedFiles(this.selectedFiles);let e=this.element.querySelector(".div-selected-preview");e&&(e.innerHTML="")}clearFileInput(){const e=this.element.querySelector(".file-input-wrapper");if(!e)return;const t=e.querySelector('input[type="file"]');if(!t)return;try{if(t.value="",t.files&&t.files.length>0){const a=new DataTransfer;t.files=a.files}}catch{}const i=e.querySelector(".file-drop-info-highlight");i&&(i.innerHTML="");const s=e.querySelector(".img-preview");s&&s.remove();const n=e.querySelector(".file-preview-container");n&&(n.innerHTML="");const r=e.querySelector(".btn-clearphoto");r&&r.click();const o=this.element.querySelector('input[type="file"]');o&&o.removeAttribute("required")}acceptsImagesOnly(e){const t=(e.getAttribute("accept")||"").split(",").map(i=>i.trim());return t.length===0?!1:t.every(i=>i.startsWith("image/")||i==="image/*")}renderList(e,t){t.innerHTML="",e.forEach(i=>{if(i.name){const s=document.createElement("li");t.appendChild(s);const n=document.createElement("a");n.setAttribute("href","#");let r=this.settings.assetsFolder,o=i.form.thumbnail,a="";if(r&&o){let h=r+o;a=`<img class="thumbnail" src="${h}" alt="${i.name}" />`,i.form.thumbnailFit&&(a=`<img class="thumbnail" style="object-fit:${i.form.thumbnailFit}" src="${h}" alt="${i.name}" />`)}const d=document.createElement("div");d.className="div-template-buttons";let u=!1,l=!1;if(this.settings.templateButtons&&this.settings.templateButtons.viewButton&&this.settings.templateButtons.viewButton.text){const h=document.createElement("button");h.className="btn-template-view",h.innerText=this.out(this.settings.templateButtons.viewButton.text),d.appendChild(h),h.addEventListener("click",p=>{if(p.preventDefault(),this.isGenerating){alert(this.out("Please wait until generation is complete."));return}this.settings.onSelectTemplate&&this.settings.onSelectTemplate(i),this.trigger("templateView",i)}),u=!0}if(this.settings.templateButtons&&this.settings.templateButtons.useButton&&this.settings.templateButtons.useButton.text){const h=document.createElement("button");h.className="btn-template-use",h.innerText=this.out(this.settings.templateButtons.useButton.text),d.appendChild(h),h.addEventListener("click",p=>{p.preventDefault(),this.settings.onSelectTemplate&&this.settings.onSelectTemplate(i),this.trigger("templateUse",i)}),l=!0}n.innerHTML=`
306
306
  ${a}
@@ -329,15 +329,15 @@ Check the information and return the details.
329
329
  <path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M7 7m0 2.667a2.667 2.667 0 0 1 2.667 -2.667h8.666a2.667 2.667 0 0 1 2.667 2.667v8.666a2.667 2.667 0 0 1 -2.667 2.667h-8.666a2.667 2.667 0 0 1 -2.667 -2.667z" /><path d="M4.012 16.737a2.005 2.005 0 0 1 -1.012 -1.737v-10c0 -1.1 .9 -2 2 -2h10c.75 0 1.158 .385 1.5 1" />
330
330
  </svg>
331
331
  <span>${this.out("Copy")}</span>
332
- `},600)}),l.addEventListener("click",h=>{h.preventDefault(),localStorage.removeItem("_results"),localStorage.removeItem("_results_html"),e.innerHTML=""})}getScrollableParent(e){for(;e.parentElement;){const i=window.getComputedStyle(e.parentElement).overflowY;if((i==="auto"||i==="scroll")&&e.parentElement.scrollHeight>e.parentElement.clientHeight)return e.parentElement;e=e.parentElement}return null}stickyElement(e){if(!this.settings.alwaysVisibleSubmit)return;const t=this.getScrollableParent(e);this._scrollListener&&(t?t.removeEventListener("scroll",this._scrollListener):window.removeEventListener("scroll",this._scrollListener),window.removeEventListener("resize",this._resizeListener));let i;const s=()=>{e.style.position="",t?i=e.offsetTop+e.offsetHeight-t.offsetTop:i=e.offsetTop+e.offsetHeight},n=()=>{if(t)if(t.offsetHeight+t.scrollTop>i)e.style.position="",e.style.top="";else{const a=window.innerHeight-e.offsetHeight;e.style.position="fixed",e.style.top=`${a}px`}else if(window.innerHeight+window.scrollY>i)e.style.position="",e.style.top="";else{const a=window.innerHeight-e.offsetHeight;e.style.position="fixed",e.style.top=`${a}px`}e.parentNode.offsetWidth!==0&&(e.style.width=`${e.parentNode.offsetWidth}px`)};this._scrollListener=n;let r;this._resizeListener=()=>{r&&clearTimeout(r),r=setTimeout(()=>{let o=null;const a=()=>{const d=e.offsetTop;d===o?(s(),n()):(o=d,requestAnimationFrame(a))};a()},200)},s(),n(),t?t.addEventListener("scroll",n):window.addEventListener("scroll",n),window.addEventListener("resize",this._resizeListener)}view(e){if(!e)return;let t;try{t=JSON.parse(e)}catch{console.log("Invalid JSON Form.");return}this.json=t,this.inputListener=()=>{clearTimeout(this.debounceTimeout),this.debounceTimeout=setTimeout(()=>{const n=this.getFormValues();this.settings.onInputChange&&this.settings.onInputChange(n)},300)},this.changeListener=()=>{const n=this.getFormValues();this.settings.onInputChange&&this.settings.onInputChange(n)};let i;if(this.settings.isBuilder){if(!this.settings.previewSelector){this.settings.consoleLog&&console.log("previewSelector not set.");return}i=document.querySelector(this.settings.previewSelector)}else i=this.element;if(i){if(i.classList.remove("hidden"),i.classList.add("formview-container"),i.classList.add("fb-ui"),i.innerHTML="",!(t.hideHeader||!1)){const l=document.createElement("div");l.className="form-header",i.appendChild(l);const h=document.createElement("h1");h.className="form-title",h.innerText=t.title||this.out("Your Form Title Here"),l.appendChild(h);const p=document.createElement("p");p.className="form-desc",p.innerText=t.description||this.out("Your Description Here"),l.appendChild(p)}let r;this.settings.isBuilder?r=document.createElement("form"):r=document.createElement("div"),r.className="form-wrapper",r.style.flexFlow="wrap",i.appendChild(r);let o=1;t.elements&&t.elements.forEach(l=>{if(l.type==="spacer"){const g=document.createElement("div");g.className="form-spacer",l.spacerHeight&&!isNaN(parseFloat(l.spacerHeight))&&(g.style.height=l.spacerHeight+"px"),l.displayInOutput||r.appendChild(g);return}if(l.type==="separator"){const g=document.createElement("hr");g.style.borderTopColor=l.color,l.displayInOutput||r.appendChild(g);return}if(l.type==="html"){if(l.html){const g=document.createElement("div");g.innerHTML=l.html,l.displayInOutput||r.appendChild(g)}return}if(l.type==="heading"){const g=document.createElement(l.heading||"h2");g.innerHTML=l.headingText||this.out("Your Heading Here!"),l.displayInOutput||r.appendChild(g);return}if(l.type==="paragraph"){const g=document.createElement("p");g.innerHTML=l.paragraphText||this.out("Your paragraph content here!"),l.displayInOutput||r.appendChild(g);return}if(l.type==="media"){if(l.tag==="video"){const g=document.createElement("video");g.style.width="100%",g.style.height="auto",g.controls=!0;var h=document.createElement("source");h.src=l.url,h.type="video/mp4",g.appendChild(h),l.displayInOutput||r.appendChild(g)}else if(l.tag==="audio"){const g=document.createElement("audio");g.controls=!0;let v=document.createElement("source");v.src=l.url,v.type="audio/mp3",g.appendChild(v),l.displayInOutput||r.appendChild(g)}else if(l.tag==="img"){const g=document.createElement("img");g.src=l.url,g.setAttribute("alt",this.out("Output Image")),l.displayInOutput||r.appendChild(g)}return}if(l.type==="image"){const g=document.createElement("img");g.src=l.url,g.setAttribute("alt",this.out("Output Image")),l.displayInOutput||r.appendChild(g);return}if(l.type==="video"){const g=document.createElement("video");g.style.width="100%",g.style.height="auto",g.controls=!0;let v=document.createElement("source");v.src=l.url,v.type="video/mp4",g.appendChild(v),l.displayInOutput||r.appendChild(g);return}if(l.type==="audio"){const g=document.createElement("audio");g.controls=!0;let v=document.createElement("source");v.src=l.url,v.type="audio/mp3",g.appendChild(v),l.displayInOutput||r.appendChild(g);return}const p=document.createElement("div");p.className="form-field",l.type==="hidden"&&(p.className="hidden"),l.displayInOutput||r.appendChild(p),l.type==="color"&&p.classList.add("field-color");const b=l.type;let w=l.name;if(r.querySelector(`[name="${w}"]`)&&(o++,w=w+"_"+o),b==="short-text"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`short_text_label_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`short_text_label_${g}`,f.type="text",f.name=w,f.value=l.value||"",f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("input",this.inputListener)}if(b==="long-text"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`long_text_label_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("textarea");f.id=`long_text_label_${g}`,f.name=w,f.value=l.value||"",f.className="inp-base",f.style.height=l.height+"px",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("input",this.inputListener)}if(b==="number"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`number_label_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`number_label_${g}`,f.type="number",f.name=w,f.value=l.value||"",f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("input",this.inputListener)}if(b==="slider"){p.classList.add("input-slider");let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`number_label_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500">*</span>':""),p.appendChild(v),l.fieldNote){const E=document.createElement("div");E.className="field-note",E.innerHTML=l.fieldNote,p.appendChild(E)}const f=document.createElement("div");f.className="slider-container",p.appendChild(f);const m=document.createElement("div");m.className="slider-values",f.appendChild(m);const y=document.createElement("span");m.appendChild(y),y.innerText=l.minValue;const k=document.createElement("span");m.appendChild(k),k.innerText=l.maxValue;const x=document.createElement("input");x.id=`number_label_${g}`,x.type="range",x.name=w,x.setAttribute("min",l.minValue),x.setAttribute("max",l.maxValue),x.setAttribute("step",l.step),x.setAttribute("value",l.value||0),f.appendChild(x);const S=document.createElement("div");S.className="current-value",f.appendChild(S),f.querySelector(".current-value").textContent=l.value||0,x.addEventListener("input",()=>{f.querySelector(".current-value").textContent=x.value})}if(b==="select"){let g=this.getId();const v=document.createElement("div");if(v.id=`radio_group_label_${g}`,v.className="field-label-normal",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("div");if(f.setAttribute("aria-labelledby",`radio_group_label_${g}`),f.setAttribute("role","group"),f.className="div-options",p.appendChild(f),l.choices&&l.choices.forEach((m,y)=>{let k=m;l.choicesText&&(k=l.choicesText[y]||m);const x=document.createElement("label");x.setAttribute("for",`${g}_${y}`),x.className="option-label",f.appendChild(x);const S=document.createElement("input");S.type="radio",S.className="peer",S.id=`${g}_${y}`,S.name=w,S.value=m,x.appendChild(S),y===l.selected&&(S.checked=!0);const E=document.createElement("span");E.className="peer-span-rounded",x.appendChild(E);const C='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M12 7a5 5 0 1 1 -4.995 5.217l-.005 -.217l.005 -.217a5 5 0 0 1 4.995 -4.783z"></path></svg>';E.innerHTML=C,y===0&&l.isRequired&&S.setAttribute("required","required");const A=document.createElement("span");A.innerText=k,x.appendChild(A),S.addEventListener("change",this.changeListener)}),l.showOtherItem){const m=document.createElement("label");m.setAttribute("for",g+"_other"),m.className="option-label",f.appendChild(m);const y=document.createElement("input");y.type="radio",y.className="peer",y.id=g+"_other",y.name=w,y.value="other",m.appendChild(y);const k=document.createElement("span");k.className="peer-span-rounded",m.appendChild(k);const x='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M12 7a5 5 0 1 1 -4.995 5.217l-.005 -.217l.005 -.217a5 5 0 0 1 4.995 -4.783z"></path></svg>';k.innerHTML=x;const S=document.createElement("span");S.innerText=l.otherText,m.appendChild(S);const E=document.createElement("div");p.appendChild(E);const C=document.createElement("input");C.type="text",C.name=w+"_other",C.className="inp-base",E.appendChild(C),y.addEventListener("change",this.changeListener),C.addEventListener("input",this.inputListener)}}if(b==="multi-select"){let g=this.getId();const v=document.createElement("div");if(v.id=`checkbox_group_label_${g}`,v.className="field-label-normal",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("div");if(f.setAttribute("aria-labelledby",`checkbox_group_label_${g}`),f.setAttribute("role","group"),f.className="div-options",p.appendChild(f),l.choices&&l.choices.forEach((m,y)=>{let k=m;l.choicesText&&(k=l.choicesText[y]||m);const x=document.createElement("label");x.setAttribute("for",`${g}_${y}`),x.className="option-label",f.appendChild(x);const S=document.createElement("input");S.type="checkbox",S.className="peer",S.id=`${g}_${y}`,S.name=w+"[]",S.value=m,x.appendChild(S);const E=document.createElement("span");E.className="peer-span-square",x.appendChild(E);const C=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="4" stroke-linecap="round" stroke-linejoin="round">
332
+ `},600)}),l.addEventListener("click",h=>{h.preventDefault(),localStorage.removeItem("_results"),localStorage.removeItem("_results_html"),e.innerHTML=""})}getScrollableParent(e){for(;e.parentElement;){const i=window.getComputedStyle(e.parentElement).overflowY;if((i==="auto"||i==="scroll")&&e.parentElement.scrollHeight>e.parentElement.clientHeight)return e.parentElement;e=e.parentElement}return null}stickyElement(e){if(!this.settings.alwaysVisibleSubmit)return;const t=this.getScrollableParent(e);this._scrollListener&&(t?t.removeEventListener("scroll",this._scrollListener):window.removeEventListener("scroll",this._scrollListener),window.removeEventListener("resize",this._resizeListener));let i;const s=()=>{e.style.position="",t?i=e.offsetTop+e.offsetHeight-t.offsetTop:i=e.offsetTop+e.offsetHeight},n=()=>{if(t)if(t.offsetHeight+t.scrollTop>i)e.style.position="",e.style.top="";else{const a=window.innerHeight-e.offsetHeight;e.style.position="fixed",e.style.top=`${a}px`}else if(window.innerHeight+window.scrollY>i)e.style.position="",e.style.top="";else{const a=window.innerHeight-e.offsetHeight;e.style.position="fixed",e.style.top=`${a}px`}e.parentNode.offsetWidth!==0&&(e.style.width=`${e.parentNode.offsetWidth}px`)};this._scrollListener=n;let r;this._resizeListener=()=>{r&&clearTimeout(r),r=setTimeout(()=>{let o=null;const a=()=>{const d=e.offsetTop;d===o?(s(),n()):(o=d,requestAnimationFrame(a))};a()},200)},s(),n(),t?t.addEventListener("scroll",n):window.addEventListener("scroll",n),window.addEventListener("resize",this._resizeListener)}view(e){if(!e)return;let t;try{t=JSON.parse(e)}catch{console.log("Invalid JSON Form.");return}this.json=t,this.inputListener=()=>{clearTimeout(this.debounceTimeout),this.debounceTimeout=setTimeout(()=>{const n=this.getFormValues();this.settings.onInputChange&&this.settings.onInputChange(n)},300)},this.changeListener=()=>{const n=this.getFormValues();this.settings.onInputChange&&this.settings.onInputChange(n)};let i;if(this.settings.isBuilder){if(!this.settings.previewSelector){this.settings.consoleLog&&console.log("previewSelector not set.");return}i=document.querySelector(this.settings.previewSelector)}else i=this.element;if(i){if(i.classList.remove("hidden"),i.classList.add("formview-container"),i.classList.add("fb-ui"),i.innerHTML="",!(t.hideHeader||!1)){const l=document.createElement("div");l.className="form-header",i.appendChild(l);const h=document.createElement("h1");h.className="form-title",h.innerText=t.title||this.out("Your Form Title Here"),l.appendChild(h);const p=document.createElement("p");p.className="form-desc",p.innerText=t.description||this.out("Your Description Here"),l.appendChild(p)}let r;this.settings.isBuilder?r=document.createElement("form"):r=document.createElement("div"),r.className="form-wrapper",r.style.flexFlow="wrap",i.appendChild(r);let o=1;t.elements&&t.elements.forEach(l=>{if(l.type==="spacer"){const g=document.createElement("div");g.className="form-spacer",l.spacerHeight&&!isNaN(parseFloat(l.spacerHeight))&&(g.style.height=l.spacerHeight+"px"),l.displayInOutput||r.appendChild(g);return}if(l.type==="separator"){const g=document.createElement("hr");g.style.borderTopColor=l.color,l.displayInOutput||r.appendChild(g);return}if(l.type==="html"){if(l.html){const g=document.createElement("div");g.innerHTML=l.html,l.displayInOutput||r.appendChild(g)}return}if(l.type==="heading"){const g=document.createElement(l.heading||"h2");g.innerHTML=l.headingText||this.out("Your Heading Here!"),l.displayInOutput||r.appendChild(g);return}if(l.type==="paragraph"){const g=document.createElement("p");g.innerHTML=l.paragraphText||this.out("Your paragraph content here!"),l.displayInOutput||r.appendChild(g);return}if(l.type==="media"){if(l.tag==="video"){const g=document.createElement("video");g.style.width="100%",g.style.height="auto",g.controls=!0;var h=document.createElement("source");h.src=l.url,h.type="video/mp4",g.appendChild(h),l.displayInOutput||r.appendChild(g)}else if(l.tag==="audio"){const g=document.createElement("audio");g.controls=!0;let y=document.createElement("source");y.src=l.url,y.type="audio/mp3",g.appendChild(y),l.displayInOutput||r.appendChild(g)}else if(l.tag==="img"){const g=document.createElement("img");g.src=l.url,g.setAttribute("alt",this.out("Output Image")),l.displayInOutput||r.appendChild(g)}return}if(l.type==="image"){const g=document.createElement("img");g.src=l.url,g.setAttribute("alt",this.out("Output Image")),l.displayInOutput||r.appendChild(g);return}if(l.type==="video"){const g=document.createElement("video");g.style.width="100%",g.style.height="auto",g.controls=!0;let y=document.createElement("source");y.src=l.url,y.type="video/mp4",g.appendChild(y),l.displayInOutput||r.appendChild(g);return}if(l.type==="audio"){const g=document.createElement("audio");g.controls=!0;let y=document.createElement("source");y.src=l.url,y.type="audio/mp3",g.appendChild(y),l.displayInOutput||r.appendChild(g);return}const p=document.createElement("div");p.className="form-field",l.type==="hidden"&&(p.className="hidden"),l.displayInOutput||r.appendChild(p),l.type==="color"&&p.classList.add("field-color");const b=l.type;let w=l.name;if(r.querySelector(`[name="${w}"]`)&&(o++,w=w+"_"+o),b==="short-text"){let g=this.getId();const y=document.createElement("label");if(y.setAttribute("for",`short_text_label_${g}`),y.className="field-label",y.innerHTML=l.title+(l.isRequired?' <span class="text-red-500" aria-hidden="true">*</span>':""),p.appendChild(y),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`short_text_label_${g}`,f.type="text",f.name=w,f.value=l.value||"",f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("input",this.inputListener)}if(b==="long-text"){let g=this.getId();const y=document.createElement("label");if(y.setAttribute("for",`long_text_label_${g}`),y.className="field-label",y.innerHTML=l.title+(l.isRequired?' <span class="text-red-500" aria-hidden="true">*</span>':""),p.appendChild(y),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("textarea");f.id=`long_text_label_${g}`,f.name=w,f.value=l.value||"",f.className="inp-base",f.style.height=l.height+"px",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("input",this.inputListener)}if(b==="number"){let g=this.getId();const y=document.createElement("label");if(y.setAttribute("for",`number_label_${g}`),y.className="field-label",y.innerHTML=l.title+(l.isRequired?' <span class="text-red-500" aria-hidden="true">*</span>':""),p.appendChild(y),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`number_label_${g}`,f.type="number",f.name=w,f.value=l.value||"",f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("input",this.inputListener)}if(b==="slider"){p.classList.add("input-slider");let g=this.getId();const y=document.createElement("label");if(y.setAttribute("for",`number_label_${g}`),y.className="field-label",y.innerHTML=l.title+(l.isRequired?' <span class="text-red-500" aria-hidden="true">*</span>':""),p.appendChild(y),l.fieldNote){const E=document.createElement("div");E.className="field-note",E.innerHTML=l.fieldNote,p.appendChild(E)}const f=document.createElement("div");f.className="slider-container",p.appendChild(f);const m=document.createElement("div");m.className="slider-values",f.appendChild(m);const v=document.createElement("span");m.appendChild(v),v.innerText=l.minValue;const k=document.createElement("span");m.appendChild(k),k.innerText=l.maxValue;const x=document.createElement("input");x.id=`number_label_${g}`,x.type="range",x.name=w,x.setAttribute("min",l.minValue),x.setAttribute("max",l.maxValue),x.setAttribute("step",l.step),x.setAttribute("value",l.value||0),f.appendChild(x);const S=document.createElement("div");S.className="current-value",f.appendChild(S),f.querySelector(".current-value").textContent=l.value||0,x.addEventListener("input",()=>{f.querySelector(".current-value").textContent=x.value})}if(b==="select"){let g=this.getId();const y=document.createElement("div");if(y.id=`radio_group_label_${g}`,y.className="field-label-normal",y.innerHTML=l.title+(l.isRequired?' <span class="text-red-500" aria-hidden="true">*</span>':""),p.appendChild(y),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("div");if(f.setAttribute("aria-labelledby",`radio_group_label_${g}`),f.setAttribute("role","group"),f.className="div-options",p.appendChild(f),l.choices&&l.choices.forEach((m,v)=>{let k=m;l.choicesText&&(k=l.choicesText[v]||m);const x=document.createElement("label");x.setAttribute("for",`${g}_${v}`),x.className="option-label",f.appendChild(x);const S=document.createElement("input");S.type="radio",S.className="peer",S.id=`${g}_${v}`,S.name=w,S.value=m,x.appendChild(S),v===l.selected&&(S.checked=!0);const E=document.createElement("span");E.className="peer-span-rounded",x.appendChild(E);const C='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M12 7a5 5 0 1 1 -4.995 5.217l-.005 -.217l.005 -.217a5 5 0 0 1 4.995 -4.783z"></path></svg>';E.innerHTML=C,v===0&&l.isRequired&&S.setAttribute("required","required");const A=document.createElement("span");A.innerText=k,x.appendChild(A),S.addEventListener("change",this.changeListener)}),l.showOtherItem){const m=document.createElement("label");m.setAttribute("for",g+"_other"),m.className="option-label",f.appendChild(m);const v=document.createElement("input");v.type="radio",v.className="peer",v.id=g+"_other",v.name=w,v.value="other",m.appendChild(v);const k=document.createElement("span");k.className="peer-span-rounded",m.appendChild(k);const x='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M12 7a5 5 0 1 1 -4.995 5.217l-.005 -.217l.005 -.217a5 5 0 0 1 4.995 -4.783z"></path></svg>';k.innerHTML=x;const S=document.createElement("span");S.innerText=l.otherText,m.appendChild(S);const E=document.createElement("div");p.appendChild(E);const C=document.createElement("input");C.type="text",C.name=w+"_other",C.className="inp-base",E.appendChild(C),v.addEventListener("change",this.changeListener),C.addEventListener("input",this.inputListener)}}if(b==="multi-select"){let g=this.getId();const y=document.createElement("div");if(y.id=`checkbox_group_label_${g}`,y.className="field-label-normal",y.innerHTML=l.title+(l.isRequired?` <span class="text-red-500" aria-hidden="true">*</span><span style="position:absolute;width:1px;height:1px;clip-path:inset(50%);overflow:hidden;white-space:nowrap;">(${this.out("required")})</span>`:""),p.appendChild(y),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("div");if(f.setAttribute("aria-labelledby",`checkbox_group_label_${g}`),f.setAttribute("role","group"),f.className="div-options",p.appendChild(f),l.choices&&l.choices.forEach((m,v)=>{let k=m;l.choicesText&&(k=l.choicesText[v]||m);const x=document.createElement("label");x.setAttribute("for",`${g}_${v}`),x.className="option-label",f.appendChild(x);const S=document.createElement("input");S.type="checkbox",S.className="peer",S.id=`${g}_${v}`,S.name=w+"[]",S.value=m,x.appendChild(S);const E=document.createElement("span");E.className="peer-span-square",x.appendChild(E);const C=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="4" stroke-linecap="round" stroke-linejoin="round">
333
333
  <path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M5 12l5 5l10 -10" />
334
- </svg>`;E.innerHTML=C;const A=document.createElement("span");A.innerText=k,x.appendChild(A),S.addEventListener("change",this.changeListener)}),l.showOtherItem){const m=document.createElement("label");m.setAttribute("for",g+"_other"),m.className="option-label",f.appendChild(m);const y=document.createElement("input");y.type="checkbox",y.className="peer",y.id=g+"_other",y.name=w,y.value="other",m.appendChild(y);const k=document.createElement("span");k.className="peer-span-square",m.appendChild(k);const x=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="4" stroke-linecap="round" stroke-linejoin="round">
334
+ </svg>`;E.innerHTML=C;const A=document.createElement("span");A.innerText=k,x.appendChild(A),S.addEventListener("change",this.changeListener)}),l.showOtherItem){const m=document.createElement("label");m.setAttribute("for",g+"_other"),m.className="option-label",f.appendChild(m);const v=document.createElement("input");v.type="checkbox",v.className="peer",v.id=g+"_other",v.name=w,v.value="other",m.appendChild(v);const k=document.createElement("span");k.className="peer-span-square",m.appendChild(k);const x=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="4" stroke-linecap="round" stroke-linejoin="round">
335
335
  <path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M5 12l5 5l10 -10" />
336
- </svg>`;k.innerHTML=x;const S=document.createElement("span");S.innerText=l.otherText,m.appendChild(S);const E=document.createElement("div");p.appendChild(E);const C=document.createElement("input");C.type="text",C.name=w+"_other",C.className="inp-base",E.appendChild(C),y.addEventListener("change",this.changeListener),C.addEventListener("input",this.inputListener)}}if(b==="switch"){let g=this.getId();const v=document.createElement("label");if(v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500">*</span>':""),v.id=`switch_${g}`,p.appendChild(v),l.fieldNote){const x=document.createElement("div");x.className="field-note",x.innerHTML=l.fieldNote,p.appendChild(x)}const f=document.createElement("div");f.className="switch",f.tabIndex=0,f.role="switch",f.setAttribute("aria-labelledby",`switch_${g}`),f.setAttribute("aria-checked","false"),f.setAttribute("data-checked","false"),p.appendChild(f);const m=document.createElement("div");m.className="switch-thumb",f.appendChild(m);const y=document.createElement("input");y.id=`switch_${g}`,y.type="text",y.name=w,y.style.cssText="opacity:0.01;width:1px;height:1px;position:absolute;bottom:0px;left:25px;",y.setAttribute("tabindex","-1"),l.isRequired&&(y.setAttribute("required","required"),y.setCustomValidity(this.out("Please toggle this switch to proceed."))),f.appendChild(y),l.value==="true"?(f.setAttribute("aria-checked","true"),f.setAttribute("data-checked","true"),y.value="true",l.isRequired&&y.setCustomValidity("")):(f.setAttribute("aria-checked","false"),f.setAttribute("data-checked","false"),y.value="false",l.isRequired&&y.setCustomValidity(this.out("Please toggle this switch to proceed."))),v.addEventListener("click",()=>{f.focus()});const k=()=>{const x=f.getAttribute("aria-checked")==="true";f.setAttribute("aria-checked",!x),f.setAttribute("data-checked",!x),x?(y.value="false",l.isRequired&&y.setCustomValidity(this.out("Please toggle this switch to proceed."))):(y.value="true",l.isRequired&&y.setCustomValidity(""));const S=this.getFormValues();this.settings.onInputChange&&this.settings.onInputChange(S)};f.addEventListener("keydown",x=>{(x.key===" "||x.key==="Enter")&&(x.preventDefault(),k())}),f.addEventListener("click",()=>{k()})}if(b==="dropdown"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`dropdown_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500">*</span>':""),p.appendChild(v),l.fieldNote){const A=document.createElement("div");A.className="field-note",A.innerHTML=l.fieldNote,p.appendChild(A)}const f=document.createElement("div");f.className="relative",p.appendChild(f);const m=document.createElement("div");m.className="relative inline-block",f.appendChild(m);const y=document.createElement("select");y.id=`dropdown_${g}`,y.name=w,l.isRequired&&y.setAttribute("required","required"),m.appendChild(y);const k=document.createElement("option");if(k.setAttribute("selected","selected"),k.setAttribute("disabled","disabled"),k.value="",k.innerText=l.placeholder,y.appendChild(k),l.choices&&l.choices.forEach((A,L)=>{let D=A;l.choicesText&&(D=l.choicesText[L]||A);const I=document.createElement("option");I.value=A,I.innerText=D,y.appendChild(I),L===l.selected&&(k.remove(),I.setAttribute("selected","selected"))}),l.showOtherItem){const A=document.createElement("option");A.value="other",A.innerText=l.otherText,y.appendChild(A)}const x=document.createElement("div");x.className="select-arrow",m.appendChild(x),this.appendHtml(x,`
336
+ </svg>`;k.innerHTML=x;const S=document.createElement("span");S.innerText=l.otherText,m.appendChild(S);const E=document.createElement("div");p.appendChild(E);const C=document.createElement("input");C.type="text",C.name=w+"_other",C.className="inp-base",E.appendChild(C),v.addEventListener("change",this.changeListener),C.addEventListener("input",this.inputListener)}}if(b==="switch"){let g=this.getId();const y=document.createElement("label");if(y.className="field-label",y.innerHTML=l.title+(l.isRequired?' <span class="text-red-500" aria-hidden="true">*</span>':""),y.id=`switch_${g}`,p.appendChild(y),l.fieldNote){const x=document.createElement("div");x.className="field-note",x.innerHTML=l.fieldNote,p.appendChild(x)}const f=document.createElement("div");f.className="switch",f.tabIndex=0,f.role="switch",f.setAttribute("aria-labelledby",`switch_${g}`),f.setAttribute("aria-checked","false"),f.setAttribute("data-checked","false"),p.appendChild(f);const m=document.createElement("div");m.className="switch-thumb",f.appendChild(m);const v=document.createElement("input");v.id=`switch_input_${g}`,v.setAttribute("aria-hidden","true"),v.type="text",v.name=w,v.style.cssText="position:absolute;bottom:0px;left:25px;width:1px;height:1px;clip-path:inset(50%);overflow:hidden;",v.setAttribute("tabindex","-1"),l.isRequired&&(v.setAttribute("required","required"),v.setCustomValidity(this.out("Please toggle this switch to proceed.")),f.setAttribute("aria-required","true")),p.appendChild(v),l.value==="true"?(f.setAttribute("aria-checked","true"),f.setAttribute("data-checked","true"),v.value="true",l.isRequired&&v.setCustomValidity("")):(f.setAttribute("aria-checked","false"),f.setAttribute("data-checked","false"),v.value="false",l.isRequired&&v.setCustomValidity(this.out("Please toggle this switch to proceed."))),y.addEventListener("click",()=>{f.focus()});const k=()=>{const x=f.getAttribute("aria-checked")==="true";f.setAttribute("aria-checked",!x),f.setAttribute("data-checked",!x),x?(v.value="false",l.isRequired&&v.setCustomValidity(this.out("Please toggle this switch to proceed."))):(v.value="true",l.isRequired&&v.setCustomValidity(""));const S=this.getFormValues();this.settings.onInputChange&&this.settings.onInputChange(S)};f.addEventListener("keydown",x=>{(x.key===" "||x.key==="Enter")&&(x.preventDefault(),k())}),f.addEventListener("click",()=>{k()})}if(b==="dropdown"){let g=this.getId();const y=document.createElement("label");if(y.setAttribute("for",`dropdown_${g}`),y.className="field-label",y.innerHTML=l.title+(l.isRequired?' <span class="text-red-500" aria-hidden="true">*</span>':""),p.appendChild(y),l.fieldNote){const A=document.createElement("div");A.className="field-note",A.innerHTML=l.fieldNote,p.appendChild(A)}const f=document.createElement("div");f.className="relative",p.appendChild(f);const m=document.createElement("div");m.className="relative inline-block",f.appendChild(m);const v=document.createElement("select");v.id=`dropdown_${g}`,v.name=w,l.isRequired&&v.setAttribute("required","required"),m.appendChild(v);const k=document.createElement("option");if(k.setAttribute("selected","selected"),k.setAttribute("disabled","disabled"),k.value="",k.innerText=l.placeholder,v.appendChild(k),l.choices&&l.choices.forEach((A,L)=>{let D=A;l.choicesText&&(D=l.choicesText[L]||A);const I=document.createElement("option");I.value=A,I.innerText=D,v.appendChild(I),L===l.selected&&(k.remove(),I.setAttribute("selected","selected"))}),l.showOtherItem){const A=document.createElement("option");A.value="other",A.innerText=l.otherText,v.appendChild(A)}const x=document.createElement("div");x.className="select-arrow",m.appendChild(x),this.appendHtml(x,`
337
337
  <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
338
338
  <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" />
339
339
  </svg>
340
- `);const S=document.createElement("input");S.type="text",S.id=`input_other_${g}`,S.name=w+"_other",S.className="input-other hidden inp-base",p.appendChild(S);const E=p.querySelector(`#dropdown_${g}`),C=p.querySelector(`#input_other_${g}`);E.addEventListener("change",()=>{E.value==="other"?(C.classList.remove("hidden"),C.focus()):C.classList.add("hidden");const A=this.getFormValues();this.settings.onInputChange&&this.settings.onInputChange(A)}),S.addEventListener("input",this.inputListener)}if(b==="date"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`date_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`date_${g}`,f.type="date",f.name=w,f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("change",this.changeListener)}if(b==="time"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`time_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`time_${g}`,f.type="time",f.name=w,f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("change",this.changeListener)}if(b==="datetime"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`datetime_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`datetime_${g}`,f.type="datetime-local",f.name=w,f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("change",this.changeListener)}if(b==="color"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`color_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`color_${g}`,f.type="color",f.name=w,f.value=l.value||"",f.className="input-color",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("input",this.inputListener)}if(b==="file"||b==="multifile"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`file_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500">*</span>':""),p.appendChild(v),l.fieldNote){const P=document.createElement("div");P.className="field-note",P.innerHTML=l.fieldNote,p.appendChild(P)}const f=document.createElement("div");f.className="file-input-wrapper",b==="file"&&f.setAttribute("aria-label",this.out(this.settings.fileUploadText)),b==="multifile"&&f.setAttribute("aria-label",this.out(this.settings.multiFileUploadText)),p.appendChild(f);const m=document.createElement("input");m.id=`input_url_label_${g}`,m.type="text",m.name=w+"__url",m.value=l.value||"",m.className="inp-base input-file-url",m.placeholder=l.placeholder||this.out("Enter URL."),p.appendChild(m),m.addEventListener("input",()=>{const P=p.querySelector(".btn-clearfile");P&&P.click(),this.inputListener(),m.value!==""?l.isRequired&&y.removeAttribute("required"):l.isRequired&&y.setAttribute("required","required"),Lt(m.value),this.clearSelectedFiles()}),l.useURL?m.style.display="":m.style.display="none";const y=document.createElement("input");y.id=`file_${g}`,y.type="file",b==="multifile"&&(y.multiple=!0),y.name=w,l.isRequired&&y.setAttribute("required","required"),y.className="peer",f.appendChild(y);const k=document.createElement("div");k.className="file-drop-area",f.appendChild(k);const x=document.createElement("div");x.className="file-controls",x.id=`drag_message_${g}`,f.appendChild(x);let S;(!l.source||l.source&&l.source==="local"||l.source&&l.source==="local_and_camera")&&(S=document.createElement("div"),S.className="file-drop-info",b==="file"&&(S.innerHTML=this.out(this.settings.fileUploadText)),b==="multifile"&&(S.innerHTML=this.out(this.settings.multiFileUploadText)),x.appendChild(S));let E;(!l.source||l.source&&l.source==="local"||l.source&&l.source==="local_and_camera")&&(E=document.createElement("button"),E.className="btn-selectfile",E.innerHTML=`
340
+ `);const S=document.createElement("input");S.type="text",S.id=`input_other_${g}`,S.name=w+"_other",S.className="input-other hidden inp-base",p.appendChild(S);const E=p.querySelector(`#dropdown_${g}`),C=p.querySelector(`#input_other_${g}`);E.addEventListener("change",()=>{E.value==="other"?(C.classList.remove("hidden"),C.focus()):C.classList.add("hidden");const A=this.getFormValues();this.settings.onInputChange&&this.settings.onInputChange(A)}),S.addEventListener("input",this.inputListener)}if(b==="date"){let g=this.getId();const y=document.createElement("label");if(y.setAttribute("for",`date_${g}`),y.className="field-label",y.innerHTML=l.title+(l.isRequired?' <span class="text-red-500" aria-hidden="true">*</span>':""),p.appendChild(y),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`date_${g}`,f.type="date",f.name=w,f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("change",this.changeListener)}if(b==="time"){let g=this.getId();const y=document.createElement("label");if(y.setAttribute("for",`time_${g}`),y.className="field-label",y.innerHTML=l.title+(l.isRequired?' <span class="text-red-500" aria-hidden="true">*</span>':""),p.appendChild(y),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`time_${g}`,f.type="time",f.name=w,f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("change",this.changeListener)}if(b==="datetime"){let g=this.getId();const y=document.createElement("label");if(y.setAttribute("for",`datetime_${g}`),y.className="field-label",y.innerHTML=l.title+(l.isRequired?' <span class="text-red-500" aria-hidden="true">*</span>':""),p.appendChild(y),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`datetime_${g}`,f.type="datetime-local",f.name=w,f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("change",this.changeListener)}if(b==="color"){let g=this.getId();const y=document.createElement("label");if(y.setAttribute("for",`color_${g}`),y.className="field-label",y.innerHTML=l.title+(l.isRequired?' <span class="text-red-500" aria-hidden="true">*</span>':""),p.appendChild(y),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`color_${g}`,f.type="color",f.name=w,f.value=l.value||"",f.className="input-color",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("input",this.inputListener)}if(b==="file"||b==="multifile"){let g=this.getId();const y=document.createElement("label");if(y.setAttribute("for",`file_${g}`),y.className="field-label",y.innerHTML=l.title+(l.isRequired?' <span class="text-red-500" aria-hidden="true">*</span>':""),p.appendChild(y),l.fieldNote){const P=document.createElement("div");P.className="field-note",P.innerHTML=l.fieldNote,p.appendChild(P)}const f=document.createElement("div");f.className="file-input-wrapper",b==="file"&&f.setAttribute("aria-label",this.out(this.settings.fileUploadText)),b==="multifile"&&f.setAttribute("aria-label",this.out(this.settings.multiFileUploadText)),p.appendChild(f);const m=document.createElement("input");m.id=`input_url_label_${g}`,m.type="text",m.name=w+"__url",m.value=l.value||"",m.className="inp-base input-file-url",m.placeholder=l.placeholder||this.out("Enter URL."),p.appendChild(m),m.addEventListener("input",()=>{const P=p.querySelector(".btn-clearfile");P&&P.click(),this.inputListener(),m.value!==""?l.isRequired&&v.removeAttribute("required"):l.isRequired&&v.setAttribute("required","required"),Lt(m.value),this.clearSelectedFiles()}),l.useURL?m.style.display="":m.style.display="none";const v=document.createElement("input");v.id=`file_${g}`,v.type="file",b==="multifile"&&(v.multiple=!0),v.name=w,l.isRequired&&v.setAttribute("required","required"),v.className="peer",f.appendChild(v);const k=document.createElement("div");k.className="file-drop-area",f.appendChild(k);const x=document.createElement("div");x.className="file-controls",x.id=`drag_message_${g}`,f.appendChild(x);let S;(!l.source||l.source&&l.source==="local"||l.source&&l.source==="local_and_camera")&&(S=document.createElement("div"),S.className="file-drop-info",b==="file"&&(S.innerHTML=this.out(this.settings.fileUploadText)),b==="multifile"&&(S.innerHTML=this.out(this.settings.multiFileUploadText)),x.appendChild(S));let E;(!l.source||l.source&&l.source==="local"||l.source&&l.source==="local_and_camera")&&(E=document.createElement("button"),E.className="btn-selectfile",E.innerHTML=`
341
341
  <svg style="fill:none"xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round" class="icon-folder-open"><path stroke="none" d="M0 0h24v24H0z" fill="none"/>
342
342
  <path d="M5 19l2.757 -7.351a1 1 0 0 1 .936 -.649h12.307a1 1 0 0 1 .986 1.164l-.996 5.211a2 2 0 0 1 -1.964 1.625h-14.026a2 2 0 0 1 -2 -2v-11a2 2 0 0 1 2 -2h4l3 3h7a2 2 0 0 1 2 2v2" />
343
343
  </svg>
@@ -347,7 +347,7 @@ Check the information and return the details.
347
347
  <path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M5 7h1a2 2 0 0 0 2 -2a1 1 0 0 1 1 -1h6a1 1 0 0 1 1 1a2 2 0 0 0 2 2h1a2 2 0 0 1 2 2v9a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-9a2 2 0 0 1 2 -2" /><path d="M9 13a3 3 0 1 0 6 0a3 3 0 0 0 -6 0" />
348
348
  </svg>
349
349
  ${this.out("Take Photo")}
350
- `,x.appendChild(C));const A=document.createElement("div");A.className="file-preview-container",f.appendChild(A);const L=document.createElement("div");L.className="file-drop-info-highlight",L.id=`file_name_${g}`,f.appendChild(L),E&&E.addEventListener("click",P=>{P.preventDefault(),y.click()}),f.classList.add("disabledrop"),(!l.source||l.source&&l.source==="local"||l.source&&l.source==="local_and_camera")&&(f.classList.remove("disabledrop"),f.addEventListener("dragover",P=>{P.preventDefault(),Array.from(P.dataTransfer.items).some(se=>se.kind==="file")&&f.classList.add("drag-over")}),f.addEventListener("dragleave",()=>{f.classList.remove("drag-over")}),b==="file"?f.addEventListener("drop",P=>{if(P.preventDefault(),P.dataTransfer.files&&P.dataTransfer.files.length>0){f.classList.remove("drag-over");const X=P.dataTransfer.files[0];X&&(y.files=P.dataTransfer.files,Ne(X),this.clearSelectedFiles())}}):b==="multifile"&&f.addEventListener("drop",P=>{if(P.preventDefault(),P.dataTransfer.files&&P.dataTransfer.files.length>0){f.classList.remove("drag-over"),A.innerHTML="";const X=P.dataTransfer.files;X.length>0&&(y.files=X,Array.from(X).forEach(se=>{De(se)}),this.clearSelectedFiles())}})),b==="file"?y.addEventListener("change",()=>{const P=y.files[0];P&&(Ne(P),this.clearSelectedFiles())}):b==="multifile"&&y.addEventListener("change",()=>{A.innerHTML="";const P=y.files;Array.from(P).forEach(X=>{X&&(De(X),this.clearSelectedFiles())})});const D={images:[{type:"image/jpeg",extensions:".jpg, .jpeg"},{type:"image/png",extensions:".png"},{type:"image/gif",extensions:".gif"},{type:"image/webp",extensions:".webp"}],videos:[{type:"video/mp4",extensions:".mp4"},{type:"video/webm",extensions:".webm"},{type:"video/ogg",extensions:".ogg"},{type:"video/quicktime",extensions:".mov"}],audio:[{type:"audio/mpeg",extensions:".mp3"},{type:"audio/wav",extensions:".wav"}],documents:[{type:"application/pdf",extensions:".pdf"},{type:"application/json",extensions:".json"},{type:"text/plain",extensions:".txt"},{type:"text/csv",extensions:".csv"},{type:"application/msword",extensions:".doc"},{type:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",extensions:".docx"},{type:"application/vnd.ms-excel",extensions:".xls"},{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",extensions:".xlsx"}],others:[{type:"application/zip",extensions:".zip"},{type:"application/x-rar-compressed",extensions:".rar"}]};let I=[];(l.allowedFileTypes||["images","videos","audio","documents","others"]).forEach(P=>{switch(P){case"images":I=I.concat(D.images);break;case"videos":I=I.concat(D.videos);break;case"audio":I=I.concat(D.audio);break;case"documents":I=I.concat(D.documents);break;case"others":I=I.concat(D.others);break}});const R=I.map(P=>P.type).join(",");y.setAttribute("accept",R);let q;if(l.useImageMask){p.classList.add("image-mask");const P=document.createElement("div");p.appendChild(P),q=new fn(P,{lang:this.settings.lang,name:w+"_mask"}),this.objImageMask=q}l.largePreview&&p.classList.add("large-preview");const M=()=>{const P=f.querySelector(".img-preview");P&&(P.remove(),l.useImageMask&&q.clearImage())};let T=`
350
+ `,x.appendChild(C));const A=document.createElement("div");A.className="file-preview-container",f.appendChild(A);const L=document.createElement("div");L.className="file-drop-info-highlight",L.id=`file_name_${g}`,f.appendChild(L),E&&E.addEventListener("click",P=>{P.preventDefault(),v.click()}),f.classList.add("disabledrop"),(!l.source||l.source&&l.source==="local"||l.source&&l.source==="local_and_camera")&&(f.classList.remove("disabledrop"),f.addEventListener("dragover",P=>{P.preventDefault(),Array.from(P.dataTransfer.items).some(se=>se.kind==="file")&&f.classList.add("drag-over")}),f.addEventListener("dragleave",()=>{f.classList.remove("drag-over")}),b==="file"?f.addEventListener("drop",P=>{if(P.preventDefault(),P.dataTransfer.files&&P.dataTransfer.files.length>0){f.classList.remove("drag-over");const X=P.dataTransfer.files[0];X&&(v.files=P.dataTransfer.files,Ne(X),this.clearSelectedFiles())}}):b==="multifile"&&f.addEventListener("drop",P=>{if(P.preventDefault(),P.dataTransfer.files&&P.dataTransfer.files.length>0){f.classList.remove("drag-over"),A.innerHTML="";const X=P.dataTransfer.files;X.length>0&&(v.files=X,Array.from(X).forEach(se=>{De(se)}),this.clearSelectedFiles())}})),b==="file"?v.addEventListener("change",()=>{const P=v.files[0];P&&(Ne(P),this.clearSelectedFiles())}):b==="multifile"&&v.addEventListener("change",()=>{A.innerHTML="";const P=v.files;Array.from(P).forEach(X=>{X&&(De(X),this.clearSelectedFiles())})});const D={images:[{type:"image/jpeg",extensions:".jpg, .jpeg"},{type:"image/png",extensions:".png"},{type:"image/gif",extensions:".gif"},{type:"image/webp",extensions:".webp"}],videos:[{type:"video/mp4",extensions:".mp4"},{type:"video/webm",extensions:".webm"},{type:"video/ogg",extensions:".ogg"},{type:"video/quicktime",extensions:".mov"}],audio:[{type:"audio/mpeg",extensions:".mp3"},{type:"audio/wav",extensions:".wav"}],documents:[{type:"application/pdf",extensions:".pdf"},{type:"application/json",extensions:".json"},{type:"text/plain",extensions:".txt"},{type:"text/csv",extensions:".csv"},{type:"application/msword",extensions:".doc"},{type:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",extensions:".docx"},{type:"application/vnd.ms-excel",extensions:".xls"},{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",extensions:".xlsx"}],others:[{type:"application/zip",extensions:".zip"},{type:"application/x-rar-compressed",extensions:".rar"}]};let I=[];(l.allowedFileTypes||["images","videos","audio","documents","others"]).forEach(P=>{switch(P){case"images":I=I.concat(D.images);break;case"videos":I=I.concat(D.videos);break;case"audio":I=I.concat(D.audio);break;case"documents":I=I.concat(D.documents);break;case"others":I=I.concat(D.others);break}});const R=I.map(P=>P.type).join(",");v.setAttribute("accept",R);let q;if(l.useImageMask){p.classList.add("image-mask");const P=document.createElement("div");p.appendChild(P),q=new fn(P,{lang:this.settings.lang,name:w+"_mask"}),this.objImageMask=q}l.largePreview&&p.classList.add("large-preview");const M=()=>{const P=f.querySelector(".img-preview");P&&(P.remove(),l.useImageMask&&q.clearImage())};let T=`
351
351
  <div class="div-livevideo">
352
352
  <video class="livevideo" autoplay playsinline style="display:none"></video>
353
353
  <canvas class="photo-captured" style="display:none"></canvas>
@@ -379,19 +379,19 @@ Check the information and return the details.
379
379
  </svg>
380
380
  </button>
381
381
  </div>
382
- `;this.appendHtml(f,T);const $=p.querySelector(".livevideo"),N=p.querySelector(".photo-captured"),U=p.querySelector(".btn-selectfile2"),G=p.querySelector(".btn-takephoto2"),Y=p.querySelector(".btn-capturephoto"),he=p.querySelector(".btn-clearphoto"),re=p.querySelector(".btn-stopcamera");this.photoBlob={};let ye;U&&U.addEventListener("click",P=>{P.preventDefault(),E.click()});const Me=async()=>{const P=p.querySelector(".btn-clearfile");P&&P.click();try{ye=await navigator.mediaDevices.getUserMedia({video:!0}),$.srcObject=ye}catch{alert("Unable to access the camera."),$.style.display="none",Y.style.display="none",re.style.display="none",x.style.display="none",L.style.display="none"}setTimeout(()=>{G.style.display="none",N.style.display="none",$.style.display="",Y.style.display="",he.style.display="none",U&&(U.style.display="none"),G.style.display="none",re.style.display="",x.style.display="none",L.style.display="none"},100)};C&&C.addEventListener("click",async P=>{P.preventDefault(),Me()}),G.addEventListener("click",async P=>{P.preventDefault(),Me()}),re.addEventListener("click",()=>{ye&&ye.getTracks().forEach(P=>P.stop()),$.style.display="none",Y.style.display="none",re.style.display="none",G.style.display="none",x.style.display="",L.style.display=""}),Y.addEventListener("click",P=>{if(P.preventDefault(),N.style.display="",N.width=$.videoWidth,N.height=$.videoHeight,N.getContext("2d").drawImage($,0,0,N.width,N.height),ye.getTracks().forEach(X=>X.stop()),$.style.display="none",Y.style.display="none",he.style.display="",U&&(U.style.display=""),G.style.display="",re.style.display="none",N.toBlob(X=>{this.photoBlob[w]=X,y.removeAttribute("required")},"image/jpeg"),G.style.display="",l.useImageMask){const X=N.toDataURL("image/jpeg");q.setImage(X)}this.clearSelectedFiles()});const $e=()=>{this.photoBlob[w]=null,N.style.display="none",N.getContext("2d").clearRect(0,0,N.width,N.height),m.value!==""?l.isRequired&&y.removeAttribute("required"):l.isRequired&&y.setAttribute("required","required"),he.style.display="none",U&&(U.style.display="none"),G.style.display="none",x.style.display="",L.style.display=""};he.addEventListener("click",()=>{$e()});const Lt=(P,X)=>{const se=`.${P.split(".").pop().toLowerCase()}`;if(!I.some(j=>j.extensions.split(", ").includes(se)))return;let Se=D.images.some(j=>j.extensions.split(", ").includes(se));if(l.useImageMask){if(!Se)return;q.loadUrl(P)}$e(),L.innerHTML="";const pe=document.createElement("div");L.appendChild(pe);const K=document.createElement("button");if(K.className="btn-clearfile",K.innerHTML=`
382
+ `;this.appendHtml(f,T);const $=p.querySelector(".livevideo"),N=p.querySelector(".photo-captured"),U=p.querySelector(".btn-selectfile2"),G=p.querySelector(".btn-takephoto2"),Y=p.querySelector(".btn-capturephoto"),he=p.querySelector(".btn-clearphoto"),re=p.querySelector(".btn-stopcamera");this.photoBlob={};let ye;U&&U.addEventListener("click",P=>{P.preventDefault(),E.click()});const Me=async()=>{const P=p.querySelector(".btn-clearfile");P&&P.click();try{ye=await navigator.mediaDevices.getUserMedia({video:!0}),$.srcObject=ye}catch{alert("Unable to access the camera."),$.style.display="none",Y.style.display="none",re.style.display="none",x.style.display="none",L.style.display="none"}setTimeout(()=>{G.style.display="none",N.style.display="none",$.style.display="",Y.style.display="",he.style.display="none",U&&(U.style.display="none"),G.style.display="none",re.style.display="",x.style.display="none",L.style.display="none"},100)};C&&C.addEventListener("click",async P=>{P.preventDefault(),Me()}),G.addEventListener("click",async P=>{P.preventDefault(),Me()}),re.addEventListener("click",()=>{ye&&ye.getTracks().forEach(P=>P.stop()),$.style.display="none",Y.style.display="none",re.style.display="none",G.style.display="none",x.style.display="",L.style.display=""}),Y.addEventListener("click",P=>{if(P.preventDefault(),N.style.display="",N.width=$.videoWidth,N.height=$.videoHeight,N.getContext("2d").drawImage($,0,0,N.width,N.height),ye.getTracks().forEach(X=>X.stop()),$.style.display="none",Y.style.display="none",he.style.display="",U&&(U.style.display=""),G.style.display="",re.style.display="none",N.toBlob(X=>{this.photoBlob[w]=X,v.removeAttribute("required")},"image/jpeg"),G.style.display="",l.useImageMask){const X=N.toDataURL("image/jpeg");q.setImage(X)}this.clearSelectedFiles()});const $e=()=>{this.photoBlob[w]=null,N.style.display="none",N.getContext("2d").clearRect(0,0,N.width,N.height),m.value!==""?l.isRequired&&v.removeAttribute("required"):l.isRequired&&v.setAttribute("required","required"),he.style.display="none",U&&(U.style.display="none"),G.style.display="none",x.style.display="",L.style.display=""};he.addEventListener("click",()=>{$e()});const Lt=(P,X)=>{const se=`.${P.split(".").pop().toLowerCase()}`;if(!I.some(j=>j.extensions.split(", ").includes(se)))return;let Se=D.images.some(j=>j.extensions.split(", ").includes(se));if(l.useImageMask){if(!Se)return;q.loadUrl(P)}$e(),L.innerHTML="";const pe=document.createElement("div");L.appendChild(pe);const K=document.createElement("button");if(K.className="btn-clearfile",K.innerHTML=`
383
383
  <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round">
384
384
  <path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M19 20h-10.5l-4.21 -4.3a1 1 0 0 1 0 -1.41l10 -10a1 1 0 0 1 1.41 0l5 5a1 1 0 0 1 0 1.41l-9.2 9.3" /><path d="M18 13.3l-6.3 -6.3" />
385
385
  </svg>
386
- `,L.appendChild(K),K.addEventListener("click",j=>{let Te=K.closest(".form-field").querySelector(".img-preview");Te&&Te.remove(),m.value="",y.value="",L.innerHTML="",S.innerText=this.out(this.settings.fileUploadText),l.useImageMask&&q.clearImage();const He=document.querySelector(".formview-container .submit-container");He&&setTimeout(()=>{this.stickyElement(He)},1e3),j.preventDefault(),j.stopImmediatePropagation()}),Se){let j=f.querySelector(".formview-container .img-preview");j||(j=document.createElement("img"),j.className="img-preview",f.appendChild(j)),j.src=P}else M();if(!X){const j=this.getFormValues();this.settings.onInputChange&&this.settings.onInputChange(j)}const ve=document.querySelector(".formview-container .submit-container");ve&&setTimeout(()=>{this.stickyElement(ve)},1e3)};l.value&&Lt(l.value,!0);const Ne=P=>{if(P){if(!I.some(K=>K.type===P.type)){alert(this.out("Invalid file type."));return}if(l.useImageMask){if(!["image/jpeg","image/png","image/webp"].includes(P.type)){alert(this.out("Invalid file type."));return}q.loadImage(P)}$e(),m.value="",L.innerHTML="";const se=document.createElement("div");se.innerText=P.name,L.appendChild(se);const ue=document.createElement("button");if(ue.className="btn-clearfile",ue.innerHTML=`
386
+ `,L.appendChild(K),K.addEventListener("click",j=>{let Te=K.closest(".form-field").querySelector(".img-preview");Te&&Te.remove(),m.value="",v.value="",L.innerHTML="",S.innerText=this.out(this.settings.fileUploadText),l.useImageMask&&q.clearImage();const He=document.querySelector(".formview-container .submit-container");He&&setTimeout(()=>{this.stickyElement(He)},1e3),j.preventDefault(),j.stopImmediatePropagation()}),Se){let j=f.querySelector(".formview-container .img-preview");j||(j=document.createElement("img"),j.className="img-preview",f.appendChild(j)),j.src=P}else M();if(!X){const j=this.getFormValues();this.settings.onInputChange&&this.settings.onInputChange(j)}const ve=document.querySelector(".formview-container .submit-container");ve&&setTimeout(()=>{this.stickyElement(ve)},1e3)};l.value&&Lt(l.value,!0);const Ne=P=>{if(P){if(!I.some(K=>K.type===P.type)){alert(this.out("Invalid file type."));return}if(l.useImageMask){if(!["image/jpeg","image/png","image/webp"].includes(P.type)){alert(this.out("Invalid file type."));return}q.loadImage(P)}$e(),m.value="",L.innerHTML="";const se=document.createElement("div");se.innerText=P.name,L.appendChild(se);const ue=document.createElement("button");if(ue.className="btn-clearfile",ue.innerHTML=`
387
387
  <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
388
388
  <path stroke-linecap="round" stroke-linejoin="round" d="m14.74 9-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 0 1-2.244 2.077H8.084a2.25 2.25 0 0 1-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 0 0-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 0 1 3.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 0 0-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 0 0-7.5 0" />
389
389
  </svg>
390
- `,L.appendChild(ue),ue.addEventListener("click",K=>{let j=ue.closest(".form-field").querySelector(".img-preview");j&&j.remove(),y.value="",L.innerHTML="",S.innerText=this.out(this.settings.fileUploadText),l.useImageMask&&q.clearImage();const we=document.querySelector(".formview-container .submit-container");we&&setTimeout(()=>{this.stickyElement(we)},1e3),K.preventDefault(),K.stopImmediatePropagation()}),P.type.startsWith("image/")){const K=new FileReader;K.onload=function(ve){let j=f.querySelector(".formview-container .img-preview");j||(j=document.createElement("img"),j.className="img-preview",f.appendChild(j)),j.src=ve.target.result},K.readAsDataURL(P)}else M();const Se=this.getFormValues();this.settings.onInputChange&&this.settings.onInputChange(Se);const pe=document.querySelector(".formview-container .submit-container");pe&&setTimeout(()=>{this.stickyElement(pe)},1e3)}},De=P=>{if(P){if(I=I.concat(D.images),!I.some(j=>j.type===P.type)){alert(this.out("Invalid file type."));return}const se=document.createElement("div");se.className="image-item",A.appendChild(se);const ue=document.createElement("div");ue.className="file-drop-info-highlight",se.appendChild(ue);const Se=document.createElement("div");Se.innerText=P.name,ue.appendChild(Se);const pe=document.createElement("button");if(pe.className="btn-clearfile",pe.innerHTML=`
390
+ `,L.appendChild(ue),ue.addEventListener("click",K=>{let j=ue.closest(".form-field").querySelector(".img-preview");j&&j.remove(),v.value="",L.innerHTML="",S.innerText=this.out(this.settings.fileUploadText),l.useImageMask&&q.clearImage();const we=document.querySelector(".formview-container .submit-container");we&&setTimeout(()=>{this.stickyElement(we)},1e3),K.preventDefault(),K.stopImmediatePropagation()}),P.type.startsWith("image/")){const K=new FileReader;K.onload=function(ve){let j=f.querySelector(".formview-container .img-preview");j||(j=document.createElement("img"),j.className="img-preview",f.appendChild(j)),j.src=ve.target.result},K.readAsDataURL(P)}else M();const Se=this.getFormValues();this.settings.onInputChange&&this.settings.onInputChange(Se);const pe=document.querySelector(".formview-container .submit-container");pe&&setTimeout(()=>{this.stickyElement(pe)},1e3)}},De=P=>{if(P){if(I=I.concat(D.images),!I.some(j=>j.type===P.type)){alert(this.out("Invalid file type."));return}const se=document.createElement("div");se.className="image-item",A.appendChild(se);const ue=document.createElement("div");ue.className="file-drop-info-highlight",se.appendChild(ue);const Se=document.createElement("div");Se.innerText=P.name,ue.appendChild(Se);const pe=document.createElement("button");if(pe.className="btn-clearfile",pe.innerHTML=`
391
391
  <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
392
392
  <path stroke-linecap="round" stroke-linejoin="round" d="m14.74 9-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 0 1-2.244 2.077H8.084a2.25 2.25 0 0 1-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 0 0-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 0 1 3.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 0 0-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 0 0-7.5 0" />
393
393
  </svg>
394
- `,ue.appendChild(pe),pe.addEventListener("click",j=>{const we=pe.closest(".image-item");we&&we.remove(),(yn=>{const mi=new DataTransfer,vn=y.files;Array.from(vn).forEach(bi=>{bi!==yn&&mi.items.add(bi)}),y.files=mi.files})(P);const He=document.querySelector(".formview-container .submit-container");He&&setTimeout(()=>{this.stickyElement(He)},1e3),j.preventDefault(),j.stopImmediatePropagation()}),P.type.startsWith("image/")){const j=new FileReader;j.onload=function(we){let Te=document.createElement("img");Te.className="img-preview",se.appendChild(Te),Te.src=we.target.result},j.readAsDataURL(P)}const K=this.getFormValues();this.settings.onInputChange&&this.settings.onInputChange(K);const ve=document.querySelector(".formview-container .submit-container");ve&&setTimeout(()=>{this.stickyElement(ve)},1e3)}}}if(b==="email"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`email_label_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`email_label_${g}`,f.type="email",f.name=w,f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("input",this.inputListener)}if(b==="phone"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`phone_label_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`phone_label_${g}`,f.type="tel",f.name=w,f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("input",this.inputListener)}if(b==="url"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`url_label_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`url_label_${g}`,f.type="url",f.name=w,f.value=l.value||"",f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("input",this.inputListener)}if(b==="hidden"){let g=this.getId();const v=document.createElement("label");v.setAttribute("for",`hidden_label_${g}`),v.className="field-label hidden",v.innerText=l.title,p.appendChild(v);const f=document.createElement("input");f.id=`hidden_label_${g}`,f.type="hidden",f.name=w,f.value=l.value,p.appendChild(f)}});const a=r.closest("[data-site-token]");if(a){const l=a.getAttribute("data-site-token"),h=document.createElement("input");h.type="hidden",h.name="form_token",h.value=l,r.appendChild(h)}if(this.settings.isBuilder){const l=document.createElement("div");l.className="submit-container",r.appendChild(l);let h=!0;if("hideReset"in t&&(h=t.hideReset),!h){const _=document.createElement("button");_.className="btn-resetform";const g=t.resetText||this.settings.resetText;_.innerText=g,l.appendChild(_),_.addEventListener("click",f=>{f.preventDefault();const m=_.closest("form");m&&(m.reset(),m.querySelectorAll(".btn-clearfile").forEach(x=>{x.click()}),m.querySelectorAll(".slider-container").forEach(x=>{const S=x.querySelector("input");x.querySelector(".current-value").textContent=S.value}))}),(t.fullWidthButton||!1)&&_.classList.add("w-full")}const p=document.createElement("button");p.className="btn-submitform";const b=t.submitText||this.settings.submitText;p.innerText=b,l.appendChild(p),(t.fullWidthButton||!1)&&p.classList.add("w-full"),this.settings.alwaysVisibleSubmit&&l.classList.add("always-visible"),this.stickyElement(l),r.addEventListener("submit",async _=>{_.preventDefault(),this.steps&&this.steps.length>0&&this.process()})}else{let l="Reference Code:",h="reference_code",p="reference_code";const b=document.createElement("div");b.className="form-field ",b.classList.add(p),r.appendChild(b);let w=this.getId();const _=document.createElement("label");_.setAttribute("for",`short_text_label_${w}`),_.className="field-label",_.innerHTML=l,b.appendChild(_);const g=document.createElement("input");if(g.id=`short_text_label_${w}`,g.type="text",g.name=h,g.autocomplete="off",g.setAttribute("aria-hidden","true"),g.setAttribute("tabindex","-1"),g.className="inp-base",b.appendChild(g),this.settings.captchaContainer){const v=this.settings.captchaContainerClassName,f=document.createElement("div");f.className="captcha-container",v&&f.classList.add(v),r.appendChild(f)}if(t.useSubmitButton){const v=document.createElement("div");v.className="submit-container",r.appendChild(v);let f=!0;if("hideReset"in t&&(f=t.hideReset),!f){const S=document.createElement("button");S.className="btn-resetform";const E=t.resetText||this.settings.resetText;S.innerText=E,v.appendChild(S),S.addEventListener("click",A=>{A.preventDefault();const L=S.closest("form");L&&(L.reset(),L.querySelectorAll(".btn-clearfile").forEach(O=>{O.click()}),L.querySelectorAll(".slider-container").forEach(O=>{const R=O.querySelector("input");O.querySelector(".current-value").textContent=R.value}))}),(t.fullWidthButton||!1)&&S.classList.add("w-full")}const m=document.createElement("button");m.className="btn-submitform";const y=t.submitText;m.innerText=y,v.appendChild(m),(t.fullWidthButton||!1)&&m.classList.add("w-full"),this.settings.alwaysVisibleSubmit&&v.classList.add("always-visible"),this.stickyElement(v),m.addEventListener("click",async S=>{this.trigger("submit",S)});const x=r.closest("form");x?x.addEventListener("submit",async S=>{this.steps&&this.steps.length>0&&(S.preventDefault(),S.stopImmediatePropagation(),this.process())}):m.addEventListener("click",async S=>{this.steps&&this.steps.length>0&&(S.preventDefault(),this.process())})}}let d,u;this.settings.resultSelector&&(d=document.querySelector(this.settings.resultSelector),d.classList.add("result-wrapper"),d.innerHTML="",u=document.createElement("div"),u.classList.add("result-container"),d.appendChild(u)),t.elements&&d&&t.elements.forEach(l=>{if(l.displayInOutput){if(l.type==="spacer"){const p=document.createElement("div");p.className="form-spacer",l.spacerHeight&&!isNaN(parseFloat(l.spacerHeight))&&(p.style.height=l.spacerHeight+"px"),u.appendChild(p);return}if(l.type==="separator"){const p=document.createElement("hr");p.style.borderTopColor=l.color,u.appendChild(p);return}if(l.type==="html"){if(l.html){const p=document.createElement("div");p.innerHTML=l.html,u.appendChild(p)}return}if(l.type==="heading"){const p=document.createElement(l.heading||"h2");p.innerHTML=l.headingText||this.out("Your Heading Here!"),u.appendChild(p);return}if(l.type==="paragraph"){const p=document.createElement("p");p.innerHTML=l.paragraphText||this.out("Your paragraph content here!"),u.appendChild(p);return}if(l.type==="media"){if(l.tag==="video"){const p=document.createElement("video");p.style.width="100%",p.style.height="auto",p.controls=!0;var h=document.createElement("source");h.src=l.url,h.type="video/mp4",p.appendChild(h),u.appendChild(p)}else if(l.tag==="audio"){const p=document.createElement("audio");p.controls=!0;let b=document.createElement("source");b.src=l.url,b.type="audio/mp3",p.appendChild(b),u.appendChild(p)}else if(l.tag==="img"){const p=document.createElement("img");p.src=l.url,p.setAttribute("alt",this.out("Output Image")),u.appendChild(p)}return}if(l.type==="image"){const p=document.createElement("img");p.src=l.url,p.setAttribute("alt",this.out("Output Image")),u.appendChild(p);return}if(l.type==="video"){const p=document.createElement("video");p.style.width="100%",p.style.height="auto",p.controls=!0;let b=document.createElement("source");b.src=l.url,b.type="video/mp4",p.appendChild(b),u.appendChild(p);return}if(l.type==="audio"){const p=document.createElement("audio");p.controls=!0;let b=document.createElement("source");b.src=l.url,b.type="audio/mp3",p.appendChild(b),u.appendChild(p);return}}})}if(this.settings.resultSelector&&document.querySelector(this.settings.resultSelector).classList.add("result-wrapper"),this.settings.saveResults&&this.settings.resultSelector&&localStorage.getItem("_results"))try{this.previousResults=JSON.parse(localStorage.getItem("_results"));let n=localStorage.getItem("_results_html");const r=document.querySelector(this.settings.resultSelector);r.innerHTML=n,this.addResultTool(),r.querySelectorAll(".link-download").forEach(a=>{a.addEventListener("click",async d=>{d.preventDefault();const u=d.target.href;try{const l=await fetch(u,{mode:"cors"});if(!l.ok)throw new Error("Failed to fetch the image.");const h=await l.blob(),p=u.substring(u.lastIndexOf("/")+1),b=document.createElement("a");b.href=URL.createObjectURL(h),b.download=p,b.click(),URL.revokeObjectURL(b.href)}catch(l){console.error("Error downloading the image:",l)}})})}catch{}const s=document.querySelector(".formview-container .submit-container");s&&setTimeout(()=>{this.stickyElement(s)},1e3)}abort(){this.controller&&this.controller.abort()}async search(e){let t={"Content-Type":"application/json",...this.settings.headers};try{const i=await fetch(this.settings.searchUrl,{method:"POST",headers:t,body:JSON.stringify({query:e,customData:this.settings.customData})});if(!i.ok)throw new Error("Failed to fetch data");const s=await i.json(),n=s.organic_results?"organic_results":"organic";return(s[n]||[]).map(r=>({title:r.title,link:r.link,snippet:r.snippet||r.description}))}catch(i){return console.error("Error in search:",i.message||i),[]}}async scrapeUrls(e){if(e.length===0)return{data:"",urls:[],failed:[]};this.settings.consoleLog&&console.log(e);let t={"Content-Type":"application/json",...this.settings.headers};const i=await fetch(this.settings.scrapeUrl,{method:"POST",headers:t,body:JSON.stringify({urls:e,customData:this.settings.customData})});if(!i.ok)throw new Error(`Error: ${i.statusText}`);let s="";const n=await i.json();if(this.settings.consoleLog&&console.log(n),n.error)return this.settings.consoleLog&&console.log(n.error),{data:"",urls:[],failed:[]};let r=[],o=[];if(this.settings.scrapeProvider==="firecrawl"&&n.forEach(a=>{if(a.success){const d=a.metadata.title,u=a.markdown,l=a.metadata.url;r.push(l),s+=`
394
+ `,ue.appendChild(pe),pe.addEventListener("click",j=>{const we=pe.closest(".image-item");we&&we.remove(),(yn=>{const mi=new DataTransfer,vn=v.files;Array.from(vn).forEach(bi=>{bi!==yn&&mi.items.add(bi)}),v.files=mi.files})(P);const He=document.querySelector(".formview-container .submit-container");He&&setTimeout(()=>{this.stickyElement(He)},1e3),j.preventDefault(),j.stopImmediatePropagation()}),P.type.startsWith("image/")){const j=new FileReader;j.onload=function(we){let Te=document.createElement("img");Te.className="img-preview",se.appendChild(Te),Te.src=we.target.result},j.readAsDataURL(P)}const K=this.getFormValues();this.settings.onInputChange&&this.settings.onInputChange(K);const ve=document.querySelector(".formview-container .submit-container");ve&&setTimeout(()=>{this.stickyElement(ve)},1e3)}}}if(b==="email"){let g=this.getId();const y=document.createElement("label");if(y.setAttribute("for",`email_label_${g}`),y.className="field-label",y.innerHTML=l.title+(l.isRequired?' <span class="text-red-500" aria-hidden="true">*</span>':""),p.appendChild(y),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`email_label_${g}`,f.type="email",f.name=w,f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("input",this.inputListener)}if(b==="phone"){let g=this.getId();const y=document.createElement("label");if(y.setAttribute("for",`phone_label_${g}`),y.className="field-label",y.innerHTML=l.title+(l.isRequired?' <span class="text-red-500" aria-hidden="true">*</span>':""),p.appendChild(y),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`phone_label_${g}`,f.type="tel",f.name=w,f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("input",this.inputListener)}if(b==="url"){let g=this.getId();const y=document.createElement("label");if(y.setAttribute("for",`url_label_${g}`),y.className="field-label",y.innerHTML=l.title+(l.isRequired?' <span class="text-red-500" aria-hidden="true">*</span>':""),p.appendChild(y),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`url_label_${g}`,f.type="url",f.name=w,f.value=l.value||"",f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("input",this.inputListener)}if(b==="hidden"){let g=this.getId();const y=document.createElement("label");y.setAttribute("for",`hidden_label_${g}`),y.className="field-label hidden",y.innerText=l.title,p.appendChild(y);const f=document.createElement("input");f.id=`hidden_label_${g}`,f.type="hidden",f.name=w,f.value=l.value,p.appendChild(f)}});const a=r.closest("[data-site-token]");if(a){const l=a.getAttribute("data-site-token"),h=document.createElement("input");h.type="hidden",h.name="form_token",h.value=l,r.appendChild(h)}if(this.settings.isBuilder){const l=document.createElement("div");l.className="submit-container",r.appendChild(l);let h=!0;if("hideReset"in t&&(h=t.hideReset),!h){const _=document.createElement("button");_.className="btn-resetform";const g=t.resetText||this.settings.resetText;_.innerText=g,l.appendChild(_),_.addEventListener("click",f=>{f.preventDefault();const m=_.closest("form");m&&(m.reset(),m.querySelectorAll(".btn-clearfile").forEach(x=>{x.click()}),m.querySelectorAll(".slider-container").forEach(x=>{const S=x.querySelector("input");x.querySelector(".current-value").textContent=S.value}))}),(t.fullWidthButton||!1)&&_.classList.add("w-full")}const p=document.createElement("button");p.className="btn-submitform";const b=t.submitText||this.settings.submitText;p.innerText=b,l.appendChild(p),(t.fullWidthButton||!1)&&p.classList.add("w-full"),this.settings.alwaysVisibleSubmit&&l.classList.add("always-visible"),this.stickyElement(l),r.addEventListener("submit",async _=>{_.preventDefault(),this.steps&&this.steps.length>0&&this.process()})}else{let l="Reference Code:",h="reference_code",p="reference_code";const b=document.createElement("div");b.className="form-field ",b.classList.add(p),r.appendChild(b);let w=this.getId();const _=document.createElement("label");_.setAttribute("for",`short_text_label_${w}`),_.className="field-label",_.innerHTML=l,b.appendChild(_);const g=document.createElement("input");if(g.id=`short_text_label_${w}`,g.type="text",g.name=h,g.autocomplete="off",g.setAttribute("aria-hidden","true"),g.setAttribute("tabindex","-1"),g.className="inp-base",b.appendChild(g),this.settings.captchaContainer){const y=this.settings.captchaContainerClassName,f=document.createElement("div");f.className="captcha-container",y&&f.classList.add(y),r.appendChild(f)}if(t.useSubmitButton){const y=document.createElement("div");y.className="submit-container",r.appendChild(y);let f=!0;if("hideReset"in t&&(f=t.hideReset),!f){const S=document.createElement("button");S.className="btn-resetform";const E=t.resetText||this.settings.resetText;S.innerText=E,y.appendChild(S),S.addEventListener("click",A=>{A.preventDefault();const L=S.closest("form");L&&(L.reset(),L.querySelectorAll(".btn-clearfile").forEach(O=>{O.click()}),L.querySelectorAll(".slider-container").forEach(O=>{const R=O.querySelector("input");O.querySelector(".current-value").textContent=R.value}))}),(t.fullWidthButton||!1)&&S.classList.add("w-full")}const m=document.createElement("button");m.className="btn-submitform";const v=t.submitText;m.innerText=v,y.appendChild(m),(t.fullWidthButton||!1)&&m.classList.add("w-full"),this.settings.alwaysVisibleSubmit&&y.classList.add("always-visible"),this.stickyElement(y),m.addEventListener("click",async S=>{this.trigger("submit",S)});const x=r.closest("form");x?x.addEventListener("submit",async S=>{this.steps&&this.steps.length>0&&(S.preventDefault(),S.stopImmediatePropagation(),this.process())}):m.addEventListener("click",async S=>{this.steps&&this.steps.length>0&&(S.preventDefault(),this.process())})}}let d,u;this.settings.resultSelector&&(d=document.querySelector(this.settings.resultSelector),d.classList.add("result-wrapper"),d.innerHTML="",u=document.createElement("div"),u.classList.add("result-container"),d.appendChild(u)),t.elements&&d&&t.elements.forEach(l=>{if(l.displayInOutput){if(l.type==="spacer"){const p=document.createElement("div");p.className="form-spacer",l.spacerHeight&&!isNaN(parseFloat(l.spacerHeight))&&(p.style.height=l.spacerHeight+"px"),u.appendChild(p);return}if(l.type==="separator"){const p=document.createElement("hr");p.style.borderTopColor=l.color,u.appendChild(p);return}if(l.type==="html"){if(l.html){const p=document.createElement("div");p.innerHTML=l.html,u.appendChild(p)}return}if(l.type==="heading"){const p=document.createElement(l.heading||"h2");p.innerHTML=l.headingText||this.out("Your Heading Here!"),u.appendChild(p);return}if(l.type==="paragraph"){const p=document.createElement("p");p.innerHTML=l.paragraphText||this.out("Your paragraph content here!"),u.appendChild(p);return}if(l.type==="media"){if(l.tag==="video"){const p=document.createElement("video");p.style.width="100%",p.style.height="auto",p.controls=!0;var h=document.createElement("source");h.src=l.url,h.type="video/mp4",p.appendChild(h),u.appendChild(p)}else if(l.tag==="audio"){const p=document.createElement("audio");p.controls=!0;let b=document.createElement("source");b.src=l.url,b.type="audio/mp3",p.appendChild(b),u.appendChild(p)}else if(l.tag==="img"){const p=document.createElement("img");p.src=l.url,p.setAttribute("alt",this.out("Output Image")),u.appendChild(p)}return}if(l.type==="image"){const p=document.createElement("img");p.src=l.url,p.setAttribute("alt",this.out("Output Image")),u.appendChild(p);return}if(l.type==="video"){const p=document.createElement("video");p.style.width="100%",p.style.height="auto",p.controls=!0;let b=document.createElement("source");b.src=l.url,b.type="video/mp4",p.appendChild(b),u.appendChild(p);return}if(l.type==="audio"){const p=document.createElement("audio");p.controls=!0;let b=document.createElement("source");b.src=l.url,b.type="audio/mp3",p.appendChild(b),u.appendChild(p);return}}})}if(this.settings.resultSelector&&document.querySelector(this.settings.resultSelector).classList.add("result-wrapper"),this.settings.saveResults&&this.settings.resultSelector&&localStorage.getItem("_results"))try{this.previousResults=JSON.parse(localStorage.getItem("_results"));let n=localStorage.getItem("_results_html");const r=document.querySelector(this.settings.resultSelector);r.innerHTML=n,this.addResultTool(),r.querySelectorAll(".link-download").forEach(a=>{a.addEventListener("click",async d=>{d.preventDefault();const u=d.target.href;try{const l=await fetch(u,{mode:"cors"});if(!l.ok)throw new Error("Failed to fetch the image.");const h=await l.blob(),p=u.substring(u.lastIndexOf("/")+1),b=document.createElement("a");b.href=URL.createObjectURL(h),b.download=p,b.click(),URL.revokeObjectURL(b.href)}catch(l){console.error("Error downloading the image:",l)}})})}catch{}const s=document.querySelector(".formview-container .submit-container");s&&setTimeout(()=>{this.stickyElement(s)},1e3)}abort(){this.controller&&this.controller.abort()}async search(e){let t={"Content-Type":"application/json",...this.settings.headers};try{const i=await fetch(this.settings.searchUrl,{method:"POST",headers:t,body:JSON.stringify({query:e,customData:this.settings.customData})});if(!i.ok)throw new Error("Failed to fetch data");const s=await i.json(),n=s.organic_results?"organic_results":"organic";return(s[n]||[]).map(r=>({title:r.title,link:r.link,snippet:r.snippet||r.description}))}catch(i){return console.error("Error in search:",i.message||i),[]}}async scrapeUrls(e){if(e.length===0)return{data:"",urls:[],failed:[]};this.settings.consoleLog&&console.log(e);let t={"Content-Type":"application/json",...this.settings.headers};const i=await fetch(this.settings.scrapeUrl,{method:"POST",headers:t,body:JSON.stringify({urls:e,customData:this.settings.customData})});if(!i.ok)throw new Error(`Error: ${i.statusText}`);let s="";const n=await i.json();if(this.settings.consoleLog&&console.log(n),n.error)return this.settings.consoleLog&&console.log(n.error),{data:"",urls:[],failed:[]};let r=[],o=[];if(this.settings.scrapeProvider==="firecrawl"&&n.forEach(a=>{if(a.success){const d=a.metadata.title,u=a.markdown,l=a.metadata.url;r.push(l),s+=`
395
395
 
396
396
 
397
397
  ## ${d}
@@ -426,7 +426,7 @@ Check if the request requires checking certain URLs. If so, returns the URLs.
426
426
  Also check if the request requires search to find answers by searching on the web to get the current relevant information.
427
427
  `,n=[{name:"check_request",description:"Check user request.",parameters:{type:"object",properties:{needscrape:{type:"boolean",description:"Check the if request requires search on the web or not."},url:{type:"string",description:"If request need to check certail URL, return the URL."},url2:{type:"string",description:"If the request needs to check a certail URL, return the URL."},url3:{type:"string",description:"If the request needs to check a certail URL, return the URL."},url4:{type:"string",description:"If the request needs to check a certail URL, return the URL."},url5:{type:"string",description:"If the request needs to check a certail URL, return the URL."},url6:{type:"string",description:"If the request needs to check a certail URL, return the URL."},url7:{type:"string",description:"If the request needs to check a certail URL, return the URL."},url8:{type:"string",description:"If the request needs to check a certail URL, return the URL."},needsearch:{type:"boolean",description:"Check the if request requires search on the web or not."}},required:["needsearch","needscrape"]}}],r=await this.send(s,i,t,n);return r?JSON.parse(r):!1}async getRelevantInfo(e,t,i){if(!this.settings.searchUrl&&!this.settings.scrapeUrl)return{data:"",urls:[],failed:[]};const s=document.createElement("div");s.classList.add("status"),i.appendChild(s);let n="",r=await this.checkPrompt(`${t}
428
428
 
429
- ${e}`);this.settings.consoleLog&&console.log(r);let o=[],a=[];if(r.url&&r.needscrape&&this.settings.scrapeUrl){let d=document.createElement("p");d.innerHTML=this.out("Fetching data from the web..."),s.appendChild(d);let u=[];r.url&&u.push(r.url),r.url2&&u.push(r.url2),r.url3&&u.push(r.url3),r.url4&&u.push(r.url4),r.url5&&u.push(r.url5),r.url6&&u.push(r.url6),r.url7&&u.push(r.url7),r.url8&&u.push(r.url8);let l=await this.scrapeUrls(u);n+=l.data,o=l.urls,a=l.failed}else if(this.settings.searchUrl&&this.settings.scrapeUrl){let d=document.createElement("p");d.innerHTML=this.out("Searching the web.."),s.appendChild(d);let u=await this.search(e);const l=this.settings.scrapeExclude;let h=u.filter(g=>{let v=new URL(g.link).hostname;return!l.some(f=>v.includes(f))});const p=this.settings.scrapeLimit,b=h.slice(0,p);s.innerHTML="",d=document.createElement("p"),d.innerHTML=this.out("Getting more information..."),s.appendChild(d);let w=[];for(let g=0;g<b.length;g++)w.push(u[g].link);let _=await this.scrapeUrls(w);n+=_.data,o=_.urls,a=_.failed}return{data:n,urls:o,failed:a}}showDemoInfo(e){if(!this.settings.resultSelector){this.settings.consoleLog&&console.log("resultSelector not set.");return}const t=document.querySelector(this.settings.resultSelector);t.innerHTML="";const i=document.createElement("div");i.classList.add("result-container"),t.appendChild(i),i.innerHTML=`
429
+ ${e}`);this.settings.consoleLog&&console.log(r);let o=[],a=[];if(r.url&&r.needscrape&&this.settings.scrapeUrl){let d=document.createElement("p");d.innerHTML=this.out("Fetching data from the web..."),s.appendChild(d);let u=[];r.url&&u.push(r.url),r.url2&&u.push(r.url2),r.url3&&u.push(r.url3),r.url4&&u.push(r.url4),r.url5&&u.push(r.url5),r.url6&&u.push(r.url6),r.url7&&u.push(r.url7),r.url8&&u.push(r.url8);let l=await this.scrapeUrls(u);n+=l.data,o=l.urls,a=l.failed}else if(this.settings.searchUrl&&this.settings.scrapeUrl){let d=document.createElement("p");d.innerHTML=this.out("Searching the web.."),s.appendChild(d);let u=await this.search(e);const l=this.settings.scrapeExclude;let h=u.filter(g=>{let y=new URL(g.link).hostname;return!l.some(f=>y.includes(f))});const p=this.settings.scrapeLimit,b=h.slice(0,p);s.innerHTML="",d=document.createElement("p"),d.innerHTML=this.out("Getting more information..."),s.appendChild(d);let w=[];for(let g=0;g<b.length;g++)w.push(u[g].link);let _=await this.scrapeUrls(w);n+=_.data,o=_.urls,a=_.failed}return{data:n,urls:o,failed:a}}showDemoInfo(e){if(!this.settings.resultSelector){this.settings.consoleLog&&console.log("resultSelector not set.");return}const t=document.querySelector(this.settings.resultSelector);t.innerHTML="";const i=document.createElement("div");i.classList.add("result-container"),t.appendChild(i),i.innerHTML=`
430
430
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 20" width="27" height="20" fill="currentColor">
431
431
  <circle cx="15" cy="15" r="10">
432
432
  <animate attributeName="cy" dur="0.6s" values="15;5;15" repeatCount="indefinite"></animate>
@@ -478,7 +478,7 @@ ${e}`);this.settings.consoleLog&&console.log(r);let o=[],a=[];if(r.url&&r.needsc
478
478
  </svg>
479
479
  </span>
480
480
  ${this.out("Abort")}
481
- `,this.isNormal=!0),this.isGenerating=!0;let u=(m,y)=>{if(m===void 0)return"";if(!isNaN(m))return m;let k=m;return y&&y.trim().startsWith("{")&&(k=JSON.stringify(m).slice(1,-1)),k};t.innerHTML="";let l=JSON.parse(JSON.stringify(this.steps)),h=this.getFormValues();if(!h)return;if(!(h&&Object.keys(h).length===0)){for(const m of l){let y=m.prompt;if(m.provider==="google"){for(const x of h)if(x.value instanceof FileList&&x.value.length>0){const E=x.value[0];if(!E)continue;const C=await new Promise((A,L)=>{const D=new FileReader;D.onload=I=>{const O=I.target.result.split(",")[1];A(O)},D.onerror=L,D.readAsDataURL(E)});y=y.replaceAll(`{{${x.name}}}`,C),y=y.replaceAll(`{{${x.name.toUpperCase()}}}`,C)}}m.prompt=y}l.forEach(m=>{let y=m.prompt;h.forEach(k=>{if(k.value===void 0&&(k.value=""),typeof k.value=="object"&&Array.isArray(k.value)){const x=k.value.join(", ");y=y.replaceAll(`{{${k.name}}}`,x),y=y.replaceAll(`{{${k.name.toUpperCase()}}}`,x)}else k.value instanceof FileList||typeof k.value=="string"&&k.value.indexOf("base64")!==-1?(y=y.replaceAll(`{{${k.name}}}`,k.name),y=y.replaceAll(`{{${k.name.toUpperCase()}}}`,k.name)):(y=y.replaceAll(`{{${k.name}}}`,u(k.value,m.prompt)),y=y.replaceAll(`{{${k.name.toUpperCase()}}}`,u(k.value,m.prompt)))}),m.prompt=y}),l.forEach(m=>{let y=m.context;h.forEach(k=>{if(k.value||(k.value=""),typeof k.value=="object"&&Array.isArray(k.value)){const x=k.value.join(", ");y=y.replaceAll(`{{${k.name}}}`,x),y=y.replaceAll(`{{${k.name.toUpperCase()}}}`,x)}else k.value instanceof FileList||typeof k.value=="string"&&k.value.indexOf("base64")!==-1?(y=y.replaceAll(`{{${k.name}}}`,k.name),y=y.replaceAll(`{{${k.name.toUpperCase()}}}`,k.name)):(y=y.replaceAll(`{{${k.name}}}`,u(k.value,m.prompt)),y=y.replaceAll(`{{${k.name.toUpperCase()}}}`,u(k.value,m.prompt)))}),m.context=y})}const p=async(m,y,k,x,S,E,C,A)=>{const L=document.createElement("div");L.classList.add("result-container"),t.appendChild(L),L.innerHTML=`
481
+ `,this.isNormal=!0),this.isGenerating=!0;let u=(m,v)=>{if(m===void 0)return"";if(!isNaN(m))return m;let k=m;return v&&v.trim().startsWith("{")&&(k=JSON.stringify(m).slice(1,-1)),k};t.innerHTML="";let l=JSON.parse(JSON.stringify(this.steps)),h=this.getFormValues();if(!h)return;if(!(h&&Object.keys(h).length===0)){for(const m of l){let v=m.prompt;if(m.provider==="google"){for(const x of h)if(x.value instanceof FileList&&x.value.length>0){const E=x.value[0];if(!E)continue;const C=await new Promise((A,L)=>{const D=new FileReader;D.onload=I=>{const O=I.target.result.split(",")[1];A(O)},D.onerror=L,D.readAsDataURL(E)});v=v.replaceAll(`{{${x.name}}}`,C),v=v.replaceAll(`{{${x.name.toUpperCase()}}}`,C)}}m.prompt=v}l.forEach(m=>{let v=m.prompt;h.forEach(k=>{if(k.value===void 0&&(k.value=""),typeof k.value=="object"&&Array.isArray(k.value)){const x=k.value.join(", ");v=v.replaceAll(`{{${k.name}}}`,x),v=v.replaceAll(`{{${k.name.toUpperCase()}}}`,x)}else k.value instanceof FileList||typeof k.value=="string"&&k.value.indexOf("base64")!==-1?(v=v.replaceAll(`{{${k.name}}}`,k.name),v=v.replaceAll(`{{${k.name.toUpperCase()}}}`,k.name)):(v=v.replaceAll(`{{${k.name}}}`,u(k.value,m.prompt)),v=v.replaceAll(`{{${k.name.toUpperCase()}}}`,u(k.value,m.prompt)))}),m.prompt=v}),l.forEach(m=>{let v=m.context;h.forEach(k=>{if(k.value||(k.value=""),typeof k.value=="object"&&Array.isArray(k.value)){const x=k.value.join(", ");v=v.replaceAll(`{{${k.name}}}`,x),v=v.replaceAll(`{{${k.name.toUpperCase()}}}`,x)}else k.value instanceof FileList||typeof k.value=="string"&&k.value.indexOf("base64")!==-1?(v=v.replaceAll(`{{${k.name}}}`,k.name),v=v.replaceAll(`{{${k.name.toUpperCase()}}}`,k.name)):(v=v.replaceAll(`{{${k.name}}}`,u(k.value,m.prompt)),v=v.replaceAll(`{{${k.name.toUpperCase()}}}`,u(k.value,m.prompt)))}),m.context=v})}const p=async(m,v,k,x,S,E,C,A)=>{const L=document.createElement("div");L.classList.add("result-container"),t.appendChild(L),L.innerHTML=`
482
482
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 20" width="27" height="20" fill="currentColor">
483
483
  <circle cx="15" cy="15" r="10">
484
484
  <animate attributeName="cy" dur="0.6s" values="15;5;15" repeatCount="indefinite"></animate>
@@ -498,14 +498,14 @@ ${e}`);this.settings.consoleLog&&console.log(r);let o=[],a=[];if(r.url&&r.needsc
498
498
  </svg>
499
499
  </span>
500
500
  &nbsp;
501
- `,o.setAttribute("disabled","")));let O="",R="",q;if(C&&C.search&&(q=await this.getRelevantInfo(m,y,L),q.data!==""&&(y+=`
501
+ `,o.setAttribute("disabled","")));let O="",R="",q;if(C&&C.search&&(q=await this.getRelevantInfo(m,v,L),q.data!==""&&(v+=`
502
502
  Use the following information to answer the request:
503
503
 
504
504
  ${q.data}
505
- `)),C&&(C.image||C.video||C.audio)||D){const M=await this.media.generate(m,y,k,x,C,L,A);return this.needCleanup=!0,this.settings.consoleLog&&console.log(M),M.mediaGenerated?{media:M.output,media2:M.output2,markdown:M.markdown}:(L.innerHTML=`<p>${M.message}</p>`,!1)}if(this.settings.assistantId){if(this.settings.assistantStreamUrl)await this.assistantStream(m,y,S,E,async M=>{if(!(M&&typeof M=="object")){if(O+=M,!A){const T=z.parse(O);L.innerHTML=T,R+=T}await new Promise(T=>setTimeout(T,50))}}),await new Promise(M=>{const T=setInterval(()=>{L.innerHTML===z.parse(O)&&(clearInterval(T),M())},10)}),A&&(L.innerHTML="",L.remove()),this.outputHtml+=`<div class="result-container">${R}</div>`;else if(this.settings.assistantUrl){let M=await this.assistant(m,y,S,E);if(!M)return!1;if(O=M,A)L.innerHTML="",L.remove();else{const T=z.parse(M);L.innerHTML=T,this.outputHtml+=`<div class="result-container">${T}</div>`}}}else if(this.settings.sendCommandStreamUrl){let M="",T="",$="";const N=async U=>{let G=0;for(;G<U.length;){if($=M.slice(0,$.length+1),G++,!A){const Y=z.parse($);L.innerHTML=Y,T=Y}await new Promise(Y=>setTimeout(Y,50))}};await this.sendStream(m,y,S,x,E,async U=>{O+=U,M+=U,await N(U)}),await new Promise(U=>{const G=setInterval(()=>{$.length===M.length&&(clearInterval(G),U())},10)}),A&&(L.innerHTML="",L.remove()),this.outputHtml+=`<div class="result-container">${T}</div>`}else{let M=await this.send(m,y,S,x,E);if(!M)return!1;if(O=M,A)L.innerHTML="",L.remove();else{const T=z.parse(M);L.innerHTML=T,this.outputHtml+=`<div class="result-container">${T}</div>`}}if(!A){let M="";if(q&&q.urls.forEach($=>{let N=$;N.length>75&&(N=N.slice(0,75)+"..."),M+=`<div><a class="source_url" href="${$}">${N}</url></div>`}),q&&q.failed.forEach($=>{let N=$;N.length>75&&(N=N.slice(0,75)+"..."),M+=`<div><a class="source_url" style="opacity:0.5" href="${$}">${N}</url></div>`}),M!==""){const $=document.createElement("div");$.classList.add("result-container"),t.appendChild($),$.innerHTML=M}}return this.payloads.push({prompt:m,context:y}),this.output.push(O),{media:[],markdown:O}};d||await(async m=>{this.previousResults=[],this.outputHtml="";for(let y=0;y<m.length;y++){if(!this.isGenerating)return;let{prompt:k,context:x,provider:S,model:E,system:C,functs:A,tools:L,hideOutput:D}=m[y];S=S||"",x=x||"",C=C||"You are an assistant",A=A||[];let I=k;this.previousResults.forEach((R,q)=>{const M=`{{output_step_${q+1}}}`;I=I.replace(new RegExp(M,"g"),u(R,k)),I=I.replace(new RegExp(M.toUpperCase(),"g"),u(R,k))}),k=I,k=k.replace(/[\u00A0\u2000-\u200B\u202F\u205F\u3000\uFEFF]/g," ").trim(),this.settings.consoleLog&&console.log(k),I=x,this.previousResults.forEach((R,q)=>{const M=`{{output_step_${q+1}}}`;I=I.replace(new RegExp(M,"g"),u(R,k)),I=I.replace(new RegExp(M.toUpperCase(),"g"),u(R,k))}),x=I,x=x.replace(/[\u00A0\u2000-\u200B\u202F\u205F\u3000\uFEFF]/g," ").trim();let O=await p(k,x,S,E,C,A,L,D);if(!O)break;if(this.mediaGenerated.push(...O.media),O.media&&O.media.length===1){let R=O.media[0],q=O.media2&&O.media2.length===1&&O.media2[0];this.previousResults.push(q||R),D&&(this.filesUploaded[`output_step_${y}`]=R)}else this.previousResults.push(O.markdown)}})(l),d&&(e===0&&(this.previousResults=[]),await(async(y,k)=>{if(!this.isGenerating)return;let{prompt:x,context:S,provider:E,model:C,system:A,functs:L,tools:D,hideOutput:I}=y[k];S=S||"",A=A||"You are an assistant",L=L||[];let O=x;this.previousResults&&this.previousResults.forEach((q,M)=>{const T=`{{output_step_${M+1}}}`;O=O.replace(new RegExp(T,"g"),q),O=O.replace(new RegExp(T.toUpperCase(),"g"),q)}),x=O,x=x.replace(/[\u00A0\u2000-\u200B\u202F\u205F\u3000\uFEFF]/g," ").trim(),this.settings.consoleLog&&console.log(x),O=S,this.previousResults&&this.previousResults.forEach((q,M)=>{const T=`{{output_step_${M+1}}}`;O=O.replace(new RegExp(T,"g"),q),O=O.replace(new RegExp(T.toUpperCase(),"g"),q)}),S=O,S=S.replace(/[\u00A0\u2000-\u200B\u202F\u205F\u3000\uFEFF]/g," ").trim(),this.settings.consoleLog&&console.log(S);let R=await p(x,S,E,C,A,L,D,I);if(R&&(this.mediaGenerated.push(...R.media),!!this.previousResults))if(R.media&&R.media.length===1){let q=R.media[0],M=R.media2&&R.media2.length===1&&R.media2[0];this.previousResults[k]=M||q,I&&(this.filesUploaded[`output_step_${k}`]=q)}else this.previousResults[k]=R.markdown})(l,e)),o.innerHTML=a,o.removeAttribute("disabled"),this.isGenerating=!1;const w=this.calculateCost();this.settings.onUsage&&this.settings.onUsage(w),this.trigger("usage",w),this.isNormal=!1,this.isSingle=!1;const _=(m,y=100)=>{const k=document.createElement("div");if(k.innerHTML=m,k.querySelector("video"))return"Video";if(k.querySelector("img"))return"Image";if(k.querySelector("audio"))return"Audio";const x=k.textContent.trim();return x.length>y?x.substring(0,y)+"...":x},g=Object.keys(this.filesUploaded).length===0&&this.filesUploaded.constructor===Object;if(this.needCleanup&&!g){this.settings.consoleLog&&(console.log("Cleanup"),console.log(this.filesUploaded));let m={"Content-Type":"application/json",...this.settings.headers};await fetch(this.settings.cleanup,{method:"POST",headers:m,body:JSON.stringify(this.filesUploaded)})}let v=this.outputHtml;this.mediaGenerated=this.mediaGenerated.filter(m=>v.indexOf(m)!==-1),this.trigger("resultReady",{previewText:_(v),markdown:this.previousResults,html:v,media:this.mediaGenerated,input:this.payloads,output:this.output}),this.settings.saveResults&&(localStorage.setItem("_results",JSON.stringify(this.previousResults)),localStorage.setItem("_results_html",v)),this.addResultTool(),t.querySelectorAll(".link-download").forEach(m=>{m.addEventListener("click",async y=>{y.preventDefault();const k=y.target.href;try{const x=await fetch(k,{mode:"cors"});if(!x.ok)throw new Error("Failed to fetch the image.");const S=await x.blob(),E=k.substring(k.lastIndexOf("/")+1),C=document.createElement("a");C.href=URL.createObjectURL(S),C.download=E,C.click(),URL.revokeObjectURL(C.href)}catch(x){console.error("Error downloading the image:",x)}})})}calculateCost(){const e=this.settings.inputCost/1e6,t=this.settings.outputCost/1e6,i=this.tokenInput*e,s=this.tokenOutput*t;return i+s}loadWorkflow(e){if(!e)return;const i=JSON.parse(e).steps;i.forEach(s=>{Object.prototype.hasOwnProperty.call(s,"context")||(s.context="")}),this.steps=i}getFileInput(e){let t;if(this.settings.isBuilder){if(!this.settings.previewSelector){this.settings.consoleLog&&console.log("previewSelector not set.");return}t=document.querySelector(this.settings.previewSelector)}else t=this.element;return t?e?t.querySelector(`input[type="file"][name="${e}"]`):t.querySelector('input[type="file"]'):null}getFormValues(){const e=this.element;if(!e)return[];const t=e.querySelectorAll("[name]");if(t.length===0)return{};const i={};t.forEach(r=>{let{name:o,type:a,value:d,checked:u,files:l}=r;if(a==="checkbox")o=o.replace("[]",""),u&&(i[o]=i[o]||[],d==="other"&&(d=e.querySelector(`[name="${o+"_other"}"]`).value),i[o].push(d));else if(a==="radio")u&&(d==="other"&&(d=e.querySelector(`[name="${o+"_other"}"]`).value),i[o]=d);else if(a==="select-one")d==="other"&&(d=e.querySelector(`[name="${o+"_other"}"]`).value),i[o]=d;else if(a==="file")i[o]=l;else if(a==="select-multiple"){const h=Array.from(r.selectedOptions);i[o]=h.map(p=>p.value)}else if(a==="color"){i[o]=d;const h=this.hexToRgb(d);i[o+"_red"]=h.red,i[o+"_green"]=h.green,i[o+"_blue"]=h.blue}else i[o]=d});let s=[];return this.json.elements.forEach(r=>{let o=r.title,a=r.name,d=r.type;if(a==="")return;let u=i[a],l={questions:o,name:a,value:u,type:d};s.push(l);let h=a+"__url";u=i[h],u&&(l={questions:o,name:h,value:u},s.push(l)),r.useImageMask&&(a=a+"_mask",u=i[a],l={questions:o,name:a,value:u},s.push(l));let p=a+"_red";u=i[p],u!==void 0&&(l={questions:o,name:p,value:u},s.push(l));let b=a+"_green";u=i[b],u!==void 0&&(l={questions:o,name:b,value:u},s.push(l));let w=a+"_blue";u=i[w],u!==void 0&&(l={questions:o,name:w,value:u},s.push(l))}),this.settings.consoleLog&&console.log(s),s}setTheme(e,t){let i;if(!e)i={};else try{i=JSON.parse(e)}catch{i={}}this.themeData=e;const s=i.cssVariables;let n,r=document.documentElement;t&&(r=t),n=s&&s["--form-text-color"]||"",r.style.setProperty("--form-text-color",n),n=s&&s["--form-primary-color"]||"#3b82f6",r.style.setProperty("--form-primary-color",n),n=s&&s["--form-title-color"]||"",r.style.setProperty("--form-title-color",n),n=s&&s["--form-desc-color"]||"",r.style.setProperty("--form-desc-color",n),n=s&&s["--form-label-color"]||"",r.style.setProperty("--form-label-color",n),n=s&&s["--form-label-font-size"]||"",r.style.setProperty("--form-label-font-size",n),n=s&&s["--form-input-font-size"]||"",r.style.setProperty("--form-input-font-size",n),n=s&&s["--form-input-border-color"]||"",r.style.setProperty("--form-input-border-color",n),n=s&&s["--form-primary-border-width"]||"1px",r.style.setProperty("--form-primary-border-width",n),n=s&&s["--form-secondary-border-width"]||"2px",r.style.setProperty("--form-secondary-border-width",n),n=s&&s["--form-input-background-color"]||"",r.style.setProperty("--form-input-background-color",n),n=s&&s["--form-input-text-color"]||"",r.style.setProperty("--form-input-text-color",n),n=s&&s["--form-input-placeholder-color"]||"",r.style.setProperty("--form-input-placeholder-color",n),n=s&&s["--form-choice-border-color"]||"",r.style.setProperty("--form-choice-border-color",n),n=s&&s["--form-switch-background-color"]||"",r.style.setProperty("--form-switch-background-color",n),n=s&&s["--form-switch-knob-color"]||"",r.style.setProperty("--form-switch-knob-color",n),n=s&&s["--form-switch-focus-offset-color"]||"",r.style.setProperty("--form-switch-focus-offset-color",n),n=s&&s["--form-dropfile-border-color"]||"rgb(194 194 194)",r.style.setProperty("--form-dropfile-border-color",n),n=s&&s["--form-dropfile-hover-color"]||"",r.style.setProperty("--form-dropfile-hover-color",n),n=s&&s["--form-button-background-color"]||"",r.style.setProperty("--form-button-background-color",n),n=s&&s["--form-button-hover-background-color"]||"",r.style.setProperty("--form-button-hover-background-color",n),n=s&&s["--form-button-text-color"]||"",r.style.setProperty("--form-button-text-color",n),n=s&&s["--form-button-hover-text-color"]||"",r.style.setProperty("--form-button-hover-text-color",n),n=s&&s["--form-button-border-width"]||"1px",r.style.setProperty("--form-button-border-width",n),n=s&&s["--form-button-border-color"]||"",r.style.setProperty("--form-button-border-color",n),n=s&&s["--form-button-hover-border-color"]||"",r.style.setProperty("--form-button-hover-border-color",n),n=s&&s["--form-reset-background-color"]||"",r.style.setProperty("--form-reset-background-color",n),n=s&&s["--form-reset-hover-background-color"]||"",r.style.setProperty("--form-reset-hover-background-color",n),n=s&&s["--form-reset-text-color"]||"",r.style.setProperty("--form-reset-text-color",n),n=s&&s["--form-reset-hover-text-color"]||"",r.style.setProperty("--form-reset-hover-text-color",n),n=s&&s["--form-reset-border-width"]||"1px",r.style.setProperty("--form-reset-border-width",n),n=s&&s["--form-reset-border-color"]||"",r.style.setProperty("--form-reset-border-color",n),n=s&&s["--form-reset-hover-border-color"]||"",r.style.setProperty("--form-reset-hover-border-color",n)}async send(e,t,i,s,n){this.controller=new AbortController,this.signal=this.controller.signal;let r=.6,o=.9,a=1;n||(n=[]),s=s||this.settings.model,n.length>0&&(s=this.settings.model2);const d={question:e,context:t,system:i,functs:n,temperature:r,topP:o,num:a,model:s,customData:this.settings.customData};try{let u={"Content-Type":"application/json",...this.settings.headers},h=await(await fetch(this.settings.sendCommandUrl,{signal:this.signal,method:"POST",headers:u,body:JSON.stringify(d)})).json();if(h.error)return console.log(`Error:
506
- `+h.error),!1;if(h.answer.usage&&(this.tokenInput+=h.answer.usage.prompt_tokens,this.tokenOutput+=h.answer.usage.completion_tokens),n.length===0){let p;return h.answer.choices.forEach(b=>{p=b.message.content}),p}else return h.answer}catch(u){return u.name==="AbortError"?this.settings.consoleLog&&console.log("Request aborted by user."):console.error("Error:",u),!1}}async sendStream(e,t,i,s,n,r){this.controller=new AbortController,this.signal=this.controller.signal;let o=.6,a=.9,d=1;n||(n=[]),s=s||this.settings.model;const u={question:e,context:t,system:i,functs:n,temperature:o,topP:a,num:d,model:s,customData:this.settings.customData};try{let l={"Content-Type":"application/json",...this.settings.headers};const h=await fetch(this.settings.sendCommandStreamUrl,{signal:this.signal,method:"POST",headers:l,body:JSON.stringify(u)});if(!h.ok)return console.error("Error:",h.statusText),!1;const p=h.body.getReader(),b=new TextDecoder;let w="",_=!1;for(;!_;){const{done:g,value:v}=await p.read();if(_=g,_)break;const f=b.decode(v,{stream:!0});w+=f;const m=w.split(`
507
- `);w="";let y=0,k=0;for(const x of m)if(x.trim()!==""&&x.startsWith("data:")){const S=x.slice(5).trim();if(S==="[DONE]"){this.settings.consoleLog&&console.log("Stream completed.");break}try{const E=JSON.parse(S);if(E.usage&&(y=E.usage.prompt_tokens,k=E.usage.completion_tokens),E.choices&&E.choices[0].delta&&E.choices[0].delta.content){const C=E.choices[0].delta.content;r&&r(C)}}catch{w+=x+`
508
- `}}this.tokenInput+=y,this.tokenOutput+=k}return!0}catch(l){return l.name==="AbortError"?this.settings.consoleLog&&console.log("Request aborted by user."):console.error("Error:",l),!1}}async assistant(e,t,i,s){this.controller=new AbortController,this.signal=this.controller.signal;let n=.6,r=.9,o=1;s||(s=[]);let a=this.settings.model;s.length>0&&(a=this.settings.model2);const d={assistantId:this.settings.assistantId,question:e,context:t,system:i,functs:s,temperature:n,topP:r,num:o,model:a,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(d)})).json();return h.error?(console.log(`Error:
509
- `+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,i,s,n){this.controller=new AbortController,this.signal=this.controller.signal;let r=.6,o=.9,a=1;s||(s=[]);const d={assistantId:this.settings.assistantId,question:e,context:t,system:i,functs:s,temperature:r,topP:o,num:a,model:this.settings.model,customData:this.settings.customData};try{let u={"Content-Type":"application/json",...this.settings.headers};const l=await fetch(this.settings.assistantStreamUrl,{signal:this.signal,method:"POST",headers:u,body:JSON.stringify(d)});if(!l.ok)return console.error("Error:",l.statusText),!1;const h=l.body.getReader(),p=new TextDecoder;let b="",w=!1;for(;!w;){const{done:_,value:g}=await h.read();if(w=_,w)break;const v=p.decode(g,{stream:!0});b+=v;const f=b.split(`
510
- `);b="";for(const m of f)if(m.trim()!=="")if(m.startsWith("data:")){const y=m.slice(5).trim();y==="[DONE]"&&this.settings.consoleLog&&console.log("Stream completed.");try{const k=JSON.parse(y);if(k.choices&&k.choices[0].delta&&k.choices[0].delta.content){const x=k.choices[0].delta.content;n&&n(x)}}catch{b+=m+`
511
- `}}else{const y=JSON.parse(m);this.tokenInput+=y.prompt_tokens,this.tokenOutput+=y.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("#",""),i=parseInt(t,16),s=i>>16&255,n=i>>8&255,r=i&255;return{red:s,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"),i=this.getScrollableParent(t);i?i.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 mn{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(i=>this.config.plugins[i]&&!this.plugins.has(i));return t.length>0&&await Promise.all(t.map(i=>this.loadPlugin(i))),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(i=>{if(i.startsWith("cb-")){const s=i.replace("cb-","");e.add(s)}})}),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;if(e==="code"){const i={name:"code",version:"1.0.0",mount:function(s,n){return{}}};return this.plugins.set(e,i),this.emit("plugin-loaded",{name:e,plugin:i}),i}try{t.css&&this.loadCSS(this.resolveUrl(t.css));const i=this.resolveUrl(t.url),s=await this.importModule(i),n=s.default||s;return this.plugins.set(e,n),typeof n.init=="function"&&await n.init(this),this.emit("plugin-loaded",{name:e,plugin:n}),n}catch(i){return console.error(`[PluginManager] Failed to load plugin "${e}":`,i),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,i)=>{const s=t.dataset.cbType,n=this.plugins.get(s);if(n&&typeof n.mount=="function")try{const r=this.parseOptions(t);let o=t.querySelector(".grid-sortable");o||t.classList.contains("grid-sortable")&&(o=t),o&&Array.from(o.children).forEach((u,l)=>{u.nodeType===1&&u.tagName!=="STYLE"&&u.tagName!=="SCRIPT"&&u.setAttribute("data-index",l)}),t.querySelectorAll(".edit").forEach((u,l)=>{const h=`content-${Date.now()}-${i}-${l}`;u.setAttribute("data-edit-id",h)}),t.hasAttribute("data-cb-original-content")||t.setAttribute("data-cb-original-content",t.innerHTML);const d=n.mount(t,r);this.components.set(t,d),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 "${s}":`,r)}}),this.components.size}parseOptions(e){const t={};return Array.from(e.attributes).forEach(i=>{if(i.name.startsWith("data-cb-")){const s=i.name.replace("data-cb-","").replace(/-([a-z])/g,(n,r)=>r.toUpperCase());t[s]=this.parseValue(i.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 i=e.querySelectorAll(".edit[data-edit-id]");if(i.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,o)=>{const a=e.getAttribute("data-cb-original-content");if(!a)return;const d=document.createElement("template");d.innerHTML=a.trim();const l=d.content.querySelector(`[data-edit-id="${r}"]`);if(l){l.innerHTML=o;const h=d.innerHTML;e.setAttribute("data-cb-original-content",h)}};i.forEach(r=>{r.setAttribute("contenteditable","true");const o=u=>{var l=document.createRange();l.selectNodeContents(u);var h=window.getSelection();h.removeAllRanges(),h.addRange(l)},a=u=>{if((u.ctrlKey||u.metaKey)&&u.which===65){let l;try{window.getSelection?l=window.getSelection().getRangeAt(0).commonAncestorContainer.parentNode:document.selection&&(l=document.selection.createRange().parentElement()),o(l),u.preventDefault(),u.stopImmediatePropagation()}catch{}}};r.addEventListener("keydown",a),r._cbKeydownHandler=a;const d=new MutationObserver(()=>{const u=r.getAttribute("data-edit-id"),l=r.innerHTML;n(u,l)});d.observe(r,{childList:!0,characterData:!0,subtree:!0,attributes:!0}),r._cbObserver=d})}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)}unmountComponent(e){if(!e||!this.components.has(e))return!1;const t=this.components.get(e),i=e.dataset.cbType,s=this.plugins.get(i);if(s&&typeof s.unmount=="function")try{s.unmount(e,t)}catch{}return this.components.delete(e),!0}async reinitialize(e=document){if(this.reinitializeInProgress)return clearTimeout(this.pendingReinitialize),new Promise(t=>{this.pendingReinitialize=setTimeout(async()=>{this.pendingReinitialize=null;const i=await this.reinitialize(e);t(i)},100)});this.reinitializeInProgress=!0;try{const t=[];this.components.forEach((o,a)=>{(e===document||e.contains(a))&&t.push({element:a,instance:o})}),t.forEach(({element:o,instance:a})=>{const d=o.dataset.cbType,u=this.plugins.get(d);u&&typeof u.unmount=="function"&&u.unmount(o,a),this.components.delete(o)});const s=this.detectComponentTypesInContainer(e).filter(o=>this.config.plugins[o]&&!this.plugins.has(o));s.length>0&&await Promise.all(s.map(o=>this.loadPlugin(o)));const n=e.querySelectorAll("[data-cb-type]");let r=0;for(const o of n){const a=o.dataset.cbType,d=this.plugins.get(a);if(d&&typeof d.mount=="function")try{const u=this.parseOptions(o);let l=o.querySelector(".grid-sortable");if(l||o.classList.contains("grid-sortable")&&(l=o),l&&Array.from(l.children).forEach((b,w)=>{b.nodeType===1&&b.tagName!=="STYLE"&&b.tagName!=="SCRIPT"&&b.setAttribute("data-index",w)}),o.querySelectorAll(".edit").forEach((b,w)=>{const _=`content-${Date.now()}-${r}-${w}`;b.setAttribute("data-edit-id",_)}),!o.hasAttribute("data-cb-original-content"))o.setAttribute("data-cb-original-content",o.innerHTML);else{let b=document.createRange();o.innerHTML="",o.appendChild(b.createContextualFragment(o.getAttribute("data-cb-original-content")));let w=!1;o.querySelectorAll(".edit:not([data-edit-id])").forEach((_,g)=>{_.setAttribute("data-edit-id",`content-${Date.now()}-${r}-new-${g}`),w=!0}),w&&o.setAttribute("data-cb-original-content",o.innerHTML)}const p=await d.mount(o,u);this.components.set(o,p),this.setupInlineEditing(o,u),o.setAttribute("data-cb-loaded","true"),typeof o.mount=="function"&&o.mount(),r++}catch(u){console.error(`[PluginManager] Failed to mount component "${a}":`,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(s=>{t.add(s.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 i=this.validatePluginSource(t.url);if(!i.allowed)throw new Error(`Security: ${i.reason}`);i.warning&&(console.warn(`[PluginManager] ${i.warning}`),this.emit("plugin-security-warning",{pluginId:e,url:t.url,warning:i.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 s=await this.loadPlugin(e);return this.emit("external-plugin-loaded",{pluginId:e,url:t.url}),s}catch(s){throw delete this.config.plugins[e],this.externalPlugins.delete(e),console.error(`[PluginManager] Failed to load external plugin "${e}":`,s),s}}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 s=new URL(e).hostname;if(!this.config.trustedDomains.some(r=>{if(r.startsWith("*.")){const o=r.slice(2);return s===o||s.endsWith("."+o)}return s===r}))return{allowed:!0,warning:`Loading plugin from external domain: ${s}. 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[i,s]of Object.entries(e))try{const n=await this.loadExternalPlugin(i,s);t.push({pluginId:i,success:!0,plugin:n})}catch(n){t.push({pluginId:i,success:!1,error:n.message}),console.error(`[PluginManager] Failed to load external plugin "${i}":`,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),i=[];return this.components.forEach((s,n)=>{n.dataset.cbType===e&&i.push({element:n,instance:s})}),i.forEach(({element:s,instance:n})=>{t&&typeof t.unmount=="function"&&t.unmount(s,n),this.components.delete(s)}),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 i=t.dataset.cbType,s=this.plugins.get(i);s&&typeof s.unmount=="function"&&s.unmount(t,e)}),this.components.forEach((e,t)=>{t.querySelectorAll('.edit[contenteditable="true"]').forEach(s=>{s.removeAttribute("contenteditable"),s._cbObserver&&(s._cbObserver.disconnect(),delete s._cbObserver),s._cbKeydownHandler&&(s.removeEventListener("keydown",s._cbKeydownHandler),delete s._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 i=new CustomEvent(`contentbox:${e}`,{detail:t});document.dispatchEvent(i)}}setRuntime(e){this.runtime=e}}class bn{constructor(e={}){const t={skin:"light",plugins:{},autoLoadPlugins:!0,pluginBaseUrl:"",allowExternalPlugins:!0,trustedDomains:[]};this.settings={...t,...e},this.initialized=!1,this.pluginManager=new mn({plugins:this.settings.plugins,autoLoad:this.settings.autoLoadPlugins,pluginBaseUrl:this.settings.pluginBaseUrl,allowExternalPlugins:this.settings.allowExternalPlugins,trustedDomains:this.settings.trustedDomains}),this.pluginManager.setRuntime(this),window.Glide=Rs,window.FormViewer=gn}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}unmountComponent(e){return this.pluginManager.unmountComponent(e)}async reinitialize(e){const t=await this.pluginManager.reinitialize(e);return this.initCore(),t}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 i=new CustomEvent(`contentbox:${e}`,{detail:t});document.dispatchEvent(i)}on(e,t){document.addEventListener(`contentbox:${e}`,t)}off(e,t){document.removeEventListener(`contentbox:${e}`,t)}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(){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(i=>{const s=n=>{if(i.closest('[contenteditable="true"]'))return n.preventDefault(),!1;{let r=i.getAttribute("href")||i.getAttribute("data-modal-url");this.openLightbox(r,i,e),n.preventDefault(),n.stopImmediatePropagation()}};i.addEventListener("click",s),i._lightboxHandler=s})}refreshLightbox(e){this.glightbox&&this.glightbox.destroy(),this.glightbox=new jt(e),window.GLightbox=jt.default}openLightbox(e,t,i){let s=[],n=0;if(t){const o=t.closest("[data-gallery]");let a=[];o?a=o.querySelectorAll(".is-lightbox"):document.querySelectorAll(".is-lightbox,.block-click").forEach(u=>{u.closest("[data-gallery]")||a.push(u)}),a.forEach((d,u)=>{let l=d.getAttribute("href");l||(l=d.getAttribute("data-modal-url")),s.push({href:l}),e===l&&(n=u)})}const r=document.activeElement;r?.blur(),s.length>0?(this.glightbox.setElements(s),this.glightbox.openAt(n)):(this.glightbox.setElements([{href:e}]),this.glightbox.open()),this.glightbox.on("close",()=>{this.refreshLightbox(i),r?.focus()})}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 bn})();
505
+ `)),C&&(C.image||C.video||C.audio)||D){const M=await this.media.generate(m,v,k,x,C,L,A);return this.needCleanup=!0,this.settings.consoleLog&&console.log(M),M.mediaGenerated?{media:M.output,media2:M.output2,markdown:M.markdown}:(L.innerHTML=`<p>${M.message}</p>`,!1)}if(this.settings.assistantId){if(this.settings.assistantStreamUrl)await this.assistantStream(m,v,S,E,async M=>{if(!(M&&typeof M=="object")){if(O+=M,!A){const T=z.parse(O);L.innerHTML=T,R+=T}await new Promise(T=>setTimeout(T,50))}}),await new Promise(M=>{const T=setInterval(()=>{L.innerHTML===z.parse(O)&&(clearInterval(T),M())},10)}),A&&(L.innerHTML="",L.remove()),this.outputHtml+=`<div class="result-container">${R}</div>`;else if(this.settings.assistantUrl){let M=await this.assistant(m,v,S,E);if(!M)return!1;if(O=M,A)L.innerHTML="",L.remove();else{const T=z.parse(M);L.innerHTML=T,this.outputHtml+=`<div class="result-container">${T}</div>`}}}else if(this.settings.sendCommandStreamUrl){let M="",T="",$="";const N=async U=>{let G=0;for(;G<U.length;){if($=M.slice(0,$.length+1),G++,!A){const Y=z.parse($);L.innerHTML=Y,T=Y}await new Promise(Y=>setTimeout(Y,50))}};await this.sendStream(m,v,S,x,E,async U=>{O+=U,M+=U,await N(U)}),await new Promise(U=>{const G=setInterval(()=>{$.length===M.length&&(clearInterval(G),U())},10)}),A&&(L.innerHTML="",L.remove()),this.outputHtml+=`<div class="result-container">${T}</div>`}else{let M=await this.send(m,v,S,x,E);if(!M)return!1;if(O=M,A)L.innerHTML="",L.remove();else{const T=z.parse(M);L.innerHTML=T,this.outputHtml+=`<div class="result-container">${T}</div>`}}if(!A){let M="";if(q&&q.urls.forEach($=>{let N=$;N.length>75&&(N=N.slice(0,75)+"..."),M+=`<div><a class="source_url" href="${$}">${N}</url></div>`}),q&&q.failed.forEach($=>{let N=$;N.length>75&&(N=N.slice(0,75)+"..."),M+=`<div><a class="source_url" style="opacity:0.5" href="${$}">${N}</url></div>`}),M!==""){const $=document.createElement("div");$.classList.add("result-container"),t.appendChild($),$.innerHTML=M}}return this.payloads.push({prompt:m,context:v}),this.output.push(O),{media:[],markdown:O}};d||await(async m=>{this.previousResults=[],this.outputHtml="";for(let v=0;v<m.length;v++){if(!this.isGenerating)return;let{prompt:k,context:x,provider:S,model:E,system:C,functs:A,tools:L,hideOutput:D}=m[v];S=S||"",x=x||"",C=C||"You are an assistant",A=A||[];let I=k;this.previousResults.forEach((R,q)=>{const M=`{{output_step_${q+1}}}`;I=I.replace(new RegExp(M,"g"),u(R,k)),I=I.replace(new RegExp(M.toUpperCase(),"g"),u(R,k))}),k=I,k=k.replace(/[\u00A0\u2000-\u200B\u202F\u205F\u3000\uFEFF]/g," ").trim(),this.settings.consoleLog&&console.log(k),I=x,this.previousResults.forEach((R,q)=>{const M=`{{output_step_${q+1}}}`;I=I.replace(new RegExp(M,"g"),u(R,k)),I=I.replace(new RegExp(M.toUpperCase(),"g"),u(R,k))}),x=I,x=x.replace(/[\u00A0\u2000-\u200B\u202F\u205F\u3000\uFEFF]/g," ").trim();let O=await p(k,x,S,E,C,A,L,D);if(!O)break;if(this.mediaGenerated.push(...O.media),O.media&&O.media.length===1){let R=O.media[0],q=O.media2&&O.media2.length===1&&O.media2[0];this.previousResults.push(q||R),D&&(this.filesUploaded[`output_step_${v}`]=R)}else this.previousResults.push(O.markdown)}})(l),d&&(e===0&&(this.previousResults=[]),await(async(v,k)=>{if(!this.isGenerating)return;let{prompt:x,context:S,provider:E,model:C,system:A,functs:L,tools:D,hideOutput:I}=v[k];S=S||"",A=A||"You are an assistant",L=L||[];let O=x;this.previousResults&&this.previousResults.forEach((q,M)=>{const T=`{{output_step_${M+1}}}`;O=O.replace(new RegExp(T,"g"),q),O=O.replace(new RegExp(T.toUpperCase(),"g"),q)}),x=O,x=x.replace(/[\u00A0\u2000-\u200B\u202F\u205F\u3000\uFEFF]/g," ").trim(),this.settings.consoleLog&&console.log(x),O=S,this.previousResults&&this.previousResults.forEach((q,M)=>{const T=`{{output_step_${M+1}}}`;O=O.replace(new RegExp(T,"g"),q),O=O.replace(new RegExp(T.toUpperCase(),"g"),q)}),S=O,S=S.replace(/[\u00A0\u2000-\u200B\u202F\u205F\u3000\uFEFF]/g," ").trim(),this.settings.consoleLog&&console.log(S);let R=await p(x,S,E,C,A,L,D,I);if(R&&(this.mediaGenerated.push(...R.media),!!this.previousResults))if(R.media&&R.media.length===1){let q=R.media[0],M=R.media2&&R.media2.length===1&&R.media2[0];this.previousResults[k]=M||q,I&&(this.filesUploaded[`output_step_${k}`]=q)}else this.previousResults[k]=R.markdown})(l,e)),o.innerHTML=a,o.removeAttribute("disabled"),this.isGenerating=!1;const w=this.calculateCost();this.settings.onUsage&&this.settings.onUsage(w),this.trigger("usage",w),this.isNormal=!1,this.isSingle=!1;const _=(m,v=100)=>{const k=document.createElement("div");if(k.innerHTML=m,k.querySelector("video"))return"Video";if(k.querySelector("img"))return"Image";if(k.querySelector("audio"))return"Audio";const x=k.textContent.trim();return x.length>v?x.substring(0,v)+"...":x},g=Object.keys(this.filesUploaded).length===0&&this.filesUploaded.constructor===Object;if(this.needCleanup&&!g){this.settings.consoleLog&&(console.log("Cleanup"),console.log(this.filesUploaded));let m={"Content-Type":"application/json",...this.settings.headers};await fetch(this.settings.cleanup,{method:"POST",headers:m,body:JSON.stringify(this.filesUploaded)})}let y=this.outputHtml;this.mediaGenerated=this.mediaGenerated.filter(m=>y.indexOf(m)!==-1),this.trigger("resultReady",{previewText:_(y),markdown:this.previousResults,html:y,media:this.mediaGenerated,input:this.payloads,output:this.output}),this.settings.saveResults&&(localStorage.setItem("_results",JSON.stringify(this.previousResults)),localStorage.setItem("_results_html",y)),this.addResultTool(),t.querySelectorAll(".link-download").forEach(m=>{m.addEventListener("click",async v=>{v.preventDefault();const k=v.target.href;try{const x=await fetch(k,{mode:"cors"});if(!x.ok)throw new Error("Failed to fetch the image.");const S=await x.blob(),E=k.substring(k.lastIndexOf("/")+1),C=document.createElement("a");C.href=URL.createObjectURL(S),C.download=E,C.click(),URL.revokeObjectURL(C.href)}catch(x){console.error("Error downloading the image:",x)}})})}calculateCost(){const e=this.settings.inputCost/1e6,t=this.settings.outputCost/1e6,i=this.tokenInput*e,s=this.tokenOutput*t;return i+s}loadWorkflow(e){if(!e)return;const i=JSON.parse(e).steps;i.forEach(s=>{Object.prototype.hasOwnProperty.call(s,"context")||(s.context="")}),this.steps=i}getFileInput(e){let t;if(this.settings.isBuilder){if(!this.settings.previewSelector){this.settings.consoleLog&&console.log("previewSelector not set.");return}t=document.querySelector(this.settings.previewSelector)}else t=this.element;return t?e?t.querySelector(`input[type="file"][name="${e}"]`):t.querySelector('input[type="file"]'):null}getFormValues(){const e=this.element;if(!e)return[];const t=e.querySelectorAll("[name]");if(t.length===0)return{};const i={};t.forEach(r=>{let{name:o,type:a,value:d,checked:u,files:l}=r;if(a==="checkbox")o=o.replace("[]",""),u&&(i[o]=i[o]||[],d==="other"&&(d=e.querySelector(`[name="${o+"_other"}"]`).value),i[o].push(d));else if(a==="radio")u&&(d==="other"&&(d=e.querySelector(`[name="${o+"_other"}"]`).value),i[o]=d);else if(a==="select-one")d==="other"&&(d=e.querySelector(`[name="${o+"_other"}"]`).value),i[o]=d;else if(a==="file")i[o]=l;else if(a==="select-multiple"){const h=Array.from(r.selectedOptions);i[o]=h.map(p=>p.value)}else if(a==="color"){i[o]=d;const h=this.hexToRgb(d);i[o+"_red"]=h.red,i[o+"_green"]=h.green,i[o+"_blue"]=h.blue}else i[o]=d});let s=[];return this.json.elements.forEach(r=>{let o=r.title,a=r.name,d=r.type;if(a==="")return;let u=i[a],l={questions:o,name:a,value:u,type:d};s.push(l);let h=a+"__url";u=i[h],u&&(l={questions:o,name:h,value:u},s.push(l)),r.useImageMask&&(a=a+"_mask",u=i[a],l={questions:o,name:a,value:u},s.push(l));let p=a+"_red";u=i[p],u!==void 0&&(l={questions:o,name:p,value:u},s.push(l));let b=a+"_green";u=i[b],u!==void 0&&(l={questions:o,name:b,value:u},s.push(l));let w=a+"_blue";u=i[w],u!==void 0&&(l={questions:o,name:w,value:u},s.push(l))}),this.settings.consoleLog&&console.log(s),s}setTheme(e,t){let i;if(!e)i={};else try{i=JSON.parse(e)}catch{i={}}this.themeData=e;const s=i.cssVariables;let n,r=document.documentElement;t&&(r=t),n=s&&s["--form-text-color"]||"",r.style.setProperty("--form-text-color",n),n=s&&s["--form-primary-color"]||"#3b82f6",r.style.setProperty("--form-primary-color",n),n=s&&s["--form-title-color"]||"",r.style.setProperty("--form-title-color",n),n=s&&s["--form-desc-color"]||"",r.style.setProperty("--form-desc-color",n),n=s&&s["--form-label-color"]||"",r.style.setProperty("--form-label-color",n),n=s&&s["--form-label-font-size"]||"",r.style.setProperty("--form-label-font-size",n),n=s&&s["--form-input-font-size"]||"",r.style.setProperty("--form-input-font-size",n),n=s&&s["--form-input-border-color"]||"",r.style.setProperty("--form-input-border-color",n),n=s&&s["--form-primary-border-width"]||"1px",r.style.setProperty("--form-primary-border-width",n),n=s&&s["--form-secondary-border-width"]||"2px",r.style.setProperty("--form-secondary-border-width",n),n=s&&s["--form-input-background-color"]||"",r.style.setProperty("--form-input-background-color",n),n=s&&s["--form-input-text-color"]||"",r.style.setProperty("--form-input-text-color",n),n=s&&s["--form-input-placeholder-color"]||"",r.style.setProperty("--form-input-placeholder-color",n),n=s&&s["--form-choice-border-color"]||"",r.style.setProperty("--form-choice-border-color",n),n=s&&s["--form-switch-background-color"]||"",r.style.setProperty("--form-switch-background-color",n),n=s&&s["--form-switch-knob-color"]||"",r.style.setProperty("--form-switch-knob-color",n),n=s&&s["--form-switch-focus-offset-color"]||"",r.style.setProperty("--form-switch-focus-offset-color",n),n=s&&s["--form-dropfile-border-color"]||"rgb(194 194 194)",r.style.setProperty("--form-dropfile-border-color",n),n=s&&s["--form-dropfile-hover-color"]||"",r.style.setProperty("--form-dropfile-hover-color",n),n=s&&s["--form-button-background-color"]||"",r.style.setProperty("--form-button-background-color",n),n=s&&s["--form-button-hover-background-color"]||"",r.style.setProperty("--form-button-hover-background-color",n),n=s&&s["--form-button-text-color"]||"",r.style.setProperty("--form-button-text-color",n),n=s&&s["--form-button-hover-text-color"]||"",r.style.setProperty("--form-button-hover-text-color",n),n=s&&s["--form-button-border-width"]||"1px",r.style.setProperty("--form-button-border-width",n),n=s&&s["--form-button-border-color"]||"",r.style.setProperty("--form-button-border-color",n),n=s&&s["--form-button-hover-border-color"]||"",r.style.setProperty("--form-button-hover-border-color",n),n=s&&s["--form-reset-background-color"]||"",r.style.setProperty("--form-reset-background-color",n),n=s&&s["--form-reset-hover-background-color"]||"",r.style.setProperty("--form-reset-hover-background-color",n),n=s&&s["--form-reset-text-color"]||"",r.style.setProperty("--form-reset-text-color",n),n=s&&s["--form-reset-hover-text-color"]||"",r.style.setProperty("--form-reset-hover-text-color",n),n=s&&s["--form-reset-border-width"]||"1px",r.style.setProperty("--form-reset-border-width",n),n=s&&s["--form-reset-border-color"]||"",r.style.setProperty("--form-reset-border-color",n),n=s&&s["--form-reset-hover-border-color"]||"",r.style.setProperty("--form-reset-hover-border-color",n)}async send(e,t,i,s,n){this.controller=new AbortController,this.signal=this.controller.signal;let r=.6,o=.9,a=1;n||(n=[]),s=s||this.settings.model,n.length>0&&(s=this.settings.model2);const d={question:e,context:t,system:i,functs:n,temperature:r,topP:o,num:a,model:s,customData:this.settings.customData};try{let u={"Content-Type":"application/json",...this.settings.headers},h=await(await fetch(this.settings.sendCommandUrl,{signal:this.signal,method:"POST",headers:u,body:JSON.stringify(d)})).json();if(h.error)return console.log(`Error:
506
+ `+h.error),!1;if(h.answer.usage&&(this.tokenInput+=h.answer.usage.prompt_tokens,this.tokenOutput+=h.answer.usage.completion_tokens),n.length===0){let p;return h.answer.choices.forEach(b=>{p=b.message.content}),p}else return h.answer}catch(u){return u.name==="AbortError"?this.settings.consoleLog&&console.log("Request aborted by user."):console.error("Error:",u),!1}}async sendStream(e,t,i,s,n,r){this.controller=new AbortController,this.signal=this.controller.signal;let o=.6,a=.9,d=1;n||(n=[]),s=s||this.settings.model;const u={question:e,context:t,system:i,functs:n,temperature:o,topP:a,num:d,model:s,customData:this.settings.customData};try{let l={"Content-Type":"application/json",...this.settings.headers};const h=await fetch(this.settings.sendCommandStreamUrl,{signal:this.signal,method:"POST",headers:l,body:JSON.stringify(u)});if(!h.ok)return console.error("Error:",h.statusText),!1;const p=h.body.getReader(),b=new TextDecoder;let w="",_=!1;for(;!_;){const{done:g,value:y}=await p.read();if(_=g,_)break;const f=b.decode(y,{stream:!0});w+=f;const m=w.split(`
507
+ `);w="";let v=0,k=0;for(const x of m)if(x.trim()!==""&&x.startsWith("data:")){const S=x.slice(5).trim();if(S==="[DONE]"){this.settings.consoleLog&&console.log("Stream completed.");break}try{const E=JSON.parse(S);if(E.usage&&(v=E.usage.prompt_tokens,k=E.usage.completion_tokens),E.choices&&E.choices[0].delta&&E.choices[0].delta.content){const C=E.choices[0].delta.content;r&&r(C)}}catch{w+=x+`
508
+ `}}this.tokenInput+=v,this.tokenOutput+=k}return!0}catch(l){return l.name==="AbortError"?this.settings.consoleLog&&console.log("Request aborted by user."):console.error("Error:",l),!1}}async assistant(e,t,i,s){this.controller=new AbortController,this.signal=this.controller.signal;let n=.6,r=.9,o=1;s||(s=[]);let a=this.settings.model;s.length>0&&(a=this.settings.model2);const d={assistantId:this.settings.assistantId,question:e,context:t,system:i,functs:s,temperature:n,topP:r,num:o,model:a,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(d)})).json();return h.error?(console.log(`Error:
509
+ `+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,i,s,n){this.controller=new AbortController,this.signal=this.controller.signal;let r=.6,o=.9,a=1;s||(s=[]);const d={assistantId:this.settings.assistantId,question:e,context:t,system:i,functs:s,temperature:r,topP:o,num:a,model:this.settings.model,customData:this.settings.customData};try{let u={"Content-Type":"application/json",...this.settings.headers};const l=await fetch(this.settings.assistantStreamUrl,{signal:this.signal,method:"POST",headers:u,body:JSON.stringify(d)});if(!l.ok)return console.error("Error:",l.statusText),!1;const h=l.body.getReader(),p=new TextDecoder;let b="",w=!1;for(;!w;){const{done:_,value:g}=await h.read();if(w=_,w)break;const y=p.decode(g,{stream:!0});b+=y;const f=b.split(`
510
+ `);b="";for(const m of f)if(m.trim()!=="")if(m.startsWith("data:")){const v=m.slice(5).trim();v==="[DONE]"&&this.settings.consoleLog&&console.log("Stream completed.");try{const k=JSON.parse(v);if(k.choices&&k.choices[0].delta&&k.choices[0].delta.content){const x=k.choices[0].delta.content;n&&n(x)}}catch{b+=m+`
511
+ `}}else{const v=JSON.parse(m);this.tokenInput+=v.prompt_tokens,this.tokenOutput+=v.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("#",""),i=parseInt(t,16),s=i>>16&255,n=i>>8&255,r=i&255;return{red:s,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"),i=this.getScrollableParent(t);i?i.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 mn{constructor(e={}){this.config={plugins:{},autoLoad:!0,pluginBaseUrl:"",autoRegisterPlugins:!0,pluginFolder:"",allowExternalPlugins:!0,trustedDomains:[],onReInit:()=>{},...e},this.plugins=new Map,this.loadedStyles=new Map,this.components=new Map,this.externalPlugins=new Map,this.autoPlugins={},this.missingPlugins=new Set}canLoad(e){if(this.config.plugins[e]||this.autoPlugins[e])return!0;if(!this.config.autoRegisterPlugins||e==="code"||this.missingPlugins.has(e)||!/^[a-z0-9][a-z0-9-]*$/.test(e))return!1;const t=this.getPluginFolder();return t?(this.autoPlugins[e]={url:t+e+"/index.js",css:t+e+"/style.css",auto:!0},!0):!1}getPluginFolder(){let e=this.config.pluginFolder;if(!e)for(const[t,i]of Object.entries(this.config.plugins)){if(!i||typeof i.url!="string")continue;const s="/"+t+"/index.js";if(i.url.endsWith(s)){e=i.url.slice(0,-s.length+1);break}}return e&&!e.endsWith("/")&&(e+="/"),e||""}contentTypes(e=document){const t=new Set;return e.nodeType===1&&e.dataset.cbType&&t.add(e.dataset.cbType),e.querySelectorAll("[data-cb-type]").forEach(i=>t.add(i.dataset.cbType)),t}async autoLoadPlugins(){const e=this.detectComponentTypes(),t=this.contentTypes(),i=e.filter(s=>!this.plugins.has(s)&&(this.config.plugins[s]||t.has(s)&&this.canLoad(s)));return i.length>0&&await Promise.all(i.map(s=>this.loadPlugin(s))),i}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(i=>{if(i.startsWith("cb-")){const s=i.replace("cb-","");e.add(s)}})}),Array.from(e)}async loadPlugin(e){if(this.plugins.has(e))return this.plugins.get(e);const t=this.config.plugins[e]||(this.canLoad(e)?this.autoPlugins[e]:null);if(!t)return console.warn(`[PluginManager] Plugin "${e}" not found in registry`),null;if(e==="code"){const i={name:"code",version:"1.0.0",mount:function(s,n){return{}}};return this.plugins.set(e,i),this.emit("plugin-loaded",{name:e,plugin:i}),i}try{let i=null;t.css&&!t.auto&&(i=this.loadCSS(this.resolveUrl(t.css)));const s=this.resolveUrl(t.url),n=await this.importModule(s),r=n.default||n;return t.css&&t.auto&&(i=this.loadCSS(this.resolveUrl(t.css))),i&&await i,this.plugins.set(e,r),typeof r.init=="function"&&await r.init(this),this.emit("plugin-loaded",{name:e,plugin:r}),r}catch(i){return t.auto?(delete this.autoPlugins[e],this.missingPlugins.add(e),null):(console.error(`[PluginManager] Failed to load plugin "${e}":`,i),null)}}async importModule(e){return import(e)}loadCSS(e){if(this.loadedStyles.has(e))return this.loadedStyles.get(e);const t=document.createElement("link");t.rel="stylesheet",t.href=e;const i=new Promise(s=>{t.onload=()=>{this.emit("css-loaded",{url:e}),s()},t.onerror=()=>{console.error(`[PluginManager] Failed to load CSS: ${e}`),s()}});return document.head.appendChild(t),this.loadedStyles.set(e,i),i}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,i)=>{const s=t.dataset.cbType,n=this.plugins.get(s);if(n&&typeof n.mount=="function")try{const r=this.parseOptions(t);let o=t.querySelector(".grid-sortable");o||t.classList.contains("grid-sortable")&&(o=t),o&&Array.from(o.children).forEach((u,l)=>{u.nodeType===1&&u.tagName!=="STYLE"&&u.tagName!=="SCRIPT"&&u.setAttribute("data-index",l)}),t.querySelectorAll(".edit").forEach((u,l)=>{const h=`content-${Date.now()}-${i}-${l}`;u.setAttribute("data-edit-id",h)}),t.hasAttribute("data-cb-original-content")||t.setAttribute("data-cb-original-content",t.innerHTML);const d=n.mount(t,r);this.components.set(t,d),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 "${s}":`,r)}}),this.components.size}parseOptions(e){const t={};return Array.from(e.attributes).forEach(i=>{if(i.name.startsWith("data-cb-")){const s=i.name.replace("data-cb-","").replace(/-([a-z])/g,(n,r)=>r.toUpperCase());t[s]=this.parseValue(i.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 i=e.querySelectorAll(".edit[data-edit-id]");if(i.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,o)=>{const a=e.getAttribute("data-cb-original-content");if(!a)return;const d=document.createElement("template");d.innerHTML=a.trim();const l=d.content.querySelector(`[data-edit-id="${r}"]`);if(l){l.innerHTML=o;const h=d.innerHTML;e.setAttribute("data-cb-original-content",h)}};i.forEach(r=>{r.setAttribute("contenteditable","true");const o=u=>{var l=document.createRange();l.selectNodeContents(u);var h=window.getSelection();h.removeAllRanges(),h.addRange(l)},a=u=>{if((u.ctrlKey||u.metaKey)&&u.which===65){let l;try{window.getSelection?l=window.getSelection().getRangeAt(0).commonAncestorContainer.parentNode:document.selection&&(l=document.selection.createRange().parentElement()),o(l),u.preventDefault(),u.stopImmediatePropagation()}catch{}}};r.addEventListener("keydown",a),r._cbKeydownHandler=a;const d=new MutationObserver(()=>{const u=r.getAttribute("data-edit-id"),l=r.innerHTML;n(u,l)});d.observe(r,{childList:!0,characterData:!0,subtree:!0,attributes:!0}),r._cbObserver=d})}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)}unmountComponent(e){if(!e||!this.components.has(e))return!1;const t=this.components.get(e),i=e.dataset.cbType,s=this.plugins.get(i);if(s&&typeof s.unmount=="function")try{s.unmount(e,t)}catch{}return this.components.delete(e),!0}async reinitialize(e=document){if(this.reinitializeInProgress)return clearTimeout(this.pendingReinitialize),new Promise(t=>{this.pendingReinitialize=setTimeout(async()=>{this.pendingReinitialize=null;const i=await this.reinitialize(e);t(i)},100)});this.reinitializeInProgress=!0;try{const t=[];this.components.forEach((a,d)=>{(e===document||e.contains(d))&&t.push({element:d,instance:a})}),t.forEach(({element:a,instance:d})=>{const u=a.dataset.cbType,l=this.plugins.get(u);l&&typeof l.unmount=="function"&&l.unmount(a,d),this.components.delete(a)});const i=this.detectComponentTypesInContainer(e),s=this.contentTypes(e),n=i.filter(a=>!this.plugins.has(a)&&(this.config.plugins[a]||s.has(a)&&this.canLoad(a)));n.length>0&&await Promise.all(n.map(a=>this.loadPlugin(a)));const r=e.querySelectorAll("[data-cb-type]");let o=0;for(const a of r){const d=a.dataset.cbType,u=this.plugins.get(d);if(u&&typeof u.mount=="function")try{const l=this.parseOptions(a);let h=a.querySelector(".grid-sortable");if(h||a.classList.contains("grid-sortable")&&(h=a),h&&Array.from(h.children).forEach((w,_)=>{w.nodeType===1&&w.tagName!=="STYLE"&&w.tagName!=="SCRIPT"&&w.setAttribute("data-index",_)}),a.querySelectorAll(".edit").forEach((w,_)=>{const g=`content-${Date.now()}-${o}-${_}`;w.setAttribute("data-edit-id",g)}),!a.hasAttribute("data-cb-original-content"))a.setAttribute("data-cb-original-content",a.innerHTML);else{let w=document.createRange();a.innerHTML="",a.appendChild(w.createContextualFragment(a.getAttribute("data-cb-original-content")));let _=!1;a.querySelectorAll(".edit:not([data-edit-id])").forEach((g,y)=>{g.setAttribute("data-edit-id",`content-${Date.now()}-${o}-new-${y}`),_=!0}),_&&a.setAttribute("data-cb-original-content",a.innerHTML)}const b=await u.mount(a,l);this.components.set(a,b),this.setupInlineEditing(a,l),a.setAttribute("data-cb-loaded","true"),typeof a.mount=="function"&&a.mount(),o++}catch(l){console.error(`[PluginManager] Failed to mount component "${d}":`,l)}}return typeof this.config.onReInit=="function"&&this.config.onReInit(),this.emit("reinitialized",{container:e,count:o}),o}finally{this.reinitializeInProgress=!1}}detectComponentTypesInContainer(e){const t=new Set;return e.querySelectorAll("[data-cb-type]").forEach(s=>{t.add(s.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 i=this.validatePluginSource(t.url);if(!i.allowed)throw new Error(`Security: ${i.reason}`);i.warning&&(console.warn(`[PluginManager] ${i.warning}`),this.emit("plugin-security-warning",{pluginId:e,url:t.url,warning:i.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 s=await this.loadPlugin(e);return this.emit("external-plugin-loaded",{pluginId:e,url:t.url}),s}catch(s){throw delete this.config.plugins[e],this.externalPlugins.delete(e),console.error(`[PluginManager] Failed to load external plugin "${e}":`,s),s}}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 s=new URL(e).hostname;if(!this.config.trustedDomains.some(r=>{if(r.startsWith("*.")){const o=r.slice(2);return s===o||s.endsWith("."+o)}return s===r}))return{allowed:!0,warning:`Loading plugin from external domain: ${s}. 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[i,s]of Object.entries(e))try{const n=await this.loadExternalPlugin(i,s);t.push({pluginId:i,success:!0,plugin:n})}catch(n){t.push({pluginId:i,success:!1,error:n.message}),console.error(`[PluginManager] Failed to load external plugin "${i}":`,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),i=[];return this.components.forEach((s,n)=>{n.dataset.cbType===e&&i.push({element:n,instance:s})}),i.forEach(({element:s,instance:n})=>{t&&typeof t.unmount=="function"&&t.unmount(s,n),this.components.delete(s)}),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 i=t.dataset.cbType,s=this.plugins.get(i);s&&typeof s.unmount=="function"&&s.unmount(t,e)}),this.components.forEach((e,t)=>{t.querySelectorAll('.edit[contenteditable="true"]').forEach(s=>{s.removeAttribute("contenteditable"),s._cbObserver&&(s._cbObserver.disconnect(),delete s._cbObserver),s._cbKeydownHandler&&(s.removeEventListener("keydown",s._cbKeydownHandler),delete s._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 i=new CustomEvent(`contentbox:${e}`,{detail:t});document.dispatchEvent(i)}}setRuntime(e){this.runtime=e}}class bn{constructor(e={}){const t={skin:"light",plugins:{},autoLoadPlugins:!0,autoRegisterPlugins:!0,pluginFolder:"",pluginBaseUrl:"",allowExternalPlugins:!0,trustedDomains:[]};this.settings={...t,...e},this.initialized=!1,this.pluginManager=new mn({plugins:this.settings.plugins,autoLoad:this.settings.autoLoadPlugins,autoRegisterPlugins:this.settings.autoRegisterPlugins,pluginFolder:this.settings.pluginFolder,pluginBaseUrl:this.settings.pluginBaseUrl,allowExternalPlugins:this.settings.allowExternalPlugins,trustedDomains:this.settings.trustedDomains}),this.pluginManager.setRuntime(this),window.Glide=Rs,window.FormViewer=gn}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}unmountComponent(e){return this.pluginManager.unmountComponent(e)}async reinitialize(e){const t=await this.pluginManager.reinitialize(e);return this.initCore(),t}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 i=new CustomEvent(`contentbox:${e}`,{detail:t});document.dispatchEvent(i)}on(e,t){document.addEventListener(`contentbox:${e}`,t)}off(e,t){document.removeEventListener(`contentbox:${e}`,t)}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(){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(i=>{const s=n=>{if(i.closest('[contenteditable="true"]'))return n.preventDefault(),!1;{let r=i.getAttribute("href")||i.getAttribute("data-modal-url");this.openLightbox(r,i,e),n.preventDefault(),n.stopImmediatePropagation()}};i.addEventListener("click",s),i._lightboxHandler=s})}refreshLightbox(e){this.glightbox&&this.glightbox.destroy(),this.glightbox=new jt(e),window.GLightbox=jt.default}openLightbox(e,t,i){let s=[],n=0;if(t){const o=t.closest("[data-gallery]");let a=[];o?a=o.querySelectorAll(".is-lightbox"):document.querySelectorAll(".is-lightbox,.block-click").forEach(u=>{u.closest("[data-gallery]")||a.push(u)}),a.forEach((d,u)=>{let l=d.getAttribute("href");l||(l=d.getAttribute("data-modal-url")),s.push({href:l}),e===l&&(n=u)})}const r=document.activeElement;r?.blur(),s.length>0?(this.glightbox.setElements(s),this.glightbox.openAt(n)):(this.glightbox.setElements([{href:e}]),this.glightbox.open()),this.glightbox.on("close",()=>{this.refreshLightbox(i),r?.focus()})}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 bn})();