@prose-reader/cfi 1.214.0 → 1.216.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 +3 -2
- package/dist/index.js +139 -136
- 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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export { parse } from './parse';
|
|
1
|
+
export { parse, type ParsedCfi, type CfiPart } from './parse';
|
|
2
2
|
export { resolve } from './resolve';
|
|
3
3
|
export { generate } from './generate';
|
|
4
4
|
export { compare } from './compare';
|
|
5
|
-
export {
|
|
5
|
+
export { resolveExtensions } from './resolve';
|
|
6
6
|
export { serialize } from './serialize';
|
|
7
|
+
export { isIndirectionOnly, isParsedCfiRange } from './utils';
|
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,27 +16,36 @@ 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
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
46
|
const s = a[c];
|
|
38
47
|
if (!s) {
|
|
39
|
-
n === "/" || n === ":" ? o([n, parseInt(r, 10)]) : n === "~" ? o(["~", parseFloat(r)]) : n === "@" ? o(["@", parseFloat(r)]) : n === "[" ? o(["[", r]) :
|
|
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
51
|
if (s === "^" && !i) {
|
|
@@ -103,17 +112,17 @@ function se(e) {
|
|
|
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;
|
|
@@ -155,64 +164,57 @@ 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, o] =
|
|
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 && P(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
|
-
if (e[0])
|
|
202
|
-
return y(e[0], 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);
|
|
203
205
|
throw new Error("Invalid CFI structure");
|
|
204
206
|
}
|
|
205
|
-
function
|
|
207
|
+
function le(e, t) {
|
|
206
208
|
const n = e.parent[0] || [], i = e.start[0] || [], r = e.end[0] || [];
|
|
207
209
|
let o = t.documentElement;
|
|
208
210
|
if (n.length > 0) {
|
|
209
|
-
const d =
|
|
210
|
-
|
|
211
|
+
const d = p(n, t);
|
|
212
|
+
w(d.node) && (o = d.node);
|
|
211
213
|
}
|
|
212
214
|
if (!o)
|
|
213
215
|
throw new Error("Failed to resolve parent node in CFI range");
|
|
214
|
-
const l =
|
|
215
|
-
if (!
|
|
216
|
+
const l = p(i, t), f = p(r, t);
|
|
217
|
+
if (!w(l.node) || !w(f.node))
|
|
216
218
|
throw new Error("Failed to resolve start or end node in CFI range");
|
|
217
219
|
const a = l.node, c = f.node, s = t.createRange();
|
|
218
220
|
return s.setStart(
|
|
@@ -227,7 +229,7 @@ function G(e, t) {
|
|
|
227
229
|
isRange: !0
|
|
228
230
|
};
|
|
229
231
|
}
|
|
230
|
-
function
|
|
232
|
+
function fe(e) {
|
|
231
233
|
if (e != null && e.side) return e.side;
|
|
232
234
|
if (e != null && e.text && e.text.length > 0) {
|
|
233
235
|
const t = e.text[0];
|
|
@@ -241,12 +243,12 @@ function le(e) {
|
|
|
241
243
|
function S(e) {
|
|
242
244
|
return e.index % 2 !== 0;
|
|
243
245
|
}
|
|
244
|
-
function
|
|
245
|
-
const n = (
|
|
246
|
+
function ge(e) {
|
|
247
|
+
const n = (M(e) ? e.end : e).at(-1), i = n == null ? void 0 : n.at(-1);
|
|
246
248
|
return i == null ? void 0 : i.extensions;
|
|
247
249
|
}
|
|
248
|
-
function
|
|
249
|
-
const t =
|
|
250
|
+
function U(e) {
|
|
251
|
+
const t = fe(e), n = e == null ? void 0 : e.extensions;
|
|
250
252
|
return {
|
|
251
253
|
offset: e == null ? void 0 : e.offset,
|
|
252
254
|
temporal: e == null ? void 0 : e.temporal,
|
|
@@ -255,29 +257,29 @@ function J(e) {
|
|
|
255
257
|
extensions: n
|
|
256
258
|
};
|
|
257
259
|
}
|
|
258
|
-
function
|
|
260
|
+
function N(e, t) {
|
|
259
261
|
return {
|
|
260
262
|
node: e,
|
|
261
263
|
isRange: !1,
|
|
262
|
-
...
|
|
264
|
+
...U(t)
|
|
263
265
|
};
|
|
264
266
|
}
|
|
265
|
-
function
|
|
267
|
+
function T(e, t) {
|
|
266
268
|
return {
|
|
267
269
|
node: e,
|
|
268
270
|
isRange: !0,
|
|
269
|
-
...
|
|
271
|
+
...U(t)
|
|
270
272
|
};
|
|
271
273
|
}
|
|
272
|
-
function
|
|
274
|
+
function D(e, t, n) {
|
|
273
275
|
const i = e.createRange();
|
|
274
276
|
if (i.selectNodeContents(t), n !== void 0) {
|
|
275
277
|
const r = Array.isArray(n) ? n[0] : n;
|
|
276
|
-
|
|
278
|
+
ne(t) && i.setStart(t, r || 0);
|
|
277
279
|
}
|
|
278
280
|
return i;
|
|
279
281
|
}
|
|
280
|
-
function
|
|
282
|
+
function W(e, t, n, i) {
|
|
281
283
|
let r = e;
|
|
282
284
|
for (let o = n; o < t.length; o++) {
|
|
283
285
|
const l = t[o];
|
|
@@ -309,28 +311,28 @@ function X(e, t, n, i) {
|
|
|
309
311
|
}
|
|
310
312
|
return r;
|
|
311
313
|
}
|
|
312
|
-
function
|
|
314
|
+
function p(e, t, n = {}) {
|
|
313
315
|
const { throwOnError: i = !1, asRange: r = !1 } = n;
|
|
314
316
|
if (!t) {
|
|
315
317
|
if (i)
|
|
316
318
|
throw new Error("Document is not available");
|
|
317
|
-
return
|
|
319
|
+
return N(null);
|
|
318
320
|
}
|
|
319
|
-
const { node: o, remainingPathIndex: l } =
|
|
321
|
+
const { node: o, remainingPathIndex: l } = ce(t, e);
|
|
320
322
|
if (o && l >= e.length) {
|
|
321
323
|
const s = e.at(-1);
|
|
322
324
|
if (s && S(s)) {
|
|
323
325
|
const d = s.index - 1;
|
|
324
326
|
if (d >= 0 && d < o.childNodes.length) {
|
|
325
327
|
const u = o.childNodes[d];
|
|
326
|
-
return
|
|
328
|
+
return N(u, s);
|
|
327
329
|
}
|
|
328
330
|
}
|
|
329
331
|
if (r) {
|
|
330
|
-
const d =
|
|
331
|
-
return
|
|
332
|
+
const d = D(t, o, s == null ? void 0 : s.offset);
|
|
333
|
+
return T(d, s);
|
|
332
334
|
}
|
|
333
|
-
return
|
|
335
|
+
return N(o, s);
|
|
334
336
|
}
|
|
335
337
|
let f = o || t.documentElement;
|
|
336
338
|
const a = o ? l : 0;
|
|
@@ -339,9 +341,9 @@ function y(e, t, n = {}) {
|
|
|
339
341
|
if (s && !S(s)) {
|
|
340
342
|
if (s.index === 0 && f) {
|
|
341
343
|
const u = t.createRange();
|
|
342
|
-
return u.setStart(f, 0), u.setEnd(f, 0),
|
|
344
|
+
return u.setStart(f, 0), u.setEnd(f, 0), T(u, s);
|
|
343
345
|
}
|
|
344
|
-
const d =
|
|
346
|
+
const d = W(
|
|
345
347
|
f,
|
|
346
348
|
e.slice(0, -1),
|
|
347
349
|
a,
|
|
@@ -353,24 +355,24 @@ function y(e, t, n = {}) {
|
|
|
353
355
|
);
|
|
354
356
|
if (Math.floor(s.index / 2) - 1 === u.length) {
|
|
355
357
|
const x = t.createRange();
|
|
356
|
-
return x.selectNodeContents(d), x.collapse(!1),
|
|
358
|
+
return x.selectNodeContents(d), x.collapse(!1), T(x, s);
|
|
357
359
|
}
|
|
358
360
|
}
|
|
359
361
|
}
|
|
360
362
|
}
|
|
361
|
-
if (f =
|
|
363
|
+
if (f = W(f, e, a, i), !f) {
|
|
362
364
|
if (i)
|
|
363
365
|
throw new Error("Failed to resolve CFI path");
|
|
364
|
-
return
|
|
366
|
+
return N(null);
|
|
365
367
|
}
|
|
366
368
|
const c = e.at(-1);
|
|
367
369
|
if (r) {
|
|
368
|
-
const s =
|
|
369
|
-
return
|
|
370
|
+
const s = D(t, f, c == null ? void 0 : c.offset);
|
|
371
|
+
return T(s, c);
|
|
370
372
|
}
|
|
371
|
-
return
|
|
373
|
+
return N(f, c);
|
|
372
374
|
}
|
|
373
|
-
function
|
|
375
|
+
function ce(e, t) {
|
|
374
376
|
for (let n = t.length - 1; n >= 0; n--) {
|
|
375
377
|
const i = t[n];
|
|
376
378
|
if (i != null && i.id) {
|
|
@@ -380,7 +382,7 @@ function fe(e, t) {
|
|
|
380
382
|
}
|
|
381
383
|
return { node: null, remainingPathIndex: 0 };
|
|
382
384
|
}
|
|
383
|
-
function
|
|
385
|
+
function G(e, t, n = {}) {
|
|
384
386
|
if (!e.textContent || e.textContent.trim() === "")
|
|
385
387
|
return null;
|
|
386
388
|
const i = e.textContent, r = n.textAssertionLength || 10;
|
|
@@ -390,15 +392,15 @@ function K(e, t, n = {}) {
|
|
|
390
392
|
}
|
|
391
393
|
return i.substring(0, Math.min(i.length, r));
|
|
392
394
|
}
|
|
393
|
-
function
|
|
395
|
+
function ae(e) {
|
|
394
396
|
const [t, n] = e, i = Math.max(0, Math.min(100, t)), r = Math.max(0, Math.min(100, n));
|
|
395
397
|
return `@${i}:${r}`;
|
|
396
398
|
}
|
|
397
|
-
function
|
|
399
|
+
function P(e, t, n) {
|
|
398
400
|
let i = e;
|
|
399
|
-
return t !== void 0 && (i += `~${t}`), n !== void 0 && (i +=
|
|
401
|
+
return t !== void 0 && (i += `~${t}`), n !== void 0 && (i += ae(n)), i;
|
|
400
402
|
}
|
|
401
|
-
function
|
|
403
|
+
function J(e, t, n) {
|
|
402
404
|
let i = e;
|
|
403
405
|
if (t && (i += `[${g(t)}]`), n) {
|
|
404
406
|
const r = n === "before" ? "b" : "a";
|
|
@@ -406,7 +408,7 @@ function Q(e, t, n) {
|
|
|
406
408
|
}
|
|
407
409
|
return i;
|
|
408
410
|
}
|
|
409
|
-
function
|
|
411
|
+
function j(e, t, n = {}, i) {
|
|
410
412
|
var a;
|
|
411
413
|
let r = "", o = e, l = null;
|
|
412
414
|
if ((e == null ? void 0 : e.nodeType) === Node.TEXT_NODE) {
|
|
@@ -417,15 +419,15 @@ function M(e, t, n = {}, i) {
|
|
|
417
419
|
const d = Array.from(c.childNodes).indexOf(e);
|
|
418
420
|
if (d === -1)
|
|
419
421
|
throw new Error("Node not found in parent's children");
|
|
420
|
-
if (r = `/${d + 1}`,
|
|
422
|
+
if (r = `/${d + 1}`, b(c) && c.id) {
|
|
421
423
|
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((
|
|
424
|
+
r = `/${h.slice(0, h.indexOf(c) + 1).filter((y) => y.nodeType === Node.ELEMENT_NODE).length * 2}[${g(u)}]${r}`, o = c.parentNode;
|
|
423
425
|
} else
|
|
424
426
|
o = c;
|
|
425
427
|
}
|
|
426
428
|
let f = null;
|
|
427
|
-
for (l && n.includeTextAssertions && (f =
|
|
428
|
-
if (!(l && o === l.parentNode && r.includes(`[${
|
|
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 : ""}]`))) {
|
|
429
431
|
const c = o.parentNode, s = Array.from(c.childNodes), d = s.indexOf(o);
|
|
430
432
|
if (d === -1)
|
|
431
433
|
throw new Error("Node not found in parent's children");
|
|
@@ -433,22 +435,22 @@ function M(e, t, n = {}, i) {
|
|
|
433
435
|
let h;
|
|
434
436
|
o.nodeType, Node.ELEMENT_NODE, h = u.length;
|
|
435
437
|
const x = h * 2;
|
|
436
|
-
|
|
438
|
+
b(o) && o.id ? r = `/${x}[${g(o.id)}]${r}` : r = `/${x}${r}`;
|
|
437
439
|
}
|
|
438
440
|
if (o.parentNode.nodeName.toLowerCase() === "html")
|
|
439
441
|
break;
|
|
440
442
|
o = o.parentNode;
|
|
441
443
|
}
|
|
442
|
-
return t !== void 0 && (r += `:${t}`), r =
|
|
444
|
+
return t !== void 0 && (r += `:${t}`), r = P(
|
|
443
445
|
r,
|
|
444
446
|
i == null ? void 0 : i.temporal,
|
|
445
447
|
(i == null ? void 0 : i.spatial) || n.spatialOffset
|
|
446
|
-
), r =
|
|
448
|
+
), r = J(r, f, n.includeSideBias), r = m(r, n.extensions), r;
|
|
447
449
|
}
|
|
448
|
-
function
|
|
450
|
+
function X(e, t, n, i = {}, r) {
|
|
449
451
|
if (e === t) {
|
|
450
452
|
let a = n !== void 0 ? `:${n}` : "";
|
|
451
|
-
return a =
|
|
453
|
+
return a = P(a, r == null ? void 0 : r.temporal, r == null ? void 0 : r.spatial), a;
|
|
452
454
|
}
|
|
453
455
|
const o = [];
|
|
454
456
|
let l = t;
|
|
@@ -465,44 +467,44 @@ function z(e, t, n, i = {}, r) {
|
|
|
465
467
|
if (s === -1)
|
|
466
468
|
throw new Error("Node not found in parent's children");
|
|
467
469
|
const d = s + 1;
|
|
468
|
-
|
|
470
|
+
b(l) && l.id ? o.unshift(`/${d}[${g(l.id)}]`) : o.unshift(`/${d}`), l = a;
|
|
469
471
|
}
|
|
470
472
|
let f = o.join("");
|
|
471
|
-
if (n !== void 0 && (f += `:${n}`), f =
|
|
472
|
-
const a =
|
|
473
|
-
f =
|
|
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) {
|
|
474
|
+
const a = G(t, n, i);
|
|
475
|
+
f = J(
|
|
474
476
|
f,
|
|
475
477
|
a,
|
|
476
478
|
i.includeSideBias
|
|
477
479
|
);
|
|
478
480
|
}
|
|
479
|
-
return f =
|
|
481
|
+
return f = m(f, i.extensions), f;
|
|
480
482
|
}
|
|
481
|
-
const
|
|
483
|
+
const de = (e) => Object.entries(e).map(([t, n]) => {
|
|
482
484
|
const i = g(n);
|
|
483
485
|
return `${t}=${encodeURIComponent(i)}`;
|
|
484
486
|
}).join(";");
|
|
485
|
-
function
|
|
487
|
+
function m(e, t) {
|
|
486
488
|
if (!t || Object.keys(t).length === 0)
|
|
487
489
|
return e;
|
|
488
|
-
const n =
|
|
490
|
+
const n = de(t);
|
|
489
491
|
if (e.endsWith("]")) {
|
|
490
492
|
const i = e.lastIndexOf("["), r = e.substring(i + 1, e.length - 1);
|
|
491
493
|
return r.includes(n) ? e : `${e.substring(0, e.length - 1)}${r.includes(";"), ";"}${n}]`;
|
|
492
494
|
}
|
|
493
495
|
return e.endsWith("!") ? e : `${e}[;${n}]`;
|
|
494
496
|
}
|
|
495
|
-
function
|
|
496
|
-
const f =
|
|
497
|
+
function ue(e, t, n, i, r = {}, o, l) {
|
|
498
|
+
const f = Q(e, n);
|
|
497
499
|
if (!f)
|
|
498
500
|
throw new Error("No common ancestor found");
|
|
499
|
-
const a =
|
|
501
|
+
const a = j(f, void 0, r), c = X(
|
|
500
502
|
f,
|
|
501
503
|
e,
|
|
502
504
|
t,
|
|
503
505
|
r,
|
|
504
506
|
o
|
|
505
|
-
), s =
|
|
507
|
+
), s = X(
|
|
506
508
|
f,
|
|
507
509
|
n,
|
|
508
510
|
i,
|
|
@@ -510,39 +512,39 @@ function de(e, t, n, i, r = {}, o, l) {
|
|
|
510
512
|
l
|
|
511
513
|
);
|
|
512
514
|
if (r.extensions && Object.keys(r.extensions).length > 0) {
|
|
513
|
-
const d =
|
|
515
|
+
const d = m(a, r.extensions), u = m(c, r.extensions), h = m(s, r.extensions);
|
|
514
516
|
return `${d},${u},${h}`;
|
|
515
517
|
}
|
|
516
518
|
return `${a},${c},${s}`;
|
|
517
519
|
}
|
|
518
|
-
const
|
|
520
|
+
const z = (e, t, n = {}, i) => {
|
|
519
521
|
const r = "";
|
|
520
522
|
let l = `/6/${(e + 1) * 2}`;
|
|
521
|
-
return t && (l += `[${g(t)}]`), l = i ?
|
|
523
|
+
return t && (l += `[${g(t)}]`), l = i ? m(l, n.extensions) : l, `${l}${r}!`;
|
|
522
524
|
};
|
|
523
|
-
function
|
|
524
|
-
if (
|
|
525
|
-
return `epubcfi(${
|
|
525
|
+
function Ne(e, t = {}) {
|
|
526
|
+
if (w(e))
|
|
527
|
+
return `epubcfi(${j(e, void 0, t)})`;
|
|
526
528
|
let n = "";
|
|
527
529
|
if (!("start" in e))
|
|
528
|
-
return e.spineIndex !== void 0 && (n =
|
|
530
|
+
return e.spineIndex !== void 0 && (n = z(
|
|
529
531
|
e.spineIndex,
|
|
530
532
|
e.spineId,
|
|
531
533
|
t,
|
|
532
534
|
!e.node
|
|
533
|
-
), !e.node) ? `epubcfi(${n})` : (n +=
|
|
535
|
+
), !e.node) ? `epubcfi(${n})` : (n += j(
|
|
534
536
|
e.node ?? null,
|
|
535
537
|
e.offset,
|
|
536
538
|
t,
|
|
537
539
|
e
|
|
538
540
|
), `epubcfi(${n})`);
|
|
539
541
|
const { start: i, end: r } = e;
|
|
540
|
-
return i.spineIndex !== void 0 && (n =
|
|
542
|
+
return i.spineIndex !== void 0 && (n = z(
|
|
541
543
|
i.spineIndex,
|
|
542
544
|
i.spineId,
|
|
543
545
|
t,
|
|
544
546
|
!i.node
|
|
545
|
-
)), i.node && r.node && (n +=
|
|
547
|
+
)), i.node && r.node && (n += ue(
|
|
546
548
|
i.node,
|
|
547
549
|
i.offset ?? 0,
|
|
548
550
|
r.node,
|
|
@@ -552,32 +554,32 @@ function ge(e, t = {}) {
|
|
|
552
554
|
r
|
|
553
555
|
)), `epubcfi(${n})`;
|
|
554
556
|
}
|
|
555
|
-
function
|
|
556
|
-
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;
|
|
557
559
|
}
|
|
558
|
-
function
|
|
560
|
+
function Y(e) {
|
|
559
561
|
return e.offset !== void 0 ? 1 : e.index !== void 0 ? 2 : e.temporal !== void 0 || e.spatial !== void 0 ? 3 : 4;
|
|
560
562
|
}
|
|
561
|
-
function
|
|
563
|
+
function V(e, t) {
|
|
562
564
|
var r, o, l, f;
|
|
563
565
|
const n = typeof e == "string" ? O(e) : e, i = typeof t == "string" ? O(t) : t;
|
|
564
566
|
if ("parent" in n || "parent" in i)
|
|
565
|
-
return
|
|
567
|
+
return V(E(n), E(i)) || V(E(n, !0), E(i, !0));
|
|
566
568
|
for (let a = 0; a < Math.max(n.length, i.length); a++) {
|
|
567
569
|
const c = n[a] || [], s = i[a] || [], d = Math.max(c.length, s.length) - 1;
|
|
568
570
|
for (let u = 0; u <= d; u++) {
|
|
569
571
|
const h = c[u], x = s[u];
|
|
570
572
|
if (!h) return -1;
|
|
571
573
|
if (!x) return 1;
|
|
572
|
-
const $ =
|
|
573
|
-
if ($ !==
|
|
574
|
-
return $ -
|
|
574
|
+
const $ = Y(h), y = Y(x);
|
|
575
|
+
if ($ !== y)
|
|
576
|
+
return $ - y;
|
|
575
577
|
if (h.index > x.index) return 1;
|
|
576
578
|
if (h.index < x.index) return -1;
|
|
577
|
-
const
|
|
578
|
-
if (
|
|
579
|
-
if (!
|
|
580
|
-
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) {
|
|
581
583
|
if ((h.temporal ?? 0) > (x.temporal ?? 0)) return 1;
|
|
582
584
|
if ((h.temporal ?? 0) < (x.temporal ?? 0)) return -1;
|
|
583
585
|
}
|
|
@@ -600,7 +602,7 @@ function q(e, t) {
|
|
|
600
602
|
}
|
|
601
603
|
return 0;
|
|
602
604
|
}
|
|
603
|
-
function
|
|
605
|
+
function he(e) {
|
|
604
606
|
let t = `/${e.index}`;
|
|
605
607
|
if (e.id) {
|
|
606
608
|
if (t += `[${g(e.id)}`, e.extensions)
|
|
@@ -615,22 +617,23 @@ function ue(e) {
|
|
|
615
617
|
n.push(`;${i}=${g(r)}`);
|
|
616
618
|
return n.length > 0 && (t += `[${n.join("")}]`), t;
|
|
617
619
|
}
|
|
618
|
-
function
|
|
619
|
-
return e.map((t) =>
|
|
620
|
+
function v(e) {
|
|
621
|
+
return e.map((t) => he(t)).join("");
|
|
620
622
|
}
|
|
621
|
-
function
|
|
623
|
+
function me(e) {
|
|
622
624
|
if (Array.isArray(e))
|
|
623
|
-
return `epubcfi(${e.map(
|
|
624
|
-
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("!");
|
|
625
627
|
return `epubcfi(${t},${n},${i})`;
|
|
626
628
|
}
|
|
627
629
|
export {
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
630
|
+
V as compare,
|
|
631
|
+
Ne as generate,
|
|
632
|
+
te as isIndirectionOnly,
|
|
633
|
+
M as isParsedCfiRange,
|
|
631
634
|
O as parse,
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
+
xe as resolve,
|
|
636
|
+
ge as resolveExtensions,
|
|
637
|
+
me as serialize
|
|
635
638
|
};
|
|
636
639
|
//# sourceMappingURL=index.js.map
|