@zinejs/core 0.7.2 → 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
@@ -245,32 +245,32 @@ var _ = class {
245
245
  };
246
246
  }
247
247
  }, v = "page", y = !1;
248
- function ee() {
248
+ function b() {
249
249
  return y ? !1 : (y = !0, !0);
250
250
  }
251
- function b() {
251
+ function x() {
252
252
  y = !1;
253
253
  }
254
- function x(e) {
254
+ function S(e) {
255
255
  let t = new URLSearchParams(e.replace(/^#/, "")).get(v);
256
256
  if (t === null) return null;
257
257
  let n = Number(t);
258
258
  return Number.isInteger(n) && n >= 1 ? n - 1 : null;
259
259
  }
260
- function S(e, t) {
260
+ function C(e, t) {
261
261
  let n = new URLSearchParams(e.replace(/^#/, ""));
262
262
  return n.set(v, String(t + 1)), `#${n.toString()}`;
263
263
  }
264
- function C(e, t) {
264
+ function w(e, t) {
265
265
  let n = null, r = () => {
266
- let r = x(e.location.hash);
266
+ let r = S(e.location.hash);
267
267
  r === null || r === n || (n = r, t(r));
268
268
  };
269
269
  return e.addEventListener("hashchange", r), {
270
270
  push(t) {
271
271
  if (t === n) return;
272
272
  n = t;
273
- let r = S(e.location.hash, t);
273
+ let r = C(e.location.hash, t);
274
274
  r !== e.location.hash && e.history?.replaceState?.(e.history.state, "", r);
275
275
  },
276
276
  stop() {
@@ -280,49 +280,49 @@ function C(e, t) {
280
280
  }
281
281
  //#endregion
282
282
  //#region src/renderer/select.ts
283
- var w = {
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()
286
- }, T = !0;
287
- function E(e) {
285
+ webgl2: async () => new (await (import("./webglRenderer-nGRruZk2.js"))).WebglRenderer()
286
+ }, E = !0;
287
+ function ee(e) {
288
288
  return typeof e == "object" && !!e && !Array.isArray(e) && typeof e.mount == "function";
289
289
  }
290
- function D(e) {
291
- return e.gpu && T ? ["webgl2", "css"] : ["css"];
290
+ function te(e) {
291
+ return e.gpu && E ? ["webgl2", "css"] : ["css"];
292
292
  }
293
- function O() {
294
- return { gpu: k() };
293
+ function D() {
294
+ return { gpu: O() };
295
295
  }
296
- function k() {
296
+ function O() {
297
297
  try {
298
298
  return !!document.createElement("canvas").getContext("webgl2");
299
299
  } catch {
300
300
  return !1;
301
301
  }
302
302
  }
303
- async function A(e = "auto", t = O()) {
304
- if (E(e)) return e;
305
- let n = Array.isArray(e) ? e : e === "auto" ? D(t) : [e];
303
+ async function k(e = "auto", t = D()) {
304
+ if (ee(e)) return e;
305
+ let n = Array.isArray(e) ? e : e === "auto" ? te(t) : [e];
306
306
  for (let e of n) {
307
307
  if (e === "webgl2" && !t.gpu) continue;
308
- let n = w[e];
308
+ let n = T[e];
309
309
  if (n) return n();
310
310
  }
311
311
  throw n.length === 1 && n[0] === "webgl2" && !t.gpu ? Error("renderer: 'webgl2' was forced but this device has no WebGL2. Use 'css' or 'auto'.") : Error(`renderer: none of [${n.join(", ")}] could be loaded — use 'css' or 'auto'.`);
312
312
  }
313
313
  //#endregion
314
314
  //#region src/source/compose.ts
315
- function j(e, t) {
315
+ function A(e, t) {
316
316
  let n = typeof t.frontCover == "string", r = typeof t.backCover == "string", i = t.pages != null && Object.keys(t.pages).length > 0;
317
- return !n && !r && !i ? e : new N(e, t);
317
+ return !n && !r && !i ? e : new M(e, t);
318
318
  }
319
- function M(e) {
319
+ function j(e) {
320
320
  return fetch(e).then((t) => {
321
321
  if (!t.ok) throw Error(`zine: could not load image "${e}" (HTTP ${t.status}).`);
322
322
  return t.blob();
323
323
  }).then((e) => createImageBitmap(e));
324
324
  }
325
- var N = class {
325
+ var M = class {
326
326
  #e;
327
327
  #t;
328
328
  #n;
@@ -331,6 +331,7 @@ var N = 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 N = 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;
@@ -390,16 +391,16 @@ var N = class {
390
391
  }
391
392
  #s(e) {
392
393
  let t = this.#a.get(e);
393
- return t === void 0 && (t = M(e).catch((t) => {
394
+ return t === void 0 && (t = j(e).catch((t) => {
394
395
  throw this.#a.delete(e), t;
395
396
  }), this.#a.set(e, t)), t;
396
397
  }
397
- }, P = .25, F = .0015, I = 6, L = 250, R = 24, z = 1.55, B = 32, V = 60, H = 2.5, U = 1.5, W = 120;
398
- function G(e, t, n) {
398
+ }, N = .25, P = .0015, F = 6, I = 250, L = 24, R = 2 * I, z = 1.55, B = 32, V = 60, H = 2.5, U = 1.5, W = 120, G = .85, K = .72;
399
+ function q(e, t, n) {
399
400
  let r = Math.max(0, t - B), i = Math.min(e.length, t + n + B), a = e.slice(r, i).replace(/\s+/g, " ").trim();
400
401
  return `${r > 0 ? "…" : ""}${a}${i < e.length ? "…" : ""}`;
401
402
  }
402
- var K = class {
403
+ var J = class {
403
404
  #e;
404
405
  #t;
405
406
  #n = new l();
@@ -463,26 +464,31 @@ var K = class {
463
464
  #re = null;
464
465
  #ie = null;
465
466
  #ae = null;
466
- #oe = null;
467
+ #oe = -Infinity;
467
468
  #se = null;
468
- #ce = /* @__PURE__ */ new Set();
469
- #le;
470
- #ue = null;
471
- #de = 1;
472
- #fe = 0;
469
+ #ce = null;
470
+ #le = /* @__PURE__ */ new Set();
471
+ #ue;
472
+ #de = null;
473
+ #fe;
473
474
  #pe = null;
474
- #me;
475
+ #me = null;
476
+ #he = "download";
477
+ #ge = 1;
478
+ #_e = 0;
479
+ #ve = null;
480
+ #ye;
475
481
  debug = { setFlipProgress: (e, t) => {
476
482
  this.#z?.setFlipProgress(e, t);
477
483
  } };
478
484
  constructor(e, t) {
479
- Q(e, t), this.#e = e, t.width !== void 0 && (e.style.width = `${t.width}px`), t.height !== void 0 && (e.style.height = `${t.height}px`), this.#t = j(t.source, {
485
+ re(e, t), this.#e = e, t.width !== void 0 && (e.style.width = `${t.width}px`), t.height !== void 0 && (e.style.height = `${t.height}px`), this.#t = A(t.source, {
480
486
  frontCover: t.frontCover,
481
487
  backCover: t.backCover,
482
488
  pages: t.pages
483
489
  });
484
490
  let n = t.direction ?? "ltr";
485
- this.#a = n, this.#x = (t.deepLink ?? !0) && ee(), 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.#le = t.controls ?? !0, this.#b = t.startPage, typeof this.#t.open != "function" && this.#yt(), 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;
486
492
  let r = t.zoom?.doubleClick, i = r === !1 ? [] : [...r ?? [
487
493
  1,
488
494
  2,
@@ -490,10 +496,10 @@ var K = class {
490
496
  ]].sort((e, t) => e - t);
491
497
  this.#M = i.length > 0 ? i : null, this.#N = t.zoom?.max ?? 4;
492
498
  let a = this.#A && this.#M !== null, o = t.zoom?.doubleClickInFlipZone ?? this.#u === "half";
493
- this.#f = this.#u !== "off" && a && o && t.clickFlipDelay !== 0, this.#p = this.#f ? t.clickFlipDelay ?? L : 0, this.#me = this.#We(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");
494
500
  }
495
501
  get ready() {
496
- return this.#me;
502
+ return this.#ye;
497
503
  }
498
504
  getPageCount() {
499
505
  return this.#t.pageCount;
@@ -520,7 +526,7 @@ var K = class {
520
526
  return this.#h;
521
527
  }
522
528
  setSpreadMode(e) {
523
- e !== this.#o && (this.#o = e, this.#_ = !1, this.#rt(), this.#it());
529
+ e !== this.#o && (this.#o = e, this.#_ = !1, this.#ht(), this.#gt());
524
530
  }
525
531
  toggleSpreadMode() {
526
532
  this.setSpreadMode(this.#o === "single" ? this.#s === "single" ? "double" : this.#s : "single");
@@ -536,16 +542,16 @@ var K = class {
536
542
  if (this.#v = e, e) {
537
543
  let e = this.#z?.measure().containerWidth;
538
544
  if (e === void 0) return;
539
- this.#_ = !1, this.#nt(e);
545
+ this.#_ = !1, this.#mt(e);
540
546
  } else {
541
547
  if (!this.#_) return;
542
- this.#_ = !1, this.#rt();
548
+ this.#_ = !1, this.#ht();
543
549
  }
544
- this.#it();
550
+ this.#gt();
545
551
  }
546
552
  }
547
553
  getPageImage(e) {
548
- return this.#gt(e);
554
+ return this.#Ot(e);
549
555
  }
550
556
  canFlipNext() {
551
557
  return this.#E + 1 < this.#T.length;
@@ -593,11 +599,11 @@ var K = class {
593
599
  return typeof this.#t.getOutline == "function";
594
600
  }
595
601
  getOutline() {
596
- if (!this.#se) {
602
+ if (!this.#ce) {
597
603
  let e = this.#t.getOutline;
598
- this.#se = typeof e == "function" ? Promise.resolve(e.call(this.#t)).catch(() => []) : Promise.resolve([]);
604
+ this.#ce = typeof e == "function" ? Promise.resolve(e.call(this.#t)).catch(() => []) : Promise.resolve([]);
599
605
  }
600
- return this.#se;
606
+ return this.#ce;
601
607
  }
602
608
  async getSourceFile() {
603
609
  let e = this.#t.getDownload;
@@ -629,35 +635,35 @@ var K = class {
629
635
  let i = t.toLowerCase().indexOf(r);
630
636
  i < 0 || a.push({
631
637
  page: e,
632
- excerpt: G(t, i, r.length)
638
+ excerpt: q(t, i, r.length)
633
639
  });
634
640
  }
635
641
  return a;
636
642
  }
637
643
  flipNext() {
638
- this.#he(1);
644
+ this.#be(1);
639
645
  }
640
646
  flipPrev() {
641
- this.#he(-1);
647
+ this.#be(-1);
642
648
  }
643
- #he(e) {
644
- this.#ge(() => this.#be(this.#E + e));
649
+ #be(e) {
650
+ this.#xe(() => this.#Ee(this.#E + e));
645
651
  }
646
652
  flipTo(e) {
647
- let t = q(e, 0, Math.max(0, this.#t.pageCount - 1));
648
- this.#ge(() => this.#be(this.#vt(t)));
653
+ let t = Y(e, 0, Math.max(0, this.#t.pageCount - 1));
654
+ this.#xe(() => this.#Ee(this.#At(t)));
649
655
  }
650
- #ge(e) {
651
- this.#i.state === "idle" ? e() : this.#J ? (this.#q = null, this.#_e(), e()) : this.#q = e;
656
+ #xe(e) {
657
+ this.#i.state === "idle" ? e() : this.#J ? (this.#q = null, this.#Se(), e()) : this.#q = e;
652
658
  }
653
- #_e() {
659
+ #Se() {
654
660
  let e = this.#J;
655
661
  e && (this.#J = null, this.#H !== null && (cancelAnimationFrame(this.#H), this.#H = null), this.#z?.setFlipProgress(e.toT, e.direction), e.onDone());
656
662
  }
657
- #ve() {
663
+ #Ce() {
658
664
  let e = this.#q;
659
665
  if (!e) {
660
- this.#ft();
666
+ this.#wt();
661
667
  return;
662
668
  }
663
669
  this.#q = null, e();
@@ -667,84 +673,90 @@ var K = class {
667
673
  }
668
674
  setZoom(e, t) {
669
675
  if (!this.#z || !this.#A) return;
670
- let n = q(e, 1, this.#N), r = this.#z.measure(), i = r.screenAt?.(this.#I), a = t ?? (i ? {
676
+ let n = Y(e, 1, this.#N), r = this.#z.measure(), i = r.screenAt?.(this.#I), a = t ?? (i ? {
671
677
  x: i.x + this.#L + i.width / 2,
672
678
  y: i.y + this.#R + i.height / 2
673
679
  } : null) ?? {
674
680
  x: r.containerWidth / 2,
675
681
  y: r.containerHeight / 2
676
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);
677
- [s, c] = this.#ye(s, c, n, r.containerWidth, r.containerHeight), this.#I = n, this.#L = s, this.#R = c, this.#z.setViewTransform(n, s, c), this.#ct(), 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 });
678
684
  }
679
685
  resetZoom() {
680
686
  this.setZoom(1);
681
687
  }
682
- #ye(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) {
683
692
  let a = typeof devicePixelRatio == "number" && devicePixelRatio > 0 ? devicePixelRatio : 1, o = (e) => Math.round(e * a) / a || 0, s = this.#z?.measure().screenAt?.(n) ?? {
684
693
  x: 0,
685
694
  y: 0,
686
695
  width: r * n,
687
696
  height: i * n
688
- }, [c, l] = J(s.x, s.width, r), [u, d] = J(s.y, s.height, i);
689
- return [o(q(e, c, l)), o(q(t, u, d))];
697
+ }, [c, l] = X(s.x, s.width, r), [u, d] = X(s.y, s.height, i);
698
+ return [o(Y(e, c, l)), o(Y(t, u, d))];
690
699
  }
691
700
  on(e, t) {
692
701
  return this.#n.on(e, t);
693
702
  }
694
703
  destroy() {
695
- this.#V = !0, this.#H !== null && cancelAnimationFrame(this.#H), this.#J = null, this.#q = null, this.#Fe(), this.#P?.disconnect(), this.#C?.stop(), this.#C = null, this.#w?.(), this.#x && b(), this.#ue?.(), this.#oe?.(), this.#ne?.(), this.#ie?.(), this.#re?.(), this.#te?.(), this.#pe !== null && clearTimeout(this.#pe), this.#fe++, 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();
696
705
  }
697
- #be(e) {
706
+ #Ee(e) {
698
707
  if (e < 0 || e >= this.#T.length || e === this.#E || this.#i.send("flip") === null) return;
699
- let t = e > this.#E ? "forward" : "backward", n = this.#we(e);
708
+ let t = e > this.#E ? "forward" : "backward", n = this.#je(e);
700
709
  this.#n.emit("flipStart", {
701
710
  from: this.#D,
702
711
  to: n
703
- }), this.#xe(e, t, n, ++this.#Y);
712
+ }), this.#De(e, t, n, ++this.#Y);
704
713
  }
705
- async #xe(e, t, n, r) {
706
- let i = this.#T[e], a = i ? await this.#ht(i) : {
714
+ async #De(e, t, n, r) {
715
+ let i = this.#T[e], a = i ? await this.#Dt(i) : {
707
716
  left: null,
708
717
  right: null
709
718
  };
710
719
  r === this.#Y && (this.#z?.beginFlip(this.#O, a, t, {
711
720
  fill: this.#h,
712
- curl: this.#et(),
721
+ curl: this.#ft(),
713
722
  anchor: { y: this.#l }
714
- }), this.#Se(0, 1, t, () => this.#Ce(e, n, a)));
723
+ }), this.#Oe(0, 1, t, () => this.#Ae(e, n, a), () => this.#ke(n)));
715
724
  }
716
- #Se(e, t, n, r) {
717
- let i = this.#$e() * Math.abs(t - e);
718
- if (i <= 0) {
725
+ #Oe(e, t, n, r, i) {
726
+ let a = this.#dt() * Math.abs(t - e);
727
+ if (a <= 0) {
719
728
  this.#z?.setFlipProgress(t, n), r();
720
729
  return;
721
730
  }
722
- let a = {
731
+ let o = {
723
732
  toT: t,
724
733
  direction: n,
725
734
  onDone: r
726
735
  };
727
- this.#J = a;
728
- let o = performance.now(), s = (c) => {
729
- if (this.#J !== a) return;
730
- let l = Math.min(1, (c - o) / i), u = this.#h ? X(l) : Y(l);
731
- this.#z?.setFlipProgress(e + (t - e) * u, n), l < 1 ? this.#H = requestAnimationFrame(s) : (this.#H = null, this.#J = null, r());
736
+ this.#J = o;
737
+ let s = performance.now(), c = !1, l = (u) => {
738
+ if (this.#J !== o) return;
739
+ let d = Math.min(1, (u - s) / a), f = this.#h ? ne(d) : Z(d);
740
+ i && !c && f >= (this.#h ? K : G) && (c = !0, i()), d < 1 ? (this.#z?.setFlipProgress(e + (t - e) * f, n), this.#H = requestAnimationFrame(l)) : (this.#z?.setFlipProgress(t, n), this.#H = null, this.#J = null, r());
732
741
  };
733
- this.#H = requestAnimationFrame(s);
742
+ this.#H = requestAnimationFrame(l);
743
+ }
744
+ #ke(e) {
745
+ this.#D !== e && (this.#D = e, this.#ut(), this.#n.emit("pageChanged", { page: e }));
734
746
  }
735
- #Ce(e, t, n) {
747
+ #Ae(e, t, n) {
736
748
  let r = this.#T[e];
737
- this.#E = e, this.#D = t, this.#O = n, r && this.#at(r, n), this.#_t(), this.#i.send("settle"), this.#Qe(), this.#n.emit("pageChanged", { page: t }), this.#n.emit("flipEnd", { page: t }), this.#ve();
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();
738
750
  }
739
- #we(e) {
751
+ #je(e) {
740
752
  let t = this.#T[e];
741
753
  if (!t) return this.#D;
742
754
  let n = [t.left, t.right].filter((e) => e !== null);
743
755
  return n.length > 0 ? Math.min(...n) : this.#D;
744
756
  }
745
- #Te(e, t) {
757
+ #Me(e, t) {
746
758
  if (this.#Z || !this.#z) return;
747
- if (this.#Fe(), this.#I > 1) {
759
+ if (this.#Ue(), this.#I > 1) {
748
760
  if (this.#i.send("panStart") === null) return;
749
761
  this.#X = {
750
762
  baseTx: this.#L,
@@ -752,27 +764,27 @@ var K = class {
752
764
  };
753
765
  return;
754
766
  }
755
- let n = this.#je(), r = this.#Me(e, t);
767
+ let n = this.#ze(), r = this.#Be(e, t);
756
768
  this.#G = r;
757
- let i = Math.min(n.width, n.height) * P, 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;
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;
758
770
  if (this.#i.state !== "idle") {
759
771
  if (!this.#J || !s) {
760
772
  this.#W = null;
761
773
  return;
762
774
  }
763
- this.#_e();
775
+ this.#Se();
764
776
  }
765
777
  if (!s) return;
766
- this.#l = q(r.y / n.height, 0, 1);
778
+ this.#l = Y(r.y / n.height, 0, 1);
767
779
  let c = r.x > n.width / 2, l = this.#a === "rtl" ? !c : c, u = this.#E + (l ? 1 : -1);
768
780
  u < 0 || u >= this.#T.length || (this.#W = {
769
781
  direction: l ? "forward" : "backward",
770
782
  targetIndex: u,
771
- toPage: this.#we(u),
783
+ toPage: this.#je(u),
772
784
  width: n.width
773
785
  });
774
786
  }
775
- #Ee() {
787
+ #Ne() {
776
788
  let e = this.#W;
777
789
  e && (this.#W = null, this.#i.send("grab") !== null && (this.#U = {
778
790
  direction: e.direction,
@@ -787,32 +799,32 @@ var K = class {
787
799
  }, this.#n.emit("flipStart", {
788
800
  from: this.#D,
789
801
  to: e.toPage
790
- }), this.#De(e.targetIndex, e.direction)));
802
+ }), this.#Pe(e.targetIndex, e.direction)));
791
803
  }
792
- async #De(e, t) {
793
- let n = this.#T[e], r = n ? await this.#ht(n) : {
804
+ async #Pe(e, t) {
805
+ let n = this.#T[e], r = n ? await this.#Dt(n) : {
794
806
  left: null,
795
807
  right: null
796
808
  };
797
809
  this.#U?.targetIndex === e && (this.#U.toContent = r, this.#z?.beginFlip(this.#O, r, t, {
798
810
  fill: this.#h,
799
- curl: this.#et(),
811
+ curl: this.#ft(),
800
812
  anchor: { y: this.#l }
801
813
  }), this.#z?.setFlipProgress(this.#U.t, t));
802
814
  }
803
- #Oe(e, t) {
815
+ #Fe(e, t) {
804
816
  if (this.#Z) return;
805
817
  if (this.#X) {
806
818
  if (!this.#z) return;
807
- let n = this.#z.measure(), [r, i] = this.#ye(this.#X.baseTx + e, this.#X.baseTy + t, this.#I, n.containerWidth, n.containerHeight);
808
- this.#L = r, this.#R = i, this.#z.setViewTransform(this.#I, r, i), this.#ct();
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();
809
821
  return;
810
822
  }
811
- this.#W && Math.hypot(e, t) > I && this.#Ee();
823
+ this.#W && Math.hypot(e, t) > F && this.#Ne();
812
824
  let n = this.#U;
813
- n && (n.t = q((n.direction === "forward" ? -e : e) / n.width, 0, 1), this.#z?.setFlipProgress(n.t, n.direction));
825
+ n && (n.t = Y((n.direction === "forward" ? -e : e) / n.width, 0, 1), this.#z?.setFlipProgress(n.t, n.direction));
814
826
  }
815
- #ke(e) {
827
+ #Ie(e) {
816
828
  if (this.#Z) return;
817
829
  if (this.#X) {
818
830
  this.#X = null, this.#i.send("panEnd");
@@ -820,28 +832,35 @@ var K = class {
820
832
  }
821
833
  let t = this.#U;
822
834
  if (!t) {
823
- this.#W = null, this.#Ae(e);
835
+ this.#W = null, this.#Le(e) || this.#Re(e);
824
836
  return;
825
837
  }
826
838
  this.#U = null, this.#i.send("release");
827
- let n = e.swipe && (t.direction === "forward" ? e.dx < 0 : e.dx > 0);
828
- t.t >= .5 || n ? this.#Se(t.t, 1, t.direction, () => this.#Ce(t.targetIndex, t.toPage, t.toContent)) : this.#Se(t.t, 0, t.direction, () => this.#Ie());
829
- }
830
- #Ae(e) {
831
- if (this.#u === "off" || this.#I > 1 || !this.#G || Math.abs(e.dx) > I || Math.abs(e.dy) > I) return;
832
- let t = this.#Ne(this.#G);
833
- if (!t || !this.#Pe(t)) return;
834
- this.#l = q(this.#G.y / this.#je().height, 0, 1);
835
- let n = t === "forward" ? 1 : -1, r = () => this.#be(this.#E + n);
836
- if (this.#Fe(), this.#p <= 0) {
837
- this.#ge(r);
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;
848
+ }
849
+ #Re(e) {
850
+ if (this.#u === "off" || this.#I > 1 || !this.#G || Math.abs(e.dx) > F || Math.abs(e.dy) > F) return;
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);
838
857
  return;
839
858
  }
840
859
  this.#K = setTimeout(() => {
841
- this.#K = null, this.#ge(r);
860
+ this.#K = null, this.#xe(r);
842
861
  }, this.#p);
843
862
  }
844
- #je() {
863
+ #ze() {
845
864
  let e = this.#z.measure();
846
865
  return e.content ?? e.book ?? {
847
866
  x: 0,
@@ -850,40 +869,40 @@ var K = class {
850
869
  height: e.containerHeight
851
870
  };
852
871
  }
853
- #Me(e, t) {
854
- let n = this.#e.getBoundingClientRect(), r = this.#je();
872
+ #Be(e, t) {
873
+ let n = this.#e.getBoundingClientRect(), r = this.#ze();
855
874
  return {
856
875
  x: e - n.left - r.x,
857
876
  y: t - n.top - r.y
858
877
  };
859
878
  }
860
- #Ne(e) {
879
+ #Ve(e) {
861
880
  if (!this.#z) return null;
862
- let t = this.#je().width, n;
881
+ let t = this.#ze().width, n;
863
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;
864
883
  let r = this.#a === "rtl" ? "left" : "right";
865
884
  return n === r ? "forward" : "backward";
866
885
  }
867
- #Pe(e) {
886
+ #He(e) {
868
887
  let t = this.#E + (e === "forward" ? 1 : -1);
869
888
  return t >= 0 && t < this.#T.length;
870
889
  }
871
- #Fe() {
890
+ #Ue() {
872
891
  this.#K !== null && (clearTimeout(this.#K), this.#K = null);
873
892
  }
874
- #Ie() {
893
+ #We() {
875
894
  let e = this.#T[this.#E];
876
- e && this.#at(e, this.#O), this.#i.send("settle"), this.#n.emit("flipEnd", { page: this.#D }), this.#ve();
895
+ e && this.#_t(e, this.#O), this.#i.send("settle"), this.#n.emit("flipEnd", { page: this.#D }), this.#Ce();
877
896
  }
878
- #Le() {
879
- if (this.#W = null, this.#Fe(), this.#U) {
897
+ #Ge() {
898
+ if (this.#W = null, this.#Ue(), this.#U) {
880
899
  this.#U = null, this.#i.send("release"), this.#i.send("settle");
881
900
  let e = this.#T[this.#E];
882
- e && this.#at(e, this.#O);
901
+ e && this.#_t(e, this.#O);
883
902
  } else this.#X && (this.#X = null, this.#i.send("panEnd"));
884
903
  this.#Z = !0, this.#Q = this.#I;
885
904
  }
886
- #Re(e, t, n) {
905
+ #Ke(e, t, n) {
887
906
  if (!this.#Z) return;
888
907
  let r = this.#e.getBoundingClientRect();
889
908
  this.setZoom(this.#Q * n, {
@@ -891,19 +910,19 @@ var K = class {
891
910
  y: t - r.top
892
911
  });
893
912
  }
894
- #ze() {
913
+ #qe() {
895
914
  this.#Z = !1;
896
915
  }
897
- #Be() {
916
+ #Je() {
898
917
  if (!this.#S) return;
899
918
  let e = (e) => e.preventDefault();
900
919
  this.#e.addEventListener("contextmenu", e), this.#re = () => this.#e.removeEventListener("contextmenu", e);
901
920
  }
902
- #Ve() {
921
+ #Ye() {
903
922
  let e = (e) => {
904
923
  if (!this.#j || !this.#A || !(e.ctrlKey || e.metaKey)) return;
905
924
  e.preventDefault();
906
- let t = this.#e.getBoundingClientRect(), n = Math.exp(-e.deltaY * F);
925
+ let t = this.#e.getBoundingClientRect(), n = Math.exp(-e.deltaY * P);
907
926
  this.setZoom(this.#I * n, {
908
927
  x: e.clientX - t.left,
909
928
  y: e.clientY - t.top
@@ -911,12 +930,12 @@ var K = class {
911
930
  };
912
931
  this.#e.addEventListener("wheel", e, { passive: !1 }), this.#ne = () => this.#e.removeEventListener("wheel", e);
913
932
  }
914
- #He() {
933
+ #Xe() {
915
934
  let e = (e) => {
916
935
  let t = this.#M;
917
936
  if (!this.#A || t === null || !this.#z) return;
918
937
  let n = performance.now(), r = this.#ae;
919
- if (!(r !== null && n - r.t <= L && Math.hypot(e.clientX - r.x, e.clientY - r.y) <= R)) {
938
+ if (!(r !== null && n - r.t <= I && Math.hypot(e.clientX - r.x, e.clientY - r.y) <= L)) {
920
939
  this.#ae = {
921
940
  t: n,
922
941
  x: e.clientX,
@@ -924,89 +943,116 @@ var K = class {
924
943
  };
925
944
  return;
926
945
  }
927
- this.#ae = null, this.#Ue(e.clientX, e.clientY, t);
946
+ this.#ae = null, this.#Ze(e.clientX, e.clientY, t);
928
947
  };
929
948
  this.#e.addEventListener("click", e), this.#ie = () => this.#e.removeEventListener("click", e);
930
949
  }
931
- #Ue(e, t, n) {
950
+ #Ze(e, t, n) {
932
951
  if (this.#I <= 1 && this.#u !== "off" && !this.#f) {
933
- let n = this.#Me(e, t), r = this.#Ne(n);
934
- if (r !== null && this.#Pe(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;
935
954
  }
936
- this.#Fe();
955
+ this.#Ue();
937
956
  let r = n.find((e) => e > this.#I + 1e-6) ?? n[0] ?? this.#I, i = this.#e.getBoundingClientRect();
938
957
  this.setZoom(r, {
939
958
  x: e - i.left,
940
959
  y: t - i.top
941
960
  });
942
961
  }
943
- async #We(e) {
944
- let t = A(e);
945
- typeof this.#t.open == "function" && (await this.#t.open(), this.#yt()), this.#t.prefetch([this.#D]);
946
- let n = await t, r = await this.#Ge(n);
947
- this.#z = r, this.#t.onPageUpdate?.((e) => this.#st(e)), this.#nt(r.measure().containerWidth);
962
+ async #Qe(e) {
963
+ let t = k(e);
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);
948
976
  let i = new m({
949
- onStart: (e) => this.#Te(e.x, e.y),
950
- onMove: (e) => this.#Oe(e.dx, e.dy),
951
- onEnd: (e) => this.#ke(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)
952
980
  }), a = new _({
953
- onPinchStart: () => this.#Le(),
954
- onPinchMove: (e) => this.#Re(e.centerX, e.centerY, e.scale),
955
- onPinchEnd: () => this.#ze()
981
+ onPinchStart: () => this.#Ge(),
982
+ onPinchMove: (e) => this.#Ke(e.centerX, e.centerY, e.scale),
983
+ onPinchEnd: () => this.#qe()
956
984
  });
957
985
  this.#te = h(this.#e, {
958
986
  pointer: i,
959
987
  pinch: a
960
- }), this.#Ve(), this.#He(), this.#Be(), this.#qe(), this.#oe = this.#Xe(), await this.#it(), this.#pt(), this.#_t(), this.#Qe(), this.#Ye(), await this.#Je(), 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);
961
992
  }
962
- async #Ge(e) {
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 {}
1001
+ }
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) {
963
1009
  try {
964
1010
  return await e.mount(this.#e), e.onFatal?.(() => {
965
- this.#Ke();
1011
+ this.#it();
966
1012
  }), e;
967
1013
  } catch {
968
1014
  e.destroy();
969
- let t = await A("css");
1015
+ let t = await k("css");
970
1016
  return await t.mount(this.#e), this.#B = !0, this.#n.emit("rendererFallback", {
971
1017
  from: "webgl2",
972
1018
  to: "css"
973
1019
  }), t;
974
1020
  }
975
1021
  }
976
- async #Ke() {
1022
+ async #it() {
977
1023
  if (this.#B || this.#V) return;
978
1024
  this.#B = !0, this.#z?.destroy(), this.#z = null;
979
- let e = await A("css");
1025
+ let e = await k("css");
980
1026
  if (this.#V) {
981
1027
  e.destroy();
982
1028
  return;
983
1029
  }
984
- await e.mount(this.#e), this.#z = e, this.#nt(e.measure().containerWidth), await this.#it(), 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", {
985
1031
  from: "webgl2",
986
1032
  to: "css"
987
1033
  });
988
1034
  }
989
- #qe() {
1035
+ #at() {
990
1036
  if (typeof matchMedia != "function") return;
991
1037
  let e = matchMedia("(prefers-reduced-motion: reduce)");
992
1038
  this.#$ = e.matches, e.addEventListener?.("change", (e) => {
993
1039
  this.#$ = e.matches;
994
1040
  });
995
1041
  }
996
- async #Je() {
997
- if (this.#le === !1 || this.#V) return;
1042
+ async #ot() {
1043
+ if (this.#ue === !1 || this.#V) return;
998
1044
  let e = this.#e;
999
1045
  if (!(!e.ownerDocument || typeof e.appendChild != "function")) try {
1000
- let { mountControls: t } = await import("./controls-BrPo8pKL.js");
1046
+ let { mountControls: t } = await import("./controls-Bj72hxVJ.js");
1001
1047
  if (this.#V) return;
1002
- let n = this.#le === !0 ? {} : this.#le;
1003
- this.#ue = t(this, e, n);
1048
+ let n = this.#ue === !0 ? {} : this.#ue;
1049
+ this.#de = t(this, e, n);
1004
1050
  } catch {}
1005
1051
  }
1006
- #Ye() {
1052
+ #st() {
1007
1053
  if (!this.#x || globalThis.location === void 0) return;
1008
1054
  let e = globalThis;
1009
- this.#C = C(e, (e) => {
1055
+ this.#C = w(e, (e) => {
1010
1056
  e !== this.#D && this.flipTo(e);
1011
1057
  }), this.#C.push(this.#D), this.#w = this.#n.on("pageChanged", ({ page: e }) => {
1012
1058
  this.#C?.push(e);
@@ -1016,20 +1062,20 @@ var K = class {
1016
1062
  let t = globalThis.location?.href ?? "";
1017
1063
  if (!t) return "";
1018
1064
  let n = new URL(t);
1019
- return n.hash = S(n.hash, q(e, 0, Math.max(0, this.#t.pageCount - 1))), n.toString();
1065
+ return n.hash = C(n.hash, Y(e, 0, Math.max(0, this.#t.pageCount - 1))), n.toString();
1020
1066
  }
1021
- #Xe() {
1067
+ #ct() {
1022
1068
  let e = this.#e, t = e.ownerDocument;
1023
1069
  if (!t || typeof e.setAttribute != "function") return null;
1024
1070
  e.hasAttribute("tabindex") || (e.tabIndex = 0), e.setAttribute("aria-roledescription", "flipbook");
1025
- let n = (e) => this.#Ze(e);
1071
+ let n = (e) => this.#lt(e);
1026
1072
  e.addEventListener("keydown", n);
1027
1073
  let r = t.createElement("div");
1028
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, () => {
1029
1075
  e.removeEventListener("keydown", n), r.remove(), this.#ee = null;
1030
1076
  };
1031
1077
  }
1032
- #Ze(e) {
1078
+ #lt(e) {
1033
1079
  let t = this.#a === "rtl" ? "ArrowLeft" : "ArrowRight";
1034
1080
  switch (e.key) {
1035
1081
  case "ArrowRight":
@@ -1045,70 +1091,70 @@ var K = class {
1045
1091
  default: break;
1046
1092
  }
1047
1093
  }
1048
- #Qe() {
1094
+ #ut() {
1049
1095
  this.#ee && (this.#ee.textContent = `Page ${this.#D + 1} of ${this.#t.pageCount}`);
1050
1096
  }
1051
- #$e() {
1097
+ #dt() {
1052
1098
  return this.#$ ? W : this.#k * (this.#h ? z : 1);
1053
1099
  }
1054
- #et() {
1100
+ #ft() {
1055
1101
  return this.#$ ? "simple" : this.#c;
1056
1102
  }
1057
1103
  update() {
1058
- !this.#z || this.#i.state !== "idle" || (this.#nt(this.#z.measure().containerWidth), this.#it());
1104
+ !this.#z || this.#i.state !== "idle" || (this.#mt(this.#z.measure().containerWidth), this.#gt());
1059
1105
  }
1060
- #tt() {
1106
+ #pt() {
1061
1107
  return this.#_ || this.#o === "single" ? "single" : this.#o;
1062
1108
  }
1063
- #nt(e) {
1109
+ #mt(e) {
1064
1110
  let t = this.#v && o(e, this.#m);
1065
- t !== this.#_ && (this.#_ = t, this.#rt());
1111
+ t !== this.#_ && (this.#_ = t, this.#ht());
1066
1112
  }
1067
- #rt() {
1068
- let e = this.#tt(), t = e !== this.#g;
1113
+ #ht() {
1114
+ let e = this.#pt(), t = e !== this.#g;
1069
1115
  this.#g = e, this.#h = e === "single", this.#T = a(this.#t.pageCount, {
1070
1116
  direction: this.#a,
1071
1117
  mode: e
1072
- }), this.#E = this.#vt(this.#D), t && this.#n.emit("spreadChanged", {
1118
+ }), this.#E = this.#At(this.#D), t && this.#n.emit("spreadChanged", {
1073
1119
  mode: e,
1074
1120
  singlePage: this.#h
1075
1121
  });
