@frybynite/image-cloud 0.5.2 → 0.6.1

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.
Files changed (89) hide show
  1. package/README.md +46 -13
  2. package/dist/composite-CtUxtN2l.js +96 -0
  3. package/dist/composite-CtUxtN2l.js.map +1 -0
  4. package/dist/google-drive-CC-qFSV1.js +260 -0
  5. package/dist/google-drive-CC-qFSV1.js.map +1 -0
  6. package/dist/image-cloud-auto-init.js +345 -759
  7. package/dist/image-cloud-auto-init.js.map +1 -1
  8. package/dist/image-cloud.js +1248 -1204
  9. package/dist/image-cloud.js.map +1 -1
  10. package/dist/image-cloud.umd.js +5 -5
  11. package/dist/image-cloud.umd.js.map +1 -1
  12. package/dist/index.d.ts +1654 -23
  13. package/dist/loaders/all.d.ts +1654 -0
  14. package/dist/loaders/all.js +496 -0
  15. package/dist/loaders/all.js.map +1 -0
  16. package/dist/loaders/composite.d.ts +1654 -0
  17. package/dist/loaders/composite.js +96 -0
  18. package/dist/loaders/composite.js.map +1 -0
  19. package/dist/loaders/google-drive.d.ts +1654 -0
  20. package/dist/loaders/google-drive.js +260 -0
  21. package/dist/loaders/google-drive.js.map +1 -0
  22. package/dist/loaders/static.d.ts +1654 -0
  23. package/dist/loaders/static.js +219 -0
  24. package/dist/loaders/static.js.map +1 -0
  25. package/dist/react.d.ts +1654 -1
  26. package/dist/react.js +434 -848
  27. package/dist/react.js.map +1 -1
  28. package/dist/static-ejylHtQ4.js +219 -0
  29. package/dist/static-ejylHtQ4.js.map +1 -0
  30. package/dist/vue.d.ts +1654 -1
  31. package/dist/vue.js +442 -856
  32. package/dist/vue.js.map +1 -1
  33. package/dist/web-component.d.ts +1654 -1
  34. package/dist/web-component.js +429 -843
  35. package/dist/web-component.js.map +1 -1
  36. package/package.json +28 -15
  37. package/dist/ImageCloud.d.ts +0 -99
  38. package/dist/ImageCloud.d.ts.map +0 -1
  39. package/dist/config/adapter.d.ts +0 -50
  40. package/dist/config/adapter.d.ts.map +0 -1
  41. package/dist/config/defaults.d.ts +0 -118
  42. package/dist/config/defaults.d.ts.map +0 -1
  43. package/dist/config/types.d.ts +0 -599
  44. package/dist/config/types.d.ts.map +0 -1
  45. package/dist/engines/AnimationEngine.d.ts +0 -82
  46. package/dist/engines/AnimationEngine.d.ts.map +0 -1
  47. package/dist/engines/EntryAnimationEngine.d.ts +0 -161
  48. package/dist/engines/EntryAnimationEngine.d.ts.map +0 -1
  49. package/dist/engines/LayoutEngine.d.ts +0 -68
  50. package/dist/engines/LayoutEngine.d.ts.map +0 -1
  51. package/dist/engines/PathAnimator.d.ts +0 -50
  52. package/dist/engines/PathAnimator.d.ts.map +0 -1
  53. package/dist/engines/SwipeEngine.d.ts +0 -53
  54. package/dist/engines/SwipeEngine.d.ts.map +0 -1
  55. package/dist/engines/ZoomEngine.d.ts +0 -139
  56. package/dist/engines/ZoomEngine.d.ts.map +0 -1
  57. package/dist/image-cloud-auto-init.d.ts +0 -14
  58. package/dist/image-cloud-auto-init.d.ts.map +0 -1
  59. package/dist/index.d.ts.map +0 -1
  60. package/dist/layouts/ClusterPlacementLayout.d.ts +0 -40
  61. package/dist/layouts/ClusterPlacementLayout.d.ts.map +0 -1
  62. package/dist/layouts/GridPlacementLayout.d.ts +0 -27
  63. package/dist/layouts/GridPlacementLayout.d.ts.map +0 -1
  64. package/dist/layouts/RadialPlacementLayout.d.ts +0 -33
  65. package/dist/layouts/RadialPlacementLayout.d.ts.map +0 -1
  66. package/dist/layouts/RandomPlacementLayout.d.ts +0 -26
  67. package/dist/layouts/RandomPlacementLayout.d.ts.map +0 -1
  68. package/dist/layouts/SpiralPlacementLayout.d.ts +0 -43
  69. package/dist/layouts/SpiralPlacementLayout.d.ts.map +0 -1
  70. package/dist/layouts/WavePlacementLayout.d.ts +0 -48
  71. package/dist/layouts/WavePlacementLayout.d.ts.map +0 -1
  72. package/dist/loaders/CompositeLoader.d.ts +0 -37
  73. package/dist/loaders/CompositeLoader.d.ts.map +0 -1
  74. package/dist/loaders/GoogleDriveLoader.d.ts +0 -90
  75. package/dist/loaders/GoogleDriveLoader.d.ts.map +0 -1
  76. package/dist/loaders/ImageFilter.d.ts +0 -26
  77. package/dist/loaders/ImageFilter.d.ts.map +0 -1
  78. package/dist/loaders/StaticImageLoader.d.ts +0 -85
  79. package/dist/loaders/StaticImageLoader.d.ts.map +0 -1
  80. package/dist/react/index.d.ts +0 -16
  81. package/dist/react/index.d.ts.map +0 -1
  82. package/dist/styles/functionalStyles.d.ts +0 -11
  83. package/dist/styles/functionalStyles.d.ts.map +0 -1
  84. package/dist/utils/styleUtils.d.ts +0 -54
  85. package/dist/utils/styleUtils.d.ts.map +0 -1
  86. package/dist/vue/index.d.ts +0 -18
  87. package/dist/vue/index.d.ts.map +0 -1
  88. package/dist/web-component/index.d.ts +0 -15
  89. package/dist/web-component/index.d.ts.map +0 -1
