@zinejs/core 0.1.0 → 0.3.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-D-rEO00p.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,312 @@ 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-Bg6VF4CW.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.55, 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
399
  #V = null;
321
400
  #H = null;
322
- #U = null;
323
- #W = null;
324
- #G;
401
+ #U = !1;
402
+ #W = 1;
403
+ #G = !1;
404
+ #K = null;
405
+ #q = null;
406
+ #J = null;
407
+ #Y = null;
408
+ #X = null;
409
+ #Z;
325
410
  debug = { setFlipProgress: (e, t) => {
326
- this.#O?.setFlipProgress(e, t);
411
+ this.#M?.setFlipProgress(e, t);
327
412
  } };
328
413
  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 ?? [
414
+ F(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, {
415
+ frontCover: t.frontCover,
416
+ backCover: t.backCover,
417
+ pages: t.pages
418
+ });
419
+ let n = t.direction ?? "ltr";
420
+ this.#a = n, this.#o = t.spreadMode ?? "cover", this.#s = t.curl ?? "cone", this.#l = t.clickToFlip ?? "edge", this.#u = t.clickZoneSize ?? 64, this.#p = t.singlePageThreshold ?? 640, this.#_ = t.startPage, typeof this.#t.open != "function" && this.#He(), this.#S = t.flipDuration ?? 800, this.#C = t.zoom?.enabled ?? !0, this.#w = t.zoom?.wheel ?? !0;
421
+ let r = t.zoom?.doubleClick, i = r === !1 ? [] : [...r ?? [
333
422
  1,
334
423
  2,
335
424
  4
336
425
  ]].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");
426
+ this.#T = i.length > 0 ? i : null, this.#E = t.zoom?.max ?? 4;
427
+ let a = this.#C && this.#T !== null, o = t.zoom?.doubleClickInFlipZone ?? this.#l === "half";
428
+ this.#d = this.#l !== "off" && a && o && t.clickFlipDelay !== 0, this.#f = this.#d ? t.clickFlipDelay ?? O : 0, this.#Z = this.#Se(t.renderer ?? "auto");
340
429
  }
341
430
  get ready() {
342
- return this.#G;
431
+ return this.#Z;
343
432
  }
344
433
  getPageCount() {
345
434
  return this.#t.pageCount;
346
435
  }
347
436
  getPage() {
348
- return this.#g;
437
+ return this.#b;
349
438
  }
350
439
  flipNext() {
351
- this.#q(this.#h + 1);
440
+ this.#Q(() => this.#ne(this.#y + 1));
352
441
  }
353
442
  flipPrev() {
354
- this.#q(this.#h - 1);
443
+ this.#Q(() => this.#ne(this.#y - 1));
355
444
  }
