@michaelyagi/shoji 0.1.0-beta.13 → 0.1.0-beta.14
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/dist/core/shoji-core.css +43 -0
- package/dist/core/shoji-core.min.css +1 -1
- package/dist/esm/core/iconSwap.d.ts +21 -0
- package/dist/esm/iconSwap-BAXTLihx.js +21 -0
- package/dist/esm/iconSwap-BAXTLihx.js.map +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/index2.css +43 -0
- package/dist/esm/plugins/autoplay/index.js +4 -2
- package/dist/esm/plugins/autoplay/index.js.map +1 -1
- package/dist/esm/plugins/fullscreen/index.js +4 -2
- package/dist/esm/plugins/fullscreen/index.js.map +1 -1
- package/dist/esm/plugins/zoom/icons.d.ts +14 -1
- package/dist/esm/plugins/zoom/index.js +18 -2
- package/dist/esm/plugins/zoom/index.js.map +1 -1
- package/dist/plugins/autoplay.js +20 -2
- package/dist/plugins/autoplay.js.map +1 -1
- package/dist/plugins/autoplay.min.js +1 -1
- package/dist/plugins/autoplay.min.js.map +1 -1
- package/dist/plugins/fullscreen.js +20 -2
- package/dist/plugins/fullscreen.js.map +1 -1
- package/dist/plugins/fullscreen.min.js +1 -1
- package/dist/plugins/fullscreen.min.js.map +1 -1
- package/dist/plugins/zoom.js +34 -2
- package/dist/plugins/zoom.js.map +1 -1
- package/dist/plugins/zoom.min.js +1 -1
- package/dist/plugins/zoom.min.js.map +1 -1
- package/dist/shoji.css +43 -0
- package/dist/shoji.js +41 -7
- package/dist/shoji.js.map +1 -1
- package/dist/shoji.min.css +1 -1
- package/dist/shoji.min.js +1 -1
- package/dist/shoji.min.js.map +1 -1
- package/package.json +1 -1
package/dist/shoji.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(rt,ct){typeof exports=="object"&&typeof module<"u"?module.exports=ct():typeof define=="function"&&define.amd?define(ct):(rt=typeof globalThis<"u"?globalThis:rt||self,rt.Shoji=ct())})(this,(function(){"use strict";var $i=Object.defineProperty;var Vi=(rt,ct,Pt)=>ct in rt?$i(rt,ct,{enumerable:!0,configurable:!0,writable:!0,value:Pt}):rt[ct]=Pt;var f=(rt,ct,Pt)=>Vi(rt,typeof ct!="symbol"?ct+"":ct,Pt);let rt=0,ct="",Pt="",ie="",ne=0,se=0,wt=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(rt===0)return;const o=document.documentElement;getComputedStyle(o).overflow!=="hidden"&&(o.style.overflow="hidden",wt==null||wt.takeRecords())}function Qe(){if(rt===0){ne=window.scrollX,se=window.scrollY,_t=!1;const o=window.innerWidth-document.documentElement.clientWidth,t=Ue();if(Pt=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`}ct=document.documentElement.style.overflow,document.documentElement.style.overflow="hidden",document.addEventListener("touchstart",le,{passive:!0}),document.addEventListener("touchmove",ce,{passive:!1}),wt=new MutationObserver(Je),wt.observe(document.documentElement,{attributes:!0,attributeFilter:["style"]})}rt++}function to(){rt=Math.max(0,rt-1),rt===0&&(wt==null||wt.disconnect(),wt=null,document.removeEventListener("touchstart",le),document.removeEventListener("touchmove",ce),document.documentElement.style.overflow=ct,document.documentElement.style.paddingRight=Pt,document.documentElement.style.paddingLeft=ie,_t||window.scrollTo({left:ne,top:se,behavior:"instant"}))}class eo{constructor(){f(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 At(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 u=At("shoji-close",de,t.close),p=At("shoji-toolbar-button shoji-caption-toggle",no,t.showCaption);p.setAttribute("aria-pressed","false"),p.hidden=!0;const w=At("shoji-toolbar-button shoji-toolbar-overflow",so,t.moreControls);w.setAttribute("aria-haspopup","true"),w.setAttribute("aria-expanded","false"),w.hidden=!0,c.append(p,w,u);const h=document.createElement("div");h.className="shoji-toolbar-overflow-panel",h.setAttribute("role","dialog"),h.setAttribute("aria-label",t.moreControls),h.tabIndex=-1,h.hidden=!0;const S=document.createElement("div");S.className="shoji-counter",S.id=e,a.appendChild(S),r.append(a,l,c),s.appendChild(r),s.appendChild(h);const v=At("shoji-nav shoji-nav-prev",oo,t.previous),x=At("shoji-nav shoji-nav-next",io,t.next);s.appendChild(v),s.appendChild(x),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 $=At("shoji-caption-modal-close",de,t.close),I=document.createElement("div");return I.className="shoji-caption-modal-content",R.append($,I),C.appendChild(R),s.appendChild(C),i.appendChild(s),{outer:i,backdrop:n,dialog:s,counter:S,caption:M,captionModal:C,captionModalPanel:R,captionModalContent:I,captionModalCloseButton:$,closeButton:u,prevButton:v,nextButton:x,captionToggleButton:p,toolbar:r,toolbarLeft:a,toolbarCenter:l,toolbarRight:c,toolbarOverflowButton:w,toolbarOverflowPanel:h}}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(){f(this,"container",null);f(this,"previouslyFocused",null);f(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){f(this,"target");f(this,"options");f(this,"callbacks");f(this,"pointers",new Map);f(this,"primaryPointerId",null);f(this,"direction",null);f(this,"dragStartDistance",0);f(this,"pinching",!1);f(this,"pinchStartDistance",0);f(this,"capturedThisGesture",!1);f(this,"lastTapTime",-1/0);f(this,"lastTapX",0);f(this,"lastTapY",0);f(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)}}});f(this,"onPointerMove",t=>{var r,a,l,c,u,p,w,h;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[S,v]=[...this.pointers.values()],x=he(S,v),M=this.pinchStartDistance>0?x/this.pinchStartDistance:1,C=ue(S,v);(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 S=Math.abs(i),v=Math.abs(n);if(Math.max(S,v)<this.options.lockThreshold)return;this.direction=S>v?"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),(p=(u=this.callbacks).onDragStart)==null||p.call(u,this.direction,t)}this.direction==="horizontal"&&t.preventDefault();const s=(this.direction==="horizontal"?i:n)-this.dragStartDistance;(h=(w=this.callbacks).onDragMove)==null||h.call(w,this.direction,s,t)});f(this,"onPointerUp",t=>{this.finishPointer(t,!1)});f(this,"onPointerCancel",t=>{this.finishPointer(t,!0)});f(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,u=c/l,p=!e&&(Math.abs(c)>=this.options.swipeThreshold||Math.abs(u)>=this.options.swipeVelocity);(a=(r=this.callbacks).onDragEnd)==null||a.call(r,this.direction,c,u,p,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 go(o){const t=o.querySelector("img");if(t){const e=t.getBoundingClientRect();if(e.width>0&&e.height>0)return e}return o.getBoundingClientRect()}function ve(o,t,e,i){const n=go(o),s=me(t,e,i);return s.width===0||s.height===0||n.width===0||n.height===0?null:ge(s,n)}function It(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 vo({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",It(t,()=>ye(t,"none")))}function yo({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 u=t.style.transform,p=ge(c,s);t.style.transition="none",t.style.transform=u&&u!=="none"?`${u} ${p}`:p,t.offsetHeight}}t.style.transition="transform var(--shoji-duration) var(--shoji-easing)",t.offsetHeight,t.style.transform=a;const l=t.style.transform;It(t,()=>{ye(t,l),r()})}const bo="transform var(--shoji-duration) var(--shoji-momentum-easing)",wo="transform var(--shoji-duration) var(--shoji-momentum-easing), opacity var(--shoji-duration) var(--shoji-momentum-easing)",be=160,Eo="button, video, input, select, textarea, a[href], [data-shoji-no-drag], .shoji-caption, .shoji-caption-modal, .shoji-toolbar-overflow-panel",Co="button, input, select, textarea, a[href], [data-shoji-no-drag], .shoji-caption, .shoji-caption-modal, .shoji-toolbar-overflow-panel";function So(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 To(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 Mo(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 Lo(o,t,e){if(Mo(o,t))return!0;const i=o.composedPath(),n=i.find(s=>s instanceof HTMLVideoElement);return n?So(o,n)?(To(e),!0):!1:i.some(s=>s instanceof Element&&s.matches(Co))}class xo{constructor(t,e,i){f(this,"engine");f(this,"controlsHideThreshold");f(this,"controlsHiddenForDrag",!1);f(this,"lastDragDelta",0);f(this,"onDragMove",(t,e)=>{this.host.isZoomed()||(t==="horizontal"?this.host.slides.setDragOffset(e,null):this.host.canClose()&&this.applyVerticalDragFeedback(e))});f(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=>Lo(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,bo),!i){e();return}It(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?wo:"",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 Oo{constructor(){f(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=Ro(n)??Po(n);s&&i.push({element:n,item:s})}return i}function mt(o,t){return o.getAttribute(t)??void 0}function kt(o,t){const e=o.getAttribute(t);if(e===null)return;const i=Number(e);return Number.isFinite(i)?i:void 0}const jo=new Set(["no-drag","video-id","video-provider"]);function qt(o,t,e){const i=mt(o,"data-shoji-caption");i&&(t.caption=i),t.id=mt(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);!jo.has(r)&&!(r in t)&&((n??(n={}))[r]=s.value)}n&&(t.data=n)}function Po(o){const t=mt(o,"href")??mt(o,"data-shoji-src");if(!t)return;const e={src:t},i=o.querySelector("img"),n=(i==null?void 0:i.getAttribute("src"))??mt(o,"data-shoji-thumb");n&&(e.thumb=n);const s=(i==null?void 0:i.getAttribute("alt"))??mt(o,"data-shoji-alt");s&&(e.alt=s);const r=kt(o,"data-shoji-width");r!==void 0&&(e.width=r);const a=kt(o,"data-shoji-height");a!==void 0&&(e.height=a);const l=mt(o,"data-shoji-srcset");l&&(e.srcset=l);const c=mt(o,"data-shoji-sizes");return c&&(e.sizes=c),qt(o,e,t),e}function Ro(o){var n;const t=mt(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(p=>({src:p.getAttribute("src")??"",type:p.getAttribute("type")??""})).filter(p=>p.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=kt(o,"data-shoji-width");c!==void 0&&(a.width=c);const u=kt(o,"data-shoji-height");return u!==void 0&&(a.height=u),qt(o,a,r),a}const i=mt(o,"data-shoji-video");if(i){const s=mt(o,"data-shoji-video-provider"),r=Ao(i,s,t),a={src:i,video:r.video};r.sources&&(a.sources=r.sources);const l=mt(o,"data-shoji-poster");l&&(a.poster=l);const c=kt(o,"data-shoji-width");c!==void 0&&(a.width=c);const u=kt(o,"data-shoji-height");return u!==void 0&&(a.height=u),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:Io(o)}]}}function Ao(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 Io(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 ko{constructor(t){f(this,"element");f(this,"slots");f(this,"preload");f(this,"videoProviders");f(this,"dragOffsetPx",0);f(this,"cache",new Map);f(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((h,S)=>{const v=S-this.preload,x=e+v,M=r?(x%t.length+t.length)%t.length:x,C=M>=0&&M<t.length?t[M]:void 0;return{offset:v,index:M,item:C}}),l=new Set(a.map(h=>h.index));for(const[h,S]of this.cache)l.has(h)||(He(S.node),this.cache.delete(h));const c=new Set,u=new Set;for(const h of a){if(!h.item)continue;const S=this.slots.find(v=>v.assignedIndex===h.index&&v.ready);S&&(c.add(h.index),u.add(S),S.offset!==h.offset&&(S.offset=h.offset,i(h.index)))}const p=this.slots.filter(h=>!u.has(h));a.filter(h=>!h.item||!c.has(h.index)).forEach((h,S)=>{var C;const v=p[S];v.offset=h.offset;const{index:x,item:M}=h;if(!M){v.assignedIndex=null,v.ready=!1,Nt(v.media),v.media.replaceChildren();return}if(v.assignedIndex!==x){if(v.assignedIndex=x,v.ready=!1,Nt(v.media),v.media.replaceChildren(Bo()),this.applyAspect(v,M),x===e&&n){const R=M.width&&M.height?{width:M.width,height:M.height}:void 0;this.revealOpenPlaceholder(n,v,x,R)}((C=M.video)==null?void 0:C.provider)==="html5"?this.renderVideo(M,v,x,i):M.video?this.renderProviderVideo(M,v,x,i):this.ensureImageDecoding(M,x,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=Do(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 w=document.createElement("div");w.className="shoji-slide-placeholder",w.textContent="Video",this.swapIn(e,w,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 u=()=>{c||l.signal.aborted||(c=!0,a.hidden=!1,e.media.querySelectorAll(".shoji-slide-spinner, .shoji-slide-open-placeholder, .shoji-slide-provider-poster").forEach(w=>w.remove()),this.applyAspect(e,t),e.ready=!0,this.cache.set(i,{node:a,item:t}),n(i))},p=w=>{t.poster||c||l.signal.aborted||Pe(e,w)};r(a,t,u,l.signal,p)}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 Do(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 Bo(){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&&He(t);const e=o.querySelector(".shoji-slide-provider-video");e&&Ae(e)}function Re(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 He(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 Q(o){return{name:o.name,enter:t=>Ie(o.enter,t),leave:t=>Ie(o.leave,t)}}const Fo=[Q({name:"slide",enter:{directional:!0,translateX:100},leave:{directional:!0,translateX:-100}}),Q({name:"fade",enter:{opacity:0},leave:{opacity:0}}),Q({name:"zoom",enter:{scale:.6,opacity:0},leave:{scale:1.4,opacity:0}}),Q({name:"deck",enter:{translateY:6,scale:.85,opacity:0},leave:{translateY:-4,scale:.92,opacity:0}}),Q({name:"slideVertical",enter:{directional:!0,translateY:100},leave:{directional:!0,translateY:-100}}),Q({name:"push",enter:{directional:!0,translateX:120},leave:{directional:!0,translateX:-120}}),Q({name:"fadeUp",enter:{translateY:12,opacity:0},leave:{translateY:-12,opacity:0}}),Q({name:"fadeDown",enter:{translateY:-12,opacity:0},leave:{translateY:12,opacity:0}}),Q({name:"fadeLeft",enter:{translateX:-12,opacity:0},leave:{translateX:12,opacity:0}}),Q({name:"fadeRight",enter:{translateX:12,opacity:0},leave:{translateX:-12,opacity:0}}),Q({name:"zoomOut",enter:{scale:1.4,opacity:0},leave:{scale:.6,opacity:0}}),Q({name:"scaleUp",enter:{scale:.7},leave:{scale:1.3}}),Q({name:"scaleDown",enter:{scale:1.3},leave:{scale:.7}}),Q({name:"rotate",enter:{rotateZ:15,opacity:0},leave:{rotateZ:-15,opacity:0}}),Q({name:"rotateLeft",enter:{directional:!0,rotateZ:-25,opacity:0},leave:{directional:!0,rotateZ:25,opacity:0}}),Q({name:"rotateRight",enter:{directional:!0,rotateZ:25,opacity:0},leave:{directional:!0,rotateZ:-25,opacity:0}}),Q({name:"flipX",enter:{rotateX:90,perspective:1200,opacity:0},leave:{rotateX:-90,perspective:1200,opacity:0}}),Q({name:"flipY",enter:{directional:!0,rotateY:90,perspective:1200,opacity:0},leave:{directional:!0,rotateY:-90,perspective:1200,opacity:0}}),Q({name:"cube",enter:{directional:!0,rotateY:70,translateX:40,perspective:1600,opacity:1},leave:{directional:!0,rotateY:-70,translateX:-40,perspective:1600,opacity:1}}),Q({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}}),Q({name:"drop",enter:{translateY:-30,opacity:0},leave:{translateY:20,opacity:0}})],No=Object.fromEntries(Fo.map(o=>[o.name,o]));function $o(){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 Vo(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 Yo(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 Wo(o){o.style.transition="",o.style.transform="",o.style.opacity="",o.style.transformOrigin=""}class zo{constructor(t,e=()=>()=>{}){this.slides=t,this.decorateLeave=e}animate(t,e,i){this.run(i,(n,s)=>{const r=t.leave(e);Yo(n,r.transform,r.opacity);const a=t.enter(e);Vo(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=Wo){if($o()){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 _o(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 Xo(o,t){if(o.composedPath().some(i=>i instanceof Element&&i.matches(`.shoji-slide-img, .shoji-video-mount, iframe, .shoji-counter, ${Eo}`)))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 qo(o){return typeof o=="object"&&o!==null&&typeof o.dangerouslySetInnerHTML=="string"}class Zo{constructor(t,e={}){f(this,"options",{});f(this,"element");f(this,"bus",new eo);f(this,"selector",Xt);f(this,"isDynamicMode",!1);f(this,"preload",1);f(this,"locale",Be);f(this,"showCounter",!0);f(this,"captionVisibleOnVideo",!1);f(this,"captionFadePending",!1);f(this,"loop",!0);f(this,"closable",!0);f(this,"autoHideDelay",5e3);f(this,"maxPinnedToolbarButtons",2);f(this,"focusTrap",new co);f(this,"liveRegion",new Oo);f(this,"autoHideTimer",null);f(this,"autoHidden",!1);f(this,"hoverableElements",new Set);f(this,"hoveringElements",new Set);f(this,"isClosing",!1);f(this,"controlsHiddenByDrag",!1);f(this,"itemList",[]);f(this,"scannedElements",[]);f(this,"activeIndex",0);f(this,"opened",!1);f(this,"destroyed",!1);f(this,"slides",null);f(this,"dom",null);f(this,"gesture",null);f(this,"transition",null);f(this,"toolbarHeightObserver",null);f(this,"toolbarHeightFrame",null);f(this,"captionTruncationFrame",null);f(this,"captionModalOpen",!1);f(this,"captionModalReturnFocus",null);f(this,"captionModalOpenedViaKeyboard",!1);f(this,"pluginToolbarButtons",[]);f(this,"toolbarOverflowOpen",!1);f(this,"toolbarOverflowReturnFocus",null);f(this,"shortcuts",new Map);f(this,"pluginStorage",new Map);f(this,"activePluginNames",new Set);f(this,"videoProviders",new Map);f(this,"zoomGate",null);f(this,"zoomStartProvider",null);f(this,"slideLeaveDecorators",new Set);f(this,"pluginCleanups",[]);f(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}});f(this,"onOuterClick",t=>{var e;this.closable&&Xo(t,((e=this.dom)==null?void 0:e.caption)??null)&&this.close()});f(this,"onActivity",()=>{this.reconcileHover(),!(this.autoHideDelay===0||this.autoHideDelay===!1||this.isClosing||this.controlsHiddenByDrag||this.captionModalOpen)&&(this.showControls(),this.scheduleAutoHide())});f(this,"controlsHiddenAtGestureStart",!1);f(this,"captureGestureStartState",()=>{this.controlsHiddenAtGestureStart=this.autoHidden});f(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()}});f(this,"onCaptionModalKeydown",t=>{t.stopPropagation(),t.key==="Escape"&&this.closeCaptionModal()});f(this,"onToolbarOverflowKeydown",t=>{t.stopPropagation(),t.key==="Escape"&&this.closeToolbarOverflow()});f(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=_o(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 ko({preload:this.preload,videoProviders:this.videoProviders}),this.transition=new zo(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 xo({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 p=this.pluginToolbarButtons.filter(w=>w.slot==="right"&&w.el.parentElement===n&&!w.el.hidden).length+(s.hidden?0:1)+1;i.style.gridTemplateColumns=`repeat(${p}, 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}markIntentionalScroll(){Ge()}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):qo(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 w of r.getClientRects()){if(w.height===0)continue;const h=w.top-s,S=w.bottom-s;S<=n?S>a&&(a=S):h<l&&(l=h)}const u=(a>0?a:n)+i,p=Number.isFinite(l)?Math.min(u,l):u;t.style.maxHeight=`${Math.max(0,Math.floor(p)-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&&vo({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}),Re(((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=No[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();Re(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"),yo({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 Go(){return typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}const Uo={name:"activeThumbnail",defaults:{activeClass:"shoji-thumb-active",scrollIntoView:!0,highlight:!1,borderColor:"blue"},init(o){const{gallery:t}=o,e=String(o.options.activeClass??"shoji-thumb-active"),i=o.options.scrollIntoView!==!1,n=o.options.highlight===!0,s=String(o.options.borderColor??"blue"),r=typeof o.options.highlightDuration=="number"?o.options.highlightDuration:null,a=typeof o.options.highlightFadeDuration=="number"?o.options.highlightFadeDuration:800,l="shoji-thumb-active--highlight";let c=null,u=null,p=null,w=null;function h(){p!==null&&(clearTimeout(p),p=null)}function S(){w!==null&&(clearTimeout(w),w=null)}function v(j){S();const W=t.getOriginElement(j);return c&&c!==W&&(c.classList.remove(e),n&&c.classList.remove(l)),W&&(W.classList.add(e),n&&(W.classList.add(l),W.style.setProperty("--shoji-active-thumbnail-border-color",s),W.style.setProperty("--shoji-active-thumbnail-fade-duration",`${a}ms`))),c=W,W}function x(j){try{t.markIntentionalScroll(),j.scrollIntoView({block:"nearest",inline:"nearest",behavior:Go()?"auto":"smooth"})}catch{}}function M(j){u=j,h();const W=v(j);W&&i&&(p=setTimeout(()=>{p=null,x(W)},80))}function C(){const j=p!==null?c:null;if(h(),j&&i&&x(j),n&&r!==null&&c){const W=c;w=setTimeout(()=>{w=null,W.style.setProperty("--shoji-active-thumbnail-border-color","transparent")},r)}}function R(){h(),S(),c==null||c.classList.remove(e),n&&(c==null||c.classList.remove(l)),c=null,u=null}const $=o.on("afterOpen",({index:j})=>M(j)),I=o.on("afterSlide",({to:j})=>M(j)),V=o.on("beforeClose",C),Y=o.on("layoutRender",()=>{u!==null&&v(u)});return()=>{$(),I(),V(),Y(),R()}}},Fe='<svg viewBox="0 0 24 24" width="24" height="24" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>',Ko='<svg viewBox="0 0 24 24" width="24" height="24" fill="currentColor"><path d="M7 5h4v14H7zM13 5h4v14h-4z"/></svg>';function Jo(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 Qo(o){const t=o==null?void 0:o.querySelector(".shoji-slide-provider-video");return!!t&&typeof t.play!="function"}const Ne=400,ti=8,ei=1e3,oi={name:"autoplay",defaults:{interval:5e3,showProgress:!0,onZoom:"stop",onRotateFlip:"stop",onCaptionExpand:"stop",stopOnManualNavigate:!0},init(o){const{gallery:t}=o,e=Number(o.options.interval??5e3),i=o.options.showProgress!==!1,n=o.options.autoStart===!0,s=E=>E===!1||E==="pause"?E:"stop",r=s(o.options.onZoom),a=s(o.options.onRotateFlip),l=s(o.options.onCaptionExpand),c=o.options.stopOnManualNavigate!==!1,u=o.options.locale,p=(u==null?void 0:u.play)??"Play slideshow",w=(u==null?void 0:u.pause)??"Pause slideshow";let h=!1,S=null,v=null,x=!1,M=!1,C=!1,R=!1,$=!1,I=!1,V=!1,Y=!1,j=null;function W(){j!==null&&(clearTimeout(j),j=null)}function ot(){I=!1,V=!1,Y=!1,W()}function ut(){return r!==!1&&C||a!==!1&&R||l!==!1&&$}function z(){(I||V||Y)&&(ut()||(W(),j=setTimeout(()=>{j=null,!ut()&&(ot(),lt())},ei)))}let _=!1;const A=o.ui.outer();function vt(E){if(!h)return;const H=t.getActiveMedia();H&&E.target instanceof Node&&H.contains(E.target)&&at()}A.addEventListener("error",vt);const K=document.createElement("button");K.type="button",K.className="shoji-toolbar-button shoji-autoplay-toggle",K.setAttribute("aria-label",p),K.title=p,K.innerHTML=Fe;const ft=document.createElement("div");ft.className="shoji-autoplay-progress",ft.hidden=!0;const st=document.createElement("div");st.className="shoji-autoplay-progress-bar",ft.appendChild(st);function xt(){S!==null&&(clearTimeout(S),S=null)}function F(){i&&(ft.hidden=!0,st.style.transition="none",st.style.width="0%")}function D(E){i&&(ft.hidden=!1,st.style.transition="none",st.style.width="0%",st.offsetWidth,st.style.transition=`width ${E}ms linear`,st.style.width="100%")}function N(){const E=!h&&(r!==!1&&C||a!==!1&&R);K.ariaDisabled=E?"true":null,E?K.tabIndex=-1:K.removeAttribute("tabindex")}function dt(E){h=E,K.innerHTML=E?Ko:Fe,K.setAttribute("aria-label",E?w:p),K.title=E?w:p,N()}function gt(){h&&at()}function ht(){v!=null&&v.ended||it()}function Et(){v&&(v.removeEventListener("ended",gt),v.removeEventListener("pause",ht),v=null)}function Ot(E,H){E.muted=!0;const G=E.play();G&&typeof G.then=="function"?Ct(E,H,G):jt(E,H)}function jt(E,H){setTimeout(()=>{v!==E||!h||E.paused&&(H>0?Ot(E,H-1):at())},Ne)}function Ct(E,H,G){G.catch(()=>{}),setTimeout(()=>{v!==E||!h||E.paused&&(H>0?Ct(E,H-1,G):at())},Ne)}function yt(){if(xt(),Et(),F(),x=!1,!h)return;const E=t.getActiveMedia(),H=Jo(E);if(H){if(v=H,H.addEventListener("ended",gt),H.addEventListener("pause",ht),H instanceof HTMLVideoElement){const G=H.play();G&&typeof G.catch=="function"&&G.catch(T=>{v!==H||!h||(T instanceof DOMException&&T.name==="NotAllowedError"?it():at())})}else Ot(H,ti);return}x=Qo(E),D(e),S=setTimeout(at,e)}function at(){const E=t.currentIndex;_=!0,t.next(),_=!1,t.currentIndex===E&&it()}function lt(){h||(W(),dt(!0),o.emit("autoplayStart",{}),yt())}function it(){h&&(dt(!1),xt(),F(),v&&!v.paused&&v.pause(),Et(),o.emit("autoplayStop",{}))}function St(){const E=r!==!1&&C,H=a!==!1&&R;!E&&!H||(it(),r==="pause"&&E&&(I=!0),a==="pause"&&H&&(V=!0))}function Tt(){if(h){ot(),it();return}lt(),St()}const bt=o.on("dragCloseThreshold",({hidden:E})=>{E?(M=h,h&&(ot(),it())):M&&(M=!1,lt())}),Bt=1.001,Ht=o.on("zoomChange",({scale:E})=>{C=E>Bt,r!==!1&&C&&h?(r==="stop"&&ot(),it(),r==="pause"&&(I=!0)):(N(),C||z())}),Mt=o.on("rotateFlipChange",({flipH:E,flipV:H,rotation:G})=>{R=E||H||G!==0,a!==!1&&h?(a==="stop"&&ot(),it(),a==="pause"&&(V=!0)):(N(),a!==!1&&!R&&z())}),Lt=o.on("captionModalChange",({open:E})=>{$=E,l!==!1&&E&&h?(l==="stop"&&ot(),it(),l==="pause"&&(Y=!0)):E||z()});K.addEventListener("click",Tt);const y=o.ui.toolbar("right",K),g=i?o.ui.overlay(ft):null,m=o.ui.registerShortcut(" ",Tt),L=o.on("beforeSlide",()=>{Et()}),B=o.on("afterSlide",()=>{C=!1,R=!1,ot(),N(),h&&(c&&!_?it():yt())}),X=o.on("slideItemLoad",({index:E})=>{h&&x&&E===t.currentIndex&&yt()}),d=o.on("requestAutoplayStop",()=>{h&&(ot(),it())}),b=o.on("requestAutoplayStart",()=>{h||(lt(),St())}),P=o.on("close",()=>{ot(),it()}),J=o.on("afterOpen",()=>{C=!1,R=!1,$=!1,ot(),N(),n&<()});return()=>{W(),it(),A.removeEventListener("error",vt),y(),g==null||g(),m(),L(),B(),X(),J(),P(),bt(),Ht(),Mt(),Lt(),d(),b()}}},$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>',ii='<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 ni(){return!!(document.fullscreenEnabled||document.webkitFullscreenEnabled)}function si(){return document.fullscreenElement??document.webkitFullscreenElement??null}function ri(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 ai={name:"fullscreen",init(o){if(!ni())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 si()===t}function a(h){s.innerHTML=h?ii:$e,s.setAttribute("aria-label",h?n:i),s.title=h?n:i,s.setAttribute("aria-pressed",String(h))}function l(){r()?Jt():ri(t)}s.addEventListener("click",l);const c=()=>{const h=r();a(h),o.emit("fullscreenChange",{fullscreen:h})};document.addEventListener("fullscreenchange",c),document.addEventListener("webkitfullscreenchange",c);const u=o.ui.toolbar("right",s),p=o.on("close",()=>{r()&&Jt()}),w=o.on("requestFullscreenToggle",l);return()=>{document.removeEventListener("fullscreenchange",c),document.removeEventListener("webkitfullscreenchange",c),u(),p(),w(),r()&&Jt()}}};function li(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 ci(o,t,e){return(o-t*(e-1))/e}function Ve(o,t,e){const i=li(t),n=ci(t.containerWidth,t.gutterX,i),s=e&&e.length===i?[...e]:new Array(i).fill(0),r=o.map((l,c)=>{const u=t.fill==="ordered"?c%i:di(s),p=l.width>0?n*(l.height/l.width):n,w=u*(n+t.gutterX),h=s[u];return s[u]=h+p+t.gutterY,{x:w,y:h,width:n,height:p}}),a=o.length===0?0:Math.max(...s)-t.gutterY;return{positions:r,columnCount:i,columnWidth:n,columnHeights:s,containerHeight:a}}function di(o){let t=0;for(let e=1;e<o.length;e++)o[e]<o[t]&&(t=e);return t}function hi(o,t){const{containerWidth:e,gutterX:i,gutterY:n,rowHeight:s}=t,r=new Array(o.length);let a=0,l=0,c=0,u=0;function p(S){return S.height>0?s*(S.width/S.height):s}function w(S,v){let x=0;for(let M=S;M<v;M++){const C=p(o[M]);r[M]={x,y:a,width:C,height:s},x+=C+i}u++,a+=s+n}for(let S=0;S<o.length;S++){const v=p(o[S]),x=S-l,M=c+(x>0?i:0)+v;x>0&&M>e?(w(l,S),l=S,c=v):c=M}l<o.length&&w(l,o.length);const h=o.length===0?0:a-n;return{positions:r,rowCount:u,containerHeight:h}}function Dt(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),u=[];let p=0,w=0,h=0;function S(C,R,$){return(e-i*(R-C-1))/$}function v(C,R,$){let I=0;for(let V=C;V<R;V++){const Y=$*Dt(o[V]);c[V]={x:I,y:p,width:Y,height:$},I+=Y+i}u.push({start:C,end:R,y:p,height:$}),p+=$+n}function x(C,R,$){let I=R,V=$,Y=!1;for(;I-C>1&&S(C,I,V)<r;){if(I-C===2&&S(C,C+1,Dt(o[C]))>a){Y=!0;break}I--,V-=Dt(o[I])}const j=S(C,I,V),W=(I-C===1||Y)&&j<r?j:Math.min(Math.max(j,r),a);return v(C,I,W),I}for(let C=0;C<o.length;C++){h+=Dt(o[C]);const R=C-w+1;if(s*h+i*(R-1)>=e){const I=x(w,C+1,h);w=I,h=0;for(let V=I;V<=C;V++)h+=Dt(o[V])}}if(w<o.length)if(l==="justify"){let C=w;for(;C<o.length;){let R=0;for(let $=C;$<o.length;$++)R+=Dt(o[$]);C=x(C,o.length,R)}}else l==="left"&&v(w,o.length,s);const M=o.length===0?0:Math.max(0,p-n);return{positions:c,containerHeight:M,rows:u}}const ui={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 fi(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 pi={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),u=o.options.fill??"shortest",p=Number(o.options.rowHeight??220),w=Number(o.options.minRowHeight??120),h=Number(o.options.maxRowHeight??360),S=o.options.lastRow??"justify",v=o.options.animate!==!1,x=o.options.autoMeasure!==!1,M=e==="masonry"&&s==="horizontal",C=o.options.groupBy,R=o.options.renderHeading,$=o.options.headingOverflow??"show",I=o.options.stickyHeadings===!0,V=I&&e==="grid";I&&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 Y=!!C&&!M,j={gutter:i,columns:r,columnWidth:a,minColumnWidth:l,maxColumnWidth:c,fill:u,rowHeight:p,minRowHeight:w,maxRowHeight:h,lastRow:S},W=o.options.breakpoints,ot=W?Object.entries(W).map(([y,g])=>[Number(y),g]).sort((y,g)=>y[0]-g[0]):[];function ut(y){const g=ot.find(([L])=>y<=L);if(!g)return j;const m=g[1];return{gutter:m.gutter!==void 0?Ye(m.gutter):j.gutter,columns:m.columns??j.columns,columnWidth:m.columnWidth??j.columnWidth,minColumnWidth:m.minColumnWidth??j.minColumnWidth,maxColumnWidth:m.maxColumnWidth??j.maxColumnWidth,fill:m.fill??j.fill,rowHeight:m.rowHeight??j.rowHeight,minRowHeight:m.minRowHeight??j.minRowHeight,maxRowHeight:m.maxRowHeight??j.maxRowHeight,lastRow:m.lastRow??j.lastRow}}const z=t.element;z.classList.add("shoji-layout",`shoji-layout--${e}`),v&&z.classList.add("shoji-layout--animate");let _=[],A=[],vt,K=[],ft=!1;const st=new WeakMap;function xt(y){const g=[];for(let m=0;m<y.length;m++){const L=C(y[m]),B=g[g.length-1];!B||B.key!==L?g.push({key:L,startIndex:m,endIndex:m+1}):B.endIndex=m+1}return g}function F(y,g){const m=R?R(y,g):y;let L,B=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 X=document.createElement("span");X.className="shoji-layout-heading-title",X.textContent=m.title,L.appendChild(X);let d=null;m.subtitle&&(d=document.createElement("span"),d.className="shoji-layout-heading-subtitle",d.textContent=m.subtitle,L.appendChild(d)),B={titleEl:X,subtitleEl:d}}return L.classList.add("shoji-layout-heading"),V&&L.classList.add("shoji-layout-heading--sticky"),{root:L,structured:B}}function D(){return A.map((y,g)=>({heading:y,start:y.tileStart,end:g+1<A.length?A[g+1].tileStart:_.length}))}function N(y){return y.thumb??y.poster??(y.video?void 0:y.src)}function dt(y){if(y!=null&&y.width&&y.height)return{width:y.width,height:y.height};const g=y&&st.get(y);if(g)return g;const m=x&&!!y&&!!N(y);return!ft&&!m&&(ft=!0,console.warn(x?"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.")),ui}function gt(y,g){const m=document.createElement("a");m.className="shoji-layout-tile",y.id&&(m.dataset.shojiId=y.id),m.dataset.shojiIndex=String(g);const L=document.createElement("img");L.src=y.thumb??y.poster??y.src,L.loading="lazy",L.alt=y.alt??"",m.appendChild(L);const B={index:g,root:m,img:L};return m.addEventListener("click",X=>{X.preventDefault(),t.open(B.index)}),B}function ht(y){const g=z.getBoundingClientRect().width,m=ut(g);z.style.setProperty("--shoji-layout-column-width",`${m.columnWidth}px`),z.style.setProperty("--shoji-layout-gutter",`${m.gutter.y}px ${m.gutter.x}px`);for(const L of y)L.root.style.setProperty("--shoji-layout-tile-aspect",`${n}`)}function Et(y){const g=z.getBoundingClientRect().width;if(g<=0)return;const m=ut(g),L={containerWidth:g,gutterX:m.gutter.x,gutterY:m.gutter.y,columns:m.columns,columnWidth:m.columnWidth,minColumnWidth:m.minColumnWidth,maxColumnWidth:m.maxColumnWidth,fill:m.fill};if(Y&&A.length>0){const P=D(),J=P.map(H=>H.heading.root.getBoundingClientRect().height);let E=0;P.forEach(({heading:H,start:G,end:T},O)=>{const k=_.slice(G,T);H.root.style.transform=`translate(0px, ${E}px)`,E+=J[O]+m.gutter.y;const Z=Ve(k.map(q=>dt(t.items[q.index])),L);k.forEach((q,tt)=>{const nt=Z.positions[tt];q.root.style.width=`${nt.width}px`,q.root.style.height=`${nt.height}px`,q.root.style.visibility="visible",q.root.style.transform=`translate(${nt.x}px, ${E+nt.y}px)`}),E+=Z.containerHeight+m.gutter.y}),vt=void 0,z.style.height=`${Math.max(0,E-m.gutter.y)}px`;return}const B=y??_,X=B.map(P=>dt(t.items[P.index])),b=Ve(X,L,y?vt:void 0);B.forEach((P,J)=>{const E=b.positions[J];P.root.style.width=`${E.width}px`,P.root.style.height=`${E.height}px`,P.root.style.visibility="visible",P.root.style.transform=`translate(${E.x}px, ${E.y}px)`}),vt=b.columnHeights,z.style.height=`${b.containerHeight}px`}function Ot(){const y=z.getBoundingClientRect().width;if(y<=0)return;const g=ut(y),m=_.map(B=>dt(t.items[B.index])),L=hi(m,{containerWidth:y,gutterX:g.gutter.x,gutterY:g.gutter.y,rowHeight:g.rowHeight});_.forEach((B,X)=>{const d=L.positions[X];B.root.style.width=`${d.width}px`,B.root.style.height=`${d.height}px`,B.root.style.visibility="visible",B.root.style.transform=`translate(${d.x}px, ${d.y}px)`}),z.style.height=`${L.containerHeight}px`}function jt(y,g,m){const L=new Map,B=new Map;if($==="fit")for(const T of A){if(!T.structured)continue;const{subtitleEl:O}=T.structured;T.root.style.maxWidth="none",T.root.style.whiteSpace="nowrap",O&&(O.hidden=!1),L.set(T.tileStart,T.root.getBoundingClientRect().width),O?(O.hidden=!0,B.set(T.tileStart,T.root.getBoundingClientRect().width),O.hidden=!1):B.set(T.tileStart,L.get(T.tileStart))}function X(T,O){return _.slice(T,O).map(k=>dt(t.items[k.index]))}function d(T,O){const k=A[T].tileStart,Z=O<A.length?A[O].tileStart:_.length,q=Vt(X(k,Z),y);for(let tt=T;tt<O;tt++){const nt=A[tt];if(!nt.structured)continue;const U=q.positions[nt.tileStart-k];if(!U)continue;const et=tt+1<O?A[tt+1]:void 0,pt=et?q.positions[et.tileStart-k]:null,oe=(!!pt&&Math.abs(pt.y-U.y)<.5?pt.x:m)-U.x-g.gutter.x;if(Math.min(L.get(nt.tileStart)??1/0,B.get(nt.tileStart)??1/0)>oe)return null}return q}function b(){if($!=="fit")return[{startSection:0,endSection:A.length,tileStart:0,tileEnd:_.length,result:Vt(X(0,_.length),y)}];const T=[];let O=0;for(;O<A.length;){const k=d(O,O+1),Z=A[O].tileStart;if(k===null){const U=O+1<A.length?A[O+1].tileStart:_.length;T.push({startSection:O,endSection:O+1,tileStart:Z,tileEnd:U,result:Vt(X(Z,U),y)}),O+=1;continue}let q=O+1,tt=k;for(;q<A.length;){const U=d(O,q+1);if(U===null)break;q+=1,tt=U}const nt=q<A.length?A[q].tileStart:_.length;T.push({startSection:O,endSection:q,tileStart:Z,tileEnd:nt,result:tt}),O=q}return T}function P(T){for(let O=T.startSection;O<T.endSection;O++){const k=A[O];if(!k.structured)continue;const Z=T.result.positions[k.tileStart-T.tileStart];if(!Z)continue;const q=O+1<T.endSection?A[O+1]:void 0,tt=q?T.result.positions[q.tileStart-T.tileStart]:null,U=(!!tt&&Math.abs(tt.y-Z.y)<.5?tt.x:m)-Z.x-g.gutter.x,{subtitleEl:et}=k.structured;k.root.style.whiteSpace="nowrap",k.root.style.maxWidth="none",k.root.style.overflow="",k.root.style.textOverflow="",et&&(et.hidden=!1),!((L.get(k.tileStart)??0)<=U)&&(et&&(et.hidden=!0,(B.get(k.tileStart)??0)<=U)||(k.root.style.maxWidth=`${Math.max(0,U)}px`,k.root.style.overflow="hidden",k.root.style.textOverflow="ellipsis"))}}function J(T){for(let O=T.startSection;O<T.endSection;O++){const k=A[O];if(!k.structured)continue;const Z=T.result.positions[k.tileStart-T.tileStart];if(!Z)continue;const q=O+1<T.endSection?A[O+1]:void 0,tt=q?T.result.positions[q.tileStart-T.tileStart]:null,U=(!!tt&&Math.abs(tt.y-Z.y)<.5?tt.x:m)-Z.x-g.gutter.x;k.root.style.whiteSpace="normal",k.root.style.maxWidth=`${Math.max(0,U)}px`;const et=getComputedStyle(k.root),pt=parseFloat(et.lineHeight),ee=Number.isFinite(pt)?pt:parseFloat(et.fontSize)*1.2,oe=Math.max(1,Math.floor(g.maxRowHeight/ee));k.root.style.display="-webkit-box",k.root.style.overflow="hidden",k.root.style.setProperty("-webkit-box-orient","vertical"),k.root.style.setProperty("-webkit-line-clamp",`${oe}`)}}const E=b();let H=0,G=0;for(const T of E){$==="fit"?P(T):$==="wrap"&&J(T);const O=new Map;for(let Z=T.startSection;Z<T.endSection;Z++){const q=A[Z];O.set(q.tileStart,q.root.getBoundingClientRect().height)}for(const Z of T.result.rows){const q=Z.start+T.tileStart,tt=Z.end+T.tileStart;let nt=0;for(;G<T.endSection&&A[G].tileStart<tt;){const U=A[G],et=T.result.positions[U.tileStart-T.tileStart];et&&(U.root.hidden=!1,U.root.style.transform=`translate(${et.x}px, ${Z.y+H}px)`,nt=Math.max(nt,O.get(U.tileStart)??0)),G++}nt>0&&(H+=nt+g.gutter.y);for(let U=q;U<tt;U++){const et=T.result.positions[U-T.tileStart],pt=_[U];pt.root.hidden=et===null,et&&(pt.root.style.width=`${et.width}px`,pt.root.style.height=`${et.height}px`,pt.root.style.visibility="visible",pt.root.style.transform=`translate(${et.x}px, ${et.y+H}px)`)}}const k=T.result.rows.length>0?T.result.rows[T.result.rows.length-1].end+T.tileStart:T.tileStart;for(let Z=k;Z<T.tileEnd;Z++)_[Z].root.hidden=!0;H+=T.result.containerHeight+g.gutter.y}for(;G<A.length;)A[G].root.hidden=!0,G++;z.style.height=`${Math.max(0,H-g.gutter.y)}px`}function Ct(){const y=z.getBoundingClientRect().width;if(y<=0)return;const g=ut(y),m={containerWidth:y,gutterX:g.gutter.x,gutterY:g.gutter.y,rowHeight:g.rowHeight,minRowHeight:g.minRowHeight,maxRowHeight:g.maxRowHeight,lastRow:g.lastRow};if(Y&&A.length>0){jt(m,g,y);return}const L=_.map(X=>dt(t.items[X.index])),B=Vt(L,m);_.forEach((X,d)=>{const b=B.positions[d];X.root.hidden=b===null,b&&(X.root.style.width=`${b.width}px`,X.root.style.height=`${b.height}px`,X.root.style.visibility="visible",X.root.style.transform=`translate(${b.x}px, ${b.y}px)`)}),z.style.height=`${B.containerHeight}px`}function yt(){M?Ot():e==="masonry"?Et(null):e==="justified"?Ct():ht(_)}let at=!1,lt=null;function it(){lt!==null||at||(lt=requestAnimationFrame(()=>{lt=null,!at&&(Y?bt(t.items):yt())}))}function St(y){if(x)for(const g of y){const m=t.items[g.index];if(!m||m.width&&m.height||st.has(m)||!N(m))continue;const L=()=>{at||g.img.naturalWidth>0&&g.img.naturalHeight>0&&(st.set(m,{width:g.img.naturalWidth,height:g.img.naturalHeight}),it())};g.img.complete?L():g.img.addEventListener("load",L,{once:!0})}}function Tt(y){o.emit("layoutRender",{tiles:y.map(g=>({index:g.index,element:g.root}))})}function bt(y){if(z.replaceChildren(),_=y.map((g,m)=>gt(g,m)),A=[],Y)for(const g of xt(y)){const m=y.slice(g.startIndex,g.endIndex),{root:L,structured:B}=F(g.key,m);z.appendChild(L),A.push({root:L,tileStart:g.startIndex,structured:B});for(let X=g.startIndex;X<g.endIndex;X++)z.appendChild(_[X].root)}else for(const g of _)z.appendChild(g.root);vt=void 0,yt(),St(_),Tt(_)}function Bt(y,g){const m=y.map((L,B)=>gt(L,g+B));for(const L of m)z.appendChild(L.root);_=[..._,...m],M?Ot():e==="masonry"?Et(m):e==="justified"?Ct():ht(m),St(m),Tt(m)}bt(t.items),K=t.items;const Ht=o.on("itemsUpdated",({items:y})=>{Y?bt(y):fi(K,y)?Bt(y.slice(K.length),K.length):bt(y),K=y});let Mt=null,Lt;return(e==="masonry"||e==="justified"||ot.length>0)&&(Lt=new ResizeObserver(()=>{Mt===null&&(Mt=requestAnimationFrame(()=>{Mt=null,yt()}))}),Lt.observe(z)),()=>{at=!0,lt!==null&&cancelAnimationFrame(lt),Lt==null||Lt.disconnect(),Mt!==null&&cancelAnimationFrame(Mt),Ht(),z.classList.remove("shoji-layout",`shoji-layout--${e}`,"shoji-layout--animate"),z.style.removeProperty("height"),z.style.removeProperty("width"),z.replaceChildren()}}};function mi(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 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="M9 14 4 9l5-5"/><path d="M4 9h10a6 6 0 1 1 0 12H9"/></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="M15 14 20 9l-5-5"/><path d="M20 9H10a6 6 0 1 0 0 12h5"/></svg>',yi='<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>',bi='<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 wi(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 Ei(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 Ci={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,u=!1;function p(F){const D=t.items[t.currentIndex];if(D!=null&&D.width&&D.height)return{width:D.width,height:D.height};const N=F.querySelector("img");if(N!=null&&N.naturalWidth&&N.naturalHeight)return{width:N.naturalWidth,height:N.naturalHeight}}function w(F){const D=t.getActiveMedia();if(!D)return;const N=p(D),dt=Ei(D.clientWidth,D.clientHeight,l,N==null?void 0:N.width,N==null?void 0:N.height),gt=wi(c,u,l,dt);if(!F){D.style.transform=gt;return}D.style.transition="transform var(--shoji-duration) var(--shoji-easing)",D.style.transform=gt,It(D,()=>{D.style.transition=""})}function h(F,D){const N=document.createElement("button");return N.type="button",N.className="shoji-toolbar-button",N.innerHTML=F,N.setAttribute("aria-label",D),N.title=D,N}const S=h(gi,i),v=h(vi,n),x=h(yi,s),M=h(bi,r);x.setAttribute("aria-pressed","false"),M.setAttribute("aria-pressed","false");function C(F,D){a=mi({...a,...F}),D!==void 0&&(l+=D),w(!0),x.setAttribute("aria-pressed",String(a.flipH)),M.setAttribute("aria-pressed",String(a.flipV)),o.emit("rotateFlipChange",{index:t.currentIndex,...a})}function R(F){return F!==(c!==u)?90:-90}function $(){const F=R(!1);C({rotation:a.rotation+F},F)}function I(){const F=R(!0);C({rotation:a.rotation+F},F)}function V(){c=!c,C({flipH:!a.flipH})}function Y(){u=!u,C({flipV:!a.flipV})}S.addEventListener("click",$),v.addEventListener("click",I),x.addEventListener("click",V),M.addEventListener("click",Y);function j(){a={...ze},l=0,c=!1,u=!1,w(!1),x.setAttribute("aria-pressed","false"),M.setAttribute("aria-pressed","false")}let W=null;function ot(){const F=t.getActiveMedia(),D=F==null?void 0:F.style.transform;W=D&&D!=="none"?D:null}const ut=[S,v,x,M].map(F=>o.ui.toolbar("right",F)),z=o.on("requestRotateLeft",$),_=o.on("requestRotateRight",I),A=o.on("requestFlipHorizontal",V),vt=o.on("requestFlipVertical",Y),K=o.on("afterOpen",j),ft=o.on("beforeSlide",()=>{ot(),j()}),st=o.on("afterSlide",j),xt=t.registerSlideLeaveDecorator(F=>{if(!W)return;const D=W;return W=null,F.style.transform=D,()=>{F.style.transition="transform var(--shoji-duration) var(--shoji-easing)",F.style.transform="none"}});return()=>{for(const F of ut)F();z(),_(),A(),vt(),K(),ft(),st(),xt()}}};let Yt=null;const Si=250;function Ti(){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 Mi(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 Li=(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(u=>u.ok?u.json():null).then(u=>{i.aborted||typeof(u==null?void 0:u.thumbnail_url)=="string"&&n(u.thumbnail_url)}).catch(()=>{})}const a=document.createElement("div");a.className="shoji-video-mount",o.appendChild(a),Ti().then(c=>{if(i.aborted)return;const u=o,p=new c.Player(a,{...r?{url:r}:{id:Number(s)},playsinline:!0});let w=null;function h(){w!==null&&(clearTimeout(w),w=null)}p.on("play",()=>{h(),u.paused=!1,u.dispatchEvent(new Event("play"))}),p.on("pause",()=>{u.paused=!0,h(),w=setTimeout(()=>{w=null,u.dispatchEvent(new Event("pause"))},Si)}),p.on("ended",()=>{h(),u.paused=!0,u.ended=!0,u.dispatchEvent(new Event("ended"))}),p.on("error",S=>u.dispatchEvent(new CustomEvent("error",{bubbles:!0,detail:{name:S.name}}))),p.ready().then(()=>{Mi(o,p),Promise.all([p.getVideoWidth(),p.getVideoHeight()]).then(([S,v])=>{S&&v&&o.style.setProperty("--shoji-provider-video-aspect",`calc(${S} / ${v})`)}).catch(()=>{}).then(()=>e())}),i.addEventListener("abort",()=>{h(),p.destroy()},{once:!0})})};let Wt=null;function xi(){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 Oi(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 ji(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 Pi=(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),xi().then(l=>{if(i.aborted)return;const c=o,u=new l.Player(r,{videoId:s,playerVars:{playsinline:1,rel:0},events:{onReady:()=>{Oi(o,u),e()},onStateChange:p=>ji(p,l,c),onError:p=>c.dispatchEvent(new CustomEvent("error",{bubbles:!0,detail:{code:p.data}}))}});i.addEventListener("abort",()=>u.destroy(),{once:!0})})},Ri={name:"video",init(o){const t=o.ui.registerVideoProvider("youtube",Pi),e=o.ui.registerVideoProvider("vimeo",Li);return()=>{t(),e()}}},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.5M10 7v6M7 10h6"/></svg>',Ai='<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>',Ii='<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 ki(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 Di(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 Bi(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,u=[{x:0,y:0},{x:s,y:0},{x:0,y:r},{x:s,y:r}].map(({x:h,y:S})=>{const v={x:n.tx+t.tx+h*e,y:n.ty+t.ty+S*e},x=Xe(v.x,v.y,i);return{x:a+x.tx,y:l+x.ty}}),p=u.map(h=>h.x),w=u.map(h=>h.y);return{left:Math.min(...p),top:Math.min(...w),right:Math.max(...p),bottom:Math.max(...w)}}function Ze(o,t,e,i,n=zt,s=te(o)){const r=Bi(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},u=Qt(c.tx,c.ty,n);return{tx:i.tx+u.tx,ty:i.ty+u.ty}}function Fi(o,t,e,i,n,s,r=zt,a=te(o)){const l=Di(o,t,r,a),c=n-l.x,u=s-l.y,p=Qt(c,u,r),w=1-i/e;return{tx:t.tx+p.tx*w,ty:t.ty+p.ty*w}}const Rt=1.001;function Ni(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(Zo,{Autoplay:oi,Layout:pi,ActiveThumbnail:Uo,Fullscreen:ai,RotateFlip:Ci,Video:Ri,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,u={tx:0,ty:0},p=null,w=null,h=null,S=1;function v(){const d=t.getActiveMedia(),b=d==null?void 0:d.firstElementChild;return b instanceof HTMLImageElement?b:null}function x(d){const b=d.getBoundingClientRect();return{left:b.left,top:b.top,width:b.width,height:b.height}}function M(d){return p&&w&&h?!0:c!==1?!1:(p=x(d),w=x(d.parentElement??d),h={tx:-(d.offsetWidth||p.width)/2,ty:-(d.offsetHeight||p.height)/2},!0)}function C(d){const b=t.getActiveMedia();if(!b||b.style.transition===""){d();return}It(b,d)}function R(){const d=v();d&&(d.style.transformOrigin="0 0",d.style.transform=c===1&&u.tx===0&&u.ty===0?"none":`translate3d(${u.tx}px, ${u.ty}px, 0) scale3d(${c}, ${c}, 1)`,d.classList.toggle("shoji-zoomed",c>1))}function $(){o.emit("zoomChange",{index:t.currentIndex,scale:c})}function I(d,b,P){d.style.transition="transform var(--shoji-duration) var(--shoji-easing)",b(),It(d,()=>{d.style.transition="",P==null||P()})}function V(d,b,P,J=e,E=!1){C(()=>{const H=v();if(!H||!M(H))return;const G=ki(d,1,Math.max(J,1)),T=t.getActiveMedia(),O=_e(T?getComputedStyle(T).transform:"none");u=Fi(p,u,c,G,b,P,O,h),c=G,u=Ze(p,w,c,u,O,h),E?I(H,R):R(),$()})}function Y(d=!1){const b=c!==1;c=1,u={tx:0,ty:0},p=null,w=null,h=null,b&&$();const P=v();if(!P)return;const J=()=>{P.style.transform="",P.classList.remove("shoji-zoomed")};d?I(P,J,()=>{P.style.transformOrigin=""}):(J(),P.style.transformOrigin="")}let j=null,W="";function ot(){const d=v(),b=d==null?void 0:d.style.transform;j=b&&b!=="none"?b:null,W=(d==null?void 0:d.style.transformOrigin)||"0 0"}function ut(){var d;(d=v())==null||d.classList.add("shoji-zoom-enabled")}function z(d,b){c>Rt?Y(!0):V(i,d,b,e,!0)}const _=o.on("pinchStart",()=>{S=c}),A=o.on("pinchMove",({scale:d,centerX:b,centerY:P})=>{V(S*d,b,P)}),vt=o.on("pinchEnd",()=>{c<=Rt&&Y()}),K=o.on("doubleTap",({x:d,y:b})=>z(d,b)),ft=o.on("wheelZoom",({deltaScale:d,x:b,y:P})=>{V(c+d,b,P)}),st=o.on("requestZoomIn",at),xt=o.on("requestZoomOut",lt),F=o.on("requestZoomActualSize",it),D=o.on("requestZoomReset",()=>Y(!0));let N=null,dt=0,gt=0;const ht=o.ui.outer();function Et(d){if(c<=Rt||Ni(d))return;const b=v();!b||!d.composedPath().includes(b)||(N=d.pointerId,dt=d.clientX,gt=d.clientY,b.setPointerCapture(d.pointerId))}function Ot(d){if(N!==d.pointerId||!p||!w||!h)return;d.preventDefault();const b=d.clientX-dt,P=d.clientY-gt;dt=d.clientX,gt=d.clientY;const J=t.getActiveMedia(),E=_e(J?getComputedStyle(J).transform:"none"),{tx:H,ty:G}=Qt(b,P,E);u=Ze(p,w,c,{tx:u.tx+H,ty:u.ty+G},E,h),R()}function jt(d){N===d.pointerId&&(N=null)}ht.addEventListener("pointerdown",Et),ht.addEventListener("pointermove",Ot,{passive:!1}),ht.addEventListener("pointerup",jt),ht.addEventListener("pointercancel",jt);function Ct(d,b){const P=document.createElement("button");return P.type="button",P.className="shoji-toolbar-button",P.innerHTML=d,P.setAttribute("aria-label",b),P.title=b,P}function yt(){const d=t.getActiveMedia(),b=d==null?void 0:d.getBoundingClientRect();return b?{x:b.left+b.width/2,y:b.top+b.height/2}:{x:0,y:0}}function at(){const{x:d,y:b}=yt();V(c*n,d,b,e,!0)}function lt(){const{x:d,y:b}=yt();c/n<=Rt?Y(!0):V(c/n,d,b,e,!0)}function it(){C(()=>{const d=v();if(!d||!d.naturalWidth||!M(d))return;if(c>Rt){Y(!0);return}const b=d.naturalWidth/p.width,{x:P,y:J}=yt();V(b,P,J,b,!0)})}const St=Ct(Hi,r),Tt=Ct(Ai,a),bt=Ct(Ii,l);St.addEventListener("click",at),Tt.addEventListener("click",lt),bt.addEventListener("click",it);const Bt=[St,Tt,bt].map(d=>o.ui.toolbar("right",d));function Ht(){var b;const d=!!((b=t.items[t.currentIndex])!=null&&b.video);St.hidden=d,Tt.hidden=d,bt.hidden=d}const Mt=[o.ui.registerShortcut("w",at),o.ui.registerShortcut("W",at),o.ui.registerShortcut("s",lt),o.ui.registerShortcut("S",lt)],Lt=o.on("afterOpen",()=>{Y(),ut(),Ht()}),y=o.on("beforeSlide",()=>{ot(),Y()}),g=o.on("afterSlide",()=>{Y(),ut(),Ht()}),m=o.on("beforeClose",()=>Y()),L=t.registerZoomGate(()=>c>Rt),B=t.registerZoomStartProvider(()=>{var d;return c>Rt?((d=v())==null?void 0:d.getBoundingClientRect())??null:null}),X=t.registerSlideLeaveDecorator(d=>{if(!j)return;const b=j,P=W;j=null;const J=d.querySelector("img");if(J)return J.style.transformOrigin=P,J.style.transform=b,()=>{J.style.transition="transform var(--shoji-duration) var(--shoji-easing)",J.style.transform="none"}});return ut(),Ht(),()=>{var d;for(const b of Bt)b();for(const b of Mt)b();Lt(),y(),g(),m(),_(),A(),vt(),K(),ft(),st(),xt(),F(),D(),ht.removeEventListener("pointerdown",Et),ht.removeEventListener("pointermove",Ot),ht.removeEventListener("pointerup",jt),ht.removeEventListener("pointercancel",jt),L(),B(),X(),Y(),(d=v())==null||d.classList.remove("shoji-zoom-enabled")}}},version:"0.1.0-beta.13"})}));
|
|
1
|
+
(function(rt,ct){typeof exports=="object"&&typeof module<"u"?module.exports=ct():typeof define=="function"&&define.amd?define(ct):(rt=typeof globalThis<"u"?globalThis:rt||self,rt.Shoji=ct())})(this,(function(){"use strict";var Yi=Object.defineProperty;var Wi=(rt,ct,Rt)=>ct in rt?Yi(rt,ct,{enumerable:!0,configurable:!0,writable:!0,value:Rt}):rt[ct]=Rt;var f=(rt,ct,Rt)=>Wi(rt,typeof ct!="symbol"?ct+"":ct,Rt);let rt=0,ct="",Rt="",ne="",se=0,re=0,Et=null,zt=!1;const ae=".shoji-outer";function Ze(){zt=!0}function Ge(){return getComputedStyle(document.documentElement).direction==="rtl"}function Ue(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 le=!1;function ce(o){const t=o.target;le=!(t instanceof Element&&t.closest(ae)!==null)&&Ue(t)}function de(o){const t=o.target;!(t instanceof Element&&t.closest(ae)!==null)&&!le&&o.preventDefault()}function Ke(){if(rt===0)return;const o=document.documentElement;getComputedStyle(o).overflow!=="hidden"&&(o.style.overflow="hidden",Et==null||Et.takeRecords())}function Je(){if(rt===0){se=window.scrollX,re=window.scrollY,zt=!1;const o=window.innerWidth-document.documentElement.clientWidth,t=Ge();if(Rt=document.documentElement.style.paddingRight,ne=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`}ct=document.documentElement.style.overflow,document.documentElement.style.overflow="hidden",document.addEventListener("touchstart",ce,{passive:!0}),document.addEventListener("touchmove",de,{passive:!1}),Et=new MutationObserver(Ke),Et.observe(document.documentElement,{attributes:!0,attributeFilter:["style"]})}rt++}function Qe(){rt=Math.max(0,rt-1),rt===0&&(Et==null||Et.disconnect(),Et=null,document.removeEventListener("touchstart",ce),document.removeEventListener("touchmove",de),document.documentElement.style.overflow=ct,document.documentElement.style.paddingRight=Rt,document.documentElement.style.paddingLeft=ne,zt||window.scrollTo({left:se,top:re,behavior:"instant"}))}class to{constructor(){f(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 he='<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>',eo='<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>',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="M9 6l6 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"><rect x="3" y="5" width="18" height="14" rx="2"/><path d="M7 10h10M7 14h6"/></svg>',no='<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 so=0;function At(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 ro(o,t){const e=`shoji-counter-${++so}`,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 h=At("shoji-close",he,t.close),p=At("shoji-toolbar-button shoji-caption-toggle",io,t.showCaption);p.setAttribute("aria-pressed","false"),p.hidden=!0;const E=At("shoji-toolbar-button shoji-toolbar-overflow",no,t.moreControls);E.setAttribute("aria-haspopup","true"),E.setAttribute("aria-expanded","false"),E.hidden=!0,c.append(p,E,h);const u=document.createElement("div");u.className="shoji-toolbar-overflow-panel",u.setAttribute("role","dialog"),u.setAttribute("aria-label",t.moreControls),u.tabIndex=-1,u.hidden=!0;const C=document.createElement("div");C.className="shoji-counter",C.id=e,a.appendChild(C),r.append(a,l,c),s.appendChild(r),s.appendChild(u);const g=At("shoji-nav shoji-nav-prev",eo,t.previous),j=At("shoji-nav shoji-nav-next",oo,t.next);s.appendChild(g),s.appendChild(j),s.appendChild(o);const M=document.createElement("div");M.className="shoji-caption",s.appendChild(M);const T=document.createElement("div");T.className="shoji-caption-modal",T.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 N=At("shoji-caption-modal-close",he,t.close),k=document.createElement("div");return k.className="shoji-caption-modal-content",R.append(N,k),T.appendChild(R),s.appendChild(T),i.appendChild(s),{outer:i,backdrop:n,dialog:s,counter:C,caption:M,captionModal:T,captionModalPanel:R,captionModalContent:k,captionModalCloseButton:N,closeButton:h,prevButton:g,nextButton:j,captionToggleButton:p,toolbar:r,toolbarLeft:a,toolbarCenter:l,toolbarRight:c,toolbarOverflowButton:E,toolbarOverflowPanel:u}}const ao='a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), video[controls], [tabindex]:not([tabindex="-1"])';class lo{constructor(){f(this,"container",null);f(this,"previouslyFocused",null);f(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(ao)):[]}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 co=300,ho=30,uo=500;class fo{constructor(t,e,i){f(this,"target");f(this,"options");f(this,"callbacks");f(this,"pointers",new Map);f(this,"primaryPointerId",null);f(this,"direction",null);f(this,"dragStartDistance",0);f(this,"pinching",!1);f(this,"pinchStartDistance",0);f(this,"capturedThisGesture",!1);f(this,"lastTapTime",-1/0);f(this,"lastTapX",0);f(this,"lastTapY",0);f(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=ue(r,a);const l=fe(r,a);(s=(n=this.callbacks).onPinchStart)==null||s.call(n,l.x,l.y)}}});f(this,"onPointerMove",t=>{var r,a,l,c,h,p,E,u;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[C,g]=[...this.pointers.values()],j=ue(C,g),M=this.pinchStartDistance>0?j/this.pinchStartDistance:1,T=fe(C,g);(a=(r=this.callbacks).onPinchMove)==null||a.call(r,M,T.x,T.y);return}if(t.pointerId!==this.primaryPointerId)return;const i=t.clientX-e.startX,n=t.clientY-e.startY;if(this.direction===null){const C=Math.abs(i),g=Math.abs(n);if(Math.max(C,g)<this.options.lockThreshold)return;this.direction=C>g?"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),(p=(h=this.callbacks).onDragStart)==null||p.call(h,this.direction,t)}this.direction==="horizontal"&&t.preventDefault();const s=(this.direction==="horizontal"?i:n)-this.dragStartDistance;(u=(E=this.callbacks).onDragMove)==null||u.call(E,this.direction,s,t)});f(this,"onPointerUp",t=>{this.finishPointer(t,!1)});f(this,"onPointerCancel",t=>{this.finishPointer(t,!0)});f(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<=uo&&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,h=c/l,p=!e&&(Math.abs(c)>=this.options.swipeThreshold||Math.abs(h)>=this.options.swipeVelocity);(a=(r=this.callbacks).onDragEnd)==null||a.call(r,this.direction,c,h,p,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<=co&&Math.hypot(t-this.lastTapX,e-this.lastTapY)<=ho?((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 ue(o,t){return Math.hypot(o.lastX-t.lastX,o.lastY-t.lastY)}function fe(o,t){return{x:(o.lastX+t.lastX)/2,y:(o.lastY+t.lastY)/2}}function pe(){return typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}function po(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 me(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 ge(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?me(s,t,e):s}function ve(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 mo(o){const t=o.querySelector("img");if(t){const e=t.getBoundingClientRect();if(e.width>0&&e.height>0)return e}return o.getBoundingClientRect()}function ye(o,t,e,i){const n=mo(o),s=ge(t,e,i);return s.width===0||s.height===0||n.width===0||n.height===0?null:ve(s,n)}function It(o,t,e="transform"){const i=po(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 be(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(pe())return;const n=ye(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",It(t,()=>be(t,"none")))}function vo({origin:o,target:t,aspectRatio:e,naturalSize:i,dragStart:n,zoomStart:s},r){if(pe()){r();return}const a=ye(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=ge(t,e,i);if(c.width>0&&c.height>0){const h=t.style.transform,p=ve(c,s);t.style.transition="none",t.style.transform=h&&h!=="none"?`${h} ${p}`:p,t.offsetHeight}}t.style.transition="transform var(--shoji-duration) var(--shoji-easing)",t.offsetHeight,t.style.transform=a;const l=t.style.transform;It(t,()=>{be(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)",we=160,wo="button, video, input, select, textarea, a[href], [data-shoji-no-drag], .shoji-caption, .shoji-caption-modal, .shoji-toolbar-overflow-panel",Co="button, input, select, textarea, a[href], [data-shoji-no-drag], .shoji-caption, .shoji-caption-modal, .shoji-toolbar-overflow-panel";function Eo(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?Eo(o,n)?(So(e),!0):!1:i.some(s=>s instanceof Element&&s.matches(Co))}class Lo{constructor(t,e,i){f(this,"engine");f(this,"controlsHideThreshold");f(this,"controlsHiddenForDrag",!1);f(this,"lastDragDelta",0);f(this,"onDragMove",(t,e)=>{this.host.isZoomed()||(t==="horizontal"?this.host.slides.setDragOffset(e,null):this.host.canClose()&&this.applyVerticalDragFeedback(e))});f(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 fo(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}It(i,e)}applyVerticalDragFeedback(t){const e=Math.min(Math.abs(t)/we,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)/we,1),e={translateY:this.lastDragDelta,scale:1-t*.15,opacity:1-t*.6};return this.clearVerticalDragFeedback(!1),e}}class xo{constructor(){f(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 Ce(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 ft(o,t){return o.getAttribute(t)??void 0}function kt(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=ft(o,"data-shoji-caption");i&&(t.caption=i),t.id=ft(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=ft(o,"href")??ft(o,"data-shoji-src");if(!t)return;const e={src:t},i=o.querySelector("img"),n=(i==null?void 0:i.getAttribute("src"))??ft(o,"data-shoji-thumb");n&&(e.thumb=n);const s=(i==null?void 0:i.getAttribute("alt"))??ft(o,"data-shoji-alt");s&&(e.alt=s);const r=kt(o,"data-shoji-width");r!==void 0&&(e.width=r);const a=kt(o,"data-shoji-height");a!==void 0&&(e.height=a);const l=ft(o,"data-shoji-srcset");l&&(e.srcset=l);const c=ft(o,"data-shoji-sizes");return c&&(e.sizes=c),qt(o,e,t),e}function Po(o){var n;const t=ft(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(p=>({src:p.getAttribute("src")??"",type:p.getAttribute("type")??""})).filter(p=>p.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=kt(o,"data-shoji-width");c!==void 0&&(a.width=c);const h=kt(o,"data-shoji-height");return h!==void 0&&(a.height=h),qt(o,a,r),a}const i=ft(o,"data-shoji-video");if(i){const s=ft(o,"data-shoji-video-provider"),r=Ho(i,s,t),a={src:i,video:r.video};r.sources&&(a.sources=r.sources);const l=ft(o,"data-shoji-poster");l&&(a.poster=l);const c=kt(o,"data-shoji-width");c!==void 0&&(a.width=c);const h=kt(o,"data-shoji-height");return h!==void 0&&(a.height=h),qt(o,a,i),a}t&&console.warn(`Shoji: data-shoji-video-id="${t}" ignored — requires a data-shoji-video URL.`)}const Ro=new Set(["youtube","vimeo","html5"]);function Zt(o){return{video:{provider:"html5"},sources:[{src:o,type:Ao(o)}]}}function Ho(o,t,e){if(t&&!Ro.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,Me,xe);if(i)return i;const n=Ee("vimeo",o,t,e,Le,Oe);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 Se=new Set(["youtu.be","youtube.com","youtube-nocookie.com"]),Te=new Set(["vimeo.com","player.vimeo.com"]);function Ft(o){return o.replace(/^(www|m|music)\./,"")}function Me(o){try{return Se.has(Ft(new URL(o,window.location.href).hostname))}catch{return!1}}function Le(o){try{return Te.has(Ft(new URL(o,window.location.href).hostname))}catch{return!1}}function xe(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(!Se.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 Oe(o){var e;let t;try{t=new URL(o,window.location.href)}catch{return}if(Te.has(Ft(t.hostname)))return(e=t.pathname.match(/\/(\d+)(?:\/|$)/))==null?void 0:e[1]}const je=[{provider:"youtube",isHost:Me,detectId:xe},{provider:"vimeo",isHost:Le,detectId:Oe}];function Pe(o){return o.map(t=>{var s,r;if(t.video===!0){const a=je.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=je.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){f(this,"element");f(this,"slots");f(this,"preload");f(this,"videoProviders");f(this,"dragOffsetPx",0);f(this,"cache",new Map);f(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((u,C)=>{const g=C-this.preload,j=e+g,M=r?(j%t.length+t.length)%t.length:j,T=M>=0&&M<t.length?t[M]:void 0;return{offset:g,index:M,item:T}}),l=new Set(a.map(u=>u.index));for(const[u,C]of this.cache)l.has(u)||(Ae(C.node),this.cache.delete(u));const c=new Set,h=new Set;for(const u of a){if(!u.item)continue;const C=this.slots.find(g=>g.assignedIndex===u.index&&g.ready);C&&(c.add(u.index),h.add(C),C.offset!==u.offset&&(C.offset=u.offset,i(u.index)))}const p=this.slots.filter(u=>!h.has(u));a.filter(u=>!u.item||!c.has(u.index)).forEach((u,C)=>{var T;const g=p[C];g.offset=u.offset;const{index:j,item:M}=u;if(!M){g.assignedIndex=null,g.ready=!1,Nt(g.media),g.media.replaceChildren();return}if(g.assignedIndex!==j){if(g.assignedIndex=j,g.ready=!1,Nt(g.media),g.media.replaceChildren(Do()),this.applyAspect(g,M),j===e&&n){const R=M.width&&M.height?{width:M.width,height:M.height}:void 0;this.revealOpenPlaceholder(n,g,j,R)}((T=M.video)==null?void 0:T.provider)==="html5"?this.renderVideo(M,g,j,i):M.video?this.renderProviderVideo(M,g,j,i):this.ensureImageDecoding(M,j,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=me({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 E=document.createElement("div");E.className="shoji-slide-placeholder",E.textContent="Video",this.swapIn(e,E,t,i),n(i);return}t.poster&&Re(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 h=()=>{c||l.signal.aborted||(c=!0,a.hidden=!1,e.media.querySelectorAll(".shoji-slide-spinner, .shoji-slide-open-placeholder, .shoji-slide-provider-poster").forEach(E=>E.remove()),this.applyAspect(e,t),e.ready=!0,this.cache.set(i,{node:a,item:t}),n(i))},p=E=>{t.poster||c||l.signal.aborted||Re(e,E)};r(a,t,h,l.signal,p)}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 Re(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&&Ae(t);const e=o.querySelector(".shoji-slide-provider-video");e&&Ie(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 Ae(o){if(o.tagName!=="VIDEO"){Ie(o);return}const t=o;t.pause(),t.removeAttribute("src"),t.load()}function Ie(o){const t=Gt.get(o);t&&(Gt.delete(o),t.abort())}function ke(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 K(o){return{name:o.name,enter:t=>ke(o.enter,t),leave:t=>ke(o.leave,t)}}const Bo=[K({name:"slide",enter:{directional:!0,translateX:100},leave:{directional:!0,translateX:-100}}),K({name:"fade",enter:{opacity:0},leave:{opacity:0}}),K({name:"zoom",enter:{scale:.6,opacity:0},leave:{scale:1.4,opacity:0}}),K({name:"deck",enter:{translateY:6,scale:.85,opacity:0},leave:{translateY:-4,scale:.92,opacity:0}}),K({name:"slideVertical",enter:{directional:!0,translateY:100},leave:{directional:!0,translateY:-100}}),K({name:"push",enter:{directional:!0,translateX:120},leave:{directional:!0,translateX:-120}}),K({name:"fadeUp",enter:{translateY:12,opacity:0},leave:{translateY:-12,opacity:0}}),K({name:"fadeDown",enter:{translateY:-12,opacity:0},leave:{translateY:12,opacity:0}}),K({name:"fadeLeft",enter:{translateX:-12,opacity:0},leave:{translateX:12,opacity:0}}),K({name:"fadeRight",enter:{translateX:12,opacity:0},leave:{translateX:-12,opacity:0}}),K({name:"zoomOut",enter:{scale:1.4,opacity:0},leave:{scale:.6,opacity:0}}),K({name:"scaleUp",enter:{scale:.7},leave:{scale:1.3}}),K({name:"scaleDown",enter:{scale:1.3},leave:{scale:.7}}),K({name:"rotate",enter:{rotateZ:15,opacity:0},leave:{rotateZ:-15,opacity:0}}),K({name:"rotateLeft",enter:{directional:!0,rotateZ:-25,opacity:0},leave:{directional:!0,rotateZ:25,opacity:0}}),K({name:"rotateRight",enter:{directional:!0,rotateZ:25,opacity:0},leave:{directional:!0,rotateZ:-25,opacity:0}}),K({name:"flipX",enter:{rotateX:90,perspective:1200,opacity:0},leave:{rotateX:-90,perspective:1200,opacity:0}}),K({name:"flipY",enter:{directional:!0,rotateY:90,perspective:1200,opacity:0},leave:{directional:!0,rotateY:-90,perspective:1200,opacity:0}}),K({name:"cube",enter:{directional:!0,rotateY:70,translateX:40,perspective:1600,opacity:1},leave:{directional:!0,rotateY:-70,translateX:-40,perspective:1600,opacity:1}}),K({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}}),K({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 De(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 Be(o,t){const e=getComputedStyle(o),i=Math.max(De(e.transitionDuration),De(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(),Be(s,()=>s.remove()),Be(l,()=>i(l))}}function Ut(o){return o.id??o.src}function _o(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,Fe={close:"Close",previous:"Previous image",next:"Next image",showCaption:"Show caption",hideCaption:"Hide caption",fullCaption:"Full caption",moreControls:"More controls"};function zo(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={}){f(this,"options",{});f(this,"element");f(this,"bus",new to);f(this,"selector",Xt);f(this,"isDynamicMode",!1);f(this,"preload",1);f(this,"locale",Fe);f(this,"showCounter",!0);f(this,"captionVisibleOnVideo",!1);f(this,"captionFadePending",!1);f(this,"loop",!0);f(this,"closable",!0);f(this,"autoHideDelay",5e3);f(this,"maxPinnedToolbarButtons",2);f(this,"focusTrap",new lo);f(this,"liveRegion",new xo);f(this,"autoHideTimer",null);f(this,"autoHidden",!1);f(this,"hoverableElements",new Set);f(this,"hoveringElements",new Set);f(this,"isClosing",!1);f(this,"controlsHiddenByDrag",!1);f(this,"itemList",[]);f(this,"scannedElements",[]);f(this,"activeIndex",0);f(this,"opened",!1);f(this,"destroyed",!1);f(this,"slides",null);f(this,"dom",null);f(this,"gesture",null);f(this,"transition",null);f(this,"toolbarHeightObserver",null);f(this,"toolbarHeightFrame",null);f(this,"captionTruncationFrame",null);f(this,"captionModalOpen",!1);f(this,"captionModalReturnFocus",null);f(this,"captionModalOpenedViaKeyboard",!1);f(this,"pluginToolbarButtons",[]);f(this,"toolbarOverflowOpen",!1);f(this,"toolbarOverflowReturnFocus",null);f(this,"shortcuts",new Map);f(this,"pluginStorage",new Map);f(this,"activePluginNames",new Set);f(this,"videoProviders",new Map);f(this,"zoomGate",null);f(this,"zoomStartProvider",null);f(this,"slideLeaveDecorators",new Set);f(this,"pluginCleanups",[]);f(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}});f(this,"onOuterClick",t=>{var e;this.closable&&zo(t,((e=this.dom)==null?void 0:e.caption)??null)&&this.close()});f(this,"onActivity",()=>{this.reconcileHover(),!(this.autoHideDelay===0||this.autoHideDelay===!1||this.isClosing||this.controlsHiddenByDrag||this.captionModalOpen)&&(this.showControls(),this.scheduleAutoHide())});f(this,"controlsHiddenAtGestureStart",!1);f(this,"captureGestureStartState",()=>{this.controlsHiddenAtGestureStart=this.autoHidden});f(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()}});f(this,"onCaptionModalKeydown",t=>{t.stopPropagation(),t.key==="Escape"&&this.closeCaptionModal()});f(this,"onToolbarOverflowKeydown",t=>{t.stopPropagation(),t.key==="Escape"&&this.closeToolbarOverflow()});f(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=_o(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={...Fe,...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=Pe(t.items??[]);else{const e=Ce(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=ro(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 p=this.pluginToolbarButtons.filter(E=>E.slot==="right"&&E.el.parentElement===n&&!E.el.hidden).length+(s.hidden?0:1)+1;i.style.gridTemplateColumns=`repeat(${p}, 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}markIntentionalScroll(){Ze()}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 E of r.getClientRects()){if(E.height===0)continue;const u=E.top-s,C=E.bottom-s;C<=n?C>a&&(a=C):u<l&&(l=u)}const h=(a>0?a:n)+i,p=Number.isFinite(l)?Math.min(h,l):h;t.style.maxHeight=`${Math.max(0,Math.floor(p)-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,Je();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,Qe(),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=Pe(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=Ce(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,highlight:!1,borderColor:"blue"},init(o){const{gallery:t}=o,e=String(o.options.activeClass??"shoji-thumb-active"),i=o.options.scrollIntoView!==!1,n=o.options.highlight===!0,s=String(o.options.borderColor??"blue"),r=typeof o.options.highlightDuration=="number"?o.options.highlightDuration:null,a=typeof o.options.highlightFadeDuration=="number"?o.options.highlightFadeDuration:800,l="shoji-thumb-active--highlight";let c=null,h=null,p=null,E=null;function u(){p!==null&&(clearTimeout(p),p=null)}function C(){E!==null&&(clearTimeout(E),E=null)}function g(x){C();const $=t.getOriginElement(x);return c&&c!==$&&(c.classList.remove(e),n&&c.classList.remove(l)),$&&($.classList.add(e),n&&($.classList.add(l),$.style.setProperty("--shoji-active-thumbnail-border-color",s),$.style.setProperty("--shoji-active-thumbnail-fade-duration",`${a}ms`))),c=$,$}function j(x){try{t.markIntentionalScroll(),x.scrollIntoView({block:"nearest",inline:"nearest",behavior:Zo()?"auto":"smooth"})}catch{}}function M(x){h=x,u();const $=g(x);$&&i&&(p=setTimeout(()=>{p=null,j($)},80))}function T(){const x=p!==null?c:null;if(u(),x&&i&&j(x),n&&r!==null&&c){const $=c;E=setTimeout(()=>{E=null,$.style.setProperty("--shoji-active-thumbnail-border-color","transparent")},r)}}function R(){u(),C(),c==null||c.classList.remove(e),n&&(c==null||c.classList.remove(l)),c=null,h=null}const N=o.on("afterOpen",({index:x})=>M(x)),k=o.on("afterSlide",({to:x})=>M(x)),X=o.on("beforeClose",T),q=o.on("layoutRender",()=>{h!==null&&g(h)});return()=>{N(),k(),X(),q(),R()}}};function Jt(o,t){const e=document.createElement("span");e.className="shoji-icon-swap";const i=document.createElement("span");i.className="shoji-icon-swap-icon shoji-icon-swap-icon--off",i.innerHTML=o;const n=document.createElement("span");return n.className="shoji-icon-swap-icon shoji-icon-swap-icon--on",n.innerHTML=t,e.append(i,n),{el:e,setState(s){e.classList.toggle("shoji-icon-swap--on",s)}}}const Uo='<svg viewBox="0 0 24 24" width="24" height="24" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>',Ko='<svg viewBox="0 0 24 24" width="24" height="24" fill="currentColor"><path d="M7 5h4v14H7zM13 5h4v14h-4z"/></svg>';function Jo(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 Qo(o){const t=o==null?void 0:o.querySelector(".shoji-slide-provider-video");return!!t&&typeof t.play!="function"}const Ne=400,ti=8,ei=1e3,oi={name:"autoplay",defaults:{interval:5e3,showProgress:!0,onZoom:"stop",onRotateFlip:"stop",onCaptionExpand:"stop",stopOnManualNavigate:!0},init(o){const{gallery:t}=o,e=Number(o.options.interval??5e3),i=o.options.showProgress!==!1,n=o.options.autoStart===!0,s=w=>w===!1||w==="pause"?w:"stop",r=s(o.options.onZoom),a=s(o.options.onRotateFlip),l=s(o.options.onCaptionExpand),c=o.options.stopOnManualNavigate!==!1,h=o.options.locale,p=(h==null?void 0:h.play)??"Play slideshow",E=(h==null?void 0:h.pause)??"Pause slideshow";let u=!1,C=null,g=null,j=!1,M=!1,T=!1,R=!1,N=!1,k=!1,X=!1,q=!1,x=null;function $(){x!==null&&(clearTimeout(x),x=null)}function et(){k=!1,X=!1,q=!1,$()}function yt(){return r!==!1&&T||a!==!1&&R||l!==!1&&N}function V(){(k||X||q)&&(yt()||($(),x=setTimeout(()=>{x=null,!yt()&&(et(),gt())},ei)))}let Y=!1;const I=o.ui.outer();function bt(w){if(!u)return;const H=t.getActiveMedia();H&&w.target instanceof Node&&H.contains(w.target)&&st()}I.addEventListener("error",bt);const U=document.createElement("button");U.type="button",U.className="shoji-toolbar-button shoji-autoplay-toggle",U.setAttribute("aria-label",p),U.title=p;const St=Jt(Uo,Ko);U.appendChild(St.el);const dt=document.createElement("div");dt.className="shoji-autoplay-progress",dt.hidden=!0;const lt=document.createElement("div");lt.className="shoji-autoplay-progress-bar",dt.appendChild(lt);function F(){C!==null&&(clearTimeout(C),C=null)}function D(){i&&(dt.hidden=!0,lt.style.transition="none",lt.style.width="0%")}function Z(w){i&&(dt.hidden=!1,lt.style.transition="none",lt.style.width="0%",lt.offsetWidth,lt.style.transition=`width ${w}ms linear`,lt.style.width="100%")}function it(){const w=!u&&(r!==!1&&T||a!==!1&&R);U.ariaDisabled=w?"true":null,w?U.tabIndex=-1:U.removeAttribute("tabindex")}function pt(w){u=w,St.setState(w),U.setAttribute("aria-label",w?E:p),U.title=w?E:p,it()}function Tt(){u&&st()}function ht(){g!=null&&g.ended||ot()}function Mt(){g&&(g.removeEventListener("ended",Tt),g.removeEventListener("pause",ht),g=null)}function Ht(w,H){w.muted=!0;const y=w.play();y&&typeof y.then=="function"?xt(w,H,y):Lt(w,H)}function Lt(w,H){setTimeout(()=>{g!==w||!u||w.paused&&(H>0?Ht(w,H-1):st())},Ne)}function xt(w,H,y){y.catch(()=>{}),setTimeout(()=>{g!==w||!u||w.paused&&(H>0?xt(w,H-1,y):st())},Ne)}function mt(){if(F(),Mt(),D(),j=!1,!u)return;const w=t.getActiveMedia(),H=Jo(w);if(H){if(g=H,H.addEventListener("ended",Tt),H.addEventListener("pause",ht),H instanceof HTMLVideoElement){const y=H.play();y&&typeof y.catch=="function"&&y.catch(L=>{g!==H||!u||(L instanceof DOMException&&L.name==="NotAllowedError"?ot():st())})}else Ht(H,ti);return}j=Qo(w),Z(e),C=setTimeout(st,e)}function st(){const w=t.currentIndex;Y=!0,t.next(),Y=!1,t.currentIndex===w&&ot()}function gt(){u||($(),pt(!0),o.emit("autoplayStart",{}),mt())}function ot(){u&&(pt(!1),F(),D(),g&&!g.paused&&g.pause(),Mt(),o.emit("autoplayStop",{}))}function Ot(){const w=r!==!1&&T,H=a!==!1&&R;!w&&!H||(ot(),r==="pause"&&w&&(k=!0),a==="pause"&&H&&(X=!0))}function wt(){if(u){et(),ot();return}gt(),Ot()}const vt=o.on("dragCloseThreshold",({hidden:w})=>{w?(M=u,u&&(et(),ot())):M&&(M=!1,gt())}),Bt=1.001,jt=o.on("zoomChange",({scale:w})=>{T=w>Bt,r!==!1&&T&&u?(r==="stop"&&et(),ot(),r==="pause"&&(k=!0)):(it(),T||V())}),Ct=o.on("rotateFlipChange",({flipH:w,flipV:H,rotation:y})=>{R=w||H||y!==0,a!==!1&&u?(a==="stop"&&et(),ot(),a==="pause"&&(X=!0)):(it(),a!==!1&&!R&&V())}),b=o.on("captionModalChange",({open:w})=>{N=w,l!==!1&&w&&u?(l==="stop"&&et(),ot(),l==="pause"&&(q=!0)):w||V()});U.addEventListener("click",wt);const v=o.ui.toolbar("right",U),m=i?o.ui.overlay(dt):null,O=o.ui.registerShortcut(" ",wt),B=o.on("beforeSlide",()=>{Mt()}),_=o.on("afterSlide",()=>{T=!1,R=!1,et(),it(),u&&(c&&!Y?ot():mt())}),Q=o.on("slideItemLoad",({index:w})=>{u&&j&&w===t.currentIndex&&mt()}),at=o.on("requestAutoplayStop",()=>{u&&(et(),ot())}),d=o.on("requestAutoplayStart",()=>{u||(gt(),Ot())}),S=o.on("close",()=>{et(),ot()}),P=o.on("afterOpen",()=>{T=!1,R=!1,N=!1,et(),it(),n&>()});return()=>{$(),ot(),I.removeEventListener("error",bt),v(),m==null||m(),O(),B(),_(),Q(),P(),S(),vt(),jt(),Ct(),b(),at(),d()}}},ii='<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>',ni='<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 si(){return!!(document.fullscreenEnabled||document.webkitFullscreenEnabled)}function ri(){return document.fullscreenElement??document.webkitFullscreenElement??null}function ai(o){var e;const t=o;t.requestFullscreen?t.requestFullscreen().catch(()=>{}):(e=t.webkitRequestFullscreen)==null||e.call(t)}function Qt(){var t;const o=document;document.exitFullscreen?document.exitFullscreen().catch(()=>{}):(t=o.webkitExitFullscreen)==null||t.call(o)}const li={name:"fullscreen",init(o){if(!si())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";const r=Jt(ii,ni);s.appendChild(r.el),s.setAttribute("aria-label",i),s.title=i,s.setAttribute("aria-pressed","false");function a(){return ri()===t}function l(C){r.setState(C),s.setAttribute("aria-label",C?n:i),s.title=C?n:i,s.setAttribute("aria-pressed",String(C))}function c(){a()?Qt():ai(t)}s.addEventListener("click",c);const h=()=>{const C=a();l(C),o.emit("fullscreenChange",{fullscreen:C})};document.addEventListener("fullscreenchange",h),document.addEventListener("webkitfullscreenchange",h);const p=o.ui.toolbar("right",s),E=o.on("close",()=>{a()&&Qt()}),u=o.on("requestFullscreenToggle",c);return()=>{document.removeEventListener("fullscreenchange",h),document.removeEventListener("webkitfullscreenchange",h),p(),E(),u(),a()&&Qt()}}};function ci(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 di(o,t,e){return(o-t*(e-1))/e}function $e(o,t,e){const i=ci(t),n=di(t.containerWidth,t.gutterX,i),s=e&&e.length===i?[...e]:new Array(i).fill(0),r=o.map((l,c)=>{const h=t.fill==="ordered"?c%i:hi(s),p=l.width>0?n*(l.height/l.width):n,E=h*(n+t.gutterX),u=s[h];return s[h]=u+p+t.gutterY,{x:E,y:u,width:n,height:p}}),a=o.length===0?0:Math.max(...s)-t.gutterY;return{positions:r,columnCount:i,columnWidth:n,columnHeights:s,containerHeight:a}}function hi(o){let t=0;for(let e=1;e<o.length;e++)o[e]<o[t]&&(t=e);return t}function ui(o,t){const{containerWidth:e,gutterX:i,gutterY:n,rowHeight:s}=t,r=new Array(o.length);let a=0,l=0,c=0,h=0;function p(C){return C.height>0?s*(C.width/C.height):s}function E(C,g){let j=0;for(let M=C;M<g;M++){const T=p(o[M]);r[M]={x:j,y:a,width:T,height:s},j+=T+i}h++,a+=s+n}for(let C=0;C<o.length;C++){const g=p(o[C]),j=C-l,M=c+(j>0?i:0)+g;j>0&&M>e?(E(l,C),l=C,c=g):c=M}l<o.length&&E(l,o.length);const u=o.length===0?0:a-n;return{positions:r,rowCount:h,containerHeight:u}}function Dt(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),h=[];let p=0,E=0,u=0;function C(T,R,N){return(e-i*(R-T-1))/N}function g(T,R,N){let k=0;for(let X=T;X<R;X++){const q=N*Dt(o[X]);c[X]={x:k,y:p,width:q,height:N},k+=q+i}h.push({start:T,end:R,y:p,height:N}),p+=N+n}function j(T,R,N){let k=R,X=N,q=!1;for(;k-T>1&&C(T,k,X)<r;){if(k-T===2&&C(T,T+1,Dt(o[T]))>a){q=!0;break}k--,X-=Dt(o[k])}const x=C(T,k,X),$=(k-T===1||q)&&x<r?x:Math.min(Math.max(x,r),a);return g(T,k,$),k}for(let T=0;T<o.length;T++){u+=Dt(o[T]);const R=T-E+1;if(s*u+i*(R-1)>=e){const k=j(E,T+1,u);E=k,u=0;for(let X=k;X<=T;X++)u+=Dt(o[X])}}if(E<o.length)if(l==="justify"){let T=E;for(;T<o.length;){let R=0;for(let N=T;N<o.length;N++)R+=Dt(o[N]);T=j(T,o.length,R)}}else l==="left"&&g(E,o.length,s);const M=o.length===0?0:Math.max(0,p-n);return{positions:c,containerHeight:M,rows:h}}const fi={width:4,height:3};function Ve(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 Ye(o){return o.id??o.src}function pi(o,t){if(t.length<=o.length)return!1;for(let e=0;e<o.length;e++)if(Ye(o[e])!==Ye(t[e]))return!1;return!0}const mi={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=Ve(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),h=o.options.fill??"shortest",p=Number(o.options.rowHeight??220),E=Number(o.options.minRowHeight??120),u=Number(o.options.maxRowHeight??360),C=o.options.lastRow??"justify",g=o.options.animate!==!1,j=o.options.autoMeasure!==!1,M=e==="masonry"&&s==="horizontal",T=o.options.groupBy,R=o.options.renderHeading,N=o.options.headingOverflow??"show",k=o.options.stickyHeadings===!0,X=k&&e==="grid";k&&e!=="grid"&&console.warn("Shoji: layout plugin — stickyHeadings is only implemented for type: 'grid'; ignored (see the option's doc comment)."),T&&M&&console.warn("Shoji: layout plugin — groupBy isn't supported with orientation: 'horizontal'; ignored.");const q=!!T&&!M,x={gutter:i,columns:r,columnWidth:a,minColumnWidth:l,maxColumnWidth:c,fill:h,rowHeight:p,minRowHeight:E,maxRowHeight:u,lastRow:C},$=o.options.breakpoints,et=$?Object.entries($).map(([b,v])=>[Number(b),v]).sort((b,v)=>b[0]-v[0]):[];function yt(b){const v=et.find(([O])=>b<=O);if(!v)return x;const m=v[1];return{gutter:m.gutter!==void 0?Ve(m.gutter):x.gutter,columns:m.columns??x.columns,columnWidth:m.columnWidth??x.columnWidth,minColumnWidth:m.minColumnWidth??x.minColumnWidth,maxColumnWidth:m.maxColumnWidth??x.maxColumnWidth,fill:m.fill??x.fill,rowHeight:m.rowHeight??x.rowHeight,minRowHeight:m.minRowHeight??x.minRowHeight,maxRowHeight:m.maxRowHeight??x.maxRowHeight,lastRow:m.lastRow??x.lastRow}}const V=t.element;V.classList.add("shoji-layout",`shoji-layout--${e}`),g&&V.classList.add("shoji-layout--animate");let Y=[],I=[],bt,U=[],St=!1;const dt=new WeakMap;function lt(b){const v=[];for(let m=0;m<b.length;m++){const O=T(b[m]),B=v[v.length-1];!B||B.key!==O?v.push({key:O,startIndex:m,endIndex:m+1}):B.endIndex=m+1}return v}function F(b,v){const m=R?R(b,v):b;let O,B=null;if(typeof m=="string")O=document.createElement("h2"),O.textContent=m;else if(m instanceof HTMLElement)O=m;else{O=document.createElement("h2");const _=document.createElement("span");_.className="shoji-layout-heading-title",_.textContent=m.title,O.appendChild(_);let Q=null;m.subtitle&&(Q=document.createElement("span"),Q.className="shoji-layout-heading-subtitle",Q.textContent=m.subtitle,O.appendChild(Q)),B={titleEl:_,subtitleEl:Q}}return O.classList.add("shoji-layout-heading"),X&&O.classList.add("shoji-layout-heading--sticky"),{root:O,structured:B}}function D(){return I.map((b,v)=>({heading:b,start:b.tileStart,end:v+1<I.length?I[v+1].tileStart:Y.length}))}function Z(b){return b.thumb??b.poster??(b.video?void 0:b.src)}function it(b){if(b!=null&&b.width&&b.height)return{width:b.width,height:b.height};const v=b&&dt.get(b);if(v)return v;const m=j&&!!b&&!!Z(b);return!St&&!m&&(St=!0,console.warn(j?"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.")),fi}function pt(b,v){const m=document.createElement("a");m.className="shoji-layout-tile",b.id&&(m.dataset.shojiId=b.id),m.dataset.shojiIndex=String(v);const O=document.createElement("img");O.src=b.thumb??b.poster??b.src,O.loading="lazy",O.alt=b.alt??"",m.appendChild(O);const B={index:v,root:m,img:O};return m.addEventListener("click",_=>{_.preventDefault(),t.open(B.index)}),B}function Tt(b){const v=V.getBoundingClientRect().width,m=yt(v);V.style.setProperty("--shoji-layout-column-width",`${m.columnWidth}px`),V.style.setProperty("--shoji-layout-gutter",`${m.gutter.y}px ${m.gutter.x}px`);for(const O of b)O.root.style.setProperty("--shoji-layout-tile-aspect",`${n}`)}function ht(b){const v=V.getBoundingClientRect().width;if(v<=0)return;const m=yt(v),O={containerWidth:v,gutterX:m.gutter.x,gutterY:m.gutter.y,columns:m.columns,columnWidth:m.columnWidth,minColumnWidth:m.minColumnWidth,maxColumnWidth:m.maxColumnWidth,fill:m.fill};if(q&&I.length>0){const d=D(),S=d.map(w=>w.heading.root.getBoundingClientRect().height);let P=0;d.forEach(({heading:w,start:H,end:y},L)=>{const A=Y.slice(H,y);w.root.style.transform=`translate(0px, ${P}px)`,P+=S[L]+m.gutter.y;const W=$e(A.map(z=>it(t.items[z.index])),O);A.forEach((z,J)=>{const nt=W.positions[J];z.root.style.width=`${nt.width}px`,z.root.style.height=`${nt.height}px`,z.root.style.visibility="visible",z.root.style.transform=`translate(${nt.x}px, ${P+nt.y}px)`}),P+=W.containerHeight+m.gutter.y}),bt=void 0,V.style.height=`${Math.max(0,P-m.gutter.y)}px`;return}const B=b??Y,_=B.map(d=>it(t.items[d.index])),at=$e(_,O,b?bt:void 0);B.forEach((d,S)=>{const P=at.positions[S];d.root.style.width=`${P.width}px`,d.root.style.height=`${P.height}px`,d.root.style.visibility="visible",d.root.style.transform=`translate(${P.x}px, ${P.y}px)`}),bt=at.columnHeights,V.style.height=`${at.containerHeight}px`}function Mt(){const b=V.getBoundingClientRect().width;if(b<=0)return;const v=yt(b),m=Y.map(B=>it(t.items[B.index])),O=ui(m,{containerWidth:b,gutterX:v.gutter.x,gutterY:v.gutter.y,rowHeight:v.rowHeight});Y.forEach((B,_)=>{const Q=O.positions[_];B.root.style.width=`${Q.width}px`,B.root.style.height=`${Q.height}px`,B.root.style.visibility="visible",B.root.style.transform=`translate(${Q.x}px, ${Q.y}px)`}),V.style.height=`${O.containerHeight}px`}function Ht(b,v,m){const O=new Map,B=new Map;if(N==="fit")for(const y of I){if(!y.structured)continue;const{subtitleEl:L}=y.structured;y.root.style.maxWidth="none",y.root.style.whiteSpace="nowrap",L&&(L.hidden=!1),O.set(y.tileStart,y.root.getBoundingClientRect().width),L?(L.hidden=!0,B.set(y.tileStart,y.root.getBoundingClientRect().width),L.hidden=!1):B.set(y.tileStart,O.get(y.tileStart))}function _(y,L){return Y.slice(y,L).map(A=>it(t.items[A.index]))}function Q(y,L){const A=I[y].tileStart,W=L<I.length?I[L].tileStart:Y.length,z=Vt(_(A,W),b);for(let J=y;J<L;J++){const nt=I[J];if(!nt.structured)continue;const G=z.positions[nt.tileStart-A];if(!G)continue;const tt=J+1<L?I[J+1]:void 0,ut=tt?z.positions[tt.tileStart-A]:null,ie=(!!ut&&Math.abs(ut.y-G.y)<.5?ut.x:m)-G.x-v.gutter.x;if(Math.min(O.get(nt.tileStart)??1/0,B.get(nt.tileStart)??1/0)>ie)return null}return z}function at(){if(N!=="fit")return[{startSection:0,endSection:I.length,tileStart:0,tileEnd:Y.length,result:Vt(_(0,Y.length),b)}];const y=[];let L=0;for(;L<I.length;){const A=Q(L,L+1),W=I[L].tileStart;if(A===null){const G=L+1<I.length?I[L+1].tileStart:Y.length;y.push({startSection:L,endSection:L+1,tileStart:W,tileEnd:G,result:Vt(_(W,G),b)}),L+=1;continue}let z=L+1,J=A;for(;z<I.length;){const G=Q(L,z+1);if(G===null)break;z+=1,J=G}const nt=z<I.length?I[z].tileStart:Y.length;y.push({startSection:L,endSection:z,tileStart:W,tileEnd:nt,result:J}),L=z}return y}function d(y){for(let L=y.startSection;L<y.endSection;L++){const A=I[L];if(!A.structured)continue;const W=y.result.positions[A.tileStart-y.tileStart];if(!W)continue;const z=L+1<y.endSection?I[L+1]:void 0,J=z?y.result.positions[z.tileStart-y.tileStart]:null,G=(!!J&&Math.abs(J.y-W.y)<.5?J.x:m)-W.x-v.gutter.x,{subtitleEl:tt}=A.structured;A.root.style.whiteSpace="nowrap",A.root.style.maxWidth="none",A.root.style.overflow="",A.root.style.textOverflow="",tt&&(tt.hidden=!1),!((O.get(A.tileStart)??0)<=G)&&(tt&&(tt.hidden=!0,(B.get(A.tileStart)??0)<=G)||(A.root.style.maxWidth=`${Math.max(0,G)}px`,A.root.style.overflow="hidden",A.root.style.textOverflow="ellipsis"))}}function S(y){for(let L=y.startSection;L<y.endSection;L++){const A=I[L];if(!A.structured)continue;const W=y.result.positions[A.tileStart-y.tileStart];if(!W)continue;const z=L+1<y.endSection?I[L+1]:void 0,J=z?y.result.positions[z.tileStart-y.tileStart]:null,G=(!!J&&Math.abs(J.y-W.y)<.5?J.x:m)-W.x-v.gutter.x;A.root.style.whiteSpace="normal",A.root.style.maxWidth=`${Math.max(0,G)}px`;const tt=getComputedStyle(A.root),ut=parseFloat(tt.lineHeight),oe=Number.isFinite(ut)?ut:parseFloat(tt.fontSize)*1.2,ie=Math.max(1,Math.floor(v.maxRowHeight/oe));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",`${ie}`)}}const P=at();let w=0,H=0;for(const y of P){N==="fit"?d(y):N==="wrap"&&S(y);const L=new Map;for(let W=y.startSection;W<y.endSection;W++){const z=I[W];L.set(z.tileStart,z.root.getBoundingClientRect().height)}for(const W of y.result.rows){const z=W.start+y.tileStart,J=W.end+y.tileStart;let nt=0;for(;H<y.endSection&&I[H].tileStart<J;){const G=I[H],tt=y.result.positions[G.tileStart-y.tileStart];tt&&(G.root.hidden=!1,G.root.style.transform=`translate(${tt.x}px, ${W.y+w}px)`,nt=Math.max(nt,L.get(G.tileStart)??0)),H++}nt>0&&(w+=nt+v.gutter.y);for(let G=z;G<J;G++){const tt=y.result.positions[G-y.tileStart],ut=Y[G];ut.root.hidden=tt===null,tt&&(ut.root.style.width=`${tt.width}px`,ut.root.style.height=`${tt.height}px`,ut.root.style.visibility="visible",ut.root.style.transform=`translate(${tt.x}px, ${tt.y+w}px)`)}}const A=y.result.rows.length>0?y.result.rows[y.result.rows.length-1].end+y.tileStart:y.tileStart;for(let W=A;W<y.tileEnd;W++)Y[W].root.hidden=!0;w+=y.result.containerHeight+v.gutter.y}for(;H<I.length;)I[H].root.hidden=!0,H++;V.style.height=`${Math.max(0,w-v.gutter.y)}px`}function Lt(){const b=V.getBoundingClientRect().width;if(b<=0)return;const v=yt(b),m={containerWidth:b,gutterX:v.gutter.x,gutterY:v.gutter.y,rowHeight:v.rowHeight,minRowHeight:v.minRowHeight,maxRowHeight:v.maxRowHeight,lastRow:v.lastRow};if(q&&I.length>0){Ht(m,v,b);return}const O=Y.map(_=>it(t.items[_.index])),B=Vt(O,m);Y.forEach((_,Q)=>{const at=B.positions[Q];_.root.hidden=at===null,at&&(_.root.style.width=`${at.width}px`,_.root.style.height=`${at.height}px`,_.root.style.visibility="visible",_.root.style.transform=`translate(${at.x}px, ${at.y}px)`)}),V.style.height=`${B.containerHeight}px`}function xt(){M?Mt():e==="masonry"?ht(null):e==="justified"?Lt():Tt(Y)}let mt=!1,st=null;function gt(){st!==null||mt||(st=requestAnimationFrame(()=>{st=null,!mt&&(q?wt(t.items):xt())}))}function ot(b){if(j)for(const v of b){const m=t.items[v.index];if(!m||m.width&&m.height||dt.has(m)||!Z(m))continue;const O=()=>{mt||v.img.naturalWidth>0&&v.img.naturalHeight>0&&(dt.set(m,{width:v.img.naturalWidth,height:v.img.naturalHeight}),gt())};v.img.complete?O():v.img.addEventListener("load",O,{once:!0})}}function Ot(b){o.emit("layoutRender",{tiles:b.map(v=>({index:v.index,element:v.root}))})}function wt(b){if(V.replaceChildren(),Y=b.map((v,m)=>pt(v,m)),I=[],q)for(const v of lt(b)){const m=b.slice(v.startIndex,v.endIndex),{root:O,structured:B}=F(v.key,m);V.appendChild(O),I.push({root:O,tileStart:v.startIndex,structured:B});for(let _=v.startIndex;_<v.endIndex;_++)V.appendChild(Y[_].root)}else for(const v of Y)V.appendChild(v.root);bt=void 0,xt(),ot(Y),Ot(Y)}function vt(b,v){const m=b.map((O,B)=>pt(O,v+B));for(const O of m)V.appendChild(O.root);Y=[...Y,...m],M?Mt():e==="masonry"?ht(m):e==="justified"?Lt():Tt(m),ot(m),Ot(m)}wt(t.items),U=t.items;const Bt=o.on("itemsUpdated",({items:b})=>{q?wt(b):pi(U,b)?vt(b.slice(U.length),U.length):wt(b),U=b});let jt=null,Ct;return(e==="masonry"||e==="justified"||et.length>0)&&(Ct=new ResizeObserver(()=>{jt===null&&(jt=requestAnimationFrame(()=>{jt=null,xt()}))}),Ct.observe(V)),()=>{mt=!0,st!==null&&cancelAnimationFrame(st),Ct==null||Ct.disconnect(),jt!==null&&cancelAnimationFrame(jt),Bt(),V.classList.remove("shoji-layout",`shoji-layout--${e}`,"shoji-layout--animate"),V.style.removeProperty("height"),V.style.removeProperty("width"),V.replaceChildren()}}};function gi(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 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="M9 14 4 9l5-5"/><path d="M4 9h10a6 6 0 1 1 0 12H9"/></svg>',yi='<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>',bi='<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>',wi='<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>',We={flipH:!1,flipV:!1,rotation:0};function Ci(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 Ei(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 Si={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={...We},l=0,c=!1,h=!1;function p(F){const D=t.items[t.currentIndex];if(D!=null&&D.width&&D.height)return{width:D.width,height:D.height};const Z=F.querySelector("img");if(Z!=null&&Z.naturalWidth&&Z.naturalHeight)return{width:Z.naturalWidth,height:Z.naturalHeight}}function E(F){const D=t.getActiveMedia();if(!D)return;const Z=p(D),it=Ei(D.clientWidth,D.clientHeight,l,Z==null?void 0:Z.width,Z==null?void 0:Z.height),pt=Ci(c,h,l,it);if(!F){D.style.transform=pt;return}D.style.transition="transform var(--shoji-duration) var(--shoji-easing)",D.style.transform=pt,It(D,()=>{D.style.transition=""})}function u(F,D){const Z=document.createElement("button");return Z.type="button",Z.className="shoji-toolbar-button",Z.innerHTML=F,Z.setAttribute("aria-label",D),Z.title=D,Z}const C=u(vi,i),g=u(yi,n),j=u(bi,s),M=u(wi,r);j.setAttribute("aria-pressed","false"),M.setAttribute("aria-pressed","false");function T(F,D){a=gi({...a,...F}),D!==void 0&&(l+=D),E(!0),j.setAttribute("aria-pressed",String(a.flipH)),M.setAttribute("aria-pressed",String(a.flipV)),o.emit("rotateFlipChange",{index:t.currentIndex,...a})}function R(F){return F!==(c!==h)?90:-90}function N(){const F=R(!1);T({rotation:a.rotation+F},F)}function k(){const F=R(!0);T({rotation:a.rotation+F},F)}function X(){c=!c,T({flipH:!a.flipH})}function q(){h=!h,T({flipV:!a.flipV})}C.addEventListener("click",N),g.addEventListener("click",k),j.addEventListener("click",X),M.addEventListener("click",q);function x(){a={...We},l=0,c=!1,h=!1,E(!1),j.setAttribute("aria-pressed","false"),M.setAttribute("aria-pressed","false")}let $=null;function et(){const F=t.getActiveMedia(),D=F==null?void 0:F.style.transform;$=D&&D!=="none"?D:null}const yt=[C,g,j,M].map(F=>o.ui.toolbar("right",F)),V=o.on("requestRotateLeft",N),Y=o.on("requestRotateRight",k),I=o.on("requestFlipHorizontal",X),bt=o.on("requestFlipVertical",q),U=o.on("afterOpen",x),St=o.on("beforeSlide",()=>{et(),x()}),dt=o.on("afterSlide",x),lt=t.registerSlideLeaveDecorator(F=>{if(!$)return;const D=$;return $=null,F.style.transform=D,()=>{F.style.transition="transform var(--shoji-duration) var(--shoji-easing)",F.style.transform="none"}});return()=>{for(const F of yt)F();V(),Y(),I(),bt(),U(),St(),dt(),lt()}}};let Yt=null;const Ti=250;function Mi(){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 Li(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 xi=(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(h=>h.ok?h.json():null).then(h=>{i.aborted||typeof(h==null?void 0:h.thumbnail_url)=="string"&&n(h.thumbnail_url)}).catch(()=>{})}const a=document.createElement("div");a.className="shoji-video-mount",o.appendChild(a),Mi().then(c=>{if(i.aborted)return;const h=o,p=new c.Player(a,{...r?{url:r}:{id:Number(s)},playsinline:!0});let E=null;function u(){E!==null&&(clearTimeout(E),E=null)}p.on("play",()=>{u(),h.paused=!1,h.dispatchEvent(new Event("play"))}),p.on("pause",()=>{h.paused=!0,u(),E=setTimeout(()=>{E=null,h.dispatchEvent(new Event("pause"))},Ti)}),p.on("ended",()=>{u(),h.paused=!0,h.ended=!0,h.dispatchEvent(new Event("ended"))}),p.on("error",C=>h.dispatchEvent(new CustomEvent("error",{bubbles:!0,detail:{name:C.name}}))),p.ready().then(()=>{Li(o,p),Promise.all([p.getVideoWidth(),p.getVideoHeight()]).then(([C,g])=>{C&&g&&o.style.setProperty("--shoji-provider-video-aspect",`calc(${C} / ${g})`)}).catch(()=>{}).then(()=>e())}),i.addEventListener("abort",()=>{u(),p.destroy()},{once:!0})})};let Wt=null;function Oi(){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 ji(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 Pi(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 Ri=(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),Oi().then(l=>{if(i.aborted)return;const c=o,h=new l.Player(r,{videoId:s,playerVars:{playsinline:1,rel:0},events:{onReady:()=>{ji(o,h),e()},onStateChange:p=>Pi(p,l,c),onError:p=>c.dispatchEvent(new CustomEvent("error",{bubbles:!0,detail:{code:p.data}}))}});i.addEventListener("abort",()=>h.destroy(),{once:!0})})},Hi={name:"video",init(o){const t=o.ui.registerVideoProvider("youtube",Ri),e=o.ui.registerVideoProvider("vimeo",xi);return()=>{t(),e()}}},Ai='<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>',Ii='<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>',ki='<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 9L3 3M3 8V3h5M15 15l6 6M21 16v5h-5"/></svg>',Di='<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 3l6 6M9 3v6H3M21 21l-6-6M15 21v-6h6"/></svg>';function Bi(o,t,e){return Math.min(e,Math.max(t,o))}const _t={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])}:{..._t}}function te(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 ze(o,t,e){return{tx:e.a*o+e.c*t,ty:e.b*o+e.d*t}}function ee(o){return{tx:-o.width/2,ty:-o.height/2}}function Fi(o,t,e=_t,i=ee(o)){const n=o.left+o.width/2,s=o.top+o.height/2,r=ze(i.tx+t.tx,i.ty+t.ty,e);return{x:n+r.tx,y:s+r.ty}}function Xe(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 Ni(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,h=[{x:0,y:0},{x:s,y:0},{x:0,y:r},{x:s,y:r}].map(({x:u,y:C})=>{const g={x:n.tx+t.tx+u*e,y:n.ty+t.ty+C*e},j=ze(g.x,g.y,i);return{x:a+j.tx,y:l+j.ty}}),p=h.map(u=>u.x),E=h.map(u=>u.y);return{left:Math.min(...p),top:Math.min(...E),right:Math.max(...p),bottom:Math.max(...E)}}function qe(o,t,e,i,n=_t,s=ee(o)){const r=Ni(o,i,e,n,s),a=Xe(r.left,r.right-r.left,t.left,t.width),l=Xe(r.top,r.bottom-r.top,t.top,t.height),c={tx:a-r.left,ty:l-r.top},h=te(c.tx,c.ty,n);return{tx:i.tx+h.tx,ty:i.ty+h.ty}}function $i(o,t,e,i,n,s,r=_t,a=ee(o)){const l=Fi(o,t,r,a),c=n-l.x,h=s-l.y,p=te(c,h,r),E=1-i/e;return{tx:t.tx+p.tx*E,ty:t.ty+p.ty*E}}const Pt=1.001;function Vi(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:oi,Layout:mi,ActiveThumbnail:Go,Fullscreen:li,RotateFlip:Si,Video:Hi,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,h={tx:0,ty:0},p=null,E=null,u=null,C=1;function g(){const d=t.getActiveMedia(),S=d==null?void 0:d.firstElementChild;return S instanceof HTMLImageElement?S:null}function j(d){const S=d.getBoundingClientRect();return{left:S.left,top:S.top,width:S.width,height:S.height}}function M(d){return p&&E&&u?!0:c!==1?!1:(p=j(d),E=j(d.parentElement??d),u={tx:-(d.offsetWidth||p.width)/2,ty:-(d.offsetHeight||p.height)/2},!0)}function T(d){const S=t.getActiveMedia();if(!S||S.style.transition===""){d();return}It(S,d)}function R(){const d=g();d&&(d.style.transformOrigin="0 0",d.style.transform=c===1&&h.tx===0&&h.ty===0?"none":`translate3d(${h.tx}px, ${h.ty}px, 0) scale3d(${c}, ${c}, 1)`,d.classList.toggle("shoji-zoomed",c>1))}function N(){o.emit("zoomChange",{index:t.currentIndex,scale:c}),k()}function k(){Bt.setState(c>Pt)}function X(d,S,P){d.style.transition="transform var(--shoji-duration) var(--shoji-easing)",S(),It(d,()=>{d.style.transition="",P==null||P()})}function q(d,S,P,w=e,H=!1){T(()=>{const y=g();if(!y||!M(y))return;const L=Bi(d,1,Math.max(w,1)),A=t.getActiveMedia(),W=_e(A?getComputedStyle(A).transform:"none");h=$i(p,h,c,L,S,P,W,u),c=L,h=qe(p,E,c,h,W,u),H?X(y,R):R(),N()})}function x(d=!1){const S=c!==1;c=1,h={tx:0,ty:0},p=null,E=null,u=null,k(),S&&N();const P=g();if(!P)return;const w=()=>{P.style.transform="",P.classList.remove("shoji-zoomed")};d?X(P,w,()=>{P.style.transformOrigin=""}):(w(),P.style.transformOrigin="")}let $=null,et="";function yt(){const d=g(),S=d==null?void 0:d.style.transform;$=S&&S!=="none"?S:null,et=(d==null?void 0:d.style.transformOrigin)||"0 0"}function V(){var d;(d=g())==null||d.classList.add("shoji-zoom-enabled")}function Y(d,S){c>Pt?x(!0):q(i,d,S,e,!0)}const I=o.on("pinchStart",()=>{C=c}),bt=o.on("pinchMove",({scale:d,centerX:S,centerY:P})=>{q(C*d,S,P)}),U=o.on("pinchEnd",()=>{c<=Pt&&x()}),St=o.on("doubleTap",({x:d,y:S})=>Y(d,S)),dt=o.on("wheelZoom",({deltaScale:d,x:S,y:P})=>{q(c+d,S,P)}),lt=o.on("requestZoomIn",st),F=o.on("requestZoomOut",gt),D=o.on("requestZoomActualSize",ot),Z=o.on("requestZoomReset",()=>x(!0));let it=null,pt=0,Tt=0;const ht=o.ui.outer();function Mt(d){if(c<=Pt||Vi(d))return;const S=g();!S||!d.composedPath().includes(S)||(it=d.pointerId,pt=d.clientX,Tt=d.clientY,S.setPointerCapture(d.pointerId))}function Ht(d){if(it!==d.pointerId||!p||!E||!u)return;d.preventDefault();const S=d.clientX-pt,P=d.clientY-Tt;pt=d.clientX,Tt=d.clientY;const w=t.getActiveMedia(),H=_e(w?getComputedStyle(w).transform:"none"),{tx:y,ty:L}=te(S,P,H);h=qe(p,E,c,{tx:h.tx+y,ty:h.ty+L},H,u),R()}function Lt(d){it===d.pointerId&&(it=null)}ht.addEventListener("pointerdown",Mt),ht.addEventListener("pointermove",Ht,{passive:!1}),ht.addEventListener("pointerup",Lt),ht.addEventListener("pointercancel",Lt);function xt(d,S){const P=document.createElement("button");return P.type="button",P.className="shoji-toolbar-button",P.innerHTML=d,P.setAttribute("aria-label",S),P.title=S,P}function mt(){const d=t.getActiveMedia(),S=d==null?void 0:d.getBoundingClientRect();return S?{x:S.left+S.width/2,y:S.top+S.height/2}:{x:0,y:0}}function st(){const{x:d,y:S}=mt();q(c*n,d,S,e,!0)}function gt(){const{x:d,y:S}=mt();c/n<=Pt?x(!0):q(c/n,d,S,e,!0)}function ot(){T(()=>{const d=g();if(!d||!d.naturalWidth||!M(d))return;if(c>Pt){x(!0);return}const S=d.naturalWidth/p.width,{x:P,y:w}=mt();q(S,P,w,S,!0)})}const Ot=xt(Ai,r),wt=xt(Ii,a),vt=document.createElement("button");vt.type="button",vt.className="shoji-toolbar-button";const Bt=Jt(ki,Di);vt.appendChild(Bt.el),vt.setAttribute("aria-label",l),vt.title=l,Ot.addEventListener("click",st),wt.addEventListener("click",gt),vt.addEventListener("click",ot);const jt=[Ot,wt,vt].map(d=>o.ui.toolbar("right",d));function Ct(){var S;const d=!!((S=t.items[t.currentIndex])!=null&&S.video);Ot.hidden=d,wt.hidden=d,vt.hidden=d}const b=[o.ui.registerShortcut("w",st),o.ui.registerShortcut("W",st),o.ui.registerShortcut("s",gt),o.ui.registerShortcut("S",gt)],v=o.on("afterOpen",()=>{x(),V(),Ct()}),m=o.on("beforeSlide",()=>{yt(),x()}),O=o.on("afterSlide",()=>{x(),V(),Ct()}),B=o.on("beforeClose",()=>x()),_=t.registerZoomGate(()=>c>Pt),Q=t.registerZoomStartProvider(()=>{var d;return c>Pt?((d=g())==null?void 0:d.getBoundingClientRect())??null:null}),at=t.registerSlideLeaveDecorator(d=>{if(!$)return;const S=$,P=et;$=null;const w=d.querySelector("img");if(w)return w.style.transformOrigin=P,w.style.transform=S,()=>{w.style.transition="transform var(--shoji-duration) var(--shoji-easing)",w.style.transform="none"}});return V(),Ct(),()=>{var d;for(const S of jt)S();for(const S of b)S();v(),m(),O(),B(),I(),bt(),U(),St(),dt(),lt(),F(),D(),Z(),ht.removeEventListener("pointerdown",Mt),ht.removeEventListener("pointermove",Ht),ht.removeEventListener("pointerup",Lt),ht.removeEventListener("pointercancel",Lt),_(),Q(),at(),x(),(d=g())==null||d.classList.remove("shoji-zoom-enabled")}}},version:"0.1.0-beta.14"})}));
|
|
2
2
|
//# sourceMappingURL=shoji.min.js.map
|