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