1076
1122
  }
1077
- async #it() {
1123
+ async #gt() {
1078
1124
  let e = this.#T[this.#E];
1079
- !e || !this.#z || (this.#O = await this.#ht(e), this.#at(e, this.#O));
1125
+ !e || !this.#z || (this.#O = await this.#Dt(e), this.#_t(e, this.#O));
1080
1126
  }
1081
- #at(e, t) {
1082
- this.#z?.renderSpread(e, t, { fill: this.#h }), this.#ot(), this.#de = 1, this.#ct();
1127
+ #_t(e, t) {
1128
+ this.#z?.renderSpread(e, t, { fill: this.#h }), this.#vt(), this.#ge = 1, this.#bt();
1083
1129
  }
1084
- #ot() {
1130
+ #vt() {
1085
1131
  let e = this.#z?.measure().book;
1086
1132
  if (!e || e.width <= 0 || e.height <= 0) return;
1087
1133
  let t = (e.width / e.height).toFixed(4);
1088
1134
  t !== this.#y && (this.#y = t, this.#e.style.aspectRatio = t);
1089
1135
  }
1090
- #st(e) {
1136
+ #yt(e) {
1091
1137
  if (this.#i.state !== "idle") {
1092
- this.#ce.add(e);
1138
+ this.#le.add(e);
1093
1139
  return;
1094
1140
  }
