@zinejs/core 0.7.3 → 0.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -282,7 +282,7 @@ function w(e, t) {
282
282
  //#region src/renderer/select.ts
283
283
  var T = {
284
284
  css: async () => new (await (import("./cssRenderer-Deskm2ND.js"))).CssRenderer(),
285
- webgl2: async () => new (await (import("./webglRenderer-D_XGumQT.js"))).WebglRenderer()
285
+ webgl2: async () => new (await (import("./webglRenderer-nGRruZk2.js"))).WebglRenderer()
286
286
  }, E = !0;
287
287
  function ee(e) {
288
288
  return typeof e == "object" && !!e && !Array.isArray(e) && typeof e.mount == "function";
@@ -331,6 +331,7 @@ var M = class {
331
331
  #a = /* @__PURE__ */ new Map();
332
332
  open;
333
333
  onPageUpdate;
334
+ onProgress;
334
335
  getText;
335
336
  getDownload;
336
337
  getOutline;
@@ -339,7 +340,7 @@ var M = class {
339
340
  await e.open(), this.#o();
340
341
  } : this.#o(), typeof e.onPageUpdate == "function" && (this.onPageUpdate = (t) => {
341
342
  e.onPageUpdate((e) => t(e + (this.#t === null ? 0 : 1)));
342
- }), typeof e.getText == "function" && (this.getText = async (t) => {
343
+ }), typeof e.onProgress == "function" && (this.onProgress = (t) => e.onProgress(t)), typeof e.getText == "function" && (this.getText = async (t) => {
343
344
  let n = this.#t === null ? 0 : 1;
344
345
  if (this.#t !== null && t === 0 || this.#n !== null && t === this.pageCount - 1) return "";
345
346
  let r = t - n;
@@ -469,10 +470,14 @@ var J = class {
469
470
  #le = /* @__PURE__ */ new Set();
470
471
  #ue;
471
472
  #de = null;
472
- #fe = 1;
473
- #pe = 0;
473
+ #fe;
474
+ #pe = null;
474
475
  #me = null;
475
- #he;
476
+ #he = "download";
477
+ #ge = 1;
478
+ #_e = 0;
479
+ #ve = null;
480
+ #ye;
476
481
  debug = { setFlipProgress: (e, t) => {
477
482
  this.#z?.setFlipProgress(e, t);
478
483
  } };
@@ -483,7 +488,7 @@ var J = class {
483
488
  pages: t.pages
484
489
  });
485
490
  let n = t.direction ?? "ltr";
486
- this.#a = n, this.#x = (t.deepLink ?? !0) && b(), this.#S = t.disableContextMenu ?? !1, this.#o = t.spreadMode ?? "cover", this.#s = this.#o, this.#c = t.curl ?? "cone", this.#u = t.clickToFlip ?? "edge", this.#d = t.clickZoneSize ?? 64, this.#m = t.singlePageThreshold ?? 640, this.#v = t.responsiveSpread ?? !0, this.#ue = t.controls ?? !0, this.#b = t.startPage, typeof this.#t.open != "function" && this.#xt(), this.#k = t.flipDuration ?? 800, this.#A = t.zoom?.enabled ?? !0, this.#j = t.zoom?.wheel ?? !0;
491
+ this.#a = n, this.#x = (t.deepLink ?? !0) && b(), this.#S = t.disableContextMenu ?? !1, this.#o = t.spreadMode ?? "cover", this.#s = this.#o, this.#c = t.curl ?? "cone", this.#u = t.clickToFlip ?? "edge", this.#d = t.clickZoneSize ?? 64, this.#m = t.singlePageThreshold ?? 640, this.#v = t.responsiveSpread ?? !0, this.#ue = t.controls ?? !0, this.#fe = t.loading ?? !0, this.#b = t.startPage, typeof this.#t.open != "function" && this.#jt(), this.#k = t.flipDuration ?? 800, this.#A = t.zoom?.enabled ?? !0, this.#j = t.zoom?.wheel ?? !0;
487
492
  let r = t.zoom?.doubleClick, i = r === !1 ? [] : [...r ?? [
488
493
  1,
489
494
  2,
@@ -491,10 +496,10 @@ var J = class {
491
496
  ]].sort((e, t) => e - t);
492
497
  this.#M = i.length > 0 ? i : null, this.#N = t.zoom?.max ?? 4;
493
498
  let a = this.#A && this.#M !== null, o = t.zoom?.doubleClickInFlipZone ?? this.#u === "half";
494
- this.#f = this.#u !== "off" && a && o && t.clickFlipDelay !== 0, this.#p = this.#f ? t.clickFlipDelay ?? I : 0, this.#he = this.#Ke(t.renderer ?? "auto");
499
+ this.#f = this.#u !== "off" && a && o && t.clickFlipDelay !== 0, this.#p = this.#f ? t.clickFlipDelay ?? I : 0, this.#ye = this.#Qe(t.renderer ?? "auto");
495
500
  }
496
501
  get ready() {
497
- return this.#he;
502
+ return this.#ye;
498
503
  }
499
504
  getPageCount() {
500
505
  return this.#t.pageCount;
@@ -521,7 +526,7 @@ var J = class {
521
526
  return this.#h;
522
527
  }
523
528
  setSpreadMode(e) {
524
- e !== this.#o && (this.#o = e, this.#_ = !1, this.#at(), this.#ot());
529
+ e !== this.#o && (this.#o = e, this.#_ = !1, this.#ht(), this.#gt());
525
530
  }
526
531
  toggleSpreadMode() {
527
532
  this.setSpreadMode(this.#o === "single" ? this.#s === "single" ? "double" : this.#s : "single");
@@ -537,16 +542,16 @@ var J = class {
537
542
  if (this.#v = e, e) {
538
543
  let e = this.#z?.measure().containerWidth;
539
544
  if (e === void 0) return;
540
- this.#_ = !1, this.#it(e);
545
+ this.#_ = !1, this.#mt(e);
541
546
  } else {
542
547
  if (!this.#_) return;
543
- this.#_ = !1, this.#at();
548
+ this.#_ = !1, this.#ht();
544
549
  }
545
- this.#ot();
550
+ this.#gt();
546
551
  }
547
552
  }
548
553
  getPageImage(e) {
549
- return this.#vt(e);
554
+ return this.#Ot(e);
550
555
  }
551
556
  canFlipNext() {
552
557
  return this.#E + 1 < this.#T.length;
@@ -636,29 +641,29 @@ var J = class {
636
641
  return a;
637
642
  }
638
643
  flipNext() {
639
- this.#ge(1);
644
+ this.#be(1);
640
645
  }
641
646
  flipPrev() {
642
- this.#ge(-1);
647
+ this.#be(-1);
643
648
  }
644
- #ge(e) {
645
- this.#_e(() => this.#xe(this.#E + e));
649
+ #be(e) {
650
+ this.#xe(() => this.#Ee(this.#E + e));
646
651
  }
647
652
  flipTo(e) {
648
653
  let t = Y(e, 0, Math.max(0, this.#t.pageCount - 1));
649
- this.#_e(() => this.#xe(this.#bt(t)));
654
+ this.#xe(() => this.#Ee(this.#At(t)));
650
655
  }
651
- #_e(e) {
652
- this.#i.state === "idle" ? e() : this.#J ? (this.#q = null, this.#ve(), e()) : this.#q = e;
656
+ #xe(e) {
657
+ this.#i.state === "idle" ? e() : this.#J ? (this.#q = null, this.#Se(), e()) : this.#q = e;
653
658
  }
654
- #ve() {
659
+ #Se() {
655
660
  let e = this.#J;
656
661
  e && (this.#J = null, this.#H !== null && (cancelAnimationFrame(this.#H), this.#H = null), this.#z?.setFlipProgress(e.toT, e.direction), e.onDone());
657
662
  }
658
- #ye() {
663
+ #Ce() {
659
664
  let e = this.#q;
660
665
  if (!e) {
661
- this.#mt();
666
+ this.#wt();
662
667
  return;
663
668
  }
664
669
  this.#q = null, e();
@@ -675,12 +680,15 @@ var J = class {
675
680
  x: r.containerWidth / 2,
676
681
  y: r.containerHeight / 2
677
682
  }, o = this.#I, s = n === 1 ? 0 : a.x - n / o * (a.x - this.#L), c = n === 1 ? 0 : a.y - n / o * (a.y - this.#R);
678
- [s, c] = this.#be(s, c, n, r.containerWidth, r.containerHeight), this.#I = n, this.#L = s, this.#R = c, this.#z.setViewTransform(n, s, c), this.#ut(), this.#n.emit("zoomChanged", { scale: n });
683
+ [s, c] = this.#Te(s, c, n, r.containerWidth, r.containerHeight), this.#I = n, this.#L = s, this.#R = c, this.#z.setViewTransform(n, s, c), o > 1 != n > 1 && this.#we(), this.#bt(), this.#n.emit("zoomChanged", { scale: n });
679
684
  }
680
685
  resetZoom() {
681
686
  this.setZoom(1);
682
687
  }
683
- #be(e, t, n, r, i) {
688
+ #we() {
689
+ this.#e.style.touchAction = this.#I > 1 ? "none" : "pan-y";
690
+ }
691
+ #Te(e, t, n, r, i) {
684
692
  let a = typeof devicePixelRatio == "number" && devicePixelRatio > 0 ? devicePixelRatio : 1, o = (e) => Math.round(e * a) / a || 0, s = this.#z?.measure().screenAt?.(n) ?? {
685
693
  x: 0,
686
694
  y: 0,
@@ -693,29 +701,29 @@ var J = class {
693
701
  return this.#n.on(e, t);
694
702
  }
695
703
  destroy() {
696
- this.#V = !0, this.#H !== null && cancelAnimationFrame(this.#H), this.#J = null, this.#q = null, this.#Le(), this.#P?.disconnect(), this.#C?.stop(), this.#C = null, this.#w?.(), this.#x && x(), this.#de?.(), this.#se?.(), this.#ne?.(), this.#ie?.(), this.#re?.(), this.#te?.(), this.#me !== null && clearTimeout(this.#me), this.#pe++, this.#z?.destroy(), this.#z = null, this.#t.destroy(), this.#n.clear();
704
+ this.#V = !0, this.#H !== null && cancelAnimationFrame(this.#H), this.#J = null, this.#q = null, this.#Ue(), this.#P?.disconnect(), this.#C?.stop(), this.#C = null, this.#w?.(), this.#x && x(), this.#de?.(), this.#nt(), this.#se?.(), this.#ne?.(), this.#ie?.(), this.#re?.(), this.#te?.(), this.#ve !== null && clearTimeout(this.#ve), this.#_e++, this.#z?.destroy(), this.#z = null, this.#t.destroy(), this.#n.clear();
697
705
  }
698
- #xe(e) {
706
+ #Ee(e) {
699
707
  if (e < 0 || e >= this.#T.length || e === this.#E || this.#i.send("flip") === null) return;
700
- let t = e > this.#E ? "forward" : "backward", n = this.#Ee(e);
708
+ let t = e > this.#E ? "forward" : "backward", n = this.#je(e);
701
709
  this.#n.emit("flipStart", {
702
710
  from: this.#D,
703
711
  to: n
704
- }), this.#Se(e, t, n, ++this.#Y);
712
+ }), this.#De(e, t, n, ++this.#Y);
705
713
  }
706
- async #Se(e, t, n, r) {
707
- let i = this.#T[e], a = i ? await this.#_t(i) : {
714
+ async #De(e, t, n, r) {
715
+ let i = this.#T[e], a = i ? await this.#Dt(i) : {
708
716
  left: null,
709
717
  right: null
710
718
  };
711
719
  r === this.#Y && (this.#z?.beginFlip(this.#O, a, t, {
712
720
  fill: this.#h,
713
- curl: this.#nt(),
721
+ curl: this.#ft(),
714
722
  anchor: { y: this.#l }
715
- }), this.#Ce(0, 1, t, () => this.#Te(e, n, a), () => this.#we(n)));
723
+ }), this.#Oe(0, 1, t, () => this.#Ae(e, n, a), () => this.#ke(n)));
716
724
  }