356
445
  flipTo(e) {
357
- let t = E(e, 0, Math.max(0, this.#t.pageCount - 1));
358
- this.#q(this.#Oe(t));
446
+ let t = j(e, 0, Math.max(0, this.#t.pageCount - 1));
447
+ this.#Q(() => this.#ne(this.#Ve(t)));
448
+ }
449
+ #Q(e) {
450
+ this.#i.state === "idle" ? e() : this.#V ? (this.#$(), e()) : this.#B = e;
451
+ }
452
+ #$() {
453
+ let e = this.#V;
454
+ e && (this.#V = null, this.#F !== null && (cancelAnimationFrame(this.#F), this.#F = null), this.#M?.setFlipProgress(e.toT, e.direction), e.onDone());
455
+ }
456
+ #ee() {
457
+ let e = this.#B;
458
+ e && (this.#B = null, e());
359
459
  }
360
460
  getZoom() {
361
- return this.#T;
461
+ return this.#k;
362
462
  }
363
463
  setZoom(e, t) {
364
- if (!this.#O || !this.#y) return;
365
- let n = E(e, 1, this.#S), r = this.#O.measure(), i = t ?? {
464
+ if (!this.#M || !this.#C) return;
465
+ let n = j(e, 1, this.#E), r = this.#M.measure(), i = t ?? {
366
466
  x: r.containerWidth / 2,
367
467
  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 });
468
+ }, 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);
469
+ [o, s] = this.#te(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
470
  }
371
471
  resetZoom() {
372
472
  this.setZoom(1);
373
473
  }
374
- #K(e, t, n, r, i) {
375
- return [E(e, r * (1 - n), 0), E(t, i * (1 - n), 0)];
474
+ #te(e, t, n, r, i) {
475
+ return [j(e, r * (1 - n), 0), j(t, i * (1 - n), 0)];
376
476
  }
377
477
  on(e, t) {
378
478
  return this.#n.on(e, t);
379
479
  }
380
480
  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();
481
+ this.#P = !0, this.#F !== null && cancelAnimationFrame(this.#F), this.#V = null, this.#B = null, this.#he(), this.#D?.disconnect(), this.#X?.(), this.#J?.(), this.#Y?.(), this.#q?.(), this.#M?.destroy(), this.#M = null, this.#t.destroy(), this.#n.clear();
382
482
  }
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);
483
+ #ne(e) {
484
+ if (e < 0 || e >= this.#v.length || e === this.#y || this.#i.send("flip") === null) return;
485
+ let t = e > this.#y ? "forward" : "backward", n = this.#oe(e);
386
486
  this.#n.emit("flipStart", {
387
- from: this.#g,
487
+ from: this.#b,
388
488
  to: n
389
- }), this.#J(e, t, n);
489
+ }), this.#re(e, t, n);
390
490
  }
391
- async #J(e, t, n) {
392
- let r = this.#m[e], i = r ? await this.#Te(r) : {
491
+ async #re(e, t, n) {
492
+ let r = this.#v[e], i = r ? await this.#Re(r) : {
393
493
  left: null,
394
494
  right: null
395
495
  };
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);
496
+ this.#M?.beginFlip(this.#x, i, t, {
497
+ fill: this.#m,
498
+ curl: this.#s,
499
+ anchor: { y: this.#c }
500
+ }), this.#ie(0, 1, t, () => this.#ae(e, n, i));
501
+ }
502
+ #ie(e, t, n, r) {
503
+ let i = this.#ke() * Math.abs(t - e);
400
504
  if (i <= 0) {
401
- this.#O?.setFlipProgress(t, n), r();
505
+ this.#M?.setFlipProgress(t, n), r();
402
506
  return;
403
507
  }
404
- let a = performance.now(), o = (s) => {
405
- 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());
508
+ let a = {
509
+ toT: t,
510
+ direction: n,
511
+ onDone: r
407
512
  };
408
- this.#j = requestAnimationFrame(o);
513
+ this.#V = a;
514
+ let o = performance.now(), s = (c) => {
515
+ if (this.#V !== a) return;
516
+ let l = Math.min(1, (c - o) / i), u = this.#m ? N(l) : M(l);
517
+ this.#M?.setFlipProgress(e + (t - e) * u, n), l < 1 ? this.#F = requestAnimationFrame(s) : (this.#F = null, this.#V = null, r());
518
+ };
519
+ this.#F = requestAnimationFrame(s);
409
520
  }
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 });
521
+ #ae(e, t, n) {
522
+ let r = this.#v[e];
523
+ this.#y = e, this.#b = t, this.#x = n, r && this.#Ne(r, n), this.#Be(), this.#i.send("settle"), this.#Oe(), this.#n.emit("pageChanged", { page: t }), this.#n.emit("flipEnd", { page: t }), this.#ee();
413
524
  }
414
- #Z(e) {
415
- let t = this.#m[e];
416
- if (!t) return this.#g;
525
+ #oe(e) {
526
+ let t = this.#v[e];
527
+ if (!t) return this.#b;
417
528
  let n = [t.left, t.right].filter((e) => e !== null);
418
- return n.length > 0 ? Math.min(...n) : this.#g;
529
+ return n.length > 0 ? Math.min(...n) : this.#b;
419
530
  }
