@zinejs/core 0.1.0 → 0.2.0

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,41 +1,55 @@
1
+ import { t as e } from "./types-Bz64qLvE.js";
1
2
  //#region src/engine/spread.ts
2
- function e(e, t = {}) {
3
- let { direction: n = "ltr", cover: r = !1, singlePage: i = !1 } = t;
3
+ function t(e, t = {}) {
4
+ let { direction: n = "ltr", mode: r = "cover" } = t;
4
5
  if (e <= 0) return [];
5
- let a = (t) => t >= 0 && t < e ? t : null, o = [];
6
- if (i) for (let t = 0; t < e; t++) o.push({
6
+ let i = (t) => t >= 0 && t < e ? t : null, a = [];
7
+ if (r === "single") for (let t = 0; t < e; t++) a.push({
7
8
  left: null,
8
9
  right: t
9
10
  });
10
- else if (r) {
11
- o.push({
11
+ else if (r === "double") for (let t = 0; t < e; t += 2) a.push({
12
+ left: i(t),
13
+ right: i(t + 1)
14
+ });
15
+ else if (r === "cover") {
16
+ a.push({
12
17
  left: null,
13
18
  right: 0
14
19
  });
15
- for (let t = 1; t < e; t += 2) o.push({
16
- left: a(t),
17
- right: a(t + 1)
20
+ for (let t = 1; t < e; t += 2) a.push({
21
+ left: i(t),
22
+ right: i(t + 1)
18
23
  });
19
- } else for (let t = 0; t < e; t += 2) o.push({
20
- left: a(t),
21
- right: a(t + 1)
22
- });
23
- return n === "rtl" ? o.map((e) => ({
24
+ } else if (a.push({
25
+ left: null,
26
+ right: 0
27
+ }), e > 1) {
28
+ for (let t = 1; t <= e - 2; t += 2) a.push({
29
+ left: i(t),
30
+ right: t + 1 <= e - 2 ? i(t + 1) : null
31
+ });
32
+ a.push({
33
+ left: e - 1,
34
+ right: null
35
+ });
36
+ }
37
+ return n === "rtl" ? a.map((e) => ({
24
38
  left: e.right,
25
39
  right: e.left
26
- })) : o;
40
+ })) : a;
27
41
  }
28
- function t(e, t) {
42
+ function n(e, t) {
29
43
  return e < t;
30
44
  }
31
45
  //#endregion
32
46
  //#region src/engine/virtualizer.ts
33
- function n(e, t, n) {
47
+ function r(e, t, n) {
34
48
  let r = [], i = Math.max(0, e - n), a = Math.min(t - 1, e + n);
35
49
  for (let e = i; e <= a; e++) r.push(e);
36
50
  return r;
37
51
  }
38
- var r = class {
52
+ var i = class {
39
53
  #e;
40
54
  #t = /* @__PURE__ */ new Set();
41
55
  constructor(e = 2) {
@@ -45,7 +59,7 @@ var r = class {
45
59
  return [...this.#t].sort((e, t) => e - t);
46
60
  }
47
61
  update(e, t) {
48
- let r = new Set(n(e, t, this.#e)), i = [...r].filter((e) => !this.#t.has(e)).sort((e, t) => e - t), a = [...this.#t].filter((e) => !r.has(e)).sort((e, t) => e - t);
62
+ let n = new Set(r(e, t, this.#e)), i = [...n].filter((e) => !this.#t.has(e)).sort((e, t) => e - t), a = [...this.#t].filter((e) => !n.has(e)).sort((e, t) => e - t);
49
63
  for (let e of a) this.#t.delete(e);
50
64
  for (let e of i) this.#t.add(e);
51
65
  return {
@@ -53,7 +67,7 @@ var r = class {
53
67
  toEvict: a
54
68
  };
55
69
  }
56
- }, i = class {
70
+ }, a = class {
57
71
  #e = /* @__PURE__ */ new Map();
58
72
  on(e, t) {
59
73
  let n = this.#e.get(e);
@@ -69,7 +83,7 @@ var r = class {
69
83
  clear() {
70
84
  this.#e.clear();
71
85
  }
72
- }, a = {
86
+ }, o = {
73
87
  idle: {
74
88
  grab: "dragging",
75
89
  panStart: "zoomed-panning",
@@ -79,10 +93,10 @@ var r = class {
79
93
  animating: { settle: "idle" },
80
94
  "zoomed-panning": { panEnd: "idle" }
81
95
  };
82
- function o(e, t) {
83
- return a[e][t] ?? null;
96
+ function s(e, t) {
97
+ return o[e][t] ?? null;
84
98
  }
85
- var s = class {
99
+ var c = class {
86
100
  #e;
87
101
  constructor(e = "idle") {
88
102
  this.#e = e;
@@ -91,10 +105,10 @@ var s = class {
91
105
  return this.#e;
92
106
  }
93
107
  send(e) {
94
- let t = o(this.#e, e);
108
+ let t = s(this.#e, e);
95
109
  return t !== null && (this.#e = t), t;
96
110
  }
97
- }, c = .3, l = class {
111
+ }, l = .3, u = class {
98
112
  #e;
99
113
  #t = null;
100
114
  #n = null;
@@ -140,7 +154,7 @@ var s = class {
140
154
  }
141
155
  #a(e, t, n, r, i) {
142
156
  if (e !== this.#t || this.#n === null) return;
143
- let a = this.#n, o = this.#i ?? a, s = this.#r ?? a, l = o.t - s.t, u = l > 0 ? (o.x - s.x) / l : 0, d = l > 0 ? (o.y - s.y) / l : 0, f = Math.hypot(u, d);
157
+ let a = this.#n, o = this.#i ?? a, s = this.#r ?? a, c = o.t - s.t, u = c > 0 ? (o.x - s.x) / c : 0, d = c > 0 ? (o.y - s.y) / c : 0, f = Math.hypot(u, d);
144
158
  this.#o(), this.#e.onEnd?.({
145
159
  x: t,
146
160
  y: n,
@@ -149,7 +163,7 @@ var s = class {
149
163
  dt: r - a.t,
150
164
  vx: u,
151
165
  vy: d,
152
- swipe: !i && f > c,
166
+ swipe: !i && f > l,
153
167
  canceled: i
154
168
  });
155
169
  }
@@ -157,7 +171,7 @@ var s = class {
157
171
  this.#t = null, this.#n = null, this.#r = null, this.#i = null;
158
172
  }
159
173
  };
160
- function u(e, t) {
174
+ function d(e, t) {
161
175
  let { pointer: n, pinch: r } = t, i = (e) => {
162
176
  let t = e;
163
177
  n?.down(t.pointerId, t.clientX, t.clientY, t.timeStamp), r?.down(t.pointerId, t.clientX, t.clientY);
@@ -175,10 +189,10 @@ function u(e, t) {
175
189
  e.removeEventListener("pointerdown", i), e.removeEventListener("pointermove", a), e.removeEventListener("pointerup", o), e.removeEventListener("pointercancel", s);
176
190
  };
177
191
  }
178
- function d(e, t) {
192
+ function f(e, t) {
179
193
  return Math.hypot(e.x - t.x, e.y - t.y);
180
194
  }
181
- var f = class {
195
+ var p = class {
182
196
  #e;
183
197
  #t = /* @__PURE__ */ new Map();
184
198
  #n = 0;
@@ -195,7 +209,7 @@ var f = class {
195
209
  y: n
196
210
  }), this.#t.size === 2)) {
197
211
  let { a: e, b: t } = this.#a();
198
- this.#n = d(e, t), this.#r = !0, this.#e.onPinchStart?.({
212
+ this.#n = f(e, t), this.#r = !0, this.#e.onPinchStart?.({
199
213
  centerX: (e.x + t.x) / 2,
200
214
  centerY: (e.y + t.y) / 2,
201
215
  distance: this.#n
@@ -209,7 +223,7 @@ var f = class {
209
223
  this.#e.onPinchMove?.({
210
224
  centerX: (i.x + a.x) / 2,
211
225
  centerY: (i.y + a.y) / 2,
212
- scale: this.#n > 0 ? d(i, a) / this.#n : 1
226
+ scale: this.#n > 0 ? f(i, a) / this.#n : 1
213
227
  });
214
228
  }
215
229
  up(e) {
@@ -232,7 +246,7 @@ var f = class {
232
246
  };
233
247
  //#endregion
234
248
  //#region src/geometry/hitTest.ts
235
- function p(e, t, n) {
249
+ function m(e, t, n) {
236
250
  let { width: r, height: i } = t;
237
251
  if (e.x < 0 || e.x > r || e.y < 0 || e.y > i) return "outside";
238
252
  let a = e.x <= n || e.x >= r - n, o = e.y <= n || e.y >= i - n;
@@ -240,214 +254,292 @@ function p(e, t, n) {
240
254
  }
241
255
  //#endregion
242
256
  //#region src/renderer/select.ts
243
- var m = {
244
- css: async () => new (await (import("./cssRenderer-BACNXO8M.js"))).CssRenderer(),
245
- webgl2: async () => new (await (import("./webglRenderer-D-1UyC-B.js"))).WebglRenderer()
246
- }, h = !0;
247
- function g(e) {
248
- return typeof e == "object" && !!e && !Array.isArray(e) && typeof e.mount == "function";
249
- }
257
+ var h = {
258
+ css: async () => new (await (import("./cssRenderer-OzRRoEa4.js"))).CssRenderer(),
259
+ webgl2: async () => new (await (import("./webglRenderer-m-lr412M.js"))).WebglRenderer()
260
+ }, g = !0;
250
261
  function _(e) {
251
- return e.gpu && h ? ["webgl2", "css"] : ["css"];
262
+ return typeof e == "object" && !!e && !Array.isArray(e) && typeof e.mount == "function";
252
263
  }
253
- function v() {
254
- return { gpu: y() };
264
+ function v(e) {
265
+ return e.gpu && g ? ["webgl2", "css"] : ["css"];
255
266
  }
256
267
  function y() {
268
+ return { gpu: b() };
269
+ }
270
+ function b() {
257
271
  try {
258
272
  return !!document.createElement("canvas").getContext("webgl2");
259
273
  } catch {
260
274
  return !1;
261
275
  }
262
276
  }
263
- async function b(e = "auto", t = v()) {
264
- if (g(e)) return e;
265
- let n = Array.isArray(e) ? e : e === "auto" ? _(t) : [e];
277
+ async function x(e = "auto", t = y()) {
278
+ if (_(e)) return e;
279
+ let n = Array.isArray(e) ? e : e === "auto" ? v(t) : [e];
266
280
  for (let e of n) {
267
281
  if (e === "webgl2" && !t.gpu) continue;
268
- let n = m[e];
282
+ let n = h[e];
269
283
  if (n) return n();
270
284
  }
271
285
  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'.`);
272
286
  }
273
287
  //#endregion
274
- //#region src/zine.ts
275
- var x = .25, S = .0015, C = 6, w = 250, T = class {
288
+ //#region src/source/compose.ts
289
+ function S(e, t) {
290
+ let n = typeof t.frontCover == "string", r = typeof t.backCover == "string", i = t.pages != null && Object.keys(t.pages).length > 0;
291
+ return !n && !r && !i ? e : new w(e, t);
292
+ }
293
+ function C(e) {
294
+ return fetch(e).then((t) => {
295
+ if (!t.ok) throw Error(`zine: could not load image "${e}" (HTTP ${t.status}).`);
296
+ return t.blob();
297
+ }).then((e) => createImageBitmap(e));
298
+ }
299
+ var w = class {
300
+ #e;
301
+ #t;
302
+ #n;
303
+ #r;
304
+ #i = /* @__PURE__ */ new Map();
305
+ #a = /* @__PURE__ */ new Map();
306
+ open;
307
+ onPageUpdate;
308
+ constructor(e, t) {
309
+ this.#e = e, this.#t = typeof t.frontCover == "string" ? t.frontCover : null, this.#n = typeof t.backCover == "string" ? t.backCover : null, this.#r = t.pages ?? {}, typeof e.open == "function" ? this.open = async () => {
310
+ await e.open(), this.#o();
311
+ } : this.#o(), typeof e.onPageUpdate == "function" && (this.onPageUpdate = (t) => {
312
+ e.onPageUpdate((e) => t(e + (this.#t === null ? 0 : 1)));
313
+ });
314
+ }
315
+ get pageCount() {
316
+ return this.#e.pageCount + (this.#t === null ? 0 : 1) + (this.#n === null ? 0 : 1);
317
+ }
318
+ get(e) {
319
+ let t = this.#t === null ? 0 : 1;
320
+ if (this.#t !== null && e === 0) return this.#s(this.#t);
321
+ if (this.#n !== null && e === this.pageCount - 1) return this.#s(this.#n);
322
+ let n = e - t, r = this.#i.get(n);
323
+ return r === void 0 ? this.#e.get(n) : this.#s(r);
324
+ }
325
+ prefetch(e) {
326
+ let t = this.#t === null ? 0 : 1, n = [];
327
+ for (let r of e) if (this.#t !== null && r === 0) this.#s(this.#t).catch(() => {});
328
+ else if (this.#n !== null && r === this.pageCount - 1) this.#s(this.#n).catch(() => {});
329
+ else {
330
+ let e = r - t, i = this.#i.get(e);
331
+ i === void 0 ? n.push(e) : this.#s(i).catch(() => {});
332
+ }
333
+ this.#e.prefetch(n);
334
+ }
335
+ destroy() {
336
+ this.#e.destroy();
337
+ for (let e of this.#a.values()) e.then((e) => e.close()).catch(() => {});
338
+ this.#a.clear();
339
+ }
340
+ #o() {
341
+ let e = this.#e.pageCount;
342
+ this.#i.clear();
343
+ for (let [t, n] of Object.entries(this.#r)) {
344
+ let r = Number(t), i = r < 0 ? e + r : r;
345
+ Number.isInteger(i) && i >= 0 && i < e && this.#i.set(i, n);
346
+ }
347
+ }
348
+ #s(e) {
349
+ let t = this.#a.get(e);
350
+ return t === void 0 && (t = C(e).catch((t) => {
351
+ throw this.#a.delete(e), t;
352
+ }), this.#a.set(e, t)), t;
353
+ }
354
+ }, T = .25, E = .0015, D = 6, O = 250, k = 1.75, A = class {
276
355
  #e;
277
356
  #t;
278
- #n = new i();
279
- #r = new r(2);
280
- #i = new s();
357
+ #n = new a();
358
+ #r = new i(2);
359
+ #i = new c();
281
360
  #a;
282
361
  #o;
283
362
  #s;
284
- #c;
363
+ #c = 1;
285
364
  #l;
286
365
  #u;
287
366
  #d;
288
- #f = !1;
367
+ #f;
289
368
  #p;
290
- #m = [];
291
- #h = 0;
292
- #g = 0;
293
- #_ = {
369
+ #m = !1;
370
+ #h = !1;
371
+ #g = "";
372
+ #_;
373
+ #v = [];
374
+ #y = 0;
375
+ #b = 0;
376
+ #x = {
294
377
  left: null,
295
378
  right: null
296
379
  };
297
- #v;
298
- #y;
299
- #b;
300
- #x;
301
380
  #S;
302
- #C = null;
303
- #w = !1;
304
- #T = 1;
305
- #E = 0;
306
- #D = 0;
307
- #O = null;
308
- #k = !1;
309
- #A = !1;
310
- #j = null;
381
+ #C;
382
+ #w;
383
+ #T;
384
+ #E;
385
+ #D = null;
386
+ #O = !1;
387
+ #k = 1;
388
+ #A = 0;
389
+ #j = 0;
311
390
  #M = null;
312
- #N = null;
313
- #P = null;
391
+ #N = !1;
392
+ #P = !1;
314
393
  #F = null;
315
394
  #I = null;
316
- #L = !1;
317
- #R = 1;
318
- #z = !1;
395
+ #L = null;
396
+ #R = null;
397
+ #z = null;
319
398
  #B = null;
320
- #V = null;
321
- #H = null;
322
- #U = null;
399
+ #V = !1;
400
+ #H = 1;
401
+ #U = !1;
323
402
  #W = null;
324
- #G;
403
+ #G = null;
404
+ #K = null;
405
+ #q = null;
406
+ #J = null;
407
+ #Y;
325
408
  debug = { setFlipProgress: (e, t) => {
326
- this.#O?.setFlipProgress(e, t);
409
+ this.#M?.setFlipProgress(e, t);
327
410
  } };
328
411
  constructor(e, t) {
329
- k(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 = t.source;
330
- let n = t.direction ?? "ltr", r = t.cover ?? !1;
331
- this.#a = n, this.#o = r, this.#s = t.clickToFlip ?? "edge", this.#c = t.clickZoneSize ?? 64, this.#d = t.singlePageThreshold ?? 640, this.#p = t.startPage, typeof this.#t.open != "function" && this.#ke(), this.#v = t.flipDuration ?? 800, this.#y = t.zoom?.enabled ?? !0, this.#b = t.zoom?.wheel ?? !0;
332
- let i = t.zoom?.doubleClick, a = i === !1 ? [] : [...i ?? [
412
+ P(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 = S(t.source, {
413
+ frontCover: t.frontCover,
414
+ backCover: t.backCover,
415
+ pages: t.pages
416
+ });
417
+ let n = t.direction ?? "ltr";
418
+ this.#a = n, this.#o = t.spreadMode ?? "cover", this.#s = t.curl ?? "roll", this.#l = t.clickToFlip ?? "edge", this.#u = t.clickZoneSize ?? 64, this.#p = t.singlePageThreshold ?? 640, this.#_ = t.startPage, typeof this.#t.open != "function" && this.#Le(), this.#S = t.flipDuration ?? 800, this.#C = t.zoom?.enabled ?? !0, this.#w = t.zoom?.wheel ?? !0;
419
+ let r = t.zoom?.doubleClick, i = r === !1 ? [] : [...r ?? [
333
420
  1,
334
421
  2,
335
422
  4
336
423
  ]].sort((e, t) => e - t);
337
- this.#x = a.length > 0 ? a : null, this.#S = t.zoom?.max ?? 4;
338
- let o = this.#y && this.#x !== null, s = t.zoom?.doubleClickInFlipZone ?? this.#s === "half";
339
- this.#l = this.#s !== "off" && o && s && t.clickFlipDelay !== 0, this.#u = this.#l ? t.clickFlipDelay ?? w : 0, this.#G = this.#fe(t.renderer ?? "auto");
424
+ this.#T = i.length > 0 ? i : null, this.#E = t.zoom?.max ?? 4;
425
+ let a = this.#C && this.#T !== null, o = t.zoom?.doubleClickInFlipZone ?? this.#l === "half";
426
+ this.#d = this.#l !== "off" && a && o && t.clickFlipDelay !== 0, this.#f = this.#d ? t.clickFlipDelay ?? O : 0, this.#Y = this.#_e(t.renderer ?? "auto");
340
427
  }
341
428
  get ready() {
342
- return this.#G;
429
+ return this.#Y;
343
430
  }
344
431
  getPageCount() {
345
432
  return this.#t.pageCount;
346
433
  }
347
434
  getPage() {
348
- return this.#g;
435
+ return this.#b;
349
436
  }
350
437
  flipNext() {
351
- this.#q(this.#h + 1);
438
+ this.#Z(this.#y + 1);
352
439
  }
353
440
  flipPrev() {
354
- this.#q(this.#h - 1);
441
+ this.#Z(this.#y - 1);
355
442
  }
356
443
  flipTo(e) {
357
- let t = E(e, 0, Math.max(0, this.#t.pageCount - 1));
358
- this.#q(this.#Oe(t));
444
+ let t = j(e, 0, Math.max(0, this.#t.pageCount - 1));
445
+ this.#Z(this.#Ie(t));
359
446
  }
360
447
  getZoom() {
361
- return this.#T;
448
+ return this.#k;
362
449
  }
363
450
  setZoom(e, t) {
364
- if (!this.#O || !this.#y) return;
365
- let n = E(e, 1, this.#S), r = this.#O.measure(), i = t ?? {
451
+ if (!this.#M || !this.#C) return;
452
+ let n = j(e, 1, this.#E), r = this.#M.measure(), i = t ?? {
366
453
  x: r.containerWidth / 2,
367
454
  y: r.containerHeight / 2
368
- }, a = this.#T, o = n === 1 ? 0 : i.x - n / a * (i.x - this.#E), s = n === 1 ? 0 : i.y - n / a * (i.y - this.#D);
369
- [o, s] = this.#K(o, s, n, r.containerWidth, r.containerHeight), this.#T = n, this.#E = o, this.#D = s, this.#O.setViewTransform(n, o, s), this.#n.emit("zoomChanged", { scale: n });
455
+ }, a = this.#k, o = n === 1 ? 0 : i.x - n / a * (i.x - this.#A), s = n === 1 ? 0 : i.y - n / a * (i.y - this.#j);
456
+ [o, s] = this.#X(o, s, n, r.containerWidth, r.containerHeight), this.#k = n, this.#A = o, this.#j = s, this.#M.setViewTransform(n, o, s), this.#n.emit("zoomChanged", { scale: n });
370
457
  }
371
458
  resetZoom() {
372
459
  this.setZoom(1);
373
460
  }
374
- #K(e, t, n, r, i) {
375
- return [E(e, r * (1 - n), 0), E(t, i * (1 - n), 0)];
461
+ #X(e, t, n, r, i) {
462
+ return [j(e, r * (1 - n), 0), j(t, i * (1 - n), 0)];
376
463
  }
377
464
  on(e, t) {
378
465
  return this.#n.on(e, t);
379
466
  }
380
467
  destroy() {
381
- this.#A = !0, this.#j !== null && cancelAnimationFrame(this.#j), this.#ae(), this.#C?.disconnect(), this.#W?.(), this.#H?.(), this.#U?.(), this.#V?.(), this.#O?.destroy(), this.#O = null, this.#t.destroy(), this.#n.clear();
468
+ this.#P = !0, this.#F !== null && cancelAnimationFrame(this.#F), this.#ue(), this.#D?.disconnect(), this.#J?.(), this.#K?.(), this.#q?.(), this.#G?.(), this.#M?.destroy(), this.#M = null, this.#t.destroy(), this.#n.clear();
382
469
  }
383
- #q(e) {
384
- if (e < 0 || e >= this.#m.length || e === this.#h || this.#i.send("flip") === null) return;
385
- let t = e > this.#h ? "forward" : "backward", n = this.#Z(e);
470
+ #Z(e) {
471
+ if (e < 0 || e >= this.#v.length || e === this.#y || this.#i.send("flip") === null) return;
472
+ let t = e > this.#y ? "forward" : "backward", n = this.#te(e);
386
473
  this.#n.emit("flipStart", {
387
- from: this.#g,
474
+ from: this.#b,
388
475
  to: n
389
- }), this.#J(e, t, n);
476
+ }), this.#Q(e, t, n);
390
477
  }
391
- async #J(e, t, n) {
392
- let r = this.#m[e], i = r ? await this.#Te(r) : {
478
+ async #Q(e, t, n) {
479
+ let r = this.#v[e], i = r ? await this.#Ne(r) : {
393
480
  left: null,
394
481
  right: null
395
482
  };
396
- this.#O?.beginFlip(this.#_, i, t, { fill: this.#f }), this.#Y(0, 1, t, () => this.#X(e, n, i));
397
- }
398
- #Y(e, t, n, r) {
399
- let i = this.#ye() * Math.abs(t - e);
483
+ this.#M?.beginFlip(this.#x, i, t, {
484
+ fill: this.#m,
485
+ curl: this.#s,
486
+ anchor: { y: this.#c }
487
+ }), this.#$(0, 1, t, () => this.#ee(e, n, i));
488
+ }
489
+ #$(e, t, n, r) {
490
+ let i = this.#we() * Math.abs(t - e);
400
491
  if (i <= 0) {
401
- this.#O?.setFlipProgress(t, n), r();
492
+ this.#M?.setFlipProgress(t, n), r();
402
493
  return;
403
494
  }
404
495
  let a = performance.now(), o = (s) => {
405
496
  let c = Math.min(1, (s - a) / i);
406
- this.#O?.setFlipProgress(e + (t - e) * D(c), n), c < 1 ? this.#j = requestAnimationFrame(o) : (this.#j = null, r());
497
+ this.#M?.setFlipProgress(e + (t - e) * M(c), n), c < 1 ? this.#F = requestAnimationFrame(o) : (this.#F = null, r());
407
498
  };
408
- this.#j = requestAnimationFrame(o);
499
+ this.#F = requestAnimationFrame(o);
409
500
  }
410
- #X(e, t, n) {
411
- let r = this.#m[e];
412
- this.#h = e, this.#g = t, this.#_ = n, r && this.#Se(r, n), this.#De(), this.#i.send("settle"), this.#ve(), this.#n.emit("pageChanged", { page: t }), this.#n.emit("flipEnd", { page: t });
501
+ #ee(e, t, n) {
502
+ let r = this.#v[e];
503
+ this.#y = e, this.#b = t, this.#x = n, r && this.#Oe(r, n), this.#Fe(), this.#i.send("settle"), this.#Ce(), this.#n.emit("pageChanged", { page: t }), this.#n.emit("flipEnd", { page: t });
413
504
  }
414
- #Z(e) {
415
- let t = this.#m[e];
416
- if (!t) return this.#g;
505
+ #te(e) {
506
+ let t = this.#v[e];
507
+ if (!t) return this.#b;
417
508
  let n = [t.left, t.right].filter((e) => e !== null);
418
- return n.length > 0 ? Math.min(...n) : this.#g;
509
+ return n.length > 0 ? Math.min(...n) : this.#b;
419
510
  }
420
- #Q(e, t) {
421
- if (this.#L || !this.#O || this.#i.state !== "idle") return;
422
- if (this.#ae(), this.#T > 1) {
511
+ #ne(e, t) {
512
+ if (this.#V || !this.#M || this.#i.state !== "idle") return;
513
+ if (this.#ue(), this.#k > 1) {
423
514
  if (this.#i.send("panStart") === null) return;
424
- this.#I = {
425
- baseTx: this.#E,
426
- baseTy: this.#D
515
+ this.#B = {
516
+ baseTx: this.#A,
517
+ baseTy: this.#j
427
518
  };
428
519
  return;
429
520
  }
430
- let n = this.#e.getBoundingClientRect(), r = {
431
- x: e - n.left,
432
- y: t - n.top
521
+ let n = this.#e.getBoundingClientRect(), r = this.#ce(), i = {
522
+ x: e - n.left - r.x,
523
+ y: t - n.top - r.y
433
524
  };
434
- this.#P = r;
435
- let { containerWidth: i, containerHeight: a } = this.#O.measure(), o = Math.min(i, a) * x;
436
- if (p(r, {
437
- width: i,
438
- height: a
439
- }, o) !== "corner") return;
440
- let s = r.x > i / 2, c = this.#a === "rtl" ? !s : s, l = this.#h + (c ? 1 : -1);
441
- l < 0 || l >= this.#m.length || (this.#N = {
442
- direction: c ? "forward" : "backward",
443
- targetIndex: l,
444
- toPage: this.#Z(l),
445
- width: i
525
+ this.#R = i;
526
+ let a = Math.min(r.width, r.height) * T;
527
+ if (m(i, {
528
+ width: r.width,
529
+ height: r.height
530
+ }, a) !== "corner") return;
531
+ this.#c = j(i.y / r.height, 0, 1);
532
+ let o = i.x > r.width / 2, s = this.#a === "rtl" ? !o : o, c = this.#y + (s ? 1 : -1);
533
+ c < 0 || c >= this.#v.length || (this.#L = {
534
+ direction: s ? "forward" : "backward",
535
+ targetIndex: c,
536
+ toPage: this.#te(c),
537
+ width: r.width
446
538
  });
447
539
  }
448
- #$() {
449
- let e = this.#N;
450
- e && (this.#N = null, this.#i.send("grab") !== null && (this.#M = {
540
+ #re() {
541
+ let e = this.#L;
542
+ e && (this.#L = null, this.#i.send("grab") !== null && (this.#I = {
451
543
  direction: e.direction,
452
544
  targetIndex: e.targetIndex,
453
545
  toPage: e.toPage,
@@ -458,189 +550,202 @@ var x = .25, S = .0015, C = 6, w = 250, T = class {
458
550
  width: e.width,
459
551
  t: 0
460
552
  }, this.#n.emit("flipStart", {
461
- from: this.#g,
553
+ from: this.#b,
462
554
  to: e.toPage
463
- }), this.#ee(e.targetIndex, e.direction)));
555
+ }), this.#ie(e.targetIndex, e.direction)));
464
556
  }
465
- async #ee(e, t) {
466
- let n = this.#m[e], r = n ? await this.#Te(n) : {
557
+ async #ie(e, t) {
558
+ let n = this.#v[e], r = n ? await this.#Ne(n) : {
467
559
  left: null,
468
560
  right: null
469
561
  };
470
- this.#M?.targetIndex === e && (this.#M.toContent = r, this.#O?.beginFlip(this.#_, r, t, { fill: this.#f }), this.#O?.setFlipProgress(this.#M.t, t));
471
- }
472
- #te(e, t) {
473
- if (this.#L) return;
474
- if (this.#I) {
475
- if (!this.#O) return;
476
- let n = this.#O.measure(), [r, i] = this.#K(this.#I.baseTx + e, this.#I.baseTy + t, this.#T, n.containerWidth, n.containerHeight);
477
- this.#E = r, this.#D = i, this.#O.setViewTransform(this.#T, r, i);
562
+ this.#I?.targetIndex === e && (this.#I.toContent = r, this.#M?.beginFlip(this.#x, r, t, {
563
+ fill: this.#m,
564
+ curl: this.#s,
565
+ anchor: { y: this.#c }
566
+ }), this.#M?.setFlipProgress(this.#I.t, t));
567
+ }
568
+ #ae(e, t) {
569
+ if (this.#V) return;
570
+ if (this.#B) {
571
+ if (!this.#M) return;
572
+ let n = this.#M.measure(), [r, i] = this.#X(this.#B.baseTx + e, this.#B.baseTy + t, this.#k, n.containerWidth, n.containerHeight);
573
+ this.#A = r, this.#j = i, this.#M.setViewTransform(this.#k, r, i);
478
574
  return;
479
575
  }
480
- this.#N && Math.hypot(e, t) > C && this.#$();
481
- let n = this.#M;
482
- n && (n.t = E((n.direction === "forward" ? -e : e) / n.width, 0, 1), this.#O?.setFlipProgress(n.t, n.direction));
483
- }
484
- #ne(e) {
485
- if (this.#L) return;
486
- if (this.#I) {
487
- this.#I = null, this.#i.send("panEnd");
576
+ this.#L && Math.hypot(e, t) > D && this.#re();
577
+ let n = this.#I;
578
+ n && (n.t = j((n.direction === "forward" ? -e : e) / n.width, 0, 1), this.#M?.setFlipProgress(n.t, n.direction));
579
+ }
580
+ #oe(e) {
581
+ if (this.#V) return;
582
+ if (this.#B) {
583
+ this.#B = null, this.#i.send("panEnd");
488
584
  return;
489
585
  }
490
- let t = this.#M;
586
+ let t = this.#I;
491
587
  if (!t) {
492
- this.#N = null, this.#re(e);
588
+ this.#L = null, this.#se(e);
493
589
  return;
494
590
  }
495
- this.#M = null, this.#i.send("release");
591
+ this.#I = null, this.#i.send("release");
496
592
  let n = e.swipe && (t.direction === "forward" ? e.dx < 0 : e.dx > 0);
497
- t.t >= .5 || n ? this.#Y(t.t, 1, t.direction, () => this.#X(t.targetIndex, t.toPage, t.toContent)) : this.#Y(t.t, 0, t.direction, () => this.#oe());
593
+ t.t >= .5 || n ? this.#$(t.t, 1, t.direction, () => this.#ee(t.targetIndex, t.toPage, t.toContent)) : this.#$(t.t, 0, t.direction, () => this.#de());
498
594
  }
499
- #re(e) {
500
- if (this.#s === "off" || this.#T > 1 || !this.#P || Math.abs(e.dx) > C || Math.abs(e.dy) > C) return;
501
- let t = this.#ie(this.#P);
595
+ #se(e) {
596
+ if (this.#l === "off" || this.#k > 1 || !this.#R || Math.abs(e.dx) > D || Math.abs(e.dy) > D) return;
597
+ let t = this.#le(this.#R);
502
598
  if (!t) return;
503
- let n = this.#h + (t === "forward" ? 1 : -1);
504
- if (!(n < 0 || n >= this.#m.length)) {
505
- if (this.#ae(), this.#u <= 0) {
506
- this.#q(n);
599
+ let n = this.#y + (t === "forward" ? 1 : -1);
600
+ if (!(n < 0 || n >= this.#v.length)) {
601
+ if (this.#c = j(this.#R.y / this.#ce().height, 0, 1), this.#ue(), this.#f <= 0) {
602
+ this.#Z(n);
507
603
  return;
508
604
  }
509
- this.#F = setTimeout(() => {
510
- this.#F = null, this.#q(n);
511
- }, this.#u);
605
+ this.#z = setTimeout(() => {
606
+ this.#z = null, this.#Z(n);
607
+ }, this.#f);
512
608
  }
513
609
  }
514
- #ie(e) {
515
- if (!this.#O) return null;
516
- let { containerWidth: t } = this.#O.measure(), n;
517
- if (n = this.#s === "half" ? e.x > t / 2 ? "right" : "left" : e.x <= this.#c ? "left" : e.x >= t - this.#c ? "right" : null, !n) return null;
610
+ #ce() {
611
+ let e = this.#M.measure();
612
+ return e.content ?? e.book ?? {
613
+ x: 0,
614
+ y: 0,
615
+ width: e.containerWidth,
616
+ height: e.containerHeight
617
+ };
618
+ }
619
+ #le(e) {
620
+ if (!this.#M) return null;
621
+ let t = this.#ce().width, n;
622
+ if (n = this.#l === "half" ? e.x > t / 2 ? "right" : "left" : e.x <= this.#u ? "left" : e.x >= t - this.#u ? "right" : null, !n) return null;
518
623
  let r = this.#a === "rtl" ? "left" : "right";
519
624
  return n === r ? "forward" : "backward";
520
625
  }
521
- #ae() {
522
- this.#F !== null && (clearTimeout(this.#F), this.#F = null);
523
- }
524
- #oe() {
525
- let e = this.#m[this.#h];
526
- e && this.#Se(e, this.#_), this.#i.send("settle"), this.#n.emit("flipEnd", { page: this.#g });
527
- }
528
- #se() {
529
- if (this.#N = null, this.#ae(), this.#M) {
530
- this.#M = null, this.#i.send("release"), this.#i.send("settle");
531
- let e = this.#m[this.#h];
532
- e && this.#Se(e, this.#_);
533
- } else this.#I && (this.#I = null, this.#i.send("panEnd"));
534
- this.#L = !0, this.#R = this.#T;
626
+ #ue() {
627
+ this.#z !== null && (clearTimeout(this.#z), this.#z = null);
535
628
  }
536
- #ce(e, t, n) {
537
- if (!this.#L) return;
629
+ #de() {
630
+ let e = this.#v[this.#y];
631
+ e && this.#Oe(e, this.#x), this.#i.send("settle"), this.#n.emit("flipEnd", { page: this.#b });
632
+ }
633
+ #fe() {
634
+ if (this.#L = null, this.#ue(), this.#I) {
635
+ this.#I = null, this.#i.send("release"), this.#i.send("settle");
636
+ let e = this.#v[this.#y];
637
+ e && this.#Oe(e, this.#x);
638
+ } else this.#B && (this.#B = null, this.#i.send("panEnd"));
639
+ this.#V = !0, this.#H = this.#k;
640
+ }
641
+ #pe(e, t, n) {
642
+ if (!this.#V) return;
538
643
  let r = this.#e.getBoundingClientRect();
539
- this.setZoom(this.#R * n, {
644
+ this.setZoom(this.#H * n, {
540
645
  x: e - r.left,
541
646
  y: t - r.top
542
647
  });
543
648
  }
544
- #le() {
545
- this.#L = !1;
649
+ #me() {
650
+ this.#V = !1;
546
651
  }
547
- #ue() {
652
+ #he() {
548
653
  let e = (e) => {
549
- if (!this.#b || !this.#y || !(e.ctrlKey || e.metaKey)) return;
654
+ if (!this.#w || !this.#C || !(e.ctrlKey || e.metaKey)) return;
550
655
  e.preventDefault();
551
- let t = this.#e.getBoundingClientRect(), n = Math.exp(-e.deltaY * S);
552
- this.setZoom(this.#T * n, {
656
+ let t = this.#e.getBoundingClientRect(), n = Math.exp(-e.deltaY * E);
657
+ this.setZoom(this.#k * n, {
553
658
  x: e.clientX - t.left,
554
659
  y: e.clientY - t.top
555
660
  });
556
661
  };
557
- this.#e.addEventListener("wheel", e, { passive: !1 }), this.#H = () => this.#e.removeEventListener("wheel", e);
662
+ this.#e.addEventListener("wheel", e, { passive: !1 }), this.#K = () => this.#e.removeEventListener("wheel", e);
558
663
  }
559
- #de() {
664
+ #ge() {
560
665
  let e = (e) => {
561
- let t = this.#x;
562
- if (!this.#y || t === null) return;
563
- if (this.#T <= 1 && this.#s !== "off" && !this.#l) {
666
+ let t = this.#T;
667
+ if (!this.#C || t === null) return;
668
+ if (this.#k <= 1 && this.#l !== "off" && !this.#d) {
564
669
  let t = this.#e.getBoundingClientRect(), n = {
565
670
  x: e.clientX - t.left,
566
671
  y: e.clientY - t.top
567
672
  };
568
- if (this.#ie(n) !== null) return;
673
+ if (this.#le(n) !== null) return;
569
674
  }
570
- this.#ae(), e.preventDefault();
571
- let n = t.find((e) => e > this.#T + 1e-6) ?? t[0] ?? this.#T, r = this.#e.getBoundingClientRect();
675
+ this.#ue(), e.preventDefault();
676
+ let n = t.find((e) => e > this.#k + 1e-6) ?? t[0] ?? this.#k, r = this.#e.getBoundingClientRect();
572
677
  this.setZoom(n, {
573
678
  x: e.clientX - r.left,
574
679
  y: e.clientY - r.top
575
680
  });
576
681
  };
577
- this.#e.addEventListener("dblclick", e), this.#U = () => this.#e.removeEventListener("dblclick", e);
578
- }
579
- async #fe(e) {
580
- let t = b(e);
581
- typeof this.#t.open == "function" && (await this.#t.open(), this.#ke()), this.#t.prefetch([this.#g]);
582
- let n = await t, r = await this.#pe(n);
583
- this.#O = r, this.#be(r.measure().containerWidth);
584
- let i = new l({
585
- onStart: (e) => this.#Q(e.x, e.y),
586
- onMove: (e) => this.#te(e.dx, e.dy),
587
- onEnd: (e) => this.#ne(e)
588
- }), a = new f({
589
- onPinchStart: () => this.#se(),
590
- onPinchMove: (e) => this.#ce(e.centerX, e.centerY, e.scale),
591
- onPinchEnd: () => this.#le()
682
+ this.#e.addEventListener("dblclick", e), this.#q = () => this.#e.removeEventListener("dblclick", e);
683
+ }
684
+ async #_e(e) {
685
+ let t = x(e);
686
+ typeof this.#t.open == "function" && (await this.#t.open(), this.#Le()), this.#t.prefetch([this.#b]);
687
+ let n = await t, r = await this.#ve(n);
688
+ this.#M = r, this.#t.onPageUpdate?.((e) => this.#Ae(e)), this.#Ee(r.measure().containerWidth);
689
+ let i = new u({
690
+ onStart: (e) => this.#ne(e.x, e.y),
691
+ onMove: (e) => this.#ae(e.dx, e.dy),
692
+ onEnd: (e) => this.#oe(e)
693
+ }), a = new p({
694
+ onPinchStart: () => this.#fe(),
695
+ onPinchMove: (e) => this.#pe(e.centerX, e.centerY, e.scale),
696
+ onPinchEnd: () => this.#me()
592
697
  });
593
- this.#V = u(this.#e, {
698
+ this.#G = d(this.#e, {
594
699
  pointer: i,
595
700
  pinch: a
596
- }), this.#ue(), this.#de(), this.#he(), this.#W = this.#ge(), await this.#xe(), this.#Ce(), this.#De(), this.#ve(), this.#n.emit("ready");
701
+ }), this.#he(), this.#ge(), this.#be(), this.#J = this.#xe(), await this.#De(), this.#je(), this.#Fe(), this.#Ce(), this.#n.emit("ready");
597
702
  }
598
- async #pe(e) {
703
+ async #ve(e) {
599
704
  try {
600
705
  return await e.mount(this.#e), e.onFatal?.(() => {
601
- this.#me();
706
+ this.#ye();
602
707
  }), e;
603
708
  } catch {
604
709
  e.destroy();
605
- let t = await b("css");
606
- return await t.mount(this.#e), this.#k = !0, this.#n.emit("rendererFallback", {
710
+ let t = await x("css");
711
+ return await t.mount(this.#e), this.#N = !0, this.#n.emit("rendererFallback", {
607
712
  from: "webgl2",
608
713
  to: "css"
609
714
  }), t;
610
715
  }
611
716
  }
612
- async #me() {
613
- if (this.#k || this.#A) return;
614
- this.#k = !0, this.#O?.destroy(), this.#O = null;
615
- let e = await b("css");
616
- if (this.#A) {
717
+ async #ye() {
718
+ if (this.#N || this.#P) return;
719
+ this.#N = !0, this.#M?.destroy(), this.#M = null;
720
+ let e = await x("css");
721
+ if (this.#P) {
617
722
  e.destroy();
618
723
  return;
619
724
  }
620
- await e.mount(this.#e), this.#O = e, this.#be(e.measure().containerWidth), await this.#xe(), this.#n.emit("rendererFallback", {
725
+ await e.mount(this.#e), this.#M = e, this.#Ee(e.measure().containerWidth), await this.#De(), this.#n.emit("rendererFallback", {
621
726
  from: "webgl2",
622
727
  to: "css"
623
728
  });
624
729
  }
625
- #he() {
730
+ #be() {
626
731
  if (typeof matchMedia != "function") return;
627
732
  let e = matchMedia("(prefers-reduced-motion: reduce)");
628
- this.#z = e.matches, e.addEventListener?.("change", (e) => {
629
- this.#z = e.matches;
733
+ this.#U = e.matches, e.addEventListener?.("change", (e) => {
734
+ this.#U = e.matches;
630
735
  });
631
736
  }
632
- #ge() {
737
+ #xe() {
633
738
  let e = this.#e, t = e.ownerDocument;
634
739
  if (!t || typeof e.setAttribute != "function") return null;
635
740
  e.hasAttribute("tabindex") || (e.tabIndex = 0), e.setAttribute("aria-roledescription", "flipbook");
636
- let n = (e) => this.#_e(e);
741
+ let n = (e) => this.#Se(e);
637
742
  e.addEventListener("keydown", n);
638
743
  let r = t.createElement("div");
639
- 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.#B = r, () => {
640
- e.removeEventListener("keydown", n), r.remove(), this.#B = null;
744
+ 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.#W = r, () => {
745
+ e.removeEventListener("keydown", n), r.remove(), this.#W = null;
641
746
  };
642
747
  }
643
- #_e(e) {
748
+ #Se(e) {
644
749
  let t = this.#a === "rtl" ? "ArrowLeft" : "ArrowRight";
645
750
  switch (e.key) {
646
751
  case "ArrowRight":
@@ -656,46 +761,64 @@ var x = .25, S = .0015, C = 6, w = 250, T = class {
656
761
  default: break;
657
762
  }
658
763
  }
659
- #ve() {
660
- this.#B && (this.#B.textContent = `Page ${this.#g + 1} of ${this.#t.pageCount}`);
764
+ #Ce() {
765
+ this.#W && (this.#W.textContent = `Page ${this.#b + 1} of ${this.#t.pageCount}`);
661
766
  }
662
- #ye() {
663
- return this.#z ? 0 : this.#v;
767
+ #we() {
768
+ if (this.#U) return 0;
769
+ let e = this.#m && this.#s === "roll";
770
+ return this.#S * (e ? k : 1);
664
771
  }
665
772
  update() {
666
- !this.#O || this.#i.state !== "idle" || (this.#be(this.#O.measure().containerWidth), this.#xe());
773
+ !this.#M || this.#i.state !== "idle" || (this.#Ee(this.#M.measure().containerWidth), this.#De());
667
774
  }
668
- #be(n) {
669
- let r = t(n, this.#d);
670
- r !== this.#f && (this.#f = r, this.#m = e(this.#t.pageCount, {
671
- direction: this.#a,
672
- cover: this.#o,
673
- singlePage: r
674
- }), this.#h = this.#Oe(this.#g));
775
+ #Te() {
776
+ return this.#h || this.#o === "single" ? "single" : this.#o;
675
777
  }
676
- async #xe() {
677
- let e = this.#m[this.#h];
678
- !e || !this.#O || (this.#_ = await this.#Te(e), this.#Se(e, this.#_));
778
+ #Ee(e) {
779
+ let r = n(e, this.#p);
780
+ if (r === this.#h) return;
781
+ this.#h = r;
782
+ let i = this.#Te();
783
+ this.#m = i === "single", this.#v = t(this.#t.pageCount, {
784
+ direction: this.#a,
785
+ mode: i
786
+ }), this.#y = this.#Ie(this.#b);
679
787
  }
680
- #Se(e, t) {
681
- this.#O?.renderSpread(e, t, { fill: this.#f });
788
+ async #De() {
789
+ let e = this.#v[this.#y];
790
+ !e || !this.#M || (this.#x = await this.#Ne(e), this.#Oe(e, this.#x));
682
791
  }
683
- #Ce() {
684
- typeof ResizeObserver > "u" || (this.#C = new ResizeObserver(() => this.#we()), this.#C.observe(this.#e));
792
+ #Oe(e, t) {
793
+ this.#M?.renderSpread(e, t, { fill: this.#m }), this.#ke();
685
794
  }
686
- #we() {
687
- this.#w || (this.#w = !0, requestAnimationFrame(() => {
688
- this.#w = !1, this.update();
795
+ #ke() {
796
+ let e = this.#M?.measure().book;
797
+ if (!e || e.width <= 0 || e.height <= 0) return;
798
+ let t = (e.width / e.height).toFixed(4);
799
+ t !== this.#g && (this.#g = t, this.#e.style.aspectRatio = t);
800
+ }
801
+ #Ae(e) {
802
+ if (this.#i.state !== "idle") return;
803
+ let t = this.#v[this.#y];
804
+ t && (t.left === e || t.right === e) && this.#De();
805
+ }
806
+ #je() {
807
+ typeof ResizeObserver > "u" || (this.#D = new ResizeObserver(() => this.#Me()), this.#D.observe(this.#e));
808
+ }
809
+ #Me() {
810
+ this.#O || (this.#O = !0, requestAnimationFrame(() => {
811
+ this.#O = !1, this.update();
689
812
  }));
690
813
  }
691
- async #Te(e) {
692
- let [t, n] = await Promise.all([this.#Ee(e.left), this.#Ee(e.right)]);
814
+ async #Ne(e) {
815
+ let [t, n] = await Promise.all([this.#Pe(e.left), this.#Pe(e.right)]);
693
816
  return {
694
817
  left: t,
695
818
  right: n
696
819
  };
697
820
  }
698
- async #Ee(e) {
821
+ async #Pe(e) {
699
822
  if (e === null) return null;
700
823
  try {
701
824
  return await this.#t.get(e);
@@ -706,59 +829,75 @@ var x = .25, S = .0015, C = 6, w = 250, T = class {
706
829
  }), null;
707
830
  }
708
831
  }
709
- #De() {
710
- let { toMount: e } = this.#r.update(this.#h, this.#m.length), t = [];
832
+ #Fe() {
833
+ let { toMount: e } = this.#r.update(this.#y, this.#v.length), t = [];
711
834
  for (let n of e) {
712
- let e = this.#m[n];
835
+ let e = this.#v[n];
713
836
  e?.left != null && t.push(e.left), e?.right != null && t.push(e.right);
714
837
  }
715
838
  this.#t.prefetch(t);
716
839
  }
717
- #Oe(e) {
718
- let t = this.#m.findIndex((t) => t.left === e || t.right === e);
840
+ #Ie(e) {
841
+ let t = this.#v.findIndex((t) => t.left === e || t.right === e);
719
842
  return t === -1 ? 0 : t;
720
843
  }
721
- #ke() {
722
- let t = this.#t.pageCount;
723
- if (!Number.isInteger(t) || t < 1) throw Error(`Zine: source has ${t} pages; a Source must have at least 1 page.`);
724
- let n = this.#p;
725
- if (n !== void 0 && (!Number.isInteger(n) || n < 0 || n >= t)) throw Error(`Zine: startPage ${JSON.stringify(n)} is out of range for a ${t}-page book (valid 0..${t - 1}).`);
726
- this.#m = e(t, {
844
+ #Le() {
845
+ let e = this.#t.pageCount;
846
+ if (!Number.isInteger(e) || e < 1) throw Error(`Zine: source has ${e} pages; a Source must have at least 1 page.`);
847
+ let n = this.#_;
848
+ if (n !== void 0 && (!Number.isInteger(n) || n < 0 || n >= e)) throw Error(`Zine: startPage ${JSON.stringify(n)} is out of range for a ${e}-page book (valid 0..${e - 1}).`);
849
+ let r = this.#Te();
850
+ this.#m = r === "single", this.#v = t(e, {
727
851
  direction: this.#a,
728
- cover: this.#o
729
- }), this.#g = E(n ?? 0, 0, t - 1), this.#h = this.#Oe(this.#g);
852
+ mode: r
853
+ }), this.#b = j(n ?? 0, 0, e - 1), this.#y = this.#Ie(this.#b);
730
854
  }
731
855
  };
732
- function E(e, t, n) {
856
+ function j(e, t, n) {
733
857
  return e < t ? t : e > n ? n : e;
734
858
  }
735
- function D(e) {
859
+ function M(e) {
736
860
  return e < .5 ? 4 * e * e * e : 1 - (-2 * e + 2) ** 3 / 2;
737
861
  }
738
- function O(e) {
862
+ function N(e) {
739
863
  return e === null ? "null" : Array.isArray(e) ? "array" : typeof e;
740
864
  }
741
- function k(e, t) {
742
- if (typeof e != "object" || !e || typeof e.appendChild != "function" || typeof e.addEventListener != "function") throw Error(`Zine: container must be a DOM element; received ${O(e)}.`);
743
- if (typeof t != "object" || !t) throw Error("Zine: an options object with a `source` is required.");
744
- let n = t, r = n.source;
745
- if (typeof r != "object" || !r || typeof r.get != "function" || typeof r.pageCount != "number") throw Error("Zine: `source` is required and must be a Source, e.g. new ImageSource(urls).");
746
- let i = n.startPage;
747
- if (i !== void 0 && (typeof i != "number" || !Number.isInteger(i) || i < 0)) throw Error(`Zine: startPage must be a non-negative integer; got ${JSON.stringify(i)}.`);
748
- let a = n.direction;
749
- if (a !== void 0 && a !== "ltr" && a !== "rtl") throw Error(`Zine: direction must be 'ltr' or 'rtl'; got ${JSON.stringify(a)}.`);
750
- let o = n.clickToFlip;
751
- if (o !== void 0 && ![
865
+ function P(t, n) {
866
+ if (typeof t != "object" || !t || typeof t.appendChild != "function" || typeof t.addEventListener != "function") throw Error(`Zine: container must be a DOM element; received ${N(t)}.`);
867
+ if (typeof n != "object" || !n) throw Error("Zine: an options object with a `source` is required.");
868
+ let r = n, i = r.source;
869
+ 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).");
870
+ let a = r.startPage;
871
+ 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)}.`);
872
+ let o = r.direction;
873
+ if (o !== void 0 && o !== "ltr" && o !== "rtl") throw Error(`Zine: direction must be 'ltr' or 'rtl'; got ${JSON.stringify(o)}.`);
874
+ let s = r.clickToFlip;
875
+ if (s !== void 0 && ![
752
876
  "edge",
753
877
  "half",
754
878
  "off"
755
- ].includes(o)) throw Error(`Zine: clickToFlip must be 'edge', 'half', or 'off'; got ${JSON.stringify(o)}.`);
756
- A(n.width, "width", 1), A(n.height, "height", 1), A(n.flipDuration, "flipDuration", 0), A(n.clickZoneSize, "clickZoneSize", 0), A(n.clickFlipDelay, "clickFlipDelay", 0), A(n.singlePageThreshold, "singlePageThreshold", 0), j(n.zoom), M(n.renderer);
879
+ ].includes(s)) throw Error(`Zine: clickToFlip must be 'edge', 'half', or 'off'; got ${JSON.stringify(s)}.`);
880
+ let c = r.curl;
881
+ if (c !== void 0 && !e.includes(c)) throw Error(`Zine: curl must be one of ${e.join(", ")}; got ${JSON.stringify(c)}.`);
882
+ let l = r.spreadMode;
883
+ if (l !== void 0 && ![
884
+ "double",
885
+ "single",
886
+ "cover",
887
+ "book"
888
+ ].includes(l)) throw Error(`Zine: spreadMode must be 'double', 'single', 'cover', or 'book'; got ${JSON.stringify(l)}.`);
889
+ for (let e of ["frontCover", "backCover"]) {
890
+ let t = r[e];
891
+ if (t !== void 0 && typeof t != "string") throw Error(`Zine: ${e} must be an image URL string; got ${JSON.stringify(t)}.`);
892
+ }
893
+ let u = r.pages;
894
+ if (u !== void 0 && (typeof u != "object" || !u || Array.isArray(u))) throw Error("Zine: pages must be an object mapping page indices to image URLs.");
895
+ F(r.width, "width", 1), F(r.height, "height", 1), F(r.flipDuration, "flipDuration", 0), F(r.clickZoneSize, "clickZoneSize", 0), F(r.clickFlipDelay, "clickFlipDelay", 0), F(r.singlePageThreshold, "singlePageThreshold", 0), I(r.zoom), L(r.renderer);
757
896
  }
758
- function A(e, t, n) {
897
+ function F(e, t, n) {
759
898
  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)}.`);
760
899
  }
761
- function j(e) {
900
+ function I(e) {
762
901
  if (e === void 0) return;
763
902
  if (typeof e != "object" || !e || Array.isArray(e)) throw Error("Zine: zoom must be an object, e.g. { max: 4 }.");
764
903
  let t = e;
@@ -769,9 +908,9 @@ function j(e) {
769
908
  let e = t.doubleClick;
770
909
  if (!Array.isArray(e) || e.some((e) => typeof e != "number" || !Number.isFinite(e) || e < 1)) throw Error("Zine: zoom.doubleClick must be false or an array of zoom levels >= 1, e.g. [1, 2, 4].");
771
910
  }
772
- A(t.max, "zoom.max", 1);
911
+ F(t.max, "zoom.max", 1);
773
912
  }
774
- function M(e) {
913
+ function L(e) {
775
914
  if (e !== void 0) {
776
915
  if (typeof e == "string") {
777
916
  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.`);
@@ -786,7 +925,7 @@ function M(e) {
786
925
  }
787
926
  //#endregion
788
927
  //#region src/source/imageSource.ts
789
- var N = class {
928
+ var R = class {
790
929
  pageCount;
791
930
  fit;
792
931
  #e;
@@ -823,6 +962,6 @@ var N = class {
823
962
  }
824
963
  };
825
964
  //#endregion
826
- export { N as ImageSource, T as Zine };
965
+ export { e as CURL_TYPES, R as ImageSource, A as Zine };
827
966
 
828
967
  //# sourceMappingURL=index.js.map