717
- #Ce(e, t, n, r, i) {
718
- let a = this.#tt() * Math.abs(t - e);
725
+ #Oe(e, t, n, r, i) {
726
+ let a = this.#dt() * Math.abs(t - e);
719
727
  if (a <= 0) {
720
728
  this.#z?.setFlipProgress(t, n), r();
721
729
  return;
@@ -733,22 +741,22 @@ var J = class {
733
741
  };
734
742
  this.#H = requestAnimationFrame(l);
735
743
  }
736
- #we(e) {
737
- this.#D !== e && (this.#D = e, this.#et(), this.#n.emit("pageChanged", { page: e }));
744
+ #ke(e) {
745
+ this.#D !== e && (this.#D = e, this.#ut(), this.#n.emit("pageChanged", { page: e }));
738
746
  }
739
- #Te(e, t, n) {
747
+ #Ae(e, t, n) {
740
748
  let r = this.#T[e];
741
- this.#E = e, this.#O = n, r && this.#st(r, n), this.#yt(), this.#i.send("settle"), this.#oe = performance.now(), this.#we(t), this.#n.emit("flipEnd", { page: t }), this.#ye();
749
+ this.#E = e, this.#O = n, r && this.#_t(r, n), this.#kt(), this.#i.send("settle"), this.#oe = performance.now(), this.#ke(t), this.#n.emit("flipEnd", { page: t }), this.#Ce();
742
750
  }