420
- #Q(e, t) {
421
- if (this.#L || !this.#O || this.#i.state !== "idle") return;
422
- if (this.#ae(), this.#T > 1) {
531
+ #se(e, t) {
532
+ if (this.#U || !this.#M || this.#i.state !== "idle") return;
533
+ if (this.#he(), this.#k > 1) {
423
534
  if (this.#i.send("panStart") === null) return;
424
- this.#I = {
425
- baseTx: this.#E,
426
- baseTy: this.#D
535
+ this.#H = {
536
+ baseTx: this.#A,
537
+ baseTy: this.#j
427
538
  };
428
539
  return;
429
540
  }
430
- let n = this.#e.getBoundingClientRect(), r = {
431
- x: e - n.left,
432
- y: t - n.top
541
+ let n = this.#e.getBoundingClientRect(), r = this.#pe(), i = {
542
+ x: e - n.left - r.x,
543
+ y: t - n.top - r.y
433
544
  };
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
545
+ this.#R = i;
546
+ let a = Math.min(r.width, r.height) * T;
547
+ if (m(i, {
548
+ width: r.width,
549
+ height: r.height
550
+ }, a) !== "corner") return;
551
+ this.#c = j(i.y / r.height, 0, 1);
552
+ let o = i.x > r.width / 2, s = this.#a === "rtl" ? !o : o, c = this.#y + (s ? 1 : -1);
553
+ c < 0 || c >= this.#v.length || (this.#L = {
554
+ direction: s ? "forward" : "backward",
555
+ targetIndex: c,
556
+ toPage: this.#oe(c),
557
+ width: r.width
446
558
  });
447
559
  }
448
- #$() {
449
- let e = this.#N;
450
- e && (this.#N = null, this.#i.send("grab") !== null && (this.#M = {
560
+ #ce() {
561
+ let e = this.#L;
562
+ e && (this.#L = null, this.#i.send("grab") !== null && (this.#I = {
451
563
  direction: e.direction,
452
564
  targetIndex: e.targetIndex,
453
565
  toPage: e.toPage,
@@ -458,189 +570,203 @@ var x = .25, S = .0015, C = 6, w = 250, T = class {
458
570
  width: e.width,
459
571
  t: 0
460
572
  }, this.#n.emit("flipStart", {
461
- from: this.#g,
573
+ from: this.#b,
462
574
  to: e.toPage
463
- }), this.#ee(e.targetIndex, e.direction)));
575
+ }), this.#le(e.targetIndex, e.direction)));
464
576
  }
465
- async #ee(e, t) {
466
- let n = this.#m[e], r = n ? await this.#Te(n) : {
577
+ async #le(e, t) {
578
+ let n = this.#v[e], r = n ? await this.#Re(n) : {
467
579
  left: null,
468
580
  right: null
469
581
  };
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);
582
+ this.#I?.targetIndex === e && (this.#I.toContent = r, this.#M?.beginFlip(this.#x, r, t, {
583
+ fill: this.#m,
584
+ curl: this.#s,
585
+ anchor: { y: this.#c }
586
+ }), this.#M?.setFlipProgress(this.#I.t, t));
587
+ }
588
+ #ue(e, t) {
589
+ if (this.#U) return;
590
+ if (this.#H) {
591
+ if (!this.#M) return;
592
+ let n = this.#M.measure(), [r, i] = this.#te(this.#H.baseTx + e, this.#H.baseTy + t, this.#k, n.containerWidth, n.containerHeight);
593
+ this.#A = r, this.#j = i, this.#M.setViewTransform(this.#k, r, i);
478
594
  return;
479
595
  }
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");
596
+ this.#L && Math.hypot(e, t) > D && this.#ce();
597
+ let n = this.#I;
598
+ n && (n.t = j((n.direction === "forward" ? -e : e) / n.width, 0, 1), this.#M?.setFlipProgress(n.t, n.direction));
599
+ }
600
+ #de(e) {
601
+ if (this.#U) return;
602
+ if (this.#H) {
603
+ this.#H = null, this.#i.send("panEnd");
488
604
  return;
489
605
  }
490
- let t = this.#M;
606
+ let t = this.#I;
491
607
  if (!t) {
492
- this.#N = null, this.#re(e);
608
+ this.#L = null, this.#fe(e);
493
609
  return;
494
610
  }
495
- this.#M = null, this.#i.send("release");
611
+ this.#I = null, this.#i.send("release");
496
612
  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());
613
+ t.t >= .5 || n ? this.#ie(t.t, 1, t.direction, () => this.#ae(t.targetIndex, t.toPage, t.toContent)) : this.#ie(t.t, 0, t.direction, () => this.#ge());
498
614
  }
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);
615
+ #fe(e) {
616
+ if (this.#l === "off" || this.#k > 1 || !this.#R || Math.abs(e.dx) > D || Math.abs(e.dy) > D) return;
617
+ let t = this.#me(this.#R);
502
618
  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);
