@readium/navigator 1.3.3 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -557,11 +557,11 @@ function Jt(i) {
|
|
|
557
557
|
function st(i) {
|
|
558
558
|
return typeof i == "string" ? new Date(i) : void 0;
|
|
559
559
|
}
|
|
560
|
-
function
|
|
560
|
+
function fA(i) {
|
|
561
561
|
return isNaN(i) ? void 0 : i;
|
|
562
562
|
}
|
|
563
563
|
function T(i) {
|
|
564
|
-
return
|
|
564
|
+
return fA(i) !== void 0 && Math.sign(i) >= 0 ? i : void 0;
|
|
565
565
|
}
|
|
566
566
|
function Ne(i) {
|
|
567
567
|
const A = new Array();
|
|
@@ -580,7 +580,7 @@ class z {
|
|
|
580
580
|
static deserialize(A) {
|
|
581
581
|
if (!A)
|
|
582
582
|
return;
|
|
583
|
-
const t =
|
|
583
|
+
const t = fA(A.progression), e = fA(A.totalProgression), n = fA(A.position), r = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Set([
|
|
584
584
|
"fragment",
|
|
585
585
|
"fragments",
|
|
586
586
|
"progression",
|
|
@@ -1945,11 +1945,11 @@ function qt(i) {
|
|
|
1945
1945
|
function lt(i) {
|
|
1946
1946
|
return typeof i == "string" ? new Date(i) : void 0;
|
|
1947
1947
|
}
|
|
1948
|
-
function
|
|
1948
|
+
function IA(i) {
|
|
1949
1949
|
return isNaN(i) ? void 0 : i;
|
|
1950
1950
|
}
|
|
1951
1951
|
function x(i) {
|
|
1952
|
-
return
|
|
1952
|
+
return IA(i) !== void 0 && Math.sign(i) >= 0 ? i : void 0;
|
|
1953
1953
|
}
|
|
1954
1954
|
function ti(i) {
|
|
1955
1955
|
const A = new Array();
|
|
@@ -1968,7 +1968,7 @@ class Q {
|
|
|
1968
1968
|
static deserialize(A) {
|
|
1969
1969
|
if (!A)
|
|
1970
1970
|
return;
|
|
1971
|
-
const t =
|
|
1971
|
+
const t = IA(A.progression), e = IA(A.totalProgression), n = IA(A.position), r = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Set([
|
|
1972
1972
|
"fragment",
|
|
1973
1973
|
"fragments",
|
|
1974
1974
|
"progression",
|
|
@@ -2558,9 +2558,9 @@ function _t(i, A, t) {
|
|
|
2558
2558
|
a.set(u, m), u < h.length && (h[u] = m);
|
|
2559
2559
|
for (let B = 0; B <= r; B += 1) {
|
|
2560
2560
|
m[B] = 0;
|
|
2561
|
-
for (let
|
|
2562
|
-
const E = B * n +
|
|
2563
|
-
E >= A.length || A.charCodeAt(E) === u && (m[B] |= 1 <<
|
|
2561
|
+
for (let f = 0; f < n; f += 1) {
|
|
2562
|
+
const E = B * n + f;
|
|
2563
|
+
E >= A.length || A.charCodeAt(E) === u && (m[B] |= 1 << f);
|
|
2564
2564
|
}
|
|
2565
2565
|
}
|
|
2566
2566
|
}
|
|
@@ -2576,17 +2576,17 @@ function _t(i, A, t) {
|
|
|
2576
2576
|
let m;
|
|
2577
2577
|
u < h.length ? m = h[u] : (m = a.get(u), typeof m > "u" && (m = o));
|
|
2578
2578
|
let B = 0;
|
|
2579
|
-
for (let
|
|
2580
|
-
B = dt(s, m,
|
|
2579
|
+
for (let f = 0; f <= c; f += 1)
|
|
2580
|
+
B = dt(s, m, f, B), l[f] += B;
|
|
2581
2581
|
if (l[c] - B <= t && c < r && (m[c + 1] & 1 || B < 0)) {
|
|
2582
2582
|
c += 1, s.P[c] = -1, s.M[c] = 0;
|
|
2583
|
-
let
|
|
2583
|
+
let f;
|
|
2584
2584
|
if (c === r) {
|
|
2585
2585
|
const E = A.length % n;
|
|
2586
|
-
|
|
2586
|
+
f = E === 0 ? n : E;
|
|
2587
2587
|
} else
|
|
2588
|
-
|
|
2589
|
-
l[c] = l[c - 1] +
|
|
2588
|
+
f = n;
|
|
2589
|
+
l[c] = l[c - 1] + f - B + dt(s, m, c, B);
|
|
2590
2590
|
} else
|
|
2591
2591
|
for (; c > 0 && l[c] >= t + n; )
|
|
2592
2592
|
c -= 1;
|
|
@@ -3231,7 +3231,7 @@ var $ = function(i) {
|
|
|
3231
3231
|
}
|
|
3232
3232
|
var n = i, r = n.offsetWidth, s = n.offsetHeight;
|
|
3233
3233
|
return !(r || s || i.getClientRects().length);
|
|
3234
|
-
},
|
|
3234
|
+
}, ft = function(i) {
|
|
3235
3235
|
var A;
|
|
3236
3236
|
if (i instanceof Element)
|
|
3237
3237
|
return !0;
|
|
@@ -3252,7 +3252,7 @@ var $ = function(i) {
|
|
|
3252
3252
|
return !0;
|
|
3253
3253
|
}
|
|
3254
3254
|
return !1;
|
|
3255
|
-
}, lA = typeof window < "u" ? window : {}, mA = /* @__PURE__ */ new WeakMap(),
|
|
3255
|
+
}, lA = typeof window < "u" ? window : {}, mA = /* @__PURE__ */ new WeakMap(), It = /auto|scroll/, Bi = /^tb|vertical/, Ei = /msie|trident/i.test(lA.navigator && lA.navigator.userAgent), H = function(i) {
|
|
3256
3256
|
return parseFloat(i || "0");
|
|
3257
3257
|
}, rA = function(i, A, t) {
|
|
3258
3258
|
return i === void 0 && (i = 0), A === void 0 && (A = 0), t === void 0 && (t = !1), new ui((t ? A : i) || 0, (t ? i : A) || 0);
|
|
@@ -3266,7 +3266,7 @@ var $ = function(i) {
|
|
|
3266
3266
|
return mA.get(i);
|
|
3267
3267
|
if (se(i))
|
|
3268
3268
|
return mA.set(i, pt), pt;
|
|
3269
|
-
var t = getComputedStyle(i), e = nt(i) && i.ownerSVGElement && i.getBBox(), n = !Ei && t.boxSizing === "border-box", r = Bi.test(t.writingMode || ""), s = !e &&
|
|
3269
|
+
var t = getComputedStyle(i), e = nt(i) && i.ownerSVGElement && i.getBBox(), n = !Ei && t.boxSizing === "border-box", r = Bi.test(t.writingMode || ""), s = !e && It.test(t.overflowY || ""), o = !e && It.test(t.overflowX || ""), a = e ? 0 : H(t.paddingTop), h = e ? 0 : H(t.paddingRight), c = e ? 0 : H(t.paddingBottom), l = e ? 0 : H(t.paddingLeft), g = e ? 0 : H(t.borderTopWidth), u = e ? 0 : H(t.borderRightWidth), m = e ? 0 : H(t.borderBottomWidth), B = e ? 0 : H(t.borderLeftWidth), f = l + h, E = a + c, p = B + u, I = g + m, w = o ? i.offsetHeight - I - i.clientHeight : 0, R = s ? i.offsetWidth - p - i.clientWidth : 0, AA = n ? f + p : 0, O = n ? E + I : 0, X = e ? e.width : H(t.width) - AA - R, Z = e ? e.height : H(t.height) - O - w, dA = X + f + R + p, MA = Z + E + w + I, tA = $({
|
|
3270
3270
|
devicePixelContentBoxSize: rA(Math.round(X * devicePixelRatio), Math.round(Z * devicePixelRatio), r),
|
|
3271
3271
|
borderBoxSize: rA(dA, MA, r),
|
|
3272
3272
|
contentBoxSize: rA(X, Z, r),
|
|
@@ -3283,7 +3283,7 @@ var $ = function(i) {
|
|
|
3283
3283
|
default:
|
|
3284
3284
|
return r;
|
|
3285
3285
|
}
|
|
3286
|
-
},
|
|
3286
|
+
}, fi = function() {
|
|
3287
3287
|
function i(A) {
|
|
3288
3288
|
var t = oe(A);
|
|
3289
3289
|
this.target = A, this.contentRect = t.contentRect, this.borderBoxSize = $([t.borderBoxSize]), this.contentBoxSize = $([t.contentBoxSize]), this.devicePixelContentBoxSize = $([t.devicePixelContentBoxSize]);
|
|
@@ -3295,13 +3295,13 @@ var $ = function(i) {
|
|
|
3295
3295
|
for (var A = 0, t = i.parentNode; t; )
|
|
3296
3296
|
A += 1, t = t.parentNode;
|
|
3297
3297
|
return A;
|
|
3298
|
-
},
|
|
3298
|
+
}, Ii = function() {
|
|
3299
3299
|
var i = 1 / 0, A = [];
|
|
3300
3300
|
_.forEach(function(r) {
|
|
3301
3301
|
if (r.activeTargets.length !== 0) {
|
|
3302
3302
|
var s = [];
|
|
3303
3303
|
r.activeTargets.forEach(function(o) {
|
|
3304
|
-
var a = new
|
|
3304
|
+
var a = new fi(o.target), h = he(o.target);
|
|
3305
3305
|
s.push(a), o.lastReportedSize = ae(o.target, o.observedBox), h < i && (i = h);
|
|
3306
3306
|
}), A.push(function() {
|
|
3307
3307
|
r.callback.call(r.observer, s, r.observer);
|
|
@@ -3322,7 +3322,7 @@ var $ = function(i) {
|
|
|
3322
3322
|
}, pi = function() {
|
|
3323
3323
|
var i = 0;
|
|
3324
3324
|
for (wt(i); gi(); )
|
|
3325
|
-
i =
|
|
3325
|
+
i = Ii(), wt(i);
|
|
3326
3326
|
return di() && Mi(), i > 0;
|
|
3327
3327
|
}, SA, ce = [], wi = function() {
|
|
3328
3328
|
return ce.splice(0).forEach(function(i) {
|
|
@@ -3456,13 +3456,13 @@ var $ = function(i) {
|
|
|
3456
3456
|
return i.prototype.observe = function(A, t) {
|
|
3457
3457
|
if (arguments.length === 0)
|
|
3458
3458
|
throw new TypeError("Failed to execute 'observe' on 'ResizeObserver': 1 argument required, but only 0 present.");
|
|
3459
|
-
if (!
|
|
3459
|
+
if (!ft(A))
|
|
3460
3460
|
throw new TypeError("Failed to execute 'observe' on 'ResizeObserver': parameter 1 is not of type 'Element");
|
|
3461
3461
|
EA.observe(this, A, t);
|
|
3462
3462
|
}, i.prototype.unobserve = function(A) {
|
|
3463
3463
|
if (arguments.length === 0)
|
|
3464
3464
|
throw new TypeError("Failed to execute 'unobserve' on 'ResizeObserver': 1 argument required, but only 0 present.");
|
|
3465
|
-
if (!
|
|
3465
|
+
if (!ft(A))
|
|
3466
3466
|
throw new TypeError("Failed to execute 'unobserve' on 'ResizeObserver': parameter 1 is not of type 'Element");
|
|
3467
3467
|
EA.unobserve(this, A);
|
|
3468
3468
|
}, i.prototype.disconnect = function() {
|
|
@@ -3576,24 +3576,24 @@ class Si {
|
|
|
3576
3576
|
getComputedStyle(this.wnd.document.documentElement).getPropertyValue(
|
|
3577
3577
|
"column-count"
|
|
3578
3578
|
)
|
|
3579
|
-
), c = a / (h || 1), l = this.wnd.document.scrollingElement, g = l.scrollLeft, u = l.scrollTop, m = (
|
|
3579
|
+
), c = a / (h || 1), l = this.wnd.document.scrollingElement, g = l.scrollLeft, u = l.scrollTop, m = (I, w, R) => {
|
|
3580
3580
|
var AA, O, X, Z, dA, MA;
|
|
3581
|
-
if (
|
|
3582
|
-
|
|
3581
|
+
if (I.style.position = "absolute", ((O = (AA = A.decoration) == null ? void 0 : AA.style) == null ? void 0 : O.width) === "viewport") {
|
|
3582
|
+
I.style.width = `${a}px`, I.style.height = `${w.height}px`;
|
|
3583
3583
|
let tA = Math.floor(w.left / a) * a;
|
|
3584
|
-
|
|
3584
|
+
I.style.left = `${tA + g}px`, I.style.top = `${w.top + u}px`;
|
|
3585
3585
|
} else if (((Z = (X = A.decoration) == null ? void 0 : X.style) == null ? void 0 : Z.width) === "bounds")
|
|
3586
|
-
|
|
3586
|
+
I.style.width = `${R.width}px`, I.style.height = `${w.height}px`, I.style.left = `${R.left + g}px`, I.style.top = `${w.top + u}px`;
|
|
3587
3587
|
else if (((MA = (dA = A.decoration) == null ? void 0 : dA.style) == null ? void 0 : MA.width) === "page") {
|
|
3588
|
-
|
|
3588
|
+
I.style.width = `${c}px`, I.style.height = `${w.height}px`;
|
|
3589
3589
|
let tA = Math.floor(w.left / c) * c;
|
|
3590
|
-
|
|
3590
|
+
I.style.left = `${tA + g}px`, I.style.top = `${w.top + u}px`;
|
|
3591
3591
|
} else
|
|
3592
|
-
|
|
3592
|
+
I.style.width = `${w.width}px`, I.style.height = `${w.height}px`, I.style.left = `${w.left + g}px`, I.style.top = `${w.top + u}px`;
|
|
3593
3593
|
}, B = A.range.getBoundingClientRect();
|
|
3594
|
-
let
|
|
3594
|
+
let f = this.wnd.document.createElement("template");
|
|
3595
3595
|
const E = Ti(this.wnd, "--USER__appearance") === "readium-night-on";
|
|
3596
|
-
|
|
3596
|
+
f.innerHTML = `
|
|
3597
3597
|
<div
|
|
3598
3598
|
class="r2-highlight-0"
|
|
3599
3599
|
style="${[
|
|
@@ -3606,18 +3606,18 @@ class Si {
|
|
|
3606
3606
|
>
|
|
3607
3607
|
</div>
|
|
3608
3608
|
`.trim();
|
|
3609
|
-
const p =
|
|
3609
|
+
const p = f.content.firstElementChild;
|
|
3610
3610
|
if (((s = (r = A.decoration) == null ? void 0 : r.style) == null ? void 0 : s.layout) === "bounds") {
|
|
3611
|
-
const
|
|
3612
|
-
|
|
3611
|
+
const I = p.cloneNode(!0);
|
|
3612
|
+
I.style.setProperty("pointer-events", "none"), m(I, B, B), o.append(I);
|
|
3613
3613
|
} else {
|
|
3614
|
-
let
|
|
3614
|
+
let I = oi(
|
|
3615
3615
|
A.range,
|
|
3616
3616
|
!0
|
|
3617
3617
|
// doNotMergeHorizontallyAlignedRects
|
|
3618
3618
|
);
|
|
3619
|
-
|
|
3620
|
-
for (let w of
|
|
3619
|
+
I = I.sort((w, R) => w.top < R.top ? -1 : w.top > R.top ? 1 : 0);
|
|
3620
|
+
for (let w of I) {
|
|
3621
3621
|
const R = p.cloneNode(!0);
|
|
3622
3622
|
R.style.setProperty("pointer-events", "none"), m(R, w, B), o.append(R);
|
|
3623
3623
|
}
|
|
@@ -3773,7 +3773,7 @@ function Be(i) {
|
|
|
3773
3773
|
return Gi.indexOf(i.nodeName.toLowerCase()) !== -1 || i.hasAttribute("contenteditable") && ((A = i.getAttribute("contenteditable")) == null ? void 0 : A.toLowerCase()) !== "false" ? i : i.parentElement ? Be(i.parentElement) : null;
|
|
3774
3774
|
}
|
|
3775
3775
|
function Ee(i, A) {
|
|
3776
|
-
const t =
|
|
3776
|
+
const t = fe(i, i.document.body, A);
|
|
3777
3777
|
return new L({
|
|
3778
3778
|
href: "#",
|
|
3779
3779
|
type: "application/xhtml+xml",
|
|
@@ -3787,11 +3787,11 @@ function Ee(i, A) {
|
|
|
3787
3787
|
})
|
|
3788
3788
|
});
|
|
3789
3789
|
}
|
|
3790
|
-
function
|
|
3790
|
+
function fe(i, A, t) {
|
|
3791
3791
|
for (var e = 0; e < A.children.length; e++) {
|
|
3792
3792
|
const n = A.children[e];
|
|
3793
3793
|
if (!bi(n) && vi(i, n, t))
|
|
3794
|
-
return
|
|
3794
|
+
return fe(i, n, t);
|
|
3795
3795
|
}
|
|
3796
3796
|
return A;
|
|
3797
3797
|
}
|
|
@@ -3807,7 +3807,7 @@ function bi(i) {
|
|
|
3807
3807
|
const A = getComputedStyle(i);
|
|
3808
3808
|
return !!(A && (A.getPropertyValue("display") != "block" || A.getPropertyValue("opacity") === "0"));
|
|
3809
3809
|
}
|
|
3810
|
-
const Ct = "readium-column-snapper-style", Ji = 200,
|
|
3810
|
+
const Ct = "readium-column-snapper-style", Ji = 200, Ie = class N extends ue {
|
|
3811
3811
|
constructor() {
|
|
3812
3812
|
super(...arguments), this.shakeTimeout = 0, this.snappingCancelled = !1, this.alreadyScrollLeft = 0, this.overscroll = 0, this.cachedScrollWidth = 0, this.touchState = 0, this.startingX = void 0, this.endingX = void 0, this.onTouchStarter = this.onTouchStart.bind(this), this.onTouchEnder = this.onTouchEnd.bind(this), this.onWidthChanger = this.onWidthChange.bind(this), this.onTouchMover = this.onTouchMove.bind(this);
|
|
3813
3813
|
}
|
|
@@ -3849,7 +3849,7 @@ const Ct = "readium-column-snapper-style", Ji = 200, fe = class N extends ue {
|
|
|
3849
3849
|
), c = this.snapOffset(o + h);
|
|
3850
3850
|
if (A && c !== this.scrollOffset()) {
|
|
3851
3851
|
this.snappingCancelled = !1;
|
|
3852
|
-
const l = (B,
|
|
3852
|
+
const l = (B, f, E, p) => E > p ? f : B + (f - B) * Hi(E / p), g = (
|
|
3853
3853
|
/*Math.abs(startX - (this.useTransform ? currentOffset : 0)) < 10 ? 1 : */
|
|
3854
3854
|
Ji * s
|
|
3855
3855
|
);
|
|
@@ -3858,8 +3858,8 @@ const Ct = "readium-column-snapper-style", Ji = 200, fe = class N extends ue {
|
|
|
3858
3858
|
if (this.snappingCancelled)
|
|
3859
3859
|
return;
|
|
3860
3860
|
u || (u = B);
|
|
3861
|
-
const
|
|
3862
|
-
n.scrollLeft = p, this.overscroll !== 0 && (n.style.transform = `translate3d(${-E}px, 0px, 0px)`),
|
|
3861
|
+
const f = B - u, E = l(this.overscroll, 0, f, g), p = l(e, c, f, g);
|
|
3862
|
+
n.scrollLeft = p, this.overscroll !== 0 && (n.style.transform = `translate3d(${-E}px, 0px, 0px)`), f < g ? this.wnd.requestAnimationFrame(m) : (this.clearTouches(), n.style.removeProperty("transform"), n.scrollLeft = c, t || this.reportProgress());
|
|
3863
3863
|
};
|
|
3864
3864
|
this.wnd.requestAnimationFrame(m);
|
|
3865
3865
|
} else
|
|
@@ -4040,8 +4040,8 @@ const Ct = "readium-column-snapper-style", Ji = 200, fe = class N extends ue {
|
|
|
4040
4040
|
return this.snappingCancelled = !0, t.unregisterAll(N.moduleName), this.resizeObserver.disconnect(), this.mutationObserver.disconnect(), A.removeEventListener("touchstart", this.onTouchStarter), A.removeEventListener("touchend", this.onTouchEnder), A.removeEventListener("touchmove", this.onTouchMover), A.removeEventListener("orientationchange", this.onWidthChanger), A.removeEventListener("resize", this.onWidthChanger), (e = A.document.getElementById(Ct)) == null || e.remove(), t.log("ColumnSnapper Unmounted"), super.unmount(A, t);
|
|
4041
4041
|
}
|
|
4042
4042
|
};
|
|
4043
|
-
|
|
4044
|
-
let Pi =
|
|
4043
|
+
Ie.moduleName = "column_snapper";
|
|
4044
|
+
let Pi = Ie;
|
|
4045
4045
|
const YA = {
|
|
4046
4046
|
top: "js-iframe-reader-top-anchor",
|
|
4047
4047
|
bottom: "js-iframe-reader-bottom-anchor"
|
|
@@ -4561,7 +4561,7 @@ class Re {
|
|
|
4561
4561
|
}
|
|
4562
4562
|
class $i {
|
|
4563
4563
|
constructor(A) {
|
|
4564
|
-
this.currModules = [], this.frame = document.createElement("iframe"), this.frame.classList.add("readium-navigator-iframe"), this.frame.style.visibility = "hidden", this.frame.style.setProperty("aria-hidden", "true"), this.frame.style.opacity = "0", this.frame.style.position = "absolute", this.frame.style.pointerEvents = "none", this.frame.style.transition = "visibility 0s, opacity 0.1s linear", this.source = A;
|
|
4564
|
+
this.destroyed = !1, this.currModules = [], this.frame = document.createElement("iframe"), this.frame.classList.add("readium-navigator-iframe"), this.frame.style.visibility = "hidden", this.frame.style.setProperty("aria-hidden", "true"), this.frame.style.opacity = "0", this.frame.style.position = "absolute", this.frame.style.pointerEvents = "none", this.frame.style.transition = "visibility 0s, opacity 0.1s linear", this.source = A;
|
|
4565
4565
|
}
|
|
4566
4566
|
async load(A) {
|
|
4567
4567
|
return new Promise((t, e) => {
|
|
@@ -4599,25 +4599,27 @@ class $i {
|
|
|
4599
4599
|
}
|
|
4600
4600
|
async destroy() {
|
|
4601
4601
|
var A;
|
|
4602
|
-
await this.hide(), (A = this.loader) == null || A.destroy(), this.frame.remove();
|
|
4602
|
+
await this.hide(), (A = this.loader) == null || A.destroy(), this.frame.remove(), this.destroyed = !0;
|
|
4603
4603
|
}
|
|
4604
4604
|
async hide() {
|
|
4605
4605
|
var A;
|
|
4606
|
-
if (this.
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4606
|
+
if (!this.destroyed) {
|
|
4607
|
+
if (this.frame.style.visibility = "hidden", this.frame.style.setProperty("aria-hidden", "true"), this.frame.style.opacity = "0", this.frame.style.pointerEvents = "none", this.frame.parentElement)
|
|
4608
|
+
return this.comms === void 0 || !this.comms.ready ? void 0 : new Promise((t, e) => {
|
|
4609
|
+
var n;
|
|
4610
|
+
(n = this.comms) == null || n.send("unfocus", void 0, (r) => {
|
|
4611
|
+
var s;
|
|
4612
|
+
(s = this.comms) == null || s.halt(), t();
|
|
4613
|
+
});
|
|
4612
4614
|
});
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
+
(A = this.comms) == null || A.halt();
|
|
4616
|
+
}
|
|
4615
4617
|
}
|
|
4616
4618
|
async show(A) {
|
|
4617
|
-
if (
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
4619
|
+
if (this.destroyed)
|
|
4620
|
+
throw Error("Trying to show frame when it doesn't exist");
|
|
4621
|
+
if (!this.frame.parentElement)
|
|
4622
|
+
throw Error("Trying to show frame that is not attached to the DOM");
|
|
4621
4623
|
return this.comms ? this.comms.resume() : this.comms = new Re(this.frame.contentWindow, this.source), new Promise((t, e) => {
|
|
4622
4624
|
var n;
|
|
4623
4625
|
(n = this.comms) == null || n.send("activate", void 0, () => {
|
|
@@ -4633,13 +4635,17 @@ class $i {
|
|
|
4633
4635
|
});
|
|
4634
4636
|
}
|
|
4635
4637
|
get iframe() {
|
|
4638
|
+
if (this.destroyed)
|
|
4639
|
+
throw Error("Trying to use frame when it doesn't exist");
|
|
4636
4640
|
return this.frame;
|
|
4637
4641
|
}
|
|
4638
4642
|
get realSize() {
|
|
4643
|
+
if (this.destroyed)
|
|
4644
|
+
throw Error("Trying to use frame client rect when it doesn't exist");
|
|
4639
4645
|
return this.frame.getBoundingClientRect();
|
|
4640
4646
|
}
|
|
4641
4647
|
get window() {
|
|
4642
|
-
if (!this.frame.contentWindow)
|
|
4648
|
+
if (this.destroyed || !this.frame.contentWindow)
|
|
4643
4649
|
throw Error("Trying to use frame window when it doesn't exist");
|
|
4644
4650
|
return this.frame.contentWindow;
|
|
4645
4651
|
}
|
|
@@ -4681,7 +4687,7 @@ class An {
|
|
|
4681
4687
|
const s = this.positions[r].href;
|
|
4682
4688
|
this.inprogress.has(s) && await this.inprogress.get(s);
|
|
4683
4689
|
const o = new Promise(async (a, h) => {
|
|
4684
|
-
var m, B,
|
|
4690
|
+
var m, B, f;
|
|
4685
4691
|
const c = [], l = [];
|
|
4686
4692
|
this.positions.forEach((E, p) => {
|
|
4687
4693
|
(p > r + xt || p < r - xt) && (c.includes(E.href) || c.push(E.href)), p < r + jt && p > r - jt && (l.includes(E.href) || l.push(E.href));
|
|
@@ -4706,8 +4712,8 @@ class An {
|
|
|
4706
4712
|
const R = await new Kt(A, this.currentBaseURL || "", p).build();
|
|
4707
4713
|
this.blobs.set(E, R);
|
|
4708
4714
|
}
|
|
4709
|
-
const
|
|
4710
|
-
E !== s && await
|
|
4715
|
+
const I = new $i(this.blobs.get(E));
|
|
4716
|
+
E !== s && await I.hide(), this.container.appendChild(I.iframe), await I.load(e), this.pool.set(E, I);
|
|
4711
4717
|
};
|
|
4712
4718
|
try {
|
|
4713
4719
|
await Promise.all(l.map((E) => g(E)));
|
|
@@ -4717,7 +4723,7 @@ class An {
|
|
|
4717
4723
|
const u = this.pool.get(s);
|
|
4718
4724
|
if ((u == null ? void 0 : u.source) !== ((m = this._currentFrame) == null ? void 0 : m.source) || n) {
|
|
4719
4725
|
await ((B = this._currentFrame) == null ? void 0 : B.hide()), u && await u.load(e);
|
|
4720
|
-
const E = (((
|
|
4726
|
+
const E = (((f = t == null ? void 0 : t.locations) == null ? void 0 : f.progression) ?? 0) > 0;
|
|
4721
4727
|
u && await u.show(E ? t.locations.progression : void 0), this._currentFrame = u;
|
|
4722
4728
|
}
|
|
4723
4729
|
a();
|
|
@@ -5210,8 +5216,8 @@ class an {
|
|
|
5210
5216
|
m += u.X / this.scale, this.pinch.target.X += m, u.X += this.pinch.target.X * this.scale / this.pinch.startScale;
|
|
5211
5217
|
let B = -u.Y / r;
|
|
5212
5218
|
B += u.Y / this.scale, this.pinch.target.Y += B, u.Y += this.pinch.target.Y * this.scale / this.pinch.startScale;
|
|
5213
|
-
let
|
|
5214
|
-
this.pan.translateX =
|
|
5219
|
+
let f = (u.X - (this.pan.startX - this.manager.width / 2)) * 1 / this.scale, E = (u.Y - (this.pan.startY - this.manager.height / 2)) * 1 / this.scale;
|
|
5220
|
+
this.pan.translateX = f, this.pan.translateY = E, (h = this.debugger) != null && h.show && (this.debugger.DOM.pinchTarget.style.left = `${this.pinch.target.X * this.scale / this.pinch.startScale - 5 + this.manager.width / 2}px`, this.debugger.DOM.pinchTarget.style.top = `${this.pinch.target.Y * this.scale / this.pinch.startScale - 5 + this.manager.height / 2}px`, this.debugger.DOM.pinchTarget.innerText = `${(this.pinch.target.X * this.scale / this.pinch.startScale).toFixed(2)},${(this.pinch.target.Y * this.scale / this.pinch.startScale).toFixed(2)}`);
|
|
5215
5221
|
}
|
|
5216
5222
|
const l = this.frameBounds.width / 6, g = this.frameBounds.height / 6;
|
|
5217
5223
|
this.pan.translateX < -l && (this.pan.overscrollX = -(l + this.pan.translateX), this.pan.translateX = -l), this.pan.translateY < -g && (this.pan.overscrollY = -(g + this.pan.translateY), this.pan.translateY = -g), this.pan.translateX > l && (this.pan.overscrollX = l - this.pan.translateX, this.pan.translateX = l), this.pan.translateY > g && (this.pan.overscrollY = g - this.pan.translateY, this.pan.translateY = g), n = !0, (c = this.debugger) != null && c.show && (this.debugger.DOM.stats.innerText = `TX: ${this.pan.translateX.toFixed(2)}
|
|
@@ -5554,21 +5560,21 @@ class un {
|
|
|
5554
5560
|
l.includes(m) || this.pool.has(m) && (this.cancelShowing(m), await ((B = this.pool.get(m)) == null ? void 0 : B.unload()));
|
|
5555
5561
|
}), this.currentBaseURL !== void 0 && A.baseURL !== this.currentBaseURL && (this.blobs.forEach((m) => URL.revokeObjectURL(m)), this.blobs.clear()), this.currentBaseURL = A.baseURL;
|
|
5556
5562
|
const g = async (m) => {
|
|
5557
|
-
const B = A.readingOrder.findIndexWithHref(m),
|
|
5558
|
-
if (
|
|
5563
|
+
const B = A.readingOrder.findIndexWithHref(m), f = A.readingOrder.items[B];
|
|
5564
|
+
if (f) {
|
|
5559
5565
|
if (!this.blobs.has(m)) {
|
|
5560
|
-
const p = await new Kt(A, this.currentBaseURL || "",
|
|
5566
|
+
const p = await new Kt(A, this.currentBaseURL || "", f).build(!0);
|
|
5561
5567
|
this.blobs.set(m, p);
|
|
5562
5568
|
}
|
|
5563
5569
|
this.delayedShow.has(m) || this.delayedShow.set(m, new Promise((E, p) => {
|
|
5564
|
-
let
|
|
5570
|
+
let I = !1;
|
|
5565
5571
|
const w = window.setTimeout(async () => {
|
|
5566
5572
|
this.delayedTimeout.set(m, 0);
|
|
5567
|
-
const R = this.makeSpread(this.reAlign(B)), AA = this.spreadPosition(R,
|
|
5568
|
-
await O.load(e, this.blobs.get(m)), this.peripherals.isScaled || await O.show(AA), this.delayedShow.delete(m),
|
|
5573
|
+
const R = this.makeSpread(this.reAlign(B)), AA = this.spreadPosition(R, f), O = this.pool.get(m);
|
|
5574
|
+
await O.load(e, this.blobs.get(m)), this.peripherals.isScaled || await O.show(AA), this.delayedShow.delete(m), I = !0, E();
|
|
5569
5575
|
}, cn);
|
|
5570
5576
|
setTimeout(() => {
|
|
5571
|
-
!
|
|
5577
|
+
!I && this.delayedShow.has(m) && p(`Offscreen load timeout: ${m}`);
|
|
5572
5578
|
}, ln), this.delayedTimeout.set(m, w);
|
|
5573
5579
|
}));
|
|
5574
5580
|
}
|
|
@@ -5580,8 +5586,8 @@ class un {
|
|
|
5580
5586
|
}
|
|
5581
5587
|
const u = [];
|
|
5582
5588
|
for (const m of s) {
|
|
5583
|
-
const B = this.pool.get(m.href),
|
|
5584
|
-
|
|
5589
|
+
const B = this.pool.get(m.href), f = this.blobs.get(m.href);
|
|
5590
|
+
f && (this.cancelShowing(m.href), await B.load(e, f), await B.show(this.spreadPosition(s, m)), this.previousFrames.push(B), await B.activate(), u.push(B));
|
|
5585
5591
|
}
|
|
5586
5592
|
for (; this.previousFrames.length > 0; ) {
|
|
5587
5593
|
const m = this.previousFrames.shift();
|
package/dist/index.umd.cjs
CHANGED
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
min-height: 100%;
|
|
93
93
|
|
|
94
94
|
/*cursor: var() TODO*/
|
|
95
|
-
}`,A.document.head.appendChild(e),t.register("set_property",O.moduleName,(n,r)=>{const s=n;At(A,s[0],s[1]),r(!0)}),t.register("remove_property",O.moduleName,(n,r)=>{qt(A,n),r(!0)}),t.register("first_visible_locator",O.moduleName,(n,r)=>r(!1)),t.register("unfocus",O.moduleName,(n,r)=>{N(A),r(!0)}),t.register(["focus","go_next","go_prev","go_id","go_end","go_start","go_text","go_progression"],O.moduleName,(n,r)=>r(!0)),t.register("activate",O.moduleName,(n,r)=>{this.unblock(A),r(!0)}),t.log("FixedSetup Mounted"),!0}unmount(A,t){var e;return t.unregisterAll(O.moduleName),(e=A.document.getElementById(me))==null||e.remove(),t.log("FixedSetup Unmounted"),super.unmount(A,t)}};Be.moduleName="fixed_setup";let sn=Be;const on=["fixed_setup","decorator","peripherals"],an=["reflowable_setup","decorator","peripherals","column_snapper","scroll_snapper"],tt=new Map([sn,rn,le,Li,$i,nn].map(i=>[i.moduleName,i]));class zA{constructor(A=window,t=[]){this.loadedModules=[],this.wnd=A,this.comms=new hi(A);const e=[...new Set(t)];if(e.length){if(typeof A>"u")throw Error("Loader is not in a web browser");A.parent!==A&&this.comms.log("Loader is probably in a frame"),this.loadedModules=e.map(n=>{const r=this.loadModule(n);if(r)return r.mount(this.wnd,this.comms),r}).filter(n=>n!==void 0)}}loadModule(A){const t=tt.get(A);return t===void 0?(this.comms.log(`Module "${name}" does not exist in the library`),t):new t}addModule(A){const t=this.loadModule(A);return!t||!t.mount(this.wnd,this.comms)?!1:(this.loadedModules.push(t),!0)}removeModule(A){const t=tt.get(A);if(t===void 0)return this.comms.log(`Module "${A}" does not exist in the library`),!1;const e=this.loadedModules.findIndex(n=>n instanceof t);return e<0?!1:(this.loadedModules[e].unmount(this.wnd,this.comms),this.loadedModules.splice(e,1),!0)}destroy(){this.comms.destroy(),this.loadedModules.forEach(A=>A.unmount(this.wnd,this.comms)),this.loadedModules=[]}}const hn=1e4;class et{constructor(A,t){this.registry=new Map,this._ready=!1,this.listenerBuffer=[],this.handler=this.handle.bind(this),this.wnd=A,this.origin=t;try{this.channelId=window.crypto.randomUUID()}catch{this.channelId=vA()}this.gc=setInterval(()=>{this.registry.forEach((e,n)=>{performance.now()-e.time>hn&&(console.warn(n,"event for",e.key,"was never handled!"),this.registry.delete(n))})},5e3),window.addEventListener("message",this.handler),this.send("_ping",void 0)}set listener(A){this.listenerBuffer.length>0&&this.listenerBuffer.forEach(t=>A(t[0],t[1])),this.listenerBuffer=[],this._listener=A}clearListener(){typeof this._listener=="function"&&(this._listener=void 0)}halt(){this._ready=!1,window.removeEventListener("message",this.handler),clearInterval(this.gc),this._listener=void 0,this.registry.clear()}resume(){window.addEventListener("message",this.handler),this._ready=!0}handle(A){const t=A.data;if(!t._readium){console.warn("Ignoring",t);return}if(t._channel===this.channelId)switch(t.key){case"_ack":{if(!t.id)return;const e=this.registry.get(t.id);if(!e)return;this.registry.delete(t.id),e.cb(!!t.data);return}case"_pong":this._ready=!0;default:{if(!this.ready)return;typeof this._listener=="function"?this._listener(t.key,t.data):this.listenerBuffer.push([t.key,t.data])}}}get ready(){return this._ready}send(A,t,e,n=!1,r=[]){const s=vA();return e&&this.registry.set(s,{cb:e,time:performance.now(),key:A}),this.wnd.postMessage({_readium:eA,_channel:this.channelId,id:s,data:t,key:A,strict:n},"/",r),s}}class Ee{constructor(A){this.currModules=[],this.frame=document.createElement("iframe"),this.frame.classList.add("readium-navigator-iframe"),this.frame.style.visibility="hidden",this.frame.style.setProperty("aria-hidden","true"),this.frame.style.opacity="0",this.frame.style.position="absolute",this.frame.style.pointerEvents="none",this.frame.style.transition="visibility 0s, opacity 0.1s linear",this.source=A}async load(A){return new Promise((t,e)=>{var n;if(this.loader){const r=this.frame.contentWindow;if([...this.currModules].sort().join("|")===[...A].sort().join("|")){try{t(r)}catch{}return}(n=this.comms)==null||n.halt(),this.loader.destroy(),this.loader=new zA(r,A),this.currModules=A,this.comms=void 0;try{t(r)}catch{}return}this.frame.onload=()=>{const r=this.frame.contentWindow;this.loader=new zA(r,A),this.currModules=A;try{t(r)}catch{}},this.frame.onerror=r=>{try{e(r)}catch{}},this.frame.contentWindow.location.replace(this.source)})}async destroy(){var A;await this.hide(),(A=this.loader)==null||A.destroy(),this.frame.remove()}async hide(){var A;if(this.frame.style.visibility="hidden",this.frame.style.setProperty("aria-hidden","true"),this.frame.style.opacity="0",this.frame.style.pointerEvents="none",this.frame.parentElement)return this.comms===void 0?void 0:new Promise((t,e)=>{var n;(n=this.comms)==null||n.send("unfocus",void 0,r=>{var s;(s=this.comms)==null||s.halt(),t()})});(A=this.comms)==null||A.halt()}async show(A){if(!this.frame.parentElement){console.warn("Trying to show frame that is not attached to the DOM");return}return this.comms?this.comms.resume():this.comms=new et(this.frame.contentWindow,this.source),new Promise((t,e)=>{var n;(n=this.comms)==null||n.send("activate",void 0,()=>{var r;(r=this.comms)==null||r.send("focus",void 0,()=>{var o;const s=()=>{this.frame.style.removeProperty("visibility"),this.frame.style.removeProperty("aria-hidden"),this.frame.style.removeProperty("opacity"),this.frame.style.removeProperty("pointer-events"),t()};A&&A>0?(o=this.comms)==null||o.send("go_progression",A,s):s()})})})}get iframe(){return this.frame}get realSize(){return this.frame.getBoundingClientRect()}get window(){if(!this.frame.contentWindow)throw Error("Trying to use frame window when it doesn't exist");return this.frame.contentWindow}get atLeft(){return this.window.scrollX<5}get atRight(){return this.window.scrollX>this.window.document.scrollingElement.scrollWidth-this.window.innerWidth-5}get msg(){return this.comms}get ldr(){return this.loader}}const fe=5,Ie=3;class pe{constructor(A,t){this.pool=new Map,this.blobs=new Map,this.inprogress=new Map,this.container=A,this.positions=t}async destroy(){let A=this.inprogress.values(),t=A.next();const e=[];for(;t.value;)e.push(t.value),t=A.next();e.length>0&&await Promise.allSettled(e),this.inprogress.clear();let n=this.pool.values(),r=n.next();for(;r.value;)await r.value.destroy(),r=n.next();this.pool.clear(),this.blobs.forEach(s=>URL.revokeObjectURL(s)),this.container.childNodes.forEach(s=>{(s.nodeType===Node.ELEMENT_NODE||s.nodeType===Node.TEXT_NODE)&&s.remove()})}async update(A,t,e,n=!1){let r=this.positions.findIndex(a=>a.locations.position===t.locations.position);if(r<0)throw Error(`Locator not found in position list: ${t.locations.position} > ${this.positions.reduce((a,h)=>h.locations.position||0>a?h.locations.position||0:a,0)}`);const s=this.positions[r].href;this.inprogress.has(s)&&await this.inprogress.get(s);const o=new Promise(async(a,h)=>{var m,B,f;const c=[],l=[];this.positions.forEach((E,p)=>{(p>r+fe||p<r-fe)&&(c.includes(E.href)||c.push(E.href)),p<r+Ie&&p>r-Ie&&(l.includes(E.href)||l.push(E.href))}),c.forEach(async E=>{var p;l.includes(E)||this.pool.has(E)&&(await((p=this.pool.get(E))==null?void 0:p.destroy()),this.pool.delete(E))}),this.currentBaseURL!==void 0&&A.baseURL!==this.currentBaseURL&&(this.blobs.forEach(E=>URL.revokeObjectURL(E)),this.blobs.clear()),this.currentBaseURL=A.baseURL;const g=async E=>{if(this.pool.has(E)){const w=this.pool.get(E);if(!this.blobs.has(E))await w.destroy(),this.pool.delete(E);else{await w.load(e);return}}const p=A.readingOrder.findWithHref(E);if(!p)return;if(!this.blobs.has(E)){const Y=await new Bt(A,this.currentBaseURL||"",p).build();this.blobs.set(E,Y)}const I=new Ee(this.blobs.get(E));E!==s&&await I.hide(),this.container.appendChild(I.iframe),await I.load(e),this.pool.set(E,I)};try{await Promise.all(l.map(E=>g(E)))}catch(E){h(E)}const u=this.pool.get(s);if((u==null?void 0:u.source)!==((m=this._currentFrame)==null?void 0:m.source)||n){await((B=this._currentFrame)==null?void 0:B.hide()),u&&await u.load(e);const E=(((f=t==null?void 0:t.locations)==null?void 0:f.progression)??0)>0;u&&await u.show(E?t.locations.progression:void 0),this._currentFrame=u}a()});this.inprogress.set(s,o),await o,this.inprogress.delete(s)}get currentFrames(){return[this._currentFrame]}get currentBounds(){const A={x:0,y:0,width:0,height:0,top:0,right:0,bottom:0,left:0,toJSON(){return this}};return this.currentFrames.forEach(t=>{if(!t)return;const e=t.realSize;A.x=Math.min(A.x,e.x),A.y=Math.min(A.y,e.y),A.width+=e.width,A.height=Math.max(A.height,e.height),A.top=Math.min(A.top,e.top),A.right=Math.min(A.right,e.right),A.bottom=Math.min(A.bottom,e.bottom),A.left=Math.min(A.left,e.left)}),A}}class we{constructor(A,t,e){this.currModules=[],this.cachedPage=void 0,this.peripherals=A,this.debugHref=e,this.frame=document.createElement("iframe"),this.frame.classList.add("readium-navigator-iframe"),this.frame.classList.add("blank"),this.frame.scrolling="no",this.frame.style.visibility="hidden",this.frame.style.setProperty("aria-hidden","true"),this.frame.style.display="none",this.frame.style.position="absolute",this.frame.style.pointerEvents="none",this.frame.style.transformOrigin="0 0",this.frame.style.transform="scale(1)",this.frame.style.background="#fff",this.frame.style.touchAction="none",this.frame.dataset.originalHref=e,this.source="about:blank",this.wrapper=document.createElement("div"),this.wrapper.style.position="relative",this.wrapper.style.float=this.wrapper.style.cssFloat=t===F.rtl?"right":"left",this.wrapper.appendChild(this.frame)}async load(A,t){return this.source===t&&this.loadPromise&&[...this.currModules].sort().join("|")===[...A].sort().join("|")?this.loadPromise:(this.loaded&&this.source!==t&&this.window.stop(),this.source=t,this.loadPromise=new Promise((e,n)=>{var r;if(this.loader&&this.loaded){const s=this.frame.contentWindow;if([...this.currModules].sort().join("|")===[...A].sort().join("|")){try{e(s),this.loadPromise=void 0}catch{}return}(r=this.comms)==null||r.halt(),this.loader.destroy(),this.loader=new zA(s,A),this.currModules=A,this.comms=void 0;try{e(s),this.loadPromise=void 0}catch{}return}this.frame.addEventListener("load",()=>{const s=this.frame.contentWindow;this.loader=new zA(s,A),this.currModules=A,this.peripherals.observe(this.wrapper),this.peripherals.observe(s);try{e(s)}catch{}},{once:!0}),this.frame.addEventListener("error",s=>{try{n(s.error),this.loadPromise=void 0}catch{}},{once:!0}),this.frame.style.removeProperty("display"),this.frame.contentWindow.location.replace(this.source)}),this.loadPromise)}loadPageSize(){const A=this.frame.contentWindow,t=A.document.head.querySelector("meta[name=viewport]");if(t){const e=/(\w+) *= *([^\s,]+)/g;let n,r=0,s=0;for(;n=e.exec(t.content);)n[1]==="width"?r=Number.parseFloat(n[2]):n[1]==="height"&&(s=Number.parseFloat(n[2]));if(r>0&&s>0)return{width:r,height:s}}return{width:A.document.body.scrollWidth,height:A.document.body.scrollHeight}}update(A){if(!this.loaded)return;const t=this.loadPageSize();this.frame.style.height=`${t.height}px`,this.frame.style.width=`${t.width}px`;const e=Math.min(this.wrapper.clientWidth/t.width,this.wrapper.clientHeight/t.height);this.frame.style.transform=`scale(${e})`;const n=this.frame.getBoundingClientRect(),r=this.wrapper.clientHeight-n.height;if(this.frame.style.top=`${r/2}px`,A===D.left){const s=this.wrapper.clientWidth-n.width;this.frame.style.left=`${s}px`}else if(A===D.center){const s=this.wrapper.clientWidth-n.width;this.frame.style.left=`${s/2}px`}else this.frame.style.left="0px";this.frame.style.removeProperty("visibility"),this.frame.style.removeProperty("aria-hidden"),this.frame.style.removeProperty("pointer-events"),this.frame.classList.remove("blank"),this.frame.classList.add("loaded")}async destroy(){var A;await this.unfocus(),(A=this.loader)==null||A.destroy(),this.wrapper.remove()}async unload(){var A,t;if(this.loaded)return this.deselect(),this.frame.style.visibility="hidden",this.frame.style.setProperty("aria-hidden","true"),this.frame.style.pointerEvents="none",this.frame.classList.add("blank"),this.frame.classList.remove("loaded"),(A=this.comms)==null||A.halt(),(t=this.loader)==null||t.destroy(),this.comms=void 0,this.frame.blur(),new Promise((e,n)=>{this.frame.addEventListener("load",()=>{try{this.showPromise=void 0,e()}catch{}},{once:!0}),this.frame.addEventListener("error",r=>{try{this.showPromise=void 0,n(r.error)}catch{}},{once:!0}),this.source="about:blank",this.frame.contentWindow.location.replace("about:blank"),this.frame.style.display="none"})}deselect(){var A,t;(t=(A=this.frame.contentWindow)==null?void 0:A.getSelection())==null||t.removeAllRanges()}async unfocus(){var A;if(this.frame.parentElement)return this.comms===void 0?void 0:new Promise((t,e)=>{var n;(n=this.comms)==null||n.send("unfocus",void 0,r=>{var s;(s=this.comms)==null||s.halt(),this.showPromise=void 0,t()})});(A=this.comms)==null||A.halt()}async show(A){if(!this.frame.parentElement){console.warn("Trying to show frame that is not attached to the DOM");return}if(!this.loaded){this.showPromise=void 0;return}return this.showPromise?(this.cachedPage!==A&&(this.update(A),this.cachedPage=A),this.showPromise):(this.cachedPage=A,this.comms?this.comms.resume():this.comms=new et(this.frame.contentWindow,this.source),this.showPromise=new Promise((t,e)=>{this.comms.send("focus",void 0,n=>{this.update(this.cachedPage),t()})}),this.showPromise)}async activate(){return new Promise((A,t)=>{var e;if(!this.comms)return A();(e=this.comms)==null||e.send("activate",void 0,()=>{A()})})}get element(){return this.wrapper}get iframe(){return this.frame}get realSize(){return this.frame.getBoundingClientRect()}get loaded(){return this.frame.contentWindow&&this.frame.contentWindow.location.href!=="about:blank"}set width(A){const t=`${A}%`;this.wrapper.style.width!==t&&(this.wrapper.style.width=t)}set height(A){const t=`${A}px`;this.wrapper.style.height!==t&&(this.wrapper.style.height=t)}get window(){if(!this.frame.contentWindow)throw Error("Trying to use frame window when it doesn't exist");return this.frame.contentWindow}get atLeft(){return this.window.scrollX<5}get atRight(){return this.window.scrollX>this.window.document.scrollingElement.scrollWidth-this.window.innerWidth-5}get msg(){return this.comms}get ldr(){return this.loader}}/*!
|
|
95
|
+
}`,A.document.head.appendChild(e),t.register("set_property",O.moduleName,(n,r)=>{const s=n;At(A,s[0],s[1]),r(!0)}),t.register("remove_property",O.moduleName,(n,r)=>{qt(A,n),r(!0)}),t.register("first_visible_locator",O.moduleName,(n,r)=>r(!1)),t.register("unfocus",O.moduleName,(n,r)=>{N(A),r(!0)}),t.register(["focus","go_next","go_prev","go_id","go_end","go_start","go_text","go_progression"],O.moduleName,(n,r)=>r(!0)),t.register("activate",O.moduleName,(n,r)=>{this.unblock(A),r(!0)}),t.log("FixedSetup Mounted"),!0}unmount(A,t){var e;return t.unregisterAll(O.moduleName),(e=A.document.getElementById(me))==null||e.remove(),t.log("FixedSetup Unmounted"),super.unmount(A,t)}};Be.moduleName="fixed_setup";let sn=Be;const on=["fixed_setup","decorator","peripherals"],an=["reflowable_setup","decorator","peripherals","column_snapper","scroll_snapper"],tt=new Map([sn,rn,le,Li,$i,nn].map(i=>[i.moduleName,i]));class zA{constructor(A=window,t=[]){this.loadedModules=[],this.wnd=A,this.comms=new hi(A);const e=[...new Set(t)];if(e.length){if(typeof A>"u")throw Error("Loader is not in a web browser");A.parent!==A&&this.comms.log("Loader is probably in a frame"),this.loadedModules=e.map(n=>{const r=this.loadModule(n);if(r)return r.mount(this.wnd,this.comms),r}).filter(n=>n!==void 0)}}loadModule(A){const t=tt.get(A);return t===void 0?(this.comms.log(`Module "${name}" does not exist in the library`),t):new t}addModule(A){const t=this.loadModule(A);return!t||!t.mount(this.wnd,this.comms)?!1:(this.loadedModules.push(t),!0)}removeModule(A){const t=tt.get(A);if(t===void 0)return this.comms.log(`Module "${A}" does not exist in the library`),!1;const e=this.loadedModules.findIndex(n=>n instanceof t);return e<0?!1:(this.loadedModules[e].unmount(this.wnd,this.comms),this.loadedModules.splice(e,1),!0)}destroy(){this.comms.destroy(),this.loadedModules.forEach(A=>A.unmount(this.wnd,this.comms)),this.loadedModules=[]}}const hn=1e4;class et{constructor(A,t){this.registry=new Map,this._ready=!1,this.listenerBuffer=[],this.handler=this.handle.bind(this),this.wnd=A,this.origin=t;try{this.channelId=window.crypto.randomUUID()}catch{this.channelId=vA()}this.gc=setInterval(()=>{this.registry.forEach((e,n)=>{performance.now()-e.time>hn&&(console.warn(n,"event for",e.key,"was never handled!"),this.registry.delete(n))})},5e3),window.addEventListener("message",this.handler),this.send("_ping",void 0)}set listener(A){this.listenerBuffer.length>0&&this.listenerBuffer.forEach(t=>A(t[0],t[1])),this.listenerBuffer=[],this._listener=A}clearListener(){typeof this._listener=="function"&&(this._listener=void 0)}halt(){this._ready=!1,window.removeEventListener("message",this.handler),clearInterval(this.gc),this._listener=void 0,this.registry.clear()}resume(){window.addEventListener("message",this.handler),this._ready=!0}handle(A){const t=A.data;if(!t._readium){console.warn("Ignoring",t);return}if(t._channel===this.channelId)switch(t.key){case"_ack":{if(!t.id)return;const e=this.registry.get(t.id);if(!e)return;this.registry.delete(t.id),e.cb(!!t.data);return}case"_pong":this._ready=!0;default:{if(!this.ready)return;typeof this._listener=="function"?this._listener(t.key,t.data):this.listenerBuffer.push([t.key,t.data])}}}get ready(){return this._ready}send(A,t,e,n=!1,r=[]){const s=vA();return e&&this.registry.set(s,{cb:e,time:performance.now(),key:A}),this.wnd.postMessage({_readium:eA,_channel:this.channelId,id:s,data:t,key:A,strict:n},"/",r),s}}class Ee{constructor(A){this.destroyed=!1,this.currModules=[],this.frame=document.createElement("iframe"),this.frame.classList.add("readium-navigator-iframe"),this.frame.style.visibility="hidden",this.frame.style.setProperty("aria-hidden","true"),this.frame.style.opacity="0",this.frame.style.position="absolute",this.frame.style.pointerEvents="none",this.frame.style.transition="visibility 0s, opacity 0.1s linear",this.source=A}async load(A){return new Promise((t,e)=>{var n;if(this.loader){const r=this.frame.contentWindow;if([...this.currModules].sort().join("|")===[...A].sort().join("|")){try{t(r)}catch{}return}(n=this.comms)==null||n.halt(),this.loader.destroy(),this.loader=new zA(r,A),this.currModules=A,this.comms=void 0;try{t(r)}catch{}return}this.frame.onload=()=>{const r=this.frame.contentWindow;this.loader=new zA(r,A),this.currModules=A;try{t(r)}catch{}},this.frame.onerror=r=>{try{e(r)}catch{}},this.frame.contentWindow.location.replace(this.source)})}async destroy(){var A;await this.hide(),(A=this.loader)==null||A.destroy(),this.frame.remove(),this.destroyed=!0}async hide(){var A;if(!this.destroyed){if(this.frame.style.visibility="hidden",this.frame.style.setProperty("aria-hidden","true"),this.frame.style.opacity="0",this.frame.style.pointerEvents="none",this.frame.parentElement)return this.comms===void 0||!this.comms.ready?void 0:new Promise((t,e)=>{var n;(n=this.comms)==null||n.send("unfocus",void 0,r=>{var s;(s=this.comms)==null||s.halt(),t()})});(A=this.comms)==null||A.halt()}}async show(A){if(this.destroyed)throw Error("Trying to show frame when it doesn't exist");if(!this.frame.parentElement)throw Error("Trying to show frame that is not attached to the DOM");return this.comms?this.comms.resume():this.comms=new et(this.frame.contentWindow,this.source),new Promise((t,e)=>{var n;(n=this.comms)==null||n.send("activate",void 0,()=>{var r;(r=this.comms)==null||r.send("focus",void 0,()=>{var o;const s=()=>{this.frame.style.removeProperty("visibility"),this.frame.style.removeProperty("aria-hidden"),this.frame.style.removeProperty("opacity"),this.frame.style.removeProperty("pointer-events"),t()};A&&A>0?(o=this.comms)==null||o.send("go_progression",A,s):s()})})})}get iframe(){if(this.destroyed)throw Error("Trying to use frame when it doesn't exist");return this.frame}get realSize(){if(this.destroyed)throw Error("Trying to use frame client rect when it doesn't exist");return this.frame.getBoundingClientRect()}get window(){if(this.destroyed||!this.frame.contentWindow)throw Error("Trying to use frame window when it doesn't exist");return this.frame.contentWindow}get atLeft(){return this.window.scrollX<5}get atRight(){return this.window.scrollX>this.window.document.scrollingElement.scrollWidth-this.window.innerWidth-5}get msg(){return this.comms}get ldr(){return this.loader}}const fe=5,Ie=3;class pe{constructor(A,t){this.pool=new Map,this.blobs=new Map,this.inprogress=new Map,this.container=A,this.positions=t}async destroy(){let A=this.inprogress.values(),t=A.next();const e=[];for(;t.value;)e.push(t.value),t=A.next();e.length>0&&await Promise.allSettled(e),this.inprogress.clear();let n=this.pool.values(),r=n.next();for(;r.value;)await r.value.destroy(),r=n.next();this.pool.clear(),this.blobs.forEach(s=>URL.revokeObjectURL(s)),this.container.childNodes.forEach(s=>{(s.nodeType===Node.ELEMENT_NODE||s.nodeType===Node.TEXT_NODE)&&s.remove()})}async update(A,t,e,n=!1){let r=this.positions.findIndex(a=>a.locations.position===t.locations.position);if(r<0)throw Error(`Locator not found in position list: ${t.locations.position} > ${this.positions.reduce((a,h)=>h.locations.position||0>a?h.locations.position||0:a,0)}`);const s=this.positions[r].href;this.inprogress.has(s)&&await this.inprogress.get(s);const o=new Promise(async(a,h)=>{var m,B,f;const c=[],l=[];this.positions.forEach((E,p)=>{(p>r+fe||p<r-fe)&&(c.includes(E.href)||c.push(E.href)),p<r+Ie&&p>r-Ie&&(l.includes(E.href)||l.push(E.href))}),c.forEach(async E=>{var p;l.includes(E)||this.pool.has(E)&&(await((p=this.pool.get(E))==null?void 0:p.destroy()),this.pool.delete(E))}),this.currentBaseURL!==void 0&&A.baseURL!==this.currentBaseURL&&(this.blobs.forEach(E=>URL.revokeObjectURL(E)),this.blobs.clear()),this.currentBaseURL=A.baseURL;const g=async E=>{if(this.pool.has(E)){const w=this.pool.get(E);if(!this.blobs.has(E))await w.destroy(),this.pool.delete(E);else{await w.load(e);return}}const p=A.readingOrder.findWithHref(E);if(!p)return;if(!this.blobs.has(E)){const Y=await new Bt(A,this.currentBaseURL||"",p).build();this.blobs.set(E,Y)}const I=new Ee(this.blobs.get(E));E!==s&&await I.hide(),this.container.appendChild(I.iframe),await I.load(e),this.pool.set(E,I)};try{await Promise.all(l.map(E=>g(E)))}catch(E){h(E)}const u=this.pool.get(s);if((u==null?void 0:u.source)!==((m=this._currentFrame)==null?void 0:m.source)||n){await((B=this._currentFrame)==null?void 0:B.hide()),u&&await u.load(e);const E=(((f=t==null?void 0:t.locations)==null?void 0:f.progression)??0)>0;u&&await u.show(E?t.locations.progression:void 0),this._currentFrame=u}a()});this.inprogress.set(s,o),await o,this.inprogress.delete(s)}get currentFrames(){return[this._currentFrame]}get currentBounds(){const A={x:0,y:0,width:0,height:0,top:0,right:0,bottom:0,left:0,toJSON(){return this}};return this.currentFrames.forEach(t=>{if(!t)return;const e=t.realSize;A.x=Math.min(A.x,e.x),A.y=Math.min(A.y,e.y),A.width+=e.width,A.height=Math.max(A.height,e.height),A.top=Math.min(A.top,e.top),A.right=Math.min(A.right,e.right),A.bottom=Math.min(A.bottom,e.bottom),A.left=Math.min(A.left,e.left)}),A}}class we{constructor(A,t,e){this.currModules=[],this.cachedPage=void 0,this.peripherals=A,this.debugHref=e,this.frame=document.createElement("iframe"),this.frame.classList.add("readium-navigator-iframe"),this.frame.classList.add("blank"),this.frame.scrolling="no",this.frame.style.visibility="hidden",this.frame.style.setProperty("aria-hidden","true"),this.frame.style.display="none",this.frame.style.position="absolute",this.frame.style.pointerEvents="none",this.frame.style.transformOrigin="0 0",this.frame.style.transform="scale(1)",this.frame.style.background="#fff",this.frame.style.touchAction="none",this.frame.dataset.originalHref=e,this.source="about:blank",this.wrapper=document.createElement("div"),this.wrapper.style.position="relative",this.wrapper.style.float=this.wrapper.style.cssFloat=t===F.rtl?"right":"left",this.wrapper.appendChild(this.frame)}async load(A,t){return this.source===t&&this.loadPromise&&[...this.currModules].sort().join("|")===[...A].sort().join("|")?this.loadPromise:(this.loaded&&this.source!==t&&this.window.stop(),this.source=t,this.loadPromise=new Promise((e,n)=>{var r;if(this.loader&&this.loaded){const s=this.frame.contentWindow;if([...this.currModules].sort().join("|")===[...A].sort().join("|")){try{e(s),this.loadPromise=void 0}catch{}return}(r=this.comms)==null||r.halt(),this.loader.destroy(),this.loader=new zA(s,A),this.currModules=A,this.comms=void 0;try{e(s),this.loadPromise=void 0}catch{}return}this.frame.addEventListener("load",()=>{const s=this.frame.contentWindow;this.loader=new zA(s,A),this.currModules=A,this.peripherals.observe(this.wrapper),this.peripherals.observe(s);try{e(s)}catch{}},{once:!0}),this.frame.addEventListener("error",s=>{try{n(s.error),this.loadPromise=void 0}catch{}},{once:!0}),this.frame.style.removeProperty("display"),this.frame.contentWindow.location.replace(this.source)}),this.loadPromise)}loadPageSize(){const A=this.frame.contentWindow,t=A.document.head.querySelector("meta[name=viewport]");if(t){const e=/(\w+) *= *([^\s,]+)/g;let n,r=0,s=0;for(;n=e.exec(t.content);)n[1]==="width"?r=Number.parseFloat(n[2]):n[1]==="height"&&(s=Number.parseFloat(n[2]));if(r>0&&s>0)return{width:r,height:s}}return{width:A.document.body.scrollWidth,height:A.document.body.scrollHeight}}update(A){if(!this.loaded)return;const t=this.loadPageSize();this.frame.style.height=`${t.height}px`,this.frame.style.width=`${t.width}px`;const e=Math.min(this.wrapper.clientWidth/t.width,this.wrapper.clientHeight/t.height);this.frame.style.transform=`scale(${e})`;const n=this.frame.getBoundingClientRect(),r=this.wrapper.clientHeight-n.height;if(this.frame.style.top=`${r/2}px`,A===D.left){const s=this.wrapper.clientWidth-n.width;this.frame.style.left=`${s}px`}else if(A===D.center){const s=this.wrapper.clientWidth-n.width;this.frame.style.left=`${s/2}px`}else this.frame.style.left="0px";this.frame.style.removeProperty("visibility"),this.frame.style.removeProperty("aria-hidden"),this.frame.style.removeProperty("pointer-events"),this.frame.classList.remove("blank"),this.frame.classList.add("loaded")}async destroy(){var A;await this.unfocus(),(A=this.loader)==null||A.destroy(),this.wrapper.remove()}async unload(){var A,t;if(this.loaded)return this.deselect(),this.frame.style.visibility="hidden",this.frame.style.setProperty("aria-hidden","true"),this.frame.style.pointerEvents="none",this.frame.classList.add("blank"),this.frame.classList.remove("loaded"),(A=this.comms)==null||A.halt(),(t=this.loader)==null||t.destroy(),this.comms=void 0,this.frame.blur(),new Promise((e,n)=>{this.frame.addEventListener("load",()=>{try{this.showPromise=void 0,e()}catch{}},{once:!0}),this.frame.addEventListener("error",r=>{try{this.showPromise=void 0,n(r.error)}catch{}},{once:!0}),this.source="about:blank",this.frame.contentWindow.location.replace("about:blank"),this.frame.style.display="none"})}deselect(){var A,t;(t=(A=this.frame.contentWindow)==null?void 0:A.getSelection())==null||t.removeAllRanges()}async unfocus(){var A;if(this.frame.parentElement)return this.comms===void 0?void 0:new Promise((t,e)=>{var n;(n=this.comms)==null||n.send("unfocus",void 0,r=>{var s;(s=this.comms)==null||s.halt(),this.showPromise=void 0,t()})});(A=this.comms)==null||A.halt()}async show(A){if(!this.frame.parentElement){console.warn("Trying to show frame that is not attached to the DOM");return}if(!this.loaded){this.showPromise=void 0;return}return this.showPromise?(this.cachedPage!==A&&(this.update(A),this.cachedPage=A),this.showPromise):(this.cachedPage=A,this.comms?this.comms.resume():this.comms=new et(this.frame.contentWindow,this.source),this.showPromise=new Promise((t,e)=>{this.comms.send("focus",void 0,n=>{this.update(this.cachedPage),t()})}),this.showPromise)}async activate(){return new Promise((A,t)=>{var e;if(!this.comms)return A();(e=this.comms)==null||e.send("activate",void 0,()=>{A()})})}get element(){return this.wrapper}get iframe(){return this.frame}get realSize(){return this.frame.getBoundingClientRect()}get loaded(){return this.frame.contentWindow&&this.frame.contentWindow.location.href!=="about:blank"}set width(A){const t=`${A}%`;this.wrapper.style.width!==t&&(this.wrapper.style.width=t)}set height(A){const t=`${A}px`;this.wrapper.style.height!==t&&(this.wrapper.style.height=t)}get window(){if(!this.frame.contentWindow)throw Error("Trying to use frame window when it doesn't exist");return this.frame.contentWindow}get atLeft(){return this.window.scrollX<5}get atRight(){return this.window.scrollX>this.window.document.scrollingElement.scrollWidth-this.window.innerWidth-5}get msg(){return this.comms}get ldr(){return this.loader}}/*!
|
|
96
96
|
* (℠)
|
|
97
97
|
* # sML.js | I'm a Simple and Middling Library.
|
|
98
98
|
*
|
package/package.json
CHANGED
|
@@ -8,6 +8,7 @@ export class FrameManager {
|
|
|
8
8
|
private loader: Loader | undefined;
|
|
9
9
|
public readonly source: string;
|
|
10
10
|
private comms: FrameComms | undefined;
|
|
11
|
+
private destroyed: boolean = false;
|
|
11
12
|
|
|
12
13
|
private currModules: ModuleName[] = [];
|
|
13
14
|
|
|
@@ -57,15 +58,17 @@ export class FrameManager {
|
|
|
57
58
|
await this.hide();
|
|
58
59
|
this.loader?.destroy();
|
|
59
60
|
this.frame.remove();
|
|
61
|
+
this.destroyed = true;
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
async hide(): Promise<void> {
|
|
65
|
+
if(this.destroyed) return;
|
|
63
66
|
this.frame.style.visibility = "hidden";
|
|
64
67
|
this.frame.style.setProperty("aria-hidden", "true");
|
|
65
68
|
this.frame.style.opacity = "0";
|
|
66
69
|
this.frame.style.pointerEvents = "none";
|
|
67
70
|
if(this.frame.parentElement) {
|
|
68
|
-
if(this.comms === undefined) return;
|
|
71
|
+
if(this.comms === undefined || !this.comms.ready) return;
|
|
69
72
|
return new Promise((res, _) => {
|
|
70
73
|
this.comms?.send("unfocus", undefined, (_: boolean) => {
|
|
71
74
|
this.comms?.halt();
|
|
@@ -77,10 +80,8 @@ export class FrameManager {
|
|
|
77
80
|
}
|
|
78
81
|
|
|
79
82
|
async show(atProgress?: number): Promise<void> {
|
|
80
|
-
if(
|
|
81
|
-
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
83
|
+
if(this.destroyed) throw Error("Trying to show frame when it doesn't exist");
|
|
84
|
+
if(!this.frame.parentElement) throw Error("Trying to show frame that is not attached to the DOM");
|
|
84
85
|
if(this.comms) this.comms.resume();
|
|
85
86
|
else this.comms = new FrameComms(this.frame.contentWindow!, this.source);
|
|
86
87
|
return new Promise((res, _) => {
|
|
@@ -104,15 +105,17 @@ export class FrameManager {
|
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
get iframe() {
|
|
108
|
+
if(this.destroyed) throw Error("Trying to use frame when it doesn't exist");
|
|
107
109
|
return this.frame;
|
|
108
110
|
}
|
|
109
111
|
|
|
110
112
|
get realSize() {
|
|
113
|
+
if(this.destroyed) throw Error("Trying to use frame client rect when it doesn't exist");
|
|
111
114
|
return this.frame.getBoundingClientRect();
|
|
112
115
|
}
|
|
113
116
|
|
|
114
117
|
get window() {
|
|
115
|
-
if(!this.frame.contentWindow) throw Error("Trying to use frame window when it doesn't exist");
|
|
118
|
+
if(this.destroyed || !this.frame.contentWindow) throw Error("Trying to use frame window when it doesn't exist");
|
|
116
119
|
return this.frame.contentWindow;
|
|
117
120
|
}
|
|
118
121
|
|