743
- #Ee(e) {
751
+ #je(e) {
744
752
  let t = this.#T[e];
745
753
  if (!t) return this.#D;
746
754
  let n = [t.left, t.right].filter((e) => e !== null);
747
755
  return n.length > 0 ? Math.min(...n) : this.#D;
748
756
  }
749
- #De(e, t) {
757
+ #Me(e, t) {
750
758
  if (this.#Z || !this.#z) return;
751
- if (this.#Le(), this.#I > 1) {
759
+ if (this.#Ue(), this.#I > 1) {
752
760
  if (this.#i.send("panStart") === null) return;
753
761
  this.#X = {
754
762
  baseTx: this.#L,
@@ -756,7 +764,7 @@ var J = class {
756
764
  };
757
765
  return;
758
766
  }
759
- let n = this.#Ne(), r = this.#Pe(e, t);
767
+ let n = this.#ze(), r = this.#Be(e, t);
760
768
  this.#G = r;
761
769
  let i = Math.min(n.width, n.height) * N, a = r.x >= 0 && r.x <= n.width && r.y >= 0 && r.y <= n.height, o = r.x <= i || r.x >= n.width - i, s = a && o;
762
770
  if (this.#i.state !== "idle") {
@@ -764,7 +772,7 @@ var J = class {
764
772
  this.#W = null;
765
773
  return;
766
774
  }
767
- this.#ve();
775
+ this.#Se();
768
776
  }
769
777
  if (!s) return;
770
778
  this.#l = Y(r.y / n.height, 0, 1);
@@ -772,11 +780,11 @@ var J = class {
772
780
  u < 0 || u >= this.#T.length || (this.#W = {
773
781
  direction: l ? "forward" : "backward",
774
782
  targetIndex: u,
775
- toPage: this.#Ee(u),
783
+ toPage: this.#je(u),
776
784
  width: n.width
777
785
  });
778
786
  }
779
- #Oe() {
787
+ #Ne() {
780
788
  let e = this.#W;
781
789
  e && (this.#W = null, this.#i.send("grab") !== null && (this.#U = {
782
790
  direction: e.direction,
@@ -791,32 +799,32 @@ var J = class {
791
799
  }, this.#n.emit("flipStart", {
792
800
  from: this.#D,
793
801
  to: e.toPage
794
- }), this.#ke(e.targetIndex, e.direction)));
802
+ }), this.#Pe(e.targetIndex, e.direction)));
795
803
  }
796
- async #ke(e, t) {
797
- let n = this.#T[e], r = n ? await this.#_t(n) : {
804
+ async #Pe(e, t) {
805
+ let n = this.#T[e], r = n ? await this.#Dt(n) : {
798
806
  left: null,
799
807
  right: null
800
808
  };
801
809
  this.#U?.targetIndex === e && (this.#U.toContent = r, this.#z?.beginFlip(this.#O, r, t, {
802
810
  fill: this.#h,
803
- curl: this.#nt(),
811
+ curl: this.#ft(),
804
812
  anchor: { y: this.#l }
805
813
  }), this.#z?.setFlipProgress(this.#U.t, t));
806
814
  }