507
- return;
508
- }
509
- this.#F = setTimeout(() => {
510
- this.#F = null, this.#q(n);
511
- }, this.#u);
619
+ let n = t === "forward" ? 1 : -1;
620
+ if (this.#y + n < 0 || this.#y + n >= this.#v.length) return;
621
+ this.#c = j(this.#R.y / this.#pe().height, 0, 1);
622
+ let r = () => this.#ne(this.#y + n);
623
+ if (this.#he(), this.#f <= 0) {
624
+ this.#Q(r);
625
+ return;
512
626
  }
627
+ this.#z = setTimeout(() => {
628
+ this.#z = null, this.#Q(r);
629
+ }, this.#f);
630
+ }
631
+ #pe() {
632
+ let e = this.#M.measure();
633
+ return e.content ?? e.book ?? {
634
+ x: 0,
635
+ y: 0,
636
+ width: e.containerWidth,
637
+ height: e.containerHeight
638
+ };
513
639
  }
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;
640
+ #me(e) {
641
+ if (!this.#M) return null;
642
+ let t = this.#pe().width, n;
643
+ 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
644
  let r = this.#a === "rtl" ? "left" : "right";
519
645
  return n === r ? "forward" : "backward";
520
646
  }
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;
647
+ #he() {
648
+ this.#z !== null && (clearTimeout(this.#z), this.#z = null);
535
649
  }
536
- #ce(e, t, n) {
537
- if (!this.#L) return;
650
+ #ge() {
651
+ let e = this.#v[this.#y];
652
+ e && this.#Ne(e, this.#x), this.#i.send("settle"), this.#n.emit("flipEnd", { page: this.#b }), this.#ee();
653
+ }
654
+ #_e() {
655
+ if (this.#L = null, this.#he(), this.#I) {
656
+ this.#I = null, this.#i.send("release"), this.#i.send("settle");
657
+ let e = this.#v[this.#y];
658
+ e && this.#Ne(e, this.#x);
659
+ } else this.#H && (this.#H = null, this.#i.send("panEnd"));
660
+ this.#U = !0, this.#W = this.#k;
661
+ }
662
+ #ve(e, t, n) {
663
+ if (!this.#U) return;
538
664
  let r = this.#e.getBoundingClientRect();
539
- this.setZoom(this.#R * n, {
665
+ this.setZoom(this.#W * n, {
540
666
  x: e - r.left,
541
667
  y: t - r.top
542
668
  });
543
669
  }
544
- #le() {
545
- this.#L = !1;
670
+ #ye() {
671
+ this.#U = !1;
546
672
  }
