@prose-reader/cfi 1.215.0 → 1.217.0

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