807
- #Ae(e, t) {
815
+ #Fe(e, t) {
808
816
  if (this.#Z) return;
809
817
  if (this.#X) {
810
818
  if (!this.#z) return;
811
- let n = this.#z.measure(), [r, i] = this.#be(this.#X.baseTx + e, this.#X.baseTy + t, this.#I, n.containerWidth, n.containerHeight);
812
- this.#L = r, this.#R = i, this.#z.setViewTransform(this.#I, r, i), this.#ut();
819
+ let n = this.#z.measure(), [r, i] = this.#Te(this.#X.baseTx + e, this.#X.baseTy + t, this.#I, n.containerWidth, n.containerHeight);
820
+ this.#L = r, this.#R = i, this.#z.setViewTransform(this.#I, r, i), this.#bt();
813
821
  return;
814
822
  }
815
- this.#W && Math.hypot(e, t) > F && this.#Oe();
823
+ this.#W && Math.hypot(e, t) > F && this.#Ne();
816
824
  let n = this.#U;
817
825
  n && (n.t = Y((n.direction === "forward" ? -e : e) / n.width, 0, 1), this.#z?.setFlipProgress(n.t, n.direction));
818
826
  }
819
- #je(e) {
827
+ #Ie(e) {
820
828
  if (this.#Z) return;
821
829
  if (this.#X) {
822
830
  this.#X = null, this.#i.send("panEnd");
@@ -824,28 +832,35 @@ var J = class {
824
832
  }
825
833
  let t = this.#U;
826
834
  if (!t) {
827
- this.#W = null, this.#Me(e);
835
+ this.#W = null, this.#Le(e) || this.#Re(e);
828
836
  return;
829
837
  }
830
838
  this.#U = null, this.#i.send("release");
831
- let n = e.swipe && (t.direction === "forward" ? e.dx < 0 : e.dx > 0);
832
- t.t >= .5 || n ? this.#Ce(t.t, 1, t.direction, () => this.#Te(t.targetIndex, t.toPage, t.toContent), () => this.#we(t.toPage)) : this.#Ce(t.t, 0, t.direction, () => this.#Re());
839
+ let n = e.swipe && Math.abs(e.vx) > Math.abs(e.vy), r = t.direction === "forward" ? e.vx < 0 : e.vx > 0, i = n && r, a = n && !r;
840
+ i || t.t >= .5 && !a ? this.#Oe(t.t, 1, t.direction, () => this.#Ae(t.targetIndex, t.toPage, t.toContent), () => this.#ke(t.toPage)) : this.#Oe(t.t, 0, t.direction, () => this.#We());
841
+ }
842
+ #Le(e) {
843
+ if (this.#I > 1 || !e.swipe || Math.abs(e.dx) <= Math.abs(e.dy)) return !1;
844
+ let t = this.#a === "rtl" ? e.dx > 0 : e.dx < 0, n = t ? "forward" : "backward";
845
+ if (!this.#He(n)) return !1;
846
+ let r = t ? 1 : -1;
847
+ return this.#xe(() => this.#Ee(this.#E + r)), !0;
833
848
  }
834
- #Me(e) {
849
+ #Re(e) {
835
850
  if (this.#u === "off" || this.#I > 1 || !this.#G || Math.abs(e.dx) > F || Math.abs(e.dy) > F) return;
836
- let t = this.#Fe(this.#G);
837
- if (!t || !this.#Ie(t)) return;
838
- this.#l = Y(this.#G.y / this.#Ne().height, 0, 1);
839
- let n = t === "forward" ? 1 : -1, r = () => this.#xe(this.#E + n);
840
- if (this.#Le(), this.#p <= 0) {
841
- this.#_e(r);
851
+ let t = this.#Ve(this.#G);
852
+ if (!t || !this.#He(t)) return;
853
+ this.#l = Y(this.#G.y / this.#ze().height, 0, 1);
854
+ let n = t === "forward" ? 1 : -1, r = () => this.#Ee(this.#E + n);
855
+ if (this.#Ue(), this.#p <= 0) {
856
+ this.#xe(r);
842
857
  return;
843
858
  }
844
859
  this.#K = setTimeout(() => {
845
- this.#K = null, this.#_e(r);
860
+ this.#K = null, this.#xe(r);
846
861
  }, this.#p);
847
862
  }
848
- #Ne() {
863
+ #ze() {
849
864
  let e = this.#z.measure();
850
865
  return e.content ?? e.book ?? {
851
866
  x: 0,
@@ -854,40 +869,40 @@ var J = class {
854
869
  height: e.containerHeight
855
870
  };
856
871
  }
857
- #Pe(e, t) {
858
- let n = this.#e.getBoundingClientRect(), r = this.#Ne();
872
+ #Be(e, t) {
873
+ let n = this.#e.getBoundingClientRect(), r = this.#ze();
859
874
  return {
860
875
  x: e - n.left - r.x,
861
876
  y: t - n.top - r.y
862
877
  };
863
878
  }
864
- #Fe(e) {
879
+ #Ve(e) {
865
880
  if (!this.#z) return null;
866
- let t = this.#Ne().width, n;
881
+ let t = this.#ze().width, n;
867
882
  if (n = this.#u === "half" ? e.x > t / 2 ? "right" : "left" : e.x <= this.#d ? "left" : e.x >= t - this.#d ? "right" : null, !n) return null;
868
883
  let r = this.#a === "rtl" ? "left" : "right";
869
884
  return n === r ? "forward" : "backward";
870
885
  }
871
- #Ie(e) {
886
+ #He(e) {
872
887
  let t = this.#E + (e === "forward" ? 1 : -1);
873
888
  return t >= 0 && t < this.#T.length;
874
889
  }
875
- #Le() {
890
+ #Ue() {
876
891
  this.#K !== null && (clearTimeout(this.#K), this.#K = null);
877
892
  }
878
- #Re() {
893
+ #We() {
879
894
  let e = this.#T[this.#E];
880
- e && this.#st(e, this.#O), this.#i.send("settle"), this.#n.emit("flipEnd", { page: this.#D }), this.#ye();
895
+ e && this.#_t(e, this.#O), this.#i.send("settle"), this.#n.emit("flipEnd", { page: this.#D }), this.#Ce();
881
896
  }
882
- #ze() {
883
- if (this.#W = null, this.#Le(), this.#U) {
897
+ #Ge() {
898
+ if (this.#W = null, this.#Ue(), this.#U) {
884
899
  this.#U = null, this.#i.send("release"), this.#i.send("settle");
885
900
  let e = this.#T[this.#E];
886
- e && this.#st(e, this.#O);
901
+ e && this.#_t(e, this.#O);
887
902
  } else this.#X && (this.#X = null, this.#i.send("panEnd"));
888
903
  this.#Z = !0, this.#Q = this.#I;
889
904
  }
890
- #Be(e, t, n) {
905
+ #Ke(e, t, n) {
891
906
  if (!this.#Z) return;
892
907
  let r = this.#e.getBoundingClientRect();
893
908
  this.setZoom(this.#Q * n, {
@@ -895,15 +910,15 @@ var J = class {
895
910
  y: t - r.top
896
911
  });
897
912
  }
898
- #Ve() {
913
+ #qe() {
899
914
  this.#Z = !1;
900
915
  }
901
- #He() {
916
+ #Je() {
902
917
  if (!this.#S) return;
903
918
  let e = (e) => e.preventDefault();
904
919
  this.#e.addEventListener("contextmenu", e), this.#re = () => this.#e.removeEventListener("contextmenu", e);
905
920
  }
906
- #Ue() {
921
+ #Ye() {
907
922
  let e = (e) => {
908
923
  if (!this.#j || !this.#A || !(e.ctrlKey || e.metaKey)) return;
909
924
  e.preventDefault();
@@ -915,7 +930,7 @@ var J = class {
915
930
  };
916
931
  this.#e.addEventListener("wheel", e, { passive: !1 }), this.#ne = () => this.#e.removeEventListener("wheel", e);
917
932
  }
918
- #We() {
933
+ #Xe() {
919
934
  let e = (e) => {
920
935
  let t = this.#M;
921
936
  if (!this.#A || t === null || !this.#z) return;
@@ -928,45 +943,72 @@ var J = class {
928
943
  };
929
944
  return;
930
945
  }
931
- this.#ae = null, this.#Ge(e.clientX, e.clientY, t);
946
+ this.#ae = null, this.#Ze(e.clientX, e.clientY, t);
932
947
  };
933
948
  this.#e.addEventListener("click", e), this.#ie = () => this.#e.removeEventListener("click", e);
934
949
  }
935
- #Ge(e, t, n) {
950
+ #Ze(e, t, n) {
936
951
  if (this.#I <= 1 && this.#u !== "off" && !this.#f) {
937
- let n = this.#Pe(e, t), r = this.#Fe(n);
938
- if (r !== null && (this.#Ie(r) || performance.now() - this.#oe <= R)) return;
952
+ let n = this.#Be(e, t), r = this.#Ve(n);
953
+ if (r !== null && this.#He(r) || this.#i.state === "animating" || performance.now() - this.#oe <= R) return;
939
954
  }
940
- this.#Le();
955
+ this.#Ue();
941
956
  let r = n.find((e) => e > this.#I + 1e-6) ?? n[0] ?? this.#I, i = this.#e.getBoundingClientRect();
942
957
  this.setZoom(r, {
943
958
  x: e - i.left,
944
959
  y: t - i.top
945
960
  });
946
961
  }
947
- async #Ke(e) {
962
+ async #Qe(e) {
948
963
  let t = k(e);
949
- typeof this.#t.open == "function" && (await this.#t.open(), this.#xt()), this.#t.prefetch([this.#D]);
950
- let n = await t, r = await this.#qe(n);
951
- this.#z = r, this.#t.onPageUpdate?.((e) => this.#lt(e)), this.#it(r.measure().containerWidth);
964
+ if (this.#t.onProgress?.((e) => this.#$e(e)), typeof this.#t.open == "function") {
965
+ this.#et();
966
+ try {
967
+ await this.#t.open(), this.#jt();
968
+ } catch (e) {
969
+ throw this.#nt(), e;
970
+ }
971
+ this.#tt("preparing");
972
+ }
973
+ this.#t.prefetch([this.#D]);
974
+ let n = await t, r = await this.#rt(n);
975
+ this.#z = r, this.#t.onPageUpdate?.((e) => this.#yt(e)), this.#mt(r.measure().containerWidth);
952
976
  let i = new m({
953
- onStart: (e) => this.#De(e.x, e.y),
954
- onMove: (e) => this.#Ae(e.dx, e.dy),
955
- onEnd: (e) => this.#je(e)
977
+ onStart: (e) => this.#Me(e.x, e.y),
978
+ onMove: (e) => this.#Fe(e.dx, e.dy),
979
+ onEnd: (e) => this.#Ie(e)
956
980
  }), a = new _({
957
- onPinchStart: () => this.#ze(),
958
- onPinchMove: (e) => this.#Be(e.centerX, e.centerY, e.scale),
959
- onPinchEnd: () => this.#Ve()
981
+ onPinchStart: () => this.#Ge(),
982
+ onPinchMove: (e) => this.#Ke(e.centerX, e.centerY, e.scale),
983
+ onPinchEnd: () => this.#qe()
960
984
  });
961
985
  this.#te = h(this.#e, {
962
986
  pointer: i,
963
987
  pinch: a
964
- }), this.#Ue(), this.#We(), this.#He(), this.#Ye(), this.#se = this.#Qe(), await this.#ot(), this.#ht(), this.#yt(), this.#et(), this.#Ze(), await this.#Xe(), this.#n.emit("ready");
988
+ }), this.#we(), this.#Ye(), this.#Xe(), this.#Je(), this.#at(), this.#se = this.#ct(), await this.#gt(), this.#nt(), this.#Tt(), this.#kt(), this.#ut(), this.#st(), await this.#ot(), this.#n.emit("ready");
989
+ }
990
+ #$e(e) {
991
+ this.#me = e, this.#n.emit("progress", e), this.#pe?.update(e);
992
+ }
993
+ async #et() {
994
+ if (this.#fe === !1 || this.#V) return;
995
+ let e = this.#e;
996
+ if (!(!e.ownerDocument || typeof e.appendChild != "function")) try {
997
+ let { mountLoading: t } = await import("./loading-C0qbANt2.js");
998
+ if (this.#he === "done" || this.#V) return;
999
+ this.#pe = t(e), this.#me && this.#pe.update(this.#me), this.#he === "preparing" && this.#pe.preparing();
1000
+ } catch {}
965
1001
  }
966
- async #qe(e) {
1002
+ #tt(e) {
1003
+ this.#he !== "done" && (this.#he = e, this.#pe?.preparing());
1004
+ }
1005
+ #nt() {
1006
+ this.#he = "done", this.#pe?.destroy(), this.#pe = null;
1007
+ }
1008
+ async #rt(e) {
967
1009
  try {
968
1010
  return await e.mount(this.#e), e.onFatal?.(() => {
969
- this.#Je();
1011
+ this.#it();
970
1012
  }), e;