547
- #ue() {
673
+ #be() {
548
674
  let e = (e) => {
549
- if (!this.#b || !this.#y || !(e.ctrlKey || e.metaKey)) return;
675
+ if (!this.#w || !this.#C || !(e.ctrlKey || e.metaKey)) return;
550
676
  e.preventDefault();
551
- let t = this.#e.getBoundingClientRect(), n = Math.exp(-e.deltaY * S);
552
- this.setZoom(this.#T * n, {
677
+ let t = this.#e.getBoundingClientRect(), n = Math.exp(-e.deltaY * E);
678
+ this.setZoom(this.#k * n, {
553
679
  x: e.clientX - t.left,
554
680
  y: e.clientY - t.top
555
681
  });
556
682
  };
557
- this.#e.addEventListener("wheel", e, { passive: !1 }), this.#H = () => this.#e.removeEventListener("wheel", e);
683
+ this.#e.addEventListener("wheel", e, { passive: !1 }), this.#J = () => this.#e.removeEventListener("wheel", e);
558
684
  }
559
- #de() {
685
+ #xe() {
560
686
  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) {
687
+ let t = this.#T;
688
+ if (!this.#C || t === null) return;
689
+ if (this.#k <= 1 && this.#l !== "off" && !this.#d) {
564
690
  let t = this.#e.getBoundingClientRect(), n = {
565
691
  x: e.clientX - t.left,
566
692
  y: e.clientY - t.top
567
693
  };
568
- if (this.#ie(n) !== null) return;
694
+ if (this.#me(n) !== null) return;
569
695
  }
570
- this.#ae(), e.preventDefault();
571
- let n = t.find((e) => e > this.#T + 1e-6) ?? t[0] ?? this.#T, r = this.#e.getBoundingClientRect();
696
+ this.#he(), e.preventDefault();
697
+ let n = t.find((e) => e > this.#k + 1e-6) ?? t[0] ?? this.#k, r = this.#e.getBoundingClientRect();
572
698
  this.setZoom(n, {
573
699
  x: e.clientX - r.left,
574
700
  y: e.clientY - r.top
575
701
  });
576
702
  };
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()
703
+ this.#e.addEventListener("dblclick", e), this.#Y = () => this.#e.removeEventListener("dblclick", e);
704
+ }
705
+ async #Se(e) {
706
+ let t = x(e);
707
+ typeof this.#t.open == "function" && (await this.#t.open(), this.#He()), this.#t.prefetch([this.#b]);
708
+ let n = await t, r = await this.#Ce(n);
709
+ this.#M = r, this.#t.onPageUpdate?.((e) => this.#Fe(e)), this.#je(r.measure().containerWidth);
710
+ let i = new u({
711
+ onStart: (e) => this.#se(e.x, e.y),
712
+ onMove: (e) => this.#ue(e.dx, e.dy),
713
+ onEnd: (e) => this.#de(e)
714
+ }), a = new p({
715
+ onPinchStart: () => this.#_e(),
716
+ onPinchMove: (e) => this.#ve(e.centerX, e.centerY, e.scale),
717
+ onPinchEnd: () => this.#ye()
592
718
  });
593
- this.#V = u(this.#e, {
719
+ this.#q = d(this.#e, {
594
720
  pointer: i,
595
721
  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");
722
+ }), this.#be(), this.#xe(), this.#Te(), this.#X = this.#Ee(), await this.#Me(), this.#Ie(), this.#Be(), this.#Oe(), this.#n.emit("ready");
597
723
  }
598
- async #pe(e) {
724
+ async #Ce(e) {
599
725
  try {
600
726
  return await e.mount(this.#e), e.onFatal?.(() => {
601
- this.#me();
727
+ this.#we();
602
728
  }), e;
603
729
  } catch {
604
730
  e.destroy();
605
- let t = await b("css");
606
- return await t.mount(this.#e), this.#k = !0, this.#n.emit("rendererFallback", {
731
+ let t = await x("css");
732
+ return await t.mount(this.#e), this.#N = !0, this.#n.emit("rendererFallback", {
607
733
  from: "webgl2",
608
734
  to: "css"
609
735
  }), t;
610
736
  }
