@prose-reader/cfi 1.213.0 → 1.214.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.d.ts +1 -1
- package/dist/index.js +218 -199
- 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 +2 -2
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
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 =
|
|
10
|
+
const n = Z(e), i = new Set(n);
|
|
11
11
|
let r = t;
|
|
12
12
|
for (; r; ) {
|
|
13
13
|
if (i.has(r))
|
|
@@ -16,25 +16,25 @@ function Z(e, t) {
|
|
|
16
16
|
}
|
|
17
17
|
return null;
|
|
18
18
|
}
|
|
19
|
-
const
|
|
19
|
+
const ne = /[\[\]\^,();]/g;
|
|
20
20
|
function g(e) {
|
|
21
|
-
return e.replace(
|
|
21
|
+
return e.replace(ne, "^$&");
|
|
22
22
|
}
|
|
23
|
-
const
|
|
24
|
-
function
|
|
25
|
-
const t = e.match(
|
|
23
|
+
const te = /^epubcfi\((.*)\)$/, w = (e) => e.nodeType === Node.ELEMENT_NODE, p = (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
30
|
let n = null, i = !1, r = "";
|
|
31
31
|
const o = (c) => {
|
|
32
32
|
t.push(c), n = null, r = "";
|
|
33
33
|
}, l = (c) => {
|
|
34
34
|
r += c, i = !1;
|
|
35
|
-
}, f =
|
|
36
|
-
for (let c = 0; c <
|
|
37
|
-
const s =
|
|
35
|
+
}, f = ie(e).trim(), a = Array.from(f).concat("");
|
|
36
|
+
for (let c = 0; c < a.length; c++) {
|
|
37
|
+
const s = a[c];
|
|
38
38
|
if (!s) {
|
|
39
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;
|
|
@@ -113,77 +113,77 @@ function U(e, t) {
|
|
|
113
113
|
n.push(e.slice(i, r)), i = r;
|
|
114
114
|
return n.push(e.slice(i)), n;
|
|
115
115
|
}
|
|
116
|
-
function
|
|
116
|
+
function oe(e) {
|
|
117
117
|
var r;
|
|
118
118
|
const t = [], n = {};
|
|
119
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 [f,
|
|
124
|
-
f === "/" ? (i++, t[i] = { index:
|
|
123
|
+
const [f, a] = l;
|
|
124
|
+
f === "/" ? (i++, t[i] = { index: a }, 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
129
|
const f = n[o] || [];
|
|
130
|
-
for (let
|
|
131
|
-
const c = f[
|
|
130
|
+
for (let a = 0; a < f.length; a++) {
|
|
131
|
+
const c = f[a];
|
|
132
132
|
if (!c) continue;
|
|
133
|
-
const [s,
|
|
133
|
+
const [s, d] = c;
|
|
134
134
|
if (s === ":")
|
|
135
|
-
l.offset =
|
|
135
|
+
l.offset = d;
|
|
136
136
|
else if (s === "~")
|
|
137
|
-
l.temporal =
|
|
137
|
+
l.temporal = d;
|
|
138
138
|
else if (s === "@")
|
|
139
|
-
l.spatial = (l.spatial || []).concat(
|
|
139
|
+
l.spatial = (l.spatial || []).concat(d);
|
|
140
140
|
else if (s === ";s")
|
|
141
|
-
l.side =
|
|
141
|
+
l.side = d;
|
|
142
142
|
else if (s.startsWith(";") && s !== ";s") {
|
|
143
143
|
const u = s.substring(1);
|
|
144
|
-
l.extensions || (l.extensions = {}), l.extensions[u] =
|
|
144
|
+
l.extensions || (l.extensions = {}), l.extensions[u] = d;
|
|
145
145
|
} else if (s === "[") {
|
|
146
|
-
const u = typeof
|
|
147
|
-
if (
|
|
148
|
-
l.id =
|
|
149
|
-
else if (
|
|
150
|
-
const
|
|
151
|
-
l.text =
|
|
146
|
+
const u = typeof d == "string" && !d.includes(" ") && d.length < 50;
|
|
147
|
+
if (a === 0 && u && !l.id)
|
|
148
|
+
l.id = d;
|
|
149
|
+
else if (d !== "") {
|
|
150
|
+
const h = d.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
|
|
158
|
+
function T(e) {
|
|
159
159
|
const t = H(e, "!");
|
|
160
|
-
return U(e, t).map(
|
|
160
|
+
return U(e, t).map(oe);
|
|
161
161
|
}
|
|
162
|
-
function
|
|
162
|
+
function O(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
168
|
const n = H(t, ",");
|
|
169
169
|
if (n.length === 0)
|
|
170
|
-
return
|
|
170
|
+
return T(t);
|
|
171
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 P(e) {
|
|
179
179
|
return e !== null && typeof e == "object" && "parent" in e && "start" in e && "end" in e;
|
|
180
180
|
}
|
|
181
|
-
function
|
|
181
|
+
function he(e, t, n = {}) {
|
|
182
182
|
try {
|
|
183
183
|
if (typeof e != "string")
|
|
184
184
|
return D(e, t, n);
|
|
185
|
-
const i =
|
|
186
|
-
return n.asRange &&
|
|
185
|
+
const i = O(e);
|
|
186
|
+
return n.asRange && P(i) ? G(i, t) : D(i, t, n);
|
|
187
187
|
} catch (i) {
|
|
188
188
|
if (n.throwOnError)
|
|
189
189
|
throw i;
|
|
@@ -192,31 +192,31 @@ function ue(e, t, n = {}) {
|
|
|
192
192
|
}
|
|
193
193
|
function D(e, t, n = { asRange: !1 }) {
|
|
194
194
|
const { asRange: i = !1 } = n;
|
|
195
|
-
if (
|
|
195
|
+
if (P(e)) {
|
|
196
196
|
if (i)
|
|
197
|
-
return
|
|
197
|
+
return G(e, t);
|
|
198
198
|
const r = e.start[0] || [];
|
|
199
|
-
return
|
|
199
|
+
return y(r, t, n);
|
|
200
200
|
}
|
|
201
201
|
if (e[0])
|
|
202
|
-
return
|
|
202
|
+
return y(e[0], t, n);
|
|
203
203
|
throw new Error("Invalid CFI structure");
|
|
204
204
|
}
|
|
205
|
-
function
|
|
205
|
+
function G(e, t) {
|
|
206
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 d = y(n, t);
|
|
210
|
+
p(d.node) && (o = d.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 = y(i, t), f = y(r, t);
|
|
215
|
+
if (!p(l.node) || !p(f.node))
|
|
216
216
|
throw new Error("Failed to resolve start or end node in CFI range");
|
|
217
|
-
const
|
|
217
|
+
const a = l.node, c = f.node, s = t.createRange();
|
|
218
218
|
return s.setStart(
|
|
219
|
-
|
|
219
|
+
a,
|
|
220
220
|
(Array.isArray(l.offset) ? l.offset[0] : l.offset) ?? 0
|
|
221
221
|
), s.setEnd(
|
|
222
222
|
c,
|
|
@@ -227,7 +227,7 @@ function V(e, t) {
|
|
|
227
227
|
isRange: !0
|
|
228
228
|
};
|
|
229
229
|
}
|
|
230
|
-
function
|
|
230
|
+
function le(e) {
|
|
231
231
|
if (e != null && e.side) return e.side;
|
|
232
232
|
if (e != null && e.text && e.text.length > 0) {
|
|
233
233
|
const t = e.text[0];
|
|
@@ -241,12 +241,12 @@ function oe(e) {
|
|
|
241
241
|
function S(e) {
|
|
242
242
|
return e.index % 2 !== 0;
|
|
243
243
|
}
|
|
244
|
-
function
|
|
245
|
-
const n = (
|
|
244
|
+
function xe(e) {
|
|
245
|
+
const n = (P(e) ? e.end : e).at(-1), i = n == null ? void 0 : n.at(-1);
|
|
246
246
|
return i == null ? void 0 : i.extensions;
|
|
247
247
|
}
|
|
248
|
-
function
|
|
249
|
-
const t =
|
|
248
|
+
function J(e) {
|
|
249
|
+
const t = le(e), n = e == null ? void 0 : e.extensions;
|
|
250
250
|
return {
|
|
251
251
|
offset: e == null ? void 0 : e.offset,
|
|
252
252
|
temporal: e == null ? void 0 : e.temporal,
|
|
@@ -255,25 +255,25 @@ function G(e) {
|
|
|
255
255
|
extensions: n
|
|
256
256
|
};
|
|
257
257
|
}
|
|
258
|
-
function
|
|
258
|
+
function E(e, t) {
|
|
259
259
|
return {
|
|
260
260
|
node: e,
|
|
261
261
|
isRange: !1,
|
|
262
|
-
...
|
|
262
|
+
...J(t)
|
|
263
263
|
};
|
|
264
264
|
}
|
|
265
|
-
function
|
|
265
|
+
function v(e, t) {
|
|
266
266
|
return {
|
|
267
267
|
node: e,
|
|
268
268
|
isRange: !0,
|
|
269
|
-
...
|
|
269
|
+
...J(t)
|
|
270
270
|
};
|
|
271
271
|
}
|
|
272
272
|
function W(e, t, n) {
|
|
273
273
|
const i = e.createRange();
|
|
274
274
|
if (i.selectNodeContents(t), n !== void 0) {
|
|
275
275
|
const r = Array.isArray(n) ? n[0] : n;
|
|
276
|
-
|
|
276
|
+
re(t) && i.setStart(t, r || 0);
|
|
277
277
|
}
|
|
278
278
|
return i;
|
|
279
279
|
}
|
|
@@ -295,9 +295,9 @@ function X(e, t, n, i) {
|
|
|
295
295
|
} else {
|
|
296
296
|
const f = Array.from(r.childNodes).filter(
|
|
297
297
|
(c) => c.nodeType === Node.ELEMENT_NODE
|
|
298
|
-
),
|
|
299
|
-
if (
|
|
300
|
-
const c = f[
|
|
298
|
+
), a = Math.floor(l.index / 2) - 1;
|
|
299
|
+
if (a >= 0 && a < f.length) {
|
|
300
|
+
const c = f[a];
|
|
301
301
|
c && (r = c);
|
|
302
302
|
} else {
|
|
303
303
|
if (i)
|
|
@@ -309,68 +309,68 @@ function X(e, t, n, i) {
|
|
|
309
309
|
}
|
|
310
310
|
return r;
|
|
311
311
|
}
|
|
312
|
-
function
|
|
312
|
+
function y(e, t, n = {}) {
|
|
313
313
|
const { throwOnError: i = !1, asRange: r = !1 } = n;
|
|
314
314
|
if (!t) {
|
|
315
315
|
if (i)
|
|
316
316
|
throw new Error("Document is not available");
|
|
317
|
-
return
|
|
317
|
+
return E(null);
|
|
318
318
|
}
|
|
319
|
-
const { node: o, remainingPathIndex: l } =
|
|
319
|
+
const { node: o, remainingPathIndex: l } = fe(t, e);
|
|
320
320
|
if (o && l >= e.length) {
|
|
321
321
|
const s = e.at(-1);
|
|
322
322
|
if (s && S(s)) {
|
|
323
|
-
const
|
|
324
|
-
if (
|
|
325
|
-
const u = o.childNodes[
|
|
326
|
-
return
|
|
323
|
+
const d = s.index - 1;
|
|
324
|
+
if (d >= 0 && d < o.childNodes.length) {
|
|
325
|
+
const u = o.childNodes[d];
|
|
326
|
+
return E(u, s);
|
|
327
327
|
}
|
|
328
328
|
}
|
|
329
329
|
if (r) {
|
|
330
|
-
const
|
|
331
|
-
return
|
|
330
|
+
const d = W(t, o, s == null ? void 0 : s.offset);
|
|
331
|
+
return v(d, s);
|
|
332
332
|
}
|
|
333
|
-
return
|
|
333
|
+
return E(o, s);
|
|
334
334
|
}
|
|
335
335
|
let f = o || t.documentElement;
|
|
336
|
-
const
|
|
336
|
+
const a = o ? l : 0;
|
|
337
337
|
if (r && e.length > 0) {
|
|
338
338
|
const s = e[e.length - 1];
|
|
339
339
|
if (s && !S(s)) {
|
|
340
340
|
if (s.index === 0 && f) {
|
|
341
341
|
const u = t.createRange();
|
|
342
|
-
return u.setStart(f, 0), u.setEnd(f, 0),
|
|
342
|
+
return u.setStart(f, 0), u.setEnd(f, 0), v(u, s);
|
|
343
343
|
}
|
|
344
|
-
const
|
|
344
|
+
const d = X(
|
|
345
345
|
f,
|
|
346
346
|
e.slice(0, -1),
|
|
347
|
-
|
|
347
|
+
a,
|
|
348
348
|
i
|
|
349
349
|
);
|
|
350
|
-
if (
|
|
351
|
-
const u = Array.from(
|
|
352
|
-
(
|
|
350
|
+
if (d) {
|
|
351
|
+
const u = Array.from(d.childNodes).filter(
|
|
352
|
+
(x) => x.nodeType === Node.ELEMENT_NODE
|
|
353
353
|
);
|
|
354
354
|
if (Math.floor(s.index / 2) - 1 === u.length) {
|
|
355
|
-
const
|
|
356
|
-
return
|
|
355
|
+
const x = t.createRange();
|
|
356
|
+
return x.selectNodeContents(d), x.collapse(!1), v(x, s);
|
|
357
357
|
}
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
|
-
if (f = X(f, e,
|
|
361
|
+
if (f = X(f, e, a, i), !f) {
|
|
362
362
|
if (i)
|
|
363
363
|
throw new Error("Failed to resolve CFI path");
|
|
364
|
-
return
|
|
364
|
+
return E(null);
|
|
365
365
|
}
|
|
366
366
|
const c = e.at(-1);
|
|
367
367
|
if (r) {
|
|
368
368
|
const s = W(t, f, c == null ? void 0 : c.offset);
|
|
369
|
-
return
|
|
369
|
+
return v(s, c);
|
|
370
370
|
}
|
|
371
|
-
return
|
|
371
|
+
return E(f, c);
|
|
372
372
|
}
|
|
373
|
-
function
|
|
373
|
+
function fe(e, t) {
|
|
374
374
|
for (let n = t.length - 1; n >= 0; n--) {
|
|
375
375
|
const i = t[n];
|
|
376
376
|
if (i != null && i.id) {
|
|
@@ -380,7 +380,7 @@ function le(e, t) {
|
|
|
380
380
|
}
|
|
381
381
|
return { node: null, remainingPathIndex: 0 };
|
|
382
382
|
}
|
|
383
|
-
function
|
|
383
|
+
function K(e, t, n = {}) {
|
|
384
384
|
if (!e.textContent || e.textContent.trim() === "")
|
|
385
385
|
return null;
|
|
386
386
|
const i = e.textContent, r = n.textAssertionLength || 10;
|
|
@@ -390,15 +390,15 @@ function J(e, t, n = {}) {
|
|
|
390
390
|
}
|
|
391
391
|
return i.substring(0, Math.min(i.length, r));
|
|
392
392
|
}
|
|
393
|
-
function
|
|
393
|
+
function ce(e) {
|
|
394
394
|
const [t, n] = e, i = Math.max(0, Math.min(100, t)), r = Math.max(0, Math.min(100, n));
|
|
395
395
|
return `@${i}:${r}`;
|
|
396
396
|
}
|
|
397
397
|
function j(e, t, n) {
|
|
398
398
|
let i = e;
|
|
399
|
-
return t !== void 0 && (i += `~${t}`), n !== void 0 && (i +=
|
|
399
|
+
return t !== void 0 && (i += `~${t}`), n !== void 0 && (i += ce(n)), i;
|
|
400
400
|
}
|
|
401
|
-
function
|
|
401
|
+
function Q(e, t, n) {
|
|
402
402
|
let i = e;
|
|
403
403
|
if (t && (i += `[${g(t)}]`), n) {
|
|
404
404
|
const r = n === "before" ? "b" : "a";
|
|
@@ -406,60 +406,56 @@ function K(e, t, n) {
|
|
|
406
406
|
}
|
|
407
407
|
return i;
|
|
408
408
|
}
|
|
409
|
-
function
|
|
410
|
-
var
|
|
409
|
+
function M(e, t, n = {}, i) {
|
|
410
|
+
var a;
|
|
411
411
|
let r = "", o = e, l = null;
|
|
412
|
-
if (e.nodeType === Node.TEXT_NODE) {
|
|
412
|
+
if ((e == null ? void 0 : e.nodeType) === Node.TEXT_NODE) {
|
|
413
413
|
l = e;
|
|
414
414
|
const c = e.parentNode;
|
|
415
415
|
if (!c)
|
|
416
416
|
throw new Error("Text node doesn't have a parent");
|
|
417
|
-
const
|
|
418
|
-
if (
|
|
417
|
+
const d = Array.from(c.childNodes).indexOf(e);
|
|
418
|
+
if (d === -1)
|
|
419
419
|
throw new Error("Node not found in parent's children");
|
|
420
|
-
if (r = `/${
|
|
421
|
-
const u = c.id,
|
|
422
|
-
r = `/${
|
|
420
|
+
if (r = `/${d + 1}`, w(c) && c.id) {
|
|
421
|
+
const u = c.id, h = Array.from(((a = c.parentNode) == null ? void 0 : a.childNodes) || []);
|
|
422
|
+
r = `/${h.slice(0, h.indexOf(c) + 1).filter((I) => I.nodeType === Node.ELEMENT_NODE).length * 2}[${g(u)}]${r}`, o = c.parentNode;
|
|
423
423
|
} else
|
|
424
424
|
o = c;
|
|
425
425
|
}
|
|
426
426
|
let f = null;
|
|
427
|
-
for (l && n.includeTextAssertions && (f =
|
|
427
|
+
for (l && n.includeTextAssertions && (f = K(l, t, n)); o != null && o.parentNode; ) {
|
|
428
428
|
if (!(l && o === l.parentNode && r.includes(`[${w(o) ? o.id : ""}]`))) {
|
|
429
|
-
const c = o.parentNode, s = Array.from(c.childNodes),
|
|
430
|
-
if (
|
|
429
|
+
const c = o.parentNode, s = Array.from(c.childNodes), d = s.indexOf(o);
|
|
430
|
+
if (d === -1)
|
|
431
431
|
throw new Error("Node not found in parent's children");
|
|
432
|
-
const u = s.slice(0,
|
|
433
|
-
let
|
|
434
|
-
o.nodeType, Node.ELEMENT_NODE,
|
|
435
|
-
const
|
|
436
|
-
w(o) && o.id ? r = `/${
|
|
432
|
+
const u = s.slice(0, d + 1).filter(($) => $.nodeType === Node.ELEMENT_NODE);
|
|
433
|
+
let h;
|
|
434
|
+
o.nodeType, Node.ELEMENT_NODE, h = u.length;
|
|
435
|
+
const x = h * 2;
|
|
436
|
+
w(o) && o.id ? r = `/${x}[${g(o.id)}]${r}` : r = `/${x}${r}`;
|
|
437
437
|
}
|
|
438
438
|
if (o.parentNode.nodeName.toLowerCase() === "html")
|
|
439
439
|
break;
|
|
440
440
|
o = o.parentNode;
|
|
441
441
|
}
|
|
442
|
-
|
|
442
|
+
return t !== void 0 && (r += `:${t}`), r = j(
|
|
443
443
|
r,
|
|
444
444
|
i == null ? void 0 : i.temporal,
|
|
445
445
|
(i == null ? void 0 : i.spatial) || n.spatialOffset
|
|
446
|
-
), r =
|
|
447
|
-
const c = O(n.extensions);
|
|
448
|
-
r.includes("[") ? r = r.replace(/\]$/, `;${c}]`) : r = `${r}[;${c}]`;
|
|
449
|
-
}
|
|
450
|
-
return r;
|
|
446
|
+
), r = Q(r, f, n.includeSideBias), r = N(r, n.extensions), r;
|
|
451
447
|
}
|
|
452
448
|
function z(e, t, n, i = {}, r) {
|
|
453
449
|
if (e === t) {
|
|
454
|
-
let
|
|
455
|
-
return
|
|
450
|
+
let a = n !== void 0 ? `:${n}` : "";
|
|
451
|
+
return a = j(a, r == null ? void 0 : r.temporal, r == null ? void 0 : r.spatial), a;
|
|
456
452
|
}
|
|
457
453
|
const o = [];
|
|
458
454
|
let l = t;
|
|
459
455
|
for (; l && l !== e; ) {
|
|
460
|
-
const
|
|
461
|
-
if (!
|
|
462
|
-
const c =
|
|
456
|
+
const a = l.parentNode;
|
|
457
|
+
if (!a) break;
|
|
458
|
+
const c = a.childNodes;
|
|
463
459
|
let s = -1;
|
|
464
460
|
for (let u = 0; u < c.length; u++)
|
|
465
461
|
if (c[u] === l) {
|
|
@@ -468,29 +464,39 @@ function z(e, t, n, i = {}, r) {
|
|
|
468
464
|
}
|
|
469
465
|
if (s === -1)
|
|
470
466
|
throw new Error("Node not found in parent's children");
|
|
471
|
-
const
|
|
472
|
-
w(l) && l.id ? o.unshift(`/${
|
|
467
|
+
const d = s + 1;
|
|
468
|
+
w(l) && l.id ? o.unshift(`/${d}[${g(l.id)}]`) : o.unshift(`/${d}`), l = a;
|
|
473
469
|
}
|
|
474
470
|
let f = o.join("");
|
|
475
471
|
if (n !== void 0 && (f += `:${n}`), f = j(f, r == null ? void 0 : r.temporal, r == null ? void 0 : r.spatial), i.includeTextAssertions && t.nodeType === Node.TEXT_NODE) {
|
|
476
|
-
const
|
|
477
|
-
f =
|
|
472
|
+
const a = K(t, n, i);
|
|
473
|
+
f = Q(
|
|
478
474
|
f,
|
|
479
|
-
|
|
475
|
+
a,
|
|
480
476
|
i.includeSideBias
|
|
481
477
|
);
|
|
482
478
|
}
|
|
483
|
-
return f =
|
|
479
|
+
return f = N(f, i.extensions), f;
|
|
484
480
|
}
|
|
485
|
-
const
|
|
486
|
-
|
|
487
|
-
return
|
|
481
|
+
const ae = (e) => Object.entries(e).map(([t, n]) => {
|
|
482
|
+
const i = g(n);
|
|
483
|
+
return `${t}=${encodeURIComponent(i)}`;
|
|
484
|
+
}).join(";");
|
|
485
|
+
function N(e, t) {
|
|
486
|
+
if (!t || Object.keys(t).length === 0)
|
|
487
|
+
return e;
|
|
488
|
+
const n = ae(t);
|
|
489
|
+
if (e.endsWith("]")) {
|
|
490
|
+
const i = e.lastIndexOf("["), r = e.substring(i + 1, e.length - 1);
|
|
491
|
+
return r.includes(n) ? e : `${e.substring(0, e.length - 1)}${r.includes(";"), ";"}${n}]`;
|
|
492
|
+
}
|
|
493
|
+
return e.endsWith("!") ? e : `${e}[;${n}]`;
|
|
488
494
|
}
|
|
489
|
-
function
|
|
490
|
-
const f =
|
|
495
|
+
function de(e, t, n, i, r = {}, o, l) {
|
|
496
|
+
const f = ee(e, n);
|
|
491
497
|
if (!f)
|
|
492
498
|
throw new Error("No common ancestor found");
|
|
493
|
-
const
|
|
499
|
+
const a = M(f, void 0, r), c = z(
|
|
494
500
|
f,
|
|
495
501
|
e,
|
|
496
502
|
t,
|
|
@@ -504,84 +510,97 @@ function ae(e, t, n, i, r = {}, o, l) {
|
|
|
504
510
|
l
|
|
505
511
|
);
|
|
506
512
|
if (r.extensions && Object.keys(r.extensions).length > 0) {
|
|
507
|
-
const
|
|
508
|
-
return `${
|
|
509
|
-
}
|
|
510
|
-
return `${d},${c},${s}`;
|
|
511
|
-
}
|
|
512
|
-
function xe(e, t = {}) {
|
|
513
|
-
if (b(e))
|
|
514
|
-
return `epubcfi(${P(e, void 0, t)})`;
|
|
515
|
-
if ("node" in e && !("start" in e)) {
|
|
516
|
-
let n = "";
|
|
517
|
-
return e.spineIndex !== void 0 && (n = `/6/${(e.spineIndex + 1) * 2}`, e.spineId && (n += `[${g(e.spineId)}]`), n += "!"), n += P(e.node, e.offset, t, e), `epubcfi(${n})`;
|
|
513
|
+
const d = N(a, r.extensions), u = N(c, r.extensions), h = N(s, r.extensions);
|
|
514
|
+
return `${d},${u},${h}`;
|
|
518
515
|
}
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
516
|
+
return `${a},${c},${s}`;
|
|
517
|
+
}
|
|
518
|
+
const Y = (e, t, n = {}, i) => {
|
|
519
|
+
const r = "";
|
|
520
|
+
let l = `/6/${(e + 1) * 2}`;
|
|
521
|
+
return t && (l += `[${g(t)}]`), l = i ? N(l, n.extensions) : l, `${l}${r}!`;
|
|
522
|
+
};
|
|
523
|
+
function ge(e, t = {}) {
|
|
524
|
+
if (p(e))
|
|
525
|
+
return `epubcfi(${M(e, void 0, t)})`;
|
|
526
|
+
let n = "";
|
|
527
|
+
if (!("start" in e))
|
|
528
|
+
return e.spineIndex !== void 0 && (n = Y(
|
|
529
|
+
e.spineIndex,
|
|
530
|
+
e.spineId,
|
|
527
531
|
t,
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
532
|
+
!e.node
|
|
533
|
+
), !e.node) ? `epubcfi(${n})` : (n += M(
|
|
534
|
+
e.node ?? null,
|
|
535
|
+
e.offset,
|
|
536
|
+
t,
|
|
537
|
+
e
|
|
538
|
+
), `epubcfi(${n})`);
|
|
539
|
+
const { start: i, end: r } = e;
|
|
540
|
+
return i.spineIndex !== void 0 && (n = Y(
|
|
541
|
+
i.spineIndex,
|
|
542
|
+
i.spineId,
|
|
543
|
+
t,
|
|
544
|
+
!i.node
|
|
545
|
+
)), i.node && r.node && (n += de(
|
|
546
|
+
i.node,
|
|
547
|
+
i.offset ?? 0,
|
|
548
|
+
r.node,
|
|
549
|
+
r.offset ?? 0,
|
|
550
|
+
t,
|
|
551
|
+
i,
|
|
552
|
+
r
|
|
553
|
+
)), `epubcfi(${n})`;
|
|
535
554
|
}
|
|
536
|
-
function
|
|
537
|
-
return typeof e == "string" ?
|
|
555
|
+
function m(e, t = !1) {
|
|
556
|
+
return typeof e == "string" ? m(O(e), t) : "parent" in e ? t ? e.parent.concat(e.end) : e.parent.concat(e.start) : e;
|
|
538
557
|
}
|
|
539
|
-
function
|
|
558
|
+
function V(e) {
|
|
540
559
|
return e.offset !== void 0 ? 1 : e.index !== void 0 ? 2 : e.temporal !== void 0 || e.spatial !== void 0 ? 3 : 4;
|
|
541
560
|
}
|
|
542
561
|
function q(e, t) {
|
|
543
562
|
var r, o, l, f;
|
|
544
|
-
const n = typeof e == "string" ?
|
|
563
|
+
const n = typeof e == "string" ? O(e) : e, i = typeof t == "string" ? O(t) : t;
|
|
545
564
|
if ("parent" in n || "parent" in i)
|
|
546
|
-
return q(
|
|
547
|
-
for (let
|
|
548
|
-
const c = n[
|
|
549
|
-
for (let u = 0; u <=
|
|
550
|
-
const
|
|
551
|
-
if (!
|
|
552
|
-
if (!
|
|
553
|
-
const $ =
|
|
554
|
-
if ($ !==
|
|
555
|
-
return $ -
|
|
556
|
-
if (
|
|
557
|
-
if (
|
|
558
|
-
const R =
|
|
565
|
+
return q(m(n), m(i)) || q(m(n, !0), m(i, !0));
|
|
566
|
+
for (let a = 0; a < Math.max(n.length, i.length); a++) {
|
|
567
|
+
const c = n[a] || [], s = i[a] || [], d = Math.max(c.length, s.length) - 1;
|
|
568
|
+
for (let u = 0; u <= d; u++) {
|
|
569
|
+
const h = c[u], x = s[u];
|
|
570
|
+
if (!h) return -1;
|
|
571
|
+
if (!x) return 1;
|
|
572
|
+
const $ = V(h), I = V(x);
|
|
573
|
+
if ($ !== I)
|
|
574
|
+
return $ - I;
|
|
575
|
+
if (h.index > x.index) return 1;
|
|
576
|
+
if (h.index < x.index) return -1;
|
|
577
|
+
const R = h.temporal !== void 0, k = x.temporal !== void 0;
|
|
559
578
|
if (R && !k) return 1;
|
|
560
579
|
if (!R && k) return -1;
|
|
561
580
|
if (R && k) {
|
|
562
|
-
if ((
|
|
563
|
-
if ((
|
|
581
|
+
if ((h.temporal ?? 0) > (x.temporal ?? 0)) return 1;
|
|
582
|
+
if ((h.temporal ?? 0) < (x.temporal ?? 0)) return -1;
|
|
564
583
|
}
|
|
565
|
-
const A =
|
|
584
|
+
const A = h.spatial !== void 0, C = x.spatial !== void 0;
|
|
566
585
|
if (A && !C) return 1;
|
|
567
586
|
if (!A && C) return -1;
|
|
568
587
|
if (A && C) {
|
|
569
|
-
const F = ((r =
|
|
570
|
-
if (F >
|
|
571
|
-
if (F <
|
|
572
|
-
const
|
|
573
|
-
if (
|
|
574
|
-
if (
|
|
588
|
+
const F = ((r = h.spatial) == null ? void 0 : r[1]) ?? 0, B = ((o = x.spatial) == null ? void 0 : o[1]) ?? 0;
|
|
589
|
+
if (F > B) return 1;
|
|
590
|
+
if (F < B) return -1;
|
|
591
|
+
const _ = ((l = h.spatial) == null ? void 0 : l[0]) ?? 0, L = ((f = x.spatial) == null ? void 0 : f[0]) ?? 0;
|
|
592
|
+
if (_ > L) return 1;
|
|
593
|
+
if (_ < L) return -1;
|
|
575
594
|
}
|
|
576
|
-
if (u ===
|
|
577
|
-
if ((
|
|
578
|
-
if ((
|
|
595
|
+
if (u === d) {
|
|
596
|
+
if ((h.offset ?? 0) > (x.offset ?? 0)) return 1;
|
|
597
|
+
if ((h.offset ?? 0) < (x.offset ?? 0)) return -1;
|
|
579
598
|
}
|
|
580
599
|
}
|
|
581
600
|
}
|
|
582
601
|
return 0;
|
|
583
602
|
}
|
|
584
|
-
function
|
|
603
|
+
function ue(e) {
|
|
585
604
|
let t = `/${e.index}`;
|
|
586
605
|
if (e.id) {
|
|
587
606
|
if (t += `[${g(e.id)}`, e.extensions)
|
|
@@ -596,22 +615,22 @@ function de(e) {
|
|
|
596
615
|
n.push(`;${i}=${g(r)}`);
|
|
597
616
|
return n.length > 0 && (t += `[${n.join("")}]`), t;
|
|
598
617
|
}
|
|
599
|
-
function
|
|
600
|
-
return e.map((t) =>
|
|
618
|
+
function b(e) {
|
|
619
|
+
return e.map((t) => ue(t)).join("");
|
|
601
620
|
}
|
|
602
|
-
function
|
|
621
|
+
function Ne(e) {
|
|
603
622
|
if (Array.isArray(e))
|
|
604
|
-
return `epubcfi(${e.map(
|
|
605
|
-
const t = e.parent.map(
|
|
623
|
+
return `epubcfi(${e.map(b).join("!")})`;
|
|
624
|
+
const t = e.parent.map(b).join("!"), n = e.start.map(b).join("!"), i = e.end.map(b).join("!");
|
|
606
625
|
return `epubcfi(${t},${n},${i})`;
|
|
607
626
|
}
|
|
608
627
|
export {
|
|
609
628
|
q as compare,
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
629
|
+
ge as generate,
|
|
630
|
+
P as isParsedCfiRange,
|
|
631
|
+
O as parse,
|
|
632
|
+
he as resolve,
|
|
633
|
+
xe as resolveExtensions,
|
|
634
|
+
Ne as serialize
|
|
616
635
|
};
|
|
617
636
|
//# sourceMappingURL=index.js.map
|