971
1013
  } catch {
972
1014
  e.destroy();
@@ -977,7 +1019,7 @@ var J = class {
977
1019
  }), t;
978
1020
  }
979
1021
  }
980
- async #Je() {
1022
+ async #it() {
981
1023
  if (this.#B || this.#V) return;
982
1024
  this.#B = !0, this.#z?.destroy(), this.#z = null;
983
1025
  let e = await k("css");
@@ -985,19 +1027,19 @@ var J = class {
985
1027
  e.destroy();
986
1028
  return;
987
1029
  }
988
- await e.mount(this.#e), this.#z = e, this.#it(e.measure().containerWidth), await this.#ot(), this.#n.emit("rendererFallback", {
1030
+ await e.mount(this.#e), this.#z = e, this.#mt(e.measure().containerWidth), await this.#gt(), this.#n.emit("rendererFallback", {
989
1031
  from: "webgl2",
990
1032
  to: "css"
991
1033
  });
992
1034
  }
993
- #Ye() {
1035
+ #at() {
994
1036
  if (typeof matchMedia != "function") return;
995
1037
  let e = matchMedia("(prefers-reduced-motion: reduce)");
996
1038
  this.#$ = e.matches, e.addEventListener?.("change", (e) => {
997
1039
  this.#$ = e.matches;
