@readium/navigator-html-injectables 1.2.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 +13 -0
- package/dist/index.js +3144 -0
- package/dist/index.umd.cjs +69 -0
- package/package.json +58 -0
- package/src/Loader.ts +85 -0
- package/src/comms/comms.ts +168 -0
- package/src/comms/index.ts +3 -0
- package/src/comms/keys.ts +42 -0
- package/src/comms/mid.ts +5 -0
- package/src/helpers/animation.ts +5 -0
- package/src/helpers/css.ts +16 -0
- package/src/helpers/document.ts +43 -0
- package/src/helpers/dom.ts +126 -0
- package/src/helpers/locator.ts +67 -0
- package/src/helpers/rect.ts +301 -0
- package/src/helpers/scrollSnapperHelper.ts +43 -0
- package/src/index.ts +3 -0
- package/src/modules/Decorator.ts +462 -0
- package/src/modules/Module.ts +23 -0
- package/src/modules/ModuleLibrary.ts +44 -0
- package/src/modules/Peripherals.ts +148 -0
- package/src/modules/index.ts +3 -0
- package/src/modules/setup/FixedSetup.ts +73 -0
- package/src/modules/setup/ReflowableSetup.ts +65 -0
- package/src/modules/setup/Setup.ts +131 -0
- package/src/modules/snapper/ColumnSnapper.ts +468 -0
- package/src/modules/snapper/ScrollSnapper.ts +168 -0
- package/src/modules/snapper/Snapper.ts +49 -0
- package/src/vendor/approx-string-match/LICENSE +21 -0
- package/src/vendor/approx-string-match/README.MD +1 -0
- package/src/vendor/approx-string-match/index.ts +362 -0
- package/src/vendor/hypothesis/README.MD +1 -0
- package/src/vendor/hypothesis/anchoring/api-types.ts +309 -0
- package/src/vendor/hypothesis/anchoring/html.ts +134 -0
- package/src/vendor/hypothesis/anchoring/match-quote.ts +163 -0
- package/src/vendor/hypothesis/anchoring/placeholder.ts +59 -0
- package/src/vendor/hypothesis/anchoring/text-range.ts +327 -0
- package/src/vendor/hypothesis/anchoring/trim-range.ts +220 -0
- package/src/vendor/hypothesis/anchoring/types.ts +377 -0
- package/src/vendor/hypothesis/anchoring/xpath.ts +164 -0
- package/src/vendor/hypothesis/tsconfig.json +33 -0
- package/src/vendor/hypothesis/types/shared.ts +40 -0
- package/types/src/Loader.d.ts +33 -0
- package/types/src/comms/comms.d.ts +40 -0
- package/types/src/comms/index.d.ts +3 -0
- package/types/src/comms/keys.d.ts +2 -0
- package/types/src/comms/mid.d.ts +1 -0
- package/types/src/helpers/animation.d.ts +1 -0
- package/types/src/helpers/css.d.ts +4 -0
- package/types/src/helpers/document.d.ts +8 -0
- package/types/src/helpers/dom.d.ts +15 -0
- package/types/src/helpers/locator.d.ts +2 -0
- package/types/src/helpers/rect.d.ts +10 -0
- package/types/src/helpers/scrollSnapperHelper.d.ts +5 -0
- package/types/src/index.d.ts +3 -0
- package/types/src/modules/Decorator.d.ts +43 -0
- package/types/src/modules/Module.d.ts +11 -0
- package/types/src/modules/ModuleLibrary.d.ts +5 -0
- package/types/src/modules/Peripherals.d.ts +39 -0
- package/types/src/modules/ReflowablePeripherals.d.ts +37 -0
- package/types/src/modules/index.d.ts +3 -0
- package/types/src/modules/setup/FixedSetup.d.ts +9 -0
- package/types/src/modules/setup/ReflowableSetup.d.ts +9 -0
- package/types/src/modules/setup/Setup.d.ts +17 -0
- package/types/src/modules/snapper/ColumnSnapper.d.ts +41 -0
- package/types/src/modules/snapper/ScrollSnapper.d.ts +16 -0
- package/types/src/modules/snapper/Snapper.d.ts +11 -0
- package/types/src/vendor/approx-string-match/index.d.ts +54 -0
- package/types/src/vendor/hypothesis/anchoring/api-types.d.ts +266 -0
- package/types/src/vendor/hypothesis/anchoring/html.d.ts +17 -0
- package/types/src/vendor/hypothesis/anchoring/match-quote.d.ts +30 -0
- package/types/src/vendor/hypothesis/anchoring/placeholder.d.ts +32 -0
- package/types/src/vendor/hypothesis/anchoring/text-range.d.ts +103 -0
- package/types/src/vendor/hypothesis/anchoring/trim-range.d.ts +17 -0
- package/types/src/vendor/hypothesis/anchoring/types.d.ts +102 -0
- package/types/src/vendor/hypothesis/anchoring/xpath.d.ts +15 -0
- package/types/src/vendor/hypothesis/types/shared.d.ts +32 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,3144 @@
|
|
|
1
|
+
const Mt = Math.pow(2, 32), Ae = () => Math.round(Math.random() * Mt).toString(36), Nt = () => `${Math.round(performance.now())}-${Ae()}-${Ae()}`, X = 1;
|
|
2
|
+
class Rt {
|
|
3
|
+
constructor(e) {
|
|
4
|
+
this.destination = null, this.registrar = /* @__PURE__ */ new Map(), this.origin = "", this.channelId = "", this.receiver = this.receive.bind(this), this.preLog = [], this.wnd = e, e.addEventListener("message", this.receiver);
|
|
5
|
+
}
|
|
6
|
+
receive(e) {
|
|
7
|
+
if (e.source === null)
|
|
8
|
+
throw Error("Event source is null");
|
|
9
|
+
if (typeof e.data != "object")
|
|
10
|
+
return;
|
|
11
|
+
const t = e.data;
|
|
12
|
+
if (!(!("_readium" in t) || !t._readium || t._readium <= 0)) {
|
|
13
|
+
if (t.key === "_ping") {
|
|
14
|
+
if (!this.destination) {
|
|
15
|
+
if (this.destination = e.source, this.origin = e.origin, this.channelId = t._channel, t._readium !== X) {
|
|
16
|
+
t._readium > X ? this.send("error", `received comms version ${t._readium} higher than ${X}`) : this.send("error", `received comms version ${t._readium} lower than ${X}`), this.destination = null, this.origin = "", this.channelId = "";
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
this.send("_pong", void 0), this.preLog.forEach((r) => this.send("log", r)), this.preLog = [];
|
|
20
|
+
}
|
|
21
|
+
return;
|
|
22
|
+
} else if (this.channelId) {
|
|
23
|
+
if (t._channel !== this.channelId || e.origin !== this.origin)
|
|
24
|
+
return;
|
|
25
|
+
} else
|
|
26
|
+
return;
|
|
27
|
+
this.handle(t);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
handle(e) {
|
|
31
|
+
const t = this.registrar.get(e.key);
|
|
32
|
+
if (!t || t.length === 0) {
|
|
33
|
+
e.strict && this.send("_unhandled", e);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
t.forEach((r) => r.cb(e.data, (s) => {
|
|
37
|
+
this.send("_ack", s, e.id);
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
register(e, t, r) {
|
|
41
|
+
Array.isArray(e) || (e = [e]), e.forEach((s) => {
|
|
42
|
+
const n = this.registrar.get(s);
|
|
43
|
+
if (n && n.length >= 0) {
|
|
44
|
+
if (n.find((a) => a.module === t))
|
|
45
|
+
throw new Error(`Trying to register another callback for combination of event ${s} and module ${t}`);
|
|
46
|
+
n.push({
|
|
47
|
+
cb: r,
|
|
48
|
+
module: t
|
|
49
|
+
}), this.registrar.set(s, n);
|
|
50
|
+
} else
|
|
51
|
+
this.registrar.set(s, [{
|
|
52
|
+
cb: r,
|
|
53
|
+
module: t
|
|
54
|
+
}]);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
unregister(e, t) {
|
|
58
|
+
Array.isArray(e) || (e = [e]), e.forEach((r) => {
|
|
59
|
+
const s = this.registrar.get(r);
|
|
60
|
+
!s || s.length === 0 || s.splice(s.findIndex((n) => n.module === t), 1);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
unregisterAll(e) {
|
|
64
|
+
this.registrar.forEach((t, r) => this.registrar.set(r, t.filter((s) => s.module !== e)));
|
|
65
|
+
}
|
|
66
|
+
log(...e) {
|
|
67
|
+
this.destination ? this.send("log", e) : this.preLog.push(e);
|
|
68
|
+
}
|
|
69
|
+
get ready() {
|
|
70
|
+
return !!this.destination;
|
|
71
|
+
}
|
|
72
|
+
destroy() {
|
|
73
|
+
this.destination = null, this.channelId = "", this.preLog = [], this.registrar.clear(), this.wnd.removeEventListener("message", this.receiver);
|
|
74
|
+
}
|
|
75
|
+
send(e, t, r = void 0, s = []) {
|
|
76
|
+
if (!this.destination)
|
|
77
|
+
throw Error("Attempted to send comms message before destination has been initialized");
|
|
78
|
+
const n = {
|
|
79
|
+
_readium: X,
|
|
80
|
+
_channel: this.channelId,
|
|
81
|
+
id: r ?? Nt(),
|
|
82
|
+
// scrict,
|
|
83
|
+
key: e,
|
|
84
|
+
data: t
|
|
85
|
+
};
|
|
86
|
+
try {
|
|
87
|
+
this.destination.postMessage(n, {
|
|
88
|
+
targetOrigin: this.origin,
|
|
89
|
+
transfer: s
|
|
90
|
+
});
|
|
91
|
+
} catch (o) {
|
|
92
|
+
if (s.length > 0)
|
|
93
|
+
throw o;
|
|
94
|
+
this.destination.postMessage(n, this.origin, s);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
class ce {
|
|
99
|
+
}
|
|
100
|
+
var F = [], Lt = function() {
|
|
101
|
+
return F.some(function(i) {
|
|
102
|
+
return i.activeTargets.length > 0;
|
|
103
|
+
});
|
|
104
|
+
}, zt = function() {
|
|
105
|
+
return F.some(function(i) {
|
|
106
|
+
return i.skippedTargets.length > 0;
|
|
107
|
+
});
|
|
108
|
+
}, Me = "ResizeObserver loop completed with undelivered notifications.", It = function() {
|
|
109
|
+
var i;
|
|
110
|
+
typeof ErrorEvent == "function" ? i = new ErrorEvent("error", {
|
|
111
|
+
message: Me
|
|
112
|
+
}) : (i = document.createEvent("Event"), i.initEvent("error", !1, !1), i.message = Me), window.dispatchEvent(i);
|
|
113
|
+
}, G;
|
|
114
|
+
(function(i) {
|
|
115
|
+
i.BORDER_BOX = "border-box", i.CONTENT_BOX = "content-box", i.DEVICE_PIXEL_CONTENT_BOX = "device-pixel-content-box";
|
|
116
|
+
})(G || (G = {}));
|
|
117
|
+
var k = function(i) {
|
|
118
|
+
return Object.freeze(i);
|
|
119
|
+
}, Bt = function() {
|
|
120
|
+
function i(e, t) {
|
|
121
|
+
this.inlineSize = e, this.blockSize = t, k(this);
|
|
122
|
+
}
|
|
123
|
+
return i;
|
|
124
|
+
}(), Qe = function() {
|
|
125
|
+
function i(e, t, r, s) {
|
|
126
|
+
return this.x = e, this.y = t, this.width = r, this.height = s, this.top = this.y, this.left = this.x, this.bottom = this.top + this.height, this.right = this.left + this.width, k(this);
|
|
127
|
+
}
|
|
128
|
+
return i.prototype.toJSON = function() {
|
|
129
|
+
var e = this, t = e.x, r = e.y, s = e.top, n = e.right, o = e.bottom, a = e.left, h = e.width, c = e.height;
|
|
130
|
+
return { x: t, y: r, top: s, right: n, bottom: o, left: a, width: h, height: c };
|
|
131
|
+
}, i.fromRect = function(e) {
|
|
132
|
+
return new i(e.x, e.y, e.width, e.height);
|
|
133
|
+
}, i;
|
|
134
|
+
}(), Ee = function(i) {
|
|
135
|
+
return i instanceof SVGElement && "getBBox" in i;
|
|
136
|
+
}, et = function(i) {
|
|
137
|
+
if (Ee(i)) {
|
|
138
|
+
var e = i.getBBox(), t = e.width, r = e.height;
|
|
139
|
+
return !t && !r;
|
|
140
|
+
}
|
|
141
|
+
var s = i, n = s.offsetWidth, o = s.offsetHeight;
|
|
142
|
+
return !(n || o || i.getClientRects().length);
|
|
143
|
+
}, Ne = function(i) {
|
|
144
|
+
var e;
|
|
145
|
+
if (i instanceof Element)
|
|
146
|
+
return !0;
|
|
147
|
+
var t = (e = i == null ? void 0 : i.ownerDocument) === null || e === void 0 ? void 0 : e.defaultView;
|
|
148
|
+
return !!(t && i instanceof t.Element);
|
|
149
|
+
}, Dt = function(i) {
|
|
150
|
+
switch (i.tagName) {
|
|
151
|
+
case "INPUT":
|
|
152
|
+
if (i.type !== "image")
|
|
153
|
+
break;
|
|
154
|
+
case "VIDEO":
|
|
155
|
+
case "AUDIO":
|
|
156
|
+
case "EMBED":
|
|
157
|
+
case "OBJECT":
|
|
158
|
+
case "CANVAS":
|
|
159
|
+
case "IFRAME":
|
|
160
|
+
case "IMG":
|
|
161
|
+
return !0;
|
|
162
|
+
}
|
|
163
|
+
return !1;
|
|
164
|
+
}, _ = typeof window < "u" ? window : {}, Q = /* @__PURE__ */ new WeakMap(), Re = /auto|scroll/, Wt = /^tb|vertical/, Ft = /msie|trident/i.test(_.navigator && _.navigator.userAgent), N = function(i) {
|
|
165
|
+
return parseFloat(i || "0");
|
|
166
|
+
}, $ = function(i, e, t) {
|
|
167
|
+
return i === void 0 && (i = 0), e === void 0 && (e = 0), t === void 0 && (t = !1), new Bt((t ? e : i) || 0, (t ? i : e) || 0);
|
|
168
|
+
}, Le = k({
|
|
169
|
+
devicePixelContentBoxSize: $(),
|
|
170
|
+
borderBoxSize: $(),
|
|
171
|
+
contentBoxSize: $(),
|
|
172
|
+
contentRect: new Qe(0, 0, 0, 0)
|
|
173
|
+
}), tt = function(i, e) {
|
|
174
|
+
if (e === void 0 && (e = !1), Q.has(i) && !e)
|
|
175
|
+
return Q.get(i);
|
|
176
|
+
if (et(i))
|
|
177
|
+
return Q.set(i, Le), Le;
|
|
178
|
+
var t = getComputedStyle(i), r = Ee(i) && i.ownerSVGElement && i.getBBox(), s = !Ft && t.boxSizing === "border-box", n = Wt.test(t.writingMode || ""), o = !r && Re.test(t.overflowY || ""), a = !r && Re.test(t.overflowX || ""), h = r ? 0 : N(t.paddingTop), c = r ? 0 : N(t.paddingRight), d = r ? 0 : N(t.paddingBottom), p = r ? 0 : N(t.paddingLeft), u = r ? 0 : N(t.borderTopWidth), f = r ? 0 : N(t.borderRightWidth), v = r ? 0 : N(t.borderBottomWidth), g = r ? 0 : N(t.borderLeftWidth), y = p + c, x = h + d, S = g + f, m = u + v, E = a ? i.offsetHeight - m - i.clientHeight : 0, O = o ? i.offsetWidth - S - i.clientWidth : 0, Y = s ? y + S : 0, Z = s ? x + m : 0, B = r ? r.width : N(t.width) - Y - O, D = r ? r.height : N(t.height) - Z - E, K = B + y + O + S, J = D + x + E + m, U = k({
|
|
179
|
+
devicePixelContentBoxSize: $(Math.round(B * devicePixelRatio), Math.round(D * devicePixelRatio), n),
|
|
180
|
+
borderBoxSize: $(K, J, n),
|
|
181
|
+
contentBoxSize: $(B, D, n),
|
|
182
|
+
contentRect: new Qe(p, h, B, D)
|
|
183
|
+
});
|
|
184
|
+
return Q.set(i, U), U;
|
|
185
|
+
}, it = function(i, e, t) {
|
|
186
|
+
var r = tt(i, t), s = r.borderBoxSize, n = r.contentBoxSize, o = r.devicePixelContentBoxSize;
|
|
187
|
+
switch (e) {
|
|
188
|
+
case G.DEVICE_PIXEL_CONTENT_BOX:
|
|
189
|
+
return o;
|
|
190
|
+
case G.BORDER_BOX:
|
|
191
|
+
return s;
|
|
192
|
+
default:
|
|
193
|
+
return n;
|
|
194
|
+
}
|
|
195
|
+
}, kt = function() {
|
|
196
|
+
function i(e) {
|
|
197
|
+
var t = tt(e);
|
|
198
|
+
this.target = e, this.contentRect = t.contentRect, this.borderBoxSize = k([t.borderBoxSize]), this.contentBoxSize = k([t.contentBoxSize]), this.devicePixelContentBoxSize = k([t.devicePixelContentBoxSize]);
|
|
199
|
+
}
|
|
200
|
+
return i;
|
|
201
|
+
}(), rt = function(i) {
|
|
202
|
+
if (et(i))
|
|
203
|
+
return 1 / 0;
|
|
204
|
+
for (var e = 0, t = i.parentNode; t; )
|
|
205
|
+
e += 1, t = t.parentNode;
|
|
206
|
+
return e;
|
|
207
|
+
}, Ut = function() {
|
|
208
|
+
var i = 1 / 0, e = [];
|
|
209
|
+
F.forEach(function(o) {
|
|
210
|
+
if (o.activeTargets.length !== 0) {
|
|
211
|
+
var a = [];
|
|
212
|
+
o.activeTargets.forEach(function(c) {
|
|
213
|
+
var d = new kt(c.target), p = rt(c.target);
|
|
214
|
+
a.push(d), c.lastReportedSize = it(c.target, c.observedBox), p < i && (i = p);
|
|
215
|
+
}), e.push(function() {
|
|
216
|
+
o.callback.call(o.observer, a, o.observer);
|
|
217
|
+
}), o.activeTargets.splice(0, o.activeTargets.length);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
for (var t = 0, r = e; t < r.length; t++) {
|
|
221
|
+
var s = r[t];
|
|
222
|
+
s();
|
|
223
|
+
}
|
|
224
|
+
return i;
|
|
225
|
+
}, ze = function(i) {
|
|
226
|
+
F.forEach(function(t) {
|
|
227
|
+
t.activeTargets.splice(0, t.activeTargets.length), t.skippedTargets.splice(0, t.skippedTargets.length), t.observationTargets.forEach(function(s) {
|
|
228
|
+
s.isActive() && (rt(s.target) > i ? t.activeTargets.push(s) : t.skippedTargets.push(s));
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
}, $t = function() {
|
|
232
|
+
var i = 0;
|
|
233
|
+
for (ze(i); Lt(); )
|
|
234
|
+
i = Ut(), ze(i);
|
|
235
|
+
return zt() && It(), i > 0;
|
|
236
|
+
}, de, st = [], Ht = function() {
|
|
237
|
+
return st.splice(0).forEach(function(i) {
|
|
238
|
+
return i();
|
|
239
|
+
});
|
|
240
|
+
}, qt = function(i) {
|
|
241
|
+
if (!de) {
|
|
242
|
+
var e = 0, t = document.createTextNode(""), r = { characterData: !0 };
|
|
243
|
+
new MutationObserver(function() {
|
|
244
|
+
return Ht();
|
|
245
|
+
}).observe(t, r), de = function() {
|
|
246
|
+
t.textContent = "".concat(e ? e-- : e++);
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
st.push(i), de();
|
|
250
|
+
}, Xt = function(i) {
|
|
251
|
+
qt(function() {
|
|
252
|
+
requestAnimationFrame(i);
|
|
253
|
+
});
|
|
254
|
+
}, re = 0, Vt = function() {
|
|
255
|
+
return !!re;
|
|
256
|
+
}, _t = 250, jt = { attributes: !0, characterData: !0, childList: !0, subtree: !0 }, Ie = [
|
|
257
|
+
"resize",
|
|
258
|
+
"load",
|
|
259
|
+
"transitionend",
|
|
260
|
+
"animationend",
|
|
261
|
+
"animationstart",
|
|
262
|
+
"animationiteration",
|
|
263
|
+
"keyup",
|
|
264
|
+
"keydown",
|
|
265
|
+
"mouseup",
|
|
266
|
+
"mousedown",
|
|
267
|
+
"mouseover",
|
|
268
|
+
"mouseout",
|
|
269
|
+
"blur",
|
|
270
|
+
"focus"
|
|
271
|
+
], Be = function(i) {
|
|
272
|
+
return i === void 0 && (i = 0), Date.now() + i;
|
|
273
|
+
}, ue = !1, Gt = function() {
|
|
274
|
+
function i() {
|
|
275
|
+
var e = this;
|
|
276
|
+
this.stopped = !0, this.listener = function() {
|
|
277
|
+
return e.schedule();
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
return i.prototype.run = function(e) {
|
|
281
|
+
var t = this;
|
|
282
|
+
if (e === void 0 && (e = _t), !ue) {
|
|
283
|
+
ue = !0;
|
|
284
|
+
var r = Be(e);
|
|
285
|
+
Xt(function() {
|
|
286
|
+
var s = !1;
|
|
287
|
+
try {
|
|
288
|
+
s = $t();
|
|
289
|
+
} finally {
|
|
290
|
+
if (ue = !1, e = r - Be(), !Vt())
|
|
291
|
+
return;
|
|
292
|
+
s ? t.run(1e3) : e > 0 ? t.run(e) : t.start();
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
}, i.prototype.schedule = function() {
|
|
297
|
+
this.stop(), this.run();
|
|
298
|
+
}, i.prototype.observe = function() {
|
|
299
|
+
var e = this, t = function() {
|
|
300
|
+
return e.observer && e.observer.observe(document.body, jt);
|
|
301
|
+
};
|
|
302
|
+
document.body ? t() : _.addEventListener("DOMContentLoaded", t);
|
|
303
|
+
}, i.prototype.start = function() {
|
|
304
|
+
var e = this;
|
|
305
|
+
this.stopped && (this.stopped = !1, this.observer = new MutationObserver(this.listener), this.observe(), Ie.forEach(function(t) {
|
|
306
|
+
return _.addEventListener(t, e.listener, !0);
|
|
307
|
+
}));
|
|
308
|
+
}, i.prototype.stop = function() {
|
|
309
|
+
var e = this;
|
|
310
|
+
this.stopped || (this.observer && this.observer.disconnect(), Ie.forEach(function(t) {
|
|
311
|
+
return _.removeEventListener(t, e.listener, !0);
|
|
312
|
+
}), this.stopped = !0);
|
|
313
|
+
}, i;
|
|
314
|
+
}(), fe = new Gt(), De = function(i) {
|
|
315
|
+
!re && i > 0 && fe.start(), re += i, !re && fe.stop();
|
|
316
|
+
}, Yt = function(i) {
|
|
317
|
+
return !Ee(i) && !Dt(i) && getComputedStyle(i).display === "inline";
|
|
318
|
+
}, Zt = function() {
|
|
319
|
+
function i(e, t) {
|
|
320
|
+
this.target = e, this.observedBox = t || G.CONTENT_BOX, this.lastReportedSize = {
|
|
321
|
+
inlineSize: 0,
|
|
322
|
+
blockSize: 0
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
return i.prototype.isActive = function() {
|
|
326
|
+
var e = it(this.target, this.observedBox, !0);
|
|
327
|
+
return Yt(this.target) && (this.lastReportedSize = e), this.lastReportedSize.inlineSize !== e.inlineSize || this.lastReportedSize.blockSize !== e.blockSize;
|
|
328
|
+
}, i;
|
|
329
|
+
}(), Kt = function() {
|
|
330
|
+
function i(e, t) {
|
|
331
|
+
this.activeTargets = [], this.skippedTargets = [], this.observationTargets = [], this.observer = e, this.callback = t;
|
|
332
|
+
}
|
|
333
|
+
return i;
|
|
334
|
+
}(), ee = /* @__PURE__ */ new WeakMap(), We = function(i, e) {
|
|
335
|
+
for (var t = 0; t < i.length; t += 1)
|
|
336
|
+
if (i[t].target === e)
|
|
337
|
+
return t;
|
|
338
|
+
return -1;
|
|
339
|
+
}, te = function() {
|
|
340
|
+
function i() {
|
|
341
|
+
}
|
|
342
|
+
return i.connect = function(e, t) {
|
|
343
|
+
var r = new Kt(e, t);
|
|
344
|
+
ee.set(e, r);
|
|
345
|
+
}, i.observe = function(e, t, r) {
|
|
346
|
+
var s = ee.get(e), n = s.observationTargets.length === 0;
|
|
347
|
+
We(s.observationTargets, t) < 0 && (n && F.push(s), s.observationTargets.push(new Zt(t, r && r.box)), De(1), fe.schedule());
|
|
348
|
+
}, i.unobserve = function(e, t) {
|
|
349
|
+
var r = ee.get(e), s = We(r.observationTargets, t), n = r.observationTargets.length === 1;
|
|
350
|
+
s >= 0 && (n && F.splice(F.indexOf(r), 1), r.observationTargets.splice(s, 1), De(-1));
|
|
351
|
+
}, i.disconnect = function(e) {
|
|
352
|
+
var t = this, r = ee.get(e);
|
|
353
|
+
r.observationTargets.slice().forEach(function(s) {
|
|
354
|
+
return t.unobserve(e, s.target);
|
|
355
|
+
}), r.activeTargets.splice(0, r.activeTargets.length);
|
|
356
|
+
}, i;
|
|
357
|
+
}(), nt = function() {
|
|
358
|
+
function i(e) {
|
|
359
|
+
if (arguments.length === 0)
|
|
360
|
+
throw new TypeError("Failed to construct 'ResizeObserver': 1 argument required, but only 0 present.");
|
|
361
|
+
if (typeof e != "function")
|
|
362
|
+
throw new TypeError("Failed to construct 'ResizeObserver': The callback provided as parameter 1 is not a function.");
|
|
363
|
+
te.connect(this, e);
|
|
364
|
+
}
|
|
365
|
+
return i.prototype.observe = function(e, t) {
|
|
366
|
+
if (arguments.length === 0)
|
|
367
|
+
throw new TypeError("Failed to execute 'observe' on 'ResizeObserver': 1 argument required, but only 0 present.");
|
|
368
|
+
if (!Ne(e))
|
|
369
|
+
throw new TypeError("Failed to execute 'observe' on 'ResizeObserver': parameter 1 is not of type 'Element");
|
|
370
|
+
te.observe(this, e, t);
|
|
371
|
+
}, i.prototype.unobserve = function(e) {
|
|
372
|
+
if (arguments.length === 0)
|
|
373
|
+
throw new TypeError("Failed to execute 'unobserve' on 'ResizeObserver': 1 argument required, but only 0 present.");
|
|
374
|
+
if (!Ne(e))
|
|
375
|
+
throw new TypeError("Failed to execute 'unobserve' on 'ResizeObserver': parameter 1 is not of type 'Element");
|
|
376
|
+
te.unobserve(this, e);
|
|
377
|
+
}, i.prototype.disconnect = function() {
|
|
378
|
+
te.disconnect(this);
|
|
379
|
+
}, i.toString = function() {
|
|
380
|
+
return "function ResizeObserver () { [polyfill code] }";
|
|
381
|
+
}, i;
|
|
382
|
+
}();
|
|
383
|
+
const Fe = "readium-snapper-style", ot = class me extends ce {
|
|
384
|
+
constructor() {
|
|
385
|
+
super(...arguments), this.protected = !1;
|
|
386
|
+
}
|
|
387
|
+
buildStyles() {
|
|
388
|
+
return `
|
|
389
|
+
html, body {
|
|
390
|
+
touch-action: manipulation;
|
|
391
|
+
user-select: ${this.protected ? "none" : "auto"};
|
|
392
|
+
}`;
|
|
393
|
+
}
|
|
394
|
+
mount(e, t) {
|
|
395
|
+
const r = e.document.createElement("style");
|
|
396
|
+
return r.dataset.readium = "true", r.id = Fe, r.textContent = this.buildStyles(), e.document.head.appendChild(r), t.register("protect", me.moduleName, (s, n) => {
|
|
397
|
+
this.protected = !0, r.textContent = this.buildStyles(), n(!0);
|
|
398
|
+
}), t.register("unprotect", me.moduleName, (s, n) => {
|
|
399
|
+
this.protected = !1, r.textContent = this.buildStyles(), n(!0);
|
|
400
|
+
}), t.log("Snapper Mounted"), !0;
|
|
401
|
+
}
|
|
402
|
+
unmount(e, t) {
|
|
403
|
+
var r;
|
|
404
|
+
return (r = e.document.getElementById(Fe)) == null || r.remove(), t.log("Snapper Unmounted"), !0;
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
ot.moduleName = "snapper";
|
|
408
|
+
let at = ot;
|
|
409
|
+
function W(i) {
|
|
410
|
+
return i.document.body.dir.toLowerCase() === "rtl";
|
|
411
|
+
}
|
|
412
|
+
function lt(i) {
|
|
413
|
+
return parseInt(
|
|
414
|
+
i.getComputedStyle(
|
|
415
|
+
i.document.documentElement
|
|
416
|
+
).getPropertyValue("column-count")
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
function Jt(i) {
|
|
420
|
+
const e = "readium-virtual-page";
|
|
421
|
+
let t = i.document.getElementById(e);
|
|
422
|
+
if (lt(i) !== 2)
|
|
423
|
+
t && t.remove();
|
|
424
|
+
else {
|
|
425
|
+
const s = i.document.scrollingElement.scrollWidth / i.innerWidth;
|
|
426
|
+
Math.round(s * 2) / 2 % 1 > 0.1 && (t ? t.remove() : (t = i.document.createElement("div"), t.setAttribute("id", e), t.dataset.readium = "true", t.style.breakBefore = "column", t.innerHTML = "​", i.document.body.appendChild(t)));
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
function Qt(i) {
|
|
430
|
+
return i < 0.5 ? 2 * i * i : -1 + (4 - 2 * i) * i;
|
|
431
|
+
}
|
|
432
|
+
class xe {
|
|
433
|
+
/**
|
|
434
|
+
* Creates a [Encryption].
|
|
435
|
+
*/
|
|
436
|
+
constructor(e) {
|
|
437
|
+
this.algorithm = e.algorithm, this.compression = e.compression, this.originalLength = e.originalLength, this.profile = e.profile, this.scheme = e.scheme;
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Parses a [Encryption] from its RWPM JSON representation.
|
|
441
|
+
*/
|
|
442
|
+
static deserialize(e) {
|
|
443
|
+
if (e && e.algorithm)
|
|
444
|
+
return new xe({
|
|
445
|
+
algorithm: e.algorithm,
|
|
446
|
+
compression: e.compression,
|
|
447
|
+
originalLength: e.originalLength,
|
|
448
|
+
profile: e.profile,
|
|
449
|
+
scheme: e.scheme
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Serializes a [Encryption] to its RWPM JSON representation.
|
|
454
|
+
*/
|
|
455
|
+
serialize() {
|
|
456
|
+
const e = { algorithm: this.algorithm };
|
|
457
|
+
return this.compression !== void 0 && (e.compression = this.compression), this.originalLength !== void 0 && (e.originalLength = this.originalLength), this.profile !== void 0 && (e.profile = this.profile), this.scheme !== void 0 && (e.scheme = this.scheme), e;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
class b {
|
|
461
|
+
constructor(e) {
|
|
462
|
+
this.otherProperties = e;
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Creates a [Properties] from its RWPM JSON representation.
|
|
466
|
+
*/
|
|
467
|
+
static deserialize(e) {
|
|
468
|
+
if (e)
|
|
469
|
+
return new b(e);
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Serializes a [Properties] to its RWPM JSON representation.
|
|
473
|
+
*/
|
|
474
|
+
serialize() {
|
|
475
|
+
return this.otherProperties;
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Makes a copy of this [Properties] after merging in the given additional other [properties].
|
|
479
|
+
*/
|
|
480
|
+
add(e) {
|
|
481
|
+
const t = Object.assign({}, this.otherProperties);
|
|
482
|
+
for (const r in e)
|
|
483
|
+
t[r] = e[r];
|
|
484
|
+
return new b(t);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
Object.defineProperty(b.prototype, "encryption", {
|
|
488
|
+
get: function() {
|
|
489
|
+
return xe.deserialize(this.otherProperties.encrypted);
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
b.prototype.getContains = function() {
|
|
493
|
+
return new Set(this.otherProperties.contains || []);
|
|
494
|
+
};
|
|
495
|
+
b.prototype.getLayout = function() {
|
|
496
|
+
return this.otherProperties.layout;
|
|
497
|
+
};
|
|
498
|
+
class l {
|
|
499
|
+
/** Creates a MediaType object. */
|
|
500
|
+
constructor(e) {
|
|
501
|
+
let t, r, s = e.mediaType.replace(/\s/g, "").split(";");
|
|
502
|
+
const n = s[0].split("/");
|
|
503
|
+
if (n.length === 2) {
|
|
504
|
+
if (t = n[0].toLowerCase().trim(), r = n[1].toLowerCase().trim(), t.length === 0 || r.length === 0)
|
|
505
|
+
throw new Error("Invalid media type");
|
|
506
|
+
} else
|
|
507
|
+
throw new Error("Invalid media type");
|
|
508
|
+
const o = {};
|
|
509
|
+
for (let u = 1; u < s.length; u++) {
|
|
510
|
+
const f = s[u].split("=");
|
|
511
|
+
if (f.length === 2) {
|
|
512
|
+
const v = f[0].toLocaleLowerCase(), g = v === "charset" ? f[1].toUpperCase() : f[1];
|
|
513
|
+
o[v] = g;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
const a = {}, h = Object.keys(o);
|
|
517
|
+
h.sort((u, f) => u.localeCompare(f)), h.forEach((u) => a[u] = o[u]);
|
|
518
|
+
let c = "";
|
|
519
|
+
for (const u in a) {
|
|
520
|
+
const f = a[u];
|
|
521
|
+
c += `;${u}=${f}`;
|
|
522
|
+
}
|
|
523
|
+
const d = `${t}/${r}${c}`, p = a.encoding;
|
|
524
|
+
this.string = d, this.type = t, this.subtype = r, this.parameters = a, this.encoding = p, this.name = e.name, this.fileExtension = e.fileExtension;
|
|
525
|
+
}
|
|
526
|
+
static parse(e) {
|
|
527
|
+
return new l(e);
|
|
528
|
+
}
|
|
529
|
+
/** Structured syntax suffix, e.g. `+zip` in `application/epub+zip`.
|
|
530
|
+
* Gives a hint on the underlying structure of this media type.
|
|
531
|
+
* See. https://tools.ietf.org/html/rfc6838#section-4.2.8
|
|
532
|
+
*/
|
|
533
|
+
get structuredSyntaxSuffix() {
|
|
534
|
+
const e = this.subtype.split("+");
|
|
535
|
+
return e.length > 1 ? `+${e[e.length - 1]}` : void 0;
|
|
536
|
+
}
|
|
537
|
+
/** Parameter values might or might not be case-sensitive, depending on the semantics of
|
|
538
|
+
* the parameter name.
|
|
539
|
+
* https://tools.ietf.org/html/rfc2616#section-3.7
|
|
540
|
+
*
|
|
541
|
+
* The character set names may be up to 40 characters taken from the printable characters
|
|
542
|
+
* of US-ASCII. However, no distinction is made between use of upper and lower case
|
|
543
|
+
* letters.
|
|
544
|
+
* https://www.iana.org/assignments/character-sets/character-sets.xhtml
|
|
545
|
+
*/
|
|
546
|
+
get charset() {
|
|
547
|
+
return this.parameters.charset;
|
|
548
|
+
}
|
|
549
|
+
/** Returns whether the given `other` media type is included in this media type.
|
|
550
|
+
* For example, `text/html` contains `text/html;charset=utf-8`.
|
|
551
|
+
* - `other` must match the parameters in the `parameters` property, but extra parameters
|
|
552
|
+
* are ignored.
|
|
553
|
+
* - Order of parameters is ignored.
|
|
554
|
+
* - Wildcards are supported, meaning that `image/*` contains `image/png`
|
|
555
|
+
*/
|
|
556
|
+
contains(e) {
|
|
557
|
+
const t = typeof e == "string" ? l.parse({ mediaType: e }) : e;
|
|
558
|
+
if (!((this.type === "*" || this.type === t.type) && (this.subtype === "*" || this.subtype === t.subtype)))
|
|
559
|
+
return !1;
|
|
560
|
+
const r = new Set(
|
|
561
|
+
Object.entries(this.parameters).map(([n, o]) => `${n}=${o}`)
|
|
562
|
+
), s = new Set(
|
|
563
|
+
Object.entries(t.parameters).map(([n, o]) => `${n}=${o}`)
|
|
564
|
+
);
|
|
565
|
+
for (const n of Array.from(r.values()))
|
|
566
|
+
if (!s.has(n))
|
|
567
|
+
return !1;
|
|
568
|
+
return !0;
|
|
569
|
+
}
|
|
570
|
+
/** Returns whether this media type and `other` are the same, ignoring parameters that
|
|
571
|
+
* are not in both media types.
|
|
572
|
+
* For example, `text/html` matches `text/html;charset=utf-8`, but `text/html;charset=ascii`
|
|
573
|
+
* doesn't. This is basically like `contains`, but working in both direction.
|
|
574
|
+
*/
|
|
575
|
+
matches(e) {
|
|
576
|
+
const t = typeof e == "string" ? l.parse({ mediaType: e }) : e;
|
|
577
|
+
return this.contains(t) || t.contains(this);
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Returns whether this media type matches any of the [others] media types.
|
|
581
|
+
*/
|
|
582
|
+
matchesAny(...e) {
|
|
583
|
+
for (const t of e)
|
|
584
|
+
if (this.matches(t))
|
|
585
|
+
return !0;
|
|
586
|
+
return !1;
|
|
587
|
+
}
|
|
588
|
+
/** Checks the MediaType equals another one (comparing their string) */
|
|
589
|
+
equals(e) {
|
|
590
|
+
return this.string === e.string;
|
|
591
|
+
}
|
|
592
|
+
/** Returns whether this media type is structured as a ZIP archive. */
|
|
593
|
+
get isZIP() {
|
|
594
|
+
return this.matchesAny(
|
|
595
|
+
l.ZIP,
|
|
596
|
+
l.LCP_PROTECTED_AUDIOBOOK,
|
|
597
|
+
l.LCP_PROTECTED_PDF
|
|
598
|
+
) || this.structuredSyntaxSuffix === "+zip";
|
|
599
|
+
}
|
|
600
|
+
/** Returns whether this media type is structured as a JSON file. */
|
|
601
|
+
get isJSON() {
|
|
602
|
+
return this.matchesAny(l.JSON) || this.structuredSyntaxSuffix === "+json";
|
|
603
|
+
}
|
|
604
|
+
/** Returns whether this media type is of an OPDS feed. */
|
|
605
|
+
get isOPDS() {
|
|
606
|
+
return this.matchesAny(
|
|
607
|
+
l.OPDS1,
|
|
608
|
+
l.OPDS1_ENTRY,
|
|
609
|
+
l.OPDS2,
|
|
610
|
+
l.OPDS2_PUBLICATION,
|
|
611
|
+
l.OPDS_AUTHENTICATION
|
|
612
|
+
) || this.structuredSyntaxSuffix === "+json";
|
|
613
|
+
}
|
|
614
|
+
/** Returns whether this media type is of an HTML document. */
|
|
615
|
+
get isHTML() {
|
|
616
|
+
return this.matchesAny(l.HTML, l.XHTML);
|
|
617
|
+
}
|
|
618
|
+
/** Returns whether this media type is of a bitmap image, so excluding vectorial formats. */
|
|
619
|
+
get isBitmap() {
|
|
620
|
+
return this.matchesAny(
|
|
621
|
+
l.BMP,
|
|
622
|
+
l.GIF,
|
|
623
|
+
l.JPEG,
|
|
624
|
+
l.PNG,
|
|
625
|
+
l.TIFF,
|
|
626
|
+
l.WEBP
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
/** Returns whether this media type is of an audio clip. */
|
|
630
|
+
get isAudio() {
|
|
631
|
+
return this.type === "audio";
|
|
632
|
+
}
|
|
633
|
+
/** Returns whether this media type is of a video clip. */
|
|
634
|
+
get isVideo() {
|
|
635
|
+
return this.type === "video";
|
|
636
|
+
}
|
|
637
|
+
/** Returns whether this media type is of a Readium Web Publication Manifest. */
|
|
638
|
+
get isRWPM() {
|
|
639
|
+
return this.matchesAny(
|
|
640
|
+
l.READIUM_AUDIOBOOK_MANIFEST,
|
|
641
|
+
l.DIVINA_MANIFEST,
|
|
642
|
+
l.READIUM_WEBPUB_MANIFEST
|
|
643
|
+
);
|
|
644
|
+
}
|
|
645
|
+
/** Returns whether this media type is of a publication file. */
|
|
646
|
+
get isPublication() {
|
|
647
|
+
return this.matchesAny(
|
|
648
|
+
l.READIUM_AUDIOBOOK,
|
|
649
|
+
l.READIUM_AUDIOBOOK_MANIFEST,
|
|
650
|
+
l.CBZ,
|
|
651
|
+
l.DIVINA,
|
|
652
|
+
l.DIVINA_MANIFEST,
|
|
653
|
+
l.EPUB,
|
|
654
|
+
l.LCP_PROTECTED_AUDIOBOOK,
|
|
655
|
+
l.LCP_PROTECTED_PDF,
|
|
656
|
+
l.LPF,
|
|
657
|
+
l.PDF,
|
|
658
|
+
l.W3C_WPUB_MANIFEST,
|
|
659
|
+
l.READIUM_WEBPUB,
|
|
660
|
+
l.READIUM_WEBPUB_MANIFEST,
|
|
661
|
+
l.ZAB
|
|
662
|
+
);
|
|
663
|
+
}
|
|
664
|
+
// Known Media Types
|
|
665
|
+
static get AAC() {
|
|
666
|
+
return l.parse({ mediaType: "audio/aac", fileExtension: "aac" });
|
|
667
|
+
}
|
|
668
|
+
static get ACSM() {
|
|
669
|
+
return l.parse({
|
|
670
|
+
mediaType: "application/vnd.adobe.adept+xml",
|
|
671
|
+
name: "Adobe Content Server Message",
|
|
672
|
+
fileExtension: "acsm"
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
static get AIFF() {
|
|
676
|
+
return l.parse({ mediaType: "audio/aiff", fileExtension: "aiff" });
|
|
677
|
+
}
|
|
678
|
+
static get AVI() {
|
|
679
|
+
return l.parse({
|
|
680
|
+
mediaType: "video/x-msvideo",
|
|
681
|
+
fileExtension: "avi"
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
static get BINARY() {
|
|
685
|
+
return l.parse({ mediaType: "application/octet-stream" });
|
|
686
|
+
}
|
|
687
|
+
static get BMP() {
|
|
688
|
+
return l.parse({ mediaType: "image/bmp", fileExtension: "bmp" });
|
|
689
|
+
}
|
|
690
|
+
static get CBZ() {
|
|
691
|
+
return l.parse({
|
|
692
|
+
mediaType: "application/vnd.comicbook+zip",
|
|
693
|
+
name: "Comic Book Archive",
|
|
694
|
+
fileExtension: "cbz"
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
static get CSS() {
|
|
698
|
+
return l.parse({ mediaType: "text/css", fileExtension: "css" });
|
|
699
|
+
}
|
|
700
|
+
static get DIVINA() {
|
|
701
|
+
return l.parse({
|
|
702
|
+
mediaType: "application/divina+zip",
|
|
703
|
+
name: "Digital Visual Narratives",
|
|
704
|
+
fileExtension: "divina"
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
static get DIVINA_MANIFEST() {
|
|
708
|
+
return l.parse({
|
|
709
|
+
mediaType: "application/divina+json",
|
|
710
|
+
name: "Digital Visual Narratives",
|
|
711
|
+
fileExtension: "json"
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
static get EPUB() {
|
|
715
|
+
return l.parse({
|
|
716
|
+
mediaType: "application/epub+zip",
|
|
717
|
+
name: "EPUB",
|
|
718
|
+
fileExtension: "epub"
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
static get GIF() {
|
|
722
|
+
return l.parse({ mediaType: "image/gif", fileExtension: "gif" });
|
|
723
|
+
}
|
|
724
|
+
static get GZ() {
|
|
725
|
+
return l.parse({
|
|
726
|
+
mediaType: "application/gzip",
|
|
727
|
+
fileExtension: "gz"
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
static get HTML() {
|
|
731
|
+
return l.parse({ mediaType: "text/html", fileExtension: "html" });
|
|
732
|
+
}
|
|
733
|
+
static get JAVASCRIPT() {
|
|
734
|
+
return l.parse({
|
|
735
|
+
mediaType: "text/javascript",
|
|
736
|
+
fileExtension: "js"
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
static get JPEG() {
|
|
740
|
+
return l.parse({ mediaType: "image/jpeg", fileExtension: "jpeg" });
|
|
741
|
+
}
|
|
742
|
+
static get JSON() {
|
|
743
|
+
return l.parse({ mediaType: "application/json" });
|
|
744
|
+
}
|
|
745
|
+
static get LCP_LICENSE_DOCUMENT() {
|
|
746
|
+
return l.parse({
|
|
747
|
+
mediaType: "application/vnd.readium.lcp.license.v1.0+json",
|
|
748
|
+
name: "LCP License",
|
|
749
|
+
fileExtension: "lcpl"
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
static get LCP_PROTECTED_AUDIOBOOK() {
|
|
753
|
+
return l.parse({
|
|
754
|
+
mediaType: "application/audiobook+lcp",
|
|
755
|
+
name: "LCP Protected Audiobook",
|
|
756
|
+
fileExtension: "lcpa"
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
static get LCP_PROTECTED_PDF() {
|
|
760
|
+
return l.parse({
|
|
761
|
+
mediaType: "application/pdf+lcp",
|
|
762
|
+
name: "LCP Protected PDF",
|
|
763
|
+
fileExtension: "lcpdf"
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
static get LCP_STATUS_DOCUMENT() {
|
|
767
|
+
return l.parse({
|
|
768
|
+
mediaType: "application/vnd.readium.license.status.v1.0+json"
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
static get LPF() {
|
|
772
|
+
return l.parse({
|
|
773
|
+
mediaType: "application/lpf+zip",
|
|
774
|
+
fileExtension: "lpf"
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
static get MP3() {
|
|
778
|
+
return l.parse({ mediaType: "audio/mpeg", fileExtension: "mp3" });
|
|
779
|
+
}
|
|
780
|
+
static get MPEG() {
|
|
781
|
+
return l.parse({ mediaType: "video/mpeg", fileExtension: "mpeg" });
|
|
782
|
+
}
|
|
783
|
+
static get NCX() {
|
|
784
|
+
return l.parse({
|
|
785
|
+
mediaType: "application/x-dtbncx+xml",
|
|
786
|
+
fileExtension: "ncx"
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
static get OGG() {
|
|
790
|
+
return l.parse({ mediaType: "audio/ogg", fileExtension: "oga" });
|
|
791
|
+
}
|
|
792
|
+
static get OGV() {
|
|
793
|
+
return l.parse({ mediaType: "video/ogg", fileExtension: "ogv" });
|
|
794
|
+
}
|
|
795
|
+
static get OPDS1() {
|
|
796
|
+
return l.parse({
|
|
797
|
+
mediaType: "application/atom+xml;profile=opds-catalog"
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
static get OPDS1_ENTRY() {
|
|
801
|
+
return l.parse({
|
|
802
|
+
mediaType: "application/atom+xml;type=entry;profile=opds-catalog"
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
static get OPDS2() {
|
|
806
|
+
return l.parse({ mediaType: "application/opds+json" });
|
|
807
|
+
}
|
|
808
|
+
static get OPDS2_PUBLICATION() {
|
|
809
|
+
return l.parse({ mediaType: "application/opds-publication+json" });
|
|
810
|
+
}
|
|
811
|
+
static get OPDS_AUTHENTICATION() {
|
|
812
|
+
return l.parse({
|
|
813
|
+
mediaType: "application/opds-authentication+json"
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
static get OPUS() {
|
|
817
|
+
return l.parse({ mediaType: "audio/opus", fileExtension: "opus" });
|
|
818
|
+
}
|
|
819
|
+
static get OTF() {
|
|
820
|
+
return l.parse({ mediaType: "font/otf", fileExtension: "otf" });
|
|
821
|
+
}
|
|
822
|
+
static get PDF() {
|
|
823
|
+
return l.parse({
|
|
824
|
+
mediaType: "application/pdf",
|
|
825
|
+
name: "PDF",
|
|
826
|
+
fileExtension: "pdf"
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
static get PNG() {
|
|
830
|
+
return l.parse({ mediaType: "image/png", fileExtension: "png" });
|
|
831
|
+
}
|
|
832
|
+
static get READIUM_AUDIOBOOK() {
|
|
833
|
+
return l.parse({
|
|
834
|
+
mediaType: "application/audiobook+zip",
|
|
835
|
+
name: "Readium Audiobook",
|
|
836
|
+
fileExtension: "audiobook"
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
static get READIUM_AUDIOBOOK_MANIFEST() {
|
|
840
|
+
return l.parse({
|
|
841
|
+
mediaType: "application/audiobook+json",
|
|
842
|
+
name: "Readium Audiobook",
|
|
843
|
+
fileExtension: "json"
|
|
844
|
+
});
|
|
845
|
+
}
|
|
846
|
+
static get READIUM_WEBPUB() {
|
|
847
|
+
return l.parse({
|
|
848
|
+
mediaType: "application/webpub+zip",
|
|
849
|
+
name: "Readium Web Publication",
|
|
850
|
+
fileExtension: "webpub"
|
|
851
|
+
});
|
|
852
|
+
}
|
|
853
|
+
static get READIUM_WEBPUB_MANIFEST() {
|
|
854
|
+
return l.parse({
|
|
855
|
+
mediaType: "application/webpub+json",
|
|
856
|
+
name: "Readium Web Publication",
|
|
857
|
+
fileExtension: "json"
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
static get SMIL() {
|
|
861
|
+
return l.parse({
|
|
862
|
+
mediaType: "application/smil+xml",
|
|
863
|
+
fileExtension: "smil"
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
static get SVG() {
|
|
867
|
+
return l.parse({
|
|
868
|
+
mediaType: "image/svg+xml",
|
|
869
|
+
fileExtension: "svg"
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
static get TEXT() {
|
|
873
|
+
return l.parse({ mediaType: "text/plain", fileExtension: "txt" });
|
|
874
|
+
}
|
|
875
|
+
static get TIFF() {
|
|
876
|
+
return l.parse({ mediaType: "image/tiff", fileExtension: "tiff" });
|
|
877
|
+
}
|
|
878
|
+
static get TTF() {
|
|
879
|
+
return l.parse({ mediaType: "font/ttf", fileExtension: "ttf" });
|
|
880
|
+
}
|
|
881
|
+
static get W3C_WPUB_MANIFEST() {
|
|
882
|
+
return l.parse({
|
|
883
|
+
mediaType: "application/x.readium.w3c.wpub+json",
|
|
884
|
+
name: "Web Publication",
|
|
885
|
+
fileExtension: "json"
|
|
886
|
+
});
|
|
887
|
+
}
|
|
888
|
+
static get WAV() {
|
|
889
|
+
return l.parse({ mediaType: "audio/wav", fileExtension: "wav" });
|
|
890
|
+
}
|
|
891
|
+
static get WEBM_AUDIO() {
|
|
892
|
+
return l.parse({ mediaType: "audio/webm", fileExtension: "webm" });
|
|
893
|
+
}
|
|
894
|
+
static get WEBM_VIDEO() {
|
|
895
|
+
return l.parse({ mediaType: "video/webm", fileExtension: "webm" });
|
|
896
|
+
}
|
|
897
|
+
static get WEBP() {
|
|
898
|
+
return l.parse({ mediaType: "image/webp", fileExtension: "webp" });
|
|
899
|
+
}
|
|
900
|
+
static get WOFF() {
|
|
901
|
+
return l.parse({ mediaType: "font/woff", fileExtension: "woff" });
|
|
902
|
+
}
|
|
903
|
+
static get WOFF2() {
|
|
904
|
+
return l.parse({ mediaType: "font/woff2", fileExtension: "woff2" });
|
|
905
|
+
}
|
|
906
|
+
static get XHTML() {
|
|
907
|
+
return l.parse({
|
|
908
|
+
mediaType: "application/xhtml+xml",
|
|
909
|
+
fileExtension: "xhtml"
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
static get XML() {
|
|
913
|
+
return l.parse({
|
|
914
|
+
mediaType: "application/xml",
|
|
915
|
+
fileExtension: "xml"
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
static get ZAB() {
|
|
919
|
+
return l.parse({
|
|
920
|
+
mediaType: "application/x.readium.zab+zip",
|
|
921
|
+
name: "Zipped Audio Book",
|
|
922
|
+
fileExtension: "zab"
|
|
923
|
+
});
|
|
924
|
+
}
|
|
925
|
+
static get ZIP() {
|
|
926
|
+
return l.parse({
|
|
927
|
+
mediaType: "application/zip",
|
|
928
|
+
fileExtension: "zip"
|
|
929
|
+
});
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
class ke {
|
|
933
|
+
constructor(e) {
|
|
934
|
+
this.uri = e, this.parameters = this.getParameters(e);
|
|
935
|
+
}
|
|
936
|
+
/**
|
|
937
|
+
* List of URI template parameter keys, if the [Link] is templated.
|
|
938
|
+
*/
|
|
939
|
+
getParameters(e) {
|
|
940
|
+
const t = /\{\??([^}]+)\}/g, r = e.match(t);
|
|
941
|
+
return r ? new Set(
|
|
942
|
+
r.join(",").replace(t, "$1").split(",").map((s) => s.trim())
|
|
943
|
+
) : /* @__PURE__ */ new Set();
|
|
944
|
+
}
|
|
945
|
+
/** Expands the URI by replacing the template variables by the given parameters.
|
|
946
|
+
* Any extra parameter is appended as query parameters.
|
|
947
|
+
* See RFC 6570 on URI template: https://tools.ietf.org/html/rfc6570
|
|
948
|
+
*/
|
|
949
|
+
expand(e) {
|
|
950
|
+
const t = (s) => s.split(",").map((n) => {
|
|
951
|
+
const o = e[n];
|
|
952
|
+
return o ? encodeURIComponent(o) : "";
|
|
953
|
+
}).join(","), r = (s) => "?" + s.split(",").map((n) => {
|
|
954
|
+
const o = n.split("=")[0], a = e[o];
|
|
955
|
+
return a ? `${o}=${encodeURIComponent(a)}` : "";
|
|
956
|
+
}).join("&");
|
|
957
|
+
return this.uri.replace(/\{(\??)([^}]+)\}/g, (...s) => s[1] ? r(s[2]) : t(s[2]));
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
function ei(i) {
|
|
961
|
+
return i && i instanceof Array ? i : void 0;
|
|
962
|
+
}
|
|
963
|
+
function ht(i) {
|
|
964
|
+
return i && typeof i == "string" ? [i] : ei(i);
|
|
965
|
+
}
|
|
966
|
+
function Ue(i) {
|
|
967
|
+
return typeof i == "string" ? new Date(i) : void 0;
|
|
968
|
+
}
|
|
969
|
+
function se(i) {
|
|
970
|
+
return isNaN(i) ? void 0 : i;
|
|
971
|
+
}
|
|
972
|
+
function P(i) {
|
|
973
|
+
return se(i) !== void 0 && Math.sign(i) >= 0 ? i : void 0;
|
|
974
|
+
}
|
|
975
|
+
function ti(i) {
|
|
976
|
+
const e = new Array();
|
|
977
|
+
return i.forEach((t) => e.push(t)), e;
|
|
978
|
+
}
|
|
979
|
+
class w {
|
|
980
|
+
/**
|
|
981
|
+
* Creates a [Locations].
|
|
982
|
+
*/
|
|
983
|
+
constructor(e) {
|
|
984
|
+
this.fragments = e.fragments ? e.fragments : new Array(), this.progression = e.progression, this.totalProgression = e.totalProgression, this.position = e.position, this.otherLocations = e.otherLocations;
|
|
985
|
+
}
|
|
986
|
+
/**
|
|
987
|
+
* Parses a [Locations] from its RWPM JSON representation.
|
|
988
|
+
*/
|
|
989
|
+
static deserialize(e) {
|
|
990
|
+
if (!e)
|
|
991
|
+
return;
|
|
992
|
+
const t = se(e.progression), r = se(e.totalProgression), s = se(e.position), n = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set([
|
|
993
|
+
"fragment",
|
|
994
|
+
"fragments",
|
|
995
|
+
"progression",
|
|
996
|
+
"totalProgression",
|
|
997
|
+
"position"
|
|
998
|
+
]);
|
|
999
|
+
return Object.entries(e).forEach(([a, h]) => {
|
|
1000
|
+
o.has(a) || n.set(a, h);
|
|
1001
|
+
}), new w({
|
|
1002
|
+
fragments: ht(e.fragments || e.fragment),
|
|
1003
|
+
progression: t !== void 0 && t >= 0 && t <= 1 ? t : void 0,
|
|
1004
|
+
totalProgression: r !== void 0 && r >= 0 && r <= 1 ? r : void 0,
|
|
1005
|
+
position: s !== void 0 && s > 0 ? s : void 0,
|
|
1006
|
+
otherLocations: n.size === 0 ? void 0 : n
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
1009
|
+
/**
|
|
1010
|
+
* Serializes a [Locations] to its RWPM JSON representation.
|
|
1011
|
+
*/
|
|
1012
|
+
serialize() {
|
|
1013
|
+
const e = {};
|
|
1014
|
+
return this.fragments && (e.fragments = this.fragments), this.progression !== void 0 && (e.progression = this.progression), this.totalProgression !== void 0 && (e.totalProgression = this.totalProgression), this.position !== void 0 && (e.position = this.position), this.otherLocations && this.otherLocations.forEach((t, r) => e[r] = t), e;
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
class q {
|
|
1018
|
+
/**
|
|
1019
|
+
* Creates a [Text].
|
|
1020
|
+
*/
|
|
1021
|
+
constructor(e) {
|
|
1022
|
+
this.after = e.after, this.before = e.before, this.highlight = e.highlight;
|
|
1023
|
+
}
|
|
1024
|
+
/**
|
|
1025
|
+
* Parses a [Locations] from its RWPM JSON representation.
|
|
1026
|
+
*/
|
|
1027
|
+
static deserialize(e) {
|
|
1028
|
+
if (e)
|
|
1029
|
+
return new q({
|
|
1030
|
+
after: e.after,
|
|
1031
|
+
before: e.before,
|
|
1032
|
+
highlight: e.highlight
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
/**
|
|
1036
|
+
* Serializes a [Locations] to its RWPM JSON representation.
|
|
1037
|
+
*/
|
|
1038
|
+
serialize() {
|
|
1039
|
+
const e = {};
|
|
1040
|
+
return this.after !== void 0 && (e.after = this.after), this.before !== void 0 && (e.before = this.before), this.highlight !== void 0 && (e.highlight = this.highlight), e;
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
class I {
|
|
1044
|
+
/**
|
|
1045
|
+
* Creates a [Locator].
|
|
1046
|
+
*/
|
|
1047
|
+
constructor(e) {
|
|
1048
|
+
this.href = e.href, this.type = e.type, this.title = e.title, this.locations = e.locations ? e.locations : new w({}), this.text = e.text;
|
|
1049
|
+
}
|
|
1050
|
+
/**
|
|
1051
|
+
* Parses a [Link] from its RWPM JSON representation.
|
|
1052
|
+
*/
|
|
1053
|
+
static deserialize(e) {
|
|
1054
|
+
if (e && e.href && e.type)
|
|
1055
|
+
return new I({
|
|
1056
|
+
href: e.href,
|
|
1057
|
+
type: e.type,
|
|
1058
|
+
title: e.title,
|
|
1059
|
+
locations: w.deserialize(e.locations),
|
|
1060
|
+
text: q.deserialize(e.text)
|
|
1061
|
+
});
|
|
1062
|
+
}
|
|
1063
|
+
/**
|
|
1064
|
+
* Serializes a [Link] to its RWPM JSON representation.
|
|
1065
|
+
*/
|
|
1066
|
+
serialize() {
|
|
1067
|
+
const e = { href: this.href, type: this.type };
|
|
1068
|
+
return this.title !== void 0 && (e.title = this.title), this.locations && (e.locations = this.locations.serialize()), this.text && (e.text = this.text.serialize()), e;
|
|
1069
|
+
}
|
|
1070
|
+
/**
|
|
1071
|
+
* Shortcut to get a copy of the [Locator] with different [Locations] sub-properties.
|
|
1072
|
+
*/
|
|
1073
|
+
copyWithLocations(e) {
|
|
1074
|
+
return new I({
|
|
1075
|
+
href: this.href,
|
|
1076
|
+
type: this.type,
|
|
1077
|
+
title: this.title,
|
|
1078
|
+
text: this.text,
|
|
1079
|
+
locations: new w({ ...this.locations, ...e })
|
|
1080
|
+
});
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
class H {
|
|
1084
|
+
/**
|
|
1085
|
+
* Creates a [Link].
|
|
1086
|
+
*/
|
|
1087
|
+
constructor(e) {
|
|
1088
|
+
this.href = e.href, this.templated = e.templated, this.type = e.type, this.title = e.title, this.rels = e.rels, this.properties = e.properties, this.height = e.height, this.width = e.width, this.duration = e.duration, this.bitrate = e.bitrate, this.languages = e.languages, this.alternates = e.alternates, this.children = e.children;
|
|
1089
|
+
}
|
|
1090
|
+
/**
|
|
1091
|
+
* Parses a [Link] from its RWPM JSON representation.
|
|
1092
|
+
*/
|
|
1093
|
+
static deserialize(e) {
|
|
1094
|
+
if (e && e.href && typeof e.href == "string")
|
|
1095
|
+
return new H({
|
|
1096
|
+
href: e.href,
|
|
1097
|
+
templated: e.templated,
|
|
1098
|
+
type: e.type,
|
|
1099
|
+
title: e.title,
|
|
1100
|
+
rels: e.rel ? e.rel instanceof Array ? new Set(e.rel) : /* @__PURE__ */ new Set([e.rel]) : void 0,
|
|
1101
|
+
properties: b.deserialize(e.properties),
|
|
1102
|
+
height: P(e.height),
|
|
1103
|
+
width: P(e.width),
|
|
1104
|
+
duration: P(e.duration),
|
|
1105
|
+
bitrate: P(e.bitrate),
|
|
1106
|
+
languages: ht(e.language),
|
|
1107
|
+
alternates: ne.deserialize(e.alternate),
|
|
1108
|
+
children: ne.deserialize(e.children)
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
/**
|
|
1112
|
+
* Serializes a [Link] to its RWPM JSON representation.
|
|
1113
|
+
*/
|
|
1114
|
+
serialize() {
|
|
1115
|
+
const e = { href: this.href };
|
|
1116
|
+
return this.templated !== void 0 && (e.templated = this.templated), this.type !== void 0 && (e.type = this.type), this.title !== void 0 && (e.title = this.title), this.rels && (e.rel = ti(this.rels)), this.properties && (e.properties = this.properties.serialize()), this.height !== void 0 && (e.height = this.height), this.width !== void 0 && (e.width = this.width), this.duration !== void 0 && (e.duration = this.duration), this.bitrate !== void 0 && (e.bitrate = this.bitrate), this.languages && (e.language = this.languages), this.alternates && (e.alternate = this.alternates.serialize()), this.children && (e.children = this.children.serialize()), e;
|
|
1117
|
+
}
|
|
1118
|
+
/** MediaType of the linked resource. */
|
|
1119
|
+
get mediaType() {
|
|
1120
|
+
return this.type !== void 0 ? l.parse({ mediaType: this.type }) : l.BINARY;
|
|
1121
|
+
}
|
|
1122
|
+
/** Computes an absolute URL to the link, relative to the given `baseURL`.
|
|
1123
|
+
* If the link's `href` is already absolute, the `baseURL` is ignored.
|
|
1124
|
+
*/
|
|
1125
|
+
toURL(e) {
|
|
1126
|
+
const t = this.href.replace(/^(\/)/, "");
|
|
1127
|
+
if (t.length === 0)
|
|
1128
|
+
return;
|
|
1129
|
+
let r = e || "/";
|
|
1130
|
+
return r.startsWith("/") && (r = "file://" + r), new URL(t, r).href.replace(/^(file:\/\/)/, "");
|
|
1131
|
+
}
|
|
1132
|
+
/** List of URI template parameter keys, if the `Link` is templated. */
|
|
1133
|
+
get templateParameters() {
|
|
1134
|
+
return this.templated ? new ke(this.href).parameters : /* @__PURE__ */ new Set();
|
|
1135
|
+
}
|
|
1136
|
+
/** Expands the `Link`'s HREF by replacing URI template variables by the given parameters.
|
|
1137
|
+
* See RFC 6570 on URI template: https://tools.ietf.org/html/rfc6570
|
|
1138
|
+
*/
|
|
1139
|
+
expandTemplate(e) {
|
|
1140
|
+
return new H({
|
|
1141
|
+
href: new ke(this.href).expand(e),
|
|
1142
|
+
templated: !1
|
|
1143
|
+
});
|
|
1144
|
+
}
|
|
1145
|
+
/**
|
|
1146
|
+
* Makes a copy of this [Link] after merging in the given additional other [properties].
|
|
1147
|
+
*/
|
|
1148
|
+
addProperties(e) {
|
|
1149
|
+
var t;
|
|
1150
|
+
const r = H.deserialize(this.serialize());
|
|
1151
|
+
return r.properties = r.properties ? (t = r.properties) == null ? void 0 : t.add(e) : new b(e), r;
|
|
1152
|
+
}
|
|
1153
|
+
/**
|
|
1154
|
+
* Creates a [Locator] from a reading order [Link].
|
|
1155
|
+
*/
|
|
1156
|
+
get locator() {
|
|
1157
|
+
let e = this.href.split("#");
|
|
1158
|
+
return new I({
|
|
1159
|
+
href: e.length > 0 && e[0] !== void 0 ? e[0] : this.href,
|
|
1160
|
+
type: this.type ?? "",
|
|
1161
|
+
title: this.title,
|
|
1162
|
+
locations: new w({
|
|
1163
|
+
fragments: e.length > 1 && e[1] !== void 0 ? [e[1]] : []
|
|
1164
|
+
})
|
|
1165
|
+
});
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
class ne {
|
|
1169
|
+
/**
|
|
1170
|
+
* Creates a [Links].
|
|
1171
|
+
*/
|
|
1172
|
+
constructor(e) {
|
|
1173
|
+
this.items = e;
|
|
1174
|
+
}
|
|
1175
|
+
/**
|
|
1176
|
+
* Creates a list of [Link] from its RWPM JSON representation.
|
|
1177
|
+
*/
|
|
1178
|
+
static deserialize(e) {
|
|
1179
|
+
if (e && e instanceof Array)
|
|
1180
|
+
return new ne(
|
|
1181
|
+
e.map((t) => H.deserialize(t)).filter((t) => t !== void 0)
|
|
1182
|
+
);
|
|
1183
|
+
}
|
|
1184
|
+
/**
|
|
1185
|
+
* Serializes an array of [Link] to its RWPM JSON representation.
|
|
1186
|
+
*/
|
|
1187
|
+
serialize() {
|
|
1188
|
+
return this.items.map((e) => e.serialize());
|
|
1189
|
+
}
|
|
1190
|
+
/** Finds the first link with the given relation. */
|
|
1191
|
+
findWithRel(e) {
|
|
1192
|
+
const t = (r) => r.rels && r.rels.has(e);
|
|
1193
|
+
return this.items.find(t);
|
|
1194
|
+
}
|
|
1195
|
+
/** Finds all the links with the given relation. */
|
|
1196
|
+
filterByRel(e) {
|
|
1197
|
+
const t = (r) => r.rels && r.rels.has(e);
|
|
1198
|
+
return this.items.filter(t);
|
|
1199
|
+
}
|
|
1200
|
+
/** Finds the first link matching the given HREF. */
|
|
1201
|
+
findWithHref(e) {
|
|
1202
|
+
const t = (r) => r.href === e;
|
|
1203
|
+
return this.items.find(t);
|
|
1204
|
+
}
|
|
1205
|
+
/** Finds the index of the first link matching the given HREF. */
|
|
1206
|
+
findIndexWithHref(e) {
|
|
1207
|
+
const t = (r) => r.href === e;
|
|
1208
|
+
return this.items.findIndex(t);
|
|
1209
|
+
}
|
|
1210
|
+
/** Finds the first link matching the given media type. */
|
|
1211
|
+
findWithMediaType(e) {
|
|
1212
|
+
const t = (r) => r.mediaType.matches(e);
|
|
1213
|
+
return this.items.find(t);
|
|
1214
|
+
}
|
|
1215
|
+
/** Finds all the links matching the given media type. */
|
|
1216
|
+
filterByMediaType(e) {
|
|
1217
|
+
const t = (r) => r.mediaType.matches(e);
|
|
1218
|
+
return this.items.filter(t);
|
|
1219
|
+
}
|
|
1220
|
+
/** Finds all the links matching any of the given media types. */
|
|
1221
|
+
filterByMediaTypes(e) {
|
|
1222
|
+
const t = (r) => {
|
|
1223
|
+
for (const s of e)
|
|
1224
|
+
if (r.mediaType.matches(s))
|
|
1225
|
+
return !0;
|
|
1226
|
+
return !1;
|
|
1227
|
+
};
|
|
1228
|
+
return this.items.filter(t);
|
|
1229
|
+
}
|
|
1230
|
+
/** Returns whether all the resources in the collection are audio clips. */
|
|
1231
|
+
everyIsAudio() {
|
|
1232
|
+
const e = (t) => t.mediaType.isAudio;
|
|
1233
|
+
return this.items.length > 0 && this.items.every(e);
|
|
1234
|
+
}
|
|
1235
|
+
/** Returns whether all the resources in the collection are bitmaps. */
|
|
1236
|
+
everyIsBitmap() {
|
|
1237
|
+
const e = (t) => t.mediaType.isBitmap;
|
|
1238
|
+
return this.items.length > 0 && this.items.every(e);
|
|
1239
|
+
}
|
|
1240
|
+
/** Returns whether all the resources in the collection are HTML documents. */
|
|
1241
|
+
everyIsHTML() {
|
|
1242
|
+
const e = (t) => t.mediaType.isHTML;
|
|
1243
|
+
return this.items.length > 0 && this.items.every(e);
|
|
1244
|
+
}
|
|
1245
|
+
/** Returns whether all the resources in the collection are video clips. */
|
|
1246
|
+
everyIsVideo() {
|
|
1247
|
+
const e = (t) => t.mediaType.isVideo;
|
|
1248
|
+
return this.items.length > 0 && this.items.every(e);
|
|
1249
|
+
}
|
|
1250
|
+
/** Returns whether all the resources in the collection are matching any of the given media types. */
|
|
1251
|
+
everyMatchesMediaType(e) {
|
|
1252
|
+
return Array.isArray(e) ? this.items.length > 0 && this.items.every((t) => {
|
|
1253
|
+
for (const r of e)
|
|
1254
|
+
return t.mediaType.matches(r);
|
|
1255
|
+
return !1;
|
|
1256
|
+
}) : this.items.length > 0 && this.items.every((t) => t.mediaType.matches(e));
|
|
1257
|
+
}
|
|
1258
|
+
filterLinksHasType() {
|
|
1259
|
+
return this.items.filter((e) => e.type);
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
class oe {
|
|
1263
|
+
/**
|
|
1264
|
+
* Creates a [DomRange].
|
|
1265
|
+
*/
|
|
1266
|
+
constructor(e) {
|
|
1267
|
+
this.cssSelector = e.cssSelector, this.textNodeIndex = e.textNodeIndex, this.charOffset = e.charOffset;
|
|
1268
|
+
}
|
|
1269
|
+
/**
|
|
1270
|
+
* Parses a [DomRangePoint] from its RWPM JSON representation.
|
|
1271
|
+
*/
|
|
1272
|
+
static deserialize(e) {
|
|
1273
|
+
if (!(e && e.cssSelector))
|
|
1274
|
+
return;
|
|
1275
|
+
let t = P(e.textNodeIndex);
|
|
1276
|
+
if (t === void 0)
|
|
1277
|
+
return;
|
|
1278
|
+
let r = P(e.charOffset);
|
|
1279
|
+
return r === void 0 && (r = P(e.offset)), new oe({
|
|
1280
|
+
cssSelector: e.cssSelector,
|
|
1281
|
+
textNodeIndex: t,
|
|
1282
|
+
charOffset: r
|
|
1283
|
+
});
|
|
1284
|
+
}
|
|
1285
|
+
/**
|
|
1286
|
+
* Serializes a [DomRangePoint] to its RWPM JSON representation.
|
|
1287
|
+
*/
|
|
1288
|
+
serialize() {
|
|
1289
|
+
const e = {
|
|
1290
|
+
cssSelector: this.cssSelector,
|
|
1291
|
+
textNodeIndex: this.textNodeIndex
|
|
1292
|
+
};
|
|
1293
|
+
return this.charOffset !== void 0 && (e.charOffset = this.charOffset), e;
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
class we {
|
|
1297
|
+
/**
|
|
1298
|
+
* Creates a [DomRange].
|
|
1299
|
+
*/
|
|
1300
|
+
constructor(e) {
|
|
1301
|
+
this.start = e.start, this.end = e.end;
|
|
1302
|
+
}
|
|
1303
|
+
/**
|
|
1304
|
+
* Parses a [DomRange] from its RWPM JSON representation.
|
|
1305
|
+
*/
|
|
1306
|
+
static deserialize(e) {
|
|
1307
|
+
if (!e)
|
|
1308
|
+
return;
|
|
1309
|
+
let t = oe.deserialize(e.start);
|
|
1310
|
+
if (t)
|
|
1311
|
+
return new we({
|
|
1312
|
+
start: t,
|
|
1313
|
+
end: oe.deserialize(e.end)
|
|
1314
|
+
});
|
|
1315
|
+
}
|
|
1316
|
+
/**
|
|
1317
|
+
* Serializes a [DomRange] to its RWPM JSON representation.
|
|
1318
|
+
*/
|
|
1319
|
+
serialize() {
|
|
1320
|
+
const e = { start: this.start.serialize() };
|
|
1321
|
+
return this.end && (e.end = this.end.serialize()), e;
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
w.prototype.getCssSelector = function() {
|
|
1325
|
+
var i;
|
|
1326
|
+
return (i = this.otherLocations) == null ? void 0 : i.get("cssSelector");
|
|
1327
|
+
};
|
|
1328
|
+
w.prototype.getPartialCfi = function() {
|
|
1329
|
+
var i;
|
|
1330
|
+
return (i = this.otherLocations) == null ? void 0 : i.get("partialCfi");
|
|
1331
|
+
};
|
|
1332
|
+
w.prototype.getDomRange = function() {
|
|
1333
|
+
var i;
|
|
1334
|
+
return we.deserialize((i = this.otherLocations) == null ? void 0 : i.get("domRange"));
|
|
1335
|
+
};
|
|
1336
|
+
w.prototype.fragmentParameters = function() {
|
|
1337
|
+
return new Map(
|
|
1338
|
+
this.fragments.map((i) => i.startsWith("#") ? i.slice(1) : i).join("&").split("&").filter((i) => !i.startsWith("#")).map((i) => i.split("=")).filter((i) => i.length === 2).map((i) => [
|
|
1339
|
+
i[0].trim().toLowerCase(),
|
|
1340
|
+
i[1].trim()
|
|
1341
|
+
])
|
|
1342
|
+
);
|
|
1343
|
+
};
|
|
1344
|
+
w.prototype.htmlId = function() {
|
|
1345
|
+
if (!this.fragments.length)
|
|
1346
|
+
return;
|
|
1347
|
+
let i = this.fragments.find((e) => e.length && !e.includes("="));
|
|
1348
|
+
if (!i) {
|
|
1349
|
+
const e = this.fragmentParameters();
|
|
1350
|
+
e.has("id") ? i = e.get("id") : e.has("name") && (i = e.get("name"));
|
|
1351
|
+
}
|
|
1352
|
+
return i != null && i.startsWith("#") ? i.slice(1) : i;
|
|
1353
|
+
};
|
|
1354
|
+
w.prototype.page = function() {
|
|
1355
|
+
const i = parseInt(this.fragmentParameters().get("page"));
|
|
1356
|
+
if (!isNaN(i) && i >= 0)
|
|
1357
|
+
return i;
|
|
1358
|
+
};
|
|
1359
|
+
w.prototype.time = function() {
|
|
1360
|
+
const i = parseInt(this.fragmentParameters().get("t"));
|
|
1361
|
+
if (!isNaN(i))
|
|
1362
|
+
return i;
|
|
1363
|
+
};
|
|
1364
|
+
w.prototype.space = function() {
|
|
1365
|
+
const i = this.fragmentParameters();
|
|
1366
|
+
if (!i.has("xywh"))
|
|
1367
|
+
return;
|
|
1368
|
+
const e = i.get("xywh").split(",").map((t) => parseInt(t));
|
|
1369
|
+
if (e.length === 4 && !e.some(isNaN))
|
|
1370
|
+
return e;
|
|
1371
|
+
};
|
|
1372
|
+
class Te {
|
|
1373
|
+
/** Creates a [Price]. */
|
|
1374
|
+
constructor(e) {
|
|
1375
|
+
this.currency = e.currency, this.value = e.value;
|
|
1376
|
+
}
|
|
1377
|
+
/**
|
|
1378
|
+
* Parses a [Price] from its RWPM JSON representation.
|
|
1379
|
+
*/
|
|
1380
|
+
static deserialize(e) {
|
|
1381
|
+
if (!e)
|
|
1382
|
+
return;
|
|
1383
|
+
let t = e.currency;
|
|
1384
|
+
if (!(t && typeof t == "string" && t.length > 0))
|
|
1385
|
+
return;
|
|
1386
|
+
let r = P(e.value);
|
|
1387
|
+
if (r !== void 0)
|
|
1388
|
+
return new Te({ currency: t, value: r });
|
|
1389
|
+
}
|
|
1390
|
+
/**
|
|
1391
|
+
* Serializes a [Price] to its RWPM JSON representation.
|
|
1392
|
+
*/
|
|
1393
|
+
serialize() {
|
|
1394
|
+
return { currency: this.currency, value: this.value };
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
class j {
|
|
1398
|
+
/** Creates a [Acquisition]. */
|
|
1399
|
+
constructor(e) {
|
|
1400
|
+
this.type = e.type, this.children = e.children;
|
|
1401
|
+
}
|
|
1402
|
+
/**
|
|
1403
|
+
* Parses a [Acquisition] from its RWPM JSON representation.
|
|
1404
|
+
*/
|
|
1405
|
+
static deserialize(e) {
|
|
1406
|
+
if (e && e.type)
|
|
1407
|
+
return new j({
|
|
1408
|
+
type: e.type,
|
|
1409
|
+
children: j.deserializeArray(e.children)
|
|
1410
|
+
});
|
|
1411
|
+
}
|
|
1412
|
+
static deserializeArray(e) {
|
|
1413
|
+
if (e instanceof Array)
|
|
1414
|
+
return e.map((t) => j.deserialize(t)).filter((t) => t !== void 0);
|
|
1415
|
+
}
|
|
1416
|
+
/**
|
|
1417
|
+
* Serializes a [Acquisition] to its RWPM JSON representation.
|
|
1418
|
+
*/
|
|
1419
|
+
serialize() {
|
|
1420
|
+
const e = { type: this.type };
|
|
1421
|
+
return this.children && (e.children = this.children.map((t) => t.serialize())), e;
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
class Se {
|
|
1425
|
+
/** Creates a [Price]. */
|
|
1426
|
+
constructor(e) {
|
|
1427
|
+
this.total = e.total, this.position = e.position;
|
|
1428
|
+
}
|
|
1429
|
+
/**
|
|
1430
|
+
* Parses a [Holds] from its RWPM JSON representation.
|
|
1431
|
+
*/
|
|
1432
|
+
static deserialize(e) {
|
|
1433
|
+
if (e)
|
|
1434
|
+
return new Se({
|
|
1435
|
+
total: P(e.total),
|
|
1436
|
+
position: P(e.position)
|
|
1437
|
+
});
|
|
1438
|
+
}
|
|
1439
|
+
/**
|
|
1440
|
+
* Serializes a [Holds] to its RWPM JSON representation.
|
|
1441
|
+
*/
|
|
1442
|
+
serialize() {
|
|
1443
|
+
const e = {};
|
|
1444
|
+
return this.total !== void 0 && (e.total = this.total), this.position !== void 0 && (e.position = this.position), e;
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
class Ce {
|
|
1448
|
+
/** Creates a [Copies]. */
|
|
1449
|
+
constructor(e) {
|
|
1450
|
+
this.total = e.total, this.available = e.available;
|
|
1451
|
+
}
|
|
1452
|
+
/**
|
|
1453
|
+
* Parses a [Copies] from its RWPM JSON representation.
|
|
1454
|
+
*/
|
|
1455
|
+
static deserialize(e) {
|
|
1456
|
+
if (e)
|
|
1457
|
+
return new Ce({
|
|
1458
|
+
total: P(e.total),
|
|
1459
|
+
available: P(e.available)
|
|
1460
|
+
});
|
|
1461
|
+
}
|
|
1462
|
+
/**
|
|
1463
|
+
* Serializes a [Copies] to its RWPM JSON representation.
|
|
1464
|
+
*/
|
|
1465
|
+
serialize() {
|
|
1466
|
+
const e = {};
|
|
1467
|
+
return this.total !== void 0 && (e.total = this.total), this.available !== void 0 && (e.available = this.available), e;
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
class Pe {
|
|
1471
|
+
/** Creates a [Availability]. */
|
|
1472
|
+
constructor(e) {
|
|
1473
|
+
this.state = e.state, this.since = e.since, this.until = e.until;
|
|
1474
|
+
}
|
|
1475
|
+
/**
|
|
1476
|
+
* Parses a [Availability] from its RWPM JSON representation.
|
|
1477
|
+
*/
|
|
1478
|
+
static deserialize(e) {
|
|
1479
|
+
if (e && e.state)
|
|
1480
|
+
return new Pe({
|
|
1481
|
+
state: e.state,
|
|
1482
|
+
since: Ue(e.since),
|
|
1483
|
+
until: Ue(e.until)
|
|
1484
|
+
});
|
|
1485
|
+
}
|
|
1486
|
+
/**
|
|
1487
|
+
* Serializes a [Availability] to its RWPM JSON representation.
|
|
1488
|
+
*/
|
|
1489
|
+
serialize() {
|
|
1490
|
+
const e = { state: this.state };
|
|
1491
|
+
return this.since !== void 0 && (e.since = this.since.toISOString()), this.until !== void 0 && (e.until = this.until.toISOString()), e;
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
b.prototype.getNumberOfItems = function() {
|
|
1495
|
+
return P(this.otherProperties.numberOfItems);
|
|
1496
|
+
};
|
|
1497
|
+
b.prototype.getPrice = function() {
|
|
1498
|
+
return Te.deserialize(this.otherProperties.price);
|
|
1499
|
+
};
|
|
1500
|
+
b.prototype.getIndirectAcquisitions = function() {
|
|
1501
|
+
const i = this.otherProperties.indirectAcquisition;
|
|
1502
|
+
if (i && i instanceof Array)
|
|
1503
|
+
return i.map((e) => j.deserialize(e)).filter((e) => e !== void 0);
|
|
1504
|
+
};
|
|
1505
|
+
b.prototype.getHolds = function() {
|
|
1506
|
+
return Se.deserialize(this.otherProperties.holds);
|
|
1507
|
+
};
|
|
1508
|
+
b.prototype.getCopies = function() {
|
|
1509
|
+
return Ce.deserialize(this.otherProperties.copies);
|
|
1510
|
+
};
|
|
1511
|
+
b.prototype.getAvailability = function() {
|
|
1512
|
+
return Pe.deserialize(this.otherProperties.availability);
|
|
1513
|
+
};
|
|
1514
|
+
b.prototype.getAuthenticate = function() {
|
|
1515
|
+
return H.deserialize(this.otherProperties.authenticate);
|
|
1516
|
+
};
|
|
1517
|
+
b.prototype.getClipped = function() {
|
|
1518
|
+
return this.otherProperties.clipped;
|
|
1519
|
+
};
|
|
1520
|
+
b.prototype.getFit = function() {
|
|
1521
|
+
return this.otherProperties.fit;
|
|
1522
|
+
};
|
|
1523
|
+
b.prototype.getOrientation = function() {
|
|
1524
|
+
return this.otherProperties.orientation;
|
|
1525
|
+
};
|
|
1526
|
+
b.prototype.getOverflow = function() {
|
|
1527
|
+
return this.otherProperties.overflow;
|
|
1528
|
+
};
|
|
1529
|
+
b.prototype.getPage = function() {
|
|
1530
|
+
return this.otherProperties.page || void 0;
|
|
1531
|
+
};
|
|
1532
|
+
b.prototype.getSpread = function() {
|
|
1533
|
+
return this.otherProperties.spread || void 0;
|
|
1534
|
+
};
|
|
1535
|
+
function $e(i) {
|
|
1536
|
+
return i.split("").reverse().join("");
|
|
1537
|
+
}
|
|
1538
|
+
function ii(i, e, t) {
|
|
1539
|
+
const r = $e(e);
|
|
1540
|
+
return t.map((s) => {
|
|
1541
|
+
const n = Math.max(0, s.end - e.length - s.errors), o = $e(i.slice(n, s.end));
|
|
1542
|
+
return {
|
|
1543
|
+
start: ct(o, r, s.errors).reduce((h, c) => s.end - c.end < h ? s.end - c.end : h, s.end),
|
|
1544
|
+
end: s.end,
|
|
1545
|
+
errors: s.errors
|
|
1546
|
+
};
|
|
1547
|
+
});
|
|
1548
|
+
}
|
|
1549
|
+
function pe(i) {
|
|
1550
|
+
return (i | -i) >> 31 & 1;
|
|
1551
|
+
}
|
|
1552
|
+
function He(i, e, t, r) {
|
|
1553
|
+
let s = i.P[t], n = i.M[t];
|
|
1554
|
+
const o = r >>> 31, a = e[t] | o, h = a | n, c = (a & s) + s ^ s | a;
|
|
1555
|
+
let d = n | ~(c | s), p = s & c;
|
|
1556
|
+
const u = pe(d & i.lastRowMask[t]) - pe(p & i.lastRowMask[t]);
|
|
1557
|
+
return d <<= 1, p <<= 1, p |= o, d |= pe(r) - o, s = p | ~(h | d), n = d & h, i.P[t] = s, i.M[t] = n, u;
|
|
1558
|
+
}
|
|
1559
|
+
function ct(i, e, t) {
|
|
1560
|
+
if (e.length === 0)
|
|
1561
|
+
return [];
|
|
1562
|
+
t = Math.min(t, e.length);
|
|
1563
|
+
const r = [], s = 32, n = Math.ceil(e.length / s) - 1, o = {
|
|
1564
|
+
P: new Uint32Array(n + 1),
|
|
1565
|
+
M: new Uint32Array(n + 1),
|
|
1566
|
+
lastRowMask: new Uint32Array(n + 1)
|
|
1567
|
+
};
|
|
1568
|
+
o.lastRowMask.fill(1 << 31), o.lastRowMask[n] = 1 << (e.length - 1) % s;
|
|
1569
|
+
const a = new Uint32Array(n + 1), h = /* @__PURE__ */ new Map(), c = [];
|
|
1570
|
+
for (let u = 0; u < 256; u++)
|
|
1571
|
+
c.push(a);
|
|
1572
|
+
for (let u = 0; u < e.length; u += 1) {
|
|
1573
|
+
const f = e.charCodeAt(u);
|
|
1574
|
+
if (h.has(f))
|
|
1575
|
+
continue;
|
|
1576
|
+
const v = new Uint32Array(n + 1);
|
|
1577
|
+
h.set(f, v), f < c.length && (c[f] = v);
|
|
1578
|
+
for (let g = 0; g <= n; g += 1) {
|
|
1579
|
+
v[g] = 0;
|
|
1580
|
+
for (let y = 0; y < s; y += 1) {
|
|
1581
|
+
const x = g * s + y;
|
|
1582
|
+
if (x >= e.length)
|
|
1583
|
+
continue;
|
|
1584
|
+
e.charCodeAt(x) === f && (v[g] |= 1 << y);
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
let d = Math.max(0, Math.ceil(t / s) - 1);
|
|
1589
|
+
const p = new Uint32Array(n + 1);
|
|
1590
|
+
for (let u = 0; u <= d; u += 1)
|
|
1591
|
+
p[u] = (u + 1) * s;
|
|
1592
|
+
p[n] = e.length;
|
|
1593
|
+
for (let u = 0; u <= d; u += 1)
|
|
1594
|
+
o.P[u] = -1, o.M[u] = 0;
|
|
1595
|
+
for (let u = 0; u < i.length; u += 1) {
|
|
1596
|
+
const f = i.charCodeAt(u);
|
|
1597
|
+
let v;
|
|
1598
|
+
f < c.length ? v = c[f] : (v = h.get(f), typeof v > "u" && (v = a));
|
|
1599
|
+
let g = 0;
|
|
1600
|
+
for (let y = 0; y <= d; y += 1)
|
|
1601
|
+
g = He(o, v, y, g), p[y] += g;
|
|
1602
|
+
if (p[d] - g <= t && d < n && (v[d + 1] & 1 || g < 0)) {
|
|
1603
|
+
d += 1, o.P[d] = -1, o.M[d] = 0;
|
|
1604
|
+
let y;
|
|
1605
|
+
if (d === n) {
|
|
1606
|
+
const x = e.length % s;
|
|
1607
|
+
y = x === 0 ? s : x;
|
|
1608
|
+
} else
|
|
1609
|
+
y = s;
|
|
1610
|
+
p[d] = p[d - 1] + y - g + He(o, v, d, g);
|
|
1611
|
+
} else
|
|
1612
|
+
for (; d > 0 && p[d] >= t + s; )
|
|
1613
|
+
d -= 1;
|
|
1614
|
+
d === n && p[d] <= t && (p[d] < t && r.splice(0, r.length), r.push({
|
|
1615
|
+
start: -1,
|
|
1616
|
+
end: u + 1,
|
|
1617
|
+
errors: p[d]
|
|
1618
|
+
}), t = p[d]);
|
|
1619
|
+
}
|
|
1620
|
+
return r;
|
|
1621
|
+
}
|
|
1622
|
+
function ri(i, e, t) {
|
|
1623
|
+
const r = ct(i, e, t);
|
|
1624
|
+
return ii(i, e, r);
|
|
1625
|
+
}
|
|
1626
|
+
function dt(i, e, t) {
|
|
1627
|
+
let r = 0;
|
|
1628
|
+
const s = [];
|
|
1629
|
+
for (; r !== -1; )
|
|
1630
|
+
r = i.indexOf(e, r), r !== -1 && (s.push({
|
|
1631
|
+
start: r,
|
|
1632
|
+
end: r + e.length,
|
|
1633
|
+
errors: 0
|
|
1634
|
+
}), r += 1);
|
|
1635
|
+
return s.length > 0 ? s : ri(i, e, t);
|
|
1636
|
+
}
|
|
1637
|
+
function qe(i, e) {
|
|
1638
|
+
return e.length === 0 || i.length === 0 ? 0 : 1 - dt(i, e, e.length)[0].errors / e.length;
|
|
1639
|
+
}
|
|
1640
|
+
function si(i, e, t = {}) {
|
|
1641
|
+
if (e.length === 0)
|
|
1642
|
+
return null;
|
|
1643
|
+
const r = Math.min(256, e.length / 2), s = dt(i, e, r);
|
|
1644
|
+
if (s.length === 0)
|
|
1645
|
+
return null;
|
|
1646
|
+
const n = (a) => {
|
|
1647
|
+
const u = 1 - a.errors / e.length, f = t.prefix ? qe(
|
|
1648
|
+
i.slice(
|
|
1649
|
+
Math.max(0, a.start - t.prefix.length),
|
|
1650
|
+
a.start
|
|
1651
|
+
),
|
|
1652
|
+
t.prefix
|
|
1653
|
+
) : 1, v = t.suffix ? qe(
|
|
1654
|
+
i.slice(a.end, a.end + t.suffix.length),
|
|
1655
|
+
t.suffix
|
|
1656
|
+
) : 1;
|
|
1657
|
+
let g = 1;
|
|
1658
|
+
typeof t.hint == "number" && (g = 1 - Math.abs(a.start - t.hint) / i.length);
|
|
1659
|
+
const y = 50 * u + 20 * f + 20 * v + 2 * g, x = 50 + 20 + 20 + 2;
|
|
1660
|
+
return y / x;
|
|
1661
|
+
}, o = s.map((a) => ({
|
|
1662
|
+
start: a.start,
|
|
1663
|
+
end: a.end,
|
|
1664
|
+
score: n(a)
|
|
1665
|
+
}));
|
|
1666
|
+
return o.sort((a, h) => h.score - a.score), o[0];
|
|
1667
|
+
}
|
|
1668
|
+
function ge(i, e, t) {
|
|
1669
|
+
const r = t === 1 ? e : e - 1;
|
|
1670
|
+
if (i.charAt(r).trim() !== "")
|
|
1671
|
+
return e;
|
|
1672
|
+
let s, n;
|
|
1673
|
+
if (t === 2 ? (s = i.substring(0, e), n = s.trimEnd()) : (s = i.substring(e), n = s.trimStart()), !n.length)
|
|
1674
|
+
return -1;
|
|
1675
|
+
const o = s.length - n.length;
|
|
1676
|
+
return t === 2 ? e - o : e + o;
|
|
1677
|
+
}
|
|
1678
|
+
function Xe(i, e) {
|
|
1679
|
+
const t = i.commonAncestorContainer.ownerDocument.createNodeIterator(
|
|
1680
|
+
i.commonAncestorContainer,
|
|
1681
|
+
NodeFilter.SHOW_TEXT
|
|
1682
|
+
), r = e === 1 ? i.startContainer : i.endContainer, s = e === 1 ? i.endContainer : i.startContainer;
|
|
1683
|
+
let n = t.nextNode();
|
|
1684
|
+
for (; n && n !== r; )
|
|
1685
|
+
n = t.nextNode();
|
|
1686
|
+
e === 2 && (n = t.previousNode());
|
|
1687
|
+
let o = -1;
|
|
1688
|
+
const a = () => {
|
|
1689
|
+
if (n = e === 1 ? t.nextNode() : t.previousNode(), n) {
|
|
1690
|
+
const h = n.textContent, c = e === 1 ? 0 : h.length;
|
|
1691
|
+
o = ge(h, c, e);
|
|
1692
|
+
}
|
|
1693
|
+
};
|
|
1694
|
+
for (; n && o === -1 && n !== s; )
|
|
1695
|
+
a();
|
|
1696
|
+
if (n && o >= 0)
|
|
1697
|
+
return { node: n, offset: o };
|
|
1698
|
+
throw new RangeError("No text nodes with non-whitespace text found in range");
|
|
1699
|
+
}
|
|
1700
|
+
function ni(i) {
|
|
1701
|
+
if (!i.toString().trim().length)
|
|
1702
|
+
throw new RangeError("Range contains no non-whitespace text");
|
|
1703
|
+
if (i.startContainer.nodeType !== Node.TEXT_NODE)
|
|
1704
|
+
throw new RangeError("Range startContainer is not a text node");
|
|
1705
|
+
if (i.endContainer.nodeType !== Node.TEXT_NODE)
|
|
1706
|
+
throw new RangeError("Range endContainer is not a text node");
|
|
1707
|
+
const e = i.cloneRange();
|
|
1708
|
+
let t = !1, r = !1;
|
|
1709
|
+
const s = {
|
|
1710
|
+
start: ge(
|
|
1711
|
+
i.startContainer.textContent,
|
|
1712
|
+
i.startOffset,
|
|
1713
|
+
1
|
|
1714
|
+
/* Forwards */
|
|
1715
|
+
),
|
|
1716
|
+
end: ge(
|
|
1717
|
+
i.endContainer.textContent,
|
|
1718
|
+
i.endOffset,
|
|
1719
|
+
2
|
|
1720
|
+
/* Backwards */
|
|
1721
|
+
)
|
|
1722
|
+
};
|
|
1723
|
+
if (s.start >= 0 && (e.setStart(i.startContainer, s.start), t = !0), s.end > 0 && (e.setEnd(i.endContainer, s.end), r = !0), t && r)
|
|
1724
|
+
return e;
|
|
1725
|
+
if (!t) {
|
|
1726
|
+
const { node: n, offset: o } = Xe(
|
|
1727
|
+
e,
|
|
1728
|
+
1
|
|
1729
|
+
/* Forwards */
|
|
1730
|
+
);
|
|
1731
|
+
n && o >= 0 && e.setStart(n, o);
|
|
1732
|
+
}
|
|
1733
|
+
if (!r) {
|
|
1734
|
+
const { node: n, offset: o } = Xe(
|
|
1735
|
+
e,
|
|
1736
|
+
2
|
|
1737
|
+
/* Backwards */
|
|
1738
|
+
);
|
|
1739
|
+
n && o > 0 && e.setEnd(n, o);
|
|
1740
|
+
}
|
|
1741
|
+
return e;
|
|
1742
|
+
}
|
|
1743
|
+
function ut(i) {
|
|
1744
|
+
var e;
|
|
1745
|
+
switch (i.nodeType) {
|
|
1746
|
+
case Node.ELEMENT_NODE:
|
|
1747
|
+
case Node.TEXT_NODE:
|
|
1748
|
+
return ((e = i.textContent) == null ? void 0 : e.length) ?? 0;
|
|
1749
|
+
default:
|
|
1750
|
+
return 0;
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
function Ve(i) {
|
|
1754
|
+
let e = i.previousSibling, t = 0;
|
|
1755
|
+
for (; e; )
|
|
1756
|
+
t += ut(e), e = e.previousSibling;
|
|
1757
|
+
return t;
|
|
1758
|
+
}
|
|
1759
|
+
function pt(i, ...e) {
|
|
1760
|
+
let t = e.shift();
|
|
1761
|
+
const r = i.ownerDocument.createNodeIterator(
|
|
1762
|
+
i,
|
|
1763
|
+
NodeFilter.SHOW_TEXT
|
|
1764
|
+
), s = [];
|
|
1765
|
+
let n = r.nextNode(), o, a = 0;
|
|
1766
|
+
for (; t !== void 0 && n; )
|
|
1767
|
+
o = n, a + o.data.length > t ? (s.push({ node: o, offset: t - a }), t = e.shift()) : (n = r.nextNode(), a += o.data.length);
|
|
1768
|
+
for (; t !== void 0 && o && a === t; )
|
|
1769
|
+
s.push({ node: o, offset: o.data.length }), t = e.shift();
|
|
1770
|
+
if (t !== void 0)
|
|
1771
|
+
throw new RangeError("Offset exceeds text length");
|
|
1772
|
+
return s;
|
|
1773
|
+
}
|
|
1774
|
+
class R {
|
|
1775
|
+
constructor(e, t) {
|
|
1776
|
+
if (t < 0)
|
|
1777
|
+
throw new Error("Offset is invalid");
|
|
1778
|
+
this.element = e, this.offset = t;
|
|
1779
|
+
}
|
|
1780
|
+
/**
|
|
1781
|
+
* Return a copy of this position with offset relative to a given ancestor
|
|
1782
|
+
* element.
|
|
1783
|
+
*
|
|
1784
|
+
* @param parent - Ancestor of `this.element`
|
|
1785
|
+
*/
|
|
1786
|
+
relativeTo(e) {
|
|
1787
|
+
if (!e.contains(this.element))
|
|
1788
|
+
throw new Error("Parent is not an ancestor of current element");
|
|
1789
|
+
let t = this.element, r = this.offset;
|
|
1790
|
+
for (; t !== e; )
|
|
1791
|
+
r += Ve(t), t = t.parentElement;
|
|
1792
|
+
return new R(t, r);
|
|
1793
|
+
}
|
|
1794
|
+
/**
|
|
1795
|
+
* Resolve the position to a specific text node and offset within that node.
|
|
1796
|
+
*
|
|
1797
|
+
* Throws if `this.offset` exceeds the length of the element's text. In the
|
|
1798
|
+
* case where the element has no text and `this.offset` is 0, the `direction`
|
|
1799
|
+
* option determines what happens.
|
|
1800
|
+
*
|
|
1801
|
+
* Offsets at the boundary between two nodes are resolved to the start of the
|
|
1802
|
+
* node that begins at the boundary.
|
|
1803
|
+
*
|
|
1804
|
+
* @param options.direction - Specifies in which direction to search for the
|
|
1805
|
+
* nearest text node if `this.offset` is `0` and
|
|
1806
|
+
* `this.element` has no text. If not specified an
|
|
1807
|
+
* error is thrown.
|
|
1808
|
+
*
|
|
1809
|
+
* @throws {RangeError}
|
|
1810
|
+
*/
|
|
1811
|
+
resolve(e = {}) {
|
|
1812
|
+
try {
|
|
1813
|
+
return pt(this.element, this.offset)[0];
|
|
1814
|
+
} catch (t) {
|
|
1815
|
+
if (this.offset === 0 && e.direction !== void 0) {
|
|
1816
|
+
const r = document.createTreeWalker(
|
|
1817
|
+
this.element.getRootNode(),
|
|
1818
|
+
NodeFilter.SHOW_TEXT
|
|
1819
|
+
);
|
|
1820
|
+
r.currentNode = this.element;
|
|
1821
|
+
const s = e.direction === 1, n = s ? r.nextNode() : r.previousNode();
|
|
1822
|
+
if (!n)
|
|
1823
|
+
throw t;
|
|
1824
|
+
return { node: n, offset: s ? 0 : n.data.length };
|
|
1825
|
+
} else
|
|
1826
|
+
throw t;
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
/**
|
|
1830
|
+
* Construct a `TextPosition` that refers to the `offset`th character within
|
|
1831
|
+
* `node`.
|
|
1832
|
+
*/
|
|
1833
|
+
static fromCharOffset(e, t) {
|
|
1834
|
+
switch (e.nodeType) {
|
|
1835
|
+
case Node.TEXT_NODE:
|
|
1836
|
+
return R.fromPoint(e, t);
|
|
1837
|
+
case Node.ELEMENT_NODE:
|
|
1838
|
+
return new R(e, t);
|
|
1839
|
+
default:
|
|
1840
|
+
throw new Error("Node is not an element or text node");
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
/**
|
|
1844
|
+
* Construct a `TextPosition` representing the range start or end point (node, offset).
|
|
1845
|
+
*
|
|
1846
|
+
* @param node
|
|
1847
|
+
* @param offset - Offset within the node
|
|
1848
|
+
*/
|
|
1849
|
+
static fromPoint(e, t) {
|
|
1850
|
+
switch (e.nodeType) {
|
|
1851
|
+
case Node.TEXT_NODE: {
|
|
1852
|
+
if (t < 0 || t > e.data.length)
|
|
1853
|
+
throw new Error("Text node offset is out of range");
|
|
1854
|
+
if (!e.parentElement)
|
|
1855
|
+
throw new Error("Text node has no parent");
|
|
1856
|
+
const r = Ve(e) + t;
|
|
1857
|
+
return new R(e.parentElement, r);
|
|
1858
|
+
}
|
|
1859
|
+
case Node.ELEMENT_NODE: {
|
|
1860
|
+
if (t < 0 || t > e.childNodes.length)
|
|
1861
|
+
throw new Error("Child node offset is out of range");
|
|
1862
|
+
let r = 0;
|
|
1863
|
+
for (let s = 0; s < t; s++)
|
|
1864
|
+
r += ut(e.childNodes[s]);
|
|
1865
|
+
return new R(e, r);
|
|
1866
|
+
}
|
|
1867
|
+
default:
|
|
1868
|
+
throw new Error("Point is not in an element or text node");
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
class z {
|
|
1873
|
+
constructor(e, t) {
|
|
1874
|
+
this.start = e, this.end = t;
|
|
1875
|
+
}
|
|
1876
|
+
/**
|
|
1877
|
+
* Create a new TextRange whose `start` and `end` are computed relative to
|
|
1878
|
+
* `element`. `element` must be an ancestor of both `start.element` and
|
|
1879
|
+
* `end.element`.
|
|
1880
|
+
*/
|
|
1881
|
+
relativeTo(e) {
|
|
1882
|
+
return new z(
|
|
1883
|
+
this.start.relativeTo(e),
|
|
1884
|
+
this.end.relativeTo(e)
|
|
1885
|
+
);
|
|
1886
|
+
}
|
|
1887
|
+
/**
|
|
1888
|
+
* Resolve this TextRange to a (DOM) Range.
|
|
1889
|
+
*
|
|
1890
|
+
* The resulting DOM Range will always start and end in a `Text` node.
|
|
1891
|
+
* Hence `TextRange.fromRange(range).toRange()` can be used to "shrink" a
|
|
1892
|
+
* range to the text it contains.
|
|
1893
|
+
*
|
|
1894
|
+
* May throw if the `start` or `end` positions cannot be resolved to a range.
|
|
1895
|
+
*/
|
|
1896
|
+
toRange() {
|
|
1897
|
+
let e, t;
|
|
1898
|
+
this.start.element === this.end.element && this.start.offset <= this.end.offset ? [e, t] = pt(
|
|
1899
|
+
this.start.element,
|
|
1900
|
+
this.start.offset,
|
|
1901
|
+
this.end.offset
|
|
1902
|
+
) : (e = this.start.resolve({
|
|
1903
|
+
direction: 1
|
|
1904
|
+
/* FORWARDS */
|
|
1905
|
+
}), t = this.end.resolve({
|
|
1906
|
+
direction: 2
|
|
1907
|
+
/* BACKWARDS */
|
|
1908
|
+
}));
|
|
1909
|
+
const r = new Range();
|
|
1910
|
+
return r.setStart(e.node, e.offset), r.setEnd(t.node, t.offset), r;
|
|
1911
|
+
}
|
|
1912
|
+
/**
|
|
1913
|
+
* Create a TextRange from a (DOM) Range
|
|
1914
|
+
*/
|
|
1915
|
+
static fromRange(e) {
|
|
1916
|
+
const t = R.fromPoint(
|
|
1917
|
+
e.startContainer,
|
|
1918
|
+
e.startOffset
|
|
1919
|
+
), r = R.fromPoint(e.endContainer, e.endOffset);
|
|
1920
|
+
return new z(t, r);
|
|
1921
|
+
}
|
|
1922
|
+
/**
|
|
1923
|
+
* Create a TextRange representing the `start`th to `end`th characters in
|
|
1924
|
+
* `root`
|
|
1925
|
+
*/
|
|
1926
|
+
static fromOffsets(e, t, r) {
|
|
1927
|
+
return new z(
|
|
1928
|
+
new R(e, t),
|
|
1929
|
+
new R(e, r)
|
|
1930
|
+
);
|
|
1931
|
+
}
|
|
1932
|
+
/**
|
|
1933
|
+
* Return a new Range representing `range` trimmed of any leading or trailing
|
|
1934
|
+
* whitespace
|
|
1935
|
+
*/
|
|
1936
|
+
static trimmedRange(e) {
|
|
1937
|
+
return ni(z.fromRange(e).toRange());
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
class ae {
|
|
1941
|
+
constructor(e, t, r) {
|
|
1942
|
+
this.root = e, this.start = t, this.end = r;
|
|
1943
|
+
}
|
|
1944
|
+
static fromRange(e, t) {
|
|
1945
|
+
const r = z.fromRange(t).relativeTo(e);
|
|
1946
|
+
return new ae(
|
|
1947
|
+
e,
|
|
1948
|
+
r.start.offset,
|
|
1949
|
+
r.end.offset
|
|
1950
|
+
);
|
|
1951
|
+
}
|
|
1952
|
+
static fromSelector(e, t) {
|
|
1953
|
+
return new ae(e, t.start, t.end);
|
|
1954
|
+
}
|
|
1955
|
+
toSelector() {
|
|
1956
|
+
return {
|
|
1957
|
+
type: "TextPositionSelector",
|
|
1958
|
+
start: this.start,
|
|
1959
|
+
end: this.end
|
|
1960
|
+
};
|
|
1961
|
+
}
|
|
1962
|
+
toRange() {
|
|
1963
|
+
return z.fromOffsets(this.root, this.start, this.end).toRange();
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
class le {
|
|
1967
|
+
/**
|
|
1968
|
+
* @param root - A root element from which to anchor.
|
|
1969
|
+
*/
|
|
1970
|
+
constructor(e, t, r = {}) {
|
|
1971
|
+
this.root = e, this.exact = t, this.context = r;
|
|
1972
|
+
}
|
|
1973
|
+
/**
|
|
1974
|
+
* Create a `TextQuoteAnchor` from a range.
|
|
1975
|
+
*
|
|
1976
|
+
* Will throw if `range` does not contain any text nodes.
|
|
1977
|
+
*/
|
|
1978
|
+
static fromRange(e, t) {
|
|
1979
|
+
const r = e.textContent, s = z.fromRange(t).relativeTo(e), n = s.start.offset, o = s.end.offset, a = 32;
|
|
1980
|
+
return new le(e, r.slice(n, o), {
|
|
1981
|
+
prefix: r.slice(Math.max(0, n - a), n),
|
|
1982
|
+
suffix: r.slice(o, Math.min(r.length, o + a))
|
|
1983
|
+
});
|
|
1984
|
+
}
|
|
1985
|
+
static fromSelector(e, t) {
|
|
1986
|
+
const { prefix: r, suffix: s } = t;
|
|
1987
|
+
return new le(e, t.exact, { prefix: r, suffix: s });
|
|
1988
|
+
}
|
|
1989
|
+
toSelector() {
|
|
1990
|
+
return {
|
|
1991
|
+
type: "TextQuoteSelector",
|
|
1992
|
+
exact: this.exact,
|
|
1993
|
+
prefix: this.context.prefix,
|
|
1994
|
+
suffix: this.context.suffix
|
|
1995
|
+
};
|
|
1996
|
+
}
|
|
1997
|
+
toRange(e = {}) {
|
|
1998
|
+
return this.toPositionAnchor(e).toRange();
|
|
1999
|
+
}
|
|
2000
|
+
toPositionAnchor(e = {}) {
|
|
2001
|
+
const t = this.root.textContent, r = si(t, this.exact, {
|
|
2002
|
+
...this.context,
|
|
2003
|
+
hint: e.hint
|
|
2004
|
+
});
|
|
2005
|
+
if (!r)
|
|
2006
|
+
throw new Error("Quote not found");
|
|
2007
|
+
return new ae(this.root, r.start, r.end);
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
function Oe(i, e) {
|
|
2011
|
+
try {
|
|
2012
|
+
let r = e.locations, s = e.text;
|
|
2013
|
+
if (s && s.highlight) {
|
|
2014
|
+
let n;
|
|
2015
|
+
r && r.getCssSelector() && (n = i.querySelector(r.getCssSelector())), n || (n = i.body);
|
|
2016
|
+
let o = new le(n, s.highlight, {
|
|
2017
|
+
prefix: s.before,
|
|
2018
|
+
suffix: s.after
|
|
2019
|
+
});
|
|
2020
|
+
try {
|
|
2021
|
+
return o.toRange();
|
|
2022
|
+
} catch {
|
|
2023
|
+
return console.warn("Quote not found:", o), null;
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
if (r) {
|
|
2027
|
+
var t = null;
|
|
2028
|
+
if (!t && r.getCssSelector() && (t = i.querySelector(r.getCssSelector())), !t && r.fragments) {
|
|
2029
|
+
for (const n of r.fragments)
|
|
2030
|
+
if (t = i.getElementById(n), t)
|
|
2031
|
+
break;
|
|
2032
|
+
}
|
|
2033
|
+
if (t) {
|
|
2034
|
+
let n = i.createRange();
|
|
2035
|
+
return t.childNodes.length === 0 ? (n.selectNodeContents(t), n) : (n.setStartBefore(t), n.setEndAfter(t), n);
|
|
2036
|
+
}
|
|
2037
|
+
}
|
|
2038
|
+
} catch (r) {
|
|
2039
|
+
console.error(r);
|
|
2040
|
+
}
|
|
2041
|
+
return null;
|
|
2042
|
+
}
|
|
2043
|
+
function T(i) {
|
|
2044
|
+
const e = i.getSelection();
|
|
2045
|
+
e && e.removeAllRanges();
|
|
2046
|
+
}
|
|
2047
|
+
const oi = [
|
|
2048
|
+
"a",
|
|
2049
|
+
"audio",
|
|
2050
|
+
"button",
|
|
2051
|
+
"canvas",
|
|
2052
|
+
"details",
|
|
2053
|
+
"input",
|
|
2054
|
+
"label",
|
|
2055
|
+
"option",
|
|
2056
|
+
"select",
|
|
2057
|
+
"submit",
|
|
2058
|
+
"textarea",
|
|
2059
|
+
"video"
|
|
2060
|
+
];
|
|
2061
|
+
function ft(i) {
|
|
2062
|
+
var e;
|
|
2063
|
+
return oi.indexOf(i.nodeName.toLowerCase()) !== -1 || i.hasAttribute("contenteditable") && ((e = i.getAttribute("contenteditable")) == null ? void 0 : e.toLowerCase()) !== "false" ? i : i.parentElement ? ft(i.parentElement) : null;
|
|
2064
|
+
}
|
|
2065
|
+
function mt(i, e) {
|
|
2066
|
+
const t = gt(i, i.document.body, e);
|
|
2067
|
+
return new I({
|
|
2068
|
+
href: "#",
|
|
2069
|
+
type: "application/xhtml+xml",
|
|
2070
|
+
locations: new w({
|
|
2071
|
+
otherLocations: /* @__PURE__ */ new Map([
|
|
2072
|
+
["cssSelector", i._readium_cssSelectorGenerator.getCssSelector(t)]
|
|
2073
|
+
])
|
|
2074
|
+
}),
|
|
2075
|
+
text: new q({
|
|
2076
|
+
highlight: t.textContent || void 0
|
|
2077
|
+
})
|
|
2078
|
+
});
|
|
2079
|
+
}
|
|
2080
|
+
function gt(i, e, t) {
|
|
2081
|
+
for (var r = 0; r < e.children.length; r++) {
|
|
2082
|
+
const s = e.children[r];
|
|
2083
|
+
if (!li(s) && ai(i, s, t))
|
|
2084
|
+
return gt(i, s, t);
|
|
2085
|
+
}
|
|
2086
|
+
return e;
|
|
2087
|
+
}
|
|
2088
|
+
function ai(i, e, t) {
|
|
2089
|
+
if (e === document.body || e === document.documentElement)
|
|
2090
|
+
return !0;
|
|
2091
|
+
if (!document || !document.documentElement || !document.body)
|
|
2092
|
+
return !1;
|
|
2093
|
+
const r = e.getBoundingClientRect();
|
|
2094
|
+
return t ? r.bottom > 0 && r.top < i.innerHeight : r.right > 0 && r.left < i.innerWidth;
|
|
2095
|
+
}
|
|
2096
|
+
function li(i) {
|
|
2097
|
+
const e = getComputedStyle(i);
|
|
2098
|
+
return !!(e && (e.getPropertyValue("display") != "block" || e.getPropertyValue("opacity") === "0"));
|
|
2099
|
+
}
|
|
2100
|
+
const _e = "readium-column-snapper-style", hi = 200, vt = class C extends at {
|
|
2101
|
+
constructor() {
|
|
2102
|
+
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);
|
|
2103
|
+
}
|
|
2104
|
+
doc() {
|
|
2105
|
+
return this.wnd.document.scrollingElement;
|
|
2106
|
+
}
|
|
2107
|
+
scrollOffset() {
|
|
2108
|
+
return this.doc().scrollLeft > 0 ? this.doc().scrollLeft : this.alreadyScrollLeft;
|
|
2109
|
+
}
|
|
2110
|
+
snapOffset(e) {
|
|
2111
|
+
const t = e + (W(this.wnd) ? -1 : 1);
|
|
2112
|
+
return t - t % this.wnd.innerWidth;
|
|
2113
|
+
}
|
|
2114
|
+
reportProgress() {
|
|
2115
|
+
this.comms.send("progress", this.wnd.scrollX / this.cachedScrollWidth);
|
|
2116
|
+
}
|
|
2117
|
+
shake() {
|
|
2118
|
+
if (this.overscroll !== 0 || this.shakeTimeout !== 0)
|
|
2119
|
+
return;
|
|
2120
|
+
const e = this.doc();
|
|
2121
|
+
e.classList.add(W(this.wnd) ? "readium-bounce-l" : "readium-bounce-r");
|
|
2122
|
+
const t = this.scrollOffset();
|
|
2123
|
+
this.shakeTimeout = this.wnd.setTimeout(() => {
|
|
2124
|
+
e.classList.remove("readium-bounce-l"), e.classList.remove("readium-bounce-r"), this.shakeTimeout = 0, this.doc().scrollLeft = t;
|
|
2125
|
+
}, 150);
|
|
2126
|
+
}
|
|
2127
|
+
// We have to cache this because during overscroll (transform, or left) the width is incorrect due to browser
|
|
2128
|
+
takeOverSnap() {
|
|
2129
|
+
var t;
|
|
2130
|
+
this.snappingCancelled = !0, this.clearTouches();
|
|
2131
|
+
const e = this.doc();
|
|
2132
|
+
this.overscroll = ((t = e.style.transform) == null ? void 0 : t.length) > 12 ? parseFloat(e.style.transform.slice(12).split("px")[0]) : 0;
|
|
2133
|
+
}
|
|
2134
|
+
// Snaps the current offset to the page width.
|
|
2135
|
+
snapCurrentOffset(e = !1, t = !1) {
|
|
2136
|
+
const r = this.wnd.scrollX > 0 ? this.wnd.scrollX : this.alreadyScrollLeft, s = this.doc(), n = this.dragOffset(), o = lt(this.wnd), a = Math.min(Math.max(0, r), this.cachedScrollWidth), h = W(this.wnd) ? -1 : 1, c = (
|
|
2137
|
+
// The hurdle to overcome in order to change pages
|
|
2138
|
+
h * (this.wnd.innerWidth / 3) * (h * n > 0 ? 2 : 1)
|
|
2139
|
+
), d = this.snapOffset(a + c);
|
|
2140
|
+
if (e && d !== this.scrollOffset()) {
|
|
2141
|
+
this.snappingCancelled = !1;
|
|
2142
|
+
const p = (g, y, x, S) => x > S ? y : g + (y - g) * Qt(x / S), u = (
|
|
2143
|
+
/*Math.abs(startX - (this.useTransform ? currentOffset : 0)) < 10 ? 1 : */
|
|
2144
|
+
hi * o
|
|
2145
|
+
);
|
|
2146
|
+
let f;
|
|
2147
|
+
const v = (g) => {
|
|
2148
|
+
if (this.snappingCancelled)
|
|
2149
|
+
return;
|
|
2150
|
+
f || (f = g);
|
|
2151
|
+
const y = g - f, x = p(this.overscroll, 0, y, u), S = p(r, d, y, u);
|
|
2152
|
+
s.scrollLeft = S, this.overscroll !== 0 && (s.style.transform = `translate3d(${-x}px, 0px, 0px)`), y < u ? this.wnd.requestAnimationFrame(v) : (this.clearTouches(), s.style.removeProperty("transform"), s.scrollLeft = d, t || this.reportProgress());
|
|
2153
|
+
};
|
|
2154
|
+
this.wnd.requestAnimationFrame(v);
|
|
2155
|
+
} else
|
|
2156
|
+
s.style.removeProperty("transform"), this.wnd.requestAnimationFrame(() => {
|
|
2157
|
+
s.scrollLeft = d, this.clearTouches(), t || this.reportProgress();
|
|
2158
|
+
});
|
|
2159
|
+
}
|
|
2160
|
+
dragOffset() {
|
|
2161
|
+
return (this.startingX ?? 0) - (this.endingX ?? 0);
|
|
2162
|
+
}
|
|
2163
|
+
clearTouches() {
|
|
2164
|
+
this.startingX = void 0, this.endingX = void 0, this.overscroll = 0;
|
|
2165
|
+
}
|
|
2166
|
+
onTouchStart(e) {
|
|
2167
|
+
switch (e.stopPropagation(), this.takeOverSnap(), e.touches.length) {
|
|
2168
|
+
case 1:
|
|
2169
|
+
break;
|
|
2170
|
+
case 2:
|
|
2171
|
+
this.onTouchEnd(e);
|
|
2172
|
+
return;
|
|
2173
|
+
default: {
|
|
2174
|
+
this.onTouchEnd(e), this.comms.send("tap_more", e.touches.length);
|
|
2175
|
+
return;
|
|
2176
|
+
}
|
|
2177
|
+
}
|
|
2178
|
+
this.startingX = e.touches[0].clientX, this.alreadyScrollLeft = this.doc().scrollLeft, this.touchState = 1;
|
|
2179
|
+
}
|
|
2180
|
+
onTouchEnd(e) {
|
|
2181
|
+
if (this.touchState === 2) {
|
|
2182
|
+
const t = this.dragOffset(), r = this.scrollOffset();
|
|
2183
|
+
this.cachedScrollWidth <= this.wnd.innerWidth ? (this.reportProgress(), t > 5 && this.comms.send("no_more", void 0), t < -5 && this.comms.send("no_less", void 0)) : r < 5 && t < 5 ? (this.alreadyScrollLeft = 0, this.comms.send("no_less", void 0)) : this.cachedScrollWidth - r - this.wnd.innerWidth < 5 && t > 5 && (this.alreadyScrollLeft = this.cachedScrollWidth, this.comms.send("no_more", void 0)), this.snapCurrentOffset(!0), this.comms.send("swipe", t);
|
|
2184
|
+
}
|
|
2185
|
+
this.touchState = 0;
|
|
2186
|
+
}
|
|
2187
|
+
onWidthChange() {
|
|
2188
|
+
this.cachedScrollWidth = this.doc().scrollWidth, this.comms.ready && this.snapCurrentOffset();
|
|
2189
|
+
}
|
|
2190
|
+
onTouchMove(e) {
|
|
2191
|
+
if (this.touchState === 0)
|
|
2192
|
+
return;
|
|
2193
|
+
this.touchState === 1 && (this.touchState = 2, T(this.wnd)), this.endingX = e.touches[0].clientX;
|
|
2194
|
+
const t = this.dragOffset(), r = this.alreadyScrollLeft + t;
|
|
2195
|
+
r < 0 ? (this.overscroll = r, this.doc().style.transform = `translate3d(${-this.overscroll}px, 0px, 0px)`) : r + this.wnd.innerWidth > this.cachedScrollWidth ? (this.overscroll = r, this.doc().style.transform = `translate3d(${-r}px, 0px, 0px)`) : (this.overscroll = 0, this.doc().style.removeProperty("transform"), this.doc().scrollLeft = this.alreadyScrollLeft + t);
|
|
2196
|
+
}
|
|
2197
|
+
mount(e, t) {
|
|
2198
|
+
if (this.wnd = e, this.comms = t, !super.mount(e, t))
|
|
2199
|
+
return !1;
|
|
2200
|
+
const r = e.document.createElement("style");
|
|
2201
|
+
r.dataset.readium = "true", r.id = _e, r.textContent = `
|
|
2202
|
+
@keyframes readium-bounce-l-animation {
|
|
2203
|
+
0%, 100% {transform: translate3d(0, 0, 0);}
|
|
2204
|
+
50% {transform: translate3d(-50px, 0, 0);}
|
|
2205
|
+
}
|
|
2206
|
+
|
|
2207
|
+
@keyframes readium-bounce-r-animation {
|
|
2208
|
+
0%, 100% {transform: translate3d(0, 0, 0);}
|
|
2209
|
+
50% {transform: translate3d(50px, 0, 0);}
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2212
|
+
.readium-bounce-l {
|
|
2213
|
+
animation: readium-bounce-l-animation 150ms ease-out 1;
|
|
2214
|
+
}
|
|
2215
|
+
|
|
2216
|
+
.readium-bounce-r {
|
|
2217
|
+
animation: readium-bounce-r-animation 150ms ease-out 1;
|
|
2218
|
+
}
|
|
2219
|
+
|
|
2220
|
+
html {
|
|
2221
|
+
overflow: hidden;
|
|
2222
|
+
}
|
|
2223
|
+
|
|
2224
|
+
body {
|
|
2225
|
+
-ms-overflow-style: none; /* for Internet Explorer, Edge */
|
|
2226
|
+
}
|
|
2227
|
+
|
|
2228
|
+
* {
|
|
2229
|
+
scrollbar-width: none; /* for Firefox */
|
|
2230
|
+
}
|
|
2231
|
+
|
|
2232
|
+
body::-webkit-scrollbar {
|
|
2233
|
+
display: none; /* for Chrome, Safari, and Opera */
|
|
2234
|
+
}
|
|
2235
|
+
`, e.document.head.appendChild(r);
|
|
2236
|
+
const s = e.ResizeObserver || nt;
|
|
2237
|
+
this.resizeObserver = new s(() => e.requestAnimationFrame(() => {
|
|
2238
|
+
e && Jt(e);
|
|
2239
|
+
})), this.resizeObserver.observe(e.document.body), this.mutationObserver = new MutationObserver(() => {
|
|
2240
|
+
this.wnd.requestAnimationFrame(() => this.cachedScrollWidth = this.doc().scrollWidth);
|
|
2241
|
+
}), e.frameElement && this.mutationObserver.observe(e.frameElement, { attributes: !0, attributeFilter: ["style"] }), this.mutationObserver.observe(e.document, { attributes: !0, attributeFilter: ["style"] });
|
|
2242
|
+
const n = (o) => {
|
|
2243
|
+
const a = this.doc().scrollLeft;
|
|
2244
|
+
return this.doc().scrollLeft = this.snapOffset(o), a !== this.doc().scrollLeft;
|
|
2245
|
+
};
|
|
2246
|
+
return e.addEventListener("orientationchange", this.onWidthChanger), e.addEventListener("resize", this.onWidthChanger), e.requestAnimationFrame(() => this.cachedScrollWidth = this.doc().scrollWidth), t.register("go_progression", C.moduleName, (o, a) => {
|
|
2247
|
+
const h = o;
|
|
2248
|
+
if (h < 0 || h > 1) {
|
|
2249
|
+
t.send("error", {
|
|
2250
|
+
message: "go_progression must be given a position from 0.0 to 1.0"
|
|
2251
|
+
}), a(!1);
|
|
2252
|
+
return;
|
|
2253
|
+
}
|
|
2254
|
+
this.wnd.requestAnimationFrame(() => {
|
|
2255
|
+
this.cachedScrollWidth = this.doc().scrollWidth;
|
|
2256
|
+
const c = this.cachedScrollWidth, d = W(e) ? -1 : 1, p = c * h * d;
|
|
2257
|
+
this.doc().scrollLeft = this.snapOffset(p), this.reportProgress(), T(this.wnd), a(!0);
|
|
2258
|
+
});
|
|
2259
|
+
}), t.register("go_id", C.moduleName, (o, a) => {
|
|
2260
|
+
const h = e.document.getElementById(o);
|
|
2261
|
+
if (!h) {
|
|
2262
|
+
a(!1);
|
|
2263
|
+
return;
|
|
2264
|
+
}
|
|
2265
|
+
this.wnd.requestAnimationFrame(() => {
|
|
2266
|
+
this.doc().scrollLeft = this.snapOffset(h.getBoundingClientRect().left + e.scrollX), this.reportProgress(), T(this.wnd), a(!0);
|
|
2267
|
+
});
|
|
2268
|
+
}), t.register("go_text", C.moduleName, (o, a) => {
|
|
2269
|
+
let h;
|
|
2270
|
+
Array.isArray(o) && (o.length > 1 && (h = o[1]), o = o[0]);
|
|
2271
|
+
const c = q.deserialize(o), d = Oe(this.wnd.document, new I({
|
|
2272
|
+
href: e.location.href,
|
|
2273
|
+
type: "text/html",
|
|
2274
|
+
text: c,
|
|
2275
|
+
locations: h ? new w({
|
|
2276
|
+
otherLocations: /* @__PURE__ */ new Map([
|
|
2277
|
+
["cssSelector", h]
|
|
2278
|
+
])
|
|
2279
|
+
}) : void 0
|
|
2280
|
+
}));
|
|
2281
|
+
if (!d) {
|
|
2282
|
+
a(!1);
|
|
2283
|
+
return;
|
|
2284
|
+
}
|
|
2285
|
+
this.wnd.requestAnimationFrame(() => {
|
|
2286
|
+
this.doc().scrollLeft = this.snapOffset(d.getBoundingClientRect().left + e.scrollX), this.reportProgress(), T(this.wnd), a(!0);
|
|
2287
|
+
});
|
|
2288
|
+
}), t.register("go_end", C.moduleName, (o, a) => {
|
|
2289
|
+
const h = W(e) ? -1 : 1;
|
|
2290
|
+
this.wnd.requestAnimationFrame(() => {
|
|
2291
|
+
this.cachedScrollWidth = this.doc().scrollWidth;
|
|
2292
|
+
const c = this.cachedScrollWidth * h;
|
|
2293
|
+
if (this.doc().scrollLeft === c)
|
|
2294
|
+
return a(!1);
|
|
2295
|
+
this.doc().scrollLeft = this.snapOffset(c), this.reportProgress(), T(this.wnd), a(!0);
|
|
2296
|
+
});
|
|
2297
|
+
}), t.register("go_start", C.moduleName, (o, a) => {
|
|
2298
|
+
this.wnd.requestAnimationFrame(() => {
|
|
2299
|
+
if (this.doc().scrollLeft === 0)
|
|
2300
|
+
return a(!1);
|
|
2301
|
+
this.doc().scrollLeft = 0, this.reportProgress(), T(this.wnd), a(!0);
|
|
2302
|
+
});
|
|
2303
|
+
}), t.register("go_prev", C.moduleName, (o, a) => {
|
|
2304
|
+
this.wnd.requestAnimationFrame(() => {
|
|
2305
|
+
const h = e.scrollX - e.innerWidth, c = W(e) ? -(this.cachedScrollWidth - e.innerWidth) : 0, d = n(Math.max(h, c));
|
|
2306
|
+
d && (this.reportProgress(), T(this.wnd)), a(d);
|
|
2307
|
+
});
|
|
2308
|
+
}), t.register("go_next", C.moduleName, (o, a) => {
|
|
2309
|
+
this.wnd.requestAnimationFrame(() => {
|
|
2310
|
+
const h = e.scrollX + e.innerWidth, c = W(e) ? 0 : this.cachedScrollWidth - e.innerWidth, d = n(Math.min(h, c));
|
|
2311
|
+
d && (this.reportProgress(), T(this.wnd)), a(d);
|
|
2312
|
+
});
|
|
2313
|
+
}), t.register("unfocus", C.moduleName, (o, a) => {
|
|
2314
|
+
this.snappingCancelled = !0, T(this.wnd), a(!0);
|
|
2315
|
+
}), t.register("shake", C.moduleName, (o, a) => {
|
|
2316
|
+
this.shake(), a(!0);
|
|
2317
|
+
}), t.register("focus", C.moduleName, (o, a) => {
|
|
2318
|
+
this.wnd.requestAnimationFrame(() => {
|
|
2319
|
+
this.cachedScrollWidth = this.doc().scrollWidth, this.snapCurrentOffset(!1, !0), this.reportProgress(), a(!0);
|
|
2320
|
+
});
|
|
2321
|
+
}), t.register("first_visible_locator", C.moduleName, (o, a) => {
|
|
2322
|
+
const h = mt(e, !1);
|
|
2323
|
+
this.comms.send("first_visible_locator", h.serialize()), a(!0);
|
|
2324
|
+
}), e.addEventListener("touchstart", this.onTouchStarter, { passive: !0 }), e.addEventListener("touchend", this.onTouchEnder, { passive: !0 }), e.addEventListener("touchmove", this.onTouchMover, { passive: !0 }), e.document.addEventListener("touchstart", () => {
|
|
2325
|
+
}), t.log("ColumnSnapper Mounted"), !0;
|
|
2326
|
+
}
|
|
2327
|
+
unmount(e, t) {
|
|
2328
|
+
var r;
|
|
2329
|
+
return this.snappingCancelled = !0, t.unregisterAll(C.moduleName), this.resizeObserver.disconnect(), this.mutationObserver.disconnect(), e.removeEventListener("touchstart", this.onTouchStarter), e.removeEventListener("touchend", this.onTouchEnder), e.removeEventListener("touchmove", this.onTouchMover), e.removeEventListener("orientationchange", this.onWidthChanger), e.removeEventListener("resize", this.onWidthChanger), (r = e.document.getElementById(_e)) == null || r.remove(), t.log("ColumnSnapper Unmounted"), super.unmount(e, t);
|
|
2330
|
+
}
|
|
2331
|
+
};
|
|
2332
|
+
vt.moduleName = "column_snapper";
|
|
2333
|
+
let ci = vt;
|
|
2334
|
+
const he = {
|
|
2335
|
+
top: "js-iframe-reader-top-anchor",
|
|
2336
|
+
bottom: "js-iframe-reader-bottom-anchor"
|
|
2337
|
+
};
|
|
2338
|
+
class di extends HTMLElement {
|
|
2339
|
+
connectedCallback() {
|
|
2340
|
+
this.setAttribute("aria-hidden", "true"), this.style.setProperty("display", "block", "important"), this.style.setProperty("padding", "0", "important"), this.style.setProperty("margin", "0", "important"), this.style.setProperty("visibility", "hidden", "important");
|
|
2341
|
+
}
|
|
2342
|
+
}
|
|
2343
|
+
function ui(i) {
|
|
2344
|
+
const e = i.getElementsByTagName("body")[0], t = document.createElement("anchor-observer"), r = document.createElement("anchor-observer");
|
|
2345
|
+
t.dataset.readium = "true", r.dataset.readium = "true", t == null || t.setAttribute("id", he.top), t == null || t.style.setProperty("height", "115px", "important"), r == null || r.setAttribute("id", he.bottom), r == null || r.style.setProperty("height", "80px", "important"), e == null || e.insertBefore(t, e.firstChild), e == null || e.appendChild(r);
|
|
2346
|
+
}
|
|
2347
|
+
function pi(i) {
|
|
2348
|
+
var s, n;
|
|
2349
|
+
const e = i.getElementsByTagName("body")[0], t = e == null ? void 0 : e.querySelector(`#${he.top}`), r = e == null ? void 0 : e.querySelector(`#${he.bottom}`);
|
|
2350
|
+
t && ((s = t.parentElement) == null || s.removeChild(t)), r && ((n = r.parentElement) == null || n.removeChild(r));
|
|
2351
|
+
}
|
|
2352
|
+
const je = "readium-scroll-snapper-style", yt = class M extends at {
|
|
2353
|
+
constructor() {
|
|
2354
|
+
super(...arguments), this.createAnchorElements = () => {
|
|
2355
|
+
ui(this.doc());
|
|
2356
|
+
}, this.removeAnchorElements = () => {
|
|
2357
|
+
pi(this.doc());
|
|
2358
|
+
}, this.createCustomElement = () => {
|
|
2359
|
+
customElements.get("anchor-observer") || customElements.define("anchor-observer", di);
|
|
2360
|
+
};
|
|
2361
|
+
}
|
|
2362
|
+
doc() {
|
|
2363
|
+
return this.wnd.document.scrollingElement;
|
|
2364
|
+
}
|
|
2365
|
+
reportProgress(e) {
|
|
2366
|
+
this.comms.send("progress", e);
|
|
2367
|
+
}
|
|
2368
|
+
mount(e, t) {
|
|
2369
|
+
this.wnd = e, this.comms = t;
|
|
2370
|
+
const r = e.document.createElement("style");
|
|
2371
|
+
return r.dataset.readium = "true", r.id = je, r.textContent = `
|
|
2372
|
+
* {
|
|
2373
|
+
scrollbar-width: none; /* for Firefox */
|
|
2374
|
+
}
|
|
2375
|
+
|
|
2376
|
+
body::-webkit-scrollbar {
|
|
2377
|
+
display: none; /* for Chrome, Safari, and Opera */
|
|
2378
|
+
}
|
|
2379
|
+
`, e.document.head.appendChild(r), t.register("go_progression", M.moduleName, (s, n) => {
|
|
2380
|
+
const o = s;
|
|
2381
|
+
if (o < 0 || o > 1) {
|
|
2382
|
+
t.send("error", {
|
|
2383
|
+
message: "go_progression must be given a position from 0.0 to 1.0"
|
|
2384
|
+
}), n(!1);
|
|
2385
|
+
return;
|
|
2386
|
+
}
|
|
2387
|
+
this.wnd.requestAnimationFrame(() => {
|
|
2388
|
+
this.doc().scrollTop = this.doc().offsetHeight * o, this.reportProgress(o), T(this.wnd), n(!0);
|
|
2389
|
+
});
|
|
2390
|
+
}), t.register("go_id", M.moduleName, (s, n) => {
|
|
2391
|
+
const o = e.document.getElementById(s);
|
|
2392
|
+
if (!o) {
|
|
2393
|
+
n(!1);
|
|
2394
|
+
return;
|
|
2395
|
+
}
|
|
2396
|
+
this.wnd.requestAnimationFrame(() => {
|
|
2397
|
+
this.doc().scrollTop = o.getBoundingClientRect().top + e.scrollY - e.innerHeight / 2, this.reportProgress(this.doc().scrollTop / this.doc().offsetHeight), T(this.wnd), n(!0);
|
|
2398
|
+
});
|
|
2399
|
+
}), t.register("go_text", M.moduleName, (s, n) => {
|
|
2400
|
+
let o;
|
|
2401
|
+
Array.isArray(s) && (s.length > 1 && (o = s[1]), s = s[0]);
|
|
2402
|
+
const a = q.deserialize(s), h = Oe(this.wnd.document, new I({
|
|
2403
|
+
href: e.location.href,
|
|
2404
|
+
type: "text/html",
|
|
2405
|
+
text: a,
|
|
2406
|
+
locations: o ? new w({
|
|
2407
|
+
otherLocations: /* @__PURE__ */ new Map([
|
|
2408
|
+
["cssSelector", o]
|
|
2409
|
+
])
|
|
2410
|
+
}) : void 0
|
|
2411
|
+
}));
|
|
2412
|
+
if (!h) {
|
|
2413
|
+
n(!1);
|
|
2414
|
+
return;
|
|
2415
|
+
}
|
|
2416
|
+
this.wnd.requestAnimationFrame(() => {
|
|
2417
|
+
this.doc().scrollTop = h.getBoundingClientRect().top + e.scrollY - e.innerHeight / 2, this.reportProgress(this.doc().scrollTop / this.doc().offsetHeight), T(this.wnd), n(!0);
|
|
2418
|
+
});
|
|
2419
|
+
}), t.register("go_start", M.moduleName, (s, n) => {
|
|
2420
|
+
if (this.doc().scrollTop === 0)
|
|
2421
|
+
return n(!1);
|
|
2422
|
+
this.doc().scrollTop = 0, this.reportProgress(0), n(!0);
|
|
2423
|
+
}), t.register("go_end", M.moduleName, (s, n) => {
|
|
2424
|
+
if (this.doc().scrollTop === 0)
|
|
2425
|
+
return n(!1);
|
|
2426
|
+
this.doc().scrollTop = 0, this.reportProgress(0), n(!0);
|
|
2427
|
+
}), t.register("unfocus", M.moduleName, (s, n) => {
|
|
2428
|
+
T(this.wnd), n(!0);
|
|
2429
|
+
}), t.register([
|
|
2430
|
+
"go_next",
|
|
2431
|
+
"go_prev"
|
|
2432
|
+
], M.moduleName, (s, n) => n(!1)), t.register("focus", M.moduleName, (s, n) => {
|
|
2433
|
+
this.reportProgress(this.doc().scrollTop / this.doc().offsetHeight), n(!0);
|
|
2434
|
+
}), t.register("first_visible_locator", M.moduleName, (s, n) => {
|
|
2435
|
+
const o = mt(e, !0);
|
|
2436
|
+
this.comms.send("first_visible_locator", o.serialize()), n(!0);
|
|
2437
|
+
}), t.log("ScrollSnapper Mounted"), this.createCustomElement(), this.createAnchorElements(), !0;
|
|
2438
|
+
}
|
|
2439
|
+
unmount(e, t) {
|
|
2440
|
+
var r;
|
|
2441
|
+
return t.unregisterAll(M.moduleName), this.removeAnchorElements(), (r = e.document.getElementById(je)) == null || r.remove(), t.log("ScrollSnapper Unmounted"), !0;
|
|
2442
|
+
}
|
|
2443
|
+
};
|
|
2444
|
+
yt.moduleName = "scroll_snapper";
|
|
2445
|
+
let fi = yt;
|
|
2446
|
+
class bt extends ce {
|
|
2447
|
+
constructor() {
|
|
2448
|
+
super(...arguments), this.pointerMoved = !1, this.onPointerUp = this.onPointUp.bind(this), this.onPointerMove = this.onPointMove.bind(this), this.onPointerDown = this.onPointDown.bind(this), this.onContextMenu = this.onContext.bind(this), this.onClicker = this.onClick.bind(this);
|
|
2449
|
+
}
|
|
2450
|
+
onPointUp(e) {
|
|
2451
|
+
var s, n, o, a, h;
|
|
2452
|
+
const t = this.wnd.getSelection();
|
|
2453
|
+
if (t && ((s = t.toString()) == null ? void 0 : s.length) > 0) {
|
|
2454
|
+
const c = (n = t.getRangeAt(0)) == null ? void 0 : n.getClientRects();
|
|
2455
|
+
if (!c || c.length === 0)
|
|
2456
|
+
return;
|
|
2457
|
+
const d = c[0], p = {
|
|
2458
|
+
text: t.toString(),
|
|
2459
|
+
x: d.x,
|
|
2460
|
+
y: d.y,
|
|
2461
|
+
width: d.width,
|
|
2462
|
+
height: d.height,
|
|
2463
|
+
targetFrameSrc: (a = (o = this.wnd) == null ? void 0 : o.location) == null ? void 0 : a.href
|
|
2464
|
+
};
|
|
2465
|
+
this.comms.send("text_selected", p);
|
|
2466
|
+
}
|
|
2467
|
+
if (this.pointerMoved) {
|
|
2468
|
+
this.pointerMoved = !1;
|
|
2469
|
+
return;
|
|
2470
|
+
}
|
|
2471
|
+
if (!(t != null && t.isCollapsed) || !e.isPrimary)
|
|
2472
|
+
return;
|
|
2473
|
+
const r = this.wnd.devicePixelRatio;
|
|
2474
|
+
e.preventDefault(), this.comms.send(e.pointerType === "touch" ? "tap" : "click", {
|
|
2475
|
+
defaultPrevented: e.defaultPrevented,
|
|
2476
|
+
x: e.clientX * r,
|
|
2477
|
+
y: e.clientY * r,
|
|
2478
|
+
targetFrameSrc: this.wnd.location.href,
|
|
2479
|
+
targetElement: e.target.outerHTML,
|
|
2480
|
+
interactiveElement: (h = ft(e.target)) == null ? void 0 : h.outerHTML,
|
|
2481
|
+
cssSelector: this.wnd._readium_cssSelectorGenerator.getCssSelector(e.target)
|
|
2482
|
+
}), this.pointerMoved = !1;
|
|
2483
|
+
}
|
|
2484
|
+
onPointMove(e) {
|
|
2485
|
+
if (e.movementY !== void 0 && e.movementX !== void 0) {
|
|
2486
|
+
(Math.abs(e.movementX) > 1 || Math.abs(e.movementY) > 1) && (this.pointerMoved = !0);
|
|
2487
|
+
return;
|
|
2488
|
+
}
|
|
2489
|
+
this.pointerMoved = !0;
|
|
2490
|
+
}
|
|
2491
|
+
onPointDown() {
|
|
2492
|
+
this.pointerMoved = !1;
|
|
2493
|
+
}
|
|
2494
|
+
onContext(e) {
|
|
2495
|
+
this.onPointUp(e), this.pointerMoved = !1;
|
|
2496
|
+
}
|
|
2497
|
+
onClick(e) {
|
|
2498
|
+
if (e.preventDefault(), !e.isTrusted) {
|
|
2499
|
+
const t = new PointerEvent("pointerup", {
|
|
2500
|
+
isPrimary: !0,
|
|
2501
|
+
pointerType: "mouse",
|
|
2502
|
+
// Not really a better choice than this
|
|
2503
|
+
clientX: e.clientX,
|
|
2504
|
+
clientY: e.clientY
|
|
2505
|
+
});
|
|
2506
|
+
Object.defineProperty(t, "target", { writable: !1, value: e.target }), Object.defineProperty(t, "defaultPrevented", { writable: !1, value: e.defaultPrevented }), this.onPointUp(t);
|
|
2507
|
+
}
|
|
2508
|
+
}
|
|
2509
|
+
mount(e, t) {
|
|
2510
|
+
return this.wnd = e, this.comms = t, e.document.addEventListener("pointerdown", this.onPointerDown), e.document.addEventListener("pointerup", this.onPointerUp), e.document.addEventListener("contextmenu", this.onContextMenu), e.document.addEventListener("pointermove", this.onPointerMove), e.document.addEventListener("click", this.onClicker), t.log("Peripherals Mounted"), !0;
|
|
2511
|
+
}
|
|
2512
|
+
unmount(e, t) {
|
|
2513
|
+
return e.document.removeEventListener("pointerdown", this.onPointerDown), e.document.removeEventListener("pointerup", this.onPointerUp), e.document.removeEventListener("contextmenu", this.onContextMenu), e.document.removeEventListener("pointermove", this.onPointerMove), e.document.removeEventListener("click", this.onClicker), t.log("Peripherals Unmounted"), !0;
|
|
2514
|
+
}
|
|
2515
|
+
}
|
|
2516
|
+
bt.moduleName = "peripherals";
|
|
2517
|
+
const Et = class ve extends ce {
|
|
2518
|
+
constructor() {
|
|
2519
|
+
super(...arguments), this.mediaPlayingCount = 0, this.allAnimations = /* @__PURE__ */ new Set();
|
|
2520
|
+
}
|
|
2521
|
+
wndOnErr(e) {
|
|
2522
|
+
var t;
|
|
2523
|
+
(t = this.comms) == null || t.send("error", {
|
|
2524
|
+
message: e.message,
|
|
2525
|
+
filename: e.filename,
|
|
2526
|
+
lineno: e.lineno,
|
|
2527
|
+
colno: e.colno
|
|
2528
|
+
});
|
|
2529
|
+
}
|
|
2530
|
+
unblock(e) {
|
|
2531
|
+
var t;
|
|
2532
|
+
for (e._readium_blockEvents = !1; ((t = e._readium_blockedEvents) == null ? void 0 : t.length) > 0; ) {
|
|
2533
|
+
const r = e._readium_blockedEvents.shift();
|
|
2534
|
+
switch (r[0]) {
|
|
2535
|
+
case 0:
|
|
2536
|
+
Reflect.apply(r[1], r[2], r[3]);
|
|
2537
|
+
break;
|
|
2538
|
+
case 1:
|
|
2539
|
+
const s = r[1], n = r[2];
|
|
2540
|
+
e.removeEventListener(s.type, e._readium_eventBlocker, !0);
|
|
2541
|
+
const o = new Event(s.type, {
|
|
2542
|
+
bubbles: s.bubbles,
|
|
2543
|
+
cancelable: s.cancelable
|
|
2544
|
+
});
|
|
2545
|
+
n ? n.dispatchEvent(o) : e.dispatchEvent(o);
|
|
2546
|
+
break;
|
|
2547
|
+
}
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
onMediaPlayEvent() {
|
|
2551
|
+
var e;
|
|
2552
|
+
this.mediaPlayingCount++, (e = this.comms) == null || e.send("media_play", this.mediaPlayingCount);
|
|
2553
|
+
}
|
|
2554
|
+
onMediaPauseEvent() {
|
|
2555
|
+
var e;
|
|
2556
|
+
this.mediaPlayingCount > 0 && this.mediaPlayingCount--, (e = this.comms) == null || e.send("media_pause", this.mediaPlayingCount);
|
|
2557
|
+
}
|
|
2558
|
+
pauseAllMedia(e) {
|
|
2559
|
+
const t = e.document.querySelectorAll("audio,video");
|
|
2560
|
+
for (let r = 0; r < t.length; r++)
|
|
2561
|
+
t[r].pause();
|
|
2562
|
+
}
|
|
2563
|
+
mount(e, t) {
|
|
2564
|
+
this.comms = t, e.addEventListener(
|
|
2565
|
+
"error",
|
|
2566
|
+
this.wndOnErr,
|
|
2567
|
+
!1
|
|
2568
|
+
), "getAnimations" in e.document && e.document.getAnimations().forEach((s) => {
|
|
2569
|
+
s.cancel(), this.allAnimations.add(s);
|
|
2570
|
+
}), t.register("activate", ve.moduleName, (s, n) => {
|
|
2571
|
+
this.allAnimations.forEach((o) => {
|
|
2572
|
+
o.cancel(), o.play();
|
|
2573
|
+
}), n(!0);
|
|
2574
|
+
}), t.register("unfocus", ve.moduleName, (s, n) => {
|
|
2575
|
+
this.pauseAllMedia(e), this.allAnimations.forEach((o) => o.pause()), n(!0);
|
|
2576
|
+
});
|
|
2577
|
+
const r = e.document.querySelectorAll("audio,video");
|
|
2578
|
+
for (let s = 0; s < r.length; s++) {
|
|
2579
|
+
const n = r[s];
|
|
2580
|
+
n.addEventListener("play", this.onMediaPlayEvent, {
|
|
2581
|
+
passive: !0
|
|
2582
|
+
}), n.addEventListener("pause", this.onMediaPauseEvent, {
|
|
2583
|
+
passive: !0
|
|
2584
|
+
});
|
|
2585
|
+
}
|
|
2586
|
+
return t.log("Setup Mounted"), !0;
|
|
2587
|
+
}
|
|
2588
|
+
unmount(e, t) {
|
|
2589
|
+
return e.removeEventListener("error", this.wndOnErr), e.removeEventListener("play", this.onMediaPlayEvent), e.removeEventListener("pause", this.onMediaPauseEvent), this.allAnimations.forEach((r) => r.cancel()), this.allAnimations.clear(), t.log("Setup Unmounted"), !0;
|
|
2590
|
+
}
|
|
2591
|
+
};
|
|
2592
|
+
Et.moduleName = "setup";
|
|
2593
|
+
let xt = Et;
|
|
2594
|
+
function mi(i, e) {
|
|
2595
|
+
return i.document.documentElement.style.getPropertyValue(e);
|
|
2596
|
+
}
|
|
2597
|
+
function ye(i, e, t) {
|
|
2598
|
+
i.document.documentElement.style.setProperty(e, t);
|
|
2599
|
+
}
|
|
2600
|
+
function wt(i, e) {
|
|
2601
|
+
i.document.documentElement.style.removeProperty(e);
|
|
2602
|
+
}
|
|
2603
|
+
const Ge = "readium-viewport", Tt = class V extends xt {
|
|
2604
|
+
onViewportWidthChanged(e) {
|
|
2605
|
+
const t = e.target;
|
|
2606
|
+
ye(t, "--RS__viewportWidth", `${t.innerWidth}px`);
|
|
2607
|
+
}
|
|
2608
|
+
mount(e, t) {
|
|
2609
|
+
if (!super.mount(e, t))
|
|
2610
|
+
return !1;
|
|
2611
|
+
const r = e.document.createElement("meta");
|
|
2612
|
+
return r.dataset.readium = "true", r.setAttribute("name", "viewport"), r.setAttribute("id", Ge), r.setAttribute(
|
|
2613
|
+
"content",
|
|
2614
|
+
"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no"
|
|
2615
|
+
), e.document.head.appendChild(r), e.addEventListener("orientationchange", this.onViewportWidthChanged), e.addEventListener("resize", this.onViewportWidthChanged), this.onViewportWidthChanged({
|
|
2616
|
+
target: e
|
|
2617
|
+
}), t.register("set_property", V.moduleName, (s, n) => {
|
|
2618
|
+
const o = s;
|
|
2619
|
+
ye(e, o[0], o[1]), n(!0);
|
|
2620
|
+
}), t.register("remove_property", V.moduleName, (s, n) => {
|
|
2621
|
+
wt(e, s), n(!0);
|
|
2622
|
+
}), t.register("activate", V.moduleName, (s, n) => {
|
|
2623
|
+
this.unblock(e), n(!0);
|
|
2624
|
+
}), t.log("ReflowableSetup Mounted"), !0;
|
|
2625
|
+
}
|
|
2626
|
+
unmount(e, t) {
|
|
2627
|
+
var r;
|
|
2628
|
+
return t.unregisterAll(V.moduleName), (r = e.document.head.querySelector(`#${Ge}`)) == null || r.remove(), e.removeEventListener("orientationchange", this.onViewportWidthChanged), t.log("ReflowableSetup Unmounted"), super.unmount(e, t);
|
|
2629
|
+
}
|
|
2630
|
+
};
|
|
2631
|
+
Tt.moduleName = "reflowable_setup";
|
|
2632
|
+
let gi = Tt;
|
|
2633
|
+
const Ye = "readium-fixed-style", St = class L extends xt {
|
|
2634
|
+
mount(e, t) {
|
|
2635
|
+
if (!super.mount(e, t))
|
|
2636
|
+
return !1;
|
|
2637
|
+
const r = e.document.createElement("style");
|
|
2638
|
+
return r.id = Ye, r.dataset.readium = "true", r.textContent = `
|
|
2639
|
+
html, body {
|
|
2640
|
+
text-size-adjust: none;
|
|
2641
|
+
-ms-text-size-adjust: none;
|
|
2642
|
+
-webkit-text-size-adjust: none;
|
|
2643
|
+
-moz-text-size-adjust: none;
|
|
2644
|
+
|
|
2645
|
+
/* Fight Safari pinches */
|
|
2646
|
+
touch-action: none !important;
|
|
2647
|
+
min-height: 100%;
|
|
2648
|
+
|
|
2649
|
+
/*cursor: var() TODO*/
|
|
2650
|
+
}`, e.document.head.appendChild(r), t.register("set_property", L.moduleName, (s, n) => {
|
|
2651
|
+
const o = s;
|
|
2652
|
+
ye(e, o[0], o[1]), n(!0);
|
|
2653
|
+
}), t.register("remove_property", L.moduleName, (s, n) => {
|
|
2654
|
+
wt(e, s), n(!0);
|
|
2655
|
+
}), t.register("first_visible_locator", L.moduleName, (s, n) => n(!1)), t.register("unfocus", L.moduleName, (s, n) => {
|
|
2656
|
+
T(e), n(!0);
|
|
2657
|
+
}), t.register([
|
|
2658
|
+
"focus",
|
|
2659
|
+
"go_next",
|
|
2660
|
+
"go_prev",
|
|
2661
|
+
"go_id",
|
|
2662
|
+
"go_end",
|
|
2663
|
+
"go_start",
|
|
2664
|
+
"go_text",
|
|
2665
|
+
"go_progression"
|
|
2666
|
+
], L.moduleName, (s, n) => n(!0)), t.register("activate", L.moduleName, (s, n) => {
|
|
2667
|
+
this.unblock(e), n(!0);
|
|
2668
|
+
}), t.log("FixedSetup Mounted"), !0;
|
|
2669
|
+
}
|
|
2670
|
+
unmount(e, t) {
|
|
2671
|
+
var r;
|
|
2672
|
+
return t.unregisterAll(L.moduleName), (r = e.document.getElementById(Ye)) == null || r.remove(), t.log("FixedSetup Unmounted"), super.unmount(e, t);
|
|
2673
|
+
}
|
|
2674
|
+
};
|
|
2675
|
+
St.moduleName = "fixed_setup";
|
|
2676
|
+
let vi = St;
|
|
2677
|
+
function yi(i, e) {
|
|
2678
|
+
let t = i.getClientRects();
|
|
2679
|
+
t.length || i.commonAncestorContainer.nodeType === Node.ELEMENT_NODE && (t = i.commonAncestorContainer.getClientRects());
|
|
2680
|
+
const r = 1, s = [];
|
|
2681
|
+
for (const c of t)
|
|
2682
|
+
s.push({
|
|
2683
|
+
bottom: c.bottom,
|
|
2684
|
+
height: c.height,
|
|
2685
|
+
left: c.left,
|
|
2686
|
+
right: c.right,
|
|
2687
|
+
top: c.top,
|
|
2688
|
+
width: c.width
|
|
2689
|
+
});
|
|
2690
|
+
const n = Ct(
|
|
2691
|
+
s,
|
|
2692
|
+
r,
|
|
2693
|
+
e
|
|
2694
|
+
), o = Ei(n, r), a = Pt(o), h = 2 * 2;
|
|
2695
|
+
for (let c = a.length - 1; c >= 0; c--) {
|
|
2696
|
+
const d = a[c];
|
|
2697
|
+
if (!(d.width * d.height > h))
|
|
2698
|
+
if (a.length > 1)
|
|
2699
|
+
a.splice(c, 1);
|
|
2700
|
+
else
|
|
2701
|
+
break;
|
|
2702
|
+
}
|
|
2703
|
+
return a;
|
|
2704
|
+
}
|
|
2705
|
+
function Ct(i, e, t) {
|
|
2706
|
+
for (let r = 0; r < i.length; r++)
|
|
2707
|
+
for (let s = r + 1; s < i.length; s++) {
|
|
2708
|
+
const n = i[r], o = i[s];
|
|
2709
|
+
if (n === o)
|
|
2710
|
+
continue;
|
|
2711
|
+
const a = A(n.top, o.top, e) && A(n.bottom, o.bottom, e), h = A(n.left, o.left, e) && A(n.right, o.right, e);
|
|
2712
|
+
if ((h && !t || a && !h) && Ot(n, o, e)) {
|
|
2713
|
+
const u = i.filter((v) => v !== n && v !== o), f = bi(n, o);
|
|
2714
|
+
return u.push(f), Ct(
|
|
2715
|
+
u,
|
|
2716
|
+
e,
|
|
2717
|
+
t
|
|
2718
|
+
);
|
|
2719
|
+
}
|
|
2720
|
+
}
|
|
2721
|
+
return i;
|
|
2722
|
+
}
|
|
2723
|
+
function bi(i, e) {
|
|
2724
|
+
const t = Math.min(i.left, e.left), r = Math.max(i.right, e.right), s = Math.min(i.top, e.top), n = Math.max(i.bottom, e.bottom);
|
|
2725
|
+
return {
|
|
2726
|
+
bottom: n,
|
|
2727
|
+
height: n - s,
|
|
2728
|
+
left: t,
|
|
2729
|
+
right: r,
|
|
2730
|
+
top: s,
|
|
2731
|
+
width: r - t
|
|
2732
|
+
};
|
|
2733
|
+
}
|
|
2734
|
+
function Ei(i, e) {
|
|
2735
|
+
const t = new Set(i);
|
|
2736
|
+
for (const r of i) {
|
|
2737
|
+
if (!(r.width > 1 && r.height > 1)) {
|
|
2738
|
+
t.delete(r);
|
|
2739
|
+
continue;
|
|
2740
|
+
}
|
|
2741
|
+
for (const n of i)
|
|
2742
|
+
if (r !== n && t.has(n) && xi(n, r, e)) {
|
|
2743
|
+
t.delete(r);
|
|
2744
|
+
break;
|
|
2745
|
+
}
|
|
2746
|
+
}
|
|
2747
|
+
return Array.from(t);
|
|
2748
|
+
}
|
|
2749
|
+
function xi(i, e, t) {
|
|
2750
|
+
return ie(i, e.left, e.top, t) && ie(i, e.right, e.top, t) && ie(i, e.left, e.bottom, t) && ie(i, e.right, e.bottom, t);
|
|
2751
|
+
}
|
|
2752
|
+
function ie(i, e, t, r) {
|
|
2753
|
+
return (i.left < e || A(i.left, e, r)) && (i.right > e || A(i.right, e, r)) && (i.top < t || A(i.top, t, r)) && (i.bottom > t || A(i.bottom, t, r));
|
|
2754
|
+
}
|
|
2755
|
+
function Pt(i) {
|
|
2756
|
+
for (let e = 0; e < i.length; e++)
|
|
2757
|
+
for (let t = e + 1; t < i.length; t++) {
|
|
2758
|
+
const r = i[e], s = i[t];
|
|
2759
|
+
if (r !== s && Ot(r, s, -1)) {
|
|
2760
|
+
let n = [], o;
|
|
2761
|
+
const a = Ze(r, s);
|
|
2762
|
+
if (a.length === 1)
|
|
2763
|
+
n = a, o = r;
|
|
2764
|
+
else {
|
|
2765
|
+
const c = Ze(s, r);
|
|
2766
|
+
a.length < c.length ? (n = a, o = r) : (n = c, o = s);
|
|
2767
|
+
}
|
|
2768
|
+
const h = i.filter((c) => c !== o);
|
|
2769
|
+
return Array.prototype.push.apply(h, n), Pt(h);
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2772
|
+
return i;
|
|
2773
|
+
}
|
|
2774
|
+
function Ze(i, e) {
|
|
2775
|
+
const t = wi(e, i);
|
|
2776
|
+
if (t.height === 0 || t.width === 0)
|
|
2777
|
+
return [i];
|
|
2778
|
+
const r = [];
|
|
2779
|
+
{
|
|
2780
|
+
const s = {
|
|
2781
|
+
bottom: i.bottom,
|
|
2782
|
+
height: 0,
|
|
2783
|
+
left: i.left,
|
|
2784
|
+
right: t.left,
|
|
2785
|
+
top: i.top,
|
|
2786
|
+
width: 0
|
|
2787
|
+
};
|
|
2788
|
+
s.width = s.right - s.left, s.height = s.bottom - s.top, s.height !== 0 && s.width !== 0 && r.push(s);
|
|
2789
|
+
}
|
|
2790
|
+
{
|
|
2791
|
+
const s = {
|
|
2792
|
+
bottom: t.top,
|
|
2793
|
+
height: 0,
|
|
2794
|
+
left: t.left,
|
|
2795
|
+
right: t.right,
|
|
2796
|
+
top: i.top,
|
|
2797
|
+
width: 0
|
|
2798
|
+
};
|
|
2799
|
+
s.width = s.right - s.left, s.height = s.bottom - s.top, s.height !== 0 && s.width !== 0 && r.push(s);
|
|
2800
|
+
}
|
|
2801
|
+
{
|
|
2802
|
+
const s = {
|
|
2803
|
+
bottom: i.bottom,
|
|
2804
|
+
height: 0,
|
|
2805
|
+
left: t.left,
|
|
2806
|
+
right: t.right,
|
|
2807
|
+
top: t.bottom,
|
|
2808
|
+
width: 0
|
|
2809
|
+
};
|
|
2810
|
+
s.width = s.right - s.left, s.height = s.bottom - s.top, s.height !== 0 && s.width !== 0 && r.push(s);
|
|
2811
|
+
}
|
|
2812
|
+
{
|
|
2813
|
+
const s = {
|
|
2814
|
+
bottom: i.bottom,
|
|
2815
|
+
height: 0,
|
|
2816
|
+
left: t.right,
|
|
2817
|
+
right: i.right,
|
|
2818
|
+
top: i.top,
|
|
2819
|
+
width: 0
|
|
2820
|
+
};
|
|
2821
|
+
s.width = s.right - s.left, s.height = s.bottom - s.top, s.height !== 0 && s.width !== 0 && r.push(s);
|
|
2822
|
+
}
|
|
2823
|
+
return r;
|
|
2824
|
+
}
|
|
2825
|
+
function wi(i, e) {
|
|
2826
|
+
const t = Math.max(i.left, e.left), r = Math.min(i.right, e.right), s = Math.max(i.top, e.top), n = Math.min(i.bottom, e.bottom);
|
|
2827
|
+
return {
|
|
2828
|
+
bottom: n,
|
|
2829
|
+
height: Math.max(0, n - s),
|
|
2830
|
+
left: t,
|
|
2831
|
+
right: r,
|
|
2832
|
+
top: s,
|
|
2833
|
+
width: Math.max(0, r - t)
|
|
2834
|
+
};
|
|
2835
|
+
}
|
|
2836
|
+
function Ot(i, e, t) {
|
|
2837
|
+
return (i.left < e.right || t >= 0 && A(i.left, e.right, t)) && (e.left < i.right || t >= 0 && A(e.left, i.right, t)) && (i.top < e.bottom || t >= 0 && A(i.top, e.bottom, t)) && (e.top < i.bottom || t >= 0 && A(e.top, i.bottom, t));
|
|
2838
|
+
}
|
|
2839
|
+
function A(i, e, t) {
|
|
2840
|
+
return Math.abs(i - e) <= t;
|
|
2841
|
+
}
|
|
2842
|
+
const Ti = window.ResizeObserver || nt, Si = "Highlight" in window, Ke = ["IMG", "IMAGE", "AUDIO", "VIDEO", "SVG"];
|
|
2843
|
+
class Ci {
|
|
2844
|
+
/**
|
|
2845
|
+
* Creates a DecorationGroup object
|
|
2846
|
+
* @param id Unique HTML ID-adhering name of the group
|
|
2847
|
+
* @param name Human-readable name of the group
|
|
2848
|
+
*/
|
|
2849
|
+
constructor(e, t, r, s) {
|
|
2850
|
+
this.wnd = e, this.comms = t, this.id = r, this.name = s, this.items = [], this.lastItemId = 0, this.container = void 0, this.activateable = !1, this.experimentalHighlights = !1, this.currentRender = 0, Si && (this.experimentalHighlights = !0, this.notTextFlag = /* @__PURE__ */ new Map());
|
|
2851
|
+
}
|
|
2852
|
+
get activeable() {
|
|
2853
|
+
return this.activateable;
|
|
2854
|
+
}
|
|
2855
|
+
set activeable(e) {
|
|
2856
|
+
this.activateable = e;
|
|
2857
|
+
}
|
|
2858
|
+
/**
|
|
2859
|
+
* Adds a new decoration to the group.
|
|
2860
|
+
* @param decoration Decoration to add
|
|
2861
|
+
*/
|
|
2862
|
+
add(e) {
|
|
2863
|
+
var o, a, h, c;
|
|
2864
|
+
const t = `${this.id}-${this.lastItemId++}`, r = Oe(this.wnd.document, e.locator);
|
|
2865
|
+
if (!r) {
|
|
2866
|
+
this.comms.log("Can't locate DOM range for decoration", e);
|
|
2867
|
+
return;
|
|
2868
|
+
}
|
|
2869
|
+
const s = r.commonAncestorContainer;
|
|
2870
|
+
s.nodeType !== Node.TEXT_NODE && this.experimentalHighlights && (Ke.includes(s.nodeName.toUpperCase()) && ((o = this.notTextFlag) == null || o.set(t, !0)), s.querySelector(Ke.join(", ").toLowerCase()) && ((a = this.notTextFlag) == null || a.set(t, !0)), (((h = s.textContent) == null ? void 0 : h.trim()) || "").length === 0 && ((c = this.notTextFlag) == null || c.set(t, !0)));
|
|
2871
|
+
const n = {
|
|
2872
|
+
decoration: e,
|
|
2873
|
+
id: t,
|
|
2874
|
+
range: r
|
|
2875
|
+
};
|
|
2876
|
+
this.items.push(n), this.layout(n), this.renderLayout([n]);
|
|
2877
|
+
}
|
|
2878
|
+
/**
|
|
2879
|
+
* Removes the decoration with given ID from the group.
|
|
2880
|
+
* @param identifier ID of item to remove
|
|
2881
|
+
*/
|
|
2882
|
+
remove(e) {
|
|
2883
|
+
var s, n;
|
|
2884
|
+
const t = this.items.findIndex((o) => o.decoration.id === e);
|
|
2885
|
+
if (t < 0)
|
|
2886
|
+
return;
|
|
2887
|
+
const r = this.items[t];
|
|
2888
|
+
if (this.items.splice(t, 1), r.clickableElements = void 0, r.container && (r.container.remove(), r.container = void 0), this.experimentalHighlights && !((s = this.notTextFlag) != null && s.has(r.id))) {
|
|
2889
|
+
const o = this.wnd.CSS.highlights.get(this.id);
|
|
2890
|
+
o == null || o.delete(r.range);
|
|
2891
|
+
}
|
|
2892
|
+
(n = this.notTextFlag) == null || n.delete(r.id);
|
|
2893
|
+
}
|
|
2894
|
+
/**
|
|
2895
|
+
* Notifies that the given decoration was modified and needs to be updated.
|
|
2896
|
+
* @param decoration Decoration to update
|
|
2897
|
+
*/
|
|
2898
|
+
update(e) {
|
|
2899
|
+
this.remove(e.id), this.add(e);
|
|
2900
|
+
}
|
|
2901
|
+
/**
|
|
2902
|
+
* Removes all decorations from this group.
|
|
2903
|
+
*/
|
|
2904
|
+
clear() {
|
|
2905
|
+
var e;
|
|
2906
|
+
this.clearContainer(), this.items.length = 0, (e = this.notTextFlag) == null || e.clear();
|
|
2907
|
+
}
|
|
2908
|
+
/**
|
|
2909
|
+
* Recreates the decoration elements.
|
|
2910
|
+
* To be called after reflowing the resource, for example.
|
|
2911
|
+
*/
|
|
2912
|
+
requestLayout() {
|
|
2913
|
+
this.wnd.cancelAnimationFrame(this.currentRender), this.clearContainer(), this.items.forEach((e) => this.layout(e)), this.renderLayout(this.items);
|
|
2914
|
+
}
|
|
2915
|
+
experimentalLayout(e) {
|
|
2916
|
+
var s, n;
|
|
2917
|
+
const [t, r] = this.requireContainer(!0);
|
|
2918
|
+
r.add(e.range), t.innerHTML = `
|
|
2919
|
+
::highlight(${this.id}) {
|
|
2920
|
+
color: black;
|
|
2921
|
+
background-color: ${((n = (s = e.decoration) == null ? void 0 : s.style) == null ? void 0 : n.tint) ?? "yellow"};
|
|
2922
|
+
}`;
|
|
2923
|
+
}
|
|
2924
|
+
/**
|
|
2925
|
+
* Layouts a single DecorationItem.
|
|
2926
|
+
* @param item
|
|
2927
|
+
*/
|
|
2928
|
+
layout(e) {
|
|
2929
|
+
var v, g, y, x, S;
|
|
2930
|
+
if (this.experimentalHighlights && !((v = this.notTextFlag) != null && v.has(e.id)))
|
|
2931
|
+
return this.experimentalLayout(e);
|
|
2932
|
+
const t = this.wnd.document.createElement("div");
|
|
2933
|
+
t.setAttribute("id", e.id), t.style.setProperty("pointer-events", "none");
|
|
2934
|
+
const r = this.wnd.innerWidth, s = parseInt(
|
|
2935
|
+
getComputedStyle(this.wnd.document.documentElement).getPropertyValue(
|
|
2936
|
+
"column-count"
|
|
2937
|
+
)
|
|
2938
|
+
), n = r / (s || 1), o = this.wnd.document.scrollingElement, a = o.scrollLeft, h = o.scrollTop, c = (m, E, O) => {
|
|
2939
|
+
var Y, Z, B, D, K, J;
|
|
2940
|
+
if (m.style.position = "absolute", ((Z = (Y = e.decoration) == null ? void 0 : Y.style) == null ? void 0 : Z.width) === "viewport") {
|
|
2941
|
+
m.style.width = `${r}px`, m.style.height = `${E.height}px`;
|
|
2942
|
+
let U = Math.floor(E.left / r) * r;
|
|
2943
|
+
m.style.left = `${U + a}px`, m.style.top = `${E.top + h}px`;
|
|
2944
|
+
} else if (((D = (B = e.decoration) == null ? void 0 : B.style) == null ? void 0 : D.width) === "bounds")
|
|
2945
|
+
m.style.width = `${O.width}px`, m.style.height = `${E.height}px`, m.style.left = `${O.left + a}px`, m.style.top = `${E.top + h}px`;
|
|
2946
|
+
else if (((J = (K = e.decoration) == null ? void 0 : K.style) == null ? void 0 : J.width) === "page") {
|
|
2947
|
+
m.style.width = `${n}px`, m.style.height = `${E.height}px`;
|
|
2948
|
+
let U = Math.floor(E.left / n) * n;
|
|
2949
|
+
m.style.left = `${U + a}px`, m.style.top = `${E.top + h}px`;
|
|
2950
|
+
} else
|
|
2951
|
+
m.style.width = `${E.width}px`, m.style.height = `${E.height}px`, m.style.left = `${E.left + a}px`, m.style.top = `${E.top + h}px`;
|
|
2952
|
+
}, d = e.range.getBoundingClientRect();
|
|
2953
|
+
let p = this.wnd.document.createElement("template");
|
|
2954
|
+
const u = mi(this.wnd, "--USER__appearance") === "readium-night-on";
|
|
2955
|
+
p.innerHTML = `
|
|
2956
|
+
<div
|
|
2957
|
+
class="r2-highlight-0"
|
|
2958
|
+
style="${[
|
|
2959
|
+
`background-color: ${((y = (g = e.decoration) == null ? void 0 : g.style) == null ? void 0 : y.tint) ?? "yellow"} !important`,
|
|
2960
|
+
//"opacity: 0.3 !important",
|
|
2961
|
+
`mix-blend-mode: ${u ? "exclusion" : "multiply"} !important`,
|
|
2962
|
+
"opacity: 1 !important",
|
|
2963
|
+
"box-sizing: border-box !important"
|
|
2964
|
+
].join("; ")}"
|
|
2965
|
+
>
|
|
2966
|
+
</div>
|
|
2967
|
+
`.trim();
|
|
2968
|
+
const f = p.content.firstElementChild;
|
|
2969
|
+
if (((S = (x = e.decoration) == null ? void 0 : x.style) == null ? void 0 : S.layout) === "bounds") {
|
|
2970
|
+
const m = f.cloneNode(!0);
|
|
2971
|
+
m.style.setProperty("pointer-events", "none"), c(m, d, d), t.append(m);
|
|
2972
|
+
} else {
|
|
2973
|
+
let m = yi(
|
|
2974
|
+
e.range,
|
|
2975
|
+
!0
|
|
2976
|
+
// doNotMergeHorizontallyAlignedRects
|
|
2977
|
+
);
|
|
2978
|
+
m = m.sort((E, O) => E.top < O.top ? -1 : E.top > O.top ? 1 : 0);
|
|
2979
|
+
for (let E of m) {
|
|
2980
|
+
const O = f.cloneNode(!0);
|
|
2981
|
+
O.style.setProperty("pointer-events", "none"), c(O, E, d), t.append(O);
|
|
2982
|
+
}
|
|
2983
|
+
}
|
|
2984
|
+
e.container = t, e.clickableElements = Array.from(
|
|
2985
|
+
t.querySelectorAll("[data-activable='1']")
|
|
2986
|
+
), e.clickableElements.length || (e.clickableElements = Array.from(t.children));
|
|
2987
|
+
}
|
|
2988
|
+
renderLayout(e) {
|
|
2989
|
+
this.wnd.cancelAnimationFrame(this.currentRender), this.currentRender = this.wnd.requestAnimationFrame(() => {
|
|
2990
|
+
if (e = e.filter((r) => {
|
|
2991
|
+
var s;
|
|
2992
|
+
return !this.experimentalHighlights || !!((s = this.notTextFlag) != null && s.has(r.id));
|
|
2993
|
+
}), !e || e.length === 0)
|
|
2994
|
+
return;
|
|
2995
|
+
this.requireContainer().append(...e.map((r) => r.container).filter((r) => !!r));
|
|
2996
|
+
});
|
|
2997
|
+
}
|
|
2998
|
+
/**
|
|
2999
|
+
* Returns the group container element, after making sure it exists.
|
|
3000
|
+
* @returns Group's container
|
|
3001
|
+
*/
|
|
3002
|
+
requireContainer(e = !1) {
|
|
3003
|
+
if (e) {
|
|
3004
|
+
let t;
|
|
3005
|
+
this.wnd.document.getElementById(`${this.id}-style`) ? t = this.wnd.document.getElementById(`${this.id}-style`) : (t = this.wnd.document.createElement("style"), t.dataset.readium = "true", t.id = `${this.id}-style`, this.wnd.document.head.appendChild(t));
|
|
3006
|
+
let r;
|
|
3007
|
+
return this.wnd.CSS.highlights.has(this.id) ? r = this.wnd.CSS.highlights.get(this.id) : (r = new this.wnd.Highlight(), this.wnd.CSS.highlights.set(this.id, r)), [t, r];
|
|
3008
|
+
}
|
|
3009
|
+
return this.container || (this.container = this.wnd.document.createElement("div"), this.container.setAttribute("id", this.id), this.container.dataset.group = this.name, this.container.dataset.readium = "true", this.container.style.setProperty("pointer-events", "none"), this.container.style.display = "contents", this.wnd.document.body.append(this.container)), this.container;
|
|
3010
|
+
}
|
|
3011
|
+
/**
|
|
3012
|
+
* Removes the group container.
|
|
3013
|
+
*/
|
|
3014
|
+
clearContainer() {
|
|
3015
|
+
this.experimentalHighlights && this.wnd.CSS.highlights.delete(this.id), this.container && (this.container.remove(), this.container = void 0);
|
|
3016
|
+
}
|
|
3017
|
+
}
|
|
3018
|
+
const At = class be extends ce {
|
|
3019
|
+
constructor() {
|
|
3020
|
+
super(...arguments), this.resizeFrame = 0, this.lastGroupId = 0, this.groups = /* @__PURE__ */ new Map(), this.handleResizer = this.handleResize.bind(this);
|
|
3021
|
+
}
|
|
3022
|
+
cleanup() {
|
|
3023
|
+
this.groups.forEach((e) => e.clear()), this.groups.clear();
|
|
3024
|
+
}
|
|
3025
|
+
handleResize() {
|
|
3026
|
+
this.wnd.clearTimeout(this.resizeFrame), this.resizeFrame = this.wnd.setTimeout(() => {
|
|
3027
|
+
this.groups.forEach((e) => {
|
|
3028
|
+
e.experimentalHighlights || e.requestLayout();
|
|
3029
|
+
});
|
|
3030
|
+
}, 50);
|
|
3031
|
+
}
|
|
3032
|
+
mount(e, t) {
|
|
3033
|
+
return this.wnd = e, t.register("decorate", be.moduleName, (r, s) => {
|
|
3034
|
+
const n = r;
|
|
3035
|
+
n.decoration && n.decoration.locator && (n.decoration.locator = I.deserialize(n.decoration.locator)), this.groups.has(n.group) || this.groups.set(n.group, new Ci(
|
|
3036
|
+
e,
|
|
3037
|
+
t,
|
|
3038
|
+
`readium-decoration-${this.lastGroupId++}`,
|
|
3039
|
+
n.group
|
|
3040
|
+
));
|
|
3041
|
+
const o = this.groups.get(n.group);
|
|
3042
|
+
switch (n.action) {
|
|
3043
|
+
case "add":
|
|
3044
|
+
o == null || o.add(n.decoration);
|
|
3045
|
+
break;
|
|
3046
|
+
case "remove":
|
|
3047
|
+
o == null || o.remove(n.decoration.id);
|
|
3048
|
+
break;
|
|
3049
|
+
case "clear":
|
|
3050
|
+
o == null || o.clear();
|
|
3051
|
+
break;
|
|
3052
|
+
case "update":
|
|
3053
|
+
o == null || o.update(n.decoration);
|
|
3054
|
+
break;
|
|
3055
|
+
}
|
|
3056
|
+
s(!0);
|
|
3057
|
+
}), this.resizeObserver = new Ti(() => e.requestAnimationFrame(() => this.handleResize())), this.resizeObserver.observe(e.document.body), e.addEventListener("orientationchange", this.handleResizer), e.addEventListener("resize", this.handleResizer), t.log("Decorator Mounted"), !0;
|
|
3058
|
+
}
|
|
3059
|
+
unmount(e, t) {
|
|
3060
|
+
return e.removeEventListener("orientationchange", this.handleResizer), e.removeEventListener("resize", this.handleResizer), t.unregisterAll(be.moduleName), this.resizeObserver.disconnect(), this.cleanup(), t.log("Decorator Unmounted"), !0;
|
|
3061
|
+
}
|
|
3062
|
+
};
|
|
3063
|
+
At.moduleName = "decorator";
|
|
3064
|
+
let Pi = At;
|
|
3065
|
+
const Oi = [
|
|
3066
|
+
"fixed_setup",
|
|
3067
|
+
"decorator",
|
|
3068
|
+
"peripherals"
|
|
3069
|
+
], Ai = [
|
|
3070
|
+
"reflowable_setup",
|
|
3071
|
+
"decorator",
|
|
3072
|
+
"peripherals",
|
|
3073
|
+
"column_snapper",
|
|
3074
|
+
"scroll_snapper"
|
|
3075
|
+
], Je = new Map([
|
|
3076
|
+
// All modules go here
|
|
3077
|
+
vi,
|
|
3078
|
+
gi,
|
|
3079
|
+
bt,
|
|
3080
|
+
Pi,
|
|
3081
|
+
ci,
|
|
3082
|
+
fi
|
|
3083
|
+
].map((i) => [i.moduleName, i]));
|
|
3084
|
+
class Mi {
|
|
3085
|
+
/**
|
|
3086
|
+
* @param wnd Window instance to operate on
|
|
3087
|
+
* @param initialModules List of initial modules to load
|
|
3088
|
+
*/
|
|
3089
|
+
constructor(e = window, t = []) {
|
|
3090
|
+
this.loadedModules = [], this.wnd = e, this.comms = new Rt(e);
|
|
3091
|
+
const r = [...new Set(t)];
|
|
3092
|
+
if (r.length) {
|
|
3093
|
+
if (typeof e > "u")
|
|
3094
|
+
throw Error("Loader is not in a web browser");
|
|
3095
|
+
e.parent !== e && this.comms.log("Loader is probably in a frame"), this.loadedModules = r.map((s) => {
|
|
3096
|
+
const n = this.loadModule(s);
|
|
3097
|
+
if (n)
|
|
3098
|
+
return n.mount(this.wnd, this.comms), n;
|
|
3099
|
+
}).filter((s) => s !== void 0);
|
|
3100
|
+
}
|
|
3101
|
+
}
|
|
3102
|
+
loadModule(e) {
|
|
3103
|
+
const t = Je.get(e);
|
|
3104
|
+
return t === void 0 ? (this.comms.log(`Module "${name}" does not exist in the library`), t) : new t();
|
|
3105
|
+
}
|
|
3106
|
+
/**
|
|
3107
|
+
* Add a module by name
|
|
3108
|
+
* @param moduleName Module name
|
|
3109
|
+
* @returns Success
|
|
3110
|
+
*/
|
|
3111
|
+
addModule(e) {
|
|
3112
|
+
const t = this.loadModule(e);
|
|
3113
|
+
return !t || !t.mount(this.wnd, this.comms) ? !1 : (this.loadedModules.push(t), !0);
|
|
3114
|
+
}
|
|
3115
|
+
/**
|
|
3116
|
+
* Remove a module by name
|
|
3117
|
+
* @param moduleName Module name
|
|
3118
|
+
* @returns Success
|
|
3119
|
+
*/
|
|
3120
|
+
removeModule(e) {
|
|
3121
|
+
const t = Je.get(e);
|
|
3122
|
+
if (t === void 0)
|
|
3123
|
+
return this.comms.log(`Module "${e}" does not exist in the library`), !1;
|
|
3124
|
+
const r = this.loadedModules.findIndex((s) => s instanceof t);
|
|
3125
|
+
return r < 0 ? !1 : (this.loadedModules[r].unmount(this.wnd, this.comms), this.loadedModules.splice(r, 1), !0);
|
|
3126
|
+
}
|
|
3127
|
+
/**
|
|
3128
|
+
* Unmount and remove all modules
|
|
3129
|
+
*/
|
|
3130
|
+
destroy() {
|
|
3131
|
+
this.comms.destroy(), this.loadedModules.forEach((e) => e.unmount(this.wnd, this.comms)), this.loadedModules = [];
|
|
3132
|
+
}
|
|
3133
|
+
}
|
|
3134
|
+
export {
|
|
3135
|
+
X as COMMS_VERSION,
|
|
3136
|
+
Rt as Comms,
|
|
3137
|
+
Oi as FXLModules,
|
|
3138
|
+
Mi as Loader,
|
|
3139
|
+
ce as Module,
|
|
3140
|
+
Je as ModuleLibrary,
|
|
3141
|
+
bt as Peripherals,
|
|
3142
|
+
Ai as ReflowableModules,
|
|
3143
|
+
Nt as mid
|
|
3144
|
+
};
|