1095
1141
  let t = this.#T[this.#E];
1096
- t && (t.left === e || t.right === e) && this.#it();
1142
+ t && (t.left === e || t.right === e) && this.#gt();
1097
1143
  }
1098
- #ct() {
1099
- this.#pe !== null && clearTimeout(this.#pe);
1100
- let e = this.#ut();
1101
- if (e !== this.#de) {
1144
+ #bt() {
1145
+ this.#ve !== null && clearTimeout(this.#ve);
1146
+ let e = this.#St();
1147
+ if (e !== this.#ge) {
1102
1148
  if (e === 1) {
1103
- this.#fe++, this.#de = 1, this.#it();
1149
+ this.#_e++, this.#ge = 1, this.#gt();
1104
1150
  return;
1105
1151
  }
1106
- this.#pe = setTimeout(() => {
1107
- this.#pe = null, this.#dt();
1152
+ this.#ve = setTimeout(() => {
1153
+ this.#ve = null, this.#Ct();
1108
1154
  }, V);
1109
1155
  }
1110
1156
  }
1111
- #lt() {
1157
+ #xt() {
1112
1158
  let e = this.#z?.measure(), t = e?.content ?? e?.book;
1113
1159
  if (!t || t.width <= 0) return 1;
1114
1160
  let n = this.#O, r = +!!n.left + +!!n.right;
