@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/README.md +7 -2
- package/dist/cssRenderer-OzRRoEa4.js +127 -0
- package/dist/cssRenderer-OzRRoEa4.js.map +1 -0
- package/dist/engine/spread.d.ts +10 -5
- package/dist/geometry/curls/cone.d.ts +17 -0
- package/dist/geometry/curls/flick.d.ts +20 -0
- package/dist/geometry/curls/index.d.ts +5 -0
- package/dist/geometry/curls/leaf.d.ts +19 -0
- package/dist/geometry/curls/mesh.d.ts +20 -0
- package/dist/geometry/curls/roll.d.ts +8 -0
- package/dist/geometry/curls/simple.d.ts +7 -0
- package/dist/geometry/curls/types.d.ts +25 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +476 -315
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +47 -60
- package/dist/index.umd.cjs.map +1 -1
- package/dist/renderer/types.d.ts +22 -0
- package/dist/renderer/webglRenderer.d.ts +6 -5
- package/dist/source/compose.d.ts +16 -0
- package/dist/source/types.d.ts +6 -0
- package/dist/types-D-rEO00p.js +12 -0
- package/dist/types-D-rEO00p.js.map +1 -0
- package/dist/webglRenderer-Bg6VF4CW.js +558 -0
- package/dist/webglRenderer-Bg6VF4CW.js.map +1 -0
- package/dist/zine.d.ts +12 -3
- package/options.schema.json +27 -7
- package/package.json +1 -1
- package/dist/cssRenderer-BACNXO8M.js +0 -68
- package/dist/cssRenderer-BACNXO8M.js.map +0 -1
- package/dist/flipProgressToPose-DZWSuKoE.js +0 -13
- package/dist/flipProgressToPose-DZWSuKoE.js.map +0 -1
- package/dist/webglRenderer-D-1UyC-B.js +0 -306
- package/dist/webglRenderer-D-1UyC-B.js.map +0 -1
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
|
|
3
|
-
let { direction: n = "ltr",
|
|
3
|
+
function t(e, t = {}) {
|
|
4
|
+
let { direction: n = "ltr", mode: r = "cover" } = t;
|
|
4
5
|
if (e <= 0) return [];
|
|
5
|
-
let
|
|
6
|
-
if (
|
|
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
|
-
|
|
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)
|
|
16
|
-
left:
|
|
17
|
-
right:
|
|
20
|
+
for (let t = 1; t < e; t += 2) a.push({
|
|
21
|
+
left: i(t),
|
|
22
|
+
right: i(t + 1)
|
|
18
23
|
});
|
|
19
|
-
} else
|
|
20
|
-
left:
|
|
21
|
-
right:
|
|
22
|
-
})
|
|
23
|
-
|
|
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
|
-
})) :
|
|
40
|
+
})) : a;
|
|
27
41
|
}
|
|
28
|
-
function
|
|
42
|
+
function n(e, t) {
|
|
29
43
|
return e < t;
|
|
30
44
|
}
|
|
31
45
|
//#endregion
|
|
32
46
|
//#region src/engine/virtualizer.ts
|
|
33
|
-
function
|
|
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
|
|
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
|
|
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
|
-
},
|
|
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
|
-
},
|
|
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
|
|
83
|
-
return
|
|
96
|
+
function s(e, t) {
|
|
97
|
+
return o[e][t] ?? null;
|
|
84
98
|
}
|
|
85
|
-
var
|
|
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 =
|
|
108
|
+
let t = s(this.#e, e);
|
|
95
109
|
return t !== null && (this.#e = t), t;
|
|
96
110
|
}
|
|
97
|
-
},
|
|
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,
|
|
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 >
|
|
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
|
|
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
|
|
192
|
+
function f(e, t) {
|
|
179
193
|
return Math.hypot(e.x - t.x, e.y - t.y);
|
|
180
194
|
}
|
|
181
|
-
var
|
|
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 =
|
|
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 ?
|
|
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
|
|
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
|
|
244
|
-
css: async () => new (await (import("./cssRenderer-
|
|
245
|
-
webgl2: async () => new (await (import("./webglRenderer-
|
|
246
|
-
},
|
|
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
|
|
262
|
+
return typeof e == "object" && !!e && !Array.isArray(e) && typeof e.mount == "function";
|
|
252
263
|
}
|
|
253
|
-
function v() {
|
|
254
|
-
return
|
|
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
|
|
264
|
-
if (
|
|
265
|
-
let n = Array.isArray(e) ? e : e === "auto" ?
|
|
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 =
|
|
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/
|
|
275
|
-
|
|
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
|
|
279
|
-
#r = new
|
|
280
|
-
#i = new
|
|
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
|
|
367
|
+
#f;
|
|
289
368
|
#p;
|
|
290
|
-
#m =
|
|
291
|
-
#h =
|
|
292
|
-
#g =
|
|
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
|
|
303
|
-
#w
|
|
304
|
-
#T
|
|
305
|
-
#E
|
|
306
|
-
#D =
|
|
307
|
-
#O =
|
|
308
|
-
#k =
|
|
309
|
-
#A =
|
|
310
|
-
#j =
|
|
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 =
|
|
313
|
-
#P =
|
|
391
|
+
#N = !1;
|
|
392
|
+
#P = !1;
|
|
314
393
|
#F = null;
|
|
315
394
|
#I = null;
|
|
316
|
-
#L =
|
|
317
|
-
#R =
|
|
318
|
-
#z =
|
|
395
|
+
#L = null;
|
|
396
|
+
#R = null;
|
|
397
|
+
#z = null;
|
|
319
398
|
#B = null;
|
|
320
399
|
#V = null;
|
|
321
400
|
#H = null;
|
|
322
|
-
#U =
|
|
323
|
-
#W =
|
|
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.#
|
|
411
|
+
this.#M?.setFlipProgress(e, t);
|
|
327
412
|
} };
|
|
328
413
|
constructor(e, t) {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
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.#
|
|
338
|
-
let
|
|
339
|
-
this.#
|
|
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.#
|
|
431
|
+
return this.#Z;
|
|
343
432
|
}
|
|
344
433
|
getPageCount() {
|
|
345
434
|
return this.#t.pageCount;
|
|
346
435
|
}
|
|
347
436
|
getPage() {
|
|
348
|
-
return this.#
|
|
437
|
+
return this.#b;
|
|
349
438
|
}
|
|
350
439
|
flipNext() {
|
|
351
|
-
this.#
|
|
440
|
+
this.#Q(() => this.#ne(this.#y + 1));
|
|
352
441
|
}
|
|
353
442
|
flipPrev() {
|
|
354
|
-
this.#
|
|
443
|
+
this.#Q(() => this.#ne(this.#y - 1));
|
|
355
444
|
}
|
|
356
445
|
flipTo(e) {
|
|
357
|
-
let t =
|
|
358
|
-
this.#
|
|
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.#
|
|
461
|
+
return this.#k;
|
|
362
462
|
}
|
|
363
463
|
setZoom(e, t) {
|
|
364
|
-
if (!this.#
|
|
365
|
-
let n =
|
|
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.#
|
|
369
|
-
[o, s] = this.#
|
|
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
|
-
#
|
|
375
|
-
return [
|
|
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.#
|
|
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
|
-
#
|
|
384
|
-
if (e < 0 || e >= this.#
|
|
385
|
-
let t = e > this.#
|
|
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.#
|
|
487
|
+
from: this.#b,
|
|
388
488
|
to: n
|
|
389
|
-
}), this.#
|
|
489
|
+
}), this.#re(e, t, n);
|
|
390
490
|
}
|
|
391
|
-
async #
|
|
392
|
-
let r = this.#
|
|
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.#
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
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.#
|
|
505
|
+
this.#M?.setFlipProgress(t, n), r();
|
|
402
506
|
return;
|
|
403
507
|
}
|
|
404
|
-
let a =
|
|
405
|
-
|
|
406
|
-
|
|
508
|
+
let a = {
|
|
509
|
+
toT: t,
|
|
510
|
+
direction: n,
|
|
511
|
+
onDone: r
|
|
407
512
|
};
|
|
408
|
-
this.#
|
|
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
|
-
#
|
|
411
|
-
let r = this.#
|
|
412
|
-
this.#
|
|
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
|
-
#
|
|
415
|
-
let t = this.#
|
|
416
|
-
if (!t) return this.#
|
|
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.#
|
|
529
|
+
return n.length > 0 ? Math.min(...n) : this.#b;
|
|
419
530
|
}
|
|
420
|
-
#
|
|
421
|
-
if (this.#
|
|
422
|
-
if (this.#
|
|
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.#
|
|
425
|
-
baseTx: this.#
|
|
426
|
-
baseTy: this.#
|
|
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.#
|
|
435
|
-
let
|
|
436
|
-
if (
|
|
437
|
-
width:
|
|
438
|
-
height:
|
|
439
|
-
},
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
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.#
|
|
450
|
-
e && (this.#
|
|
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.#
|
|
573
|
+
from: this.#b,
|
|
462
574
|
to: e.toPage
|
|
463
|
-
}), this.#
|
|
575
|
+
}), this.#le(e.targetIndex, e.direction)));
|
|
464
576
|
}
|
|
465
|
-
async #
|
|
466
|
-
let n = this.#
|
|
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.#
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
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.#
|
|
481
|
-
let n = this.#
|
|
482
|
-
n && (n.t =
|
|
483
|
-
}
|
|
484
|
-
#
|
|
485
|
-
if (this.#
|
|
486
|
-
if (this.#
|
|
487
|
-
this.#
|
|
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.#
|
|
606
|
+
let t = this.#I;
|
|
491
607
|
if (!t) {
|
|
492
|
-
this.#
|
|
608
|
+
this.#L = null, this.#fe(e);
|
|
493
609
|
return;
|
|
494
610
|
}
|
|
495
|
-
this.#
|
|
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.#
|
|
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
|
-
#
|
|
500
|
-
if (this.#
|
|
501
|
-
let t = this.#
|
|
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 =
|
|
504
|
-
if (
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
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
|
-
#
|
|
515
|
-
if (!this.#
|
|
516
|
-
let
|
|
517
|
-
if (n = this.#
|
|
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
|
-
#
|
|
522
|
-
this.#
|
|
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
|
-
#
|
|
537
|
-
|
|
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.#
|
|
665
|
+
this.setZoom(this.#W * n, {
|
|
540
666
|
x: e - r.left,
|
|
541
667
|
y: t - r.top
|
|
542
668
|
});
|
|
543
669
|
}
|
|
544
|
-
#
|
|
545
|
-
this.#
|
|
670
|
+
#ye() {
|
|
671
|
+
this.#U = !1;
|
|
546
672
|
}
|
|
547
|
-
#
|
|
673
|
+
#be() {
|
|
548
674
|
let e = (e) => {
|
|
549
|
-
if (!this.#
|
|
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 *
|
|
552
|
-
this.setZoom(this.#
|
|
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.#
|
|
683
|
+
this.#e.addEventListener("wheel", e, { passive: !1 }), this.#J = () => this.#e.removeEventListener("wheel", e);
|
|
558
684
|
}
|
|
559
|
-
#
|
|
685
|
+
#xe() {
|
|
560
686
|
let e = (e) => {
|
|
561
|
-
let t = this.#
|
|
562
|
-
if (!this.#
|
|
563
|
-
if (this.#
|
|
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.#
|
|
694
|
+
if (this.#me(n) !== null) return;
|
|
569
695
|
}
|
|
570
|
-
this.#
|
|
571
|
-
let n = t.find((e) => e > this.#
|
|
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.#
|
|
578
|
-
}
|
|
579
|
-
async #
|
|
580
|
-
let t =
|
|
581
|
-
typeof this.#t.open == "function" && (await this.#t.open(), this.#
|
|
582
|
-
let n = await t, r = await this.#
|
|
583
|
-
this.#
|
|
584
|
-
let i = new
|
|
585
|
-
onStart: (e) => this.#
|
|
586
|
-
onMove: (e) => this.#
|
|
587
|
-
onEnd: (e) => this.#
|
|
588
|
-
}), a = new
|
|
589
|
-
onPinchStart: () => this.#
|
|
590
|
-
onPinchMove: (e) => this.#
|
|
591
|
-
onPinchEnd: () => this.#
|
|
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.#
|
|
719
|
+
this.#q = d(this.#e, {
|
|
594
720
|
pointer: i,
|
|
595
721
|
pinch: a
|
|
596
|
-
}), this.#
|
|
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 #
|
|
724
|
+
async #Ce(e) {
|
|
599
725
|
try {
|
|
600
726
|
return await e.mount(this.#e), e.onFatal?.(() => {
|
|
601
|
-
this.#
|
|
727
|
+
this.#we();
|
|
602
728
|
}), e;
|
|
603
729
|
} catch {
|
|
604
730
|
e.destroy();
|
|
605
|
-
let t = await
|
|
606
|
-
return await t.mount(this.#e), this.#
|
|
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 #
|
|
613
|
-
if (this.#
|
|
614
|
-
this.#
|
|
615
|
-
let e = await
|
|
616
|
-
if (this.#
|
|
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.#
|
|
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
|
-
#
|
|
751
|
+
#Te() {
|
|
626
752
|
if (typeof matchMedia != "function") return;
|
|
627
753
|
let e = matchMedia("(prefers-reduced-motion: reduce)");
|
|
628
|
-
this.#
|
|
629
|
-
this.#
|
|
754
|
+
this.#G = e.matches, e.addEventListener?.("change", (e) => {
|
|
755
|
+
this.#G = e.matches;
|
|
630
756
|
});
|
|
631
757
|
}
|
|
632
|
-
#
|
|
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.#
|
|
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.#
|
|
640
|
-
e.removeEventListener("keydown", n), r.remove(), this.#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
660
|
-
this.#
|
|
785
|
+
#Oe() {
|
|
786
|
+
this.#K && (this.#K.textContent = `Page ${this.#b + 1} of ${this.#t.pageCount}`);
|
|
661
787
|
}
|
|
662
|
-
#
|
|
663
|
-
return this.#
|
|
788
|
+
#ke() {
|
|
789
|
+
return this.#G ? 0 : this.#S * (this.#m ? k : 1);
|
|
664
790
|
}
|
|
665
791
|
update() {
|
|
666
|
-
!this.#
|
|
792
|
+
!this.#M || this.#i.state !== "idle" || (this.#je(this.#M.measure().containerWidth), this.#Me());
|
|
667
793
|
}
|
|
668
|
-
#
|
|
669
|
-
|
|
670
|
-
|
|
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
|
-
|
|
673
|
-
|
|
674
|
-
|
|
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
|
-
|
|
677
|
-
|
|
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
|
-
#
|
|
681
|
-
|
|
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
|
-
#
|
|
684
|
-
|
|
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
|
-
#
|
|
687
|
-
|
|
688
|
-
|
|
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 #
|
|
692
|
-
let [t, n] = await Promise.all([this.#
|
|
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 #
|
|
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
|
-
#
|
|
710
|
-
let { toMount: e } = this.#r.update(this.#
|
|
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.#
|
|
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
|
-
#
|
|
718
|
-
let t = this.#
|
|
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
|
-
#
|
|
722
|
-
let
|
|
723
|
-
if (!Number.isInteger(
|
|
724
|
-
let n = this.#
|
|
725
|
-
if (n !== void 0 && (!Number.isInteger(n) || n < 0 || n >=
|
|
726
|
-
|
|
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
|
-
|
|
729
|
-
}), this.#
|
|
871
|
+
mode: r
|
|
872
|
+
}), this.#b = j(n ?? 0, 0, e - 1), this.#y = this.#Ve(this.#b);
|
|
730
873
|
}
|
|
731
874
|
};
|
|
732
|
-
function
|
|
875
|
+
function j(e, t, n) {
|
|
733
876
|
return e < t ? t : e > n ? n : e;
|
|
734
877
|
}
|
|
735
|
-
function
|
|
736
|
-
return e < .5 ?
|
|
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
|
|
884
|
+
function P(e) {
|
|
739
885
|
return e === null ? "null" : Array.isArray(e) ? "array" : typeof e;
|
|
740
886
|
}
|
|
741
|
-
function
|
|
742
|
-
if (typeof
|
|
743
|
-
if (typeof
|
|
744
|
-
let
|
|
745
|
-
if (typeof
|
|
746
|
-
let
|
|
747
|
-
if (
|
|
748
|
-
let
|
|
749
|
-
if (
|
|
750
|
-
let
|
|
751
|
-
if (
|
|
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(
|
|
756
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
933
|
+
I(t.max, "zoom.max", 1);
|
|
773
934
|
}
|
|
774
|
-
function
|
|
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
|
|
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 {
|
|
987
|
+
export { e as CURL_TYPES, z as ImageSource, A as Zine };
|
|
827
988
|
|
|
828
989
|
//# sourceMappingURL=index.js.map
|