611
737
  }
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) {
738
+ async #we() {
739
+ if (this.#N || this.#P) return;
740
+ this.#N = !0, this.#M?.destroy(), this.#M = null;
741
+ let e = await x("css");
742
+ if (this.#P) {
617
743
  e.destroy();
618
744
  return;
619
745
  }
620
- await e.mount(this.#e), this.#O = e, this.#be(e.measure().containerWidth), await this.#xe(), this.#n.emit("rendererFallback", {
746
+ await e.mount(this.#e), this.#M = e, this.#je(e.measure().containerWidth), await this.#Me(), this.#n.emit("rendererFallback", {
621
747
  from: "webgl2",
622
748
  to: "css"
623
749
  });
624
750
  }
625
- #he() {
751
+ #Te() {
626
752
  if (typeof matchMedia != "function") return;
627
753
  let e = matchMedia("(prefers-reduced-motion: reduce)");
628
- this.#z = e.matches, e.addEventListener?.("change", (e) => {
629
- this.#z = e.matches;
754
+ this.#G = e.matches, e.addEventListener?.("change", (e) => {
755
+ this.#G = e.matches;
630
756
  });
631
757
  }
632
- #ge() {
758
+ #Ee() {
633
759
  let e = this.#e, t = e.ownerDocument;
634
760
  if (!t || typeof e.setAttribute != "function") return null;
635
761
  e.hasAttribute("tabindex") || (e.tabIndex = 0), e.setAttribute("aria-roledescription", "flipbook");
636
- let n = (e) => this.#_e(e);
762
+ let n = (e) => this.#De(e);
637
763
  e.addEventListener("keydown", n);
638
764
  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;
765
+ 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.#K = r, () => {
766
+ e.removeEventListener("keydown", n), r.remove(), this.#K = null;
641
767
  };
642
768
  }
643
- #_e(e) {
769
+ #De(e) {
644
770
  let t = this.#a === "rtl" ? "ArrowLeft" : "ArrowRight";
645
771
  switch (e.key) {
646
772
  case "ArrowRight":
@@ -656,46 +782,62 @@ var x = .25, S = .0015, C = 6, w = 250, T = class {
656
782
  default: break;
657
783
  }
658
784
  }
659
- #ve() {
660
- this.#B && (this.#B.textContent = `Page ${this.#g + 1} of ${this.#t.pageCount}`);
785
+ #Oe() {
786
+ this.#K && (this.#K.textContent = `Page ${this.#b + 1} of ${this.#t.pageCount}`);
661
787
  }
662
- #ye() {
663
- return this.#z ? 0 : this.#v;
788
+ #ke() {
789
+ return this.#G ? 0 : this.#S * (this.#m ? k : 1);
664
790
  }
665
791
  update() {
666
- !this.#O || this.#i.state !== "idle" || (this.#be(this.#O.measure().containerWidth), this.#xe());
792
+ !this.#M || this.#i.state !== "idle" || (this.#je(this.#M.measure().containerWidth), this.#Me());
667
793
  }
668
- #be(n) {
669
- let r = t(n, this.#d);
670
- r !== this.#f && (this.#f = r, this.#m = e(this.#t.pageCount, {
794
+ #Ae() {
795
+ return this.#h || this.#o === "single" ? "single" : this.#o;
796
+ }
797
+ #je(e) {
798
+ let r = n(e, this.#p);
799
+ if (r === this.#h) return;
800
+ this.#h = r;
801
+ let i = this.#Ae();
802
+ this.#m = i === "single", this.#v = t(this.#t.pageCount, {
671
803
  direction: this.#a,
672
- cover: this.#o,
673
- singlePage: r
674
- }), this.#h = this.#Oe(this.#g));
804
+ mode: i
805
+ }), this.#y = this.#Ve(this.#b);
806
+ }
807
+ async #Me() {
808
+ let e = this.#v[this.#y];
809
+ !e || !this.#M || (this.#x = await this.#Re(e), this.#Ne(e, this.#x));
675
810
  }
676
- async #xe() {
677
- let e = this.#m[this.#h];
678
- !e || !this.#O || (this.#_ = await this.#Te(e), this.#Se(e, this.#_));
811
+ #Ne(e, t) {
812
+ this.#M?.renderSpread(e, t, { fill: this.#m }), this.#Pe();
679
813
  }
