@zinejs/core 0.2.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 +3 -1
- package/dist/geometry/curls/cone.d.ts +17 -0
- package/dist/geometry/curls/flick.d.ts +20 -0
- package/dist/geometry/curls/leaf.d.ts +19 -0
- package/dist/geometry/curls/simple.d.ts +0 -8
- package/dist/geometry/curls/types.d.ts +7 -4
- package/dist/index.js +172 -150
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +13 -7
- package/dist/index.umd.cjs.map +1 -1
- package/dist/{types-Bz64qLvE.js → types-D-rEO00p.js} +6 -5
- package/dist/types-D-rEO00p.js.map +1 -0
- package/dist/{webglRenderer-m-lr412M.js → webglRenderer-Bg6VF4CW.js} +158 -93
- package/dist/webglRenderer-Bg6VF4CW.js.map +1 -0
- package/dist/zine.d.ts +1 -1
- package/options.schema.json +4 -4
- package/package.json +1 -1
- package/dist/geometry/curls/fold.d.ts +0 -9
- package/dist/geometry/curls/peel.d.ts +0 -9
- package/dist/types-Bz64qLvE.js.map +0 -1
- package/dist/webglRenderer-m-lr412M.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as e } from "./types-
|
|
1
|
+
import { t as e } from "./types-D-rEO00p.js";
|
|
2
2
|
//#region src/engine/spread.ts
|
|
3
3
|
function t(e, t = {}) {
|
|
4
4
|
let { direction: n = "ltr", mode: r = "cover" } = t;
|
|
@@ -256,7 +256,7 @@ function m(e, t, n) {
|
|
|
256
256
|
//#region src/renderer/select.ts
|
|
257
257
|
var h = {
|
|
258
258
|
css: async () => new (await (import("./cssRenderer-OzRRoEa4.js"))).CssRenderer(),
|
|
259
|
-
webgl2: async () => new (await (import("./webglRenderer-
|
|
259
|
+
webgl2: async () => new (await (import("./webglRenderer-Bg6VF4CW.js"))).WebglRenderer()
|
|
260
260
|
}, g = !0;
|
|
261
261
|
function _(e) {
|
|
262
262
|
return typeof e == "object" && !!e && !Array.isArray(e) && typeof e.mount == "function";
|
|
@@ -351,7 +351,7 @@ var w = class {
|
|
|
351
351
|
throw this.#a.delete(e), t;
|
|
352
352
|
}), this.#a.set(e, t)), t;
|
|
353
353
|
}
|
|
354
|
-
}, T = .25, E = .0015, D = 6, O = 250, k = 1.
|
|
354
|
+
}, T = .25, E = .0015, D = 6, O = 250, k = 1.55, A = class {
|
|
355
355
|
#e;
|
|
356
356
|
#t;
|
|
357
357
|
#n = new a();
|
|
@@ -396,26 +396,28 @@ var w = class {
|
|
|
396
396
|
#R = null;
|
|
397
397
|
#z = null;
|
|
398
398
|
#B = null;
|
|
399
|
-
#V =
|
|
400
|
-
#H =
|
|
399
|
+
#V = null;
|
|
400
|
+
#H = null;
|
|
401
401
|
#U = !1;
|
|
402
|
-
#W =
|
|
403
|
-
#G =
|
|
402
|
+
#W = 1;
|
|
403
|
+
#G = !1;
|
|
404
404
|
#K = null;
|
|
405
405
|
#q = null;
|
|
406
406
|
#J = null;
|
|
407
|
-
#Y;
|
|
407
|
+
#Y = null;
|
|
408
|
+
#X = null;
|
|
409
|
+
#Z;
|
|
408
410
|
debug = { setFlipProgress: (e, t) => {
|
|
409
411
|
this.#M?.setFlipProgress(e, t);
|
|
410
412
|
} };
|
|
411
413
|
constructor(e, t) {
|
|
412
|
-
|
|
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, {
|
|
413
415
|
frontCover: t.frontCover,
|
|
414
416
|
backCover: t.backCover,
|
|
415
417
|
pages: t.pages
|
|
416
418
|
});
|
|
417
419
|
let n = t.direction ?? "ltr";
|
|
418
|
-
this.#a = n, this.#o = t.spreadMode ?? "cover", this.#s = t.curl ?? "
|
|
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;
|
|
419
421
|
let r = t.zoom?.doubleClick, i = r === !1 ? [] : [...r ?? [
|
|
420
422
|
1,
|
|
421
423
|
2,
|
|
@@ -423,10 +425,10 @@ var w = class {
|
|
|
423
425
|
]].sort((e, t) => e - t);
|
|
424
426
|
this.#T = i.length > 0 ? i : null, this.#E = t.zoom?.max ?? 4;
|
|
425
427
|
let a = this.#C && this.#T !== null, o = t.zoom?.doubleClickInFlipZone ?? this.#l === "half";
|
|
426
|
-
this.#d = this.#l !== "off" && a && o && t.clickFlipDelay !== 0, this.#f = this.#d ? t.clickFlipDelay ?? O : 0, this.#
|
|
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");
|
|
427
429
|
}
|
|
428
430
|
get ready() {
|
|
429
|
-
return this.#
|
|
431
|
+
return this.#Z;
|
|
430
432
|
}
|
|
431
433
|
getPageCount() {
|
|
432
434
|
return this.#t.pageCount;
|
|
@@ -435,14 +437,25 @@ var w = class {
|
|
|
435
437
|
return this.#b;
|
|
436
438
|
}
|
|
437
439
|
flipNext() {
|
|
438
|
-
this.#
|
|
440
|
+
this.#Q(() => this.#ne(this.#y + 1));
|
|
439
441
|
}
|
|
440
442
|
flipPrev() {
|
|
441
|
-
this.#
|
|
443
|
+
this.#Q(() => this.#ne(this.#y - 1));
|
|
442
444
|
}
|
|
443
445
|
flipTo(e) {
|
|
444
446
|
let t = j(e, 0, Math.max(0, this.#t.pageCount - 1));
|
|
445
|
-
this.#
|
|
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());
|
|
446
459
|
}
|
|
447
460
|
getZoom() {
|
|
448
461
|
return this.#k;
|
|
@@ -453,30 +466,30 @@ var w = class {
|
|
|
453
466
|
x: r.containerWidth / 2,
|
|
454
467
|
y: r.containerHeight / 2
|
|
455
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);
|
|
456
|
-
[o, s] = this.#
|
|
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 });
|
|
457
470
|
}
|
|
458
471
|
resetZoom() {
|
|
459
472
|
this.setZoom(1);
|
|
460
473
|
}
|
|
461
|
-
#
|
|
474
|
+
#te(e, t, n, r, i) {
|
|
462
475
|
return [j(e, r * (1 - n), 0), j(t, i * (1 - n), 0)];
|
|
463
476
|
}
|
|
464
477
|
on(e, t) {
|
|
465
478
|
return this.#n.on(e, t);
|
|
466
479
|
}
|
|
467
480
|
destroy() {
|
|
468
|
-
this.#P = !0, this.#F !== null && cancelAnimationFrame(this.#F), 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();
|
|
469
482
|
}
|
|
470
|
-
#
|
|
483
|
+
#ne(e) {
|
|
471
484
|
if (e < 0 || e >= this.#v.length || e === this.#y || this.#i.send("flip") === null) return;
|
|
472
|
-
let t = e > this.#y ? "forward" : "backward", n = this.#
|
|
485
|
+
let t = e > this.#y ? "forward" : "backward", n = this.#oe(e);
|
|
473
486
|
this.#n.emit("flipStart", {
|
|
474
487
|
from: this.#b,
|
|
475
488
|
to: n
|
|
476
|
-
}), this.#
|
|
489
|
+
}), this.#re(e, t, n);
|
|
477
490
|
}
|
|
478
|
-
async #
|
|
479
|
-
let r = this.#v[e], i = r ? await this.#
|
|
491
|
+
async #re(e, t, n) {
|
|
492
|
+
let r = this.#v[e], i = r ? await this.#Re(r) : {
|
|
480
493
|
left: null,
|
|
481
494
|
right: null
|
|
482
495
|
};
|
|
@@ -484,41 +497,48 @@ var w = class {
|
|
|
484
497
|
fill: this.#m,
|
|
485
498
|
curl: this.#s,
|
|
486
499
|
anchor: { y: this.#c }
|
|
487
|
-
}), this
|
|
500
|
+
}), this.#ie(0, 1, t, () => this.#ae(e, n, i));
|
|
488
501
|
}
|
|
489
|
-
|
|
490
|
-
let i = this.#
|
|
502
|
+
#ie(e, t, n, r) {
|
|
503
|
+
let i = this.#ke() * Math.abs(t - e);
|
|
491
504
|
if (i <= 0) {
|
|
492
505
|
this.#M?.setFlipProgress(t, n), r();
|
|
493
506
|
return;
|
|
494
507
|
}
|
|
495
|
-
let a =
|
|
496
|
-
|
|
497
|
-
|
|
508
|
+
let a = {
|
|
509
|
+
toT: t,
|
|
510
|
+
direction: n,
|
|
511
|
+
onDone: r
|
|
512
|
+
};
|
|
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());
|
|
498
518
|
};
|
|
499
|
-
this.#F = requestAnimationFrame(
|
|
519
|
+
this.#F = requestAnimationFrame(s);
|
|
500
520
|
}
|
|
501
|
-
#
|
|
521
|
+
#ae(e, t, n) {
|
|
502
522
|
let r = this.#v[e];
|
|
503
|
-
this.#y = e, this.#b = t, this.#x = n, r && this.#
|
|
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();
|
|
504
524
|
}
|
|
505
|
-
#
|
|
525
|
+
#oe(e) {
|
|
506
526
|
let t = this.#v[e];
|
|
507
527
|
if (!t) return this.#b;
|
|
508
528
|
let n = [t.left, t.right].filter((e) => e !== null);
|
|
509
529
|
return n.length > 0 ? Math.min(...n) : this.#b;
|
|
510
530
|
}
|
|
511
|
-
#
|
|
512
|
-
if (this.#
|
|
513
|
-
if (this.#
|
|
531
|
+
#se(e, t) {
|
|
532
|
+
if (this.#U || !this.#M || this.#i.state !== "idle") return;
|
|
533
|
+
if (this.#he(), this.#k > 1) {
|
|
514
534
|
if (this.#i.send("panStart") === null) return;
|
|
515
|
-
this.#
|
|
535
|
+
this.#H = {
|
|
516
536
|
baseTx: this.#A,
|
|
517
537
|
baseTy: this.#j
|
|
518
538
|
};
|
|
519
539
|
return;
|
|
520
540
|
}
|
|
521
|
-
let n = this.#e.getBoundingClientRect(), r = this.#
|
|
541
|
+
let n = this.#e.getBoundingClientRect(), r = this.#pe(), i = {
|
|
522
542
|
x: e - n.left - r.x,
|
|
523
543
|
y: t - n.top - r.y
|
|
524
544
|
};
|
|
@@ -533,11 +553,11 @@ var w = class {
|
|
|
533
553
|
c < 0 || c >= this.#v.length || (this.#L = {
|
|
534
554
|
direction: s ? "forward" : "backward",
|
|
535
555
|
targetIndex: c,
|
|
536
|
-
toPage: this.#
|
|
556
|
+
toPage: this.#oe(c),
|
|
537
557
|
width: r.width
|
|
538
558
|
});
|
|
539
559
|
}
|
|
540
|
-
#
|
|
560
|
+
#ce() {
|
|
541
561
|
let e = this.#L;
|
|
542
562
|
e && (this.#L = null, this.#i.send("grab") !== null && (this.#I = {
|
|
543
563
|
direction: e.direction,
|
|
@@ -552,10 +572,10 @@ var w = class {
|
|
|
552
572
|
}, this.#n.emit("flipStart", {
|
|
553
573
|
from: this.#b,
|
|
554
574
|
to: e.toPage
|
|
555
|
-
}), this.#
|
|
575
|
+
}), this.#le(e.targetIndex, e.direction)));
|
|
556
576
|
}
|
|
557
|
-
async #
|
|
558
|
-
let n = this.#v[e], r = n ? await this.#
|
|
577
|
+
async #le(e, t) {
|
|
578
|
+
let n = this.#v[e], r = n ? await this.#Re(n) : {
|
|
559
579
|
left: null,
|
|
560
580
|
right: null
|
|
561
581
|
};
|
|
@@ -565,49 +585,50 @@ var w = class {
|
|
|
565
585
|
anchor: { y: this.#c }
|
|
566
586
|
}), this.#M?.setFlipProgress(this.#I.t, t));
|
|
567
587
|
}
|
|
568
|
-
#
|
|
569
|
-
if (this.#
|
|
570
|
-
if (this.#
|
|
588
|
+
#ue(e, t) {
|
|
589
|
+
if (this.#U) return;
|
|
590
|
+
if (this.#H) {
|
|
571
591
|
if (!this.#M) return;
|
|
572
|
-
let n = this.#M.measure(), [r, i] = this.#
|
|
592
|
+
let n = this.#M.measure(), [r, i] = this.#te(this.#H.baseTx + e, this.#H.baseTy + t, this.#k, n.containerWidth, n.containerHeight);
|
|
573
593
|
this.#A = r, this.#j = i, this.#M.setViewTransform(this.#k, r, i);
|
|
574
594
|
return;
|
|
575
595
|
}
|
|
576
|
-
this.#L && Math.hypot(e, t) > D && this.#
|
|
596
|
+
this.#L && Math.hypot(e, t) > D && this.#ce();
|
|
577
597
|
let n = this.#I;
|
|
578
598
|
n && (n.t = j((n.direction === "forward" ? -e : e) / n.width, 0, 1), this.#M?.setFlipProgress(n.t, n.direction));
|
|
579
599
|
}
|
|
580
|
-
#
|
|
581
|
-
if (this.#
|
|
582
|
-
if (this.#
|
|
583
|
-
this.#
|
|
600
|
+
#de(e) {
|
|
601
|
+
if (this.#U) return;
|
|
602
|
+
if (this.#H) {
|
|
603
|
+
this.#H = null, this.#i.send("panEnd");
|
|
584
604
|
return;
|
|
585
605
|
}
|
|
586
606
|
let t = this.#I;
|
|
587
607
|
if (!t) {
|
|
588
|
-
this.#L = null, this.#
|
|
608
|
+
this.#L = null, this.#fe(e);
|
|
589
609
|
return;
|
|
590
610
|
}
|
|
591
611
|
this.#I = null, this.#i.send("release");
|
|
592
612
|
let n = e.swipe && (t.direction === "forward" ? e.dx < 0 : e.dx > 0);
|
|
593
|
-
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());
|
|
594
614
|
}
|
|
595
|
-
#
|
|
615
|
+
#fe(e) {
|
|
596
616
|
if (this.#l === "off" || this.#k > 1 || !this.#R || Math.abs(e.dx) > D || Math.abs(e.dy) > D) return;
|
|
597
|
-
let t = this.#
|
|
617
|
+
let t = this.#me(this.#R);
|
|
598
618
|
if (!t) return;
|
|
599
|
-
let n =
|
|
600
|
-
if (
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
this.#z = null, this.#Z(n);
|
|
607
|
-
}, this.#f);
|
|
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;
|
|
608
626
|
}
|
|
627
|
+
this.#z = setTimeout(() => {
|
|
628
|
+
this.#z = null, this.#Q(r);
|
|
629
|
+
}, this.#f);
|
|
609
630
|
}
|
|
610
|
-
#
|
|
631
|
+
#pe() {
|
|
611
632
|
let e = this.#M.measure();
|
|
612
633
|
return e.content ?? e.book ?? {
|
|
613
634
|
x: 0,
|
|
@@ -616,40 +637,40 @@ var w = class {
|
|
|
616
637
|
height: e.containerHeight
|
|
617
638
|
};
|
|
618
639
|
}
|
|
619
|
-
#
|
|
640
|
+
#me(e) {
|
|
620
641
|
if (!this.#M) return null;
|
|
621
|
-
let t = this.#
|
|
642
|
+
let t = this.#pe().width, n;
|
|
622
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;
|
|
623
644
|
let r = this.#a === "rtl" ? "left" : "right";
|
|
624
645
|
return n === r ? "forward" : "backward";
|
|
625
646
|
}
|
|
626
|
-
#
|
|
647
|
+
#he() {
|
|
627
648
|
this.#z !== null && (clearTimeout(this.#z), this.#z = null);
|
|
628
649
|
}
|
|
629
|
-
#
|
|
650
|
+
#ge() {
|
|
630
651
|
let e = this.#v[this.#y];
|
|
631
|
-
e && this.#
|
|
652
|
+
e && this.#Ne(e, this.#x), this.#i.send("settle"), this.#n.emit("flipEnd", { page: this.#b }), this.#ee();
|
|
632
653
|
}
|
|
633
|
-
#
|
|
634
|
-
if (this.#L = null, this.#
|
|
654
|
+
#_e() {
|
|
655
|
+
if (this.#L = null, this.#he(), this.#I) {
|
|
635
656
|
this.#I = null, this.#i.send("release"), this.#i.send("settle");
|
|
636
657
|
let e = this.#v[this.#y];
|
|
637
|
-
e && this.#
|
|
638
|
-
} else this.#
|
|
639
|
-
this.#
|
|
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;
|
|
640
661
|
}
|
|
641
|
-
#
|
|
642
|
-
if (!this.#
|
|
662
|
+
#ve(e, t, n) {
|
|
663
|
+
if (!this.#U) return;
|
|
643
664
|
let r = this.#e.getBoundingClientRect();
|
|
644
|
-
this.setZoom(this.#
|
|
665
|
+
this.setZoom(this.#W * n, {
|
|
645
666
|
x: e - r.left,
|
|
646
667
|
y: t - r.top
|
|
647
668
|
});
|
|
648
669
|
}
|
|
649
|
-
#
|
|
650
|
-
this.#
|
|
670
|
+
#ye() {
|
|
671
|
+
this.#U = !1;
|
|
651
672
|
}
|
|
652
|
-
#
|
|
673
|
+
#be() {
|
|
653
674
|
let e = (e) => {
|
|
654
675
|
if (!this.#w || !this.#C || !(e.ctrlKey || e.metaKey)) return;
|
|
655
676
|
e.preventDefault();
|
|
@@ -659,9 +680,9 @@ var w = class {
|
|
|
659
680
|
y: e.clientY - t.top
|
|
660
681
|
});
|
|
661
682
|
};
|
|
662
|
-
this.#e.addEventListener("wheel", e, { passive: !1 }), this.#
|
|
683
|
+
this.#e.addEventListener("wheel", e, { passive: !1 }), this.#J = () => this.#e.removeEventListener("wheel", e);
|
|
663
684
|
}
|
|
664
|
-
#
|
|
685
|
+
#xe() {
|
|
665
686
|
let e = (e) => {
|
|
666
687
|
let t = this.#T;
|
|
667
688
|
if (!this.#C || t === null) return;
|
|
@@ -670,40 +691,40 @@ var w = class {
|
|
|
670
691
|
x: e.clientX - t.left,
|
|
671
692
|
y: e.clientY - t.top
|
|
672
693
|
};
|
|
673
|
-
if (this.#
|
|
694
|
+
if (this.#me(n) !== null) return;
|
|
674
695
|
}
|
|
675
|
-
this.#
|
|
696
|
+
this.#he(), e.preventDefault();
|
|
676
697
|
let n = t.find((e) => e > this.#k + 1e-6) ?? t[0] ?? this.#k, r = this.#e.getBoundingClientRect();
|
|
677
698
|
this.setZoom(n, {
|
|
678
699
|
x: e.clientX - r.left,
|
|
679
700
|
y: e.clientY - r.top
|
|
680
701
|
});
|
|
681
702
|
};
|
|
682
|
-
this.#e.addEventListener("dblclick", e), this.#
|
|
703
|
+
this.#e.addEventListener("dblclick", e), this.#Y = () => this.#e.removeEventListener("dblclick", e);
|
|
683
704
|
}
|
|
684
|
-
async #
|
|
705
|
+
async #Se(e) {
|
|
685
706
|
let t = x(e);
|
|
686
|
-
typeof this.#t.open == "function" && (await this.#t.open(), this.#
|
|
687
|
-
let n = await t, r = await this.#
|
|
688
|
-
this.#M = r, this.#t.onPageUpdate?.((e) => this.#
|
|
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);
|
|
689
710
|
let i = new u({
|
|
690
|
-
onStart: (e) => this.#
|
|
691
|
-
onMove: (e) => this.#
|
|
692
|
-
onEnd: (e) => this.#
|
|
711
|
+
onStart: (e) => this.#se(e.x, e.y),
|
|
712
|
+
onMove: (e) => this.#ue(e.dx, e.dy),
|
|
713
|
+
onEnd: (e) => this.#de(e)
|
|
693
714
|
}), a = new p({
|
|
694
|
-
onPinchStart: () => this.#
|
|
695
|
-
onPinchMove: (e) => this.#
|
|
696
|
-
onPinchEnd: () => this.#
|
|
715
|
+
onPinchStart: () => this.#_e(),
|
|
716
|
+
onPinchMove: (e) => this.#ve(e.centerX, e.centerY, e.scale),
|
|
717
|
+
onPinchEnd: () => this.#ye()
|
|
697
718
|
});
|
|
698
|
-
this.#
|
|
719
|
+
this.#q = d(this.#e, {
|
|
699
720
|
pointer: i,
|
|
700
721
|
pinch: a
|
|
701
|
-
}), 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");
|
|
702
723
|
}
|
|
703
|
-
async #
|
|
724
|
+
async #Ce(e) {
|
|
704
725
|
try {
|
|
705
726
|
return await e.mount(this.#e), e.onFatal?.(() => {
|
|
706
|
-
this.#
|
|
727
|
+
this.#we();
|
|
707
728
|
}), e;
|
|
708
729
|
} catch {
|
|
709
730
|
e.destroy();
|
|
@@ -714,7 +735,7 @@ var w = class {
|
|
|
714
735
|
}), t;
|
|
715
736
|
}
|
|
716
737
|
}
|
|
717
|
-
async #
|
|
738
|
+
async #we() {
|
|
718
739
|
if (this.#N || this.#P) return;
|
|
719
740
|
this.#N = !0, this.#M?.destroy(), this.#M = null;
|
|
720
741
|
let e = await x("css");
|
|
@@ -722,30 +743,30 @@ var w = class {
|
|
|
722
743
|
e.destroy();
|
|
723
744
|
return;
|
|
724
745
|
}
|
|
725
|
-
await e.mount(this.#e), this.#M = e, this.#
|
|
746
|
+
await e.mount(this.#e), this.#M = e, this.#je(e.measure().containerWidth), await this.#Me(), this.#n.emit("rendererFallback", {
|
|
726
747
|
from: "webgl2",
|
|
727
748
|
to: "css"
|
|
728
749
|
});
|
|
729
750
|
}
|
|
730
|
-
#
|
|
751
|
+
#Te() {
|
|
731
752
|
if (typeof matchMedia != "function") return;
|
|
732
753
|
let e = matchMedia("(prefers-reduced-motion: reduce)");
|
|
733
|
-
this.#
|
|
734
|
-
this.#
|
|
754
|
+
this.#G = e.matches, e.addEventListener?.("change", (e) => {
|
|
755
|
+
this.#G = e.matches;
|
|
735
756
|
});
|
|
736
757
|
}
|
|
737
|
-
#
|
|
758
|
+
#Ee() {
|
|
738
759
|
let e = this.#e, t = e.ownerDocument;
|
|
739
760
|
if (!t || typeof e.setAttribute != "function") return null;
|
|
740
761
|
e.hasAttribute("tabindex") || (e.tabIndex = 0), e.setAttribute("aria-roledescription", "flipbook");
|
|
741
|
-
let n = (e) => this.#
|
|
762
|
+
let n = (e) => this.#De(e);
|
|
742
763
|
e.addEventListener("keydown", n);
|
|
743
764
|
let r = t.createElement("div");
|
|
744
|
-
return r.setAttribute("aria-live", "polite"), r.setAttribute("aria-atomic", "true"), r.style.cssText = "position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0;", e.appendChild(r), this.#
|
|
745
|
-
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;
|
|
746
767
|
};
|
|
747
768
|
}
|
|
748
|
-
#
|
|
769
|
+
#De(e) {
|
|
749
770
|
let t = this.#a === "rtl" ? "ArrowLeft" : "ArrowRight";
|
|
750
771
|
switch (e.key) {
|
|
751
772
|
case "ArrowRight":
|
|
@@ -761,64 +782,62 @@ var w = class {
|
|
|
761
782
|
default: break;
|
|
762
783
|
}
|
|
763
784
|
}
|
|
764
|
-
#
|
|
765
|
-
this.#
|
|
785
|
+
#Oe() {
|
|
786
|
+
this.#K && (this.#K.textContent = `Page ${this.#b + 1} of ${this.#t.pageCount}`);
|
|
766
787
|
}
|
|
767
|
-
#
|
|
768
|
-
|
|
769
|
-
let e = this.#m && this.#s === "roll";
|
|
770
|
-
return this.#S * (e ? k : 1);
|
|
788
|
+
#ke() {
|
|
789
|
+
return this.#G ? 0 : this.#S * (this.#m ? k : 1);
|
|
771
790
|
}
|
|
772
791
|
update() {
|
|
773
|
-
!this.#M || this.#i.state !== "idle" || (this.#
|
|
792
|
+
!this.#M || this.#i.state !== "idle" || (this.#je(this.#M.measure().containerWidth), this.#Me());
|
|
774
793
|
}
|
|
775
|
-
#
|
|
794
|
+
#Ae() {
|
|
776
795
|
return this.#h || this.#o === "single" ? "single" : this.#o;
|
|
777
796
|
}
|
|
778
|
-
#
|
|
797
|
+
#je(e) {
|
|
779
798
|
let r = n(e, this.#p);
|
|
780
799
|
if (r === this.#h) return;
|
|
781
800
|
this.#h = r;
|
|
782
|
-
let i = this.#
|
|
801
|
+
let i = this.#Ae();
|
|
783
802
|
this.#m = i === "single", this.#v = t(this.#t.pageCount, {
|
|
784
803
|
direction: this.#a,
|
|
785
804
|
mode: i
|
|
786
|
-
}), this.#y = this.#
|
|
805
|
+
}), this.#y = this.#Ve(this.#b);
|
|
787
806
|
}
|
|
788
|
-
async #
|
|
807
|
+
async #Me() {
|
|
789
808
|
let e = this.#v[this.#y];
|
|
790
|
-
!e || !this.#M || (this.#x = await this.#
|
|
809
|
+
!e || !this.#M || (this.#x = await this.#Re(e), this.#Ne(e, this.#x));
|
|
791
810
|
}
|
|
792
|
-
#
|
|
793
|
-
this.#M?.renderSpread(e, t, { fill: this.#m }), this.#
|
|
811
|
+
#Ne(e, t) {
|
|
812
|
+
this.#M?.renderSpread(e, t, { fill: this.#m }), this.#Pe();
|
|
794
813
|
}
|
|
795
|
-
#
|
|
814
|
+
#Pe() {
|
|
796
815
|
let e = this.#M?.measure().book;
|
|
797
816
|
if (!e || e.width <= 0 || e.height <= 0) return;
|
|
798
817
|
let t = (e.width / e.height).toFixed(4);
|
|
799
818
|
t !== this.#g && (this.#g = t, this.#e.style.aspectRatio = t);
|
|
800
819
|
}
|
|
801
|
-
#
|
|
820
|
+
#Fe(e) {
|
|
802
821
|
if (this.#i.state !== "idle") return;
|
|
803
822
|
let t = this.#v[this.#y];
|
|
804
|
-
t && (t.left === e || t.right === e) && this.#
|
|
823
|
+
t && (t.left === e || t.right === e) && this.#Me();
|
|
805
824
|
}
|
|
806
|
-
#
|
|
807
|
-
typeof ResizeObserver > "u" || (this.#D = new ResizeObserver(() => this.#
|
|
825
|
+
#Ie() {
|
|
826
|
+
typeof ResizeObserver > "u" || (this.#D = new ResizeObserver(() => this.#Le()), this.#D.observe(this.#e));
|
|
808
827
|
}
|
|
809
|
-
#
|
|
828
|
+
#Le() {
|
|
810
829
|
this.#O || (this.#O = !0, requestAnimationFrame(() => {
|
|
811
830
|
this.#O = !1, this.update();
|
|
812
831
|
}));
|
|
813
832
|
}
|
|
814
|
-
async #
|
|
815
|
-
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)]);
|
|
816
835
|
return {
|
|
817
836
|
left: t,
|
|
818
837
|
right: n
|
|
819
838
|
};
|
|
820
839
|
}
|
|
821
|
-
async #
|
|
840
|
+
async #ze(e) {
|
|
822
841
|
if (e === null) return null;
|
|
823
842
|
try {
|
|
824
843
|
return await this.#t.get(e);
|
|
@@ -829,7 +848,7 @@ var w = class {
|
|
|
829
848
|
}), null;
|
|
830
849
|
}
|
|
831
850
|
}
|
|
832
|
-
#
|
|
851
|
+
#Be() {
|
|
833
852
|
let { toMount: e } = this.#r.update(this.#y, this.#v.length), t = [];
|
|
834
853
|
for (let n of e) {
|
|
835
854
|
let e = this.#v[n];
|
|
@@ -837,33 +856,36 @@ var w = class {
|
|
|
837
856
|
}
|
|
838
857
|
this.#t.prefetch(t);
|
|
839
858
|
}
|
|
840
|
-
#
|
|
859
|
+
#Ve(e) {
|
|
841
860
|
let t = this.#v.findIndex((t) => t.left === e || t.right === e);
|
|
842
861
|
return t === -1 ? 0 : t;
|
|
843
862
|
}
|
|
844
|
-
#
|
|
863
|
+
#He() {
|
|
845
864
|
let e = this.#t.pageCount;
|
|
846
865
|
if (!Number.isInteger(e) || e < 1) throw Error(`Zine: source has ${e} pages; a Source must have at least 1 page.`);
|
|
847
866
|
let n = this.#_;
|
|
848
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}).`);
|
|
849
|
-
let r = this.#
|
|
868
|
+
let r = this.#Ae();
|
|
850
869
|
this.#m = r === "single", this.#v = t(e, {
|
|
851
870
|
direction: this.#a,
|
|
852
871
|
mode: r
|
|
853
|
-
}), this.#b = j(n ?? 0, 0, e - 1), this.#y = this.#
|
|
872
|
+
}), this.#b = j(n ?? 0, 0, e - 1), this.#y = this.#Ve(this.#b);
|
|
854
873
|
}
|
|
855
874
|
};
|
|
856
875
|
function j(e, t, n) {
|
|
857
876
|
return e < t ? t : e > n ? n : e;
|
|
858
877
|
}
|
|
859
878
|
function M(e) {
|
|
860
|
-
return e < .5 ?
|
|
879
|
+
return e < .5 ? 2 * e * e : 1 - (-2 * e + 2) ** 2 / 2;
|
|
861
880
|
}
|
|
862
881
|
function N(e) {
|
|
882
|
+
return 1 - (1 - M(e)) ** 1.3;
|
|
883
|
+
}
|
|
884
|
+
function P(e) {
|
|
863
885
|
return e === null ? "null" : Array.isArray(e) ? "array" : typeof e;
|
|
864
886
|
}
|
|
865
|
-
function
|
|
866
|
-
if (typeof t != "object" || !t || typeof t.appendChild != "function" || typeof t.addEventListener != "function") throw Error(`Zine: container must be a DOM element; received ${
|
|
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)}.`);
|
|
867
889
|
if (typeof n != "object" || !n) throw Error("Zine: an options object with a `source` is required.");
|
|
868
890
|
let r = n, i = r.source;
|
|
869
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,12 +914,12 @@ function P(t, n) {
|
|
|
892
914
|
}
|
|
893
915
|
let u = r.pages;
|
|
894
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.");
|
|
895
|
-
|
|
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);
|
|
896
918
|
}
|
|
897
|
-
function
|
|
919
|
+
function I(e, t, n) {
|
|
898
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)}.`);
|
|
899
921
|
}
|
|
900
|
-
function
|
|
922
|
+
function L(e) {
|
|
901
923
|
if (e === void 0) return;
|
|
902
924
|
if (typeof e != "object" || !e || Array.isArray(e)) throw Error("Zine: zoom must be an object, e.g. { max: 4 }.");
|
|
903
925
|
let t = e;
|
|
@@ -908,9 +930,9 @@ function I(e) {
|
|
|
908
930
|
let e = t.doubleClick;
|
|
909
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].");
|
|
910
932
|
}
|
|
911
|
-
|
|
933
|
+
I(t.max, "zoom.max", 1);
|
|
912
934
|
}
|
|
913
|
-
function
|
|
935
|
+
function R(e) {
|
|
914
936
|
if (e !== void 0) {
|
|
915
937
|
if (typeof e == "string") {
|
|
916
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.`);
|
|
@@ -925,7 +947,7 @@ function L(e) {
|
|
|
925
947
|
}
|
|
926
948
|
//#endregion
|
|
927
949
|
//#region src/source/imageSource.ts
|
|
928
|
-
var
|
|
950
|
+
var z = class {
|
|
929
951
|
pageCount;
|
|
930
952
|
fit;
|
|
931
953
|
#e;
|
|
@@ -962,6 +984,6 @@ var R = class {
|
|
|
962
984
|
}
|
|
963
985
|
};
|
|
964
986
|
//#endregion
|
|
965
|
-
export { e as CURL_TYPES,
|
|
987
|
+
export { e as CURL_TYPES, z as ImageSource, A as Zine };
|
|
966
988
|
|
|
967
989
|
//# sourceMappingURL=index.js.map
|