@michaelyagi/shoji 0.1.0-beta.1 → 0.1.0-beta.2

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.
package/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # Shoji
2
2
 
3
3
  [![CI](https://github.com/MichaelYagi/shoji/actions/workflows/ci.yml/badge.svg)](https://github.com/MichaelYagi/shoji/actions/workflows/ci.yml)
4
- [![npm (alpha)](https://img.shields.io/npm/v/%40michaelyagi%2Fshoji/alpha.svg)](https://www.npmjs.com/package/@michaelyagi/shoji)
4
+ [![npm (beta)](https://img.shields.io/npm/v/%40michaelyagi%2Fshoji/beta.svg)](https://www.npmjs.com/package/@michaelyagi/shoji)
5
5
 
6
6
  A zero-dependency, plugin-first TypeScript lightbox/gallery. Drop in two `<script>`/`<link>` tags, or install from npm — everything beyond the minimal lightbox, including every official plugin, is opt-in.
7
7
 
8
- > **Status: alpha.** The API is still settling — expect breaking changes between `0.x` releases.
8
+ > **Status: beta.** The API is still settling — expect breaking changes between `0.x` releases.
9
9
 
10
10
  ## Features
11
11
 
@@ -28,7 +28,7 @@ A zero-dependency, plugin-first TypeScript lightbox/gallery. Drop in two `<scrip
28
28
  ```
29
29
 
30
30
  ```bash
31
- npm install @michaelyagi/shoji@alpha
31
+ npm install @michaelyagi/shoji@beta
32
32
  ```
33
33
 
34
34
  ```js
package/dist/esm/index.js CHANGED
@@ -6,7 +6,7 @@ import { Layout } from "./plugins/layout/index.js";
6
6
  import { RotateFlip } from "./plugins/rotateFlip/index.js";
7
7
  import { Video } from "./plugins/video/index.js";
8
8
  import { Zoom } from "./plugins/zoom/index.js";
9
- const version = "0.1.0-beta.1";
9
+ const version = "0.1.0-beta.2";
10
10
  const Shoji = Object.assign(Gallery, {
11
11
  Autoplay,
12
12
  Layout,
package/dist/shoji.js CHANGED
@@ -5278,7 +5278,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
5278
5278
  };
5279
5279
  }
5280
5280
  };
5281
- const version = "0.1.0-beta.1";
5281
+ const version = "0.1.0-beta.2";
5282
5282
  const Shoji = Object.assign(Gallery, {
5283
5283
  Autoplay,
5284
5284
  Layout,
package/dist/shoji.min.js CHANGED
@@ -1,2 +1,2 @@
1
- (function(tt,it){typeof exports=="object"&&typeof module<"u"?module.exports=it():typeof define=="function"&&define.amd?define(it):(tt=typeof globalThis<"u"?globalThis:tt||self,tt.Shoji=it())})(this,(function(){"use strict";var Fi=Object.defineProperty;var Ni=(tt,it,xt)=>it in tt?Fi(tt,it,{enumerable:!0,configurable:!0,writable:!0,value:xt}):tt[it]=xt;var p=(tt,it,xt)=>Ni(tt,typeof it!="symbol"?it+"":it,xt);let tt=0,it="",xt="",ie="",ne=0,se=0,gt=null,_t=!1;const re=".shoji-outer";function Ge(){_t=!0}function Ue(){return getComputedStyle(document.documentElement).direction==="rtl"}function Ke(o){let t=o instanceof Element?o:(o==null?void 0:o.parentElement)??null;for(;t&&t!==document.documentElement;){const e=getComputedStyle(t);if((e.overflowY==="auto"||e.overflowY==="scroll")&&t.scrollHeight>t.clientHeight)return!0;t=t.parentElement}return!1}let ae=!1;function le(o){const t=o.target;ae=!(t instanceof Element&&t.closest(re)!==null)&&Ke(t)}function ce(o){const t=o.target;!(t instanceof Element&&t.closest(re)!==null)&&!ae&&o.preventDefault()}function Je(){if(tt===0)return;const o=document.documentElement;getComputedStyle(o).overflow!=="hidden"&&(o.style.overflow="hidden",gt==null||gt.takeRecords())}function Qe(){if(tt===0){ne=window.scrollX,se=window.scrollY,_t=!1;const o=window.innerWidth-document.documentElement.clientWidth,t=Ue();if(xt=document.documentElement.style.paddingRight,ie=document.documentElement.style.paddingLeft,o>0)if(t){const e=parseFloat(getComputedStyle(document.documentElement).paddingLeft)||0;document.documentElement.style.paddingLeft=`${e+o}px`}else{const e=parseFloat(getComputedStyle(document.documentElement).paddingRight)||0;document.documentElement.style.paddingRight=`${e+o}px`}it=document.documentElement.style.overflow,document.documentElement.style.overflow="hidden",document.addEventListener("touchstart",le,{passive:!0}),document.addEventListener("touchmove",ce,{passive:!1}),gt=new MutationObserver(Je),gt.observe(document.documentElement,{attributes:!0,attributeFilter:["style"]})}tt++}function to(){tt=Math.max(0,tt-1),tt===0&&(gt==null||gt.disconnect(),gt=null,document.removeEventListener("touchstart",le),document.removeEventListener("touchmove",ce),document.documentElement.style.overflow=it,document.documentElement.style.paddingRight=xt,document.documentElement.style.paddingLeft=ie,_t||window.scrollTo({left:ne,top:se,behavior:"instant"}))}class eo{constructor(){p(this,"listeners",new Map)}on(t,e){let i=this.listeners.get(t);return i||(i=new Set,this.listeners.set(t,i)),i.add(e),()=>this.off(t,e)}off(t,e){var i;(i=this.listeners.get(t))==null||i.delete(e)}emit(t,e){const i=this.listeners.get(t);if(i)for(const n of i)n(e)}clear(){this.listeners.clear()}}const de='<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M6 6l12 12M18 6L6 18"/></svg>',oo='<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 6l-6 6 6 6"/></svg>',io='<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 6l6 6-6 6"/></svg>',no='<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="5" width="18" height="14" rx="2"/><path d="M7 10h10M7 14h6"/></svg>',so='<svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 9l6 6 6-6"/></svg>';let ro=0;function Rt(o,t,e){const i=document.createElement("button");return i.type="button",i.className=o,i.ariaLabel=i.title=e,i.innerHTML=t,i}function ao(o,t){const e=`shoji-counter-${++ro}`,i=document.createElement("div");i.className="shoji-outer";const n=document.createElement("div");n.className="shoji-backdrop",i.appendChild(n);const s=document.createElement("div");s.className="shoji-dialog",s.setAttribute("role","dialog"),s.setAttribute("aria-modal","true"),s.setAttribute("aria-labelledby",e),s.tabIndex=-1;const r=document.createElement("div");r.className="shoji-toolbar";const a=document.createElement("div");a.className="shoji-toolbar-slot shoji-toolbar-left";const l=document.createElement("div");l.className="shoji-toolbar-slot shoji-toolbar-center";const c=document.createElement("div");c.className="shoji-toolbar-slot shoji-toolbar-right";const f=Rt("shoji-close",de,t.close),y=Rt("shoji-toolbar-button shoji-caption-toggle",no,t.showCaption);y.setAttribute("aria-pressed","false"),y.hidden=!0;const g=Rt("shoji-toolbar-button shoji-toolbar-overflow",so,t.moreControls);g.setAttribute("aria-haspopup","true"),g.setAttribute("aria-expanded","false"),g.hidden=!0,c.append(y,g,f);const v=document.createElement("div");v.className="shoji-toolbar-overflow-panel",v.setAttribute("role","dialog"),v.setAttribute("aria-label",t.moreControls),v.tabIndex=-1,v.hidden=!0;const b=document.createElement("div");b.className="shoji-counter",b.id=e,a.appendChild(b),r.append(a,l,c),s.appendChild(r),s.appendChild(v);const E=Rt("shoji-nav shoji-nav-prev",oo,t.previous),T=Rt("shoji-nav shoji-nav-next",io,t.next);s.appendChild(E),s.appendChild(T),s.appendChild(o);const M=document.createElement("div");M.className="shoji-caption",s.appendChild(M);const C=document.createElement("div");C.className="shoji-caption-modal",C.hidden=!0;const R=document.createElement("div");R.className="shoji-caption-modal-panel",R.setAttribute("role","dialog"),R.setAttribute("aria-modal","true"),R.setAttribute("aria-label",t.fullCaption),R.tabIndex=-1;const V=Rt("shoji-caption-modal-close",de,t.close),N=document.createElement("div");return N.className="shoji-caption-modal-content",R.append(V,N),C.appendChild(R),s.appendChild(C),i.appendChild(s),{outer:i,backdrop:n,dialog:s,counter:b,caption:M,captionModal:C,captionModalPanel:R,captionModalContent:N,captionModalCloseButton:V,closeButton:f,prevButton:E,nextButton:T,captionToggleButton:y,toolbar:r,toolbarLeft:a,toolbarCenter:l,toolbarRight:c,toolbarOverflowButton:g,toolbarOverflowPanel:v}}const lo='a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), video[controls], [tabindex]:not([tabindex="-1"])';class co{constructor(){p(this,"container",null);p(this,"previouslyFocused",null);p(this,"onKeydown",t=>{if(t.key!=="Tab"||!this.container)return;const e=this.getFocusable();if(e.length===0){t.preventDefault(),this.container.focus();return}const i=e[0],n=e[e.length-1],s=document.activeElement,r=s instanceof HTMLElement&&e.includes(s);t.shiftKey?(!r||s===i)&&(t.preventDefault(),n.focus()):(!r||s===n)&&(t.preventDefault(),i.focus())})}getFocusable(){return this.container?Array.from(this.container.querySelectorAll(lo)):[]}activate(t){this.previouslyFocused=document.activeElement,this.container=t,document.addEventListener("keydown",this.onKeydown,!0),t.focus()}retarget(t){this.container=t,t.focus()}deactivate(){var t;document.removeEventListener("keydown",this.onKeydown,!0),this.container=null,(t=this.previouslyFocused)==null||t.focus({preventScroll:!0}),this.previouslyFocused=null}}const ho=300,uo=30,fo=500;class po{constructor(t,e,i){p(this,"target");p(this,"options");p(this,"callbacks");p(this,"pointers",new Map);p(this,"primaryPointerId",null);p(this,"direction",null);p(this,"dragStartDistance",0);p(this,"pinching",!1);p(this,"pinchStartDistance",0);p(this,"capturedThisGesture",!1);p(this,"lastTapTime",-1/0);p(this,"lastTapX",0);p(this,"lastTapY",0);p(this,"onPointerDown",t=>{var e,i,n,s;if(!(t.isPrimary===!1&&this.pointers.size===0)&&!(this.pointers.size===0&&((i=(e=this.callbacks).ignore)!=null&&i.call(e,t)))){if(this.pointers.set(t.pointerId,{startX:t.clientX,startY:t.clientY,startTime:t.timeStamp,lastX:t.clientX,lastY:t.clientY,lastTime:t.timeStamp}),this.pointers.size===1)this.primaryPointerId=t.pointerId,this.direction=null,this.capturedThisGesture=!1;else if(this.pointers.size===2){this.direction=null,this.pinching=!0;const[r,a]=[...this.pointers.values()];this.pinchStartDistance=he(r,a);const l=ue(r,a);(s=(n=this.callbacks).onPinchStart)==null||s.call(n,l.x,l.y)}}});p(this,"onPointerMove",t=>{var r,a,l,c,f,y,g,v;const e=this.pointers.get(t.pointerId);if(!e)return;if(e.lastX=t.clientX,e.lastY=t.clientY,e.lastTime=t.timeStamp,this.pinching){if(this.pointers.size<2)return;const[b,E]=[...this.pointers.values()],T=he(b,E),M=this.pinchStartDistance>0?T/this.pinchStartDistance:1,C=ue(b,E);(a=(r=this.callbacks).onPinchMove)==null||a.call(r,M,C.x,C.y);return}if(t.pointerId!==this.primaryPointerId)return;const i=t.clientX-e.startX,n=t.clientY-e.startY;if(this.direction===null){const b=Math.abs(i),E=Math.abs(n);if(Math.max(b,E)<this.options.lockThreshold)return;this.direction=b>E?"horizontal":"vertical",this.dragStartDistance=this.direction==="horizontal"?i:n,(((c=(l=this.callbacks).shouldCapture)==null?void 0:c.call(l))??!0)&&(this.target.setPointerCapture(t.pointerId),this.capturedThisGesture=!0),(y=(f=this.callbacks).onDragStart)==null||y.call(f,this.direction,t)}this.direction==="horizontal"&&t.preventDefault();const s=(this.direction==="horizontal"?i:n)-this.dragStartDistance;(v=(g=this.callbacks).onDragMove)==null||v.call(g,this.direction,s,t)});p(this,"onPointerUp",t=>{this.finishPointer(t,!1)});p(this,"onPointerCancel",t=>{this.finishPointer(t,!0)});p(this,"onWheel",t=>{var i,n;if(!t.ctrlKey)return;t.preventDefault();const e=-t.deltaY*.01;(n=(i=this.callbacks).onWheelZoom)==null||n.call(i,e,t.clientX,t.clientY,t)});this.target=t,this.callbacks=e,this.options={lockThreshold:(i==null?void 0:i.lockThreshold)??10,swipeThreshold:(i==null?void 0:i.swipeThreshold)??50,swipeVelocity:(i==null?void 0:i.swipeVelocity)??.3},this.target.addEventListener("pointerdown",this.onPointerDown),this.target.addEventListener("pointermove",this.onPointerMove),this.target.addEventListener("pointerup",this.onPointerUp),this.target.addEventListener("pointercancel",this.onPointerCancel),this.target.addEventListener("wheel",this.onWheel,{passive:!1})}destroy(){this.target.removeEventListener("pointerdown",this.onPointerDown),this.target.removeEventListener("pointermove",this.onPointerMove),this.target.removeEventListener("pointerup",this.onPointerUp),this.target.removeEventListener("pointercancel",this.onPointerCancel),this.target.removeEventListener("wheel",this.onWheel),this.pointers.clear()}finishPointer(t,e){var n,s,r,a;const i=this.pointers.get(t.pointerId);if(i){if(i.lastX=t.clientX,i.lastY=t.clientY,i.lastTime=t.timeStamp,this.pointers.delete(t.pointerId),this.pinching){this.pointers.size<2&&(this.pinching=!1,(s=(n=this.callbacks).onPinchEnd)==null||s.call(n));return}if(t.pointerId===this.primaryPointerId){if(this.direction===null)!e&&t.timeStamp-i.startTime<=fo&&this.registerTap(i.lastX,i.lastY,t);else{const l=Math.max(1,i.lastTime-i.startTime),c=(this.direction==="horizontal"?i.lastX-i.startX:i.lastY-i.startY)-this.dragStartDistance,f=c/l,y=!e&&(Math.abs(c)>=this.options.swipeThreshold||Math.abs(f)>=this.options.swipeVelocity);(a=(r=this.callbacks).onDragEnd)==null||a.call(r,this.direction,c,f,y,e),this.capturedThisGesture&&this.suppressRetargetedClick()}this.primaryPointerId=null,this.direction=null,this.capturedThisGesture=!1}}}suppressRetargetedClick(){let t=!1;const e=i=>{t||(t=!0,i==null||i.stopPropagation(),this.target.removeEventListener("click",e,{capture:!0}))};this.target.addEventListener("click",e,{capture:!0}),setTimeout(e,500)}registerTap(t,e,i){var r,a,l,c;const n=i.timeStamp;n-this.lastTapTime<=ho&&Math.hypot(t-this.lastTapX,e-this.lastTapY)<=uo?((a=(r=this.callbacks).onDoubleTap)==null||a.call(r,t,e,i),this.lastTapTime=0):((c=(l=this.callbacks).onTap)==null||c.call(l,t,e,i),this.lastTapTime=n,this.lastTapX=t,this.lastTapY=e)}}function he(o,t){return Math.hypot(o.lastX-t.lastX,o.lastY-t.lastY)}function ue(o,t){return{x:(o.lastX+t.lastX)/2,y:(o.lastY+t.lastY)/2}}function fe(){return typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}function mo(o){var e;const t=((e=o.split(",")[0])==null?void 0:e.trim())??"";return t.endsWith("ms")?parseFloat(t):t.endsWith("s")?parseFloat(t)*1e3:0}function pe(o,t,e){const i=o.width/o.height;let n=t>i?o.width:o.height*t,s=t>i?o.width/t:o.height;if(e&&e.width>0&&e.height>0){const r=Math.min(1,e.width/n,e.height/s);n*=r,s*=r}return{left:o.left+(o.width-n)/2,top:o.top+(o.height-s)/2,width:n,height:s}}function me(o,t,e){const i=o.firstElementChild,n=i instanceof HTMLElement&&(i.classList.contains("shoji-slide-spinner")||i.classList.contains("shoji-slide-open-placeholder"));if(i instanceof HTMLElement&&!n){const r=i.getBoundingClientRect();if(r.width>0&&r.height>0)return r}const s=o.getBoundingClientRect();return t&&s.width>0&&s.height>0?pe(s,t,e):s}function ge(o,t){const e=Math.min(t.width/o.width,t.height/o.height),i=t.left+t.width/2-(o.left+o.width/2),n=t.top+t.height/2-(o.top+o.height/2);return`translate3d(${i}px, ${n}px, 0) scale3d(${e}, ${e}, 1)`}function ve(o,t,e,i){const n=o.getBoundingClientRect(),s=me(t,e,i);return s.width===0||s.height===0||n.width===0||n.height===0?null:ge(s,n)}function At(o,t,e="transform"){const i=mo(getComputedStyle(o).transitionDuration);let n=!1;const s=()=>{n||(n=!0,o.removeEventListener("transitionend",r),t())},r=a=>{a.target===o&&a.propertyName===e&&s()};o.addEventListener("transitionend",r),setTimeout(s,i+100)}function ye(o,t){o.style.transition="",o.style.transformOrigin="",o.style.willChange="",o.style.opacity="",o.style.transform===t&&(o.style.transform="")}function go({origin:o,target:t,aspectRatio:e,naturalSize:i}){if(fe())return;const n=ve(o,t,e,i);n&&(t.style.transition="none",t.style.transformOrigin="center",t.style.willChange="transform",t.style.transform=n,t.offsetHeight,t.style.transition="transform var(--shoji-duration) var(--shoji-easing)",t.style.transform="none",At(t,()=>ye(t,"none")))}function vo({origin:o,target:t,aspectRatio:e,naturalSize:i,dragStart:n,zoomStart:s},r){if(fe()){r();return}const a=ve(o,t,e,i);if(!a){r();return}if(t.style.transformOrigin="center",t.style.willChange="transform",n)t.style.transition="none",t.style.transform=`translate3d(0px, ${n.translateY}px, 0px) scale3d(${n.scale}, ${n.scale}, 1)`,t.style.opacity=String(n.opacity),t.offsetHeight;else if(s){const c=me(t,e,i);if(c.width>0&&c.height>0){const f=t.style.transform,y=ge(c,s);t.style.transition="none",t.style.transform=f&&f!=="none"?`${f} ${y}`:y,t.offsetHeight}}t.style.transition="transform var(--shoji-duration) var(--shoji-easing)",t.offsetHeight,t.style.transform=a;const l=t.style.transform;At(t,()=>{ye(t,l),r()})}const yo="transform var(--shoji-duration) var(--shoji-momentum-easing)",bo="transform var(--shoji-duration) var(--shoji-momentum-easing), opacity var(--shoji-duration) var(--shoji-momentum-easing)",be=160,wo="button, video, input, select, textarea, a[href], [data-shoji-no-drag], .shoji-caption, .shoji-caption-modal, .shoji-toolbar-overflow-panel",Eo="button, input, select, textarea, a[href], [data-shoji-no-drag], .shoji-caption, .shoji-caption-modal, .shoji-toolbar-overflow-panel";function Co(o,t){const e=t.getBoundingClientRect(),i=parseFloat(getComputedStyle(t).getPropertyValue("--shoji-video-gesture-margin"));return o.clientY>=e.bottom-(Number.isFinite(i)?i:0)}function So(o){let t=!1;const e=i=>{t||(t=!0,i==null||i.stopPropagation(),o.removeEventListener("click",e,{capture:!0}))};o.addEventListener("click",e,{capture:!0}),setTimeout(e,500)}function To(o,t){if(t.hidden||!t.classList.contains("shoji-caption--video"))return!1;const e=t.getBoundingClientRect();return o.clientX>=e.left&&o.clientX<=e.right&&o.clientY>=e.top&&o.clientY<=e.bottom}function Mo(o,t,e){if(To(o,t))return!0;const i=o.composedPath(),n=i.find(s=>s instanceof HTMLVideoElement);return n?Co(o,n)?(So(e),!0):!1:i.some(s=>s instanceof Element&&s.matches(Eo))}class Lo{constructor(t,e,i){p(this,"engine");p(this,"controlsHideThreshold");p(this,"controlsHiddenForDrag",!1);p(this,"lastDragDelta",0);p(this,"onDragMove",(t,e)=>{this.host.isZoomed()||(t==="horizontal"?this.host.slides.setDragOffset(e,null):this.host.canClose()&&this.applyVerticalDragFeedback(e))});p(this,"onDragEnd",(t,e,i,n)=>{this.host.isZoomed()||(t==="horizontal"?this.finishHorizontalDrag(e,n):this.finishVerticalDrag(n))});this.host=t,this.controlsHideThreshold=(i==null?void 0:i.swipeThreshold)??50,this.engine=new po(t.dialog,{ignore:n=>Mo(n,t.caption,t.dialog),shouldCapture:()=>!t.isZoomed(),onDragStart:()=>t.onActivity(),onDragMove:this.onDragMove,onDragEnd:this.onDragEnd,onTap:(n,s)=>e.onTap(n,s),onDoubleTap:(n,s)=>e.onDoubleTap(n,s),onPinchStart:(n,s)=>e.onPinchStart(n,s),onPinchMove:(n,s,r)=>e.onPinchMove(n,s,r),onPinchEnd:()=>e.onPinchEnd(),onWheelZoom:(n,s,r)=>e.onWheelZoom(n,s,r)},i)}destroy(){this.engine.destroy()}finishHorizontalDrag(t,e){const i=t<0,n=i?this.host.canGoNext():this.host.canGoPrev();if(!e||t===0||!n){this.settleDragOffset(0,()=>{});return}const s=this.host.dialog.getBoundingClientRect().width||1,r=i?-s:s;this.settleDragOffset(r,()=>{this.host.slides.setDragOffset(0,null),i?this.host.next():this.host.prev()})}settleDragOffset(t,e){const i=this.host.slides.getSlotRoot(0);if(this.host.slides.setDragOffset(t,yo),!i){e();return}At(i,e)}applyVerticalDragFeedback(t){const e=Math.min(Math.abs(t)/be,1),i=this.host.slides.element;this.lastDragDelta=t,i.style.transition="",i.style.transform=`translateY(${t}px) scale(${1-e*.15})`,i.style.opacity=String(1-e*.6);const n=Math.abs(t)>=this.controlsHideThreshold;n!==this.controlsHiddenForDrag&&(this.controlsHiddenForDrag=n,this.host.setControlsHiddenForDrag(n))}clearVerticalDragFeedback(t){const e=this.host.slides.element;e.style.transition=t?bo:"",e.style.transform="",e.style.opacity=""}finishVerticalDrag(t){const e=this.controlsHiddenForDrag;this.controlsHiddenForDrag=!1,t&&this.host.canClose()?this.host.closeFromSwipe(this.takeFrozenDragTransform()):(this.clearVerticalDragFeedback(!0),e&&this.host.setControlsHiddenForDrag(!1))}takeFrozenDragTransform(){const t=Math.min(Math.abs(this.lastDragDelta)/be,1),e={translateY:this.lastDragDelta,scale:1-t*.15,opacity:1-t*.6};return this.clearVerticalDragFeedback(!1),e}}class xo{constructor(){p(this,"element");this.element=document.createElement("div"),this.element.className="shoji-live-region",this.element.setAttribute("role","status"),this.element.setAttribute("aria-live","polite")}announce(t){this.element.textContent="",this.element.offsetWidth,this.element.textContent=t}}const Xt=":scope > a, :scope > [data-shoji-src], :scope > [data-shoji-video]";function we(o,t=Xt){const e=Array.from(o.querySelectorAll(t)),i=[];for(const n of e){const s=Po(n)??jo(n);s&&i.push({element:n,item:s})}return i}function ct(o,t){return o.getAttribute(t)??void 0}function It(o,t){const e=o.getAttribute(t);if(e===null)return;const i=Number(e);return Number.isFinite(i)?i:void 0}const Oo=new Set(["no-drag","video-id","video-provider"]);function qt(o,t,e){const i=ct(o,"data-shoji-caption");i&&(t.caption=i),t.id=ct(o,"data-shoji-id")??e;let n;for(const s of o.attributes){if(!s.name.startsWith("data-shoji-"))continue;const r=s.name.slice(11);!Oo.has(r)&&!(r in t)&&((n??(n={}))[r]=s.value)}n&&(t.data=n)}function jo(o){const t=ct(o,"href")??ct(o,"data-shoji-src");if(!t)return;const e={src:t},i=o.querySelector("img"),n=(i==null?void 0:i.getAttribute("src"))??ct(o,"data-shoji-thumb");n&&(e.thumb=n);const s=(i==null?void 0:i.getAttribute("alt"))??ct(o,"data-shoji-alt");s&&(e.alt=s);const r=It(o,"data-shoji-width");r!==void 0&&(e.width=r);const a=It(o,"data-shoji-height");a!==void 0&&(e.height=a);const l=ct(o,"data-shoji-srcset");l&&(e.srcset=l);const c=ct(o,"data-shoji-sizes");return c&&(e.sizes=c),qt(o,e,t),e}function Po(o){var n;const t=ct(o,"data-shoji-video-id"),e=o.querySelector("video");if(e){t&&console.warn(`Shoji: data-shoji-video-id="${t}" ignored — no effect on a nested <video> (always html5).`);const s=Array.from(e.querySelectorAll("source")).map(y=>({src:y.getAttribute("src")??"",type:y.getAttribute("type")??""})).filter(y=>y.src),r=e.getAttribute("src")??((n=s[0])==null?void 0:n.src);if(!r)return;const a={src:r,video:{provider:"html5"}};s.length&&(a.sources=s);const l=e.getAttribute("poster");l&&(a.poster=l);const c=It(o,"data-shoji-width");c!==void 0&&(a.width=c);const f=It(o,"data-shoji-height");return f!==void 0&&(a.height=f),qt(o,a,r),a}const i=ct(o,"data-shoji-video");if(i){const s=ct(o,"data-shoji-video-provider"),r=Ro(i,s,t),a={src:i,video:r.video};r.sources&&(a.sources=r.sources);const l=ct(o,"data-shoji-poster");l&&(a.poster=l);const c=It(o,"data-shoji-width");c!==void 0&&(a.width=c);const f=It(o,"data-shoji-height");return f!==void 0&&(a.height=f),qt(o,a,i),a}t&&console.warn(`Shoji: data-shoji-video-id="${t}" ignored — requires a data-shoji-video URL.`)}const Ho=new Set(["youtube","vimeo","html5"]);function Zt(o){return{video:{provider:"html5"},sources:[{src:o,type:Ao(o)}]}}function Ro(o,t,e){if(t&&!Ho.has(t)&&(console.warn(`Shoji: data-shoji-video-provider="${t}" isn't recognized — ignored.`),t=void 0),t==="html5")return e&&console.warn(`Shoji: data-shoji-video-id="${e}" ignored — provider html5 has no id.`),Zt(o);const i=Ee("youtube",o,t,e,Te,Le);if(i)return i;const n=Ee("vimeo",o,t,e,Me,xe);return n||(e&&console.warn(`Shoji: data-shoji-video-id="${e}" ignored — data-shoji-video="${o}" isn't a recognized YouTube/Vimeo URL; falling back to html5.`),Zt(o))}function Ee(o,t,e,i,n,s){const r=e===o;if(!r&&!n(t))return;const a=i??s(t);if(!a){if(!r)return Zt(t);console.warn(`Shoji: data-shoji-video-provider="${o}" but no id could be parsed from "${t}".`)}return{video:{provider:o,id:a,url:t}}}const Ce=new Set(["youtu.be","youtube.com","youtube-nocookie.com"]),Se=new Set(["vimeo.com","player.vimeo.com"]);function Ft(o){return o.replace(/^(www|m|music)\./,"")}function Te(o){try{return Ce.has(Ft(new URL(o,window.location.href).hostname))}catch{return!1}}function Me(o){try{return Se.has(Ft(new URL(o,window.location.href).hostname))}catch{return!1}}function Le(o){let t;try{t=new URL(o,window.location.href)}catch{return}const e=Ft(t.hostname);if(e==="youtu.be")return t.pathname.slice(1).split("/")[0]||void 0;if(!Ce.has(e))return;if(t.pathname==="/watch")return t.searchParams.get("v")??void 0;const i=t.pathname.match(/^\/(?:embed|shorts|live|v)\/([^/?]+)/);return i==null?void 0:i[1]}function xe(o){var e;let t;try{t=new URL(o,window.location.href)}catch{return}if(Se.has(Ft(t.hostname)))return(e=t.pathname.match(/\/(\d+)(?:\/|$)/))==null?void 0:e[1]}const Oe=[{provider:"youtube",isHost:Te,detectId:Le},{provider:"vimeo",isHost:Me,detectId:xe}];function je(o){return o.map(t=>{var s,r;if(t.video===!0){const a=Oe.find(c=>c.isHost(t.src)),l=a?{provider:a.provider,id:a.detectId(t.src)}:{provider:"html5"};return(l.provider==="youtube"||l.provider==="vimeo")&&!l.id&&console.warn(`Shoji: item "${t.id??t.src}" has video: true, but no id could be parsed from src ("${t.src}") — the embed won't load. Use an explicit video.id instead.`),{...t,video:l}}const e=t,i=(s=e.video)==null?void 0:s.provider;if(i!=="youtube"&&i!=="vimeo"||e.video&&"id"in e.video&&e.video.id)return e;const n=Oe.find(a=>a.provider===i).detectId(e.src);return n?{...e,video:{provider:i,id:n,url:(r=e.video)==null?void 0:r.url}}:(console.warn(`Shoji: item "${e.id??e.src}" has video.provider: '${i}' with no id, and src ("${e.src}") isn't a recognized ${i==="youtube"?"YouTube":"Vimeo"} URL — the embed won't load. Set video.id explicitly.`),e)})}function Ao(o){const t=o.split(/[?#]/)[0]??o,e=t.slice(t.lastIndexOf(".")+1).toLowerCase();return e==="webm"?"video/webm":e==="ogg"||e==="ogv"?"video/ogg":"video/mp4"}class Io{constructor(t){p(this,"element");p(this,"slots");p(this,"preload");p(this,"videoProviders");p(this,"dragOffsetPx",0);p(this,"cache",new Map);p(this,"pending",new Map);this.element=document.createElement("div"),this.element.className="shoji-slides",this.preload=t.preload,this.videoProviders=t.videoProviders;const e=t.preload*2+1;this.slots=Array.from({length:e},(i,n)=>{const s=n-t.preload,r=document.createElement("div");r.className="shoji-slide";const a=document.createElement("div");return a.className="shoji-slide-media",r.appendChild(a),this.element.appendChild(r),{root:r,media:a,offset:s,assignedIndex:null,ready:!1}}),this.applyTransforms(null)}getActiveMedia(){var t;return((t=this.slots.find(e=>e.offset===0))==null?void 0:t.media)??null}isActiveReady(){var t;return((t=this.slots.find(e=>e.offset===0))==null?void 0:t.ready)??!1}setDragOffset(t,e){this.dragOffsetPx=t,this.applyTransforms(e)}getSlotRoot(t){var e;return((e=this.slots.find(i=>i.offset===t))==null?void 0:e.root)??null}applyTransforms(t){for(const e of this.slots)e.root.style.transition=t??"",e.root.style.transform=`translateX(calc(${e.offset*100}% + ${this.dragOffsetPx}px))`}render(t,e,i,n,s=!1){const r=s&&t.length>this.slots.length,a=this.slots.map((v,b)=>{const E=b-this.preload,T=e+E,M=r?(T%t.length+t.length)%t.length:T,C=M>=0&&M<t.length?t[M]:void 0;return{offset:E,index:M,item:C}}),l=new Set(a.map(v=>v.index));for(const[v,b]of this.cache)l.has(v)||(Re(b.node),this.cache.delete(v));const c=new Set,f=new Set;for(const v of a){if(!v.item)continue;const b=this.slots.find(E=>E.assignedIndex===v.index&&E.ready);b&&(c.add(v.index),f.add(b),b.offset!==v.offset&&(b.offset=v.offset,i(v.index)))}const y=this.slots.filter(v=>!f.has(v));a.filter(v=>!v.item||!c.has(v.index)).forEach((v,b)=>{var C;const E=y[b];E.offset=v.offset;const{index:T,item:M}=v;if(!M){E.assignedIndex=null,E.ready=!1,Nt(E.media),E.media.replaceChildren();return}if(E.assignedIndex!==T){if(E.assignedIndex=T,E.ready=!1,Nt(E.media),E.media.replaceChildren(Do()),this.applyAspect(E,M),T===e&&n){const R=M.width&&M.height?{width:M.width,height:M.height}:void 0;this.revealOpenPlaceholder(n,E,T,R)}((C=M.video)==null?void 0:C.provider)==="html5"?this.renderVideo(M,E,T,i):M.video?this.renderProviderVideo(M,E,T,i):this.ensureImageDecoding(M,T,i)}}),this.applyTransforms(null)}applyAspect(t,e){e.width&&e.height?t.media.style.aspectRatio=`${e.width} / ${e.height}`:t.media.style.removeProperty("aspect-ratio"),e.video&&e.width&&e.height?t.media.style.setProperty("--shoji-provider-video-aspect",`calc(${e.width} / ${e.height})`):t.media.style.removeProperty("--shoji-provider-video-aspect")}swapIn(t,e,i,n){Nt(t.media),this.applyAspect(t,i),t.media.replaceChildren(e),t.ready=!0,this.cache.set(n,{node:e,item:i})}moveIn(t,e,i){this.applyAspect(t,e.item),t.media.replaceChildren(e.node),t.ready=!0,this.cache.set(i,e)}ensureImageDecoding(t,e,i){if(this.pending.has(e))return;const n=document.createElement("img");n.className="shoji-slide-img",n.alt=t.alt??"",n.draggable=!1,"fetchPriority"in n&&(n.fetchPriority="high"),t.srcset&&(n.srcset=t.srcset),t.sizes&&(n.sizes=t.sizes),n.src=t.src,this.pending.set(e,n);const s=()=>{this.pending.delete(e);const r={node:n,item:t};this.cache.set(e,r);const a=this.slots.find(l=>l.assignedIndex===e);a&&(this.moveIn(a,r,e),i(e))};typeof n.decode=="function"?n.decode().then(s,s):(n.addEventListener("load",s,{once:!0}),n.addEventListener("error",s,{once:!0}))}revealOpenPlaceholder(t,e,i,n){const s=ko(t),r=()=>{if(!(e.assignedIndex!==i||e.ready)&&(e.media.querySelectorAll(".shoji-slide-spinner, .shoji-slide-provider-poster").forEach(a=>a.remove()),e.media.appendChild(s),n)){const a=e.root.getBoundingClientRect(),l=pe({left:0,top:0,width:a.width,height:a.height},n.width/n.height,n);s.style.width=`${l.width}px`,s.style.height=`${l.height}px`}};typeof s.decode=="function"?s.decode().then(r,r):(s.addEventListener("load",r,{once:!0}),s.addEventListener("error",r,{once:!0}))}renderVideo(t,e,i,n){if(!(!!t.src||!!(t.sources&&t.sources.length>0))){const l=document.createElement("div");l.className="shoji-slide-placeholder",l.textContent="Video",this.swapIn(e,l,t,i),n(i);return}const r=document.createElement("video");if(r.className="shoji-slide-video",r.controls=!0,r.playsInline=!0,r.draggable=!1,t.poster&&(r.poster=t.poster),t.width&&t.height&&(r.style.aspectRatio=`${t.width} / ${t.height}`),t.sources&&t.sources.length>0)for(const l of t.sources){const c=document.createElement("source");c.src=l.src,c.type=l.type,r.appendChild(c)}else r.src=t.src;this.swapIn(e,r,t,i);const a=()=>n(i);r.addEventListener("loadedmetadata",a,{once:!0}),r.addEventListener("error",a,{once:!0})}renderProviderVideo(t,e,i,n){const s=t.video,r=s.provider==="custom"?s.render:this.videoProviders.get(s.provider);if(!r){const g=document.createElement("div");g.className="shoji-slide-placeholder",g.textContent="Video",this.swapIn(e,g,t,i),n(i);return}t.poster&&Pe(e,t.poster);const a=document.createElement("div");a.className="shoji-slide-provider-video",a.hidden=!0;const l=new AbortController;Gt.set(a,l),e.media.appendChild(a);let c=!1;const f=()=>{c||l.signal.aborted||(c=!0,a.hidden=!1,e.media.querySelectorAll(".shoji-slide-spinner, .shoji-slide-open-placeholder, .shoji-slide-provider-poster").forEach(g=>g.remove()),this.applyAspect(e,t),e.ready=!0,this.cache.set(i,{node:a,item:t}),n(i))},y=g=>{t.poster||c||l.signal.aborted||Pe(e,g)};r(a,t,f,l.signal,y)}destroy(){for(const t of this.slots)Nt(t.media),t.media.replaceChildren(),t.assignedIndex=null,t.ready=!1;this.cache.clear(),this.pending.clear(),this.element.remove()}}function Pe(o,t){o.media.querySelectorAll(".shoji-slide-spinner, .shoji-slide-open-placeholder, .shoji-slide-provider-poster").forEach(i=>i.remove());const e=document.createElement("img");e.className="shoji-slide-img shoji-slide-provider-poster",e.alt="",e.draggable=!1,e.src=t,o.media.appendChild(e)}function ko(o){const t=document.createElement("img");return t.className="shoji-slide-img shoji-slide-open-placeholder",t.alt="",t.draggable=!1,t.src=o,t}function Do(){const o=document.createElement("div");return o.className="shoji-slide-spinner",o.setAttribute("aria-hidden","true"),o}const Gt=new WeakMap;function Nt(o){const t=o.querySelector("video");t&&Re(t);const e=o.querySelector(".shoji-slide-provider-video");e&&Ae(e)}function He(o){const t=o==null?void 0:o.querySelector("video");if(t){t.pause();return}const e=o==null?void 0:o.querySelector(".shoji-slide-provider-video");e&&typeof e.pause=="function"&&e.pause()}function Re(o){if(o.tagName!=="VIDEO"){Ae(o);return}const t=o;t.pause(),t.removeAttribute("src"),t.load()}function Ae(o){const t=Gt.get(o);t&&(Gt.delete(o),t.abort())}function Ie(o,t){const e=o.directional?t:1,i=[];o.perspective&&i.push(`perspective(${o.perspective}px)`);const n=o.translateX!==void 0?o.translateX*e:0,s=o.translateY??0;return(n!==0||s!==0)&&i.push(`translate(${n}%, ${s}%)`),o.rotateY!==void 0&&i.push(`rotateY(${o.rotateY*e}deg)`),o.rotateX!==void 0&&i.push(`rotateX(${o.rotateX}deg)`),o.rotateZ!==void 0&&i.push(`rotateZ(${o.rotateZ*e}deg)`),o.scale!==void 0&&i.push(`scale(${o.scale})`),{transform:i.length>0?i.join(" "):"none",opacity:o.opacity??1}}function Z(o){return{name:o.name,enter:t=>Ie(o.enter,t),leave:t=>Ie(o.leave,t)}}const Bo=[Z({name:"slide",enter:{directional:!0,translateX:100},leave:{directional:!0,translateX:-100}}),Z({name:"fade",enter:{opacity:0},leave:{opacity:0}}),Z({name:"zoom",enter:{scale:.6,opacity:0},leave:{scale:1.4,opacity:0}}),Z({name:"deck",enter:{translateY:6,scale:.85,opacity:0},leave:{translateY:-4,scale:.92,opacity:0}}),Z({name:"slideVertical",enter:{directional:!0,translateY:100},leave:{directional:!0,translateY:-100}}),Z({name:"push",enter:{directional:!0,translateX:120},leave:{directional:!0,translateX:-120}}),Z({name:"fadeUp",enter:{translateY:12,opacity:0},leave:{translateY:-12,opacity:0}}),Z({name:"fadeDown",enter:{translateY:-12,opacity:0},leave:{translateY:12,opacity:0}}),Z({name:"fadeLeft",enter:{translateX:-12,opacity:0},leave:{translateX:12,opacity:0}}),Z({name:"fadeRight",enter:{translateX:12,opacity:0},leave:{translateX:-12,opacity:0}}),Z({name:"zoomOut",enter:{scale:1.4,opacity:0},leave:{scale:.6,opacity:0}}),Z({name:"scaleUp",enter:{scale:.7},leave:{scale:1.3}}),Z({name:"scaleDown",enter:{scale:1.3},leave:{scale:.7}}),Z({name:"rotate",enter:{rotateZ:15,opacity:0},leave:{rotateZ:-15,opacity:0}}),Z({name:"rotateLeft",enter:{directional:!0,rotateZ:-25,opacity:0},leave:{directional:!0,rotateZ:25,opacity:0}}),Z({name:"rotateRight",enter:{directional:!0,rotateZ:25,opacity:0},leave:{directional:!0,rotateZ:-25,opacity:0}}),Z({name:"flipX",enter:{rotateX:90,perspective:1200,opacity:0},leave:{rotateX:-90,perspective:1200,opacity:0}}),Z({name:"flipY",enter:{directional:!0,rotateY:90,perspective:1200,opacity:0},leave:{directional:!0,rotateY:-90,perspective:1200,opacity:0}}),Z({name:"cube",enter:{directional:!0,rotateY:70,translateX:40,perspective:1600,opacity:1},leave:{directional:!0,rotateY:-70,translateX:-40,perspective:1600,opacity:1}}),Z({name:"coverflow",enter:{directional:!0,rotateY:35,translateX:60,scale:.8,perspective:1400,opacity:0},leave:{directional:!0,rotateY:-35,translateX:-60,scale:.8,perspective:1400,opacity:0}}),Z({name:"drop",enter:{translateY:-30,opacity:0},leave:{translateY:20,opacity:0}})],Fo=Object.fromEntries(Bo.map(o=>[o.name,o]));function No(){return typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}function ke(o){var e;const t=((e=o.split(",")[0])==null?void 0:e.trim())??"";return t.endsWith("ms")?parseFloat(t):t.endsWith("s")?parseFloat(t)*1e3:0}function De(o,t){const e=getComputedStyle(o),i=Math.max(ke(e.transitionDuration),ke(e.animationDuration));let n=!1;const s=()=>{n||(n=!0,o.removeEventListener("transitionend",r),o.removeEventListener("animationend",r),t())},r=a=>{a.target===o&&s()};o.addEventListener("transitionend",r),o.addEventListener("animationend",r),setTimeout(s,i+100)}function $o(o,t,e){o.style.transition="none",o.style.transformOrigin="center",o.style.transform=t,o.style.opacity=String(e),o.offsetHeight,o.style.transition="transform var(--shoji-duration) var(--shoji-easing), opacity var(--shoji-duration) var(--shoji-easing)",o.style.transform="none",o.style.opacity="1"}function Vo(o,t,e){o.style.transformOrigin="center",o.style.transition="transform var(--shoji-duration) var(--shoji-easing), opacity var(--shoji-duration) var(--shoji-easing)",o.offsetHeight,o.style.transform=t,o.style.opacity=String(e)}function Yo(o){o.style.transition="",o.style.transform="",o.style.opacity="",o.style.transformOrigin=""}class Wo{constructor(t,e=()=>()=>{}){this.slides=t,this.decorateLeave=e}animate(t,e,i){this.run(i,(n,s)=>{const r=t.leave(e);Vo(n,r.transform,r.opacity);const a=t.enter(e);$o(s,a.transform,a.opacity)})}animateCustom(t,e,i){const n=e===1?"next":"prev";this.run(i,(s,r)=>{s.dataset.shojiDirection=n,s.classList.add(`shoji-transition-${t}-leave`),r.dataset.shojiDirection=n,r.classList.add(`shoji-transition-${t}-enter`)},s=>{s.classList.remove(`shoji-transition-${t}-enter`),delete s.dataset.shojiDirection})}run(t,e,i=Yo){if(No()){t();return}const n=this.slides.getActiveMedia();if(!n){t();return}const s=document.createElement("div");s.className="shoji-slide-ghost";const r=s.appendChild(n.cloneNode(!0));this.slides.element.appendChild(s);const a=this.decorateLeave(r);s.offsetHeight,t();const l=this.slides.getActiveMedia();if(!l){s.remove();return}e(s,l),a(),De(s,()=>s.remove()),De(l,()=>i(l))}}function Ut(o){return o.id??o.src}function zo(o){if(typeof o!="string")return o;const t=document.querySelector(o);if(!t)throw new Error(`Shoji: no element matches selector "${o}"`);return t}const $t=new WeakMap,Kt=new Set,Be={close:"Close",previous:"Previous image",next:"Next image",showCaption:"Show caption",hideCaption:"Hide caption",fullCaption:"Full caption",moreControls:"More controls"};function _o(o,t){if(o.composedPath().some(i=>i instanceof Element&&i.matches(`.shoji-slide-img, .shoji-video-mount, iframe, .shoji-counter, ${wo}`)))return!1;if(t&&!t.hidden&&t.classList.contains("shoji-caption--video")){const i=t.getBoundingClientRect();if(o.clientX>=i.left&&o.clientX<=i.right&&o.clientY>=i.top&&o.clientY<=i.bottom)return!1}return!0}function Xo(o){return typeof o=="object"&&o!==null&&typeof o.dangerouslySetInnerHTML=="string"}class qo{constructor(t,e={}){p(this,"options",{});p(this,"element");p(this,"bus",new eo);p(this,"selector",Xt);p(this,"isDynamicMode",!1);p(this,"preload",1);p(this,"locale",Be);p(this,"showCounter",!0);p(this,"captionVisibleOnVideo",!1);p(this,"captionFadePending",!1);p(this,"loop",!0);p(this,"closable",!0);p(this,"autoHideDelay",5e3);p(this,"maxPinnedToolbarButtons",2);p(this,"focusTrap",new co);p(this,"liveRegion",new xo);p(this,"autoHideTimer",null);p(this,"autoHidden",!1);p(this,"hoverableElements",new Set);p(this,"hoveringElements",new Set);p(this,"isClosing",!1);p(this,"controlsHiddenByDrag",!1);p(this,"itemList",[]);p(this,"scannedElements",[]);p(this,"activeIndex",0);p(this,"opened",!1);p(this,"destroyed",!1);p(this,"slides",null);p(this,"dom",null);p(this,"gesture",null);p(this,"transition",null);p(this,"toolbarHeightObserver",null);p(this,"toolbarHeightFrame",null);p(this,"captionTruncationFrame",null);p(this,"captionModalOpen",!1);p(this,"captionModalReturnFocus",null);p(this,"captionModalOpenedViaKeyboard",!1);p(this,"pluginToolbarButtons",[]);p(this,"toolbarOverflowOpen",!1);p(this,"toolbarOverflowReturnFocus",null);p(this,"shortcuts",new Map);p(this,"pluginStorage",new Map);p(this,"activePluginNames",new Set);p(this,"videoProviders",new Map);p(this,"zoomGate",null);p(this,"zoomStartProvider",null);p(this,"slideLeaveDecorators",new Set);p(this,"pluginCleanups",[]);p(this,"onContainerClick",t=>{let e=t.target;for(;e&&e!==this.element;){if(e instanceof HTMLElement){const i=this.scannedElements.indexOf(e);if(i!==-1){t.preventDefault(),this.open(i);return}}e=e.parentNode}});p(this,"onOuterClick",t=>{var e;this.closable&&_o(t,((e=this.dom)==null?void 0:e.caption)??null)&&this.close()});p(this,"onActivity",()=>{this.reconcileHover(),!(this.autoHideDelay===0||this.autoHideDelay===!1||this.isClosing||this.controlsHiddenByDrag||this.captionModalOpen)&&(this.showControls(),this.scheduleAutoHide())});p(this,"controlsHiddenAtGestureStart",!1);p(this,"captureGestureStartState",()=>{this.controlsHiddenAtGestureStart=this.autoHidden});p(this,"onKeydown",t=>{if(!(document.activeElement instanceof HTMLVideoElement&&t.key!=="Escape")){switch(this.onActivity(),t.key){case"Escape":this.closable&&this.close();break;case"ArrowLeft":case"a":case"A":this.prev();break;case"ArrowRight":case"d":case"D":this.next();break;case"Home":this.goTo(0);break;case"End":this.goTo(this.itemList.length-1);break;default:{const e=this.shortcuts.get(t.key);if(!e)return;e(t)}}t.preventDefault()}});p(this,"onCaptionModalKeydown",t=>{t.stopPropagation(),t.key==="Escape"&&this.closeCaptionModal()});p(this,"onToolbarOverflowKeydown",t=>{t.stopPropagation(),t.key==="Escape"&&this.closeToolbarOverflow()});p(this,"onCaptionActivate",t=>{var e;if((e=this.dom)!=null&&e.caption.classList.contains("shoji-caption--truncated")){if(this.captionModalOpenedViaKeyboard=t instanceof KeyboardEvent,t instanceof KeyboardEvent){if(t.key!=="Enter"&&t.key!==" ")return;t.preventDefault(),t.stopPropagation()}else{const i=window.getSelection();if(i&&!i.isCollapsed||t.target instanceof Element&&t.target.closest("a, button"))return}this.openCaptionModal()}});this.element=zo(t),$t.set(this.element,this),Kt.add(this),this.applyOptions(e)}static getInstance(t){return $t.get(t)}static instances(){return Kt.values()}applyOptions(t){if(this.options=t,this.selector=t.selector??Xt,this.isDynamicMode=t.items!==void 0,this.preload=t.preload??1,this.locale={...Be,...t.locale},this.showCounter=t.counter??!0,this.loop=t.loop??!0,this.closable=t.closable??!0,this.autoHideDelay=t.autoHideDelay??5e3,this.maxPinnedToolbarButtons=t.maxPinnedToolbarButtons??2,this.activeIndex=0,this.scannedElements=[],this.isDynamicMode)this.itemList=je(t.items??[]);else{const e=we(this.element,this.selector);this.itemList=e.map(i=>i.item),this.scannedElements=e.map(i=>i.element),this.element.addEventListener("click",this.onContainerClick)}this.ensureLightbox(),this.dom.closeButton.hidden=!this.closable,t.openOnInit&&this.itemList.length>0&&this.open(t.index??0)}get items(){return this.itemList}get currentIndex(){return this.activeIndex}get isOpen(){return this.opened}get isDestroyed(){return this.destroyed}get controlsHidden(){return this.autoHidden}getActivePlugins(){return[...this.activePluginNames]}getActiveMedia(){var t;return((t=this.slides)==null?void 0:t.getActiveMedia())??null}registerZoomGate(t){return this.zoomGate=t,()=>{this.zoomGate===t&&(this.zoomGate=null)}}registerZoomStartProvider(t){return this.zoomStartProvider=t,()=>{this.zoomStartProvider===t&&(this.zoomStartProvider=null)}}registerSlideLeaveDecorator(t){return this.slideLeaveDecorators.add(t),()=>{this.slideLeaveDecorators.delete(t)}}on(t,e){return this.bus.on(t,e)}clampToRange(t){return Math.min(Math.max(t,0),Math.max(this.itemList.length-1,0))}ensureLightbox(){if(this.dom)return;this.slides=new Io({preload:this.preload,videoProviders:this.videoProviders}),this.transition=new Wo(this.slides,e=>{const i=[];for(const n of this.slideLeaveDecorators){const s=n(e);s&&i.push(s)}return()=>{for(const n of i)n()}});const t=ao(this.slides.element,this.locale);if(this.dom=t,this.options.backdropOpacity!=null){const e=Math.min(Math.max(this.options.backdropOpacity,0),1);t.outer.style.setProperty("--shoji-backdrop-opacity",String(e))}if(this.options.transitionDuration!=null){const e=Math.max(this.options.transitionDuration,0);t.outer.style.setProperty("--shoji-duration",`${e}ms`)}this.autoHideDelay===0&&t.dialog.classList.add("shoji-cursor-visible"),t.outer.appendChild(this.liveRegion.element),t.closeButton.addEventListener("click",()=>this.close()),t.prevButton.addEventListener("click",()=>this.prev()),t.nextButton.addEventListener("click",()=>this.next()),t.captionToggleButton.addEventListener("click",()=>{this.captionVisibleOnVideo=!this.captionVisibleOnVideo,this.updateCaptionVisibility()}),t.caption.addEventListener("click",this.onCaptionActivate),t.caption.addEventListener("keydown",this.onCaptionActivate),t.captionModalCloseButton.addEventListener("click",()=>this.closeCaptionModal()),t.captionModal.addEventListener("click",e=>{e.stopPropagation(),e.target===t.captionModal&&this.closeCaptionModal()}),t.toolbarOverflowButton.addEventListener("click",e=>{e.stopPropagation(),this.toggleToolbarOverflow()}),t.outer.addEventListener("click",e=>{!this.toolbarOverflowOpen||e.composedPath().some(n=>n===t.toolbarOverflowPanel||n===t.toolbarOverflowButton)||(e.stopPropagation(),this.closeToolbarOverflow())}),t.outer.addEventListener("click",this.onOuterClick),t.outer.addEventListener("pointermove",this.onActivity,{passive:!0}),t.outer.addEventListener("pointerdown",this.captureGestureStartState,{passive:!0}),t.outer.addEventListener("pointerdown",this.onActivity,{passive:!0}),t.outer.addEventListener("touchstart",this.onActivity,{passive:!0}),t.outer.addEventListener("wheel",this.onActivity,{passive:!0}),t.outer.addEventListener("focusin",this.onActivity),t.outer.addEventListener("focusout",()=>this.scheduleAutoHide());for(const e of[t.closeButton,t.prevButton,t.nextButton,t.captionToggleButton,t.caption,t.captionModalPanel,t.counter,t.toolbarLeft,t.toolbarCenter,t.toolbarRight])this.wireControlHover(e);document.body.appendChild(t.outer),this.toolbarHeightObserver=new ResizeObserver(()=>this.scheduleToolbarOverflowMeasure()),this.toolbarHeightObserver.observe(t.toolbar),this.gesture=new Lo({dialog:t.dialog,caption:t.caption,slides:this.slides,canGoNext:()=>this.loop||this.activeIndex<this.itemList.length-1,canGoPrev:()=>this.loop||this.activeIndex>0,next:()=>this.navigate(this.nextIndex(),1,!1),prev:()=>this.navigate(this.prevIndex(),-1,!1),close:()=>this.close(),closeFromSwipe:e=>this.closeFromSwipe(e),setControlsHiddenForDrag:e=>this.setControlsHiddenForDrag(e),canClose:()=>this.closable,onActivity:()=>this.onActivity(),isZoomed:()=>{var e;return(((e=this.zoomGate)==null?void 0:e.call(this))??!1)||this.captionModalOpen||this.toolbarOverflowOpen}},{onTap:(e,i)=>this.bus.emit("tap",{x:e,y:i,controlsWereHidden:this.controlsHiddenAtGestureStart}),onDoubleTap:(e,i)=>this.bus.emit("doubleTap",{x:e,y:i}),onPinchStart:(e,i)=>this.bus.emit("pinchStart",{centerX:e,centerY:i}),onPinchMove:(e,i,n)=>this.bus.emit("pinchMove",{scale:e,centerX:i,centerY:n}),onPinchEnd:()=>this.bus.emit("pinchEnd",{}),onWheelZoom:(e,i,n)=>this.bus.emit("wheelZoom",{deltaScale:e,x:i,y:n})},this.options.gestures),this.initPlugins()}resolveValidPluginNames(t){const e=new Set;for(const n of t)n&&typeof n.init=="function"&&e.add(n.name);let i=!0;for(;i;){i=!1;for(const n of t){if(!n||typeof n.init!="function"||!e.has(n.name))continue;(n.requires??[]).some(r=>!e.has(r))&&(e.delete(n.name),i=!0)}}return e}initPlugins(){this.activePluginNames.clear(),this.videoProviders.clear();const t=this.options.plugins??[],e=this.resolveValidPluginNames(t);for(const i of t){if(!i||typeof i.init!="function"){console.error("Shoji: skipping an invalid plugins[] entry (not a ShojiPlugin object):",i);continue}if(!e.has(i.name)){const a=(i.requires??[]).filter(l=>!e.has(l));console.error(`Shoji: plugin "${i.name}" requires [${a.join(", ")}], which failed to load (missing, invalid, or itself had an unmet requires) — skipping.`);continue}const n={...i.defaults,...this.options[i.name]},s={gallery:this,options:n,on:this.on.bind(this),emit:(a,l)=>this.bus.emit(a,l),ui:{toolbar:(a,l)=>this.pluginToolbar(a,l),overlay:(a,l)=>this.pluginOverlay(a,l),outer:()=>this.dom.outer,registerShortcut:(a,l)=>(this.shortcuts.set(a,l),()=>this.shortcuts.delete(a)),registerVideoProvider:(a,l)=>(this.videoProviders.set(a,l),()=>{this.videoProviders.get(a)===l&&this.videoProviders.delete(a)})},storage:{get:a=>this.pluginStorage.get(a),set:(a,l)=>{this.pluginStorage.set(a,l)}}},r=i.init(s);typeof r=="function"&&this.pluginCleanups.push(r),this.activePluginNames.add(i.name)}}pluginToolbar(t,e){const i=this.dom,n=e instanceof HTMLElement,s=n?e:this.buildToolbarButton(e),r=n?this.wireControlHover(s):null;return t==="right"?i.toolbarRight.insertBefore(s,i.toolbarOverflowButton):(t==="left"?i.toolbarLeft:i.toolbarCenter).appendChild(s),this.pluginToolbarButtons.push({el:s,slot:t}),this.scheduleToolbarOverflowMeasure(),()=>{r==null||r(),s.remove();const a=this.pluginToolbarButtons.findIndex(l=>l.el===s);a!==-1&&this.pluginToolbarButtons.splice(a,1),this.scheduleToolbarOverflowMeasure()}}buildToolbarButton(t){const e=document.createElement("button");return e.type="button",e.className="shoji-toolbar-button",t.icon?(e.ariaLabel=e.title=t.label,e.innerHTML=t.icon):e.textContent=t.label,e.addEventListener("click",t.onClick),this.wireControlHover(e),e}scheduleToolbarOverflowMeasure(){this.toolbarHeightFrame===null&&(this.toolbarHeightFrame=requestAnimationFrame(()=>{this.toolbarHeightFrame=null,this.dom&&(this.measureToolbarOverflow(),this.dom.dialog.style.setProperty("--shoji-toolbar-height",`${this.dom.toolbar.getBoundingClientRect().height}px`))}))}measureToolbarOverflow(){if(!this.dom)return;const t=this.dom;for(const{el:s,slot:r}of this.pluginToolbarButtons)r==="right"?t.toolbarRight.insertBefore(s,t.toolbarOverflowButton):(r==="left"?t.toolbarLeft:t.toolbarCenter).appendChild(s);t.toolbarOverflowPanel.replaceChildren(),t.toolbarOverflowButton.hidden=!0,this.toolbarOverflowOpen&&this.closeToolbarOverflow();const e=t.closeButton.getBoundingClientRect().height,i=()=>[t.toolbarLeft,t.toolbarCenter,t.toolbarRight].every(s=>s.getBoundingClientRect().height<=e+1);if(i())return;const n=Math.min(this.maxPinnedToolbarButtons,this.pluginToolbarButtons.length);t.toolbarOverflowButton.hidden=!1;for(let s=this.pluginToolbarButtons.length-1;s>=0&&!(s<n&&i());s--)t.toolbarOverflowPanel.insertBefore(this.pluginToolbarButtons[s].el,t.toolbarOverflowPanel.firstChild)}toggleToolbarOverflow(){this.toolbarOverflowOpen?this.closeToolbarOverflow():this.openToolbarOverflow()}openToolbarOverflow(){!this.dom||this.toolbarOverflowOpen||(this.toolbarOverflowReturnFocus=document.activeElement,this.dom.toolbarOverflowPanel.hidden=!1,this.positionToolbarOverflowPanel(),this.dom.toolbarOverflowButton.setAttribute("aria-expanded","true"),this.toolbarOverflowOpen=!0,this.focusTrap.retarget(this.dom.toolbarOverflowPanel),document.addEventListener("keydown",this.onToolbarOverflowKeydown,!0))}positionToolbarOverflowPanel(){if(!this.dom)return;const{dialog:t,toolbarOverflowButton:e,toolbarOverflowPanel:i,toolbarRight:n,captionToggleButton:s}=this.dom,r=t.getBoundingClientRect().right,a=e.getBoundingClientRect().right,l=parseFloat(getComputedStyle(i).paddingRight)||0,c=r-a-l;i.style.right=`${Math.max(0,c)}px`;const y=this.pluginToolbarButtons.filter(g=>g.slot==="right"&&g.el.parentElement===n&&!g.el.hidden).length+(s.hidden?0:1)+1;i.style.gridTemplateColumns=`repeat(${y}, 44px)`}closeToolbarOverflow(){var t;!this.dom||!this.toolbarOverflowOpen||(document.removeEventListener("keydown",this.onToolbarOverflowKeydown,!0),this.dom.toolbarOverflowPanel.hidden=!0,this.dom.toolbarOverflowButton.setAttribute("aria-expanded","false"),this.toolbarOverflowOpen=!1,this.focusTrap.retarget(this.dom.dialog),(t=this.toolbarOverflowReturnFocus)==null||t.focus({preventScroll:!0}),this.toolbarOverflowReturnFocus=null)}pluginOverlay(t,e){e!==void 0&&(t.style.zIndex=String(e)),this.dom.dialog.appendChild(t);const i=this.wireControlHover(t);return()=>{i(),t.remove()}}wireControlHover(t){this.hoverableElements.add(t);const e=()=>{this.hoveringElements.add(t),this.onActivity()},i=()=>{this.hoveringElements.delete(t)&&this.scheduleAutoHide()};return t.addEventListener("pointerenter",e),t.addEventListener("pointerleave",i),()=>{t.removeEventListener("pointerenter",e),t.removeEventListener("pointerleave",i),this.hoverableElements.delete(t),this.hoveringElements.delete(t)&&this.scheduleAutoHide()}}isControlActive(){return this.hoveringElements.size>0}reconcileHover(){for(const t of this.hoverableElements)t.matches(":hover")?this.hoveringElements.add(t):this.hoveringElements.delete(t)}getOriginElement(t){const e=this.itemList[t];if(e!=null&&e.id&&typeof CSS<"u"&&typeof CSS.escape=="function"){const i=document.querySelector(`[data-shoji-id="${CSS.escape(e.id)}"]`);if(i)return i}return this.scannedElements[t]??null}scheduleAutoHide(){if(this.autoHideTimer!==null&&(clearTimeout(this.autoHideTimer),this.autoHideTimer=null),!!this.opened&&this.autoHideDelay!==!1){if(this.autoHideDelay===0){this.hideControls();return}this.autoHideTimer=setTimeout(()=>this.hideControls(),this.autoHideDelay)}}hideControls(){this.reconcileHover(),!(!this.dom||this.autoHidden||this.isControlActive()||this.autoHideDelay===!1||this.captionModalOpen||this.toolbarOverflowOpen)&&(this.autoHidden=!0,this.dom.dialog.classList.add("shoji-controls-hidden"),this.bus.emit("controls:hide",{}))}showControls(){!this.dom||!this.autoHidden||(this.autoHidden=!1,this.dom.dialog.classList.remove("shoji-controls-hidden","shoji-controls-hidden-for-close"),this.bus.emit("controls:show",{}))}renderCaption(t,e){return e instanceof HTMLElement?(t.replaceChildren(e),!1):Xo(e)?(t.innerHTML=e.dangerouslySetInnerHTML,e.dangerouslySetInnerHTML===""):(t.textContent=e??"",!e)}setSlideLoading(t){if(this.dom){this.dom.outer.classList.toggle("shoji-slide-loading",t);for(const e of this.dom.outer.querySelectorAll(".shoji-toolbar-button"))e.ariaDisabled=t?"true":null,t?e.tabIndex=-1:e.removeAttribute("tabindex")}}transitionCaption(){var s;const t=this.dom;if(!t||typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches)return;const e=((s=getComputedStyle(t.caption).transitionDuration.split(",")[0])==null?void 0:s.trim())??"",n=(e.endsWith("ms")?parseFloat(e):e.endsWith("s")?parseFloat(e)*1e3:0)/2;this.captionFadePending=!0,t.caption.style.transitionDuration=`${n}ms`,t.caption.style.opacity="0",setTimeout(()=>{this.dom&&(this.captionFadePending=!1,this.updateCaptionVisibility(),this.dom.caption.style.opacity="",setTimeout(()=>{this.dom&&(this.dom.caption.style.transitionDuration="")},n))},n)}updateCaptionVisibility(){if(!this.dom||!this.slides)return;const t=this.itemList[this.activeIndex],e=this.renderCaption(this.dom.caption,t==null?void 0:t.caption),i=!!(t!=null&&t.video);this.dom.caption.classList.toggle("shoji-caption--video",i);const n=i&&!this.captionVisibleOnVideo;this.dom.caption.hidden=e||!this.slides.isActiveReady()||n;const s=this.dom.captionToggleButton;s.hidden=!i||e,s.hidden||(s.setAttribute("aria-pressed",String(this.captionVisibleOnVideo)),s.ariaLabel=s.title=this.captionVisibleOnVideo?this.locale.hideCaption:this.locale.showCaption),this.updateCaptionTruncation(),this.captionTruncationFrame!==null&&cancelAnimationFrame(this.captionTruncationFrame),this.captionTruncationFrame=requestAnimationFrame(()=>{this.captionTruncationFrame=null,this.updateCaptionTruncation()})}updateCaptionTruncation(){if(!this.dom)return;const t=this.dom.caption;t.style.removeProperty("max-height");const e=!t.hidden&&t.scrollHeight>t.clientHeight;if(e){const i=parseFloat(getComputedStyle(t).paddingBottom)||0,n=t.clientHeight-i,s=t.getBoundingClientRect().top,r=document.createRange();r.selectNodeContents(t);let a=0,l=1/0;for(const g of r.getClientRects()){if(g.height===0)continue;const v=g.top-s,b=g.bottom-s;b<=n?b>a&&(a=b):v<l&&(l=v)}const f=(a>0?a:n)+i,y=Number.isFinite(l)?Math.min(f,l):f;t.style.maxHeight=`${Math.max(0,Math.floor(y)-1)}px`}t.classList.toggle("shoji-caption--truncated",e),e?(t.tabIndex=0,t.setAttribute("role","button"),t.setAttribute("aria-haspopup","dialog")):(t.removeAttribute("tabindex"),t.removeAttribute("role"),t.removeAttribute("aria-haspopup"),this.captionModalOpen&&this.closeCaptionModal())}openCaptionModal(){if(!this.dom||this.captionModalOpen)return;const t=this.itemList[this.activeIndex];this.renderCaption(this.dom.captionModalContent,t==null?void 0:t.caption),this.dom.captionModal.hidden=!1,this.captionModalReturnFocus=document.activeElement,this.dom.caption.hidden=!0,this.hoveringElements.clear(),this.captionModalOpen=!0,this.focusTrap.retarget(this.dom.captionModalPanel),document.addEventListener("keydown",this.onCaptionModalKeydown,!0),this.bus.emit("captionModalChange",{open:!0})}closeCaptionModal(){var t;!this.dom||!this.captionModalOpen||(document.removeEventListener("keydown",this.onCaptionModalKeydown,!0),this.dom.captionModal.hidden=!0,this.captionModalOpen=!1,this.updateCaptionVisibility(),this.focusTrap.retarget(this.dom.dialog),this.captionModalOpenedViaKeyboard&&((t=this.captionModalReturnFocus)==null||t.focus({preventScroll:!0})),this.captionModalReturnFocus=null,this.captionModalOpenedViaKeyboard=!1,this.onActivity(),this.bus.emit("captionModalChange",{open:!1}))}renderCurrentSlide(t){if(!this.slides||!this.dom)return;const e=this.dom;this.slides.render(this.itemList,this.activeIndex,r=>{r===this.activeIndex&&(this.bus.emit("slideItemLoad",{index:r}),this.setSlideLoading(!1),this.captionFadePending||this.updateCaptionVisibility())},t,this.loop),this.setSlideLoading(!this.slides.isActiveReady());const i=this.itemList[this.activeIndex],n=this.itemList.length;e.counter.textContent=n>0?`${this.activeIndex+1} / ${n}`:"",e.counter.hidden=!this.showCounter||n===0,this.captionFadePending||this.updateCaptionVisibility();const s=`Image ${this.activeIndex+1} of ${n}${i!=null&&i.alt?`: ${i.alt}`:""}`;this.liveRegion.announce(s),e.prevButton.hidden=n<=1,e.nextButton.hidden=n<=1,e.prevButton.disabled=!this.loop&&this.activeIndex<=0,e.nextButton.disabled=!this.loop&&this.activeIndex>=n-1}open(t=this.options.index??0){var r,a;if(this.destroyed||this.opened)return;this.bus.emit("beforeOpen",{index:t}),this.ensureLightbox(),this.opened=!0,this.activeIndex=t,this.captionVisibleOnVideo=!!this.options.showVideoCaption,Qe();const e=this.getOriginElement(t),i=this.resolveNaturalSize(t),n=!!(e&&i)&&!(typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches);n&&this.dom&&(this.captionFadePending=!0,this.dom.caption.style.opacity="0"),this.renderCurrentSlide(i&&!((r=this.itemList[t])!=null&&r.video)?this.resolveOpenPlaceholderSrc(this.itemList[t],e):void 0),this.dom.outer.classList.add("shoji-open"),document.addEventListener("keydown",this.onKeydown),this.focusTrap.activate(this.dom.dialog),this.scheduleAutoHide();const s=(a=this.slides)==null?void 0:a.getActiveMedia();s&&e&&i&&go({origin:e,target:s,aspectRatio:this.resolveAspectRatio(t,e),naturalSize:i}),n&&this.dom&&(this.captionFadePending=!1,this.updateCaptionVisibility(),this.dom.caption.style.opacity=""),this.bus.emit("open",{index:t}),this.bus.emit("afterOpen",{index:t})}resolveOpenPlaceholderSrc(t,e){if(t!=null&&t.thumb)return t.thumb;const i=e==null?void 0:e.getAttribute("data-shoji-thumb");if(i)return i;const n=e==null?void 0:e.querySelector("img");return(n==null?void 0:n.currentSrc)||(n==null?void 0:n.src)||void 0}goTo(t,e){if(this.destroyed||!this.opened||this.itemList.length===0)return;const i=this.clampToRange(t);if(i===this.activeIndex)return;const n=i>this.activeIndex?1:-1;this.navigate(i,n,(e==null?void 0:e.animate)??!0)}next(){this.navigate(this.nextIndex(),1,!0)}prev(){this.navigate(this.prevIndex(),-1,!0)}nextIndex(){return this.activeIndex>=this.itemList.length-1&&this.loop?0:this.activeIndex+1}prevIndex(){return this.activeIndex<=0&&this.loop?this.itemList.length-1:this.activeIndex-1}navigate(t,e,i){var r;if(this.destroyed||!this.opened||this.itemList.length===0)return;const n=this.clampToRange(t);if(n===this.activeIndex)return;this.captionModalOpen&&this.closeCaptionModal(),this.toolbarOverflowOpen&&this.closeToolbarOverflow();const s=this.activeIndex;if(this.bus.emit("beforeSlide",{from:s,to:n}),He(((r=this.slides)==null?void 0:r.getActiveMedia())??null),this.activeIndex=n,i&&this.transition){this.transitionCaption();const a=()=>this.renderCurrentSlide(),l=this.resolveTransitionMode(),c=Fo[l];c?this.transition.animate(c,e,a):this.transition.animateCustom(l,e,a)}else this.renderCurrentSlide();this.bus.emit("afterSlide",{from:s,to:n})}resolveTransitionMode(){return this.options.mode??"slide"}close(){this.beginClose()}closeFromSwipe(t){this.beginClose(t)}beginClose(t){var r,a,l;if(this.destroyed||!this.opened||this.isClosing)return;this.captionModalOpen&&this.closeCaptionModal(),this.toolbarOverflowOpen&&this.closeToolbarOverflow();const e=((r=this.zoomStartProvider)==null?void 0:r.call(this))??void 0;this.bus.emit("beforeClose",{}),this.isClosing=!0;const i=(a=this.slides)==null?void 0:a.getActiveMedia();He(i??null);const n=this.getOriginElement(this.activeIndex),s=this.resolveNaturalSize(this.activeIndex);if(i&&n&&((l=this.slides)!=null&&l.isActiveReady()||s)){const c=this.resolveAspectRatio(this.activeIndex,n);this.forceHideControls(),this.dom&&(this.dom.backdrop.style.opacity="0"),vo({origin:n,target:i,aspectRatio:c,naturalSize:s,dragStart:t,zoomStart:e},()=>this.finishClose())}else this.finishClose()}forceHideControls(){!this.dom||this.autoHidden||(this.autoHidden=!0,this.dom.dialog.classList.add("shoji-controls-hidden","shoji-controls-hidden-for-close"),this.bus.emit("controls:hide",{}))}setControlsHiddenForDrag(t){var e;this.controlsHiddenByDrag=t,t?this.forceHideControls():this.controlsHiddenAtGestureStart||this.showControls(),(e=this.dom)==null||e.dialog.classList.toggle("shoji-controls-hidden-for-drag",t),this.bus.emit("dragCloseThreshold",{hidden:t})}resolveAspectRatio(t,e){const i=this.itemList[t];if(i!=null&&i.width&&i.height)return i.width/i.height;const n=e==null?void 0:e.querySelector("img");if(n!=null&&n.naturalWidth&&n.naturalHeight)return n.naturalWidth/n.naturalHeight}resolveNaturalSize(t){const e=this.itemList[t];return e!=null&&e.width&&e.height?{width:e.width,height:e.height}:void 0}finishClose(){var t,e,i;this.opened&&(this.isClosing=!1,this.opened=!1,to(),document.removeEventListener("keydown",this.onKeydown),this.focusTrap.deactivate(),(t=this.dom)==null||t.outer.classList.remove("shoji-open"),this.dom&&(this.dom.backdrop.style.opacity=""),this.autoHideTimer!==null&&(clearTimeout(this.autoHideTimer),this.autoHideTimer=null),this.autoHidden=!1,this.hoveringElements.clear(),this.controlsHiddenByDrag=!1,(e=this.dom)==null||e.dialog.classList.remove("shoji-controls-hidden","shoji-controls-hidden-for-close"),(i=this.dom)==null||i.dialog.classList.remove("shoji-controls-hidden-for-drag"),this.bus.emit("close",{}),this.bus.emit("afterClose",{}))}updateSlides(t,e){if(this.destroyed)return;const i=this.itemList[this.activeIndex],n=i?Ut(i):void 0;this.itemList=je(t);let s=e;if(s===void 0&&n!==void 0){const r=t.findIndex(a=>Ut(a)===n);r!==-1&&(s=r)}this.activeIndex=Math.min(Math.max(s??this.activeIndex,0),Math.max(t.length-1,0)),this.opened&&this.renderCurrentSlide(),this.bus.emit("itemsUpdated",{items:this.itemList})}addSlides(t,e){if(this.destroyed)return;const i=[...this.itemList];i.splice(e??i.length,0,...t),this.updateSlides(i)}removeSlides(t){if(this.destroyed)return;const e=Array.isArray(t)?t:[t],i=new Set(e.filter(r=>typeof r=="number")),n=new Set(e.filter(r=>typeof r=="string")),s=this.itemList.filter((r,a)=>!i.has(a)&&!n.has(Ut(r)));this.updateSlides(s)}refresh(){if(this.destroyed)return;if(this.isDynamicMode){console.warn("Shoji: refresh() is a no-op in dynamic mode — call updateSlides() instead.");return}const t=we(this.element,this.selector);this.scannedElements=t.map(e=>e.element),this.updateSlides(t.map(e=>e.item))}teardown(){var t,e,i,n;this.opened&&(this.captionModalOpen&&this.closeCaptionModal(),this.toolbarOverflowOpen&&this.closeToolbarOverflow(),this.isClosing||this.bus.emit("beforeClose",{}),this.finishClose());for(const s of this.pluginCleanups)s();this.pluginCleanups=[],this.shortcuts.clear(),this.pluginStorage.clear(),this.activePluginNames.clear(),this.videoProviders.clear(),this.isDynamicMode||this.element.removeEventListener("click",this.onContainerClick),(t=this.gesture)==null||t.destroy(),this.gesture=null,this.transition=null,(e=this.toolbarHeightObserver)==null||e.disconnect(),this.toolbarHeightObserver=null,this.toolbarHeightFrame!==null&&cancelAnimationFrame(this.toolbarHeightFrame),this.toolbarHeightFrame=null,this.captionTruncationFrame!==null&&cancelAnimationFrame(this.captionTruncationFrame),this.captionTruncationFrame=null,this.captionFadePending=!1,(i=this.slides)==null||i.destroy(),(n=this.dom)==null||n.outer.remove(),this.slides=null,this.dom=null,this.hoverableElements.clear(),this.hoveringElements.clear(),this.pluginToolbarButtons.length=0}destroy(){this.destroyed||($t.get(this.element)===this&&$t.delete(this.element),Kt.delete(this),this.teardown(),this.bus.emit("destroy",{}),this.bus.clear(),this.destroyed=!0)}reinit(t=this.options){this.destroyed||(this.teardown(),this.bus.clear(),this.applyOptions(t))}}function Zo(){return typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}const Go={name:"activeThumbnail",defaults:{activeClass:"shoji-thumb-active",scrollIntoView:!0},init(o){const{gallery:t}=o,e=String(o.options.activeClass??"shoji-thumb-active"),i=o.options.scrollIntoView!==!1;let n=null,s=null,r=null;function a(){r!==null&&(clearTimeout(r),r=null)}function l(E){const T=t.getOriginElement(E);return n&&n!==T&&n.classList.remove(e),T&&T.classList.add(e),n=T,T}function c(E){s=E,a();const T=l(E);T&&i&&(r=setTimeout(()=>{r=null;try{Ge(),T.scrollIntoView({block:"nearest",inline:"nearest",behavior:Zo()?"auto":"smooth"})}catch{}},80))}function f(){a(),n==null||n.classList.remove(e),n=null,s=null}const y=o.on("afterOpen",({index:E})=>c(E)),g=o.on("afterSlide",({to:E})=>c(E)),v=o.on("close",f),b=o.on("layoutRender",()=>{s!==null&&l(s)});return()=>{y(),g(),v(),b(),f()}}},Fe='<svg viewBox="0 0 24 24" width="24" height="24" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>',Uo='<svg viewBox="0 0 24 24" width="24" height="24" fill="currentColor"><path d="M7 5h4v14H7zM13 5h4v14h-4z"/></svg>';function Ko(o){const t=o==null?void 0:o.querySelector("video");if(t)return t;const e=o==null?void 0:o.querySelector(".shoji-slide-provider-video");return e&&typeof e.play=="function"?e:null}function Jo(o){const t=o==null?void 0:o.querySelector(".shoji-slide-provider-video");return!!t&&typeof t.play!="function"}const Ne=400,Qo=8,ti={name:"autoplay",defaults:{interval:5e3,showProgress:!0,pauseOnZoom:!0,pauseOnRotateFlip:!0,pauseOnCaptionExpand:!0,pauseOnManualNavigate:!0},init(o){const{gallery:t}=o,e=Number(o.options.interval??5e3),i=o.options.showProgress!==!1,n=o.options.autoStart===!0,s=o.options.pauseOnZoom!==!1,r=o.options.pauseOnRotateFlip!==!1,a=o.options.pauseOnCaptionExpand!==!1,l=o.options.pauseOnManualNavigate!==!1,c=o.options.locale,f=(c==null?void 0:c.play)??"Play slideshow",y=(c==null?void 0:c.pause)??"Pause slideshow";let g=!1,v=null,b=null,E=!1,T=!1,M=!1,C=!1,R=!1;const V=o.ui.outer();function N(d){if(!g)return;const u=t.getActiveMedia();u&&d.target instanceof Node&&u.contains(d.target)&&j()}V.addEventListener("error",N);const P=document.createElement("button");P.type="button",P.className="shoji-toolbar-button shoji-autoplay-toggle",P.setAttribute("aria-label",f),P.title=f,P.innerHTML=Fe;const $=document.createElement("div");$.className="shoji-autoplay-progress",$.hidden=!0;const k=document.createElement("div");k.className="shoji-autoplay-progress-bar",$.appendChild(k);function et(){v!==null&&(clearTimeout(v),v=null)}function pt(){i&&($.hidden=!0,k.style.transition="none",k.style.width="0%")}function dt(d){i&&($.hidden=!1,k.style.transition="none",k.style.width="0%",k.offsetWidth,k.style.transition=`width ${d}ms linear`,k.style.width="100%")}function D(){const d=!g&&(s&&M||r&&C);P.ariaDisabled=d?"true":null,d?P.tabIndex=-1:P.removeAttribute("tabindex")}function Y(d){g=d,P.innerHTML=d?Uo:Fe,P.setAttribute("aria-label",d?y:f),P.title=d?y:f,D()}function H(){g&&j()}function ut(){b!=null&&b.ended||X()}function at(){b&&(b.removeEventListener("ended",H),b.removeEventListener("pause",ut),b=null)}function vt(d,u){d.muted=!0;const m=d.play();m&&typeof m.then=="function"?Ct(d,u,m):yt(d,u)}function yt(d,u){setTimeout(()=>{b!==d||!g||d.paused&&(u>0?vt(d,u-1):j())},Ne)}function Ct(d,u,m){m.catch(()=>{}),setTimeout(()=>{b!==d||!g||d.paused&&(u>0?Ct(d,u-1,m):j())},Ne)}function I(){if(et(),at(),pt(),E=!1,!g)return;const d=t.getActiveMedia(),u=Ko(d);if(u){if(b=u,u.addEventListener("ended",H),u.addEventListener("pause",ut),u instanceof HTMLVideoElement){const m=u.play();m&&typeof m.catch=="function"&&m.catch(L=>{b!==u||!g||(L instanceof DOMException&&L.name==="NotAllowedError"?X():j())})}else vt(u,Qo);return}E=Jo(d),dt(e),v=setTimeout(j,e)}function j(){const d=t.currentIndex;R=!0,t.next(),R=!1,t.currentIndex===d&&X()}function B(){g||(Y(!0),o.emit("autoplayStart",{}),I())}function X(){g&&(Y(!1),et(),pt(),b&&!b.paused&&b.pause(),at(),o.emit("autoplayStop",{}))}function ht(){(s&&M||r&&C)&&X()}function nt(){if(g){X();return}B(),ht()}const jt=o.on("dragCloseThreshold",({hidden:d})=>{d?(T=g,g&&X()):T&&(T=!1,B())}),Pt=1.001,St=o.on("zoomChange",({scale:d})=>{M=d>Pt,s&&M&&g?X():D()}),Tt=o.on("rotateFlipChange",({flipH:d,flipV:u,rotation:m})=>{C=d||u||m!==0,r&&g?X():D()}),bt=o.on("captionModalChange",({open:d})=>{a&&d&&g&&X()});P.addEventListener("click",nt);const ft=o.ui.toolbar("right",P),st=i?o.ui.overlay($):null,Dt=o.ui.registerShortcut(" ",nt),Mt=o.on("beforeSlide",()=>{at()}),Lt=o.on("afterSlide",()=>{M=!1,C=!1,D(),g&&(l&&!R?X():I())}),mt=o.on("slideItemLoad",({index:d})=>{g&&E&&d===t.currentIndex&&I()}),Bt=o.on("requestAutoplayPause",()=>{g&&X()}),Ht=o.on("requestAutoplayStart",()=>{g||(B(),ht())}),wt=o.on("close",()=>X()),Et=o.on("afterOpen",()=>{M=!1,C=!1,D(),n&&B()});return()=>{X(),V.removeEventListener("error",N),ft(),st==null||st(),Dt(),Mt(),Lt(),mt(),Et(),wt(),jt(),St(),Tt(),bt(),Bt(),Ht()}}},$e='<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/></svg>',ei='<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 4v5H4M15 4v5h5M9 20v-5H4M15 20v-5h5"/></svg>';function oi(){return!!(document.fullscreenEnabled||document.webkitFullscreenEnabled)}function ii(){return document.fullscreenElement??document.webkitFullscreenElement??null}function ni(o){var e;const t=o;t.requestFullscreen?t.requestFullscreen().catch(()=>{}):(e=t.webkitRequestFullscreen)==null||e.call(t)}function Jt(){var t;const o=document;document.exitFullscreen?document.exitFullscreen().catch(()=>{}):(t=o.webkitExitFullscreen)==null||t.call(o)}const si={name:"fullscreen",init(o){if(!oi())return;const t=o.ui.outer(),e=o.gallery.options.locale??{},i=e.enterFullscreen??"Enter fullscreen",n=e.exitFullscreen??"Exit fullscreen",s=document.createElement("button");s.type="button",s.className="shoji-toolbar-button",s.innerHTML=$e,s.setAttribute("aria-label",i),s.title=i,s.setAttribute("aria-pressed","false");function r(){return ii()===t}function a(v){s.innerHTML=v?ei:$e,s.setAttribute("aria-label",v?n:i),s.title=v?n:i,s.setAttribute("aria-pressed",String(v))}function l(){r()?Jt():ni(t)}s.addEventListener("click",l);const c=()=>{const v=r();a(v),o.emit("fullscreenChange",{fullscreen:v})};document.addEventListener("fullscreenchange",c),document.addEventListener("webkitfullscreenchange",c);const f=o.ui.toolbar("right",s),y=o.on("close",()=>{r()&&Jt()}),g=o.on("requestFullscreenToggle",l);return()=>{document.removeEventListener("fullscreenchange",c),document.removeEventListener("webkitfullscreenchange",c),f(),y(),g(),r()&&Jt()}}};function ri(o){const{containerWidth:t,gutterX:e,columns:i}=o;if(typeof i=="number")return Math.max(1,Math.floor(i));const n=Math.max(1,Math.floor((t+e)/(o.columnWidth+e))),s=Math.max(1,Math.floor((t+e)/(o.minColumnWidth+e))),r=Math.max(1,Math.ceil((t+e)/(o.maxColumnWidth+e)));return Math.max(r,Math.min(n,s))}function ai(o,t,e){return(o-t*(e-1))/e}function Ve(o,t,e){const i=ri(t),n=ai(t.containerWidth,t.gutterX,i),s=e&&e.length===i?[...e]:new Array(i).fill(0),r=o.map((l,c)=>{const f=t.fill==="ordered"?c%i:li(s),y=l.width>0?n*(l.height/l.width):n,g=f*(n+t.gutterX),v=s[f];return s[f]=v+y+t.gutterY,{x:g,y:v,width:n,height:y}}),a=o.length===0?0:Math.max(...s)-t.gutterY;return{positions:r,columnCount:i,columnWidth:n,columnHeights:s,containerHeight:a}}function li(o){let t=0;for(let e=1;e<o.length;e++)o[e]<o[t]&&(t=e);return t}function ci(o,t){const{containerWidth:e,gutterX:i,gutterY:n,rowHeight:s}=t,r=new Array(o.length);let a=0,l=0,c=0,f=0;function y(b){return b.height>0?s*(b.width/b.height):s}function g(b,E){let T=0;for(let M=b;M<E;M++){const C=y(o[M]);r[M]={x:T,y:a,width:C,height:s},T+=C+i}f++,a+=s+n}for(let b=0;b<o.length;b++){const E=y(o[b]),T=b-l,M=c+(T>0?i:0)+E;T>0&&M>e?(g(l,b),l=b,c=E):c=M}l<o.length&&g(l,o.length);const v=o.length===0?0:a-n;return{positions:r,rowCount:f,containerHeight:v}}function kt(o){return o.width>0&&o.height>0?o.width/o.height:1}function Vt(o,t){const{containerWidth:e,gutterX:i,gutterY:n,rowHeight:s,minRowHeight:r,maxRowHeight:a,lastRow:l}=t,c=new Array(o.length).fill(null),f=[];let y=0,g=0,v=0;function b(C,R,V){return(e-i*(R-C-1))/V}function E(C,R,V){let N=0;for(let P=C;P<R;P++){const $=V*kt(o[P]);c[P]={x:N,y,width:$,height:V},N+=$+i}f.push({start:C,end:R,y,height:V}),y+=V+n}function T(C,R,V){let N=R,P=V,$=!1;for(;N-C>1&&b(C,N,P)<r;){if(N-C===2&&b(C,C+1,kt(o[C]))>a){$=!0;break}N--,P-=kt(o[N])}const k=b(C,N,P),et=(N-C===1||$)&&k<r?k:Math.min(Math.max(k,r),a);return E(C,N,et),N}for(let C=0;C<o.length;C++){v+=kt(o[C]);const R=C-g+1;if(s*v+i*(R-1)>=e){const N=T(g,C+1,v);g=N,v=0;for(let P=N;P<=C;P++)v+=kt(o[P])}}if(g<o.length)if(l==="justify"){let C=g;for(;C<o.length;){let R=0;for(let V=C;V<o.length;V++)R+=kt(o[V]);C=T(C,o.length,R)}}else l==="left"&&E(g,o.length,s);const M=o.length===0?0:Math.max(0,y-n);return{positions:c,containerHeight:M,rows:f}}const di={width:4,height:3};function Ye(o){if(o&&typeof o=="object"){const e=o;return{x:Number(e.x??8),y:Number(e.y??8)}}const t=Number(o??8);return{x:t,y:t}}function We(o){return o.id??o.src}function hi(o,t){if(t.length<=o.length)return!1;for(let e=0;e<o.length;e++)if(We(o[e])!==We(t[e]))return!1;return!0}const ui={name:"layout",defaults:{type:"justified",gutter:8,columns:"auto",columnWidth:240,minColumnWidth:160,maxColumnWidth:480,fill:"shortest",animate:!0,autoMeasure:!0},init(o){const{gallery:t}=o,e=o.options.type??"justified",i=Ye(o.options.gutter),n=Number(o.options.aspectRatio??1),s=o.options.orientation??"vertical",r=o.options.columns??"auto",a=Number(o.options.columnWidth??240),l=Number(o.options.minColumnWidth??160),c=Number(o.options.maxColumnWidth??480),f=o.options.fill??"shortest",y=Number(o.options.rowHeight??220),g=Number(o.options.minRowHeight??120),v=Number(o.options.maxRowHeight??360),b=o.options.lastRow??"justify",E=o.options.animate!==!1,T=o.options.autoMeasure!==!1,M=e==="masonry"&&s==="horizontal",C=o.options.groupBy,R=o.options.renderHeading,V=o.options.headingOverflow??"show",N=o.options.stickyHeadings===!0,P=N&&e==="grid";N&&e!=="grid"&&console.warn("Shoji: layout plugin — stickyHeadings is only implemented for type: 'grid'; ignored (see the option's doc comment)."),C&&M&&console.warn("Shoji: layout plugin — groupBy isn't supported with orientation: 'horizontal'; ignored.");const $=!!C&&!M,k={gutter:i,columns:r,columnWidth:a,minColumnWidth:l,maxColumnWidth:c,fill:f,rowHeight:y,minRowHeight:g,maxRowHeight:v,lastRow:b},et=o.options.breakpoints,pt=et?Object.entries(et).map(([d,u])=>[Number(d),u]).sort((d,u)=>d[0]-u[0]):[];function dt(d){const u=pt.find(([L])=>d<=L);if(!u)return k;const m=u[1];return{gutter:m.gutter!==void 0?Ye(m.gutter):k.gutter,columns:m.columns??k.columns,columnWidth:m.columnWidth??k.columnWidth,minColumnWidth:m.minColumnWidth??k.minColumnWidth,maxColumnWidth:m.maxColumnWidth??k.maxColumnWidth,fill:m.fill??k.fill,rowHeight:m.rowHeight??k.rowHeight,minRowHeight:m.minRowHeight??k.minRowHeight,maxRowHeight:m.maxRowHeight??k.maxRowHeight,lastRow:m.lastRow??k.lastRow}}const D=t.element;D.classList.add("shoji-layout",`shoji-layout--${e}`),E&&D.classList.add("shoji-layout--animate");let Y=[],H=[],ut,at=[],vt=!1;const yt=new WeakMap;function Ct(d){const u=[];for(let m=0;m<d.length;m++){const L=C(d[m]),F=u[u.length-1];!F||F.key!==L?u.push({key:L,startIndex:m,endIndex:m+1}):F.endIndex=m+1}return u}function I(d,u){const m=R?R(d,u):d;let L,F=null;if(typeof m=="string")L=document.createElement("h2"),L.textContent=m;else if(m instanceof HTMLElement)L=m;else{L=document.createElement("h2");const z=document.createElement("span");z.className="shoji-layout-heading-title",z.textContent=m.title,L.appendChild(z);let h=null;m.subtitle&&(h=document.createElement("span"),h.className="shoji-layout-heading-subtitle",h.textContent=m.subtitle,L.appendChild(h)),F={titleEl:z,subtitleEl:h}}return L.classList.add("shoji-layout-heading"),P&&L.classList.add("shoji-layout-heading--sticky"),{root:L,structured:F}}function j(){return H.map((d,u)=>({heading:d,start:d.tileStart,end:u+1<H.length?H[u+1].tileStart:Y.length}))}function B(d){return d.thumb??d.poster??(d.video?void 0:d.src)}function X(d){if(d!=null&&d.width&&d.height)return{width:d.width,height:d.height};const u=d&&yt.get(d);if(u)return u;const m=T&&!!d&&!!B(d);return!vt&&!m&&(vt=!0,console.warn(T?"Shoji: layout plugin — item(s) missing width/height with no measurable thumb/poster/src to auto-measure from either; falling back to a 4:3 placeholder ratio permanently for those.":"Shoji: layout plugin — item(s) missing width/height and autoMeasure is disabled. Masonry/justified positions are computed from aspect ratios up front, never by measuring loaded images (DESIGN.md §5.2 — that causes layout-jump), so items without dimensions fall back to a 4:3 placeholder ratio instead.")),di}function ht(d,u){const m=document.createElement("a");m.className="shoji-layout-tile",d.id&&(m.dataset.shojiId=d.id),m.dataset.shojiIndex=String(u);const L=document.createElement("img");L.src=d.thumb??d.poster??d.src,L.loading="lazy",L.alt=d.alt??"",m.appendChild(L);const F={index:u,root:m,img:L};return m.addEventListener("click",z=>{z.preventDefault(),t.open(F.index)}),F}function nt(d){const u=D.getBoundingClientRect().width,m=dt(u);D.style.setProperty("--shoji-layout-column-width",`${m.columnWidth}px`),D.style.setProperty("--shoji-layout-gutter",`${m.gutter.y}px ${m.gutter.x}px`);for(const L of d)L.root.style.setProperty("--shoji-layout-tile-aspect",`${n}`)}function jt(d){const u=D.getBoundingClientRect().width;if(u<=0)return;const m=dt(u),L={containerWidth:u,gutterX:m.gutter.x,gutterY:m.gutter.y,columns:m.columns,columnWidth:m.columnWidth,minColumnWidth:m.minColumnWidth,maxColumnWidth:m.maxColumnWidth,fill:m.fill};if($&&H.length>0){const O=j(),G=O.map(ot=>ot.heading.root.getBoundingClientRect().height);let Q=0;O.forEach(({heading:ot,start:rt,end:S},x)=>{const A=Y.slice(rt,S);ot.root.style.transform=`translate(0px, ${Q}px)`,Q+=G[x]+m.gutter.y;const _=Ve(A.map(W=>X(t.items[W.index])),L);A.forEach((W,U)=>{const J=_.positions[U];W.root.style.width=`${J.width}px`,W.root.style.height=`${J.height}px`,W.root.style.visibility="visible",W.root.style.transform=`translate(${J.x}px, ${Q+J.y}px)`}),Q+=_.containerHeight+m.gutter.y}),ut=void 0,D.style.height=`${Math.max(0,Q-m.gutter.y)}px`;return}const F=d??Y,z=F.map(O=>X(t.items[O.index])),w=Ve(z,L,d?ut:void 0);F.forEach((O,G)=>{const Q=w.positions[G];O.root.style.width=`${Q.width}px`,O.root.style.height=`${Q.height}px`,O.root.style.visibility="visible",O.root.style.transform=`translate(${Q.x}px, ${Q.y}px)`}),ut=w.columnHeights,D.style.height=`${w.containerHeight}px`}function Pt(){const d=D.getBoundingClientRect().width;if(d<=0)return;const u=dt(d),m=Y.map(F=>X(t.items[F.index])),L=ci(m,{containerWidth:d,gutterX:u.gutter.x,gutterY:u.gutter.y,rowHeight:u.rowHeight});Y.forEach((F,z)=>{const h=L.positions[z];F.root.style.width=`${h.width}px`,F.root.style.height=`${h.height}px`,F.root.style.visibility="visible",F.root.style.transform=`translate(${h.x}px, ${h.y}px)`}),D.style.height=`${L.containerHeight}px`}function St(d,u,m){const L=new Map,F=new Map;if(V==="fit")for(const S of H){if(!S.structured)continue;const{subtitleEl:x}=S.structured;S.root.style.maxWidth="none",S.root.style.whiteSpace="nowrap",x&&(x.hidden=!1),L.set(S.tileStart,S.root.getBoundingClientRect().width),x?(x.hidden=!0,F.set(S.tileStart,S.root.getBoundingClientRect().width),x.hidden=!1):F.set(S.tileStart,L.get(S.tileStart))}function z(S,x){return Y.slice(S,x).map(A=>X(t.items[A.index]))}function h(S,x){const A=H[S].tileStart,_=x<H.length?H[x].tileStart:Y.length,W=Vt(z(A,_),d);for(let U=S;U<x;U++){const J=H[U];if(!J.structured)continue;const q=W.positions[J.tileStart-A];if(!q)continue;const K=U+1<x?H[U+1]:void 0,lt=K?W.positions[K.tileStart-A]:null,oe=(!!lt&&Math.abs(lt.y-q.y)<.5?lt.x:m)-q.x-u.gutter.x;if(Math.min(L.get(J.tileStart)??1/0,F.get(J.tileStart)??1/0)>oe)return null}return W}function w(){if(V!=="fit")return[{startSection:0,endSection:H.length,tileStart:0,tileEnd:Y.length,result:Vt(z(0,Y.length),d)}];const S=[];let x=0;for(;x<H.length;){const A=h(x,x+1),_=H[x].tileStart;if(A===null){const q=x+1<H.length?H[x+1].tileStart:Y.length;S.push({startSection:x,endSection:x+1,tileStart:_,tileEnd:q,result:Vt(z(_,q),d)}),x+=1;continue}let W=x+1,U=A;for(;W<H.length;){const q=h(x,W+1);if(q===null)break;W+=1,U=q}const J=W<H.length?H[W].tileStart:Y.length;S.push({startSection:x,endSection:W,tileStart:_,tileEnd:J,result:U}),x=W}return S}function O(S){for(let x=S.startSection;x<S.endSection;x++){const A=H[x];if(!A.structured)continue;const _=S.result.positions[A.tileStart-S.tileStart];if(!_)continue;const W=x+1<S.endSection?H[x+1]:void 0,U=W?S.result.positions[W.tileStart-S.tileStart]:null,q=(!!U&&Math.abs(U.y-_.y)<.5?U.x:m)-_.x-u.gutter.x,{subtitleEl:K}=A.structured;A.root.style.whiteSpace="nowrap",A.root.style.maxWidth="none",A.root.style.overflow="",A.root.style.textOverflow="",K&&(K.hidden=!1),!((L.get(A.tileStart)??0)<=q)&&(K&&(K.hidden=!0,(F.get(A.tileStart)??0)<=q)||(A.root.style.maxWidth=`${Math.max(0,q)}px`,A.root.style.overflow="hidden",A.root.style.textOverflow="ellipsis"))}}function G(S){for(let x=S.startSection;x<S.endSection;x++){const A=H[x];if(!A.structured)continue;const _=S.result.positions[A.tileStart-S.tileStart];if(!_)continue;const W=x+1<S.endSection?H[x+1]:void 0,U=W?S.result.positions[W.tileStart-S.tileStart]:null,q=(!!U&&Math.abs(U.y-_.y)<.5?U.x:m)-_.x-u.gutter.x;A.root.style.whiteSpace="normal",A.root.style.maxWidth=`${Math.max(0,q)}px`;const K=getComputedStyle(A.root),lt=parseFloat(K.lineHeight),ee=Number.isFinite(lt)?lt:parseFloat(K.fontSize)*1.2,oe=Math.max(1,Math.floor(u.maxRowHeight/ee));A.root.style.display="-webkit-box",A.root.style.overflow="hidden",A.root.style.setProperty("-webkit-box-orient","vertical"),A.root.style.setProperty("-webkit-line-clamp",`${oe}`)}}const Q=w();let ot=0,rt=0;for(const S of Q){V==="fit"?O(S):V==="wrap"&&G(S);const x=new Map;for(let _=S.startSection;_<S.endSection;_++){const W=H[_];x.set(W.tileStart,W.root.getBoundingClientRect().height)}for(const _ of S.result.rows){const W=_.start+S.tileStart,U=_.end+S.tileStart;let J=0;for(;rt<S.endSection&&H[rt].tileStart<U;){const q=H[rt],K=S.result.positions[q.tileStart-S.tileStart];K&&(q.root.hidden=!1,q.root.style.transform=`translate(${K.x}px, ${_.y+ot}px)`,J=Math.max(J,x.get(q.tileStart)??0)),rt++}J>0&&(ot+=J+u.gutter.y);for(let q=W;q<U;q++){const K=S.result.positions[q-S.tileStart],lt=Y[q];lt.root.hidden=K===null,K&&(lt.root.style.width=`${K.width}px`,lt.root.style.height=`${K.height}px`,lt.root.style.visibility="visible",lt.root.style.transform=`translate(${K.x}px, ${K.y+ot}px)`)}}const A=S.result.rows.length>0?S.result.rows[S.result.rows.length-1].end+S.tileStart:S.tileStart;for(let _=A;_<S.tileEnd;_++)Y[_].root.hidden=!0;ot+=S.result.containerHeight+u.gutter.y}for(;rt<H.length;)H[rt].root.hidden=!0,rt++;D.style.height=`${Math.max(0,ot-u.gutter.y)}px`}function Tt(){const d=D.getBoundingClientRect().width;if(d<=0)return;const u=dt(d),m={containerWidth:d,gutterX:u.gutter.x,gutterY:u.gutter.y,rowHeight:u.rowHeight,minRowHeight:u.minRowHeight,maxRowHeight:u.maxRowHeight,lastRow:u.lastRow};if($&&H.length>0){St(m,u,d);return}const L=Y.map(z=>X(t.items[z.index])),F=Vt(L,m);Y.forEach((z,h)=>{const w=F.positions[h];z.root.hidden=w===null,w&&(z.root.style.width=`${w.width}px`,z.root.style.height=`${w.height}px`,z.root.style.visibility="visible",z.root.style.transform=`translate(${w.x}px, ${w.y}px)`)}),D.style.height=`${F.containerHeight}px`}function bt(){M?Pt():e==="masonry"?jt(null):e==="justified"?Tt():nt(Y)}let ft=!1,st=null;function Dt(){st!==null||ft||(st=requestAnimationFrame(()=>{st=null,!ft&&($?mt(t.items):bt())}))}function Mt(d){if(T)for(const u of d){const m=t.items[u.index];if(!m||m.width&&m.height||yt.has(m)||!B(m))continue;const L=()=>{ft||u.img.naturalWidth>0&&u.img.naturalHeight>0&&(yt.set(m,{width:u.img.naturalWidth,height:u.img.naturalHeight}),Dt())};u.img.complete?L():u.img.addEventListener("load",L,{once:!0})}}function Lt(d){o.emit("layoutRender",{tiles:d.map(u=>({index:u.index,element:u.root}))})}function mt(d){if(D.replaceChildren(),Y=d.map((u,m)=>ht(u,m)),H=[],$)for(const u of Ct(d)){const m=d.slice(u.startIndex,u.endIndex),{root:L,structured:F}=I(u.key,m);D.appendChild(L),H.push({root:L,tileStart:u.startIndex,structured:F});for(let z=u.startIndex;z<u.endIndex;z++)D.appendChild(Y[z].root)}else for(const u of Y)D.appendChild(u.root);ut=void 0,bt(),Mt(Y),Lt(Y)}function Bt(d,u){const m=d.map((L,F)=>ht(L,u+F));for(const L of m)D.appendChild(L.root);Y=[...Y,...m],M?Pt():e==="masonry"?jt(m):e==="justified"?Tt():nt(m),Mt(m),Lt(m)}mt(t.items),at=t.items;const Ht=o.on("itemsUpdated",({items:d})=>{$?mt(d):hi(at,d)?Bt(d.slice(at.length),at.length):mt(d),at=d});let wt=null,Et;return(e==="masonry"||e==="justified"||pt.length>0)&&(Et=new ResizeObserver(()=>{wt===null&&(wt=requestAnimationFrame(()=>{wt=null,bt()}))}),Et.observe(D)),()=>{ft=!0,st!==null&&cancelAnimationFrame(st),Et==null||Et.disconnect(),wt!==null&&cancelAnimationFrame(wt),Ht(),D.classList.remove("shoji-layout",`shoji-layout--${e}`,"shoji-layout--animate"),D.style.removeProperty("height"),D.style.removeProperty("width"),D.replaceChildren()}}};function fi(o){const t=(o.rotation%360+360)%360;return o.flipH&&o.flipV?{flipH:!1,flipV:!1,rotation:(t+180)%360}:{flipH:o.flipH,flipV:o.flipV,rotation:t}}const pi='<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 14 4 9l5-5"/><path d="M4 9h10a6 6 0 1 1 0 12H9"/></svg>',mi='<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 14 20 9l-5-5"/><path d="M20 9H10a6 6 0 1 0 0 12h5"/></svg>',gi='<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3v18"/><path d="M17 7l3 5-3 5"/><path d="M7 7l-3 5 3 5"/></svg>',vi='<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 12h18"/><path d="M7 17l5 3 5-3"/><path d="M7 7l5-3 5 3"/></svg>',ze={flipH:!1,flipV:!1,rotation:0};function yi(o,t,e,i){if(!o&&!t&&e===0&&i===1)return"none";const n=(o?-1:1)*i,s=(t?-1:1)*i;return`scaleX(${n}) scaleY(${s}) rotate(${e}deg)`}function bi(o,t,e,i,n){if(!o||!t||!i||!n||e/90%2===0)return 1;const s=Math.min(1,o/i,t/n);return Math.min(1,o/n,t/i)/s}const wi={name:"rotateFlip",init(o){const{gallery:t}=o,e=t.options.locale??{},i=e.rotateLeft??"Rotate left",n=e.rotateRight??"Rotate right",s=e.flipHorizontal??"Flip horizontal",r=e.flipVertical??"Flip vertical";let a={...ze},l=0,c=!1,f=!1;function y(I){const j=t.items[t.currentIndex];if(j!=null&&j.width&&j.height)return{width:j.width,height:j.height};const B=I.querySelector("img");if(B!=null&&B.naturalWidth&&B.naturalHeight)return{width:B.naturalWidth,height:B.naturalHeight}}function g(I){const j=t.getActiveMedia();if(!j)return;const B=y(j),X=bi(j.clientWidth,j.clientHeight,l,B==null?void 0:B.width,B==null?void 0:B.height),ht=yi(c,f,l,X);if(!I){j.style.transform=ht;return}j.style.transition="transform var(--shoji-duration) var(--shoji-easing)",j.style.transform=ht,At(j,()=>{j.style.transition=""})}function v(I,j){const B=document.createElement("button");return B.type="button",B.className="shoji-toolbar-button",B.innerHTML=I,B.setAttribute("aria-label",j),B.title=j,B}const b=v(pi,i),E=v(mi,n),T=v(gi,s),M=v(vi,r);T.setAttribute("aria-pressed","false"),M.setAttribute("aria-pressed","false");function C(I,j){a=fi({...a,...I}),j!==void 0&&(l+=j),g(!0),T.setAttribute("aria-pressed",String(a.flipH)),M.setAttribute("aria-pressed",String(a.flipV)),o.emit("rotateFlipChange",{index:t.currentIndex,...a})}function R(I){return I!==(c!==f)?90:-90}function V(){const I=R(!1);C({rotation:a.rotation+I},I)}function N(){const I=R(!0);C({rotation:a.rotation+I},I)}function P(){c=!c,C({flipH:!a.flipH})}function $(){f=!f,C({flipV:!a.flipV})}b.addEventListener("click",V),E.addEventListener("click",N),T.addEventListener("click",P),M.addEventListener("click",$);function k(){a={...ze},l=0,c=!1,f=!1,g(!1),T.setAttribute("aria-pressed","false"),M.setAttribute("aria-pressed","false")}let et=null;function pt(){const I=t.getActiveMedia(),j=I==null?void 0:I.style.transform;et=j&&j!=="none"?j:null}const dt=[b,E,T,M].map(I=>o.ui.toolbar("right",I)),D=o.on("requestRotateLeft",V),Y=o.on("requestRotateRight",N),H=o.on("requestFlipHorizontal",P),ut=o.on("requestFlipVertical",$),at=o.on("afterOpen",k),vt=o.on("beforeSlide",()=>{pt(),k()}),yt=o.on("afterSlide",k),Ct=t.registerSlideLeaveDecorator(I=>{if(!et)return;const j=et;return et=null,I.style.transform=j,()=>{I.style.transition="transform var(--shoji-duration) var(--shoji-easing)",I.style.transform="none"}});return()=>{for(const I of dt)I();D(),Y(),H(),ut(),at(),vt(),yt(),Ct()}}};let Yt=null;const Ei=250;function Ci(){var o;return(o=window.Vimeo)!=null&&o.Player?Promise.resolve(window.Vimeo):Yt||(Yt=new Promise(t=>{const e=document.createElement("script");e.src="https://player.vimeo.com/api/player.js",e.onload=()=>t(window.Vimeo),document.head.appendChild(e)}),Yt)}function Si(o,t){const e=o;e.paused=!0,e.ended=!1,e.play=()=>t.play(),e.pause=()=>t.pause();let i=!1;return Object.defineProperty(e,"muted",{configurable:!0,get:()=>i,set:n=>{i=n,t.setMuted(n)}}),e}const Ti=(o,t,e,i,n)=>{var l;if(((l=t.video)==null?void 0:l.provider)!=="vimeo")return;const{id:s,url:r}=t.video;if(!s&&!r){const c=document.createElement("div");c.className="shoji-slide-placeholder",c.textContent="Video",o.appendChild(c),e();return}if(!t.poster){const c=r??`https://vimeo.com/${s}`;fetch(`https://vimeo.com/api/oembed.json?url=${encodeURIComponent(c)}`).then(f=>f.ok?f.json():null).then(f=>{i.aborted||typeof(f==null?void 0:f.thumbnail_url)=="string"&&n(f.thumbnail_url)}).catch(()=>{})}const a=document.createElement("div");a.className="shoji-video-mount",o.appendChild(a),Ci().then(c=>{if(i.aborted)return;const f=o,y=new c.Player(a,{...r?{url:r}:{id:Number(s)},playsinline:!0});let g=null;function v(){g!==null&&(clearTimeout(g),g=null)}y.on("play",()=>{v(),f.paused=!1,f.dispatchEvent(new Event("play"))}),y.on("pause",()=>{f.paused=!0,v(),g=setTimeout(()=>{g=null,f.dispatchEvent(new Event("pause"))},Ei)}),y.on("ended",()=>{v(),f.paused=!0,f.ended=!0,f.dispatchEvent(new Event("ended"))}),y.on("error",b=>f.dispatchEvent(new CustomEvent("error",{bubbles:!0,detail:{name:b.name}}))),y.ready().then(()=>{Si(o,y),Promise.all([y.getVideoWidth(),y.getVideoHeight()]).then(([b,E])=>{b&&E&&o.style.setProperty("--shoji-provider-video-aspect",`calc(${b} / ${E})`)}).catch(()=>{}).then(()=>e())}),i.addEventListener("abort",()=>{v(),y.destroy()},{once:!0})})};let Wt=null;function Mi(){var o;return(o=window.YT)!=null&&o.Player?Promise.resolve(window.YT):Wt||(Wt=new Promise(t=>{const e=window.onYouTubeIframeAPIReady;window.onYouTubeIframeAPIReady=()=>{e==null||e(),t(window.YT)};const i=document.createElement("script");i.src="https://www.youtube.com/iframe_api",document.head.appendChild(i)}),Wt)}function Li(o,t){const e=o;return e.paused=!0,e.ended=!1,e.play=()=>t.playVideo(),e.pause=()=>t.pauseVideo(),Object.defineProperty(e,"muted",{configurable:!0,get:()=>t.isMuted(),set:i=>i?t.mute():t.unMute()}),e}function xi(o,t,e){o.data===t.PlayerState.PLAYING?(e.paused=!1,e.dispatchEvent(new Event("play"))):o.data===t.PlayerState.PAUSED?(e.paused=!0,e.dispatchEvent(new Event("pause"))):o.data===t.PlayerState.ENDED&&(e.paused=!0,e.ended=!0,e.dispatchEvent(new Event("ended")))}const Oi=(o,t,e,i,n)=>{var a;if(((a=t.video)==null?void 0:a.provider)!=="youtube")return;const s=t.video.id;if(!s){const l=document.createElement("div");l.className="shoji-slide-placeholder",l.textContent="Video",o.appendChild(l),e();return}t.poster||n(`https://img.youtube.com/vi/${s}/hqdefault.jpg`);const r=document.createElement("div");o.appendChild(r),Mi().then(l=>{if(i.aborted)return;const c=o,f=new l.Player(r,{videoId:s,playerVars:{playsinline:1,rel:0},events:{onReady:()=>{Li(o,f),e()},onStateChange:y=>xi(y,l,c),onError:y=>c.dispatchEvent(new CustomEvent("error",{bubbles:!0,detail:{code:y.data}}))}});i.addEventListener("abort",()=>f.destroy(),{once:!0})})},ji={name:"video",init(o){const t=o.ui.registerVideoProvider("youtube",Oi),e=o.ui.registerVideoProvider("vimeo",Ti);return()=>{t(),e()}}},Pi='<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="10" cy="10" r="7"/><path d="M21 21l-5.5-5.5M10 7v6M7 10h6"/></svg>',Hi='<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="10" cy="10" r="7"/><path d="M21 21l-5.5-5.5M7 10h6"/></svg>',Ri='<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="4" width="16" height="16" rx="1"/><path d="M9 15l6-6M9 9h0M15 15h0"/></svg>';function Ai(o,t,e){return Math.min(e,Math.max(t,o))}const zt={a:1,b:0,c:0,d:1};function _e(o){const t=/^matrix\(\s*([^,]+),\s*([^,]+),\s*([^,]+),\s*([^,]+),/.exec(o);return t?{a:Number(t[1]),b:Number(t[2]),c:Number(t[3]),d:Number(t[4])}:{...zt}}function Qt(o,t,e){const i=e.a*e.d-e.b*e.c;return i===0?{tx:o,ty:t}:{tx:(e.d*o-e.c*t)/i,ty:(e.a*t-e.b*o)/i}}function Xe(o,t,e){return{tx:e.a*o+e.c*t,ty:e.b*o+e.d*t}}function te(o){return{tx:-o.width/2,ty:-o.height/2}}function Ii(o,t,e=zt,i=te(o)){const n=o.left+o.width/2,s=o.top+o.height/2,r=Xe(i.tx+t.tx,i.ty+t.ty,e);return{x:n+r.tx,y:s+r.ty}}function qe(o,t,e,i){if(t<=i)return e+(i-t)/2;const n=e+i-t;return Math.min(e,Math.max(n,o))}function ki(o,t,e,i,n){const s=-n.tx*2,r=-n.ty*2,a=o.left+o.width/2,l=o.top+o.height/2,f=[{x:0,y:0},{x:s,y:0},{x:0,y:r},{x:s,y:r}].map(({x:v,y:b})=>{const E={x:n.tx+t.tx+v*e,y:n.ty+t.ty+b*e},T=Xe(E.x,E.y,i);return{x:a+T.tx,y:l+T.ty}}),y=f.map(v=>v.x),g=f.map(v=>v.y);return{left:Math.min(...y),top:Math.min(...g),right:Math.max(...y),bottom:Math.max(...g)}}function Ze(o,t,e,i,n=zt,s=te(o)){const r=ki(o,i,e,n,s),a=qe(r.left,r.right-r.left,t.left,t.width),l=qe(r.top,r.bottom-r.top,t.top,t.height),c={tx:a-r.left,ty:l-r.top},f=Qt(c.tx,c.ty,n);return{tx:i.tx+f.tx,ty:i.ty+f.ty}}function Di(o,t,e,i,n,s,r=zt,a=te(o)){const l=Ii(o,t,r,a),c=n-l.x,f=s-l.y,y=Qt(c,f,r),g=1-i/e;return{tx:t.tx+y.tx*g,ty:t.ty+y.ty*g}}const Ot=1.001;function Bi(o){return o.composedPath().some(t=>t instanceof Element&&t.matches("button, video, input, select, textarea, a[href], [data-shoji-no-drag], .shoji-caption"))}return Object.assign(qo,{Autoplay:ti,Layout:ui,ActiveThumbnail:Go,Fullscreen:si,RotateFlip:wi,Video:ji,Zoom:{name:"zoom",defaults:{maxScale:4,doubleTapScale:2,buttonStep:1.5},init(o){const{gallery:t}=o,e=Number(o.options.maxScale??4),i=Number(o.options.doubleTapScale??2),n=Number(o.options.buttonStep??1.5),s=t.options.locale??{},r=s.zoomIn??"Zoom in",a=s.zoomOut??"Zoom out",l=s.zoomActualSize??"Actual size";let c=1,f={tx:0,ty:0},y=null,g=null,v=null,b=1;function E(){const h=t.getActiveMedia(),w=h==null?void 0:h.firstElementChild;return w instanceof HTMLImageElement?w:null}function T(h){const w=h.getBoundingClientRect();return{left:w.left,top:w.top,width:w.width,height:w.height}}function M(h){return y&&g&&v?!0:c!==1?!1:(y=T(h),g=T(h.parentElement??h),v={tx:-(h.offsetWidth||y.width)/2,ty:-(h.offsetHeight||y.height)/2},!0)}function C(h){const w=t.getActiveMedia();if(!w||w.style.transition===""){h();return}At(w,h)}function R(){const h=E();h&&(h.style.transformOrigin="0 0",h.style.transform=c===1&&f.tx===0&&f.ty===0?"none":`translate3d(${f.tx}px, ${f.ty}px, 0) scale3d(${c}, ${c}, 1)`,h.classList.toggle("shoji-zoomed",c>1))}function V(){o.emit("zoomChange",{index:t.currentIndex,scale:c})}function N(h,w,O){h.style.transition="transform var(--shoji-duration) var(--shoji-easing)",w(),At(h,()=>{h.style.transition="",O==null||O()})}function P(h,w,O,G=e,Q=!1){C(()=>{const ot=E();if(!ot||!M(ot))return;const rt=Ai(h,1,Math.max(G,1)),S=t.getActiveMedia(),x=_e(S?getComputedStyle(S).transform:"none");f=Di(y,f,c,rt,w,O,x,v),c=rt,f=Ze(y,g,c,f,x,v),Q?N(ot,R):R(),V()})}function $(h=!1){const w=c!==1;c=1,f={tx:0,ty:0},y=null,g=null,v=null,w&&V();const O=E();if(!O)return;const G=()=>{O.style.transform="",O.classList.remove("shoji-zoomed")};h?N(O,G,()=>{O.style.transformOrigin=""}):(G(),O.style.transformOrigin="")}let k=null,et="";function pt(){const h=E(),w=h==null?void 0:h.style.transform;k=w&&w!=="none"?w:null,et=(h==null?void 0:h.style.transformOrigin)||"0 0"}function dt(){var h;(h=E())==null||h.classList.add("shoji-zoom-enabled")}function D(h,w){c>Ot?$(!0):P(i,h,w,e,!0)}const Y=o.on("pinchStart",()=>{b=c}),H=o.on("pinchMove",({scale:h,centerX:w,centerY:O})=>{P(b*h,w,O)}),ut=o.on("pinchEnd",()=>{c<=Ot&&$()}),at=o.on("doubleTap",({x:h,y:w})=>D(h,w)),vt=o.on("wheelZoom",({deltaScale:h,x:w,y:O})=>{P(c+h,w,O)}),yt=o.on("requestZoomIn",ft),Ct=o.on("requestZoomOut",st),I=o.on("requestZoomActualSize",Dt),j=o.on("requestZoomReset",()=>$(!0));let B=null,X=0,ht=0;const nt=o.ui.outer();function jt(h){if(c<=Ot||Bi(h))return;const w=E();!w||!h.composedPath().includes(w)||(B=h.pointerId,X=h.clientX,ht=h.clientY,w.setPointerCapture(h.pointerId))}function Pt(h){if(B!==h.pointerId||!y||!g||!v)return;h.preventDefault();const w=h.clientX-X,O=h.clientY-ht;X=h.clientX,ht=h.clientY;const G=t.getActiveMedia(),Q=_e(G?getComputedStyle(G).transform:"none"),{tx:ot,ty:rt}=Qt(w,O,Q);f=Ze(y,g,c,{tx:f.tx+ot,ty:f.ty+rt},Q,v),R()}function St(h){B===h.pointerId&&(B=null)}nt.addEventListener("pointerdown",jt),nt.addEventListener("pointermove",Pt,{passive:!1}),nt.addEventListener("pointerup",St),nt.addEventListener("pointercancel",St);function Tt(h,w){const O=document.createElement("button");return O.type="button",O.className="shoji-toolbar-button",O.innerHTML=h,O.setAttribute("aria-label",w),O.title=w,O}function bt(){const h=t.getActiveMedia(),w=h==null?void 0:h.getBoundingClientRect();return w?{x:w.left+w.width/2,y:w.top+w.height/2}:{x:0,y:0}}function ft(){const{x:h,y:w}=bt();P(c*n,h,w,e,!0)}function st(){const{x:h,y:w}=bt();c/n<=Ot?$(!0):P(c/n,h,w,e,!0)}function Dt(){C(()=>{const h=E();if(!h||!h.naturalWidth||!M(h))return;if(c>Ot){$(!0);return}const w=h.naturalWidth/y.width,{x:O,y:G}=bt();P(w,O,G,w,!0)})}const Mt=Tt(Pi,r),Lt=Tt(Hi,a),mt=Tt(Ri,l);Mt.addEventListener("click",ft),Lt.addEventListener("click",st),mt.addEventListener("click",Dt);const Bt=[Mt,Lt,mt].map(h=>o.ui.toolbar("right",h));function Ht(){var w;const h=!!((w=t.items[t.currentIndex])!=null&&w.video);Mt.hidden=h,Lt.hidden=h,mt.hidden=h}const wt=[o.ui.registerShortcut("w",ft),o.ui.registerShortcut("W",ft),o.ui.registerShortcut("s",st),o.ui.registerShortcut("S",st)],Et=o.on("afterOpen",()=>{$(),dt(),Ht()}),d=o.on("beforeSlide",()=>{pt(),$()}),u=o.on("afterSlide",()=>{$(),dt(),Ht()}),m=o.on("beforeClose",()=>$()),L=t.registerZoomGate(()=>c>Ot),F=t.registerZoomStartProvider(()=>{var h;return c>Ot?((h=E())==null?void 0:h.getBoundingClientRect())??null:null}),z=t.registerSlideLeaveDecorator(h=>{if(!k)return;const w=k,O=et;k=null;const G=h.querySelector("img");if(G)return G.style.transformOrigin=O,G.style.transform=w,()=>{G.style.transition="transform var(--shoji-duration) var(--shoji-easing)",G.style.transform="none"}});return dt(),Ht(),()=>{var h;for(const w of Bt)w();for(const w of wt)w();Et(),d(),u(),m(),Y(),H(),ut(),at(),vt(),yt(),Ct(),I(),j(),nt.removeEventListener("pointerdown",jt),nt.removeEventListener("pointermove",Pt),nt.removeEventListener("pointerup",St),nt.removeEventListener("pointercancel",St),L(),F(),z(),$(),(h=E())==null||h.classList.remove("shoji-zoom-enabled")}}},version:"0.1.0-beta.1"})}));
1
+ (function(tt,it){typeof exports=="object"&&typeof module<"u"?module.exports=it():typeof define=="function"&&define.amd?define(it):(tt=typeof globalThis<"u"?globalThis:tt||self,tt.Shoji=it())})(this,(function(){"use strict";var Fi=Object.defineProperty;var Ni=(tt,it,xt)=>it in tt?Fi(tt,it,{enumerable:!0,configurable:!0,writable:!0,value:xt}):tt[it]=xt;var p=(tt,it,xt)=>Ni(tt,typeof it!="symbol"?it+"":it,xt);let tt=0,it="",xt="",ie="",ne=0,se=0,gt=null,_t=!1;const re=".shoji-outer";function Ge(){_t=!0}function Ue(){return getComputedStyle(document.documentElement).direction==="rtl"}function Ke(o){let t=o instanceof Element?o:(o==null?void 0:o.parentElement)??null;for(;t&&t!==document.documentElement;){const e=getComputedStyle(t);if((e.overflowY==="auto"||e.overflowY==="scroll")&&t.scrollHeight>t.clientHeight)return!0;t=t.parentElement}return!1}let ae=!1;function le(o){const t=o.target;ae=!(t instanceof Element&&t.closest(re)!==null)&&Ke(t)}function ce(o){const t=o.target;!(t instanceof Element&&t.closest(re)!==null)&&!ae&&o.preventDefault()}function Je(){if(tt===0)return;const o=document.documentElement;getComputedStyle(o).overflow!=="hidden"&&(o.style.overflow="hidden",gt==null||gt.takeRecords())}function Qe(){if(tt===0){ne=window.scrollX,se=window.scrollY,_t=!1;const o=window.innerWidth-document.documentElement.clientWidth,t=Ue();if(xt=document.documentElement.style.paddingRight,ie=document.documentElement.style.paddingLeft,o>0)if(t){const e=parseFloat(getComputedStyle(document.documentElement).paddingLeft)||0;document.documentElement.style.paddingLeft=`${e+o}px`}else{const e=parseFloat(getComputedStyle(document.documentElement).paddingRight)||0;document.documentElement.style.paddingRight=`${e+o}px`}it=document.documentElement.style.overflow,document.documentElement.style.overflow="hidden",document.addEventListener("touchstart",le,{passive:!0}),document.addEventListener("touchmove",ce,{passive:!1}),gt=new MutationObserver(Je),gt.observe(document.documentElement,{attributes:!0,attributeFilter:["style"]})}tt++}function to(){tt=Math.max(0,tt-1),tt===0&&(gt==null||gt.disconnect(),gt=null,document.removeEventListener("touchstart",le),document.removeEventListener("touchmove",ce),document.documentElement.style.overflow=it,document.documentElement.style.paddingRight=xt,document.documentElement.style.paddingLeft=ie,_t||window.scrollTo({left:ne,top:se,behavior:"instant"}))}class eo{constructor(){p(this,"listeners",new Map)}on(t,e){let i=this.listeners.get(t);return i||(i=new Set,this.listeners.set(t,i)),i.add(e),()=>this.off(t,e)}off(t,e){var i;(i=this.listeners.get(t))==null||i.delete(e)}emit(t,e){const i=this.listeners.get(t);if(i)for(const n of i)n(e)}clear(){this.listeners.clear()}}const de='<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M6 6l12 12M18 6L6 18"/></svg>',oo='<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 6l-6 6 6 6"/></svg>',io='<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 6l6 6-6 6"/></svg>',no='<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="5" width="18" height="14" rx="2"/><path d="M7 10h10M7 14h6"/></svg>',so='<svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 9l6 6 6-6"/></svg>';let ro=0;function Rt(o,t,e){const i=document.createElement("button");return i.type="button",i.className=o,i.ariaLabel=i.title=e,i.innerHTML=t,i}function ao(o,t){const e=`shoji-counter-${++ro}`,i=document.createElement("div");i.className="shoji-outer";const n=document.createElement("div");n.className="shoji-backdrop",i.appendChild(n);const s=document.createElement("div");s.className="shoji-dialog",s.setAttribute("role","dialog"),s.setAttribute("aria-modal","true"),s.setAttribute("aria-labelledby",e),s.tabIndex=-1;const r=document.createElement("div");r.className="shoji-toolbar";const a=document.createElement("div");a.className="shoji-toolbar-slot shoji-toolbar-left";const l=document.createElement("div");l.className="shoji-toolbar-slot shoji-toolbar-center";const c=document.createElement("div");c.className="shoji-toolbar-slot shoji-toolbar-right";const f=Rt("shoji-close",de,t.close),y=Rt("shoji-toolbar-button shoji-caption-toggle",no,t.showCaption);y.setAttribute("aria-pressed","false"),y.hidden=!0;const g=Rt("shoji-toolbar-button shoji-toolbar-overflow",so,t.moreControls);g.setAttribute("aria-haspopup","true"),g.setAttribute("aria-expanded","false"),g.hidden=!0,c.append(y,g,f);const v=document.createElement("div");v.className="shoji-toolbar-overflow-panel",v.setAttribute("role","dialog"),v.setAttribute("aria-label",t.moreControls),v.tabIndex=-1,v.hidden=!0;const b=document.createElement("div");b.className="shoji-counter",b.id=e,a.appendChild(b),r.append(a,l,c),s.appendChild(r),s.appendChild(v);const E=Rt("shoji-nav shoji-nav-prev",oo,t.previous),T=Rt("shoji-nav shoji-nav-next",io,t.next);s.appendChild(E),s.appendChild(T),s.appendChild(o);const M=document.createElement("div");M.className="shoji-caption",s.appendChild(M);const C=document.createElement("div");C.className="shoji-caption-modal",C.hidden=!0;const R=document.createElement("div");R.className="shoji-caption-modal-panel",R.setAttribute("role","dialog"),R.setAttribute("aria-modal","true"),R.setAttribute("aria-label",t.fullCaption),R.tabIndex=-1;const V=Rt("shoji-caption-modal-close",de,t.close),N=document.createElement("div");return N.className="shoji-caption-modal-content",R.append(V,N),C.appendChild(R),s.appendChild(C),i.appendChild(s),{outer:i,backdrop:n,dialog:s,counter:b,caption:M,captionModal:C,captionModalPanel:R,captionModalContent:N,captionModalCloseButton:V,closeButton:f,prevButton:E,nextButton:T,captionToggleButton:y,toolbar:r,toolbarLeft:a,toolbarCenter:l,toolbarRight:c,toolbarOverflowButton:g,toolbarOverflowPanel:v}}const lo='a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), video[controls], [tabindex]:not([tabindex="-1"])';class co{constructor(){p(this,"container",null);p(this,"previouslyFocused",null);p(this,"onKeydown",t=>{if(t.key!=="Tab"||!this.container)return;const e=this.getFocusable();if(e.length===0){t.preventDefault(),this.container.focus();return}const i=e[0],n=e[e.length-1],s=document.activeElement,r=s instanceof HTMLElement&&e.includes(s);t.shiftKey?(!r||s===i)&&(t.preventDefault(),n.focus()):(!r||s===n)&&(t.preventDefault(),i.focus())})}getFocusable(){return this.container?Array.from(this.container.querySelectorAll(lo)):[]}activate(t){this.previouslyFocused=document.activeElement,this.container=t,document.addEventListener("keydown",this.onKeydown,!0),t.focus()}retarget(t){this.container=t,t.focus()}deactivate(){var t;document.removeEventListener("keydown",this.onKeydown,!0),this.container=null,(t=this.previouslyFocused)==null||t.focus({preventScroll:!0}),this.previouslyFocused=null}}const ho=300,uo=30,fo=500;class po{constructor(t,e,i){p(this,"target");p(this,"options");p(this,"callbacks");p(this,"pointers",new Map);p(this,"primaryPointerId",null);p(this,"direction",null);p(this,"dragStartDistance",0);p(this,"pinching",!1);p(this,"pinchStartDistance",0);p(this,"capturedThisGesture",!1);p(this,"lastTapTime",-1/0);p(this,"lastTapX",0);p(this,"lastTapY",0);p(this,"onPointerDown",t=>{var e,i,n,s;if(!(t.isPrimary===!1&&this.pointers.size===0)&&!(this.pointers.size===0&&((i=(e=this.callbacks).ignore)!=null&&i.call(e,t)))){if(this.pointers.set(t.pointerId,{startX:t.clientX,startY:t.clientY,startTime:t.timeStamp,lastX:t.clientX,lastY:t.clientY,lastTime:t.timeStamp}),this.pointers.size===1)this.primaryPointerId=t.pointerId,this.direction=null,this.capturedThisGesture=!1;else if(this.pointers.size===2){this.direction=null,this.pinching=!0;const[r,a]=[...this.pointers.values()];this.pinchStartDistance=he(r,a);const l=ue(r,a);(s=(n=this.callbacks).onPinchStart)==null||s.call(n,l.x,l.y)}}});p(this,"onPointerMove",t=>{var r,a,l,c,f,y,g,v;const e=this.pointers.get(t.pointerId);if(!e)return;if(e.lastX=t.clientX,e.lastY=t.clientY,e.lastTime=t.timeStamp,this.pinching){if(this.pointers.size<2)return;const[b,E]=[...this.pointers.values()],T=he(b,E),M=this.pinchStartDistance>0?T/this.pinchStartDistance:1,C=ue(b,E);(a=(r=this.callbacks).onPinchMove)==null||a.call(r,M,C.x,C.y);return}if(t.pointerId!==this.primaryPointerId)return;const i=t.clientX-e.startX,n=t.clientY-e.startY;if(this.direction===null){const b=Math.abs(i),E=Math.abs(n);if(Math.max(b,E)<this.options.lockThreshold)return;this.direction=b>E?"horizontal":"vertical",this.dragStartDistance=this.direction==="horizontal"?i:n,(((c=(l=this.callbacks).shouldCapture)==null?void 0:c.call(l))??!0)&&(this.target.setPointerCapture(t.pointerId),this.capturedThisGesture=!0),(y=(f=this.callbacks).onDragStart)==null||y.call(f,this.direction,t)}this.direction==="horizontal"&&t.preventDefault();const s=(this.direction==="horizontal"?i:n)-this.dragStartDistance;(v=(g=this.callbacks).onDragMove)==null||v.call(g,this.direction,s,t)});p(this,"onPointerUp",t=>{this.finishPointer(t,!1)});p(this,"onPointerCancel",t=>{this.finishPointer(t,!0)});p(this,"onWheel",t=>{var i,n;if(!t.ctrlKey)return;t.preventDefault();const e=-t.deltaY*.01;(n=(i=this.callbacks).onWheelZoom)==null||n.call(i,e,t.clientX,t.clientY,t)});this.target=t,this.callbacks=e,this.options={lockThreshold:(i==null?void 0:i.lockThreshold)??10,swipeThreshold:(i==null?void 0:i.swipeThreshold)??50,swipeVelocity:(i==null?void 0:i.swipeVelocity)??.3},this.target.addEventListener("pointerdown",this.onPointerDown),this.target.addEventListener("pointermove",this.onPointerMove),this.target.addEventListener("pointerup",this.onPointerUp),this.target.addEventListener("pointercancel",this.onPointerCancel),this.target.addEventListener("wheel",this.onWheel,{passive:!1})}destroy(){this.target.removeEventListener("pointerdown",this.onPointerDown),this.target.removeEventListener("pointermove",this.onPointerMove),this.target.removeEventListener("pointerup",this.onPointerUp),this.target.removeEventListener("pointercancel",this.onPointerCancel),this.target.removeEventListener("wheel",this.onWheel),this.pointers.clear()}finishPointer(t,e){var n,s,r,a;const i=this.pointers.get(t.pointerId);if(i){if(i.lastX=t.clientX,i.lastY=t.clientY,i.lastTime=t.timeStamp,this.pointers.delete(t.pointerId),this.pinching){this.pointers.size<2&&(this.pinching=!1,(s=(n=this.callbacks).onPinchEnd)==null||s.call(n));return}if(t.pointerId===this.primaryPointerId){if(this.direction===null)!e&&t.timeStamp-i.startTime<=fo&&this.registerTap(i.lastX,i.lastY,t);else{const l=Math.max(1,i.lastTime-i.startTime),c=(this.direction==="horizontal"?i.lastX-i.startX:i.lastY-i.startY)-this.dragStartDistance,f=c/l,y=!e&&(Math.abs(c)>=this.options.swipeThreshold||Math.abs(f)>=this.options.swipeVelocity);(a=(r=this.callbacks).onDragEnd)==null||a.call(r,this.direction,c,f,y,e),this.capturedThisGesture&&this.suppressRetargetedClick()}this.primaryPointerId=null,this.direction=null,this.capturedThisGesture=!1}}}suppressRetargetedClick(){let t=!1;const e=i=>{t||(t=!0,i==null||i.stopPropagation(),this.target.removeEventListener("click",e,{capture:!0}))};this.target.addEventListener("click",e,{capture:!0}),setTimeout(e,500)}registerTap(t,e,i){var r,a,l,c;const n=i.timeStamp;n-this.lastTapTime<=ho&&Math.hypot(t-this.lastTapX,e-this.lastTapY)<=uo?((a=(r=this.callbacks).onDoubleTap)==null||a.call(r,t,e,i),this.lastTapTime=0):((c=(l=this.callbacks).onTap)==null||c.call(l,t,e,i),this.lastTapTime=n,this.lastTapX=t,this.lastTapY=e)}}function he(o,t){return Math.hypot(o.lastX-t.lastX,o.lastY-t.lastY)}function ue(o,t){return{x:(o.lastX+t.lastX)/2,y:(o.lastY+t.lastY)/2}}function fe(){return typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}function mo(o){var e;const t=((e=o.split(",")[0])==null?void 0:e.trim())??"";return t.endsWith("ms")?parseFloat(t):t.endsWith("s")?parseFloat(t)*1e3:0}function pe(o,t,e){const i=o.width/o.height;let n=t>i?o.width:o.height*t,s=t>i?o.width/t:o.height;if(e&&e.width>0&&e.height>0){const r=Math.min(1,e.width/n,e.height/s);n*=r,s*=r}return{left:o.left+(o.width-n)/2,top:o.top+(o.height-s)/2,width:n,height:s}}function me(o,t,e){const i=o.firstElementChild,n=i instanceof HTMLElement&&(i.classList.contains("shoji-slide-spinner")||i.classList.contains("shoji-slide-open-placeholder"));if(i instanceof HTMLElement&&!n){const r=i.getBoundingClientRect();if(r.width>0&&r.height>0)return r}const s=o.getBoundingClientRect();return t&&s.width>0&&s.height>0?pe(s,t,e):s}function ge(o,t){const e=Math.min(t.width/o.width,t.height/o.height),i=t.left+t.width/2-(o.left+o.width/2),n=t.top+t.height/2-(o.top+o.height/2);return`translate3d(${i}px, ${n}px, 0) scale3d(${e}, ${e}, 1)`}function ve(o,t,e,i){const n=o.getBoundingClientRect(),s=me(t,e,i);return s.width===0||s.height===0||n.width===0||n.height===0?null:ge(s,n)}function At(o,t,e="transform"){const i=mo(getComputedStyle(o).transitionDuration);let n=!1;const s=()=>{n||(n=!0,o.removeEventListener("transitionend",r),t())},r=a=>{a.target===o&&a.propertyName===e&&s()};o.addEventListener("transitionend",r),setTimeout(s,i+100)}function ye(o,t){o.style.transition="",o.style.transformOrigin="",o.style.willChange="",o.style.opacity="",o.style.transform===t&&(o.style.transform="")}function go({origin:o,target:t,aspectRatio:e,naturalSize:i}){if(fe())return;const n=ve(o,t,e,i);n&&(t.style.transition="none",t.style.transformOrigin="center",t.style.willChange="transform",t.style.transform=n,t.offsetHeight,t.style.transition="transform var(--shoji-duration) var(--shoji-easing)",t.style.transform="none",At(t,()=>ye(t,"none")))}function vo({origin:o,target:t,aspectRatio:e,naturalSize:i,dragStart:n,zoomStart:s},r){if(fe()){r();return}const a=ve(o,t,e,i);if(!a){r();return}if(t.style.transformOrigin="center",t.style.willChange="transform",n)t.style.transition="none",t.style.transform=`translate3d(0px, ${n.translateY}px, 0px) scale3d(${n.scale}, ${n.scale}, 1)`,t.style.opacity=String(n.opacity),t.offsetHeight;else if(s){const c=me(t,e,i);if(c.width>0&&c.height>0){const f=t.style.transform,y=ge(c,s);t.style.transition="none",t.style.transform=f&&f!=="none"?`${f} ${y}`:y,t.offsetHeight}}t.style.transition="transform var(--shoji-duration) var(--shoji-easing)",t.offsetHeight,t.style.transform=a;const l=t.style.transform;At(t,()=>{ye(t,l),r()})}const yo="transform var(--shoji-duration) var(--shoji-momentum-easing)",bo="transform var(--shoji-duration) var(--shoji-momentum-easing), opacity var(--shoji-duration) var(--shoji-momentum-easing)",be=160,wo="button, video, input, select, textarea, a[href], [data-shoji-no-drag], .shoji-caption, .shoji-caption-modal, .shoji-toolbar-overflow-panel",Eo="button, input, select, textarea, a[href], [data-shoji-no-drag], .shoji-caption, .shoji-caption-modal, .shoji-toolbar-overflow-panel";function Co(o,t){const e=t.getBoundingClientRect(),i=parseFloat(getComputedStyle(t).getPropertyValue("--shoji-video-gesture-margin"));return o.clientY>=e.bottom-(Number.isFinite(i)?i:0)}function So(o){let t=!1;const e=i=>{t||(t=!0,i==null||i.stopPropagation(),o.removeEventListener("click",e,{capture:!0}))};o.addEventListener("click",e,{capture:!0}),setTimeout(e,500)}function To(o,t){if(t.hidden||!t.classList.contains("shoji-caption--video"))return!1;const e=t.getBoundingClientRect();return o.clientX>=e.left&&o.clientX<=e.right&&o.clientY>=e.top&&o.clientY<=e.bottom}function Mo(o,t,e){if(To(o,t))return!0;const i=o.composedPath(),n=i.find(s=>s instanceof HTMLVideoElement);return n?Co(o,n)?(So(e),!0):!1:i.some(s=>s instanceof Element&&s.matches(Eo))}class Lo{constructor(t,e,i){p(this,"engine");p(this,"controlsHideThreshold");p(this,"controlsHiddenForDrag",!1);p(this,"lastDragDelta",0);p(this,"onDragMove",(t,e)=>{this.host.isZoomed()||(t==="horizontal"?this.host.slides.setDragOffset(e,null):this.host.canClose()&&this.applyVerticalDragFeedback(e))});p(this,"onDragEnd",(t,e,i,n)=>{this.host.isZoomed()||(t==="horizontal"?this.finishHorizontalDrag(e,n):this.finishVerticalDrag(n))});this.host=t,this.controlsHideThreshold=(i==null?void 0:i.swipeThreshold)??50,this.engine=new po(t.dialog,{ignore:n=>Mo(n,t.caption,t.dialog),shouldCapture:()=>!t.isZoomed(),onDragStart:()=>t.onActivity(),onDragMove:this.onDragMove,onDragEnd:this.onDragEnd,onTap:(n,s)=>e.onTap(n,s),onDoubleTap:(n,s)=>e.onDoubleTap(n,s),onPinchStart:(n,s)=>e.onPinchStart(n,s),onPinchMove:(n,s,r)=>e.onPinchMove(n,s,r),onPinchEnd:()=>e.onPinchEnd(),onWheelZoom:(n,s,r)=>e.onWheelZoom(n,s,r)},i)}destroy(){this.engine.destroy()}finishHorizontalDrag(t,e){const i=t<0,n=i?this.host.canGoNext():this.host.canGoPrev();if(!e||t===0||!n){this.settleDragOffset(0,()=>{});return}const s=this.host.dialog.getBoundingClientRect().width||1,r=i?-s:s;this.settleDragOffset(r,()=>{this.host.slides.setDragOffset(0,null),i?this.host.next():this.host.prev()})}settleDragOffset(t,e){const i=this.host.slides.getSlotRoot(0);if(this.host.slides.setDragOffset(t,yo),!i){e();return}At(i,e)}applyVerticalDragFeedback(t){const e=Math.min(Math.abs(t)/be,1),i=this.host.slides.element;this.lastDragDelta=t,i.style.transition="",i.style.transform=`translateY(${t}px) scale(${1-e*.15})`,i.style.opacity=String(1-e*.6);const n=Math.abs(t)>=this.controlsHideThreshold;n!==this.controlsHiddenForDrag&&(this.controlsHiddenForDrag=n,this.host.setControlsHiddenForDrag(n))}clearVerticalDragFeedback(t){const e=this.host.slides.element;e.style.transition=t?bo:"",e.style.transform="",e.style.opacity=""}finishVerticalDrag(t){const e=this.controlsHiddenForDrag;this.controlsHiddenForDrag=!1,t&&this.host.canClose()?this.host.closeFromSwipe(this.takeFrozenDragTransform()):(this.clearVerticalDragFeedback(!0),e&&this.host.setControlsHiddenForDrag(!1))}takeFrozenDragTransform(){const t=Math.min(Math.abs(this.lastDragDelta)/be,1),e={translateY:this.lastDragDelta,scale:1-t*.15,opacity:1-t*.6};return this.clearVerticalDragFeedback(!1),e}}class xo{constructor(){p(this,"element");this.element=document.createElement("div"),this.element.className="shoji-live-region",this.element.setAttribute("role","status"),this.element.setAttribute("aria-live","polite")}announce(t){this.element.textContent="",this.element.offsetWidth,this.element.textContent=t}}const Xt=":scope > a, :scope > [data-shoji-src], :scope > [data-shoji-video]";function we(o,t=Xt){const e=Array.from(o.querySelectorAll(t)),i=[];for(const n of e){const s=Po(n)??jo(n);s&&i.push({element:n,item:s})}return i}function ct(o,t){return o.getAttribute(t)??void 0}function It(o,t){const e=o.getAttribute(t);if(e===null)return;const i=Number(e);return Number.isFinite(i)?i:void 0}const Oo=new Set(["no-drag","video-id","video-provider"]);function qt(o,t,e){const i=ct(o,"data-shoji-caption");i&&(t.caption=i),t.id=ct(o,"data-shoji-id")??e;let n;for(const s of o.attributes){if(!s.name.startsWith("data-shoji-"))continue;const r=s.name.slice(11);!Oo.has(r)&&!(r in t)&&((n??(n={}))[r]=s.value)}n&&(t.data=n)}function jo(o){const t=ct(o,"href")??ct(o,"data-shoji-src");if(!t)return;const e={src:t},i=o.querySelector("img"),n=(i==null?void 0:i.getAttribute("src"))??ct(o,"data-shoji-thumb");n&&(e.thumb=n);const s=(i==null?void 0:i.getAttribute("alt"))??ct(o,"data-shoji-alt");s&&(e.alt=s);const r=It(o,"data-shoji-width");r!==void 0&&(e.width=r);const a=It(o,"data-shoji-height");a!==void 0&&(e.height=a);const l=ct(o,"data-shoji-srcset");l&&(e.srcset=l);const c=ct(o,"data-shoji-sizes");return c&&(e.sizes=c),qt(o,e,t),e}function Po(o){var n;const t=ct(o,"data-shoji-video-id"),e=o.querySelector("video");if(e){t&&console.warn(`Shoji: data-shoji-video-id="${t}" ignored — no effect on a nested <video> (always html5).`);const s=Array.from(e.querySelectorAll("source")).map(y=>({src:y.getAttribute("src")??"",type:y.getAttribute("type")??""})).filter(y=>y.src),r=e.getAttribute("src")??((n=s[0])==null?void 0:n.src);if(!r)return;const a={src:r,video:{provider:"html5"}};s.length&&(a.sources=s);const l=e.getAttribute("poster");l&&(a.poster=l);const c=It(o,"data-shoji-width");c!==void 0&&(a.width=c);const f=It(o,"data-shoji-height");return f!==void 0&&(a.height=f),qt(o,a,r),a}const i=ct(o,"data-shoji-video");if(i){const s=ct(o,"data-shoji-video-provider"),r=Ro(i,s,t),a={src:i,video:r.video};r.sources&&(a.sources=r.sources);const l=ct(o,"data-shoji-poster");l&&(a.poster=l);const c=It(o,"data-shoji-width");c!==void 0&&(a.width=c);const f=It(o,"data-shoji-height");return f!==void 0&&(a.height=f),qt(o,a,i),a}t&&console.warn(`Shoji: data-shoji-video-id="${t}" ignored — requires a data-shoji-video URL.`)}const Ho=new Set(["youtube","vimeo","html5"]);function Zt(o){return{video:{provider:"html5"},sources:[{src:o,type:Ao(o)}]}}function Ro(o,t,e){if(t&&!Ho.has(t)&&(console.warn(`Shoji: data-shoji-video-provider="${t}" isn't recognized — ignored.`),t=void 0),t==="html5")return e&&console.warn(`Shoji: data-shoji-video-id="${e}" ignored — provider html5 has no id.`),Zt(o);const i=Ee("youtube",o,t,e,Te,Le);if(i)return i;const n=Ee("vimeo",o,t,e,Me,xe);return n||(e&&console.warn(`Shoji: data-shoji-video-id="${e}" ignored — data-shoji-video="${o}" isn't a recognized YouTube/Vimeo URL; falling back to html5.`),Zt(o))}function Ee(o,t,e,i,n,s){const r=e===o;if(!r&&!n(t))return;const a=i??s(t);if(!a){if(!r)return Zt(t);console.warn(`Shoji: data-shoji-video-provider="${o}" but no id could be parsed from "${t}".`)}return{video:{provider:o,id:a,url:t}}}const Ce=new Set(["youtu.be","youtube.com","youtube-nocookie.com"]),Se=new Set(["vimeo.com","player.vimeo.com"]);function Ft(o){return o.replace(/^(www|m|music)\./,"")}function Te(o){try{return Ce.has(Ft(new URL(o,window.location.href).hostname))}catch{return!1}}function Me(o){try{return Se.has(Ft(new URL(o,window.location.href).hostname))}catch{return!1}}function Le(o){let t;try{t=new URL(o,window.location.href)}catch{return}const e=Ft(t.hostname);if(e==="youtu.be")return t.pathname.slice(1).split("/")[0]||void 0;if(!Ce.has(e))return;if(t.pathname==="/watch")return t.searchParams.get("v")??void 0;const i=t.pathname.match(/^\/(?:embed|shorts|live|v)\/([^/?]+)/);return i==null?void 0:i[1]}function xe(o){var e;let t;try{t=new URL(o,window.location.href)}catch{return}if(Se.has(Ft(t.hostname)))return(e=t.pathname.match(/\/(\d+)(?:\/|$)/))==null?void 0:e[1]}const Oe=[{provider:"youtube",isHost:Te,detectId:Le},{provider:"vimeo",isHost:Me,detectId:xe}];function je(o){return o.map(t=>{var s,r;if(t.video===!0){const a=Oe.find(c=>c.isHost(t.src)),l=a?{provider:a.provider,id:a.detectId(t.src)}:{provider:"html5"};return(l.provider==="youtube"||l.provider==="vimeo")&&!l.id&&console.warn(`Shoji: item "${t.id??t.src}" has video: true, but no id could be parsed from src ("${t.src}") — the embed won't load. Use an explicit video.id instead.`),{...t,video:l}}const e=t,i=(s=e.video)==null?void 0:s.provider;if(i!=="youtube"&&i!=="vimeo"||e.video&&"id"in e.video&&e.video.id)return e;const n=Oe.find(a=>a.provider===i).detectId(e.src);return n?{...e,video:{provider:i,id:n,url:(r=e.video)==null?void 0:r.url}}:(console.warn(`Shoji: item "${e.id??e.src}" has video.provider: '${i}' with no id, and src ("${e.src}") isn't a recognized ${i==="youtube"?"YouTube":"Vimeo"} URL — the embed won't load. Set video.id explicitly.`),e)})}function Ao(o){const t=o.split(/[?#]/)[0]??o,e=t.slice(t.lastIndexOf(".")+1).toLowerCase();return e==="webm"?"video/webm":e==="ogg"||e==="ogv"?"video/ogg":"video/mp4"}class Io{constructor(t){p(this,"element");p(this,"slots");p(this,"preload");p(this,"videoProviders");p(this,"dragOffsetPx",0);p(this,"cache",new Map);p(this,"pending",new Map);this.element=document.createElement("div"),this.element.className="shoji-slides",this.preload=t.preload,this.videoProviders=t.videoProviders;const e=t.preload*2+1;this.slots=Array.from({length:e},(i,n)=>{const s=n-t.preload,r=document.createElement("div");r.className="shoji-slide";const a=document.createElement("div");return a.className="shoji-slide-media",r.appendChild(a),this.element.appendChild(r),{root:r,media:a,offset:s,assignedIndex:null,ready:!1}}),this.applyTransforms(null)}getActiveMedia(){var t;return((t=this.slots.find(e=>e.offset===0))==null?void 0:t.media)??null}isActiveReady(){var t;return((t=this.slots.find(e=>e.offset===0))==null?void 0:t.ready)??!1}setDragOffset(t,e){this.dragOffsetPx=t,this.applyTransforms(e)}getSlotRoot(t){var e;return((e=this.slots.find(i=>i.offset===t))==null?void 0:e.root)??null}applyTransforms(t){for(const e of this.slots)e.root.style.transition=t??"",e.root.style.transform=`translateX(calc(${e.offset*100}% + ${this.dragOffsetPx}px))`}render(t,e,i,n,s=!1){const r=s&&t.length>this.slots.length,a=this.slots.map((v,b)=>{const E=b-this.preload,T=e+E,M=r?(T%t.length+t.length)%t.length:T,C=M>=0&&M<t.length?t[M]:void 0;return{offset:E,index:M,item:C}}),l=new Set(a.map(v=>v.index));for(const[v,b]of this.cache)l.has(v)||(Re(b.node),this.cache.delete(v));const c=new Set,f=new Set;for(const v of a){if(!v.item)continue;const b=this.slots.find(E=>E.assignedIndex===v.index&&E.ready);b&&(c.add(v.index),f.add(b),b.offset!==v.offset&&(b.offset=v.offset,i(v.index)))}const y=this.slots.filter(v=>!f.has(v));a.filter(v=>!v.item||!c.has(v.index)).forEach((v,b)=>{var C;const E=y[b];E.offset=v.offset;const{index:T,item:M}=v;if(!M){E.assignedIndex=null,E.ready=!1,Nt(E.media),E.media.replaceChildren();return}if(E.assignedIndex!==T){if(E.assignedIndex=T,E.ready=!1,Nt(E.media),E.media.replaceChildren(Do()),this.applyAspect(E,M),T===e&&n){const R=M.width&&M.height?{width:M.width,height:M.height}:void 0;this.revealOpenPlaceholder(n,E,T,R)}((C=M.video)==null?void 0:C.provider)==="html5"?this.renderVideo(M,E,T,i):M.video?this.renderProviderVideo(M,E,T,i):this.ensureImageDecoding(M,T,i)}}),this.applyTransforms(null)}applyAspect(t,e){e.width&&e.height?t.media.style.aspectRatio=`${e.width} / ${e.height}`:t.media.style.removeProperty("aspect-ratio"),e.video&&e.width&&e.height?t.media.style.setProperty("--shoji-provider-video-aspect",`calc(${e.width} / ${e.height})`):t.media.style.removeProperty("--shoji-provider-video-aspect")}swapIn(t,e,i,n){Nt(t.media),this.applyAspect(t,i),t.media.replaceChildren(e),t.ready=!0,this.cache.set(n,{node:e,item:i})}moveIn(t,e,i){this.applyAspect(t,e.item),t.media.replaceChildren(e.node),t.ready=!0,this.cache.set(i,e)}ensureImageDecoding(t,e,i){if(this.pending.has(e))return;const n=document.createElement("img");n.className="shoji-slide-img",n.alt=t.alt??"",n.draggable=!1,"fetchPriority"in n&&(n.fetchPriority="high"),t.srcset&&(n.srcset=t.srcset),t.sizes&&(n.sizes=t.sizes),n.src=t.src,this.pending.set(e,n);const s=()=>{this.pending.delete(e);const r={node:n,item:t};this.cache.set(e,r);const a=this.slots.find(l=>l.assignedIndex===e);a&&(this.moveIn(a,r,e),i(e))};typeof n.decode=="function"?n.decode().then(s,s):(n.addEventListener("load",s,{once:!0}),n.addEventListener("error",s,{once:!0}))}revealOpenPlaceholder(t,e,i,n){const s=ko(t),r=()=>{if(!(e.assignedIndex!==i||e.ready)&&(e.media.querySelectorAll(".shoji-slide-spinner, .shoji-slide-provider-poster").forEach(a=>a.remove()),e.media.appendChild(s),n)){const a=e.root.getBoundingClientRect(),l=pe({left:0,top:0,width:a.width,height:a.height},n.width/n.height,n);s.style.width=`${l.width}px`,s.style.height=`${l.height}px`}};typeof s.decode=="function"?s.decode().then(r,r):(s.addEventListener("load",r,{once:!0}),s.addEventListener("error",r,{once:!0}))}renderVideo(t,e,i,n){if(!(!!t.src||!!(t.sources&&t.sources.length>0))){const l=document.createElement("div");l.className="shoji-slide-placeholder",l.textContent="Video",this.swapIn(e,l,t,i),n(i);return}const r=document.createElement("video");if(r.className="shoji-slide-video",r.controls=!0,r.playsInline=!0,r.draggable=!1,t.poster&&(r.poster=t.poster),t.width&&t.height&&(r.style.aspectRatio=`${t.width} / ${t.height}`),t.sources&&t.sources.length>0)for(const l of t.sources){const c=document.createElement("source");c.src=l.src,c.type=l.type,r.appendChild(c)}else r.src=t.src;this.swapIn(e,r,t,i);const a=()=>n(i);r.addEventListener("loadedmetadata",a,{once:!0}),r.addEventListener("error",a,{once:!0})}renderProviderVideo(t,e,i,n){const s=t.video,r=s.provider==="custom"?s.render:this.videoProviders.get(s.provider);if(!r){const g=document.createElement("div");g.className="shoji-slide-placeholder",g.textContent="Video",this.swapIn(e,g,t,i),n(i);return}t.poster&&Pe(e,t.poster);const a=document.createElement("div");a.className="shoji-slide-provider-video",a.hidden=!0;const l=new AbortController;Gt.set(a,l),e.media.appendChild(a);let c=!1;const f=()=>{c||l.signal.aborted||(c=!0,a.hidden=!1,e.media.querySelectorAll(".shoji-slide-spinner, .shoji-slide-open-placeholder, .shoji-slide-provider-poster").forEach(g=>g.remove()),this.applyAspect(e,t),e.ready=!0,this.cache.set(i,{node:a,item:t}),n(i))},y=g=>{t.poster||c||l.signal.aborted||Pe(e,g)};r(a,t,f,l.signal,y)}destroy(){for(const t of this.slots)Nt(t.media),t.media.replaceChildren(),t.assignedIndex=null,t.ready=!1;this.cache.clear(),this.pending.clear(),this.element.remove()}}function Pe(o,t){o.media.querySelectorAll(".shoji-slide-spinner, .shoji-slide-open-placeholder, .shoji-slide-provider-poster").forEach(i=>i.remove());const e=document.createElement("img");e.className="shoji-slide-img shoji-slide-provider-poster",e.alt="",e.draggable=!1,e.src=t,o.media.appendChild(e)}function ko(o){const t=document.createElement("img");return t.className="shoji-slide-img shoji-slide-open-placeholder",t.alt="",t.draggable=!1,t.src=o,t}function Do(){const o=document.createElement("div");return o.className="shoji-slide-spinner",o.setAttribute("aria-hidden","true"),o}const Gt=new WeakMap;function Nt(o){const t=o.querySelector("video");t&&Re(t);const e=o.querySelector(".shoji-slide-provider-video");e&&Ae(e)}function He(o){const t=o==null?void 0:o.querySelector("video");if(t){t.pause();return}const e=o==null?void 0:o.querySelector(".shoji-slide-provider-video");e&&typeof e.pause=="function"&&e.pause()}function Re(o){if(o.tagName!=="VIDEO"){Ae(o);return}const t=o;t.pause(),t.removeAttribute("src"),t.load()}function Ae(o){const t=Gt.get(o);t&&(Gt.delete(o),t.abort())}function Ie(o,t){const e=o.directional?t:1,i=[];o.perspective&&i.push(`perspective(${o.perspective}px)`);const n=o.translateX!==void 0?o.translateX*e:0,s=o.translateY??0;return(n!==0||s!==0)&&i.push(`translate(${n}%, ${s}%)`),o.rotateY!==void 0&&i.push(`rotateY(${o.rotateY*e}deg)`),o.rotateX!==void 0&&i.push(`rotateX(${o.rotateX}deg)`),o.rotateZ!==void 0&&i.push(`rotateZ(${o.rotateZ*e}deg)`),o.scale!==void 0&&i.push(`scale(${o.scale})`),{transform:i.length>0?i.join(" "):"none",opacity:o.opacity??1}}function Z(o){return{name:o.name,enter:t=>Ie(o.enter,t),leave:t=>Ie(o.leave,t)}}const Bo=[Z({name:"slide",enter:{directional:!0,translateX:100},leave:{directional:!0,translateX:-100}}),Z({name:"fade",enter:{opacity:0},leave:{opacity:0}}),Z({name:"zoom",enter:{scale:.6,opacity:0},leave:{scale:1.4,opacity:0}}),Z({name:"deck",enter:{translateY:6,scale:.85,opacity:0},leave:{translateY:-4,scale:.92,opacity:0}}),Z({name:"slideVertical",enter:{directional:!0,translateY:100},leave:{directional:!0,translateY:-100}}),Z({name:"push",enter:{directional:!0,translateX:120},leave:{directional:!0,translateX:-120}}),Z({name:"fadeUp",enter:{translateY:12,opacity:0},leave:{translateY:-12,opacity:0}}),Z({name:"fadeDown",enter:{translateY:-12,opacity:0},leave:{translateY:12,opacity:0}}),Z({name:"fadeLeft",enter:{translateX:-12,opacity:0},leave:{translateX:12,opacity:0}}),Z({name:"fadeRight",enter:{translateX:12,opacity:0},leave:{translateX:-12,opacity:0}}),Z({name:"zoomOut",enter:{scale:1.4,opacity:0},leave:{scale:.6,opacity:0}}),Z({name:"scaleUp",enter:{scale:.7},leave:{scale:1.3}}),Z({name:"scaleDown",enter:{scale:1.3},leave:{scale:.7}}),Z({name:"rotate",enter:{rotateZ:15,opacity:0},leave:{rotateZ:-15,opacity:0}}),Z({name:"rotateLeft",enter:{directional:!0,rotateZ:-25,opacity:0},leave:{directional:!0,rotateZ:25,opacity:0}}),Z({name:"rotateRight",enter:{directional:!0,rotateZ:25,opacity:0},leave:{directional:!0,rotateZ:-25,opacity:0}}),Z({name:"flipX",enter:{rotateX:90,perspective:1200,opacity:0},leave:{rotateX:-90,perspective:1200,opacity:0}}),Z({name:"flipY",enter:{directional:!0,rotateY:90,perspective:1200,opacity:0},leave:{directional:!0,rotateY:-90,perspective:1200,opacity:0}}),Z({name:"cube",enter:{directional:!0,rotateY:70,translateX:40,perspective:1600,opacity:1},leave:{directional:!0,rotateY:-70,translateX:-40,perspective:1600,opacity:1}}),Z({name:"coverflow",enter:{directional:!0,rotateY:35,translateX:60,scale:.8,perspective:1400,opacity:0},leave:{directional:!0,rotateY:-35,translateX:-60,scale:.8,perspective:1400,opacity:0}}),Z({name:"drop",enter:{translateY:-30,opacity:0},leave:{translateY:20,opacity:0}})],Fo=Object.fromEntries(Bo.map(o=>[o.name,o]));function No(){return typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}function ke(o){var e;const t=((e=o.split(",")[0])==null?void 0:e.trim())??"";return t.endsWith("ms")?parseFloat(t):t.endsWith("s")?parseFloat(t)*1e3:0}function De(o,t){const e=getComputedStyle(o),i=Math.max(ke(e.transitionDuration),ke(e.animationDuration));let n=!1;const s=()=>{n||(n=!0,o.removeEventListener("transitionend",r),o.removeEventListener("animationend",r),t())},r=a=>{a.target===o&&s()};o.addEventListener("transitionend",r),o.addEventListener("animationend",r),setTimeout(s,i+100)}function $o(o,t,e){o.style.transition="none",o.style.transformOrigin="center",o.style.transform=t,o.style.opacity=String(e),o.offsetHeight,o.style.transition="transform var(--shoji-duration) var(--shoji-easing), opacity var(--shoji-duration) var(--shoji-easing)",o.style.transform="none",o.style.opacity="1"}function Vo(o,t,e){o.style.transformOrigin="center",o.style.transition="transform var(--shoji-duration) var(--shoji-easing), opacity var(--shoji-duration) var(--shoji-easing)",o.offsetHeight,o.style.transform=t,o.style.opacity=String(e)}function Yo(o){o.style.transition="",o.style.transform="",o.style.opacity="",o.style.transformOrigin=""}class Wo{constructor(t,e=()=>()=>{}){this.slides=t,this.decorateLeave=e}animate(t,e,i){this.run(i,(n,s)=>{const r=t.leave(e);Vo(n,r.transform,r.opacity);const a=t.enter(e);$o(s,a.transform,a.opacity)})}animateCustom(t,e,i){const n=e===1?"next":"prev";this.run(i,(s,r)=>{s.dataset.shojiDirection=n,s.classList.add(`shoji-transition-${t}-leave`),r.dataset.shojiDirection=n,r.classList.add(`shoji-transition-${t}-enter`)},s=>{s.classList.remove(`shoji-transition-${t}-enter`),delete s.dataset.shojiDirection})}run(t,e,i=Yo){if(No()){t();return}const n=this.slides.getActiveMedia();if(!n){t();return}const s=document.createElement("div");s.className="shoji-slide-ghost";const r=s.appendChild(n.cloneNode(!0));this.slides.element.appendChild(s);const a=this.decorateLeave(r);s.offsetHeight,t();const l=this.slides.getActiveMedia();if(!l){s.remove();return}e(s,l),a(),De(s,()=>s.remove()),De(l,()=>i(l))}}function Ut(o){return o.id??o.src}function zo(o){if(typeof o!="string")return o;const t=document.querySelector(o);if(!t)throw new Error(`Shoji: no element matches selector "${o}"`);return t}const $t=new WeakMap,Kt=new Set,Be={close:"Close",previous:"Previous image",next:"Next image",showCaption:"Show caption",hideCaption:"Hide caption",fullCaption:"Full caption",moreControls:"More controls"};function _o(o,t){if(o.composedPath().some(i=>i instanceof Element&&i.matches(`.shoji-slide-img, .shoji-video-mount, iframe, .shoji-counter, ${wo}`)))return!1;if(t&&!t.hidden&&t.classList.contains("shoji-caption--video")){const i=t.getBoundingClientRect();if(o.clientX>=i.left&&o.clientX<=i.right&&o.clientY>=i.top&&o.clientY<=i.bottom)return!1}return!0}function Xo(o){return typeof o=="object"&&o!==null&&typeof o.dangerouslySetInnerHTML=="string"}class qo{constructor(t,e={}){p(this,"options",{});p(this,"element");p(this,"bus",new eo);p(this,"selector",Xt);p(this,"isDynamicMode",!1);p(this,"preload",1);p(this,"locale",Be);p(this,"showCounter",!0);p(this,"captionVisibleOnVideo",!1);p(this,"captionFadePending",!1);p(this,"loop",!0);p(this,"closable",!0);p(this,"autoHideDelay",5e3);p(this,"maxPinnedToolbarButtons",2);p(this,"focusTrap",new co);p(this,"liveRegion",new xo);p(this,"autoHideTimer",null);p(this,"autoHidden",!1);p(this,"hoverableElements",new Set);p(this,"hoveringElements",new Set);p(this,"isClosing",!1);p(this,"controlsHiddenByDrag",!1);p(this,"itemList",[]);p(this,"scannedElements",[]);p(this,"activeIndex",0);p(this,"opened",!1);p(this,"destroyed",!1);p(this,"slides",null);p(this,"dom",null);p(this,"gesture",null);p(this,"transition",null);p(this,"toolbarHeightObserver",null);p(this,"toolbarHeightFrame",null);p(this,"captionTruncationFrame",null);p(this,"captionModalOpen",!1);p(this,"captionModalReturnFocus",null);p(this,"captionModalOpenedViaKeyboard",!1);p(this,"pluginToolbarButtons",[]);p(this,"toolbarOverflowOpen",!1);p(this,"toolbarOverflowReturnFocus",null);p(this,"shortcuts",new Map);p(this,"pluginStorage",new Map);p(this,"activePluginNames",new Set);p(this,"videoProviders",new Map);p(this,"zoomGate",null);p(this,"zoomStartProvider",null);p(this,"slideLeaveDecorators",new Set);p(this,"pluginCleanups",[]);p(this,"onContainerClick",t=>{let e=t.target;for(;e&&e!==this.element;){if(e instanceof HTMLElement){const i=this.scannedElements.indexOf(e);if(i!==-1){t.preventDefault(),this.open(i);return}}e=e.parentNode}});p(this,"onOuterClick",t=>{var e;this.closable&&_o(t,((e=this.dom)==null?void 0:e.caption)??null)&&this.close()});p(this,"onActivity",()=>{this.reconcileHover(),!(this.autoHideDelay===0||this.autoHideDelay===!1||this.isClosing||this.controlsHiddenByDrag||this.captionModalOpen)&&(this.showControls(),this.scheduleAutoHide())});p(this,"controlsHiddenAtGestureStart",!1);p(this,"captureGestureStartState",()=>{this.controlsHiddenAtGestureStart=this.autoHidden});p(this,"onKeydown",t=>{if(!(document.activeElement instanceof HTMLVideoElement&&t.key!=="Escape")){switch(this.onActivity(),t.key){case"Escape":this.closable&&this.close();break;case"ArrowLeft":case"a":case"A":this.prev();break;case"ArrowRight":case"d":case"D":this.next();break;case"Home":this.goTo(0);break;case"End":this.goTo(this.itemList.length-1);break;default:{const e=this.shortcuts.get(t.key);if(!e)return;e(t)}}t.preventDefault()}});p(this,"onCaptionModalKeydown",t=>{t.stopPropagation(),t.key==="Escape"&&this.closeCaptionModal()});p(this,"onToolbarOverflowKeydown",t=>{t.stopPropagation(),t.key==="Escape"&&this.closeToolbarOverflow()});p(this,"onCaptionActivate",t=>{var e;if((e=this.dom)!=null&&e.caption.classList.contains("shoji-caption--truncated")){if(this.captionModalOpenedViaKeyboard=t instanceof KeyboardEvent,t instanceof KeyboardEvent){if(t.key!=="Enter"&&t.key!==" ")return;t.preventDefault(),t.stopPropagation()}else{const i=window.getSelection();if(i&&!i.isCollapsed||t.target instanceof Element&&t.target.closest("a, button"))return}this.openCaptionModal()}});this.element=zo(t),$t.set(this.element,this),Kt.add(this),this.applyOptions(e)}static getInstance(t){return $t.get(t)}static instances(){return Kt.values()}applyOptions(t){if(this.options=t,this.selector=t.selector??Xt,this.isDynamicMode=t.items!==void 0,this.preload=t.preload??1,this.locale={...Be,...t.locale},this.showCounter=t.counter??!0,this.loop=t.loop??!0,this.closable=t.closable??!0,this.autoHideDelay=t.autoHideDelay??5e3,this.maxPinnedToolbarButtons=t.maxPinnedToolbarButtons??2,this.activeIndex=0,this.scannedElements=[],this.isDynamicMode)this.itemList=je(t.items??[]);else{const e=we(this.element,this.selector);this.itemList=e.map(i=>i.item),this.scannedElements=e.map(i=>i.element),this.element.addEventListener("click",this.onContainerClick)}this.ensureLightbox(),this.dom.closeButton.hidden=!this.closable,t.openOnInit&&this.itemList.length>0&&this.open(t.index??0)}get items(){return this.itemList}get currentIndex(){return this.activeIndex}get isOpen(){return this.opened}get isDestroyed(){return this.destroyed}get controlsHidden(){return this.autoHidden}getActivePlugins(){return[...this.activePluginNames]}getActiveMedia(){var t;return((t=this.slides)==null?void 0:t.getActiveMedia())??null}registerZoomGate(t){return this.zoomGate=t,()=>{this.zoomGate===t&&(this.zoomGate=null)}}registerZoomStartProvider(t){return this.zoomStartProvider=t,()=>{this.zoomStartProvider===t&&(this.zoomStartProvider=null)}}registerSlideLeaveDecorator(t){return this.slideLeaveDecorators.add(t),()=>{this.slideLeaveDecorators.delete(t)}}on(t,e){return this.bus.on(t,e)}clampToRange(t){return Math.min(Math.max(t,0),Math.max(this.itemList.length-1,0))}ensureLightbox(){if(this.dom)return;this.slides=new Io({preload:this.preload,videoProviders:this.videoProviders}),this.transition=new Wo(this.slides,e=>{const i=[];for(const n of this.slideLeaveDecorators){const s=n(e);s&&i.push(s)}return()=>{for(const n of i)n()}});const t=ao(this.slides.element,this.locale);if(this.dom=t,this.options.backdropOpacity!=null){const e=Math.min(Math.max(this.options.backdropOpacity,0),1);t.outer.style.setProperty("--shoji-backdrop-opacity",String(e))}if(this.options.transitionDuration!=null){const e=Math.max(this.options.transitionDuration,0);t.outer.style.setProperty("--shoji-duration",`${e}ms`)}this.autoHideDelay===0&&t.dialog.classList.add("shoji-cursor-visible"),t.outer.appendChild(this.liveRegion.element),t.closeButton.addEventListener("click",()=>this.close()),t.prevButton.addEventListener("click",()=>this.prev()),t.nextButton.addEventListener("click",()=>this.next()),t.captionToggleButton.addEventListener("click",()=>{this.captionVisibleOnVideo=!this.captionVisibleOnVideo,this.updateCaptionVisibility()}),t.caption.addEventListener("click",this.onCaptionActivate),t.caption.addEventListener("keydown",this.onCaptionActivate),t.captionModalCloseButton.addEventListener("click",()=>this.closeCaptionModal()),t.captionModal.addEventListener("click",e=>{e.stopPropagation(),e.target===t.captionModal&&this.closeCaptionModal()}),t.toolbarOverflowButton.addEventListener("click",e=>{e.stopPropagation(),this.toggleToolbarOverflow()}),t.outer.addEventListener("click",e=>{!this.toolbarOverflowOpen||e.composedPath().some(n=>n===t.toolbarOverflowPanel||n===t.toolbarOverflowButton)||(e.stopPropagation(),this.closeToolbarOverflow())}),t.outer.addEventListener("click",this.onOuterClick),t.outer.addEventListener("pointermove",this.onActivity,{passive:!0}),t.outer.addEventListener("pointerdown",this.captureGestureStartState,{passive:!0}),t.outer.addEventListener("pointerdown",this.onActivity,{passive:!0}),t.outer.addEventListener("touchstart",this.onActivity,{passive:!0}),t.outer.addEventListener("wheel",this.onActivity,{passive:!0}),t.outer.addEventListener("focusin",this.onActivity),t.outer.addEventListener("focusout",()=>this.scheduleAutoHide());for(const e of[t.closeButton,t.prevButton,t.nextButton,t.captionToggleButton,t.caption,t.captionModalPanel,t.counter,t.toolbarLeft,t.toolbarCenter,t.toolbarRight])this.wireControlHover(e);document.body.appendChild(t.outer),this.toolbarHeightObserver=new ResizeObserver(()=>this.scheduleToolbarOverflowMeasure()),this.toolbarHeightObserver.observe(t.toolbar),this.gesture=new Lo({dialog:t.dialog,caption:t.caption,slides:this.slides,canGoNext:()=>this.loop||this.activeIndex<this.itemList.length-1,canGoPrev:()=>this.loop||this.activeIndex>0,next:()=>this.navigate(this.nextIndex(),1,!1),prev:()=>this.navigate(this.prevIndex(),-1,!1),close:()=>this.close(),closeFromSwipe:e=>this.closeFromSwipe(e),setControlsHiddenForDrag:e=>this.setControlsHiddenForDrag(e),canClose:()=>this.closable,onActivity:()=>this.onActivity(),isZoomed:()=>{var e;return(((e=this.zoomGate)==null?void 0:e.call(this))??!1)||this.captionModalOpen||this.toolbarOverflowOpen}},{onTap:(e,i)=>this.bus.emit("tap",{x:e,y:i,controlsWereHidden:this.controlsHiddenAtGestureStart}),onDoubleTap:(e,i)=>this.bus.emit("doubleTap",{x:e,y:i}),onPinchStart:(e,i)=>this.bus.emit("pinchStart",{centerX:e,centerY:i}),onPinchMove:(e,i,n)=>this.bus.emit("pinchMove",{scale:e,centerX:i,centerY:n}),onPinchEnd:()=>this.bus.emit("pinchEnd",{}),onWheelZoom:(e,i,n)=>this.bus.emit("wheelZoom",{deltaScale:e,x:i,y:n})},this.options.gestures),this.initPlugins()}resolveValidPluginNames(t){const e=new Set;for(const n of t)n&&typeof n.init=="function"&&e.add(n.name);let i=!0;for(;i;){i=!1;for(const n of t){if(!n||typeof n.init!="function"||!e.has(n.name))continue;(n.requires??[]).some(r=>!e.has(r))&&(e.delete(n.name),i=!0)}}return e}initPlugins(){this.activePluginNames.clear(),this.videoProviders.clear();const t=this.options.plugins??[],e=this.resolveValidPluginNames(t);for(const i of t){if(!i||typeof i.init!="function"){console.error("Shoji: skipping an invalid plugins[] entry (not a ShojiPlugin object):",i);continue}if(!e.has(i.name)){const a=(i.requires??[]).filter(l=>!e.has(l));console.error(`Shoji: plugin "${i.name}" requires [${a.join(", ")}], which failed to load (missing, invalid, or itself had an unmet requires) — skipping.`);continue}const n={...i.defaults,...this.options[i.name]},s={gallery:this,options:n,on:this.on.bind(this),emit:(a,l)=>this.bus.emit(a,l),ui:{toolbar:(a,l)=>this.pluginToolbar(a,l),overlay:(a,l)=>this.pluginOverlay(a,l),outer:()=>this.dom.outer,registerShortcut:(a,l)=>(this.shortcuts.set(a,l),()=>this.shortcuts.delete(a)),registerVideoProvider:(a,l)=>(this.videoProviders.set(a,l),()=>{this.videoProviders.get(a)===l&&this.videoProviders.delete(a)})},storage:{get:a=>this.pluginStorage.get(a),set:(a,l)=>{this.pluginStorage.set(a,l)}}},r=i.init(s);typeof r=="function"&&this.pluginCleanups.push(r),this.activePluginNames.add(i.name)}}pluginToolbar(t,e){const i=this.dom,n=e instanceof HTMLElement,s=n?e:this.buildToolbarButton(e),r=n?this.wireControlHover(s):null;return t==="right"?i.toolbarRight.insertBefore(s,i.toolbarOverflowButton):(t==="left"?i.toolbarLeft:i.toolbarCenter).appendChild(s),this.pluginToolbarButtons.push({el:s,slot:t}),this.scheduleToolbarOverflowMeasure(),()=>{r==null||r(),s.remove();const a=this.pluginToolbarButtons.findIndex(l=>l.el===s);a!==-1&&this.pluginToolbarButtons.splice(a,1),this.scheduleToolbarOverflowMeasure()}}buildToolbarButton(t){const e=document.createElement("button");return e.type="button",e.className="shoji-toolbar-button",t.icon?(e.ariaLabel=e.title=t.label,e.innerHTML=t.icon):e.textContent=t.label,e.addEventListener("click",t.onClick),this.wireControlHover(e),e}scheduleToolbarOverflowMeasure(){this.toolbarHeightFrame===null&&(this.toolbarHeightFrame=requestAnimationFrame(()=>{this.toolbarHeightFrame=null,this.dom&&(this.measureToolbarOverflow(),this.dom.dialog.style.setProperty("--shoji-toolbar-height",`${this.dom.toolbar.getBoundingClientRect().height}px`))}))}measureToolbarOverflow(){if(!this.dom)return;const t=this.dom;for(const{el:s,slot:r}of this.pluginToolbarButtons)r==="right"?t.toolbarRight.insertBefore(s,t.toolbarOverflowButton):(r==="left"?t.toolbarLeft:t.toolbarCenter).appendChild(s);t.toolbarOverflowPanel.replaceChildren(),t.toolbarOverflowButton.hidden=!0,this.toolbarOverflowOpen&&this.closeToolbarOverflow();const e=t.closeButton.getBoundingClientRect().height,i=()=>[t.toolbarLeft,t.toolbarCenter,t.toolbarRight].every(s=>s.getBoundingClientRect().height<=e+1);if(i())return;const n=Math.min(this.maxPinnedToolbarButtons,this.pluginToolbarButtons.length);t.toolbarOverflowButton.hidden=!1;for(let s=this.pluginToolbarButtons.length-1;s>=0&&!(s<n&&i());s--)t.toolbarOverflowPanel.insertBefore(this.pluginToolbarButtons[s].el,t.toolbarOverflowPanel.firstChild)}toggleToolbarOverflow(){this.toolbarOverflowOpen?this.closeToolbarOverflow():this.openToolbarOverflow()}openToolbarOverflow(){!this.dom||this.toolbarOverflowOpen||(this.toolbarOverflowReturnFocus=document.activeElement,this.dom.toolbarOverflowPanel.hidden=!1,this.positionToolbarOverflowPanel(),this.dom.toolbarOverflowButton.setAttribute("aria-expanded","true"),this.toolbarOverflowOpen=!0,this.focusTrap.retarget(this.dom.toolbarOverflowPanel),document.addEventListener("keydown",this.onToolbarOverflowKeydown,!0))}positionToolbarOverflowPanel(){if(!this.dom)return;const{dialog:t,toolbarOverflowButton:e,toolbarOverflowPanel:i,toolbarRight:n,captionToggleButton:s}=this.dom,r=t.getBoundingClientRect().right,a=e.getBoundingClientRect().right,l=parseFloat(getComputedStyle(i).paddingRight)||0,c=r-a-l;i.style.right=`${Math.max(0,c)}px`;const y=this.pluginToolbarButtons.filter(g=>g.slot==="right"&&g.el.parentElement===n&&!g.el.hidden).length+(s.hidden?0:1)+1;i.style.gridTemplateColumns=`repeat(${y}, 44px)`}closeToolbarOverflow(){var t;!this.dom||!this.toolbarOverflowOpen||(document.removeEventListener("keydown",this.onToolbarOverflowKeydown,!0),this.dom.toolbarOverflowPanel.hidden=!0,this.dom.toolbarOverflowButton.setAttribute("aria-expanded","false"),this.toolbarOverflowOpen=!1,this.focusTrap.retarget(this.dom.dialog),(t=this.toolbarOverflowReturnFocus)==null||t.focus({preventScroll:!0}),this.toolbarOverflowReturnFocus=null)}pluginOverlay(t,e){e!==void 0&&(t.style.zIndex=String(e)),this.dom.dialog.appendChild(t);const i=this.wireControlHover(t);return()=>{i(),t.remove()}}wireControlHover(t){this.hoverableElements.add(t);const e=()=>{this.hoveringElements.add(t),this.onActivity()},i=()=>{this.hoveringElements.delete(t)&&this.scheduleAutoHide()};return t.addEventListener("pointerenter",e),t.addEventListener("pointerleave",i),()=>{t.removeEventListener("pointerenter",e),t.removeEventListener("pointerleave",i),this.hoverableElements.delete(t),this.hoveringElements.delete(t)&&this.scheduleAutoHide()}}isControlActive(){return this.hoveringElements.size>0}reconcileHover(){for(const t of this.hoverableElements)t.matches(":hover")?this.hoveringElements.add(t):this.hoveringElements.delete(t)}getOriginElement(t){const e=this.itemList[t];if(e!=null&&e.id&&typeof CSS<"u"&&typeof CSS.escape=="function"){const i=document.querySelector(`[data-shoji-id="${CSS.escape(e.id)}"]`);if(i)return i}return this.scannedElements[t]??null}scheduleAutoHide(){if(this.autoHideTimer!==null&&(clearTimeout(this.autoHideTimer),this.autoHideTimer=null),!!this.opened&&this.autoHideDelay!==!1){if(this.autoHideDelay===0){this.hideControls();return}this.autoHideTimer=setTimeout(()=>this.hideControls(),this.autoHideDelay)}}hideControls(){this.reconcileHover(),!(!this.dom||this.autoHidden||this.isControlActive()||this.autoHideDelay===!1||this.captionModalOpen||this.toolbarOverflowOpen)&&(this.autoHidden=!0,this.dom.dialog.classList.add("shoji-controls-hidden"),this.bus.emit("controls:hide",{}))}showControls(){!this.dom||!this.autoHidden||(this.autoHidden=!1,this.dom.dialog.classList.remove("shoji-controls-hidden","shoji-controls-hidden-for-close"),this.bus.emit("controls:show",{}))}renderCaption(t,e){return e instanceof HTMLElement?(t.replaceChildren(e),!1):Xo(e)?(t.innerHTML=e.dangerouslySetInnerHTML,e.dangerouslySetInnerHTML===""):(t.textContent=e??"",!e)}setSlideLoading(t){if(this.dom){this.dom.outer.classList.toggle("shoji-slide-loading",t);for(const e of this.dom.outer.querySelectorAll(".shoji-toolbar-button"))e.ariaDisabled=t?"true":null,t?e.tabIndex=-1:e.removeAttribute("tabindex")}}transitionCaption(){var s;const t=this.dom;if(!t||typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches)return;const e=((s=getComputedStyle(t.caption).transitionDuration.split(",")[0])==null?void 0:s.trim())??"",n=(e.endsWith("ms")?parseFloat(e):e.endsWith("s")?parseFloat(e)*1e3:0)/2;this.captionFadePending=!0,t.caption.style.transitionDuration=`${n}ms`,t.caption.style.opacity="0",setTimeout(()=>{this.dom&&(this.captionFadePending=!1,this.updateCaptionVisibility(),this.dom.caption.style.opacity="",setTimeout(()=>{this.dom&&(this.dom.caption.style.transitionDuration="")},n))},n)}updateCaptionVisibility(){if(!this.dom||!this.slides)return;const t=this.itemList[this.activeIndex],e=this.renderCaption(this.dom.caption,t==null?void 0:t.caption),i=!!(t!=null&&t.video);this.dom.caption.classList.toggle("shoji-caption--video",i);const n=i&&!this.captionVisibleOnVideo;this.dom.caption.hidden=e||!this.slides.isActiveReady()||n;const s=this.dom.captionToggleButton;s.hidden=!i||e,s.hidden||(s.setAttribute("aria-pressed",String(this.captionVisibleOnVideo)),s.ariaLabel=s.title=this.captionVisibleOnVideo?this.locale.hideCaption:this.locale.showCaption),this.updateCaptionTruncation(),this.captionTruncationFrame!==null&&cancelAnimationFrame(this.captionTruncationFrame),this.captionTruncationFrame=requestAnimationFrame(()=>{this.captionTruncationFrame=null,this.updateCaptionTruncation()})}updateCaptionTruncation(){if(!this.dom)return;const t=this.dom.caption;t.style.removeProperty("max-height");const e=!t.hidden&&t.scrollHeight>t.clientHeight;if(e){const i=parseFloat(getComputedStyle(t).paddingBottom)||0,n=t.clientHeight-i,s=t.getBoundingClientRect().top,r=document.createRange();r.selectNodeContents(t);let a=0,l=1/0;for(const g of r.getClientRects()){if(g.height===0)continue;const v=g.top-s,b=g.bottom-s;b<=n?b>a&&(a=b):v<l&&(l=v)}const f=(a>0?a:n)+i,y=Number.isFinite(l)?Math.min(f,l):f;t.style.maxHeight=`${Math.max(0,Math.floor(y)-1)}px`}t.classList.toggle("shoji-caption--truncated",e),e?(t.tabIndex=0,t.setAttribute("role","button"),t.setAttribute("aria-haspopup","dialog")):(t.removeAttribute("tabindex"),t.removeAttribute("role"),t.removeAttribute("aria-haspopup"),this.captionModalOpen&&this.closeCaptionModal())}openCaptionModal(){if(!this.dom||this.captionModalOpen)return;const t=this.itemList[this.activeIndex];this.renderCaption(this.dom.captionModalContent,t==null?void 0:t.caption),this.dom.captionModal.hidden=!1,this.captionModalReturnFocus=document.activeElement,this.dom.caption.hidden=!0,this.hoveringElements.clear(),this.captionModalOpen=!0,this.focusTrap.retarget(this.dom.captionModalPanel),document.addEventListener("keydown",this.onCaptionModalKeydown,!0),this.bus.emit("captionModalChange",{open:!0})}closeCaptionModal(){var t;!this.dom||!this.captionModalOpen||(document.removeEventListener("keydown",this.onCaptionModalKeydown,!0),this.dom.captionModal.hidden=!0,this.captionModalOpen=!1,this.updateCaptionVisibility(),this.focusTrap.retarget(this.dom.dialog),this.captionModalOpenedViaKeyboard&&((t=this.captionModalReturnFocus)==null||t.focus({preventScroll:!0})),this.captionModalReturnFocus=null,this.captionModalOpenedViaKeyboard=!1,this.onActivity(),this.bus.emit("captionModalChange",{open:!1}))}renderCurrentSlide(t){if(!this.slides||!this.dom)return;const e=this.dom;this.slides.render(this.itemList,this.activeIndex,r=>{r===this.activeIndex&&(this.bus.emit("slideItemLoad",{index:r}),this.setSlideLoading(!1),this.captionFadePending||this.updateCaptionVisibility())},t,this.loop),this.setSlideLoading(!this.slides.isActiveReady());const i=this.itemList[this.activeIndex],n=this.itemList.length;e.counter.textContent=n>0?`${this.activeIndex+1} / ${n}`:"",e.counter.hidden=!this.showCounter||n===0,this.captionFadePending||this.updateCaptionVisibility();const s=`Image ${this.activeIndex+1} of ${n}${i!=null&&i.alt?`: ${i.alt}`:""}`;this.liveRegion.announce(s),e.prevButton.hidden=n<=1,e.nextButton.hidden=n<=1,e.prevButton.disabled=!this.loop&&this.activeIndex<=0,e.nextButton.disabled=!this.loop&&this.activeIndex>=n-1}open(t=this.options.index??0){var r,a;if(this.destroyed||this.opened)return;this.bus.emit("beforeOpen",{index:t}),this.ensureLightbox(),this.opened=!0,this.activeIndex=t,this.captionVisibleOnVideo=!!this.options.showVideoCaption,Qe();const e=this.getOriginElement(t),i=this.resolveNaturalSize(t),n=!!(e&&i)&&!(typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches);n&&this.dom&&(this.captionFadePending=!0,this.dom.caption.style.opacity="0"),this.renderCurrentSlide(i&&!((r=this.itemList[t])!=null&&r.video)?this.resolveOpenPlaceholderSrc(this.itemList[t],e):void 0),this.dom.outer.classList.add("shoji-open"),document.addEventListener("keydown",this.onKeydown),this.focusTrap.activate(this.dom.dialog),this.scheduleAutoHide();const s=(a=this.slides)==null?void 0:a.getActiveMedia();s&&e&&i&&go({origin:e,target:s,aspectRatio:this.resolveAspectRatio(t,e),naturalSize:i}),n&&this.dom&&(this.captionFadePending=!1,this.updateCaptionVisibility(),this.dom.caption.style.opacity=""),this.bus.emit("open",{index:t}),this.bus.emit("afterOpen",{index:t})}resolveOpenPlaceholderSrc(t,e){if(t!=null&&t.thumb)return t.thumb;const i=e==null?void 0:e.getAttribute("data-shoji-thumb");if(i)return i;const n=e==null?void 0:e.querySelector("img");return(n==null?void 0:n.currentSrc)||(n==null?void 0:n.src)||void 0}goTo(t,e){if(this.destroyed||!this.opened||this.itemList.length===0)return;const i=this.clampToRange(t);if(i===this.activeIndex)return;const n=i>this.activeIndex?1:-1;this.navigate(i,n,(e==null?void 0:e.animate)??!0)}next(){this.navigate(this.nextIndex(),1,!0)}prev(){this.navigate(this.prevIndex(),-1,!0)}nextIndex(){return this.activeIndex>=this.itemList.length-1&&this.loop?0:this.activeIndex+1}prevIndex(){return this.activeIndex<=0&&this.loop?this.itemList.length-1:this.activeIndex-1}navigate(t,e,i){var r;if(this.destroyed||!this.opened||this.itemList.length===0)return;const n=this.clampToRange(t);if(n===this.activeIndex)return;this.captionModalOpen&&this.closeCaptionModal(),this.toolbarOverflowOpen&&this.closeToolbarOverflow();const s=this.activeIndex;if(this.bus.emit("beforeSlide",{from:s,to:n}),He(((r=this.slides)==null?void 0:r.getActiveMedia())??null),this.activeIndex=n,i&&this.transition){this.transitionCaption();const a=()=>this.renderCurrentSlide(),l=this.resolveTransitionMode(),c=Fo[l];c?this.transition.animate(c,e,a):this.transition.animateCustom(l,e,a)}else this.renderCurrentSlide();this.bus.emit("afterSlide",{from:s,to:n})}resolveTransitionMode(){return this.options.mode??"slide"}close(){this.beginClose()}closeFromSwipe(t){this.beginClose(t)}beginClose(t){var r,a,l;if(this.destroyed||!this.opened||this.isClosing)return;this.captionModalOpen&&this.closeCaptionModal(),this.toolbarOverflowOpen&&this.closeToolbarOverflow();const e=((r=this.zoomStartProvider)==null?void 0:r.call(this))??void 0;this.bus.emit("beforeClose",{}),this.isClosing=!0;const i=(a=this.slides)==null?void 0:a.getActiveMedia();He(i??null);const n=this.getOriginElement(this.activeIndex),s=this.resolveNaturalSize(this.activeIndex);if(i&&n&&((l=this.slides)!=null&&l.isActiveReady()||s)){const c=this.resolveAspectRatio(this.activeIndex,n);this.forceHideControls(),this.dom&&(this.dom.backdrop.style.opacity="0"),vo({origin:n,target:i,aspectRatio:c,naturalSize:s,dragStart:t,zoomStart:e},()=>this.finishClose())}else this.finishClose()}forceHideControls(){!this.dom||this.autoHidden||(this.autoHidden=!0,this.dom.dialog.classList.add("shoji-controls-hidden","shoji-controls-hidden-for-close"),this.bus.emit("controls:hide",{}))}setControlsHiddenForDrag(t){var e;this.controlsHiddenByDrag=t,t?this.forceHideControls():this.controlsHiddenAtGestureStart||this.showControls(),(e=this.dom)==null||e.dialog.classList.toggle("shoji-controls-hidden-for-drag",t),this.bus.emit("dragCloseThreshold",{hidden:t})}resolveAspectRatio(t,e){const i=this.itemList[t];if(i!=null&&i.width&&i.height)return i.width/i.height;const n=e==null?void 0:e.querySelector("img");if(n!=null&&n.naturalWidth&&n.naturalHeight)return n.naturalWidth/n.naturalHeight}resolveNaturalSize(t){const e=this.itemList[t];return e!=null&&e.width&&e.height?{width:e.width,height:e.height}:void 0}finishClose(){var t,e,i;this.opened&&(this.isClosing=!1,this.opened=!1,to(),document.removeEventListener("keydown",this.onKeydown),this.focusTrap.deactivate(),(t=this.dom)==null||t.outer.classList.remove("shoji-open"),this.dom&&(this.dom.backdrop.style.opacity=""),this.autoHideTimer!==null&&(clearTimeout(this.autoHideTimer),this.autoHideTimer=null),this.autoHidden=!1,this.hoveringElements.clear(),this.controlsHiddenByDrag=!1,(e=this.dom)==null||e.dialog.classList.remove("shoji-controls-hidden","shoji-controls-hidden-for-close"),(i=this.dom)==null||i.dialog.classList.remove("shoji-controls-hidden-for-drag"),this.bus.emit("close",{}),this.bus.emit("afterClose",{}))}updateSlides(t,e){if(this.destroyed)return;const i=this.itemList[this.activeIndex],n=i?Ut(i):void 0;this.itemList=je(t);let s=e;if(s===void 0&&n!==void 0){const r=t.findIndex(a=>Ut(a)===n);r!==-1&&(s=r)}this.activeIndex=Math.min(Math.max(s??this.activeIndex,0),Math.max(t.length-1,0)),this.opened&&this.renderCurrentSlide(),this.bus.emit("itemsUpdated",{items:this.itemList})}addSlides(t,e){if(this.destroyed)return;const i=[...this.itemList];i.splice(e??i.length,0,...t),this.updateSlides(i)}removeSlides(t){if(this.destroyed)return;const e=Array.isArray(t)?t:[t],i=new Set(e.filter(r=>typeof r=="number")),n=new Set(e.filter(r=>typeof r=="string")),s=this.itemList.filter((r,a)=>!i.has(a)&&!n.has(Ut(r)));this.updateSlides(s)}refresh(){if(this.destroyed)return;if(this.isDynamicMode){console.warn("Shoji: refresh() is a no-op in dynamic mode — call updateSlides() instead.");return}const t=we(this.element,this.selector);this.scannedElements=t.map(e=>e.element),this.updateSlides(t.map(e=>e.item))}teardown(){var t,e,i,n;this.opened&&(this.captionModalOpen&&this.closeCaptionModal(),this.toolbarOverflowOpen&&this.closeToolbarOverflow(),this.isClosing||this.bus.emit("beforeClose",{}),this.finishClose());for(const s of this.pluginCleanups)s();this.pluginCleanups=[],this.shortcuts.clear(),this.pluginStorage.clear(),this.activePluginNames.clear(),this.videoProviders.clear(),this.isDynamicMode||this.element.removeEventListener("click",this.onContainerClick),(t=this.gesture)==null||t.destroy(),this.gesture=null,this.transition=null,(e=this.toolbarHeightObserver)==null||e.disconnect(),this.toolbarHeightObserver=null,this.toolbarHeightFrame!==null&&cancelAnimationFrame(this.toolbarHeightFrame),this.toolbarHeightFrame=null,this.captionTruncationFrame!==null&&cancelAnimationFrame(this.captionTruncationFrame),this.captionTruncationFrame=null,this.captionFadePending=!1,(i=this.slides)==null||i.destroy(),(n=this.dom)==null||n.outer.remove(),this.slides=null,this.dom=null,this.hoverableElements.clear(),this.hoveringElements.clear(),this.pluginToolbarButtons.length=0}destroy(){this.destroyed||($t.get(this.element)===this&&$t.delete(this.element),Kt.delete(this),this.teardown(),this.bus.emit("destroy",{}),this.bus.clear(),this.destroyed=!0)}reinit(t=this.options){this.destroyed||(this.teardown(),this.bus.clear(),this.applyOptions(t))}}function Zo(){return typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}const Go={name:"activeThumbnail",defaults:{activeClass:"shoji-thumb-active",scrollIntoView:!0},init(o){const{gallery:t}=o,e=String(o.options.activeClass??"shoji-thumb-active"),i=o.options.scrollIntoView!==!1;let n=null,s=null,r=null;function a(){r!==null&&(clearTimeout(r),r=null)}function l(E){const T=t.getOriginElement(E);return n&&n!==T&&n.classList.remove(e),T&&T.classList.add(e),n=T,T}function c(E){s=E,a();const T=l(E);T&&i&&(r=setTimeout(()=>{r=null;try{Ge(),T.scrollIntoView({block:"nearest",inline:"nearest",behavior:Zo()?"auto":"smooth"})}catch{}},80))}function f(){a(),n==null||n.classList.remove(e),n=null,s=null}const y=o.on("afterOpen",({index:E})=>c(E)),g=o.on("afterSlide",({to:E})=>c(E)),v=o.on("close",f),b=o.on("layoutRender",()=>{s!==null&&l(s)});return()=>{y(),g(),v(),b(),f()}}},Fe='<svg viewBox="0 0 24 24" width="24" height="24" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>',Uo='<svg viewBox="0 0 24 24" width="24" height="24" fill="currentColor"><path d="M7 5h4v14H7zM13 5h4v14h-4z"/></svg>';function Ko(o){const t=o==null?void 0:o.querySelector("video");if(t)return t;const e=o==null?void 0:o.querySelector(".shoji-slide-provider-video");return e&&typeof e.play=="function"?e:null}function Jo(o){const t=o==null?void 0:o.querySelector(".shoji-slide-provider-video");return!!t&&typeof t.play!="function"}const Ne=400,Qo=8,ti={name:"autoplay",defaults:{interval:5e3,showProgress:!0,pauseOnZoom:!0,pauseOnRotateFlip:!0,pauseOnCaptionExpand:!0,pauseOnManualNavigate:!0},init(o){const{gallery:t}=o,e=Number(o.options.interval??5e3),i=o.options.showProgress!==!1,n=o.options.autoStart===!0,s=o.options.pauseOnZoom!==!1,r=o.options.pauseOnRotateFlip!==!1,a=o.options.pauseOnCaptionExpand!==!1,l=o.options.pauseOnManualNavigate!==!1,c=o.options.locale,f=(c==null?void 0:c.play)??"Play slideshow",y=(c==null?void 0:c.pause)??"Pause slideshow";let g=!1,v=null,b=null,E=!1,T=!1,M=!1,C=!1,R=!1;const V=o.ui.outer();function N(d){if(!g)return;const u=t.getActiveMedia();u&&d.target instanceof Node&&u.contains(d.target)&&j()}V.addEventListener("error",N);const P=document.createElement("button");P.type="button",P.className="shoji-toolbar-button shoji-autoplay-toggle",P.setAttribute("aria-label",f),P.title=f,P.innerHTML=Fe;const $=document.createElement("div");$.className="shoji-autoplay-progress",$.hidden=!0;const k=document.createElement("div");k.className="shoji-autoplay-progress-bar",$.appendChild(k);function et(){v!==null&&(clearTimeout(v),v=null)}function pt(){i&&($.hidden=!0,k.style.transition="none",k.style.width="0%")}function dt(d){i&&($.hidden=!1,k.style.transition="none",k.style.width="0%",k.offsetWidth,k.style.transition=`width ${d}ms linear`,k.style.width="100%")}function D(){const d=!g&&(s&&M||r&&C);P.ariaDisabled=d?"true":null,d?P.tabIndex=-1:P.removeAttribute("tabindex")}function Y(d){g=d,P.innerHTML=d?Uo:Fe,P.setAttribute("aria-label",d?y:f),P.title=d?y:f,D()}function H(){g&&j()}function ut(){b!=null&&b.ended||X()}function at(){b&&(b.removeEventListener("ended",H),b.removeEventListener("pause",ut),b=null)}function vt(d,u){d.muted=!0;const m=d.play();m&&typeof m.then=="function"?Ct(d,u,m):yt(d,u)}function yt(d,u){setTimeout(()=>{b!==d||!g||d.paused&&(u>0?vt(d,u-1):j())},Ne)}function Ct(d,u,m){m.catch(()=>{}),setTimeout(()=>{b!==d||!g||d.paused&&(u>0?Ct(d,u-1,m):j())},Ne)}function I(){if(et(),at(),pt(),E=!1,!g)return;const d=t.getActiveMedia(),u=Ko(d);if(u){if(b=u,u.addEventListener("ended",H),u.addEventListener("pause",ut),u instanceof HTMLVideoElement){const m=u.play();m&&typeof m.catch=="function"&&m.catch(L=>{b!==u||!g||(L instanceof DOMException&&L.name==="NotAllowedError"?X():j())})}else vt(u,Qo);return}E=Jo(d),dt(e),v=setTimeout(j,e)}function j(){const d=t.currentIndex;R=!0,t.next(),R=!1,t.currentIndex===d&&X()}function B(){g||(Y(!0),o.emit("autoplayStart",{}),I())}function X(){g&&(Y(!1),et(),pt(),b&&!b.paused&&b.pause(),at(),o.emit("autoplayStop",{}))}function ht(){(s&&M||r&&C)&&X()}function nt(){if(g){X();return}B(),ht()}const jt=o.on("dragCloseThreshold",({hidden:d})=>{d?(T=g,g&&X()):T&&(T=!1,B())}),Pt=1.001,St=o.on("zoomChange",({scale:d})=>{M=d>Pt,s&&M&&g?X():D()}),Tt=o.on("rotateFlipChange",({flipH:d,flipV:u,rotation:m})=>{C=d||u||m!==0,r&&g?X():D()}),bt=o.on("captionModalChange",({open:d})=>{a&&d&&g&&X()});P.addEventListener("click",nt);const ft=o.ui.toolbar("right",P),st=i?o.ui.overlay($):null,Dt=o.ui.registerShortcut(" ",nt),Mt=o.on("beforeSlide",()=>{at()}),Lt=o.on("afterSlide",()=>{M=!1,C=!1,D(),g&&(l&&!R?X():I())}),mt=o.on("slideItemLoad",({index:d})=>{g&&E&&d===t.currentIndex&&I()}),Bt=o.on("requestAutoplayPause",()=>{g&&X()}),Ht=o.on("requestAutoplayStart",()=>{g||(B(),ht())}),wt=o.on("close",()=>X()),Et=o.on("afterOpen",()=>{M=!1,C=!1,D(),n&&B()});return()=>{X(),V.removeEventListener("error",N),ft(),st==null||st(),Dt(),Mt(),Lt(),mt(),Et(),wt(),jt(),St(),Tt(),bt(),Bt(),Ht()}}},$e='<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/></svg>',ei='<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 4v5H4M15 4v5h5M9 20v-5H4M15 20v-5h5"/></svg>';function oi(){return!!(document.fullscreenEnabled||document.webkitFullscreenEnabled)}function ii(){return document.fullscreenElement??document.webkitFullscreenElement??null}function ni(o){var e;const t=o;t.requestFullscreen?t.requestFullscreen().catch(()=>{}):(e=t.webkitRequestFullscreen)==null||e.call(t)}function Jt(){var t;const o=document;document.exitFullscreen?document.exitFullscreen().catch(()=>{}):(t=o.webkitExitFullscreen)==null||t.call(o)}const si={name:"fullscreen",init(o){if(!oi())return;const t=o.ui.outer(),e=o.gallery.options.locale??{},i=e.enterFullscreen??"Enter fullscreen",n=e.exitFullscreen??"Exit fullscreen",s=document.createElement("button");s.type="button",s.className="shoji-toolbar-button",s.innerHTML=$e,s.setAttribute("aria-label",i),s.title=i,s.setAttribute("aria-pressed","false");function r(){return ii()===t}function a(v){s.innerHTML=v?ei:$e,s.setAttribute("aria-label",v?n:i),s.title=v?n:i,s.setAttribute("aria-pressed",String(v))}function l(){r()?Jt():ni(t)}s.addEventListener("click",l);const c=()=>{const v=r();a(v),o.emit("fullscreenChange",{fullscreen:v})};document.addEventListener("fullscreenchange",c),document.addEventListener("webkitfullscreenchange",c);const f=o.ui.toolbar("right",s),y=o.on("close",()=>{r()&&Jt()}),g=o.on("requestFullscreenToggle",l);return()=>{document.removeEventListener("fullscreenchange",c),document.removeEventListener("webkitfullscreenchange",c),f(),y(),g(),r()&&Jt()}}};function ri(o){const{containerWidth:t,gutterX:e,columns:i}=o;if(typeof i=="number")return Math.max(1,Math.floor(i));const n=Math.max(1,Math.floor((t+e)/(o.columnWidth+e))),s=Math.max(1,Math.floor((t+e)/(o.minColumnWidth+e))),r=Math.max(1,Math.ceil((t+e)/(o.maxColumnWidth+e)));return Math.max(r,Math.min(n,s))}function ai(o,t,e){return(o-t*(e-1))/e}function Ve(o,t,e){const i=ri(t),n=ai(t.containerWidth,t.gutterX,i),s=e&&e.length===i?[...e]:new Array(i).fill(0),r=o.map((l,c)=>{const f=t.fill==="ordered"?c%i:li(s),y=l.width>0?n*(l.height/l.width):n,g=f*(n+t.gutterX),v=s[f];return s[f]=v+y+t.gutterY,{x:g,y:v,width:n,height:y}}),a=o.length===0?0:Math.max(...s)-t.gutterY;return{positions:r,columnCount:i,columnWidth:n,columnHeights:s,containerHeight:a}}function li(o){let t=0;for(let e=1;e<o.length;e++)o[e]<o[t]&&(t=e);return t}function ci(o,t){const{containerWidth:e,gutterX:i,gutterY:n,rowHeight:s}=t,r=new Array(o.length);let a=0,l=0,c=0,f=0;function y(b){return b.height>0?s*(b.width/b.height):s}function g(b,E){let T=0;for(let M=b;M<E;M++){const C=y(o[M]);r[M]={x:T,y:a,width:C,height:s},T+=C+i}f++,a+=s+n}for(let b=0;b<o.length;b++){const E=y(o[b]),T=b-l,M=c+(T>0?i:0)+E;T>0&&M>e?(g(l,b),l=b,c=E):c=M}l<o.length&&g(l,o.length);const v=o.length===0?0:a-n;return{positions:r,rowCount:f,containerHeight:v}}function kt(o){return o.width>0&&o.height>0?o.width/o.height:1}function Vt(o,t){const{containerWidth:e,gutterX:i,gutterY:n,rowHeight:s,minRowHeight:r,maxRowHeight:a,lastRow:l}=t,c=new Array(o.length).fill(null),f=[];let y=0,g=0,v=0;function b(C,R,V){return(e-i*(R-C-1))/V}function E(C,R,V){let N=0;for(let P=C;P<R;P++){const $=V*kt(o[P]);c[P]={x:N,y,width:$,height:V},N+=$+i}f.push({start:C,end:R,y,height:V}),y+=V+n}function T(C,R,V){let N=R,P=V,$=!1;for(;N-C>1&&b(C,N,P)<r;){if(N-C===2&&b(C,C+1,kt(o[C]))>a){$=!0;break}N--,P-=kt(o[N])}const k=b(C,N,P),et=(N-C===1||$)&&k<r?k:Math.min(Math.max(k,r),a);return E(C,N,et),N}for(let C=0;C<o.length;C++){v+=kt(o[C]);const R=C-g+1;if(s*v+i*(R-1)>=e){const N=T(g,C+1,v);g=N,v=0;for(let P=N;P<=C;P++)v+=kt(o[P])}}if(g<o.length)if(l==="justify"){let C=g;for(;C<o.length;){let R=0;for(let V=C;V<o.length;V++)R+=kt(o[V]);C=T(C,o.length,R)}}else l==="left"&&E(g,o.length,s);const M=o.length===0?0:Math.max(0,y-n);return{positions:c,containerHeight:M,rows:f}}const di={width:4,height:3};function Ye(o){if(o&&typeof o=="object"){const e=o;return{x:Number(e.x??8),y:Number(e.y??8)}}const t=Number(o??8);return{x:t,y:t}}function We(o){return o.id??o.src}function hi(o,t){if(t.length<=o.length)return!1;for(let e=0;e<o.length;e++)if(We(o[e])!==We(t[e]))return!1;return!0}const ui={name:"layout",defaults:{type:"justified",gutter:8,columns:"auto",columnWidth:240,minColumnWidth:160,maxColumnWidth:480,fill:"shortest",animate:!0,autoMeasure:!0},init(o){const{gallery:t}=o,e=o.options.type??"justified",i=Ye(o.options.gutter),n=Number(o.options.aspectRatio??1),s=o.options.orientation??"vertical",r=o.options.columns??"auto",a=Number(o.options.columnWidth??240),l=Number(o.options.minColumnWidth??160),c=Number(o.options.maxColumnWidth??480),f=o.options.fill??"shortest",y=Number(o.options.rowHeight??220),g=Number(o.options.minRowHeight??120),v=Number(o.options.maxRowHeight??360),b=o.options.lastRow??"justify",E=o.options.animate!==!1,T=o.options.autoMeasure!==!1,M=e==="masonry"&&s==="horizontal",C=o.options.groupBy,R=o.options.renderHeading,V=o.options.headingOverflow??"show",N=o.options.stickyHeadings===!0,P=N&&e==="grid";N&&e!=="grid"&&console.warn("Shoji: layout plugin — stickyHeadings is only implemented for type: 'grid'; ignored (see the option's doc comment)."),C&&M&&console.warn("Shoji: layout plugin — groupBy isn't supported with orientation: 'horizontal'; ignored.");const $=!!C&&!M,k={gutter:i,columns:r,columnWidth:a,minColumnWidth:l,maxColumnWidth:c,fill:f,rowHeight:y,minRowHeight:g,maxRowHeight:v,lastRow:b},et=o.options.breakpoints,pt=et?Object.entries(et).map(([d,u])=>[Number(d),u]).sort((d,u)=>d[0]-u[0]):[];function dt(d){const u=pt.find(([L])=>d<=L);if(!u)return k;const m=u[1];return{gutter:m.gutter!==void 0?Ye(m.gutter):k.gutter,columns:m.columns??k.columns,columnWidth:m.columnWidth??k.columnWidth,minColumnWidth:m.minColumnWidth??k.minColumnWidth,maxColumnWidth:m.maxColumnWidth??k.maxColumnWidth,fill:m.fill??k.fill,rowHeight:m.rowHeight??k.rowHeight,minRowHeight:m.minRowHeight??k.minRowHeight,maxRowHeight:m.maxRowHeight??k.maxRowHeight,lastRow:m.lastRow??k.lastRow}}const D=t.element;D.classList.add("shoji-layout",`shoji-layout--${e}`),E&&D.classList.add("shoji-layout--animate");let Y=[],H=[],ut,at=[],vt=!1;const yt=new WeakMap;function Ct(d){const u=[];for(let m=0;m<d.length;m++){const L=C(d[m]),F=u[u.length-1];!F||F.key!==L?u.push({key:L,startIndex:m,endIndex:m+1}):F.endIndex=m+1}return u}function I(d,u){const m=R?R(d,u):d;let L,F=null;if(typeof m=="string")L=document.createElement("h2"),L.textContent=m;else if(m instanceof HTMLElement)L=m;else{L=document.createElement("h2");const z=document.createElement("span");z.className="shoji-layout-heading-title",z.textContent=m.title,L.appendChild(z);let h=null;m.subtitle&&(h=document.createElement("span"),h.className="shoji-layout-heading-subtitle",h.textContent=m.subtitle,L.appendChild(h)),F={titleEl:z,subtitleEl:h}}return L.classList.add("shoji-layout-heading"),P&&L.classList.add("shoji-layout-heading--sticky"),{root:L,structured:F}}function j(){return H.map((d,u)=>({heading:d,start:d.tileStart,end:u+1<H.length?H[u+1].tileStart:Y.length}))}function B(d){return d.thumb??d.poster??(d.video?void 0:d.src)}function X(d){if(d!=null&&d.width&&d.height)return{width:d.width,height:d.height};const u=d&&yt.get(d);if(u)return u;const m=T&&!!d&&!!B(d);return!vt&&!m&&(vt=!0,console.warn(T?"Shoji: layout plugin — item(s) missing width/height with no measurable thumb/poster/src to auto-measure from either; falling back to a 4:3 placeholder ratio permanently for those.":"Shoji: layout plugin — item(s) missing width/height and autoMeasure is disabled. Masonry/justified positions are computed from aspect ratios up front, never by measuring loaded images (DESIGN.md §5.2 — that causes layout-jump), so items without dimensions fall back to a 4:3 placeholder ratio instead.")),di}function ht(d,u){const m=document.createElement("a");m.className="shoji-layout-tile",d.id&&(m.dataset.shojiId=d.id),m.dataset.shojiIndex=String(u);const L=document.createElement("img");L.src=d.thumb??d.poster??d.src,L.loading="lazy",L.alt=d.alt??"",m.appendChild(L);const F={index:u,root:m,img:L};return m.addEventListener("click",z=>{z.preventDefault(),t.open(F.index)}),F}function nt(d){const u=D.getBoundingClientRect().width,m=dt(u);D.style.setProperty("--shoji-layout-column-width",`${m.columnWidth}px`),D.style.setProperty("--shoji-layout-gutter",`${m.gutter.y}px ${m.gutter.x}px`);for(const L of d)L.root.style.setProperty("--shoji-layout-tile-aspect",`${n}`)}function jt(d){const u=D.getBoundingClientRect().width;if(u<=0)return;const m=dt(u),L={containerWidth:u,gutterX:m.gutter.x,gutterY:m.gutter.y,columns:m.columns,columnWidth:m.columnWidth,minColumnWidth:m.minColumnWidth,maxColumnWidth:m.maxColumnWidth,fill:m.fill};if($&&H.length>0){const O=j(),G=O.map(ot=>ot.heading.root.getBoundingClientRect().height);let Q=0;O.forEach(({heading:ot,start:rt,end:S},x)=>{const A=Y.slice(rt,S);ot.root.style.transform=`translate(0px, ${Q}px)`,Q+=G[x]+m.gutter.y;const _=Ve(A.map(W=>X(t.items[W.index])),L);A.forEach((W,U)=>{const J=_.positions[U];W.root.style.width=`${J.width}px`,W.root.style.height=`${J.height}px`,W.root.style.visibility="visible",W.root.style.transform=`translate(${J.x}px, ${Q+J.y}px)`}),Q+=_.containerHeight+m.gutter.y}),ut=void 0,D.style.height=`${Math.max(0,Q-m.gutter.y)}px`;return}const F=d??Y,z=F.map(O=>X(t.items[O.index])),w=Ve(z,L,d?ut:void 0);F.forEach((O,G)=>{const Q=w.positions[G];O.root.style.width=`${Q.width}px`,O.root.style.height=`${Q.height}px`,O.root.style.visibility="visible",O.root.style.transform=`translate(${Q.x}px, ${Q.y}px)`}),ut=w.columnHeights,D.style.height=`${w.containerHeight}px`}function Pt(){const d=D.getBoundingClientRect().width;if(d<=0)return;const u=dt(d),m=Y.map(F=>X(t.items[F.index])),L=ci(m,{containerWidth:d,gutterX:u.gutter.x,gutterY:u.gutter.y,rowHeight:u.rowHeight});Y.forEach((F,z)=>{const h=L.positions[z];F.root.style.width=`${h.width}px`,F.root.style.height=`${h.height}px`,F.root.style.visibility="visible",F.root.style.transform=`translate(${h.x}px, ${h.y}px)`}),D.style.height=`${L.containerHeight}px`}function St(d,u,m){const L=new Map,F=new Map;if(V==="fit")for(const S of H){if(!S.structured)continue;const{subtitleEl:x}=S.structured;S.root.style.maxWidth="none",S.root.style.whiteSpace="nowrap",x&&(x.hidden=!1),L.set(S.tileStart,S.root.getBoundingClientRect().width),x?(x.hidden=!0,F.set(S.tileStart,S.root.getBoundingClientRect().width),x.hidden=!1):F.set(S.tileStart,L.get(S.tileStart))}function z(S,x){return Y.slice(S,x).map(A=>X(t.items[A.index]))}function h(S,x){const A=H[S].tileStart,_=x<H.length?H[x].tileStart:Y.length,W=Vt(z(A,_),d);for(let U=S;U<x;U++){const J=H[U];if(!J.structured)continue;const q=W.positions[J.tileStart-A];if(!q)continue;const K=U+1<x?H[U+1]:void 0,lt=K?W.positions[K.tileStart-A]:null,oe=(!!lt&&Math.abs(lt.y-q.y)<.5?lt.x:m)-q.x-u.gutter.x;if(Math.min(L.get(J.tileStart)??1/0,F.get(J.tileStart)??1/0)>oe)return null}return W}function w(){if(V!=="fit")return[{startSection:0,endSection:H.length,tileStart:0,tileEnd:Y.length,result:Vt(z(0,Y.length),d)}];const S=[];let x=0;for(;x<H.length;){const A=h(x,x+1),_=H[x].tileStart;if(A===null){const q=x+1<H.length?H[x+1].tileStart:Y.length;S.push({startSection:x,endSection:x+1,tileStart:_,tileEnd:q,result:Vt(z(_,q),d)}),x+=1;continue}let W=x+1,U=A;for(;W<H.length;){const q=h(x,W+1);if(q===null)break;W+=1,U=q}const J=W<H.length?H[W].tileStart:Y.length;S.push({startSection:x,endSection:W,tileStart:_,tileEnd:J,result:U}),x=W}return S}function O(S){for(let x=S.startSection;x<S.endSection;x++){const A=H[x];if(!A.structured)continue;const _=S.result.positions[A.tileStart-S.tileStart];if(!_)continue;const W=x+1<S.endSection?H[x+1]:void 0,U=W?S.result.positions[W.tileStart-S.tileStart]:null,q=(!!U&&Math.abs(U.y-_.y)<.5?U.x:m)-_.x-u.gutter.x,{subtitleEl:K}=A.structured;A.root.style.whiteSpace="nowrap",A.root.style.maxWidth="none",A.root.style.overflow="",A.root.style.textOverflow="",K&&(K.hidden=!1),!((L.get(A.tileStart)??0)<=q)&&(K&&(K.hidden=!0,(F.get(A.tileStart)??0)<=q)||(A.root.style.maxWidth=`${Math.max(0,q)}px`,A.root.style.overflow="hidden",A.root.style.textOverflow="ellipsis"))}}function G(S){for(let x=S.startSection;x<S.endSection;x++){const A=H[x];if(!A.structured)continue;const _=S.result.positions[A.tileStart-S.tileStart];if(!_)continue;const W=x+1<S.endSection?H[x+1]:void 0,U=W?S.result.positions[W.tileStart-S.tileStart]:null,q=(!!U&&Math.abs(U.y-_.y)<.5?U.x:m)-_.x-u.gutter.x;A.root.style.whiteSpace="normal",A.root.style.maxWidth=`${Math.max(0,q)}px`;const K=getComputedStyle(A.root),lt=parseFloat(K.lineHeight),ee=Number.isFinite(lt)?lt:parseFloat(K.fontSize)*1.2,oe=Math.max(1,Math.floor(u.maxRowHeight/ee));A.root.style.display="-webkit-box",A.root.style.overflow="hidden",A.root.style.setProperty("-webkit-box-orient","vertical"),A.root.style.setProperty("-webkit-line-clamp",`${oe}`)}}const Q=w();let ot=0,rt=0;for(const S of Q){V==="fit"?O(S):V==="wrap"&&G(S);const x=new Map;for(let _=S.startSection;_<S.endSection;_++){const W=H[_];x.set(W.tileStart,W.root.getBoundingClientRect().height)}for(const _ of S.result.rows){const W=_.start+S.tileStart,U=_.end+S.tileStart;let J=0;for(;rt<S.endSection&&H[rt].tileStart<U;){const q=H[rt],K=S.result.positions[q.tileStart-S.tileStart];K&&(q.root.hidden=!1,q.root.style.transform=`translate(${K.x}px, ${_.y+ot}px)`,J=Math.max(J,x.get(q.tileStart)??0)),rt++}J>0&&(ot+=J+u.gutter.y);for(let q=W;q<U;q++){const K=S.result.positions[q-S.tileStart],lt=Y[q];lt.root.hidden=K===null,K&&(lt.root.style.width=`${K.width}px`,lt.root.style.height=`${K.height}px`,lt.root.style.visibility="visible",lt.root.style.transform=`translate(${K.x}px, ${K.y+ot}px)`)}}const A=S.result.rows.length>0?S.result.rows[S.result.rows.length-1].end+S.tileStart:S.tileStart;for(let _=A;_<S.tileEnd;_++)Y[_].root.hidden=!0;ot+=S.result.containerHeight+u.gutter.y}for(;rt<H.length;)H[rt].root.hidden=!0,rt++;D.style.height=`${Math.max(0,ot-u.gutter.y)}px`}function Tt(){const d=D.getBoundingClientRect().width;if(d<=0)return;const u=dt(d),m={containerWidth:d,gutterX:u.gutter.x,gutterY:u.gutter.y,rowHeight:u.rowHeight,minRowHeight:u.minRowHeight,maxRowHeight:u.maxRowHeight,lastRow:u.lastRow};if($&&H.length>0){St(m,u,d);return}const L=Y.map(z=>X(t.items[z.index])),F=Vt(L,m);Y.forEach((z,h)=>{const w=F.positions[h];z.root.hidden=w===null,w&&(z.root.style.width=`${w.width}px`,z.root.style.height=`${w.height}px`,z.root.style.visibility="visible",z.root.style.transform=`translate(${w.x}px, ${w.y}px)`)}),D.style.height=`${F.containerHeight}px`}function bt(){M?Pt():e==="masonry"?jt(null):e==="justified"?Tt():nt(Y)}let ft=!1,st=null;function Dt(){st!==null||ft||(st=requestAnimationFrame(()=>{st=null,!ft&&($?mt(t.items):bt())}))}function Mt(d){if(T)for(const u of d){const m=t.items[u.index];if(!m||m.width&&m.height||yt.has(m)||!B(m))continue;const L=()=>{ft||u.img.naturalWidth>0&&u.img.naturalHeight>0&&(yt.set(m,{width:u.img.naturalWidth,height:u.img.naturalHeight}),Dt())};u.img.complete?L():u.img.addEventListener("load",L,{once:!0})}}function Lt(d){o.emit("layoutRender",{tiles:d.map(u=>({index:u.index,element:u.root}))})}function mt(d){if(D.replaceChildren(),Y=d.map((u,m)=>ht(u,m)),H=[],$)for(const u of Ct(d)){const m=d.slice(u.startIndex,u.endIndex),{root:L,structured:F}=I(u.key,m);D.appendChild(L),H.push({root:L,tileStart:u.startIndex,structured:F});for(let z=u.startIndex;z<u.endIndex;z++)D.appendChild(Y[z].root)}else for(const u of Y)D.appendChild(u.root);ut=void 0,bt(),Mt(Y),Lt(Y)}function Bt(d,u){const m=d.map((L,F)=>ht(L,u+F));for(const L of m)D.appendChild(L.root);Y=[...Y,...m],M?Pt():e==="masonry"?jt(m):e==="justified"?Tt():nt(m),Mt(m),Lt(m)}mt(t.items),at=t.items;const Ht=o.on("itemsUpdated",({items:d})=>{$?mt(d):hi(at,d)?Bt(d.slice(at.length),at.length):mt(d),at=d});let wt=null,Et;return(e==="masonry"||e==="justified"||pt.length>0)&&(Et=new ResizeObserver(()=>{wt===null&&(wt=requestAnimationFrame(()=>{wt=null,bt()}))}),Et.observe(D)),()=>{ft=!0,st!==null&&cancelAnimationFrame(st),Et==null||Et.disconnect(),wt!==null&&cancelAnimationFrame(wt),Ht(),D.classList.remove("shoji-layout",`shoji-layout--${e}`,"shoji-layout--animate"),D.style.removeProperty("height"),D.style.removeProperty("width"),D.replaceChildren()}}};function fi(o){const t=(o.rotation%360+360)%360;return o.flipH&&o.flipV?{flipH:!1,flipV:!1,rotation:(t+180)%360}:{flipH:o.flipH,flipV:o.flipV,rotation:t}}const pi='<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 14 4 9l5-5"/><path d="M4 9h10a6 6 0 1 1 0 12H9"/></svg>',mi='<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 14 20 9l-5-5"/><path d="M20 9H10a6 6 0 1 0 0 12h5"/></svg>',gi='<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3v18"/><path d="M17 7l3 5-3 5"/><path d="M7 7l-3 5 3 5"/></svg>',vi='<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 12h18"/><path d="M7 17l5 3 5-3"/><path d="M7 7l5-3 5 3"/></svg>',ze={flipH:!1,flipV:!1,rotation:0};function yi(o,t,e,i){if(!o&&!t&&e===0&&i===1)return"none";const n=(o?-1:1)*i,s=(t?-1:1)*i;return`scaleX(${n}) scaleY(${s}) rotate(${e}deg)`}function bi(o,t,e,i,n){if(!o||!t||!i||!n||e/90%2===0)return 1;const s=Math.min(1,o/i,t/n);return Math.min(1,o/n,t/i)/s}const wi={name:"rotateFlip",init(o){const{gallery:t}=o,e=t.options.locale??{},i=e.rotateLeft??"Rotate left",n=e.rotateRight??"Rotate right",s=e.flipHorizontal??"Flip horizontal",r=e.flipVertical??"Flip vertical";let a={...ze},l=0,c=!1,f=!1;function y(I){const j=t.items[t.currentIndex];if(j!=null&&j.width&&j.height)return{width:j.width,height:j.height};const B=I.querySelector("img");if(B!=null&&B.naturalWidth&&B.naturalHeight)return{width:B.naturalWidth,height:B.naturalHeight}}function g(I){const j=t.getActiveMedia();if(!j)return;const B=y(j),X=bi(j.clientWidth,j.clientHeight,l,B==null?void 0:B.width,B==null?void 0:B.height),ht=yi(c,f,l,X);if(!I){j.style.transform=ht;return}j.style.transition="transform var(--shoji-duration) var(--shoji-easing)",j.style.transform=ht,At(j,()=>{j.style.transition=""})}function v(I,j){const B=document.createElement("button");return B.type="button",B.className="shoji-toolbar-button",B.innerHTML=I,B.setAttribute("aria-label",j),B.title=j,B}const b=v(pi,i),E=v(mi,n),T=v(gi,s),M=v(vi,r);T.setAttribute("aria-pressed","false"),M.setAttribute("aria-pressed","false");function C(I,j){a=fi({...a,...I}),j!==void 0&&(l+=j),g(!0),T.setAttribute("aria-pressed",String(a.flipH)),M.setAttribute("aria-pressed",String(a.flipV)),o.emit("rotateFlipChange",{index:t.currentIndex,...a})}function R(I){return I!==(c!==f)?90:-90}function V(){const I=R(!1);C({rotation:a.rotation+I},I)}function N(){const I=R(!0);C({rotation:a.rotation+I},I)}function P(){c=!c,C({flipH:!a.flipH})}function $(){f=!f,C({flipV:!a.flipV})}b.addEventListener("click",V),E.addEventListener("click",N),T.addEventListener("click",P),M.addEventListener("click",$);function k(){a={...ze},l=0,c=!1,f=!1,g(!1),T.setAttribute("aria-pressed","false"),M.setAttribute("aria-pressed","false")}let et=null;function pt(){const I=t.getActiveMedia(),j=I==null?void 0:I.style.transform;et=j&&j!=="none"?j:null}const dt=[b,E,T,M].map(I=>o.ui.toolbar("right",I)),D=o.on("requestRotateLeft",V),Y=o.on("requestRotateRight",N),H=o.on("requestFlipHorizontal",P),ut=o.on("requestFlipVertical",$),at=o.on("afterOpen",k),vt=o.on("beforeSlide",()=>{pt(),k()}),yt=o.on("afterSlide",k),Ct=t.registerSlideLeaveDecorator(I=>{if(!et)return;const j=et;return et=null,I.style.transform=j,()=>{I.style.transition="transform var(--shoji-duration) var(--shoji-easing)",I.style.transform="none"}});return()=>{for(const I of dt)I();D(),Y(),H(),ut(),at(),vt(),yt(),Ct()}}};let Yt=null;const Ei=250;function Ci(){var o;return(o=window.Vimeo)!=null&&o.Player?Promise.resolve(window.Vimeo):Yt||(Yt=new Promise(t=>{const e=document.createElement("script");e.src="https://player.vimeo.com/api/player.js",e.onload=()=>t(window.Vimeo),document.head.appendChild(e)}),Yt)}function Si(o,t){const e=o;e.paused=!0,e.ended=!1,e.play=()=>t.play(),e.pause=()=>t.pause();let i=!1;return Object.defineProperty(e,"muted",{configurable:!0,get:()=>i,set:n=>{i=n,t.setMuted(n)}}),e}const Ti=(o,t,e,i,n)=>{var l;if(((l=t.video)==null?void 0:l.provider)!=="vimeo")return;const{id:s,url:r}=t.video;if(!s&&!r){const c=document.createElement("div");c.className="shoji-slide-placeholder",c.textContent="Video",o.appendChild(c),e();return}if(!t.poster){const c=r??`https://vimeo.com/${s}`;fetch(`https://vimeo.com/api/oembed.json?url=${encodeURIComponent(c)}`).then(f=>f.ok?f.json():null).then(f=>{i.aborted||typeof(f==null?void 0:f.thumbnail_url)=="string"&&n(f.thumbnail_url)}).catch(()=>{})}const a=document.createElement("div");a.className="shoji-video-mount",o.appendChild(a),Ci().then(c=>{if(i.aborted)return;const f=o,y=new c.Player(a,{...r?{url:r}:{id:Number(s)},playsinline:!0});let g=null;function v(){g!==null&&(clearTimeout(g),g=null)}y.on("play",()=>{v(),f.paused=!1,f.dispatchEvent(new Event("play"))}),y.on("pause",()=>{f.paused=!0,v(),g=setTimeout(()=>{g=null,f.dispatchEvent(new Event("pause"))},Ei)}),y.on("ended",()=>{v(),f.paused=!0,f.ended=!0,f.dispatchEvent(new Event("ended"))}),y.on("error",b=>f.dispatchEvent(new CustomEvent("error",{bubbles:!0,detail:{name:b.name}}))),y.ready().then(()=>{Si(o,y),Promise.all([y.getVideoWidth(),y.getVideoHeight()]).then(([b,E])=>{b&&E&&o.style.setProperty("--shoji-provider-video-aspect",`calc(${b} / ${E})`)}).catch(()=>{}).then(()=>e())}),i.addEventListener("abort",()=>{v(),y.destroy()},{once:!0})})};let Wt=null;function Mi(){var o;return(o=window.YT)!=null&&o.Player?Promise.resolve(window.YT):Wt||(Wt=new Promise(t=>{const e=window.onYouTubeIframeAPIReady;window.onYouTubeIframeAPIReady=()=>{e==null||e(),t(window.YT)};const i=document.createElement("script");i.src="https://www.youtube.com/iframe_api",document.head.appendChild(i)}),Wt)}function Li(o,t){const e=o;return e.paused=!0,e.ended=!1,e.play=()=>t.playVideo(),e.pause=()=>t.pauseVideo(),Object.defineProperty(e,"muted",{configurable:!0,get:()=>t.isMuted(),set:i=>i?t.mute():t.unMute()}),e}function xi(o,t,e){o.data===t.PlayerState.PLAYING?(e.paused=!1,e.dispatchEvent(new Event("play"))):o.data===t.PlayerState.PAUSED?(e.paused=!0,e.dispatchEvent(new Event("pause"))):o.data===t.PlayerState.ENDED&&(e.paused=!0,e.ended=!0,e.dispatchEvent(new Event("ended")))}const Oi=(o,t,e,i,n)=>{var a;if(((a=t.video)==null?void 0:a.provider)!=="youtube")return;const s=t.video.id;if(!s){const l=document.createElement("div");l.className="shoji-slide-placeholder",l.textContent="Video",o.appendChild(l),e();return}t.poster||n(`https://img.youtube.com/vi/${s}/hqdefault.jpg`);const r=document.createElement("div");o.appendChild(r),Mi().then(l=>{if(i.aborted)return;const c=o,f=new l.Player(r,{videoId:s,playerVars:{playsinline:1,rel:0},events:{onReady:()=>{Li(o,f),e()},onStateChange:y=>xi(y,l,c),onError:y=>c.dispatchEvent(new CustomEvent("error",{bubbles:!0,detail:{code:y.data}}))}});i.addEventListener("abort",()=>f.destroy(),{once:!0})})},ji={name:"video",init(o){const t=o.ui.registerVideoProvider("youtube",Oi),e=o.ui.registerVideoProvider("vimeo",Ti);return()=>{t(),e()}}},Pi='<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="10" cy="10" r="7"/><path d="M21 21l-5.5-5.5M10 7v6M7 10h6"/></svg>',Hi='<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="10" cy="10" r="7"/><path d="M21 21l-5.5-5.5M7 10h6"/></svg>',Ri='<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="4" width="16" height="16" rx="1"/><path d="M9 15l6-6M9 9h0M15 15h0"/></svg>';function Ai(o,t,e){return Math.min(e,Math.max(t,o))}const zt={a:1,b:0,c:0,d:1};function _e(o){const t=/^matrix\(\s*([^,]+),\s*([^,]+),\s*([^,]+),\s*([^,]+),/.exec(o);return t?{a:Number(t[1]),b:Number(t[2]),c:Number(t[3]),d:Number(t[4])}:{...zt}}function Qt(o,t,e){const i=e.a*e.d-e.b*e.c;return i===0?{tx:o,ty:t}:{tx:(e.d*o-e.c*t)/i,ty:(e.a*t-e.b*o)/i}}function Xe(o,t,e){return{tx:e.a*o+e.c*t,ty:e.b*o+e.d*t}}function te(o){return{tx:-o.width/2,ty:-o.height/2}}function Ii(o,t,e=zt,i=te(o)){const n=o.left+o.width/2,s=o.top+o.height/2,r=Xe(i.tx+t.tx,i.ty+t.ty,e);return{x:n+r.tx,y:s+r.ty}}function qe(o,t,e,i){if(t<=i)return e+(i-t)/2;const n=e+i-t;return Math.min(e,Math.max(n,o))}function ki(o,t,e,i,n){const s=-n.tx*2,r=-n.ty*2,a=o.left+o.width/2,l=o.top+o.height/2,f=[{x:0,y:0},{x:s,y:0},{x:0,y:r},{x:s,y:r}].map(({x:v,y:b})=>{const E={x:n.tx+t.tx+v*e,y:n.ty+t.ty+b*e},T=Xe(E.x,E.y,i);return{x:a+T.tx,y:l+T.ty}}),y=f.map(v=>v.x),g=f.map(v=>v.y);return{left:Math.min(...y),top:Math.min(...g),right:Math.max(...y),bottom:Math.max(...g)}}function Ze(o,t,e,i,n=zt,s=te(o)){const r=ki(o,i,e,n,s),a=qe(r.left,r.right-r.left,t.left,t.width),l=qe(r.top,r.bottom-r.top,t.top,t.height),c={tx:a-r.left,ty:l-r.top},f=Qt(c.tx,c.ty,n);return{tx:i.tx+f.tx,ty:i.ty+f.ty}}function Di(o,t,e,i,n,s,r=zt,a=te(o)){const l=Ii(o,t,r,a),c=n-l.x,f=s-l.y,y=Qt(c,f,r),g=1-i/e;return{tx:t.tx+y.tx*g,ty:t.ty+y.ty*g}}const Ot=1.001;function Bi(o){return o.composedPath().some(t=>t instanceof Element&&t.matches("button, video, input, select, textarea, a[href], [data-shoji-no-drag], .shoji-caption"))}return Object.assign(qo,{Autoplay:ti,Layout:ui,ActiveThumbnail:Go,Fullscreen:si,RotateFlip:wi,Video:ji,Zoom:{name:"zoom",defaults:{maxScale:4,doubleTapScale:2,buttonStep:1.5},init(o){const{gallery:t}=o,e=Number(o.options.maxScale??4),i=Number(o.options.doubleTapScale??2),n=Number(o.options.buttonStep??1.5),s=t.options.locale??{},r=s.zoomIn??"Zoom in",a=s.zoomOut??"Zoom out",l=s.zoomActualSize??"Actual size";let c=1,f={tx:0,ty:0},y=null,g=null,v=null,b=1;function E(){const h=t.getActiveMedia(),w=h==null?void 0:h.firstElementChild;return w instanceof HTMLImageElement?w:null}function T(h){const w=h.getBoundingClientRect();return{left:w.left,top:w.top,width:w.width,height:w.height}}function M(h){return y&&g&&v?!0:c!==1?!1:(y=T(h),g=T(h.parentElement??h),v={tx:-(h.offsetWidth||y.width)/2,ty:-(h.offsetHeight||y.height)/2},!0)}function C(h){const w=t.getActiveMedia();if(!w||w.style.transition===""){h();return}At(w,h)}function R(){const h=E();h&&(h.style.transformOrigin="0 0",h.style.transform=c===1&&f.tx===0&&f.ty===0?"none":`translate3d(${f.tx}px, ${f.ty}px, 0) scale3d(${c}, ${c}, 1)`,h.classList.toggle("shoji-zoomed",c>1))}function V(){o.emit("zoomChange",{index:t.currentIndex,scale:c})}function N(h,w,O){h.style.transition="transform var(--shoji-duration) var(--shoji-easing)",w(),At(h,()=>{h.style.transition="",O==null||O()})}function P(h,w,O,G=e,Q=!1){C(()=>{const ot=E();if(!ot||!M(ot))return;const rt=Ai(h,1,Math.max(G,1)),S=t.getActiveMedia(),x=_e(S?getComputedStyle(S).transform:"none");f=Di(y,f,c,rt,w,O,x,v),c=rt,f=Ze(y,g,c,f,x,v),Q?N(ot,R):R(),V()})}function $(h=!1){const w=c!==1;c=1,f={tx:0,ty:0},y=null,g=null,v=null,w&&V();const O=E();if(!O)return;const G=()=>{O.style.transform="",O.classList.remove("shoji-zoomed")};h?N(O,G,()=>{O.style.transformOrigin=""}):(G(),O.style.transformOrigin="")}let k=null,et="";function pt(){const h=E(),w=h==null?void 0:h.style.transform;k=w&&w!=="none"?w:null,et=(h==null?void 0:h.style.transformOrigin)||"0 0"}function dt(){var h;(h=E())==null||h.classList.add("shoji-zoom-enabled")}function D(h,w){c>Ot?$(!0):P(i,h,w,e,!0)}const Y=o.on("pinchStart",()=>{b=c}),H=o.on("pinchMove",({scale:h,centerX:w,centerY:O})=>{P(b*h,w,O)}),ut=o.on("pinchEnd",()=>{c<=Ot&&$()}),at=o.on("doubleTap",({x:h,y:w})=>D(h,w)),vt=o.on("wheelZoom",({deltaScale:h,x:w,y:O})=>{P(c+h,w,O)}),yt=o.on("requestZoomIn",ft),Ct=o.on("requestZoomOut",st),I=o.on("requestZoomActualSize",Dt),j=o.on("requestZoomReset",()=>$(!0));let B=null,X=0,ht=0;const nt=o.ui.outer();function jt(h){if(c<=Ot||Bi(h))return;const w=E();!w||!h.composedPath().includes(w)||(B=h.pointerId,X=h.clientX,ht=h.clientY,w.setPointerCapture(h.pointerId))}function Pt(h){if(B!==h.pointerId||!y||!g||!v)return;h.preventDefault();const w=h.clientX-X,O=h.clientY-ht;X=h.clientX,ht=h.clientY;const G=t.getActiveMedia(),Q=_e(G?getComputedStyle(G).transform:"none"),{tx:ot,ty:rt}=Qt(w,O,Q);f=Ze(y,g,c,{tx:f.tx+ot,ty:f.ty+rt},Q,v),R()}function St(h){B===h.pointerId&&(B=null)}nt.addEventListener("pointerdown",jt),nt.addEventListener("pointermove",Pt,{passive:!1}),nt.addEventListener("pointerup",St),nt.addEventListener("pointercancel",St);function Tt(h,w){const O=document.createElement("button");return O.type="button",O.className="shoji-toolbar-button",O.innerHTML=h,O.setAttribute("aria-label",w),O.title=w,O}function bt(){const h=t.getActiveMedia(),w=h==null?void 0:h.getBoundingClientRect();return w?{x:w.left+w.width/2,y:w.top+w.height/2}:{x:0,y:0}}function ft(){const{x:h,y:w}=bt();P(c*n,h,w,e,!0)}function st(){const{x:h,y:w}=bt();c/n<=Ot?$(!0):P(c/n,h,w,e,!0)}function Dt(){C(()=>{const h=E();if(!h||!h.naturalWidth||!M(h))return;if(c>Ot){$(!0);return}const w=h.naturalWidth/y.width,{x:O,y:G}=bt();P(w,O,G,w,!0)})}const Mt=Tt(Pi,r),Lt=Tt(Hi,a),mt=Tt(Ri,l);Mt.addEventListener("click",ft),Lt.addEventListener("click",st),mt.addEventListener("click",Dt);const Bt=[Mt,Lt,mt].map(h=>o.ui.toolbar("right",h));function Ht(){var w;const h=!!((w=t.items[t.currentIndex])!=null&&w.video);Mt.hidden=h,Lt.hidden=h,mt.hidden=h}const wt=[o.ui.registerShortcut("w",ft),o.ui.registerShortcut("W",ft),o.ui.registerShortcut("s",st),o.ui.registerShortcut("S",st)],Et=o.on("afterOpen",()=>{$(),dt(),Ht()}),d=o.on("beforeSlide",()=>{pt(),$()}),u=o.on("afterSlide",()=>{$(),dt(),Ht()}),m=o.on("beforeClose",()=>$()),L=t.registerZoomGate(()=>c>Ot),F=t.registerZoomStartProvider(()=>{var h;return c>Ot?((h=E())==null?void 0:h.getBoundingClientRect())??null:null}),z=t.registerSlideLeaveDecorator(h=>{if(!k)return;const w=k,O=et;k=null;const G=h.querySelector("img");if(G)return G.style.transformOrigin=O,G.style.transform=w,()=>{G.style.transition="transform var(--shoji-duration) var(--shoji-easing)",G.style.transform="none"}});return dt(),Ht(),()=>{var h;for(const w of Bt)w();for(const w of wt)w();Et(),d(),u(),m(),Y(),H(),ut(),at(),vt(),yt(),Ct(),I(),j(),nt.removeEventListener("pointerdown",jt),nt.removeEventListener("pointermove",Pt),nt.removeEventListener("pointerup",St),nt.removeEventListener("pointercancel",St),L(),F(),z(),$(),(h=E())==null||h.classList.remove("shoji-zoom-enabled")}}},version:"0.1.0-beta.2"})}));
2
2
  //# sourceMappingURL=shoji.min.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@michaelyagi/shoji",
3
- "version": "0.1.0-beta.1",
3
+ "version": "0.1.0-beta.2",
4
4
  "description": "Zero-dependency TypeScript lightbox/gallery library.",
5
5
  "type": "module",
6
6
  "license": "MIT",