@frybynite/image-cloud 0.10.3 → 0.11.0

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,7 +1,7 @@
1
- (function(S,V){typeof exports=="object"&&typeof module<"u"?V(exports):typeof define=="function"&&define.amd?define(["exports"],V):(S=typeof globalThis<"u"?globalThis:S||self,V(S.ImageCloud={}))})(this,(function(S){"use strict";const V=Object.freeze({none:"none",sm:"0 2px 4px rgba(0,0,0,0.1)",md:"0 4px 16px rgba(0,0,0,0.4)",lg:"0 8px 32px rgba(0,0,0,0.5)",glow:"0 0 30px rgba(255,255,255,0.6)"}),ht=Object.freeze({energetic:Object.freeze({overshoot:.25,bounces:2,decayRatio:.5}),playful:Object.freeze({overshoot:.15,bounces:1,decayRatio:.5}),subtle:Object.freeze({overshoot:.08,bounces:1,decayRatio:.5})}),dt=Object.freeze({gentle:Object.freeze({stiffness:150,damping:30,mass:1,oscillations:2}),bouncy:Object.freeze({stiffness:300,damping:15,mass:1,oscillations:4}),wobbly:Object.freeze({stiffness:180,damping:12,mass:1.5,oscillations:5}),snappy:Object.freeze({stiffness:400,damping:25,mass:.8,oscillations:2})}),ut=Object.freeze({gentle:Object.freeze({amplitude:30,frequency:1.5,decay:!0,decayRate:.9,phase:0}),playful:Object.freeze({amplitude:50,frequency:2.5,decay:!0,decayRate:.7,phase:0}),serpentine:Object.freeze({amplitude:60,frequency:3,decay:!1,decayRate:1,phase:0}),flutter:Object.freeze({amplitude:20,frequency:4,decay:!0,decayRate:.5,phase:0})}),ft=Object.freeze({type:"linear"}),gt=Object.freeze({mode:"none"}),mt=Object.freeze({mode:"none"}),Rt=Object.freeze({default:Object.freeze({border:Object.freeze({width:0,color:"#000000",radius:0,style:"solid"}),shadow:"none",clipPath:void 0,filter:Object.freeze({}),opacity:1,cursor:"pointer",outline:Object.freeze({width:0,color:"#000000",style:"solid",offset:0})}),hover:Object.freeze({shadow:"none"}),focused:Object.freeze({shadow:"none"})}),ne=Object.freeze({tightness:1}),oe=Object.freeze({rows:1,amplitude:100,frequency:2,phaseShift:0,synchronization:"offset"}),se=Object.freeze({spacing:0}),ae=Object.freeze({mobile:Object.freeze({maxWidth:767}),tablet:Object.freeze({maxWidth:1199})}),re=Object.freeze({mode:"adaptive",minSize:50,maxSize:400,variance:Object.freeze({min:1,max:1})}),ce=Object.freeze({mode:"none",range:Object.freeze({min:-15,max:15})}),Lt=Object.freeze({sizing:re,rotation:ce}),pt=Object.freeze({validateUrls:!0,validationTimeout:5e3,validationMethod:"head",allowedExtensions:["jpg","jpeg","png","gif","webp","bmp"]}),Ft=Object.freeze({enabled:!1,centers:!1,loaders:!1}),le=Object.freeze({maxAngle:5,speed:2e3,sync:"random"}),he=Object.freeze({minScale:.95,maxScale:1.05,speed:2400,sync:"random"}),de=Object.freeze({onRatio:.7,speed:3e3,style:"snap"}),ue=Object.freeze({speed:4e3,direction:"clockwise"}),Mt=Object.freeze({type:"none"}),C=Object.freeze({loaders:[],config:Object.freeze({loaders:pt,debug:Ft}),image:Lt,layout:Object.freeze({algorithm:"radial",scaleDecay:0,responsive:ae,targetCoverage:.6,densityFactor:1,spacing:Object.freeze({padding:50})}),animation:Object.freeze({duration:600,easing:Object.freeze({default:"cubic-bezier(0.4, 0.0, 0.2, 1)",bounce:"cubic-bezier(0.68, -0.55, 0.265, 1.55)",focus:"cubic-bezier(0.4, 0.0, 0.2, 1)"}),queue:Object.freeze({enabled:!0,interval:150}),entry:Object.freeze({start:Object.freeze({position:"nearest-edge",offset:100,circular:Object.freeze({radius:"120%",distribution:"even"})}),timing:Object.freeze({duration:600}),easing:"cubic-bezier(0.25, 1, 0.5, 1)",path:ft,rotation:gt,scale:mt}),idle:Mt}),interaction:Object.freeze({focus:Object.freeze({scalePercent:.8,zIndex:1e3,animationDuration:void 0}),navigation:Object.freeze({keyboard:!0,swipe:!0}),dragging:!0}),ui:Object.freeze({showLoadingSpinner:!1,showImageCounter:!1,showNavButtons:!1,showFocusOutline:!1}),styling:Rt});function tt(o,t){if(!o)return t||{};if(!t)return{...o};const i={...o};return t.border!==void 0&&(i.border={...o.border,...t.border}),t.borderTop!==void 0&&(i.borderTop={...o.borderTop,...t.borderTop}),t.borderRight!==void 0&&(i.borderRight={...o.borderRight,...t.borderRight}),t.borderBottom!==void 0&&(i.borderBottom={...o.borderBottom,...t.borderBottom}),t.borderLeft!==void 0&&(i.borderLeft={...o.borderLeft,...t.borderLeft}),t.filter!==void 0&&(i.filter={...o.filter,...t.filter}),t.outline!==void 0&&(i.outline={...o.outline,...t.outline}),t.shadow!==void 0&&(i.shadow=t.shadow),t.clipPath!==void 0&&(i.clipPath=t.clipPath),t.opacity!==void 0&&(i.opacity=t.opacity),t.cursor!==void 0&&(i.cursor=t.cursor),t.className!==void 0&&(i.className=t.className),t.objectFit!==void 0&&(i.objectFit=t.objectFit),t.aspectRatio!==void 0&&(i.aspectRatio=t.aspectRatio),t.borderRadiusTopLeft!==void 0&&(i.borderRadiusTopLeft=t.borderRadiusTopLeft),t.borderRadiusTopRight!==void 0&&(i.borderRadiusTopRight=t.borderRadiusTopRight),t.borderRadiusBottomRight!==void 0&&(i.borderRadiusBottomRight=t.borderRadiusBottomRight),t.borderRadiusBottomLeft!==void 0&&(i.borderRadiusBottomLeft=t.borderRadiusBottomLeft),i}function fe(o,t){if(!t)return{...o};const i=tt(o.default,t.default),e=tt(tt(i,o.hover),t.hover),n=tt(tt(i,o.focused),t.focused);return{default:i,hover:e,focused:n}}function ge(o,t){if(!t)return{...o};const i={...o};if(t.sizing!==void 0&&(i.sizing={...o.sizing,...t.sizing},t.sizing.variance)){const e=t.sizing.variance,n=e.min!==void 0&&e.min>=.25&&e.min<=1?e.min:o.sizing?.variance?.min??1,s=e.max!==void 0&&e.max>=1&&e.max<=1.75?e.max:o.sizing?.variance?.max??1;i.sizing.variance={min:n,max:s}}if(t.rotation!==void 0&&(i.rotation={...o.rotation,...t.rotation},t.rotation.range)){const e=t.rotation.range,n=e.min!==void 0&&e.min>=-180&&e.min<=0?e.min:o.rotation?.range?.min??-15,s=e.max!==void 0&&e.max>=0&&e.max<=180?e.max:o.rotation?.range?.max??15;i.rotation.range={min:n,max:s}}return i}function me(o={}){const t=o.image,i=[...o.loaders??[]];o.images&&o.images.length>0&&i.unshift({static:{sources:[{urls:o.images}]}});const n={loaders:{...pt,...o.config?.loaders??{}}},s={loaders:i,config:n,image:ge(Lt,t),layout:{...C.layout},animation:{...C.animation},interaction:{...C.interaction},ui:{...C.ui},styling:fe(Rt,o.styling)};if(o.layout&&(s.layout={...C.layout,...o.layout},o.layout.responsive&&(s.layout.responsive={...C.layout.responsive,mobile:o.layout.responsive.mobile?{...C.layout.responsive.mobile,...o.layout.responsive.mobile}:C.layout.responsive.mobile,tablet:o.layout.responsive.tablet?{...C.layout.responsive.tablet,...o.layout.responsive.tablet}:C.layout.responsive.tablet}),o.layout.spacing&&(s.layout.spacing={...C.layout.spacing,...o.layout.spacing})),o.animation&&(s.animation={...C.animation,...o.animation},o.animation.easing&&(s.animation.easing={...C.animation.easing,...o.animation.easing}),o.animation.queue&&(s.animation.queue={...C.animation.queue,...o.animation.queue}),o.animation.entry&&(s.animation.entry={...C.animation.entry,...o.animation.entry,start:o.animation.entry.start?{...C.animation.entry.start,...o.animation.entry.start,circular:o.animation.entry.start.circular?{...C.animation.entry.start.circular,...o.animation.entry.start.circular}:C.animation.entry.start.circular}:C.animation.entry.start,timing:o.animation.entry.timing?{...C.animation.entry.timing,...o.animation.entry.timing}:C.animation.entry.timing,path:o.animation.entry.path?{...ft,...o.animation.entry.path}:C.animation.entry.path,rotation:o.animation.entry.rotation?{...gt,...o.animation.entry.rotation}:C.animation.entry.rotation,scale:o.animation.entry.scale?{...mt,...o.animation.entry.scale}:C.animation.entry.scale}),o.animation.idle&&(s.animation.idle={...Mt,...o.animation.idle})),o.interaction&&(s.interaction={...C.interaction,...o.interaction},o.interaction.focus&&(s.interaction.focus={...C.interaction.focus,...o.interaction.focus}),o.interaction.navigation&&(s.interaction.navigation={...C.interaction.navigation,...o.interaction.navigation})),s.ui={...C.ui,...o.ui},s.config.debug={...Ft,...o.config?.debug??{}},s.layout.algorithm==="honeycomb"&&s.styling){const r={shape:"hexagon",mode:"height-relative"};s.styling={...s.styling,default:{...s.styling.default,clipPath:r},hover:{...s.styling.hover,clipPath:r}}}return s}function pe(o,t){return{...o?ht[o]:ht.playful,...t}}function be(o,t){return{...o?dt[o]:dt.gentle,...t}}function ye(o,t){return{...o?ut[o]:ut.gentle,...t}}class Ot{constructor(t){this.activeAnimations=new Map,this.animationIdCounter=0,this.config=t}buildTransformString(t){const i=["translate(-50%, -50%)"];if(t.x!==void 0||t.y!==void 0){const e=t.x??0,n=t.y??0;i.push(`translate(${e}px, ${n}px)`)}return t.rotation!==void 0&&i.push(`rotate(${t.rotation}deg)`),t.scale!==void 0&&i.push(`scale(${t.scale})`),i.join(" ")}animateTransformCancellable(t,i,e,n=null,s=null){this.cancelAllAnimations(t);const r=n??this.config.duration,a=s??this.config.easing.default,c=this.buildTransformString(i),l=this.buildTransformString(e);t.style.transition="none";const u=t.animate([{transform:c},{transform:l}],{duration:r,easing:a,fill:"forwards"}),h={id:`anim-${++this.animationIdCounter}`,element:t,animation:u,fromState:i,toState:e,startTime:performance.now(),duration:r};return this.activeAnimations.set(t,h),u.finished.then(()=>{t.style.transform=l,this.activeAnimations.delete(t)}).catch(()=>{this.activeAnimations.delete(t)}),h}cancelAnimation(t,i=!0){const e=this.getCurrentTransform(t.element);if(t.animation.cancel(),i){const n=this.buildTransformString({x:e.x,y:e.y,rotation:e.rotation,scale:e.scale});t.element.style.transform=n}return this.activeAnimations.delete(t.element),e}cancelAllAnimations(t){const i=this.activeAnimations.get(t);i&&this.cancelAnimation(i,!1);const e=t.getAnimations();for(const n of e)n.cancel()}getCurrentTransform(t){const e=getComputedStyle(t).transform;if(e==="none"||!e)return{x:0,y:0,rotation:0,scale:1};const n=new DOMMatrix(e),s=Math.sqrt(n.a*n.a+n.b*n.b),r=Math.atan2(n.b,n.a)*(180/Math.PI),a=n.e,c=n.f;return{x:a,y:c,rotation:r,scale:s}}hasActiveAnimation(t){return this.activeAnimations.has(t)}getAnimationHandle(t){return this.activeAnimations.get(t)}animateTransform(t,i,e=null,n=null){return new Promise(s=>{const r=e??this.config.duration,a=n??this.config.easing.default;t.style.transition=`transform ${r}ms ${a}, box-shadow ${r}ms ${a}`,t.style.transform=this.buildTransformString(i),setTimeout(()=>{s()},r)})}resetTransform(t,i){return this.animateTransform(t,i)}clearTransition(t){t.style.transition=""}wait(t){return new Promise(i=>setTimeout(i,t))}}function K(o,t,i){return o+(t-o)*i}function ve(o,t,i,e){const{overshoot:n,bounces:s,decayRatio:r}=e,a=i.x-t.x,c=i.y-t.y,l=Ee(s,r);let u=0,h=0,d=1,g=n,p=!1;for(let f=0;f<l.length;f++)if(o<=l[f].time){h=f===0?0:l[f-1].time,d=l[f].time,g=l[f].overshoot,p=l[f].isOvershoot;break}const b=(o-h)/(d-h);if(p)u=1+g*st(b);else if(h===0)u=st(b);else{const m=1+(l.find((y,E)=>y.time>h&&E>0&&l[E-1].isOvershoot)?.overshoot||g);u=K(m,1,st(b))}return{x:t.x+a*u,y:t.y+c*u}}function Ee(o,t){const i=[];let e=.6;i.push({time:e,overshoot:0,isOvershoot:!1});let n=.15;const r=.4/(o*2);for(let a=0;a<o;a++)e+=r,i.push({time:e,overshoot:n,isOvershoot:!0}),e+=r,i.push({time:e,overshoot:n*t,isOvershoot:!1}),n*=t;return i.push({time:1,overshoot:0,isOvershoot:!1}),i}function we(o,t,i,e){const{stiffness:n,damping:s,mass:r,oscillations:a}=e,c=i.x-t.x,l=i.y-t.y,u=Math.sqrt(n/r),h=s/(2*Math.sqrt(n*r));let d;if(h<1){const g=u*Math.sqrt(1-h*h),p=Math.exp(-h*u*o*3),b=Math.cos(g*o*a*Math.PI);d=1-p*b}else d=1-Math.exp(-u*o*3);return d=Math.max(0,Math.min(d,1.3)),{x:t.x+c*d,y:t.y+l*d}}function xe(o,t,i,e){const{amplitude:n,frequency:s,decay:r,decayRate:a,phase:c}=e,l=i.x-t.x,u=i.y-t.y,h=Math.sqrt(l*l+u*u),d=h>0?-u/h:0,g=h>0?l/h:1,p=s*Math.PI*2*o+c,b=r?Math.pow(1-o,a):1,f=n*Math.sin(p)*b,m=Se(o);return{x:K(t.x,i.x,m)+f*d,y:K(t.y,i.y,m)+f*g}}function st(o){return 1-(1-o)*(1-o)}function Se(o){return 1-Math.pow(1-o,3)}function Ie(o,t,i){const{amplitude:e,frequency:n,decay:s}=i,r=Math.sin(o*n*Math.PI*2),a=s?Math.pow(1-o,2):1,c=e*r*a;return t+c}function Ce(o,t,i){const{overshoot:e,bounces:n}=i,s=[];s.push({time:.5,scale:e});let r=e;const a=.5,l=.5/(n*2);let u=.5;for(let d=0;d<n;d++){const g=1-(r-1)*a;u+=l,s.push({time:u,scale:g}),r=1+(r-1)*a*a,u+=l,d<n-1&&s.push({time:u,scale:r})}s.push({time:1,scale:1});let h=1;for(let d=0;d<s.length;d++)if(o<=s[d].time){const g=d===0?0:s[d-1].time,p=d===0?1:s[d-1].scale,b=(o-g)/(s[d].time-g),f=st(b);h=p+(s[d].scale-p)*f;break}return h*t}function zt(o){const{element:t,startPosition:i,endPosition:e,pathConfig:n,duration:s,imageWidth:r,imageHeight:a,rotation:c,scale:l,onComplete:u,rotationConfig:h,startRotation:d,scaleConfig:g,startScale:p}=o,b=n.type,f=d!==void 0&&d!==c,m=h?.mode==="wobble",y=h?.wobble||{amplitude:15,frequency:3,decay:!0},E=f||m,v=p!==void 0&&p!==l,I=g?.mode==="pop",w=g?.pop||{overshoot:1.2,bounces:1};if(b==="linear"&&!E&&!(v||I)){u&&u();return}const z=performance.now(),F=-r/2,U=-a/2;function D(N){const k=N-z,T=Math.min(k/s,1);let P;switch(b){case"bounce":{const B=pe(n.bouncePreset,n.bounce);P=ve(T,i,e,B);break}case"elastic":{const B=be(n.elasticPreset,n.elastic);P=we(T,i,e,B);break}case"wave":{const B=ye(n.wavePreset,n.wave);P=xe(T,i,e,B);break}default:P={x:K(i.x,e.x,T),y:K(i.y,e.y,T)}}const G=P.x-e.x,H=P.y-e.y;let M;m?M=Ie(T,c,y):f?M=K(d,c,T):M=c;let R;I?R=Ce(T,l,w):v?R=K(p,l,T):R=l,t.style.transform=`translate(${F}px, ${U}px) translate(${G}px, ${H}px) rotate(${M}deg) scale(${R})`,T<1?requestAnimationFrame(D):(t.style.transform=`translate(${F}px, ${U}px) rotate(${c}deg) scale(${l})`,u&&u())}requestAnimationFrame(D)}function Dt(o){return o==="bounce"||o==="elastic"||o==="wave"}const Ae={radial:"center",spiral:"center",grid:"top",cluster:"nearest-edge",random:"nearest-edge",wave:"left",honeycomb:"center"};class Pt{constructor(t,i){this.config=t,this.layoutAlgorithm=i,this.resolvedStartPosition=this.resolveStartPosition(),this.pathConfig=t.path||ft,this.rotationConfig=t.rotation||gt,this.scaleConfig=t.scale||mt}resolveStartPosition(){return this.config.start.position?this.config.start.position:Ae[this.layoutAlgorithm]||"nearest-edge"}calculateStartPosition(t,i,e,n,s){const r=this.resolvedStartPosition,a=this.config.start.offset??100;switch(r){case"nearest-edge":return this.calculateNearestEdge(t,i,e,a);case"top":return this.calculateEdgePosition("top",t,i,e,a);case"bottom":return this.calculateEdgePosition("bottom",t,i,e,a);case"left":return this.calculateEdgePosition("left",t,i,e,a);case"right":return this.calculateEdgePosition("right",t,i,e,a);case"center":return this.calculateCenterPosition(e,t,i);case"random-edge":return this.calculateRandomEdge(t,i,e,a);case"circular":return this.calculateCircularPosition(t,i,e,n,s);default:return this.calculateNearestEdge(t,i,e,a)}}calculateNearestEdge(t,i,e,n){const s=t.x,r=t.y,a=s,c=e.width-s,l=r,u=e.height-r,h=Math.min(a,c,l,u);let d=t.x,g=t.y;return h===a?d=-(i.width+n):h===c?d=e.width+n:h===l?g=-(i.height+n):g=e.height+n,{x:d,y:g}}calculateEdgePosition(t,i,e,n,s){let r=i.x,a=i.y;switch(t){case"top":a=-(e.height+s);break;case"bottom":a=n.height+s;break;case"left":r=-(e.width+s);break;case"right":r=n.width+s;break}return{x:r,y:a}}calculateCenterPosition(t,i,e){const n=t.width/2,s=t.height/2;return{x:n,y:s,useScale:!0}}calculateRandomEdge(t,i,e,n){const s=["top","bottom","left","right"],r=s[Math.floor(Math.random()*s.length)];return this.calculateEdgePosition(r,t,i,e,n)}calculateCircularPosition(t,i,e,n,s){const r=this.config.start.circular||{},a=r.distribution||"even";let c;const l=r.radius||"120%";if(typeof l=="string"&&l.endsWith("%")){const b=parseFloat(l)/100;c=Math.sqrt(e.width**2+e.height**2)*b/2}else c=typeof l=="number"?l:500;let u;a==="even"?u=n/s*2*Math.PI:u=Math.random()*2*Math.PI;const h=e.width/2,d=e.height/2,g=h+Math.cos(u)*c,p=d+Math.sin(u)*c;return{x:g,y:p}}getAnimationParams(t){const i=this.config.timing.duration,e=this.config.easing;return{startTransform:"",duration:i,delay:0,easing:e}}buildStartTransform(t,i,e,n,s,r,a,c){const l=t.x-i.x,u=t.y-i.y,h=a!==void 0?a:e,d=c!==void 0?c:n,g=s!==void 0?-s/2:0,p=r!==void 0?-r/2:0,b=s!==void 0?`translate(${g}px, ${p}px)`:"translate(-50%, -50%)";return t.useScale?`${b} translate(${l}px, ${u}px) rotate(${h}deg) scale(0)`:`${b} translate(${l}px, ${u}px) rotate(${h}deg) scale(${d})`}buildFinalTransform(t,i,e,n){if(e!==void 0&&n!==void 0){const s=-e/2,r=-n/2;return`translate(${s}px, ${r}px) rotate(${t}deg) scale(${i})`}return`translate(-50%, -50%) rotate(${t}deg) scale(${i})`}getTransitionCSS(){const t=this.config.timing.duration,i=this.config.easing;return this.requiresJSAnimation()?`opacity ${t}ms ease-out`:`opacity ${t}ms ease-out, transform ${t}ms ${i}`}requiresJSAnimation(){return Dt(this.pathConfig.type)}getPathConfig(){return this.pathConfig}getPathType(){return this.pathConfig.type}getTiming(){return{duration:this.config.timing.duration}}getRotationConfig(){return this.rotationConfig}getRotationMode(){return this.rotationConfig.mode}calculateStartRotation(t){switch(this.rotationConfig.mode){case"none":return t;case"settle":{const e=this.rotationConfig.startRotation;if(e===void 0)return t+(Math.random()-.5)*60;if(typeof e=="number")return e;const n=e.max-e.min;return e.min+Math.random()*n}case"spin":{const e=this.rotationConfig.spinCount??1,n=this.resolveSpinDirection(t);return t+e*360*n}case"random":return t+(Math.random()-.5)*60;case"wobble":return t;default:return t}}resolveSpinDirection(t){switch(this.rotationConfig.direction??"auto"){case"clockwise":return-1;case"counterclockwise":return 1;case"random":return Math.random()<.5?1:-1;default:return t>=0?1:-1}}requiresJSRotation(){return this.rotationConfig.mode==="wobble"}calculateWobbleRotation(t,i){if(this.rotationConfig.mode!=="wobble")return i;const e=this.rotationConfig.wobble||{amplitude:15,frequency:3,decay:!0},{amplitude:n,frequency:s,decay:r}=e,a=Math.sin(t*s*Math.PI*2),c=r?Math.pow(1-t,2):1,l=n*a*c;return i+l}getScaleConfig(){return this.scaleConfig}getScaleMode(){return this.scaleConfig.mode}calculateStartScale(t){switch(this.scaleConfig.mode){case"none":return t;case"grow":return(this.scaleConfig.startScale??.3)*t;case"shrink":return(this.scaleConfig.startScale??1.5)*t;case"pop":return t;case"random":{const e=this.scaleConfig.range??{min:.5,max:1};return(e.min+Math.random()*(e.max-e.min))*t}default:return t}}requiresJSScale(){return this.scaleConfig.mode==="pop"}calculatePopScale(t,i){if(this.scaleConfig.mode!=="pop")return i;const e=this.scaleConfig.pop||{overshoot:1.2,bounces:1},{overshoot:n,bounces:s}=e,r=this.generateScaleBounceKeyframes(s,n);let a=i;for(let c=0;c<r.length;c++)if(t<=r[c].time){const l=c===0?0:r[c-1].time,u=c===0?i:r[c-1].scale,h=(t-l)/(r[c].time-l),d=this.easeOutQuad(h);a=u+(r[c].scale-u)*d;break}return a*i}generateScaleBounceKeyframes(t,i){const e=[];e.push({time:.5,scale:i});let n=i;const s=.5,a=.5/(t*2);let c=.5;for(let l=0;l<t;l++){const u=1-(n-1)*s;c+=a,e.push({time:c,scale:u}),n=1+(n-1)*s*s,c+=a,l<t-1&&e.push({time:c,scale:n})}return e.push({time:1,scale:1}),e}easeOutQuad(t){return 1-(1-t)*(1-t)}}class Te{constructor(t,i=600){this.entries=new Map,this.togetherRafId=null,this.togetherSpeed=0,this.config=t,this.entryDurationMs=i}register(t,i,e,n){if(this.entries.has(t))return;const s=n??this.entryDurationMs,r=this.config.startDelay??s,a={element:t,index:i,totalImages:e,animation:null,blinkAnimation:null,customTeardown:null,paused:!1,stopped:!1,startTimer:null};this.entries.set(t,a),a.startTimer=setTimeout(()=>{a.startTimer=null,!a.stopped&&!a.paused&&this._startAnimation(a)},r)}pauseForImage(t){const i=this.entries.get(t);i&&(i.paused=!0,i.startTimer!==null&&(clearTimeout(i.startTimer),i.startTimer=null),this._pauseEntry(i))}resumeForImage(t){const i=this.entries.get(t);!i||i.stopped||(i.paused=!1,this._startAnimation(i))}stopForImage(t){const i=this.entries.get(t);i&&(i.stopped=!0,i.startTimer!==null&&(clearTimeout(i.startTimer),i.startTimer=null),this._cancelEntry(i),this.entries.delete(t))}pauseAll(){for(const t of this.entries.values())t.paused=!0,t.startTimer!==null&&(clearTimeout(t.startTimer),t.startTimer=null),this._pauseEntry(t)}resumeAll(){for(const t of this.entries.values())t.stopped||(t.paused=!1,this._startAnimation(t))}stopAll(){for(const t of this.entries.values())t.stopped=!0,t.startTimer!==null&&(clearTimeout(t.startTimer),t.startTimer=null),this._cancelEntry(t);this.entries.clear(),this._stopTogetherLoop()}_startAnimation(t){const{type:i}=this.config;switch(i){case"wiggle":this._startWiggle(t);break;case"pulse":this._startPulse(t);break;case"blink":this._startBlink(t);break;case"spin":this._startSpin(t);break;case"custom":this._startCustom(t);break}}_startWiggle(t){const i={...le,...this.config.wiggle},e=[{transform:"rotate(0deg)",offset:0},{transform:`rotate(${i.maxAngle}deg)`,offset:.25},{transform:"rotate(0deg)",offset:.5},{transform:`rotate(${-i.maxAngle}deg)`,offset:.75},{transform:"rotate(0deg)",offset:1}];i.sync==="together"?(t.animation=t.element.animate(e,{duration:i.speed,iterations:1/0,composite:"add",fill:"both"}),t.animation.pause(),this._startTogetherLoop(i.speed)):t.animation=t.element.animate(e,{duration:i.speed,delay:-(Math.random()*i.speed),iterations:1/0,composite:"add"})}_startPulse(t){const i={...he,...this.config.pulse},e=[{transform:"scale(1)",offset:0},{transform:`scale(${i.maxScale})`,offset:.25},{transform:"scale(1)",offset:.5},{transform:`scale(${i.minScale})`,offset:.75},{transform:"scale(1)",offset:1}];i.sync==="together"?(t.animation=t.element.animate(e,{duration:i.speed,iterations:1/0,composite:"add",fill:"both"}),t.animation.pause(),this._startTogetherLoop(i.speed)):t.animation=t.element.animate(e,{duration:i.speed,delay:-(Math.random()*i.speed),iterations:1/0,composite:"add"})}_startBlink(t){const i={...de,...this.config.blink},e=-(Math.random()*i.speed),n=parseFloat(getComputedStyle(t.element).opacity)||1;let s,r;i.style==="fade"?(s=[{opacity:n,offset:0},{opacity:0,offset:.5},{opacity:n,offset:1}],r={duration:i.speed,delay:e,iterations:1/0,easing:"ease-in-out"}):(s=[{opacity:n,offset:0},{opacity:n,offset:i.onRatio},{opacity:0,offset:Math.min(i.onRatio+.01,.99)},{opacity:0,offset:.99},{opacity:n,offset:1}],r={duration:i.speed,delay:e,iterations:1/0}),t.blinkAnimation=t.element.animate(s,r)}_startSpin(t){const i={...ue,...this.config.spin},e=i.direction==="clockwise"?360:-360;t.animation=t.element.animate([{transform:"rotate(0deg)"},{transform:`rotate(${e}deg)`}],{duration:i.speed,iterations:1/0,easing:"linear",composite:"add"})}_startCustom(t){const i=this.config.custom;if(!i)return;const e=i({element:t.element,index:t.index,totalImages:t.totalImages});typeof e=="function"?t.customTeardown=e:e&&typeof e.play=="function"&&(t.animation=e)}_startTogetherLoop(t){if(this.togetherSpeed=t,this.togetherRafId!==null)return;const i=()=>{const e=performance.now()%this.togetherSpeed;for(const n of this.entries.values())!n.stopped&&!n.paused&&n.animation&&(n.animation.currentTime=e);this.togetherRafId=requestAnimationFrame(i)};this.togetherRafId=requestAnimationFrame(i)}_stopTogetherLoop(){this.togetherRafId!==null&&(cancelAnimationFrame(this.togetherRafId),this.togetherRafId=null)}_pauseEntry(t){t.animation&&(t.animation.cancel(),t.animation=null),t.blinkAnimation&&(t.blinkAnimation.cancel(),t.blinkAnimation=null)}_cancelEntry(t){t.animation&&(t.animation.cancel(),t.animation=null),t.blinkAnimation&&(t.blinkAnimation.cancel(),t.blinkAnimation=null),t.customTeardown&&(t.customTeardown(),t.customTeardown=null)}}class $t{constructor(t,i={}){this.config=t,this.imageConfig=i}generate(t,i,e={}){const n=[],{width:s,height:r}=i,a=this.config.spacing.padding,c=e.fixedHeight??200,l=this.imageConfig.rotation?.mode??"none",u=this.imageConfig.rotation?.range?.min??-15,h=this.imageConfig.rotation?.range?.max??15,d=this.imageConfig.sizing?.variance?.min??1,g=this.imageConfig.sizing?.variance?.max??1,p=d!==1||g!==1,f=c*1.5/2,m=c/2,y=s-a-f,E=r-a-m,v=a+f,I=a+m;for(let w=0;w<t;w++){const A=this.random(v,y),z=this.random(I,E),F=l==="random"?this.random(u,h):0,U=p?this.random(d,g):1,D=c*U,N={id:w,x:A,y:z,rotation:F,scale:U,baseSize:D};n.push(N)}return n}random(t,i){return Math.random()*(i-t)+t}}class _t{constructor(t,i={}){this.config=t,this.imageConfig=i}generate(t,i,e={}){const n=[],{width:s,height:r}=i,a=e.fixedHeight??200,c=this.imageConfig.rotation?.mode??"none",l=this.imageConfig.rotation?.range?.min??-15,u=this.imageConfig.rotation?.range?.max??15,h=this.imageConfig.sizing?.variance?.min??1,d=this.imageConfig.sizing?.variance?.max??1,g=h!==1||d!==1,p=this.config.scaleDecay??0,b={...ne,...this.config.radial},f=e.fixedHeight??a,m=s/2,y=r/2,E=Math.ceil(Math.sqrt(t)),v=this.config.spacing.padding??50,I=Math.max(f*.8,Math.min(m-v-f/2,y-v-f/2));if(t>0){const z=g?this.random(h,d):1,F=f*z;n.push({id:0,x:m,y,rotation:c==="random"?this.random(l*.33,u*.33):0,scale:z,baseSize:F,zIndex:100})}let w=1,A=1;for(;w<t;){const z=A/E,F=p>0?1-z*p*.5:1,U=Math.max(f*.8,I/E*1.5/b.tightness),D=A*U,N=D*1.5,k=Math.PI*(3*(N+D)-Math.sqrt((3*N+D)*(N+3*D))),T=this.estimateWidth(f),P=Math.floor(k/(T*.7));if(P===0){A++;continue}const G=2*Math.PI/P,H=A*(20*Math.PI/180);for(let M=0;M<P&&w<t;M++){const R=M*G+H,B=g?this.random(h,d):1,X=F*B,L=f*X;let $=m+Math.cos(R)*N,O=y+Math.sin(R)*D;const _=L*1.5/2,j=L/2;$-_<v?$=v+_:$+_>s-v&&($=s-v-_),O-j<v?O=v+j:O+j>r-v&&(O=r-v-j);const J=c==="random"?this.random(l,u):0;n.push({id:w,x:$,y:O,rotation:J,scale:X,baseSize:L,zIndex:Math.max(1,100-A)}),w++}A++}return n}estimateWidth(t){return t*1.4}random(t,i){return Math.random()*(i-t)+t}}const Re={columns:"auto",rows:"auto",stagger:"none",jitter:0,overlap:0,fillDirection:"row",alignment:"center",gap:10,overflowOffset:.25},Ut=[{x:1,y:1},{x:-1,y:-1},{x:1,y:-1},{x:-1,y:1},{x:-1,y:0},{x:1,y:0},{x:0,y:-1},{x:0,y:1}];class Ht{constructor(t,i={}){this.config=t,this.imageConfig=i}generate(t,i,e={}){const n=[],{width:s,height:r}=i,a={...Re,...this.config.grid},c=this.config.spacing.padding,l=e.fixedHeight??200,u=this.imageConfig.rotation?.mode??"none",h=this.imageConfig.sizing?.variance?.min??1,d=this.imageConfig.sizing?.variance?.max??1,g=h!==1||d!==1,p=s-2*c,b=r-2*c,{columns:f,rows:m}=this.calculateGridDimensions(t,p,b,l,a),y=a.stagger==="row",E=a.stagger==="column",v=y?f+.5:f,I=E?m+.5:m,w=(p-a.gap*(f-1))/v,A=(b-a.gap*(m-1))/I,z=y?w/2:0,F=E?A/2:0,U=1+a.overlap,D=Math.min(w,A)*U,N=e.fixedHeight?Math.min(e.fixedHeight,D):D,k=f*w+(f-1)*a.gap+z,T=m*A+(m-1)*a.gap+F,P=c+(p-k)/2,G=c+(b-T)/2,H=f*m,M=a.columns!=="auto"&&a.rows!=="auto",R=M&&t>H;typeof window<"u"&&(window.__gridOverflowDebug={gridConfigColumns:a.columns,gridConfigRows:a.rows,columns:f,rows:m,cellCount:H,hasFixedGrid:M,imageCount:t,isOverflowMode:R});const B=R?new Array(H).fill(0):[],X=Math.min(w,A)*a.overflowOffset;for(let L=0;L<t;L++){let $,O,Y=0;if(R&&L>=H){const q=L-H,W=q%H;Y=Math.floor(q/H)+1,B[W]++,a.fillDirection==="row"?($=W%f,O=Math.floor(W/f)):(O=W%m,$=Math.floor(W/m))}else a.fillDirection==="row"?($=L%f,O=Math.floor(L/f)):(O=L%m,$=Math.floor(L/m));let _=P+$*(w+a.gap)+w/2,j=G+O*(A+a.gap)+A/2;if(a.stagger==="row"&&O%2===1?_+=w/2:a.stagger==="column"&&$%2===1&&(j+=A/2),Y>0){const q=(Y-1)%Ut.length,W=Ut[q];_+=W.x*X,j+=W.y*X}if(a.jitter>0){const q=w/2*a.jitter,W=A/2*a.jitter;_+=this.random(-q,q),j+=this.random(-W,W)}let J=_,Z=j;if(!R&&a.fillDirection==="row"){const q=t%f||f;if(O===Math.floor((t-1)/f)&&q<f){const ie=q*w+(q-1)*a.gap;let Tt=0;a.alignment==="center"?Tt=(k-ie)/2:a.alignment==="end"&&(Tt=k-ie),J+=Tt}}const wt=g?this.random(h,d):1,Q=N*wt,ct=Q*1.5/2,lt=Q/2,St=c+ct,It=s-c-ct,Ze=c+lt,Qe=r-c-lt;J=Math.max(St,Math.min(J,It)),Z=Math.max(Ze,Math.min(Z,Qe));let Ct=0;if(u==="random"){const q=this.imageConfig.rotation?.range?.min??-15,W=this.imageConfig.rotation?.range?.max??15;a.jitter>0?Ct=this.random(q*a.jitter,W*a.jitter):Ct=this.random(q,W)}let At;R&&Y>0?At=50-Y:At=R?100+L:L+1,n.push({id:L,x:J,y:Z,rotation:Ct,scale:wt,baseSize:Q,zIndex:At})}return n}calculateGridDimensions(t,i,e,n,s){let r,a;if(s.columns!=="auto"&&s.rows!=="auto")r=s.columns,a=s.rows;else if(s.columns!=="auto")r=s.columns,a=Math.ceil(t/r);else if(s.rows!=="auto")a=s.rows,r=Math.ceil(t/a);else{const c=i/e;for(r=Math.max(1,Math.round(Math.sqrt(t*c/1.4))),a=Math.ceil(t/r);r>1&&(r-1)*a>=t;)r--}return{columns:Math.max(1,r),rows:Math.max(1,a)}}random(t,i){return Math.random()*(i-t)+t}}const Le=Math.PI*(3-Math.sqrt(5)),Fe={spiralType:"golden",direction:"counterclockwise",tightness:1,scaleDecay:0,startAngle:0};class Nt{constructor(t,i={}){this.config=t,this.imageConfig=i}generate(t,i,e={}){const n=[],{width:s,height:r}=i,a={...Fe,...this.config.spiral},c=this.config.spacing.padding,l=e.fixedHeight??200,u=this.imageConfig.rotation?.mode??"none",h=this.imageConfig.rotation?.range?.min??-15,d=this.imageConfig.rotation?.range?.max??15,g=this.imageConfig.sizing?.variance?.min??1,p=this.imageConfig.sizing?.variance?.max??1,b=g!==1||p!==1,f=this.config.scaleDecay??a.scaleDecay,m=s/2,y=r/2,E=Math.min(m-c-l/2,y-c-l/2),v=a.direction==="clockwise"?-1:1;for(let I=0;I<t;I++){let w,A;if(a.spiralType==="golden")w=I*Le*v+a.startAngle,A=this.calculateGoldenRadius(I,t,E,a.tightness);else if(a.spiralType==="archimedean"){const _=I*.5*a.tightness;w=_*v+a.startAngle,A=this.calculateArchimedeanRadius(_,t,E,a.tightness)}else{const _=I*.3*a.tightness;w=_*v+a.startAngle,A=this.calculateLogarithmicRadius(_,t,E,a.tightness)}const z=m+Math.cos(w)*A,F=y+Math.sin(w)*A,U=A/E,D=f>0?1-U*f*.5:1,N=b?this.random(g,p):1,k=D*N,T=l*k,G=T*1.5/2,H=T/2,M=c+G,R=s-c-G,B=c+H,X=r-c-H,L=Math.max(M,Math.min(z,R)),$=Math.max(B,Math.min(F,X));let O=0;if(u==="random"){const _=w*180/Math.PI%360,j=this.random(h,d);O=a.spiralType==="golden"?j:_*.1+j*.9}else u==="tangent"&&(O=this.calculateSpiralTangent(w,A,a));const Y=t-I;n.push({id:I,x:L,y:$,rotation:O,scale:k,baseSize:T,zIndex:Y})}return n}calculateSpiralTangent(t,i,e){let n;if(e.spiralType==="golden")n=t+Math.PI/2;else if(e.spiralType==="archimedean"){const r=1/e.tightness,a=Math.atan(i/r);n=t+a}else{const r=.15/e.tightness,a=Math.atan(1/r);n=t+a}return n*180/Math.PI%360-90}calculateGoldenRadius(t,i,e,n){const r=e/Math.sqrt(i)*Math.sqrt(t)/n;return Math.min(r,e)}calculateArchimedeanRadius(t,i,e,n){const s=i*.5*n;return t/s*e}calculateLogarithmicRadius(t,i,e,n){const s=e*.05,r=.15/n,a=s*Math.exp(r*t),c=i*.3*n,l=s*Math.exp(r*c);return a/l*e}random(t,i){return Math.random()*(i-t)+t}}const Me={clusterCount:"auto",clusterSpread:150,clusterSpacing:200,density:"uniform",overlap:.3,distribution:"gaussian"};class kt{constructor(t,i={}){this.config=t,this.imageConfig=i}generate(t,i,e={}){const n=[],{width:s,height:r}=i,a={...Me,...this.config.cluster},c=this.config.spacing.padding,l=e.fixedHeight??200,u=this.imageConfig.rotation?.mode??"none",h=this.imageConfig.rotation?.range?.min??-15,d=this.imageConfig.rotation?.range?.max??15,g=this.imageConfig.sizing?.variance?.min??1,p=this.imageConfig.sizing?.variance?.max??1,b=g!==1||p!==1,f=this.calculateClusterCount(t,a.clusterCount,s,r,a.clusterSpacing),m=this.generateClusterCenters(f,s,r,c,a),y=new Array(f).fill(0);for(let v=0;v<t;v++)y[v%f]++;let E=0;for(let v=0;v<f;v++){const I=m[v],w=y[v];for(let A=0;A<w;A++){let z,F;if(a.distribution==="gaussian")z=this.gaussianRandom()*I.spread,F=this.gaussianRandom()*I.spread;else{const O=this.random(0,Math.PI*2),Y=this.random(0,I.spread);z=Math.cos(O)*Y,F=Math.sin(O)*Y}const U=1+a.overlap*.5,D=1+a.overlap*.3;z/=U,F/=U;const N=b?this.random(g,p):1,k=D*N,T=l*k;let P=I.x+z,G=I.y+F;const M=T*1.5/2,R=T/2;P=Math.max(c+M,Math.min(P,s-c-M)),G=Math.max(c+R,Math.min(G,r-c-R));const B=u==="random"?this.random(h,d):0,L=Math.sqrt(z*z+F*F)/I.spread,$=Math.round((1-L)*50)+1;n.push({id:E,x:P,y:G,rotation:B,scale:k,baseSize:T,zIndex:$}),E++}}return n}calculateClusterCount(t,i,e,n,s){if(i!=="auto")return Math.max(1,Math.min(i,t));const a=Math.max(1,Math.ceil(t/8)),c=Math.floor(e/s*(n/s)*.6);return Math.max(1,Math.min(a,c,10))}generateClusterCenters(t,i,e,n,s){const r=[],c=n+s.clusterSpread,l=i-n-s.clusterSpread,u=n+s.clusterSpread,h=e-n-s.clusterSpread;for(let d=0;d<t;d++){let g=null,p=-1;for(let b=0;b<100;b++){const f={x:this.random(c,l),y:this.random(u,h),spread:this.calculateClusterSpread(s)};let m=1/0;for(const y of r){const E=f.x-y.x,v=f.y-y.y,I=Math.sqrt(E*E+v*v);m=Math.min(m,I)}if((r.length===0||m>p)&&(g=f,p=m),m>=s.clusterSpacing)break}g&&r.push(g)}return r}calculateClusterSpread(t){return t.density==="uniform"?t.clusterSpread:t.clusterSpread*this.random(.5,1.5)}gaussianRandom(){let t=0,i=0;for(;t===0;)t=Math.random();for(;i===0;)i=Math.random();const e=Math.sqrt(-2*Math.log(t))*Math.cos(2*Math.PI*i);return Math.max(-3,Math.min(3,e))/3}random(t,i){return Math.random()*(i-t)+t}}class Bt{constructor(t,i={}){this.config=t,this.imageConfig=i}generate(t,i,e={}){const n=[],{width:s,height:r}=i,a=e.fixedHeight??200,c=this.config.spacing.padding??50,l=this.imageConfig.rotation?.mode??"none",u=this.imageConfig.rotation?.range?.min??-15,h=this.imageConfig.rotation?.range?.max??15,d=this.imageConfig.sizing?.variance?.min??1,g=this.imageConfig.sizing?.variance?.max??1,p=d!==1||g!==1,b=e.fixedHeight??a,f={...oe,...this.config.wave},{rows:m,amplitude:y,frequency:E,phaseShift:v,synchronization:I}=f,w=Math.ceil(t/m),F=b*1.5/2,U=c+F,D=s-c-F,N=D-U,k=w>1?N/(w-1):0,T=c+y+b/2,P=r-c-y-b/2,G=P-T,H=m>1?G/(m-1):0;let M=0;for(let R=0;R<m&&M<t;R++){const B=m===1?(T+P)/2:T+R*H;let X=0;I==="offset"?X=R*v:I==="alternating"&&(X=R*Math.PI);for(let L=0;L<w&&M<t;L++){const $=w===1?(U+D)/2:U+L*k,O=this.calculateWaveY($,s,y,E,X),Y=$,_=B+O,j=p?this.random(d,g):1,J=b*j;let Z=0;l==="tangent"?Z=this.calculateRotation($,s,y,E,X):l==="random"&&(Z=this.random(u,h));const Q=J*1.5/2,xt=J/2,ct=c+Q,lt=s-c-Q,St=c+xt,It=r-c-xt;n.push({id:M,x:Math.max(ct,Math.min(Y,lt)),y:Math.max(St,Math.min(_,It)),rotation:Z,scale:j,baseSize:J,zIndex:M+1}),M++}}return n}calculateWaveY(t,i,e,n,s){const r=t/i;return e*Math.sin(n*r*2*Math.PI+s)}calculateRotation(t,i,e,n,s){const r=t/i,a=e*n*2*Math.PI*Math.cos(n*r*2*Math.PI+s)/i;return Math.atan(a)*(180/Math.PI)}random(t,i){return Math.random()*(i-t)+t}}const bt=100,et=100/Math.sqrt(3),yt=[[et/2,0],[3*et/2,0],[2*et,50],[3*et/2,100],[et/2,100],[0,50]],Oe=yt[1][0]/bt,ze=yt[2][1]/bt;function De(o){return{colStep:Oe*o,rowOffset:ze*o}}function Pe(o,t,i,e,n,s){const{colStep:r}=De(s);return{px:e+r*o,py:n+s*(t+o/2)}}const $e=[[1,0,-1],[0,1,-1],[-1,1,0],[-1,0,1],[0,-1,1],[1,-1,0]];function _e(o){if(o===0)return[[0,0,0]];const t=[];let[i,e,n]=[0,-o,o];for(const[s,r,a]of $e)for(let c=0;c<o;c++)t.push([i,e,n]),i+=s,e+=r,n+=a;return t}class jt{constructor(t,i={}){this.config=t}generate(t,i,e={}){const n=[],{width:s,height:r}=i,a=s/2,c=r/2,l=e.fixedHeight??200,h={...se,...this.config.honeycomb}.spacing??0,d=l+h;let g=0,p=0;for(;g<t;){const b=_e(p);for(const[f,m,y]of b){if(g>=t)break;const{px:E,py:v}=Pe(f,m,y,a,c,d);n.push({id:g,x:E,y:v,rotation:0,scale:1,baseSize:l,zIndex:Math.max(1,100-p)}),g++}p++}return n}}class Wt{constructor(t){this.config=t.layout,this.imageConfig=t.image,this.layouts=new Map,this.placementLayout=this.initLayout()}initLayout(){switch(this.config.algorithm){case"radial":return new _t(this.config,this.imageConfig);case"grid":return new Ht(this.config,this.imageConfig);case"spiral":return new Nt(this.config,this.imageConfig);case"cluster":return new kt(this.config,this.imageConfig);case"wave":return new Bt(this.config,this.imageConfig);case"honeycomb":return new jt(this.config,this.imageConfig);default:return new $t(this.config,this.imageConfig)}}generateLayout(t,i,e={}){const n=this.placementLayout.generate(t,i,e);return n.forEach(s=>{this.layouts.set(s.id,s)}),n}getOriginalState(t){return this.layouts.get(Number(t))}reset(){this.layouts.clear()}updateConfig(t){t.layout&&(Object.assign(this.config,t.layout),t.layout.algorithm&&t.layout.algorithm!==this.config.algorithm&&(this.placementLayout=this.initLayout())),t.image&&Object.assign(this.imageConfig,t.image)}getBreakpoints(){return this.config.responsive??{mobile:{maxWidth:767},tablet:{maxWidth:1199}}}resolveBreakpoint(t){const i=this.getBreakpoints();return t<=i.mobile.maxWidth?"mobile":t<=i.tablet.maxWidth?"tablet":"screen"}resolveBaseHeight(t){const i=this.imageConfig.sizing;if(!i||i.mode==="adaptive")return;const e=i.height;if(e===void 0)return;if(typeof e=="number")return e;const n=e,s=this.resolveBreakpoint(t);return s==="mobile"?n.mobile??n.tablet??n.screen:s==="tablet"?n.tablet??n.screen??n.mobile:n.screen??n.tablet??n.mobile}calculateAdaptiveSize(t,i,e,n){const s=this.imageConfig.sizing,r=this.resolveBaseHeight(n);if(r!==void 0)return{height:r};const a=s?.minSize??50,c=s?.maxSize??400,l=this.config.targetCoverage??.6,u=this.config.densityFactor??1,{width:h,height:d}=t,b=h*d*l/i;let m=Math.sqrt(b/1.4);m*=u,m=Math.min(m,e);let y=this.clamp(m,a,c);if(y===a&&m<a){const E=Math.max(a*.05,20);y=Math.max(E,m)}return this.config.algorithm==="honeycomb"&&(y=Math.min(y,this.honeycombMaxImageHeight(i,t))),{height:y}}honeycombMaxImageHeight(t,i){if(t<=1)return 1/0;let e=0,n=1;for(;n<t;)e++,n+=6*e;const s=this.config.spacing?.padding??50,r=this.config.honeycomb?.spacing??0,a=i.width/2,c=i.height/2,l=Math.sqrt(3)/2,u=1/Math.sqrt(3),h=(c-s-r*e)/(e+.5),d=(a-s-l*r*e)/(l*e+u);return Math.max(10,Math.min(h,d))}clamp(t,i,e){return Math.max(i,Math.min(e,t))}}var x=(o=>(o.IDLE="idle",o.FOCUSING="focusing",o.FOCUSED="focused",o.UNFOCUSING="unfocusing",o.CROSS_ANIMATING="cross_animating",o))(x||{});const Gt={circle:"circle(50%)",square:"polygon(0% 0%, 100% 0%, 100% 100%, 0% 100%)",triangle:"polygon(50% 0%, 100% 100%, 0% 100%)",pentagon:"polygon(50% 0%, 100% 38%, 82% 100%, 18% 100%, 0% 38%)",hexagon:"polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%)",octagon:"polygon(30% 0%, 70% 0%, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0% 70%, 0% 30%)",diamond:"polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%)"},Ue={circle:{refHeight:100,points:[]},square:{refHeight:100,points:[[0,0],[100,0],[100,100],[0,100]]},triangle:{refHeight:100,points:[[50,0],[100,100],[0,100]]},pentagon:{refHeight:100,points:[[50,0],[100,38],[82,100],[18,100],[0,38]]},hexagon:{refHeight:bt,points:yt},octagon:{refHeight:100,points:[[30,0],[70,0],[100,30],[100,70],[70,100],[30,100],[0,70],[0,30]]},diamond:{refHeight:100,points:[[50,0],[100,50],[50,100],[0,50]]}};function He(o){if(o)return o in Gt?Gt[o]:o}function Ne(o,t,i){const e=Ue[o];if(!e)return"";const n=t/e.refHeight;if(o==="circle")return`circle(${Math.round(50*n*100)/100}px)`;const s=e.points.map(([b])=>b),r=e.points.map(([,b])=>b),a=(Math.min(...s)+Math.max(...s))/2*n,c=(Math.min(...r)+Math.max(...r))/2*n,l=(Math.max(...s)-Math.min(...s))*n,u=(i??l)/2,h=t/2,d=u-a,g=h-c;return`polygon(${e.points.map(([b,f])=>{const m=Math.round((b*n+d)*100)/100,y=Math.round((f*n+g)*100)/100;return`${m}px ${y}px`}).join(", ")})`}function ke(o){return o in V}function Be(o){return o?ke(o)?V[o]:o:V.md}function je(o){if(!o)return"";const t=[];if(o.grayscale!==void 0&&t.push(`grayscale(${o.grayscale})`),o.blur!==void 0&&t.push(`blur(${o.blur}px)`),o.brightness!==void 0&&t.push(`brightness(${o.brightness})`),o.contrast!==void 0&&t.push(`contrast(${o.contrast})`),o.saturate!==void 0&&t.push(`saturate(${o.saturate})`),o.opacity!==void 0&&t.push(`opacity(${o.opacity})`),o.sepia!==void 0&&t.push(`sepia(${o.sepia})`),o.hueRotate!==void 0&&t.push(`hue-rotate(${o.hueRotate}deg)`),o.invert!==void 0&&t.push(`invert(${o.invert})`),o.dropShadow!==void 0)if(typeof o.dropShadow=="string")t.push(`drop-shadow(${o.dropShadow})`);else{const i=o.dropShadow;t.push(`drop-shadow(${i.x}px ${i.y}px ${i.blur}px ${i.color})`)}return t.join(" ")}function it(o){if(!o||o.style==="none"||o.width===0)return"none";const t=o.width??0,i=o.style??"solid",e=o.color??"#000000";return`${t}px ${i} ${e}`}function nt(o,t,i){if(!o)return{};const e={};if(o.borderRadiusTopLeft!==void 0||o.borderRadiusTopRight!==void 0||o.borderRadiusBottomRight!==void 0||o.borderRadiusBottomLeft!==void 0){const a=o.border?.radius??0;o.borderRadiusTopLeft!==void 0?e.borderTopLeftRadius=`${o.borderRadiusTopLeft}px`:a&&(e.borderTopLeftRadius=`${a}px`),o.borderRadiusTopRight!==void 0?e.borderTopRightRadius=`${o.borderRadiusTopRight}px`:a&&(e.borderTopRightRadius=`${a}px`),o.borderRadiusBottomRight!==void 0?e.borderBottomRightRadius=`${o.borderRadiusBottomRight}px`:a&&(e.borderBottomRightRadius=`${a}px`),o.borderRadiusBottomLeft!==void 0?e.borderBottomLeftRadius=`${o.borderRadiusBottomLeft}px`:a&&(e.borderBottomLeftRadius=`${a}px`)}else o.border?.radius!==void 0&&(e.borderRadius=`${o.border.radius}px`);if(o.borderTop||o.borderRight||o.borderBottom||o.borderLeft){const a=o.border||{},c={...a,...o.borderTop},l={...a,...o.borderRight},u={...a,...o.borderBottom},h={...a,...o.borderLeft};e.borderTop=it(c),e.borderRight=it(l),e.borderBottom=it(u),e.borderLeft=it(h)}else o.border&&(e.border=it(o.border));o.shadow!==void 0&&(e.boxShadow=Be(o.shadow));const r=je(o.filter);if(e.filter=r||"none",o.opacity!==void 0&&(e.opacity=String(o.opacity)),o.cursor!==void 0&&(e.cursor=o.cursor),o.outline&&o.outline.style!=="none"&&(o.outline.width??0)>0){const a=o.outline.width??0,c=o.outline.style??"solid",l=o.outline.color??"#000000";e.outline=`${a}px ${c} ${l}`,o.outline.offset!==void 0&&(e.outlineOffset=`${o.outline.offset}px`)}if(o.objectFit!==void 0&&(e.objectFit=o.objectFit),o.aspectRatio!==void 0&&(e.aspectRatio=o.aspectRatio),o.clipPath!==void 0){let a;const c=typeof o.clipPath=="object"&&o.clipPath!==null&&"shape"in o.clipPath,l=c?o.clipPath:void 0;if(l?.mode==="height-relative"&&t)a=Ne(l.shape,t,i);else{const u=c&&l?l.shape:o.clipPath;a=He(u)}a&&(a==="none"?e.clipPath="unset":(e.clipPath=a,e.overflow="hidden"))}return e}function We(o,t){t.borderRadius!==void 0&&(o.style.borderRadius=t.borderRadius),t.borderTopLeftRadius!==void 0&&(o.style.borderTopLeftRadius=t.borderTopLeftRadius),t.borderTopRightRadius!==void 0&&(o.style.borderTopRightRadius=t.borderTopRightRadius),t.borderBottomRightRadius!==void 0&&(o.style.borderBottomRightRadius=t.borderBottomRightRadius),t.borderBottomLeftRadius!==void 0&&(o.style.borderBottomLeftRadius=t.borderBottomLeftRadius),t.border!==void 0&&(o.style.border=t.border),t.borderTop!==void 0&&(o.style.borderTop=t.borderTop),t.borderRight!==void 0&&(o.style.borderRight=t.borderRight),t.borderBottom!==void 0&&(o.style.borderBottom=t.borderBottom),t.borderLeft!==void 0&&(o.style.borderLeft=t.borderLeft),t.boxShadow!==void 0&&(o.style.boxShadow=t.boxShadow),t.filter!==void 0&&(o.style.filter=t.filter),t.opacity!==void 0&&(o.style.opacity=t.opacity),t.cursor!==void 0&&(o.style.cursor=t.cursor),t.outline!==void 0&&(o.style.outline=t.outline),t.outlineOffset!==void 0&&(o.style.outlineOffset=t.outlineOffset),t.objectFit!==void 0&&(o.style.objectFit=t.objectFit),t.aspectRatio!==void 0&&(o.style.aspectRatio=t.aspectRatio),t.clipPath!==void 0&&(o.style.clipPath=t.clipPath),t.overflow!==void 0&&(o.style.overflow=t.overflow)}function at(o,t,i,e){const n=nt(t,i,e);We(o,n)}function qt(o){return o?Array.isArray(o)?o.join(" "):o:""}function ot(o,t){const i=qt(t);i&&i.split(" ").forEach(e=>{e.trim()&&o.classList.add(e.trim())})}function vt(o,t){const i=qt(t);i&&i.split(" ").forEach(e=>{e.trim()&&o.classList.remove(e.trim())})}const Xt={UNFOCUSING:999,FOCUSING:1e3};class Yt{constructor(t,i,e){this.state=x.IDLE,this.currentFocus=null,this.focusData=null,this.outgoing=null,this.incoming=null,this.focusGeneration=0,this.onUnfocusComplete=null,this.config=t,this.animationEngine=i,this.styling=e,this.focusedClassName=e?.focused?.className}setOnUnfocusCompleteCallback(t){this.onUnfocusComplete=t}getState(){return this.state}isAnimating(){return this.state!==x.IDLE&&this.state!==x.FOCUSED}normalizeScalePercent(t){return t>1?t/100:t}calculateFocusDimensions(t,i,e){const n=this.normalizeScalePercent(this.config.scalePercent),s=e.height*n,r=t/i;let a=s,c=a*r;const l=e.width*n;return c>l&&(c=l,a=c/r),{width:c,height:a}}calculateFocusTransform(t,i){const e=t.width/2,n=t.height/2,s=e-i.x,r=n-i.y;return{x:s,y:r,rotation:0,scale:1}}buildDimensionZoomTransform(t){const i=["translate(-50%, -50%)"];if(t.x!==void 0||t.y!==void 0){const e=t.x??0,n=t.y??0;i.push(`translate(${e}px, ${n}px)`)}return t.rotation!==void 0&&i.push(`rotate(${t.rotation}deg)`),i.join(" ")}animateWithDimensions(t,i,e,n,s,r,a,c){const l=this.buildDimensionZoomTransform(i),u=this.buildDimensionZoomTransform(e);return t.style.transition="none",t.animate([{transform:l,width:`${n}px`,height:`${s}px`},{transform:u,width:`${r}px`,height:`${a}px`}],{duration:c,easing:"cubic-bezier(0.4, 0, 0.2, 1)",fill:"forwards"})}applyFocusedStyling(t,i){if(t.style.zIndex=String(i),t.classList.add("fbn-ic-focused"),ot(t,this.focusedClassName),this.styling?.focused){const e=nt(this.styling.focused,t.offsetHeight,t.offsetWidth);e.borderRadius!==void 0&&(t.style.borderRadius=e.borderRadius),e.borderTopLeftRadius!==void 0&&(t.style.borderTopLeftRadius=e.borderTopLeftRadius),e.borderTopRightRadius!==void 0&&(t.style.borderTopRightRadius=e.borderTopRightRadius),e.borderBottomRightRadius!==void 0&&(t.style.borderBottomRightRadius=e.borderBottomRightRadius),e.borderBottomLeftRadius!==void 0&&(t.style.borderBottomLeftRadius=e.borderBottomLeftRadius),e.border!==void 0&&(t.style.border=e.border),e.borderTop!==void 0&&(t.style.borderTop=e.borderTop),e.borderRight!==void 0&&(t.style.borderRight=e.borderRight),e.borderBottom!==void 0&&(t.style.borderBottom=e.borderBottom),e.borderLeft!==void 0&&(t.style.borderLeft=e.borderLeft),e.boxShadow!==void 0&&(t.style.boxShadow=e.boxShadow),e.filter!==void 0&&(t.style.filter=e.filter),e.opacity!==void 0&&(t.style.opacity=e.opacity),e.cursor!==void 0&&(t.style.cursor=e.cursor),e.outline!==void 0&&(t.style.outline=e.outline),e.outlineOffset!==void 0&&(t.style.outlineOffset=e.outlineOffset),e.objectFit!==void 0&&(t.style.objectFit=e.objectFit),e.aspectRatio!==void 0&&(t.style.aspectRatio=e.aspectRatio)}}removeFocusedStyling(t,i){if(t.style.zIndex=i,t.classList.remove("fbn-ic-focused"),vt(t,this.focusedClassName),this.styling?.default){const e=nt(this.styling.default,t.offsetHeight,t.offsetWidth);e.borderRadius!==void 0&&(t.style.borderRadius=e.borderRadius),e.borderTopLeftRadius!==void 0&&(t.style.borderTopLeftRadius=e.borderTopLeftRadius),e.borderTopRightRadius!==void 0&&(t.style.borderTopRightRadius=e.borderTopRightRadius),e.borderBottomRightRadius!==void 0&&(t.style.borderBottomRightRadius=e.borderBottomRightRadius),e.borderBottomLeftRadius!==void 0&&(t.style.borderBottomLeftRadius=e.borderBottomLeftRadius),e.border!==void 0&&(t.style.border=e.border),e.borderTop!==void 0&&(t.style.borderTop=e.borderTop),e.borderRight!==void 0&&(t.style.borderRight=e.borderRight),e.borderBottom!==void 0&&(t.style.borderBottom=e.borderBottom),e.borderLeft!==void 0&&(t.style.borderLeft=e.borderLeft),e.boxShadow!==void 0&&(t.style.boxShadow=e.boxShadow),e.filter!==void 0&&(t.style.filter=e.filter),e.opacity!==void 0&&(t.style.opacity=e.opacity),e.cursor!==void 0&&(t.style.cursor=e.cursor),e.outline!==void 0&&(t.style.outline=e.outline),e.outlineOffset!==void 0&&(t.style.outlineOffset=e.outlineOffset),e.objectFit!==void 0&&(t.style.objectFit=e.objectFit),e.aspectRatio!==void 0&&(t.style.aspectRatio=e.aspectRatio)}}startClipPathAnimation(t,i,e){let n=e?this.styling?.focused??this.styling?.default:this.styling?.default;e&&this.styling?.focused&&this.styling.focused.clipPath===void 0&&(n={...n,clipPath:void 0});const s=()=>{const r=t.offsetHeight,a=t.offsetWidth,c=nt(n,r,a);c.clipPath!==void 0?t.style.clipPath=c.clipPath:t.style.clipPath="unset",c.overflow!==void 0&&(t.style.overflow=c.overflow),i.animation.playState==="running"&&requestAnimationFrame(s)};requestAnimationFrame(s)}startFocusAnimation(t,i,e,n,s){const r=t.style.zIndex||"",a=t.offsetWidth,c=t.offsetHeight,l=this.calculateFocusDimensions(a,c,i),u=this.calculateFocusTransform(i,e);this.animationEngine.cancelAllAnimations(t);const h=this.config.animationDuration??600;this.applyFocusedStyling(t,Xt.FOCUSING);const d=n??{x:0,y:0,rotation:e.rotation,scale:1},g=s?.width??a,p=s?.height??c,b=this.animateWithDimensions(t,d,u,g,p,l.width,l.height,h),f={id:`focus-${Date.now()}`,element:t,animation:b,fromState:d,toState:u,startTime:performance.now(),duration:h};return this.focusData={element:t,originalState:e,focusTransform:u,originalZIndex:r,originalWidth:a,originalHeight:c,focusWidth:l.width,focusHeight:l.height},this.startClipPathAnimation(t,f,!0),{element:t,originalState:e,animationHandle:f,direction:"in",originalWidth:a,originalHeight:c}}startUnfocusAnimation(t,i,e,n){t.style.zIndex=String(Xt.UNFOCUSING),this.animationEngine.cancelAllAnimations(t);const s=this.config.animationDuration??600;t.classList.remove("fbn-ic-focused"),vt(t,this.focusedClassName);const r=e??this.focusData?.focusTransform??{x:0,y:0,rotation:0,scale:1},a=n?.width??this.focusData?.focusWidth??t.offsetWidth,c=n?.height??this.focusData?.focusHeight??t.offsetHeight,l={x:0,y:0,rotation:i.rotation,scale:1},u=this.focusData?.originalWidth??t.offsetWidth,h=this.focusData?.originalHeight??t.offsetHeight,d=this.animateWithDimensions(t,r,l,a,c,u,h,s),g={id:`unfocus-${Date.now()}`,element:t,animation:d,fromState:r,toState:l,startTime:performance.now(),duration:s};return this.startClipPathAnimation(t,g,!1),{element:t,originalState:i,animationHandle:g,direction:"out",originalWidth:u,originalHeight:h}}captureMidAnimationState(t){const i=getComputedStyle(t),e=new DOMMatrix(i.transform),n=t.offsetWidth,s=t.offsetHeight,r=e.e+n*.5,a=e.f+s*.5,c=Math.atan2(e.b,e.a)*(180/Math.PI);return t.style.width=`${n}px`,t.style.height=`${s}px`,t.style.transform=`translate(-50%, -50%) translate(${r}px, ${a}px) rotate(${c}deg)`,t.style.transition="none",{transform:{x:r,y:a,rotation:c,scale:1},dimensions:{width:n,height:s}}}async waitForAnimation(t){try{await t.animation.finished}catch{}}resetElementInstantly(t,i,e,n,s){this.animationEngine.cancelAllAnimations(t);const r=["translate(-50%, -50%)"];r.push("translate(0px, 0px)"),r.push(`rotate(${i.rotation}deg)`),t.style.transition="none",t.style.transform=r.join(" "),n!==void 0&&s!==void 0&&(t.style.width=`${n}px`,t.style.height=`${s}px`),this.removeFocusedStyling(t,e)}async focusImage(t,i,e){if(this.currentFocus===t&&this.state===x.FOCUSED)return this.unfocusImage();if(this.incoming?.element===t&&this.state===x.FOCUSING){const{transform:s,dimensions:r}=this.captureMidAnimationState(t);this.animationEngine.cancelAllAnimations(t),this.outgoing=this.startUnfocusAnimation(t,this.incoming.originalState,s,r),this.incoming=null,this.state=x.UNFOCUSING,await this.waitForAnimation(this.outgoing.animationHandle),this.removeFocusedStyling(this.outgoing.element,this.focusData?.originalZIndex||""),this.outgoing=null,this.currentFocus=null,this.focusData=null,this.state=x.IDLE;return}const n=++this.focusGeneration;switch(this.state){case x.IDLE:if(this.state=x.FOCUSING,this.incoming=this.startFocusAnimation(t,i,e),await this.waitForAnimation(this.incoming.animationHandle),this.focusGeneration!==n)return;this.currentFocus=t,this.incoming=null,this.state=x.FOCUSED;break;case x.FOCUSED:if(this.state=x.CROSS_ANIMATING,this.currentFocus&&this.focusData&&(this.outgoing=this.startUnfocusAnimation(this.currentFocus,this.focusData.originalState)),this.incoming=this.startFocusAnimation(t,i,e),await Promise.all([this.outgoing?this.waitForAnimation(this.outgoing.animationHandle):Promise.resolve(),this.waitForAnimation(this.incoming.animationHandle)]),this.focusGeneration!==n)return;if(this.outgoing){const s=this.outgoing.element;this.removeFocusedStyling(s,this.outgoing.originalState.zIndex?.toString()||""),this.outgoing=null,this.onUnfocusComplete?.(s)}this.currentFocus=t,this.incoming=null,this.state=x.FOCUSED;break;case x.FOCUSING:if(this.incoming&&(this.animationEngine.cancelAnimation(this.incoming.animationHandle,!1),this.resetElementInstantly(this.incoming.element,this.incoming.originalState,this.focusData?.originalZIndex||"",this.focusData?.originalWidth,this.focusData?.originalHeight),this.incoming=null),this.incoming=this.startFocusAnimation(t,i,e),await this.waitForAnimation(this.incoming.animationHandle),this.focusGeneration!==n)return;this.currentFocus=t,this.incoming=null,this.state=x.FOCUSED;break;case x.UNFOCUSING:if(this.state=x.CROSS_ANIMATING,this.incoming=this.startFocusAnimation(t,i,e),await Promise.all([this.outgoing?this.waitForAnimation(this.outgoing.animationHandle):Promise.resolve(),this.waitForAnimation(this.incoming.animationHandle)]),this.focusGeneration!==n)return;if(this.outgoing){const s=this.outgoing.element;this.removeFocusedStyling(s,this.outgoing.originalState.zIndex?.toString()||""),this.outgoing=null,this.onUnfocusComplete?.(s)}this.currentFocus=t,this.incoming=null,this.state=x.FOCUSED;break;case x.CROSS_ANIMATING:if(this.incoming?.element===t)return;if(this.outgoing?.element===t){const{transform:s,dimensions:r}=this.captureMidAnimationState(t);if(this.animationEngine.cancelAllAnimations(t),this.incoming){const{transform:a,dimensions:c}=this.captureMidAnimationState(this.incoming.element);this.animationEngine.cancelAllAnimations(this.incoming.element),this.outgoing=this.startUnfocusAnimation(this.incoming.element,this.incoming.originalState,a,c)}else this.outgoing=null;if(this.incoming=this.startFocusAnimation(t,i,e,s,r),await Promise.all([this.outgoing?this.waitForAnimation(this.outgoing.animationHandle):Promise.resolve(),this.waitForAnimation(this.incoming.animationHandle)]),this.focusGeneration!==n)return;if(this.outgoing){const a=this.outgoing.element;this.removeFocusedStyling(a,this.outgoing.originalState.zIndex?.toString()||""),this.outgoing=null,this.onUnfocusComplete?.(a)}this.currentFocus=t,this.incoming=null,this.state=x.FOCUSED;return}if(this.outgoing&&(this.animationEngine.cancelAnimation(this.outgoing.animationHandle,!1),this.resetElementInstantly(this.outgoing.element,this.outgoing.originalState,this.outgoing.originalState.zIndex?.toString()||"",this.outgoing.originalWidth,this.outgoing.originalHeight),this.outgoing=null),this.incoming){const{transform:s,dimensions:r}=this.captureMidAnimationState(this.incoming.element);this.animationEngine.cancelAllAnimations(this.incoming.element),this.outgoing=this.startUnfocusAnimation(this.incoming.element,this.incoming.originalState,s,r)}if(this.incoming=this.startFocusAnimation(t,i,e),await Promise.all([this.outgoing?this.waitForAnimation(this.outgoing.animationHandle):Promise.resolve(),this.waitForAnimation(this.incoming.animationHandle)]),this.focusGeneration!==n)return;if(this.outgoing){const s=this.outgoing.element;this.removeFocusedStyling(s,this.outgoing.originalState.zIndex?.toString()||""),this.outgoing=null,this.onUnfocusComplete?.(s)}this.currentFocus=t,this.incoming=null,this.state=x.FOCUSED;break}}async unfocusImage(){if(this.state===x.UNFOCUSING)return;const t=++this.focusGeneration;if(!this.currentFocus||!this.focusData){if(this.incoming&&this.state===x.FOCUSING){const{transform:s,dimensions:r}=this.captureMidAnimationState(this.incoming.element);if(this.animationEngine.cancelAllAnimations(this.incoming.element),this.outgoing=this.startUnfocusAnimation(this.incoming.element,this.incoming.originalState,s,r),this.incoming=null,this.state=x.UNFOCUSING,await this.waitForAnimation(this.outgoing.animationHandle),this.focusGeneration!==t)return;const a=this.outgoing.element;this.removeFocusedStyling(a,this.focusData?.originalZIndex||""),this.outgoing=null,this.focusData=null,this.state=x.IDLE,this.onUnfocusComplete?.(a)}return}if(this.state===x.CROSS_ANIMATING&&this.incoming){const{transform:s,dimensions:r}=this.captureMidAnimationState(this.incoming.element);this.animationEngine.cancelAllAnimations(this.incoming.element);const a=this.startUnfocusAnimation(this.incoming.element,this.incoming.originalState,s,r);if(await Promise.all([this.outgoing?this.waitForAnimation(this.outgoing.animationHandle):Promise.resolve(),this.waitForAnimation(a.animationHandle)]),this.focusGeneration!==t)return;let c=null;this.outgoing&&(c=this.outgoing.element,this.removeFocusedStyling(c,this.outgoing.originalState.zIndex?.toString()||""));const l=a.element;this.removeFocusedStyling(l,this.incoming.originalState.zIndex?.toString()||""),this.outgoing=null,this.incoming=null,this.currentFocus=null,this.focusData=null,this.state=x.IDLE,c&&this.onUnfocusComplete?.(c),this.onUnfocusComplete?.(l);return}this.state=x.UNFOCUSING;const i=this.currentFocus,e=this.focusData.originalState,n=this.focusData.originalZIndex;this.outgoing=this.startUnfocusAnimation(i,e),await this.waitForAnimation(this.outgoing.animationHandle),this.focusGeneration===t&&(this.removeFocusedStyling(i,n),this.outgoing=null,this.currentFocus=null,this.focusData=null,this.state=x.IDLE,this.onUnfocusComplete?.(i))}async swapFocus(t,i,e){return this.focusImage(t,i,e)}getCurrentFocus(){return this.currentFocus}isFocused(t){return this.currentFocus===t&&this.state===x.FOCUSED}isTargetingFocus(t){return this.incoming?.element===t}isInvolved(t){return this.currentFocus===t||this.incoming?.element===t||this.outgoing?.element===t}setDragOffset(t){if(!this.currentFocus||!this.focusData||this.state!==x.FOCUSED)return;const i=this.currentFocus,e=this.focusData.focusTransform,n=["translate(-50%, -50%)"],s=(e.x??0)+t,r=e.y??0;n.push(`translate(${s}px, ${r}px)`),e.rotation!==void 0&&n.push(`rotate(${e.rotation}deg)`),i.style.transition="none",i.style.transform=n.join(" ")}clearDragOffset(t,i=150){if(!this.currentFocus||!this.focusData||this.state!==x.FOCUSED)return;const e=this.currentFocus,n=this.focusData.focusTransform,s=["translate(-50%, -50%)"],r=n.x??0,a=n.y??0;s.push(`translate(${r}px, ${a}px)`),n.rotation!==void 0&&s.push(`rotate(${n.rotation}deg)`);const c=s.join(" ");t?(e.style.transition=`transform ${i}ms ease-out`,e.style.transform=c,setTimeout(()=>{this.currentFocus===e&&(e.style.transition="none")},i)):(e.style.transition="none",e.style.transform=c)}reset(){this.outgoing&&(this.animationEngine.cancelAnimation(this.outgoing.animationHandle,!1),this.resetElementInstantly(this.outgoing.element,this.outgoing.originalState,this.outgoing.originalState.zIndex?.toString()||"",this.outgoing.originalWidth,this.outgoing.originalHeight)),this.incoming&&(this.animationEngine.cancelAnimation(this.incoming.animationHandle,!1),this.resetElementInstantly(this.incoming.element,this.incoming.originalState,this.focusData?.originalZIndex||"",this.focusData?.originalWidth,this.focusData?.originalHeight)),this.currentFocus&&this.focusData&&this.resetElementInstantly(this.currentFocus,this.focusData.originalState,this.focusData.originalZIndex,this.focusData.originalWidth,this.focusData.originalHeight),this.state=x.IDLE,this.currentFocus=null,this.focusData=null,this.outgoing=null,this.incoming=null}}const Ge=50,qe=.5,Xe=20,Ye=.3,Je=150,Ve=30,rt=class rt{constructor(t,i){this.enabled=!1,this.touchState=null,this.recentTouchTimestamp=0,this.container=t,this.callbacks=i,this.boundTouchStart=this.handleTouchStart.bind(this),this.boundTouchMove=this.handleTouchMove.bind(this),this.boundTouchEnd=this.handleTouchEnd.bind(this),this.boundTouchCancel=this.handleTouchCancel.bind(this)}enable(){this.enabled||(this.enabled=!0,this.container.style.touchAction="pan-y",this.container.addEventListener("touchstart",this.boundTouchStart,{passive:!1}),this.container.addEventListener("touchmove",this.boundTouchMove,{passive:!1}),this.container.addEventListener("touchend",this.boundTouchEnd,{passive:!0}),this.container.addEventListener("touchcancel",this.boundTouchCancel,{passive:!0}))}disable(){this.enabled&&(this.enabled=!1,this.container.style.touchAction="",this.container.removeEventListener("touchstart",this.boundTouchStart),this.container.removeEventListener("touchmove",this.boundTouchMove),this.container.removeEventListener("touchend",this.boundTouchEnd),this.container.removeEventListener("touchcancel",this.boundTouchCancel),this.touchState?.isDragging&&this.callbacks.onDragEnd(!1),this.touchState=null)}destroy(){this.disable()}hadRecentTouch(){return Date.now()-this.recentTouchTimestamp<rt.TOUCH_CLICK_DELAY}handleTouchStart(t){if(t.touches.length!==1)return;this.recentTouchTimestamp=Date.now();const i=t.touches[0];this.touchState={startX:i.clientX,startY:i.clientY,startTime:performance.now(),currentX:i.clientX,isDragging:!1,isHorizontalSwipe:null}}handleTouchMove(t){if(!this.touchState||t.touches.length!==1)return;const i=t.touches[0],e=i.clientX-this.touchState.startX,n=i.clientY-this.touchState.startY;if(this.touchState.isHorizontalSwipe===null&&Math.sqrt(e*e+n*n)>10){const a=Math.atan2(Math.abs(n),Math.abs(e))*(180/Math.PI);this.touchState.isHorizontalSwipe=a<=Ve}if(this.touchState.isHorizontalSwipe!==!1&&this.touchState.isHorizontalSwipe===!0){t.preventDefault(),this.touchState.isDragging=!0,this.touchState.currentX=i.clientX;const s=e*Ye;this.callbacks.onDragOffset(s)}}handleTouchEnd(t){if(!this.touchState)return;this.recentTouchTimestamp=Date.now();const i=this.touchState.currentX-this.touchState.startX,e=performance.now()-this.touchState.startTime,n=Math.abs(i)/e,s=Math.abs(i);let r=!1;this.touchState.isHorizontalSwipe===!0&&this.touchState.isDragging&&(s>=Ge||n>=qe&&s>=Xe)&&(r=!0,i<0?this.callbacks.onNext():this.callbacks.onPrev()),this.touchState.isDragging&&this.callbacks.onDragEnd(r),this.touchState=null}handleTouchCancel(t){this.touchState?.isDragging&&this.callbacks.onDragEnd(!1),this.touchState=null}};rt.TOUCH_CLICK_DELAY=300;let Et=rt;class Jt{constructor(t){if(this._prepared=!1,this._discoveredUrls=[],this.apiKey=t.apiKey??"",this.apiEndpoint=t.apiEndpoint??"https://www.googleapis.com/drive/v3/files",this.debugLogging=t.debugLogging??!1,this.sources=t.sources??[],!this.sources||this.sources.length===0)throw new Error("GoogleDriveLoader requires at least one source to be configured")}async prepare(t){this._discoveredUrls=[];for(const i of this.sources)if("folders"in i)for(const e of i.folders){const n=i.recursive!==void 0?i.recursive:!0,s=await this.loadFromFolder(e,t,n);this._discoveredUrls.push(...s)}else if("files"in i){const e=await this.loadFiles(i.files,t);this._discoveredUrls.push(...e)}this._prepared=!0}imagesLength(){if(!this._prepared)throw new Error("GoogleDriveLoader.imagesLength() called before prepare()");return this._discoveredUrls.length}imageURLs(){if(!this._prepared)throw new Error("GoogleDriveLoader.imageURLs() called before prepare()");return[...this._discoveredUrls]}isPrepared(){return this._prepared}extractFolderId(t){const i=[/\/folders\/([a-zA-Z0-9_-]+)/,/id=([a-zA-Z0-9_-]+)/];for(const e of i){const n=t.match(e);if(n&&n[1])return n[1]}return null}async loadFromFolder(t,i,e=!0){const n=this.extractFolderId(t);if(!n)throw new Error("Invalid Google Drive folder URL. Please check the URL format.");if(!this.apiKey||this.apiKey==="YOUR_API_KEY_HERE")return this.loadImagesDirectly(n,i);try{return e?await this.loadImagesRecursively(n,i):await this.loadImagesFromSingleFolder(n,i)}catch(s){return console.error("Error loading from Google Drive API:",s),this.loadImagesDirectly(n,i)}}async loadImagesFromSingleFolder(t,i){const e=[],n=`'${t}' in parents and trashed=false`,r=`${this.apiEndpoint}?q=${encodeURIComponent(n)}&fields=files(id,name,mimeType,thumbnailLink)&key=${this.apiKey}`,a=await fetch(r);if(!a.ok)throw new Error(`API request failed: ${a.status} ${a.statusText}`);const l=(await a.json()).files.filter(u=>u.mimeType.startsWith("image/")&&i.isAllowed(u.name));return this.log(`Found ${l.length} images in folder ${t} (non-recursive)`),l.forEach(u=>{e.push(`https://lh3.googleusercontent.com/d/${u.id}=s1600`),this.log(`Added file: ${u.name}`)}),e}async loadFiles(t,i){const e=[];for(const n of t){const s=this.extractFileId(n);if(!s){this.log(`Skipping invalid file URL: ${n}`);continue}if(this.apiKey&&this.apiKey!=="YOUR_API_KEY_HERE")try{const r=`${this.apiEndpoint}/${s}?fields=name,mimeType&key=${this.apiKey}`,a=await fetch(r);if(a.ok){const c=await a.json();c.mimeType.startsWith("image/")&&i.isAllowed(c.name)?(e.push(`https://lh3.googleusercontent.com/d/${s}=s1600`),this.log(`Added file: ${c.name}`)):this.log(`Skipping non-image file: ${c.name} (${c.mimeType})`)}else this.log(`Failed to fetch metadata for file ${s}: ${a.status}`)}catch(r){this.log(`Error fetching metadata for file ${s}:`,r)}else e.push(`https://lh3.googleusercontent.com/d/${s}=s1600`)}return e}extractFileId(t){if(!/[/:.]/.test(t))return t;const i=[/\/file\/d\/([a-zA-Z0-9_-]+)/,/\/open\?id=([a-zA-Z0-9_-]+)/,/id=([a-zA-Z0-9_-]+)/];for(const e of i){const n=t.match(e);if(n&&n[1])return n[1]}return null}async loadImagesRecursively(t,i){const e=[],n=`'${t}' in parents and trashed=false`,r=`${this.apiEndpoint}?q=${encodeURIComponent(n)}&fields=files(id,name,mimeType,thumbnailLink)&key=${this.apiKey}`,a=await fetch(r);if(!a.ok)throw new Error(`API request failed: ${a.status} ${a.statusText}`);const c=await a.json(),l=c.files.filter(h=>h.mimeType.startsWith("image/")&&i.isAllowed(h.name)),u=c.files.filter(h=>h.mimeType==="application/vnd.google-apps.folder");this.log(`Found ${c.files.length} total items in folder ${t}`),c.files.forEach(h=>this.log(` - File: ${h.name} (${h.mimeType})`)),this.log(`- ${l.length} valid files (images only)`),this.log(`- ${u.length} subfolders`),l.forEach(h=>{e.push(`https://lh3.googleusercontent.com/d/${h.id}=s1600`),this.log(`Added file: ${h.name}`)});for(const h of u){this.log(`Loading images from subfolder: ${h.name}`);const d=await this.loadImagesRecursively(h.id,i);e.push(...d)}return e}async loadImagesDirectly(t,i){try{const e=`https://drive.google.com/embeddedfolderview?id=${t}`,n=await fetch(e,{mode:"cors"});if(!n.ok)throw new Error("Cannot access folder directly (CORS or permissions issue)");const s=await n.text(),r=/\/file\/d\/([a-zA-Z0-9_-]+)/g,a=[...s.matchAll(r)];return[...new Set(a.map(u=>u[1]))].map(u=>`https://drive.google.com/uc?export=view&id=${u}`)}catch(e){throw console.error("Direct loading failed:",e),new Error(`Unable to load images. Please ensure:
1
+ (function(T,J){typeof exports=="object"&&typeof module<"u"?J(exports):typeof define=="function"&&define.amd?define(["exports"],J):(T=typeof globalThis<"u"?globalThis:T||self,J(T.ImageCloud={}))})(this,(function(T){"use strict";const J=Object.freeze({none:"none",sm:"0 2px 4px rgba(0,0,0,0.1)",md:"0 4px 16px rgba(0,0,0,0.4)",lg:"0 8px 32px rgba(0,0,0,0.5)",glow:"0 0 30px rgba(255,255,255,0.6)"}),ht=Object.freeze({energetic:Object.freeze({overshoot:.25,bounces:2,decayRatio:.5}),playful:Object.freeze({overshoot:.15,bounces:1,decayRatio:.5}),subtle:Object.freeze({overshoot:.08,bounces:1,decayRatio:.5})}),dt=Object.freeze({gentle:Object.freeze({stiffness:150,damping:30,mass:1,oscillations:2}),bouncy:Object.freeze({stiffness:300,damping:15,mass:1,oscillations:4}),wobbly:Object.freeze({stiffness:180,damping:12,mass:1.5,oscillations:5}),snappy:Object.freeze({stiffness:400,damping:25,mass:.8,oscillations:2})}),ut=Object.freeze({gentle:Object.freeze({amplitude:30,frequency:1.5,decay:!0,decayRate:.9,phase:0}),playful:Object.freeze({amplitude:50,frequency:2.5,decay:!0,decayRate:.7,phase:0}),serpentine:Object.freeze({amplitude:60,frequency:3,decay:!1,decayRate:1,phase:0}),flutter:Object.freeze({amplitude:20,frequency:4,decay:!0,decayRate:.5,phase:0})}),ft=Object.freeze({type:"linear"}),gt=Object.freeze({mode:"none"}),mt=Object.freeze({mode:"none"}),At=Object.freeze({default:Object.freeze({border:Object.freeze({width:0,color:"#000000",radius:0,style:"solid"}),shadow:"none",clipPath:void 0,filter:Object.freeze({}),opacity:1,cursor:"pointer",outline:Object.freeze({width:0,color:"#000000",style:"solid",offset:0})}),hover:Object.freeze({shadow:"none"}),focused:Object.freeze({shadow:"none"})}),ne=Object.freeze({tightness:1}),oe=Object.freeze({rows:1,amplitude:100,frequency:2,phaseShift:0,synchronization:"offset"}),se=Object.freeze({spacing:0}),ae=Object.freeze({mobile:Object.freeze({maxWidth:767}),tablet:Object.freeze({maxWidth:1199})}),re=Object.freeze({mode:"adaptive",minSize:50,maxSize:400,variance:Object.freeze({min:1,max:1})}),ce=Object.freeze({mode:"none",range:Object.freeze({min:-15,max:15})}),Lt=Object.freeze({sizing:re,rotation:ce}),pt=Object.freeze({validateUrls:!0,validationTimeout:5e3,validationMethod:"head",allowedExtensions:["jpg","jpeg","png","gif","webp","bmp"]}),Ft=Object.freeze({enabled:!1,centers:!1,loaders:!1}),le=Object.freeze({maxAngle:5,speed:2e3,sync:"random"}),he=Object.freeze({minScale:.95,maxScale:1.05,speed:2400,sync:"random"}),de=Object.freeze({onRatio:.7,speed:3e3,style:"snap"}),ue=Object.freeze({speed:4e3,direction:"clockwise"}),Mt=Object.freeze({type:"none"}),R=Object.freeze({loaders:[],config:Object.freeze({loaders:pt,debug:Ft}),image:Lt,layout:Object.freeze({algorithm:"radial",scaleDecay:0,responsive:ae,targetCoverage:.6,densityFactor:1,spacing:Object.freeze({padding:50})}),animation:Object.freeze({duration:600,easing:Object.freeze({default:"cubic-bezier(0.4, 0.0, 0.2, 1)",bounce:"cubic-bezier(0.68, -0.55, 0.265, 1.55)",focus:"cubic-bezier(0.4, 0.0, 0.2, 1)"}),queue:Object.freeze({enabled:!0,interval:150}),entry:Object.freeze({start:Object.freeze({position:"nearest-edge",offset:100,circular:Object.freeze({radius:"120%",distribution:"even"})}),timing:Object.freeze({duration:600}),easing:"cubic-bezier(0.25, 1, 0.5, 1)",path:ft,rotation:gt,scale:mt}),idle:Mt}),interaction:Object.freeze({focus:Object.freeze({scalePercent:.8,zIndex:1e3,animationDuration:void 0}),navigation:Object.freeze({keyboard:!0,swipe:!0}),dragging:!0}),ui:Object.freeze({showLoadingSpinner:!1,showImageCounter:!1,showNavButtons:!1,showFocusOutline:!1}),styling:At});function tt(o,t){if(!o)return t||{};if(!t)return{...o};const i={...o};return t.border!==void 0&&(i.border={...o.border,...t.border}),t.borderTop!==void 0&&(i.borderTop={...o.borderTop,...t.borderTop}),t.borderRight!==void 0&&(i.borderRight={...o.borderRight,...t.borderRight}),t.borderBottom!==void 0&&(i.borderBottom={...o.borderBottom,...t.borderBottom}),t.borderLeft!==void 0&&(i.borderLeft={...o.borderLeft,...t.borderLeft}),t.filter!==void 0&&(i.filter={...o.filter,...t.filter}),t.outline!==void 0&&(i.outline={...o.outline,...t.outline}),t.shadow!==void 0&&(i.shadow=t.shadow),t.clipPath!==void 0&&(i.clipPath=t.clipPath),t.opacity!==void 0&&(i.opacity=t.opacity),t.cursor!==void 0&&(i.cursor=t.cursor),t.className!==void 0&&(i.className=t.className),t.objectFit!==void 0&&(i.objectFit=t.objectFit),t.aspectRatio!==void 0&&(i.aspectRatio=t.aspectRatio),t.borderRadiusTopLeft!==void 0&&(i.borderRadiusTopLeft=t.borderRadiusTopLeft),t.borderRadiusTopRight!==void 0&&(i.borderRadiusTopRight=t.borderRadiusTopRight),t.borderRadiusBottomRight!==void 0&&(i.borderRadiusBottomRight=t.borderRadiusBottomRight),t.borderRadiusBottomLeft!==void 0&&(i.borderRadiusBottomLeft=t.borderRadiusBottomLeft),i}function fe(o,t){if(!t)return{...o};const i=tt(o.default,t.default),e=tt(tt(i,o.hover),t.hover),n=tt(tt(i,o.focused),t.focused);return{default:i,hover:e,focused:n}}function ge(o,t){if(!t)return{...o};const i={...o};if(t.sizing!==void 0&&(i.sizing={...o.sizing,...t.sizing},t.sizing.variance)){const e=t.sizing.variance,n=e.min!==void 0&&e.min>=.25&&e.min<=1?e.min:o.sizing?.variance?.min??1,s=e.max!==void 0&&e.max>=1&&e.max<=1.75?e.max:o.sizing?.variance?.max??1;i.sizing.variance={min:n,max:s}}if(t.rotation!==void 0&&(i.rotation={...o.rotation,...t.rotation},t.rotation.range)){const e=t.rotation.range,n=e.min!==void 0&&e.min>=-180&&e.min<=0?e.min:o.rotation?.range?.min??-15,s=e.max!==void 0&&e.max>=0&&e.max<=180?e.max:o.rotation?.range?.max??15;i.rotation.range={min:n,max:s}}return i}function me(o={}){const t=o.image,i=[...o.loaders??[]];o.images&&o.images.length>0&&i.unshift({static:{sources:[{urls:o.images}]}});const n={loaders:{...pt,...o.config?.loaders??{}}},s={loaders:i,config:n,image:ge(Lt,t),layout:{...R.layout},animation:{...R.animation},interaction:{...R.interaction},ui:{...R.ui},styling:fe(At,o.styling)};if(o.layout&&(s.layout={...R.layout,...o.layout},o.layout.responsive&&(s.layout.responsive={...R.layout.responsive,mobile:o.layout.responsive.mobile?{...R.layout.responsive.mobile,...o.layout.responsive.mobile}:R.layout.responsive.mobile,tablet:o.layout.responsive.tablet?{...R.layout.responsive.tablet,...o.layout.responsive.tablet}:R.layout.responsive.tablet}),o.layout.spacing&&(s.layout.spacing={...R.layout.spacing,...o.layout.spacing})),o.animation&&(s.animation={...R.animation,...o.animation},o.animation.easing&&(s.animation.easing={...R.animation.easing,...o.animation.easing}),o.animation.queue&&(s.animation.queue={...R.animation.queue,...o.animation.queue}),o.animation.entry&&(s.animation.entry={...R.animation.entry,...o.animation.entry,start:o.animation.entry.start?{...R.animation.entry.start,...o.animation.entry.start,circular:o.animation.entry.start.circular?{...R.animation.entry.start.circular,...o.animation.entry.start.circular}:R.animation.entry.start.circular}:R.animation.entry.start,timing:o.animation.entry.timing?{...R.animation.entry.timing,...o.animation.entry.timing}:R.animation.entry.timing,path:o.animation.entry.path?{...ft,...o.animation.entry.path}:R.animation.entry.path,rotation:o.animation.entry.rotation?{...gt,...o.animation.entry.rotation}:R.animation.entry.rotation,scale:o.animation.entry.scale?{...mt,...o.animation.entry.scale}:R.animation.entry.scale}),o.animation.idle&&(s.animation.idle={...Mt,...o.animation.idle})),o.interaction&&(s.interaction={...R.interaction,...o.interaction},o.interaction.focus&&(s.interaction.focus={...R.interaction.focus,...o.interaction.focus}),o.interaction.navigation&&(s.interaction.navigation={...R.interaction.navigation,...o.interaction.navigation})),s.ui={...R.ui,...o.ui},s.config.debug={...Ft,...o.config?.debug??{}},s.layout.algorithm==="honeycomb"&&s.styling){const r={shape:"hexagon",mode:"height-relative"};s.styling={...s.styling,default:{...s.styling.default,clipPath:r},hover:{...s.styling.hover,clipPath:r}}}return s}function pe(o,t){return{...o?ht[o]:ht.playful,...t}}function be(o,t){return{...o?dt[o]:dt.gentle,...t}}function ye(o,t){return{...o?ut[o]:ut.gentle,...t}}class Ot{constructor(t){this.activeAnimations=new Map,this.animationIdCounter=0,this.config=t}buildTransformString(t){const i=["translate(-50%, -50%)"];if(t.x!==void 0||t.y!==void 0){const e=t.x??0,n=t.y??0;i.push(`translate(${e}px, ${n}px)`)}return t.rotation!==void 0&&i.push(`rotate(${t.rotation}deg)`),t.scale!==void 0&&i.push(`scale(${t.scale})`),i.join(" ")}animateTransformCancellable(t,i,e,n=null,s=null){this.cancelAllAnimations(t);const r=n??this.config.duration,a=s??this.config.easing.default,c=this.buildTransformString(i),d=this.buildTransformString(e);t.style.transition="none";const u=t.animate([{transform:c},{transform:d}],{duration:r,easing:a,fill:"forwards"}),f={id:`anim-${++this.animationIdCounter}`,element:t,animation:u,fromState:i,toState:e,startTime:performance.now(),duration:r};return this.activeAnimations.set(t,f),u.finished.then(()=>{t.style.transform=d,this.activeAnimations.delete(t)}).catch(()=>{this.activeAnimations.delete(t)}),f}cancelAnimation(t,i=!0){const e=this.getCurrentTransform(t.element);if(t.animation.cancel(),i){const n=this.buildTransformString({x:e.x,y:e.y,rotation:e.rotation,scale:e.scale});t.element.style.transform=n}return this.activeAnimations.delete(t.element),e}cancelAllAnimations(t){const i=this.activeAnimations.get(t);i&&this.cancelAnimation(i,!1);const e=t.getAnimations();for(const n of e)n.cancel()}getCurrentTransform(t){const e=getComputedStyle(t).transform;if(e==="none"||!e)return{x:0,y:0,rotation:0,scale:1};const n=new DOMMatrix(e),s=Math.sqrt(n.a*n.a+n.b*n.b),r=Math.atan2(n.b,n.a)*(180/Math.PI),a=n.e,c=n.f;return{x:a,y:c,rotation:r,scale:s}}hasActiveAnimation(t){return this.activeAnimations.has(t)}getAnimationHandle(t){return this.activeAnimations.get(t)}animateTransform(t,i,e=null,n=null){return new Promise(s=>{const r=e??this.config.duration,a=n??this.config.easing.default;t.style.transition=`transform ${r}ms ${a}, box-shadow ${r}ms ${a}`,t.style.transform=this.buildTransformString(i),setTimeout(()=>{s()},r)})}resetTransform(t,i){return this.animateTransform(t,i)}clearTransition(t){t.style.transition=""}wait(t){return new Promise(i=>setTimeout(i,t))}}function K(o,t,i){return o+(t-o)*i}function ve(o,t,i,e){const{overshoot:n,bounces:s,decayRatio:r}=e,a=i.x-t.x,c=i.y-t.y,d=Ee(s,r);let u=0,f=0,m=1,p=n,x=!1;for(let l=0;l<d.length;l++)if(o<=d[l].time){f=l===0?0:d[l-1].time,m=d[l].time,p=d[l].overshoot,x=d[l].isOvershoot;break}const v=(o-f)/(m-f);if(x)u=1+p*st(v);else if(f===0)u=st(v);else{const g=1+(d.find((h,b)=>h.time>f&&b>0&&d[b-1].isOvershoot)?.overshoot||p);u=K(g,1,st(v))}return{x:t.x+a*u,y:t.y+c*u}}function Ee(o,t){const i=[];let e=.6;i.push({time:e,overshoot:0,isOvershoot:!1});let n=.15;const r=.4/(o*2);for(let a=0;a<o;a++)e+=r,i.push({time:e,overshoot:n,isOvershoot:!0}),e+=r,i.push({time:e,overshoot:n*t,isOvershoot:!1}),n*=t;return i.push({time:1,overshoot:0,isOvershoot:!1}),i}function we(o,t,i,e){const{stiffness:n,damping:s,mass:r,oscillations:a}=e,c=i.x-t.x,d=i.y-t.y,u=Math.sqrt(n/r),f=s/(2*Math.sqrt(n*r));let m;if(f<1){const p=u*Math.sqrt(1-f*f),x=Math.exp(-f*u*o*3),v=Math.cos(p*o*a*Math.PI);m=1-x*v}else m=1-Math.exp(-u*o*3);return m=Math.max(0,Math.min(m,1.3)),{x:t.x+c*m,y:t.y+d*m}}function xe(o,t,i,e){const{amplitude:n,frequency:s,decay:r,decayRate:a,phase:c}=e,d=i.x-t.x,u=i.y-t.y,f=Math.sqrt(d*d+u*u),m=f>0?-u/f:0,p=f>0?d/f:1,x=s*Math.PI*2*o+c,v=r?Math.pow(1-o,a):1,l=n*Math.sin(x)*v,g=Ie(o);return{x:K(t.x,i.x,g)+l*m,y:K(t.y,i.y,g)+l*p}}function st(o){return 1-(1-o)*(1-o)}function Ie(o){return 1-Math.pow(1-o,3)}function Se(o,t,i){const{amplitude:e,frequency:n,decay:s}=i,r=Math.sin(o*n*Math.PI*2),a=s?Math.pow(1-o,2):1,c=e*r*a;return t+c}function Ce(o,t,i){const{overshoot:e,bounces:n}=i,s=[];s.push({time:.5,scale:e});let r=e;const a=.5,d=.5/(n*2);let u=.5;for(let m=0;m<n;m++){const p=1-(r-1)*a;u+=d,s.push({time:u,scale:p}),r=1+(r-1)*a*a,u+=d,m<n-1&&s.push({time:u,scale:r})}s.push({time:1,scale:1});let f=1;for(let m=0;m<s.length;m++)if(o<=s[m].time){const p=m===0?0:s[m-1].time,x=m===0?1:s[m-1].scale,v=(o-p)/(s[m].time-p),l=st(v);f=x+(s[m].scale-x)*l;break}return f*t}function zt(o){const{element:t,startPosition:i,endPosition:e,pathConfig:n,duration:s,imageWidth:r,imageHeight:a,rotation:c,scale:d,onComplete:u,onProgress:f,rotationConfig:m,startRotation:p,scaleConfig:x,startScale:v}=o,l=n.type,g=p!==void 0&&p!==c,h=m?.mode==="wobble",b=m?.wobble||{amplitude:15,frequency:3,decay:!0},I=g||h,y=v!==void 0&&v!==d,E=x?.mode==="pop",w=x?.pop||{overshoot:1.2,bounces:1};if(l==="linear"&&!I&&!(y||E)){u&&u();return}const A=performance.now(),O=-r/2,L=-a/2;function D(H){const P=H-A,z=Math.min(P/s,1);let C;switch(l){case"bounce":{const B=pe(n.bouncePreset,n.bounce);C=ve(z,i,e,B);break}case"elastic":{const B=be(n.elasticPreset,n.elastic);C=we(z,i,e,B);break}case"wave":{const B=ye(n.wavePreset,n.wave);C=xe(z,i,e,B);break}default:C={x:K(i.x,e.x,z),y:K(i.y,e.y,z)}}const U=C.x-e.x,$=C.y-e.y;let F;h?F=Se(z,c,b):g?F=K(p,c,z):F=c;let W;E?W=Ce(z,d,w):y?W=K(v,d,z):W=d,t.style.transform=`translate(${O}px, ${L}px) translate(${U}px, ${$}px) rotate(${F}deg) scale(${W})`,f&&z<1&&f(z,P,{x:C.x,y:C.y,rotation:F,scale:W}),z<1?requestAnimationFrame(D):(t.style.transform=`translate(${O}px, ${L}px) rotate(${c}deg) scale(${d})`,u&&u())}requestAnimationFrame(D)}function Dt(o){return o==="bounce"||o==="elastic"||o==="wave"}const Te={radial:"center",spiral:"center",grid:"top",cluster:"nearest-edge",random:"nearest-edge",wave:"left",honeycomb:"center"};class Pt{constructor(t,i){this.config=t,this.layoutAlgorithm=i,this.resolvedStartPosition=this.resolveStartPosition(),this.pathConfig=t.path||ft,this.rotationConfig=t.rotation||gt,this.scaleConfig=t.scale||mt}resolveStartPosition(){return this.config.start.position?this.config.start.position:Te[this.layoutAlgorithm]||"nearest-edge"}calculateStartPosition(t,i,e,n,s){const r=this.resolvedStartPosition,a=this.config.start.offset??100;switch(r){case"nearest-edge":return this.calculateNearestEdge(t,i,e,a);case"top":return this.calculateEdgePosition("top",t,i,e,a);case"bottom":return this.calculateEdgePosition("bottom",t,i,e,a);case"left":return this.calculateEdgePosition("left",t,i,e,a);case"right":return this.calculateEdgePosition("right",t,i,e,a);case"center":return this.calculateCenterPosition(e,t,i);case"random-edge":return this.calculateRandomEdge(t,i,e,a);case"circular":return this.calculateCircularPosition(t,i,e,n,s);default:return this.calculateNearestEdge(t,i,e,a)}}calculateNearestEdge(t,i,e,n){const s=t.x,r=t.y,a=s,c=e.width-s,d=r,u=e.height-r,f=Math.min(a,c,d,u);let m=t.x,p=t.y;return f===a?m=-(i.width+n):f===c?m=e.width+n:f===d?p=-(i.height+n):p=e.height+n,{x:m,y:p}}calculateEdgePosition(t,i,e,n,s){let r=i.x,a=i.y;switch(t){case"top":a=-(e.height+s);break;case"bottom":a=n.height+s;break;case"left":r=-(e.width+s);break;case"right":r=n.width+s;break}return{x:r,y:a}}calculateCenterPosition(t,i,e){const n=t.width/2,s=t.height/2;return{x:n,y:s,useScale:!0}}calculateRandomEdge(t,i,e,n){const s=["top","bottom","left","right"],r=s[Math.floor(Math.random()*s.length)];return this.calculateEdgePosition(r,t,i,e,n)}calculateCircularPosition(t,i,e,n,s){const r=this.config.start.circular||{},a=r.distribution||"even";let c;const d=r.radius||"120%";if(typeof d=="string"&&d.endsWith("%")){const v=parseFloat(d)/100;c=Math.sqrt(e.width**2+e.height**2)*v/2}else c=typeof d=="number"?d:500;let u;a==="even"?u=n/s*2*Math.PI:u=Math.random()*2*Math.PI;const f=e.width/2,m=e.height/2,p=f+Math.cos(u)*c,x=m+Math.sin(u)*c;return{x:p,y:x}}getAnimationParams(t){const i=this.config.timing.duration,e=this.config.easing;return{startTransform:"",duration:i,delay:0,easing:e}}buildStartTransform(t,i,e,n,s,r,a,c){const d=t.x-i.x,u=t.y-i.y,f=a!==void 0?a:e,m=c!==void 0?c:n,p=s!==void 0?-s/2:0,x=r!==void 0?-r/2:0,v=s!==void 0?`translate(${p}px, ${x}px)`:"translate(-50%, -50%)";return t.useScale?`${v} translate(${d}px, ${u}px) rotate(${f}deg) scale(0)`:`${v} translate(${d}px, ${u}px) rotate(${f}deg) scale(${m})`}buildFinalTransform(t,i,e,n){if(e!==void 0&&n!==void 0){const s=-e/2,r=-n/2;return`translate(${s}px, ${r}px) rotate(${t}deg) scale(${i})`}return`translate(-50%, -50%) rotate(${t}deg) scale(${i})`}getTransitionCSS(){const t=this.config.timing.duration,i=this.config.easing;return this.requiresJSAnimation()?`opacity ${t}ms ease-out`:`opacity ${t}ms ease-out, transform ${t}ms ${i}`}requiresJSAnimation(){return Dt(this.pathConfig.type)}getPathConfig(){return this.pathConfig}getPathType(){return this.pathConfig.type}getTiming(){return{duration:this.config.timing.duration}}getRotationConfig(){return this.rotationConfig}getRotationMode(){return this.rotationConfig.mode}calculateStartRotation(t){switch(this.rotationConfig.mode){case"none":return t;case"settle":{const e=this.rotationConfig.startRotation;if(e===void 0)return t+(Math.random()-.5)*60;if(typeof e=="number")return e;const n=e.max-e.min;return e.min+Math.random()*n}case"spin":{const e=this.rotationConfig.spinCount??1,n=this.resolveSpinDirection(t);return t+e*360*n}case"random":return t+(Math.random()-.5)*60;case"wobble":return t;default:return t}}resolveSpinDirection(t){switch(this.rotationConfig.direction??"auto"){case"clockwise":return-1;case"counterclockwise":return 1;case"random":return Math.random()<.5?1:-1;default:return t>=0?1:-1}}requiresJSRotation(){return this.rotationConfig.mode==="wobble"}calculateWobbleRotation(t,i){if(this.rotationConfig.mode!=="wobble")return i;const e=this.rotationConfig.wobble||{amplitude:15,frequency:3,decay:!0},{amplitude:n,frequency:s,decay:r}=e,a=Math.sin(t*s*Math.PI*2),c=r?Math.pow(1-t,2):1,d=n*a*c;return i+d}getScaleConfig(){return this.scaleConfig}getScaleMode(){return this.scaleConfig.mode}calculateStartScale(t){switch(this.scaleConfig.mode){case"none":return t;case"grow":return(this.scaleConfig.startScale??.3)*t;case"shrink":return(this.scaleConfig.startScale??1.5)*t;case"pop":return t;case"random":{const e=this.scaleConfig.range??{min:.5,max:1};return(e.min+Math.random()*(e.max-e.min))*t}default:return t}}requiresJSScale(){return this.scaleConfig.mode==="pop"}calculatePopScale(t,i){if(this.scaleConfig.mode!=="pop")return i;const e=this.scaleConfig.pop||{overshoot:1.2,bounces:1},{overshoot:n,bounces:s}=e,r=this.generateScaleBounceKeyframes(s,n);let a=i;for(let c=0;c<r.length;c++)if(t<=r[c].time){const d=c===0?0:r[c-1].time,u=c===0?i:r[c-1].scale,f=(t-d)/(r[c].time-d),m=this.easeOutQuad(f);a=u+(r[c].scale-u)*m;break}return a*i}generateScaleBounceKeyframes(t,i){const e=[];e.push({time:.5,scale:i});let n=i;const s=.5,a=.5/(t*2);let c=.5;for(let d=0;d<t;d++){const u=1-(n-1)*s;c+=a,e.push({time:c,scale:u}),n=1+(n-1)*s*s,c+=a,d<t-1&&e.push({time:c,scale:n})}return e.push({time:1,scale:1}),e}easeOutQuad(t){return 1-(1-t)*(1-t)}}class Re{constructor(t,i=600){this.entries=new Map,this.togetherRafId=null,this.togetherSpeed=0,this.config=t,this.entryDurationMs=i}register(t,i,e,n){if(this.entries.has(t))return;const s=n??this.entryDurationMs,r=this.config.startDelay??s,a={element:t,index:i,totalImages:e,animation:null,blinkAnimation:null,customTeardown:null,paused:!1,stopped:!1,startTimer:null};this.entries.set(t,a),a.startTimer=setTimeout(()=>{a.startTimer=null,!a.stopped&&!a.paused&&this._startAnimation(a)},r)}pauseForImage(t){const i=this.entries.get(t);i&&(i.paused=!0,i.startTimer!==null&&(clearTimeout(i.startTimer),i.startTimer=null),this._pauseEntry(i))}resumeForImage(t){const i=this.entries.get(t);!i||i.stopped||(i.paused=!1,this._startAnimation(i))}stopForImage(t){const i=this.entries.get(t);i&&(i.stopped=!0,i.startTimer!==null&&(clearTimeout(i.startTimer),i.startTimer=null),this._cancelEntry(i),this.entries.delete(t))}pauseAll(){for(const t of this.entries.values())t.paused=!0,t.startTimer!==null&&(clearTimeout(t.startTimer),t.startTimer=null),this._pauseEntry(t)}resumeAll(){for(const t of this.entries.values())t.stopped||(t.paused=!1,this._startAnimation(t))}stopAll(){for(const t of this.entries.values())t.stopped=!0,t.startTimer!==null&&(clearTimeout(t.startTimer),t.startTimer=null),this._cancelEntry(t);this.entries.clear(),this._stopTogetherLoop()}_startAnimation(t){const{type:i}=this.config;switch(i){case"wiggle":this._startWiggle(t);break;case"pulse":this._startPulse(t);break;case"blink":this._startBlink(t);break;case"spin":this._startSpin(t);break;case"custom":this._startCustom(t);break}}_startWiggle(t){const i={...le,...this.config.wiggle},e=[{transform:"rotate(0deg)",offset:0},{transform:`rotate(${i.maxAngle}deg)`,offset:.25},{transform:"rotate(0deg)",offset:.5},{transform:`rotate(${-i.maxAngle}deg)`,offset:.75},{transform:"rotate(0deg)",offset:1}];i.sync==="together"?(t.animation=t.element.animate(e,{duration:i.speed,iterations:1/0,composite:"add",fill:"both"}),t.animation.pause(),this._startTogetherLoop(i.speed)):t.animation=t.element.animate(e,{duration:i.speed,delay:-(Math.random()*i.speed),iterations:1/0,composite:"add"})}_startPulse(t){const i={...he,...this.config.pulse},e=[{transform:"scale(1)",offset:0},{transform:`scale(${i.maxScale})`,offset:.25},{transform:"scale(1)",offset:.5},{transform:`scale(${i.minScale})`,offset:.75},{transform:"scale(1)",offset:1}];i.sync==="together"?(t.animation=t.element.animate(e,{duration:i.speed,iterations:1/0,composite:"add",fill:"both"}),t.animation.pause(),this._startTogetherLoop(i.speed)):t.animation=t.element.animate(e,{duration:i.speed,delay:-(Math.random()*i.speed),iterations:1/0,composite:"add"})}_startBlink(t){const i={...de,...this.config.blink},e=-(Math.random()*i.speed),n=parseFloat(getComputedStyle(t.element).opacity)||1;let s,r;i.style==="fade"?(s=[{opacity:n,offset:0},{opacity:0,offset:.5},{opacity:n,offset:1}],r={duration:i.speed,delay:e,iterations:1/0,easing:"ease-in-out"}):(s=[{opacity:n,offset:0},{opacity:n,offset:i.onRatio},{opacity:0,offset:Math.min(i.onRatio+.01,.99)},{opacity:0,offset:.99},{opacity:n,offset:1}],r={duration:i.speed,delay:e,iterations:1/0}),t.blinkAnimation=t.element.animate(s,r)}_startSpin(t){const i={...ue,...this.config.spin},e=i.direction==="clockwise"?360:-360;t.animation=t.element.animate([{transform:"rotate(0deg)"},{transform:`rotate(${e}deg)`}],{duration:i.speed,iterations:1/0,easing:"linear",composite:"add"})}_startCustom(t){const i=this.config.custom;if(!i)return;const e=i({element:t.element,index:t.index,totalImages:t.totalImages});typeof e=="function"?t.customTeardown=e:e&&typeof e.play=="function"&&(t.animation=e)}_startTogetherLoop(t){if(this.togetherSpeed=t,this.togetherRafId!==null)return;const i=()=>{const e=performance.now()%this.togetherSpeed;for(const n of this.entries.values())!n.stopped&&!n.paused&&n.animation&&(n.animation.currentTime=e);this.togetherRafId=requestAnimationFrame(i)};this.togetherRafId=requestAnimationFrame(i)}_stopTogetherLoop(){this.togetherRafId!==null&&(cancelAnimationFrame(this.togetherRafId),this.togetherRafId=null)}_pauseEntry(t){t.animation&&(t.animation.cancel(),t.animation=null),t.blinkAnimation&&(t.blinkAnimation.cancel(),t.blinkAnimation=null)}_cancelEntry(t){t.animation&&(t.animation.cancel(),t.animation=null),t.blinkAnimation&&(t.blinkAnimation.cancel(),t.blinkAnimation=null),t.customTeardown&&(t.customTeardown(),t.customTeardown=null)}}class $t{constructor(t,i={}){this.config=t,this.imageConfig=i}generate(t,i,e={}){const n=[],{width:s,height:r}=i,a=this.config.spacing.padding,c=e.fixedHeight??200,d=this.imageConfig.rotation?.mode??"none",u=this.imageConfig.rotation?.range?.min??-15,f=this.imageConfig.rotation?.range?.max??15,m=this.imageConfig.sizing?.variance?.min??1,p=this.imageConfig.sizing?.variance?.max??1,x=m!==1||p!==1,l=c*1.5/2,g=c/2,h=s-a-l,b=r-a-g,I=a+l,y=a+g;for(let E=0;E<t;E++){const w=this.random(I,h),M=this.random(y,b),A=d==="random"?this.random(u,f):0,O=x?this.random(m,p):1,L=c*O,D={id:E,x:w,y:M,rotation:A,scale:O,baseSize:L};n.push(D)}return n}random(t,i){return Math.random()*(i-t)+t}}class _t{constructor(t,i={}){this.config=t,this.imageConfig=i}generate(t,i,e={}){const n=[],{width:s,height:r}=i,a=e.fixedHeight??200,c=this.imageConfig.rotation?.mode??"none",d=this.imageConfig.rotation?.range?.min??-15,u=this.imageConfig.rotation?.range?.max??15,f=this.imageConfig.sizing?.variance?.min??1,m=this.imageConfig.sizing?.variance?.max??1,p=f!==1||m!==1,x=this.config.scaleDecay??0,v={...ne,...this.config.radial},l=e.fixedHeight??a,g=s/2,h=r/2,b=Math.ceil(Math.sqrt(t)),I=this.config.spacing.padding??50,y=Math.max(l*.8,Math.min(g-I-l/2,h-I-l/2));if(t>0){const M=p?this.random(f,m):1,A=l*M;n.push({id:0,x:g,y:h,rotation:c==="random"?this.random(d*.33,u*.33):0,scale:M,baseSize:A,zIndex:100})}let E=1,w=1;for(;E<t;){const M=w/b,A=x>0?1-M*x*.5:1,O=Math.max(l*.8,y/b*1.5/v.tightness),L=w*O,D=L*1.5,H=Math.PI*(3*(D+L)-Math.sqrt((3*D+L)*(D+3*L))),P=this.estimateWidth(l),z=Math.floor(H/(P*.7));if(z===0){w++;continue}const C=2*Math.PI/z,U=w*(20*Math.PI/180);for(let $=0;$<z&&E<t;$++){const F=$*C+U,W=p?this.random(f,m):1,B=A*W,_=l*B;let N=g+Math.cos(F)*D,k=h+Math.sin(F)*L;const j=_*1.5/2,G=_/2;N-j<I?N=I+j:N+j>s-I&&(N=s-I-j),k-G<I?k=I+G:k+G>r-I&&(k=r-I-G);const V=c==="random"?this.random(d,u):0;n.push({id:E,x:N,y:k,rotation:V,scale:B,baseSize:_,zIndex:Math.max(1,100-w)}),E++}w++}return n}estimateWidth(t){return t*1.4}random(t,i){return Math.random()*(i-t)+t}}const Ae={columns:"auto",rows:"auto",stagger:"none",jitter:0,overlap:0,fillDirection:"row",alignment:"center",gap:10,overflowOffset:.25},Ut=[{x:1,y:1},{x:-1,y:-1},{x:1,y:-1},{x:-1,y:1},{x:-1,y:0},{x:1,y:0},{x:0,y:-1},{x:0,y:1}];class kt{constructor(t,i={}){this.config=t,this.imageConfig=i}generate(t,i,e={}){const n=[],{width:s,height:r}=i,a={...Ae,...this.config.grid},c=this.config.spacing.padding,d=e.fixedHeight??200,u=this.imageConfig.rotation?.mode??"none",f=this.imageConfig.sizing?.variance?.min??1,m=this.imageConfig.sizing?.variance?.max??1,p=f!==1||m!==1,x=s-2*c,v=r-2*c,{columns:l,rows:g}=this.calculateGridDimensions(t,x,v,d,a),h=a.stagger==="row",b=a.stagger==="column",I=h?l+.5:l,y=b?g+.5:g,E=(x-a.gap*(l-1))/I,w=(v-a.gap*(g-1))/y,M=h?E/2:0,A=b?w/2:0,O=1+a.overlap,L=Math.min(E,w)*O,D=e.fixedHeight?Math.min(e.fixedHeight,L):L,H=l*E+(l-1)*a.gap+M,P=g*w+(g-1)*a.gap+A,z=c+(x-H)/2,C=c+(v-P)/2,U=l*g,$=a.columns!=="auto"&&a.rows!=="auto",F=$&&t>U;typeof window<"u"&&(window.__gridOverflowDebug={gridConfigColumns:a.columns,gridConfigRows:a.rows,columns:l,rows:g,cellCount:U,hasFixedGrid:$,imageCount:t,isOverflowMode:F});const W=F?new Array(U).fill(0):[],B=Math.min(E,w)*a.overflowOffset;for(let _=0;_<t;_++){let N,k,X=0;if(F&&_>=U){const Y=_-U,q=Y%U;X=Math.floor(Y/U)+1,W[q]++,a.fillDirection==="row"?(N=q%l,k=Math.floor(q/l)):(k=q%g,N=Math.floor(q/g))}else a.fillDirection==="row"?(N=_%l,k=Math.floor(_/l)):(k=_%g,N=Math.floor(_/g));let j=z+N*(E+a.gap)+E/2,G=C+k*(w+a.gap)+w/2;if(a.stagger==="row"&&k%2===1?j+=E/2:a.stagger==="column"&&N%2===1&&(G+=w/2),X>0){const Y=(X-1)%Ut.length,q=Ut[Y];j+=q.x*B,G+=q.y*B}if(a.jitter>0){const Y=E/2*a.jitter,q=w/2*a.jitter;j+=this.random(-Y,Y),G+=this.random(-q,q)}let V=j,Z=G;if(!F&&a.fillDirection==="row"){const Y=t%l||l;if(k===Math.floor((t-1)/l)&&Y<l){const ie=Y*E+(Y-1)*a.gap;let Rt=0;a.alignment==="center"?Rt=(H-ie)/2:a.alignment==="end"&&(Rt=H-ie),V+=Rt}}const wt=p?this.random(f,m):1,Q=D*wt,ct=Q*1.5/2,lt=Q/2,It=c+ct,St=s-c-ct,Ze=c+lt,Qe=r-c-lt;V=Math.max(It,Math.min(V,St)),Z=Math.max(Ze,Math.min(Z,Qe));let Ct=0;if(u==="random"){const Y=this.imageConfig.rotation?.range?.min??-15,q=this.imageConfig.rotation?.range?.max??15;a.jitter>0?Ct=this.random(Y*a.jitter,q*a.jitter):Ct=this.random(Y,q)}let Tt;F&&X>0?Tt=50-X:Tt=F?100+_:_+1,n.push({id:_,x:V,y:Z,rotation:Ct,scale:wt,baseSize:Q,zIndex:Tt})}return n}calculateGridDimensions(t,i,e,n,s){let r,a;if(s.columns!=="auto"&&s.rows!=="auto")r=s.columns,a=s.rows;else if(s.columns!=="auto")r=s.columns,a=Math.ceil(t/r);else if(s.rows!=="auto")a=s.rows,r=Math.ceil(t/a);else{const c=i/e;for(r=Math.max(1,Math.round(Math.sqrt(t*c/1.4))),a=Math.ceil(t/r);r>1&&(r-1)*a>=t;)r--}return{columns:Math.max(1,r),rows:Math.max(1,a)}}random(t,i){return Math.random()*(i-t)+t}}const Le=Math.PI*(3-Math.sqrt(5)),Fe={spiralType:"golden",direction:"counterclockwise",tightness:1,scaleDecay:0,startAngle:0};class Ht{constructor(t,i={}){this.config=t,this.imageConfig=i}generate(t,i,e={}){const n=[],{width:s,height:r}=i,a={...Fe,...this.config.spiral},c=this.config.spacing.padding,d=e.fixedHeight??200,u=this.imageConfig.rotation?.mode??"none",f=this.imageConfig.rotation?.range?.min??-15,m=this.imageConfig.rotation?.range?.max??15,p=this.imageConfig.sizing?.variance?.min??1,x=this.imageConfig.sizing?.variance?.max??1,v=p!==1||x!==1,l=this.config.scaleDecay??a.scaleDecay,g=s/2,h=r/2,b=Math.min(g-c-d/2,h-c-d/2),I=a.direction==="clockwise"?-1:1;for(let y=0;y<t;y++){let E,w;if(a.spiralType==="golden")E=y*Le*I+a.startAngle,w=this.calculateGoldenRadius(y,t,b,a.tightness);else if(a.spiralType==="archimedean"){const j=y*.5*a.tightness;E=j*I+a.startAngle,w=this.calculateArchimedeanRadius(j,t,b,a.tightness)}else{const j=y*.3*a.tightness;E=j*I+a.startAngle,w=this.calculateLogarithmicRadius(j,t,b,a.tightness)}const M=g+Math.cos(E)*w,A=h+Math.sin(E)*w,O=w/b,L=l>0?1-O*l*.5:1,D=v?this.random(p,x):1,H=L*D,P=d*H,C=P*1.5/2,U=P/2,$=c+C,F=s-c-C,W=c+U,B=r-c-U,_=Math.max($,Math.min(M,F)),N=Math.max(W,Math.min(A,B));let k=0;if(u==="random"){const j=E*180/Math.PI%360,G=this.random(f,m);k=a.spiralType==="golden"?G:j*.1+G*.9}else u==="tangent"&&(k=this.calculateSpiralTangent(E,w,a));const X=t-y;n.push({id:y,x:_,y:N,rotation:k,scale:H,baseSize:P,zIndex:X})}return n}calculateSpiralTangent(t,i,e){let n;if(e.spiralType==="golden")n=t+Math.PI/2;else if(e.spiralType==="archimedean"){const r=1/e.tightness,a=Math.atan(i/r);n=t+a}else{const r=.15/e.tightness,a=Math.atan(1/r);n=t+a}return n*180/Math.PI%360-90}calculateGoldenRadius(t,i,e,n){const r=e/Math.sqrt(i)*Math.sqrt(t)/n;return Math.min(r,e)}calculateArchimedeanRadius(t,i,e,n){const s=i*.5*n;return t/s*e}calculateLogarithmicRadius(t,i,e,n){const s=e*.05,r=.15/n,a=s*Math.exp(r*t),c=i*.3*n,d=s*Math.exp(r*c);return a/d*e}random(t,i){return Math.random()*(i-t)+t}}const Me={clusterCount:"auto",clusterSpread:150,clusterSpacing:200,density:"uniform",overlap:.3,distribution:"gaussian"};class Nt{constructor(t,i={}){this.config=t,this.imageConfig=i}generate(t,i,e={}){const n=[],{width:s,height:r}=i,a={...Me,...this.config.cluster},c=this.config.spacing.padding,d=e.fixedHeight??200,u=this.imageConfig.rotation?.mode??"none",f=this.imageConfig.rotation?.range?.min??-15,m=this.imageConfig.rotation?.range?.max??15,p=this.imageConfig.sizing?.variance?.min??1,x=this.imageConfig.sizing?.variance?.max??1,v=p!==1||x!==1,l=this.calculateClusterCount(t,a.clusterCount,s,r,a.clusterSpacing),g=this.generateClusterCenters(l,s,r,c,a),h=new Array(l).fill(0);for(let I=0;I<t;I++)h[I%l]++;let b=0;for(let I=0;I<l;I++){const y=g[I],E=h[I];for(let w=0;w<E;w++){let M,A;if(a.distribution==="gaussian")M=this.gaussianRandom()*y.spread,A=this.gaussianRandom()*y.spread;else{const k=this.random(0,Math.PI*2),X=this.random(0,y.spread);M=Math.cos(k)*X,A=Math.sin(k)*X}const O=1+a.overlap*.5,L=1+a.overlap*.3;M/=O,A/=O;const D=v?this.random(p,x):1,H=L*D,P=d*H;let z=y.x+M,C=y.y+A;const $=P*1.5/2,F=P/2;z=Math.max(c+$,Math.min(z,s-c-$)),C=Math.max(c+F,Math.min(C,r-c-F));const W=u==="random"?this.random(f,m):0,_=Math.sqrt(M*M+A*A)/y.spread,N=Math.round((1-_)*50)+1;n.push({id:b,x:z,y:C,rotation:W,scale:H,baseSize:P,zIndex:N}),b++}}return n}calculateClusterCount(t,i,e,n,s){if(i!=="auto")return Math.max(1,Math.min(i,t));const a=Math.max(1,Math.ceil(t/8)),c=Math.floor(e/s*(n/s)*.6);return Math.max(1,Math.min(a,c,10))}generateClusterCenters(t,i,e,n,s){const r=[],c=n+s.clusterSpread,d=i-n-s.clusterSpread,u=n+s.clusterSpread,f=e-n-s.clusterSpread;for(let m=0;m<t;m++){let p=null,x=-1;for(let v=0;v<100;v++){const l={x:this.random(c,d),y:this.random(u,f),spread:this.calculateClusterSpread(s)};let g=1/0;for(const h of r){const b=l.x-h.x,I=l.y-h.y,y=Math.sqrt(b*b+I*I);g=Math.min(g,y)}if((r.length===0||g>x)&&(p=l,x=g),g>=s.clusterSpacing)break}p&&r.push(p)}return r}calculateClusterSpread(t){return t.density==="uniform"?t.clusterSpread:t.clusterSpread*this.random(.5,1.5)}gaussianRandom(){let t=0,i=0;for(;t===0;)t=Math.random();for(;i===0;)i=Math.random();const e=Math.sqrt(-2*Math.log(t))*Math.cos(2*Math.PI*i);return Math.max(-3,Math.min(3,e))/3}random(t,i){return Math.random()*(i-t)+t}}class Bt{constructor(t,i={}){this.config=t,this.imageConfig=i}generate(t,i,e={}){const n=[],{width:s,height:r}=i,a=e.fixedHeight??200,c=this.config.spacing.padding??50,d=this.imageConfig.rotation?.mode??"none",u=this.imageConfig.rotation?.range?.min??-15,f=this.imageConfig.rotation?.range?.max??15,m=this.imageConfig.sizing?.variance?.min??1,p=this.imageConfig.sizing?.variance?.max??1,x=m!==1||p!==1,v=e.fixedHeight??a,l={...oe,...this.config.wave},{rows:g,amplitude:h,frequency:b,phaseShift:I,synchronization:y}=l,E=Math.ceil(t/g),A=v*1.5/2,O=c+A,L=s-c-A,D=L-O,H=E>1?D/(E-1):0,P=c+h+v/2,z=r-c-h-v/2,C=z-P,U=g>1?C/(g-1):0;let $=0;for(let F=0;F<g&&$<t;F++){const W=g===1?(P+z)/2:P+F*U;let B=0;y==="offset"?B=F*I:y==="alternating"&&(B=F*Math.PI);for(let _=0;_<E&&$<t;_++){const N=E===1?(O+L)/2:O+_*H,k=this.calculateWaveY(N,s,h,b,B),X=N,j=W+k,G=x?this.random(m,p):1,V=v*G;let Z=0;d==="tangent"?Z=this.calculateRotation(N,s,h,b,B):d==="random"&&(Z=this.random(u,f));const Q=V*1.5/2,xt=V/2,ct=c+Q,lt=s-c-Q,It=c+xt,St=r-c-xt;n.push({id:$,x:Math.max(ct,Math.min(X,lt)),y:Math.max(It,Math.min(j,St)),rotation:Z,scale:G,baseSize:V,zIndex:$+1}),$++}}return n}calculateWaveY(t,i,e,n,s){const r=t/i;return e*Math.sin(n*r*2*Math.PI+s)}calculateRotation(t,i,e,n,s){const r=t/i,a=e*n*2*Math.PI*Math.cos(n*r*2*Math.PI+s)/i;return Math.atan(a)*(180/Math.PI)}random(t,i){return Math.random()*(i-t)+t}}const bt=100,et=100/Math.sqrt(3),yt=[[et/2,0],[3*et/2,0],[2*et,50],[3*et/2,100],[et/2,100],[0,50]],Oe=yt[1][0]/bt,ze=yt[2][1]/bt;function De(o){return{colStep:Oe*o,rowOffset:ze*o}}function Pe(o,t,i,e,n,s){const{colStep:r}=De(s);return{px:e+r*o,py:n+s*(t+o/2)}}const $e=[[1,0,-1],[0,1,-1],[-1,1,0],[-1,0,1],[0,-1,1],[1,-1,0]];function _e(o){if(o===0)return[[0,0,0]];const t=[];let[i,e,n]=[0,-o,o];for(const[s,r,a]of $e)for(let c=0;c<o;c++)t.push([i,e,n]),i+=s,e+=r,n+=a;return t}class jt{constructor(t,i={}){this.config=t}generate(t,i,e={}){const n=[],{width:s,height:r}=i,a=s/2,c=r/2,d=e.fixedHeight??200,f={...se,...this.config.honeycomb}.spacing??0,m=d+f;let p=0,x=0;for(;p<t;){const v=_e(x);for(const[l,g,h]of v){if(p>=t)break;const{px:b,py:I}=Pe(l,g,h,a,c,m);n.push({id:p,x:b,y:I,rotation:0,scale:1,baseSize:d,zIndex:Math.max(1,100-x)}),p++}x++}return n}}class Wt{constructor(t){this.config=t.layout,this.imageConfig=t.image,this.layouts=new Map,this.placementLayout=this.initLayout()}initLayout(){switch(this.config.algorithm){case"radial":return new _t(this.config,this.imageConfig);case"grid":return new kt(this.config,this.imageConfig);case"spiral":return new Ht(this.config,this.imageConfig);case"cluster":return new Nt(this.config,this.imageConfig);case"wave":return new Bt(this.config,this.imageConfig);case"honeycomb":return new jt(this.config,this.imageConfig);default:return new $t(this.config,this.imageConfig)}}generateLayout(t,i,e={}){const n=this.placementLayout.generate(t,i,e);return n.forEach(s=>{this.layouts.set(s.id,s)}),n}getOriginalState(t){return this.layouts.get(Number(t))}reset(){this.layouts.clear()}updateConfig(t){t.layout&&(Object.assign(this.config,t.layout),t.layout.algorithm&&t.layout.algorithm!==this.config.algorithm&&(this.placementLayout=this.initLayout())),t.image&&Object.assign(this.imageConfig,t.image)}getBreakpoints(){return this.config.responsive??{mobile:{maxWidth:767},tablet:{maxWidth:1199}}}resolveBreakpoint(t){const i=this.getBreakpoints();return t<=i.mobile.maxWidth?"mobile":t<=i.tablet.maxWidth?"tablet":"screen"}resolveBaseHeight(t){const i=this.imageConfig.sizing;if(!i||i.mode==="adaptive")return;const e=i.height;if(e===void 0)return;if(typeof e=="number")return e;const n=e,s=this.resolveBreakpoint(t);return s==="mobile"?n.mobile??n.tablet??n.screen:s==="tablet"?n.tablet??n.screen??n.mobile:n.screen??n.tablet??n.mobile}calculateAdaptiveSize(t,i,e,n){const s=this.imageConfig.sizing,r=this.resolveBaseHeight(n);if(r!==void 0)return{height:r};const a=s?.minSize??50,c=s?.maxSize??400,d=this.config.targetCoverage??.6,u=this.config.densityFactor??1,{width:f,height:m}=t,v=f*m*d/i;let g=Math.sqrt(v/1.4);g*=u,g=Math.min(g,e);let h=this.clamp(g,a,c);if(h===a&&g<a){const b=Math.max(a*.05,20);h=Math.max(b,g)}return this.config.algorithm==="honeycomb"&&(h=Math.min(h,this.honeycombMaxImageHeight(i,t))),{height:h}}honeycombMaxImageHeight(t,i){if(t<=1)return 1/0;let e=0,n=1;for(;n<t;)e++,n+=6*e;const s=this.config.spacing?.padding??50,r=this.config.honeycomb?.spacing??0,a=i.width/2,c=i.height/2,d=Math.sqrt(3)/2,u=1/Math.sqrt(3),f=(c-s-r*e)/(e+.5),m=(a-s-d*r*e)/(d*e+u);return Math.max(10,Math.min(f,m))}clamp(t,i,e){return Math.max(i,Math.min(e,t))}}var S=(o=>(o.IDLE="idle",o.FOCUSING="focusing",o.FOCUSED="focused",o.UNFOCUSING="unfocusing",o.CROSS_ANIMATING="cross_animating",o))(S||{});const Gt={circle:"circle(50%)",square:"polygon(0% 0%, 100% 0%, 100% 100%, 0% 100%)",triangle:"polygon(50% 0%, 100% 100%, 0% 100%)",pentagon:"polygon(50% 0%, 100% 38%, 82% 100%, 18% 100%, 0% 38%)",hexagon:"polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%)",octagon:"polygon(30% 0%, 70% 0%, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0% 70%, 0% 30%)",diamond:"polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%)"},Ue={circle:{refHeight:100,points:[]},square:{refHeight:100,points:[[0,0],[100,0],[100,100],[0,100]]},triangle:{refHeight:100,points:[[50,0],[100,100],[0,100]]},pentagon:{refHeight:100,points:[[50,0],[100,38],[82,100],[18,100],[0,38]]},hexagon:{refHeight:bt,points:yt},octagon:{refHeight:100,points:[[30,0],[70,0],[100,30],[100,70],[70,100],[30,100],[0,70],[0,30]]},diamond:{refHeight:100,points:[[50,0],[100,50],[50,100],[0,50]]}};function ke(o){if(o)return o in Gt?Gt[o]:o}function He(o,t,i){const e=Ue[o];if(!e)return"";const n=t/e.refHeight;if(o==="circle")return`circle(${Math.round(50*n*100)/100}px)`;const s=e.points.map(([v])=>v),r=e.points.map(([,v])=>v),a=(Math.min(...s)+Math.max(...s))/2*n,c=(Math.min(...r)+Math.max(...r))/2*n,d=(Math.max(...s)-Math.min(...s))*n,u=(i??d)/2,f=t/2,m=u-a,p=f-c;return`polygon(${e.points.map(([v,l])=>{const g=Math.round((v*n+m)*100)/100,h=Math.round((l*n+p)*100)/100;return`${g}px ${h}px`}).join(", ")})`}function Ne(o){return o in J}function Be(o){return o?Ne(o)?J[o]:o:J.md}function je(o){if(!o)return"";const t=[];if(o.grayscale!==void 0&&t.push(`grayscale(${o.grayscale})`),o.blur!==void 0&&t.push(`blur(${o.blur}px)`),o.brightness!==void 0&&t.push(`brightness(${o.brightness})`),o.contrast!==void 0&&t.push(`contrast(${o.contrast})`),o.saturate!==void 0&&t.push(`saturate(${o.saturate})`),o.opacity!==void 0&&t.push(`opacity(${o.opacity})`),o.sepia!==void 0&&t.push(`sepia(${o.sepia})`),o.hueRotate!==void 0&&t.push(`hue-rotate(${o.hueRotate}deg)`),o.invert!==void 0&&t.push(`invert(${o.invert})`),o.dropShadow!==void 0)if(typeof o.dropShadow=="string")t.push(`drop-shadow(${o.dropShadow})`);else{const i=o.dropShadow;t.push(`drop-shadow(${i.x}px ${i.y}px ${i.blur}px ${i.color})`)}return t.join(" ")}function it(o){if(!o||o.style==="none"||o.width===0)return"none";const t=o.width??0,i=o.style??"solid",e=o.color??"#000000";return`${t}px ${i} ${e}`}function nt(o,t,i){if(!o)return{};const e={};if(o.borderRadiusTopLeft!==void 0||o.borderRadiusTopRight!==void 0||o.borderRadiusBottomRight!==void 0||o.borderRadiusBottomLeft!==void 0){const a=o.border?.radius??0;o.borderRadiusTopLeft!==void 0?e.borderTopLeftRadius=`${o.borderRadiusTopLeft}px`:a&&(e.borderTopLeftRadius=`${a}px`),o.borderRadiusTopRight!==void 0?e.borderTopRightRadius=`${o.borderRadiusTopRight}px`:a&&(e.borderTopRightRadius=`${a}px`),o.borderRadiusBottomRight!==void 0?e.borderBottomRightRadius=`${o.borderRadiusBottomRight}px`:a&&(e.borderBottomRightRadius=`${a}px`),o.borderRadiusBottomLeft!==void 0?e.borderBottomLeftRadius=`${o.borderRadiusBottomLeft}px`:a&&(e.borderBottomLeftRadius=`${a}px`)}else o.border?.radius!==void 0&&(e.borderRadius=`${o.border.radius}px`);if(o.borderTop||o.borderRight||o.borderBottom||o.borderLeft){const a=o.border||{},c={...a,...o.borderTop},d={...a,...o.borderRight},u={...a,...o.borderBottom},f={...a,...o.borderLeft};e.borderTop=it(c),e.borderRight=it(d),e.borderBottom=it(u),e.borderLeft=it(f)}else o.border&&(e.border=it(o.border));o.shadow!==void 0&&(e.boxShadow=Be(o.shadow));const r=je(o.filter);if(e.filter=r||"none",o.opacity!==void 0&&(e.opacity=String(o.opacity)),o.cursor!==void 0&&(e.cursor=o.cursor),o.outline&&o.outline.style!=="none"&&(o.outline.width??0)>0){const a=o.outline.width??0,c=o.outline.style??"solid",d=o.outline.color??"#000000";e.outline=`${a}px ${c} ${d}`,o.outline.offset!==void 0&&(e.outlineOffset=`${o.outline.offset}px`)}if(o.objectFit!==void 0&&(e.objectFit=o.objectFit),o.aspectRatio!==void 0&&(e.aspectRatio=o.aspectRatio),o.clipPath!==void 0){let a;const c=typeof o.clipPath=="object"&&o.clipPath!==null&&"shape"in o.clipPath,d=c?o.clipPath:void 0;if(d?.mode==="height-relative"&&t)a=He(d.shape,t,i);else{const u=c&&d?d.shape:o.clipPath;a=ke(u)}a&&(a==="none"?e.clipPath="unset":(e.clipPath=a,e.overflow="hidden"))}return e}function We(o,t){t.borderRadius!==void 0&&(o.style.borderRadius=t.borderRadius),t.borderTopLeftRadius!==void 0&&(o.style.borderTopLeftRadius=t.borderTopLeftRadius),t.borderTopRightRadius!==void 0&&(o.style.borderTopRightRadius=t.borderTopRightRadius),t.borderBottomRightRadius!==void 0&&(o.style.borderBottomRightRadius=t.borderBottomRightRadius),t.borderBottomLeftRadius!==void 0&&(o.style.borderBottomLeftRadius=t.borderBottomLeftRadius),t.border!==void 0&&(o.style.border=t.border),t.borderTop!==void 0&&(o.style.borderTop=t.borderTop),t.borderRight!==void 0&&(o.style.borderRight=t.borderRight),t.borderBottom!==void 0&&(o.style.borderBottom=t.borderBottom),t.borderLeft!==void 0&&(o.style.borderLeft=t.borderLeft),t.boxShadow!==void 0&&(o.style.boxShadow=t.boxShadow),t.filter!==void 0&&(o.style.filter=t.filter),t.opacity!==void 0&&(o.style.opacity=t.opacity),t.cursor!==void 0&&(o.style.cursor=t.cursor),t.outline!==void 0&&(o.style.outline=t.outline),t.outlineOffset!==void 0&&(o.style.outlineOffset=t.outlineOffset),t.objectFit!==void 0&&(o.style.objectFit=t.objectFit),t.aspectRatio!==void 0&&(o.style.aspectRatio=t.aspectRatio),t.clipPath!==void 0&&(o.style.clipPath=t.clipPath),t.overflow!==void 0&&(o.style.overflow=t.overflow)}function at(o,t,i,e){const n=nt(t,i,e);We(o,n)}function qt(o){return o?Array.isArray(o)?o.join(" "):o:""}function ot(o,t){const i=qt(t);i&&i.split(" ").forEach(e=>{e.trim()&&o.classList.add(e.trim())})}function vt(o,t){const i=qt(t);i&&i.split(" ").forEach(e=>{e.trim()&&o.classList.remove(e.trim())})}const Yt={UNFOCUSING:999,FOCUSING:1e3};class Xt{constructor(t,i,e){this.state=S.IDLE,this.currentFocus=null,this.focusData=null,this.outgoing=null,this.incoming=null,this.focusGeneration=0,this.onUnfocusComplete=null,this.config=t,this.animationEngine=i,this.styling=e,this.focusedClassName=e?.focused?.className}setOnUnfocusCompleteCallback(t){this.onUnfocusComplete=t}getState(){return this.state}isAnimating(){return this.state!==S.IDLE&&this.state!==S.FOCUSED}normalizeScalePercent(t){return t>1?t/100:t}calculateFocusDimensions(t,i,e){const n=this.normalizeScalePercent(this.config.scalePercent),s=e.height*n,r=t/i;let a=s,c=a*r;const d=e.width*n;return c>d&&(c=d,a=c/r),{width:c,height:a}}calculateFocusTransform(t,i){const e=t.width/2,n=t.height/2,s=e-i.x,r=n-i.y;return{x:s,y:r,rotation:0,scale:1}}buildDimensionZoomTransform(t){const i=["translate(-50%, -50%)"];if(t.x!==void 0||t.y!==void 0){const e=t.x??0,n=t.y??0;i.push(`translate(${e}px, ${n}px)`)}return t.rotation!==void 0&&i.push(`rotate(${t.rotation}deg)`),i.join(" ")}animateWithDimensions(t,i,e,n,s,r,a,c){const d=this.buildDimensionZoomTransform(i),u=this.buildDimensionZoomTransform(e);return t.style.transition="none",t.animate([{transform:d,width:`${n}px`,height:`${s}px`},{transform:u,width:`${r}px`,height:`${a}px`}],{duration:c,easing:"cubic-bezier(0.4, 0, 0.2, 1)",fill:"forwards"})}applyFocusedStyling(t,i){if(t.style.zIndex=String(i),t.classList.add("fbn-ic-focused"),ot(t,this.focusedClassName),this.styling?.focused){const e=nt(this.styling.focused,t.offsetHeight,t.offsetWidth);e.borderRadius!==void 0&&(t.style.borderRadius=e.borderRadius),e.borderTopLeftRadius!==void 0&&(t.style.borderTopLeftRadius=e.borderTopLeftRadius),e.borderTopRightRadius!==void 0&&(t.style.borderTopRightRadius=e.borderTopRightRadius),e.borderBottomRightRadius!==void 0&&(t.style.borderBottomRightRadius=e.borderBottomRightRadius),e.borderBottomLeftRadius!==void 0&&(t.style.borderBottomLeftRadius=e.borderBottomLeftRadius),e.border!==void 0&&(t.style.border=e.border),e.borderTop!==void 0&&(t.style.borderTop=e.borderTop),e.borderRight!==void 0&&(t.style.borderRight=e.borderRight),e.borderBottom!==void 0&&(t.style.borderBottom=e.borderBottom),e.borderLeft!==void 0&&(t.style.borderLeft=e.borderLeft),e.boxShadow!==void 0&&(t.style.boxShadow=e.boxShadow),e.filter!==void 0&&(t.style.filter=e.filter),e.opacity!==void 0&&(t.style.opacity=e.opacity),e.cursor!==void 0&&(t.style.cursor=e.cursor),e.outline!==void 0&&(t.style.outline=e.outline),e.outlineOffset!==void 0&&(t.style.outlineOffset=e.outlineOffset),e.objectFit!==void 0&&(t.style.objectFit=e.objectFit),e.aspectRatio!==void 0&&(t.style.aspectRatio=e.aspectRatio)}}removeFocusedStyling(t,i){if(t.style.zIndex=i,t.classList.remove("fbn-ic-focused"),vt(t,this.focusedClassName),this.styling?.default){const e=nt(this.styling.default,t.offsetHeight,t.offsetWidth);e.borderRadius!==void 0&&(t.style.borderRadius=e.borderRadius),e.borderTopLeftRadius!==void 0&&(t.style.borderTopLeftRadius=e.borderTopLeftRadius),e.borderTopRightRadius!==void 0&&(t.style.borderTopRightRadius=e.borderTopRightRadius),e.borderBottomRightRadius!==void 0&&(t.style.borderBottomRightRadius=e.borderBottomRightRadius),e.borderBottomLeftRadius!==void 0&&(t.style.borderBottomLeftRadius=e.borderBottomLeftRadius),e.border!==void 0&&(t.style.border=e.border),e.borderTop!==void 0&&(t.style.borderTop=e.borderTop),e.borderRight!==void 0&&(t.style.borderRight=e.borderRight),e.borderBottom!==void 0&&(t.style.borderBottom=e.borderBottom),e.borderLeft!==void 0&&(t.style.borderLeft=e.borderLeft),e.boxShadow!==void 0&&(t.style.boxShadow=e.boxShadow),e.filter!==void 0&&(t.style.filter=e.filter),e.opacity!==void 0&&(t.style.opacity=e.opacity),e.cursor!==void 0&&(t.style.cursor=e.cursor),e.outline!==void 0&&(t.style.outline=e.outline),e.outlineOffset!==void 0&&(t.style.outlineOffset=e.outlineOffset),e.objectFit!==void 0&&(t.style.objectFit=e.objectFit),e.aspectRatio!==void 0&&(t.style.aspectRatio=e.aspectRatio)}}startClipPathAnimation(t,i,e){let n=e?this.styling?.focused??this.styling?.default:this.styling?.default;e&&this.styling?.focused&&this.styling.focused.clipPath===void 0&&(n={...n,clipPath:void 0});const s=()=>{const r=t.offsetHeight,a=t.offsetWidth,c=nt(n,r,a);c.clipPath!==void 0?t.style.clipPath=c.clipPath:t.style.clipPath="unset",c.overflow!==void 0&&(t.style.overflow=c.overflow),i.animation.playState==="running"&&requestAnimationFrame(s)};requestAnimationFrame(s)}startFocusAnimation(t,i,e,n,s){const r=t.style.zIndex||"",a=t.offsetWidth,c=t.offsetHeight,d=this.calculateFocusDimensions(a,c,i),u=this.calculateFocusTransform(i,e);this.animationEngine.cancelAllAnimations(t);const f=this.config.animationDuration??600;this.applyFocusedStyling(t,Yt.FOCUSING);const m=n??{x:0,y:0,rotation:e.rotation,scale:1},p=s?.width??a,x=s?.height??c,v=this.animateWithDimensions(t,m,u,p,x,d.width,d.height,f),l={id:`focus-${Date.now()}`,element:t,animation:v,fromState:m,toState:u,startTime:performance.now(),duration:f};return this.focusData={element:t,originalState:e,focusTransform:u,originalZIndex:r,originalWidth:a,originalHeight:c,focusWidth:d.width,focusHeight:d.height},this.startClipPathAnimation(t,l,!0),{element:t,originalState:e,animationHandle:l,direction:"in",originalWidth:a,originalHeight:c}}startUnfocusAnimation(t,i,e,n){t.style.zIndex=String(Yt.UNFOCUSING),this.animationEngine.cancelAllAnimations(t);const s=this.config.animationDuration??600;t.classList.remove("fbn-ic-focused"),vt(t,this.focusedClassName);const r=e??this.focusData?.focusTransform??{x:0,y:0,rotation:0,scale:1},a=n?.width??this.focusData?.focusWidth??t.offsetWidth,c=n?.height??this.focusData?.focusHeight??t.offsetHeight,d={x:0,y:0,rotation:i.rotation,scale:1},u=this.focusData?.originalWidth??t.offsetWidth,f=this.focusData?.originalHeight??t.offsetHeight,m=this.animateWithDimensions(t,r,d,a,c,u,f,s),p={id:`unfocus-${Date.now()}`,element:t,animation:m,fromState:r,toState:d,startTime:performance.now(),duration:s};return this.startClipPathAnimation(t,p,!1),{element:t,originalState:i,animationHandle:p,direction:"out",originalWidth:u,originalHeight:f}}captureMidAnimationState(t){const i=getComputedStyle(t),e=new DOMMatrix(i.transform),n=t.offsetWidth,s=t.offsetHeight,r=e.e+n*.5,a=e.f+s*.5,c=Math.atan2(e.b,e.a)*(180/Math.PI);return t.style.width=`${n}px`,t.style.height=`${s}px`,t.style.transform=`translate(-50%, -50%) translate(${r}px, ${a}px) rotate(${c}deg)`,t.style.transition="none",{transform:{x:r,y:a,rotation:c,scale:1},dimensions:{width:n,height:s}}}async waitForAnimation(t){try{await t.animation.finished}catch{}}resetElementInstantly(t,i,e,n,s){this.animationEngine.cancelAllAnimations(t);const r=["translate(-50%, -50%)"];r.push("translate(0px, 0px)"),r.push(`rotate(${i.rotation}deg)`),t.style.transition="none",t.style.transform=r.join(" "),n!==void 0&&s!==void 0&&(t.style.width=`${n}px`,t.style.height=`${s}px`),this.removeFocusedStyling(t,e)}async focusImage(t,i,e){if(this.currentFocus===t&&this.state===S.FOCUSED)return this.unfocusImage();if(this.incoming?.element===t&&this.state===S.FOCUSING){const{transform:s,dimensions:r}=this.captureMidAnimationState(t);this.animationEngine.cancelAllAnimations(t),this.outgoing=this.startUnfocusAnimation(t,this.incoming.originalState,s,r),this.incoming=null,this.state=S.UNFOCUSING,await this.waitForAnimation(this.outgoing.animationHandle),this.removeFocusedStyling(this.outgoing.element,this.focusData?.originalZIndex||""),this.outgoing=null,this.currentFocus=null,this.focusData=null,this.state=S.IDLE;return}const n=++this.focusGeneration;switch(this.state){case S.IDLE:if(this.state=S.FOCUSING,this.incoming=this.startFocusAnimation(t,i,e),await this.waitForAnimation(this.incoming.animationHandle),this.focusGeneration!==n)return;this.currentFocus=t,this.incoming=null,this.state=S.FOCUSED;break;case S.FOCUSED:if(this.state=S.CROSS_ANIMATING,this.currentFocus&&this.focusData&&(this.outgoing=this.startUnfocusAnimation(this.currentFocus,this.focusData.originalState)),this.incoming=this.startFocusAnimation(t,i,e),await Promise.all([this.outgoing?this.waitForAnimation(this.outgoing.animationHandle):Promise.resolve(),this.waitForAnimation(this.incoming.animationHandle)]),this.focusGeneration!==n)return;if(this.outgoing){const s=this.outgoing.element;this.removeFocusedStyling(s,this.outgoing.originalState.zIndex?.toString()||""),this.outgoing=null,this.onUnfocusComplete?.(s)}this.currentFocus=t,this.incoming=null,this.state=S.FOCUSED;break;case S.FOCUSING:if(this.incoming&&(this.animationEngine.cancelAnimation(this.incoming.animationHandle,!1),this.resetElementInstantly(this.incoming.element,this.incoming.originalState,this.focusData?.originalZIndex||"",this.focusData?.originalWidth,this.focusData?.originalHeight),this.incoming=null),this.incoming=this.startFocusAnimation(t,i,e),await this.waitForAnimation(this.incoming.animationHandle),this.focusGeneration!==n)return;this.currentFocus=t,this.incoming=null,this.state=S.FOCUSED;break;case S.UNFOCUSING:if(this.state=S.CROSS_ANIMATING,this.incoming=this.startFocusAnimation(t,i,e),await Promise.all([this.outgoing?this.waitForAnimation(this.outgoing.animationHandle):Promise.resolve(),this.waitForAnimation(this.incoming.animationHandle)]),this.focusGeneration!==n)return;if(this.outgoing){const s=this.outgoing.element;this.removeFocusedStyling(s,this.outgoing.originalState.zIndex?.toString()||""),this.outgoing=null,this.onUnfocusComplete?.(s)}this.currentFocus=t,this.incoming=null,this.state=S.FOCUSED;break;case S.CROSS_ANIMATING:if(this.incoming?.element===t)return;if(this.outgoing?.element===t){const{transform:s,dimensions:r}=this.captureMidAnimationState(t);if(this.animationEngine.cancelAllAnimations(t),this.incoming){const{transform:a,dimensions:c}=this.captureMidAnimationState(this.incoming.element);this.animationEngine.cancelAllAnimations(this.incoming.element),this.outgoing=this.startUnfocusAnimation(this.incoming.element,this.incoming.originalState,a,c)}else this.outgoing=null;if(this.incoming=this.startFocusAnimation(t,i,e,s,r),await Promise.all([this.outgoing?this.waitForAnimation(this.outgoing.animationHandle):Promise.resolve(),this.waitForAnimation(this.incoming.animationHandle)]),this.focusGeneration!==n)return;if(this.outgoing){const a=this.outgoing.element;this.removeFocusedStyling(a,this.outgoing.originalState.zIndex?.toString()||""),this.outgoing=null,this.onUnfocusComplete?.(a)}this.currentFocus=t,this.incoming=null,this.state=S.FOCUSED;return}if(this.outgoing&&(this.animationEngine.cancelAnimation(this.outgoing.animationHandle,!1),this.resetElementInstantly(this.outgoing.element,this.outgoing.originalState,this.outgoing.originalState.zIndex?.toString()||"",this.outgoing.originalWidth,this.outgoing.originalHeight),this.outgoing=null),this.incoming){const{transform:s,dimensions:r}=this.captureMidAnimationState(this.incoming.element);this.animationEngine.cancelAllAnimations(this.incoming.element),this.outgoing=this.startUnfocusAnimation(this.incoming.element,this.incoming.originalState,s,r)}if(this.incoming=this.startFocusAnimation(t,i,e),await Promise.all([this.outgoing?this.waitForAnimation(this.outgoing.animationHandle):Promise.resolve(),this.waitForAnimation(this.incoming.animationHandle)]),this.focusGeneration!==n)return;if(this.outgoing){const s=this.outgoing.element;this.removeFocusedStyling(s,this.outgoing.originalState.zIndex?.toString()||""),this.outgoing=null,this.onUnfocusComplete?.(s)}this.currentFocus=t,this.incoming=null,this.state=S.FOCUSED;break}}async unfocusImage(){if(this.state===S.UNFOCUSING)return;const t=++this.focusGeneration;if(!this.currentFocus||!this.focusData){if(this.incoming&&this.state===S.FOCUSING){const{transform:s,dimensions:r}=this.captureMidAnimationState(this.incoming.element);if(this.animationEngine.cancelAllAnimations(this.incoming.element),this.outgoing=this.startUnfocusAnimation(this.incoming.element,this.incoming.originalState,s,r),this.incoming=null,this.state=S.UNFOCUSING,await this.waitForAnimation(this.outgoing.animationHandle),this.focusGeneration!==t)return;const a=this.outgoing.element;this.removeFocusedStyling(a,this.focusData?.originalZIndex||""),this.outgoing=null,this.focusData=null,this.state=S.IDLE,this.onUnfocusComplete?.(a)}return}if(this.state===S.CROSS_ANIMATING&&this.incoming){const{transform:s,dimensions:r}=this.captureMidAnimationState(this.incoming.element);this.animationEngine.cancelAllAnimations(this.incoming.element);const a=this.startUnfocusAnimation(this.incoming.element,this.incoming.originalState,s,r);if(await Promise.all([this.outgoing?this.waitForAnimation(this.outgoing.animationHandle):Promise.resolve(),this.waitForAnimation(a.animationHandle)]),this.focusGeneration!==t)return;let c=null;this.outgoing&&(c=this.outgoing.element,this.removeFocusedStyling(c,this.outgoing.originalState.zIndex?.toString()||""));const d=a.element;this.removeFocusedStyling(d,this.incoming.originalState.zIndex?.toString()||""),this.outgoing=null,this.incoming=null,this.currentFocus=null,this.focusData=null,this.state=S.IDLE,c&&this.onUnfocusComplete?.(c),this.onUnfocusComplete?.(d);return}this.state=S.UNFOCUSING;const i=this.currentFocus,e=this.focusData.originalState,n=this.focusData.originalZIndex;this.outgoing=this.startUnfocusAnimation(i,e),await this.waitForAnimation(this.outgoing.animationHandle),this.focusGeneration===t&&(this.removeFocusedStyling(i,n),this.outgoing=null,this.currentFocus=null,this.focusData=null,this.state=S.IDLE,this.onUnfocusComplete?.(i))}async swapFocus(t,i,e){return this.focusImage(t,i,e)}getCurrentFocus(){return this.currentFocus}isFocused(t){return this.currentFocus===t&&this.state===S.FOCUSED}isTargetingFocus(t){return this.incoming?.element===t}isInvolved(t){return this.currentFocus===t||this.incoming?.element===t||this.outgoing?.element===t}setDragOffset(t){if(!this.currentFocus||!this.focusData||this.state!==S.FOCUSED)return;const i=this.currentFocus,e=this.focusData.focusTransform,n=["translate(-50%, -50%)"],s=(e.x??0)+t,r=e.y??0;n.push(`translate(${s}px, ${r}px)`),e.rotation!==void 0&&n.push(`rotate(${e.rotation}deg)`),i.style.transition="none",i.style.transform=n.join(" ")}clearDragOffset(t,i=150){if(!this.currentFocus||!this.focusData||this.state!==S.FOCUSED)return;const e=this.currentFocus,n=this.focusData.focusTransform,s=["translate(-50%, -50%)"],r=n.x??0,a=n.y??0;s.push(`translate(${r}px, ${a}px)`),n.rotation!==void 0&&s.push(`rotate(${n.rotation}deg)`);const c=s.join(" ");t?(e.style.transition=`transform ${i}ms ease-out`,e.style.transform=c,setTimeout(()=>{this.currentFocus===e&&(e.style.transition="none")},i)):(e.style.transition="none",e.style.transform=c)}reset(){this.outgoing&&(this.animationEngine.cancelAnimation(this.outgoing.animationHandle,!1),this.resetElementInstantly(this.outgoing.element,this.outgoing.originalState,this.outgoing.originalState.zIndex?.toString()||"",this.outgoing.originalWidth,this.outgoing.originalHeight)),this.incoming&&(this.animationEngine.cancelAnimation(this.incoming.animationHandle,!1),this.resetElementInstantly(this.incoming.element,this.incoming.originalState,this.focusData?.originalZIndex||"",this.focusData?.originalWidth,this.focusData?.originalHeight)),this.currentFocus&&this.focusData&&this.resetElementInstantly(this.currentFocus,this.focusData.originalState,this.focusData.originalZIndex,this.focusData.originalWidth,this.focusData.originalHeight),this.state=S.IDLE,this.currentFocus=null,this.focusData=null,this.outgoing=null,this.incoming=null}}const Ge=50,qe=.5,Ye=20,Xe=.3,Ve=150,Je=30,rt=class rt{constructor(t,i){this.enabled=!1,this.touchState=null,this.recentTouchTimestamp=0,this.container=t,this.callbacks=i,this.boundTouchStart=this.handleTouchStart.bind(this),this.boundTouchMove=this.handleTouchMove.bind(this),this.boundTouchEnd=this.handleTouchEnd.bind(this),this.boundTouchCancel=this.handleTouchCancel.bind(this)}enable(){this.enabled||(this.enabled=!0,this.container.style.touchAction="pan-y",this.container.addEventListener("touchstart",this.boundTouchStart,{passive:!1}),this.container.addEventListener("touchmove",this.boundTouchMove,{passive:!1}),this.container.addEventListener("touchend",this.boundTouchEnd,{passive:!0}),this.container.addEventListener("touchcancel",this.boundTouchCancel,{passive:!0}))}disable(){this.enabled&&(this.enabled=!1,this.container.style.touchAction="",this.container.removeEventListener("touchstart",this.boundTouchStart),this.container.removeEventListener("touchmove",this.boundTouchMove),this.container.removeEventListener("touchend",this.boundTouchEnd),this.container.removeEventListener("touchcancel",this.boundTouchCancel),this.touchState?.isDragging&&this.callbacks.onDragEnd(!1),this.touchState=null)}destroy(){this.disable()}hadRecentTouch(){return Date.now()-this.recentTouchTimestamp<rt.TOUCH_CLICK_DELAY}handleTouchStart(t){if(t.touches.length!==1)return;this.recentTouchTimestamp=Date.now();const i=t.touches[0];this.touchState={startX:i.clientX,startY:i.clientY,startTime:performance.now(),currentX:i.clientX,isDragging:!1,isHorizontalSwipe:null}}handleTouchMove(t){if(!this.touchState||t.touches.length!==1)return;const i=t.touches[0],e=i.clientX-this.touchState.startX,n=i.clientY-this.touchState.startY;if(this.touchState.isHorizontalSwipe===null&&Math.sqrt(e*e+n*n)>10){const a=Math.atan2(Math.abs(n),Math.abs(e))*(180/Math.PI);this.touchState.isHorizontalSwipe=a<=Je}if(this.touchState.isHorizontalSwipe!==!1&&this.touchState.isHorizontalSwipe===!0){t.preventDefault(),this.touchState.isDragging=!0,this.touchState.currentX=i.clientX;const s=e*Xe;this.callbacks.onDragOffset(s)}}handleTouchEnd(t){if(!this.touchState)return;this.recentTouchTimestamp=Date.now();const i=this.touchState.currentX-this.touchState.startX,e=performance.now()-this.touchState.startTime,n=Math.abs(i)/e,s=Math.abs(i);let r=!1;this.touchState.isHorizontalSwipe===!0&&this.touchState.isDragging&&(s>=Ge||n>=qe&&s>=Ye)&&(r=!0,i<0?this.callbacks.onNext():this.callbacks.onPrev()),this.touchState.isDragging&&this.callbacks.onDragEnd(r),this.touchState=null}handleTouchCancel(t){this.touchState?.isDragging&&this.callbacks.onDragEnd(!1),this.touchState=null}};rt.TOUCH_CLICK_DELAY=300;let Et=rt;class Vt{constructor(t){if(this._prepared=!1,this._discoveredUrls=[],this.apiKey=t.apiKey??"",this.apiEndpoint=t.apiEndpoint??"https://www.googleapis.com/drive/v3/files",this.debugLogging=t.debugLogging??!1,this.sources=t.sources??[],!this.sources||this.sources.length===0)throw new Error("GoogleDriveLoader requires at least one source to be configured")}async prepare(t){this._discoveredUrls=[];for(const i of this.sources)if("folders"in i)for(const e of i.folders){const n=i.recursive!==void 0?i.recursive:!0,s=await this.loadFromFolder(e,t,n);this._discoveredUrls.push(...s)}else if("files"in i){const e=await this.loadFiles(i.files,t);this._discoveredUrls.push(...e)}this._prepared=!0}imagesLength(){if(!this._prepared)throw new Error("GoogleDriveLoader.imagesLength() called before prepare()");return this._discoveredUrls.length}imageURLs(){if(!this._prepared)throw new Error("GoogleDriveLoader.imageURLs() called before prepare()");return[...this._discoveredUrls]}isPrepared(){return this._prepared}extractFolderId(t){const i=[/\/folders\/([a-zA-Z0-9_-]+)/,/id=([a-zA-Z0-9_-]+)/];for(const e of i){const n=t.match(e);if(n&&n[1])return n[1]}return null}async loadFromFolder(t,i,e=!0){const n=this.extractFolderId(t);if(!n)throw new Error("Invalid Google Drive folder URL. Please check the URL format.");if(!this.apiKey||this.apiKey==="YOUR_API_KEY_HERE")return this.loadImagesDirectly(n,i);try{return e?await this.loadImagesRecursively(n,i):await this.loadImagesFromSingleFolder(n,i)}catch(s){return console.error("Error loading from Google Drive API:",s),this.loadImagesDirectly(n,i)}}async loadImagesFromSingleFolder(t,i){const e=[],n=`'${t}' in parents and trashed=false`,r=`${this.apiEndpoint}?q=${encodeURIComponent(n)}&fields=files(id,name,mimeType,thumbnailLink)&key=${this.apiKey}`,a=await fetch(r);if(!a.ok)throw new Error(`API request failed: ${a.status} ${a.statusText}`);const d=(await a.json()).files.filter(u=>u.mimeType.startsWith("image/")&&i.isAllowed(u.name));return this.log(`Found ${d.length} images in folder ${t} (non-recursive)`),d.forEach(u=>{e.push(`https://lh3.googleusercontent.com/d/${u.id}=s1600`),this.log(`Added file: ${u.name}`)}),e}async loadFiles(t,i){const e=[];for(const n of t){const s=this.extractFileId(n);if(!s){this.log(`Skipping invalid file URL: ${n}`);continue}if(this.apiKey&&this.apiKey!=="YOUR_API_KEY_HERE")try{const r=`${this.apiEndpoint}/${s}?fields=name,mimeType&key=${this.apiKey}`,a=await fetch(r);if(a.ok){const c=await a.json();c.mimeType.startsWith("image/")&&i.isAllowed(c.name)?(e.push(`https://lh3.googleusercontent.com/d/${s}=s1600`),this.log(`Added file: ${c.name}`)):this.log(`Skipping non-image file: ${c.name} (${c.mimeType})`)}else this.log(`Failed to fetch metadata for file ${s}: ${a.status}`)}catch(r){this.log(`Error fetching metadata for file ${s}:`,r)}else e.push(`https://lh3.googleusercontent.com/d/${s}=s1600`)}return e}extractFileId(t){if(!/[/:.]/.test(t))return t;const i=[/\/file\/d\/([a-zA-Z0-9_-]+)/,/\/open\?id=([a-zA-Z0-9_-]+)/,/id=([a-zA-Z0-9_-]+)/];for(const e of i){const n=t.match(e);if(n&&n[1])return n[1]}return null}async loadImagesRecursively(t,i){const e=[],n=`'${t}' in parents and trashed=false`,r=`${this.apiEndpoint}?q=${encodeURIComponent(n)}&fields=files(id,name,mimeType,thumbnailLink)&key=${this.apiKey}`,a=await fetch(r);if(!a.ok)throw new Error(`API request failed: ${a.status} ${a.statusText}`);const c=await a.json(),d=c.files.filter(f=>f.mimeType.startsWith("image/")&&i.isAllowed(f.name)),u=c.files.filter(f=>f.mimeType==="application/vnd.google-apps.folder");this.log(`Found ${c.files.length} total items in folder ${t}`),c.files.forEach(f=>this.log(` - File: ${f.name} (${f.mimeType})`)),this.log(`- ${d.length} valid files (images only)`),this.log(`- ${u.length} subfolders`),d.forEach(f=>{e.push(`https://lh3.googleusercontent.com/d/${f.id}=s1600`),this.log(`Added file: ${f.name}`)});for(const f of u){this.log(`Loading images from subfolder: ${f.name}`);const m=await this.loadImagesRecursively(f.id,i);e.push(...m)}return e}async loadImagesDirectly(t,i){try{const e=`https://drive.google.com/embeddedfolderview?id=${t}`,n=await fetch(e,{mode:"cors"});if(!n.ok)throw new Error("Cannot access folder directly (CORS or permissions issue)");const s=await n.text(),r=/\/file\/d\/([a-zA-Z0-9_-]+)/g,a=[...s.matchAll(r)];return[...new Set(a.map(u=>u[1]))].map(u=>`https://drive.google.com/uc?export=view&id=${u}`)}catch(e){throw console.error("Direct loading failed:",e),new Error(`Unable to load images. Please ensure:
2
2
  1. The folder is shared publicly (Anyone with the link can view)
3
3
  2. The folder contains image files
4
- 3. Consider adding a Google Drive API key in config.js for better reliability`)}}manualImageUrls(t){return t.map(i=>`https://drive.google.com/uc?export=view&id=${i}`)}log(...t){this.debugLogging&&typeof console<"u"&&console.log(...t)}}class Vt{constructor(t){if(this._prepared=!1,this._discoveredUrls=[],this.validateUrls=t.validateUrls!==!1,this.validationTimeout=t.validationTimeout??5e3,this.validationMethod=t.validationMethod??"head",this.debugLogging=t.debugLogging??!1,this.sources=t.sources??[],!this.sources||this.sources.length===0)throw new Error("StaticImageLoader requires at least one source to be configured");this.log("StaticImageLoader initialized with config:",t)}async prepare(t){this._discoveredUrls=[],this.log(`Processing ${this.sources.length} source(s)`);for(const i of this.sources)try{const e=await this.processSource(i,t);this._discoveredUrls.push(...e)}catch(e){console.warn("Failed to process source:",i,e)}this._prepared=!0,this.log(`Successfully loaded ${this._discoveredUrls.length} image(s)`)}imagesLength(){if(!this._prepared)throw new Error("StaticImageLoader.imagesLength() called before prepare()");return this._discoveredUrls.length}imageURLs(){if(!this._prepared)throw new Error("StaticImageLoader.imageURLs() called before prepare()");return[...this._discoveredUrls]}isPrepared(){return this._prepared}async processSource(t,i){return t?"urls"in t?await this.processUrls(t.urls,i):"path"in t?await this.processPath(t.path,t.files,i):"json"in t?await this.processJson(t.json,i):(console.warn("Unknown source shape:",t),[]):(console.warn("Invalid source object:",t),[])}async processUrls(t,i){if(!Array.isArray(t))return console.warn("URLs must be an array:",t),[];const e=[];for(const n of t){const s=n.split("/").pop()||n;if(!i.isAllowed(s)){this.log(`Skipping filtered URL: ${n}`);continue}this.validateUrls?await this.validateUrl(n)?e.push(n):console.warn(`Skipping invalid/missing URL: ${n}`):e.push(n)}return e}async processPath(t,i,e){if(!Array.isArray(i))return console.warn("files must be an array:",i),[];const n=[];for(const s of i){if(!e.isAllowed(s)){this.log(`Skipping filtered file: ${s}`);continue}const r=this.constructUrl(t,s);this.validateUrls?await this.validateUrl(r)?n.push(r):console.warn(`Skipping invalid/missing file: ${r}`):n.push(r)}return n}async processJson(t,i){this.log(`Fetching JSON endpoint: ${t}`);const e=new AbortController,n=setTimeout(()=>e.abort(),1e4);try{const s=await fetch(t,{signal:e.signal});if(clearTimeout(n),!s.ok)throw new Error(`HTTP ${s.status} fetching ${t}`);const r=await s.json();if(!r||!Array.isArray(r.images))throw new Error('JSON source must return JSON with shape { "images": ["url1", "url2", ...] }');return this.log(`JSON endpoint returned ${r.images.length} image(s)`),await this.processUrls(r.images,i)}catch(s){throw clearTimeout(n),s instanceof Error&&s.name==="AbortError"?new Error(`Timeout fetching JSON endpoint: ${t}`):s}}async validateUrl(t){if(this.validationMethod==="none")return!0;if(this.validationMethod==="simple")try{return typeof window<"u"?new URL(t,window.location.origin):new URL(t),!0}catch{return!1}if(typeof window>"u")return!0;if(!(t.startsWith(window.location.origin)||t.startsWith("/")))return this.log(`Skipping validation for cross-origin URL: ${t}`),!0;try{const e=new AbortController,n=setTimeout(()=>e.abort(),this.validationTimeout),s=await fetch(t,{method:"HEAD",signal:e.signal});return clearTimeout(n),s.ok?!0:(this.log(`Validation failed for ${t}: HTTP ${s.status}`),!1)}catch(e){return e instanceof Error&&(e.name==="AbortError"?this.log(`Validation timeout for ${t}`):this.log(`Validation failed for ${t}:`,e.message)),!1}}constructUrl(t,i){const e=t.replace(/\/$/,"");if(this.isAbsoluteUrl(t))return`${e}/${i}`;if(typeof window>"u")return`${e}/${i}`;const n=window.location.origin,r=(t.startsWith("/")?t:"/"+t).replace(/\/$/,"");return`${n}${r}/${i}`}isAbsoluteUrl(t){try{return new URL(t),!0}catch{return!1}}log(...t){this.debugLogging&&typeof console<"u"&&console.log(...t)}}class Kt{constructor(t){if(this._prepared=!1,this._discoveredUrls=[],this.loaders=t.loaders,this.debugLogging=t.debugLogging??!1,!this.loaders||this.loaders.length===0)throw new Error("CompositeLoader requires at least one loader to be configured");this.log(`CompositeLoader initialized with ${this.loaders.length} loader(s)`)}async prepare(t){this._discoveredUrls=[],this.log(`Preparing ${this.loaders.length} loader(s) in parallel`);const i=this.loaders.map((e,n)=>e.prepare(t).then(()=>{this.log(`Loader ${n} prepared with ${e.imagesLength()} images`)}).catch(s=>{console.warn(`Loader ${n} failed to prepare:`,s)}));await Promise.all(i);for(const e of this.loaders)if(e.isPrepared()){const n=e.imageURLs();this._discoveredUrls.push(...n)}this._prepared=!0,this.log(`CompositeLoader prepared with ${this._discoveredUrls.length} total images`)}imagesLength(){if(!this._prepared)throw new Error("CompositeLoader.imagesLength() called before prepare()");return this._discoveredUrls.length}imageURLs(){if(!this._prepared)throw new Error("CompositeLoader.imageURLs() called before prepare()");return[...this._discoveredUrls]}isPrepared(){return this._prepared}log(...t){this.debugLogging&&typeof console<"u"&&console.log("[CompositeLoader]",...t)}}class Zt{constructor(t){this.allowedExtensions=t||["jpg","jpeg","png","gif","webp","bmp"]}isAllowed(t){const e=t.split("?")[0].split(".").pop()?.toLowerCase();return e?this.allowedExtensions.includes(e):!1}getAllowedExtensions(){return[...this.allowedExtensions]}}const Qt=`
4
+ 3. Consider adding a Google Drive API key in config.js for better reliability`)}}manualImageUrls(t){return t.map(i=>`https://drive.google.com/uc?export=view&id=${i}`)}log(...t){this.debugLogging&&typeof console<"u"&&console.log(...t)}}class Jt{constructor(t){if(this._prepared=!1,this._discoveredUrls=[],this.validateUrls=t.validateUrls!==!1,this.validationTimeout=t.validationTimeout??5e3,this.validationMethod=t.validationMethod??"head",this.debugLogging=t.debugLogging??!1,this.sources=t.sources??[],!this.sources||this.sources.length===0)throw new Error("StaticImageLoader requires at least one source to be configured");this.log("StaticImageLoader initialized with config:",t)}async prepare(t){this._discoveredUrls=[],this.log(`Processing ${this.sources.length} source(s)`);for(const i of this.sources)try{const e=await this.processSource(i,t);this._discoveredUrls.push(...e)}catch(e){console.warn("Failed to process source:",i,e)}this._prepared=!0,this.log(`Successfully loaded ${this._discoveredUrls.length} image(s)`)}imagesLength(){if(!this._prepared)throw new Error("StaticImageLoader.imagesLength() called before prepare()");return this._discoveredUrls.length}imageURLs(){if(!this._prepared)throw new Error("StaticImageLoader.imageURLs() called before prepare()");return[...this._discoveredUrls]}isPrepared(){return this._prepared}async processSource(t,i){return t?"urls"in t?await this.processUrls(t.urls,i):"path"in t?await this.processPath(t.path,t.files,i):"json"in t?await this.processJson(t.json,i):(console.warn("Unknown source shape:",t),[]):(console.warn("Invalid source object:",t),[])}async processUrls(t,i){if(!Array.isArray(t))return console.warn("URLs must be an array:",t),[];const e=[];for(const n of t){const s=n.split("/").pop()||n;if(!i.isAllowed(s)){this.log(`Skipping filtered URL: ${n}`);continue}this.validateUrls?await this.validateUrl(n)?e.push(n):console.warn(`Skipping invalid/missing URL: ${n}`):e.push(n)}return e}async processPath(t,i,e){if(!Array.isArray(i))return console.warn("files must be an array:",i),[];const n=[];for(const s of i){if(!e.isAllowed(s)){this.log(`Skipping filtered file: ${s}`);continue}const r=this.constructUrl(t,s);this.validateUrls?await this.validateUrl(r)?n.push(r):console.warn(`Skipping invalid/missing file: ${r}`):n.push(r)}return n}async processJson(t,i){this.log(`Fetching JSON endpoint: ${t}`);const e=new AbortController,n=setTimeout(()=>e.abort(),1e4);try{const s=await fetch(t,{signal:e.signal});if(clearTimeout(n),!s.ok)throw new Error(`HTTP ${s.status} fetching ${t}`);const r=await s.json();if(!r||!Array.isArray(r.images))throw new Error('JSON source must return JSON with shape { "images": ["url1", "url2", ...] }');return this.log(`JSON endpoint returned ${r.images.length} image(s)`),await this.processUrls(r.images,i)}catch(s){throw clearTimeout(n),s instanceof Error&&s.name==="AbortError"?new Error(`Timeout fetching JSON endpoint: ${t}`):s}}async validateUrl(t){if(this.validationMethod==="none")return!0;if(this.validationMethod==="simple")try{return typeof window<"u"?new URL(t,window.location.origin):new URL(t),!0}catch{return!1}if(typeof window>"u")return!0;if(!(t.startsWith(window.location.origin)||t.startsWith("/")))return this.log(`Skipping validation for cross-origin URL: ${t}`),!0;try{const e=new AbortController,n=setTimeout(()=>e.abort(),this.validationTimeout),s=await fetch(t,{method:"HEAD",signal:e.signal});return clearTimeout(n),s.ok?!0:(this.log(`Validation failed for ${t}: HTTP ${s.status}`),!1)}catch(e){return e instanceof Error&&(e.name==="AbortError"?this.log(`Validation timeout for ${t}`):this.log(`Validation failed for ${t}:`,e.message)),!1}}constructUrl(t,i){const e=t.replace(/\/$/,"");if(this.isAbsoluteUrl(t))return`${e}/${i}`;if(typeof window>"u")return`${e}/${i}`;const n=window.location.origin,r=(t.startsWith("/")?t:"/"+t).replace(/\/$/,"");return`${n}${r}/${i}`}isAbsoluteUrl(t){try{return new URL(t),!0}catch{return!1}}log(...t){this.debugLogging&&typeof console<"u"&&console.log(...t)}}class Kt{constructor(t){if(this._prepared=!1,this._discoveredUrls=[],this.loaders=t.loaders,this.debugLogging=t.debugLogging??!1,!this.loaders||this.loaders.length===0)throw new Error("CompositeLoader requires at least one loader to be configured");this.log(`CompositeLoader initialized with ${this.loaders.length} loader(s)`)}async prepare(t){this._discoveredUrls=[],this.log(`Preparing ${this.loaders.length} loader(s) in parallel`);const i=this.loaders.map((e,n)=>e.prepare(t).then(()=>{this.log(`Loader ${n} prepared with ${e.imagesLength()} images`)}).catch(s=>{console.warn(`Loader ${n} failed to prepare:`,s)}));await Promise.all(i);for(const e of this.loaders)if(e.isPrepared()){const n=e.imageURLs();this._discoveredUrls.push(...n)}this._prepared=!0,this.log(`CompositeLoader prepared with ${this._discoveredUrls.length} total images`)}imagesLength(){if(!this._prepared)throw new Error("CompositeLoader.imagesLength() called before prepare()");return this._discoveredUrls.length}imageURLs(){if(!this._prepared)throw new Error("CompositeLoader.imageURLs() called before prepare()");return[...this._discoveredUrls]}isPrepared(){return this._prepared}log(...t){this.debugLogging&&typeof console<"u"&&console.log("[CompositeLoader]",...t)}}class Zt{constructor(t){this.allowedExtensions=t||["jpg","jpeg","png","gif","webp","bmp"]}isAllowed(t){const e=t.split("?")[0].split(".").pop()?.toLowerCase();return e?this.allowedExtensions.includes(e):!1}getAllowedExtensions(){return[...this.allowedExtensions]}}const Qt=`
5
5
  .fbn-ic-gallery {
6
6
  position: relative;
7
7
  width: 100%;
@@ -81,5 +81,5 @@
81
81
  .fbn-ic-hidden {
82
82
  display: none !important;
83
83
  }
84
- `;function te(){if(typeof document>"u")return;const o="fbn-ic-functional-styles";if(document.getElementById(o))return;const t=document.createElement("style");t.id=o,t.textContent=Qt,document.head.appendChild(t)}class ee{constructor(t={}){this.fullConfig=me(t),t.container instanceof HTMLElement?(this.containerRef=t.container,this.containerId=null):(this.containerRef=null,this.containerId=t.container||"imageCloud"),this.imagesLoaded=!1,this.imageElements=[],this.imageLayouts=[],this.currentImageHeight=225,this.currentFocusIndex=null,this.hoveredImage=null,this.resizeTimeout=null,this.displayQueue=[],this.queueInterval=null,this.loadGeneration=0,this.loadingElAutoCreated=!1,this.errorElAutoCreated=!1,this.counterEl=null,this.counterElAutoCreated=!1,this.prevButtonEl=null,this.nextButtonEl=null,this.prevButtonElAutoCreated=!1,this.nextButtonElAutoCreated=!1,this.animationEngine=new Ot(this.fullConfig.animation),this.layoutEngine=new Wt({layout:this.fullConfig.layout,image:this.fullConfig.image}),this.zoomEngine=new Yt(this.fullConfig.interaction.focus,this.animationEngine,this.fullConfig.styling),this.defaultStyles=nt(this.fullConfig.styling?.default),this.defaultClassName=this.fullConfig.styling?.default?.className,this.hoverClassName=this.fullConfig.styling?.hover?.className;const i=this.fullConfig.animation.entry||C.animation.entry;this.entryAnimationEngine=new Pt(i,this.fullConfig.layout.algorithm);const e=this.fullConfig.animation.idle;e&&e.type!=="none"?this.idleAnimationEngine=new Te(e,i.timing?.duration??600):this.idleAnimationEngine=null,this.zoomEngine.setOnUnfocusCompleteCallback(n=>{this.idleAnimationEngine?.resumeForImage(n);const s=n;requestAnimationFrame(()=>{if(s.matches(":hover")&&this.fullConfig.styling?.hover){const r=this.imageElements.indexOf(s);if(r!==-1){const a=s.offsetHeight,c=s.cachedRenderedWidth;at(s,this.fullConfig.styling.hover,a,c),ot(s,this.hoverClassName),this.hoveredImage={element:s,layout:this.imageLayouts[r]}}}})}),this.swipeEngine=null,this.imageFilter=this.createImageFilter(),this.imageLoader=this.createLoader(),this.containerEl=null,this.loadingEl=null,this.errorEl=null}createImageFilter(){const t=this.fullConfig.config.loaders?.allowedExtensions;return new Zt(t)}createLoader(){const t=this.fullConfig.loaders,i=this.fullConfig.config.loaders??{};if(!t||t.length===0)throw new Error("No loaders configured. Provide `images`, `loaders`, or both.\n Example: imageCloud({ container: 'id', images: ['https://...'] })");const e=t.map(n=>this.createLoaderFromEntry(n,i));return e.length===1?e[0]:new Kt({loaders:e,debugLogging:this.fullConfig.config.debug?.loaders})}createLoaderFromEntry(t,i){if("static"in t){const e=t.static,n={...e,validateUrls:e.validateUrls??i.validateUrls,validationTimeout:e.validationTimeout??i.validationTimeout,validationMethod:e.validationMethod??i.validationMethod,allowedExtensions:e.allowedExtensions??i.allowedExtensions,debugLogging:e.debugLogging??this.fullConfig.config.debug?.loaders};return new Vt(n)}else if("googleDrive"in t){const e=t.googleDrive,n={...e,allowedExtensions:e.allowedExtensions??i.allowedExtensions,debugLogging:e.debugLogging??this.fullConfig.config.debug?.loaders};return new Jt(n)}else throw new Error(`Unknown loader entry: ${JSON.stringify(t)}`)}async init(){try{if(te(),this.containerRef)this.containerEl=this.containerRef;else if(this.containerEl=document.getElementById(this.containerId),!this.containerEl)throw new Error(`Container "#${this.containerId}" not found. Ensure an element with id="${this.containerId}" exists in the DOM before calling imageCloud().`);this.containerEl.classList.add("fbn-ic-gallery"),this.containerEl.setAttribute("tabindex","0"),this.fullConfig.interaction.navigation?.swipe!==!1&&(this.swipeEngine=new Et(this.containerEl,{onNext:()=>this.navigateToNextImage(),onPrev:()=>this.navigateToPreviousImage(),onDragOffset:t=>this.zoomEngine.setDragOffset(t),onDragEnd:t=>{t?this.zoomEngine.clearDragOffset(!1):this.zoomEngine.clearDragOffset(!0,Je)}})),this.setupUI(),this.setupEventListeners(),this.logDebug("ImageCloud initialized"),await this.loadImages()}catch(t){console.error(`ImageCloud initialization failed (container: "${this.containerId??"element"}"):`,t),this.errorEl&&t instanceof Error&&this.showError("Gallery failed to initialize: "+t.message)}}setupUI(){const t=this.fullConfig.ui;t.showFocusOutline?this.containerEl?.classList.remove("fbn-ic-suppress-outline"):this.containerEl?.classList.add("fbn-ic-suppress-outline"),t.showLoadingSpinner&&(t.loadingElement?(this.loadingEl=this.resolveElement(t.loadingElement),this.loadingElAutoCreated=!1):(this.loadingEl=this.createDefaultLoadingElement(),this.loadingElAutoCreated=!0)),t.errorElement?(this.errorEl=this.resolveElement(t.errorElement),this.errorElAutoCreated=!1):(this.errorEl=this.createDefaultErrorElement(),this.errorElAutoCreated=!0),t.showImageCounter&&(t.counterElement?(this.counterEl=this.resolveElement(t.counterElement),this.counterElAutoCreated=!1):(this.counterEl=this.createDefaultCounterElement(),this.counterElAutoCreated=!0)),t.showNavButtons&&(t.prevButtonElement?(this.prevButtonEl=this.resolveElement(t.prevButtonElement),this.prevButtonElAutoCreated=!1):(this.prevButtonEl=this.createDefaultPrevButtonElement(),this.prevButtonElAutoCreated=!0),t.nextButtonElement?(this.nextButtonEl=this.resolveElement(t.nextButtonElement),this.nextButtonElAutoCreated=!1):(this.nextButtonEl=this.createDefaultNextButtonElement(),this.nextButtonElAutoCreated=!0),this.prevButtonEl?.addEventListener("click",i=>{i.stopPropagation(),this.navigateToPreviousImage()}),this.nextButtonEl?.addEventListener("click",i=>{i.stopPropagation(),this.navigateToNextImage()}))}resolveElement(t){return t instanceof HTMLElement?t:document.getElementById(t)}createDefaultLoadingElement(){const t=document.createElement("div");t.className="fbn-ic-loading fbn-ic-hidden";const i=document.createElement("div");i.className="fbn-ic-spinner",t.appendChild(i);const e=document.createElement("p");return e.textContent="Loading images...",t.appendChild(e),this.containerEl.appendChild(t),t}createDefaultErrorElement(){const t=document.createElement("div");return t.className="fbn-ic-error fbn-ic-hidden",this.containerEl.appendChild(t),t}createDefaultCounterElement(){const t=document.createElement("div");return t.className="fbn-ic-counter fbn-ic-hidden",this.containerEl.appendChild(t),t}createDefaultPrevButtonElement(){const t=document.createElement("button");return t.className="fbn-ic-nav-btn fbn-ic-nav-btn-prev fbn-ic-hidden",t.textContent="‹",t.setAttribute("aria-label","Previous image"),t.setAttribute("tabindex","-1"),this.containerEl.appendChild(t),t}createDefaultNextButtonElement(){const t=document.createElement("button");return t.className="fbn-ic-nav-btn fbn-ic-nav-btn-next fbn-ic-hidden",t.textContent="›",t.setAttribute("aria-label","Next image"),t.setAttribute("tabindex","-1"),this.containerEl.appendChild(t),t}setupEventListeners(){this.fullConfig.interaction.navigation?.keyboard!==!1&&this.containerEl.addEventListener("keydown",t=>{t.key==="Escape"?(this.zoomEngine.unfocusImage(),this.currentFocusIndex=null,this.swipeEngine?.disable(),this.hideCounter(),this.hideNavButtons(),this.hideFocusIndicator()):t.key==="ArrowRight"?this.navigateToNextImage():t.key==="ArrowLeft"?this.navigateToPreviousImage():(t.key==="Enter"||t.key===" ")&&this.hoveredImage&&(this.handleImageClick(this.hoveredImage.element,this.hoveredImage.layout),t.preventDefault())}),document.addEventListener("click",t=>{this.swipeEngine?.hadRecentTouch()||!t.target.closest(".fbn-ic-image")&&!t.target.closest(".fbn-ic-nav-btn")&&(this.zoomEngine.unfocusImage(),this.currentFocusIndex=null,this.swipeEngine?.disable(),this.hideCounter(),this.hideNavButtons(),this.hideFocusIndicator())}),window.addEventListener("resize",()=>this.handleResize())}navigateToNextImage(){if(this.currentFocusIndex===null||this.imageElements.length===0)return;const t=(this.currentFocusIndex+1)%this.imageLayouts.length,i=this.imageElements.find(n=>n.dataset.imageId===String(t));if(!i)return;const e=this.imageLayouts[t];e&&(this.currentFocusIndex=t,this.handleImageClick(i,e),this.updateCounter(t),this.showNavButtons(),this.showFocusIndicator())}navigateToPreviousImage(){if(this.currentFocusIndex===null||this.imageElements.length===0)return;const t=(this.currentFocusIndex-1+this.imageLayouts.length)%this.imageLayouts.length,i=this.imageElements.find(n=>n.dataset.imageId===String(t));if(!i)return;const e=this.imageLayouts[t];e&&(this.currentFocusIndex=t,this.handleImageClick(i,e),this.updateCounter(t),this.showNavButtons(),this.showFocusIndicator())}handleResize(){this.imagesLoaded&&(this.resizeTimeout!==null&&clearTimeout(this.resizeTimeout),this.resizeTimeout=window.setTimeout(()=>{const t=this.getImageHeight();t!==this.currentImageHeight?(this.logDebug(`Window resized to new breakpoint (height: ${t}px). Reloading images...`),this.loadImages()):this.logDebug("Window resized (no breakpoint change)")},500))}getImageHeight(){const t=window.innerWidth,i=this.fullConfig.layout.responsive,n=this.fullConfig.image.sizing?.maxSize??400;return i?t<=i.mobile.maxWidth?Math.min(100,n):t<=i.tablet.maxWidth?Math.min(180,n):Math.min(225,n):t<=767?Math.min(100,n):t<=1199?Math.min(180,n):Math.min(225,n)}getContainerBounds(){return this.containerEl?{width:this.containerEl.offsetWidth,height:this.containerEl.offsetHeight||window.innerHeight*.7}:{width:window.innerWidth,height:window.innerHeight*.7}}async loadImages(){try{this.showLoading(!0),this.hideError(),this.clearImageCloud(),await this.imageLoader.prepare(this.imageFilter);const t=this.imageLoader.imagesLength();let i=this.imageLoader.imageURLs();if(t===0){this.showError("No images found."),this.showLoading(!1);return}const e=this.getContainerBounds(),n=this.getImageHeight(),s=window.innerWidth;this.logDebug(`Adaptive sizing input: container=${e.width}x${e.height}px, images=${t}, responsiveMax=${n}px`);const r=this.layoutEngine.calculateAdaptiveSize(e,t,n,s);this.logDebug(`Adaptive sizing result: height=${r.height}px`),await this.createImageCloud(i,r.height),this.showLoading(!1),this.imagesLoaded=!0}catch(t){console.error("Error loading images:",t),t instanceof Error&&this.showError(t.message||"Failed to load images."),this.showLoading(!1)}}logDebug(...t){this.fullConfig.config.debug?.enabled&&typeof console<"u"&&console.log(...t)}async createImageCloud(t,i){if(!this.containerEl)return;const e=this.getContainerBounds();this.currentImageHeight=i;const n=this.loadGeneration,s=this.layoutEngine.generateLayout(t.length,e,{fixedHeight:i});this.imageLayouts=s,this.displayQueue=[];let r=0;const a=l=>{this.containerEl&&(this.containerEl.appendChild(l),this.imageElements.push(l),requestAnimationFrame(()=>{if(l.offsetWidth,l.style.opacity=this.defaultStyles.opacity??"1",l.dataset.startX&&(this.entryAnimationEngine.requiresJSAnimation()||this.entryAnimationEngine.requiresJSRotation()||this.entryAnimationEngine.requiresJSScale()||l.dataset.startRotation!==l.dataset.rotation||l.dataset.startScale!==l.dataset.scale)){const d={x:parseFloat(l.dataset.startX),y:parseFloat(l.dataset.startY)},g={x:parseFloat(l.dataset.endX),y:parseFloat(l.dataset.endY)},p=parseFloat(l.dataset.imageWidth),b=parseFloat(l.dataset.imageHeight),f=parseFloat(l.dataset.rotation),m=parseFloat(l.dataset.scale),y=l.dataset.startRotation?parseFloat(l.dataset.startRotation):f,E=l.dataset.startScale?parseFloat(l.dataset.startScale):m,v=this.entryAnimationEngine.getTiming();zt({element:l,startPosition:d,endPosition:g,pathConfig:this.entryAnimationEngine.getPathConfig(),duration:v.duration,imageWidth:p,imageHeight:b,rotation:f,scale:m,rotationConfig:this.entryAnimationEngine.getRotationConfig(),startRotation:y,scaleConfig:this.entryAnimationEngine.getScaleConfig(),startScale:E})}else{const d=l.dataset.finalTransform||"";l.style.transform=d}const h=parseInt(l.dataset.imageId||"0");if(this.fullConfig.config.debug?.enabled&&h<3){const d=l.dataset.finalTransform||"";console.log(`Image ${h} final state:`,{left:l.style.left,top:l.style.top,width:l.style.width,height:l.style.height,computedWidth:l.offsetWidth,computedHeight:l.offsetHeight,transform:d,pathType:this.entryAnimationEngine.getPathType()})}if(this.idleAnimationEngine){const d=this.entryAnimationEngine.getTiming().duration;this.idleAnimationEngine.register(l,h,this.imageElements.length,d)}}),r++)},c=()=>{if(this.logDebug("Starting queue processing, enabled:",this.fullConfig.animation.queue.enabled),!this.fullConfig.animation.queue.enabled){for(;this.displayQueue.length>0;){const l=this.displayQueue.shift();l&&a(l)}return}this.queueInterval!==null&&clearInterval(this.queueInterval),this.queueInterval=window.setInterval(()=>{if(n!==this.loadGeneration){this.queueInterval!==null&&(clearInterval(this.queueInterval),this.queueInterval=null);return}if(this.displayQueue.length>0){const l=this.displayQueue.shift();l&&a(l)}r>=t.length&&this.displayQueue.length===0&&this.queueInterval!==null&&(clearInterval(this.queueInterval),this.queueInterval=null)},this.fullConfig.animation.queue.interval)};if("IntersectionObserver"in window&&this.containerEl){const l=new IntersectionObserver(u=>{u.forEach(h=>{h.isIntersecting&&(c(),l.disconnect())})},{threshold:.1,rootMargin:"50px"});l.observe(this.containerEl)}else c();this.fullConfig.config.debug?.centers&&this.containerEl&&(this.containerEl.querySelectorAll(".fbn-ic-debug-center").forEach(l=>l.remove()),s.forEach((l,u)=>{const h=document.createElement("div");h.className="fbn-ic-debug-center",h.style.position="absolute",h.style.width="12px",h.style.height="12px",h.style.borderRadius="50%",h.style.backgroundColor="red",h.style.border="2px solid yellow",h.style.zIndex="9999",h.style.pointerEvents="none";const d=l.x,g=l.y;h.style.left=`${d-6}px`,h.style.top=`${g-6}px`,h.title=`Image ${u}: center (${Math.round(d)}, ${Math.round(g)})`,this.containerEl.appendChild(h)})),t.forEach((l,u)=>{const h=document.createElement("img");h.referrerPolicy="no-referrer",h.classList.add("fbn-ic-image"),this.fullConfig.interaction.dragging===!1&&(h.draggable=!1),h.dataset.imageId=String(u),h.dataset.createdFlag="true";const d=s[u];h.style.position="absolute",h.style.width="auto",h.style.height=`${i}px`,h.style.left=`${d.x}px`,h.style.top=`${d.y}px`,d.zIndex&&(h.style.zIndex=String(d.zIndex)),ot(h,this.defaultClassName),h.addEventListener("mouseenter",()=>{if(this.hoveredImage={element:h,layout:d},!this.zoomEngine.isInvolved(h)){const g=h.cachedRenderedWidth;at(h,this.fullConfig.styling?.hover,i,g),ot(h,this.hoverClassName)}}),h.addEventListener("mouseleave",()=>{if(this.hoveredImage=null,!this.zoomEngine.isInvolved(h)){const g=h.cachedRenderedWidth;at(h,this.fullConfig.styling?.default,i,g),vt(h,this.hoverClassName),ot(h,this.defaultClassName)}}),h.addEventListener("click",g=>{g.stopPropagation(),this.handleImageClick(h,d)}),h.style.opacity="0",h.style.transition=this.entryAnimationEngine.getTransitionCSS(),h.onload=()=>{if(n!==this.loadGeneration)return;const g=h.naturalWidth/h.naturalHeight,p=i*g;h.dataset.onloadCalled="true",window.DEBUG_CLIPPATH&&console.log(`[onload #${u}] Called with imageHeight=${i}, renderedWidth=${p}`),h.style.width=`${p}px`,h.cachedRenderedWidth=p,h.aspectRatio=g,at(h,this.fullConfig.styling?.default,i,p);const b={x:d.x,y:d.y},f={width:p,height:i},m=this.entryAnimationEngine.calculateStartPosition(b,f,e,u,t.length),y=this.entryAnimationEngine.calculateStartRotation(d.rotation),E=this.entryAnimationEngine.calculateStartScale(d.scale),v=this.entryAnimationEngine.buildFinalTransform(d.rotation,d.scale,p,i),I=this.entryAnimationEngine.buildStartTransform(m,b,d.rotation,d.scale,p,i,y,E);this.fullConfig.config.debug?.enabled&&u<3&&console.log(`Image ${u}:`,{finalPosition:b,imageSize:f,left:d.x,top:d.y,finalTransform:v,renderedWidth:p,renderedHeight:i}),h.style.transform=I,h.dataset.finalTransform=v,(this.entryAnimationEngine.requiresJSAnimation()||this.entryAnimationEngine.requiresJSRotation()||this.entryAnimationEngine.requiresJSScale()||y!==d.rotation||E!==d.scale)&&(h.dataset.startX=String(m.x),h.dataset.startY=String(m.y),h.dataset.endX=String(b.x),h.dataset.endY=String(b.y),h.dataset.imageWidth=String(p),h.dataset.imageHeight=String(i),h.dataset.rotation=String(d.rotation),h.dataset.scale=String(d.scale),h.dataset.startRotation=String(y),h.dataset.startScale=String(E)),this.displayQueue.push(h)},h.onerror=()=>r++,h.src=l})}async handleImageClick(t,i){if(!this.containerEl)return;const e=this.zoomEngine.isFocused(t),n={width:this.containerEl.offsetWidth,height:this.containerEl.offsetHeight};if(e)await this.zoomEngine.unfocusImage(),this.currentFocusIndex=null,this.swipeEngine?.disable(),this.hideCounter(),this.hideNavButtons(),this.hideFocusIndicator();else{this.idleAnimationEngine?.pauseForImage(t);const s=t.dataset.imageId;this.currentFocusIndex=s!==void 0?parseInt(s,10):null,this.swipeEngine?.enable(),this.containerEl?.focus({preventScroll:!0}),await this.zoomEngine.focusImage(t,n,i),this.currentFocusIndex!==null&&this.updateCounter(this.currentFocusIndex),this.showNavButtons(),this.showFocusIndicator()}}clearImageCloud(){this.queueInterval!==null&&(clearInterval(this.queueInterval),this.queueInterval=null),this.loadGeneration++,this.displayQueue=[],this.hideFocusIndicator(),this.containerEl&&this.containerEl.querySelectorAll(".fbn-ic-image, .fbn-ic-debug-center").forEach(t=>t.remove()),this.imageElements=[],this.imageLayouts=[],this.currentFocusIndex=null,this.hoveredImage=null,this.layoutEngine.reset(),this.zoomEngine.reset(),this.idleAnimationEngine?.stopAll(),this.imagesLoaded=!1}showLoading(t){!this.fullConfig.ui.showLoadingSpinner||!this.loadingEl||(t?this.loadingEl.classList.remove("fbn-ic-hidden"):this.loadingEl.classList.add("fbn-ic-hidden"))}showError(t){this.errorEl&&(this.errorEl.textContent=t,this.errorEl.classList.remove("fbn-ic-hidden"))}hideError(){this.errorEl&&this.errorEl.classList.add("fbn-ic-hidden")}updateCounter(t){!this.fullConfig.ui.showImageCounter||!this.counterEl||(this.counterEl.textContent=`${t+1} of ${this.imageElements.length}`,this.counterEl.classList.remove("fbn-ic-hidden"))}hideCounter(){this.counterEl&&this.counterEl.classList.add("fbn-ic-hidden")}showFocusIndicator(){this.containerEl?.classList.add("fbn-ic-has-focus")}hideFocusIndicator(){this.containerEl?.classList.remove("fbn-ic-has-focus")}showNavButtons(){this.prevButtonEl?.classList.remove("fbn-ic-hidden"),this.nextButtonEl?.classList.remove("fbn-ic-hidden")}hideNavButtons(){this.prevButtonEl?.classList.add("fbn-ic-hidden"),this.nextButtonEl?.classList.add("fbn-ic-hidden")}destroy(){this.clearImageCloud(),this.loadingElAutoCreated&&this.loadingEl&&(this.loadingEl.remove(),this.loadingEl=null),this.errorElAutoCreated&&this.errorEl&&(this.errorEl.remove(),this.errorEl=null),this.counterElAutoCreated&&this.counterEl&&(this.counterEl.remove(),this.counterEl=null),this.prevButtonElAutoCreated&&this.prevButtonEl&&(this.prevButtonEl.remove(),this.prevButtonEl=null),this.nextButtonElAutoCreated&&this.nextButtonEl&&(this.nextButtonEl.remove(),this.nextButtonEl=null),this.resizeTimeout!==null&&clearTimeout(this.resizeTimeout),this.swipeEngine?.destroy(),this.idleAnimationEngine?.stopAll(),this.idleAnimationEngine=null}}async function Ke(o){const t=new ee(o);return await t.init(),t}S.AnimationEngine=Ot,S.BOUNCE_PRESETS=ht,S.ClusterPlacementLayout=kt,S.CompositeLoader=Kt,S.DEFAULT_CONFIG=C,S.DEFAULT_SHARED_LOADER_CONFIG=pt,S.ELASTIC_PRESETS=dt,S.EntryAnimationEngine=Pt,S.FUNCTIONAL_CSS=Qt,S.GoogleDriveLoader=Jt,S.GridPlacementLayout=Ht,S.HoneycombPlacementLayout=jt,S.ImageCloud=ee,S.ImageFilter=Zt,S.LayoutEngine=Wt,S.RadialPlacementLayout=_t,S.RandomPlacementLayout=$t,S.SpiralPlacementLayout=Nt,S.StaticImageLoader=Vt,S.WAVE_PATH_PRESETS=ut,S.WavePlacementLayout=Bt,S.ZoomEngine=Yt,S.animatePath=zt,S.imageCloud=Ke,S.injectFunctionalStyles=te,S.requiresJSAnimation=Dt,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})}));
84
+ `;function te(){if(typeof document>"u")return;const o="fbn-ic-functional-styles";if(document.getElementById(o))return;const t=document.createElement("style");t.id=o,t.textContent=Qt,document.head.appendChild(t)}class ee{constructor(t={}){this.fullConfig=me(t),t.container instanceof HTMLElement?(this.containerRef=t.container,this.containerId=null):(this.containerRef=null,this.containerId=t.container||"imageCloud"),this.callbacks=t.on??{},this.imagesLoaded=!1,this.imageElements=[],this.imageLayouts=[],this.currentImageHeight=225,this.currentFocusIndex=null,this.hoveredImage=null,this.resizeTimeout=null,this.displayQueue=[],this.queueInterval=null,this.loadGeneration=0,this.loadingElAutoCreated=!1,this.errorElAutoCreated=!1,this.counterEl=null,this.counterElAutoCreated=!1,this.prevButtonEl=null,this.nextButtonEl=null,this.prevButtonElAutoCreated=!1,this.nextButtonElAutoCreated=!1,this.animationEngine=new Ot(this.fullConfig.animation),this.layoutEngine=new Wt({layout:this.fullConfig.layout,image:this.fullConfig.image}),this.zoomEngine=new Xt(this.fullConfig.interaction.focus,this.animationEngine,this.fullConfig.styling),this.defaultStyles=nt(this.fullConfig.styling?.default),this.defaultClassName=this.fullConfig.styling?.default?.className,this.hoverClassName=this.fullConfig.styling?.hover?.className;const i=this.fullConfig.animation.entry||R.animation.entry;this.entryAnimationEngine=new Pt(i,this.fullConfig.layout.algorithm);const e=this.fullConfig.animation.idle;e&&e.type!=="none"?this.idleAnimationEngine=new Re(e,i.timing?.duration??600):this.idleAnimationEngine=null,this.zoomEngine.setOnUnfocusCompleteCallback(n=>{this.idleAnimationEngine?.resumeForImage(n);const s=n,r=this.imageElements.indexOf(s);if(this.callbacks.onImageUnfocus&&r!==-1){const a=this.imageLoader.imageURLs(),c={element:s,index:r,url:a[r]??"",layout:this.imageLayouts[r]};this.callbacks.onImageUnfocus(c)}requestAnimationFrame(()=>{if(s.matches(":hover")&&this.fullConfig.styling?.hover){const a=this.imageElements.indexOf(s);if(a!==-1){const c=s.offsetHeight,d=s.cachedRenderedWidth;at(s,this.fullConfig.styling.hover,c,d),ot(s,this.hoverClassName),this.hoveredImage={element:s,layout:this.imageLayouts[a]}}}})}),this.swipeEngine=null,this.imageFilter=this.createImageFilter(),this.imageLoader=this.createLoader(),this.containerEl=null,this.loadingEl=null,this.errorEl=null}createImageFilter(){const t=this.fullConfig.config.loaders?.allowedExtensions;return new Zt(t)}createLoader(){const t=this.fullConfig.loaders,i=this.fullConfig.config.loaders??{};if(!t||t.length===0)throw new Error("No loaders configured. Provide `images`, `loaders`, or both.\n Example: imageCloud({ container: 'id', images: ['https://...'] })");const e=t.map(n=>this.createLoaderFromEntry(n,i));return e.length===1?e[0]:new Kt({loaders:e,debugLogging:this.fullConfig.config.debug?.loaders})}createLoaderFromEntry(t,i){if("static"in t){const e=t.static,n={...e,validateUrls:e.validateUrls??i.validateUrls,validationTimeout:e.validationTimeout??i.validationTimeout,validationMethod:e.validationMethod??i.validationMethod,allowedExtensions:e.allowedExtensions??i.allowedExtensions,debugLogging:e.debugLogging??this.fullConfig.config.debug?.loaders};return new Jt(n)}else if("googleDrive"in t){const e=t.googleDrive,n={...e,allowedExtensions:e.allowedExtensions??i.allowedExtensions,debugLogging:e.debugLogging??this.fullConfig.config.debug?.loaders};return new Vt(n)}else throw new Error(`Unknown loader entry: ${JSON.stringify(t)}`)}async init(){try{if(te(),this.containerRef)this.containerEl=this.containerRef;else if(this.containerEl=document.getElementById(this.containerId),!this.containerEl)throw new Error(`Container "#${this.containerId}" not found. Ensure an element with id="${this.containerId}" exists in the DOM before calling imageCloud().`);this.containerEl.classList.add("fbn-ic-gallery"),this.containerEl.setAttribute("tabindex","0"),this.fullConfig.interaction.navigation?.swipe!==!1&&(this.swipeEngine=new Et(this.containerEl,{onNext:()=>this.navigateToNextImage(),onPrev:()=>this.navigateToPreviousImage(),onDragOffset:t=>this.zoomEngine.setDragOffset(t),onDragEnd:t=>{t?this.zoomEngine.clearDragOffset(!1):this.zoomEngine.clearDragOffset(!0,Ve)}})),this.setupUI(),this.setupEventListeners(),this.logDebug("ImageCloud initialized"),await this.loadImages()}catch(t){console.error(`ImageCloud initialization failed (container: "${this.containerId??"element"}"):`,t),this.errorEl&&t instanceof Error&&this.showError("Gallery failed to initialize: "+t.message)}}setupUI(){const t=this.fullConfig.ui;t.showFocusOutline?this.containerEl?.classList.remove("fbn-ic-suppress-outline"):this.containerEl?.classList.add("fbn-ic-suppress-outline"),t.showLoadingSpinner&&(t.loadingElement?(this.loadingEl=this.resolveElement(t.loadingElement),this.loadingElAutoCreated=!1):(this.loadingEl=this.createDefaultLoadingElement(),this.loadingElAutoCreated=!0)),t.errorElement?(this.errorEl=this.resolveElement(t.errorElement),this.errorElAutoCreated=!1):(this.errorEl=this.createDefaultErrorElement(),this.errorElAutoCreated=!0),t.showImageCounter&&(t.counterElement?(this.counterEl=this.resolveElement(t.counterElement),this.counterElAutoCreated=!1):(this.counterEl=this.createDefaultCounterElement(),this.counterElAutoCreated=!0)),t.showNavButtons&&(t.prevButtonElement?(this.prevButtonEl=this.resolveElement(t.prevButtonElement),this.prevButtonElAutoCreated=!1):(this.prevButtonEl=this.createDefaultPrevButtonElement(),this.prevButtonElAutoCreated=!0),t.nextButtonElement?(this.nextButtonEl=this.resolveElement(t.nextButtonElement),this.nextButtonElAutoCreated=!1):(this.nextButtonEl=this.createDefaultNextButtonElement(),this.nextButtonElAutoCreated=!0),this.prevButtonEl?.addEventListener("click",i=>{i.stopPropagation(),this.navigateToPreviousImage()}),this.nextButtonEl?.addEventListener("click",i=>{i.stopPropagation(),this.navigateToNextImage()}))}resolveElement(t){return t instanceof HTMLElement?t:document.getElementById(t)}createDefaultLoadingElement(){const t=document.createElement("div");t.className="fbn-ic-loading fbn-ic-hidden";const i=document.createElement("div");i.className="fbn-ic-spinner",t.appendChild(i);const e=document.createElement("p");return e.textContent="Loading images...",t.appendChild(e),this.containerEl.appendChild(t),t}createDefaultErrorElement(){const t=document.createElement("div");return t.className="fbn-ic-error fbn-ic-hidden",this.containerEl.appendChild(t),t}createDefaultCounterElement(){const t=document.createElement("div");return t.className="fbn-ic-counter fbn-ic-hidden",this.containerEl.appendChild(t),t}createDefaultPrevButtonElement(){const t=document.createElement("button");return t.className="fbn-ic-nav-btn fbn-ic-nav-btn-prev fbn-ic-hidden",t.textContent="‹",t.setAttribute("aria-label","Previous image"),t.setAttribute("tabindex","-1"),this.containerEl.appendChild(t),t}createDefaultNextButtonElement(){const t=document.createElement("button");return t.className="fbn-ic-nav-btn fbn-ic-nav-btn-next fbn-ic-hidden",t.textContent="›",t.setAttribute("aria-label","Next image"),t.setAttribute("tabindex","-1"),this.containerEl.appendChild(t),t}setupEventListeners(){this.fullConfig.interaction.navigation?.keyboard!==!1&&this.containerEl.addEventListener("keydown",t=>{t.key==="Escape"?(this.zoomEngine.unfocusImage(),this.currentFocusIndex=null,this.swipeEngine?.disable(),this.hideCounter(),this.hideNavButtons(),this.hideFocusIndicator()):t.key==="ArrowRight"?this.navigateToNextImage():t.key==="ArrowLeft"?this.navigateToPreviousImage():(t.key==="Enter"||t.key===" ")&&this.hoveredImage&&(this.handleImageClick(this.hoveredImage.element,this.hoveredImage.layout),t.preventDefault())}),document.addEventListener("click",t=>{this.swipeEngine?.hadRecentTouch()||!t.target.closest(".fbn-ic-image")&&!t.target.closest(".fbn-ic-nav-btn")&&(this.zoomEngine.unfocusImage(),this.currentFocusIndex=null,this.swipeEngine?.disable(),this.hideCounter(),this.hideNavButtons(),this.hideFocusIndicator())}),window.addEventListener("resize",()=>this.handleResize())}navigateToNextImage(){if(this.currentFocusIndex===null||this.imageElements.length===0)return;const t=(this.currentFocusIndex+1)%this.imageLayouts.length,i=this.imageElements.find(n=>n.dataset.imageId===String(t));if(!i)return;const e=this.imageLayouts[t];e&&(this.currentFocusIndex=t,this.handleImageClick(i,e),this.updateCounter(t),this.showNavButtons(),this.showFocusIndicator())}navigateToPreviousImage(){if(this.currentFocusIndex===null||this.imageElements.length===0)return;const t=(this.currentFocusIndex-1+this.imageLayouts.length)%this.imageLayouts.length,i=this.imageElements.find(n=>n.dataset.imageId===String(t));if(!i)return;const e=this.imageLayouts[t];e&&(this.currentFocusIndex=t,this.handleImageClick(i,e),this.updateCounter(t),this.showNavButtons(),this.showFocusIndicator())}handleResize(){this.imagesLoaded&&(this.resizeTimeout!==null&&clearTimeout(this.resizeTimeout),this.resizeTimeout=window.setTimeout(()=>{const t=this.getImageHeight();t!==this.currentImageHeight?(this.logDebug(`Window resized to new breakpoint (height: ${t}px). Reloading images...`),this.loadImages()):this.logDebug("Window resized (no breakpoint change)")},500))}getImageHeight(){const t=window.innerWidth,i=this.fullConfig.layout.responsive,n=this.fullConfig.image.sizing?.maxSize??400;return i?t<=i.mobile.maxWidth?Math.min(100,n):t<=i.tablet.maxWidth?Math.min(180,n):Math.min(225,n):t<=767?Math.min(100,n):t<=1199?Math.min(180,n):Math.min(225,n)}getContainerBounds(){return this.containerEl?{width:this.containerEl.offsetWidth,height:this.containerEl.offsetHeight||window.innerHeight*.7}:{width:window.innerWidth,height:window.innerHeight*.7}}async loadImages(){try{this.showLoading(!0),this.hideError(),this.clearImageCloud(),await this.imageLoader.prepare(this.imageFilter);const t=this.imageLoader.imagesLength();let i=this.imageLoader.imageURLs();if(t===0){this.showError("No images found."),this.showLoading(!1);return}const e=this.getContainerBounds(),n=this.getImageHeight(),s=window.innerWidth;this.logDebug(`Adaptive sizing input: container=${e.width}x${e.height}px, images=${t}, responsiveMax=${n}px`);const r=this.layoutEngine.calculateAdaptiveSize(e,t,n,s);this.logDebug(`Adaptive sizing result: height=${r.height}px`),await this.createImageCloud(i,r.height),this.showLoading(!1),this.imagesLoaded=!0}catch(t){console.error("Error loading images:",t),t instanceof Error&&this.showError(t.message||"Failed to load images."),this.showLoading(!1)}}logDebug(...t){this.fullConfig.config.debug?.enabled&&typeof console<"u"&&console.log(...t)}async createImageCloud(t,i){if(!this.containerEl)return;const e=this.getContainerBounds();this.currentImageHeight=i;const n=this.loadGeneration,s=this.layoutEngine.generateLayout(t.length,e,{fixedHeight:i});if(this.imageLayouts=s,this.callbacks.onLayoutComplete){const l={layouts:[...s],containerBounds:{...e},algorithm:this.fullConfig.layout.algorithm,imageCount:t.length};this.callbacks.onLayoutComplete(l)}this.displayQueue=[];let r=0,a=0,c=0,d=0,u=!1;const f=new Map,m=()=>{if(u||n!==this.loadGeneration||!this.callbacks.onGalleryReady)return;u=!0;const l={totalImages:t.length,failedImages:c,loadDuration:d>0?performance.now()-d:0};this.callbacks.onGalleryReady(l)},p=()=>{r>=t.length&&this.displayQueue.length===0&&m()},x=l=>{this.containerEl&&(this.containerEl.appendChild(l),this.imageElements.push(l),requestAnimationFrame(async()=>{l.offsetWidth,l.style.opacity=this.defaultStyles.opacity??"1";const g=parseInt(l.dataset.imageId||"0"),h=this.imageLayouts[g],b=this.entryAnimationEngine.getTiming(),I=performance.now(),y=parseFloat(l.dataset.startX||"0"),E=parseFloat(l.dataset.startY||"0"),w=parseFloat(l.dataset.endX||"0"),M=parseFloat(l.dataset.endY||"0"),A=parseFloat(l.dataset.rotation||"0"),O=parseFloat(l.dataset.scale||"1"),L=parseFloat(l.dataset.startRotation||l.dataset.rotation||"0"),D=parseFloat(l.dataset.startScale||l.dataset.scale||"1"),H=parseFloat(l.dataset.imageWidth||"0"),P=parseFloat(l.dataset.imageHeight||"0");if(this.callbacks.onEntryStart&&h){const C={element:l,index:g,totalImages:this.imageLayouts.length,layout:h,from:{x:y,y:E,rotation:L,scale:D},to:{x:w,y:M,rotation:A,scale:O},startTime:I,duration:b.duration};this.callbacks.onEntryStart(C)}if(this.entryAnimationEngine.requiresJSAnimation()||this.entryAnimationEngine.requiresJSRotation()||this.entryAnimationEngine.requiresJSScale()||l.dataset.startRotation!==l.dataset.rotation||l.dataset.startScale!==l.dataset.scale)zt({element:l,startPosition:{x:y,y:E},endPosition:{x:w,y:M},pathConfig:this.entryAnimationEngine.getPathConfig(),duration:b.duration,imageWidth:H,imageHeight:P,rotation:A,scale:O,rotationConfig:this.entryAnimationEngine.getRotationConfig(),startRotation:L,scaleConfig:this.entryAnimationEngine.getScaleConfig(),startScale:D,onProgress:this.callbacks.onEntryProgress&&h?(C,U,$)=>{const F={element:l,index:g,totalImages:this.imageLayouts.length,layout:h,from:{x:y,y:E,rotation:L,scale:D},to:{x:w,y:M,rotation:A,scale:O},startTime:I,duration:b.duration,progress:C,rawProgress:C,elapsed:U,current:$};this.callbacks.onEntryProgress(F)}:void 0,onComplete:h?()=>{if(this.callbacks.onEntryComplete){const C={element:l,index:g,layout:h,startTime:I,endTime:performance.now(),duration:b.duration};this.callbacks.onEntryComplete(C)}}:void 0});else{const C=l.dataset.finalTransform||"";if(l.style.transform=C,this.callbacks.onEntryComplete&&h){const U=$=>{if($.propertyName!=="transform")return;l.removeEventListener("transitionend",U);const F={element:l,index:g,layout:h,startTime:I,endTime:performance.now(),duration:b.duration};this.callbacks.onEntryComplete(F)};l.addEventListener("transitionend",U)}}if(this.fullConfig.config.debug?.enabled&&g<3){const C=l.dataset.finalTransform||"";console.log(`Image ${g} final state:`,{left:l.style.left,top:l.style.top,width:l.style.width,height:l.style.height,computedWidth:l.offsetWidth,computedHeight:l.offsetHeight,transform:C,pathType:this.entryAnimationEngine.getPathType()})}if(this.idleAnimationEngine){const C=this.entryAnimationEngine.getTiming().duration;this.idleAnimationEngine.register(l,g,this.imageElements.length,C)}}),r++,p())},v=()=>{if(this.logDebug("Starting queue processing, enabled:",this.fullConfig.animation.queue.enabled),!this.fullConfig.animation.queue.enabled){for(;this.displayQueue.length>0;){const l=this.displayQueue.shift();l&&x(l)}return}this.queueInterval!==null&&clearInterval(this.queueInterval),this.queueInterval=window.setInterval(()=>{if(n!==this.loadGeneration){this.queueInterval!==null&&(clearInterval(this.queueInterval),this.queueInterval=null);return}if(this.displayQueue.length>0){const l=this.displayQueue.shift();l&&x(l)}r>=t.length&&this.displayQueue.length===0&&(this.queueInterval!==null&&(clearInterval(this.queueInterval),this.queueInterval=null),m())},this.fullConfig.animation.queue.interval)};if("IntersectionObserver"in window&&this.containerEl){const l=new IntersectionObserver(g=>{g.forEach(h=>{h.isIntersecting&&(v(),l.disconnect())})},{threshold:.1,rootMargin:"50px"});l.observe(this.containerEl)}else v();this.fullConfig.config.debug?.centers&&this.containerEl&&(this.containerEl.querySelectorAll(".fbn-ic-debug-center").forEach(l=>l.remove()),s.forEach((l,g)=>{const h=document.createElement("div");h.className="fbn-ic-debug-center",h.style.position="absolute",h.style.width="12px",h.style.height="12px",h.style.borderRadius="50%",h.style.backgroundColor="red",h.style.border="2px solid yellow",h.style.zIndex="9999",h.style.pointerEvents="none";const b=l.x,I=l.y;h.style.left=`${b-6}px`,h.style.top=`${I-6}px`,h.title=`Image ${g}: center (${Math.round(b)}, ${Math.round(I)})`,this.containerEl.appendChild(h)})),t.forEach((l,g)=>{const h=document.createElement("img");h.referrerPolicy="no-referrer",h.classList.add("fbn-ic-image"),this.fullConfig.interaction.dragging===!1&&(h.draggable=!1),h.dataset.imageId=String(g),h.dataset.createdFlag="true";const b=s[g];h.style.position="absolute",h.style.width="auto",h.style.height=`${i}px`,h.style.left=`${b.x}px`,h.style.top=`${b.y}px`,b.zIndex&&(h.style.zIndex=String(b.zIndex)),ot(h,this.defaultClassName),h.addEventListener("mouseenter",()=>{if(this.hoveredImage={element:h,layout:b},!this.zoomEngine.isInvolved(h)){const y=h.cachedRenderedWidth;at(h,this.fullConfig.styling?.hover,i,y),ot(h,this.hoverClassName)}if(this.callbacks.onImageHover){const y={element:h,index:g,url:l,layout:b};this.callbacks.onImageHover(y)}}),h.addEventListener("mouseleave",()=>{if(this.hoveredImage=null,!this.zoomEngine.isInvolved(h)){const y=h.cachedRenderedWidth;at(h,this.fullConfig.styling?.default,i,y),vt(h,this.hoverClassName),ot(h,this.defaultClassName)}if(this.callbacks.onImageUnhover){const y={element:h,index:g,url:l,layout:b};this.callbacks.onImageUnhover(y)}}),h.addEventListener("click",y=>{y.stopPropagation(),this.handleImageClick(h,b)}),h.style.opacity="0",h.style.transition=this.entryAnimationEngine.getTransitionCSS(),h.onload=()=>{if(n!==this.loadGeneration)return;const y=h.naturalWidth/h.naturalHeight,E=i*y;h.dataset.onloadCalled="true",window.DEBUG_CLIPPATH&&console.log(`[onload #${g}] Called with imageHeight=${i}, renderedWidth=${E}`),h.style.width=`${E}px`,h.cachedRenderedWidth=E,h.aspectRatio=y,at(h,this.fullConfig.styling?.default,i,E);const w={x:b.x,y:b.y},M={width:E,height:i},A=this.entryAnimationEngine.calculateStartPosition(w,M,e,g,t.length),O=this.entryAnimationEngine.calculateStartRotation(b.rotation),L=this.entryAnimationEngine.calculateStartScale(b.scale),D=this.entryAnimationEngine.buildFinalTransform(b.rotation,b.scale,E,i),H=this.entryAnimationEngine.buildStartTransform(A,w,b.rotation,b.scale,E,i,O,L);if(this.fullConfig.config.debug?.enabled&&g<3&&console.log(`Image ${g}:`,{finalPosition:w,imageSize:M,left:b.x,top:b.y,finalTransform:D,renderedWidth:E,renderedHeight:i}),h.style.transform=H,h.dataset.finalTransform=D,h.dataset.startX=String(A.x),h.dataset.startY=String(A.y),h.dataset.endX=String(w.x),h.dataset.endY=String(w.y),h.dataset.imageWidth=String(E),h.dataset.imageHeight=String(i),h.dataset.rotation=String(b.rotation),h.dataset.scale=String(b.scale),h.dataset.startRotation=String(O),h.dataset.startScale=String(L),a++,this.callbacks.onImageLoaded){const P={element:h,url:l,index:g,totalImages:t.length,loadTime:performance.now()-(f.get(g)??performance.now())};this.callbacks.onImageLoaded(P)}if(this.callbacks.onLoadProgress){const P={loaded:a,failed:c,total:t.length,percent:(a+c)/t.length*100};this.callbacks.onLoadProgress(P)}this.displayQueue.push(h)};const I=()=>{if(n===this.loadGeneration){if(c++,this.callbacks.onImageError){const y={url:l,index:g,totalImages:t.length};this.callbacks.onImageError(y)}if(this.callbacks.onLoadProgress){const y={loaded:a,failed:c,total:t.length,percent:(a+c)/t.length*100};this.callbacks.onLoadProgress(y)}r++,p()}};h.onerror=()=>I(),(async()=>{let y=l;if(this.callbacks.onBeforeImageLoad){const E={url:l,index:g,totalImages:t.length},w=await this.callbacks.onBeforeImageLoad(E);if(w)if(w.fetch!==void 0){const M=w.url??l;try{const O=await(await fetch(M,w.fetch)).blob(),L=URL.createObjectURL(O);y=L;const D=h.onload;h.onload=H=>{URL.revokeObjectURL(L),D?.call(h,H)}}catch{I();return}}else w.url&&(y=w.url)}d===0&&(d=performance.now()),f.set(g,performance.now()),h.src=y})()})}async handleImageClick(t,i){if(!this.containerEl)return;const e=this.zoomEngine.isFocused(t),n={width:this.containerEl.offsetWidth,height:this.containerEl.offsetHeight};if(e)await this.zoomEngine.unfocusImage(),this.currentFocusIndex=null,this.swipeEngine?.disable(),this.hideCounter(),this.hideNavButtons(),this.hideFocusIndicator();else{this.idleAnimationEngine?.pauseForImage(t);const s=t.dataset.imageId;if(this.currentFocusIndex=s!==void 0?parseInt(s,10):null,this.swipeEngine?.enable(),this.containerEl?.focus({preventScroll:!0}),await this.zoomEngine.focusImage(t,n,i),this.currentFocusIndex!==null&&this.updateCounter(this.currentFocusIndex),this.showNavButtons(),this.showFocusIndicator(),this.callbacks.onImageFocus&&this.currentFocusIndex!==null){const r=this.imageLoader.imageURLs(),a={element:t,index:this.currentFocusIndex,url:r[this.currentFocusIndex]??"",layout:i};this.callbacks.onImageFocus(a)}}}clearImageCloud(){this.queueInterval!==null&&(clearInterval(this.queueInterval),this.queueInterval=null),this.loadGeneration++,this.displayQueue=[],this.hideFocusIndicator(),this.containerEl&&this.containerEl.querySelectorAll(".fbn-ic-image, .fbn-ic-debug-center").forEach(t=>t.remove()),this.imageElements=[],this.imageLayouts=[],this.currentFocusIndex=null,this.hoveredImage=null,this.layoutEngine.reset(),this.zoomEngine.reset(),this.idleAnimationEngine?.stopAll(),this.imagesLoaded=!1}showLoading(t){!this.fullConfig.ui.showLoadingSpinner||!this.loadingEl||(t?this.loadingEl.classList.remove("fbn-ic-hidden"):this.loadingEl.classList.add("fbn-ic-hidden"))}showError(t){this.errorEl&&(this.errorEl.textContent=t,this.errorEl.classList.remove("fbn-ic-hidden"))}hideError(){this.errorEl&&this.errorEl.classList.add("fbn-ic-hidden")}updateCounter(t){!this.fullConfig.ui.showImageCounter||!this.counterEl||(this.counterEl.textContent=`${t+1} of ${this.imageElements.length}`,this.counterEl.classList.remove("fbn-ic-hidden"))}hideCounter(){this.counterEl&&this.counterEl.classList.add("fbn-ic-hidden")}showFocusIndicator(){this.containerEl?.classList.add("fbn-ic-has-focus")}hideFocusIndicator(){this.containerEl?.classList.remove("fbn-ic-has-focus")}showNavButtons(){this.prevButtonEl?.classList.remove("fbn-ic-hidden"),this.nextButtonEl?.classList.remove("fbn-ic-hidden")}hideNavButtons(){this.prevButtonEl?.classList.add("fbn-ic-hidden"),this.nextButtonEl?.classList.add("fbn-ic-hidden")}destroy(){this.clearImageCloud(),this.loadingElAutoCreated&&this.loadingEl&&(this.loadingEl.remove(),this.loadingEl=null),this.errorElAutoCreated&&this.errorEl&&(this.errorEl.remove(),this.errorEl=null),this.counterElAutoCreated&&this.counterEl&&(this.counterEl.remove(),this.counterEl=null),this.prevButtonElAutoCreated&&this.prevButtonEl&&(this.prevButtonEl.remove(),this.prevButtonEl=null),this.nextButtonElAutoCreated&&this.nextButtonEl&&(this.nextButtonEl.remove(),this.nextButtonEl=null),this.resizeTimeout!==null&&clearTimeout(this.resizeTimeout),this.swipeEngine?.destroy(),this.idleAnimationEngine?.stopAll(),this.idleAnimationEngine=null}}async function Ke(o){const t=new ee(o);return await t.init(),t}T.AnimationEngine=Ot,T.BOUNCE_PRESETS=ht,T.ClusterPlacementLayout=Nt,T.CompositeLoader=Kt,T.DEFAULT_CONFIG=R,T.DEFAULT_SHARED_LOADER_CONFIG=pt,T.ELASTIC_PRESETS=dt,T.EntryAnimationEngine=Pt,T.FUNCTIONAL_CSS=Qt,T.GoogleDriveLoader=Vt,T.GridPlacementLayout=kt,T.HoneycombPlacementLayout=jt,T.ImageCloud=ee,T.ImageFilter=Zt,T.LayoutEngine=Wt,T.RadialPlacementLayout=_t,T.RandomPlacementLayout=$t,T.SpiralPlacementLayout=Ht,T.StaticImageLoader=Jt,T.WAVE_PATH_PRESETS=ut,T.WavePlacementLayout=Bt,T.ZoomEngine=Xt,T.animatePath=zt,T.imageCloud=Ke,T.injectFunctionalStyles=te,T.requiresJSAnimation=Dt,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})}));
85
85
  //# sourceMappingURL=image-cloud.umd.js.map