@@ -1116,21 +1162,21 @@ var K = class {
1116
1162
  let i = t.width / r, a = typeof devicePixelRatio == "number" && devicePixelRatio > 0 ? devicePixelRatio : 1, o = 0;
1117
1163
  for (let e of [n.left, n.right]) {
1118
1164
  if (!e || e.width <= 0) continue;
1119
- let t = e.width / this.#de;
1165
+ let t = e.width / this.#ge;
1120
1166
  o = Math.max(o, i * a / t);
1121
1167
  }
1122
1168
  return o === 0 ? 1 : o;
1123
1169
  }
1124
- #ut() {
1125
- let e = Math.max(1, U / (typeof devicePixelRatio == "number" && devicePixelRatio > 0 ? devicePixelRatio : 1)), t = this.#I <= 1 ? 1 : this.#I, n = this.#lt() * 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);
1126
1172
  return n <= 1.001 ? 1 : Math.min(Math.ceil(n * 2) / 2, H);
1127
1173
  }
1128
- async #dt() {
1174
+ async #Ct() {
1129
1175
  let e = this.#T[this.#E];
1130
1176
  if (!this.#z || !e) return;
1131
- let t = this.#ut();
1132
- if (t === 1 || t === this.#de) return;
1133
- let n = ++this.#fe, r = {
1177
+ let t = this.#St();
1178
+ if (t === 1 || t === this.#ge || this.#i.state !== "idle") return;
1179
+ let n = ++this.#_e, r = {
1134
1180
  x: 0,
1135
1181
  y: 0,
1136
1182
  width: 1,
@@ -1149,34 +1195,34 @@ var K = class {
1149
1195
  }), null;
1150
1196
  }
1151
1197
  }));