998
1040
  });
999
1041
  }
1000
- async #Xe() {
1042
+ async #ot() {
1001
1043
  if (this.#ue === !1 || this.#V) return;
1002
1044
  let e = this.#e;
1003
1045
  if (!(!e.ownerDocument || typeof e.appendChild != "function")) try {
@@ -1007,7 +1049,7 @@ var J = class {
1007
1049
  this.#de = t(this, e, n);
1008
1050
  } catch {}
1009
1051
  }
1010
- #Ze() {
1052
+ #st() {
1011
1053
  if (!this.#x || globalThis.location === void 0) return;
1012
1054
  let e = globalThis;
1013
1055
  this.#C = w(e, (e) => {
@@ -1022,18 +1064,18 @@ var J = class {
1022
1064
  let n = new URL(t);
1023
1065
  return n.hash = C(n.hash, Y(e, 0, Math.max(0, this.#t.pageCount - 1))), n.toString();
1024
1066
  }
1025
- #Qe() {
1067
+ #ct() {
1026
1068
  let e = this.#e, t = e.ownerDocument;
1027
1069
  if (!t || typeof e.setAttribute != "function") return null;
1028
1070
  e.hasAttribute("tabindex") || (e.tabIndex = 0), e.setAttribute("aria-roledescription", "flipbook");
1029
- let n = (e) => this.#$e(e);
1071
+ let n = (e) => this.#lt(e);
1030
1072
  e.addEventListener("keydown", n);
1031
1073
  let r = t.createElement("div");
1032
1074
  return r.setAttribute("aria-live", "polite"), r.setAttribute("aria-atomic", "true"), r.style.cssText = "position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0;", e.appendChild(r), this.#ee = r, () => {
1033
1075
  e.removeEventListener("keydown", n), r.remove(), this.#ee = null;
1034
1076
  };
1035
1077
  }
1036
- #$e(e) {
1078
+ #lt(e) {
1037
1079
  let t = this.#a === "rtl" ? "ArrowLeft" : "ArrowRight";
1038
1080
  switch (e.key) {
1039
1081
  case "ArrowRight":
@@ -1049,70 +1091,70 @@ var J = class {
1049
1091
  default: break;
1050
1092
  }
1051
1093
  }
1052
- #et() {
1094
+ #ut() {
1053
1095
  this.#ee && (this.#ee.textContent = `Page ${this.#D + 1} of ${this.#t.pageCount}`);
1054
1096
  }
1055
- #tt() {
1097
+ #dt() {
1056
1098
  return this.#$ ? W : this.#k * (this.#h ? z : 1);
1057
1099
  }
1058
- #nt() {
1100
+ #ft() {
1059
1101
  return this.#$ ? "simple" : this.#c;
1060
1102
  }