680
- #Se(e, t) {
681
- this.#O?.renderSpread(e, t, { fill: this.#f });
814
+ #Pe() {
815
+ let e = this.#M?.measure().book;
816
+ if (!e || e.width <= 0 || e.height <= 0) return;
817
+ let t = (e.width / e.height).toFixed(4);
818
+ t !== this.#g && (this.#g = t, this.#e.style.aspectRatio = t);
682
819
  }
683
- #Ce() {
684
- typeof ResizeObserver > "u" || (this.#C = new ResizeObserver(() => this.#we()), this.#C.observe(this.#e));
820
+ #Fe(e) {
821
+ if (this.#i.state !== "idle") return;
822
+ let t = this.#v[this.#y];
823
+ t && (t.left === e || t.right === e) && this.#Me();
685
824
  }
686
- #we() {
687
- this.#w || (this.#w = !0, requestAnimationFrame(() => {
688
- this.#w = !1, this.update();
825
+ #Ie() {
826
+ typeof ResizeObserver > "u" || (this.#D = new ResizeObserver(() => this.#Le()), this.#D.observe(this.#e));
827
+ }
828
+ #Le() {
829
+ this.#O || (this.#O = !0, requestAnimationFrame(() => {
830
+ this.#O = !1, this.update();
689
831
  }));
690
832
  }
691
- async #Te(e) {
692
- let [t, n] = await Promise.all([this.#Ee(e.left), this.#Ee(e.right)]);
833
+ async #Re(e) {
834
+ let [t, n] = await Promise.all([this.#ze(e.left), this.#ze(e.right)]);
693
835
  return {
694
836
  left: t,
695
837
  right: n
696
838
  };
697
839
  }
698
- async #Ee(e) {
840
+ async #ze(e) {
699
841
  if (e === null) return null;
700
842
  try {
701
843
  return await this.#t.get(e);
@@ -706,59 +848,78 @@ var x = .25, S = .0015, C = 6, w = 250, T = class {
706
848
  }), null;
707
849
  }
708
850
  }
709
- #De() {
710
- let { toMount: e } = this.#r.update(this.#h, this.#m.length), t = [];
851
+ #Be() {
852
+ let { toMount: e } = this.#r.update(this.#y, this.#v.length), t = [];
711
853
  for (let n of e) {
712
- let e = this.#m[n];
854
+ let e = this.#v[n];
713
855
  e?.left != null && t.push(e.left), e?.right != null && t.push(e.right);
714
856
  }
715
857
  this.#t.prefetch(t);
716
858
  }
717
- #Oe(e) {
718
- let t = this.#m.findIndex((t) => t.left === e || t.right === e);
859
+ #Ve(e) {
860
+ let t = this.#v.findIndex((t) => t.left === e || t.right === e);
719
861
  return t === -1 ? 0 : t;
