@zinejs/core 0.7.0 → 0.7.2

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