smartphoto 2.1.15 → 2.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -196,6 +196,11 @@ Slide fields:
196
196
  <td>close the viewer on a downward swipe</td>
197
197
  <td>true</td>
198
198
  </tr>
199
+ <tr>
200
+ <td>pinchToClose</td>
201
+ <td>close the viewer when the photo is pinched in clearly below its base scale (fit/fill)</td>
202
+ <td>true</td>
203
+ </tr>
199
204
  <tr>
200
205
  <td>swipeOffset</td>
201
206
  <td>minimum swipe distance (px) to trigger navigation/close</td>
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * SmartPhoto v2.1.15
2
+ * SmartPhoto v2.1.17
3
3
  * (c) appleple
4
4
  * Released under the MIT License.
5
5
  */
@@ -154,6 +154,7 @@
154
154
  useViewTransitionApi: true,
155
155
  swipeTopToClose: false,
156
156
  swipeBottomToClose: true,
157
+ pinchToClose: true,
157
158
  swipeOffset: 100,
158
159
  swipeVelocity: 0.5,
159
160
  headerHeight: 60,
@@ -369,8 +370,9 @@
369
370
  maxY: round(maxY, 6) / item.scale
370
371
  };
371
372
  }
373
+ var FIT_MARGIN = 24;
372
374
  function sizeItems(items, winWidth, winHeight, headerHeight, footerHeight) {
373
- const screenY = winHeight - (headerHeight + footerHeight);
375
+ const screenY = winHeight - (headerHeight + footerHeight) - FIT_MARGIN * 2;
374
376
  items.forEach((item) => {
375
377
  if (!item.loaded) {
376
378
  return;
@@ -413,7 +415,7 @@
413
415
  return Math.round(val * digit) / digit;
414
416
  }
415
417
  function getPos(e) {
416
- return { x: e.pageX, y: e.pageY };
418
+ return { x: e.clientX, y: e.clientY };
417
419
  }
418
420
  function distance(p1, p2) {
419
421
  const x = p1.x - p2.x;
@@ -446,7 +448,8 @@
446
448
  let photoVX = 0;
447
449
  let photoVY = 0;
448
450
  let pinching = false;
449
- let oldDistance = 0;
451
+ let pinchStartDistance = 0;
452
+ let pinchStartScale = 1;
450
453
  let pinchMoveFrame = null;
451
454
  let vx = 0;
452
455
  let vy = 0;
@@ -461,6 +464,14 @@
461
464
  const { width, height } = windowSize();
462
465
  return scaleBorder(item, width, height, isSmartPhone2());
463
466
  }
467
+ function baselineOf(item) {
468
+ return state.options.resizeStyle === "fill" && isSmartPhone2() ? borderOf(item) : 1;
469
+ }
470
+ const MAX_PINCH_SCALE = 4;
471
+ function maxScaleOf(item) {
472
+ return Math.max(MAX_PINCH_SCALE, borderOf(item));
473
+ }
474
+ const PINCH_CLOSE_RATIO = 0.75;
464
475
  function registerElasticForce(flagX, flagY) {
465
476
  const item = currentItem(state);
466
477
  const bound = boundOf(item);
@@ -508,7 +519,7 @@
508
519
  }
509
520
  const power = getForceAndTheta(vx, vy);
510
521
  const force = power.force - state.options.registance;
511
- if (Math.abs(force) < 0.5) {
522
+ if (force < 0.5) {
512
523
  return;
513
524
  }
514
525
  vx = Math.cos(power.theta) * force;
@@ -551,16 +562,23 @@
551
562
  { signal }
552
563
  );
553
564
  }
554
- function startPinch() {
555
- pinching = true;
556
- swiping = false;
557
- photoSwipable = false;
565
+ function rebasePinch() {
558
566
  const points = Array.from(activePointers.values());
559
- oldDistance = distance(
567
+ pinchStartDistance = distance(
560
568
  points[0],
561
569
  points[1]
562
570
  );
571
+ pinchStartScale = state.viewer.scaleSize;
572
+ }
573
+ function startPinch() {
574
+ pinching = true;
575
+ swiping = false;
576
+ photoSwipable = false;
577
+ rebasePinch();
578
+ vx = 0;
579
+ vy = 0;
563
580
  state.viewer.scale = true;
581
+ state.viewer.hideUi = true;
564
582
  callbacks.onGestureStart();
565
583
  }
566
584
  function startSwipe(e) {
@@ -614,28 +632,36 @@
614
632
  }
615
633
  function movePinch() {
616
634
  const points = Array.from(activePointers.values());
617
- const dist = distance(
618
- points[0],
619
- points[1]
620
- );
621
- const size = (dist - oldDistance) / 100;
635
+ const p0 = points[0];
636
+ const p1 = points[1];
637
+ const dist = distance(p0, p1);
638
+ if (pinchStartDistance === 0) {
639
+ pinchStartDistance = dist;
640
+ pinchStartScale = state.viewer.scaleSize;
641
+ scheduleGestureMove();
642
+ return;
643
+ }
622
644
  const oldScaleSize = state.viewer.scaleSize;
623
- const posX = state.viewer.photoPosX;
624
- const posY = state.viewer.photoPosY;
625
- state.viewer.scaleSize += round2(size, 6);
645
+ state.viewer.scaleSize = round2(
646
+ pinchStartScale * dist / pinchStartDistance,
647
+ 6
648
+ );
626
649
  if (state.viewer.scaleSize < 0.2) {
627
650
  state.viewer.scaleSize = 0.2;
628
651
  }
629
- if (state.viewer.scaleSize < oldScaleSize) {
630
- state.viewer.photoPosX = (1 + state.viewer.scaleSize - oldScaleSize) * posX;
631
- state.viewer.photoPosY = (1 + state.viewer.scaleSize - oldScaleSize) * posY;
632
- }
633
652
  const item = currentItem(state);
634
- if (item) {
635
- const border = borderOf(item);
636
- state.viewer.hideUi = state.viewer.scaleSize < 1 || state.viewer.scaleSize > border;
653
+ if (item && state.viewer.scaleSize !== oldScaleSize) {
654
+ const { width: winW, height: winH } = windowSize();
655
+ const cx = winW / 2;
656
+ const cy = state.options.headerHeight + (winH - state.options.headerHeight - state.options.footerHeight) / 2;
657
+ const k = item.scale;
658
+ const mid = { x: (p0.x + p1.x) / 2, y: (p0.y + p1.y) / 2 };
659
+ const ratio = state.viewer.scaleSize / oldScaleSize;
660
+ const dx = mid.x - (cx + state.viewer.photoPosX * k);
661
+ const dy = mid.y - (cy + state.viewer.photoPosY * k);
662
+ state.viewer.photoPosX = round2((mid.x - dx * ratio - cx) / k, 6);
663
+ state.viewer.photoPosY = round2((mid.y - dy * ratio - cy) / k, 6);
637
664
  }
638
- oldDistance = dist;
639
665
  scheduleGestureMove();
640
666
  }
641
667
  function moveSwipe(e) {
@@ -690,15 +716,39 @@
690
716
  if (!item) {
691
717
  return;
692
718
  }
693
- const border = borderOf(item);
694
- if (state.viewer.scaleSize > border) {
719
+ const base = baselineOf(item);
720
+ if (state.viewer.scaleSize <= base) {
721
+ if (state.options.pinchToClose && state.viewer.scaleSize < base * PINCH_CLOSE_RATIO) {
722
+ callbacks.onPinchClose();
723
+ return;
724
+ }
725
+ state.viewer.photoPosX = 0;
726
+ state.viewer.photoPosY = 0;
727
+ state.viewer.scaleSize = base;
728
+ state.viewer.scale = base > 1;
729
+ state.viewer.hideUi = base > 1;
730
+ callbacks.onGestureEnd();
695
731
  return;
696
732
  }
697
- state.viewer.photoPosX = 0;
698
- state.viewer.photoPosY = 0;
699
- state.viewer.scale = false;
700
- state.viewer.scaleSize = 1;
701
- state.viewer.hideUi = false;
733
+ state.viewer.scaleSize = Math.min(state.viewer.scaleSize, maxScaleOf(item));
734
+ const bound = boundOf(item);
735
+ let flagX = 0;
736
+ let flagY = 0;
737
+ if (state.viewer.photoPosX > bound.maxX) {
738
+ flagX = -1;
739
+ } else if (state.viewer.photoPosX < bound.minX) {
740
+ flagX = 1;
741
+ }
742
+ if (state.viewer.photoPosY > bound.maxY) {
743
+ flagY = -1;
744
+ } else if (state.viewer.photoPosY < bound.minY) {
745
+ flagY = 1;
746
+ }
747
+ if (flagX !== 0 || flagY !== 0) {
748
+ registerElasticForce(flagX, flagY);
749
+ }
750
+ state.viewer.scale = true;
751
+ state.viewer.hideUi = true;
702
752
  callbacks.onGestureEnd();
703
753
  }
704
754
  function endSwipe() {
@@ -789,6 +839,9 @@
789
839
  if (pinching) {
790
840
  if (activePointers.size < 2) {
791
841
  endPinch();
842
+ activePointers.clear();
843
+ } else {
844
+ rebasePinch();
792
845
  }
793
846
  return;
794
847
  }
@@ -1021,13 +1074,14 @@
1021
1074
  refs.caption.focus();
1022
1075
  }
1023
1076
  }
1024
- function render(state) {
1077
+ function render(state, options2) {
1025
1078
  const { viewer } = state;
1026
1079
  refs.count.textContent = `${viewer.currentIndex + 1}/${viewer.total}`;
1027
1080
  refs.slides.forEach((rawSlideRefs, item) => {
1028
1081
  var _a;
1029
1082
  const slideRefs = upgradeIfProcessed(item, rawSlideRefs);
1030
1083
  const isCurrent = item.index === viewer.currentIndex;
1084
+ slideRefs.li.style.transition = (options2 == null ? void 0 : options2.immediate) ? "none" : "";
1031
1085
  slideRefs.li.style.transform = `translate(${item.translateX}px,${item.translateY}px)`;
1032
1086
  slideRefs.li.classList.toggle("current", isCurrent);
1033
1087
  if (isCurrent) {
@@ -1287,7 +1341,7 @@
1287
1341
  this.resetTranslateCurrent();
1288
1342
  this.setPosByCurrentIndex();
1289
1343
  this.setSizeByScreen();
1290
- this.commit();
1344
+ this.commit(true);
1291
1345
  };
1292
1346
  this.handleResize = () => {
1293
1347
  if (!this.state.viewer.isOpen || !currentItems(this.state)) {
@@ -1301,7 +1355,7 @@
1301
1355
  this.resetTranslateCurrent();
1302
1356
  this.setPosByCurrentIndex();
1303
1357
  this.setSizeByScreen();
1304
- this.commit();
1358
+ this.commit(true);
1305
1359
  };
1306
1360
  this.handleKeydown = (e) => {
1307
1361
  if (!this.state.viewer.isOpen) {
@@ -1329,21 +1383,22 @@
1329
1383
  this.setPosByCurrentIndex();
1330
1384
  this.setHashByCurrentIndex();
1331
1385
  this.setSizeByScreen();
1332
- this.commit();
1386
+ this.commit(true);
1333
1387
  const prevWidth = getWindowWidth2();
1388
+ const prevHeight = getWindowHeight2();
1334
1389
  const timeout = 500;
1335
1390
  const poll = (time) => {
1336
1391
  this.scheduleTimeout(() => {
1337
1392
  if (!this.state.viewer.isOpen) {
1338
1393
  return;
1339
1394
  }
1340
- if (prevWidth !== getWindowWidth2()) {
1395
+ if (prevWidth !== getWindowWidth2() || prevHeight !== getWindowHeight2()) {
1341
1396
  this.updateViewportHeight();
1342
1397
  this.resetTranslateCurrent();
1343
1398
  this.setPosByCurrentIndex();
1344
1399
  this.setHashByCurrentIndex();
1345
1400
  this.setSizeByScreen();
1346
- this.commit();
1401
+ this.commit(true);
1347
1402
  } else if (time <= timeout) {
1348
1403
  poll(time + 25);
1349
1404
  }
@@ -1515,9 +1570,11 @@
1515
1570
  ) > 1;
1516
1571
  }
1517
1572
  zoomOutPhoto() {
1518
- this.state.viewer.scaleSize = 1;
1519
- this.state.viewer.hideUi = false;
1520
- this.state.viewer.scale = false;
1573
+ const item = currentItem(this.state);
1574
+ const base = this.state.options.resizeStyle === "fill" && this.isSmartPhoneFlag && item ? scaleBorder(item, getWindowWidth2(), getWindowHeight2(), true) : 1;
1575
+ this.state.viewer.scaleSize = base;
1576
+ this.state.viewer.hideUi = base > 1;
1577
+ this.state.viewer.scale = base > 1;
1521
1578
  this.state.viewer.photoPosX = 0;
1522
1579
  this.state.viewer.photoPosY = 0;
1523
1580
  this.view.updatePhotoTransform(this.state);
@@ -1758,8 +1815,8 @@
1758
1815
  dialog.style.display = "none";
1759
1816
  }
1760
1817
  }
1761
- commit() {
1762
- this.view.render(this.state);
1818
+ commit(immediate = false) {
1819
+ this.view.render(this.state, { immediate });
1763
1820
  this.view.updatePhotoTransform(this.state);
1764
1821
  this.syncDialog();
1765
1822
  }
@@ -1838,7 +1895,7 @@
1838
1895
  this.resetTranslateCurrent();
1839
1896
  this.setPosByCurrentIndex();
1840
1897
  this.setSizeByScreen();
1841
- this.commit();
1898
+ this.commit(true);
1842
1899
  return;
1843
1900
  }
1844
1901
  this.pendingViewTransitionResync = false;
@@ -1978,11 +2035,11 @@
1978
2035
  this.resetTranslateCurrent();
1979
2036
  this.setPosByCurrentIndex();
1980
2037
  this.setSizeByScreen();
1981
- this.commit();
2038
+ this.commit(true);
1982
2039
  });
1983
2040
  }
1984
2041
  openPhoto(item, trigger) {
1985
- const groupChanged = this.rootSelector ? this.resyncGroupFromDom(item.groupId) : false;
2042
+ const groupChanged = this.resyncGroupFromDom(item.groupId);
1986
2043
  this.lastTriggerElement = trigger;
1987
2044
  this.state.viewer.currentGroup = item.groupId;
1988
2045
  this.state.viewer.currentIndex = item.index;
@@ -2217,6 +2274,9 @@
2217
2274
  this.fireEvent("gestureend");
2218
2275
  this.view.updatePhotoTransform(this.state);
2219
2276
  },
2277
+ // ピンチで基準倍率よりはっきり小さく縮めて離した = 閉じたい操作
2278
+ // (PhotoSwipe の pinchToClose 相当)
2279
+ onPinchClose: () => this.hidePhoto(),
2220
2280
  onPhotoDragMove: () => this.view.updatePhotoTransform(this.state),
2221
2281
  onPhotoDragEnd: (result) => {
2222
2282
  if (result === "zoom-out") {
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * SmartPhoto v2.1.15
2
+ * SmartPhoto v2.1.17
3
3
  * (c) appleple
4
4
  * Released under the MIT License.
5
5
  */
6
- "use strict";(()=>{var K=()=>{let t=navigator.userAgent;return t.indexOf("iPhone")>0||t.indexOf("iPad")>0||t.indexOf("ipod")>0||t.indexOf("Android")>0},Ie=()=>typeof window.webkitConvertPointFromNodeToPage=="function";function Le(t,...e){var i;t=t||{};for(let o=0;o<e.length;o++){let r=e[o];if(r){for(let s in r)if(Object.hasOwn(r,s)){let n=r[s];n&&typeof n=="object"?t[s]=Le((i=t[s])!=null?i:{},n):t[s]=n}}}return t}var Te=Le,Ce=(t,e,i)=>{let o;window.CustomEvent?o=new CustomEvent(e,{cancelable:!0}):(o=document.createEvent("CustomEvent"),o.initCustomEvent(e,!1,!1,i)),t.dispatchEvent(o)},Ae=t=>{let e={};for(let i of t.split("&")){let o=i.split("="),r=o[0],s=o.length>1?o.slice(1).join("="):r;e[r]=decodeURIComponent(s)}return e},Z=()=>document.documentElement.clientWidth,ee=()=>{let t=window.visualViewport;return t?t.height*t.scale:document.documentElement.clientHeight},He=t=>({left:t.getBoundingClientRect().left,top:t.getBoundingClientRect().top});var xe=t=>{let e=t.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*[\d.]+\s*)?\)/);return e?[Number(e[1]),Number(e[2]),Number(e[3])]:null},Ue=.179,je=([t,e,i])=>{let[o,r,s]=[t,e,i].map(n=>{let m=n/255;return m<=.03928?m/12.92:((m+.055)/1.055)**2.4});return .2126*o+.7152*r+.0722*s},Me=t=>{let e=t.trim(),i=xe(e);if(!i){let o=document.createElement("div");if(o.style.color=e,!o.style.color)return"#fff";document.body.appendChild(o),i=xe(getComputedStyle(o).color),document.body.removeChild(o)}return i&&je(i)>Ue?"#000":"#fff"};var qe={classNames:{smartPhoto:"smartphoto",smartPhotoClose:"smartphoto-close",smartPhotoBody:"smartphoto-body",smartPhotoInner:"smartphoto-inner",smartPhotoContent:"smartphoto-content",smartPhotoImg:"smartphoto-img",smartPhotoImgOnMove:"smartphoto-img-onmove",smartPhotoImgElasticMove:"smartphoto-img-elasticmove",smartPhotoImgWrap:"smartphoto-img-wrap",smartPhotoArrows:"smartphoto-arrows",smartPhotoNav:"smartphoto-nav",smartPhotoArrowRight:"smartphoto-arrow-right",smartPhotoArrowLeft:"smartphoto-arrow-left",smartPhotoArrowHideIcon:"smartphoto-arrow-hide",smartPhotoImgLeft:"smartphoto-img-left",smartPhotoImgRight:"smartphoto-img-right",smartPhotoList:"smartphoto-list",smartPhotoListOnMove:"smartphoto-list-onmove",smartPhotoHeader:"smartphoto-header",smartPhotoCount:"smartphoto-count",smartPhotoCaption:"smartphoto-caption",smartPhotoDismiss:"smartphoto-dismiss",smartPhotoLoader:"smartphoto-loader",smartPhotoLoaderWrap:"smartphoto-loader-wrap",smartPhotoImgClone:"smartphoto-img-clone"},message:{gotoNextImage:"go to the next image",gotoPrevImage:"go to the previous image",closeDialog:"close the image dialog",carouselLabel:"Images"},arrows:!0,nav:!0,showAnimation:!0,verticalGravity:!1,useOrientationApi:!1,useHistoryApi:!0,useViewTransitionApi:!0,swipeTopToClose:!1,swipeBottomToClose:!0,swipeOffset:100,swipeVelocity:.5,headerHeight:60,footerHeight:60,forceInterval:10,registance:.5,loadOffset:2,resizeStyle:"fit",lazyAttribute:"data-src",animationSpeed:300};function Ve(t){return Object.keys(t).forEach(e=>{let i=t[e];i&&typeof i=="object"&&!Object.isFrozen(i)&&Ve(i)}),Object.freeze(t)}function ze(t){return{options:Ve(Te({},qe,t)),viewer:{isOpen:!1,currentGroup:null,currentIndex:0,oldIndex:0,total:0,translateX:0,translateY:0,photoPosX:0,photoPosY:0,scaleSize:1,scale:!1,elastic:!1,hideUi:!1,onMove:!1,appear:!1,appearEffect:null,prev:-1,next:-1,showPrevArrow:!1,showNextArrow:!1},groups:new Map}}function j(t){return t.getAttribute("data-group")||"nogroup"}function pe(t){return t.group||"nogroup"}function fe(t,e,i,o){let r=j(t),s=t.getAttribute("href"),n=t.querySelector("img"),m=s;n&&(n.getAttribute(e.lazyAttribute)?m=n.getAttribute(e.lazyAttribute):n.currentSrc?m=n.currentSrc:m=n.src);let p="";n!=null&&n.getAttribute("alt")?p=n.getAttribute("alt"):t.getAttribute("data-caption")?p=t.getAttribute("data-caption"):p=s!=null?s:"";let u=t.getAttribute("data-id");return{src:s,thumb:m,caption:t.getAttribute("data-caption"),alt:p,groupId:r,translateX:o*i,translateY:0,index:i,width:50,height:50,scale:1,x:0,y:0,id:u||i,loaded:!1,processed:!1,element:t}}function Oe(t,e,i){var u,f,P,b,H;let o=pe(t),r=t.src,s=(u=t.thumb)!=null?u:r,n=(f=t.caption)!=null?f:null,m=(b=(P=t.alt)!=null?P:n)!=null?b:r,p=typeof t.width=="number"&&typeof t.height=="number";return{src:r,thumb:s,caption:n,alt:m,groupId:o,translateX:i*e,translateY:0,index:e,width:p?t.width:50,height:p?t.height:50,scale:1,x:0,y:0,id:(H=t.id)!=null?H:e,loaded:p,processed:!1,element:null}}function ve(t,e){t.groups.has(e.groupId)||t.groups.set(e.groupId,[]),t.groups.get(e.groupId).push(e),t.viewer.currentGroup=e.groupId}function L(t){var e;return t.viewer.currentGroup===null?null:(e=t.groups.get(t.viewer.currentGroup))!=null?e:null}function C(t){var i;let e=L(t);return e&&(i=e[t.viewer.currentIndex])!=null?i:null}function we(t){let e=L(t);if(!e)return;let i=e.length,o=t.viewer.currentIndex+1,r=t.viewer.currentIndex-1;t.viewer.showNextArrow=!1,t.viewer.showPrevArrow=!1,o!==i&&(t.viewer.next=o,t.viewer.showNextArrow=!0),r!==-1&&(t.viewer.prev=r,t.viewer.showPrevArrow=!0)}function ge(t,e){t.forEach((i,o)=>{i.translateX=e*o})}function te(t,e){let i=10**e;return Math.round(t*i)/i}function G(t,e,i,o){return o?t.width>t.height?i/(t.height*t.scale):e/(t.width*t.scale):1/t.scale}function Ne(t,e,i,o){let r=t.width*t.scale*e.scaleSize,s=t.height*t.scale*e.scaleSize,n,m,p,u;return i>r?(p=(i-r)/2,n=-1*p):(p=(r-i)/2,n=-1*p),o>s?(u=(o-s)/2,m=-1*u):(u=(s-o)/2,m=-1*u),{minX:te(n,6)/t.scale,minY:te(m,6)/t.scale,maxX:te(p,6)/t.scale,maxY:te(u,6)/t.scale}}function Be(t,e,i,o,r){let s=i-(o+r);t.forEach(n=>{n.loaded&&(n.processed=!0,n.scale=s/n.height,n.height<s&&(n.scale=1),n.x=(n.scale-1)/2*n.width+(e-n.width*n.scale)/2,n.y=(n.scale-1)/2*n.height+(i-n.height*n.scale)/2,n.width*n.scale>e&&(n.scale=e/n.width,n.x=(n.scale-1)/2*n.width))})}function De(t){let e=C(t);return e?`group=${t.viewer.currentGroup}&photo=${e.id}`:""}function Re(t,e){let i=null;return t.groups.forEach(o=>{o.forEach(r=>{e.group===r.groupId&&e.photo===r.id&&(i=r)})}),i}function ye(t,e){let i=10**e;return Math.round(t*i)/i}function U(t){return{x:t.pageX,y:t.pageY}}function Xe(t,e){let i=t.x-e.x,o=t.y-e.y;return Math.sqrt(i*i+o*o)}var Qe=10;function _e(t,e){return{force:Math.sqrt(t*t+e*e),theta:Math.atan2(e,t)}}function Ye(){return{width:Z(),height:ee()}}function Fe({state:t,callbacks:e},{signal:i}){let o=new Map,r=Date.now(),s=!1,n=!1,m=null,p=null,u=null,f=0,P=null,b=!1,H=null,T=null,z=0,Y=0,V=!1,R=0,x=null,O=0,c=0;function Q(){return K()}function k(a){let{width:h,height:E}=Ye();return Ne(a,t.viewer,h,E)}function _(a){let{width:h,height:E}=Ye();return G(a,h,E,Q())}function oe(a,h){let E=C(t),y=k(E);t.viewer.elastic=!0,a===1?t.viewer.photoPosX=y.minX:a===-1&&(t.viewer.photoPosX=y.maxX),h===1?t.viewer.photoPosY=y.minY:h===-1&&(t.viewer.photoPosY=y.maxY),e.onPhotoDragMove(),setTimeout(()=>{t.viewer.elastic=!1,e.onPhotoDragMove()},300)}let F=setInterval(()=>{if(V||s||b||t.viewer.elastic||!t.viewer.scale)return;t.viewer.photoPosX+=O,t.viewer.photoPosY+=c;let a=C(t);if(!a)return;let h=k(a);t.viewer.photoPosX<h.minX?(t.viewer.photoPosX=h.minX,O*=-.2):t.viewer.photoPosX>h.maxX&&(t.viewer.photoPosX=h.maxX,O*=-.2),t.viewer.photoPosY<h.minY?(t.viewer.photoPosY=h.minY,c*=-.2):t.viewer.photoPosY>h.maxY&&(t.viewer.photoPosY=h.maxY,c*=-.2);let E=_e(O,c),y=E.force-t.options.registance;Math.abs(y)<.5||(O=Math.cos(E.theta)*y,c=Math.sin(E.theta)*y,e.onPhotoDragMove())},t.options.forceInterval);function W(a,h){(a>5||a<-5)&&(O+=a*.05),t.options.verticalGravity&&(h>5||h<-5)&&(c+=h*.05)}function re(a){if(!(a!=null&&a.gamma)||t.viewer.appearEffect||V||s||b||t.viewer.elastic||!t.viewer.scale)return;let{orientation:h}=window;h===0?W(a.gamma,a.beta):h===90?W(a.beta,a.gamma):h===-90?W(-a.beta,-a.gamma):h===180&&W(-a.gamma,-a.beta)}t.options.useOrientationApi&&window.addEventListener("deviceorientation",re,{signal:i});function ne(){V=!0,s=!1,b=!1;let a=Array.from(o.values());R=Xe(a[0],a[1]),t.viewer.scale=!0,e.onGestureStart()}function se(a){let h=U(a);s=!0,n=!0,m=h,p=h,f=Date.now(),P=a.target}function ae(a){b=!0;let h=U(a);T=h,H=h}function le(a){var h,E;try{(E=(h=a.currentTarget).setPointerCapture)==null||E.call(h,a.pointerId)}catch(y){}if(o.set(a.pointerId,U(a)),o.size>1){ne();return}if(t.viewer.scale){ae(a);return}se(a)}function he(){x===null&&(x=requestAnimationFrame(()=>{x=null,e.onGestureMove()}))}function ue(){x!==null&&(cancelAnimationFrame(x),x=null,e.onGestureMove())}function ce(){let a=Array.from(o.values()),h=Xe(a[0],a[1]),E=(h-R)/100,y=t.viewer.scaleSize,I=t.viewer.photoPosX,M=t.viewer.photoPosY;t.viewer.scaleSize+=ye(E,6),t.viewer.scaleSize<.2&&(t.viewer.scaleSize=.2),t.viewer.scaleSize<y&&(t.viewer.photoPosX=(1+t.viewer.scaleSize-y)*I,t.viewer.photoPosY=(1+t.viewer.scaleSize-y)*M);let D=C(t);if(D){let de=_(D);t.viewer.hideUi=t.viewer.scaleSize<1||t.viewer.scaleSize>de}R=h,he()}function d(a){let h=U(a),E=h.x-p.x,y=h.y-m.y;n&&(e.onSwipeStart(),n=!1,u=Math.abs(E)>Math.abs(y)?"horizontal":"vertical"),u==="horizontal"?t.viewer.translateX+=E:t.viewer.translateY=y,p=h,e.onSwipeMove()}function l(a){let h=U(a),E=h.x-T.x,y=h.y-T.y,I=ye(t.viewer.scaleSize*E,6),M=ye(t.viewer.scaleSize*y,6);t.viewer.photoPosX+=I,z=I,t.viewer.photoPosY+=M,Y=M,T=h,e.onPhotoDragMove()}function g(a){if(o.has(a.pointerId)){if(o.set(a.pointerId,U(a)),V){ce();return}if(b){l(a);return}d(a)}}function v(){V=!1,ue();let a=C(t);if(!a)return;let h=_(a);t.viewer.scaleSize>h||(t.viewer.photoPosX=0,t.viewer.photoPosY=0,t.viewer.scale=!1,t.viewer.scaleSize=1,t.viewer.hideUi=!1,e.onGestureEnd())}function w(){var Pe;s=!1;let a=m,h=p,E=Date.now(),y=r-E,I=h.x-a.x,M=h.y-a.y,D=I===0&&M===0;if(!Q()&&D){e.onTap(P);return}if(Math.abs(y)<=500&&D){e.onTap(P);return}r=E;let de=(Pe=L(t))!=null?Pe:[];if(u==="horizontal"){let $="stay",Ge=Math.max(E-f,1),Se=Math.abs(I)>=Qe&&Math.abs(I)/Ge>=t.options.swipeVelocity;(I>=t.options.swipeOffset||Se&&I>0)&&t.viewer.currentIndex!==0?$="prev":(I<=-t.options.swipeOffset||Se&&I<0)&&t.viewer.currentIndex!==de.length-1&&($="next"),e.onSwipeEnd($)}else{let $="stay";t.options.swipeBottomToClose&&M>=t.options.swipeOffset?$="close-bottom":t.options.swipeTopToClose&&M<=-t.options.swipeOffset&&($="close-top"),e.onSwipeEnd($)}}function S(){b=!1;let a=T,h=H;if(a.x===h.x&&a.y===h.y){e.onPhotoDragEnd("zoom-out");return}let E=C(t);if(!E){e.onPhotoDragEnd(null);return}let y=k(E),I=t.options.swipeOffset*t.viewer.scaleSize,M=0,D=0;if(t.viewer.photoPosX>y.maxX?M=-1:t.viewer.photoPosX<y.minX&&(M=1),t.viewer.photoPosY>y.maxY?D=-1:t.viewer.photoPosY<y.minY&&(D=1),t.viewer.photoPosX-y.maxX>I&&t.viewer.currentIndex!==0){e.onPhotoDragEnd("prev");return}if(y.minX-t.viewer.photoPosX>I&&t.viewer.currentIndex+1!==t.viewer.total){e.onPhotoDragEnd("next");return}M===0&&D===0?(O=z/5,c=Y/5):oe(M,D),e.onPhotoDragEnd(null)}function N(a){if(o.delete(a.pointerId),V){o.size<2&&v();return}if(b){S();return}s&&w()}function J(...a){for(let h of a)h.addEventListener("pointerdown",le,{signal:i}),h.addEventListener("pointermove",g,{signal:i}),h.addEventListener("pointerup",N,{signal:i}),h.addEventListener("pointercancel",N,{signal:i})}function B(){clearInterval(F),x!==null&&(cancelAnimationFrame(x),x=null)}return{attach:J,detach:B}}function ie(t){let e=document.createElement("span");return e.className="smartphoto-sr-only",e.textContent=t,e}function Ee(){let t=document.createElement("button");return t.type="button",t}function Je(t){return t.replace(/"/g,'\\"')}function We({id:t,options:e},i,{signal:o}){let{classNames:r,message:s}=e,n=document.createElement("div");n.setAttribute("data-id",t);let m=document.createElement("dialog");m.className=r.smartPhoto,m.setAttribute("aria-labelledby",`smartphoto-${t}-title`),m.style.display="none",m.style.setProperty("--smartphoto-animation-speed",`${e.animationSpeed}ms`);let p=document.createElement("div");p.className=r.smartPhotoBody;let u=document.createElement("div");u.className=r.smartPhotoInner;let f=document.createElement("div");f.className=r.smartPhotoHeader;let P=document.createElement("span");P.className=r.smartPhotoCount;let b=document.createElement("h1");b.id=`smartphoto-${t}-title`,b.className=r.smartPhotoCaption,b.setAttribute("tabindex","-1");let H=document.createElement("button");H.className=r.smartPhotoDismiss,H.appendChild(ie(s.closeDialog)),H.addEventListener("click",()=>i.onDismiss(),{signal:o}),f.append(P,b,H);let T=document.createElement("div");T.className=r.smartPhotoContent,T.addEventListener("click",d=>{d.target===T&&i.onBackdropClick()},{signal:o});let z=document.createElement("ul");z.className=r.smartPhotoList,z.setAttribute("role","region"),z.setAttribute("aria-roledescription","carousel"),z.setAttribute("aria-label",s.carouselLabel),z.setAttribute("aria-live","polite"),z.setAttribute("aria-atomic","false"),u.append(f,T,z);let Y=null,V=null,R=null;if(e.arrows){Y=document.createElement("ul"),Y.className=r.smartPhotoArrows,V=document.createElement("li"),V.className=r.smartPhotoArrowLeft;let d=Ee();d.appendChild(ie(s.gotoPrevImage)),d.addEventListener("click",()=>i.onPrev(),{signal:o}),V.appendChild(d),R=document.createElement("li"),R.className=r.smartPhotoArrowRight;let l=Ee();l.appendChild(ie(s.gotoNextImage)),l.addEventListener("click",()=>i.onNext(),{signal:o}),R.appendChild(l),Y.append(V,R),u.appendChild(Y)}let x=null,O=null;e.nav&&(x=document.createElement("nav"),x.className=r.smartPhotoNav,x.setAttribute("aria-label","Choose slide to display"),O=document.createElement("ul"),x.appendChild(O),u.appendChild(x)),p.appendChild(u),m.appendChild(p),n.appendChild(m);let c={dialog:m,count:P,caption:b,dismiss:H,content:T,list:z,arrows:Y,arrowLeft:V,arrowRight:R,nav:x,navList:O,slides:new Map,imgClone:null};function Q(){let d=document.createElement("div");d.className=r.smartPhotoLoaderWrap;let l=document.createElement("span");return l.className=r.smartPhotoLoader,d.appendChild(l),d}function k(d){var v,w;let l=document.createElement("div");l.className=r.smartPhotoImgWrap;let g=document.createElement("img");return g.className=r.smartPhotoImg,g.src=(v=d.src)!=null?v:"",g.alt=(w=d.alt)!=null?w:"",g.addEventListener("dragstart",S=>S.preventDefault(),{signal:o}),l.appendChild(g),{imgWrap:l,img:g}}function _(d,l){var g;c.list.replaceChildren(),(g=c.navList)==null||g.replaceChildren(),c.slides=new Map,d.forEach(v=>{var N,J;let w=document.createElement("li");w.setAttribute("role","group"),w.setAttribute("aria-roledescription","slide"),w.setAttribute("aria-label",`${v.index+1} of ${d.length}`);let S={li:w,loaderWrap:null,imgWrap:null,img:null,navLink:null};if(v.processed){let{imgWrap:B,img:a}=k(v);w.appendChild(B),S.imgWrap=B,S.img=a}else{let B=Q();w.appendChild(B),S.loaderWrap=B}if(c.list.appendChild(w),c.slides.set(v,S),c.navList){let B=document.createElement("li"),a=Ee();a.style.backgroundImage=`url("${Je((N=v.thumb)!=null?N:"")}")`;let h=v.index;a.addEventListener("click",()=>i.onNavigate(h),{signal:o}),a.appendChild(ie(`go to ${(J=v.caption)!=null?J:""}`)),B.appendChild(a),c.navList.appendChild(B),S.navLink=a}}),W(l)}function oe(d,l){var w;if(l.imgWrap||!d.processed)return l;let{imgWrap:g,img:v}=k(d);return(w=l.loaderWrap)==null||w.replaceWith(g),l.loaderWrap=null,l.imgWrap=g,l.img=v,l}function F(d){d&&document.activeElement&&d.contains(document.activeElement)&&c.caption.focus()}function W(d){let{viewer:l}=d;c.count.textContent=`${l.currentIndex+1}/${l.total}`,c.slides.forEach((g,v)=>{var N;let w=oe(v,g),S=v.index===l.currentIndex;w.li.style.transform=`translate(${v.translateX}px,${v.translateY}px)`,w.li.classList.toggle("current",S),S?w.li.removeAttribute("aria-hidden"):w.li.setAttribute("aria-hidden","true"),S&&(c.caption.textContent=(N=v.caption)!=null?N:""),w.imgWrap&&w.img&&(w.imgWrap.style.transform=`translate(${v.x}px,${v.y}px) scale(${v.scale})`,w.img.style.width=`${v.width}px`,S||(w.img.style.transform="translate(0px,0px) scale(1)"),w.img.classList.toggle("active",l.appear),w.img.classList.toggle(r.smartPhotoImgOnMove,l.scale),w.img.classList.toggle(r.smartPhotoImgElasticMove,l.elastic)),w.navLink&&(w.navLink.classList.toggle("current",S),S?w.navLink.setAttribute("aria-current","true"):w.navLink.removeAttribute("aria-current"))}),c.arrowLeft&&(l.showPrevArrow?c.arrowLeft.removeAttribute("aria-hidden"):(F(c.arrowLeft),c.arrowLeft.setAttribute("aria-hidden","true"))),c.arrowRight&&(l.showNextArrow?c.arrowRight.removeAttribute("aria-hidden"):(F(c.arrowRight),c.arrowRight.setAttribute("aria-hidden","true"))),c.arrows&&(l.hideUi&&F(c.arrows),c.arrows.setAttribute("aria-hidden",l.hideUi?"true":"false")),c.nav&&(l.hideUi&&F(c.nav),c.nav.setAttribute("aria-hidden",l.hideUi?"true":"false"))}function re(d){for(let[l,g]of c.slides)if(l.index===d.viewer.currentIndex)return g;return null}function ne(d){let{viewer:l}=d,g=re(d),v=g==null?void 0:g.img;v&&(v.style.transform=`translate(${l.photoPosX}px,${l.photoPosY}px) scale(${l.scaleSize})`,v.classList.toggle(r.smartPhotoImgOnMove,l.scale),v.classList.toggle(r.smartPhotoImgElasticMove,l.elastic)),c.nav&&(l.hideUi&&F(c.nav),c.nav.setAttribute("aria-hidden",l.hideUi?"true":"false")),c.arrows&&(l.hideUi&&F(c.arrows),c.arrows.setAttribute("aria-hidden",l.hideUi?"true":"false"))}function se(d){let{viewer:l}=d;c.list.style.transform=`translate(${l.translateX}px,${l.translateY}px)`,c.list.classList.toggle(r.smartPhotoListOnMove,l.onMove)}function ae(d){for(let[l,g]of c.slides){if(l.index!==d.viewer.currentIndex)continue;let{img:v,imgWrap:w}=g;if(!v||!w||!l.width||!l.scale||l.scale>=1)return;let S=v.getBoundingClientRect();v.style.width=`${l.width*l.scale}px`,w.style.transform=`translate(${l.x}px,${l.y}px) scale(1)`;let N=v.getBoundingClientRect();w.style.transform=`translate(${l.x+S.left-N.left}px,${l.y+S.top-N.top}px) scale(1)`;return}}function le(){for(let[d,l]of c.slides){let{img:g,imgWrap:v}=l;g&&v&&(v.style.transform=`translate(${d.x}px,${d.y}px) scale(${d.scale})`,g.style.width=`${d.width}px`)}}function he(d){let l=document.createElement("img");l.className=r.smartPhotoImgClone,l.src=d.img,l.style.width=`${d.width}px`,l.style.height=`${d.height}px`,l.style.transform=`translate(${d.left}px,${d.top}px) scale(1)`,p.appendChild(l),c.imgClone=l}function ue(){var d;(d=c.imgClone)==null||d.remove(),c.imgClone=null}function ce(){n.remove()}return{root:n,refs:c,render:W,syncSlides:_,updatePhotoTransform:ne,applyViewTransitionLayout:ae,resetViewTransitionLayout:le,updateListTransform:se,showAppearEffect:he,removeAppearEffect:ue,destroy:ce}}var A=Z,X=ee;function Ke(t){return t.length>0&&t[0]instanceof Element}function Ze(){return(Date.now().toString(36)+Math.random().toString(36).substring(2,7)).toUpperCase()}function $e(){return{x:window.pageXOffset!==void 0?window.pageXOffset:document.documentElement.scrollLeft,y:window.pageYOffset!==void 0?window.pageYOffset:document.documentElement.scrollTop}}var q=class{constructor(e,i){this.id=Ze();this.abortController=new AbortController;this.isSmartPhoneFlag=K();this.lastTriggerElement=null;this.isFiringPublicCloseEvent=!1;this.finishHideEffect=null;this.isViewTransitionActive=!1;this.pendingViewTransitionResync=!1;this.timeouts=[];this.loadAllFired=new Set;this.syncedGroupId=null;this.rootSelector=null;this.itemsByElement=new Map;this.handleDocumentClick=e=>{if(!(e.target instanceof Element))return;let i=e;if(i.__smartphotoClaimed)return;let o=this.findRegisteredAncestor(e.target);if(!o&&this.rootSelector&&(o=e.target.closest(this.rootSelector)),!o)return;if(e.preventDefault(),i.__smartphotoClaimed=!0,!this.itemsByElement.has(o)&&this.rootSelector){let s=j(o);this.resyncGroupFromDom(s)&&this.syncCurrentGroupView()}let r=this.itemsByElement.get(o);r&&this.openPhoto(r,o)};this.updateViewportHeight=()=>{this.view.refs.dialog.style.setProperty("--smartphoto-vh",`${X()}px`)};this.handleVisualViewportResize=()=>{if(this.updateViewportHeight(),!(!this.isSmartPhoneFlag||!this.state.viewer.isOpen||!L(this.state))){if(this.isViewTransitionActive){this.pendingViewTransitionResync=!0;return}this.resetTranslateCurrent(),this.setPosByCurrentIndex(),this.setSizeByScreen(),this.commit()}};this.handleResize=()=>{if(!(!this.state.viewer.isOpen||!L(this.state))){if(this.updateViewportHeight(),this.isViewTransitionActive){this.pendingViewTransitionResync=!0;return}this.resetTranslateCurrent(),this.setPosByCurrentIndex(),this.setSizeByScreen(),this.commit()}};this.handleKeydown=e=>{if(!this.state.viewer.isOpen)return;let i=e.keyCode||e.which;i===37?this.gotoSlide(this.state.viewer.prev):i===39?this.gotoSlide(this.state.viewer.next):i===27&&this.hidePhoto()};this.handleOrientationChange=()=>{if(!this.state.viewer.isOpen||!L(this.state))return;if(this.isViewTransitionActive){this.pendingViewTransitionResync=!0;return}this.updateViewportHeight(),this.resetTranslateCurrent(),this.setPosByCurrentIndex(),this.setHashByCurrentIndex(),this.setSizeByScreen(),this.commit();let e=A(),i=500,o=r=>{this.scheduleTimeout(()=>{this.state.viewer.isOpen&&(e!==A()?(this.updateViewportHeight(),this.resetTranslateCurrent(),this.setPosByCurrentIndex(),this.setHashByCurrentIndex(),this.setSizeByScreen(),this.commit()):r<=i&&o(r+25))},25)};o(0)};this.rootSelector=typeof e=="string"?e:null,this.state=ze(i!=null?i:{}),this.view=We({id:this.id,options:this.state.options},this.buildViewHandlers(),{signal:this.abortController.signal}),document.body.appendChild(this.view.root),this.gestures=Fe({state:this.state,callbacks:this.buildGestureCallbacks()},{signal:this.abortController.signal}),this.gestures.attach(this.view.refs.content,this.view.refs.list),this.view.refs.dialog.addEventListener("close",()=>{!this.isFiringPublicCloseEvent&&this.state.viewer.isOpen&&this.hidePhoto()},{signal:this.abortController.signal}),document.addEventListener("click",this.handleDocumentClick,{signal:this.abortController.signal}),this.ingestSource(e),this.syncCurrentGroupView();let o=this.restoreFromHash();if(o&&this.openPhoto(o,o.element),this.updateViewportHeight(),this.applyAutoIconContrast(),window.visualViewport?window.visualViewport.addEventListener("resize",this.handleVisualViewportResize,{signal:this.abortController.signal}):window.addEventListener("resize",this.updateViewportHeight,{signal:this.abortController.signal}),!this.isSmartPhoneFlag){window.addEventListener("resize",this.handleResize,{signal:this.abortController.signal}),window.addEventListener("keydown",this.handleKeydown,{signal:this.abortController.signal});return}window.addEventListener("orientationchange",this.handleOrientationChange,{signal:this.abortController.signal})}on(e,i){let o=this.view.refs.dialog,r=s=>i.call(o,s);o.addEventListener(e,r,{signal:this.abortController.signal})}destroy(){this.state.viewer.isOpen=!1,this.view.refs.dialog.open&&this.view.refs.dialog.close(),this.abortController.abort(),this.timeouts.forEach(e=>{clearTimeout(e)}),this.timeouts=[],this.itemsByElement.clear(),this.gestures.detach(),this.view.destroy()}[Symbol.dispose](){this.destroy()}gotoSlide(e){var s,n;let i=Number.parseInt(String(e),10),o=Number.isNaN(i)?0:i,r=(n=(s=L(this.state))==null?void 0:s.length)!=null?n:0;o<0||o>=r||(this.state.viewer.currentIndex=o,this.slideList())}hidePhoto(e="bottom"){var o;if(!this.state.viewer.isOpen)return;this.state.viewer.isOpen=!1,this.state.viewer.appear=!1,this.state.viewer.appearEffect=null,this.view.removeAppearEffect(),this.state.viewer.hideUi=!1,this.state.viewer.scale=!1,this.state.viewer.scaleSize=1;let i=$e();location.hash&&this.setHash(""),window.scroll(i.x,i.y),this.syncDialog(),(o=this.lastTriggerElement)!=null&&o.isConnected&&this.lastTriggerElement.focus(),this.lastTriggerElement=null,this.doHideEffect(e).then(()=>{this.view.render(this.state),this.isFiringPublicCloseEvent=!0,this.fireEvent("close"),this.isFiringPublicCloseEvent=!1})}zoomPhoto(){let e=C(this.state);e&&(this.state.viewer.hideUi=!0,this.state.viewer.scaleSize=G(e,A(),X(),this.isSmartPhoneFlag),!(this.state.viewer.scaleSize<=1)&&(this.state.viewer.photoPosX=0,this.state.viewer.photoPosY=0,this.view.updatePhotoTransform(this.state),this.scheduleTimeout(()=>{this.state.viewer.isOpen&&(this.state.viewer.scale=!0,this.view.updatePhotoTransform(this.state),this.fireEvent("zoomin"))},this.state.options.animationSpeed)))}canZoomCurrentPhoto(){let e=C(this.state);return!!e&&G(e,A(),X(),this.isSmartPhoneFlag)>1}zoomOutPhoto(){this.state.viewer.scaleSize=1,this.state.viewer.hideUi=!1,this.state.viewer.scale=!1,this.state.viewer.photoPosX=0,this.state.viewer.photoPosY=0,this.view.updatePhotoTransform(this.state),this.fireEvent("zoomout")}addNewItem(e){return this.addItem(e)}show(e=0,i={}){var p,u,f;let o=(p=i.group)!=null?p:this.state.viewer.currentGroup;if(o===null)return;let r=this.state.groups.get(o);if(!(r!=null&&r.length))return;let s=typeof e=="number"?r[e]:r.find(P=>P.id===e);if(!s)return;let n=document.activeElement instanceof HTMLElement?document.activeElement:null,m=(f=(u=i.trigger)!=null?u:s.element)!=null?f:n;this.openPhoto(s,m)}hide(){this.hidePhoto()}next(){this.state.viewer.showNextArrow&&this.gotoSlide(this.state.viewer.next)}prev(){this.state.viewer.showPrevArrow&&this.gotoSlide(this.state.viewer.prev)}addItem(e){let i=e instanceof HTMLElement?this.addElementItem(e):this.addSlideItem(e);return this.syncCurrentGroupView(),i}get currentIndex(){return this.state.viewer.currentIndex}ingestSource(e){if(Array.isArray(e)&&!Ke(e)){e.forEach(o=>{this.addSlideItem(o)});return}Array.from(typeof e=="string"?document.querySelectorAll(e):e).forEach(o=>{this.addElementItem(o)})}addElementItem(e){var s,n;let i=j(e),o=(n=(s=this.state.groups.get(i))==null?void 0:s.length)!=null?n:0,r=fe(e,this.state.options,o,A());return ve(this.state,r),this.loadAllFired.delete(i),this.itemsByElement.set(e,r),r}addSlideItem(e){var s,n;let i=pe(e),o=(n=(s=this.state.groups.get(i))==null?void 0:s.length)!=null?n:0,r=Oe(e,o,A());return ve(this.state,r),this.loadAllFired.delete(i),r}findRegisteredAncestor(e){let i=e;for(;i;){if(this.itemsByElement.has(i))return i;i=i.parentElement}return null}resyncGroupFromDom(e){var p;if(!this.rootSelector)return!1;let i=Array.from(document.querySelectorAll(this.rootSelector)).filter(u=>j(u)===e),o=new Set(i),r=(p=this.state.groups.get(e))!=null?p:[],s=new Map;r.forEach(u=>{u.element&&s.set(u.element,u)});let n=i.length!==r.length,m=i.map((u,f)=>{let P=s.get(u);if(P)return P.index!==f&&(n=!0,P.index=f),P;n=!0;let b=fe(u,this.state.options,f,A());return this.itemsByElement.set(u,b),b});return r.forEach(u=>{u.element&&!o.has(u.element)&&this.itemsByElement.delete(u.element)}),ge(m,A()),this.state.groups.set(e,m),n&&this.loadAllFired.delete(e),n}syncCurrentGroupView(){let e=L(this.state);e&&(this.view.syncSlides(e,this.state),this.syncedGroupId=this.state.viewer.currentGroup)}setHash(e){var o;if(!((o=window.history)!=null&&o.pushState)||!this.state.options.useHistoryApi)return;let i=`${location.pathname}${location.search}`;window.history.replaceState(null,"",e?`${i}#${e}`:i)}setHashByCurrentIndex(){let e=$e();this.setHash(De(this.state)),window.scroll(e.x,e.y)}restoreFromHash(){let e=location.hash.substring(1);return e?Re(this.state,Ae(e)):null}setPosByCurrentIndex(){let e=C(this.state);e&&(this.state.viewer.translateX=-e.translateX,this.state.viewer.translateY=0,this.view.updateListTransform(this.state))}setSizeByScreen(){let e=L(this.state);e&&(Be(e,A(),X(),this.state.options.headerHeight,this.state.options.footerHeight),this.syncFillScale())}resetTranslateCurrent(){ge(L(this.state),A())}currentImgElement(){for(let[e,i]of this.view.refs.slides)if(e.index===this.state.viewer.currentIndex)return i.img;return null}currentLiElement(){for(let[e,i]of this.view.refs.slides)if(e.index===this.state.viewer.currentIndex)return i.li;return null}syncDialog(){let{dialog:e,caption:i}=this.view.refs;e.style.transition=this.state.options.showAnimation===!1?"none":"",this.state.viewer.isOpen&&!e.open?(e.style.removeProperty("display"),e.showModal(),i.focus()):!this.state.viewer.isOpen&&e.open&&(e.close(),e.style.display="none")}commit(){this.view.render(this.state),this.view.updatePhotoTransform(this.state),this.syncDialog()}initPhoto(){var i;(i=this.finishHideEffect)==null||i.call(this),this.updateViewportHeight(),this.view.refs.dialog.style.opacity="";let e=L(this.state);this.state.viewer.total=e.length,this.state.viewer.isOpen=!0,this.state.viewer.photoPosX=0,this.state.viewer.photoPosY=0,this.setPosByCurrentIndex(),this.setSizeByScreen(),we(this.state)}syncFillScale(){if(this.state.options.resizeStyle!=="fill"||!this.isSmartPhoneFlag)return;let e=C(this.state);e&&(this.state.viewer.scale=!0,this.state.viewer.hideUi=!0,this.state.viewer.scaleSize=G(e,A(),X(),this.isSmartPhoneFlag))}supportsViewTransition(){return this.state.options.useViewTransitionApi&&typeof document.startViewTransition=="function"&&!Ie()}openPhotoWithViewTransition(e){var n,m;document.documentElement.style.setProperty("--smartphoto-animation-speed",`${this.state.options.animationSpeed}ms`);let i="smartphoto-hero",o=(n=e==null?void 0:e.querySelector("img"))!=null?n:null;o&&(o.style.viewTransitionName=i);let r=()=>{this.isViewTransitionActive=!1,o&&(o.style.viewTransitionName="");let p=this.currentImgElement();if(p&&(p.style.viewTransitionName=""),!this.state.viewer.isOpen){this.pendingViewTransitionResync=!1;return}if(this.pendingViewTransitionResync&&L(this.state)){this.pendingViewTransitionResync=!1,this.updateViewportHeight(),this.resetTranslateCurrent(),this.setPosByCurrentIndex(),this.setSizeByScreen(),this.commit();return}this.pendingViewTransitionResync=!1,this.view.resetViewTransitionLayout()},s=(m=document.startViewTransition)==null?void 0:m.call(document,()=>{this.initPhoto(),this.state.viewer.appear=!0,this.commit(),o&&(o.style.viewTransitionName=""),this.currentImgElement().style.viewTransitionName=i,this.view.applyViewTransitionLayout(this.state)});s&&(this.isViewTransitionActive=!0,s.ready.catch(()=>{r()}),s.finished.then(r,r))}addAppearEffect(e,i){var T;let o=(T=e==null?void 0:e.querySelector("img"))!=null?T:null;if(!o){this.state.viewer.appear=!0;return}let r=He(o),s=o.offsetWidth,n=o.offsetHeight,m=A(),p=X(),u=p-this.state.options.headerHeight-this.state.options.footerHeight,f=1;this.state.options.resizeStyle==="fill"&&this.isSmartPhoneFlag?s>n?f=p/n:f=m/s:(s>=n?i.height<u?f=i.width/s:f=u/n:i.height<u?f=i.height/n:f=u/n,s*f>m&&(f=m/s));let P=(f-1)/2*s+(m-s*f)/2,b=(f-1)/2*n+(p-n*f)/2,H=o.getAttribute(this.state.options.lazyAttribute);this.state.viewer.appearEffect={width:s,height:n,top:r.top,left:r.left,once:!0,img:H||i.src||"",afterX:P,afterY:b,scale:f}}runAppearEffect(e){this.view.showAppearEffect(e);let i=this.view.refs.imgClone;return new Promise(o=>{let r=()=>{i.removeEventListener("transitionend",r,!0),o()};i.addEventListener("transitionend",r,!0),this.scheduleTimeout(()=>{i.style.transform=`translate(${e.afterX}px, ${e.afterY}px) scale(${e.scale})`},10)})}doOpen(e,i){if(this.state.options.showAnimation!==!1&&this.supportsViewTransition())this.openPhotoWithViewTransition(e);else if(this.state.options.showAnimation===!1)this.initPhoto(),this.state.viewer.appear=!0,this.commit();else{this.initPhoto(),this.addAppearEffect(e,i),this.commit();let o=this.state.viewer.appearEffect;o&&this.runAppearEffect(o).then(()=>{this.state.viewer.appearEffect=null,this.view.removeAppearEffect(),this.state.viewer.appear=!0,this.commit()})}this.fireEvent("open"),this.resyncSizeAfterOpen()}resyncSizeAfterOpen(){let e=A(),i=X();requestAnimationFrame(()=>{if(this.state.viewer.isOpen&&!(A()===e&&X()===i)){if(this.isViewTransitionActive){this.pendingViewTransitionResync=!0;return}this.resetTranslateCurrent(),this.setPosByCurrentIndex(),this.setSizeByScreen(),this.commit()}})}openPhoto(e,i){let o=this.rootSelector?this.resyncGroupFromDom(e.groupId):!1;this.lastTriggerElement=i,this.state.viewer.currentGroup=e.groupId,this.state.viewer.currentIndex=e.index,(this.syncedGroupId!==e.groupId||o)&&this.syncCurrentGroupView(),this.setHashByCurrentIndex(),e.loaded?this.doOpen(i,e):this.loadItem(e).then(()=>{this.doOpen(i,e)})}doHideEffect(e){return new Promise(i=>{if(this.state.options.showAnimation===!1){i();return}let o=this.view.refs.dialog,r=C(this.state),s=r?this.currentLiElement():null,n=X(),m=this.currentImgElement(),p=null;if(m){let f=getComputedStyle(m).transform;f&&f!=="none"&&(m.style.transform=f,p=m.style.transform)}if(s&&r){let f=e==="top"?-n:n;s.style.transform=`translate(${r.translateX}px,${r.translateY+f}px)`}let u=f=>{this.finishHideEffect===u&&(f&&f.target!==o||(this.finishHideEffect=null,o.removeEventListener("transitionend",u,!0),m&&p&&m.style.transform===p&&(m.style.transform=""),i()))};this.finishHideEffect=u,o.addEventListener("transitionend",u,!0),this.scheduleTimeout(u,this.state.options.animationSpeed+100)})}loadItem(e){return new Promise(i=>{var r;let o=new Image;o.onload=()=>{e.width=o.width,e.height=o.height,e.loaded=!0,this.checkLoadAll(e.groupId),i()},o.onerror=()=>i(),o.src=(r=e.src)!=null?r:""})}checkLoadAll(e){if(this.loadAllFired.has(e))return;let i=this.state.groups.get(e);i!=null&&i.length&&i.every(o=>o.loaded)&&(this.loadAllFired.add(e),this.fireEvent("loadall"))}loadNeighborItems(){let e=L(this.state);if(!e)return;let{currentIndex:i}=this.state.viewer,{loadOffset:o}=this.state.options,r=[];for(let s=i-o;s<i+o;s++){let n=e[s];n&&!n.loaded&&r.push(this.loadItem(n))}r.length&&Promise.all(r).then(()=>{this.state.viewer.isOpen&&(this.initPhoto(),this.commit())})}slideList(){this.state.viewer.scaleSize=1,this.state.viewer.hideUi=!1,this.state.viewer.scale=!1,this.state.viewer.photoPosX=0,this.state.viewer.photoPosY=0,this.state.viewer.onMove=!0,this.updateViewportHeight(),this.setPosByCurrentIndex(),this.setHashByCurrentIndex(),this.setSizeByScreen(),this.scheduleTimeout(()=>{let e=C(this.state);this.state.viewer.onMove=!1,we(this.state),this.state.viewer.isOpen&&this.commit(),this.state.viewer.oldIndex!==this.state.viewer.currentIndex&&this.fireEvent("change"),this.state.viewer.oldIndex=this.state.viewer.currentIndex,this.loadNeighborItems(),e&&!e.loaded&&this.loadItem(e).then(()=>{this.state.viewer.isOpen&&(this.initPhoto(),this.commit())})},200)}scheduleTimeout(e,i){let o=window.setTimeout(()=>{this.timeouts=this.timeouts.filter(r=>r!==o),e()},i);return this.timeouts.push(o),o}applyAutoIconContrast(){let e=this.view.refs.dialog,i=getComputedStyle(e);if(i.getPropertyValue("--smartphoto-icon-color").trim())return;let o=i.getPropertyValue("--smartphoto-backdrop-color").trim();o&&e.style.setProperty("--smartphoto-icon-color",Me(o))}fireEvent(e){Ce(this.view.refs.dialog,e)}buildViewHandlers(){return{onDismiss:()=>this.hidePhoto(),onPrev:()=>this.prev(),onNext:()=>this.next(),onNavigate:e=>this.gotoSlide(e),onBackdropClick:()=>this.hidePhoto()}}buildGestureCallbacks(){return{onSwipeStart:()=>this.fireEvent("swipestart"),onSwipeMove:()=>this.view.updateListTransform(this.state),onSwipeEnd:e=>{if(this.fireEvent("swipeend"),e==="close-bottom"){this.hidePhoto("bottom");return}if(e==="close-top"){this.hidePhoto("top");return}e==="prev"?this.state.viewer.currentIndex-=1:e==="next"&&(this.state.viewer.currentIndex+=1),this.slideList()},onTap:e=>{let i=this.currentImgElement();!!i&&e instanceof Node&&i.contains(e)&&this.canZoomCurrentPhoto()?this.zoomPhoto():this.hidePhoto()},onGestureStart:()=>{this.fireEvent("gesturestart"),this.view.updatePhotoTransform(this.state)},onGestureMove:()=>this.view.updatePhotoTransform(this.state),onGestureEnd:()=>{this.fireEvent("gestureend"),this.view.updatePhotoTransform(this.state)},onPhotoDragMove:()=>this.view.updatePhotoTransform(this.state),onPhotoDragEnd:e=>{if(e==="zoom-out"){this.zoomOutPhoto();return}if(e==="prev"){this.gotoSlide(this.state.viewer.prev);return}if(e==="next"){this.gotoSlide(this.state.viewer.next);return}this.view.updatePhotoTransform(this.state)}}}};var ke=q;var be=t=>{t.fn.SmartPhoto=function(e){return typeof e=="string"||new ke(this,e),this}};if(typeof define=="function"&&define.amd)define(["jquery"],be);else{let t=window,e=t.jQuery?t.jQuery:t.$;typeof e!="undefined"&&be(e)}var ct=be;})();
6
+ "use strict";(()=>{var ae=()=>{let t=navigator.userAgent;return t.indexOf("iPhone")>0||t.indexOf("iPad")>0||t.indexOf("ipod")>0||t.indexOf("Android")>0},Me=()=>typeof window.webkitConvertPointFromNodeToPage=="function";function Ve(t,...e){var i;t=t||{};for(let o=0;o<e.length;o++){let n=e[o];if(n){for(let s in n)if(Object.hasOwn(n,s)){let r=n[s];r&&typeof r=="object"?t[s]=Ve((i=t[s])!=null?i:{},r):t[s]=r}}}return t}var ze=Ve,Oe=(t,e,i)=>{let o;window.CustomEvent?o=new CustomEvent(e,{cancelable:!0}):(o=document.createEvent("CustomEvent"),o.initCustomEvent(e,!1,!1,i)),t.dispatchEvent(o)},Ne=t=>{let e={};for(let i of t.split("&")){let o=i.split("="),n=o[0],s=o.length>1?o.slice(1).join("="):n;e[n]=decodeURIComponent(s)}return e},le=()=>document.documentElement.clientWidth,he=()=>{let t=window.visualViewport;return t?t.height*t.scale:document.documentElement.clientHeight},Be=t=>({left:t.getBoundingClientRect().left,top:t.getBoundingClientRect().top});var He=t=>{let e=t.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*[\d.]+\s*)?\)/);return e?[Number(e[1]),Number(e[2]),Number(e[3])]:null},tt=.179,it=([t,e,i])=>{let[o,n,s]=[t,e,i].map(r=>{let m=r/255;return m<=.03928?m/12.92:((m+.055)/1.055)**2.4});return .2126*o+.7152*n+.0722*s},De=t=>{let e=t.trim(),i=He(e);if(!i){let o=document.createElement("div");if(o.style.color=e,!o.style.color)return"#fff";document.body.appendChild(o),i=He(getComputedStyle(o).color),document.body.removeChild(o)}return i&&it(i)>tt?"#000":"#fff"};var ot={classNames:{smartPhoto:"smartphoto",smartPhotoClose:"smartphoto-close",smartPhotoBody:"smartphoto-body",smartPhotoInner:"smartphoto-inner",smartPhotoContent:"smartphoto-content",smartPhotoImg:"smartphoto-img",smartPhotoImgOnMove:"smartphoto-img-onmove",smartPhotoImgElasticMove:"smartphoto-img-elasticmove",smartPhotoImgWrap:"smartphoto-img-wrap",smartPhotoArrows:"smartphoto-arrows",smartPhotoNav:"smartphoto-nav",smartPhotoArrowRight:"smartphoto-arrow-right",smartPhotoArrowLeft:"smartphoto-arrow-left",smartPhotoArrowHideIcon:"smartphoto-arrow-hide",smartPhotoImgLeft:"smartphoto-img-left",smartPhotoImgRight:"smartphoto-img-right",smartPhotoList:"smartphoto-list",smartPhotoListOnMove:"smartphoto-list-onmove",smartPhotoHeader:"smartphoto-header",smartPhotoCount:"smartphoto-count",smartPhotoCaption:"smartphoto-caption",smartPhotoDismiss:"smartphoto-dismiss",smartPhotoLoader:"smartphoto-loader",smartPhotoLoaderWrap:"smartphoto-loader-wrap",smartPhotoImgClone:"smartphoto-img-clone"},message:{gotoNextImage:"go to the next image",gotoPrevImage:"go to the previous image",closeDialog:"close the image dialog",carouselLabel:"Images"},arrows:!0,nav:!0,showAnimation:!0,verticalGravity:!1,useOrientationApi:!1,useHistoryApi:!0,useViewTransitionApi:!0,swipeTopToClose:!1,swipeBottomToClose:!0,pinchToClose:!0,swipeOffset:100,swipeVelocity:.5,headerHeight:60,footerHeight:60,forceInterval:10,registance:.5,loadOffset:2,resizeStyle:"fit",lazyAttribute:"data-src",animationSpeed:300};function Re(t){return Object.keys(t).forEach(e=>{let i=t[e];i&&typeof i=="object"&&!Object.isFrozen(i)&&Re(i)}),Object.freeze(t)}function Xe(t){return{options:Re(ze({},ot,t)),viewer:{isOpen:!1,currentGroup:null,currentIndex:0,oldIndex:0,total:0,translateX:0,translateY:0,photoPosX:0,photoPosY:0,scaleSize:1,scale:!1,elastic:!1,hideUi:!1,onMove:!1,appear:!1,appearEffect:null,prev:-1,next:-1,showPrevArrow:!1,showNextArrow:!1},groups:new Map}}function ee(t){return t.getAttribute("data-group")||"nogroup"}function Ee(t){return t.group||"nogroup"}function Pe(t,e,i,o){let n=ee(t),s=t.getAttribute("href"),r=t.querySelector("img"),m=s;r&&(r.getAttribute(e.lazyAttribute)?m=r.getAttribute(e.lazyAttribute):r.currentSrc?m=r.currentSrc:m=r.src);let p="";r!=null&&r.getAttribute("alt")?p=r.getAttribute("alt"):t.getAttribute("data-caption")?p=t.getAttribute("data-caption"):p=s!=null?s:"";let c=t.getAttribute("data-id");return{src:s,thumb:m,caption:t.getAttribute("data-caption"),alt:p,groupId:n,translateX:o*i,translateY:0,index:i,width:50,height:50,scale:1,x:0,y:0,id:c||i,loaded:!1,processed:!1,element:t}}function Ye(t,e,i){var c,f,x,b,M;let o=Ee(t),n=t.src,s=(c=t.thumb)!=null?c:n,r=(f=t.caption)!=null?f:null,m=(b=(x=t.alt)!=null?x:r)!=null?b:n,p=typeof t.width=="number"&&typeof t.height=="number";return{src:n,thumb:s,caption:r,alt:m,groupId:o,translateX:i*e,translateY:0,index:e,width:p?t.width:50,height:p?t.height:50,scale:1,x:0,y:0,id:(M=t.id)!=null?M:e,loaded:p,processed:!1,element:null}}function be(t,e){t.groups.has(e.groupId)||t.groups.set(e.groupId,[]),t.groups.get(e.groupId).push(e),t.viewer.currentGroup=e.groupId}function I(t){var e;return t.viewer.currentGroup===null?null:(e=t.groups.get(t.viewer.currentGroup))!=null?e:null}function L(t){var i;let e=I(t);return e&&(i=e[t.viewer.currentIndex])!=null?i:null}function Se(t){let e=I(t);if(!e)return;let i=e.length,o=t.viewer.currentIndex+1,n=t.viewer.currentIndex-1;t.viewer.showNextArrow=!1,t.viewer.showPrevArrow=!1,o!==i&&(t.viewer.next=o,t.viewer.showNextArrow=!0),n!==-1&&(t.viewer.prev=n,t.viewer.showPrevArrow=!0)}function xe(t,e){t.forEach((i,o)=>{i.translateX=e*o})}function ue(t,e){let i=10**e;return Math.round(t*i)/i}function _(t,e,i,o){return o?t.width>t.height?i/(t.height*t.scale):e/(t.width*t.scale):1/t.scale}function Fe(t,e,i,o){let n=t.width*t.scale*e.scaleSize,s=t.height*t.scale*e.scaleSize,r,m,p,c;return i>n?(p=(i-n)/2,r=-1*p):(p=(n-i)/2,r=-1*p),o>s?(c=(o-s)/2,m=-1*c):(c=(s-o)/2,m=-1*c),{minX:ue(r,6)/t.scale,minY:ue(m,6)/t.scale,maxX:ue(p,6)/t.scale,maxY:ue(c,6)/t.scale}}var nt=24;function Ge(t,e,i,o,n){let s=i-(o+n)-nt*2;t.forEach(r=>{r.loaded&&(r.processed=!0,r.scale=s/r.height,r.height<s&&(r.scale=1),r.x=(r.scale-1)/2*r.width+(e-r.width*r.scale)/2,r.y=(r.scale-1)/2*r.height+(i-r.height*r.scale)/2,r.width*r.scale>e&&(r.scale=e/r.width,r.x=(r.scale-1)/2*r.width))})}function We(t){let e=L(t);return e?`group=${t.viewer.currentGroup}&photo=${e.id}`:""}function $e(t,e){let i=null;return t.groups.forEach(o=>{o.forEach(n=>{e.group===n.groupId&&e.photo===n.id&&(i=n)})}),i}function te(t,e){let i=10**e;return Math.round(t*i)/i}function K(t){return{x:t.clientX,y:t.clientY}}function ke(t,e){let i=t.x-e.x,o=t.y-e.y;return Math.sqrt(i*i+o*o)}var rt=10;function st(t,e){return{force:Math.sqrt(t*t+e*e),theta:Math.atan2(e,t)}}function Ie(){return{width:le(),height:he()}}function Ue({state:t,callbacks:e},{signal:i}){let o=new Map,n=Date.now(),s=!1,r=!1,m=null,p=null,c=null,f=0,x=null,b=!1,M=null,C=null,N=0,W=0,z=!1,B=0,D=1,V=null,u=0,R=0;function j(){return ae()}function q(a){let{width:h,height:w}=Ie();return Fe(a,t.viewer,h,w)}function oe(a){let{width:h,height:w}=Ie();return _(a,h,w,j())}function $(a){return t.options.resizeStyle==="fill"&&j()?oe(a):1}let ne=4;function de(a){return Math.max(ne,oe(a))}let me=.75;function re(a,h){let w=L(t),g=q(w);t.viewer.elastic=!0,a===1?t.viewer.photoPosX=g.minX:a===-1&&(t.viewer.photoPosX=g.maxX),h===1?t.viewer.photoPosY=g.minY:h===-1&&(t.viewer.photoPosY=g.maxY),e.onPhotoDragMove(),setTimeout(()=>{t.viewer.elastic=!1,e.onPhotoDragMove()},300)}let pe=setInterval(()=>{if(z||s||b||t.viewer.elastic||!t.viewer.scale)return;t.viewer.photoPosX+=u,t.viewer.photoPosY+=R;let a=L(t);if(!a)return;let h=q(a);t.viewer.photoPosX<h.minX?(t.viewer.photoPosX=h.minX,u*=-.2):t.viewer.photoPosX>h.maxX&&(t.viewer.photoPosX=h.maxX,u*=-.2),t.viewer.photoPosY<h.minY?(t.viewer.photoPosY=h.minY,R*=-.2):t.viewer.photoPosY>h.maxY&&(t.viewer.photoPosY=h.maxY,R*=-.2);let w=st(u,R),g=w.force-t.options.registance;g<.5||(u=Math.cos(w.theta)*g,R=Math.sin(w.theta)*g,e.onPhotoDragMove())},t.options.forceInterval);function Q(a,h){(a>5||a<-5)&&(u+=a*.05),t.options.verticalGravity&&(h>5||h<-5)&&(R+=h*.05)}function fe(a){if(!(a!=null&&a.gamma)||t.viewer.appearEffect||z||s||b||t.viewer.elastic||!t.viewer.scale)return;let{orientation:h}=window;h===0?Q(a.gamma,a.beta):h===90?Q(a.beta,a.gamma):h===-90?Q(-a.beta,-a.gamma):h===180&&Q(-a.gamma,-a.beta)}t.options.useOrientationApi&&window.addEventListener("deviceorientation",fe,{signal:i});function se(){let a=Array.from(o.values());B=ke(a[0],a[1]),D=t.viewer.scaleSize}function ve(){z=!0,s=!1,b=!1,se(),u=0,R=0,t.viewer.scale=!0,t.viewer.hideUi=!0,e.onGestureStart()}function d(a){let h=K(a);s=!0,r=!0,m=h,p=h,f=Date.now(),x=a.target}function l(a){b=!0;let h=K(a);C=h,M=h}function v(a){var h,w;try{(w=(h=a.currentTarget).setPointerCapture)==null||w.call(h,a.pointerId)}catch(g){}if(o.set(a.pointerId,K(a)),o.size>1){ve();return}if(t.viewer.scale){l(a);return}d(a)}function y(){V===null&&(V=requestAnimationFrame(()=>{V=null,e.onGestureMove()}))}function P(){V!==null&&(cancelAnimationFrame(V),V=null,e.onGestureMove())}function E(){let a=Array.from(o.values()),h=a[0],w=a[1],g=ke(h,w);if(B===0){B=g,D=t.viewer.scaleSize,y();return}let S=t.viewer.scaleSize;t.viewer.scaleSize=te(D*g/B,6),t.viewer.scaleSize<.2&&(t.viewer.scaleSize=.2);let H=L(t);if(H&&t.viewer.scaleSize!==S){let{width:G,height:ge}=Ie(),Z=G/2,Y=t.options.headerHeight+(ge-t.options.headerHeight-t.options.footerHeight)/2,J=H.scale,U={x:(h.x+w.x)/2,y:(h.y+w.y)/2},Ae=t.viewer.scaleSize/S,Ze=U.x-(Z+t.viewer.photoPosX*J),et=U.y-(Y+t.viewer.photoPosY*J);t.viewer.photoPosX=te((U.x-Ze*Ae-Z)/J,6),t.viewer.photoPosY=te((U.y-et*Ae-Y)/J,6)}y()}function A(a){let h=K(a),w=h.x-p.x,g=h.y-m.y;r&&(e.onSwipeStart(),r=!1,c=Math.abs(w)>Math.abs(g)?"horizontal":"vertical"),c==="horizontal"?t.viewer.translateX+=w:t.viewer.translateY=g,p=h,e.onSwipeMove()}function k(a){let h=K(a),w=h.x-C.x,g=h.y-C.y,S=te(t.viewer.scaleSize*w,6),H=te(t.viewer.scaleSize*g,6);t.viewer.photoPosX+=S,N=S,t.viewer.photoPosY+=H,W=H,C=h,e.onPhotoDragMove()}function X(a){if(o.has(a.pointerId)){if(o.set(a.pointerId,K(a)),z){E();return}if(b){k(a);return}A(a)}}function F(){z=!1,P();let a=L(t);if(!a)return;let h=$(a);if(t.viewer.scaleSize<=h){if(t.options.pinchToClose&&t.viewer.scaleSize<h*me){e.onPinchClose();return}t.viewer.photoPosX=0,t.viewer.photoPosY=0,t.viewer.scaleSize=h,t.viewer.scale=h>1,t.viewer.hideUi=h>1,e.onGestureEnd();return}t.viewer.scaleSize=Math.min(t.viewer.scaleSize,de(a));let w=q(a),g=0,S=0;t.viewer.photoPosX>w.maxX?g=-1:t.viewer.photoPosX<w.minX&&(g=1),t.viewer.photoPosY>w.maxY?S=-1:t.viewer.photoPosY<w.minY&&(S=1),(g!==0||S!==0)&&re(g,S),t.viewer.scale=!0,t.viewer.hideUi=!0,e.onGestureEnd()}function we(){var Z;s=!1;let a=m,h=p,w=Date.now(),g=n-w,S=h.x-a.x,H=h.y-a.y,G=S===0&&H===0;if(!j()&&G){e.onTap(x);return}if(Math.abs(g)<=500&&G){e.onTap(x);return}n=w;let ge=(Z=I(t))!=null?Z:[];if(c==="horizontal"){let Y="stay",J=Math.max(w-f,1),U=Math.abs(S)>=rt&&Math.abs(S)/J>=t.options.swipeVelocity;(S>=t.options.swipeOffset||U&&S>0)&&t.viewer.currentIndex!==0?Y="prev":(S<=-t.options.swipeOffset||U&&S<0)&&t.viewer.currentIndex!==ge.length-1&&(Y="next"),e.onSwipeEnd(Y)}else{let Y="stay";t.options.swipeBottomToClose&&H>=t.options.swipeOffset?Y="close-bottom":t.options.swipeTopToClose&&H<=-t.options.swipeOffset&&(Y="close-top"),e.onSwipeEnd(Y)}}function Qe(){b=!1;let a=C,h=M;if(a.x===h.x&&a.y===h.y){e.onPhotoDragEnd("zoom-out");return}let w=L(t);if(!w){e.onPhotoDragEnd(null);return}let g=q(w),S=t.options.swipeOffset*t.viewer.scaleSize,H=0,G=0;if(t.viewer.photoPosX>g.maxX?H=-1:t.viewer.photoPosX<g.minX&&(H=1),t.viewer.photoPosY>g.maxY?G=-1:t.viewer.photoPosY<g.minY&&(G=1),t.viewer.photoPosX-g.maxX>S&&t.viewer.currentIndex!==0){e.onPhotoDragEnd("prev");return}if(g.minX-t.viewer.photoPosX>S&&t.viewer.currentIndex+1!==t.viewer.total){e.onPhotoDragEnd("next");return}H===0&&G===0?(u=N/5,R=W/5):re(H,G),e.onPhotoDragEnd(null)}function Ce(a){if(o.delete(a.pointerId),z){o.size<2?(F(),o.clear()):se();return}if(b){Qe();return}s&&we()}function Je(...a){for(let h of a)h.addEventListener("pointerdown",v,{signal:i}),h.addEventListener("pointermove",X,{signal:i}),h.addEventListener("pointerup",Ce,{signal:i}),h.addEventListener("pointercancel",Ce,{signal:i})}function Ke(){clearInterval(pe),V!==null&&(cancelAnimationFrame(V),V=null)}return{attach:Je,detach:Ke}}function ce(t){let e=document.createElement("span");return e.className="smartphoto-sr-only",e.textContent=t,e}function Le(){let t=document.createElement("button");return t.type="button",t}function at(t){return t.replace(/"/g,'\\"')}function _e({id:t,options:e},i,{signal:o}){let{classNames:n,message:s}=e,r=document.createElement("div");r.setAttribute("data-id",t);let m=document.createElement("dialog");m.className=n.smartPhoto,m.setAttribute("aria-labelledby",`smartphoto-${t}-title`),m.style.display="none",m.style.setProperty("--smartphoto-animation-speed",`${e.animationSpeed}ms`);let p=document.createElement("div");p.className=n.smartPhotoBody;let c=document.createElement("div");c.className=n.smartPhotoInner;let f=document.createElement("div");f.className=n.smartPhotoHeader;let x=document.createElement("span");x.className=n.smartPhotoCount;let b=document.createElement("h1");b.id=`smartphoto-${t}-title`,b.className=n.smartPhotoCaption,b.setAttribute("tabindex","-1");let M=document.createElement("button");M.className=n.smartPhotoDismiss,M.appendChild(ce(s.closeDialog)),M.addEventListener("click",()=>i.onDismiss(),{signal:o}),f.append(x,b,M);let C=document.createElement("div");C.className=n.smartPhotoContent,C.addEventListener("click",d=>{d.target===C&&i.onBackdropClick()},{signal:o});let N=document.createElement("ul");N.className=n.smartPhotoList,N.setAttribute("role","region"),N.setAttribute("aria-roledescription","carousel"),N.setAttribute("aria-label",s.carouselLabel),N.setAttribute("aria-live","polite"),N.setAttribute("aria-atomic","false"),c.append(f,C,N);let W=null,z=null,B=null;if(e.arrows){W=document.createElement("ul"),W.className=n.smartPhotoArrows,z=document.createElement("li"),z.className=n.smartPhotoArrowLeft;let d=Le();d.appendChild(ce(s.gotoPrevImage)),d.addEventListener("click",()=>i.onPrev(),{signal:o}),z.appendChild(d),B=document.createElement("li"),B.className=n.smartPhotoArrowRight;let l=Le();l.appendChild(ce(s.gotoNextImage)),l.addEventListener("click",()=>i.onNext(),{signal:o}),B.appendChild(l),W.append(z,B),c.appendChild(W)}let D=null,V=null;e.nav&&(D=document.createElement("nav"),D.className=n.smartPhotoNav,D.setAttribute("aria-label","Choose slide to display"),V=document.createElement("ul"),D.appendChild(V),c.appendChild(D)),p.appendChild(c),m.appendChild(p),r.appendChild(m);let u={dialog:m,count:x,caption:b,dismiss:M,content:C,list:N,arrows:W,arrowLeft:z,arrowRight:B,nav:D,navList:V,slides:new Map,imgClone:null};function R(){let d=document.createElement("div");d.className=n.smartPhotoLoaderWrap;let l=document.createElement("span");return l.className=n.smartPhotoLoader,d.appendChild(l),d}function j(d){var y,P;let l=document.createElement("div");l.className=n.smartPhotoImgWrap;let v=document.createElement("img");return v.className=n.smartPhotoImg,v.src=(y=d.src)!=null?y:"",v.alt=(P=d.alt)!=null?P:"",v.addEventListener("dragstart",E=>E.preventDefault(),{signal:o}),l.appendChild(v),{imgWrap:l,img:v}}function q(d,l){var v;u.list.replaceChildren(),(v=u.navList)==null||v.replaceChildren(),u.slides=new Map,d.forEach(y=>{var A,k;let P=document.createElement("li");P.setAttribute("role","group"),P.setAttribute("aria-roledescription","slide"),P.setAttribute("aria-label",`${y.index+1} of ${d.length}`);let E={li:P,loaderWrap:null,imgWrap:null,img:null,navLink:null};if(y.processed){let{imgWrap:X,img:F}=j(y);P.appendChild(X),E.imgWrap=X,E.img=F}else{let X=R();P.appendChild(X),E.loaderWrap=X}if(u.list.appendChild(P),u.slides.set(y,E),u.navList){let X=document.createElement("li"),F=Le();F.style.backgroundImage=`url("${at((A=y.thumb)!=null?A:"")}")`;let we=y.index;F.addEventListener("click",()=>i.onNavigate(we),{signal:o}),F.appendChild(ce(`go to ${(k=y.caption)!=null?k:""}`)),X.appendChild(F),u.navList.appendChild(X),E.navLink=F}}),ne(l)}function oe(d,l){var P;if(l.imgWrap||!d.processed)return l;let{imgWrap:v,img:y}=j(d);return(P=l.loaderWrap)==null||P.replaceWith(v),l.loaderWrap=null,l.imgWrap=v,l.img=y,l}function $(d){d&&document.activeElement&&d.contains(document.activeElement)&&u.caption.focus()}function ne(d,l){let{viewer:v}=d;u.count.textContent=`${v.currentIndex+1}/${v.total}`,u.slides.forEach((y,P)=>{var k;let E=oe(P,y),A=P.index===v.currentIndex;E.li.style.transition=l!=null&&l.immediate?"none":"",E.li.style.transform=`translate(${P.translateX}px,${P.translateY}px)`,E.li.classList.toggle("current",A),A?E.li.removeAttribute("aria-hidden"):E.li.setAttribute("aria-hidden","true"),A&&(u.caption.textContent=(k=P.caption)!=null?k:""),E.imgWrap&&E.img&&(E.imgWrap.style.transform=`translate(${P.x}px,${P.y}px) scale(${P.scale})`,E.img.style.width=`${P.width}px`,A||(E.img.style.transform="translate(0px,0px) scale(1)"),E.img.classList.toggle("active",v.appear),E.img.classList.toggle(n.smartPhotoImgOnMove,v.scale),E.img.classList.toggle(n.smartPhotoImgElasticMove,v.elastic)),E.navLink&&(E.navLink.classList.toggle("current",A),A?E.navLink.setAttribute("aria-current","true"):E.navLink.removeAttribute("aria-current"))}),u.arrowLeft&&(v.showPrevArrow?u.arrowLeft.removeAttribute("aria-hidden"):($(u.arrowLeft),u.arrowLeft.setAttribute("aria-hidden","true"))),u.arrowRight&&(v.showNextArrow?u.arrowRight.removeAttribute("aria-hidden"):($(u.arrowRight),u.arrowRight.setAttribute("aria-hidden","true"))),u.arrows&&(v.hideUi&&$(u.arrows),u.arrows.setAttribute("aria-hidden",v.hideUi?"true":"false")),u.nav&&(v.hideUi&&$(u.nav),u.nav.setAttribute("aria-hidden",v.hideUi?"true":"false"))}function de(d){for(let[l,v]of u.slides)if(l.index===d.viewer.currentIndex)return v;return null}function me(d){let{viewer:l}=d,v=de(d),y=v==null?void 0:v.img;y&&(y.style.transform=`translate(${l.photoPosX}px,${l.photoPosY}px) scale(${l.scaleSize})`,y.classList.toggle(n.smartPhotoImgOnMove,l.scale),y.classList.toggle(n.smartPhotoImgElasticMove,l.elastic)),u.nav&&(l.hideUi&&$(u.nav),u.nav.setAttribute("aria-hidden",l.hideUi?"true":"false")),u.arrows&&(l.hideUi&&$(u.arrows),u.arrows.setAttribute("aria-hidden",l.hideUi?"true":"false"))}function re(d){let{viewer:l}=d;u.list.style.transform=`translate(${l.translateX}px,${l.translateY}px)`,u.list.classList.toggle(n.smartPhotoListOnMove,l.onMove)}function pe(d){for(let[l,v]of u.slides){if(l.index!==d.viewer.currentIndex)continue;let{img:y,imgWrap:P}=v;if(!y||!P||!l.width||!l.scale||l.scale>=1)return;let E=y.getBoundingClientRect();y.style.width=`${l.width*l.scale}px`,P.style.transform=`translate(${l.x}px,${l.y}px) scale(1)`;let A=y.getBoundingClientRect();P.style.transform=`translate(${l.x+E.left-A.left}px,${l.y+E.top-A.top}px) scale(1)`;return}}function Q(){for(let[d,l]of u.slides){let{img:v,imgWrap:y}=l;v&&y&&(y.style.transform=`translate(${d.x}px,${d.y}px) scale(${d.scale})`,v.style.width=`${d.width}px`)}}function fe(d){let l=document.createElement("img");l.className=n.smartPhotoImgClone,l.src=d.img,l.style.width=`${d.width}px`,l.style.height=`${d.height}px`,l.style.transform=`translate(${d.left}px,${d.top}px) scale(1)`,p.appendChild(l),u.imgClone=l}function se(){var d;(d=u.imgClone)==null||d.remove(),u.imgClone=null}function ve(){r.remove()}return{root:r,refs:u,render:ne,syncSlides:q,updatePhotoTransform:me,applyViewTransitionLayout:pe,resetViewTransitionLayout:Q,updateListTransform:re,showAppearEffect:fe,removeAppearEffect:se,destroy:ve}}var T=le,O=he;function lt(t){return t.length>0&&t[0]instanceof Element}function ht(){return(Date.now().toString(36)+Math.random().toString(36).substring(2,7)).toUpperCase()}function je(){return{x:window.pageXOffset!==void 0?window.pageXOffset:document.documentElement.scrollLeft,y:window.pageYOffset!==void 0?window.pageYOffset:document.documentElement.scrollTop}}var ie=class{constructor(e,i){this.id=ht();this.abortController=new AbortController;this.isSmartPhoneFlag=ae();this.lastTriggerElement=null;this.isFiringPublicCloseEvent=!1;this.finishHideEffect=null;this.isViewTransitionActive=!1;this.pendingViewTransitionResync=!1;this.timeouts=[];this.loadAllFired=new Set;this.syncedGroupId=null;this.rootSelector=null;this.itemsByElement=new Map;this.handleDocumentClick=e=>{if(!(e.target instanceof Element))return;let i=e;if(i.__smartphotoClaimed)return;let o=this.findRegisteredAncestor(e.target);if(!o&&this.rootSelector&&(o=e.target.closest(this.rootSelector)),!o)return;if(e.preventDefault(),i.__smartphotoClaimed=!0,!this.itemsByElement.has(o)&&this.rootSelector){let s=ee(o);this.resyncGroupFromDom(s)&&this.syncCurrentGroupView()}let n=this.itemsByElement.get(o);n&&this.openPhoto(n,o)};this.updateViewportHeight=()=>{this.view.refs.dialog.style.setProperty("--smartphoto-vh",`${O()}px`)};this.handleVisualViewportResize=()=>{if(this.updateViewportHeight(),!(!this.isSmartPhoneFlag||!this.state.viewer.isOpen||!I(this.state))){if(this.isViewTransitionActive){this.pendingViewTransitionResync=!0;return}this.resetTranslateCurrent(),this.setPosByCurrentIndex(),this.setSizeByScreen(),this.commit(!0)}};this.handleResize=()=>{if(!(!this.state.viewer.isOpen||!I(this.state))){if(this.updateViewportHeight(),this.isViewTransitionActive){this.pendingViewTransitionResync=!0;return}this.resetTranslateCurrent(),this.setPosByCurrentIndex(),this.setSizeByScreen(),this.commit(!0)}};this.handleKeydown=e=>{if(!this.state.viewer.isOpen)return;let i=e.keyCode||e.which;i===37?this.gotoSlide(this.state.viewer.prev):i===39?this.gotoSlide(this.state.viewer.next):i===27&&this.hidePhoto()};this.handleOrientationChange=()=>{if(!this.state.viewer.isOpen||!I(this.state))return;if(this.isViewTransitionActive){this.pendingViewTransitionResync=!0;return}this.updateViewportHeight(),this.resetTranslateCurrent(),this.setPosByCurrentIndex(),this.setHashByCurrentIndex(),this.setSizeByScreen(),this.commit(!0);let e=T(),i=O(),o=500,n=s=>{this.scheduleTimeout(()=>{this.state.viewer.isOpen&&(e!==T()||i!==O()?(this.updateViewportHeight(),this.resetTranslateCurrent(),this.setPosByCurrentIndex(),this.setHashByCurrentIndex(),this.setSizeByScreen(),this.commit(!0)):s<=o&&n(s+25))},25)};n(0)};this.rootSelector=typeof e=="string"?e:null,this.state=Xe(i!=null?i:{}),this.view=_e({id:this.id,options:this.state.options},this.buildViewHandlers(),{signal:this.abortController.signal}),document.body.appendChild(this.view.root),this.gestures=Ue({state:this.state,callbacks:this.buildGestureCallbacks()},{signal:this.abortController.signal}),this.gestures.attach(this.view.refs.content,this.view.refs.list),this.view.refs.dialog.addEventListener("close",()=>{!this.isFiringPublicCloseEvent&&this.state.viewer.isOpen&&this.hidePhoto()},{signal:this.abortController.signal}),document.addEventListener("click",this.handleDocumentClick,{signal:this.abortController.signal}),this.ingestSource(e),this.syncCurrentGroupView();let o=this.restoreFromHash();if(o&&this.openPhoto(o,o.element),this.updateViewportHeight(),this.applyAutoIconContrast(),window.visualViewport?window.visualViewport.addEventListener("resize",this.handleVisualViewportResize,{signal:this.abortController.signal}):window.addEventListener("resize",this.updateViewportHeight,{signal:this.abortController.signal}),!this.isSmartPhoneFlag){window.addEventListener("resize",this.handleResize,{signal:this.abortController.signal}),window.addEventListener("keydown",this.handleKeydown,{signal:this.abortController.signal});return}window.addEventListener("orientationchange",this.handleOrientationChange,{signal:this.abortController.signal})}on(e,i){let o=this.view.refs.dialog,n=s=>i.call(o,s);o.addEventListener(e,n,{signal:this.abortController.signal})}destroy(){this.state.viewer.isOpen=!1,this.view.refs.dialog.open&&this.view.refs.dialog.close(),this.abortController.abort(),this.timeouts.forEach(e=>{clearTimeout(e)}),this.timeouts=[],this.itemsByElement.clear(),this.gestures.detach(),this.view.destroy()}[Symbol.dispose](){this.destroy()}gotoSlide(e){var s,r;let i=Number.parseInt(String(e),10),o=Number.isNaN(i)?0:i,n=(r=(s=I(this.state))==null?void 0:s.length)!=null?r:0;o<0||o>=n||(this.state.viewer.currentIndex=o,this.slideList())}hidePhoto(e="bottom"){var o;if(!this.state.viewer.isOpen)return;this.state.viewer.isOpen=!1,this.state.viewer.appear=!1,this.state.viewer.appearEffect=null,this.view.removeAppearEffect(),this.state.viewer.hideUi=!1,this.state.viewer.scale=!1,this.state.viewer.scaleSize=1;let i=je();location.hash&&this.setHash(""),window.scroll(i.x,i.y),this.syncDialog(),(o=this.lastTriggerElement)!=null&&o.isConnected&&this.lastTriggerElement.focus(),this.lastTriggerElement=null,this.doHideEffect(e).then(()=>{this.view.render(this.state),this.isFiringPublicCloseEvent=!0,this.fireEvent("close"),this.isFiringPublicCloseEvent=!1})}zoomPhoto(){let e=L(this.state);e&&(this.state.viewer.hideUi=!0,this.state.viewer.scaleSize=_(e,T(),O(),this.isSmartPhoneFlag),!(this.state.viewer.scaleSize<=1)&&(this.state.viewer.photoPosX=0,this.state.viewer.photoPosY=0,this.view.updatePhotoTransform(this.state),this.scheduleTimeout(()=>{this.state.viewer.isOpen&&(this.state.viewer.scale=!0,this.view.updatePhotoTransform(this.state),this.fireEvent("zoomin"))},this.state.options.animationSpeed)))}canZoomCurrentPhoto(){let e=L(this.state);return!!e&&_(e,T(),O(),this.isSmartPhoneFlag)>1}zoomOutPhoto(){let e=L(this.state),i=this.state.options.resizeStyle==="fill"&&this.isSmartPhoneFlag&&e?_(e,T(),O(),!0):1;this.state.viewer.scaleSize=i,this.state.viewer.hideUi=i>1,this.state.viewer.scale=i>1,this.state.viewer.photoPosX=0,this.state.viewer.photoPosY=0,this.view.updatePhotoTransform(this.state),this.fireEvent("zoomout")}addNewItem(e){return this.addItem(e)}show(e=0,i={}){var p,c,f;let o=(p=i.group)!=null?p:this.state.viewer.currentGroup;if(o===null)return;let n=this.state.groups.get(o);if(!(n!=null&&n.length))return;let s=typeof e=="number"?n[e]:n.find(x=>x.id===e);if(!s)return;let r=document.activeElement instanceof HTMLElement?document.activeElement:null,m=(f=(c=i.trigger)!=null?c:s.element)!=null?f:r;this.openPhoto(s,m)}hide(){this.hidePhoto()}next(){this.state.viewer.showNextArrow&&this.gotoSlide(this.state.viewer.next)}prev(){this.state.viewer.showPrevArrow&&this.gotoSlide(this.state.viewer.prev)}addItem(e){let i=e instanceof HTMLElement?this.addElementItem(e):this.addSlideItem(e);return this.syncCurrentGroupView(),i}get currentIndex(){return this.state.viewer.currentIndex}ingestSource(e){if(Array.isArray(e)&&!lt(e)){e.forEach(o=>{this.addSlideItem(o)});return}Array.from(typeof e=="string"?document.querySelectorAll(e):e).forEach(o=>{this.addElementItem(o)})}addElementItem(e){var s,r;let i=ee(e),o=(r=(s=this.state.groups.get(i))==null?void 0:s.length)!=null?r:0,n=Pe(e,this.state.options,o,T());return be(this.state,n),this.loadAllFired.delete(i),this.itemsByElement.set(e,n),n}addSlideItem(e){var s,r;let i=Ee(e),o=(r=(s=this.state.groups.get(i))==null?void 0:s.length)!=null?r:0,n=Ye(e,o,T());return be(this.state,n),this.loadAllFired.delete(i),n}findRegisteredAncestor(e){let i=e;for(;i;){if(this.itemsByElement.has(i))return i;i=i.parentElement}return null}resyncGroupFromDom(e){var p;if(!this.rootSelector)return!1;let i=Array.from(document.querySelectorAll(this.rootSelector)).filter(c=>ee(c)===e),o=new Set(i),n=(p=this.state.groups.get(e))!=null?p:[],s=new Map;n.forEach(c=>{c.element&&s.set(c.element,c)});let r=i.length!==n.length,m=i.map((c,f)=>{let x=s.get(c);if(x)return x.index!==f&&(r=!0,x.index=f),x;r=!0;let b=Pe(c,this.state.options,f,T());return this.itemsByElement.set(c,b),b});return n.forEach(c=>{c.element&&!o.has(c.element)&&this.itemsByElement.delete(c.element)}),xe(m,T()),this.state.groups.set(e,m),r&&this.loadAllFired.delete(e),r}syncCurrentGroupView(){let e=I(this.state);e&&(this.view.syncSlides(e,this.state),this.syncedGroupId=this.state.viewer.currentGroup)}setHash(e){var o;if(!((o=window.history)!=null&&o.pushState)||!this.state.options.useHistoryApi)return;let i=`${location.pathname}${location.search}`;window.history.replaceState(null,"",e?`${i}#${e}`:i)}setHashByCurrentIndex(){let e=je();this.setHash(We(this.state)),window.scroll(e.x,e.y)}restoreFromHash(){let e=location.hash.substring(1);return e?$e(this.state,Ne(e)):null}setPosByCurrentIndex(){let e=L(this.state);e&&(this.state.viewer.translateX=-e.translateX,this.state.viewer.translateY=0,this.view.updateListTransform(this.state))}setSizeByScreen(){let e=I(this.state);e&&(Ge(e,T(),O(),this.state.options.headerHeight,this.state.options.footerHeight),this.syncFillScale())}resetTranslateCurrent(){xe(I(this.state),T())}currentImgElement(){for(let[e,i]of this.view.refs.slides)if(e.index===this.state.viewer.currentIndex)return i.img;return null}currentLiElement(){for(let[e,i]of this.view.refs.slides)if(e.index===this.state.viewer.currentIndex)return i.li;return null}syncDialog(){let{dialog:e,caption:i}=this.view.refs;e.style.transition=this.state.options.showAnimation===!1?"none":"",this.state.viewer.isOpen&&!e.open?(e.style.removeProperty("display"),e.showModal(),i.focus()):!this.state.viewer.isOpen&&e.open&&(e.close(),e.style.display="none")}commit(e=!1){this.view.render(this.state,{immediate:e}),this.view.updatePhotoTransform(this.state),this.syncDialog()}initPhoto(){var i;(i=this.finishHideEffect)==null||i.call(this),this.updateViewportHeight(),this.view.refs.dialog.style.opacity="";let e=I(this.state);this.state.viewer.total=e.length,this.state.viewer.isOpen=!0,this.state.viewer.photoPosX=0,this.state.viewer.photoPosY=0,this.setPosByCurrentIndex(),this.setSizeByScreen(),Se(this.state)}syncFillScale(){if(this.state.options.resizeStyle!=="fill"||!this.isSmartPhoneFlag)return;let e=L(this.state);e&&(this.state.viewer.scale=!0,this.state.viewer.hideUi=!0,this.state.viewer.scaleSize=_(e,T(),O(),this.isSmartPhoneFlag))}supportsViewTransition(){return this.state.options.useViewTransitionApi&&typeof document.startViewTransition=="function"&&!Me()}openPhotoWithViewTransition(e){var r,m;document.documentElement.style.setProperty("--smartphoto-animation-speed",`${this.state.options.animationSpeed}ms`);let i="smartphoto-hero",o=(r=e==null?void 0:e.querySelector("img"))!=null?r:null;o&&(o.style.viewTransitionName=i);let n=()=>{this.isViewTransitionActive=!1,o&&(o.style.viewTransitionName="");let p=this.currentImgElement();if(p&&(p.style.viewTransitionName=""),!this.state.viewer.isOpen){this.pendingViewTransitionResync=!1;return}if(this.pendingViewTransitionResync&&I(this.state)){this.pendingViewTransitionResync=!1,this.updateViewportHeight(),this.resetTranslateCurrent(),this.setPosByCurrentIndex(),this.setSizeByScreen(),this.commit(!0);return}this.pendingViewTransitionResync=!1,this.view.resetViewTransitionLayout()},s=(m=document.startViewTransition)==null?void 0:m.call(document,()=>{this.initPhoto(),this.state.viewer.appear=!0,this.commit(),o&&(o.style.viewTransitionName=""),this.currentImgElement().style.viewTransitionName=i,this.view.applyViewTransitionLayout(this.state)});s&&(this.isViewTransitionActive=!0,s.ready.catch(()=>{n()}),s.finished.then(n,n))}addAppearEffect(e,i){var C;let o=(C=e==null?void 0:e.querySelector("img"))!=null?C:null;if(!o){this.state.viewer.appear=!0;return}let n=Be(o),s=o.offsetWidth,r=o.offsetHeight,m=T(),p=O(),c=p-this.state.options.headerHeight-this.state.options.footerHeight,f=1;this.state.options.resizeStyle==="fill"&&this.isSmartPhoneFlag?s>r?f=p/r:f=m/s:(s>=r?i.height<c?f=i.width/s:f=c/r:i.height<c?f=i.height/r:f=c/r,s*f>m&&(f=m/s));let x=(f-1)/2*s+(m-s*f)/2,b=(f-1)/2*r+(p-r*f)/2,M=o.getAttribute(this.state.options.lazyAttribute);this.state.viewer.appearEffect={width:s,height:r,top:n.top,left:n.left,once:!0,img:M||i.src||"",afterX:x,afterY:b,scale:f}}runAppearEffect(e){this.view.showAppearEffect(e);let i=this.view.refs.imgClone;return new Promise(o=>{let n=()=>{i.removeEventListener("transitionend",n,!0),o()};i.addEventListener("transitionend",n,!0),this.scheduleTimeout(()=>{i.style.transform=`translate(${e.afterX}px, ${e.afterY}px) scale(${e.scale})`},10)})}doOpen(e,i){if(this.state.options.showAnimation!==!1&&this.supportsViewTransition())this.openPhotoWithViewTransition(e);else if(this.state.options.showAnimation===!1)this.initPhoto(),this.state.viewer.appear=!0,this.commit();else{this.initPhoto(),this.addAppearEffect(e,i),this.commit();let o=this.state.viewer.appearEffect;o&&this.runAppearEffect(o).then(()=>{this.state.viewer.appearEffect=null,this.view.removeAppearEffect(),this.state.viewer.appear=!0,this.commit()})}this.fireEvent("open"),this.resyncSizeAfterOpen()}resyncSizeAfterOpen(){let e=T(),i=O();requestAnimationFrame(()=>{if(this.state.viewer.isOpen&&!(T()===e&&O()===i)){if(this.isViewTransitionActive){this.pendingViewTransitionResync=!0;return}this.resetTranslateCurrent(),this.setPosByCurrentIndex(),this.setSizeByScreen(),this.commit(!0)}})}openPhoto(e,i){let o=this.resyncGroupFromDom(e.groupId);this.lastTriggerElement=i,this.state.viewer.currentGroup=e.groupId,this.state.viewer.currentIndex=e.index,(this.syncedGroupId!==e.groupId||o)&&this.syncCurrentGroupView(),this.setHashByCurrentIndex(),e.loaded?this.doOpen(i,e):this.loadItem(e).then(()=>{this.doOpen(i,e)})}doHideEffect(e){return new Promise(i=>{if(this.state.options.showAnimation===!1){i();return}let o=this.view.refs.dialog,n=L(this.state),s=n?this.currentLiElement():null,r=O(),m=this.currentImgElement(),p=null;if(m){let f=getComputedStyle(m).transform;f&&f!=="none"&&(m.style.transform=f,p=m.style.transform)}if(s&&n){let f=e==="top"?-r:r;s.style.transform=`translate(${n.translateX}px,${n.translateY+f}px)`}let c=f=>{this.finishHideEffect===c&&(f&&f.target!==o||(this.finishHideEffect=null,o.removeEventListener("transitionend",c,!0),m&&p&&m.style.transform===p&&(m.style.transform=""),i()))};this.finishHideEffect=c,o.addEventListener("transitionend",c,!0),this.scheduleTimeout(c,this.state.options.animationSpeed+100)})}loadItem(e){return new Promise(i=>{var n;let o=new Image;o.onload=()=>{e.width=o.width,e.height=o.height,e.loaded=!0,this.checkLoadAll(e.groupId),i()},o.onerror=()=>i(),o.src=(n=e.src)!=null?n:""})}checkLoadAll(e){if(this.loadAllFired.has(e))return;let i=this.state.groups.get(e);i!=null&&i.length&&i.every(o=>o.loaded)&&(this.loadAllFired.add(e),this.fireEvent("loadall"))}loadNeighborItems(){let e=I(this.state);if(!e)return;let{currentIndex:i}=this.state.viewer,{loadOffset:o}=this.state.options,n=[];for(let s=i-o;s<i+o;s++){let r=e[s];r&&!r.loaded&&n.push(this.loadItem(r))}n.length&&Promise.all(n).then(()=>{this.state.viewer.isOpen&&(this.initPhoto(),this.commit())})}slideList(){this.state.viewer.scaleSize=1,this.state.viewer.hideUi=!1,this.state.viewer.scale=!1,this.state.viewer.photoPosX=0,this.state.viewer.photoPosY=0,this.state.viewer.onMove=!0,this.updateViewportHeight(),this.setPosByCurrentIndex(),this.setHashByCurrentIndex(),this.setSizeByScreen(),this.scheduleTimeout(()=>{let e=L(this.state);this.state.viewer.onMove=!1,Se(this.state),this.state.viewer.isOpen&&this.commit(),this.state.viewer.oldIndex!==this.state.viewer.currentIndex&&this.fireEvent("change"),this.state.viewer.oldIndex=this.state.viewer.currentIndex,this.loadNeighborItems(),e&&!e.loaded&&this.loadItem(e).then(()=>{this.state.viewer.isOpen&&(this.initPhoto(),this.commit())})},200)}scheduleTimeout(e,i){let o=window.setTimeout(()=>{this.timeouts=this.timeouts.filter(n=>n!==o),e()},i);return this.timeouts.push(o),o}applyAutoIconContrast(){let e=this.view.refs.dialog,i=getComputedStyle(e);if(i.getPropertyValue("--smartphoto-icon-color").trim())return;let o=i.getPropertyValue("--smartphoto-backdrop-color").trim();o&&e.style.setProperty("--smartphoto-icon-color",De(o))}fireEvent(e){Oe(this.view.refs.dialog,e)}buildViewHandlers(){return{onDismiss:()=>this.hidePhoto(),onPrev:()=>this.prev(),onNext:()=>this.next(),onNavigate:e=>this.gotoSlide(e),onBackdropClick:()=>this.hidePhoto()}}buildGestureCallbacks(){return{onSwipeStart:()=>this.fireEvent("swipestart"),onSwipeMove:()=>this.view.updateListTransform(this.state),onSwipeEnd:e=>{if(this.fireEvent("swipeend"),e==="close-bottom"){this.hidePhoto("bottom");return}if(e==="close-top"){this.hidePhoto("top");return}e==="prev"?this.state.viewer.currentIndex-=1:e==="next"&&(this.state.viewer.currentIndex+=1),this.slideList()},onTap:e=>{let i=this.currentImgElement();!!i&&e instanceof Node&&i.contains(e)&&this.canZoomCurrentPhoto()?this.zoomPhoto():this.hidePhoto()},onGestureStart:()=>{this.fireEvent("gesturestart"),this.view.updatePhotoTransform(this.state)},onGestureMove:()=>this.view.updatePhotoTransform(this.state),onGestureEnd:()=>{this.fireEvent("gestureend"),this.view.updatePhotoTransform(this.state)},onPinchClose:()=>this.hidePhoto(),onPhotoDragMove:()=>this.view.updatePhotoTransform(this.state),onPhotoDragEnd:e=>{if(e==="zoom-out"){this.zoomOutPhoto();return}if(e==="prev"){this.gotoSlide(this.state.viewer.prev);return}if(e==="next"){this.gotoSlide(this.state.viewer.next);return}this.view.updatePhotoTransform(this.state)}}}};var qe=ie;var Te=t=>{t.fn.SmartPhoto=function(e){return typeof e=="string"||new qe(this,e),this}};if(typeof define=="function"&&define.amd)define(["jquery"],Te);else{let t=window,e=t.jQuery?t.jQuery:t.$;typeof e!="undefined"&&Te(e)}var Pt=Te;})();