@yui540/comimi 0.3.6 → 0.3.7

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.
@@ -10,6 +10,8 @@ export declare class MangaViewerCore implements MangaViewerInstance {
10
10
  private unsubscribers;
11
11
  private notificationTimers;
12
12
  private autoTimer?;
13
+ private bootstrapOverlayTimer?;
14
+ private destroyed;
13
15
  private mobileMediaQuery?;
14
16
  private lockLayoutMode;
15
17
  private bodyOverflowBackup;
@@ -1 +1 @@
1
- {"version":3,"file":"manga-viewer-core.d.ts","sourceRoot":"","sources":["../../src/core/manga-viewer-core.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAEV,KAAK,EACL,SAAS,EACT,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAElB,eAAe,EACf,cAAc,EACd,WAAW,EACZ,MAAM,UAAU,CAAC;AAIlB,qBAAa,eAAgB,YAAW,mBAAmB;IAgBvD,OAAO,CAAC,SAAS;IAfnB,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,OAAO,CAAmB;IAClC,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,QAAQ,CAAiB;IACjC,OAAO,CAAC,IAAI,CAAO;IACnB,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,aAAa,CAAyB;IAC9C,OAAO,CAAC,kBAAkB,CAA6B;IACvD,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,gBAAgB,CAAC,CAAiB;IAC1C,OAAO,CAAC,cAAc,CAAS;IAE/B,OAAO,CAAC,kBAAkB,CAAuB;gBAGvC,SAAS,EAAE,WAAW,EAC9B,OAAO,EAAE,kBAAkB;IA8E7B,OAAO,IAAI,IAAI;IAcT,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAKrC,QAAQ,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;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AAO,CAAC,kBAAkB;IAY1B,OAAO,CAAC,WAAW;YAUL,aAAa;IA+B3B,OAAO,CAAC,aAAa;IAKrB,OAAO,CAAC,gBAAgB;IAYxB,OAAO,CAAC,kBAAkB;IAc1B,OAAO,CAAC,aAAa;IAmBrB,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,sBAAsB;IAa9B,OAAO,CAAC,MAAM;CA0Bf"}
package/dist/index.js CHANGED
@@ -1344,6 +1344,7 @@ var Me = 180, Ne = 2e3, Pe = class {
1344
1344
  autoplayOverlayProgress;
1345
1345
  autoplayOverlayProgressBar;
1346
1346
  notifications;
1347
+ destroyed = !1;
1347
1348
  constructor(e, t, n, r, i, a, o = !1, s) {
1348
1349
  this.container = e, this.callbacks = t, this.assetLoader = n, this.i18n = r, this.lockLayoutMode = o, this.mascot = s, je(), this.pageStage = new V({
1349
1350
  assetLoader: this.assetLoader,
@@ -1359,7 +1360,7 @@ var Me = 180, Ne = 2e3, Pe = class {
1359
1360
  e(), typeof ResizeObserver < "u" ? (this.viewSizeObserver = new ResizeObserver(e), this.viewSizeObserver.observe(this.root)) : (window.addEventListener("resize", e), this.cleanup.push(() => window.removeEventListener("resize", e)));
1360
1361
  }
1361
1362
  update(e) {
1362
- if (this.isPageTurnAnimating) return;
1363
+ if (this.destroyed || this.isPageTurnAnimating) return;
1363
1364
  this.cleanup.forEach((e) => e()), this.cleanup = [], this.i18n.setLocale(e.settings.locale), this.root.dataset.layout = e.layout.mode, this.root.dataset.bg = e.settings.backgroundColor, e.layout.mode === "wide" && e.layout.wideHeightPx ? this.root.style.height = `${e.layout.wideHeightPx}px` : this.root.style.height = "";
1364
1365
  let t = this.prevOverlayVisible !== e.overlayVisible, n = t ? {
1365
1366
  ...e,
@@ -1394,12 +1395,12 @@ var Me = 180, Ne = 2e3, Pe = class {
1394
1395
  });
1395
1396
  }
1396
1397
  showSplash() {
1397
- this.splash || (this.splash = G(this.i18n, this.mascot), this.root.append(this.splash), this.splashRemoveTimer = window.setTimeout(() => {
1398
+ this.destroyed || this.splash || (this.splash = G(this.i18n, this.mascot), this.root.append(this.splash), this.splashRemoveTimer = window.setTimeout(() => {
1398
1399
  this.splash?.remove(), this.splash = void 0;
1399
1400
  }, Ne));
1400
1401
  }
1401
1402
  destroy() {
1402
- window.clearTimeout(this.pageTurnTimer), window.clearTimeout(this.splashRemoveTimer), this.overlayApplyRaf !== void 0 && (cancelAnimationFrame(this.overlayApplyRaf), this.overlayApplyRaf = void 0), this.cleanup.forEach((e) => e()), this.cleanup = [], this.viewSizeObserver?.disconnect(), this.viewSizeObserver = void 0, this.resizeHandle?.remove(), this.resizeHandle = void 0, this.root.remove();
1403
+ this.destroyed = !0, window.clearTimeout(this.pageTurnTimer), window.clearTimeout(this.splashRemoveTimer), this.overlayApplyRaf !== void 0 && (cancelAnimationFrame(this.overlayApplyRaf), this.overlayApplyRaf = void 0), this.cleanup.forEach((e) => e()), this.cleanup = [], this.viewSizeObserver?.disconnect(), this.viewSizeObserver = void 0, this.resizeHandle?.remove(), this.resizeHandle = void 0, this.root.remove();
1403
1404
  }
1404
1405
  getElement() {
1405
1406
  return this.root;
@@ -1853,6 +1854,8 @@ var Ie = class {
1853
1854
  unsubscribers = [];
1854
1855
  notificationTimers = /* @__PURE__ */ new Map();
1855
1856
  autoTimer;
1857
+ bootstrapOverlayTimer;
1858
+ destroyed = !1;
1856
1859
  mobileMediaQuery;
1857
1860
  lockLayoutMode = !1;
1858
1861
  bodyOverflowBackup = null;
@@ -1908,7 +1911,7 @@ var Ie = class {
1908
1911
  })), this.bindKeyboard(), this.bindViewportChange(), this.bootstrap();
1909
1912
  }
1910
1913
  destroy() {
1911
- window.clearInterval(this.autoTimer);
1914
+ this.destroyed = !0, window.clearInterval(this.autoTimer), window.clearTimeout(this.bootstrapOverlayTimer);
1912
1915
  for (let e of this.notificationTimers.values()) window.clearTimeout(e);
1913
1916
  this.notificationTimers.clear(), this.syncBodyScrollLock("inline"), this.unsubscribers.forEach((e) => e()), this.assetLoader.revokeAll(), this.renderer.destroy(), this.events.emit("destroy", void 0), this.events.clear();
1914
1917
  }
@@ -2001,6 +2004,7 @@ var Ie = class {
2001
2004
  }
2002
2005
  async bootstrap() {
2003
2006
  let e = await this.storage.getSettings(), t = await this.storage.getLayout(), n = this.store.getState().manga.id, r = await this.storage.getProgress(n);
2007
+ if (this.destroyed) return;
2004
2008
  if (e) {
2005
2009
  let t = { ...e };
2006
2010
  this.lockLayoutMode && delete t.layoutMode, this.store.dispatch({
@@ -2022,8 +2026,8 @@ var Ie = class {
2022
2026
  }), typeof r == "number" && this.store.dispatch({
2023
2027
  type: "goToPage",
2024
2028
  pageIndex: r
2025
- }), this.renderer.update(this.store.getState()), this.renderer.showSplash(), window.setTimeout(() => {
2026
- this.toggleOverlay(!0);
2029
+ }), this.renderer.update(this.store.getState()), this.renderer.showSplash(), this.bootstrapOverlayTimer = window.setTimeout(() => {
2030
+ this.destroyed || this.toggleOverlay(!0);
2027
2031
  }, 1550), this.events.emit("ready", { manga: this.store.getState().manga });
2028
2032
  }
2029
2033
  bindKeyboard() {
@@ -2580,4 +2580,4 @@ var MangaViewer=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`
2580
2580
  }
2581
2581
  }
2582
2582
  `,J=!1,Ae=[Oe,_e,De,Se,ye,q,me,he,ke,ge,ve,Te,be,xe,Ce,Ee,we].join(`
2583
- `);function je(){if(J||typeof document>`u`)return;let e=document.createElement(`style`);e.dataset.comimiViewer=`true`,e.textContent=Ae,document.head.append(e),J=!0}var Me=180,Ne=2e3,Pe=class{container;callbacks;assetLoader;i18n;lockLayoutMode;mascot;root;cleanup=[];mouseStart;touchStart;pinchStart;pageStage;pageTurnTimer;splashRemoveTimer;splash;isPageTurnAnimating=!1;suppressNextClick=!1;prevOverlayVisible=!1;overlayApplyRaf;menuPanel;viewModeSwitcher;controlsDock;resizeHandle;viewSizeObserver;autoplayOverlayProgress;autoplayOverlayProgressBar;notifications;constructor(e,t,n,r,i,a,o=!1,s){this.container=e,this.callbacks=t,this.assetLoader=n,this.i18n=r,this.lockLayoutMode=o,this.mascot=s,je(),this.pageStage=new H({assetLoader:this.assetLoader,i18n:this.i18n,isMobileViewport:()=>this.isMobileViewport(),resolvePageSrc:a}),this.root=pe({className:i}),this.container.replaceChildren(this.root),this.observeViewSize()}observeViewSize(){let e=()=>{this.root.style.setProperty(`--view-width`,`${this.root.offsetWidth}px`),this.root.style.setProperty(`--view-height`,`${this.root.offsetHeight}px`)};e(),typeof ResizeObserver<`u`?(this.viewSizeObserver=new ResizeObserver(e),this.viewSizeObserver.observe(this.root)):(window.addEventListener(`resize`,e),this.cleanup.push(()=>window.removeEventListener(`resize`,e)))}update(e){if(this.isPageTurnAnimating)return;this.cleanup.forEach(e=>e()),this.cleanup=[],this.i18n.setLocale(e.settings.locale),this.root.dataset.layout=e.layout.mode,this.root.dataset.bg=e.settings.backgroundColor,e.layout.mode===`wide`&&e.layout.wideHeightPx?this.root.style.height=`${e.layout.wideHeightPx}px`:this.root.style.height=``;let t=this.prevOverlayVisible!==e.overlayVisible,n=t?{...e,overlayVisible:this.prevOverlayVisible}:e;this.menuPanel||=new F(this.callbacks,this.i18n,{lockLayoutMode:this.lockLayoutMode,mascot:this.mascot}),!this.viewModeSwitcher&&!this.lockLayoutMode&&(this.viewModeSwitcher=new I(this.callbacks,this.i18n)),this.controlsDock||=new P(this.callbacks,this.i18n,this.mascot),this.notifications||=new W;let r=this.pageStage.getElement(),i=this.menuPanel.getElement(),a=this.viewModeSwitcher?.getElement(),o=this.controlsDock.getElement(),s=this.notifications.getElement();Array.from(this.root.children).forEach(e=>{e!==r&&e!==i&&e!==a&&e!==o&&e!==this.splash&&e!==this.autoplayOverlayProgress&&e!==s&&e.remove()}),r.parentNode!==this.root&&this.root.prepend(r),this.pageStage.update(e,this.isMobileViewport()),this.pageStage.snapTransform();let c=[ae(n,this.i18n),_({state:n,callbacks:this.callbacks})];this.syncResizeHandle(e.layout.mode===`wide`);let l=i.parentNode===this.root?i:null;if(l?c.forEach(e=>this.root.insertBefore(e,l)):(c.forEach(e=>this.root.appendChild(e)),this.root.appendChild(i)),a&&a.parentNode!==this.root&&this.root.appendChild(a),o.parentNode!==this.root&&this.root.appendChild(o),s.parentNode!==this.root&&this.root.appendChild(s),this.menuPanel.update(n),this.viewModeSwitcher?.update(n),this.controlsDock.update(n,this.isMobileViewport()),this.notifications.update(e),this.syncAutoplayOverlayProgress(e),this.splash&&this.splash.parentNode!==this.root&&this.root.append(this.splash),this.bindGestures(e),this.overlayApplyRaf!==void 0&&(cancelAnimationFrame(this.overlayApplyRaf),this.overlayApplyRaf=void 0),t){let t=e.overlayVisible;this.root.offsetWidth,this.overlayApplyRaf=requestAnimationFrame(()=>{this.overlayApplyRaf=void 0,this.applyOverlayVisibility(t)})}this.prevOverlayVisible=e.overlayVisible}applyOverlayVisibility(e){let t=String(e);this.root.querySelectorAll(`.comimi-arrows, .comimi-center-message, .comimi-menu-panel, .comimi-view-switcher, .comimi-controls-dock, .comimi-stage`).forEach(e=>{e.dataset.overlay=t})}showSplash(){this.splash||(this.splash=le(this.i18n,this.mascot),this.root.append(this.splash),this.splashRemoveTimer=window.setTimeout(()=>{this.splash?.remove(),this.splash=void 0},Ne))}destroy(){window.clearTimeout(this.pageTurnTimer),window.clearTimeout(this.splashRemoveTimer),this.overlayApplyRaf!==void 0&&(cancelAnimationFrame(this.overlayApplyRaf),this.overlayApplyRaf=void 0),this.cleanup.forEach(e=>e()),this.cleanup=[],this.viewSizeObserver?.disconnect(),this.viewSizeObserver=void 0,this.resizeHandle?.remove(),this.resizeHandle=void 0,this.root.remove()}getElement(){return this.root}isAnimatingPageTurn(){return this.isPageTurnAnimating}animatePageTurn(e,t,n){return window.clearTimeout(this.pageTurnTimer),this.isPageTurnAnimating||S(e,t,this.isMobileViewport()).length===0?!1:(this.isPageTurnAnimating=!0,this.setStageDragOffset(this.getPageTurnTargetOffset(e,t),!0),this.pageTurnTimer=window.setTimeout(()=>{this.isPageTurnAnimating=!1,n()},Me),!0)}isMobileViewport(){return window.matchMedia(`(max-width: 767px)`).matches}syncAutoplayOverlayProgress(e){if(!e.autoPageTurnEnabled){this.autoplayOverlayProgress&&(this.autoplayOverlayProgress.remove(),this.autoplayOverlayProgress=void 0,this.autoplayOverlayProgressBar=void 0);return}this.autoplayOverlayProgress||(this.autoplayOverlayProgress=document.createElement(`div`),this.autoplayOverlayProgress.className=`comimi-autoplay-overlay-progress`,this.autoplayOverlayProgressBar=document.createElement(`span`),this.autoplayOverlayProgressBar.className=`comimi-autoplay-overlay-progress-bar`,this.autoplayOverlayProgress.append(this.autoplayOverlayProgressBar)),this.autoplayOverlayProgress.parentNode!==this.root&&this.root.appendChild(this.autoplayOverlayProgress),this.autoplayOverlayProgress.dataset.visible=String(!e.overlayVisible),this.autoplayOverlayProgressBar.style.animationDuration=`${e.settings.autoPageTurnIntervalMs}ms`}clampPan(e,t,n,r){if(n<=1)return{x:0,y:0};let i=x(r,this.isMobileViewport()).length>1?this.root.offsetWidth/2:this.root.offsetWidth,a=this.root.offsetHeight,o=i*(n-1)/2,s=a*(n-1)/2;return{x:Math.min(Math.max(e,-o),o),y:Math.min(Math.max(t,-s),s)}}clampedZoom(e,t){return Math.min(Math.max(e,t.settings.zoom.min),t.settings.zoom.max)}syncResizeHandle(e){e?(this.resizeHandle||=this.createResizeHandle(),this.resizeHandle.parentNode!==this.container&&this.container.appendChild(this.resizeHandle)):this.resizeHandle&&this.resizeHandle.remove()}createResizeHandle(){let e=document.createElement(`div`);e.className=`comimi-resize-handle`,e.setAttribute(`role`,`separator`),e.setAttribute(`aria-orientation`,`horizontal`);let t=0,n=0,r,i=e=>{e.pointerId===r&&this.callbacks.setWideHeight(n+e.clientY-t)},a=e=>{e.pointerId===r&&(window.removeEventListener(`pointermove`,i),window.removeEventListener(`pointerup`,a),window.removeEventListener(`pointercancel`,a),r=void 0)};return e.addEventListener(`pointerdown`,e=>{e.preventDefault(),r=e.pointerId,t=e.clientY,n=this.root.getBoundingClientRect().height,window.addEventListener(`pointermove`,i),window.addEventListener(`pointerup`,a),window.addEventListener(`pointercancel`,a)}),e}bindGestures(e){let t=t=>{if(this.suppressNextClick||this.isPageTurnAnimating){this.suppressNextClick=!1,t.preventDefault(),t.stopPropagation();return}if(!this.isInteractiveTarget(t.target)){if(!e.overlayVisible){let n=this.root.getBoundingClientRect(),r=(t.clientX-n.left)/n.width;if(r<.3||r>=.7){let t=r<.3?`left`:`right`;(e.settings.readingDirection===`rtl`?t===`left`:t===`right`)?this.callbacks.nextPage():this.callbacks.previousPage();return}}this.callbacks.toggleOverlay()}},n=t=>{if(this.isInteractiveTarget(t.target)||!t.ctrlKey&&!t.metaKey)return;t.preventDefault();let n=t.deltaY>0?-e.settings.zoom.step:e.settings.zoom.step,r=this.clampedZoom(e.zoomScale+n,e),i=this.clampPan(e.panX,e.panY,r,e);this.callbacks.setZoom(r,i.x,i.y)},r=t=>{this.isPageTurnAnimating||this.isSwipeBlockingTarget(t.target)||t.button===0&&(this.mouseStart={x:t.clientX,y:t.clientY,panX:e.panX,panY:e.panY})},i=t=>{if(!this.mouseStart)return;t.preventDefault();let n=t.clientX-this.mouseStart.x,r=t.clientY-this.mouseStart.y;if((Math.abs(n)>6||Math.abs(r)>6)&&(this.suppressNextClick=!0),e.zoomScale<=1){this.setStageDragOffset(this.constrainDragOffset(n,r,e));return}let i=this.mouseStart.panX+t.clientX-this.mouseStart.x,a=this.mouseStart.panY+t.clientY-this.mouseStart.y,o=this.clampPan(i,a,e.zoomScale,e);this.callbacks.setPan(o.x,o.y)},a=t=>{if(!this.mouseStart)return;let n=t.clientX-this.mouseStart.x,r=t.clientY-this.mouseStart.y;this.handleSwipeEnd(n,r,e),this.mouseStart=void 0},o=t=>{if(this.isPageTurnAnimating)return;if(t.touches.length===2){t.preventDefault(),this.touchStart=void 0,this.pinchStart={distance:Y(t),scale:e.zoomScale};return}if(this.isSwipeBlockingTarget(t.target))return;let n=t.touches[0];n&&(this.touchStart={x:n.clientX,y:n.clientY,panX:e.panX,panY:e.panY})},s=t=>{if(this.pinchStart&&t.touches.length===2){t.preventDefault();let n=this.pinchStart.scale*(Y(t)/this.pinchStart.distance),r=this.clampedZoom(n,e),i=this.clampPan(e.panX,e.panY,r,e);this.callbacks.setZoom(r,i.x,i.y);return}if(this.isSwipeBlockingTarget(t.target))return;let n=t.touches[0];if(!n||!this.touchStart)return;t.preventDefault();let r=n.clientX-this.touchStart.x,i=n.clientY-this.touchStart.y;if((Math.abs(r)>6||Math.abs(i)>6)&&(this.suppressNextClick=!0),e.zoomScale<=1){this.setStageDragOffset(this.constrainDragOffset(r,i,e));return}let a=this.touchStart.panX+n.clientX-this.touchStart.x,o=this.touchStart.panY+n.clientY-this.touchStart.y,s=this.clampPan(a,o,e.zoomScale,e);this.callbacks.setPan(s.x,s.y)},c=t=>{t.touches.length<2&&(this.pinchStart=void 0);let n=t.changedTouches[0];if(!n||!this.touchStart){this.touchStart=void 0;return}let r=n.clientX-this.touchStart.x,i=n.clientY-this.touchStart.y;this.handleSwipeEnd(r,i,e),this.touchStart=void 0},l=t=>{if(this.suppressNextClick||this.isPageTurnAnimating||e.panel!==`settings`)return;let n=t.target;n instanceof Element&&(n.closest(`.comimi-settings`)||this.callbacks.setPanel(`none`))},u=e=>{this.isSwipeBlockingTarget(e.target)||e.preventDefault()};this.root.addEventListener(`click`,l,!0),this.root.addEventListener(`click`,t),this.root.addEventListener(`wheel`,n,{passive:!1}),this.root.addEventListener(`mousedown`,r),window.addEventListener(`mousemove`,i),window.addEventListener(`mouseup`,a),this.root.addEventListener(`touchstart`,o,{passive:!1}),this.root.addEventListener(`touchmove`,s,{passive:!1}),this.root.addEventListener(`touchend`,c),this.root.addEventListener(`dragstart`,u),this.cleanup.push(()=>this.root.removeEventListener(`click`,l,!0),()=>this.root.removeEventListener(`click`,t),()=>this.root.removeEventListener(`wheel`,n),()=>this.root.removeEventListener(`mousedown`,r),()=>window.removeEventListener(`mousemove`,i),()=>window.removeEventListener(`mouseup`,a),()=>this.root.removeEventListener(`touchstart`,o),()=>this.root.removeEventListener(`touchmove`,s),()=>this.root.removeEventListener(`touchend`,c),()=>this.root.removeEventListener(`dragstart`,u))}handleSwipeEnd(e,t,n){if(window.clearTimeout(this.pageTurnTimer),!(n.zoomScale<=1&&Math.abs(e)>30&&Math.abs(e)>Math.abs(t))){this.setStageDragOffset(0,!0);return}let r=T(e,n.settings.readingDirection)?`next`:`previous`;if(!(S(n,r,this.isMobileViewport()).length>0)){this.setStageDragOffset(0,!0);return}this.requestPageTurn(n,r)||(r===`next`?this.callbacks.commitNextPage():this.callbacks.commitPreviousPage())}requestPageTurn(e,t){return this.animatePageTurn(e,t,()=>{t===`next`?this.callbacks.commitNextPage():this.callbacks.commitPreviousPage()})}constrainDragOffset(e,t,n){return Math.abs(t)>Math.abs(e)?0:S(n,T(e,n.settings.readingDirection)?`next`:`previous`,this.isMobileViewport()).length>0?e:this.applyEdgeResistance(e)}applyEdgeResistance(e){let t=Math.sign(e),n=Math.abs(e),r=Math.max(this.root.clientWidth,1),i=Math.min(r*.22,140);return t*(i*(1-Math.exp(-n/i)))}setStageDragOffset(e,t=!1){this.pageStage.setDragOffset(e,t)}getPageTurnTargetOffset(e,t){return w(e,t)===`left`?this.root.clientWidth:-this.root.clientWidth}isInteractiveTarget(e){return e instanceof Element?!!e.closest([`.comimi-arrow-button`,`.comimi-view-switcher`,`.comimi-controls-dock`,`.comimi-menu-panel`,`.comimi-settings-panel`,`button`,`input`,`select`,`textarea`,`a`,`iframe`].join(`,`)):!1}isSwipeBlockingTarget(e){return e instanceof Element?!!e.closest([`.comimi-arrow-button`,`.comimi-view-switcher`,`.comimi-controls-dock`,`.comimi-menu-panel`,`.comimi-settings-panel`,`button`,`input`,`select`,`textarea`,`iframe`].join(`,`)):!1}};function Y(e){let[t,n]=Array.from(e.touches);return!t||!n?1:Math.hypot(t.clientX-n.clientX,t.clientY-n.clientY)}var Fe=class{enabled;databaseName;dbPromise;constructor(e={}){this.enabled=e.enabled!==!1&&typeof indexedDB<`u`,this.databaseName=e.databaseName??`manga-viewer`}async getSettings(){return(await this.get(`settings`,`global`))?.value}async saveSettings(e){await this.put(`settings`,{id:`global`,value:e,updatedAt:Date.now()})}async getProgress(e){return(await this.get(`readingProgress`,e))?.pageIndex}async saveProgress(e,t){await this.put(`readingProgress`,{mangaId:e,pageIndex:t,updatedAt:Date.now()})}async saveLayout(e){await this.put(`layout`,{id:`global`,value:e,updatedAt:Date.now()})}async getLayout(){return(await this.get(`layout`,`global`))?.value}async get(e,t){if(this.enabled)return Z((await this.store(e,`readonly`)).get(t))}async put(e,t){this.enabled&&await Z((await this.store(e,`readwrite`)).put(t))}async delete(e,t){this.enabled&&await Z((await this.store(e,`readwrite`)).delete(t))}async store(e,t){return(await this.open()).transaction(e,t).objectStore(e)}open(){return this.enabled?(this.dbPromise??=new Promise((e,t)=>{let n=indexedDB.open(this.databaseName,1);n.onupgradeneeded=()=>{let e=n.result;X(e,`settings`,`id`),X(e,`readingProgress`,`mangaId`),X(e,`layout`,`id`)},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)}),this.dbPromise):Promise.reject(Error(`IndexedDB is not available`))}};function X(e,t,n){e.objectStoreNames.contains(t)||e.createObjectStore(t,{keyPath:n})}function Z(e){return new Promise((t,n)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>n(e.error)})}function Q(e,t){switch(t.type){case`setManga`:{let n=i(t.pageIndex??0,t.manga.pages.length);return $({...e,manga:t.manga,currentPageIndex:n,zoomScale:1,panX:0,panY:0})}case`goToPage`:{let n=i(t.pageIndex,e.manga.pages.length),r=e.zoomScale===1&&e.panX===0&&e.panY===0;return n===e.currentPageIndex&&r?e:$({...e,currentPageIndex:n,zoomScale:1,panX:0,panY:0})}case`nextPage`:{let t=a(e.settings,e.currentPageIndex);return Q(e,{type:`goToPage`,pageIndex:e.currentPageIndex+t})}case`previousPage`:{let t=a(e.settings,e.currentPageIndex);return Q(e,{type:`goToPage`,pageIndex:e.currentPageIndex-t})}case`setOverlayVisible`:return{...e,overlayVisible:t.visible,panel:t.visible?e.panel:`none`};case`toggleAutoPageTurn`:return{...e,autoPageTurnEnabled:!e.autoPageTurnEnabled};case`updateSettings`:{let n=r(e.settings,t.settings);return $({...e,settings:n,layout:{...e.layout,mode:n.layoutMode}})}case`setLayoutMode`:return Q(e,{type:`updateSettings`,settings:{layoutMode:t.layoutMode}});case`setWideHeight`:return{...e,layout:{...e.layout,wideHeightPx:Math.max(240,Math.round(t.heightPx))}};case`setZoom`:return{...e,zoomScale:Ie(t.scale,e),panX:t.panX??e.panX,panY:t.panY??e.panY};case`setPan`:return{...e,panX:t.panX,panY:t.panY};case`resetZoom`:return{...e,zoomScale:1,panX:0,panY:0};case`setPanel`:return{...e,panel:t.panel,overlayVisible:t.panel===`none`?e.overlayVisible:!0};case`pushNotification`:return{...e,notifications:[t.notification]};case`removeNotification`:return{...e,notifications:e.notifications.filter(e=>e.id!==t.id)}}}function $(e){return{...e,visiblePageIndexes:o(e.currentPageIndex,e.manga.pages.length,e.settings)}}function Ie(e,t){return Math.min(Math.max(e,t.settings.zoom.min),t.settings.zoom.max)}var Le=class{state;listeners=new Set;constructor(e){this.state=e}getState(){return this.state}dispatch(e){let t=this.state,n=Q(t,e);if(n!==t){this.state=n;for(let e of this.listeners)e(n,t)}}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}},Re=class{objectUrls=new Set;async resolveImageSource(e,t){return t.src}revokeAll(){for(let e of this.objectUrls)URL.revokeObjectURL(e);this.objectUrls.clear()}},ze=class{handlers=new Map;on(e,t){let n=this.handlers.get(e);return n||(n=new Set,this.handlers.set(e,n)),n.add(t),()=>{n.delete(t)}}emit(e,t){let n=this.handlers.get(e);if(n)for(let e of n)try{e(t)}catch(e){console.error(e)}}clear(){this.handlers.clear()}},Be=class{container;store;storage;assetLoader;renderer;i18n;events=new ze;unsubscribers=[];notificationTimers=new Map;autoTimer;mobileMediaQuery;lockLayoutMode=!1;bodyOverflowBackup=null;constructor(e,i){this.container=e;let a=r(t,{...i.settings,locale:i.locale??i.settings?.locale??t.locale});this.lockLayoutMode=i.lockLayoutMode??!1,this.storage=new Fe(i.storage),this.assetLoader=new Re,this.i18n=new ne(a.locale,i.translations),this.store=new Le(n(i.manga,a,i.initialPageIndex));let o={goToPage:e=>{this.store.getState().autoPageTurnEnabled||this.goToPage(e)},nextPage:()=>{this.store.getState().autoPageTurnEnabled||this.nextPage()},previousPage:()=>{this.store.getState().autoPageTurnEnabled||this.previousPage()},commitNextPage:()=>this.commitNextPage(),commitPreviousPage:()=>this.commitPreviousPage(),toggleOverlay:e=>this.toggleOverlay(e),toggleAutoPageTurn:()=>this.toggleAutoPageTurn(),updateSettings:e=>{this.updateSettings(e)},setLayoutMode:e=>void this.setLayoutMode(e),setWideHeight:e=>this.setWideHeight(e),setPanel:e=>{this.store.dispatch({type:`setPanel`,panel:e})},setZoom:(e,t,n)=>this.store.dispatch({type:`setZoom`,scale:e,panX:t,panY:n}),setPan:(e,t)=>this.store.dispatch({type:`setPan`,panX:e,panY:t}),resetZoom:()=>this.store.dispatch({type:`resetZoom`})};this.renderer=new Pe(this.container,o,this.assetLoader,this.i18n,i.className,i.resolvePageSrc,this.lockLayoutMode,i.mascot);for(let[e,t]of Object.entries(i.events??{}))this.on(e,t);this.unsubscribers.push(this.store.subscribe((e,t)=>{this.renderer.update(e),this.afterStateChange(e,t)})),this.bindKeyboard(),this.bindViewportChange(),this.bootstrap()}destroy(){window.clearInterval(this.autoTimer);for(let e of this.notificationTimers.values())window.clearTimeout(e);this.notificationTimers.clear(),this.syncBodyScrollLock(`inline`),this.unsubscribers.forEach(e=>e()),this.assetLoader.revokeAll(),this.renderer.destroy(),this.events.emit(`destroy`,void 0),this.events.clear()}async setManga(e){let t=await this.storage.getProgress(e.id)??0;this.store.dispatch({type:`setManga`,manga:e,pageIndex:t})}async setPages(e){await this.setManga({...this.store.getState().manga,pages:e})}getState(){return this.store.getState()}async updateSettings(e){let t=e;this.lockLayoutMode&&`layoutMode`in e&&(t={...e},delete t.layoutMode),this.store.dispatch({type:`updateSettings`,settings:t});let n=this.store.getState().settings;this.i18n.setLocale(n.locale),await this.storage.saveSettings(n),this.events.emit(`settingsChange`,{settings:n})}goToPage(e){let t=this.store.getState().currentPageIndex;this.store.dispatch({type:`goToPage`,pageIndex:e});let n=this.store.getState().currentPageIndex;if(t!==n){let e=this.store.getState();this.storage.saveProgress(e.manga.id,n),this.events.emit(`pageChange`,{pageIndex:n,page:e.manga.pages[n]})}}nextPage(){this.renderer.isAnimatingPageTurn()||this.commitNextPage()}previousPage(){this.renderer.isAnimatingPageTurn()||this.commitPreviousPage()}commitNextPage(){if(this.renderer.isMobileViewport()){this.goToPage(this.store.getState().currentPageIndex+1);return}let e=this.store.getState().currentPageIndex;this.store.dispatch({type:`nextPage`}),this.emitPageChangeIfNeeded(e)}commitPreviousPage(){if(this.renderer.isMobileViewport()){this.goToPage(this.store.getState().currentPageIndex-1);return}let e=this.store.getState().currentPageIndex;this.store.dispatch({type:`previousPage`}),this.emitPageChangeIfNeeded(e)}toggleOverlay(e){let t=this.store.getState().overlayVisible,n=e??!t;this.store.dispatch({type:`setOverlayVisible`,visible:n})}toggleAutoPageTurn(){this.store.dispatch({type:`toggleAutoPageTurn`}),this.syncAutoTimer();let e=this.store.getState().autoPageTurnEnabled;this.notify(this.i18n.t(e?`autoplay.start`:`autoplay.stop`))}async toggleFullscreen(){if(this.lockLayoutMode)return;let e=this.store.getState();if(document.fullscreenElement){await document.exitFullscreen(),await this.setLayoutMode(`inline`);return}await this.setLayoutMode(e.layout.mode===`nativeFullscreen`?`inline`:`nativeFullscreen`)}on(e,t){return this.events.on(e,t)}async bootstrap(){let e=await this.storage.getSettings(),t=await this.storage.getLayout(),n=this.store.getState().manga.id,r=await this.storage.getProgress(n);if(e){let t={...e};this.lockLayoutMode&&delete t.layoutMode,this.store.dispatch({type:`updateSettings`,settings:t})}if(!this.lockLayoutMode&&t?.mode){let e=t.mode===`theater`?`wide`:t.mode;this.store.dispatch({type:`setLayoutMode`,layoutMode:e})}let i=t?.wideHeightPx??t?.theaterHeightPx;i&&this.store.dispatch({type:`setWideHeight`,heightPx:i}),typeof r==`number`&&this.store.dispatch({type:`goToPage`,pageIndex:r}),this.renderer.update(this.store.getState()),this.renderer.showSplash(),window.setTimeout(()=>{this.toggleOverlay(!0)},1550),this.events.emit(`ready`,{manga:this.store.getState().manga})}bindKeyboard(){this.renderer.getElement();let e=e=>{if(this.shouldHandleKeyboardEvent(e))switch(e.key){case`ArrowLeft`:e.preventDefault(),this.moveFromKey(`left`);break;case`ArrowRight`:e.preventDefault(),this.moveFromKey(`right`);break;case` `:e.preventDefault(),this.moveFromKey(e.shiftKey?`right`:`left`);break;case`a`:case`A`:e.preventDefault(),this.toggleAutoPageTurn();break;case`n`:case`N`:case`Escape`:if(this.lockLayoutMode)break;e.preventDefault(),this.setLayoutMode(`inline`);break;case`w`:case`W`:if(this.lockLayoutMode)break;e.preventDefault(),this.setLayoutMode(`wide`);break;case`f`:case`F`:if(this.lockLayoutMode)break;e.preventDefault(),this.setLayoutMode(`browserFullscreen`);break;case`m`:case`M`:{e.preventDefault();let t=this.store.getState().panel,n=t===`menu`||t===`pages`||t===`shortcuts`;this.store.dispatch({type:`setPanel`,panel:n?`none`:`menu`});break}case`p`:case`P`:e.preventDefault(),this.updateSettings({pageTurnMode:this.store.getState().settings.pageTurnMode===`spread`?`single`:`spread`});break;case`o`:case`O`:e.preventDefault(),this.toggleOverlay();break;case`s`:case`S`:{e.preventDefault();let t=this.store.getState().panel===`settings`;this.store.dispatch({type:`setPanel`,panel:t?`none`:`settings`});break}case`Escape`:e.preventDefault(),this.store.dispatch({type:`setPanel`,panel:`none`}),document.fullscreenElement&&document.exitFullscreen();break}};window.addEventListener(`keydown`,e),this.unsubscribers.push(()=>window.removeEventListener(`keydown`,e))}shouldHandleKeyboardEvent(e){let t=e.target;return t instanceof Element?!t.closest(`input, select, textarea, [contenteditable='true']`):!0}bindViewportChange(){this.mobileMediaQuery=window.matchMedia(`(max-width: 676px)`);let e=()=>{this.renderer.update(this.store.getState())};this.mobileMediaQuery.addEventListener(`change`,e),this.unsubscribers.push(()=>this.mobileMediaQuery?.removeEventListener(`change`,e))}moveFromKey(e){this.store.getState().autoPageTurnEnabled||(this.store.getState().settings.readingDirection===`rtl`?e===`left`?this.nextPage():this.previousPage():e===`left`?this.previousPage():this.nextPage())}async setLayoutMode(e){if(!this.lockLayoutMode){if(e===`nativeFullscreen`)try{await this.renderer.getElement().requestFullscreen()}catch{e=`browserFullscreen`}else document.fullscreenElement&&await document.exitFullscreen();if(e===`wide`&&!this.store.getState().layout.wideHeightPx){let e=this.renderer.getElement().offsetHeight;e>0&&this.store.dispatch({type:`setWideHeight`,heightPx:e})}this.store.dispatch({type:`setLayoutMode`,layoutMode:e}),await this.storage.saveSettings(this.store.getState().settings),await this.storage.saveLayout(this.store.getState().layout),this.events.emit(`layoutChange`,{layoutMode:e})}}setWideHeight(e){this.store.dispatch({type:`setWideHeight`,heightPx:e}),this.storage.saveLayout(this.store.getState().layout)}afterStateChange(e,t){e.autoPageTurnEnabled!==t.autoPageTurnEnabled&&this.syncAutoTimer(),e.layout.mode!==t.layout.mode&&this.syncBodyScrollLock(e.layout.mode)}syncBodyScrollLock(e){if(typeof document>`u`)return;let t=e===`browserFullscreen`;t&&this.bodyOverflowBackup===null?(this.bodyOverflowBackup=document.body.style.overflow,document.body.style.overflow=`hidden`):!t&&this.bodyOverflowBackup!==null&&(document.body.style.overflow=this.bodyOverflowBackup,this.bodyOverflowBackup=null)}syncAutoTimer(){window.clearInterval(this.autoTimer),this.store.getState().autoPageTurnEnabled&&(this.autoTimer=window.setInterval(()=>{if(this.isAtLastPage()){this.toggleAutoPageTurn();return}this.commitNextPage(),this.isAtLastPage()&&this.toggleAutoPageTurn()},this.store.getState().settings.autoPageTurnIntervalMs))}isAtLastPage(){let e=this.store.getState(),t=this.renderer.isMobileViewport()?1:a(e.settings,e.currentPageIndex);return e.currentPageIndex+t>=e.manga.pages.length}emitPageChangeIfNeeded(e){let t=this.store.getState();t.currentPageIndex!==e&&(this.storage.saveProgress(t.manga.id,t.currentPageIndex),this.events.emit(`pageChange`,{pageIndex:t.currentPageIndex,page:t.manga.pages[t.currentPageIndex]}))}notify(e,t=`info`){for(let e of this.notificationTimers.values())window.clearTimeout(e);this.notificationTimers.clear();let n=`${Date.now()}-${Math.random().toString(36).slice(2)}`;this.store.dispatch({type:`pushNotification`,notification:{id:n,message:e,tone:t,createdAt:Date.now()}});let r=window.setTimeout(()=>{this.store.dispatch({type:`removeNotification`,id:n}),this.notificationTimers.delete(n)},1500);this.notificationTimers.set(n,r)}};function Ve(e,t){return new Be(e,t)}return e.createMangaViewer=Ve,e})({});
2583
+ `);function je(){if(J||typeof document>`u`)return;let e=document.createElement(`style`);e.dataset.comimiViewer=`true`,e.textContent=Ae,document.head.append(e),J=!0}var Me=180,Ne=2e3,Pe=class{container;callbacks;assetLoader;i18n;lockLayoutMode;mascot;root;cleanup=[];mouseStart;touchStart;pinchStart;pageStage;pageTurnTimer;splashRemoveTimer;splash;isPageTurnAnimating=!1;suppressNextClick=!1;prevOverlayVisible=!1;overlayApplyRaf;menuPanel;viewModeSwitcher;controlsDock;resizeHandle;viewSizeObserver;autoplayOverlayProgress;autoplayOverlayProgressBar;notifications;destroyed=!1;constructor(e,t,n,r,i,a,o=!1,s){this.container=e,this.callbacks=t,this.assetLoader=n,this.i18n=r,this.lockLayoutMode=o,this.mascot=s,je(),this.pageStage=new H({assetLoader:this.assetLoader,i18n:this.i18n,isMobileViewport:()=>this.isMobileViewport(),resolvePageSrc:a}),this.root=pe({className:i}),this.container.replaceChildren(this.root),this.observeViewSize()}observeViewSize(){let e=()=>{this.root.style.setProperty(`--view-width`,`${this.root.offsetWidth}px`),this.root.style.setProperty(`--view-height`,`${this.root.offsetHeight}px`)};e(),typeof ResizeObserver<`u`?(this.viewSizeObserver=new ResizeObserver(e),this.viewSizeObserver.observe(this.root)):(window.addEventListener(`resize`,e),this.cleanup.push(()=>window.removeEventListener(`resize`,e)))}update(e){if(this.destroyed||this.isPageTurnAnimating)return;this.cleanup.forEach(e=>e()),this.cleanup=[],this.i18n.setLocale(e.settings.locale),this.root.dataset.layout=e.layout.mode,this.root.dataset.bg=e.settings.backgroundColor,e.layout.mode===`wide`&&e.layout.wideHeightPx?this.root.style.height=`${e.layout.wideHeightPx}px`:this.root.style.height=``;let t=this.prevOverlayVisible!==e.overlayVisible,n=t?{...e,overlayVisible:this.prevOverlayVisible}:e;this.menuPanel||=new F(this.callbacks,this.i18n,{lockLayoutMode:this.lockLayoutMode,mascot:this.mascot}),!this.viewModeSwitcher&&!this.lockLayoutMode&&(this.viewModeSwitcher=new I(this.callbacks,this.i18n)),this.controlsDock||=new P(this.callbacks,this.i18n,this.mascot),this.notifications||=new W;let r=this.pageStage.getElement(),i=this.menuPanel.getElement(),a=this.viewModeSwitcher?.getElement(),o=this.controlsDock.getElement(),s=this.notifications.getElement();Array.from(this.root.children).forEach(e=>{e!==r&&e!==i&&e!==a&&e!==o&&e!==this.splash&&e!==this.autoplayOverlayProgress&&e!==s&&e.remove()}),r.parentNode!==this.root&&this.root.prepend(r),this.pageStage.update(e,this.isMobileViewport()),this.pageStage.snapTransform();let c=[ae(n,this.i18n),_({state:n,callbacks:this.callbacks})];this.syncResizeHandle(e.layout.mode===`wide`);let l=i.parentNode===this.root?i:null;if(l?c.forEach(e=>this.root.insertBefore(e,l)):(c.forEach(e=>this.root.appendChild(e)),this.root.appendChild(i)),a&&a.parentNode!==this.root&&this.root.appendChild(a),o.parentNode!==this.root&&this.root.appendChild(o),s.parentNode!==this.root&&this.root.appendChild(s),this.menuPanel.update(n),this.viewModeSwitcher?.update(n),this.controlsDock.update(n,this.isMobileViewport()),this.notifications.update(e),this.syncAutoplayOverlayProgress(e),this.splash&&this.splash.parentNode!==this.root&&this.root.append(this.splash),this.bindGestures(e),this.overlayApplyRaf!==void 0&&(cancelAnimationFrame(this.overlayApplyRaf),this.overlayApplyRaf=void 0),t){let t=e.overlayVisible;this.root.offsetWidth,this.overlayApplyRaf=requestAnimationFrame(()=>{this.overlayApplyRaf=void 0,this.applyOverlayVisibility(t)})}this.prevOverlayVisible=e.overlayVisible}applyOverlayVisibility(e){let t=String(e);this.root.querySelectorAll(`.comimi-arrows, .comimi-center-message, .comimi-menu-panel, .comimi-view-switcher, .comimi-controls-dock, .comimi-stage`).forEach(e=>{e.dataset.overlay=t})}showSplash(){this.destroyed||this.splash||(this.splash=le(this.i18n,this.mascot),this.root.append(this.splash),this.splashRemoveTimer=window.setTimeout(()=>{this.splash?.remove(),this.splash=void 0},Ne))}destroy(){this.destroyed=!0,window.clearTimeout(this.pageTurnTimer),window.clearTimeout(this.splashRemoveTimer),this.overlayApplyRaf!==void 0&&(cancelAnimationFrame(this.overlayApplyRaf),this.overlayApplyRaf=void 0),this.cleanup.forEach(e=>e()),this.cleanup=[],this.viewSizeObserver?.disconnect(),this.viewSizeObserver=void 0,this.resizeHandle?.remove(),this.resizeHandle=void 0,this.root.remove()}getElement(){return this.root}isAnimatingPageTurn(){return this.isPageTurnAnimating}animatePageTurn(e,t,n){return window.clearTimeout(this.pageTurnTimer),this.isPageTurnAnimating||S(e,t,this.isMobileViewport()).length===0?!1:(this.isPageTurnAnimating=!0,this.setStageDragOffset(this.getPageTurnTargetOffset(e,t),!0),this.pageTurnTimer=window.setTimeout(()=>{this.isPageTurnAnimating=!1,n()},Me),!0)}isMobileViewport(){return window.matchMedia(`(max-width: 767px)`).matches}syncAutoplayOverlayProgress(e){if(!e.autoPageTurnEnabled){this.autoplayOverlayProgress&&(this.autoplayOverlayProgress.remove(),this.autoplayOverlayProgress=void 0,this.autoplayOverlayProgressBar=void 0);return}this.autoplayOverlayProgress||(this.autoplayOverlayProgress=document.createElement(`div`),this.autoplayOverlayProgress.className=`comimi-autoplay-overlay-progress`,this.autoplayOverlayProgressBar=document.createElement(`span`),this.autoplayOverlayProgressBar.className=`comimi-autoplay-overlay-progress-bar`,this.autoplayOverlayProgress.append(this.autoplayOverlayProgressBar)),this.autoplayOverlayProgress.parentNode!==this.root&&this.root.appendChild(this.autoplayOverlayProgress),this.autoplayOverlayProgress.dataset.visible=String(!e.overlayVisible),this.autoplayOverlayProgressBar.style.animationDuration=`${e.settings.autoPageTurnIntervalMs}ms`}clampPan(e,t,n,r){if(n<=1)return{x:0,y:0};let i=x(r,this.isMobileViewport()).length>1?this.root.offsetWidth/2:this.root.offsetWidth,a=this.root.offsetHeight,o=i*(n-1)/2,s=a*(n-1)/2;return{x:Math.min(Math.max(e,-o),o),y:Math.min(Math.max(t,-s),s)}}clampedZoom(e,t){return Math.min(Math.max(e,t.settings.zoom.min),t.settings.zoom.max)}syncResizeHandle(e){e?(this.resizeHandle||=this.createResizeHandle(),this.resizeHandle.parentNode!==this.container&&this.container.appendChild(this.resizeHandle)):this.resizeHandle&&this.resizeHandle.remove()}createResizeHandle(){let e=document.createElement(`div`);e.className=`comimi-resize-handle`,e.setAttribute(`role`,`separator`),e.setAttribute(`aria-orientation`,`horizontal`);let t=0,n=0,r,i=e=>{e.pointerId===r&&this.callbacks.setWideHeight(n+e.clientY-t)},a=e=>{e.pointerId===r&&(window.removeEventListener(`pointermove`,i),window.removeEventListener(`pointerup`,a),window.removeEventListener(`pointercancel`,a),r=void 0)};return e.addEventListener(`pointerdown`,e=>{e.preventDefault(),r=e.pointerId,t=e.clientY,n=this.root.getBoundingClientRect().height,window.addEventListener(`pointermove`,i),window.addEventListener(`pointerup`,a),window.addEventListener(`pointercancel`,a)}),e}bindGestures(e){let t=t=>{if(this.suppressNextClick||this.isPageTurnAnimating){this.suppressNextClick=!1,t.preventDefault(),t.stopPropagation();return}if(!this.isInteractiveTarget(t.target)){if(!e.overlayVisible){let n=this.root.getBoundingClientRect(),r=(t.clientX-n.left)/n.width;if(r<.3||r>=.7){let t=r<.3?`left`:`right`;(e.settings.readingDirection===`rtl`?t===`left`:t===`right`)?this.callbacks.nextPage():this.callbacks.previousPage();return}}this.callbacks.toggleOverlay()}},n=t=>{if(this.isInteractiveTarget(t.target)||!t.ctrlKey&&!t.metaKey)return;t.preventDefault();let n=t.deltaY>0?-e.settings.zoom.step:e.settings.zoom.step,r=this.clampedZoom(e.zoomScale+n,e),i=this.clampPan(e.panX,e.panY,r,e);this.callbacks.setZoom(r,i.x,i.y)},r=t=>{this.isPageTurnAnimating||this.isSwipeBlockingTarget(t.target)||t.button===0&&(this.mouseStart={x:t.clientX,y:t.clientY,panX:e.panX,panY:e.panY})},i=t=>{if(!this.mouseStart)return;t.preventDefault();let n=t.clientX-this.mouseStart.x,r=t.clientY-this.mouseStart.y;if((Math.abs(n)>6||Math.abs(r)>6)&&(this.suppressNextClick=!0),e.zoomScale<=1){this.setStageDragOffset(this.constrainDragOffset(n,r,e));return}let i=this.mouseStart.panX+t.clientX-this.mouseStart.x,a=this.mouseStart.panY+t.clientY-this.mouseStart.y,o=this.clampPan(i,a,e.zoomScale,e);this.callbacks.setPan(o.x,o.y)},a=t=>{if(!this.mouseStart)return;let n=t.clientX-this.mouseStart.x,r=t.clientY-this.mouseStart.y;this.handleSwipeEnd(n,r,e),this.mouseStart=void 0},o=t=>{if(this.isPageTurnAnimating)return;if(t.touches.length===2){t.preventDefault(),this.touchStart=void 0,this.pinchStart={distance:Y(t),scale:e.zoomScale};return}if(this.isSwipeBlockingTarget(t.target))return;let n=t.touches[0];n&&(this.touchStart={x:n.clientX,y:n.clientY,panX:e.panX,panY:e.panY})},s=t=>{if(this.pinchStart&&t.touches.length===2){t.preventDefault();let n=this.pinchStart.scale*(Y(t)/this.pinchStart.distance),r=this.clampedZoom(n,e),i=this.clampPan(e.panX,e.panY,r,e);this.callbacks.setZoom(r,i.x,i.y);return}if(this.isSwipeBlockingTarget(t.target))return;let n=t.touches[0];if(!n||!this.touchStart)return;t.preventDefault();let r=n.clientX-this.touchStart.x,i=n.clientY-this.touchStart.y;if((Math.abs(r)>6||Math.abs(i)>6)&&(this.suppressNextClick=!0),e.zoomScale<=1){this.setStageDragOffset(this.constrainDragOffset(r,i,e));return}let a=this.touchStart.panX+n.clientX-this.touchStart.x,o=this.touchStart.panY+n.clientY-this.touchStart.y,s=this.clampPan(a,o,e.zoomScale,e);this.callbacks.setPan(s.x,s.y)},c=t=>{t.touches.length<2&&(this.pinchStart=void 0);let n=t.changedTouches[0];if(!n||!this.touchStart){this.touchStart=void 0;return}let r=n.clientX-this.touchStart.x,i=n.clientY-this.touchStart.y;this.handleSwipeEnd(r,i,e),this.touchStart=void 0},l=t=>{if(this.suppressNextClick||this.isPageTurnAnimating||e.panel!==`settings`)return;let n=t.target;n instanceof Element&&(n.closest(`.comimi-settings`)||this.callbacks.setPanel(`none`))},u=e=>{this.isSwipeBlockingTarget(e.target)||e.preventDefault()};this.root.addEventListener(`click`,l,!0),this.root.addEventListener(`click`,t),this.root.addEventListener(`wheel`,n,{passive:!1}),this.root.addEventListener(`mousedown`,r),window.addEventListener(`mousemove`,i),window.addEventListener(`mouseup`,a),this.root.addEventListener(`touchstart`,o,{passive:!1}),this.root.addEventListener(`touchmove`,s,{passive:!1}),this.root.addEventListener(`touchend`,c),this.root.addEventListener(`dragstart`,u),this.cleanup.push(()=>this.root.removeEventListener(`click`,l,!0),()=>this.root.removeEventListener(`click`,t),()=>this.root.removeEventListener(`wheel`,n),()=>this.root.removeEventListener(`mousedown`,r),()=>window.removeEventListener(`mousemove`,i),()=>window.removeEventListener(`mouseup`,a),()=>this.root.removeEventListener(`touchstart`,o),()=>this.root.removeEventListener(`touchmove`,s),()=>this.root.removeEventListener(`touchend`,c),()=>this.root.removeEventListener(`dragstart`,u))}handleSwipeEnd(e,t,n){if(window.clearTimeout(this.pageTurnTimer),!(n.zoomScale<=1&&Math.abs(e)>30&&Math.abs(e)>Math.abs(t))){this.setStageDragOffset(0,!0);return}let r=T(e,n.settings.readingDirection)?`next`:`previous`;if(!(S(n,r,this.isMobileViewport()).length>0)){this.setStageDragOffset(0,!0);return}this.requestPageTurn(n,r)||(r===`next`?this.callbacks.commitNextPage():this.callbacks.commitPreviousPage())}requestPageTurn(e,t){return this.animatePageTurn(e,t,()=>{t===`next`?this.callbacks.commitNextPage():this.callbacks.commitPreviousPage()})}constrainDragOffset(e,t,n){return Math.abs(t)>Math.abs(e)?0:S(n,T(e,n.settings.readingDirection)?`next`:`previous`,this.isMobileViewport()).length>0?e:this.applyEdgeResistance(e)}applyEdgeResistance(e){let t=Math.sign(e),n=Math.abs(e),r=Math.max(this.root.clientWidth,1),i=Math.min(r*.22,140);return t*(i*(1-Math.exp(-n/i)))}setStageDragOffset(e,t=!1){this.pageStage.setDragOffset(e,t)}getPageTurnTargetOffset(e,t){return w(e,t)===`left`?this.root.clientWidth:-this.root.clientWidth}isInteractiveTarget(e){return e instanceof Element?!!e.closest([`.comimi-arrow-button`,`.comimi-view-switcher`,`.comimi-controls-dock`,`.comimi-menu-panel`,`.comimi-settings-panel`,`button`,`input`,`select`,`textarea`,`a`,`iframe`].join(`,`)):!1}isSwipeBlockingTarget(e){return e instanceof Element?!!e.closest([`.comimi-arrow-button`,`.comimi-view-switcher`,`.comimi-controls-dock`,`.comimi-menu-panel`,`.comimi-settings-panel`,`button`,`input`,`select`,`textarea`,`iframe`].join(`,`)):!1}};function Y(e){let[t,n]=Array.from(e.touches);return!t||!n?1:Math.hypot(t.clientX-n.clientX,t.clientY-n.clientY)}var Fe=class{enabled;databaseName;dbPromise;constructor(e={}){this.enabled=e.enabled!==!1&&typeof indexedDB<`u`,this.databaseName=e.databaseName??`manga-viewer`}async getSettings(){return(await this.get(`settings`,`global`))?.value}async saveSettings(e){await this.put(`settings`,{id:`global`,value:e,updatedAt:Date.now()})}async getProgress(e){return(await this.get(`readingProgress`,e))?.pageIndex}async saveProgress(e,t){await this.put(`readingProgress`,{mangaId:e,pageIndex:t,updatedAt:Date.now()})}async saveLayout(e){await this.put(`layout`,{id:`global`,value:e,updatedAt:Date.now()})}async getLayout(){return(await this.get(`layout`,`global`))?.value}async get(e,t){if(this.enabled)return Z((await this.store(e,`readonly`)).get(t))}async put(e,t){this.enabled&&await Z((await this.store(e,`readwrite`)).put(t))}async delete(e,t){this.enabled&&await Z((await this.store(e,`readwrite`)).delete(t))}async store(e,t){return(await this.open()).transaction(e,t).objectStore(e)}open(){return this.enabled?(this.dbPromise??=new Promise((e,t)=>{let n=indexedDB.open(this.databaseName,1);n.onupgradeneeded=()=>{let e=n.result;X(e,`settings`,`id`),X(e,`readingProgress`,`mangaId`),X(e,`layout`,`id`)},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)}),this.dbPromise):Promise.reject(Error(`IndexedDB is not available`))}};function X(e,t,n){e.objectStoreNames.contains(t)||e.createObjectStore(t,{keyPath:n})}function Z(e){return new Promise((t,n)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>n(e.error)})}function Q(e,t){switch(t.type){case`setManga`:{let n=i(t.pageIndex??0,t.manga.pages.length);return $({...e,manga:t.manga,currentPageIndex:n,zoomScale:1,panX:0,panY:0})}case`goToPage`:{let n=i(t.pageIndex,e.manga.pages.length),r=e.zoomScale===1&&e.panX===0&&e.panY===0;return n===e.currentPageIndex&&r?e:$({...e,currentPageIndex:n,zoomScale:1,panX:0,panY:0})}case`nextPage`:{let t=a(e.settings,e.currentPageIndex);return Q(e,{type:`goToPage`,pageIndex:e.currentPageIndex+t})}case`previousPage`:{let t=a(e.settings,e.currentPageIndex);return Q(e,{type:`goToPage`,pageIndex:e.currentPageIndex-t})}case`setOverlayVisible`:return{...e,overlayVisible:t.visible,panel:t.visible?e.panel:`none`};case`toggleAutoPageTurn`:return{...e,autoPageTurnEnabled:!e.autoPageTurnEnabled};case`updateSettings`:{let n=r(e.settings,t.settings);return $({...e,settings:n,layout:{...e.layout,mode:n.layoutMode}})}case`setLayoutMode`:return Q(e,{type:`updateSettings`,settings:{layoutMode:t.layoutMode}});case`setWideHeight`:return{...e,layout:{...e.layout,wideHeightPx:Math.max(240,Math.round(t.heightPx))}};case`setZoom`:return{...e,zoomScale:Ie(t.scale,e),panX:t.panX??e.panX,panY:t.panY??e.panY};case`setPan`:return{...e,panX:t.panX,panY:t.panY};case`resetZoom`:return{...e,zoomScale:1,panX:0,panY:0};case`setPanel`:return{...e,panel:t.panel,overlayVisible:t.panel===`none`?e.overlayVisible:!0};case`pushNotification`:return{...e,notifications:[t.notification]};case`removeNotification`:return{...e,notifications:e.notifications.filter(e=>e.id!==t.id)}}}function $(e){return{...e,visiblePageIndexes:o(e.currentPageIndex,e.manga.pages.length,e.settings)}}function Ie(e,t){return Math.min(Math.max(e,t.settings.zoom.min),t.settings.zoom.max)}var Le=class{state;listeners=new Set;constructor(e){this.state=e}getState(){return this.state}dispatch(e){let t=this.state,n=Q(t,e);if(n!==t){this.state=n;for(let e of this.listeners)e(n,t)}}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}},Re=class{objectUrls=new Set;async resolveImageSource(e,t){return t.src}revokeAll(){for(let e of this.objectUrls)URL.revokeObjectURL(e);this.objectUrls.clear()}},ze=class{handlers=new Map;on(e,t){let n=this.handlers.get(e);return n||(n=new Set,this.handlers.set(e,n)),n.add(t),()=>{n.delete(t)}}emit(e,t){let n=this.handlers.get(e);if(n)for(let e of n)try{e(t)}catch(e){console.error(e)}}clear(){this.handlers.clear()}},Be=class{container;store;storage;assetLoader;renderer;i18n;events=new ze;unsubscribers=[];notificationTimers=new Map;autoTimer;bootstrapOverlayTimer;destroyed=!1;mobileMediaQuery;lockLayoutMode=!1;bodyOverflowBackup=null;constructor(e,i){this.container=e;let a=r(t,{...i.settings,locale:i.locale??i.settings?.locale??t.locale});this.lockLayoutMode=i.lockLayoutMode??!1,this.storage=new Fe(i.storage),this.assetLoader=new Re,this.i18n=new ne(a.locale,i.translations),this.store=new Le(n(i.manga,a,i.initialPageIndex));let o={goToPage:e=>{this.store.getState().autoPageTurnEnabled||this.goToPage(e)},nextPage:()=>{this.store.getState().autoPageTurnEnabled||this.nextPage()},previousPage:()=>{this.store.getState().autoPageTurnEnabled||this.previousPage()},commitNextPage:()=>this.commitNextPage(),commitPreviousPage:()=>this.commitPreviousPage(),toggleOverlay:e=>this.toggleOverlay(e),toggleAutoPageTurn:()=>this.toggleAutoPageTurn(),updateSettings:e=>{this.updateSettings(e)},setLayoutMode:e=>void this.setLayoutMode(e),setWideHeight:e=>this.setWideHeight(e),setPanel:e=>{this.store.dispatch({type:`setPanel`,panel:e})},setZoom:(e,t,n)=>this.store.dispatch({type:`setZoom`,scale:e,panX:t,panY:n}),setPan:(e,t)=>this.store.dispatch({type:`setPan`,panX:e,panY:t}),resetZoom:()=>this.store.dispatch({type:`resetZoom`})};this.renderer=new Pe(this.container,o,this.assetLoader,this.i18n,i.className,i.resolvePageSrc,this.lockLayoutMode,i.mascot);for(let[e,t]of Object.entries(i.events??{}))this.on(e,t);this.unsubscribers.push(this.store.subscribe((e,t)=>{this.renderer.update(e),this.afterStateChange(e,t)})),this.bindKeyboard(),this.bindViewportChange(),this.bootstrap()}destroy(){this.destroyed=!0,window.clearInterval(this.autoTimer),window.clearTimeout(this.bootstrapOverlayTimer);for(let e of this.notificationTimers.values())window.clearTimeout(e);this.notificationTimers.clear(),this.syncBodyScrollLock(`inline`),this.unsubscribers.forEach(e=>e()),this.assetLoader.revokeAll(),this.renderer.destroy(),this.events.emit(`destroy`,void 0),this.events.clear()}async setManga(e){let t=await this.storage.getProgress(e.id)??0;this.store.dispatch({type:`setManga`,manga:e,pageIndex:t})}async setPages(e){await this.setManga({...this.store.getState().manga,pages:e})}getState(){return this.store.getState()}async updateSettings(e){let t=e;this.lockLayoutMode&&`layoutMode`in e&&(t={...e},delete t.layoutMode),this.store.dispatch({type:`updateSettings`,settings:t});let n=this.store.getState().settings;this.i18n.setLocale(n.locale),await this.storage.saveSettings(n),this.events.emit(`settingsChange`,{settings:n})}goToPage(e){let t=this.store.getState().currentPageIndex;this.store.dispatch({type:`goToPage`,pageIndex:e});let n=this.store.getState().currentPageIndex;if(t!==n){let e=this.store.getState();this.storage.saveProgress(e.manga.id,n),this.events.emit(`pageChange`,{pageIndex:n,page:e.manga.pages[n]})}}nextPage(){this.renderer.isAnimatingPageTurn()||this.commitNextPage()}previousPage(){this.renderer.isAnimatingPageTurn()||this.commitPreviousPage()}commitNextPage(){if(this.renderer.isMobileViewport()){this.goToPage(this.store.getState().currentPageIndex+1);return}let e=this.store.getState().currentPageIndex;this.store.dispatch({type:`nextPage`}),this.emitPageChangeIfNeeded(e)}commitPreviousPage(){if(this.renderer.isMobileViewport()){this.goToPage(this.store.getState().currentPageIndex-1);return}let e=this.store.getState().currentPageIndex;this.store.dispatch({type:`previousPage`}),this.emitPageChangeIfNeeded(e)}toggleOverlay(e){let t=this.store.getState().overlayVisible,n=e??!t;this.store.dispatch({type:`setOverlayVisible`,visible:n})}toggleAutoPageTurn(){this.store.dispatch({type:`toggleAutoPageTurn`}),this.syncAutoTimer();let e=this.store.getState().autoPageTurnEnabled;this.notify(this.i18n.t(e?`autoplay.start`:`autoplay.stop`))}async toggleFullscreen(){if(this.lockLayoutMode)return;let e=this.store.getState();if(document.fullscreenElement){await document.exitFullscreen(),await this.setLayoutMode(`inline`);return}await this.setLayoutMode(e.layout.mode===`nativeFullscreen`?`inline`:`nativeFullscreen`)}on(e,t){return this.events.on(e,t)}async bootstrap(){let e=await this.storage.getSettings(),t=await this.storage.getLayout(),n=this.store.getState().manga.id,r=await this.storage.getProgress(n);if(this.destroyed)return;if(e){let t={...e};this.lockLayoutMode&&delete t.layoutMode,this.store.dispatch({type:`updateSettings`,settings:t})}if(!this.lockLayoutMode&&t?.mode){let e=t.mode===`theater`?`wide`:t.mode;this.store.dispatch({type:`setLayoutMode`,layoutMode:e})}let i=t?.wideHeightPx??t?.theaterHeightPx;i&&this.store.dispatch({type:`setWideHeight`,heightPx:i}),typeof r==`number`&&this.store.dispatch({type:`goToPage`,pageIndex:r}),this.renderer.update(this.store.getState()),this.renderer.showSplash(),this.bootstrapOverlayTimer=window.setTimeout(()=>{this.destroyed||this.toggleOverlay(!0)},1550),this.events.emit(`ready`,{manga:this.store.getState().manga})}bindKeyboard(){this.renderer.getElement();let e=e=>{if(this.shouldHandleKeyboardEvent(e))switch(e.key){case`ArrowLeft`:e.preventDefault(),this.moveFromKey(`left`);break;case`ArrowRight`:e.preventDefault(),this.moveFromKey(`right`);break;case` `:e.preventDefault(),this.moveFromKey(e.shiftKey?`right`:`left`);break;case`a`:case`A`:e.preventDefault(),this.toggleAutoPageTurn();break;case`n`:case`N`:case`Escape`:if(this.lockLayoutMode)break;e.preventDefault(),this.setLayoutMode(`inline`);break;case`w`:case`W`:if(this.lockLayoutMode)break;e.preventDefault(),this.setLayoutMode(`wide`);break;case`f`:case`F`:if(this.lockLayoutMode)break;e.preventDefault(),this.setLayoutMode(`browserFullscreen`);break;case`m`:case`M`:{e.preventDefault();let t=this.store.getState().panel,n=t===`menu`||t===`pages`||t===`shortcuts`;this.store.dispatch({type:`setPanel`,panel:n?`none`:`menu`});break}case`p`:case`P`:e.preventDefault(),this.updateSettings({pageTurnMode:this.store.getState().settings.pageTurnMode===`spread`?`single`:`spread`});break;case`o`:case`O`:e.preventDefault(),this.toggleOverlay();break;case`s`:case`S`:{e.preventDefault();let t=this.store.getState().panel===`settings`;this.store.dispatch({type:`setPanel`,panel:t?`none`:`settings`});break}case`Escape`:e.preventDefault(),this.store.dispatch({type:`setPanel`,panel:`none`}),document.fullscreenElement&&document.exitFullscreen();break}};window.addEventListener(`keydown`,e),this.unsubscribers.push(()=>window.removeEventListener(`keydown`,e))}shouldHandleKeyboardEvent(e){let t=e.target;return t instanceof Element?!t.closest(`input, select, textarea, [contenteditable='true']`):!0}bindViewportChange(){this.mobileMediaQuery=window.matchMedia(`(max-width: 676px)`);let e=()=>{this.renderer.update(this.store.getState())};this.mobileMediaQuery.addEventListener(`change`,e),this.unsubscribers.push(()=>this.mobileMediaQuery?.removeEventListener(`change`,e))}moveFromKey(e){this.store.getState().autoPageTurnEnabled||(this.store.getState().settings.readingDirection===`rtl`?e===`left`?this.nextPage():this.previousPage():e===`left`?this.previousPage():this.nextPage())}async setLayoutMode(e){if(!this.lockLayoutMode){if(e===`nativeFullscreen`)try{await this.renderer.getElement().requestFullscreen()}catch{e=`browserFullscreen`}else document.fullscreenElement&&await document.exitFullscreen();if(e===`wide`&&!this.store.getState().layout.wideHeightPx){let e=this.renderer.getElement().offsetHeight;e>0&&this.store.dispatch({type:`setWideHeight`,heightPx:e})}this.store.dispatch({type:`setLayoutMode`,layoutMode:e}),await this.storage.saveSettings(this.store.getState().settings),await this.storage.saveLayout(this.store.getState().layout),this.events.emit(`layoutChange`,{layoutMode:e})}}setWideHeight(e){this.store.dispatch({type:`setWideHeight`,heightPx:e}),this.storage.saveLayout(this.store.getState().layout)}afterStateChange(e,t){e.autoPageTurnEnabled!==t.autoPageTurnEnabled&&this.syncAutoTimer(),e.layout.mode!==t.layout.mode&&this.syncBodyScrollLock(e.layout.mode)}syncBodyScrollLock(e){if(typeof document>`u`)return;let t=e===`browserFullscreen`;t&&this.bodyOverflowBackup===null?(this.bodyOverflowBackup=document.body.style.overflow,document.body.style.overflow=`hidden`):!t&&this.bodyOverflowBackup!==null&&(document.body.style.overflow=this.bodyOverflowBackup,this.bodyOverflowBackup=null)}syncAutoTimer(){window.clearInterval(this.autoTimer),this.store.getState().autoPageTurnEnabled&&(this.autoTimer=window.setInterval(()=>{if(this.isAtLastPage()){this.toggleAutoPageTurn();return}this.commitNextPage(),this.isAtLastPage()&&this.toggleAutoPageTurn()},this.store.getState().settings.autoPageTurnIntervalMs))}isAtLastPage(){let e=this.store.getState(),t=this.renderer.isMobileViewport()?1:a(e.settings,e.currentPageIndex);return e.currentPageIndex+t>=e.manga.pages.length}emitPageChangeIfNeeded(e){let t=this.store.getState();t.currentPageIndex!==e&&(this.storage.saveProgress(t.manga.id,t.currentPageIndex),this.events.emit(`pageChange`,{pageIndex:t.currentPageIndex,page:t.manga.pages[t.currentPageIndex]}))}notify(e,t=`info`){for(let e of this.notificationTimers.values())window.clearTimeout(e);this.notificationTimers.clear();let n=`${Date.now()}-${Math.random().toString(36).slice(2)}`;this.store.dispatch({type:`pushNotification`,notification:{id:n,message:e,tone:t,createdAt:Date.now()}});let r=window.setTimeout(()=>{this.store.dispatch({type:`removeNotification`,id:n}),this.notificationTimers.delete(n)},1500);this.notificationTimers.set(n,r)}};function Ve(e,t){return new Be(e,t)}return e.createMangaViewer=Ve,e})({});
@@ -30,6 +30,7 @@ export declare class ViewerRenderer {
30
30
  private autoplayOverlayProgress?;
31
31
  private autoplayOverlayProgressBar?;
32
32
  private notifications?;
33
+ private destroyed;
33
34
  constructor(container: HTMLElement, callbacks: RendererCallbacks, assetLoader: AssetLoader, i18n: I18n, className?: string, resolvePageSrc?: PageSrcResolver, lockLayoutMode?: boolean, mascot?: MascotOption | undefined);
34
35
  private observeViewSize;
35
36
  update(state: ViewerState): void;
@@ -1 +1 @@
1
- {"version":3,"file":"viewer-renderer.d.ts","sourceRoot":"","sources":["../../src/renderer/viewer-renderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAgBnD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEpC,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC3E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAY9D,qBAAa,cAAc;IAwBvB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,IAAI;IAGZ,OAAO,CAAC,cAAc;IACtB,OAAO,CAAC,MAAM,CAAC;IA9BjB,OAAO,CAAC,IAAI,CAAiB;IAC7B,OAAO,CAAC,OAAO,CAAyB;IACxC,OAAO,CAAC,UAAU,CAAC,CAAY;IAC/B,OAAO,CAAC,UAAU,CAAC,CAAY;IAC/B,OAAO,CAAC,UAAU,CAAC,CAAsC;IACzD,OAAO,CAAC,SAAS,CAAY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AAO,CAAC,uBAAuB;IAQ/B,OAAO,CAAC,mBAAmB;IA0B3B,OAAO,CAAC,qBAAqB;CAsB9B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yui540/comimi",
3
- "version": "0.3.6",
3
+ "version": "0.3.7",
4
4
  "description": "Open-source comic reader library for JS/TS",
5
5
  "keywords": [
6
6
  "manga",