1152
- if (n !== this.#fe || this.#ut() !== t) return;
1198
+ if (n !== this.#_e || this.#St() !== t || this.#i.state !== "idle") return;
1153
1199
  let a = i[0] ?? null, o = i[1] ?? null;
1154
- a === this.#O.left && o === this.#O.right || (this.#de = t, this.#O = {
1200
+ a === this.#O.left && o === this.#O.right || (this.#ge = t, this.#O = {
1155
1201
  left: a,
1156
1202
  right: o
1157
1203
  }, this.#z.renderSpread(e, this.#O, { fill: this.#h }));
1158
1204
  }
1159
- #ft() {
1160
- if (this.#ce.size === 0) return;
1161
- let e = this.#T[this.#E], t = e !== void 0 && [e.left, e.right].some((e) => e !== null && this.#ce.has(e));
1162
- this.#ce.clear(), t && this.#it();
1205
+ #wt() {
1206
+ if (this.#le.size === 0) return;
1207
+ let e = this.#T[this.#E], t = e !== void 0 && [e.left, e.right].some((e) => e !== null && this.#le.has(e));
1208
+ this.#le.clear(), t && this.#gt();
1163
1209
  }
1164
- #pt() {
1165
- typeof ResizeObserver > "u" || (this.#P = new ResizeObserver(() => this.#mt()), this.#P.observe(this.#e));
1210
+ #Tt() {
1211
+ typeof ResizeObserver > "u" || (this.#P = new ResizeObserver(() => this.#Et()), this.#P.observe(this.#e));
1166
1212
  }
1167
- #mt() {
1213
+ #Et() {
1168
1214
  this.#F || (this.#F = !0, requestAnimationFrame(() => {
1169
1215
  this.#F = !1, this.update();
1170
1216
  }));