1061
1103
  update() {
1062
- !this.#z || this.#i.state !== "idle" || (this.#it(this.#z.measure().containerWidth), this.#ot());
1104
+ !this.#z || this.#i.state !== "idle" || (this.#mt(this.#z.measure().containerWidth), this.#gt());
1063
1105
  }
1064
- #rt() {
1106
+ #pt() {
1065
1107
  return this.#_ || this.#o === "single" ? "single" : this.#o;
1066
1108
  }
1067
- #it(e) {
1109
+ #mt(e) {
1068
1110
  let t = this.#v && o(e, this.#m);
1069
- t !== this.#_ && (this.#_ = t, this.#at());
1111
+ t !== this.#_ && (this.#_ = t, this.#ht());
1070
1112
  }
1071
- #at() {
1072
- let e = this.#rt(), t = e !== this.#g;
1113
+ #ht() {
1114
+ let e = this.#pt(), t = e !== this.#g;
1073
1115
  this.#g = e, this.#h = e === "single", this.#T = a(this.#t.pageCount, {
1074
1116
  direction: this.#a,
1075
1117
  mode: e
1076
- }), this.#E = this.#bt(this.#D), t && this.#n.emit("spreadChanged", {
1118
+ }), this.#E = this.#At(this.#D), t && this.#n.emit("spreadChanged", {
1077
1119
  mode: e,
1078
1120
  singlePage: this.#h
1079
1121
  });
1080
1122
  }
1081
- async #ot() {
1123
+ async #gt() {
1082
1124
  let e = this.#T[this.#E];
1083
- !e || !this.#z || (this.#O = await this.#_t(e), this.#st(e, this.#O));
1125
+ !e || !this.#z || (this.#O = await this.#Dt(e), this.#_t(e, this.#O));
1084
1126
  }
1085
- #st(e, t) {
1086
- this.#z?.renderSpread(e, t, { fill: this.#h }), this.#ct(), this.#fe = 1, this.#ut();
1127
+ #_t(e, t) {
1128
+ this.#z?.renderSpread(e, t, { fill: this.#h }), this.#vt(), this.#ge = 1, this.#bt();
1087
1129
  }
1088
- #ct() {
1130
+ #vt() {
1089
1131
  let e = this.#z?.measure().book;
1090
1132
  if (!e || e.width <= 0 || e.height <= 0) return;
1091
1133
  let t = (e.width / e.height).toFixed(4);
1092
1134
  t !== this.#y && (this.#y = t, this.#e.style.aspectRatio = t);
1093
1135
  }
1094
- #lt(e) {
1136
+ #yt(e) {
1095
1137
  if (this.#i.state !== "idle") {
1096
1138
  this.#le.add(e);
1097
1139
  return;
1098
1140
  }
1099
1141
  let t = this.#T[this.#E];
1100
- t && (t.left === e || t.right === e) && this.#ot();
1142
+ t && (t.left === e || t.right === e) && this.#gt();
1101
1143
  }
1102
- #ut() {
1103
- this.#me !== null && clearTimeout(this.#me);
1104
- let e = this.#ft();
1105
- if (e !== this.#fe) {
1144
+ #bt() {
1145
+ this.#ve !== null && clearTimeout(this.#ve);
1146
+ let e = this.#St();
1147
+ if (e !== this.#ge) {
1106
1148
  if (e === 1) {
1107
- this.#pe++, this.#fe = 1, this.#ot();
1149
+ this.#_e++, this.#ge = 1, this.#gt();
1108
1150
  return;
1109
1151
  }
1110
- this.#me = setTimeout(() => {
1111
- this.#me = null, this.#pt();
1152
+ this.#ve = setTimeout(() => {
1153
+ this.#ve = null, this.#Ct();
1112
1154
  }, V);
1113
1155
  }
1114
1156
  }
1115
- #dt() {
1157
+ #xt() {
1116
1158
  let e = this.#z?.measure(), t = e?.content ?? e?.book;
1117
1159
  if (!t || t.width <= 0) return 1;
1118
1160
  let n = this.#O, r = +!!n.left + +!!n.right;
@@ -1120,21 +1162,21 @@ var J = class {
1120
1162
  let i = t.width / r, a = typeof devicePixelRatio == "number" && devicePixelRatio > 0 ? devicePixelRatio : 1, o = 0;
1121
1163
  for (let e of [n.left, n.right]) {
1122
1164
  if (!e || e.width <= 0) continue;
1123
- let t = e.width / this.#fe;
1165
+ let t = e.width / this.#ge;
1124
1166
  o = Math.max(o, i * a / t);
1125
1167
  }
1126
1168
  return o === 0 ? 1 : o;
1127
1169
  }
1128
- #ft() {
1129
- let e = Math.max(1, U / (typeof devicePixelRatio == "number" && devicePixelRatio > 0 ? devicePixelRatio : 1)), t = this.#I <= 1 ? 1 : this.#I, n = this.#dt() * Math.max(t, e);
1170
+ #St() {
1171
+ let e = Math.max(1, U / (typeof devicePixelRatio == "number" && devicePixelRatio > 0 ? devicePixelRatio : 1)), t = this.#I <= 1 ? 1 : this.#I, n = this.#xt() * Math.max(t, e);
1130
1172
  return n <= 1.001 ? 1 : Math.min(Math.ceil(n * 2) / 2, H);
