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