@zinejs/core 0.6.0 → 0.7.1

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
@@ -1,7 +1,7 @@
1
- import { t as e } from "./types-CcPVyhOJ.js";
2
- import { n as t, r as n, t as r } from "./registry-5nuYFMd4.js";
1
+ import { r as e, t } from "./types-DEz3mRLI.js";
2
+ import { n, r, t as i } from "./registry-5nuYFMd4.js";
3
3
  //#region src/engine/spread.ts
4
- function i(e, t = {}) {
4
+ function a(e, t = {}) {
5
5
  let { direction: n = "ltr", mode: r = "cover" } = t;
6
6
  if (e <= 0) return [];
7
7
  let i = (t) => t >= 0 && t < e ? t : null, a = [];
@@ -40,17 +40,17 @@ function i(e, t = {}) {
40
40
  right: e.left
41
41
  })) : a;
42
42
  }
43
- function a(e, t) {
43
+ function o(e, t) {
44
44
  return e < t;
45
45
  }
46
46
  //#endregion
47
47
  //#region src/engine/virtualizer.ts
48
- function o(e, t, n) {
48
+ function s(e, t, n) {
49
49
  let r = [], i = Math.max(0, e - n), a = Math.min(t - 1, e + n);
50
50
  for (let e = i; e <= a; e++) r.push(e);
51
51
  return r;
52
52
  }
53
- var s = class {
53
+ var c = class {
54
54
  #e;
55
55
  #t = /* @__PURE__ */ new Set();
56
56
  constructor(e = 2) {
@@ -60,7 +60,7 @@ var s = class {
60
60
  return [...this.#t].sort((e, t) => e - t);
61
61
  }
62
62
  update(e, t) {
63
- let n = new Set(o(e, t, this.#e)), r = [...n].filter((e) => !this.#t.has(e)).sort((e, t) => e - t), i = [...this.#t].filter((e) => !n.has(e)).sort((e, t) => e - t);
63
+ let n = new Set(s(e, t, this.#e)), r = [...n].filter((e) => !this.#t.has(e)).sort((e, t) => e - t), i = [...this.#t].filter((e) => !n.has(e)).sort((e, t) => e - t);
64
64
  for (let e of i) this.#t.delete(e);
65
65
  for (let e of r) this.#t.add(e);
66
66
  return {
@@ -68,7 +68,7 @@ var s = class {
68
68
  toEvict: i
69
69
  };
70
70
  }
71
- }, c = class {
71
+ }, l = class {
72
72
  #e = /* @__PURE__ */ new Map();
73
73
  on(e, t) {
74
74
  let n = this.#e.get(e);
@@ -84,7 +84,7 @@ var s = class {
84
84
  clear() {
85
85
  this.#e.clear();
86
86
  }
87
- }, l = {
87
+ }, u = {
88
88
  idle: {
89
89
  grab: "dragging",
90
90
  panStart: "zoomed-panning",
@@ -94,10 +94,10 @@ var s = class {
94
94
  animating: { settle: "idle" },
95
95
  "zoomed-panning": { panEnd: "idle" }
96
96
  };
97
- function u(e, t) {
98
- return l[e][t] ?? null;
97
+ function d(e, t) {
98
+ return u[e][t] ?? null;
99
99
  }
100
- var d = class {
100
+ var f = class {
101
101
  #e;
102
102
  constructor(e = "idle") {
103
103
  this.#e = e;
@@ -106,10 +106,10 @@ var d = class {
106
106
  return this.#e;
107
107
  }
108
108
  send(e) {
109
- let t = u(this.#e, e);
109
+ let t = d(this.#e, e);
110
110
  return t !== null && (this.#e = t), t;
111
111
  }
112
- }, f = .3, p = class {
112
+ }, p = .3, m = class {
113
113
  #e;
114
114
  #t = null;
115
115
  #n = null;
@@ -164,7 +164,7 @@ var d = class {
164
164
  dt: r - a.t,
165
165
  vx: l,
166
166
  vy: u,
167
- swipe: !i && d > f,
167
+ swipe: !i && d > p,
168
168
  canceled: i
169
169
  });
170
170
  }
@@ -172,7 +172,7 @@ var d = class {
172
172
  this.#t = null, this.#n = null, this.#r = null, this.#i = null;
173
173
  }
174
174
  };
175
- function m(e, t) {
175
+ function h(e, t) {
176
176
  let { pointer: n, pinch: r } = t, i = (e) => {
177
177
  let t = e;
178
178
  n?.down(t.pointerId, t.clientX, t.clientY, t.timeStamp), r?.down(t.pointerId, t.clientX, t.clientY);
@@ -190,10 +190,10 @@ function m(e, t) {
190
190
  e.removeEventListener("pointerdown", i), e.removeEventListener("pointermove", a), e.removeEventListener("pointerup", o), e.removeEventListener("pointercancel", s);
191
191
  };
192
192
  }
193
- function h(e, t) {
193
+ function g(e, t) {
194
194
  return Math.hypot(e.x - t.x, e.y - t.y);
195
195
  }
196
- var g = class {
196
+ var _ = class {
197
197
  #e;
198
198
  #t = /* @__PURE__ */ new Map();
199
199
  #n = 0;
@@ -210,7 +210,7 @@ var g = class {
210
210
  y: n
211
211
  }), this.#t.size === 2)) {
212
212
  let { a: e, b: t } = this.#a();
213
- this.#n = h(e, t), this.#r = !0, this.#e.onPinchStart?.({
213
+ this.#n = g(e, t), this.#r = !0, this.#e.onPinchStart?.({
214
214
  centerX: (e.x + t.x) / 2,
215
215
  centerY: (e.y + t.y) / 2,
216
216
  distance: this.#n
@@ -224,7 +224,7 @@ var g = class {
224
224
  this.#e.onPinchMove?.({
225
225
  centerX: (i.x + a.x) / 2,
226
226
  centerY: (i.y + a.y) / 2,
227
- scale: this.#n > 0 ? h(i, a) / this.#n : 1
227
+ scale: this.#n > 0 ? g(i, a) / this.#n : 1
228
228
  });
229
229
  }
230
230
  up(e) {
@@ -247,7 +247,7 @@ var g = class {
247
247
  };
248
248
  //#endregion
249
249
  //#region src/geometry/hitTest.ts
250
- function _(e, t, n) {
250
+ function v(e, t, n) {
251
251
  let { width: r, height: i } = t;
252
252
  if (e.x < 0 || e.x > r || e.y < 0 || e.y > i) return "outside";
253
253
  let a = e.x <= n || e.x >= r - n, o = e.y <= n || e.y >= i - n;
@@ -255,33 +255,33 @@ function _(e, t, n) {
255
255
  }
256
256
  //#endregion
257
257
  //#region src/engine/deeplink.ts
258
- var v = "page", y = !1;
259
- function b() {
260
- return y ? !1 : (y = !0, !0);
261
- }
258
+ var y = "page", b = !1;
262
259
  function x() {
263
- y = !1;
260
+ return b ? !1 : (b = !0, !0);
264
261
  }
265
- function S(e) {
266
- let t = new URLSearchParams(e.replace(/^#/, "")).get(v);
262
+ function S() {
263
+ b = !1;
264
+ }
265
+ function C(e) {
266
+ let t = new URLSearchParams(e.replace(/^#/, "")).get(y);
267
267
  if (t === null) return null;
268
268
  let n = Number(t);
269
269
  return Number.isInteger(n) && n >= 1 ? n - 1 : null;
270
270
  }
271
- function C(e, t) {
271
+ function w(e, t) {
272
272
  let n = new URLSearchParams(e.replace(/^#/, ""));
273
- return n.set(v, String(t + 1)), `#${n.toString()}`;
273
+ return n.set(y, String(t + 1)), `#${n.toString()}`;
274
274
  }
275
- function w(e, t) {
275
+ function T(e, t) {
276
276
  let n = null, r = () => {
277
- let r = S(e.location.hash);
277
+ let r = C(e.location.hash);
278
278
  r === null || r === n || (n = r, t(r));
279
279
  };
280
280
  return e.addEventListener("hashchange", r), {
281
281
  push(t) {
282
282
  if (t === n) return;
283
283
  n = t;
284
- let r = C(e.location.hash, t);
284
+ let r = w(e.location.hash, t);
285
285
  r !== e.location.hash && e.history?.replaceState?.(e.history.state, "", r);
286
286
  },
287
287
  stop() {
@@ -291,127 +291,49 @@ function w(e, t) {
291
291
  }
292
292
  //#endregion
293
293
  //#region src/renderer/select.ts
294
- var T = {
295
- css: async () => new (await (import("./cssRenderer-OzRRoEa4.js"))).CssRenderer(),
296
- webgl2: async () => new (await (import("./webglRenderer-BK-ArG1G.js"))).WebglRenderer()
297
- }, E = !0;
298
- function D(e) {
299
- return typeof e == "object" && !!e && !Array.isArray(e) && typeof e.mount == "function";
300
- }
294
+ var E = {
295
+ css: async () => new (await (import("./cssRenderer-Deskm2ND.js"))).CssRenderer(),
296
+ webgl2: async () => new (await (import("./webglRenderer-D_XGumQT.js"))).WebglRenderer()
297
+ }, D = !0;
301
298
  function O(e) {
302
- return e.gpu && E ? ["webgl2", "css"] : ["css"];
299
+ return typeof e == "object" && !!e && !Array.isArray(e) && typeof e.mount == "function";
303
300
  }
304
- function k() {
305
- return { gpu: A() };
301
+ function k(e) {
302
+ return e.gpu && D ? ["webgl2", "css"] : ["css"];
306
303
  }
307
304
  function A() {
305
+ return { gpu: j() };
306
+ }
307
+ function j() {
308
308
  try {
309
309
  return !!document.createElement("canvas").getContext("webgl2");
310
310
  } catch {
311
311
  return !1;
312
312
  }
313
313
  }
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];
314
+ async function M(e = "auto", t = A()) {
315
+ if (O(e)) return e;
316
+ let n = Array.isArray(e) ? e : e === "auto" ? k(t) : [e];
317
317
  for (let e of n) {
318
318
  if (e === "webgl2" && !t.gpu) continue;
319
- let n = T[e];
319
+ let n = E[e];
320
320
  if (n) return n();
321
321
  }
322
322
  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
323
  }
324
324
  //#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
325
  //#region src/source/compose.ts
404
- function I(e, t) {
326
+ function N(e, t) {
405
327
  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);
328
+ return !n && !r && !i ? e : new F(e, t);
407
329
  }
408
- function L(e) {
330
+ function P(e) {
409
331
  return fetch(e).then((t) => {
410
332
  if (!t.ok) throw Error(`zine: could not load image "${e}" (HTTP ${t.status}).`);
411
333
  return t.blob();
412
334
  }).then((e) => createImageBitmap(e));
413
335
  }
414
- var R = class {
336
+ var F = class {
415
337
  #e;
416
338
  #t;
417
339
  #n;
@@ -479,21 +401,21 @@ var R = class {
479
401
  }
480
402
  #s(e) {
481
403
  let t = this.#a.get(e);
482
- return t === void 0 && (t = L(e).catch((t) => {
404
+ return t === void 0 && (t = P(e).catch((t) => {
483
405
  throw this.#a.delete(e), t;
484
406
  }), this.#a.set(e, t)), t;
485
407
  }
486
- }, z = .25, B = .0015, V = 6, H = 250, U = 1.55, W = 32, G = 120;
487
- function K(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();
408
+ }, I = .25, L = .0015, R = 6, z = 250, B = 1.55, V = 32, H = 60, U = 2.5, W = 120;
409
+ function G(e, t, n) {
410
+ let r = Math.max(0, t - V), i = Math.min(e.length, t + n + V), a = e.slice(r, i).replace(/\s+/g, " ").trim();
489
411
  return `${r > 0 ? "…" : ""}${a}${i < e.length ? "…" : ""}`;
490
412
  }
491
- var q = class {
413
+ var K = class {
492
414
  #e;
493
415
  #t;
494
- #n = new c();
495
- #r = new s(2);
496
- #i = new d();
416
+ #n = new l();
417
+ #r = new c(2);
418
+ #i = new f();
497
419
  #a;
498
420
  #o;
499
421
  #s;
@@ -556,7 +478,7 @@ var q = class {
556
478
  #se = /* @__PURE__ */ new Set();
557
479
  #ce;
558
480
  #le = null;
559
- #ue = null;
481
+ #ue = 1;
560
482
  #de = 0;
561
483
  #fe = null;
562
484
  #pe;
@@ -564,13 +486,13 @@ var q = class {
564
486
  this.#z?.setFlipProgress(e, t);
565
487
  } };
566
488
  constructor(e, t) {
567
- 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 = I(t.source, {
489
+ 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 = N(t.source, {
568
490
  frontCover: t.frontCover,
569
491
  backCover: t.backCover,
570
492
  pages: t.pages
571
493
  });
572
494
  let n = t.direction ?? "ltr";
573
- 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.#ce = t.controls ?? !0, this.#b = t.startPage, typeof this.#t.open != "function" && this.#mt(), this.#k = t.flipDuration ?? 800, this.#A = t.zoom?.enabled ?? !0, this.#j = t.zoom?.wheel ?? !0;
495
+ 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;
574
496
  let r = t.zoom?.doubleClick, i = r === !1 ? [] : [...r ?? [
575
497
  1,
576
498
  2,
@@ -578,7 +500,7 @@ var q = class {
578
500
  ]].sort((e, t) => e - t);
579
501
  this.#M = i.length > 0 ? i : null, this.#N = t.zoom?.max ?? 4;
580
502
  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");
503
+ this.#f = this.#u !== "off" && a && o && t.clickFlipDelay !== 0, this.#p = this.#f ? t.clickFlipDelay ?? z : 0, this.#pe = this.#Ve(t.renderer ?? "auto");
582
504
  }
583
505
  get ready() {
584
506
  return this.#pe;
@@ -608,7 +530,7 @@ var q = class {
608
530
  return this.#h;
609
531
  }
610
532
  setSpreadMode(e) {
611
- e !== this.#o && (this.#o = e, this.#_ = !1, this.#$e(), this.#et());
533
+ e !== this.#o && (this.#o = e, this.#_ = !1, this.#et(), this.#tt());
612
534
  }
613
535
  toggleSpreadMode() {
614
536
  this.setSpreadMode(this.#o === "single" ? this.#s === "single" ? "double" : this.#s : "single");
@@ -624,16 +546,16 @@ var q = class {
624
546
  if (this.#v = e, e) {
625
547
  let e = this.#z?.measure().containerWidth;
626
548
  if (e === void 0) return;
627
- this.#_ = !1, this.#Qe(e);
549
+ this.#_ = !1, this.#$e(e);
628
550
  } else {
629
551
  if (!this.#_) return;
630
- this.#_ = !1, this.#$e();
552
+ this.#_ = !1, this.#et();
631
553
  }
632
- this.#et();
554
+ this.#tt();
633
555
  }
634
556
  }
635
557
  getPageImage(e) {
636
- return this.#dt(e);
558
+ return this.#ft(e);
637
559
  }
638
560
  canFlipNext() {
639
561
  return this.#E + 1 < this.#T.length;
@@ -717,7 +639,7 @@ var q = class {
717
639
  let i = t.toLowerCase().indexOf(r);
718
640
  i < 0 || a.push({
719
641
  page: e,
720
- excerpt: K(t, i, r.length)
642
+ excerpt: G(t, i, r.length)
721
643
  });
722
644
  }
723
645
  return a;
@@ -732,8 +654,8 @@ var q = class {
732
654
  this.#he(() => this.#ye(this.#E + e));
733
655
  }
734
656
  flipTo(e) {
735
- let t = J(e, 0, Math.max(0, this.#t.pageCount - 1));
736
- this.#he(() => this.#ye(this.#pt(t)));
657
+ let t = q(e, 0, Math.max(0, this.#t.pageCount - 1));
658
+ this.#he(() => this.#ye(this.#mt(t)));
737
659
  }
738
660
  #he(e) {
739
661
  this.#i.state === "idle" ? e() : this.#J ? (this.#q = null, this.#ge(), e()) : this.#q = e;
@@ -745,7 +667,7 @@ var q = class {
745
667
  #_e() {
746
668
  let e = this.#q;
747
669
  if (!e) {
748
- this.#st();
670
+ this.#ct();
749
671
  return;
750
672
  }
751
673
  this.#q = null, e();
@@ -755,23 +677,32 @@ var q = class {
755
677
  }
756
678
  setZoom(e, t) {
757
679
  if (!this.#z || !this.#A) return;
758
- let n = J(e, 1, this.#N), r = this.#z.measure(), i = t ?? {
680
+ let n = q(e, 1, this.#N), r = this.#z.measure(), i = r.screenAt?.(this.#I), a = t ?? (i ? {
681
+ x: i.x + this.#L + i.width / 2,
682
+ y: i.y + this.#R + i.height / 2
683
+ } : null) ?? {
759
684
  x: r.containerWidth / 2,
760
685
  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.#it(), this.#n.emit("zoomChanged", { scale: n });
686
+ }, 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);
687
+ [s, c] = this.#ve(s, c, n, r.containerWidth, r.containerHeight), this.#I = n, this.#L = s, this.#R = c, this.#z.setViewTransform(n, s, c), this.#at(), this.#n.emit("zoomChanged", { scale: n });
763
688
  }
764
689
  resetZoom() {
765
690
  this.setZoom(1);
766
691
  }
767
692
  #ve(e, t, n, r, i) {
768
- return [J(e, r * (1 - n), 0), J(t, i * (1 - n), 0)];
693
+ let a = typeof devicePixelRatio == "number" && devicePixelRatio > 0 ? devicePixelRatio : 1, o = (e) => Math.round(e * a) / a || 0, s = this.#z?.measure().screenAt?.(n) ?? {
694
+ x: 0,
695
+ y: 0,
696
+ width: r * n,
697
+ height: i * n
698
+ }, [c, l] = J(s.x, s.width, r), [u, d] = J(s.y, s.height, i);
699
+ return [o(q(e, c, l)), o(q(t, u, d))];
769
700
  }
770
701
  on(e, t) {
771
702
  return this.#n.on(e, t);
772
703
  }
773
704
  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 && x(), 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();
705
+ 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.#z?.destroy(), this.#z = null, this.#t.destroy(), this.#n.clear();
775
706
  }
776
707
  #ye(e) {
777
708
  if (e < 0 || e >= this.#T.length || e === this.#E || this.#i.send("flip") === null) return;
@@ -782,13 +713,13 @@ var q = class {
782
713
  }), this.#be(e, t, n, ++this.#Y);
783
714
  }
784
715
  async #be(e, t, n, r) {
785
- let i = this.#T[e], a = i ? await this.#ut(i) : {
716
+ let i = this.#T[e], a = i ? await this.#dt(i) : {
786
717
  left: null,
787
718
  right: null
788
719
  };
789
720
  r === this.#Y && (this.#z?.beginFlip(this.#O, a, t, {
790
721
  fill: this.#h,
791
- curl: this.#c,
722
+ curl: this.#Ze(),
792
723
  anchor: { y: this.#l }
793
724
  }), this.#xe(0, 1, t, () => this.#Se(e, n, a)));
794
725
  }
@@ -813,7 +744,7 @@ var q = class {
813
744
  }
814
745
  #Se(e, t, n) {
815
746
  let r = this.#T[e];
816
- this.#E = e, this.#D = t, this.#O = n, r && this.#tt(r, n), this.#ft(), this.#i.send("settle"), this.#Ye(), this.#n.emit("pageChanged", { page: t }), this.#n.emit("flipEnd", { page: t }), this.#_e();
747
+ 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();
817
748
  }
818
749
  #Ce(e) {
819
750
  let t = this.#T[e];
@@ -836,12 +767,12 @@ var q = class {
836
767
  this.#W = null;
837
768
  return;
838
769
  }
839
- let i = Math.min(n.width, n.height) * z;
840
- if (_(r, {
770
+ let i = Math.min(n.width, n.height) * I;
771
+ if (v(r, {
841
772
  width: n.width,
842
773
  height: n.height
843
774
  }, i) !== "corner") return;
844
- this.#l = J(r.y / n.height, 0, 1);
775
+ this.#l = q(r.y / n.height, 0, 1);
845
776
  let a = r.x > n.width / 2, o = this.#a === "rtl" ? !a : a, s = this.#E + (o ? 1 : -1);
846
777
  s < 0 || s >= this.#T.length || (this.#W = {
847
778
  direction: o ? "forward" : "backward",
@@ -868,13 +799,13 @@ var q = class {
868
799
  }), this.#Ee(e.targetIndex, e.direction)));
869
800
  }
870
801
  async #Ee(e, t) {
871
- let n = this.#T[e], r = n ? await this.#ut(n) : {
802
+ let n = this.#T[e], r = n ? await this.#dt(n) : {
872
803
  left: null,
873
804
  right: null
874
805
  };
875
806
  this.#U?.targetIndex === e && (this.#U.toContent = r, this.#z?.beginFlip(this.#O, r, t, {
876
807
  fill: this.#h,
877
- curl: this.#c,
808
+ curl: this.#Ze(),
878
809
  anchor: { y: this.#l }
879
810
  }), this.#z?.setFlipProgress(this.#U.t, t));
880
811
  }
@@ -883,12 +814,12 @@ var q = class {
883
814
  if (this.#X) {
884
815
  if (!this.#z) return;
885
816
  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.#it();
817
+ this.#L = r, this.#R = i, this.#z.setViewTransform(this.#I, r, i), this.#at();
887
818
  return;
888
819
  }
889
- this.#W && Math.hypot(e, t) > V && this.#Te();
820
+ this.#W && Math.hypot(e, t) > R && this.#Te();
890
821
  let n = this.#U;
891
- n && (n.t = J((n.direction === "forward" ? -e : e) / n.width, 0, 1), this.#z?.setFlipProgress(n.t, n.direction));
822
+ n && (n.t = q((n.direction === "forward" ? -e : e) / n.width, 0, 1), this.#z?.setFlipProgress(n.t, n.direction));
892
823
  }
893
824
  #Oe(e) {
894
825
  if (this.#Z) return;
@@ -906,12 +837,12 @@ var q = class {
906
837
  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
838
  }
908
839
  #ke(e) {
909
- if (this.#u === "off" || this.#I > 1 || !this.#G || Math.abs(e.dx) > V || Math.abs(e.dy) > V) return;
840
+ if (this.#u === "off" || this.#I > 1 || !this.#G || Math.abs(e.dx) > R || Math.abs(e.dy) > R) return;
910
841
  let t = this.#Me(this.#G);
911
842
  if (!t) return;
912
843
  let n = t === "forward" ? 1 : -1;
913
844
  if (this.#E + n < 0 || this.#E + n >= this.#T.length) return;
914
- this.#l = J(this.#G.y / this.#Ae().height, 0, 1);
845
+ this.#l = q(this.#G.y / this.#Ae().height, 0, 1);
915
846
  let r = () => this.#ye(this.#E + n);
916
847
  if (this.#Ne(), this.#p <= 0) {
917
848
  this.#he(r);
@@ -949,13 +880,13 @@ var q = class {
949
880
  }
950
881
  #Pe() {
951
882
  let e = this.#T[this.#E];
952
- e && this.#tt(e, this.#O), this.#i.send("settle"), this.#n.emit("flipEnd", { page: this.#D }), this.#_e();
883
+ e && this.#nt(e, this.#O), this.#i.send("settle"), this.#n.emit("flipEnd", { page: this.#D }), this.#_e();
953
884
  }
954
885
  #Fe() {
955
886
  if (this.#W = null, this.#Ne(), this.#U) {
956
887
  this.#U = null, this.#i.send("release"), this.#i.send("settle");
957
888
  let e = this.#T[this.#E];
958
- e && this.#tt(e, this.#O);
889
+ e && this.#nt(e, this.#O);
959
890
  } else this.#X && (this.#X = null, this.#i.send("panEnd"));
960
891
  this.#Z = !0, this.#Q = this.#I;
961
892
  }
@@ -979,7 +910,7 @@ var q = class {
979
910
  let e = (e) => {
980
911
  if (!this.#j || !this.#A || !(e.ctrlKey || e.metaKey)) return;
981
912
  e.preventDefault();
982
- let t = this.#e.getBoundingClientRect(), n = Math.exp(-e.deltaY * B);
913
+ let t = this.#e.getBoundingClientRect(), n = Math.exp(-e.deltaY * L);
983
914
  this.setZoom(this.#I * n, {
984
915
  x: e.clientX - t.left,
985
916
  y: e.clientY - t.top
@@ -1005,23 +936,23 @@ var q = class {
1005
936
  this.#e.addEventListener("dblclick", e), this.#ie = () => this.#e.removeEventListener("dblclick", e);
1006
937
  }
1007
938
  async #Ve(e) {
1008
- let t = j(e);
1009
- typeof this.#t.open == "function" && (await this.#t.open(), this.#mt()), this.#t.prefetch([this.#D]);
939
+ let t = M(e);
940
+ typeof this.#t.open == "function" && (await this.#t.open(), this.#ht()), this.#t.prefetch([this.#D]);
1010
941
  let n = await t, r = await this.#He(n);
1011
- this.#z = r, this.#t.onPageUpdate?.((e) => this.#rt(e)), this.#Qe(r.measure().containerWidth);
1012
- let i = new p({
942
+ this.#z = r, this.#t.onPageUpdate?.((e) => this.#it(e)), this.#$e(r.measure().containerWidth);
943
+ let i = new m({
1013
944
  onStart: (e) => this.#we(e.x, e.y),
1014
945
  onMove: (e) => this.#De(e.dx, e.dy),
1015
946
  onEnd: (e) => this.#Oe(e)
1016
- }), a = new g({
947
+ }), a = new _({
1017
948
  onPinchStart: () => this.#Fe(),
1018
949
  onPinchMove: (e) => this.#Ie(e.centerX, e.centerY, e.scale),
1019
950
  onPinchEnd: () => this.#Le()
1020
951
  });
1021
- this.#te = m(this.#e, {
952
+ this.#te = h(this.#e, {
1022
953
  pointer: i,
1023
954
  pinch: a
1024
- }), this.#ze(), this.#Be(), this.#Re(), this.#We(), this.#ae = this.#qe(), await this.#et(), this.#ct(), this.#ft(), this.#Ye(), this.#Ke(), await this.#Ge(), this.#n.emit("ready");
955
+ }), 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");
1025
956
  }
1026
957
  async #He(e) {
1027
958
  try {
@@ -1030,7 +961,7 @@ var q = class {
1030
961
  }), e;
1031
962
  } catch {
1032
963
  e.destroy();
1033
- let t = await j("css");
964
+ let t = await M("css");
1034
965
  return await t.mount(this.#e), this.#B = !0, this.#n.emit("rendererFallback", {
1035
966
  from: "webgl2",
1036
967
  to: "css"
@@ -1040,12 +971,12 @@ var q = class {
1040
971
  async #Ue() {
1041
972
  if (this.#B || this.#V) return;
1042
973
  this.#B = !0, this.#z?.destroy(), this.#z = null;
1043
- let e = await j("css");
974
+ let e = await M("css");
1044
975
  if (this.#V) {
1045
976
  e.destroy();
1046
977
  return;
1047
978
  }
1048
- await e.mount(this.#e), this.#z = e, this.#Qe(e.measure().containerWidth), await this.#et(), this.#n.emit("rendererFallback", {
979
+ await e.mount(this.#e), this.#z = e, this.#$e(e.measure().containerWidth), await this.#tt(), this.#n.emit("rendererFallback", {
1049
980
  from: "webgl2",
1050
981
  to: "css"
1051
982
  });
@@ -1070,7 +1001,7 @@ var q = class {
1070
1001
  #Ke() {
1071
1002
  if (!this.#x || globalThis.location === void 0) return;
1072
1003
  let e = globalThis;
1073
- this.#C = w(e, (e) => {
1004
+ this.#C = T(e, (e) => {
1074
1005
  e !== this.#D && this.flipTo(e);
1075
1006
  }), this.#C.push(this.#D), this.#w = this.#n.on("pageChanged", ({ page: e }) => {
1076
1007
  this.#C?.push(e);
@@ -1080,7 +1011,7 @@ var q = class {
1080
1011
  let t = globalThis.location?.href ?? "";
1081
1012
  if (!t) return "";
1082
1013
  let n = new URL(t);
1083
- return n.hash = C(n.hash, J(e, 0, Math.max(0, this.#t.pageCount - 1))), n.toString();
1014
+ return n.hash = w(n.hash, q(e, 0, Math.max(0, this.#t.pageCount - 1))), n.toString();
1084
1015
  }
1085
1016
  #qe() {
1086
1017
  let e = this.#e, t = e.ownerDocument;
@@ -1113,132 +1044,120 @@ var q = class {
1113
1044
  this.#ee && (this.#ee.textContent = `Page ${this.#D + 1} of ${this.#t.pageCount}`);
1114
1045
  }
1115
1046
  #Xe() {
1116
- return this.#$ ? 0 : this.#k * (this.#h ? U : 1);
1047
+ return this.#$ ? W : this.#k * (this.#h ? B : 1);
1048
+ }
1049
+ #Ze() {
1050
+ return this.#$ ? "simple" : this.#c;
1117
1051
  }
1118
1052
  update() {
1119
- !this.#z || this.#i.state !== "idle" || (this.#Qe(this.#z.measure().containerWidth), this.#et());
1053
+ !this.#z || this.#i.state !== "idle" || (this.#$e(this.#z.measure().containerWidth), this.#tt());
1120
1054
  }
1121
- #Ze() {
1055
+ #Qe() {
1122
1056
  return this.#_ || this.#o === "single" ? "single" : this.#o;
1123
1057
  }
1124
- #Qe(e) {
1125
- let t = this.#v && a(e, this.#m);
1126
- t !== this.#_ && (this.#_ = t, this.#$e());
1058
+ #$e(e) {
1059
+ let t = this.#v && o(e, this.#m);
1060
+ t !== this.#_ && (this.#_ = t, this.#et());
1127
1061
  }
1128
- #$e() {
1129
- let e = this.#Ze(), t = e !== this.#g;
1130
- this.#g = e, this.#h = e === "single", this.#T = i(this.#t.pageCount, {
1062
+ #et() {
1063
+ let e = this.#Qe(), t = e !== this.#g;
1064
+ this.#g = e, this.#h = e === "single", this.#T = a(this.#t.pageCount, {
1131
1065
  direction: this.#a,
1132
1066
  mode: e
1133
- }), this.#E = this.#pt(this.#D), t && this.#n.emit("spreadChanged", {
1067
+ }), this.#E = this.#mt(this.#D), t && this.#n.emit("spreadChanged", {
1134
1068
  mode: e,
1135
1069
  singlePage: this.#h
1136
1070
  });
1137
1071
  }
1138
- async #et() {
1072
+ async #tt() {
1139
1073
  let e = this.#T[this.#E];
1140
- !e || !this.#z || (this.#O = await this.#ut(e), this.#tt(e, this.#O));
1074
+ !e || !this.#z || (this.#O = await this.#dt(e), this.#nt(e, this.#O));
1141
1075
  }
1142
- #tt(e, t) {
1143
- this.#z?.renderSpread(e, t, { fill: this.#h }), this.#nt(), this.#ue?.clear(), this.#it();
1076
+ #nt(e, t) {
1077
+ this.#z?.renderSpread(e, t, { fill: this.#h }), this.#rt(), this.#ue = 1, this.#at();
1144
1078
  }
1145
- #nt() {
1079
+ #rt() {
1146
1080
  let e = this.#z?.measure().book;
1147
1081
  if (!e || e.width <= 0 || e.height <= 0) return;
1148
1082
  let t = (e.width / e.height).toFixed(4);
1149
1083
  t !== this.#y && (this.#y = t, this.#e.style.aspectRatio = t);
1150
1084
  }
1151
- #rt(e) {
1085
+ #it(e) {
1152
1086
  if (this.#i.state !== "idle") {
1153
1087
  this.#se.add(e);
1154
1088
  return;
1155
1089
  }
1156
1090
  let t = this.#T[this.#E];
1157
- t && (t.left === e || t.right === e) && this.#et();
1158
- }
1159
- #it() {
1160
- if (this.#fe !== null && clearTimeout(this.#fe), this.#I <= 1) {
1161
- this.#ue?.clear(), this.#de++;
1162
- return;
1163
- }
1164
- this.#fe = setTimeout(() => {
1165
- this.#fe = null, this.#at();
1166
- }, G);
1167
- }
1168
- async #at() {
1169
- let e = this.#z, t = this.#T[this.#E];
1170
- if (!e || !t || this.#I <= 1) return;
1171
- let n = e.measure(), r = n.content ?? n.book;
1172
- if (!r) return;
1173
- let i = [], a = t.left === null || t.right === null, o = a ? r.width : r.width / 2;
1174
- t.left !== null && i.push({
1175
- index: t.left,
1176
- rect: {
1177
- ...r,
1178
- width: o
1091
+ t && (t.left === e || t.right === e) && this.#tt();
1092
+ }
1093
+ #at() {
1094
+ this.#fe !== null && clearTimeout(this.#fe);
1095
+ let e = this.#ot();
1096
+ if (e !== this.#ue) {
1097
+ if (e === 1) {
1098
+ this.#de++, this.#ue = 1, this.#tt();
1099
+ return;
1179
1100
  }
1180
- }), t.right !== null && i.push({
1181
- index: t.right,
1182
- rect: {
1183
- ...r,
1184
- x: r.x + (a ? 0 : o),
1185
- width: o
1186
- }
1187
- });
1188
- let s = {
1189
- scale: this.#I,
1190
- tx: this.#L,
1191
- ty: this.#R
1192
- }, c = {
1101
+ this.#fe = setTimeout(() => {
1102
+ this.#fe = null, this.#st();
1103
+ }, H);
1104
+ }
1105
+ }
1106
+ #ot() {
1107
+ return this.#I <= 1 ? 1 : Math.min(Math.ceil(this.#I * 2) / 2, U);
1108
+ }
1109
+ async #st() {
1110
+ let e = this.#T[this.#E];
1111
+ if (!this.#z || !e) return;
1112
+ let t = this.#ot();
1113
+ if (t === 1 || t === this.#ue) return;
1114
+ let n = ++this.#de, r = {
1193
1115
  x: 0,
1194
1116
  y: 0,
1195
- width: n.containerWidth,
1196
- height: n.containerHeight
1197
- }, l = N(i, s, c), u = this.#ue?.shown ?? [];
1198
- if (l.length === u.length && l.every((e, t) => P(e, u[t]))) return;
1199
- let d = ++this.#de, f = await Promise.all(l.map(async (e) => {
1117
+ width: 1,
1118
+ height: 1
1119
+ }, i = await Promise.all([e.left, e.right].map(async (e) => {
1120
+ if (e === null) return null;
1200
1121
  try {
1201
- let t = await this.#t.get(e.index, e.request), n = e.dest.width / e.dest.height * 1, r = t.width / t.height;
1202
- return Math.abs(n - r) / n > .02 ? null : {
1203
- plan: e,
1204
- content: t
1205
- };
1122
+ return await this.#t.get(e, {
1123
+ scale: t,
1124
+ region: r
1125
+ });
1206
1126
  } catch (t) {
1207
1127
  return this.#n.emit("sourceError", {
1208
- index: e.index,
1128
+ index: e,
1209
1129
  error: t
1210
1130
  }), null;
1211
1131
  }
1212
1132
  }));
1213
- if (d !== this.#de || this.#I <= 1) return;
1214
- let p = f.filter((e) => e !== null);
1215
- p.length !== 0 && (this.#ue ??= this.#ot(), this.#ue?.draw(p, s, c));
1216
- }
1217
- #ot() {
1218
- let e = this.#e.ownerDocument;
1219
- return !e || typeof this.#e.append != "function" ? null : new F(e, this.#e);
1133
+ if (n !== this.#de || this.#ot() !== t) return;
1134
+ let a = i[0] ?? null, o = i[1] ?? null;
1135
+ a === this.#O.left && o === this.#O.right || (this.#ue = t, this.#O = {
1136
+ left: a,
1137
+ right: o
1138
+ }, this.#z.renderSpread(e, this.#O, { fill: this.#h }));
1220
1139
  }
1221
- #st() {
1140
+ #ct() {
1222
1141
  if (this.#se.size === 0) return;
1223
1142
  let e = this.#T[this.#E], t = e !== void 0 && [e.left, e.right].some((e) => e !== null && this.#se.has(e));
1224
- this.#se.clear(), t && this.#et();
1225
- }
1226
- #ct() {
1227
- typeof ResizeObserver > "u" || (this.#P = new ResizeObserver(() => this.#lt()), this.#P.observe(this.#e));
1143
+ this.#se.clear(), t && this.#tt();
1228
1144
  }
1229
1145
  #lt() {
1146
+ typeof ResizeObserver > "u" || (this.#P = new ResizeObserver(() => this.#ut()), this.#P.observe(this.#e));
1147
+ }
1148
+ #ut() {
1230
1149
  this.#F || (this.#F = !0, requestAnimationFrame(() => {
1231
1150
  this.#F = !1, this.update();
1232
1151
  }));
1233
1152
  }
1234
- async #ut(e) {
1235
- let [t, n] = await Promise.all([this.#dt(e.left), this.#dt(e.right)]);
1153
+ async #dt(e) {
1154
+ let [t, n] = await Promise.all([this.#ft(e.left), this.#ft(e.right)]);
1236
1155
  return {
1237
1156
  left: t,
1238
1157
  right: n
1239
1158
  };
1240
1159
  }
1241
- async #dt(e) {
1160
+ async #ft(e) {
1242
1161
  if (e === null) return null;
1243
1162
  try {
1244
1163
  return await this.#t.get(e);
@@ -1249,7 +1168,7 @@ var q = class {
1249
1168
  }), null;
1250
1169
  }
1251
1170
  }
1252
- #ft() {
1171
+ #pt() {
1253
1172
  let { toMount: e } = this.#r.update(this.#E, this.#T.length), t = [];
1254
1173
  for (let n of e) {
1255
1174
  let e = this.#T[n];
@@ -1257,27 +1176,34 @@ var q = class {
1257
1176
  }
1258
1177
  this.#t.prefetch(t);
1259
1178
  }
1260
- #pt(e) {
1179
+ #mt(e) {
1261
1180
  let t = this.#T.findIndex((t) => t.left === e || t.right === e);
1262
1181
  return t === -1 ? 0 : t;
1263
1182
  }
1264
- #mt() {
1183
+ #ht() {
1265
1184
  let e = this.#t.pageCount;
1266
1185
  if (!Number.isInteger(e) || e < 1) throw Error(`Zine: source has ${e} pages; a Source must have at least 1 page.`);
1267
1186
  let t = this.#b;
1268
1187
  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}).`);
1269
- let n = this.#Ze();
1270
- this.#h = n === "single", this.#T = i(e, {
1188
+ let n = this.#Qe();
1189
+ this.#h = n === "single", this.#T = a(e, {
1271
1190
  direction: this.#a,
1272
1191
  mode: n
1273
1192
  });
1274
- let r = this.#x ? S(globalThis.location?.hash ?? "") : null;
1275
- this.#D = J(r ?? t ?? 0, 0, e - 1), this.#E = this.#pt(this.#D);
1193
+ let r = this.#x ? C(globalThis.location?.hash ?? "") : null;
1194
+ this.#D = q(r ?? t ?? 0, 0, e - 1), this.#E = this.#mt(this.#D);
1276
1195
  }
1277
1196
  };
1278
- function J(e, t, n) {
1197
+ function q(e, t, n) {
1279
1198
  return e < t ? t : e > n ? n : e;
1280
1199
  }
1200
+ function J(e, t, n) {
1201
+ if (t <= n) {
1202
+ let r = (n - t) / 2 - e;
1203
+ return [r, r];
1204
+ }
1205
+ return [n - (e + t), -e];
1206
+ }
1281
1207
  function Y(e) {
1282
1208
  return e < .5 ? 2 * e * e : 1 - (-2 * e + 2) ** 2 / 2;
1283
1209
  }
@@ -1287,51 +1213,56 @@ function X(e) {
1287
1213
  function Z(e) {
1288
1214
  return e === null ? "null" : Array.isArray(e) ? "array" : typeof e;
1289
1215
  }
1290
- function Q(t, n) {
1291
- if (typeof t != "object" || !t || typeof t.appendChild != "function" || typeof t.addEventListener != "function") throw Error(`Zine: container must be a DOM element; received ${Z(t)}.`);
1292
- if (typeof n != "object" || !n) throw Error("Zine: an options object with a `source` is required.");
1293
- let r = n, i = r.source;
1294
- if (typeof i != "object" || !i || typeof i.get != "function" || typeof i.pageCount != "number") throw Error("Zine: `source` is required and must be a Source, e.g. new ImageSource(urls).");
1295
- let a = r.startPage;
1296
- if (a !== void 0 && (typeof a != "number" || !Number.isInteger(a) || a < 0)) throw Error(`Zine: startPage must be a non-negative integer; got ${JSON.stringify(a)}.`);
1297
- let o = r.direction;
1298
- if (o !== void 0 && o !== "ltr" && o !== "rtl") throw Error(`Zine: direction must be 'ltr' or 'rtl'; got ${JSON.stringify(o)}.`);
1299
- let s = r.clickToFlip;
1300
- if (s !== void 0 && ![
1216
+ function Q(n, r) {
1217
+ 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)}.`);
1218
+ if (typeof r != "object" || !r) throw Error("Zine: an options object with a `source` is required.");
1219
+ let i = r, a = i.source;
1220
+ 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).");
1221
+ let o = i.startPage;
1222
+ if (o !== void 0 && (typeof o != "number" || !Number.isInteger(o) || o < 0)) throw Error(`Zine: startPage must be a non-negative integer; got ${JSON.stringify(o)}.`);
1223
+ let s = i.direction;
1224
+ if (s !== void 0 && s !== "ltr" && s !== "rtl") throw Error(`Zine: direction must be 'ltr' or 'rtl'; got ${JSON.stringify(s)}.`);
1225
+ let c = i.clickToFlip;
1226
+ if (c !== void 0 && ![
1301
1227
  "edge",
1302
1228
  "half",
1303
1229
  "off"
1304
- ].includes(s)) throw Error(`Zine: clickToFlip must be 'edge', 'half', or 'off'; got ${JSON.stringify(s)}.`);
1305
- let c = r.curl;
1306
- if (c !== void 0 && !e.includes(c)) throw Error(`Zine: curl must be one of ${e.join(", ")}; got ${JSON.stringify(c)}.`);
1230
+ ].includes(c)) throw Error(`Zine: clickToFlip must be 'edge', 'half', or 'off'; got ${JSON.stringify(c)}.`);
1231
+ let l = i.curl;
1232
+ if (l !== void 0) {
1233
+ if (typeof l == "object" && l) {
1234
+ if (typeof l.deform != "function") throw Error("Zine: a curl model must have a deform() function.");
1235
+ } else if (e.includes(l)) throw Error(`Zine: the '${String(l)}' curl is not bundled. Import it and pass the model: import { ${String(l)} } from '@zinejs/core/curls' → curl: ${String(l)}`);
1236
+ else if (!t.includes(l)) throw Error(`Zine: curl must be ${t.join(" or ")}, or a model imported from '@zinejs/core/curls' (${e.join(", ")}); got ${JSON.stringify(l)}.`);
1237
+ }
1307
1238
  for (let e of [
1308
1239
  "deepLink",
1309
1240
  "disableContextMenu",
1310
1241
  "responsiveSpread"
1311
- ]) if (r[e] !== void 0 && typeof r[e] != "boolean") throw Error(`Zine: ${e} must be a boolean; got ${Z(r[e])}.`);
1312
- let l = r.controls;
1313
- if (l !== void 0 && typeof l != "boolean" && (typeof l != "object" || !l)) throw Error(`Zine: controls must be a boolean or an options object; got ${Z(l)}.`);
1314
- let u = l?.position;
1315
- if (u !== void 0 && ![
1242
+ ]) if (i[e] !== void 0 && typeof i[e] != "boolean") throw Error(`Zine: ${e} must be a boolean; got ${Z(i[e])}.`);
1243
+ let u = i.controls;
1244
+ 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)}.`);
1245
+ let d = u?.position;
1246
+ if (d !== void 0 && ![
1316
1247
  "top",
1317
1248
  "bottom",
1318
1249
  "left",
1319
1250
  "right"
1320
- ].includes(u)) throw Error(`Zine: controls.position must be 'top', 'bottom', 'left', or 'right'; got ${JSON.stringify(u)}.`);
1321
- let d = r.spreadMode;
1322
- if (d !== void 0 && ![
1251
+ ].includes(d)) throw Error(`Zine: controls.position must be 'top', 'bottom', 'left', or 'right'; got ${JSON.stringify(d)}.`);
1252
+ let f = i.spreadMode;
1253
+ if (f !== void 0 && ![
1323
1254
  "double",
1324
1255
  "single",
1325
1256
  "cover",
1326
1257
  "book"
1327
- ].includes(d)) throw Error(`Zine: spreadMode must be 'double', 'single', 'cover', or 'book'; got ${JSON.stringify(d)}.`);
1258
+ ].includes(f)) throw Error(`Zine: spreadMode must be 'double', 'single', 'cover', or 'book'; got ${JSON.stringify(f)}.`);
1328
1259
  for (let e of ["frontCover", "backCover"]) {
1329
- let t = r[e];
1260
+ let t = i[e];
1330
1261
  if (t !== void 0 && typeof t != "string") throw Error(`Zine: ${e} must be an image URL string; got ${JSON.stringify(t)}.`);
1331
1262
  }
1332
- let f = r.pages;
1333
- if (f !== void 0 && (typeof f != "object" || !f || Array.isArray(f))) throw Error("Zine: pages must be an object mapping page indices to image URLs.");
1334
- $(r.width, "width", 1), $(r.height, "height", 1), $(r.flipDuration, "flipDuration", 0), $(r.clickZoneSize, "clickZoneSize", 0), $(r.clickFlipDelay, "clickFlipDelay", 0), $(r.singlePageThreshold, "singlePageThreshold", 0), ee(r.zoom), te(r.renderer);
1263
+ let p = i.pages;
1264
+ 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.");
1265
+ $(i.width, "width", 1), $(i.height, "height", 1), $(i.flipDuration, "flipDuration", 0), $(i.clickZoneSize, "clickZoneSize", 0), $(i.clickFlipDelay, "clickFlipDelay", 0), $(i.singlePageThreshold, "singlePageThreshold", 0), ee(i.zoom), te(i.renderer);
1335
1266
  }
1336
1267
  function $(e, t, n) {
1337
1268
  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)}.`);
@@ -1401,6 +1332,6 @@ var ne = class {
1401
1332
  }
1402
1333
  };
1403
1334
  //#endregion
1404
- export { e as CURL_TYPES, r as DEFAULT_ITEMS, ne as ImageSource, q as Zine, t as defineControl, n as getControl };
1335
+ export { t as CURL_TYPES, i as DEFAULT_ITEMS, e as IMPORTABLE_CURLS, ne as ImageSource, K as Zine, n as defineControl, r as getControl };
1405
1336
 
1406
1337
  //# sourceMappingURL=index.js.map