@@ -1,7 +1,4 @@
1
- (function(A,V){typeof exports=="object"&&typeof module<"u"?V(exports):typeof define=="function"&&define.amd?define(["exports"],V):(A=typeof globalThis<"u"?globalThis:A||self,V(A.ImageCloud={}))})(this,(function(A){"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)"}),lt=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})}),ht=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})}),dt=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})}),ut=Object.freeze({type:"linear"}),gt=Object.freeze({mode:"none"}),mt=Object.freeze({mode:"none"}),It=Object.freeze({default:Object.freeze({border:Object.freeze({width:0,color:"#000000",radius:0,style:"solid"}),shadow:"none",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"})}),Zt=Object.freeze({rows:1,amplitude:100,frequency:2,phaseShift:0,synchronization:"offset"}),Kt=Object.freeze({mobile:Object.freeze({maxWidth:767}),tablet:Object.freeze({maxWidth:1199})}),Qt=Object.freeze({mode:"adaptive",minSize:50,maxSize:400,variance:Object.freeze({min:1,max:1})}),te=Object.freeze({mode:"none",range:Object.freeze({min:-15,max:15})}),At=Object.freeze({sizing:Qt,rotation:te}),ft=Object.freeze({validateUrls:!0,validationTimeout:5e3,validationMethod:"head",allowedExtensions:["jpg","jpeg","png","gif","webp","bmp"]}),Tt=Object.freeze({enabled:!1,centers:!1,loaders:!1}),y=Object.freeze({loaders:[],config:Object.freeze({loaders:ft,debug:Tt}),image:At,layout:Object.freeze({algorithm:"radial",scaleDecay:0,responsive:Kt,targetCoverage:.6,densityFactor:1,spacing:Object.freeze({padding:50,minGap:20})}),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,maxConcurrent:void 0}),performance:Object.freeze({useGPU:void 0,reduceMotion:void 0}),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:ut,rotation:gt,scale:mt})}),interaction:Object.freeze({focus:Object.freeze({scalePercent:.8,zIndex:1e3,animationDuration:void 0}),navigation:Object.freeze({keyboard:void 0,swipe:void 0,mouseWheel:void 0}),gestures:Object.freeze({pinchToZoom:void 0,doubleTapToFocus:void 0})}),rendering:Object.freeze({responsive:Object.freeze({breakpoints:Object.freeze({mobile:768,tablet:void 0,desktop:void 0}),mobileDetection:()=>typeof window>"u"?!1:window.innerWidth<=768}),ui:Object.freeze({showLoadingSpinner:!1,showImageCounter:!1,showThumbnails:void 0,theme:void 0}),performance:Object.freeze({lazyLoad:void 0,preloadCount:void 0,imageQuality:void 0})}),styling:It});function tt(n,t){if(!n)return t||{};if(!t)return{...n};const e={...n};return t.border!==void 0&&(e.border={...n.border,...t.border}),t.borderTop!==void 0&&(e.borderTop={...n.borderTop,...t.borderTop}),t.borderRight!==void 0&&(e.borderRight={...n.borderRight,...t.borderRight}),t.borderBottom!==void 0&&(e.borderBottom={...n.borderBottom,...t.borderBottom}),t.borderLeft!==void 0&&(e.borderLeft={...n.borderLeft,...t.borderLeft}),t.filter!==void 0&&(e.filter={...n.filter,...t.filter}),t.outline!==void 0&&(e.outline={...n.outline,...t.outline}),t.shadow!==void 0&&(e.shadow=t.shadow),t.opacity!==void 0&&(e.opacity=t.opacity),t.cursor!==void 0&&(e.cursor=t.cursor),t.className!==void 0&&(e.className=t.className),t.objectFit!==void 0&&(e.objectFit=t.objectFit),t.aspectRatio!==void 0&&(e.aspectRatio=t.aspectRatio),t.borderRadiusTopLeft!==void 0&&(e.borderRadiusTopLeft=t.borderRadiusTopLeft),t.borderRadiusTopRight!==void 0&&(e.borderRadiusTopRight=t.borderRadiusTopRight),t.borderRadiusBottomRight!==void 0&&(e.borderRadiusBottomRight=t.borderRadiusBottomRight),t.borderRadiusBottomLeft!==void 0&&(e.borderRadiusBottomLeft=t.borderRadiusBottomLeft),e}function ee(n,t){if(!t)return{...n};const e=tt(n.default,t.default),i=tt(tt(e,n.hover),t.hover),o=tt(tt(e,n.focused),t.focused);return{default:e,hover:i,focused:o}}function ie(n,t){if(!t)return{...n};const e={...n};if(t.sizing!==void 0&&(e.sizing={...n.sizing,...t.sizing},t.sizing.variance)){const i=t.sizing.variance,o=i.min!==void 0&&i.min>=.25&&i.min<=1?i.min:n.sizing?.variance?.min??1,s=i.max!==void 0&&i.max>=1&&i.max<=1.75?i.max:n.sizing?.variance?.max??1;e.sizing.variance={min:o,max:s}}if(t.rotation!==void 0&&(e.rotation={...n.rotation,...t.rotation},t.rotation.range)){const i=t.rotation.range,o=i.min!==void 0&&i.min>=-180&&i.min<=0?i.min:n.rotation?.range?.min??-15,s=i.max!==void 0&&i.max>=0&&i.max<=180?i.max:n.rotation?.range?.max??15;e.rotation.range={min:o,max:s}}return e}function ne(n){const t=n.layout?.rotation;if(t&&"enabled"in t)return{rotation:{mode:t.enabled?"random":"none",range:t.range}}}function oe(n){const t=n.layout?.sizing?.variance;if(t)return{sizing:{mode:"adaptive",variance:t}}}function se(n={}){const t=ne(n),e=oe(n);let i=n.image;(t||e)&&(i={...e||{},...t||{},...i},i.rotation&&t?.rotation&&n.image?.rotation&&(i.rotation={...t.rotation,...n.image.rotation}));const o=[...n.loaders??[]];n.images&&n.images.length>0&&o.unshift({static:{sources:[{urls:n.images}]}});const r={loaders:{...ft,...n.config?.loaders??{}}},a={loaders:o,config:r,image:ie(At,i),layout:{...y.layout},animation:{...y.animation},interaction:{...y.interaction},rendering:{...y.rendering},styling:ee(It,n.styling)};return n.layout&&(a.layout={...y.layout,...n.layout},n.layout.responsive&&(a.layout.responsive={...y.layout.responsive,mobile:n.layout.responsive.mobile?{...y.layout.responsive.mobile,...n.layout.responsive.mobile}:y.layout.responsive.mobile,tablet:n.layout.responsive.tablet?{...y.layout.responsive.tablet,...n.layout.responsive.tablet}:y.layout.responsive.tablet}),n.layout.spacing&&(a.layout.spacing={...y.layout.spacing,...n.layout.spacing})),n.animation&&(a.animation={...y.animation,...n.animation},n.animation.easing&&(a.animation.easing={...y.animation.easing,...n.animation.easing}),n.animation.queue&&(a.animation.queue={...y.animation.queue,...n.animation.queue}),n.animation.performance&&(a.animation.performance={...y.animation.performance,...n.animation.performance}),n.animation.entry&&(a.animation.entry={...y.animation.entry,...n.animation.entry,start:n.animation.entry.start?{...y.animation.entry.start,...n.animation.entry.start,circular:n.animation.entry.start.circular?{...y.animation.entry.start.circular,...n.animation.entry.start.circular}:y.animation.entry.start.circular}:y.animation.entry.start,timing:n.animation.entry.timing?{...y.animation.entry.timing,...n.animation.entry.timing}:y.animation.entry.timing,path:n.animation.entry.path?{...ut,...n.animation.entry.path}:y.animation.entry.path,rotation:n.animation.entry.rotation?{...gt,...n.animation.entry.rotation}:y.animation.entry.rotation,scale:n.animation.entry.scale?{...mt,...n.animation.entry.scale}:y.animation.entry.scale})),n.interaction&&(a.interaction={...y.interaction,...n.interaction},n.interaction.focus&&(a.interaction.focus={...y.interaction.focus,...n.interaction.focus}),n.interaction.navigation&&(a.interaction.navigation={...y.interaction.navigation,...n.interaction.navigation}),n.interaction.gestures&&(a.interaction.gestures={...y.interaction.gestures,...n.interaction.gestures})),n.rendering&&(a.rendering={...y.rendering,...n.rendering},n.rendering.responsive&&(a.rendering.responsive={...y.rendering.responsive,...n.rendering.responsive,breakpoints:n.rendering.responsive.breakpoints?{...y.rendering.responsive.breakpoints,...n.rendering.responsive.breakpoints}:y.rendering.responsive.breakpoints,mobileDetection:n.rendering.responsive.mobileDetection?n.rendering.responsive.mobileDetection:y.rendering.responsive.mobileDetection}),n.rendering.ui&&(a.rendering.ui={...y.rendering.ui,...n.rendering.ui}),n.rendering.performance&&(a.rendering.performance={...y.rendering.performance,...n.rendering.performance})),a.config.debug={...Tt,...n.config?.debug??{}},a}function ae(n,t){return{...n?lt[n]:lt.playful,...t}}function re(n,t){return{...n?ht[n]:ht.gentle,...t}}function ce(n,t){return{...n?dt[n]:dt.gentle,...t}}class Ct{constructor(t){this.activeAnimations=new Map,this.animationIdCounter=0,this.config=t}buildTransformString(t){const e=["translate(-50%, -50%)"];if(t.x!==void 0||t.y!==void 0){const i=t.x??0,o=t.y??0;e.push(`translate(${i}px, ${o}px)`)}return t.rotation!==void 0&&e.push(`rotate(${t.rotation}deg)`),t.scale!==void 0&&e.push(`scale(${t.scale})`),e.join(" ")}animateTransformCancellable(t,e,i,o=null,s=null){this.cancelAllAnimations(t);const r=o??this.config.duration,a=s??this.config.easing.default,h=this.buildTransformString(e),c=this.buildTransformString(i);t.style.transition="none";const u=t.animate([{transform:h},{transform:c}],{duration:r,easing:a,fill:"forwards"}),l={id:`anim-${++this.animationIdCounter}`,element:t,animation:u,fromState:e,toState:i,startTime:performance.now(),duration:r};return this.activeAnimations.set(t,l),u.finished.then(()=>{t.style.transform=c,this.activeAnimations.delete(t)}).catch(()=>{this.activeAnimations.delete(t)}),l}cancelAnimation(t,e=!0){const i=this.getCurrentTransform(t.element);if(t.animation.cancel(),e){const o=this.buildTransformString({x:i.x,y:i.y,rotation:i.rotation,scale:i.scale});t.element.style.transform=o}return this.activeAnimations.delete(t.element),i}cancelAllAnimations(t){const e=this.activeAnimations.get(t);e&&this.cancelAnimation(e,!1);const i=t.getAnimations();for(const o of i)o.cancel()}getCurrentTransform(t){const i=getComputedStyle(t).transform;if(i==="none"||!i)return{x:0,y:0,rotation:0,scale:1};const o=new DOMMatrix(i),s=Math.sqrt(o.a*o.a+o.b*o.b),r=Math.atan2(o.b,o.a)*(180/Math.PI),a=o.e,h=o.f;return{x:a,y:h,rotation:r,scale:s}}hasActiveAnimation(t){return this.activeAnimations.has(t)}getAnimationHandle(t){return this.activeAnimations.get(t)}animateTransform(t,e,i=null,o=null){return new Promise(s=>{const r=i??this.config.duration,a=o??this.config.easing.default;t.style.transition=`transform ${r}ms ${a}, box-shadow ${r}ms ${a}`,t.style.transform=this.buildTransformString(e),setTimeout(()=>{s()},r)})}resetTransform(t,e){return this.animateTransform(t,e)}clearTransition(t){t.style.transition=""}wait(t){return new Promise(e=>setTimeout(e,t))}}function Z(n,t,e){return n+(t-n)*e}function le(n,t,e,i){const{overshoot:o,bounces:s,decayRatio:r}=i,a=e.x-t.x,h=e.y-t.y,c=he(s,r);let u=0,l=0,d=1,m=o,b=!1;for(let g=0;g<c.length;g++)if(n<=c[g].time){l=g===0?0:c[g-1].time,d=c[g].time,m=c[g].overshoot,b=c[g].isOvershoot;break}const p=(n-l)/(d-l);if(b)u=1+m*ot(p);else if(l===0)u=ot(p);else{const f=1+(c.find((x,v)=>x.time>l&&v>0&&c[v-1].isOvershoot)?.overshoot||m);u=Z(f,1,ot(p))}return{x:t.x+a*u,y:t.y+h*u}}function he(n,t){const e=[];let i=.6;e.push({time:i,overshoot:0,isOvershoot:!1});let o=.15;const r=.4/(n*2);for(let a=0;a<n;a++)i+=r,e.push({time:i,overshoot:o,isOvershoot:!0}),i+=r,e.push({time:i,overshoot:o*t,isOvershoot:!1}),o*=t;return e.push({time:1,overshoot:0,isOvershoot:!1}),e}function de(n,t,e,i){const{stiffness:o,damping:s,mass:r,oscillations:a}=i,h=e.x-t.x,c=e.y-t.y,u=Math.sqrt(o/r),l=s/(2*Math.sqrt(o*r));let d;if(l<1){const m=u*Math.sqrt(1-l*l),b=Math.exp(-l*u*n*3),p=Math.cos(m*n*a*Math.PI);d=1-b*p}else d=1-Math.exp(-u*n*3);return d=Math.max(0,Math.min(d,1.3)),{x:t.x+h*d,y:t.y+c*d}}function ue(n,t,e,i){const{amplitude:o,frequency:s,decay:r,decayRate:a,phase:h}=i,c=e.x-t.x,u=e.y-t.y,l=Math.sqrt(c*c+u*u),d=l>0?-u/l:0,m=l>0?c/l:1,b=s*Math.PI*2*n+h,p=r?Math.pow(1-n,a):1,g=o*Math.sin(b)*p,f=ge(n);return{x:Z(t.x,e.x,f)+g*d,y:Z(t.y,e.y,f)+g*m}}function ot(n){return 1-(1-n)*(1-n)}function ge(n){return 1-Math.pow(1-n,3)}function me(n,t,e){const{amplitude:i,frequency:o,decay:s}=e,r=Math.sin(n*o*Math.PI*2),a=s?Math.pow(1-n,2):1,h=i*r*a;return t+h}function fe(n,t,e){const{overshoot:i,bounces:o}=e,s=[];s.push({time:.5,scale:i});let r=i;const a=.5,c=.5/(o*2);let u=.5;for(let d=0;d<o;d++){const m=1-(r-1)*a;u+=c,s.push({time:u,scale:m}),r=1+(r-1)*a*a,u+=c,d<o-1&&s.push({time:u,scale:r})}s.push({time:1,scale:1});let l=1;for(let d=0;d<s.length;d++)if(n<=s[d].time){const m=d===0?0:s[d-1].time,b=d===0?1:s[d-1].scale,p=(n-m)/(s[d].time-m),g=ot(p);l=b+(s[d].scale-b)*g;break}return l*t}function Rt(n){const{element:t,startPosition:e,endPosition:i,pathConfig:o,duration:s,imageWidth:r,imageHeight:a,rotation:h,scale:c,onComplete:u,rotationConfig:l,startRotation:d,scaleConfig:m,startScale:b}=n,p=o.type,g=d!==void 0&&d!==h,f=l?.mode==="wobble",x=l?.wobble||{amplitude:15,frequency:3,decay:!0},v=g||f,w=b!==void 0&&b!==c,I=m?.mode==="pop",E=m?.pop||{overshoot:1.2,bounces:1};if((p==="linear"||p==="arc")&&!v&&!(w||I)){u&&u();return}const F=performance.now(),z=-r/2,_=-a/2;function N(X){const j=X-F,C=Math.min(j/s,1);let O;switch(p){case"bounce":{const $=ae(o.bouncePreset,o.bounce);O=le(C,e,i,$);break}case"elastic":{const $=re(o.elasticPreset,o.elastic);O=de(C,e,i,$);break}case"wave":{const $=ce(o.wavePreset,o.wave);O=ue(C,e,i,$);break}default:O={x:Z(e.x,i.x,C),y:Z(e.y,i.y,C)}}const G=O.x-i.x,H=O.y-i.y;let L;f?L=me(C,h,x):g?L=Z(d,h,C):L=h;let R;I?R=fe(C,c,E):w?R=Z(b,c,C):R=c,t.style.transform=`translate(${z}px, ${_}px) translate(${G}px, ${H}px) rotate(${L}deg) scale(${R})`,C<1?requestAnimationFrame(N):(t.style.transform=`translate(${z}px, ${_}px) rotate(${h}deg) scale(${c})`,u&&u())}requestAnimationFrame(N)}function Lt(n){return n==="bounce"||n==="elastic"||n==="wave"}const pe={radial:"center",spiral:"center",grid:"top",cluster:"nearest-edge",random:"nearest-edge",wave:"left"};class Mt{constructor(t,e){this.config=t,this.layoutAlgorithm=e,this.resolvedStartPosition=this.resolveStartPosition(),this.pathConfig=t.path||ut,this.rotationConfig=t.rotation||gt,this.scaleConfig=t.scale||mt}resolveStartPosition(){return this.config.start.position?this.config.start.position:pe[this.layoutAlgorithm]||"nearest-edge"}calculateStartPosition(t,e,i,o,s){const r=this.resolvedStartPosition,a=this.config.start.offset??100;switch(r){case"nearest-edge":return this.calculateNearestEdge(t,e,i,a);case"top":return this.calculateEdgePosition("top",t,e,i,a);case"bottom":return this.calculateEdgePosition("bottom",t,e,i,a);case"left":return this.calculateEdgePosition("left",t,e,i,a);case"right":return this.calculateEdgePosition("right",t,e,i,a);case"center":return this.calculateCenterPosition(i,t,e);case"random-edge":return this.calculateRandomEdge(t,e,i,a);case"circular":return this.calculateCircularPosition(t,e,i,o,s);default:return this.calculateNearestEdge(t,e,i,a)}}calculateNearestEdge(t,e,i,o){const s=t.x,r=t.y,a=s,h=i.width-s,c=r,u=i.height-r,l=Math.min(a,h,c,u);let d=t.x,m=t.y;return l===a?d=-(e.width+o):l===h?d=i.width+o:l===c?m=-(e.height+o):m=i.height+o,{x:d,y:m}}calculateEdgePosition(t,e,i,o,s){let r=e.x,a=e.y;switch(t){case"top":a=-(i.height+s);break;case"bottom":a=o.height+s;break;case"left":r=-(i.width+s);break;case"right":r=o.width+s;break}return{x:r,y:a}}calculateCenterPosition(t,e,i){const o=t.width/2,s=t.height/2;return{x:o,y:s,useScale:!0}}calculateRandomEdge(t,e,i,o){const s=["top","bottom","left","right"],r=s[Math.floor(Math.random()*s.length)];return this.calculateEdgePosition(r,t,e,i,o)}calculateCircularPosition(t,e,i,o,s){const r=this.config.start.circular||{},a=r.distribution||"even";let h;const c=r.radius||"120%";if(typeof c=="string"&&c.endsWith("%")){const p=parseFloat(c)/100;h=Math.sqrt(i.width**2+i.height**2)*p/2}else h=typeof c=="number"?c:500;let u;a==="even"?u=o/s*2*Math.PI:u=Math.random()*2*Math.PI;const l=i.width/2,d=i.height/2,m=l+Math.cos(u)*h,b=d+Math.sin(u)*h;return{x:m,y:b}}getAnimationParams(t){const e=this.config.timing.duration,i=this.config.easing;return{startTransform:"",duration:e,delay:0,easing:i}}buildStartTransform(t,e,i,o,s,r,a,h){const c=t.x-e.x,u=t.y-e.y,l=a!==void 0?a:i,d=h!==void 0?h:o,m=s!==void 0?-s/2:0,b=r!==void 0?-r/2:0,p=s!==void 0?`translate(${m}px, ${b}px)`:"translate(-50%, -50%)";return t.useScale?`${p} translate(${c}px, ${u}px) rotate(${l}deg) scale(0)`:`${p} translate(${c}px, ${u}px) rotate(${l}deg) scale(${d})`}buildFinalTransform(t,e,i,o){if(i!==void 0&&o!==void 0){const s=-i/2,r=-o/2;return`translate(${s}px, ${r}px) rotate(${t}deg) scale(${e})`}return`translate(-50%, -50%) rotate(${t}deg) scale(${e})`}getTransitionCSS(){const t=this.config.timing.duration,e=this.config.easing;return this.requiresJSAnimation()?`opacity ${t}ms ease-out`:`opacity ${t}ms ease-out, transform ${t}ms ${e}`}requiresJSAnimation(){return Lt(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 i=this.rotationConfig.startRotation;if(i===void 0)return t+(Math.random()-.5)*60;if(typeof i=="number")return i;const o=i.max-i.min;return i.min+Math.random()*o}case"spin":{const i=this.rotationConfig.spinCount??1,o=this.resolveSpinDirection(t);return t+i*360*o}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,e){if(this.rotationConfig.mode!=="wobble")return e;const i=this.rotationConfig.wobble||{amplitude:15,frequency:3,decay:!0},{amplitude:o,frequency:s,decay:r}=i,a=Math.sin(t*s*Math.PI*2),h=r?Math.pow(1-t,2):1,c=o*a*h;return e+c}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 i=this.scaleConfig.range??{min:.5,max:1};return(i.min+Math.random()*(i.max-i.min))*t}default:return t}}requiresJSScale(){return this.scaleConfig.mode==="pop"}calculatePopScale(t,e){if(this.scaleConfig.mode!=="pop")return e;const i=this.scaleConfig.pop||{overshoot:1.2,bounces:1},{overshoot:o,bounces:s}=i,r=this.generateScaleBounceKeyframes(s,o);let a=e;for(let h=0;h<r.length;h++)if(t<=r[h].time){const c=h===0?0:r[h-1].time,u=h===0?e:r[h-1].scale,l=(t-c)/(r[h].time-c),d=this.easeOutQuad(l);a=u+(r[h].scale-u)*d;break}return a*e}generateScaleBounceKeyframes(t,e){const i=[];i.push({time:.5,scale:e});let o=e;const s=.5,a=.5/(t*2);let h=.5;for(let c=0;c<t;c++){const u=1-(o-1)*s;h+=a,i.push({time:h,scale:u}),o=1+(o-1)*s*s,h+=a,c<t-1&&i.push({time:h,scale:o})}return i.push({time:1,scale:1}),i}easeOutQuad(t){return 1-(1-t)*(1-t)}}class Ft{constructor(t,e={}){this.config=t,this.imageConfig=e}generate(t,e,i={}){const o=[],{width:s,height:r}=e,a=this.config.spacing.padding,h=i.fixedHeight??200,c=this.imageConfig.rotation?.mode??"none",u=this.imageConfig.rotation?.range?.min??-15,l=this.imageConfig.rotation?.range?.max??15,d=this.imageConfig.sizing?.variance?.min??1,m=this.imageConfig.sizing?.variance?.max??1,b=d!==1||m!==1,g=h*1.5/2,f=h/2,x=s-a-g,v=r-a-f,w=a+g,I=a+f;for(let E=0;E<t;E++){const T=this.random(w,x),F=this.random(I,v),z=c==="random"?this.random(u,l):0,_=b?this.random(d,m):1,N=h*_,X={id:E,x:T,y:F,rotation:z,scale:_,baseSize:N};o.push(X)}return o}random(t,e){return Math.random()*(e-t)+t}}class zt{constructor(t,e={}){this.config=t,this.imageConfig=e}generate(t,e,i={}){const o=[],{width:s,height:r}=e,a=i.fixedHeight??200,h=this.imageConfig.rotation?.mode??"none",c=this.imageConfig.rotation?.range?.min??-15,u=this.imageConfig.rotation?.range?.max??15,l=this.imageConfig.sizing?.variance?.min??1,d=this.imageConfig.sizing?.variance?.max??1,m=l!==1||d!==1,b=this.config.scaleDecay??0,p=i.fixedHeight??a,g=s/2,f=r/2,x=Math.ceil(Math.sqrt(t));if(t>0){const I=m?this.random(l,d):1,E=p*I;o.push({id:0,x:g,y:f,rotation:h==="random"?this.random(c*.33,u*.33):0,scale:I,baseSize:E,zIndex:100})}let v=1,w=1;for(;v<t;){const I=w/x,E=b>0?1-I*b*.5:1,T=w*(p*.8),F=T*1.5,z=Math.PI*(3*(F+T)-Math.sqrt((3*F+T)*(F+3*T))),_=this.estimateWidth(p),N=Math.floor(z/(_*.7));if(N===0){w++;continue}const X=2*Math.PI/N,j=w*(20*Math.PI/180);for(let C=0;C<N&&v<t;C++){const O=C*X+j,G=m?this.random(l,d):1,H=E*G,L=p*H;let R=g+Math.cos(O)*F,$=f+Math.sin(O)*T;const P=this.config.spacing.padding??50,U=L*1.5/2,M=L/2;R-U<P?R=P+U:R+U>s-P&&(R=s-P-U),$-M<P?$=P+M:$+M>r-P&&($=r-P-M);const W=h==="random"?this.random(c,u):0;o.push({id:v,x:R,y:$,rotation:W,scale:H,baseSize:L,zIndex:Math.max(1,100-w)}),v++}w++}return o}estimateWidth(t){return t*1.4}random(t,e){return Math.random()*(e-t)+t}}const be={columns:"auto",rows:"auto",stagger:"none",jitter:0,overlap:0,fillDirection:"row",alignment:"center",gap:10,overflowOffset:.25},Dt=[{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 Ot{constructor(t,e={}){this.config=t,this.imageConfig=e}generate(t,e,i={}){const o=[],{width:s,height:r}=e,a={...be,...this.config.grid},h=this.config.spacing.padding,c=i.fixedHeight??200,u=this.imageConfig.rotation?.mode??"none",l=this.imageConfig.sizing?.variance?.min??1,d=this.imageConfig.sizing?.variance?.max??1,m=l!==1||d!==1,b=s-2*h,p=r-2*h,{columns:g,rows:f}=this.calculateGridDimensions(t,b,p,c,a),x=a.stagger==="row",v=a.stagger==="column",w=x?g+.5:g,I=v?f+.5:f,E=(b-a.gap*(g-1))/w,T=(p-a.gap*(f-1))/I,F=x?E/2:0,z=v?T/2:0,_=1+a.overlap,N=Math.min(E,T)*_,X=i.fixedHeight?Math.min(i.fixedHeight,N):N,j=g*E+(g-1)*a.gap+F,C=f*T+(f-1)*a.gap+z,O=h+(b-j)/2,G=h+(p-C)/2,H=g*f,L=a.columns!=="auto"&&a.rows!=="auto",R=L&&t>H;typeof window<"u"&&(window.__gridOverflowDebug={gridConfigColumns:a.columns,gridConfigRows:a.rows,columns:g,rows:f,cellCount:H,hasFixedGrid:L,imageCount:t,isOverflowMode:R});const $=R?new Array(H).fill(0):[],P=Math.min(E,T)*a.overflowOffset;for(let D=0;D<t;D++){let U,M,W=0;if(R&&D>=H){const Y=D-H,k=Y%H;W=Math.floor(Y/H)+1,$[k]++,a.fillDirection==="row"?(U=k%g,M=Math.floor(k/g)):(M=k%f,U=Math.floor(k/f))}else a.fillDirection==="row"?(U=D%g,M=Math.floor(D/g)):(M=D%f,U=Math.floor(D/f));let q=O+U*(E+a.gap)+E/2,B=G+M*(T+a.gap)+T/2;if(a.stagger==="row"&&M%2===1?q+=E/2:a.stagger==="column"&&U%2===1&&(B+=T/2),W>0){const Y=(W-1)%Dt.length,k=Dt[Y];q+=k.x*P,B+=k.y*P}if(a.jitter>0){const Y=E/2*a.jitter,k=T/2*a.jitter;q+=this.random(-Y,Y),B+=this.random(-k,k)}let J=q,K=B;if(!R&&a.fillDirection==="row"){const Y=t%g||g;if(M===Math.floor((t-1)/g)&&Y<g){const Vt=Y*E+(Y-1)*a.gap;let xt=0;a.alignment==="center"?xt=(j-Vt)/2:a.alignment==="end"&&(xt=j-Vt),J+=xt}}const bt=m?this.random(l,d):1,Q=X*bt,rt=Q*1.5/2,ct=Q/2,vt=h+rt,wt=s-h-rt,Me=h+ct,Fe=r-h-ct;J=Math.max(vt,Math.min(J,wt)),K=Math.max(Me,Math.min(K,Fe));let Et=0;if(u==="random"){const Y=this.imageConfig.rotation?.range?.min??-15,k=this.imageConfig.rotation?.range?.max??15;a.jitter>0?Et=this.random(Y*a.jitter,k*a.jitter):Et=this.random(Y,k)}let St;R&&W>0?St=50-W:St=R?100+D:D+1,o.push({id:D,x:J,y:K,rotation:Et,scale:bt,baseSize:Q,zIndex:St})}return o}calculateGridDimensions(t,e,i,o,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 h=e/i;for(r=Math.max(1,Math.round(Math.sqrt(t*h/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,e){return Math.random()*(e-t)+t}}const ye=Math.PI*(3-Math.sqrt(5)),ve={spiralType:"golden",direction:"counterclockwise",tightness:1,scaleDecay:0,startAngle:0};class $t{constructor(t,e={}){this.config=t,this.imageConfig=e}generate(t,e,i={}){const o=[],{width:s,height:r}=e,a={...ve,...this.config.spiral},h=this.config.spacing.padding,c=i.fixedHeight??200,u=this.imageConfig.rotation?.mode??"none",l=this.imageConfig.rotation?.range?.min??-15,d=this.imageConfig.rotation?.range?.max??15,m=this.imageConfig.sizing?.variance?.min??1,b=this.imageConfig.sizing?.variance?.max??1,p=m!==1||b!==1,g=this.config.scaleDecay??a.scaleDecay,f=s/2,x=r/2,v=Math.min(f-h-c/2,x-h-c/2),w=a.direction==="clockwise"?-1:1;for(let I=0;I<t;I++){let E,T;if(a.spiralType==="golden")E=I*ye*w+a.startAngle,T=this.calculateGoldenRadius(I,t,v,a.tightness);else if(a.spiralType==="archimedean"){const q=I*.5*a.tightness;E=q*w+a.startAngle,T=this.calculateArchimedeanRadius(q,t,v,a.tightness)}else{const q=I*.3*a.tightness;E=q*w+a.startAngle,T=this.calculateLogarithmicRadius(q,t,v,a.tightness)}const F=f+Math.cos(E)*T,z=x+Math.sin(E)*T,_=T/v,N=g>0?1-_*g*.5:1,X=p?this.random(m,b):1,j=N*X,C=c*j,G=C*1.5/2,H=C/2,L=h+G,R=s-h-G,$=h+H,P=r-h-H,D=Math.max(L,Math.min(F,R)),U=Math.max($,Math.min(z,P));let M=0;if(u==="random"){const q=E*180/Math.PI%360,B=this.random(l,d);M=a.spiralType==="golden"?B:q*.1+B*.9}else u==="tangent"&&(M=this.calculateSpiralTangent(E,T,a));const W=t-I;o.push({id:I,x:D,y:U,rotation:M,scale:j,baseSize:C,zIndex:W})}return o}calculateSpiralTangent(t,e,i){let o;if(i.spiralType==="golden")o=t+Math.PI/2;else if(i.spiralType==="archimedean"){const r=1/i.tightness,a=Math.atan(e/r);o=t+a}else{const r=.15/i.tightness,a=Math.atan(1/r);o=t+a}return o*180/Math.PI%360-90}calculateGoldenRadius(t,e,i,o){const r=i/Math.sqrt(e)*Math.sqrt(t)/o;return Math.min(r,i)}calculateArchimedeanRadius(t,e,i,o){const s=e*.5*o;return t/s*i}calculateLogarithmicRadius(t,e,i,o){const s=i*.05,r=.15/o,a=s*Math.exp(r*t),h=e*.3*o,c=s*Math.exp(r*h);return a/c*i}random(t,e){return Math.random()*(e-t)+t}}const we={clusterCount:"auto",clusterSpread:150,clusterSpacing:200,density:"uniform",overlap:.3,distribution:"gaussian"};class Pt{constructor(t,e={}){this.config=t,this.imageConfig=e}generate(t,e,i={}){const o=[],{width:s,height:r}=e,a={...we,...this.config.cluster},h=this.config.spacing.padding,c=i.fixedHeight??200,u=this.imageConfig.rotation?.mode??"none",l=this.imageConfig.rotation?.range?.min??-15,d=this.imageConfig.rotation?.range?.max??15,m=this.imageConfig.sizing?.variance?.min??1,b=this.imageConfig.sizing?.variance?.max??1,p=m!==1||b!==1,g=this.calculateClusterCount(t,a.clusterCount,s,r,a.clusterSpacing),f=this.generateClusterCenters(g,s,r,h,a),x=new Array(g).fill(0);for(let w=0;w<t;w++)x[w%g]++;let v=0;for(let w=0;w<g;w++){const I=f[w],E=x[w];for(let T=0;T<E;T++){let F,z;if(a.distribution==="gaussian")F=this.gaussianRandom()*I.spread,z=this.gaussianRandom()*I.spread;else{const M=this.random(0,Math.PI*2),W=this.random(0,I.spread);F=Math.cos(M)*W,z=Math.sin(M)*W}const _=1+a.overlap*.5,N=1+a.overlap*.3;F/=_,z/=_;const X=p?this.random(m,b):1,j=N*X,C=c*j;let O=I.x+F,G=I.y+z;const L=C*1.5/2,R=C/2;O=Math.max(h+L,Math.min(O,s-h-L)),G=Math.max(h+R,Math.min(G,r-h-R));const $=u==="random"?this.random(l,d):0,D=Math.sqrt(F*F+z*z)/I.spread,U=Math.round((1-D)*50)+1;o.push({id:v,x:O,y:G,rotation:$,scale:j,baseSize:C,zIndex:U}),v++}}return o}calculateClusterCount(t,e,i,o,s){if(e!=="auto")return Math.max(1,Math.min(e,t));const a=Math.max(1,Math.ceil(t/8)),h=Math.floor(i/s*(o/s)*.6);return Math.max(1,Math.min(a,h,10))}generateClusterCenters(t,e,i,o,s){const r=[],h=o+s.clusterSpread,c=e-o-s.clusterSpread,u=o+s.clusterSpread,l=i-o-s.clusterSpread;for(let d=0;d<t;d++){let m=null,b=-1;for(let p=0;p<100;p++){const g={x:this.random(h,c),y:this.random(u,l),spread:this.calculateClusterSpread(s)};let f=1/0;for(const x of r){const v=g.x-x.x,w=g.y-x.y,I=Math.sqrt(v*v+w*w);f=Math.min(f,I)}if((r.length===0||f>b)&&(m=g,b=f),f>=s.clusterSpacing)break}m&&r.push(m)}return r}calculateClusterSpread(t){return t.density==="uniform"?t.clusterSpread:t.clusterSpread*this.random(.5,1.5)}gaussianRandom(){let t=0,e=0;for(;t===0;)t=Math.random();for(;e===0;)e=Math.random();const i=Math.sqrt(-2*Math.log(t))*Math.cos(2*Math.PI*e);return Math.max(-3,Math.min(3,i))/3}random(t,e){return Math.random()*(e-t)+t}}class Ut{constructor(t,e={}){this.config=t,this.imageConfig=e}generate(t,e,i={}){const o=[],{width:s,height:r}=e,a=i.fixedHeight??200,h=this.config.spacing.padding??50,c=this.imageConfig.rotation?.mode??"none",u=this.imageConfig.rotation?.range?.min??-15,l=this.imageConfig.rotation?.range?.max??15,d=this.imageConfig.sizing?.variance?.min??1,m=this.imageConfig.sizing?.variance?.max??1,b=d!==1||m!==1,p=i.fixedHeight??a,g={...Zt,...this.config.wave},{rows:f,amplitude:x,frequency:v,phaseShift:w,synchronization:I}=g,E=Math.ceil(t/f),z=p*1.5/2,_=h+z,N=s-h-z,X=N-_,j=E>1?X/(E-1):0,C=h+x+p/2,O=r-h-x-p/2,G=O-C,H=f>1?G/(f-1):0;let L=0;for(let R=0;R<f&&L<t;R++){const $=f===1?(C+O)/2:C+R*H;let P=0;I==="offset"?P=R*w:I==="alternating"&&(P=R*Math.PI);for(let D=0;D<E&&L<t;D++){const U=E===1?(_+N)/2:_+D*j,M=this.calculateWaveY(U,s,x,v,P),W=U,q=$+M,B=b?this.random(d,m):1,J=p*B;let K=0;c==="tangent"?K=this.calculateRotation(U,s,x,v,P):c==="random"&&(K=this.random(u,l));const Q=J*1.5/2,yt=J/2,rt=h+Q,ct=s-h-Q,vt=h+yt,wt=r-h-yt;o.push({id:L,x:Math.max(rt,Math.min(W,ct)),y:Math.max(vt,Math.min(q,wt)),rotation:K,scale:B,baseSize:J,zIndex:L+1}),L++}}return o}calculateWaveY(t,e,i,o,s){const r=t/e;return i*Math.sin(o*r*2*Math.PI+s)}calculateRotation(t,e,i,o,s){const r=t/e,a=i*o*2*Math.PI*Math.cos(o*r*2*Math.PI+s)/e;return Math.atan(a)*(180/Math.PI)}random(t,e){return Math.random()*(e-t)+t}}class _t{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 zt(this.config,this.imageConfig);case"grid":return new Ot(this.config,this.imageConfig);case"spiral":return new $t(this.config,this.imageConfig);case"cluster":return new Pt(this.config,this.imageConfig);case"wave":return new Ut(this.config,this.imageConfig);default:return new Ft(this.config,this.imageConfig)}}generateLayout(t,e,i={}){const o=this.placementLayout.generate(t,e,i);return o.forEach(s=>{this.layouts.set(s.id,s)}),o}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 e=this.getBreakpoints();return t<=e.mobile.maxWidth?"mobile":t<=e.tablet.maxWidth?"tablet":"screen"}resolveBaseHeight(t){const e=this.imageConfig.sizing;if(!e||e.mode==="adaptive")return;const i=e.height;if(i===void 0)return;if(typeof i=="number")return i;const o=i,s=this.resolveBreakpoint(t);return s==="mobile"?o.mobile??o.tablet??o.screen:s==="tablet"?o.tablet??o.screen??o.mobile:o.screen??o.tablet??o.mobile}calculateAdaptiveSize(t,e,i,o){const s=this.imageConfig.sizing,r=this.resolveBaseHeight(o);if(r!==void 0)return{height:r};const a=s?.minSize??50,h=s?.maxSize??400,c=this.config.targetCoverage??.6,u=this.config.densityFactor??1,{width:l,height:d}=t,p=l*d*c/e;let f=Math.sqrt(p/1.4);f*=u,f=Math.min(f,i);let x=this.clamp(f,a,h);if(x===a&&f<a){const v=Math.max(a*.05,20);x=Math.max(v,f)}return{height:x}}clamp(t,e,i){return Math.max(e,Math.min(i,t))}}var S=(n=>(n.IDLE="idle",n.FOCUSING="focusing",n.FOCUSED="focused",n.UNFOCUSING="unfocusing",n.CROSS_ANIMATING="cross_animating",n))(S||{});function Ee(n){return n in V}function Se(n){return n?Ee(n)?V[n]:n:V.md}function xe(n){if(!n)return"";const t=[];if(n.grayscale!==void 0&&t.push(`grayscale(${n.grayscale})`),n.blur!==void 0&&t.push(`blur(${n.blur}px)`),n.brightness!==void 0&&t.push(`brightness(${n.brightness})`),n.contrast!==void 0&&t.push(`contrast(${n.contrast})`),n.saturate!==void 0&&t.push(`saturate(${n.saturate})`),n.opacity!==void 0&&t.push(`opacity(${n.opacity})`),n.sepia!==void 0&&t.push(`sepia(${n.sepia})`),n.hueRotate!==void 0&&t.push(`hue-rotate(${n.hueRotate}deg)`),n.invert!==void 0&&t.push(`invert(${n.invert})`),n.dropShadow!==void 0)if(typeof n.dropShadow=="string")t.push(`drop-shadow(${n.dropShadow})`);else{const e=n.dropShadow;t.push(`drop-shadow(${e.x}px ${e.y}px ${e.blur}px ${e.color})`)}return t.join(" ")}function et(n){if(!n||n.style==="none"||n.width===0)return"none";const t=n.width??0,e=n.style??"solid",i=n.color??"#000000";return`${t}px ${e} ${i}`}function st(n){if(!n)return{};const t={};if(n.borderRadiusTopLeft!==void 0||n.borderRadiusTopRight!==void 0||n.borderRadiusBottomRight!==void 0||n.borderRadiusBottomLeft!==void 0){const s=n.border?.radius??0;n.borderRadiusTopLeft!==void 0?t.borderTopLeftRadius=`${n.borderRadiusTopLeft}px`:s&&(t.borderTopLeftRadius=`${s}px`),n.borderRadiusTopRight!==void 0?t.borderTopRightRadius=`${n.borderRadiusTopRight}px`:s&&(t.borderTopRightRadius=`${s}px`),n.borderRadiusBottomRight!==void 0?t.borderBottomRightRadius=`${n.borderRadiusBottomRight}px`:s&&(t.borderBottomRightRadius=`${s}px`),n.borderRadiusBottomLeft!==void 0?t.borderBottomLeftRadius=`${n.borderRadiusBottomLeft}px`:s&&(t.borderBottomLeftRadius=`${s}px`)}else n.border?.radius!==void 0&&(t.borderRadius=`${n.border.radius}px`);if(n.borderTop||n.borderRight||n.borderBottom||n.borderLeft){const s=n.border||{},r={...s,...n.borderTop},a={...s,...n.borderRight},h={...s,...n.borderBottom},c={...s,...n.borderLeft};t.borderTop=et(r),t.borderRight=et(a),t.borderBottom=et(h),t.borderLeft=et(c)}else n.border&&(t.border=et(n.border));n.shadow!==void 0&&(t.boxShadow=Se(n.shadow));const o=xe(n.filter);if(t.filter=o||"none",n.opacity!==void 0&&(t.opacity=String(n.opacity)),n.cursor!==void 0&&(t.cursor=n.cursor),n.outline&&n.outline.style!=="none"&&(n.outline.width??0)>0){const s=n.outline.width??0,r=n.outline.style??"solid",a=n.outline.color??"#000000";t.outline=`${s}px ${r} ${a}`,n.outline.offset!==void 0&&(t.outlineOffset=`${n.outline.offset}px`)}return n.objectFit!==void 0&&(t.objectFit=n.objectFit),n.aspectRatio!==void 0&&(t.aspectRatio=n.aspectRatio),t}function it(n,t){t.borderRadius!==void 0&&(n.style.borderRadius=t.borderRadius),t.borderTopLeftRadius!==void 0&&(n.style.borderTopLeftRadius=t.borderTopLeftRadius),t.borderTopRightRadius!==void 0&&(n.style.borderTopRightRadius=t.borderTopRightRadius),t.borderBottomRightRadius!==void 0&&(n.style.borderBottomRightRadius=t.borderBottomRightRadius),t.borderBottomLeftRadius!==void 0&&(n.style.borderBottomLeftRadius=t.borderBottomLeftRadius),t.border!==void 0&&(n.style.border=t.border),t.borderTop!==void 0&&(n.style.borderTop=t.borderTop),t.borderRight!==void 0&&(n.style.borderRight=t.borderRight),t.borderBottom!==void 0&&(n.style.borderBottom=t.borderBottom),t.borderLeft!==void 0&&(n.style.borderLeft=t.borderLeft),t.boxShadow!==void 0&&(n.style.boxShadow=t.boxShadow),t.filter!==void 0&&(n.style.filter=t.filter),t.opacity!==void 0&&(n.style.opacity=t.opacity),t.cursor!==void 0&&(n.style.cursor=t.cursor),t.outline!==void 0&&(n.style.outline=t.outline),t.outlineOffset!==void 0&&(n.style.outlineOffset=t.outlineOffset),t.objectFit!==void 0&&(n.style.objectFit=t.objectFit),t.aspectRatio!==void 0&&(n.style.aspectRatio=t.aspectRatio)}function Nt(n){return n?Array.isArray(n)?n.join(" "):n:""}function nt(n,t){const e=Nt(t);e&&e.split(" ").forEach(i=>{i.trim()&&n.classList.add(i.trim())})}function Ht(n,t){const e=Nt(t);e&&e.split(" ").forEach(i=>{i.trim()&&n.classList.remove(i.trim())})}const jt={UNFOCUSING:999,FOCUSING:1e3};class kt{constructor(t,e,i){this.state=S.IDLE,this.currentFocus=null,this.focusData=null,this.outgoing=null,this.incoming=null,this.focusGeneration=0,this.config=t,this.animationEngine=e,this.defaultStyles=st(i?.default),this.focusedStyles=st(i?.focused),this.defaultClassName=i?.default?.className,this.focusedClassName=i?.focused?.className}getState(){return this.state}isAnimating(){return this.state!==S.IDLE&&this.state!==S.FOCUSED}normalizeScalePercent(t){return t>1?t/100:t}calculateFocusDimensions(t,e,i){const o=this.normalizeScalePercent(this.config.scalePercent),s=i.height*o,r=t/e;let a=s,h=a*r;const c=i.width*o;return h>c&&(h=c,a=h/r),{width:h,height:a}}calculateFocusTransform(t,e){const i=t.width/2,o=t.height/2,s=i-e.x,r=o-e.y;return{x:s,y:r,rotation:0,scale:1}}buildDimensionZoomTransform(t){const e=["translate(-50%, -50%)"];if(t.x!==void 0||t.y!==void 0){const i=t.x??0,o=t.y??0;e.push(`translate(${i}px, ${o}px)`)}return t.rotation!==void 0&&e.push(`rotate(${t.rotation}deg)`),e.join(" ")}animateWithDimensions(t,e,i,o,s,r,a,h){const c=this.buildDimensionZoomTransform(e),u=this.buildDimensionZoomTransform(i);return t.style.transition="none",t.animate([{transform:c,width:`${o}px`,height:`${s}px`},{transform:u,width:`${r}px`,height:`${a}px`}],{duration:h,easing:"cubic-bezier(0.4, 0, 0.2, 1)",fill:"forwards"})}applyFocusedStyling(t,e){t.style.zIndex=String(e),t.classList.add("fbn-ic-focused"),it(t,this.focusedStyles),nt(t,this.focusedClassName)}removeFocusedStyling(t,e){t.style.zIndex=e,t.classList.remove("fbn-ic-focused"),Ht(t,this.focusedClassName),it(t,this.defaultStyles),nt(t,this.defaultClassName)}startFocusAnimation(t,e,i,o,s){const r=t.style.zIndex||"",a=t.offsetWidth,h=t.offsetHeight,c=this.calculateFocusDimensions(a,h,e),u=this.calculateFocusTransform(e,i);this.applyFocusedStyling(t,jt.FOCUSING),this.animationEngine.cancelAllAnimations(t);const l=o??{x:0,y:0,rotation:i.rotation,scale:1},d=s?.width??a,m=s?.height??h,b=this.config.animationDuration??600,p=this.animateWithDimensions(t,l,u,d,m,c.width,c.height,b),g={id:`focus-${Date.now()}`,element:t,animation:p,fromState:l,toState:u,startTime:performance.now(),duration:b};return this.focusData={element:t,originalState:i,focusTransform:u,originalZIndex:r,originalWidth:a,originalHeight:h,focusWidth:c.width,focusHeight:c.height},{element:t,originalState:i,animationHandle:g,direction:"in",originalWidth:a,originalHeight:h}}startUnfocusAnimation(t,e,i,o){t.style.zIndex=String(jt.UNFOCUSING),this.animationEngine.cancelAllAnimations(t);const s=i??this.focusData?.focusTransform??{x:0,y:0,rotation:0,scale:1},r=o?.width??this.focusData?.focusWidth??t.offsetWidth,a=o?.height??this.focusData?.focusHeight??t.offsetHeight,h={x:0,y:0,rotation:e.rotation,scale:1},c=this.focusData?.originalWidth??t.offsetWidth,u=this.focusData?.originalHeight??t.offsetHeight,l=this.config.animationDuration??600,d=this.animateWithDimensions(t,s,h,r,a,c,u,l),m={id:`unfocus-${Date.now()}`,element:t,animation:d,fromState:s,toState:h,startTime:performance.now(),duration:l};return{element:t,originalState:e,animationHandle:m,direction:"out",originalWidth:c,originalHeight:u}}captureMidAnimationState(t){const e=getComputedStyle(t),i=new DOMMatrix(e.transform),o=t.offsetWidth,s=t.offsetHeight,r=i.e+o*.5,a=i.f+s*.5,h=Math.atan2(i.b,i.a)*(180/Math.PI);return t.style.width=`${o}px`,t.style.height=`${s}px`,t.style.transform=`translate(-50%, -50%) translate(${r}px, ${a}px) rotate(${h}deg)`,t.style.transition="none",{transform:{x:r,y:a,rotation:h,scale:1},dimensions:{width:o,height:s}}}async waitForAnimation(t){try{await t.animation.finished}catch{}}resetElementInstantly(t,e,i,o,s){this.animationEngine.cancelAllAnimations(t);const r=["translate(-50%, -50%)"];r.push("translate(0px, 0px)"),r.push(`rotate(${e.rotation}deg)`),t.style.transition="none",t.style.transform=r.join(" "),o!==void 0&&s!==void 0&&(t.style.width=`${o}px`,t.style.height=`${s}px`),this.removeFocusedStyling(t,i)}async focusImage(t,e,i){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 o=++this.focusGeneration;switch(this.state){case S.IDLE:if(this.state=S.FOCUSING,this.incoming=this.startFocusAnimation(t,e,i),await this.waitForAnimation(this.incoming.animationHandle),this.focusGeneration!==o)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,e,i),await Promise.all([this.outgoing?this.waitForAnimation(this.outgoing.animationHandle):Promise.resolve(),this.waitForAnimation(this.incoming.animationHandle)]),this.focusGeneration!==o)return;this.outgoing&&(this.removeFocusedStyling(this.outgoing.element,this.outgoing.originalState.zIndex?.toString()||""),this.outgoing=null),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,e,i),await this.waitForAnimation(this.incoming.animationHandle),this.focusGeneration!==o)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,e,i),await Promise.all([this.outgoing?this.waitForAnimation(this.outgoing.animationHandle):Promise.resolve(),this.waitForAnimation(this.incoming.animationHandle)]),this.focusGeneration!==o)return;this.outgoing&&(this.removeFocusedStyling(this.outgoing.element,this.outgoing.originalState.zIndex?.toString()||""),this.outgoing=null),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:h}=this.captureMidAnimationState(this.incoming.element);this.animationEngine.cancelAllAnimations(this.incoming.element),this.outgoing=this.startUnfocusAnimation(this.incoming.element,this.incoming.originalState,a,h)}else this.outgoing=null;if(this.incoming=this.startFocusAnimation(t,e,i,s,r),await Promise.all([this.outgoing?this.waitForAnimation(this.outgoing.animationHandle):Promise.resolve(),this.waitForAnimation(this.incoming.animationHandle)]),this.focusGeneration!==o)return;this.outgoing&&(this.removeFocusedStyling(this.outgoing.element,this.outgoing.originalState.zIndex?.toString()||""),this.outgoing=null),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,e,i),await Promise.all([this.outgoing?this.waitForAnimation(this.outgoing.animationHandle):Promise.resolve(),this.waitForAnimation(this.incoming.animationHandle)]),this.focusGeneration!==o)return;this.outgoing&&(this.removeFocusedStyling(this.outgoing.element,this.outgoing.originalState.zIndex?.toString()||""),this.outgoing=null),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;this.removeFocusedStyling(this.outgoing.element,this.focusData?.originalZIndex||""),this.outgoing=null,this.focusData=null,this.state=S.IDLE}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;this.outgoing&&this.removeFocusedStyling(this.outgoing.element,this.outgoing.originalState.zIndex?.toString()||""),this.removeFocusedStyling(a.element,this.incoming.originalState.zIndex?.toString()||""),this.outgoing=null,this.incoming=null,this.currentFocus=null,this.focusData=null,this.state=S.IDLE;return}this.state=S.UNFOCUSING;const e=this.currentFocus,i=this.focusData.originalState,o=this.focusData.originalZIndex;this.outgoing=this.startUnfocusAnimation(e,i),await this.waitForAnimation(this.outgoing.animationHandle),this.focusGeneration===t&&(this.removeFocusedStyling(e,o),this.outgoing=null,this.currentFocus=null,this.focusData=null,this.state=S.IDLE)}async swapFocus(t,e,i){return this.focusImage(t,e,i)}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 e=this.currentFocus,i=this.focusData.focusTransform,o=["translate(-50%, -50%)"],s=(i.x??0)+t,r=i.y??0;o.push(`translate(${s}px, ${r}px)`),i.rotation!==void 0&&o.push(`rotate(${i.rotation}deg)`),e.style.transition="none",e.style.transform=o.join(" ")}clearDragOffset(t,e=150){if(!this.currentFocus||!this.focusData||this.state!==S.FOCUSED)return;const i=this.currentFocus,o=this.focusData.focusTransform,s=["translate(-50%, -50%)"],r=o.x??0,a=o.y??0;s.push(`translate(${r}px, ${a}px)`),o.rotation!==void 0&&s.push(`rotate(${o.rotation}deg)`);const h=s.join(" ");t?(i.style.transition=`transform ${e}ms ease-out`,i.style.transform=h,setTimeout(()=>{this.currentFocus===i&&(i.style.transition="none")},e)):(i.style.transition="none",i.style.transform=h)}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 Ie=50,Ae=.5,Te=20,Ce=.3,Re=150,Le=30,at=class at{constructor(t,e){this.enabled=!1,this.touchState=null,this.recentTouchTimestamp=0,this.container=t,this.callbacks=e,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<at.TOUCH_CLICK_DELAY}handleTouchStart(t){if(t.touches.length!==1)return;this.recentTouchTimestamp=Date.now();const e=t.touches[0];this.touchState={startX:e.clientX,startY:e.clientY,startTime:performance.now(),currentX:e.clientX,isDragging:!1,isHorizontalSwipe:null}}handleTouchMove(t){if(!this.touchState||t.touches.length!==1)return;const e=t.touches[0],i=e.clientX-this.touchState.startX,o=e.clientY-this.touchState.startY;if(this.touchState.isHorizontalSwipe===null&&Math.sqrt(i*i+o*o)>10){const a=Math.atan2(Math.abs(o),Math.abs(i))*(180/Math.PI);this.touchState.isHorizontalSwipe=a<=Le}if(this.touchState.isHorizontalSwipe!==!1&&this.touchState.isHorizontalSwipe===!0){t.preventDefault(),this.touchState.isDragging=!0,this.touchState.currentX=e.clientX;const s=i*Ce;this.callbacks.onDragOffset(s)}}handleTouchEnd(t){if(!this.touchState)return;this.recentTouchTimestamp=Date.now();const e=this.touchState.currentX-this.touchState.startX,i=performance.now()-this.touchState.startTime,o=Math.abs(e)/i,s=Math.abs(e);let r=!1;this.touchState.isHorizontalSwipe===!0&&this.touchState.isDragging&&(s>=Ie||o>=Ae&&s>=Te)&&(r=!0,e<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}};at.TOUCH_CLICK_DELAY=300;let pt=at;class Gt{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 e of this.sources)if("folders"in e)for(const i of e.folders){const o=e.recursive!==void 0?e.recursive:!0,s=await this.loadFromFolder(i,t,o);this._discoveredUrls.push(...s)}else if("files"in e){const i=await this.loadFiles(e.files,t);this._discoveredUrls.push(...i)}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 e=[/\/folders\/([a-zA-Z0-9_-]+)/,/id=([a-zA-Z0-9_-]+)/];for(const i of e){const o=t.match(i);if(o&&o[1])return o[1]}return null}async loadFromFolder(t,e,i=!0){const o=this.extractFolderId(t);if(!o)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(o,e);try{return i?await this.loadImagesRecursively(o,e):await this.loadImagesFromSingleFolder(o,e)}catch(s){return console.error("Error loading from Google Drive API:",s),this.loadImagesDirectly(o,e)}}async loadImagesFromSingleFolder(t,e){const i=[],o=`'${t}' in parents and trashed=false`,r=`${this.apiEndpoint}?q=${encodeURIComponent(o)}&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()).files.filter(u=>u.mimeType.startsWith("image/")&&e.isAllowed(u.name));return this.log(`Found ${c.length} images in folder ${t} (non-recursive)`),c.forEach(u=>{i.push(`https://lh3.googleusercontent.com/d/${u.id}=s1600`),this.log(`Added file: ${u.name}`)}),i}async loadFiles(t,e){const i=[];for(const o of t){const s=this.extractFileId(o);if(!s){this.log(`Skipping invalid file URL: ${o}`);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 h=await a.json();h.mimeType.startsWith("image/")&&e.isAllowed(h.name)?(i.push(`https://lh3.googleusercontent.com/d/${s}=s1600`),this.log(`Added file: ${h.name}`)):this.log(`Skipping non-image file: ${h.name} (${h.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 i.push(`https://lh3.googleusercontent.com/d/${s}=s1600`)}return i}extractFileId(t){if(!/[/:.]/.test(t))return t;const e=[/\/file\/d\/([a-zA-Z0-9_-]+)/,/\/open\?id=([a-zA-Z0-9_-]+)/,/id=([a-zA-Z0-9_-]+)/];for(const i of e){const o=t.match(i);if(o&&o[1])return o[1]}return null}async loadImagesRecursively(t,e){const i=[],o=`'${t}' in parents and trashed=false`,r=`${this.apiEndpoint}?q=${encodeURIComponent(o)}&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 h=await a.json(),c=h.files.filter(l=>l.mimeType.startsWith("image/")&&e.isAllowed(l.name)),u=h.files.filter(l=>l.mimeType==="application/vnd.google-apps.folder");this.log(`Found ${h.files.length} total items in folder ${t}`),h.files.forEach(l=>this.log(` - File: ${l.name} (${l.mimeType})`)),this.log(`- ${c.length} valid files (images only)`),this.log(`- ${u.length} subfolders`),c.forEach(l=>{i.push(`https://lh3.googleusercontent.com/d/${l.id}=s1600`),this.log(`Added file: ${l.name}`)});for(const l of u){this.log(`Loading images from subfolder: ${l.name}`);const d=await this.loadImagesRecursively(l.id,e);i.push(...d)}return i}async loadImagesDirectly(t,e){try{const i=`https://drive.google.com/embeddedfolderview?id=${t}`,o=await fetch(i,{mode:"cors"});if(!o.ok)throw new Error("Cannot access folder directly (CORS or permissions issue)");const s=await o.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(i){throw console.error("Direct loading failed:",i),new Error(`Unable to load images. Please ensure:
2
- 1. The folder is shared publicly (Anyone with the link can view)
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(e=>`https://drive.google.com/uc?export=view&id=${e}`)}log(...t){this.debugLogging&&typeof console<"u"&&console.log(...t)}}class Wt{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 e of this.sources)try{const i=await this.processSource(e,t);this._discoveredUrls.push(...i)}catch(i){console.warn("Failed to process source:",e,i)}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,e){return t?"urls"in t?await this.processUrls(t.urls,e):"path"in t?await this.processPath(t.path,t.files,e):"json"in t?await this.processJson(t.json,e):(console.warn("Unknown source shape:",t),[]):(console.warn("Invalid source object:",t),[])}async processUrls(t,e){if(!Array.isArray(t))return console.warn("URLs must be an array:",t),[];const i=[];for(const o of t){const s=o.split("/").pop()||o;if(!e.isAllowed(s)){this.log(`Skipping filtered URL: ${o}`);continue}this.validateUrls?await this.validateUrl(o)?i.push(o):console.warn(`Skipping invalid/missing URL: ${o}`):i.push(o)}return i}async processPath(t,e,i){if(!Array.isArray(e))return console.warn("files must be an array:",e),[];const o=[];for(const s of e){if(!i.isAllowed(s)){this.log(`Skipping filtered file: ${s}`);continue}const r=this.constructUrl(t,s);this.validateUrls?await this.validateUrl(r)?o.push(r):console.warn(`Skipping invalid/missing file: ${r}`):o.push(r)}return o}async processJson(t,e){this.log(`Fetching JSON endpoint: ${t}`);const i=new AbortController,o=setTimeout(()=>i.abort(),1e4);try{const s=await fetch(t,{signal:i.signal});if(clearTimeout(o),!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,e)}catch(s){throw clearTimeout(o),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 i=new AbortController,o=setTimeout(()=>i.abort(),this.validationTimeout),s=await fetch(t,{method:"HEAD",signal:i.signal});return clearTimeout(o),s.ok?!0:(this.log(`Validation failed for ${t}: HTTP ${s.status}`),!1)}catch(i){return i instanceof Error&&(i.name==="AbortError"?this.log(`Validation timeout for ${t}`):this.log(`Validation failed for ${t}:`,i.message)),!1}}constructUrl(t,e){const i=t.replace(/\/$/,"");if(this.isAbsoluteUrl(t))return`${i}/${e}`;if(typeof window>"u")return`${i}/${e}`;const o=window.location.origin,r=(t.startsWith("/")?t:"/"+t).replace(/\/$/,"");return`${o}${r}/${e}`}isAbsoluteUrl(t){try{return new URL(t),!0}catch{return!1}}log(...t){this.debugLogging&&typeof console<"u"&&console.log(...t)}}class qt{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 e=this.loaders.map((i,o)=>i.prepare(t).then(()=>{this.log(`Loader ${o} prepared with ${i.imagesLength()} images`)}).catch(s=>{console.warn(`Loader ${o} failed to prepare:`,s)}));await Promise.all(e);for(const i of this.loaders)if(i.isPrepared()){const o=i.imageURLs();this._discoveredUrls.push(...o)}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 Yt{constructor(t){this.allowedExtensions=t||["jpg","jpeg","png","gif","webp","bmp"]}isAllowed(t){const i=t.split("?")[0].split(".").pop()?.toLowerCase();return i?this.allowedExtensions.includes(i):!1}getAllowedExtensions(){return[...this.allowedExtensions]}}const Xt=`
1
+ (function(A,V){typeof exports=="object"&&typeof module<"u"?V(exports):typeof define=="function"&&define.amd?define(["exports"],V):(A=typeof globalThis<"u"?globalThis:A||self,V(A.ImageCloud={}))})(this,(function(A){"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)"}),dt=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})}),ut=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})}),gt=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})}),mt=Object.freeze({type:"linear"}),ft=Object.freeze({mode:"none"}),pt=Object.freeze({mode:"none"}),Tt=Object.freeze({default:Object.freeze({border:Object.freeze({width:0,color:"#000000",radius:0,style:"solid"}),shadow:"none",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"})}),Vt=Object.freeze({rows:1,amplitude:100,frequency:2,phaseShift:0,synchronization:"offset"}),Zt=Object.freeze({mobile:Object.freeze({maxWidth:767}),tablet:Object.freeze({maxWidth:1199})}),Kt=Object.freeze({mode:"adaptive",minSize:50,maxSize:400,variance:Object.freeze({min:1,max:1})}),Qt=Object.freeze({mode:"none",range:Object.freeze({min:-15,max:15})}),Ct=Object.freeze({sizing:Kt,rotation:Qt}),yt=Object.freeze({validateUrls:!0,validationTimeout:5e3,validationMethod:"head",allowedExtensions:["jpg","jpeg","png","gif","webp","bmp"]}),Rt=Object.freeze({enabled:!1,centers:!1,loaders:!1}),b=Object.freeze({loaders:[],config:Object.freeze({loaders:yt,debug:Rt}),image:Ct,layout:Object.freeze({algorithm:"radial",scaleDecay:0,responsive:Zt,targetCoverage:.6,densityFactor:1,spacing:Object.freeze({padding:50,minGap:20})}),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,maxConcurrent:void 0}),performance:Object.freeze({useGPU:void 0,reduceMotion:void 0}),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:mt,rotation:ft,scale:pt})}),interaction:Object.freeze({focus:Object.freeze({scalePercent:.8,zIndex:1e3,animationDuration:void 0}),navigation:Object.freeze({keyboard:void 0,swipe:void 0,mouseWheel:void 0}),gestures:Object.freeze({pinchToZoom:void 0,doubleTapToFocus:void 0})}),rendering:Object.freeze({responsive:Object.freeze({breakpoints:Object.freeze({mobile:768,tablet:void 0,desktop:void 0}),mobileDetection:()=>typeof window>"u"?!1:window.innerWidth<=768}),ui:Object.freeze({showLoadingSpinner:!1,showImageCounter:!1,showThumbnails:void 0,theme:void 0}),performance:Object.freeze({lazyLoad:void 0,preloadCount:void 0,imageQuality:void 0})}),styling:Tt});function et(o,t){if(!o)return t||{};if(!t)return{...o};const e={...o};return t.border!==void 0&&(e.border={...o.border,...t.border}),t.borderTop!==void 0&&(e.borderTop={...o.borderTop,...t.borderTop}),t.borderRight!==void 0&&(e.borderRight={...o.borderRight,...t.borderRight}),t.borderBottom!==void 0&&(e.borderBottom={...o.borderBottom,...t.borderBottom}),t.borderLeft!==void 0&&(e.borderLeft={...o.borderLeft,...t.borderLeft}),t.filter!==void 0&&(e.filter={...o.filter,...t.filter}),t.outline!==void 0&&(e.outline={...o.outline,...t.outline}),t.shadow!==void 0&&(e.shadow=t.shadow),t.opacity!==void 0&&(e.opacity=t.opacity),t.cursor!==void 0&&(e.cursor=t.cursor),t.className!==void 0&&(e.className=t.className),t.objectFit!==void 0&&(e.objectFit=t.objectFit),t.aspectRatio!==void 0&&(e.aspectRatio=t.aspectRatio),t.borderRadiusTopLeft!==void 0&&(e.borderRadiusTopLeft=t.borderRadiusTopLeft),t.borderRadiusTopRight!==void 0&&(e.borderRadiusTopRight=t.borderRadiusTopRight),t.borderRadiusBottomRight!==void 0&&(e.borderRadiusBottomRight=t.borderRadiusBottomRight),t.borderRadiusBottomLeft!==void 0&&(e.borderRadiusBottomLeft=t.borderRadiusBottomLeft),e}function te(o,t){if(!t)return{...o};const e=et(o.default,t.default),i=et(et(e,o.hover),t.hover),n=et(et(e,o.focused),t.focused);return{default:e,hover:i,focused:n}}function ee(o,t){if(!t)return{...o};const e={...o};if(t.sizing!==void 0&&(e.sizing={...o.sizing,...t.sizing},t.sizing.variance)){const i=t.sizing.variance,n=i.min!==void 0&&i.min>=.25&&i.min<=1?i.min:o.sizing?.variance?.min??1,s=i.max!==void 0&&i.max>=1&&i.max<=1.75?i.max:o.sizing?.variance?.max??1;e.sizing.variance={min:n,max:s}}if(t.rotation!==void 0&&(e.rotation={...o.rotation,...t.rotation},t.rotation.range)){const i=t.rotation.range,n=i.min!==void 0&&i.min>=-180&&i.min<=0?i.min:o.rotation?.range?.min??-15,s=i.max!==void 0&&i.max>=0&&i.max<=180?i.max:o.rotation?.range?.max??15;e.rotation.range={min:n,max:s}}return e}function ie(o){const t=o.layout?.rotation;if(t&&"enabled"in t)return{rotation:{mode:t.enabled?"random":"none",range:t.range}}}function ne(o){const t=o.layout?.sizing?.variance;if(t)return{sizing:{mode:"adaptive",variance:t}}}function oe(o={}){const t=ie(o),e=ne(o);let i=o.image;(t||e)&&(i={...e||{},...t||{},...i},i.rotation&&t?.rotation&&o.image?.rotation&&(i.rotation={...t.rotation,...o.image.rotation}));const n=[...o.loaders??[]];o.images&&o.images.length>0&&n.unshift({static:{sources:[{urls:o.images}]}});const r={loaders:{...yt,...o.config?.loaders??{}}},a={loaders:n,config:r,image:ee(Ct,i),layout:{...b.layout},animation:{...b.animation},interaction:{...b.interaction},rendering:{...b.rendering},styling:te(Tt,o.styling)};return o.layout&&(a.layout={...b.layout,...o.layout},o.layout.responsive&&(a.layout.responsive={...b.layout.responsive,mobile:o.layout.responsive.mobile?{...b.layout.responsive.mobile,...o.layout.responsive.mobile}:b.layout.responsive.mobile,tablet:o.layout.responsive.tablet?{...b.layout.responsive.tablet,...o.layout.responsive.tablet}:b.layout.responsive.tablet}),o.layout.spacing&&(a.layout.spacing={...b.layout.spacing,...o.layout.spacing})),o.animation&&(a.animation={...b.animation,...o.animation},o.animation.easing&&(a.animation.easing={...b.animation.easing,...o.animation.easing}),o.animation.queue&&(a.animation.queue={...b.animation.queue,...o.animation.queue}),o.animation.performance&&(a.animation.performance={...b.animation.performance,...o.animation.performance}),o.animation.entry&&(a.animation.entry={...b.animation.entry,...o.animation.entry,start:o.animation.entry.start?{...b.animation.entry.start,...o.animation.entry.start,circular:o.animation.entry.start.circular?{...b.animation.entry.start.circular,...o.animation.entry.start.circular}:b.animation.entry.start.circular}:b.animation.entry.start,timing:o.animation.entry.timing?{...b.animation.entry.timing,...o.animation.entry.timing}:b.animation.entry.timing,path:o.animation.entry.path?{...mt,...o.animation.entry.path}:b.animation.entry.path,rotation:o.animation.entry.rotation?{...ft,...o.animation.entry.rotation}:b.animation.entry.rotation,scale:o.animation.entry.scale?{...pt,...o.animation.entry.scale}:b.animation.entry.scale})),o.interaction&&(a.interaction={...b.interaction,...o.interaction},o.interaction.focus&&(a.interaction.focus={...b.interaction.focus,...o.interaction.focus}),o.interaction.navigation&&(a.interaction.navigation={...b.interaction.navigation,...o.interaction.navigation}),o.interaction.gestures&&(a.interaction.gestures={...b.interaction.gestures,...o.interaction.gestures})),o.rendering&&(a.rendering={...b.rendering,...o.rendering},o.rendering.responsive&&(a.rendering.responsive={...b.rendering.responsive,...o.rendering.responsive,breakpoints:o.rendering.responsive.breakpoints?{...b.rendering.responsive.breakpoints,...o.rendering.responsive.breakpoints}:b.rendering.responsive.breakpoints,mobileDetection:o.rendering.responsive.mobileDetection?o.rendering.responsive.mobileDetection:b.rendering.responsive.mobileDetection}),o.rendering.ui&&(a.rendering.ui={...b.rendering.ui,...o.rendering.ui}),o.rendering.performance&&(a.rendering.performance={...b.rendering.performance,...o.rendering.performance})),a.config.debug={...Rt,...o.config?.debug??{}},a}function se(o,t){return{...o?dt[o]:dt.playful,...t}}function ae(o,t){return{...o?ut[o]:ut.gentle,...t}}function re(o,t){return{...o?gt[o]:gt.gentle,...t}}class Lt{constructor(t){this.activeAnimations=new Map,this.animationIdCounter=0,this.config=t}buildTransformString(t){const e=["translate(-50%, -50%)"];if(t.x!==void 0||t.y!==void 0){const i=t.x??0,n=t.y??0;e.push(`translate(${i}px, ${n}px)`)}return t.rotation!==void 0&&e.push(`rotate(${t.rotation}deg)`),t.scale!==void 0&&e.push(`scale(${t.scale})`),e.join(" ")}animateTransformCancellable(t,e,i,n=null,s=null){this.cancelAllAnimations(t);const r=n??this.config.duration,a=s??this.config.easing.default,h=this.buildTransformString(e),c=this.buildTransformString(i);t.style.transition="none";const u=t.animate([{transform:h},{transform:c}],{duration:r,easing:a,fill:"forwards"}),l={id:`anim-${++this.animationIdCounter}`,element:t,animation:u,fromState:e,toState:i,startTime:performance.now(),duration:r};return this.activeAnimations.set(t,l),u.finished.then(()=>{t.style.transform=c,this.activeAnimations.delete(t)}).catch(()=>{this.activeAnimations.delete(t)}),l}cancelAnimation(t,e=!0){const i=this.getCurrentTransform(t.element);if(t.animation.cancel(),e){const n=this.buildTransformString({x:i.x,y:i.y,rotation:i.rotation,scale:i.scale});t.element.style.transform=n}return this.activeAnimations.delete(t.element),i}cancelAllAnimations(t){const e=this.activeAnimations.get(t);e&&this.cancelAnimation(e,!1);const i=t.getAnimations();for(const n of i)n.cancel()}getCurrentTransform(t){const i=getComputedStyle(t).transform;if(i==="none"||!i)return{x:0,y:0,rotation:0,scale:1};const n=new DOMMatrix(i),s=Math.sqrt(n.a*n.a+n.b*n.b),r=Math.atan2(n.b,n.a)*(180/Math.PI),a=n.e,h=n.f;return{x:a,y:h,rotation:r,scale:s}}hasActiveAnimation(t){return this.activeAnimations.has(t)}getAnimationHandle(t){return this.activeAnimations.get(t)}animateTransform(t,e,i=null,n=null){return new Promise(s=>{const r=i??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(e),setTimeout(()=>{s()},r)})}resetTransform(t,e){return this.animateTransform(t,e)}clearTransition(t){t.style.transition=""}wait(t){return new Promise(e=>setTimeout(e,t))}}function Z(o,t,e){return o+(t-o)*e}function ce(o,t,e,i){const{overshoot:n,bounces:s,decayRatio:r}=i,a=e.x-t.x,h=e.y-t.y,c=le(s,r);let u=0,l=0,d=1,m=n,y=!1;for(let g=0;g<c.length;g++)if(o<=c[g].time){l=g===0?0:c[g-1].time,d=c[g].time,m=c[g].overshoot,y=c[g].isOvershoot;break}const p=(o-l)/(d-l);if(y)u=1+m*at(p);else if(l===0)u=at(p);else{const f=1+(c.find((x,v)=>x.time>l&&v>0&&c[v-1].isOvershoot)?.overshoot||m);u=Z(f,1,at(p))}return{x:t.x+a*u,y:t.y+h*u}}function le(o,t){const e=[];let i=.6;e.push({time:i,overshoot:0,isOvershoot:!1});let n=.15;const r=.4/(o*2);for(let a=0;a<o;a++)i+=r,e.push({time:i,overshoot:n,isOvershoot:!0}),i+=r,e.push({time:i,overshoot:n*t,isOvershoot:!1}),n*=t;return e.push({time:1,overshoot:0,isOvershoot:!1}),e}function he(o,t,e,i){const{stiffness:n,damping:s,mass:r,oscillations:a}=i,h=e.x-t.x,c=e.y-t.y,u=Math.sqrt(n/r),l=s/(2*Math.sqrt(n*r));let d;if(l<1){const m=u*Math.sqrt(1-l*l),y=Math.exp(-l*u*o*3),p=Math.cos(m*o*a*Math.PI);d=1-y*p}else d=1-Math.exp(-u*o*3);return d=Math.max(0,Math.min(d,1.3)),{x:t.x+h*d,y:t.y+c*d}}function de(o,t,e,i){const{amplitude:n,frequency:s,decay:r,decayRate:a,phase:h}=i,c=e.x-t.x,u=e.y-t.y,l=Math.sqrt(c*c+u*u),d=l>0?-u/l:0,m=l>0?c/l:1,y=s*Math.PI*2*o+h,p=r?Math.pow(1-o,a):1,g=n*Math.sin(y)*p,f=ue(o);return{x:Z(t.x,e.x,f)+g*d,y:Z(t.y,e.y,f)+g*m}}function at(o){return 1-(1-o)*(1-o)}function ue(o){return 1-Math.pow(1-o,3)}function ge(o,t,e){const{amplitude:i,frequency:n,decay:s}=e,r=Math.sin(o*n*Math.PI*2),a=s?Math.pow(1-o,2):1,h=i*r*a;return t+h}function me(o,t,e){const{overshoot:i,bounces:n}=e,s=[];s.push({time:.5,scale:i});let r=i;const a=.5,c=.5/(n*2);let u=.5;for(let d=0;d<n;d++){const m=1-(r-1)*a;u+=c,s.push({time:u,scale:m}),r=1+(r-1)*a*a,u+=c,d<n-1&&s.push({time:u,scale:r})}s.push({time:1,scale:1});let l=1;for(let d=0;d<s.length;d++)if(o<=s[d].time){const m=d===0?0:s[d-1].time,y=d===0?1:s[d-1].scale,p=(o-m)/(s[d].time-m),g=at(p);l=y+(s[d].scale-y)*g;break}return l*t}function Mt(o){const{element:t,startPosition:e,endPosition:i,pathConfig:n,duration:s,imageWidth:r,imageHeight:a,rotation:h,scale:c,onComplete:u,rotationConfig:l,startRotation:d,scaleConfig:m,startScale:y}=o,p=n.type,g=d!==void 0&&d!==h,f=l?.mode==="wobble",x=l?.wobble||{amplitude:15,frequency:3,decay:!0},v=g||f,w=y!==void 0&&y!==c,I=m?.mode==="pop",E=m?.pop||{overshoot:1.2,bounces:1};if((p==="linear"||p==="arc")&&!v&&!(w||I)){u&&u();return}const F=performance.now(),z=-r/2,_=-a/2;function N(X){const j=X-F,C=Math.min(j/s,1);let O;switch(p){case"bounce":{const $=se(n.bouncePreset,n.bounce);O=ce(C,e,i,$);break}case"elastic":{const $=ae(n.elasticPreset,n.elastic);O=he(C,e,i,$);break}case"wave":{const $=re(n.wavePreset,n.wave);O=de(C,e,i,$);break}default:O={x:Z(e.x,i.x,C),y:Z(e.y,i.y,C)}}const G=O.x-i.x,H=O.y-i.y;let L;f?L=ge(C,h,x):g?L=Z(d,h,C):L=h;let R;I?R=me(C,c,E):w?R=Z(y,c,C):R=c,t.style.transform=`translate(${z}px, ${_}px) translate(${G}px, ${H}px) rotate(${L}deg) scale(${R})`,C<1?requestAnimationFrame(N):(t.style.transform=`translate(${z}px, ${_}px) rotate(${h}deg) scale(${c})`,u&&u())}requestAnimationFrame(N)}function Ft(o){return o==="bounce"||o==="elastic"||o==="wave"}const fe={radial:"center",spiral:"center",grid:"top",cluster:"nearest-edge",random:"nearest-edge",wave:"left"};class zt{constructor(t,e){this.config=t,this.layoutAlgorithm=e,this.resolvedStartPosition=this.resolveStartPosition(),this.pathConfig=t.path||mt,this.rotationConfig=t.rotation||ft,this.scaleConfig=t.scale||pt}resolveStartPosition(){return this.config.start.position?this.config.start.position:fe[this.layoutAlgorithm]||"nearest-edge"}calculateStartPosition(t,e,i,n,s){const r=this.resolvedStartPosition,a=this.config.start.offset??100;switch(r){case"nearest-edge":return this.calculateNearestEdge(t,e,i,a);case"top":return this.calculateEdgePosition("top",t,e,i,a);case"bottom":return this.calculateEdgePosition("bottom",t,e,i,a);case"left":return this.calculateEdgePosition("left",t,e,i,a);case"right":return this.calculateEdgePosition("right",t,e,i,a);case"center":return this.calculateCenterPosition(i,t,e);case"random-edge":return this.calculateRandomEdge(t,e,i,a);case"circular":return this.calculateCircularPosition(t,e,i,n,s);default:return this.calculateNearestEdge(t,e,i,a)}}calculateNearestEdge(t,e,i,n){const s=t.x,r=t.y,a=s,h=i.width-s,c=r,u=i.height-r,l=Math.min(a,h,c,u);let d=t.x,m=t.y;return l===a?d=-(e.width+n):l===h?d=i.width+n:l===c?m=-(e.height+n):m=i.height+n,{x:d,y:m}}calculateEdgePosition(t,e,i,n,s){let r=e.x,a=e.y;switch(t){case"top":a=-(i.height+s);break;case"bottom":a=n.height+s;break;case"left":r=-(i.width+s);break;case"right":r=n.width+s;break}return{x:r,y:a}}calculateCenterPosition(t,e,i){const n=t.width/2,s=t.height/2;return{x:n,y:s,useScale:!0}}calculateRandomEdge(t,e,i,n){const s=["top","bottom","left","right"],r=s[Math.floor(Math.random()*s.length)];return this.calculateEdgePosition(r,t,e,i,n)}calculateCircularPosition(t,e,i,n,s){const r=this.config.start.circular||{},a=r.distribution||"even";let h;const c=r.radius||"120%";if(typeof c=="string"&&c.endsWith("%")){const p=parseFloat(c)/100;h=Math.sqrt(i.width**2+i.height**2)*p/2}else h=typeof c=="number"?c:500;let u;a==="even"?u=n/s*2*Math.PI:u=Math.random()*2*Math.PI;const l=i.width/2,d=i.height/2,m=l+Math.cos(u)*h,y=d+Math.sin(u)*h;return{x:m,y}}getAnimationParams(t){const e=this.config.timing.duration,i=this.config.easing;return{startTransform:"",duration:e,delay:0,easing:i}}buildStartTransform(t,e,i,n,s,r,a,h){const c=t.x-e.x,u=t.y-e.y,l=a!==void 0?a:i,d=h!==void 0?h:n,m=s!==void 0?-s/2:0,y=r!==void 0?-r/2:0,p=s!==void 0?`translate(${m}px, ${y}px)`:"translate(-50%, -50%)";return t.useScale?`${p} translate(${c}px, ${u}px) rotate(${l}deg) scale(0)`:`${p} translate(${c}px, ${u}px) rotate(${l}deg) scale(${d})`}buildFinalTransform(t,e,i,n){if(i!==void 0&&n!==void 0){const s=-i/2,r=-n/2;return`translate(${s}px, ${r}px) rotate(${t}deg) scale(${e})`}return`translate(-50%, -50%) rotate(${t}deg) scale(${e})`}getTransitionCSS(){const t=this.config.timing.duration,e=this.config.easing;return this.requiresJSAnimation()?`opacity ${t}ms ease-out`:`opacity ${t}ms ease-out, transform ${t}ms ${e}`}requiresJSAnimation(){return Ft(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 i=this.rotationConfig.startRotation;if(i===void 0)return t+(Math.random()-.5)*60;if(typeof i=="number")return i;const n=i.max-i.min;return i.min+Math.random()*n}case"spin":{const i=this.rotationConfig.spinCount??1,n=this.resolveSpinDirection(t);return t+i*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,e){if(this.rotationConfig.mode!=="wobble")return e;const i=this.rotationConfig.wobble||{amplitude:15,frequency:3,decay:!0},{amplitude:n,frequency:s,decay:r}=i,a=Math.sin(t*s*Math.PI*2),h=r?Math.pow(1-t,2):1,c=n*a*h;return e+c}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 i=this.scaleConfig.range??{min:.5,max:1};return(i.min+Math.random()*(i.max-i.min))*t}default:return t}}requiresJSScale(){return this.scaleConfig.mode==="pop"}calculatePopScale(t,e){if(this.scaleConfig.mode!=="pop")return e;const i=this.scaleConfig.pop||{overshoot:1.2,bounces:1},{overshoot:n,bounces:s}=i,r=this.generateScaleBounceKeyframes(s,n);let a=e;for(let h=0;h<r.length;h++)if(t<=r[h].time){const c=h===0?0:r[h-1].time,u=h===0?e:r[h-1].scale,l=(t-c)/(r[h].time-c),d=this.easeOutQuad(l);a=u+(r[h].scale-u)*d;break}return a*e}generateScaleBounceKeyframes(t,e){const i=[];i.push({time:.5,scale:e});let n=e;const s=.5,a=.5/(t*2);let h=.5;for(let c=0;c<t;c++){const u=1-(n-1)*s;h+=a,i.push({time:h,scale:u}),n=1+(n-1)*s*s,h+=a,c<t-1&&i.push({time:h,scale:n})}return i.push({time:1,scale:1}),i}easeOutQuad(t){return 1-(1-t)*(1-t)}}class Dt{constructor(t,e={}){this.config=t,this.imageConfig=e}generate(t,e,i={}){const n=[],{width:s,height:r}=e,a=this.config.spacing.padding,h=i.fixedHeight??200,c=this.imageConfig.rotation?.mode??"none",u=this.imageConfig.rotation?.range?.min??-15,l=this.imageConfig.rotation?.range?.max??15,d=this.imageConfig.sizing?.variance?.min??1,m=this.imageConfig.sizing?.variance?.max??1,y=d!==1||m!==1,g=h*1.5/2,f=h/2,x=s-a-g,v=r-a-f,w=a+g,I=a+f;for(let E=0;E<t;E++){const T=this.random(w,x),F=this.random(I,v),z=c==="random"?this.random(u,l):0,_=y?this.random(d,m):1,N=h*_,X={id:E,x:T,y:F,rotation:z,scale:_,baseSize:N};n.push(X)}return n}random(t,e){return Math.random()*(e-t)+t}}class Ot{constructor(t,e={}){this.config=t,this.imageConfig=e}generate(t,e,i={}){const n=[],{width:s,height:r}=e,a=i.fixedHeight??200,h=this.imageConfig.rotation?.mode??"none",c=this.imageConfig.rotation?.range?.min??-15,u=this.imageConfig.rotation?.range?.max??15,l=this.imageConfig.sizing?.variance?.min??1,d=this.imageConfig.sizing?.variance?.max??1,m=l!==1||d!==1,y=this.config.scaleDecay??0,p=i.fixedHeight??a,g=s/2,f=r/2,x=Math.ceil(Math.sqrt(t));if(t>0){const I=m?this.random(l,d):1,E=p*I;n.push({id:0,x:g,y:f,rotation:h==="random"?this.random(c*.33,u*.33):0,scale:I,baseSize:E,zIndex:100})}let v=1,w=1;for(;v<t;){const I=w/x,E=y>0?1-I*y*.5:1,T=w*(p*.8),F=T*1.5,z=Math.PI*(3*(F+T)-Math.sqrt((3*F+T)*(F+3*T))),_=this.estimateWidth(p),N=Math.floor(z/(_*.7));if(N===0){w++;continue}const X=2*Math.PI/N,j=w*(20*Math.PI/180);for(let C=0;C<N&&v<t;C++){const O=C*X+j,G=m?this.random(l,d):1,H=E*G,L=p*H;let R=g+Math.cos(O)*F,$=f+Math.sin(O)*T;const P=this.config.spacing.padding??50,U=L*1.5/2,M=L/2;R-U<P?R=P+U:R+U>s-P&&(R=s-P-U),$-M<P?$=P+M:$+M>r-P&&($=r-P-M);const W=h==="random"?this.random(c,u):0;n.push({id:v,x:R,y:$,rotation:W,scale:H,baseSize:L,zIndex:Math.max(1,100-w)}),v++}w++}return n}estimateWidth(t){return t*1.4}random(t,e){return Math.random()*(e-t)+t}}const pe={columns:"auto",rows:"auto",stagger:"none",jitter:0,overlap:0,fillDirection:"row",alignment:"center",gap:10,overflowOffset:.25},$t=[{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 Pt{constructor(t,e={}){this.config=t,this.imageConfig=e}generate(t,e,i={}){const n=[],{width:s,height:r}=e,a={...pe,...this.config.grid},h=this.config.spacing.padding,c=i.fixedHeight??200,u=this.imageConfig.rotation?.mode??"none",l=this.imageConfig.sizing?.variance?.min??1,d=this.imageConfig.sizing?.variance?.max??1,m=l!==1||d!==1,y=s-2*h,p=r-2*h,{columns:g,rows:f}=this.calculateGridDimensions(t,y,p,c,a),x=a.stagger==="row",v=a.stagger==="column",w=x?g+.5:g,I=v?f+.5:f,E=(y-a.gap*(g-1))/w,T=(p-a.gap*(f-1))/I,F=x?E/2:0,z=v?T/2:0,_=1+a.overlap,N=Math.min(E,T)*_,X=i.fixedHeight?Math.min(i.fixedHeight,N):N,j=g*E+(g-1)*a.gap+F,C=f*T+(f-1)*a.gap+z,O=h+(y-j)/2,G=h+(p-C)/2,H=g*f,L=a.columns!=="auto"&&a.rows!=="auto",R=L&&t>H;typeof window<"u"&&(window.__gridOverflowDebug={gridConfigColumns:a.columns,gridConfigRows:a.rows,columns:g,rows:f,cellCount:H,hasFixedGrid:L,imageCount:t,isOverflowMode:R});const $=R?new Array(H).fill(0):[],P=Math.min(E,T)*a.overflowOffset;for(let D=0;D<t;D++){let U,M,W=0;if(R&&D>=H){const Y=D-H,k=Y%H;W=Math.floor(Y/H)+1,$[k]++,a.fillDirection==="row"?(U=k%g,M=Math.floor(k/g)):(M=k%f,U=Math.floor(k/f))}else a.fillDirection==="row"?(U=D%g,M=Math.floor(D/g)):(M=D%f,U=Math.floor(D/f));let q=O+U*(E+a.gap)+E/2,B=G+M*(T+a.gap)+T/2;if(a.stagger==="row"&&M%2===1?q+=E/2:a.stagger==="column"&&U%2===1&&(B+=T/2),W>0){const Y=(W-1)%$t.length,k=$t[Y];q+=k.x*P,B+=k.y*P}if(a.jitter>0){const Y=E/2*a.jitter,k=T/2*a.jitter;q+=this.random(-Y,Y),B+=this.random(-k,k)}let J=q,K=B;if(!R&&a.fillDirection==="row"){const Y=t%g||g;if(M===Math.floor((t-1)/g)&&Y<g){const Jt=Y*E+(Y-1)*a.gap;let At=0;a.alignment==="center"?At=(j-Jt)/2:a.alignment==="end"&&(At=j-Jt),J+=At}}const vt=m?this.random(l,d):1,tt=X*vt,lt=tt*1.5/2,ht=tt/2,Et=h+lt,St=s-h-lt,ze=h+ht,De=r-h-ht;J=Math.max(Et,Math.min(J,St)),K=Math.max(ze,Math.min(K,De));let xt=0;if(u==="random"){const Y=this.imageConfig.rotation?.range?.min??-15,k=this.imageConfig.rotation?.range?.max??15;a.jitter>0?xt=this.random(Y*a.jitter,k*a.jitter):xt=this.random(Y,k)}let It;R&&W>0?It=50-W:It=R?100+D:D+1,n.push({id:D,x:J,y:K,rotation:xt,scale:vt,baseSize:tt,zIndex:It})}return n}calculateGridDimensions(t,e,i,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 h=e/i;for(r=Math.max(1,Math.round(Math.sqrt(t*h/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,e){return Math.random()*(e-t)+t}}const ye=Math.PI*(3-Math.sqrt(5)),be={spiralType:"golden",direction:"counterclockwise",tightness:1,scaleDecay:0,startAngle:0};class Ut{constructor(t,e={}){this.config=t,this.imageConfig=e}generate(t,e,i={}){const n=[],{width:s,height:r}=e,a={...be,...this.config.spiral},h=this.config.spacing.padding,c=i.fixedHeight??200,u=this.imageConfig.rotation?.mode??"none",l=this.imageConfig.rotation?.range?.min??-15,d=this.imageConfig.rotation?.range?.max??15,m=this.imageConfig.sizing?.variance?.min??1,y=this.imageConfig.sizing?.variance?.max??1,p=m!==1||y!==1,g=this.config.scaleDecay??a.scaleDecay,f=s/2,x=r/2,v=Math.min(f-h-c/2,x-h-c/2),w=a.direction==="clockwise"?-1:1;for(let I=0;I<t;I++){let E,T;if(a.spiralType==="golden")E=I*ye*w+a.startAngle,T=this.calculateGoldenRadius(I,t,v,a.tightness);else if(a.spiralType==="archimedean"){const q=I*.5*a.tightness;E=q*w+a.startAngle,T=this.calculateArchimedeanRadius(q,t,v,a.tightness)}else{const q=I*.3*a.tightness;E=q*w+a.startAngle,T=this.calculateLogarithmicRadius(q,t,v,a.tightness)}const F=f+Math.cos(E)*T,z=x+Math.sin(E)*T,_=T/v,N=g>0?1-_*g*.5:1,X=p?this.random(m,y):1,j=N*X,C=c*j,G=C*1.5/2,H=C/2,L=h+G,R=s-h-G,$=h+H,P=r-h-H,D=Math.max(L,Math.min(F,R)),U=Math.max($,Math.min(z,P));let M=0;if(u==="random"){const q=E*180/Math.PI%360,B=this.random(l,d);M=a.spiralType==="golden"?B:q*.1+B*.9}else u==="tangent"&&(M=this.calculateSpiralTangent(E,T,a));const W=t-I;n.push({id:I,x:D,y:U,rotation:M,scale:j,baseSize:C,zIndex:W})}return n}calculateSpiralTangent(t,e,i){let n;if(i.spiralType==="golden")n=t+Math.PI/2;else if(i.spiralType==="archimedean"){const r=1/i.tightness,a=Math.atan(e/r);n=t+a}else{const r=.15/i.tightness,a=Math.atan(1/r);n=t+a}return n*180/Math.PI%360-90}calculateGoldenRadius(t,e,i,n){const r=i/Math.sqrt(e)*Math.sqrt(t)/n;return Math.min(r,i)}calculateArchimedeanRadius(t,e,i,n){const s=e*.5*n;return t/s*i}calculateLogarithmicRadius(t,e,i,n){const s=i*.05,r=.15/n,a=s*Math.exp(r*t),h=e*.3*n,c=s*Math.exp(r*h);return a/c*i}random(t,e){return Math.random()*(e-t)+t}}const ve={clusterCount:"auto",clusterSpread:150,clusterSpacing:200,density:"uniform",overlap:.3,distribution:"gaussian"};class _t{constructor(t,e={}){this.config=t,this.imageConfig=e}generate(t,e,i={}){const n=[],{width:s,height:r}=e,a={...ve,...this.config.cluster},h=this.config.spacing.padding,c=i.fixedHeight??200,u=this.imageConfig.rotation?.mode??"none",l=this.imageConfig.rotation?.range?.min??-15,d=this.imageConfig.rotation?.range?.max??15,m=this.imageConfig.sizing?.variance?.min??1,y=this.imageConfig.sizing?.variance?.max??1,p=m!==1||y!==1,g=this.calculateClusterCount(t,a.clusterCount,s,r,a.clusterSpacing),f=this.generateClusterCenters(g,s,r,h,a),x=new Array(g).fill(0);for(let w=0;w<t;w++)x[w%g]++;let v=0;for(let w=0;w<g;w++){const I=f[w],E=x[w];for(let T=0;T<E;T++){let F,z;if(a.distribution==="gaussian")F=this.gaussianRandom()*I.spread,z=this.gaussianRandom()*I.spread;else{const M=this.random(0,Math.PI*2),W=this.random(0,I.spread);F=Math.cos(M)*W,z=Math.sin(M)*W}const _=1+a.overlap*.5,N=1+a.overlap*.3;F/=_,z/=_;const X=p?this.random(m,y):1,j=N*X,C=c*j;let O=I.x+F,G=I.y+z;const L=C*1.5/2,R=C/2;O=Math.max(h+L,Math.min(O,s-h-L)),G=Math.max(h+R,Math.min(G,r-h-R));const $=u==="random"?this.random(l,d):0,D=Math.sqrt(F*F+z*z)/I.spread,U=Math.round((1-D)*50)+1;n.push({id:v,x:O,y:G,rotation:$,scale:j,baseSize:C,zIndex:U}),v++}}return n}calculateClusterCount(t,e,i,n,s){if(e!=="auto")return Math.max(1,Math.min(e,t));const a=Math.max(1,Math.ceil(t/8)),h=Math.floor(i/s*(n/s)*.6);return Math.max(1,Math.min(a,h,10))}generateClusterCenters(t,e,i,n,s){const r=[],h=n+s.clusterSpread,c=e-n-s.clusterSpread,u=n+s.clusterSpread,l=i-n-s.clusterSpread;for(let d=0;d<t;d++){let m=null,y=-1;for(let p=0;p<100;p++){const g={x:this.random(h,c),y:this.random(u,l),spread:this.calculateClusterSpread(s)};let f=1/0;for(const x of r){const v=g.x-x.x,w=g.y-x.y,I=Math.sqrt(v*v+w*w);f=Math.min(f,I)}if((r.length===0||f>y)&&(m=g,y=f),f>=s.clusterSpacing)break}m&&r.push(m)}return r}calculateClusterSpread(t){return t.density==="uniform"?t.clusterSpread:t.clusterSpread*this.random(.5,1.5)}gaussianRandom(){let t=0,e=0;for(;t===0;)t=Math.random();for(;e===0;)e=Math.random();const i=Math.sqrt(-2*Math.log(t))*Math.cos(2*Math.PI*e);return Math.max(-3,Math.min(3,i))/3}random(t,e){return Math.random()*(e-t)+t}}class Nt{constructor(t,e={}){this.config=t,this.imageConfig=e}generate(t,e,i={}){const n=[],{width:s,height:r}=e,a=i.fixedHeight??200,h=this.config.spacing.padding??50,c=this.imageConfig.rotation?.mode??"none",u=this.imageConfig.rotation?.range?.min??-15,l=this.imageConfig.rotation?.range?.max??15,d=this.imageConfig.sizing?.variance?.min??1,m=this.imageConfig.sizing?.variance?.max??1,y=d!==1||m!==1,p=i.fixedHeight??a,g={...Vt,...this.config.wave},{rows:f,amplitude:x,frequency:v,phaseShift:w,synchronization:I}=g,E=Math.ceil(t/f),z=p*1.5/2,_=h+z,N=s-h-z,X=N-_,j=E>1?X/(E-1):0,C=h+x+p/2,O=r-h-x-p/2,G=O-C,H=f>1?G/(f-1):0;let L=0;for(let R=0;R<f&&L<t;R++){const $=f===1?(C+O)/2:C+R*H;let P=0;I==="offset"?P=R*w:I==="alternating"&&(P=R*Math.PI);for(let D=0;D<E&&L<t;D++){const U=E===1?(_+N)/2:_+D*j,M=this.calculateWaveY(U,s,x,v,P),W=U,q=$+M,B=y?this.random(d,m):1,J=p*B;let K=0;c==="tangent"?K=this.calculateRotation(U,s,x,v,P):c==="random"&&(K=this.random(u,l));const tt=J*1.5/2,wt=J/2,lt=h+tt,ht=s-h-tt,Et=h+wt,St=r-h-wt;n.push({id:L,x:Math.max(lt,Math.min(W,ht)),y:Math.max(Et,Math.min(q,St)),rotation:K,scale:B,baseSize:J,zIndex:L+1}),L++}}return n}calculateWaveY(t,e,i,n,s){const r=t/e;return i*Math.sin(n*r*2*Math.PI+s)}calculateRotation(t,e,i,n,s){const r=t/e,a=i*n*2*Math.PI*Math.cos(n*r*2*Math.PI+s)/e;return Math.atan(a)*(180/Math.PI)}random(t,e){return Math.random()*(e-t)+t}}class Ht{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 Ot(this.config,this.imageConfig);case"grid":return new Pt(this.config,this.imageConfig);case"spiral":return new Ut(this.config,this.imageConfig);case"cluster":return new _t(this.config,this.imageConfig);case"wave":return new Nt(this.config,this.imageConfig);default:return new Dt(this.config,this.imageConfig)}}generateLayout(t,e,i={}){const n=this.placementLayout.generate(t,e,i);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 e=this.getBreakpoints();return t<=e.mobile.maxWidth?"mobile":t<=e.tablet.maxWidth?"tablet":"screen"}resolveBaseHeight(t){const e=this.imageConfig.sizing;if(!e||e.mode==="adaptive")return;const i=e.height;if(i===void 0)return;if(typeof i=="number")return i;const n=i,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,e,i,n){const s=this.imageConfig.sizing,r=this.resolveBaseHeight(n);if(r!==void 0)return{height:r};const a=s?.minSize??50,h=s?.maxSize??400,c=this.config.targetCoverage??.6,u=this.config.densityFactor??1,{width:l,height:d}=t,p=l*d*c/e;let f=Math.sqrt(p/1.4);f*=u,f=Math.min(f,i);let x=this.clamp(f,a,h);if(x===a&&f<a){const v=Math.max(a*.05,20);x=Math.max(v,f)}return{height:x}}clamp(t,e,i){return Math.max(e,Math.min(i,t))}}const Q=class Q{static registerLoader(t,e){Q.registry.set(t,e)}static getLoader(t){const e=Q.registry.get(t);if(!e)throw new Error(`Loader "${t}" is not registered. Import "@frybynite/image-cloud/loaders/${t}" or "@frybynite/image-cloud/loaders/all".`);return e}static isRegistered(t){return Q.registry.has(t)}};Q.registry=new Map;let it=Q;var S=(o=>(o.IDLE="idle",o.FOCUSING="focusing",o.FOCUSED="focused",o.UNFOCUSING="unfocusing",o.CROSS_ANIMATING="cross_animating",o))(S||{});function we(o){return o in V}function Ee(o){return o?we(o)?V[o]:o:V.md}function Se(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 e=o.dropShadow;t.push(`drop-shadow(${e.x}px ${e.y}px ${e.blur}px ${e.color})`)}return t.join(" ")}function nt(o){if(!o||o.style==="none"||o.width===0)return"none";const t=o.width??0,e=o.style??"solid",i=o.color??"#000000";return`${t}px ${e} ${i}`}function rt(o){if(!o)return{};const t={};if(o.borderRadiusTopLeft!==void 0||o.borderRadiusTopRight!==void 0||o.borderRadiusBottomRight!==void 0||o.borderRadiusBottomLeft!==void 0){const s=o.border?.radius??0;o.borderRadiusTopLeft!==void 0?t.borderTopLeftRadius=`${o.borderRadiusTopLeft}px`:s&&(t.borderTopLeftRadius=`${s}px`),o.borderRadiusTopRight!==void 0?t.borderTopRightRadius=`${o.borderRadiusTopRight}px`:s&&(t.borderTopRightRadius=`${s}px`),o.borderRadiusBottomRight!==void 0?t.borderBottomRightRadius=`${o.borderRadiusBottomRight}px`:s&&(t.borderBottomRightRadius=`${s}px`),o.borderRadiusBottomLeft!==void 0?t.borderBottomLeftRadius=`${o.borderRadiusBottomLeft}px`:s&&(t.borderBottomLeftRadius=`${s}px`)}else o.border?.radius!==void 0&&(t.borderRadius=`${o.border.radius}px`);if(o.borderTop||o.borderRight||o.borderBottom||o.borderLeft){const s=o.border||{},r={...s,...o.borderTop},a={...s,...o.borderRight},h={...s,...o.borderBottom},c={...s,...o.borderLeft};t.borderTop=nt(r),t.borderRight=nt(a),t.borderBottom=nt(h),t.borderLeft=nt(c)}else o.border&&(t.border=nt(o.border));o.shadow!==void 0&&(t.boxShadow=Ee(o.shadow));const n=Se(o.filter);if(t.filter=n||"none",o.opacity!==void 0&&(t.opacity=String(o.opacity)),o.cursor!==void 0&&(t.cursor=o.cursor),o.outline&&o.outline.style!=="none"&&(o.outline.width??0)>0){const s=o.outline.width??0,r=o.outline.style??"solid",a=o.outline.color??"#000000";t.outline=`${s}px ${r} ${a}`,o.outline.offset!==void 0&&(t.outlineOffset=`${o.outline.offset}px`)}return o.objectFit!==void 0&&(t.objectFit=o.objectFit),o.aspectRatio!==void 0&&(t.aspectRatio=o.aspectRatio),t}function ot(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)}function jt(o){return o?Array.isArray(o)?o.join(" "):o:""}function st(o,t){const e=jt(t);e&&e.split(" ").forEach(i=>{i.trim()&&o.classList.add(i.trim())})}function kt(o,t){const e=jt(t);e&&e.split(" ").forEach(i=>{i.trim()&&o.classList.remove(i.trim())})}const Gt={UNFOCUSING:999,FOCUSING:1e3};class Wt{constructor(t,e,i){this.state=S.IDLE,this.currentFocus=null,this.focusData=null,this.outgoing=null,this.incoming=null,this.focusGeneration=0,this.config=t,this.animationEngine=e,this.defaultStyles=rt(i?.default),this.focusedStyles=rt(i?.focused),this.defaultClassName=i?.default?.className,this.focusedClassName=i?.focused?.className}getState(){return this.state}isAnimating(){return this.state!==S.IDLE&&this.state!==S.FOCUSED}normalizeScalePercent(t){return t>1?t/100:t}calculateFocusDimensions(t,e,i){const n=this.normalizeScalePercent(this.config.scalePercent),s=i.height*n,r=t/e;let a=s,h=a*r;const c=i.width*n;return h>c&&(h=c,a=h/r),{width:h,height:a}}calculateFocusTransform(t,e){const i=t.width/2,n=t.height/2,s=i-e.x,r=n-e.y;return{x:s,y:r,rotation:0,scale:1}}buildDimensionZoomTransform(t){const e=["translate(-50%, -50%)"];if(t.x!==void 0||t.y!==void 0){const i=t.x??0,n=t.y??0;e.push(`translate(${i}px, ${n}px)`)}return t.rotation!==void 0&&e.push(`rotate(${t.rotation}deg)`),e.join(" ")}animateWithDimensions(t,e,i,n,s,r,a,h){const c=this.buildDimensionZoomTransform(e),u=this.buildDimensionZoomTransform(i);return t.style.transition="none",t.animate([{transform:c,width:`${n}px`,height:`${s}px`},{transform:u,width:`${r}px`,height:`${a}px`}],{duration:h,easing:"cubic-bezier(0.4, 0, 0.2, 1)",fill:"forwards"})}applyFocusedStyling(t,e){t.style.zIndex=String(e),t.classList.add("fbn-ic-focused"),ot(t,this.focusedStyles),st(t,this.focusedClassName)}removeFocusedStyling(t,e){t.style.zIndex=e,t.classList.remove("fbn-ic-focused"),kt(t,this.focusedClassName),ot(t,this.defaultStyles),st(t,this.defaultClassName)}startFocusAnimation(t,e,i,n,s){const r=t.style.zIndex||"",a=t.offsetWidth,h=t.offsetHeight,c=this.calculateFocusDimensions(a,h,e),u=this.calculateFocusTransform(e,i);this.applyFocusedStyling(t,Gt.FOCUSING),this.animationEngine.cancelAllAnimations(t);const l=n??{x:0,y:0,rotation:i.rotation,scale:1},d=s?.width??a,m=s?.height??h,y=this.config.animationDuration??600,p=this.animateWithDimensions(t,l,u,d,m,c.width,c.height,y),g={id:`focus-${Date.now()}`,element:t,animation:p,fromState:l,toState:u,startTime:performance.now(),duration:y};return this.focusData={element:t,originalState:i,focusTransform:u,originalZIndex:r,originalWidth:a,originalHeight:h,focusWidth:c.width,focusHeight:c.height},{element:t,originalState:i,animationHandle:g,direction:"in",originalWidth:a,originalHeight:h}}startUnfocusAnimation(t,e,i,n){t.style.zIndex=String(Gt.UNFOCUSING),this.animationEngine.cancelAllAnimations(t);const s=i??this.focusData?.focusTransform??{x:0,y:0,rotation:0,scale:1},r=n?.width??this.focusData?.focusWidth??t.offsetWidth,a=n?.height??this.focusData?.focusHeight??t.offsetHeight,h={x:0,y:0,rotation:e.rotation,scale:1},c=this.focusData?.originalWidth??t.offsetWidth,u=this.focusData?.originalHeight??t.offsetHeight,l=this.config.animationDuration??600,d=this.animateWithDimensions(t,s,h,r,a,c,u,l),m={id:`unfocus-${Date.now()}`,element:t,animation:d,fromState:s,toState:h,startTime:performance.now(),duration:l};return{element:t,originalState:e,animationHandle:m,direction:"out",originalWidth:c,originalHeight:u}}captureMidAnimationState(t){const e=getComputedStyle(t),i=new DOMMatrix(e.transform),n=t.offsetWidth,s=t.offsetHeight,r=i.e+n*.5,a=i.f+s*.5,h=Math.atan2(i.b,i.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(${h}deg)`,t.style.transition="none",{transform:{x:r,y:a,rotation:h,scale:1},dimensions:{width:n,height:s}}}async waitForAnimation(t){try{await t.animation.finished}catch{}}resetElementInstantly(t,e,i,n,s){this.animationEngine.cancelAllAnimations(t);const r=["translate(-50%, -50%)"];r.push("translate(0px, 0px)"),r.push(`rotate(${e.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,i)}async focusImage(t,e,i){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,e,i),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,e,i),await Promise.all([this.outgoing?this.waitForAnimation(this.outgoing.animationHandle):Promise.resolve(),this.waitForAnimation(this.incoming.animationHandle)]),this.focusGeneration!==n)return;this.outgoing&&(this.removeFocusedStyling(this.outgoing.element,this.outgoing.originalState.zIndex?.toString()||""),this.outgoing=null),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,e,i),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,e,i),await Promise.all([this.outgoing?this.waitForAnimation(this.outgoing.animationHandle):Promise.resolve(),this.waitForAnimation(this.incoming.animationHandle)]),this.focusGeneration!==n)return;this.outgoing&&(this.removeFocusedStyling(this.outgoing.element,this.outgoing.originalState.zIndex?.toString()||""),this.outgoing=null),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:h}=this.captureMidAnimationState(this.incoming.element);this.animationEngine.cancelAllAnimations(this.incoming.element),this.outgoing=this.startUnfocusAnimation(this.incoming.element,this.incoming.originalState,a,h)}else this.outgoing=null;if(this.incoming=this.startFocusAnimation(t,e,i,s,r),await Promise.all([this.outgoing?this.waitForAnimation(this.outgoing.animationHandle):Promise.resolve(),this.waitForAnimation(this.incoming.animationHandle)]),this.focusGeneration!==n)return;this.outgoing&&(this.removeFocusedStyling(this.outgoing.element,this.outgoing.originalState.zIndex?.toString()||""),this.outgoing=null),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,e,i),await Promise.all([this.outgoing?this.waitForAnimation(this.outgoing.animationHandle):Promise.resolve(),this.waitForAnimation(this.incoming.animationHandle)]),this.focusGeneration!==n)return;this.outgoing&&(this.removeFocusedStyling(this.outgoing.element,this.outgoing.originalState.zIndex?.toString()||""),this.outgoing=null),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;this.removeFocusedStyling(this.outgoing.element,this.focusData?.originalZIndex||""),this.outgoing=null,this.focusData=null,this.state=S.IDLE}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;this.outgoing&&this.removeFocusedStyling(this.outgoing.element,this.outgoing.originalState.zIndex?.toString()||""),this.removeFocusedStyling(a.element,this.incoming.originalState.zIndex?.toString()||""),this.outgoing=null,this.incoming=null,this.currentFocus=null,this.focusData=null,this.state=S.IDLE;return}this.state=S.UNFOCUSING;const e=this.currentFocus,i=this.focusData.originalState,n=this.focusData.originalZIndex;this.outgoing=this.startUnfocusAnimation(e,i),await this.waitForAnimation(this.outgoing.animationHandle),this.focusGeneration===t&&(this.removeFocusedStyling(e,n),this.outgoing=null,this.currentFocus=null,this.focusData=null,this.state=S.IDLE)}async swapFocus(t,e,i){return this.focusImage(t,e,i)}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 e=this.currentFocus,i=this.focusData.focusTransform,n=["translate(-50%, -50%)"],s=(i.x??0)+t,r=i.y??0;n.push(`translate(${s}px, ${r}px)`),i.rotation!==void 0&&n.push(`rotate(${i.rotation}deg)`),e.style.transition="none",e.style.transform=n.join(" ")}clearDragOffset(t,e=150){if(!this.currentFocus||!this.focusData||this.state!==S.FOCUSED)return;const i=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 h=s.join(" ");t?(i.style.transition=`transform ${e}ms ease-out`,i.style.transform=h,setTimeout(()=>{this.currentFocus===i&&(i.style.transition="none")},e)):(i.style.transition="none",i.style.transform=h)}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 xe=50,Ie=.5,Ae=20,Te=.3,Ce=150,Re=30,ct=class ct{constructor(t,e){this.enabled=!1,this.touchState=null,this.recentTouchTimestamp=0,this.container=t,this.callbacks=e,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<ct.TOUCH_CLICK_DELAY}handleTouchStart(t){if(t.touches.length!==1)return;this.recentTouchTimestamp=Date.now();const e=t.touches[0];this.touchState={startX:e.clientX,startY:e.clientY,startTime:performance.now(),currentX:e.clientX,isDragging:!1,isHorizontalSwipe:null}}handleTouchMove(t){if(!this.touchState||t.touches.length!==1)return;const e=t.touches[0],i=e.clientX-this.touchState.startX,n=e.clientY-this.touchState.startY;if(this.touchState.isHorizontalSwipe===null&&Math.sqrt(i*i+n*n)>10){const a=Math.atan2(Math.abs(n),Math.abs(i))*(180/Math.PI);this.touchState.isHorizontalSwipe=a<=Re}if(this.touchState.isHorizontalSwipe!==!1&&this.touchState.isHorizontalSwipe===!0){t.preventDefault(),this.touchState.isDragging=!0,this.touchState.currentX=e.clientX;const s=i*Te;this.callbacks.onDragOffset(s)}}handleTouchEnd(t){if(!this.touchState)return;this.recentTouchTimestamp=Date.now();const e=this.touchState.currentX-this.touchState.startX,i=performance.now()-this.touchState.startTime,n=Math.abs(e)/i,s=Math.abs(e);let r=!1;this.touchState.isHorizontalSwipe===!0&&this.touchState.isDragging&&(s>=xe||n>=Ie&&s>=Ae)&&(r=!0,e<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}};ct.TOUCH_CLICK_DELAY=300;let bt=ct;class qt{constructor(t){this.allowedExtensions=t||["jpg","jpeg","png","gif","webp","bmp"]}isAllowed(t){const i=t.split("?")[0].split(".").pop()?.toLowerCase();return i?this.allowedExtensions.includes(i):!1}getAllowedExtensions(){return[...this.allowedExtensions]}}const Yt=`
5
2
  .fbn-ic-gallery {
6
3
  position: relative;
7
4
  width: 100%;
@@ -50,5 +47,8 @@
50
47
  .fbn-ic-hidden {
51
48
  display: none !important;
52
49
  }
53
- `;function Bt(){if(typeof document>"u")return;const n="fbn-ic-functional-styles";if(document.getElementById(n))return;const t=document.createElement("style");t.id=n,t.textContent=Xt,document.head.appendChild(t)}class Jt{constructor(t={}){this.fullConfig=se(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.animationEngine=new Ct(this.fullConfig.animation),this.layoutEngine=new _t({layout:this.fullConfig.layout,image:this.fullConfig.image}),this.zoomEngine=new kt(this.fullConfig.interaction.focus,this.animationEngine,this.fullConfig.styling),this.defaultStyles=st(this.fullConfig.styling?.default),this.hoverStyles=st(this.fullConfig.styling?.hover),this.defaultClassName=this.fullConfig.styling?.default?.className,this.hoverClassName=this.fullConfig.styling?.hover?.className;const e=this.fullConfig.animation.entry||y.animation.entry;this.entryAnimationEngine=new Mt(e,this.fullConfig.layout.algorithm),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 Yt(t)}createLoader(){const t=this.fullConfig.loaders,e=this.fullConfig.config.loaders??{};if(!t||t.length===0)throw new Error("No loaders configured. Provide `images`, `loaders`, or both.");const i=t.map(o=>this.createLoaderFromEntry(o,e));return i.length===1?i[0]:new qt({loaders:i,debugLogging:this.fullConfig.config.debug?.loaders})}createLoaderFromEntry(t,e){if("static"in t){const i=t.static,o={...i,validateUrls:i.validateUrls??e.validateUrls,validationTimeout:i.validationTimeout??e.validationTimeout,validationMethod:i.validationMethod??e.validationMethod,allowedExtensions:i.allowedExtensions??e.allowedExtensions,debugLogging:i.debugLogging??this.fullConfig.config.debug?.loaders};return new Wt(o)}else if("googleDrive"in t){const i=t.googleDrive,o={...i,allowedExtensions:i.allowedExtensions??e.allowedExtensions,debugLogging:i.debugLogging??this.fullConfig.config.debug?.loaders};return new Gt(o)}else throw new Error(`Unknown loader entry: ${JSON.stringify(t)}`)}async init(){try{if(Bt(),this.containerRef)this.containerEl=this.containerRef;else if(this.containerEl=document.getElementById(this.containerId),!this.containerEl)throw new Error(`Container #${this.containerId} not found`);this.containerEl.classList.add("fbn-ic-gallery"),this.swipeEngine=new pt(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,Re)}}),this.setupUI(),this.setupEventListeners(),this.logDebug("ImageCloud initialized"),await this.loadImages()}catch(t){console.error("Gallery initialization failed:",t),this.errorEl&&t instanceof Error&&this.showError("Gallery failed to initialize: "+t.message)}}setupUI(){const t=this.fullConfig.rendering.ui;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))}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 e=document.createElement("div");e.className="fbn-ic-spinner",t.appendChild(e);const i=document.createElement("p");return i.textContent="Loading images...",t.appendChild(i),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}setupEventListeners(){document.addEventListener("keydown",t=>{t.key==="Escape"?(this.zoomEngine.unfocusImage(),this.currentFocusIndex=null,this.swipeEngine?.disable(),this.hideCounter()):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")||(this.zoomEngine.unfocusImage(),this.currentFocusIndex=null,this.swipeEngine?.disable(),this.hideCounter())}),window.addEventListener("resize",()=>this.handleResize())}navigateToNextImage(){if(this.currentFocusIndex===null||this.imageElements.length===0)return;const t=(this.currentFocusIndex+1)%this.imageLayouts.length,e=this.imageElements.find(o=>o.dataset.imageId===String(t));if(!e)return;const i=this.imageLayouts[t];i&&(this.currentFocusIndex=t,this.handleImageClick(e,i),this.updateCounter(t))}navigateToPreviousImage(){if(this.currentFocusIndex===null||this.imageElements.length===0)return;const t=(this.currentFocusIndex-1+this.imageLayouts.length)%this.imageLayouts.length,e=this.imageElements.find(o=>o.dataset.imageId===String(t));if(!e)return;const i=this.imageLayouts[t];i&&(this.currentFocusIndex=t,this.handleImageClick(e,i),this.updateCounter(t))}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,e=this.fullConfig.layout.responsive,o=this.fullConfig.image.sizing?.maxSize??400;return e?t<=e.mobile.maxWidth?Math.min(100,o):t<=e.tablet.maxWidth?Math.min(180,o):Math.min(225,o):t<=767?Math.min(100,o):t<=1199?Math.min(180,o):Math.min(225,o)}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 e=this.imageLoader.imageURLs();if(t===0){this.showError("No images found."),this.showLoading(!1);return}const i=this.getContainerBounds(),o=this.getImageHeight(),s=window.innerWidth;this.logDebug(`Adaptive sizing input: container=${i.width}x${i.height}px, images=${t}, responsiveMax=${o}px`);const r=this.layoutEngine.calculateAdaptiveSize(i,t,o,s);this.logDebug(`Adaptive sizing result: height=${r.height}px`),await this.createImageCloud(e,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,e){if(!this.containerEl)return;const i=this.getContainerBounds();this.currentImageHeight=e;const o=this.loadGeneration,s=this.layoutEngine.generateLayout(t.length,i,{fixedHeight:e});this.imageLayouts=s,this.displayQueue=[];let r=0;const a=c=>{this.containerEl&&(this.containerEl.appendChild(c),this.imageElements.push(c),requestAnimationFrame(()=>{if(c.offsetWidth,c.style.opacity=this.defaultStyles.opacity??"1",c.dataset.startX&&(this.entryAnimationEngine.requiresJSAnimation()||this.entryAnimationEngine.requiresJSRotation()||this.entryAnimationEngine.requiresJSScale()||c.dataset.startRotation!==c.dataset.rotation||c.dataset.startScale!==c.dataset.scale)){const d={x:parseFloat(c.dataset.startX),y:parseFloat(c.dataset.startY)},m={x:parseFloat(c.dataset.endX),y:parseFloat(c.dataset.endY)},b=parseFloat(c.dataset.imageWidth),p=parseFloat(c.dataset.imageHeight),g=parseFloat(c.dataset.rotation),f=parseFloat(c.dataset.scale),x=c.dataset.startRotation?parseFloat(c.dataset.startRotation):g,v=c.dataset.startScale?parseFloat(c.dataset.startScale):f,w=this.entryAnimationEngine.getTiming();Rt({element:c,startPosition:d,endPosition:m,pathConfig:this.entryAnimationEngine.getPathConfig(),duration:w.duration,imageWidth:b,imageHeight:p,rotation:g,scale:f,rotationConfig:this.entryAnimationEngine.getRotationConfig(),startRotation:x,scaleConfig:this.entryAnimationEngine.getScaleConfig(),startScale:v})}else{const d=c.dataset.finalTransform||"";c.style.transform=d}const l=parseInt(c.dataset.imageId||"0");if(this.fullConfig.config.debug?.enabled&&l<3){const d=c.dataset.finalTransform||"";console.log(`Image ${l} final state:`,{left:c.style.left,top:c.style.top,width:c.style.width,height:c.style.height,computedWidth:c.offsetWidth,computedHeight:c.offsetHeight,transform:d,pathType:this.entryAnimationEngine.getPathType()})}}),r++)},h=()=>{if(this.logDebug("Starting queue processing, enabled:",this.fullConfig.animation.queue.enabled),!this.fullConfig.animation.queue.enabled){for(;this.displayQueue.length>0;){const c=this.displayQueue.shift();c&&a(c)}return}this.queueInterval!==null&&clearInterval(this.queueInterval),this.queueInterval=window.setInterval(()=>{if(o!==this.loadGeneration){this.queueInterval!==null&&(clearInterval(this.queueInterval),this.queueInterval=null);return}if(this.displayQueue.length>0){const c=this.displayQueue.shift();c&&a(c)}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 c=new IntersectionObserver(u=>{u.forEach(l=>{l.isIntersecting&&(h(),c.disconnect())})},{threshold:.1,rootMargin:"50px"});c.observe(this.containerEl)}else h();this.fullConfig.config.debug?.centers&&this.containerEl&&(this.containerEl.querySelectorAll(".fbn-ic-debug-center").forEach(c=>c.remove()),s.forEach((c,u)=>{const l=document.createElement("div");l.className="fbn-ic-debug-center",l.style.position="absolute",l.style.width="12px",l.style.height="12px",l.style.borderRadius="50%",l.style.backgroundColor="red",l.style.border="2px solid yellow",l.style.zIndex="9999",l.style.pointerEvents="none";const d=c.x,m=c.y;l.style.left=`${d-6}px`,l.style.top=`${m-6}px`,l.title=`Image ${u}: center (${Math.round(d)}, ${Math.round(m)})`,this.containerEl.appendChild(l)})),t.forEach((c,u)=>{const l=document.createElement("img");l.referrerPolicy="no-referrer",l.classList.add("fbn-ic-image"),l.dataset.imageId=String(u);const d=s[u];l.style.position="absolute",l.style.width="auto",l.style.height=`${e}px`,l.style.left=`${d.x}px`,l.style.top=`${d.y}px`,d.zIndex&&(l.style.zIndex=String(d.zIndex)),it(l,this.defaultStyles),nt(l,this.defaultClassName),l.addEventListener("mouseenter",()=>{this.hoveredImage={element:l,layout:d},this.zoomEngine.isInvolved(l)||(it(l,this.hoverStyles),nt(l,this.hoverClassName))}),l.addEventListener("mouseleave",()=>{this.hoveredImage=null,this.zoomEngine.isInvolved(l)||(it(l,this.defaultStyles),Ht(l,this.hoverClassName),nt(l,this.defaultClassName))}),l.addEventListener("click",m=>{m.stopPropagation(),this.handleImageClick(l,d)}),l.style.opacity="0",l.style.transition=this.entryAnimationEngine.getTransitionCSS(),l.onload=()=>{if(o!==this.loadGeneration)return;const m=l.naturalWidth/l.naturalHeight,b=e*m;l.style.width=`${b}px`;const p={x:d.x,y:d.y},g={width:b,height:e},f=this.entryAnimationEngine.calculateStartPosition(p,g,i,u,t.length),x=this.entryAnimationEngine.calculateStartRotation(d.rotation),v=this.entryAnimationEngine.calculateStartScale(d.scale),w=this.entryAnimationEngine.buildFinalTransform(d.rotation,d.scale,b,e),I=this.entryAnimationEngine.buildStartTransform(f,p,d.rotation,d.scale,b,e,x,v);this.fullConfig.config.debug?.enabled&&u<3&&console.log(`Image ${u}:`,{finalPosition:p,imageSize:g,left:d.x,top:d.y,finalTransform:w,renderedWidth:b,renderedHeight:e}),l.style.transform=I,l.dataset.finalTransform=w,(this.entryAnimationEngine.requiresJSAnimation()||this.entryAnimationEngine.requiresJSRotation()||this.entryAnimationEngine.requiresJSScale()||x!==d.rotation||v!==d.scale)&&(l.dataset.startX=String(f.x),l.dataset.startY=String(f.y),l.dataset.endX=String(p.x),l.dataset.endY=String(p.y),l.dataset.imageWidth=String(b),l.dataset.imageHeight=String(e),l.dataset.rotation=String(d.rotation),l.dataset.scale=String(d.scale),l.dataset.startRotation=String(x),l.dataset.startScale=String(v)),this.displayQueue.push(l)},l.onerror=()=>r++,l.src=c})}async handleImageClick(t,e){if(!this.containerEl)return;const i=this.zoomEngine.isFocused(t),o={width:this.containerEl.offsetWidth,height:this.containerEl.offsetHeight};if(i)await this.zoomEngine.unfocusImage(),this.currentFocusIndex=null,this.swipeEngine?.disable(),this.hideCounter();else{const s=t.dataset.imageId;this.currentFocusIndex=s!==void 0?parseInt(s,10):null,this.swipeEngine?.enable(),await this.zoomEngine.focusImage(t,o,e),this.currentFocusIndex!==null&&this.updateCounter(this.currentFocusIndex)}}clearImageCloud(){this.queueInterval!==null&&(clearInterval(this.queueInterval),this.queueInterval=null),this.loadGeneration++,this.displayQueue=[],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.imagesLoaded=!1}showLoading(t){!this.fullConfig.rendering.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.rendering.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")}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.resizeTimeout!==null&&clearTimeout(this.resizeTimeout),this.swipeEngine?.destroy()}}A.AnimationEngine=Ct,A.BOUNCE_PRESETS=lt,A.ClusterPlacementLayout=Pt,A.CompositeLoader=qt,A.DEFAULT_CONFIG=y,A.DEFAULT_SHARED_LOADER_CONFIG=ft,A.ELASTIC_PRESETS=ht,A.EntryAnimationEngine=Mt,A.FUNCTIONAL_CSS=Xt,A.GoogleDriveLoader=Gt,A.GridPlacementLayout=Ot,A.ImageCloud=Jt,A.ImageFilter=Yt,A.ImageGallery=Jt,A.LayoutEngine=_t,A.RadialPlacementLayout=zt,A.RandomPlacementLayout=Ft,A.SpiralPlacementLayout=$t,A.StaticImageLoader=Wt,A.WAVE_PATH_PRESETS=dt,A.WavePlacementLayout=Ut,A.ZoomEngine=kt,A.animatePath=Rt,A.injectFunctionalStyles=Bt,A.requiresJSAnimation=Lt,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})}));
50
+ `;function Xt(){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=Yt,document.head.appendChild(t)}class Bt{constructor(t={}){this.fullConfig=oe(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.animationEngine=new Lt(this.fullConfig.animation),this.layoutEngine=new Ht({layout:this.fullConfig.layout,image:this.fullConfig.image}),this.zoomEngine=new Wt(this.fullConfig.interaction.focus,this.animationEngine,this.fullConfig.styling),this.defaultStyles=rt(this.fullConfig.styling?.default),this.hoverStyles=rt(this.fullConfig.styling?.hover),this.defaultClassName=this.fullConfig.styling?.default?.className,this.hoverClassName=this.fullConfig.styling?.hover?.className;const e=this.fullConfig.animation.entry||b.animation.entry;this.entryAnimationEngine=new zt(e,this.fullConfig.layout.algorithm),this.swipeEngine=null,this.imageFilter=this.createImageFilter(),this.containerEl=null,this.loadingEl=null,this.errorEl=null}createImageFilter(){const t=this.fullConfig.config.loaders?.allowedExtensions;return new qt(t)}async createLoader(){const t=this.fullConfig.loaders,e=this.fullConfig.config.loaders??{};if(!t||t.length===0)throw new Error("No loaders configured. Provide `images`, `loaders`, or both.");const i=await Promise.all(t.map(s=>this.createLoaderFromEntry(s,e)));if(i.length===1)return i[0];await import("@frybynite/image-cloud/loaders/composite");const n=it.getLoader("composite");return new n({loaders:i,debugLogging:this.fullConfig.config.debug?.loaders})}async createLoaderFromEntry(t,e){if("static"in t){await import("@frybynite/image-cloud/loaders/static");const i=it.getLoader("static"),n=t.static,s={...n,validateUrls:n.validateUrls??e.validateUrls,validationTimeout:n.validationTimeout??e.validationTimeout,validationMethod:n.validationMethod??e.validationMethod,allowedExtensions:n.allowedExtensions??e.allowedExtensions,debugLogging:n.debugLogging??this.fullConfig.config.debug?.loaders};return new i(s)}else if("googleDrive"in t){await import("@frybynite/image-cloud/loaders/google-drive");const i=it.getLoader("google-drive"),n=t.googleDrive,s={...n,allowedExtensions:n.allowedExtensions??e.allowedExtensions,debugLogging:n.debugLogging??this.fullConfig.config.debug?.loaders};return new i(s)}else throw new Error(`Unknown loader entry: ${JSON.stringify(t)}`)}async init(){try{if(Xt(),this.containerRef)this.containerEl=this.containerRef;else if(this.containerEl=document.getElementById(this.containerId),!this.containerEl)throw new Error(`Container #${this.containerId} not found`);this.containerEl.classList.add("fbn-ic-gallery"),this.swipeEngine=new bt(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,Ce)}}),this.setupUI(),this.setupEventListeners(),this.imageLoader=await this.createLoader(),this.logDebug("ImageCloud initialized"),await this.loadImages()}catch(t){console.error("Gallery initialization failed:",t),this.errorEl&&t instanceof Error&&this.showError("Gallery failed to initialize: "+t.message)}}setupUI(){const t=this.fullConfig.rendering.ui;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))}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 e=document.createElement("div");e.className="fbn-ic-spinner",t.appendChild(e);const i=document.createElement("p");return i.textContent="Loading images...",t.appendChild(i),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}setupEventListeners(){document.addEventListener("keydown",t=>{t.key==="Escape"?(this.zoomEngine.unfocusImage(),this.currentFocusIndex=null,this.swipeEngine?.disable(),this.hideCounter()):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")||(this.zoomEngine.unfocusImage(),this.currentFocusIndex=null,this.swipeEngine?.disable(),this.hideCounter())}),window.addEventListener("resize",()=>this.handleResize())}navigateToNextImage(){if(this.currentFocusIndex===null||this.imageElements.length===0)return;const t=(this.currentFocusIndex+1)%this.imageLayouts.length,e=this.imageElements.find(n=>n.dataset.imageId===String(t));if(!e)return;const i=this.imageLayouts[t];i&&(this.currentFocusIndex=t,this.handleImageClick(e,i),this.updateCounter(t))}navigateToPreviousImage(){if(this.currentFocusIndex===null||this.imageElements.length===0)return;const t=(this.currentFocusIndex-1+this.imageLayouts.length)%this.imageLayouts.length,e=this.imageElements.find(n=>n.dataset.imageId===String(t));if(!e)return;const i=this.imageLayouts[t];i&&(this.currentFocusIndex=t,this.handleImageClick(e,i),this.updateCounter(t))}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,e=this.fullConfig.layout.responsive,n=this.fullConfig.image.sizing?.maxSize??400;return e?t<=e.mobile.maxWidth?Math.min(100,n):t<=e.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 e=this.imageLoader.imageURLs();if(t===0){this.showError("No images found."),this.showLoading(!1);return}const i=this.getContainerBounds(),n=this.getImageHeight(),s=window.innerWidth;this.logDebug(`Adaptive sizing input: container=${i.width}x${i.height}px, images=${t}, responsiveMax=${n}px`);const r=this.layoutEngine.calculateAdaptiveSize(i,t,n,s);this.logDebug(`Adaptive sizing result: height=${r.height}px`),await this.createImageCloud(e,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,e){if(!this.containerEl)return;const i=this.getContainerBounds();this.currentImageHeight=e;const n=this.loadGeneration,s=this.layoutEngine.generateLayout(t.length,i,{fixedHeight:e});this.imageLayouts=s,this.displayQueue=[];let r=0;const a=c=>{this.containerEl&&(this.containerEl.appendChild(c),this.imageElements.push(c),requestAnimationFrame(()=>{if(c.offsetWidth,c.style.opacity=this.defaultStyles.opacity??"1",c.dataset.startX&&(this.entryAnimationEngine.requiresJSAnimation()||this.entryAnimationEngine.requiresJSRotation()||this.entryAnimationEngine.requiresJSScale()||c.dataset.startRotation!==c.dataset.rotation||c.dataset.startScale!==c.dataset.scale)){const d={x:parseFloat(c.dataset.startX),y:parseFloat(c.dataset.startY)},m={x:parseFloat(c.dataset.endX),y:parseFloat(c.dataset.endY)},y=parseFloat(c.dataset.imageWidth),p=parseFloat(c.dataset.imageHeight),g=parseFloat(c.dataset.rotation),f=parseFloat(c.dataset.scale),x=c.dataset.startRotation?parseFloat(c.dataset.startRotation):g,v=c.dataset.startScale?parseFloat(c.dataset.startScale):f,w=this.entryAnimationEngine.getTiming();Mt({element:c,startPosition:d,endPosition:m,pathConfig:this.entryAnimationEngine.getPathConfig(),duration:w.duration,imageWidth:y,imageHeight:p,rotation:g,scale:f,rotationConfig:this.entryAnimationEngine.getRotationConfig(),startRotation:x,scaleConfig:this.entryAnimationEngine.getScaleConfig(),startScale:v})}else{const d=c.dataset.finalTransform||"";c.style.transform=d}const l=parseInt(c.dataset.imageId||"0");if(this.fullConfig.config.debug?.enabled&&l<3){const d=c.dataset.finalTransform||"";console.log(`Image ${l} final state:`,{left:c.style.left,top:c.style.top,width:c.style.width,height:c.style.height,computedWidth:c.offsetWidth,computedHeight:c.offsetHeight,transform:d,pathType:this.entryAnimationEngine.getPathType()})}}),r++)},h=()=>{if(this.logDebug("Starting queue processing, enabled:",this.fullConfig.animation.queue.enabled),!this.fullConfig.animation.queue.enabled){for(;this.displayQueue.length>0;){const c=this.displayQueue.shift();c&&a(c)}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 c=this.displayQueue.shift();c&&a(c)}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 c=new IntersectionObserver(u=>{u.forEach(l=>{l.isIntersecting&&(h(),c.disconnect())})},{threshold:.1,rootMargin:"50px"});c.observe(this.containerEl)}else h();this.fullConfig.config.debug?.centers&&this.containerEl&&(this.containerEl.querySelectorAll(".fbn-ic-debug-center").forEach(c=>c.remove()),s.forEach((c,u)=>{const l=document.createElement("div");l.className="fbn-ic-debug-center",l.style.position="absolute",l.style.width="12px",l.style.height="12px",l.style.borderRadius="50%",l.style.backgroundColor="red",l.style.border="2px solid yellow",l.style.zIndex="9999",l.style.pointerEvents="none";const d=c.x,m=c.y;l.style.left=`${d-6}px`,l.style.top=`${m-6}px`,l.title=`Image ${u}: center (${Math.round(d)}, ${Math.round(m)})`,this.containerEl.appendChild(l)})),t.forEach((c,u)=>{const l=document.createElement("img");l.referrerPolicy="no-referrer",l.classList.add("fbn-ic-image"),l.dataset.imageId=String(u);const d=s[u];l.style.position="absolute",l.style.width="auto",l.style.height=`${e}px`,l.style.left=`${d.x}px`,l.style.top=`${d.y}px`,d.zIndex&&(l.style.zIndex=String(d.zIndex)),ot(l,this.defaultStyles),st(l,this.defaultClassName),l.addEventListener("mouseenter",()=>{this.hoveredImage={element:l,layout:d},this.zoomEngine.isInvolved(l)||(ot(l,this.hoverStyles),st(l,this.hoverClassName))}),l.addEventListener("mouseleave",()=>{this.hoveredImage=null,this.zoomEngine.isInvolved(l)||(ot(l,this.defaultStyles),kt(l,this.hoverClassName),st(l,this.defaultClassName))}),l.addEventListener("click",m=>{m.stopPropagation(),this.handleImageClick(l,d)}),l.style.opacity="0",l.style.transition=this.entryAnimationEngine.getTransitionCSS(),l.onload=()=>{if(n!==this.loadGeneration)return;const m=l.naturalWidth/l.naturalHeight,y=e*m;l.style.width=`${y}px`;const p={x:d.x,y:d.y},g={width:y,height:e},f=this.entryAnimationEngine.calculateStartPosition(p,g,i,u,t.length),x=this.entryAnimationEngine.calculateStartRotation(d.rotation),v=this.entryAnimationEngine.calculateStartScale(d.scale),w=this.entryAnimationEngine.buildFinalTransform(d.rotation,d.scale,y,e),I=this.entryAnimationEngine.buildStartTransform(f,p,d.rotation,d.scale,y,e,x,v);this.fullConfig.config.debug?.enabled&&u<3&&console.log(`Image ${u}:`,{finalPosition:p,imageSize:g,left:d.x,top:d.y,finalTransform:w,renderedWidth:y,renderedHeight:e}),l.style.transform=I,l.dataset.finalTransform=w,(this.entryAnimationEngine.requiresJSAnimation()||this.entryAnimationEngine.requiresJSRotation()||this.entryAnimationEngine.requiresJSScale()||x!==d.rotation||v!==d.scale)&&(l.dataset.startX=String(f.x),l.dataset.startY=String(f.y),l.dataset.endX=String(p.x),l.dataset.endY=String(p.y),l.dataset.imageWidth=String(y),l.dataset.imageHeight=String(e),l.dataset.rotation=String(d.rotation),l.dataset.scale=String(d.scale),l.dataset.startRotation=String(x),l.dataset.startScale=String(v)),this.displayQueue.push(l)},l.onerror=()=>r++,l.src=c})}async handleImageClick(t,e){if(!this.containerEl)return;const i=this.zoomEngine.isFocused(t),n={width:this.containerEl.offsetWidth,height:this.containerEl.offsetHeight};if(i)await this.zoomEngine.unfocusImage(),this.currentFocusIndex=null,this.swipeEngine?.disable(),this.hideCounter();else{const s=t.dataset.imageId;this.currentFocusIndex=s!==void 0?parseInt(s,10):null,this.swipeEngine?.enable(),await this.zoomEngine.focusImage(t,n,e),this.currentFocusIndex!==null&&this.updateCounter(this.currentFocusIndex)}}clearImageCloud(){this.queueInterval!==null&&(clearInterval(this.queueInterval),this.queueInterval=null),this.loadGeneration++,this.displayQueue=[],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.imagesLoaded=!1}showLoading(t){!this.fullConfig.rendering.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.rendering.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")}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.resizeTimeout!==null&&clearTimeout(this.resizeTimeout),this.swipeEngine?.destroy()}}class Le{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 e of this.sources)if("folders"in e)for(const i of e.folders){const n=e.recursive!==void 0?e.recursive:!0,s=await this.loadFromFolder(i,t,n);this._discoveredUrls.push(...s)}else if("files"in e){const i=await this.loadFiles(e.files,t);this._discoveredUrls.push(...i)}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 e=[/\/folders\/([a-zA-Z0-9_-]+)/,/id=([a-zA-Z0-9_-]+)/];for(const i of e){const n=t.match(i);if(n&&n[1])return n[1]}return null}async loadFromFolder(t,e,i=!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,e);try{return i?await this.loadImagesRecursively(n,e):await this.loadImagesFromSingleFolder(n,e)}catch(s){return console.error("Error loading from Google Drive API:",s),this.loadImagesDirectly(n,e)}}async loadImagesFromSingleFolder(t,e){const i=[],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()).files.filter(u=>u.mimeType.startsWith("image/")&&e.isAllowed(u.name));return this.log(`Found ${c.length} images in folder ${t} (non-recursive)`),c.forEach(u=>{i.push(`https://lh3.googleusercontent.com/d/${u.id}=s1600`),this.log(`Added file: ${u.name}`)}),i}async loadFiles(t,e){const i=[];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 h=await a.json();h.mimeType.startsWith("image/")&&e.isAllowed(h.name)?(i.push(`https://lh3.googleusercontent.com/d/${s}=s1600`),this.log(`Added file: ${h.name}`)):this.log(`Skipping non-image file: ${h.name} (${h.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 i.push(`https://lh3.googleusercontent.com/d/${s}=s1600`)}return i}extractFileId(t){if(!/[/:.]/.test(t))return t;const e=[/\/file\/d\/([a-zA-Z0-9_-]+)/,/\/open\?id=([a-zA-Z0-9_-]+)/,/id=([a-zA-Z0-9_-]+)/];for(const i of e){const n=t.match(i);if(n&&n[1])return n[1]}return null}async loadImagesRecursively(t,e){const i=[],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 h=await a.json(),c=h.files.filter(l=>l.mimeType.startsWith("image/")&&e.isAllowed(l.name)),u=h.files.filter(l=>l.mimeType==="application/vnd.google-apps.folder");this.log(`Found ${h.files.length} total items in folder ${t}`),h.files.forEach(l=>this.log(` - File: ${l.name} (${l.mimeType})`)),this.log(`- ${c.length} valid files (images only)`),this.log(`- ${u.length} subfolders`),c.forEach(l=>{i.push(`https://lh3.googleusercontent.com/d/${l.id}=s1600`),this.log(`Added file: ${l.name}`)});for(const l of u){this.log(`Loading images from subfolder: ${l.name}`);const d=await this.loadImagesRecursively(l.id,e);i.push(...d)}return i}async loadImagesDirectly(t,e){try{const i=`https://drive.google.com/embeddedfolderview?id=${t}`,n=await fetch(i,{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(i){throw console.error("Direct loading failed:",i),new Error(`Unable to load images. Please ensure:
51
+ 1. The folder is shared publicly (Anyone with the link can view)
52
+ 2. The folder contains image files
53
+ 3. Consider adding a Google Drive API key in config.js for better reliability`)}}manualImageUrls(t){return t.map(e=>`https://drive.google.com/uc?export=view&id=${e}`)}log(...t){this.debugLogging&&typeof console<"u"&&console.log(...t)}}class Me{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 e of this.sources)try{const i=await this.processSource(e,t);this._discoveredUrls.push(...i)}catch(i){console.warn("Failed to process source:",e,i)}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,e){return t?"urls"in t?await this.processUrls(t.urls,e):"path"in t?await this.processPath(t.path,t.files,e):"json"in t?await this.processJson(t.json,e):(console.warn("Unknown source shape:",t),[]):(console.warn("Invalid source object:",t),[])}async processUrls(t,e){if(!Array.isArray(t))return console.warn("URLs must be an array:",t),[];const i=[];for(const n of t){const s=n.split("/").pop()||n;if(!e.isAllowed(s)){this.log(`Skipping filtered URL: ${n}`);continue}this.validateUrls?await this.validateUrl(n)?i.push(n):console.warn(`Skipping invalid/missing URL: ${n}`):i.push(n)}return i}async processPath(t,e,i){if(!Array.isArray(e))return console.warn("files must be an array:",e),[];const n=[];for(const s of e){if(!i.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,e){this.log(`Fetching JSON endpoint: ${t}`);const i=new AbortController,n=setTimeout(()=>i.abort(),1e4);try{const s=await fetch(t,{signal:i.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,e)}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 i=new AbortController,n=setTimeout(()=>i.abort(),this.validationTimeout),s=await fetch(t,{method:"HEAD",signal:i.signal});return clearTimeout(n),s.ok?!0:(this.log(`Validation failed for ${t}: HTTP ${s.status}`),!1)}catch(i){return i instanceof Error&&(i.name==="AbortError"?this.log(`Validation timeout for ${t}`):this.log(`Validation failed for ${t}:`,i.message)),!1}}constructUrl(t,e){const i=t.replace(/\/$/,"");if(this.isAbsoluteUrl(t))return`${i}/${e}`;if(typeof window>"u")return`${i}/${e}`;const n=window.location.origin,r=(t.startsWith("/")?t:"/"+t).replace(/\/$/,"");return`${n}${r}/${e}`}isAbsoluteUrl(t){try{return new URL(t),!0}catch{return!1}}log(...t){this.debugLogging&&typeof console<"u"&&console.log(...t)}}class Fe{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 e=this.loaders.map((i,n)=>i.prepare(t).then(()=>{this.log(`Loader ${n} prepared with ${i.imagesLength()} images`)}).catch(s=>{console.warn(`Loader ${n} failed to prepare:`,s)}));await Promise.all(e);for(const i of this.loaders)if(i.isPrepared()){const n=i.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)}}A.AnimationEngine=Lt,A.BOUNCE_PRESETS=dt,A.ClusterPlacementLayout=_t,A.CompositeLoader=Fe,A.DEFAULT_CONFIG=b,A.DEFAULT_SHARED_LOADER_CONFIG=yt,A.ELASTIC_PRESETS=ut,A.EntryAnimationEngine=zt,A.FUNCTIONAL_CSS=Yt,A.GoogleDriveLoader=Le,A.GridPlacementLayout=Pt,A.ImageCloud=Bt,A.ImageFilter=qt,A.ImageGallery=Bt,A.LayoutEngine=Ht,A.RadialPlacementLayout=Ot,A.RandomPlacementLayout=Dt,A.SpiralPlacementLayout=Ut,A.StaticImageLoader=Me,A.WAVE_PATH_PRESETS=gt,A.WavePlacementLayout=Nt,A.ZoomEngine=Wt,A.animatePath=Mt,A.injectFunctionalStyles=Xt,A.requiresJSAnimation=Ft,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})}));
54
54
  //# sourceMappingURL=image-cloud.umd.js.map