@prose-reader/cfi 1.209.0 → 1.210.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/LICENCE +7 -0
- package/dist/index.js +397 -454
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +1 -1
- package/dist/index.umd.cjs.map +1 -1
- package/package.json +6 -3
package/dist/index.js
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
function
|
|
1
|
+
function Z(e) {
|
|
2
2
|
const t = [e];
|
|
3
3
|
let n = e;
|
|
4
4
|
for (; n.parentNode; )
|
|
5
5
|
t.push(n.parentNode), n = n.parentNode;
|
|
6
6
|
return t;
|
|
7
7
|
}
|
|
8
|
-
function
|
|
8
|
+
function ee(e, t) {
|
|
9
9
|
if (e === t) return e;
|
|
10
|
-
const n =
|
|
11
|
-
let
|
|
12
|
-
for (;
|
|
13
|
-
if (
|
|
14
|
-
return
|
|
15
|
-
|
|
10
|
+
const n = Z(e), i = new Set(n);
|
|
11
|
+
let r = t;
|
|
12
|
+
for (; r; ) {
|
|
13
|
+
if (i.has(r))
|
|
14
|
+
return r;
|
|
15
|
+
r = r.parentNode;
|
|
16
16
|
}
|
|
17
17
|
return null;
|
|
18
18
|
}
|
|
19
|
-
const
|
|
20
|
-
function
|
|
21
|
-
return e.replace(
|
|
19
|
+
const ne = /[\[\]\^,();]/g;
|
|
20
|
+
function g(e) {
|
|
21
|
+
return e.replace(ne, "^$&");
|
|
22
22
|
}
|
|
23
|
-
const
|
|
24
|
-
function
|
|
25
|
-
const t = e.match(
|
|
23
|
+
const te = /^epubcfi\((.*)\)$/, b = (e) => e.nodeType === Node.ELEMENT_NODE, I = (e) => typeof e == "object" && e !== null && "nodeType" in e && (e.nodeType === Node.ELEMENT_NODE || e.nodeType === Node.TEXT_NODE), re = (e) => e.nodeType === Node.TEXT_NODE;
|
|
24
|
+
function ie(e) {
|
|
25
|
+
const t = e.match(te);
|
|
26
26
|
return t && t[1] || e;
|
|
27
27
|
}
|
|
28
|
-
function
|
|
28
|
+
function se(e) {
|
|
29
29
|
const t = [];
|
|
30
|
-
let n = null,
|
|
30
|
+
let n = null, i = !1, r = "";
|
|
31
31
|
const o = (c) => {
|
|
32
|
-
t.push(c), n = null,
|
|
32
|
+
t.push(c), n = null, r = "";
|
|
33
33
|
}, l = (c) => {
|
|
34
|
-
|
|
35
|
-
},
|
|
36
|
-
for (let c = 0; c <
|
|
37
|
-
const
|
|
38
|
-
if (!
|
|
39
|
-
n === "/" || n === ":" ? o([n, parseInt(
|
|
34
|
+
r += c, i = !1;
|
|
35
|
+
}, f = ie(e).trim(), d = Array.from(f).concat("");
|
|
36
|
+
for (let c = 0; c < d.length; c++) {
|
|
37
|
+
const s = d[c];
|
|
38
|
+
if (!s) {
|
|
39
|
+
n === "/" || n === ":" ? o([n, parseInt(r, 10)]) : n === "~" ? o(["~", parseFloat(r)]) : n === "@" ? o(["@", parseFloat(r)]) : n === "[" ? o(["[", r]) : (n === ";" || n != null && n.startsWith(";")) && o([n, r]);
|
|
40
40
|
break;
|
|
41
41
|
}
|
|
42
|
-
if (
|
|
43
|
-
|
|
42
|
+
if (s === "^" && !i) {
|
|
43
|
+
i = !0;
|
|
44
44
|
continue;
|
|
45
45
|
}
|
|
46
46
|
if (n === "!")
|
|
@@ -48,190 +48,186 @@ function Z(e) {
|
|
|
48
48
|
else if (n === ",")
|
|
49
49
|
o([",", 0]);
|
|
50
50
|
else if (n === "/" || n === ":") {
|
|
51
|
-
if (/^\d$/.test(
|
|
52
|
-
l(
|
|
51
|
+
if (/^\d$/.test(s)) {
|
|
52
|
+
l(s);
|
|
53
53
|
continue;
|
|
54
54
|
}
|
|
55
|
-
o([n, parseInt(
|
|
55
|
+
o([n, parseInt(r, 10)]);
|
|
56
56
|
} else if (n === "~") {
|
|
57
|
-
if (/^\d$/.test(
|
|
58
|
-
l(
|
|
57
|
+
if (/^\d$/.test(s) || s === ".") {
|
|
58
|
+
l(s);
|
|
59
59
|
continue;
|
|
60
60
|
}
|
|
61
|
-
o(["~", parseFloat(
|
|
61
|
+
o(["~", parseFloat(r)]);
|
|
62
62
|
} else if (n === "@") {
|
|
63
|
-
if (
|
|
64
|
-
o(["@", parseFloat(
|
|
63
|
+
if (s === ":") {
|
|
64
|
+
o(["@", parseFloat(r)]), n = "@";
|
|
65
65
|
continue;
|
|
66
66
|
}
|
|
67
|
-
if (/^\d$/.test(
|
|
68
|
-
l(
|
|
67
|
+
if (/^\d$/.test(s) || s === ".") {
|
|
68
|
+
l(s);
|
|
69
69
|
continue;
|
|
70
70
|
}
|
|
71
|
-
o(["@", parseFloat(
|
|
71
|
+
o(["@", parseFloat(r)]);
|
|
72
72
|
} else if (n === "[")
|
|
73
|
-
if (
|
|
74
|
-
o(["[",
|
|
75
|
-
else if (
|
|
76
|
-
o(["[",
|
|
73
|
+
if (s === ";" && !i)
|
|
74
|
+
o(["[", r]), n = ";";
|
|
75
|
+
else if (s === "]" && !i)
|
|
76
|
+
o(["[", r]);
|
|
77
77
|
else {
|
|
78
|
-
l(
|
|
78
|
+
l(s);
|
|
79
79
|
continue;
|
|
80
80
|
}
|
|
81
81
|
else if (n === ";")
|
|
82
|
-
if (
|
|
83
|
-
n = `;${
|
|
84
|
-
else if (
|
|
85
|
-
o([n,
|
|
86
|
-
else if (
|
|
87
|
-
o([n,
|
|
82
|
+
if (s === "=" && !i)
|
|
83
|
+
n = `;${r}`, r = "";
|
|
84
|
+
else if (s === ";" && !i)
|
|
85
|
+
o([n, r]), n = ";";
|
|
86
|
+
else if (s === "]" && !i)
|
|
87
|
+
o([n, r]);
|
|
88
88
|
else {
|
|
89
|
-
l(
|
|
89
|
+
l(s);
|
|
90
90
|
continue;
|
|
91
91
|
}
|
|
92
92
|
else if (n != null && n.startsWith(";"))
|
|
93
|
-
if (
|
|
94
|
-
o([n,
|
|
95
|
-
else if (
|
|
96
|
-
o([n,
|
|
93
|
+
if (s === ";" && !i)
|
|
94
|
+
o([n, r]), n = ";";
|
|
95
|
+
else if (s === "]" && !i)
|
|
96
|
+
o([n, r]);
|
|
97
97
|
else {
|
|
98
|
-
l(
|
|
98
|
+
l(s);
|
|
99
99
|
continue;
|
|
100
100
|
}
|
|
101
|
-
else n === null &&
|
|
102
|
-
(
|
|
101
|
+
else n === null && s === ";" && (n = ";");
|
|
102
|
+
(s === "/" || s === ":" || s === "~" || s === "@" || s === "[" || s === "!" || s === ",") && (n = s);
|
|
103
103
|
}
|
|
104
104
|
return t;
|
|
105
105
|
}
|
|
106
|
-
function
|
|
107
|
-
return e ? e.map((n,
|
|
106
|
+
function H(e, t) {
|
|
107
|
+
return e ? e.map((n, i) => n[0] === t ? i : null).filter((n) => n !== null) : [];
|
|
108
108
|
}
|
|
109
|
-
function
|
|
109
|
+
function U(e, t) {
|
|
110
110
|
const n = [];
|
|
111
|
-
let
|
|
112
|
-
for (const
|
|
113
|
-
n.push(e.slice(
|
|
114
|
-
return n.push(e.slice(
|
|
111
|
+
let i = 0;
|
|
112
|
+
for (const r of t)
|
|
113
|
+
n.push(e.slice(i, r)), i = r;
|
|
114
|
+
return n.push(e.slice(i)), n;
|
|
115
115
|
}
|
|
116
|
-
function
|
|
117
|
-
var
|
|
116
|
+
function oe(e) {
|
|
117
|
+
var r;
|
|
118
118
|
const t = [], n = {};
|
|
119
|
-
let
|
|
119
|
+
let i = -1;
|
|
120
120
|
for (let o = 0; o < e.length; o++) {
|
|
121
121
|
const l = e[o];
|
|
122
122
|
if (!l) continue;
|
|
123
|
-
const [
|
|
124
|
-
|
|
123
|
+
const [f, d] = l;
|
|
124
|
+
f === "/" ? (i++, t[i] = { index: d }, n[i] = []) : i >= 0 && ((r = n[i]) == null || r.push(l));
|
|
125
125
|
}
|
|
126
126
|
for (let o = 0; o < t.length; o++) {
|
|
127
127
|
const l = t[o];
|
|
128
128
|
if (!l) continue;
|
|
129
|
-
const
|
|
130
|
-
for (let
|
|
131
|
-
const c =
|
|
129
|
+
const f = n[o] || [];
|
|
130
|
+
for (let d = 0; d < f.length; d++) {
|
|
131
|
+
const c = f[d];
|
|
132
132
|
if (!c) continue;
|
|
133
|
-
const [
|
|
134
|
-
if (
|
|
135
|
-
l.offset =
|
|
136
|
-
else if (
|
|
137
|
-
l.temporal =
|
|
138
|
-
else if (
|
|
139
|
-
l.spatial = (l.spatial || []).concat(
|
|
140
|
-
else if (
|
|
141
|
-
l.side =
|
|
142
|
-
else if (
|
|
143
|
-
const
|
|
144
|
-
l.extensions || (l.extensions = {}), l.extensions[
|
|
145
|
-
} else if (
|
|
146
|
-
const
|
|
147
|
-
if (
|
|
148
|
-
l.id =
|
|
149
|
-
else if (
|
|
150
|
-
const
|
|
151
|
-
l.text =
|
|
133
|
+
const [s, a] = c;
|
|
134
|
+
if (s === ":")
|
|
135
|
+
l.offset = a;
|
|
136
|
+
else if (s === "~")
|
|
137
|
+
l.temporal = a;
|
|
138
|
+
else if (s === "@")
|
|
139
|
+
l.spatial = (l.spatial || []).concat(a);
|
|
140
|
+
else if (s === ";s")
|
|
141
|
+
l.side = a;
|
|
142
|
+
else if (s.startsWith(";") && s !== ";s") {
|
|
143
|
+
const u = s.substring(1);
|
|
144
|
+
l.extensions || (l.extensions = {}), l.extensions[u] = a;
|
|
145
|
+
} else if (s === "[") {
|
|
146
|
+
const u = typeof a == "string" && !a.includes(" ") && a.length < 50;
|
|
147
|
+
if (d === 0 && u && !l.id)
|
|
148
|
+
l.id = a;
|
|
149
|
+
else if (a !== "") {
|
|
150
|
+
const h = a.split(",").map((x) => x.trim());
|
|
151
|
+
l.text = h;
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
return t;
|
|
157
157
|
}
|
|
158
|
-
function
|
|
159
|
-
const t =
|
|
160
|
-
return
|
|
158
|
+
function T(e) {
|
|
159
|
+
const t = H(e, "!");
|
|
160
|
+
return U(e, t).map(oe);
|
|
161
161
|
}
|
|
162
|
-
function
|
|
162
|
+
function p(e) {
|
|
163
163
|
if (!e)
|
|
164
164
|
throw new Error("CFI string cannot be empty");
|
|
165
|
-
const t =
|
|
165
|
+
const t = se(e);
|
|
166
166
|
if (!t || t.length === 0)
|
|
167
167
|
throw new Error("Failed to tokenize CFI string");
|
|
168
|
-
const n =
|
|
168
|
+
const n = H(t, ",");
|
|
169
169
|
if (n.length === 0)
|
|
170
|
-
return
|
|
171
|
-
const [
|
|
170
|
+
return T(t);
|
|
171
|
+
const [i, r, o] = U(t, n);
|
|
172
172
|
return {
|
|
173
|
-
parent:
|
|
174
|
-
start:
|
|
175
|
-
end:
|
|
173
|
+
parent: T(i || []),
|
|
174
|
+
start: T(r || []),
|
|
175
|
+
end: T(o || [])
|
|
176
176
|
};
|
|
177
177
|
}
|
|
178
|
-
function
|
|
178
|
+
function M(e) {
|
|
179
179
|
return e !== null && typeof e == "object" && "parent" in e && "start" in e && "end" in e;
|
|
180
180
|
}
|
|
181
|
-
function
|
|
181
|
+
function ue(e, t, n = {}) {
|
|
182
182
|
try {
|
|
183
183
|
if (typeof e != "string")
|
|
184
184
|
return D(e, t, n);
|
|
185
|
-
const
|
|
186
|
-
return n.asRange &&
|
|
187
|
-
} catch (
|
|
185
|
+
const i = p(e);
|
|
186
|
+
return n.asRange && M(i) ? V(i, t) : D(i, t, n);
|
|
187
|
+
} catch (i) {
|
|
188
188
|
if (n.throwOnError)
|
|
189
|
-
throw
|
|
189
|
+
throw i;
|
|
190
190
|
return { node: null, isRange: !1 };
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
193
|
function D(e, t, n = { asRange: !1 }) {
|
|
194
|
-
const { asRange:
|
|
195
|
-
if (
|
|
196
|
-
if (
|
|
197
|
-
return
|
|
198
|
-
const
|
|
199
|
-
return
|
|
194
|
+
const { asRange: i = !1 } = n;
|
|
195
|
+
if (M(e)) {
|
|
196
|
+
if (i)
|
|
197
|
+
return V(e, t);
|
|
198
|
+
const r = e.start[0] || [];
|
|
199
|
+
return E(r, t, n);
|
|
200
200
|
}
|
|
201
201
|
if (e[0])
|
|
202
|
-
return
|
|
202
|
+
return E(e[0], t, n);
|
|
203
203
|
throw new Error("Invalid CFI structure");
|
|
204
204
|
}
|
|
205
|
-
function
|
|
206
|
-
const n = e.parent[0] || [],
|
|
205
|
+
function V(e, t) {
|
|
206
|
+
const n = e.parent[0] || [], i = e.start[0] || [], r = e.end[0] || [];
|
|
207
207
|
let o = t.documentElement;
|
|
208
208
|
if (n.length > 0) {
|
|
209
|
-
const
|
|
210
|
-
|
|
209
|
+
const a = E(n, t);
|
|
210
|
+
I(a.node) && (o = a.node);
|
|
211
211
|
}
|
|
212
212
|
if (!o)
|
|
213
213
|
throw new Error("Failed to resolve parent node in CFI range");
|
|
214
|
-
const l =
|
|
215
|
-
if (!
|
|
214
|
+
const l = E(i, t), f = E(r, t);
|
|
215
|
+
if (!I(l.node) || !I(f.node))
|
|
216
216
|
throw new Error("Failed to resolve start or end node in CFI range");
|
|
217
|
-
const
|
|
218
|
-
return
|
|
219
|
-
|
|
217
|
+
const d = l.node, c = f.node, s = t.createRange();
|
|
218
|
+
return s.setStart(
|
|
219
|
+
d,
|
|
220
220
|
(Array.isArray(l.offset) ? l.offset[0] : l.offset) ?? 0
|
|
221
|
-
),
|
|
221
|
+
), s.setEnd(
|
|
222
222
|
c,
|
|
223
|
-
(Array.isArray(
|
|
223
|
+
(Array.isArray(f.offset) ? f.offset[0] : f.offset) ?? 0
|
|
224
224
|
), {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
temporal: l.temporal,
|
|
229
|
-
spatial: l.spatial,
|
|
230
|
-
side: l.side,
|
|
231
|
-
extensions: l.extensions
|
|
225
|
+
...l,
|
|
226
|
+
node: s,
|
|
227
|
+
isRange: !0
|
|
232
228
|
};
|
|
233
229
|
}
|
|
234
|
-
function
|
|
230
|
+
function le(e) {
|
|
235
231
|
if (e != null && e.side) return e.side;
|
|
236
232
|
if (e != null && e.text && e.text.length > 0) {
|
|
237
233
|
const t = e.text[0];
|
|
@@ -242,431 +238,378 @@ function y(e) {
|
|
|
242
238
|
}
|
|
243
239
|
}
|
|
244
240
|
}
|
|
245
|
-
function
|
|
241
|
+
function k(e) {
|
|
246
242
|
return e.index % 2 !== 0;
|
|
247
243
|
}
|
|
248
|
-
function
|
|
249
|
-
const n = (
|
|
250
|
-
return
|
|
244
|
+
function he(e) {
|
|
245
|
+
const n = (M(e) ? e.end : e).at(-1), i = n == null ? void 0 : n.at(-1);
|
|
246
|
+
return i == null ? void 0 : i.extensions;
|
|
247
|
+
}
|
|
248
|
+
function G(e) {
|
|
249
|
+
const t = le(e), n = e == null ? void 0 : e.extensions;
|
|
250
|
+
return {
|
|
251
|
+
offset: e == null ? void 0 : e.offset,
|
|
252
|
+
temporal: e == null ? void 0 : e.temporal,
|
|
253
|
+
spatial: e == null ? void 0 : e.spatial,
|
|
254
|
+
side: t,
|
|
255
|
+
extensions: n
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
function $(e, t) {
|
|
259
|
+
return {
|
|
260
|
+
node: e,
|
|
261
|
+
isRange: !1,
|
|
262
|
+
...G(t)
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
function v(e, t) {
|
|
266
|
+
return {
|
|
267
|
+
node: e,
|
|
268
|
+
isRange: !0,
|
|
269
|
+
...G(t)
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
function W(e, t, n) {
|
|
273
|
+
const i = e.createRange();
|
|
274
|
+
if (i.selectNodeContents(t), n !== void 0) {
|
|
275
|
+
const r = Array.isArray(n) ? n[0] : n;
|
|
276
|
+
re(t) && i.setStart(t, r || 0);
|
|
277
|
+
}
|
|
278
|
+
return i;
|
|
279
|
+
}
|
|
280
|
+
function X(e, t, n, i) {
|
|
281
|
+
let r = e;
|
|
282
|
+
for (let o = n; o < t.length; o++) {
|
|
283
|
+
const l = t[o];
|
|
284
|
+
if (!r || !l) break;
|
|
285
|
+
if (k(l)) {
|
|
286
|
+
const f = l.index - 1;
|
|
287
|
+
if (f >= 0 && f < r.childNodes.length)
|
|
288
|
+
r = r.childNodes[f];
|
|
289
|
+
else {
|
|
290
|
+
if (i)
|
|
291
|
+
throw new Error(`Invalid text node index: ${l.index}`);
|
|
292
|
+
r = null;
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
} else {
|
|
296
|
+
const f = Array.from(r.childNodes).filter(
|
|
297
|
+
(c) => c.nodeType === Node.ELEMENT_NODE
|
|
298
|
+
), d = Math.floor(l.index / 2) - 1;
|
|
299
|
+
if (d >= 0 && d < f.length) {
|
|
300
|
+
const c = f[d];
|
|
301
|
+
c && (r = c);
|
|
302
|
+
} else {
|
|
303
|
+
if (i)
|
|
304
|
+
throw new Error(`Invalid element step index: ${l.index}`);
|
|
305
|
+
r = null;
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return r;
|
|
251
311
|
}
|
|
252
|
-
function
|
|
253
|
-
const { throwOnError:
|
|
312
|
+
function E(e, t, n = {}) {
|
|
313
|
+
const { throwOnError: i = !1, asRange: r = !1 } = n;
|
|
254
314
|
if (!t) {
|
|
255
|
-
if (
|
|
315
|
+
if (i)
|
|
256
316
|
throw new Error("Document is not available");
|
|
257
|
-
return
|
|
317
|
+
return $(null);
|
|
258
318
|
}
|
|
259
|
-
const { node: o, remainingPathIndex: l } =
|
|
319
|
+
const { node: o, remainingPathIndex: l } = fe(t, e);
|
|
260
320
|
if (o && l >= e.length) {
|
|
261
|
-
const
|
|
262
|
-
if (
|
|
263
|
-
const
|
|
264
|
-
if (
|
|
265
|
-
const
|
|
266
|
-
return
|
|
267
|
-
node: m,
|
|
268
|
-
isRange: !1,
|
|
269
|
-
offset: i == null ? void 0 : i.offset,
|
|
270
|
-
temporal: i == null ? void 0 : i.temporal,
|
|
271
|
-
spatial: i == null ? void 0 : i.spatial,
|
|
272
|
-
side: p,
|
|
273
|
-
extensions: E
|
|
274
|
-
};
|
|
321
|
+
const s = e.at(-1);
|
|
322
|
+
if (s && k(s)) {
|
|
323
|
+
const a = s.index - 1;
|
|
324
|
+
if (a >= 0 && a < o.childNodes.length) {
|
|
325
|
+
const u = o.childNodes[a];
|
|
326
|
+
return $(u, s);
|
|
275
327
|
}
|
|
276
328
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
if ($.selectNodeContents(o), (i == null ? void 0 : i.offset) !== void 0) {
|
|
281
|
-
const m = Array.isArray(i.offset) ? i.offset[0] : i.offset;
|
|
282
|
-
_(o) && $.setStart(o, m || 0);
|
|
283
|
-
}
|
|
284
|
-
return $.setEnd(o, (i == null ? void 0 : i.offset) || 0), {
|
|
285
|
-
node: $,
|
|
286
|
-
isRange: !0,
|
|
287
|
-
offset: i == null ? void 0 : i.offset,
|
|
288
|
-
temporal: i == null ? void 0 : i.temporal,
|
|
289
|
-
spatial: i == null ? void 0 : i.spatial,
|
|
290
|
-
side: u,
|
|
291
|
-
extensions: x
|
|
292
|
-
};
|
|
329
|
+
if (r) {
|
|
330
|
+
const a = W(t, o, s == null ? void 0 : s.offset);
|
|
331
|
+
return v(a, s);
|
|
293
332
|
}
|
|
294
|
-
return
|
|
295
|
-
node: o,
|
|
296
|
-
isRange: !1,
|
|
297
|
-
offset: i == null ? void 0 : i.offset,
|
|
298
|
-
temporal: i == null ? void 0 : i.temporal,
|
|
299
|
-
spatial: i == null ? void 0 : i.spatial,
|
|
300
|
-
side: u,
|
|
301
|
-
extensions: x
|
|
302
|
-
};
|
|
333
|
+
return $(o, s);
|
|
303
334
|
}
|
|
304
|
-
let
|
|
305
|
-
const
|
|
306
|
-
if (
|
|
307
|
-
const
|
|
308
|
-
if (
|
|
309
|
-
if (
|
|
310
|
-
const
|
|
311
|
-
return
|
|
312
|
-
node: x,
|
|
313
|
-
isRange: !0,
|
|
314
|
-
offset: i.offset,
|
|
315
|
-
temporal: i.temporal,
|
|
316
|
-
spatial: i.spatial,
|
|
317
|
-
side: y(i),
|
|
318
|
-
extensions: i.extensions
|
|
319
|
-
};
|
|
335
|
+
let f = o || t.documentElement;
|
|
336
|
+
const d = o ? l : 0;
|
|
337
|
+
if (r && e.length > 0) {
|
|
338
|
+
const s = e[e.length - 1];
|
|
339
|
+
if (s && !k(s)) {
|
|
340
|
+
if (s.index === 0 && f) {
|
|
341
|
+
const u = t.createRange();
|
|
342
|
+
return u.setStart(f, 0), u.setEnd(f, 0), v(u, s);
|
|
320
343
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
u = null;
|
|
331
|
-
break;
|
|
332
|
-
}
|
|
333
|
-
} else {
|
|
334
|
-
const m = Array.from(
|
|
335
|
-
u.childNodes
|
|
336
|
-
).filter((E) => E.nodeType === Node.ELEMENT_NODE), p = Math.floor($.index / 2) - 1;
|
|
337
|
-
if (p >= 0 && p < m.length) {
|
|
338
|
-
const E = m[p];
|
|
339
|
-
if (E)
|
|
340
|
-
u = E;
|
|
341
|
-
else {
|
|
342
|
-
u = null;
|
|
343
|
-
break;
|
|
344
|
-
}
|
|
345
|
-
} else {
|
|
346
|
-
u = null;
|
|
347
|
-
break;
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
if (u) {
|
|
352
|
-
const x = Array.from(u.childNodes).filter(
|
|
353
|
-
(m) => m.nodeType === Node.ELEMENT_NODE
|
|
344
|
+
const a = X(
|
|
345
|
+
f,
|
|
346
|
+
e.slice(0, -1),
|
|
347
|
+
d,
|
|
348
|
+
i
|
|
349
|
+
);
|
|
350
|
+
if (a) {
|
|
351
|
+
const u = Array.from(a.childNodes).filter(
|
|
352
|
+
(x) => x.nodeType === Node.ELEMENT_NODE
|
|
354
353
|
);
|
|
355
|
-
if (Math.floor(
|
|
356
|
-
const
|
|
357
|
-
return
|
|
358
|
-
node: m,
|
|
359
|
-
isRange: !0,
|
|
360
|
-
offset: i.offset,
|
|
361
|
-
temporal: i.temporal,
|
|
362
|
-
spatial: i.spatial,
|
|
363
|
-
side: y(i),
|
|
364
|
-
extensions: i.extensions
|
|
365
|
-
};
|
|
354
|
+
if (Math.floor(s.index / 2) - 1 === u.length) {
|
|
355
|
+
const x = t.createRange();
|
|
356
|
+
return x.selectNodeContents(a), x.collapse(!1), v(x, s);
|
|
366
357
|
}
|
|
367
358
|
}
|
|
368
359
|
}
|
|
369
360
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
if (!a || !u) break;
|
|
373
|
-
if (w(u)) {
|
|
374
|
-
const x = u.index - 1;
|
|
375
|
-
if (x >= 0 && x < a.childNodes.length)
|
|
376
|
-
a = a.childNodes[x];
|
|
377
|
-
else {
|
|
378
|
-
if (r)
|
|
379
|
-
throw new Error(`Invalid text node index: ${u.index}`);
|
|
380
|
-
a = null;
|
|
381
|
-
break;
|
|
382
|
-
}
|
|
383
|
-
} else {
|
|
384
|
-
const x = Array.from(a.childNodes).filter(
|
|
385
|
-
(m) => m.nodeType === Node.ELEMENT_NODE
|
|
386
|
-
), $ = Math.floor(u.index / 2) - 1;
|
|
387
|
-
if ($ >= 0 && $ < x.length) {
|
|
388
|
-
const m = x[$];
|
|
389
|
-
m && (a = m);
|
|
390
|
-
} else {
|
|
391
|
-
if (r)
|
|
392
|
-
throw new Error(`Invalid element step index: ${u.index}`);
|
|
393
|
-
a = null;
|
|
394
|
-
break;
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
if (!a) {
|
|
399
|
-
if (r)
|
|
361
|
+
if (f = X(f, e, d, i), !f) {
|
|
362
|
+
if (i)
|
|
400
363
|
throw new Error("Failed to resolve CFI path");
|
|
401
|
-
return
|
|
364
|
+
return $(null);
|
|
402
365
|
}
|
|
403
|
-
const c = e.at(-1)
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
temporal: c == null ? void 0 : c.temporal,
|
|
408
|
-
spatial: c == null ? void 0 : c.spatial,
|
|
409
|
-
side: f,
|
|
410
|
-
extensions: d
|
|
411
|
-
};
|
|
412
|
-
if (s) {
|
|
413
|
-
const i = t.createRange();
|
|
414
|
-
if (i.selectNodeContents(a), (c == null ? void 0 : c.offset) !== void 0) {
|
|
415
|
-
const u = Array.isArray(c.offset) ? c.offset[0] : c.offset;
|
|
416
|
-
_(a) && i.setStart(a, u || 0);
|
|
417
|
-
}
|
|
418
|
-
return {
|
|
419
|
-
...g,
|
|
420
|
-
node: i,
|
|
421
|
-
isRange: !0
|
|
422
|
-
};
|
|
366
|
+
const c = e.at(-1);
|
|
367
|
+
if (r) {
|
|
368
|
+
const s = W(t, f, c == null ? void 0 : c.offset);
|
|
369
|
+
return v(s, c);
|
|
423
370
|
}
|
|
424
|
-
return
|
|
371
|
+
return $(f, c);
|
|
425
372
|
}
|
|
426
|
-
function
|
|
373
|
+
function fe(e, t) {
|
|
427
374
|
for (let n = t.length - 1; n >= 0; n--) {
|
|
428
|
-
const
|
|
429
|
-
if (
|
|
430
|
-
const
|
|
431
|
-
if (
|
|
375
|
+
const i = t[n];
|
|
376
|
+
if (i != null && i.id) {
|
|
377
|
+
const r = e.getElementById(i.id);
|
|
378
|
+
if (r) return { node: r, remainingPathIndex: n + 1 };
|
|
432
379
|
}
|
|
433
380
|
}
|
|
434
381
|
return { node: null, remainingPathIndex: 0 };
|
|
435
382
|
}
|
|
436
|
-
function
|
|
383
|
+
function J(e, t, n = {}) {
|
|
437
384
|
if (!e.textContent || e.textContent.trim() === "")
|
|
438
385
|
return null;
|
|
439
|
-
const
|
|
440
|
-
if (t !== void 0 && t <=
|
|
441
|
-
const o = Math.floor(
|
|
442
|
-
return
|
|
386
|
+
const i = e.textContent, r = n.textAssertionLength || 10;
|
|
387
|
+
if (t !== void 0 && t <= i.length) {
|
|
388
|
+
const o = Math.floor(r / 2), l = Math.max(0, t - o), f = Math.min(i.length, t + o);
|
|
389
|
+
return i.substring(l, f);
|
|
443
390
|
}
|
|
444
|
-
return
|
|
391
|
+
return i.substring(0, Math.min(i.length, r));
|
|
445
392
|
}
|
|
446
|
-
function
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
return
|
|
393
|
+
function ce(e) {
|
|
394
|
+
const [t, n] = e, i = Math.max(0, Math.min(100, t)), r = Math.max(0, Math.min(100, n));
|
|
395
|
+
return `@${i}:${r}`;
|
|
396
|
+
}
|
|
397
|
+
function S(e, t, n) {
|
|
398
|
+
let i = e;
|
|
399
|
+
return t !== void 0 && (i += `~${t}`), n !== void 0 && (i += ce(n)), i;
|
|
453
400
|
}
|
|
454
|
-
function
|
|
455
|
-
|
|
456
|
-
|
|
401
|
+
function K(e, t, n) {
|
|
402
|
+
let i = e;
|
|
403
|
+
if (t && (i += `[${g(t)}]`), n) {
|
|
404
|
+
const r = n === "before" ? "b" : "a";
|
|
405
|
+
t ? i = `${i.substring(0, i.length - 1)};s=${r}]` : i += `[;s=${r}]`;
|
|
406
|
+
}
|
|
407
|
+
return i;
|
|
408
|
+
}
|
|
409
|
+
function j(e, t, n = {}, i) {
|
|
410
|
+
var d;
|
|
411
|
+
let r = "", o = e, l = null;
|
|
457
412
|
if (e.nodeType === Node.TEXT_NODE) {
|
|
458
413
|
l = e;
|
|
459
|
-
const
|
|
460
|
-
if (!
|
|
414
|
+
const c = e.parentNode;
|
|
415
|
+
if (!c)
|
|
461
416
|
throw new Error("Text node doesn't have a parent");
|
|
462
|
-
const
|
|
463
|
-
if (
|
|
417
|
+
const a = Array.from(c.childNodes).indexOf(e);
|
|
418
|
+
if (a === -1)
|
|
464
419
|
throw new Error("Node not found in parent's children");
|
|
465
|
-
if (
|
|
466
|
-
const u =
|
|
467
|
-
|
|
420
|
+
if (r = `/${a + 1}`, b(c) && c.id) {
|
|
421
|
+
const u = c.id, h = Array.from(((d = c.parentNode) == null ? void 0 : d.childNodes) || []);
|
|
422
|
+
r = `/${h.slice(0, h.indexOf(c) + 1).filter((y) => y.nodeType === Node.ELEMENT_NODE).length * 2}[${g(u)}]${r}`, o = c.parentNode;
|
|
468
423
|
} else
|
|
469
|
-
o =
|
|
424
|
+
o = c;
|
|
470
425
|
}
|
|
471
|
-
let
|
|
472
|
-
for (l && n.includeTextAssertions && (
|
|
473
|
-
if (!(l && o === l.parentNode &&
|
|
474
|
-
const
|
|
475
|
-
if (
|
|
426
|
+
let f = null;
|
|
427
|
+
for (l && n.includeTextAssertions && (f = J(l, t, n)); o != null && o.parentNode; ) {
|
|
428
|
+
if (!(l && o === l.parentNode && r.includes(`[${b(o) ? o.id : ""}]`))) {
|
|
429
|
+
const c = o.parentNode, s = Array.from(c.childNodes), a = s.indexOf(o);
|
|
430
|
+
if (a === -1)
|
|
476
431
|
throw new Error("Node not found in parent's children");
|
|
477
|
-
const u =
|
|
478
|
-
let
|
|
479
|
-
o.nodeType, Node.ELEMENT_NODE,
|
|
480
|
-
const
|
|
481
|
-
|
|
432
|
+
const u = s.slice(0, a + 1).filter((N) => N.nodeType === Node.ELEMENT_NODE);
|
|
433
|
+
let h;
|
|
434
|
+
o.nodeType, Node.ELEMENT_NODE, h = u.length;
|
|
435
|
+
const x = h * 2;
|
|
436
|
+
b(o) && o.id ? r = `/${x}[${g(o.id)}]${r}` : r = `/${x}${r}`;
|
|
482
437
|
}
|
|
483
438
|
if (o.parentNode.nodeName.toLowerCase() === "html")
|
|
484
439
|
break;
|
|
485
440
|
o = o.parentNode;
|
|
486
441
|
}
|
|
487
|
-
t !== void 0 && (
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
const [d, g] = c, i = Math.max(0, Math.min(100, d)), u = Math.max(0, Math.min(100, g));
|
|
493
|
-
s += `@${i}:${u}`;
|
|
494
|
-
}
|
|
495
|
-
if (a && (s += `[${N(a)}]`), n.includeSideBias) {
|
|
496
|
-
const d = n.includeSideBias === "before" ? "b" : "a";
|
|
497
|
-
a ? s = `${s.substring(0, s.length - 1)};s=${d}]` : s += `[;s=${d}]`;
|
|
498
|
-
}
|
|
499
|
-
return s = H(s, n.extensions), s;
|
|
442
|
+
return t !== void 0 && (r += `:${t}`), r = S(
|
|
443
|
+
r,
|
|
444
|
+
i == null ? void 0 : i.temporal,
|
|
445
|
+
(i == null ? void 0 : i.spatial) || n.spatialOffset
|
|
446
|
+
), r = K(r, f, n.includeSideBias), r = Q(r, n.extensions), r;
|
|
500
447
|
}
|
|
501
|
-
function
|
|
448
|
+
function z(e, t, n, i = {}, r) {
|
|
502
449
|
if (e === t) {
|
|
503
|
-
let
|
|
504
|
-
|
|
505
|
-
const [c, f] = s.spatial, d = Math.max(0, Math.min(100, c)), g = Math.max(0, Math.min(100, f));
|
|
506
|
-
s.temporal !== void 0 ? h += `@${d}:${g}` : h += `@${d}:${g}`;
|
|
507
|
-
}
|
|
508
|
-
return h;
|
|
450
|
+
let d = n !== void 0 ? `:${n}` : "";
|
|
451
|
+
return d = S(d, r == null ? void 0 : r.temporal, r == null ? void 0 : r.spatial), d;
|
|
509
452
|
}
|
|
510
453
|
const o = [];
|
|
511
454
|
let l = t;
|
|
512
455
|
for (; l && l !== e; ) {
|
|
513
|
-
const
|
|
514
|
-
if (!
|
|
515
|
-
const c =
|
|
516
|
-
let
|
|
517
|
-
for (let
|
|
518
|
-
if (c[
|
|
519
|
-
|
|
456
|
+
const d = l.parentNode;
|
|
457
|
+
if (!d) break;
|
|
458
|
+
const c = d.childNodes;
|
|
459
|
+
let s = -1;
|
|
460
|
+
for (let u = 0; u < c.length; u++)
|
|
461
|
+
if (c[u] === l) {
|
|
462
|
+
s = u;
|
|
520
463
|
break;
|
|
521
464
|
}
|
|
522
|
-
if (
|
|
465
|
+
if (s === -1)
|
|
523
466
|
throw new Error("Node not found in parent's children");
|
|
524
|
-
const
|
|
525
|
-
|
|
526
|
-
}
|
|
527
|
-
let a = o.join("");
|
|
528
|
-
if (n !== void 0 && (a += `:${n}`), (s == null ? void 0 : s.temporal) !== void 0 && (a += `~${s.temporal}`), s != null && s.spatial) {
|
|
529
|
-
const [h, c] = s.spatial, f = Math.max(0, Math.min(100, h)), d = Math.max(0, Math.min(100, c));
|
|
530
|
-
a += `@${f}:${d}`;
|
|
531
|
-
}
|
|
532
|
-
if (r.includeTextAssertions && t.nodeType === Node.TEXT_NODE) {
|
|
533
|
-
const h = q(t, n, r);
|
|
534
|
-
h && (a += `[${N(h)}]`);
|
|
467
|
+
const a = s + 1;
|
|
468
|
+
b(l) && l.id ? o.unshift(`/${a}[${g(l.id)}]`) : o.unshift(`/${a}`), l = d;
|
|
535
469
|
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
470
|
+
let f = o.join("");
|
|
471
|
+
if (n !== void 0 && (f += `:${n}`), f = S(f, r == null ? void 0 : r.temporal, r == null ? void 0 : r.spatial), i.includeTextAssertions && t.nodeType === Node.TEXT_NODE) {
|
|
472
|
+
const d = J(t, n, i);
|
|
473
|
+
f = K(
|
|
474
|
+
f,
|
|
475
|
+
d,
|
|
476
|
+
i.includeSideBias
|
|
477
|
+
);
|
|
539
478
|
}
|
|
540
|
-
return
|
|
479
|
+
return f = Q(f, i.extensions), f;
|
|
541
480
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
481
|
+
const P = (e) => Object.entries(e).map(([t, n]) => `${t}=${encodeURIComponent(g(n))}`).join(";");
|
|
482
|
+
function Q(e, t) {
|
|
483
|
+
return !t || Object.keys(t).length === 0 ? e : e.endsWith("]") ? `${e.substring(0, e.length - 1)}[;${P(t)}]` : `${e}[;${P(t)}]`;
|
|
484
|
+
}
|
|
485
|
+
function ae(e, t, n, i, r = {}, o, l) {
|
|
486
|
+
const f = ee(e, n);
|
|
487
|
+
if (!f)
|
|
545
488
|
throw new Error("No common ancestor found");
|
|
546
|
-
const
|
|
547
|
-
|
|
489
|
+
const d = j(f, void 0, r), c = z(
|
|
490
|
+
f,
|
|
548
491
|
e,
|
|
549
492
|
t,
|
|
550
|
-
|
|
493
|
+
r,
|
|
551
494
|
o
|
|
552
|
-
),
|
|
553
|
-
|
|
495
|
+
), s = z(
|
|
496
|
+
f,
|
|
554
497
|
n,
|
|
498
|
+
i,
|
|
555
499
|
r,
|
|
556
|
-
s,
|
|
557
500
|
l
|
|
558
501
|
);
|
|
559
|
-
if (
|
|
560
|
-
const
|
|
561
|
-
return `${
|
|
502
|
+
if (r.extensions && Object.keys(r.extensions).length > 0) {
|
|
503
|
+
const a = P(r.extensions), u = c.includes("[") ? c.replace(/\]$/, `;${a}]`) : `${c}[;${a}]`, h = s.includes("[") ? s.replace(/\]$/, `;${a}]`) : `${s}[;${a}]`;
|
|
504
|
+
return `${d},${u},${h}`;
|
|
562
505
|
}
|
|
563
|
-
return `${
|
|
506
|
+
return `${d},${c},${s}`;
|
|
564
507
|
}
|
|
565
|
-
function
|
|
566
|
-
if (
|
|
567
|
-
return `epubcfi(${
|
|
508
|
+
function xe(e, t = {}) {
|
|
509
|
+
if (I(e))
|
|
510
|
+
return `epubcfi(${j(e, void 0, t)})`;
|
|
568
511
|
if ("node" in e && !("start" in e))
|
|
569
|
-
return `epubcfi(${
|
|
512
|
+
return `epubcfi(${j(
|
|
570
513
|
e.node,
|
|
571
514
|
e.offset,
|
|
572
515
|
t,
|
|
573
516
|
e
|
|
574
517
|
)})`;
|
|
575
518
|
if ("start" in e && "end" in e) {
|
|
576
|
-
const { start: n, end:
|
|
577
|
-
return `epubcfi(${
|
|
519
|
+
const { start: n, end: i } = e;
|
|
520
|
+
return `epubcfi(${ae(
|
|
578
521
|
n.node,
|
|
579
522
|
n.offset ?? 0,
|
|
580
|
-
|
|
581
|
-
|
|
523
|
+
i.node,
|
|
524
|
+
i.offset ?? 0,
|
|
582
525
|
t,
|
|
583
526
|
n,
|
|
584
|
-
|
|
527
|
+
i
|
|
585
528
|
)})`;
|
|
586
529
|
}
|
|
587
530
|
throw new Error(
|
|
588
531
|
"Invalid argument: expected Node, CfiPosition, or {start, end} object"
|
|
589
532
|
);
|
|
590
533
|
}
|
|
591
|
-
function
|
|
592
|
-
return typeof e == "string" ?
|
|
534
|
+
function m(e, t = !1) {
|
|
535
|
+
return typeof e == "string" ? m(p(e), t) : "parent" in e ? t ? e.parent.concat(e.end) : e.parent.concat(e.start) : e;
|
|
593
536
|
}
|
|
594
|
-
function
|
|
537
|
+
function Y(e) {
|
|
595
538
|
return e.offset !== void 0 ? 1 : e.index !== void 0 ? 2 : e.temporal !== void 0 || e.spatial !== void 0 ? 3 : 4;
|
|
596
539
|
}
|
|
597
|
-
function
|
|
598
|
-
var
|
|
599
|
-
const n = typeof e == "string" ?
|
|
600
|
-
if ("parent" in n || "parent" in
|
|
601
|
-
return
|
|
602
|
-
for (let
|
|
603
|
-
const c = n[
|
|
604
|
-
for (let
|
|
605
|
-
const
|
|
606
|
-
if (!
|
|
607
|
-
if (!
|
|
608
|
-
const
|
|
609
|
-
if (
|
|
610
|
-
return
|
|
611
|
-
if (
|
|
612
|
-
if (
|
|
613
|
-
const
|
|
614
|
-
if (
|
|
615
|
-
if (!
|
|
616
|
-
if (
|
|
617
|
-
if ((
|
|
618
|
-
if ((
|
|
540
|
+
function q(e, t) {
|
|
541
|
+
var r, o, l, f;
|
|
542
|
+
const n = typeof e == "string" ? p(e) : e, i = typeof t == "string" ? p(t) : t;
|
|
543
|
+
if ("parent" in n || "parent" in i)
|
|
544
|
+
return q(m(n), m(i)) || q(m(n, !0), m(i, !0));
|
|
545
|
+
for (let d = 0; d < Math.max(n.length, i.length); d++) {
|
|
546
|
+
const c = n[d] || [], s = i[d] || [], a = Math.max(c.length, s.length) - 1;
|
|
547
|
+
for (let u = 0; u <= a; u++) {
|
|
548
|
+
const h = c[u], x = s[u];
|
|
549
|
+
if (!h) return -1;
|
|
550
|
+
if (!x) return 1;
|
|
551
|
+
const N = Y(h), y = Y(x);
|
|
552
|
+
if (N !== y)
|
|
553
|
+
return N - y;
|
|
554
|
+
if (h.index > x.index) return 1;
|
|
555
|
+
if (h.index < x.index) return -1;
|
|
556
|
+
const R = h.temporal !== void 0, O = x.temporal !== void 0;
|
|
557
|
+
if (R && !O) return 1;
|
|
558
|
+
if (!R && O) return -1;
|
|
559
|
+
if (R && O) {
|
|
560
|
+
if ((h.temporal ?? 0) > (x.temporal ?? 0)) return 1;
|
|
561
|
+
if ((h.temporal ?? 0) < (x.temporal ?? 0)) return -1;
|
|
619
562
|
}
|
|
620
|
-
const
|
|
621
|
-
if (
|
|
622
|
-
if (!
|
|
623
|
-
if (
|
|
624
|
-
const
|
|
625
|
-
if (
|
|
626
|
-
if (
|
|
627
|
-
const B = ((l =
|
|
628
|
-
if (B >
|
|
629
|
-
if (B <
|
|
563
|
+
const A = h.spatial !== void 0, C = x.spatial !== void 0;
|
|
564
|
+
if (A && !C) return 1;
|
|
565
|
+
if (!A && C) return -1;
|
|
566
|
+
if (A && C) {
|
|
567
|
+
const F = ((r = h.spatial) == null ? void 0 : r[1]) ?? 0, _ = ((o = x.spatial) == null ? void 0 : o[1]) ?? 0;
|
|
568
|
+
if (F > _) return 1;
|
|
569
|
+
if (F < _) return -1;
|
|
570
|
+
const B = ((l = h.spatial) == null ? void 0 : l[0]) ?? 0, L = ((f = x.spatial) == null ? void 0 : f[0]) ?? 0;
|
|
571
|
+
if (B > L) return 1;
|
|
572
|
+
if (B < L) return -1;
|
|
630
573
|
}
|
|
631
|
-
if (
|
|
632
|
-
if ((
|
|
633
|
-
if ((
|
|
574
|
+
if (u === a) {
|
|
575
|
+
if ((h.offset ?? 0) > (x.offset ?? 0)) return 1;
|
|
576
|
+
if ((h.offset ?? 0) < (x.offset ?? 0)) return -1;
|
|
634
577
|
}
|
|
635
578
|
}
|
|
636
579
|
}
|
|
637
580
|
return 0;
|
|
638
581
|
}
|
|
639
|
-
function
|
|
582
|
+
function de(e) {
|
|
640
583
|
let t = `/${e.index}`;
|
|
641
584
|
if (e.id) {
|
|
642
|
-
if (t += `[${
|
|
643
|
-
for (const [
|
|
644
|
-
t += `;${
|
|
585
|
+
if (t += `[${g(e.id)}`, e.extensions)
|
|
586
|
+
for (const [i, r] of Object.entries(e.extensions))
|
|
587
|
+
t += `;${i}=${g(r)}`;
|
|
645
588
|
t += "]";
|
|
646
589
|
}
|
|
647
590
|
e.offset !== void 0 && (t += `:${e.offset}`), e.temporal !== void 0 && (t += `~${e.temporal}`), e.spatial && e.spatial.length > 0 && (t += `@${e.spatial.join(":")}`);
|
|
648
591
|
const n = [];
|
|
649
|
-
if (
|
|
650
|
-
for (const [
|
|
651
|
-
n.push(`;${
|
|
592
|
+
if (e.text && e.text.length > 0 && n.push(e.text.map(g).join(",")), (e.side || e.extensions && !e.id) && (e.side && n.push(`;s=${e.side}`), e.extensions && !e.id))
|
|
593
|
+
for (const [i, r] of Object.entries(e.extensions))
|
|
594
|
+
n.push(`;${i}=${g(r)}`);
|
|
652
595
|
return n.length > 0 && (t += `[${n.join("")}]`), t;
|
|
653
596
|
}
|
|
654
|
-
function
|
|
655
|
-
return e.map((t) =>
|
|
597
|
+
function w(e) {
|
|
598
|
+
return e.map((t) => de(t)).join("");
|
|
656
599
|
}
|
|
657
|
-
function
|
|
600
|
+
function ge(e) {
|
|
658
601
|
if (Array.isArray(e))
|
|
659
|
-
return `epubcfi(${e.map(
|
|
660
|
-
const t = e.parent.map(
|
|
661
|
-
return `epubcfi(${t},${n},${
|
|
602
|
+
return `epubcfi(${e.map(w).join("!")})`;
|
|
603
|
+
const t = e.parent.map(w).join("!"), n = e.start.map(w).join("!"), i = e.end.map(w).join("!");
|
|
604
|
+
return `epubcfi(${t},${n},${i})`;
|
|
662
605
|
}
|
|
663
606
|
export {
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
607
|
+
q as compare,
|
|
608
|
+
xe as generate,
|
|
609
|
+
M as isParsedCfiRange,
|
|
610
|
+
p as parse,
|
|
611
|
+
ue as resolve,
|
|
612
|
+
he as resolveExtensions,
|
|
613
|
+
ge as serialize
|
|
671
614
|
};
|
|
672
615
|
//# sourceMappingURL=index.js.map
|