@zinejs/core 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{cssRenderer-OzRRoEa4.js → cssRenderer-Deskm2ND.js} +9 -3
- package/dist/{cssRenderer-OzRRoEa4.js.map → cssRenderer-Deskm2ND.js.map} +1 -1
- package/dist/index.js +113 -190
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +3 -3
- package/dist/index.umd.js.map +1 -1
- package/dist/renderer/types.d.ts +15 -0
- package/dist/{webglRenderer-BcNhTqG8.js → webglRenderer-D_XGumQT.js} +12 -3
- package/dist/webglRenderer-D_XGumQT.js.map +1 -0
- package/package.json +1 -1
- package/dist/engine/zoomTile.d.ts +0 -65
- package/dist/webglRenderer-BcNhTqG8.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -291,127 +291,49 @@ function T(e, t) {
|
|
|
291
291
|
}
|
|
292
292
|
//#endregion
|
|
293
293
|
//#region src/renderer/select.ts
|
|
294
|
-
var
|
|
295
|
-
css: async () => new (await (import("./cssRenderer-
|
|
296
|
-
webgl2: async () => new (await (import("./webglRenderer-
|
|
297
|
-
},
|
|
298
|
-
function D(e) {
|
|
299
|
-
return typeof e == "object" && !!e && !Array.isArray(e) && typeof e.mount == "function";
|
|
300
|
-
}
|
|
294
|
+
var E = {
|
|
295
|
+
css: async () => new (await (import("./cssRenderer-Deskm2ND.js"))).CssRenderer(),
|
|
296
|
+
webgl2: async () => new (await (import("./webglRenderer-D_XGumQT.js"))).WebglRenderer()
|
|
297
|
+
}, D = !0;
|
|
301
298
|
function O(e) {
|
|
302
|
-
return e
|
|
299
|
+
return typeof e == "object" && !!e && !Array.isArray(e) && typeof e.mount == "function";
|
|
303
300
|
}
|
|
304
|
-
function k() {
|
|
305
|
-
return
|
|
301
|
+
function k(e) {
|
|
302
|
+
return e.gpu && D ? ["webgl2", "css"] : ["css"];
|
|
306
303
|
}
|
|
307
304
|
function A() {
|
|
305
|
+
return { gpu: j() };
|
|
306
|
+
}
|
|
307
|
+
function j() {
|
|
308
308
|
try {
|
|
309
309
|
return !!document.createElement("canvas").getContext("webgl2");
|
|
310
310
|
} catch {
|
|
311
311
|
return !1;
|
|
312
312
|
}
|
|
313
313
|
}
|
|
314
|
-
async function
|
|
315
|
-
if (
|
|
316
|
-
let n = Array.isArray(e) ? e : e === "auto" ?
|
|
314
|
+
async function M(e = "auto", t = A()) {
|
|
315
|
+
if (O(e)) return e;
|
|
316
|
+
let n = Array.isArray(e) ? e : e === "auto" ? k(t) : [e];
|
|
317
317
|
for (let e of n) {
|
|
318
318
|
if (e === "webgl2" && !t.gpu) continue;
|
|
319
|
-
let n =
|
|
319
|
+
let n = E[e];
|
|
320
320
|
if (n) return n();
|
|
321
321
|
}
|
|
322
322
|
throw n.length === 1 && n[0] === "webgl2" && !t.gpu ? Error("renderer: 'webgl2' was forced but this device has no WebGL2. Use 'css' or 'auto'.") : Error(`renderer: none of [${n.join(", ")}] could be loaded — use 'css' or 'auto'.`);
|
|
323
323
|
}
|
|
324
324
|
//#endregion
|
|
325
|
-
//#region src/engine/zoomTile.ts
|
|
326
|
-
function M(e, t) {
|
|
327
|
-
let n = Math.max(e.x, t.x), r = Math.max(e.y, t.y), i = Math.min(e.x + e.width, t.x + t.width), a = Math.min(e.y + e.height, t.y + t.height);
|
|
328
|
-
return i <= n || a <= r ? null : {
|
|
329
|
-
x: n,
|
|
330
|
-
y: r,
|
|
331
|
-
width: i - n,
|
|
332
|
-
height: a - r
|
|
333
|
-
};
|
|
334
|
-
}
|
|
335
|
-
function N(e, t, n) {
|
|
336
|
-
let { scale: r, tx: i, ty: a } = t;
|
|
337
|
-
if (r <= 1) return [];
|
|
338
|
-
let o = {
|
|
339
|
-
x: (n.x - i) / r,
|
|
340
|
-
y: (n.y - a) / r,
|
|
341
|
-
width: n.width / r,
|
|
342
|
-
height: n.height / r
|
|
343
|
-
}, s = [];
|
|
344
|
-
for (let t of e) {
|
|
345
|
-
let e = M(t.rect, o);
|
|
346
|
-
!e || t.rect.width <= 0 || t.rect.height <= 0 || s.push({
|
|
347
|
-
index: t.index,
|
|
348
|
-
request: {
|
|
349
|
-
scale: r,
|
|
350
|
-
region: {
|
|
351
|
-
x: (e.x - t.rect.x) / t.rect.width,
|
|
352
|
-
y: (e.y - t.rect.y) / t.rect.height,
|
|
353
|
-
width: e.width / t.rect.width,
|
|
354
|
-
height: e.height / t.rect.height
|
|
355
|
-
}
|
|
356
|
-
},
|
|
357
|
-
dest: e
|
|
358
|
-
});
|
|
359
|
-
}
|
|
360
|
-
return s;
|
|
361
|
-
}
|
|
362
|
-
function P(e, t) {
|
|
363
|
-
if (e.index !== t.index || e.request.scale !== t.request.scale) return !1;
|
|
364
|
-
let n = e.request.region, r = t.request.region, i = 1e-4;
|
|
365
|
-
return Math.abs(n.x - r.x) < i && Math.abs(n.y - r.y) < i && Math.abs(n.width - r.width) < i && Math.abs(n.height - r.height) < i;
|
|
366
|
-
}
|
|
367
|
-
var F = class {
|
|
368
|
-
#e;
|
|
369
|
-
#t;
|
|
370
|
-
#n = [];
|
|
371
|
-
constructor(e, t) {
|
|
372
|
-
this.#e = e.createElement("canvas"), this.#e.className = "zine-zoom-overlay", this.#e.style.cssText = "position:absolute;inset:0;pointer-events:none;opacity:0;transition:opacity 120ms linear;", t.append(this.#e), this.#t = this.#e.getContext("2d");
|
|
373
|
-
}
|
|
374
|
-
clear() {
|
|
375
|
-
if (this.#n.length === 0) return;
|
|
376
|
-
this.#n = [], this.#e.style.opacity = "0";
|
|
377
|
-
let e = this.#t;
|
|
378
|
-
e && e.clearRect(0, 0, this.#e.width, this.#e.height);
|
|
379
|
-
}
|
|
380
|
-
get shown() {
|
|
381
|
-
return this.#n;
|
|
382
|
-
}
|
|
383
|
-
draw(e, t, n) {
|
|
384
|
-
let r = this.#t;
|
|
385
|
-
if (!r) return;
|
|
386
|
-
if (e.length === 0) {
|
|
387
|
-
this.clear();
|
|
388
|
-
return;
|
|
389
|
-
}
|
|
390
|
-
let i = typeof devicePixelRatio == "number" ? devicePixelRatio : 1, a = Math.max(1, Math.ceil(n.width * i)), o = Math.max(1, Math.ceil(n.height * i));
|
|
391
|
-
(this.#e.width !== a || this.#e.height !== o) && (this.#e.width = a, this.#e.height = o), r.setTransform(i, 0, 0, i, 0, 0), r.clearRect(0, 0, n.width, n.height), r.translate(t.tx, t.ty), r.scale(t.scale, t.scale);
|
|
392
|
-
for (let { plan: t, content: n } of e) {
|
|
393
|
-
let e = t.dest;
|
|
394
|
-
r.drawImage(n, e.x, e.y, e.width, e.height);
|
|
395
|
-
}
|
|
396
|
-
this.#n = e.map((e) => e.plan), this.#e.style.opacity = "1";
|
|
397
|
-
}
|
|
398
|
-
destroy() {
|
|
399
|
-
this.#e.remove(), this.#t = null;
|
|
400
|
-
}
|
|
401
|
-
};
|
|
402
|
-
//#endregion
|
|
403
325
|
//#region src/source/compose.ts
|
|
404
|
-
function
|
|
326
|
+
function N(e, t) {
|
|
405
327
|
let n = typeof t.frontCover == "string", r = typeof t.backCover == "string", i = t.pages != null && Object.keys(t.pages).length > 0;
|
|
406
|
-
return !n && !r && !i ? e : new
|
|
328
|
+
return !n && !r && !i ? e : new F(e, t);
|
|
407
329
|
}
|
|
408
|
-
function
|
|
330
|
+
function P(e) {
|
|
409
331
|
return fetch(e).then((t) => {
|
|
410
332
|
if (!t.ok) throw Error(`zine: could not load image "${e}" (HTTP ${t.status}).`);
|
|
411
333
|
return t.blob();
|
|
412
334
|
}).then((e) => createImageBitmap(e));
|
|
413
335
|
}
|
|
414
|
-
var
|
|
336
|
+
var F = class {
|
|
415
337
|
#e;
|
|
416
338
|
#t;
|
|
417
339
|
#n;
|
|
@@ -479,16 +401,16 @@ var R = class {
|
|
|
479
401
|
}
|
|
480
402
|
#s(e) {
|
|
481
403
|
let t = this.#a.get(e);
|
|
482
|
-
return t === void 0 && (t =
|
|
404
|
+
return t === void 0 && (t = P(e).catch((t) => {
|
|
483
405
|
throw this.#a.delete(e), t;
|
|
484
406
|
}), this.#a.set(e, t)), t;
|
|
485
407
|
}
|
|
486
|
-
},
|
|
487
|
-
function
|
|
488
|
-
let r = Math.max(0, t -
|
|
408
|
+
}, I = .25, L = .0015, R = 6, z = 250, B = 1.55, V = 32, H = 60, U = 2.5, W = 120;
|
|
409
|
+
function G(e, t, n) {
|
|
410
|
+
let r = Math.max(0, t - V), i = Math.min(e.length, t + n + V), a = e.slice(r, i).replace(/\s+/g, " ").trim();
|
|
489
411
|
return `${r > 0 ? "…" : ""}${a}${i < e.length ? "…" : ""}`;
|
|
490
412
|
}
|
|
491
|
-
var
|
|
413
|
+
var K = class {
|
|
492
414
|
#e;
|
|
493
415
|
#t;
|
|
494
416
|
#n = new l();
|
|
@@ -556,7 +478,7 @@ var J = class {
|
|
|
556
478
|
#se = /* @__PURE__ */ new Set();
|
|
557
479
|
#ce;
|
|
558
480
|
#le = null;
|
|
559
|
-
#ue =
|
|
481
|
+
#ue = 1;
|
|
560
482
|
#de = 0;
|
|
561
483
|
#fe = null;
|
|
562
484
|
#pe;
|
|
@@ -564,7 +486,7 @@ var J = class {
|
|
|
564
486
|
this.#z?.setFlipProgress(e, t);
|
|
565
487
|
} };
|
|
566
488
|
constructor(e, t) {
|
|
567
|
-
|
|
489
|
+
Q(e, t), this.#e = e, t.width !== void 0 && (e.style.width = `${t.width}px`), t.height !== void 0 && (e.style.height = `${t.height}px`), this.#t = N(t.source, {
|
|
568
490
|
frontCover: t.frontCover,
|
|
569
491
|
backCover: t.backCover,
|
|
570
492
|
pages: t.pages
|
|
@@ -578,7 +500,7 @@ var J = class {
|
|
|
578
500
|
]].sort((e, t) => e - t);
|
|
579
501
|
this.#M = i.length > 0 ? i : null, this.#N = t.zoom?.max ?? 4;
|
|
580
502
|
let a = this.#A && this.#M !== null, o = t.zoom?.doubleClickInFlipZone ?? this.#u === "half";
|
|
581
|
-
this.#f = this.#u !== "off" && a && o && t.clickFlipDelay !== 0, this.#p = this.#f ? t.clickFlipDelay ??
|
|
503
|
+
this.#f = this.#u !== "off" && a && o && t.clickFlipDelay !== 0, this.#p = this.#f ? t.clickFlipDelay ?? z : 0, this.#pe = this.#Ve(t.renderer ?? "auto");
|
|
582
504
|
}
|
|
583
505
|
get ready() {
|
|
584
506
|
return this.#pe;
|
|
@@ -717,7 +639,7 @@ var J = class {
|
|
|
717
639
|
let i = t.toLowerCase().indexOf(r);
|
|
718
640
|
i < 0 || a.push({
|
|
719
641
|
page: e,
|
|
720
|
-
excerpt:
|
|
642
|
+
excerpt: G(t, i, r.length)
|
|
721
643
|
});
|
|
722
644
|
}
|
|
723
645
|
return a;
|
|
@@ -732,7 +654,7 @@ var J = class {
|
|
|
732
654
|
this.#he(() => this.#ye(this.#E + e));
|
|
733
655
|
}
|
|
734
656
|
flipTo(e) {
|
|
735
|
-
let t =
|
|
657
|
+
let t = q(e, 0, Math.max(0, this.#t.pageCount - 1));
|
|
736
658
|
this.#he(() => this.#ye(this.#mt(t)));
|
|
737
659
|
}
|
|
738
660
|
#he(e) {
|
|
@@ -755,23 +677,32 @@ var J = class {
|
|
|
755
677
|
}
|
|
756
678
|
setZoom(e, t) {
|
|
757
679
|
if (!this.#z || !this.#A) return;
|
|
758
|
-
let n =
|
|
680
|
+
let n = q(e, 1, this.#N), r = this.#z.measure(), i = r.screenAt?.(this.#I), a = t ?? (i ? {
|
|
681
|
+
x: i.x + this.#L + i.width / 2,
|
|
682
|
+
y: i.y + this.#R + i.height / 2
|
|
683
|
+
} : null) ?? {
|
|
759
684
|
x: r.containerWidth / 2,
|
|
760
685
|
y: r.containerHeight / 2
|
|
761
|
-
},
|
|
762
|
-
[
|
|
686
|
+
}, o = this.#I, s = n === 1 ? 0 : a.x - n / o * (a.x - this.#L), c = n === 1 ? 0 : a.y - n / o * (a.y - this.#R);
|
|
687
|
+
[s, c] = this.#ve(s, c, n, r.containerWidth, r.containerHeight), this.#I = n, this.#L = s, this.#R = c, this.#z.setViewTransform(n, s, c), this.#at(), this.#n.emit("zoomChanged", { scale: n });
|
|
763
688
|
}
|
|
764
689
|
resetZoom() {
|
|
765
690
|
this.setZoom(1);
|
|
766
691
|
}
|
|
767
692
|
#ve(e, t, n, r, i) {
|
|
768
|
-
|
|
693
|
+
let a = typeof devicePixelRatio == "number" && devicePixelRatio > 0 ? devicePixelRatio : 1, o = (e) => Math.round(e * a) / a || 0, s = this.#z?.measure().screenAt?.(n) ?? {
|
|
694
|
+
x: 0,
|
|
695
|
+
y: 0,
|
|
696
|
+
width: r * n,
|
|
697
|
+
height: i * n
|
|
698
|
+
}, [c, l] = J(s.x, s.width, r), [u, d] = J(s.y, s.height, i);
|
|
699
|
+
return [o(q(e, c, l)), o(q(t, u, d))];
|
|
769
700
|
}
|
|
770
701
|
on(e, t) {
|
|
771
702
|
return this.#n.on(e, t);
|
|
772
703
|
}
|
|
773
704
|
destroy() {
|
|
774
|
-
this.#V = !0, this.#H !== null && cancelAnimationFrame(this.#H), this.#J = null, this.#q = null, this.#Ne(), this.#P?.disconnect(), this.#C?.stop(), this.#C = null, this.#w?.(), this.#x && S(), this.#le?.(), this.#ae?.(), this.#ne?.(), this.#ie?.(), this.#re?.(), this.#te?.(), this.#fe !== null && clearTimeout(this.#fe), this.#de++, this.#
|
|
705
|
+
this.#V = !0, this.#H !== null && cancelAnimationFrame(this.#H), this.#J = null, this.#q = null, this.#Ne(), this.#P?.disconnect(), this.#C?.stop(), this.#C = null, this.#w?.(), this.#x && S(), this.#le?.(), this.#ae?.(), this.#ne?.(), this.#ie?.(), this.#re?.(), this.#te?.(), this.#fe !== null && clearTimeout(this.#fe), this.#de++, this.#z?.destroy(), this.#z = null, this.#t.destroy(), this.#n.clear();
|
|
775
706
|
}
|
|
776
707
|
#ye(e) {
|
|
777
708
|
if (e < 0 || e >= this.#T.length || e === this.#E || this.#i.send("flip") === null) return;
|
|
@@ -806,7 +737,7 @@ var J = class {
|
|
|
806
737
|
this.#J = a;
|
|
807
738
|
let o = performance.now(), s = (c) => {
|
|
808
739
|
if (this.#J !== a) return;
|
|
809
|
-
let l = Math.min(1, (c - o) / i), u = this.#h ?
|
|
740
|
+
let l = Math.min(1, (c - o) / i), u = this.#h ? X(l) : Y(l);
|
|
810
741
|
this.#z?.setFlipProgress(e + (t - e) * u, n), l < 1 ? this.#H = requestAnimationFrame(s) : (this.#H = null, this.#J = null, r());
|
|
811
742
|
};
|
|
812
743
|
this.#H = requestAnimationFrame(s);
|
|
@@ -836,12 +767,12 @@ var J = class {
|
|
|
836
767
|
this.#W = null;
|
|
837
768
|
return;
|
|
838
769
|
}
|
|
839
|
-
let i = Math.min(n.width, n.height) *
|
|
770
|
+
let i = Math.min(n.width, n.height) * I;
|
|
840
771
|
if (v(r, {
|
|
841
772
|
width: n.width,
|
|
842
773
|
height: n.height
|
|
843
774
|
}, i) !== "corner") return;
|
|
844
|
-
this.#l =
|
|
775
|
+
this.#l = q(r.y / n.height, 0, 1);
|
|
845
776
|
let a = r.x > n.width / 2, o = this.#a === "rtl" ? !a : a, s = this.#E + (o ? 1 : -1);
|
|
846
777
|
s < 0 || s >= this.#T.length || (this.#W = {
|
|
847
778
|
direction: o ? "forward" : "backward",
|
|
@@ -886,9 +817,9 @@ var J = class {
|
|
|
886
817
|
this.#L = r, this.#R = i, this.#z.setViewTransform(this.#I, r, i), this.#at();
|
|
887
818
|
return;
|
|
888
819
|
}
|
|
889
|
-
this.#W && Math.hypot(e, t) >
|
|
820
|
+
this.#W && Math.hypot(e, t) > R && this.#Te();
|
|
890
821
|
let n = this.#U;
|
|
891
|
-
n && (n.t =
|
|
822
|
+
n && (n.t = q((n.direction === "forward" ? -e : e) / n.width, 0, 1), this.#z?.setFlipProgress(n.t, n.direction));
|
|
892
823
|
}
|
|
893
824
|
#Oe(e) {
|
|
894
825
|
if (this.#Z) return;
|
|
@@ -906,12 +837,12 @@ var J = class {
|
|
|
906
837
|
t.t >= .5 || n ? this.#xe(t.t, 1, t.direction, () => this.#Se(t.targetIndex, t.toPage, t.toContent)) : this.#xe(t.t, 0, t.direction, () => this.#Pe());
|
|
907
838
|
}
|
|
908
839
|
#ke(e) {
|
|
909
|
-
if (this.#u === "off" || this.#I > 1 || !this.#G || Math.abs(e.dx) >
|
|
840
|
+
if (this.#u === "off" || this.#I > 1 || !this.#G || Math.abs(e.dx) > R || Math.abs(e.dy) > R) return;
|
|
910
841
|
let t = this.#Me(this.#G);
|
|
911
842
|
if (!t) return;
|
|
912
843
|
let n = t === "forward" ? 1 : -1;
|
|
913
844
|
if (this.#E + n < 0 || this.#E + n >= this.#T.length) return;
|
|
914
|
-
this.#l =
|
|
845
|
+
this.#l = q(this.#G.y / this.#Ae().height, 0, 1);
|
|
915
846
|
let r = () => this.#ye(this.#E + n);
|
|
916
847
|
if (this.#Ne(), this.#p <= 0) {
|
|
917
848
|
this.#he(r);
|
|
@@ -979,7 +910,7 @@ var J = class {
|
|
|
979
910
|
let e = (e) => {
|
|
980
911
|
if (!this.#j || !this.#A || !(e.ctrlKey || e.metaKey)) return;
|
|
981
912
|
e.preventDefault();
|
|
982
|
-
let t = this.#e.getBoundingClientRect(), n = Math.exp(-e.deltaY *
|
|
913
|
+
let t = this.#e.getBoundingClientRect(), n = Math.exp(-e.deltaY * L);
|
|
983
914
|
this.setZoom(this.#I * n, {
|
|
984
915
|
x: e.clientX - t.left,
|
|
985
916
|
y: e.clientY - t.top
|
|
@@ -1005,7 +936,7 @@ var J = class {
|
|
|
1005
936
|
this.#e.addEventListener("dblclick", e), this.#ie = () => this.#e.removeEventListener("dblclick", e);
|
|
1006
937
|
}
|
|
1007
938
|
async #Ve(e) {
|
|
1008
|
-
let t =
|
|
939
|
+
let t = M(e);
|
|
1009
940
|
typeof this.#t.open == "function" && (await this.#t.open(), this.#ht()), this.#t.prefetch([this.#D]);
|
|
1010
941
|
let n = await t, r = await this.#He(n);
|
|
1011
942
|
this.#z = r, this.#t.onPageUpdate?.((e) => this.#it(e)), this.#$e(r.measure().containerWidth);
|
|
@@ -1030,7 +961,7 @@ var J = class {
|
|
|
1030
961
|
}), e;
|
|
1031
962
|
} catch {
|
|
1032
963
|
e.destroy();
|
|
1033
|
-
let t = await
|
|
964
|
+
let t = await M("css");
|
|
1034
965
|
return await t.mount(this.#e), this.#B = !0, this.#n.emit("rendererFallback", {
|
|
1035
966
|
from: "webgl2",
|
|
1036
967
|
to: "css"
|
|
@@ -1040,7 +971,7 @@ var J = class {
|
|
|
1040
971
|
async #Ue() {
|
|
1041
972
|
if (this.#B || this.#V) return;
|
|
1042
973
|
this.#B = !0, this.#z?.destroy(), this.#z = null;
|
|
1043
|
-
let e = await
|
|
974
|
+
let e = await M("css");
|
|
1044
975
|
if (this.#V) {
|
|
1045
976
|
e.destroy();
|
|
1046
977
|
return;
|
|
@@ -1080,7 +1011,7 @@ var J = class {
|
|
|
1080
1011
|
let t = globalThis.location?.href ?? "";
|
|
1081
1012
|
if (!t) return "";
|
|
1082
1013
|
let n = new URL(t);
|
|
1083
|
-
return n.hash = w(n.hash,
|
|
1014
|
+
return n.hash = w(n.hash, q(e, 0, Math.max(0, this.#t.pageCount - 1))), n.toString();
|
|
1084
1015
|
}
|
|
1085
1016
|
#qe() {
|
|
1086
1017
|
let e = this.#e, t = e.ownerDocument;
|
|
@@ -1113,7 +1044,7 @@ var J = class {
|
|
|
1113
1044
|
this.#ee && (this.#ee.textContent = `Page ${this.#D + 1} of ${this.#t.pageCount}`);
|
|
1114
1045
|
}
|
|
1115
1046
|
#Xe() {
|
|
1116
|
-
return this.#$ ?
|
|
1047
|
+
return this.#$ ? W : this.#k * (this.#h ? B : 1);
|
|
1117
1048
|
}
|
|
1118
1049
|
#Ze() {
|
|
1119
1050
|
return this.#$ ? "simple" : this.#c;
|
|
@@ -1143,7 +1074,7 @@ var J = class {
|
|
|
1143
1074
|
!e || !this.#z || (this.#O = await this.#dt(e), this.#nt(e, this.#O));
|
|
1144
1075
|
}
|
|
1145
1076
|
#nt(e, t) {
|
|
1146
|
-
this.#z?.renderSpread(e, t, { fill: this.#h }), this.#rt(), this.#ue
|
|
1077
|
+
this.#z?.renderSpread(e, t, { fill: this.#h }), this.#rt(), this.#ue = 1, this.#at();
|
|
1147
1078
|
}
|
|
1148
1079
|
#rt() {
|
|
1149
1080
|
let e = this.#z?.measure().book;
|
|
@@ -1160,66 +1091,51 @@ var J = class {
|
|
|
1160
1091
|
t && (t.left === e || t.right === e) && this.#tt();
|
|
1161
1092
|
}
|
|
1162
1093
|
#at() {
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
}, G);
|
|
1170
|
-
}
|
|
1171
|
-
async #ot() {
|
|
1172
|
-
let e = this.#z, t = this.#T[this.#E];
|
|
1173
|
-
if (!e || !t || this.#I <= 1) return;
|
|
1174
|
-
let n = e.measure(), r = n.content ?? n.book;
|
|
1175
|
-
if (!r) return;
|
|
1176
|
-
let i = [], a = t.left === null || t.right === null, o = a ? r.width : r.width / 2;
|
|
1177
|
-
t.left !== null && i.push({
|
|
1178
|
-
index: t.left,
|
|
1179
|
-
rect: {
|
|
1180
|
-
...r,
|
|
1181
|
-
width: o
|
|
1182
|
-
}
|
|
1183
|
-
}), t.right !== null && i.push({
|
|
1184
|
-
index: t.right,
|
|
1185
|
-
rect: {
|
|
1186
|
-
...r,
|
|
1187
|
-
x: r.x + (a ? 0 : o),
|
|
1188
|
-
width: o
|
|
1094
|
+
this.#fe !== null && clearTimeout(this.#fe);
|
|
1095
|
+
let e = this.#ot();
|
|
1096
|
+
if (e !== this.#ue) {
|
|
1097
|
+
if (e === 1) {
|
|
1098
|
+
this.#de++, this.#ue = 1, this.#tt();
|
|
1099
|
+
return;
|
|
1189
1100
|
}
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1101
|
+
this.#fe = setTimeout(() => {
|
|
1102
|
+
this.#fe = null, this.#st();
|
|
1103
|
+
}, H);
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
#ot() {
|
|
1107
|
+
return this.#I <= 1 ? 1 : Math.min(Math.ceil(this.#I * 2) / 2, U);
|
|
1108
|
+
}
|
|
1109
|
+
async #st() {
|
|
1110
|
+
let e = this.#T[this.#E];
|
|
1111
|
+
if (!this.#z || !e) return;
|
|
1112
|
+
let t = this.#ot();
|
|
1113
|
+
if (t === 1 || t === this.#ue) return;
|
|
1114
|
+
let n = ++this.#de, r = {
|
|
1196
1115
|
x: 0,
|
|
1197
1116
|
y: 0,
|
|
1198
|
-
width:
|
|
1199
|
-
height:
|
|
1200
|
-
},
|
|
1201
|
-
|
|
1202
|
-
let d = ++this.#de, f = await Promise.all(l.map(async (e) => {
|
|
1117
|
+
width: 1,
|
|
1118
|
+
height: 1
|
|
1119
|
+
}, i = await Promise.all([e.left, e.right].map(async (e) => {
|
|
1120
|
+
if (e === null) return null;
|
|
1203
1121
|
try {
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
};
|
|
1122
|
+
return await this.#t.get(e, {
|
|
1123
|
+
scale: t,
|
|
1124
|
+
region: r
|
|
1125
|
+
});
|
|
1209
1126
|
} catch (t) {
|
|
1210
1127
|
return this.#n.emit("sourceError", {
|
|
1211
|
-
index: e
|
|
1128
|
+
index: e,
|
|
1212
1129
|
error: t
|
|
1213
1130
|
}), null;
|
|
1214
1131
|
}
|
|
1215
1132
|
}));
|
|
1216
|
-
if (
|
|
1217
|
-
let
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
return !e || typeof this.#e.append != "function" ? null : new F(e, this.#e);
|
|
1133
|
+
if (n !== this.#de || this.#ot() !== t) return;
|
|
1134
|
+
let a = i[0] ?? null, o = i[1] ?? null;
|
|
1135
|
+
a === this.#O.left && o === this.#O.right || (this.#ue = t, this.#O = {
|
|
1136
|
+
left: a,
|
|
1137
|
+
right: o
|
|
1138
|
+
}, this.#z.renderSpread(e, this.#O, { fill: this.#h }));
|
|
1223
1139
|
}
|
|
1224
1140
|
#ct() {
|
|
1225
1141
|
if (this.#se.size === 0) return;
|
|
@@ -1275,23 +1191,30 @@ var J = class {
|
|
|
1275
1191
|
mode: n
|
|
1276
1192
|
});
|
|
1277
1193
|
let r = this.#x ? C(globalThis.location?.hash ?? "") : null;
|
|
1278
|
-
this.#D =
|
|
1194
|
+
this.#D = q(r ?? t ?? 0, 0, e - 1), this.#E = this.#mt(this.#D);
|
|
1279
1195
|
}
|
|
1280
1196
|
};
|
|
1281
|
-
function
|
|
1197
|
+
function q(e, t, n) {
|
|
1282
1198
|
return e < t ? t : e > n ? n : e;
|
|
1283
1199
|
}
|
|
1284
|
-
function
|
|
1200
|
+
function J(e, t, n) {
|
|
1201
|
+
if (t <= n) {
|
|
1202
|
+
let r = (n - t) / 2 - e;
|
|
1203
|
+
return [r, r];
|
|
1204
|
+
}
|
|
1205
|
+
return [n - (e + t), -e];
|
|
1206
|
+
}
|
|
1207
|
+
function Y(e) {
|
|
1285
1208
|
return e < .5 ? 2 * e * e : 1 - (-2 * e + 2) ** 2 / 2;
|
|
1286
1209
|
}
|
|
1287
|
-
function
|
|
1288
|
-
return 1 - (1 -
|
|
1210
|
+
function X(e) {
|
|
1211
|
+
return 1 - (1 - Y(e)) ** 1.3;
|
|
1289
1212
|
}
|
|
1290
|
-
function
|
|
1213
|
+
function Z(e) {
|
|
1291
1214
|
return e === null ? "null" : Array.isArray(e) ? "array" : typeof e;
|
|
1292
1215
|
}
|
|
1293
|
-
function
|
|
1294
|
-
if (typeof n != "object" || !n || typeof n.appendChild != "function" || typeof n.addEventListener != "function") throw Error(`Zine: container must be a DOM element; received ${
|
|
1216
|
+
function Q(n, r) {
|
|
1217
|
+
if (typeof n != "object" || !n || typeof n.appendChild != "function" || typeof n.addEventListener != "function") throw Error(`Zine: container must be a DOM element; received ${Z(n)}.`);
|
|
1295
1218
|
if (typeof r != "object" || !r) throw Error("Zine: an options object with a `source` is required.");
|
|
1296
1219
|
let i = r, a = i.source;
|
|
1297
1220
|
if (typeof a != "object" || !a || typeof a.get != "function" || typeof a.pageCount != "number") throw Error("Zine: `source` is required and must be a Source, e.g. new ImageSource(urls).");
|
|
@@ -1316,9 +1239,9 @@ function te(n, r) {
|
|
|
1316
1239
|
"deepLink",
|
|
1317
1240
|
"disableContextMenu",
|
|
1318
1241
|
"responsiveSpread"
|
|
1319
|
-
]) if (i[e] !== void 0 && typeof i[e] != "boolean") throw Error(`Zine: ${e} must be a boolean; got ${
|
|
1242
|
+
]) if (i[e] !== void 0 && typeof i[e] != "boolean") throw Error(`Zine: ${e} must be a boolean; got ${Z(i[e])}.`);
|
|
1320
1243
|
let u = i.controls;
|
|
1321
|
-
if (u !== void 0 && typeof u != "boolean" && (typeof u != "object" || !u)) throw Error(`Zine: controls must be a boolean or an options object; got ${
|
|
1244
|
+
if (u !== void 0 && typeof u != "boolean" && (typeof u != "object" || !u)) throw Error(`Zine: controls must be a boolean or an options object; got ${Z(u)}.`);
|
|
1322
1245
|
let d = u?.position;
|
|
1323
1246
|
if (d !== void 0 && ![
|
|
1324
1247
|
"top",
|
|
@@ -1339,12 +1262,12 @@ function te(n, r) {
|
|
|
1339
1262
|
}
|
|
1340
1263
|
let p = i.pages;
|
|
1341
1264
|
if (p !== void 0 && (typeof p != "object" || !p || Array.isArray(p))) throw Error("Zine: pages must be an object mapping page indices to image URLs.");
|
|
1342
|
-
$(i.width, "width", 1), $(i.height, "height", 1), $(i.flipDuration, "flipDuration", 0), $(i.clickZoneSize, "clickZoneSize", 0), $(i.clickFlipDelay, "clickFlipDelay", 0), $(i.singlePageThreshold, "singlePageThreshold", 0),
|
|
1265
|
+
$(i.width, "width", 1), $(i.height, "height", 1), $(i.flipDuration, "flipDuration", 0), $(i.clickZoneSize, "clickZoneSize", 0), $(i.clickFlipDelay, "clickFlipDelay", 0), $(i.singlePageThreshold, "singlePageThreshold", 0), ee(i.zoom), te(i.renderer);
|
|
1343
1266
|
}
|
|
1344
1267
|
function $(e, t, n) {
|
|
1345
1268
|
if (e !== void 0 && (typeof e != "number" || !Number.isFinite(e) || e < n)) throw Error(`Zine: ${t} must be a number >= ${n}; got ${JSON.stringify(e)}.`);
|
|
1346
1269
|
}
|
|
1347
|
-
function
|
|
1270
|
+
function ee(e) {
|
|
1348
1271
|
if (e === void 0) return;
|
|
1349
1272
|
if (typeof e != "object" || !e || Array.isArray(e)) throw Error("Zine: zoom must be an object, e.g. { max: 4 }.");
|
|
1350
1273
|
let t = e;
|
|
@@ -1357,7 +1280,7 @@ function ne(e) {
|
|
|
1357
1280
|
}
|
|
1358
1281
|
$(t.max, "zoom.max", 1);
|
|
1359
1282
|
}
|
|
1360
|
-
function
|
|
1283
|
+
function te(e) {
|
|
1361
1284
|
if (e !== void 0) {
|
|
1362
1285
|
if (typeof e == "string") {
|
|
1363
1286
|
if (e !== "auto" && e !== "css" && e !== "webgl2") throw Error(`Zine: renderer '${e}' is not recognized; use 'auto', 'css', 'webgl2', an array of those, or a custom Renderer.`);
|
|
@@ -1372,7 +1295,7 @@ function re(e) {
|
|
|
1372
1295
|
}
|
|
1373
1296
|
//#endregion
|
|
1374
1297
|
//#region src/source/imageSource.ts
|
|
1375
|
-
var
|
|
1298
|
+
var ne = class {
|
|
1376
1299
|
pageCount;
|
|
1377
1300
|
fit;
|
|
1378
1301
|
#e;
|
|
@@ -1409,6 +1332,6 @@ var ie = class {
|
|
|
1409
1332
|
}
|
|
1410
1333
|
};
|
|
1411
1334
|
//#endregion
|
|
1412
|
-
export { t as CURL_TYPES, i as DEFAULT_ITEMS, e as IMPORTABLE_CURLS,
|
|
1335
|
+
export { t as CURL_TYPES, i as DEFAULT_ITEMS, e as IMPORTABLE_CURLS, ne as ImageSource, K as Zine, n as defineControl, r as getControl };
|
|
1413
1336
|
|
|
1414
1337
|
//# sourceMappingURL=index.js.map
|