1171
1217
  }
1172
- async #ht(e) {
1173
- let [t, n] = await Promise.all([this.#gt(e.left), this.#gt(e.right)]);
1218
+ async #Dt(e) {
1219
+ let [t, n] = await Promise.all([this.#Ot(e.left), this.#Ot(e.right)]);
1174
1220
  return {
1175
1221
  left: t,
1176
1222
  right: n
1177
1223
  };
1178
1224
  }
1179
- async #gt(e) {
1225
+ async #Ot(e) {
1180
1226
  if (e === null) return null;
1181
1227
  try {
1182
1228
  return await this.#t.get(e);
@@ -1187,7 +1233,7 @@ var K = class {
1187
1233
  }), null;
1188
1234
  }
1189
1235
  }
1190
- #_t() {
1236
+ #kt() {
1191
1237
  let { toMount: e } = this.#r.update(this.#E, this.#T.length), t = [];
1192
1238
  for (let n of e) {
1193
1239
  let e = this.#T[n];
@@ -1195,45 +1241,45 @@ var K = class {
1195
1241
  }
1196
1242
  this.#t.prefetch(t);
1197
1243
  }
1198
- #vt(e) {
1244
+ #At(e) {
1199
1245
  let t = this.#T.findIndex((t) => t.left === e || t.right === e);
1200
1246
  return t === -1 ? 0 : t;
1201
1247
  }