720
862
  }
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, {
863
+ #He() {
864
+ let e = this.#t.pageCount;
865
+ if (!Number.isInteger(e) || e < 1) throw Error(`Zine: source has ${e} pages; a Source must have at least 1 page.`);
866
+ let n = this.#_;
867
+ 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}).`);
868
+ let r = this.#Ae();
869
+ this.#m = r === "single", this.#v = t(e, {
727
870
  direction: this.#a,
728
- cover: this.#o
729
- }), this.#g = E(n ?? 0, 0, t - 1), this.#h = this.#Oe(this.#g);
871
+ mode: r
872
+ }), this.#b = j(n ?? 0, 0, e - 1), this.#y = this.#Ve(this.#b);
730
873
  }
731
874
  };
732
- function E(e, t, n) {
875
+ function j(e, t, n) {
733
876
  return e < t ? t : e > n ? n : e;
734
877
  }
735
- function D(e) {
736
- return e < .5 ? 4 * e * e * e : 1 - (-2 * e + 2) ** 3 / 2;
878
+ function M(e) {
879
+ return e < .5 ? 2 * e * e : 1 - (-2 * e + 2) ** 2 / 2;
880
+ }
881
+ function N(e) {
882
+ return 1 - (1 - M(e)) ** 1.3;
737
883
  }
738
- function O(e) {
884
+ function P(e) {
739
885
  return e === null ? "null" : Array.isArray(e) ? "array" : typeof e;
740
886
  }
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 && ![
887
+ function F(t, n) {
888
+ if (typeof t != "object" || !t || typeof t.appendChild != "function" || typeof t.addEventListener != "function") throw Error(`Zine: container must be a DOM element; received ${P(t)}.`);
889
+ if (typeof n != "object" || !n) throw Error("Zine: an options object with a `source` is required.");
890
+ let r = n, i = r.source;
891
+ 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).");
892
+ let a = r.startPage;
893
+ 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)}.`);
894
+ let o = r.direction;
895
+ if (o !== void 0 && o !== "ltr" && o !== "rtl") throw Error(`Zine: direction must be 'ltr' or 'rtl'; got ${JSON.stringify(o)}.`);
896
+ let s = r.clickToFlip;
897
+ if (s !== void 0 && ![
752
898
  "edge",
753
899
  "half",
754
900
  "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);
901
+ ].includes(s)) throw Error(`Zine: clickToFlip must be 'edge', 'half', or 'off'; got ${JSON.stringify(s)}.`);
902
+ let c = r.curl;
903
+ if (c !== void 0 && !e.includes(c)) throw Error(`Zine: curl must be one of ${e.join(", ")}; got ${JSON.stringify(c)}.`);
904
+ let l = r.spreadMode;
905
+ if (l !== void 0 && ![
906
+ "double",
907
+ "single",
908
+ "cover",
909
+ "book"
910
+ ].includes(l)) throw Error(`Zine: spreadMode must be 'double', 'single', 'cover', or 'book'; got ${JSON.stringify(l)}.`);
911
+ for (let e of ["frontCover", "backCover"]) {
912
+ let t = r[e];
913
+ if (t !== void 0 && typeof t != "string") throw Error(`Zine: ${e} must be an image URL string; got ${JSON.stringify(t)}.`);
914
+ }
915
+ let u = r.pages;
916
+ 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.");
917
+ I(r.width, "width", 1), I(r.height, "height", 1), I(r.flipDuration, "flipDuration", 0), I(r.clickZoneSize, "clickZoneSize", 0), I(r.clickFlipDelay, "clickFlipDelay", 0), I(r.singlePageThreshold, "singlePageThreshold", 0), L(r.zoom), R(r.renderer);
757
918
  }
758
- function A(e, t, n) {
919
+ function I(e, t, n) {
759
920
  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
921
  }
761
- function j(e) {
922
+ function L(e) {
762
923
  if (e === void 0) return;
763
924
  if (typeof e != "object" || !e || Array.isArray(e)) throw Error("Zine: zoom must be an object, e.g. { max: 4 }.");
764
925
  let t = e;
@@ -769,9 +930,9 @@ function j(e) {
769
930
  let e = t.doubleClick;
770
931
  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
932
  }
772
- A(t.max, "zoom.max", 1);
933
+ I(t.max, "zoom.max", 1);
773
934
  }
774
- function M(e) {
935
+ function R(e) {
775
936
  if (e !== void 0) {
776
937
  if (typeof e == "string") {
777
938
  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 +947,7 @@ function M(e) {
786
947
  }
787
948
  //#endregion
788
949
  //#region src/source/imageSource.ts
789
- var N = class {
950
+ var z = class {
790
951
  pageCount;
791
952
  fit;
792
953
  #e;
@@ -823,6 +984,6 @@ var N = class {
823
984
  }
824
985
  };
825
986
  //#endregion
826
- export { N as ImageSource, T as Zine };
987
+ export { e as CURL_TYPES, z as ImageSource, A as Zine };
827
988
 
828
989
  //# sourceMappingURL=index.js.map