@prose-reader/cfi 1.212.0 → 1.213.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 +2 -0
- package/dist/index.js +113 -111
- 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/generate.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
function
|
|
1
|
+
function Q(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 Z(e, t) {
|
|
9
9
|
if (e === t) return e;
|
|
10
|
-
const n =
|
|
10
|
+
const n = Q(e), i = new Set(n);
|
|
11
11
|
let r = t;
|
|
12
12
|
for (; r; ) {
|
|
13
13
|
if (i.has(r))
|
|
@@ -16,23 +16,23 @@ function ee(e, t) {
|
|
|
16
16
|
}
|
|
17
17
|
return null;
|
|
18
18
|
}
|
|
19
|
-
const
|
|
19
|
+
const ee = /[\[\]\^,();]/g;
|
|
20
20
|
function g(e) {
|
|
21
|
-
return e.replace(
|
|
21
|
+
return e.replace(ee, "^$&");
|
|
22
22
|
}
|
|
23
|
-
const
|
|
24
|
-
function
|
|
25
|
-
const t = e.match(
|
|
23
|
+
const ne = /^epubcfi\((.*)\)$/, w = (e) => e.nodeType === Node.ELEMENT_NODE, b = (e) => typeof e == "object" && e !== null && "nodeType" in e && (e.nodeType === Node.ELEMENT_NODE || e.nodeType === Node.TEXT_NODE), te = (e) => e.nodeType === Node.TEXT_NODE;
|
|
24
|
+
function re(e) {
|
|
25
|
+
const t = e.match(ne);
|
|
26
26
|
return t && t[1] || e;
|
|
27
27
|
}
|
|
28
|
-
function
|
|
28
|
+
function ie(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 =
|
|
35
|
+
}, f = re(e).trim(), d = Array.from(f).concat("");
|
|
36
36
|
for (let c = 0; c < d.length; c++) {
|
|
37
37
|
const s = d[c];
|
|
38
38
|
if (!s) {
|
|
@@ -113,7 +113,7 @@ 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 se(e) {
|
|
117
117
|
var r;
|
|
118
118
|
const t = [], n = {};
|
|
119
119
|
let i = -1;
|
|
@@ -147,32 +147,32 @@ function oe(e) {
|
|
|
147
147
|
if (d === 0 && u && !l.id)
|
|
148
148
|
l.id = a;
|
|
149
149
|
else if (a !== "") {
|
|
150
|
-
const
|
|
151
|
-
l.text =
|
|
150
|
+
const x = a.split(",").map((h) => h.trim());
|
|
151
|
+
l.text = x;
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
return t;
|
|
157
157
|
}
|
|
158
|
-
function
|
|
158
|
+
function I(e) {
|
|
159
159
|
const t = H(e, "!");
|
|
160
|
-
return U(e, t).map(
|
|
160
|
+
return U(e, t).map(se);
|
|
161
161
|
}
|
|
162
162
|
function p(e) {
|
|
163
163
|
if (!e)
|
|
164
164
|
throw new Error("CFI string cannot be empty");
|
|
165
|
-
const t =
|
|
165
|
+
const t = ie(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 I(t);
|
|
171
171
|
const [i, r, o] = U(t, n);
|
|
172
172
|
return {
|
|
173
|
-
parent:
|
|
174
|
-
start:
|
|
175
|
-
end:
|
|
173
|
+
parent: I(i || []),
|
|
174
|
+
start: I(r || []),
|
|
175
|
+
end: I(o || [])
|
|
176
176
|
};
|
|
177
177
|
}
|
|
178
178
|
function M(e) {
|
|
@@ -196,23 +196,23 @@ function D(e, t, n = { asRange: !1 }) {
|
|
|
196
196
|
if (i)
|
|
197
197
|
return V(e, t);
|
|
198
198
|
const r = e.start[0] || [];
|
|
199
|
-
return
|
|
199
|
+
return m(r, t, n);
|
|
200
200
|
}
|
|
201
201
|
if (e[0])
|
|
202
|
-
return
|
|
202
|
+
return m(e[0], t, n);
|
|
203
203
|
throw new Error("Invalid CFI structure");
|
|
204
204
|
}
|
|
205
205
|
function V(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 a =
|
|
210
|
-
|
|
209
|
+
const a = m(n, t);
|
|
210
|
+
b(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 = m(i, t), f = m(r, t);
|
|
215
|
+
if (!b(l.node) || !b(f.node))
|
|
216
216
|
throw new Error("Failed to resolve start or end node in CFI range");
|
|
217
217
|
const d = l.node, c = f.node, s = t.createRange();
|
|
218
218
|
return s.setStart(
|
|
@@ -227,7 +227,7 @@ function V(e, t) {
|
|
|
227
227
|
isRange: !0
|
|
228
228
|
};
|
|
229
229
|
}
|
|
230
|
-
function
|
|
230
|
+
function oe(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];
|
|
@@ -238,7 +238,7 @@ function le(e) {
|
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
|
-
function
|
|
241
|
+
function S(e) {
|
|
242
242
|
return e.index % 2 !== 0;
|
|
243
243
|
}
|
|
244
244
|
function he(e) {
|
|
@@ -246,7 +246,7 @@ function he(e) {
|
|
|
246
246
|
return i == null ? void 0 : i.extensions;
|
|
247
247
|
}
|
|
248
248
|
function G(e) {
|
|
249
|
-
const t =
|
|
249
|
+
const t = oe(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,14 +255,14 @@ function G(e) {
|
|
|
255
255
|
extensions: n
|
|
256
256
|
};
|
|
257
257
|
}
|
|
258
|
-
function
|
|
258
|
+
function N(e, t) {
|
|
259
259
|
return {
|
|
260
260
|
node: e,
|
|
261
261
|
isRange: !1,
|
|
262
262
|
...G(t)
|
|
263
263
|
};
|
|
264
264
|
}
|
|
265
|
-
function
|
|
265
|
+
function T(e, t) {
|
|
266
266
|
return {
|
|
267
267
|
node: e,
|
|
268
268
|
isRange: !0,
|
|
@@ -273,7 +273,7 @@ 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
|
+
te(t) && i.setStart(t, r || 0);
|
|
277
277
|
}
|
|
278
278
|
return i;
|
|
279
279
|
}
|
|
@@ -282,7 +282,7 @@ function X(e, t, n, i) {
|
|
|
282
282
|
for (let o = n; o < t.length; o++) {
|
|
283
283
|
const l = t[o];
|
|
284
284
|
if (!r || !l) break;
|
|
285
|
-
if (
|
|
285
|
+
if (S(l)) {
|
|
286
286
|
const f = l.index - 1;
|
|
287
287
|
if (f >= 0 && f < r.childNodes.length)
|
|
288
288
|
r = r.childNodes[f];
|
|
@@ -309,37 +309,37 @@ function X(e, t, n, i) {
|
|
|
309
309
|
}
|
|
310
310
|
return r;
|
|
311
311
|
}
|
|
312
|
-
function
|
|
312
|
+
function m(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 N(null);
|
|
318
318
|
}
|
|
319
|
-
const { node: o, remainingPathIndex: l } =
|
|
319
|
+
const { node: o, remainingPathIndex: l } = le(t, e);
|
|
320
320
|
if (o && l >= e.length) {
|
|
321
321
|
const s = e.at(-1);
|
|
322
|
-
if (s &&
|
|
322
|
+
if (s && S(s)) {
|
|
323
323
|
const a = s.index - 1;
|
|
324
324
|
if (a >= 0 && a < o.childNodes.length) {
|
|
325
325
|
const u = o.childNodes[a];
|
|
326
|
-
return
|
|
326
|
+
return N(u, s);
|
|
327
327
|
}
|
|
328
328
|
}
|
|
329
329
|
if (r) {
|
|
330
330
|
const a = W(t, o, s == null ? void 0 : s.offset);
|
|
331
|
-
return
|
|
331
|
+
return T(a, s);
|
|
332
332
|
}
|
|
333
|
-
return
|
|
333
|
+
return N(o, s);
|
|
334
334
|
}
|
|
335
335
|
let f = o || t.documentElement;
|
|
336
336
|
const d = o ? l : 0;
|
|
337
337
|
if (r && e.length > 0) {
|
|
338
338
|
const s = e[e.length - 1];
|
|
339
|
-
if (s && !
|
|
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), T(u, s);
|
|
343
343
|
}
|
|
344
344
|
const a = X(
|
|
345
345
|
f,
|
|
@@ -349,11 +349,11 @@ function E(e, t, n = {}) {
|
|
|
349
349
|
);
|
|
350
350
|
if (a) {
|
|
351
351
|
const u = Array.from(a.childNodes).filter(
|
|
352
|
-
(
|
|
352
|
+
(h) => h.nodeType === Node.ELEMENT_NODE
|
|
353
353
|
);
|
|
354
354
|
if (Math.floor(s.index / 2) - 1 === u.length) {
|
|
355
|
-
const
|
|
356
|
-
return
|
|
355
|
+
const h = t.createRange();
|
|
356
|
+
return h.selectNodeContents(a), h.collapse(!1), T(h, s);
|
|
357
357
|
}
|
|
358
358
|
}
|
|
359
359
|
}
|
|
@@ -361,16 +361,16 @@ function E(e, t, n = {}) {
|
|
|
361
361
|
if (f = X(f, e, d, i), !f) {
|
|
362
362
|
if (i)
|
|
363
363
|
throw new Error("Failed to resolve CFI path");
|
|
364
|
-
return
|
|
364
|
+
return N(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 T(s, c);
|
|
370
370
|
}
|
|
371
|
-
return
|
|
371
|
+
return N(f, c);
|
|
372
372
|
}
|
|
373
|
-
function
|
|
373
|
+
function le(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) {
|
|
@@ -390,13 +390,13 @@ function J(e, t, n = {}) {
|
|
|
390
390
|
}
|
|
391
391
|
return i.substring(0, Math.min(i.length, r));
|
|
392
392
|
}
|
|
393
|
-
function
|
|
393
|
+
function fe(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
|
-
function
|
|
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 += fe(n)), i;
|
|
400
400
|
}
|
|
401
401
|
function K(e, t, n) {
|
|
402
402
|
let i = e;
|
|
@@ -406,7 +406,7 @@ function K(e, t, n) {
|
|
|
406
406
|
}
|
|
407
407
|
return i;
|
|
408
408
|
}
|
|
409
|
-
function
|
|
409
|
+
function P(e, t, n = {}, i) {
|
|
410
410
|
var d;
|
|
411
411
|
let r = "", o = e, l = null;
|
|
412
412
|
if (e.nodeType === Node.TEXT_NODE) {
|
|
@@ -417,38 +417,42 @@ function j(e, t, n = {}, i) {
|
|
|
417
417
|
const a = Array.from(c.childNodes).indexOf(e);
|
|
418
418
|
if (a === -1)
|
|
419
419
|
throw new Error("Node not found in parent's children");
|
|
420
|
-
if (r = `/${a + 1}`,
|
|
421
|
-
const u = c.id,
|
|
422
|
-
r = `/${
|
|
420
|
+
if (r = `/${a + 1}`, w(c) && c.id) {
|
|
421
|
+
const u = c.id, x = Array.from(((d = c.parentNode) == null ? void 0 : d.childNodes) || []);
|
|
422
|
+
r = `/${x.slice(0, x.indexOf(c) + 1).filter((y) => y.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
427
|
for (l && n.includeTextAssertions && (f = J(l, t, n)); o != null && o.parentNode; ) {
|
|
428
|
-
if (!(l && o === l.parentNode && r.includes(`[${
|
|
428
|
+
if (!(l && o === l.parentNode && r.includes(`[${w(o) ? o.id : ""}]`))) {
|
|
429
429
|
const c = o.parentNode, s = Array.from(c.childNodes), a = s.indexOf(o);
|
|
430
430
|
if (a === -1)
|
|
431
431
|
throw new Error("Node not found in parent's children");
|
|
432
|
-
const u = s.slice(0, a + 1).filter((
|
|
433
|
-
let
|
|
434
|
-
o.nodeType, Node.ELEMENT_NODE,
|
|
435
|
-
const
|
|
436
|
-
|
|
432
|
+
const u = s.slice(0, a + 1).filter(($) => $.nodeType === Node.ELEMENT_NODE);
|
|
433
|
+
let x;
|
|
434
|
+
o.nodeType, Node.ELEMENT_NODE, x = u.length;
|
|
435
|
+
const h = x * 2;
|
|
436
|
+
w(o) && o.id ? r = `/${h}[${g(o.id)}]${r}` : r = `/${h}${r}`;
|
|
437
437
|
}
|
|
438
438
|
if (o.parentNode.nodeName.toLowerCase() === "html")
|
|
439
439
|
break;
|
|
440
440
|
o = o.parentNode;
|
|
441
441
|
}
|
|
442
|
-
|
|
442
|
+
if (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 = K(r, f, n.includeSideBias),
|
|
446
|
+
), r = K(r, f, n.includeSideBias), n.extensions && Object.keys(n.extensions).length > 0) {
|
|
447
|
+
const c = O(n.extensions);
|
|
448
|
+
r.includes("[") ? r = r.replace(/\]$/, `;${c}]`) : r = `${r}[;${c}]`;
|
|
449
|
+
}
|
|
450
|
+
return r;
|
|
447
451
|
}
|
|
448
452
|
function z(e, t, n, i = {}, r) {
|
|
449
453
|
if (e === t) {
|
|
450
454
|
let d = n !== void 0 ? `:${n}` : "";
|
|
451
|
-
return d =
|
|
455
|
+
return d = j(d, r == null ? void 0 : r.temporal, r == null ? void 0 : r.spatial), d;
|
|
452
456
|
}
|
|
453
457
|
const o = [];
|
|
454
458
|
let l = t;
|
|
@@ -465,10 +469,10 @@ function z(e, t, n, i = {}, r) {
|
|
|
465
469
|
if (s === -1)
|
|
466
470
|
throw new Error("Node not found in parent's children");
|
|
467
471
|
const a = s + 1;
|
|
468
|
-
|
|
472
|
+
w(l) && l.id ? o.unshift(`/${a}[${g(l.id)}]`) : o.unshift(`/${a}`), l = d;
|
|
469
473
|
}
|
|
470
474
|
let f = o.join("");
|
|
471
|
-
if (n !== void 0 && (f += `:${n}`), f =
|
|
475
|
+
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) {
|
|
472
476
|
const d = J(t, n, i);
|
|
473
477
|
f = K(
|
|
474
478
|
f,
|
|
@@ -476,17 +480,17 @@ function z(e, t, n, i = {}, r) {
|
|
|
476
480
|
i.includeSideBias
|
|
477
481
|
);
|
|
478
482
|
}
|
|
479
|
-
return f =
|
|
483
|
+
return f = ce(f, i.extensions), f;
|
|
480
484
|
}
|
|
481
|
-
const
|
|
482
|
-
function
|
|
483
|
-
return !t || Object.keys(t).length === 0 ? e : e.endsWith("]") ? `${e.substring(0, e.length - 1)}[;${
|
|
485
|
+
const O = (e) => Object.entries(e).map(([t, n]) => `${t}=${encodeURIComponent(g(n))}`).join(";");
|
|
486
|
+
function ce(e, t) {
|
|
487
|
+
return !t || Object.keys(t).length === 0 ? e : e.endsWith("]") ? `${e.substring(0, e.length - 1)}[;${O(t)}]` : `${e}[;${O(t)}]`;
|
|
484
488
|
}
|
|
485
489
|
function ae(e, t, n, i, r = {}, o, l) {
|
|
486
|
-
const f =
|
|
490
|
+
const f = Z(e, n);
|
|
487
491
|
if (!f)
|
|
488
492
|
throw new Error("No common ancestor found");
|
|
489
|
-
const d =
|
|
493
|
+
const d = P(f, void 0, r), c = z(
|
|
490
494
|
f,
|
|
491
495
|
e,
|
|
492
496
|
t,
|
|
@@ -500,24 +504,22 @@ function ae(e, t, n, i, r = {}, o, l) {
|
|
|
500
504
|
l
|
|
501
505
|
);
|
|
502
506
|
if (r.extensions && Object.keys(r.extensions).length > 0) {
|
|
503
|
-
const a =
|
|
504
|
-
return `${
|
|
507
|
+
const a = O(r.extensions), u = d.includes(`;${a}`) ? d : d.includes("[") ? d.replace(/\]$/, `;${a}]`) : `${d}[;${a}]`, x = c.includes(`;${a}`) ? c : c.includes("[") ? c.replace(/\]$/, `;${a}]`) : `${c}[;${a}]`, h = s.includes(`;${a}`) ? s : s.includes("[") ? s.replace(/\]$/, `;${a}]`) : `${s}[;${a}]`;
|
|
508
|
+
return `${u},${x},${h}`;
|
|
505
509
|
}
|
|
506
510
|
return `${d},${c},${s}`;
|
|
507
511
|
}
|
|
508
512
|
function xe(e, t = {}) {
|
|
509
|
-
if (
|
|
510
|
-
return `epubcfi(${
|
|
511
|
-
if ("node" in e && !("start" in e))
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
t,
|
|
516
|
-
e
|
|
517
|
-
)})`;
|
|
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})`;
|
|
518
|
+
}
|
|
518
519
|
if ("start" in e && "end" in e) {
|
|
519
520
|
const { start: n, end: i } = e;
|
|
520
|
-
|
|
521
|
+
let r = "";
|
|
522
|
+
return n.spineIndex !== void 0 && (r = `/6/${(n.spineIndex + 1) * 2}`, n.spineId && (r += `[${g(n.spineId)}]`), r += "!"), r += ae(
|
|
521
523
|
n.node,
|
|
522
524
|
n.offset ?? 0,
|
|
523
525
|
i.node,
|
|
@@ -525,14 +527,14 @@ function xe(e, t = {}) {
|
|
|
525
527
|
t,
|
|
526
528
|
n,
|
|
527
529
|
i
|
|
528
|
-
)})`;
|
|
530
|
+
), `epubcfi(${r})`;
|
|
529
531
|
}
|
|
530
532
|
throw new Error(
|
|
531
533
|
"Invalid argument: expected Node, CfiPosition, or {start, end} object"
|
|
532
534
|
);
|
|
533
535
|
}
|
|
534
|
-
function
|
|
535
|
-
return typeof e == "string" ?
|
|
536
|
+
function E(e, t = !1) {
|
|
537
|
+
return typeof e == "string" ? E(p(e), t) : "parent" in e ? t ? e.parent.concat(e.end) : e.parent.concat(e.start) : e;
|
|
536
538
|
}
|
|
537
539
|
function Y(e) {
|
|
538
540
|
return e.offset !== void 0 ? 1 : e.index !== void 0 ? 2 : e.temporal !== void 0 || e.spatial !== void 0 ? 3 : 4;
|
|
@@ -541,39 +543,39 @@ function q(e, t) {
|
|
|
541
543
|
var r, o, l, f;
|
|
542
544
|
const n = typeof e == "string" ? p(e) : e, i = typeof t == "string" ? p(t) : t;
|
|
543
545
|
if ("parent" in n || "parent" in i)
|
|
544
|
-
return q(
|
|
546
|
+
return q(E(n), E(i)) || q(E(n, !0), E(i, !0));
|
|
545
547
|
for (let d = 0; d < Math.max(n.length, i.length); d++) {
|
|
546
548
|
const c = n[d] || [], s = i[d] || [], a = Math.max(c.length, s.length) - 1;
|
|
547
549
|
for (let u = 0; u <= a; u++) {
|
|
548
|
-
const
|
|
549
|
-
if (!
|
|
550
|
-
if (!
|
|
551
|
-
const
|
|
552
|
-
if (
|
|
553
|
-
return
|
|
554
|
-
if (
|
|
555
|
-
if (
|
|
556
|
-
const R =
|
|
557
|
-
if (R && !
|
|
558
|
-
if (!R &&
|
|
559
|
-
if (R &&
|
|
560
|
-
if ((
|
|
561
|
-
if ((
|
|
550
|
+
const x = c[u], h = s[u];
|
|
551
|
+
if (!x) return -1;
|
|
552
|
+
if (!h) return 1;
|
|
553
|
+
const $ = Y(x), y = Y(h);
|
|
554
|
+
if ($ !== y)
|
|
555
|
+
return $ - y;
|
|
556
|
+
if (x.index > h.index) return 1;
|
|
557
|
+
if (x.index < h.index) return -1;
|
|
558
|
+
const R = x.temporal !== void 0, k = h.temporal !== void 0;
|
|
559
|
+
if (R && !k) return 1;
|
|
560
|
+
if (!R && k) return -1;
|
|
561
|
+
if (R && k) {
|
|
562
|
+
if ((x.temporal ?? 0) > (h.temporal ?? 0)) return 1;
|
|
563
|
+
if ((x.temporal ?? 0) < (h.temporal ?? 0)) return -1;
|
|
562
564
|
}
|
|
563
|
-
const A =
|
|
565
|
+
const A = x.spatial !== void 0, C = h.spatial !== void 0;
|
|
564
566
|
if (A && !C) return 1;
|
|
565
567
|
if (!A && C) return -1;
|
|
566
568
|
if (A && C) {
|
|
567
|
-
const F = ((r =
|
|
569
|
+
const F = ((r = x.spatial) == null ? void 0 : r[1]) ?? 0, _ = ((o = h.spatial) == null ? void 0 : o[1]) ?? 0;
|
|
568
570
|
if (F > _) return 1;
|
|
569
571
|
if (F < _) return -1;
|
|
570
|
-
const B = ((l =
|
|
572
|
+
const B = ((l = x.spatial) == null ? void 0 : l[0]) ?? 0, L = ((f = h.spatial) == null ? void 0 : f[0]) ?? 0;
|
|
571
573
|
if (B > L) return 1;
|
|
572
574
|
if (B < L) return -1;
|
|
573
575
|
}
|
|
574
576
|
if (u === a) {
|
|
575
|
-
if ((
|
|
576
|
-
if ((
|
|
577
|
+
if ((x.offset ?? 0) > (h.offset ?? 0)) return 1;
|
|
578
|
+
if ((x.offset ?? 0) < (h.offset ?? 0)) return -1;
|
|
577
579
|
}
|
|
578
580
|
}
|
|
579
581
|
}
|
|
@@ -594,13 +596,13 @@ function de(e) {
|
|
|
594
596
|
n.push(`;${i}=${g(r)}`);
|
|
595
597
|
return n.length > 0 && (t += `[${n.join("")}]`), t;
|
|
596
598
|
}
|
|
597
|
-
function
|
|
599
|
+
function v(e) {
|
|
598
600
|
return e.map((t) => de(t)).join("");
|
|
599
601
|
}
|
|
600
602
|
function ge(e) {
|
|
601
603
|
if (Array.isArray(e))
|
|
602
|
-
return `epubcfi(${e.map(
|
|
603
|
-
const t = e.parent.map(
|
|
604
|
+
return `epubcfi(${e.map(v).join("!")})`;
|
|
605
|
+
const t = e.parent.map(v).join("!"), n = e.start.map(v).join("!"), i = e.end.map(v).join("!");
|
|
604
606
|
return `epubcfi(${t},${n},${i})`;
|
|
605
607
|
}
|
|
606
608
|
export {
|