1131
1173
  }
1132
- async #pt() {
1174
+ async #Ct() {
1133
1175
  let e = this.#T[this.#E];
1134
1176
  if (!this.#z || !e) return;
1135
- let t = this.#ft();
1136
- if (t === 1 || t === this.#fe || this.#i.state !== "idle") return;
1137
- let n = ++this.#pe, r = {
1177
+ let t = this.#St();
1178
+ if (t === 1 || t === this.#ge || this.#i.state !== "idle") return;
1179
+ let n = ++this.#_e, r = {
1138
1180
  x: 0,
1139
1181
  y: 0,
1140
1182
  width: 1,
@@ -1153,34 +1195,34 @@ var J = class {
1153
1195
  }), null;
1154
1196
  }
1155
1197
  }));
1156
- if (n !== this.#pe || this.#ft() !== t || this.#i.state !== "idle") return;
1198
+ if (n !== this.#_e || this.#St() !== t || this.#i.state !== "idle") return;
1157
1199
  let a = i[0] ?? null, o = i[1] ?? null;
1158
- a === this.#O.left && o === this.#O.right || (this.#fe = t, this.#O = {
1200
+ a === this.#O.left && o === this.#O.right || (this.#ge = t, this.#O = {
1159
1201
  left: a,
1160
1202
  right: o
1161
1203
  }, this.#z.renderSpread(e, this.#O, { fill: this.#h }));
1162
1204
  }
1163
- #mt() {
1205
+ #wt() {
1164
1206
  if (this.#le.size === 0) return;
1165
1207
  let e = this.#T[this.#E], t = e !== void 0 && [e.left, e.right].some((e) => e !== null && this.#le.has(e));
1166
- this.#le.clear(), t && this.#ot();
1208
+ this.#le.clear(), t && this.#gt();
1167
1209
  }
1168
- #ht() {
1169
- typeof ResizeObserver > "u" || (this.#P = new ResizeObserver(() => this.#gt()), this.#P.observe(this.#e));
1210
+ #Tt() {
1211
+ typeof ResizeObserver > "u" || (this.#P = new ResizeObserver(() => this.#Et()), this.#P.observe(this.#e));
1170
1212
  }
1171
- #gt() {
1213
+ #Et() {
1172
1214
  this.#F || (this.#F = !0, requestAnimationFrame(() => {
1173
1215
  this.#F = !1, this.update();
1174
1216
  }));
1175
1217
  }
1176
- async #_t(e) {
1177
- let [t, n] = await Promise.all([this.#vt(e.left), this.#vt(e.right)]);
1218
+ async #Dt(e) {
1219
+ let [t, n] = await Promise.all([this.#Ot(e.left), this.#Ot(e.right)]);
1178
1220
  return {
1179
1221
  left: t,
1180
1222
  right: n
1181
1223
  };
1182
1224
  }
1183
- async #vt(e) {
1225
+ async #Ot(e) {
1184
1226
  if (e === null) return null;
1185
1227
  try {
1186
1228
  return await this.#t.get(e);
@@ -1191,7 +1233,7 @@ var J = class {
1191
1233
  }), null;
1192
1234
  }
1193
1235
  }
1194
- #yt() {
1236
+ #kt() {
1195
1237
  let { toMount: e } = this.#r.update(this.#E, this.#T.length), t = [];
1196
1238
  for (let n of e) {
1197
1239
  let e = this.#T[n];
@@ -1199,22 +1241,22 @@ var J = class {
1199
1241
  }
1200
1242
  this.#t.prefetch(t);
1201
1243
  }
1202
- #bt(e) {
1244
+ #At(e) {
1203
1245
  let t = this.#T.findIndex((t) => t.left === e || t.right === e);
1204
1246
  return t === -1 ? 0 : t;
1205
1247
  }
1206
- #xt() {
1248
+ #jt() {
1207
1249
  let e = this.#t.pageCount;
1208
1250
  if (!Number.isInteger(e) || e < 1) throw Error(`Zine: source has ${e} pages; a Source must have at least 1 page.`);
1209
1251
  let t = this.#b;
1210
1252
  if (t !== void 0 && (!Number.isInteger(t) || t < 0 || t >= e)) throw Error(`Zine: startPage ${JSON.stringify(t)} is out of range for a ${e}-page book (valid 0..${e - 1}).`);
1211
- let n = this.#rt();
1253
+ let n = this.#pt();
1212
1254
  this.#h = n === "single", this.#T = a(e, {
1213
1255
  direction: this.#a,
1214
1256
  mode: n
1215
1257
  });
1216
1258
  let r = this.#x ? S(globalThis.location?.hash ?? "") : null;
1217
- this.#D = Y(r ?? t ?? 0, 0, e - 1), this.#E = this.#bt(this.#D);
1259
+ this.#D = Y(r ?? t ?? 0, 0, e - 1), this.#E = this.#At(this.#D);
1218
1260
  }
1219
1261
  };
1220
1262
  function Y(e, t, n) {
@@ -1261,7 +1303,8 @@ function re(n, r) {
1261
1303
  for (let e of [
1262
1304
  "deepLink",
1263
1305
  "disableContextMenu",
1264
- "responsiveSpread"
1306
+ "responsiveSpread",
1307
+ "loading"
1265
1308
  ]) if (i[e] !== void 0 && typeof i[e] != "boolean") throw Error(`Zine: ${e} must be a boolean; got ${Q(i[e])}.`);
1266
1309
  let u = i.controls;
1267
1310
  if (u !== void 0 && typeof u != "boolean" && (typeof u != "object" || !u)) throw Error(`Zine: controls must be a boolean or an options object; got ${Q(u)}.`);