1202
- #yt() {
1248
+ #jt() {
1203
1249
  let e = this.#t.pageCount;
1204
1250
  if (!Number.isInteger(e) || e < 1) throw Error(`Zine: source has ${e} pages; a Source must have at least 1 page.`);
1205
1251
  let t = this.#b;
1206
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}).`);
1207
- let n = this.#tt();
1253
+ let n = this.#pt();
1208
1254
  this.#h = n === "single", this.#T = a(e, {
1209
1255
  direction: this.#a,
1210
1256
  mode: n
1211
1257
  });
1212
- let r = this.#x ? x(globalThis.location?.hash ?? "") : null;
1213
- this.#D = q(r ?? t ?? 0, 0, e - 1), this.#E = this.#vt(this.#D);
1258
+ let r = this.#x ? S(globalThis.location?.hash ?? "") : null;
1259
+ this.#D = Y(r ?? t ?? 0, 0, e - 1), this.#E = this.#At(this.#D);
1214
1260
  }
1215
1261
  };
1216
- function q(e, t, n) {
1262
+ function Y(e, t, n) {
1217
1263
  return e < t ? t : e > n ? n : e;
1218
1264
  }
1219
- function J(e, t, n) {
1265
+ function X(e, t, n) {
1220
1266
  if (t <= n) {
1221
1267
  let r = (n - t) / 2 - e;
1222
1268
  return [r, r];
1223
1269
  }
1224
1270
  return [n - (e + t), -e];
1225
1271
  }
1226
- function Y(e) {
1272
+ function Z(e) {
1227
1273
  return e < .5 ? 2 * e * e : 1 - (-2 * e + 2) ** 2 / 2;
1228
1274
  }
1229
- function X(e) {
1230
- return 1 - (1 - Y(e)) ** 1.3;
1275
+ function ne(e) {
1276
+ return 1 - (1 - Z(e)) ** 1.3;
1231
1277
  }
1232
- function Z(e) {
1278
+ function Q(e) {
1233
1279
  return e === null ? "null" : Array.isArray(e) ? "array" : typeof e;
1234
1280
  }
1235
- function Q(n, r) {
1236
- if (typeof n != "object" || !n || typeof n.appendChild != "function" || typeof n.addEventListener != "function") throw Error(`Zine: container must be a DOM element; received ${Z(n)}.`);
1281
+ function re(n, r) {
1282
+ if (typeof n != "object" || !n || typeof n.appendChild != "function" || typeof n.addEventListener != "function") throw Error(`Zine: container must be a DOM element; received ${Q(n)}.`);
1237
1283
  if (typeof r != "object" || !r) throw Error("Zine: an options object with a `source` is required.");
1238
1284
  let i = r, a = i.source;
1239
1285
  if (typeof a != "object" || !a || typeof a.get != "function" || typeof a.pageCount != "number") throw Error("Zine: `source` is required and must be a Source, e.g. new ImageSource(urls).");
@@ -1257,10 +1303,11 @@ function Q(n, r) {
1257
1303
  for (let e of [
1258
1304
  "deepLink",
1259
1305
  "disableContextMenu",
1260
- "responsiveSpread"
1261
- ]) if (i[e] !== void 0 && typeof i[e] != "boolean") throw Error(`Zine: ${e} must be a boolean; got ${Z(i[e])}.`);
1306
+ "responsiveSpread",
1307
+ "loading"
1308
+ ]) if (i[e] !== void 0 && typeof i[e] != "boolean") throw Error(`Zine: ${e} must be a boolean; got ${Q(i[e])}.`);
1262
1309
  let u = i.controls;
1263
- if (u !== void 0 && typeof u != "boolean" && (typeof u != "object" || !u)) throw Error(`Zine: controls must be a boolean or an options object; got ${Z(u)}.`);
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)}.`);
1264
1311
  let d = u?.position;
1265
1312
  if (d !== void 0 && ![
1266
1313
  "top",
@@ -1281,12 +1328,12 @@ function Q(n, r) {
1281
1328
  }
1282
1329
  let p = i.pages;
1283
1330
  if (p !== void 0 && (typeof p != "object" || !p || Array.isArray(p))) throw Error("Zine: pages must be an object mapping page indices to image URLs.");
1284
- $(i.width, "width", 1), $(i.height, "height", 1), $(i.flipDuration, "flipDuration", 0), $(i.clickZoneSize, "clickZoneSize", 0), $(i.clickFlipDelay, "clickFlipDelay", 0), $(i.singlePageThreshold, "singlePageThreshold", 0), te(i.zoom), ne(i.renderer);
1331
+ $(i.width, "width", 1), $(i.height, "height", 1), $(i.flipDuration, "flipDuration", 0), $(i.clickZoneSize, "clickZoneSize", 0), $(i.clickFlipDelay, "clickFlipDelay", 0), $(i.singlePageThreshold, "singlePageThreshold", 0), ie(i.zoom), ae(i.renderer);
1285
1332
  }
1286
1333
  function $(e, t, n) {
1287
1334
  if (e !== void 0 && (typeof e != "number" || !Number.isFinite(e) || e < n)) throw Error(`Zine: ${t} must be a number >= ${n}; got ${JSON.stringify(e)}.`);
1288
1335
  }
1289
- function te(e) {
1336
+ function ie(e) {
1290
1337
  if (e === void 0) return;
1291
1338
  if (typeof e != "object" || !e || Array.isArray(e)) throw Error("Zine: zoom must be an object, e.g. { max: 4 }.");
1292
1339
  let t = e;
@@ -1299,7 +1346,7 @@ function te(e) {
1299
1346
  }
1300
1347
  $(t.max, "zoom.max", 1);
1301
1348
  }
1302
- function ne(e) {
1349
+ function ae(e) {
1303
1350
  if (e !== void 0) {
1304
1351
  if (typeof e == "string") {
1305
1352
  if (e !== "auto" && e !== "css" && e !== "webgl2") throw Error(`Zine: renderer '${e}' is not recognized; use 'auto', 'css', 'webgl2', an array of those, or a custom Renderer.`);
@@ -1314,7 +1361,7 @@ function ne(e) {
1314
1361
  }
1315
1362
  //#endregion
1316
1363
  //#region src/source/imageSource.ts
1317
- var re = class {
1364
+ var oe = class {
1318
1365
  pageCount;
1319
1366
  fit;
1320
1367
  #e;
@@ -1351,6 +1398,6 @@ var re = class {
1351
1398
  }
1352
1399
  };
1353
1400
  //#endregion
1354
- export { t as CURL_TYPES, i as DEFAULT_ITEMS, e as IMPORTABLE_CURLS, re as ImageSource, K as Zine, n as defineControl, r as getControl };
1401
+ export { t as CURL_TYPES, i as DEFAULT_ITEMS, e as IMPORTABLE_CURLS, oe as ImageSource, J as Zine, n as defineControl, r as getControl };
1355
1402
 
1356
1403
  //# sourceMappingURL=index.js.map