@soomo/text-annotator 3.0.0-staging.6 → 3.0.0-staging.7
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.
|
@@ -4,7 +4,7 @@ const $ = {
|
|
|
4
4
|
}, ht = {
|
|
5
5
|
fill: "rgb(0, 128, 255)",
|
|
6
6
|
fillOpacity: 0.45
|
|
7
|
-
},
|
|
7
|
+
}, qt = (t, e, n, o, i) => {
|
|
8
8
|
var a;
|
|
9
9
|
const r = n ? typeof n == "function" ? n(t.annotation, t.state, i) : n : (a = t.state) != null && a.selected ? ht : $;
|
|
10
10
|
return o && o.paint(t, e) || r;
|
|
@@ -13,11 +13,11 @@ const $ = {
|
|
|
13
13
|
return (...o) => {
|
|
14
14
|
clearTimeout(n), n = setTimeout(() => t.apply(void 0, o), e);
|
|
15
15
|
};
|
|
16
|
-
}, Ot = "not-annotatable", D = `.${Ot}`,
|
|
16
|
+
}, Ot = "not-annotatable", D = `.${Ot}`, jt = (t) => {
|
|
17
17
|
var n;
|
|
18
18
|
const e = t.commonAncestorContainer;
|
|
19
19
|
return e instanceof HTMLElement ? !e.closest(D) : !((n = e.parentElement) != null && n.closest(D));
|
|
20
|
-
},
|
|
20
|
+
}, Gt = function* (t) {
|
|
21
21
|
const e = document.createNodeIterator(
|
|
22
22
|
t.commonAncestorContainer,
|
|
23
23
|
NodeFilter.SHOW_ELEMENT,
|
|
@@ -26,12 +26,12 @@ const $ = {
|
|
|
26
26
|
let n;
|
|
27
27
|
for (; n = e.nextNode(); )
|
|
28
28
|
n instanceof HTMLElement && (yield n);
|
|
29
|
-
},
|
|
30
|
-
if (!
|
|
29
|
+
}, Kt = (t) => {
|
|
30
|
+
if (!jt(t))
|
|
31
31
|
return [];
|
|
32
32
|
const e = [];
|
|
33
33
|
let n = null;
|
|
34
|
-
for (const o of
|
|
34
|
+
for (const o of Gt(t)) {
|
|
35
35
|
let i;
|
|
36
36
|
n ? (i = document.createRange(), i.setStartAfter(n), i.setEndBefore(o)) : (i = t.cloneRange(), i.setEndBefore(o)), i.collapsed || e.push(i), n = o;
|
|
37
37
|
}
|
|
@@ -43,7 +43,7 @@ const $ = {
|
|
|
43
43
|
}, dt = (t) => {
|
|
44
44
|
const e = t.cloneContents();
|
|
45
45
|
return e.querySelectorAll(D).forEach((n) => n.remove()), e;
|
|
46
|
-
},
|
|
46
|
+
}, Rn = (t) => {
|
|
47
47
|
const e = t.cloneContents();
|
|
48
48
|
return e.querySelectorAll(D).forEach((n) => n.remove()), e;
|
|
49
49
|
}, mt = (t, e) => {
|
|
@@ -60,7 +60,7 @@ const $ = {
|
|
|
60
60
|
for (let i = 0; i < t + 1; i++)
|
|
61
61
|
o = n.nextNode();
|
|
62
62
|
return o;
|
|
63
|
-
},
|
|
63
|
+
}, Qt = (t) => {
|
|
64
64
|
const {
|
|
65
65
|
commonAncestorContainer: e,
|
|
66
66
|
startContainer: n,
|
|
@@ -86,14 +86,14 @@ const $ = {
|
|
|
86
86
|
l.selectNodeContents(n), l.setStart(n, o);
|
|
87
87
|
const m = b(l), p = document.createRange();
|
|
88
88
|
p.selectNode(i), p.setEnd(i, r);
|
|
89
|
-
const y = b(p), h =
|
|
89
|
+
const y = b(p), h = Jt(t).reverse().map((d) => {
|
|
90
90
|
var w;
|
|
91
91
|
const c = document.createElement("SPAN");
|
|
92
92
|
return (w = d.parentNode) == null || w.insertBefore(c, d), c.appendChild(d), c;
|
|
93
93
|
});
|
|
94
94
|
return { unwrap: f, nodes: [m, ...h, y] };
|
|
95
95
|
}
|
|
96
|
-
},
|
|
96
|
+
}, Jt = (t) => {
|
|
97
97
|
const {
|
|
98
98
|
commonAncestorContainer: e,
|
|
99
99
|
startContainer: n,
|
|
@@ -104,15 +104,15 @@ const $ = {
|
|
|
104
104
|
for (; r != null; )
|
|
105
105
|
r === o && (a = !1), a && s.push(r), r === n && (a = !0), r = i.nextNode();
|
|
106
106
|
return s;
|
|
107
|
-
},
|
|
107
|
+
}, In = (t) => {
|
|
108
108
|
const { startContainer: e, endContainer: n } = t;
|
|
109
109
|
if (e === n)
|
|
110
110
|
return Array.from(t.getClientRects());
|
|
111
111
|
{
|
|
112
|
-
const { unwrap: o, nodes: i } =
|
|
112
|
+
const { unwrap: o, nodes: i } = Qt(t), r = i.reduce((a, s) => [...a, ...s.getClientRects()], []);
|
|
113
113
|
return o(), r;
|
|
114
114
|
}
|
|
115
|
-
},
|
|
115
|
+
}, Zt = (t, e, n = 10, o) => {
|
|
116
116
|
const i = o ? t.startContainer.parentElement.closest(o) : e, r = document.createRange();
|
|
117
117
|
r.setStart(i, 0), r.setEnd(t.startContainer, t.startOffset);
|
|
118
118
|
const a = dt(r).textContent, s = document.createRange();
|
|
@@ -122,7 +122,7 @@ const $ = {
|
|
|
122
122
|
prefix: a.substring(a.length - n),
|
|
123
123
|
suffix: u.substring(0, n)
|
|
124
124
|
};
|
|
125
|
-
},
|
|
125
|
+
}, te = /^\s*$/, ee = (t) => te.test(t.toString()), X = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), ne = (t, e) => {
|
|
126
126
|
const n = (r) => Math.round(r * 10) / 10, o = {
|
|
127
127
|
top: n(t.top),
|
|
128
128
|
bottom: n(t.bottom),
|
|
@@ -146,17 +146,17 @@ const $ = {
|
|
|
146
146
|
return "block-contains";
|
|
147
147
|
} else if (o.top >= i.top && o.bottom <= i.bottom && o.left >= i.left && o.right <= i.right)
|
|
148
148
|
return "block-is-contained";
|
|
149
|
-
},
|
|
149
|
+
}, oe = (t, e) => {
|
|
150
150
|
const n = Math.min(t.left, e.left), o = Math.max(t.right, e.right), i = Math.min(t.top, e.top), r = Math.max(t.bottom, e.bottom);
|
|
151
151
|
return new DOMRect(n, i, o - n, r - i);
|
|
152
|
-
},
|
|
152
|
+
}, ie = (t) => t.reduce((e, n) => {
|
|
153
153
|
if (n.width === 0 || n.height === 0)
|
|
154
154
|
return e;
|
|
155
155
|
let o = [...e], i = !1;
|
|
156
156
|
for (const r of e) {
|
|
157
|
-
const a =
|
|
157
|
+
const a = ne(n, r);
|
|
158
158
|
if (a === "inline-adjacent") {
|
|
159
|
-
o = o.map((s) => s === r ?
|
|
159
|
+
o = o.map((s) => s === r ? oe(n, r) : s), i = !0;
|
|
160
160
|
break;
|
|
161
161
|
} else if (a === "inline-contains") {
|
|
162
162
|
o = o.map((s) => s === r ? n : s), i = !0;
|
|
@@ -170,7 +170,7 @@ const $ = {
|
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
return i ? o : [...o, n];
|
|
173
|
-
}, []),
|
|
173
|
+
}, []), re = (t, e, n) => {
|
|
174
174
|
const o = document.createRange(), i = n ? t.startContainer.parentElement.closest(n) : e;
|
|
175
175
|
o.setStart(i, 0), o.setEnd(t.startContainer, t.startOffset);
|
|
176
176
|
const r = dt(o).textContent, a = t.toString(), s = r.length || 0, u = s + a.length;
|
|
@@ -216,10 +216,10 @@ const $ = {
|
|
|
216
216
|
}, et = (t, e) => X(t.selector) ? t : {
|
|
217
217
|
...t,
|
|
218
218
|
selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : Nt(n, e))
|
|
219
|
-
}, nt = (t, e) => X(t.target.selector) ? t : { ...t, target: et(t.target, e) },
|
|
219
|
+
}, nt = (t, e) => X(t.target.selector) ? t : { ...t, target: et(t.target, e) }, se = (t) => {
|
|
220
220
|
const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: o, innerHeight: i } = window, r = -n, a = -e, s = o - n, u = i - e;
|
|
221
221
|
return { top: e, left: n, minX: r, minY: a, maxX: s, maxY: u };
|
|
222
|
-
},
|
|
222
|
+
}, ae = (t) => {
|
|
223
223
|
let e = /* @__PURE__ */ new Set();
|
|
224
224
|
return (o) => {
|
|
225
225
|
const i = o.map((r) => r.id);
|
|
@@ -228,18 +228,18 @@ const $ = {
|
|
|
228
228
|
}, pt = (t, e, n, o) => {
|
|
229
229
|
const { store: i, selection: r, hover: a } = e;
|
|
230
230
|
let s, u, f;
|
|
231
|
-
const b =
|
|
231
|
+
const b = ae(n), l = (g) => {
|
|
232
232
|
const { x: A, y: x } = t.getBoundingClientRect(), S = i.getAt(g.clientX - A, g.clientY - x);
|
|
233
233
|
S && (!u || u(S)) ? a.current !== S.id && (t.classList.add("hovered"), a.set(S.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
|
|
234
234
|
};
|
|
235
235
|
t.addEventListener("pointermove", l);
|
|
236
236
|
const m = (g = !1) => {
|
|
237
237
|
f && f.clear();
|
|
238
|
-
const A =
|
|
239
|
-
const
|
|
240
|
-
return { annotation: Y, rects:
|
|
238
|
+
const A = se(t), { minX: x, minY: S, maxX: B, maxY: I } = A, k = u ? i.getIntersecting(x, S, B, I).filter(({ annotation: Y }) => u(Y)) : i.getIntersecting(x, S, B, I), Ht = r.selected.map(({ id: Y }) => Y), Pt = k.map(({ annotation: Y, rects: zt }) => {
|
|
239
|
+
const Ft = Ht.includes(Y.id), Wt = Y.id === a.current;
|
|
240
|
+
return { annotation: Y, rects: zt, state: { selected: Ft, hover: Wt, custom: {} } };
|
|
241
241
|
});
|
|
242
|
-
o.redraw(
|
|
242
|
+
o.redraw(Pt, A, s, f, g), setTimeout(() => b(k.map(({ annotation: Y }) => Y)), 1);
|
|
243
243
|
}, p = (g) => {
|
|
244
244
|
f = g, m();
|
|
245
245
|
}, y = (g) => {
|
|
@@ -269,14 +269,14 @@ const $ = {
|
|
|
269
269
|
setPainter: p,
|
|
270
270
|
setVisible: o.setVisible
|
|
271
271
|
};
|
|
272
|
-
},
|
|
272
|
+
}, le = () => {
|
|
273
273
|
const t = document.createElement("canvas");
|
|
274
274
|
return t.width = window.innerWidth, t.height = window.innerHeight, t.className = "r6o-highlight-layer bg", t;
|
|
275
|
-
},
|
|
275
|
+
}, ce = (t, e) => {
|
|
276
276
|
t.width = window.innerWidth, t.height = window.innerHeight;
|
|
277
|
-
},
|
|
277
|
+
}, de = (t) => {
|
|
278
278
|
t.classList.add("r6o-annotatable");
|
|
279
|
-
const e =
|
|
279
|
+
const e = le(), n = e.getContext("2d");
|
|
280
280
|
t.insertBefore(e, t.firstChild);
|
|
281
281
|
const o = (s, u, f, b) => requestAnimationFrame(() => {
|
|
282
282
|
const { width: l, height: m } = e;
|
|
@@ -308,7 +308,7 @@ const $ = {
|
|
|
308
308
|
}
|
|
309
309
|
});
|
|
310
310
|
}), i = ft(() => {
|
|
311
|
-
|
|
311
|
+
ce(e);
|
|
312
312
|
});
|
|
313
313
|
return window.addEventListener("resize", i), {
|
|
314
314
|
destroy: () => {
|
|
@@ -319,8 +319,8 @@ const $ = {
|
|
|
319
319
|
},
|
|
320
320
|
redraw: o
|
|
321
321
|
};
|
|
322
|
-
},
|
|
323
|
-
var
|
|
322
|
+
}, ue = (t, e, n) => pt(t, e, n, de(t));
|
|
323
|
+
var he = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, _ = function(t) {
|
|
324
324
|
return typeof t == "string" ? t.length > 0 : typeof t == "number";
|
|
325
325
|
}, M = function(t, e, n) {
|
|
326
326
|
return e === void 0 && (e = 0), n === void 0 && (n = Math.pow(10, e)), Math.round(n * t) / n + 0;
|
|
@@ -332,7 +332,7 @@ var fe = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, _ = function(t) {
|
|
|
332
332
|
return { r: U(t.r, 0, 255), g: U(t.g, 0, 255), b: U(t.b, 0, 255), a: U(t.a) };
|
|
333
333
|
}, ot = function(t) {
|
|
334
334
|
return { r: M(t.r), g: M(t.g), b: M(t.b), a: M(t.a, 3) };
|
|
335
|
-
},
|
|
335
|
+
}, fe = /^#([0-9a-f]{3,8})$/i, K = function(t) {
|
|
336
336
|
var e = t.toString(16);
|
|
337
337
|
return e.length < 2 ? "0" + e : e;
|
|
338
338
|
}, Vt = function(t) {
|
|
@@ -353,17 +353,17 @@ var fe = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, _ = function(t) {
|
|
|
353
353
|
}, G = function(t) {
|
|
354
354
|
return { h: (e = Vt(t)).h, s: (i = (200 - (n = e.s)) * (o = e.v) / 100) > 0 && i < 200 ? n * o / 100 / (i <= 100 ? i : 200 - i) * 100 : 0, l: i / 2, a: e.a };
|
|
355
355
|
var e, n, o, i;
|
|
356
|
-
},
|
|
357
|
-
var e =
|
|
356
|
+
}, pe = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, ge = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, me = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, be = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, At = { string: [[function(t) {
|
|
357
|
+
var e = fe.exec(t);
|
|
358
358
|
return e ? (t = e[1]).length <= 4 ? { r: parseInt(t[0] + t[0], 16), g: parseInt(t[1] + t[1], 16), b: parseInt(t[2] + t[2], 16), a: t.length === 4 ? M(parseInt(t[3] + t[3], 16) / 255, 2) : 1 } : t.length === 6 || t.length === 8 ? { r: parseInt(t.substr(0, 2), 16), g: parseInt(t.substr(2, 2), 16), b: parseInt(t.substr(4, 2), 16), a: t.length === 8 ? M(parseInt(t.substr(6, 2), 16) / 255, 2) : 1 } : null : null;
|
|
359
359
|
}, "hex"], [function(t) {
|
|
360
|
-
var e =
|
|
360
|
+
var e = me.exec(t) || be.exec(t);
|
|
361
361
|
return e ? e[2] !== e[4] || e[4] !== e[6] ? null : vt({ r: Number(e[1]) / (e[2] ? 100 / 255 : 1), g: Number(e[3]) / (e[4] ? 100 / 255 : 1), b: Number(e[5]) / (e[6] ? 100 / 255 : 1), a: e[7] === void 0 ? 1 : Number(e[7]) / (e[8] ? 100 : 1) }) : null;
|
|
362
362
|
}, "rgb"], [function(t) {
|
|
363
|
-
var e =
|
|
363
|
+
var e = pe.exec(t) || ge.exec(t);
|
|
364
364
|
if (!e)
|
|
365
365
|
return null;
|
|
366
|
-
var n, o, i = wt({ h: (n = e[1], o = e[2], o === void 0 && (o = "deg"), Number(n) * (
|
|
366
|
+
var n, o, i = wt({ h: (n = e[1], o = e[2], o === void 0 && (o = "deg"), Number(n) * (he[o] || 1)), s: Number(e[3]), l: Number(e[4]), a: e[5] === void 0 ? 1 : Number(e[5]) / (e[6] ? 100 : 1) });
|
|
367
367
|
return xt(i);
|
|
368
368
|
}, "hsl"]], object: [[function(t) {
|
|
369
369
|
var e = t.r, n = t.g, o = t.b, i = t.a, r = i === void 0 ? 1 : i;
|
|
@@ -389,7 +389,7 @@ var fe = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, _ = function(t) {
|
|
|
389
389
|
return [o, e[n][1]];
|
|
390
390
|
}
|
|
391
391
|
return [null, void 0];
|
|
392
|
-
},
|
|
392
|
+
}, ve = function(t) {
|
|
393
393
|
return typeof t == "string" ? Et(t.trim(), At.string) : typeof t == "object" && t !== null ? Et(t, At.object) : [null, void 0];
|
|
394
394
|
}, it = function(t, e) {
|
|
395
395
|
var n = G(t);
|
|
@@ -401,7 +401,7 @@ var fe = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, _ = function(t) {
|
|
|
401
401
|
return { h: n.h, s: n.s, l: U(n.l + 100 * e, 0, 100), a: n.a };
|
|
402
402
|
}, Ct = function() {
|
|
403
403
|
function t(e) {
|
|
404
|
-
this.parsed =
|
|
404
|
+
this.parsed = ve(e)[0], this.rgba = this.parsed || { r: 0, g: 0, b: 0, a: 1 };
|
|
405
405
|
}
|
|
406
406
|
return t.prototype.isValid = function() {
|
|
407
407
|
return this.parsed !== null;
|
|
@@ -454,13 +454,13 @@ var fe = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, _ = function(t) {
|
|
|
454
454
|
}(), V = function(t) {
|
|
455
455
|
return t instanceof Ct ? t : new Ct(t);
|
|
456
456
|
};
|
|
457
|
-
const
|
|
457
|
+
const we = (t) => [
|
|
458
458
|
`background-color:${V((t == null ? void 0 : t.fill) || $.fill).alpha((t == null ? void 0 : t.fillOpacity) === void 0 ? $.fillOpacity : t.fillOpacity).toHex()}`,
|
|
459
459
|
t != null && t.underlineThickness ? "text-decoration:underline" : void 0,
|
|
460
460
|
t != null && t.underlineColor ? `text-decoration-color:${t.underlineColor}` : void 0,
|
|
461
461
|
t != null && t.underlineOffset ? `text-underline-offset:${t.underlineOffset}px` : void 0,
|
|
462
462
|
t != null && t.underlineThickness ? `text-decoration-thickness:${t.underlineThickness}px` : void 0
|
|
463
|
-
].filter(Boolean).join(";"),
|
|
463
|
+
].filter(Boolean).join(";"), ye = () => {
|
|
464
464
|
const t = document.createElement("style");
|
|
465
465
|
document.getElementsByTagName("head")[0].appendChild(t);
|
|
466
466
|
let e = /* @__PURE__ */ new Set();
|
|
@@ -478,7 +478,7 @@ const ye = (t) => [
|
|
|
478
478
|
const b = r.map((l) => {
|
|
479
479
|
var y;
|
|
480
480
|
const m = s ? typeof s == "function" ? s(l.annotation, l.state) : s : (y = l.state) != null && y.selected ? ht : $, p = u && u.paint(l, a) || m;
|
|
481
|
-
return `::highlight(_${l.annotation.id}) { ${
|
|
481
|
+
return `::highlight(_${l.annotation.id}) { ${we(p)} }`;
|
|
482
482
|
});
|
|
483
483
|
t.innerHTML = b.join(`
|
|
484
484
|
`), CSS.highlights.clear(), r.forEach(({ annotation: l }) => {
|
|
@@ -487,7 +487,7 @@ const ye = (t) => [
|
|
|
487
487
|
}), e = f;
|
|
488
488
|
}
|
|
489
489
|
};
|
|
490
|
-
},
|
|
490
|
+
}, xe = (t, e, n) => pt(t, e, n, ye());
|
|
491
491
|
var Lt = Object.prototype.hasOwnProperty;
|
|
492
492
|
function ut(t, e) {
|
|
493
493
|
var n, o;
|
|
@@ -514,10 +514,10 @@ function ut(t, e) {
|
|
|
514
514
|
}
|
|
515
515
|
return t !== t && e !== e;
|
|
516
516
|
}
|
|
517
|
-
const
|
|
517
|
+
const Ae = (t, e) => {
|
|
518
518
|
const n = (o, i) => o.x <= i.x + i.width && o.x + o.width >= i.x && o.y <= i.y + i.height && o.y + o.height >= i.y;
|
|
519
519
|
return e.filter((o) => t !== o && n(t, o) && o.width > t.width).length;
|
|
520
|
-
},
|
|
520
|
+
}, Ee = (t) => {
|
|
521
521
|
t.classList.add("r6o-annotatable");
|
|
522
522
|
const e = document.createElement("div");
|
|
523
523
|
e.className = "r6o-span-highlight-layer", t.insertBefore(e, t.firstChild);
|
|
@@ -535,7 +535,7 @@ const Ee = (t, e) => {
|
|
|
535
535
|
const y = p.rects.map((v) => {
|
|
536
536
|
const h = document.createElement("span");
|
|
537
537
|
h.className = "r6o-annotation", h.dataset.annotation = p.annotation.id, h.style.left = `${v.x}px`, h.style.top = `${v.y}px`, h.style.width = `${v.width}px`, h.style.height = `${v.height}px`;
|
|
538
|
-
const d =
|
|
538
|
+
const d = Ae(v, m), c = qt(p, s, u, f, d), w = V((c == null ? void 0 : c.fill) || $.fill).alpha((c == null ? void 0 : c.fillOpacity) === void 0 ? $.fillOpacity : c.fillOpacity).toHex();
|
|
539
539
|
return h.style.backgroundColor = w, c.underlineStyle && (h.style.borderStyle = c.underlineStyle), c.underlineColor && (h.style.borderColor = c.underlineColor), c.underlineThickness && (h.style.borderBottomWidth = `${c.underlineThickness}px`), c.underlineOffset && (h.style.paddingBottom = `${c.underlineOffset}px`), e.appendChild(h), h;
|
|
540
540
|
});
|
|
541
541
|
return { id: p.annotation.id, spans: y };
|
|
@@ -545,29 +545,29 @@ const Ee = (t, e) => {
|
|
|
545
545
|
a ? e.classList.remove("hidden") : e.classList.add("hidden");
|
|
546
546
|
}
|
|
547
547
|
};
|
|
548
|
-
},
|
|
548
|
+
}, Se = (t, e, n) => pt(t, e, n, Ee(t));
|
|
549
549
|
let Q;
|
|
550
|
-
const
|
|
551
|
-
function
|
|
550
|
+
const Ce = new Uint8Array(16);
|
|
551
|
+
function Le() {
|
|
552
552
|
if (!Q && (Q = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !Q))
|
|
553
553
|
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
554
|
-
return Q(
|
|
554
|
+
return Q(Ce);
|
|
555
555
|
}
|
|
556
556
|
const O = [];
|
|
557
557
|
for (let t = 0; t < 256; ++t)
|
|
558
558
|
O.push((t + 256).toString(16).slice(1));
|
|
559
|
-
function
|
|
559
|
+
function Te(t, e = 0) {
|
|
560
560
|
return O[t[e + 0]] + O[t[e + 1]] + O[t[e + 2]] + O[t[e + 3]] + "-" + O[t[e + 4]] + O[t[e + 5]] + "-" + O[t[e + 6]] + O[t[e + 7]] + "-" + O[t[e + 8]] + O[t[e + 9]] + "-" + O[t[e + 10]] + O[t[e + 11]] + O[t[e + 12]] + O[t[e + 13]] + O[t[e + 14]] + O[t[e + 15]];
|
|
561
561
|
}
|
|
562
|
-
const
|
|
563
|
-
randomUUID:
|
|
562
|
+
const Be = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Tt = {
|
|
563
|
+
randomUUID: Be
|
|
564
564
|
};
|
|
565
565
|
function Yt(t, e, n) {
|
|
566
566
|
if (Tt.randomUUID && !e && !t)
|
|
567
567
|
return Tt.randomUUID();
|
|
568
568
|
t = t || {};
|
|
569
|
-
const o = t.random || (t.rng ||
|
|
570
|
-
return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128,
|
|
569
|
+
const o = t.random || (t.rng || Le)();
|
|
570
|
+
return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, Te(o);
|
|
571
571
|
}
|
|
572
572
|
var Bt = Object.prototype.hasOwnProperty;
|
|
573
573
|
function F(t, e) {
|
|
@@ -597,7 +597,7 @@ function F(t, e) {
|
|
|
597
597
|
}
|
|
598
598
|
function st() {
|
|
599
599
|
}
|
|
600
|
-
function
|
|
600
|
+
function Re(t, e) {
|
|
601
601
|
return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function";
|
|
602
602
|
}
|
|
603
603
|
const H = [];
|
|
@@ -605,7 +605,7 @@ function gt(t, e = st) {
|
|
|
605
605
|
let n;
|
|
606
606
|
const o = /* @__PURE__ */ new Set();
|
|
607
607
|
function i(s) {
|
|
608
|
-
if (
|
|
608
|
+
if (Re(t, s) && (t = s, n)) {
|
|
609
609
|
const u = !H.length;
|
|
610
610
|
for (const f of o)
|
|
611
611
|
f[1](), H.push(f, t);
|
|
@@ -627,7 +627,7 @@ function gt(t, e = st) {
|
|
|
627
627
|
}
|
|
628
628
|
return { set: i, update: r, subscribe: a };
|
|
629
629
|
}
|
|
630
|
-
const
|
|
630
|
+
const Ie = (t) => {
|
|
631
631
|
const { subscribe: e, set: n } = gt();
|
|
632
632
|
let o;
|
|
633
633
|
return e((i) => o = i), t.observe(({ changes: i }) => {
|
|
@@ -644,7 +644,7 @@ const Me = (t) => {
|
|
|
644
644
|
set: n
|
|
645
645
|
};
|
|
646
646
|
};
|
|
647
|
-
var
|
|
647
|
+
var Me = /* @__PURE__ */ ((t) => (t.EDIT = "EDIT", t.SELECT = "SELECT", t.NONE = "NONE", t))(Me || {});
|
|
648
648
|
const at = { selected: [] }, Oe = (t, e = "EDIT") => {
|
|
649
649
|
const { subscribe: n, set: o } = gt(at);
|
|
650
650
|
let i = at;
|
|
@@ -711,34 +711,34 @@ function _e(t, e, n) {
|
|
|
711
711
|
const o = t.random || (t.rng || Ve)();
|
|
712
712
|
return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, ke(o);
|
|
713
713
|
}
|
|
714
|
-
const
|
|
714
|
+
const Mn = (t, e, n, o) => ({
|
|
715
715
|
id: _e(),
|
|
716
716
|
annotation: t.id,
|
|
717
717
|
created: n || /* @__PURE__ */ new Date(),
|
|
718
718
|
creator: o,
|
|
719
719
|
...e
|
|
720
|
-
}),
|
|
720
|
+
}), Xe = (t, e) => {
|
|
721
721
|
const n = new Set(t.bodies.map((o) => o.id));
|
|
722
722
|
return e.bodies.filter((o) => !n.has(o.id));
|
|
723
|
-
},
|
|
723
|
+
}, De = (t, e) => {
|
|
724
724
|
const n = new Set(e.bodies.map((o) => o.id));
|
|
725
725
|
return t.bodies.filter((o) => !n.has(o.id));
|
|
726
|
-
},
|
|
726
|
+
}, $e = (t, e) => e.bodies.map((n) => {
|
|
727
727
|
const o = t.bodies.find((i) => i.id === n.id);
|
|
728
728
|
return { newBody: n, oldBody: o && !F(o, n) ? o : void 0 };
|
|
729
|
-
}).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })),
|
|
730
|
-
const n =
|
|
729
|
+
}).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), He = (t, e) => !F(t.target, e.target), _t = (t, e) => {
|
|
730
|
+
const n = Xe(t, e), o = De(t, e), i = $e(t, e);
|
|
731
731
|
return {
|
|
732
732
|
oldValue: t,
|
|
733
733
|
newValue: e,
|
|
734
734
|
bodiesCreated: n.length > 0 ? n : void 0,
|
|
735
735
|
bodiesDeleted: o.length > 0 ? o : void 0,
|
|
736
736
|
bodiesUpdated: i.length > 0 ? i : void 0,
|
|
737
|
-
targetUpdated:
|
|
737
|
+
targetUpdated: He(t, e) ? { oldTarget: t.target, newTarget: e.target } : void 0
|
|
738
738
|
};
|
|
739
739
|
};
|
|
740
740
|
var R = /* @__PURE__ */ ((t) => (t.LOCAL = "LOCAL", t.REMOTE = "REMOTE", t))(R || {});
|
|
741
|
-
const
|
|
741
|
+
const Pe = (t, e) => {
|
|
742
742
|
var n, o;
|
|
743
743
|
const { changes: i, origin: r } = e;
|
|
744
744
|
if (!(!t.options.origin || t.options.origin === r))
|
|
@@ -760,7 +760,7 @@ const ze = (t, e) => {
|
|
|
760
760
|
return !!(Array.isArray(t.options.annotations) ? t.options.annotations : [t.options.annotations]).find((s) => a.has(s));
|
|
761
761
|
} else
|
|
762
762
|
return !0;
|
|
763
|
-
},
|
|
763
|
+
}, ze = (t, e) => {
|
|
764
764
|
const n = new Set((t.created || []).map((l) => l.id)), o = new Set((t.updated || []).map(({ newValue: l }) => l.id)), i = new Set((e.created || []).map((l) => l.id)), r = new Set((e.deleted || []).map((l) => l.id)), a = new Set((e.updated || []).map(({ oldValue: l }) => l.id)), s = new Set((e.updated || []).filter(({ oldValue: l }) => n.has(l.id) || o.has(l.id)).map(({ oldValue: l }) => l.id)), u = [
|
|
765
765
|
...(t.created || []).filter((l) => !r.has(l.id)).map((l) => a.has(l.id) ? e.updated.find(({ oldValue: m }) => m.id === l.id).newValue : l),
|
|
766
766
|
...e.created || []
|
|
@@ -772,14 +772,14 @@ const ze = (t, e) => {
|
|
|
772
772
|
const { oldValue: m, newValue: p } = l;
|
|
773
773
|
if (a.has(p.id)) {
|
|
774
774
|
const y = e.updated.find((v) => v.oldValue.id === p.id).newValue;
|
|
775
|
-
return
|
|
775
|
+
return _t(m, y);
|
|
776
776
|
} else
|
|
777
777
|
return l;
|
|
778
778
|
}),
|
|
779
779
|
...(e.updated || []).filter(({ oldValue: l }) => !s.has(l.id))
|
|
780
780
|
];
|
|
781
781
|
return { created: u, deleted: f, updated: b };
|
|
782
|
-
},
|
|
782
|
+
}, Fe = (t) => t.id !== void 0, We = () => {
|
|
783
783
|
const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (g, A = {}) => n.push({ onChange: g, options: A }), i = (g) => {
|
|
784
784
|
const A = n.findIndex((x) => x.onChange == g);
|
|
785
785
|
A > -1 && n.splice(A, 1);
|
|
@@ -794,7 +794,7 @@ const ze = (t, e) => {
|
|
|
794
794
|
state: [...t.values()]
|
|
795
795
|
};
|
|
796
796
|
n.forEach((S) => {
|
|
797
|
-
|
|
797
|
+
Pe(S, x) && S.onChange(x);
|
|
798
798
|
});
|
|
799
799
|
}, a = (g, A = R.LOCAL) => {
|
|
800
800
|
if (t.get(g.id))
|
|
@@ -803,12 +803,12 @@ const ze = (t, e) => {
|
|
|
803
803
|
}, s = (g, A) => {
|
|
804
804
|
const x = typeof g == "string" ? A : g, S = typeof g == "string" ? g : g.id, B = t.get(S);
|
|
805
805
|
if (B) {
|
|
806
|
-
const I =
|
|
806
|
+
const I = _t(B, x);
|
|
807
807
|
return S === x.id ? t.set(S, x) : (t.delete(S), t.set(x.id, x)), B.bodies.forEach((k) => e.delete(k.id)), x.bodies.forEach((k) => e.set(k.id, x.id)), I;
|
|
808
808
|
} else
|
|
809
809
|
console.warn(`Cannot update annotation ${S} - does not exist`);
|
|
810
810
|
}, u = (g, A = R.LOCAL, x = R.LOCAL) => {
|
|
811
|
-
const S =
|
|
811
|
+
const S = Fe(A) ? x : A, B = s(g, A);
|
|
812
812
|
B && r(S, { updated: [B] });
|
|
813
813
|
}, f = (g, A = R.LOCAL) => {
|
|
814
814
|
const x = g.reduce((S, B) => {
|
|
@@ -965,7 +965,7 @@ const ze = (t, e) => {
|
|
|
965
965
|
}
|
|
966
966
|
};
|
|
967
967
|
};
|
|
968
|
-
let
|
|
968
|
+
let qe = () => ({
|
|
969
969
|
emit(t, ...e) {
|
|
970
970
|
for (let n = 0, o = this.events[t] || [], i = o.length; n < i; n++)
|
|
971
971
|
o[n](...e);
|
|
@@ -979,17 +979,17 @@ let je = () => ({
|
|
|
979
979
|
};
|
|
980
980
|
}
|
|
981
981
|
});
|
|
982
|
-
const
|
|
983
|
-
const e =
|
|
982
|
+
const je = 250, Ge = (t) => {
|
|
983
|
+
const e = qe(), n = [];
|
|
984
984
|
let o = -1, i = !1, r = 0;
|
|
985
985
|
const a = (p) => {
|
|
986
986
|
if (!i) {
|
|
987
987
|
const { changes: y } = p, v = performance.now();
|
|
988
|
-
if (v - r >
|
|
988
|
+
if (v - r > je)
|
|
989
989
|
n.splice(o + 1), n.push(y), o = n.length - 1;
|
|
990
990
|
else {
|
|
991
991
|
const h = n.length - 1;
|
|
992
|
-
n[h] =
|
|
992
|
+
n[h] = ze(n[h], y);
|
|
993
993
|
}
|
|
994
994
|
r = v;
|
|
995
995
|
}
|
|
@@ -1017,13 +1017,13 @@ const Ge = 250, Ke = (t) => {
|
|
|
1017
1017
|
}
|
|
1018
1018
|
}
|
|
1019
1019
|
};
|
|
1020
|
-
},
|
|
1020
|
+
}, Ke = () => {
|
|
1021
1021
|
const { subscribe: t, set: e } = gt([]);
|
|
1022
1022
|
return {
|
|
1023
1023
|
subscribe: t,
|
|
1024
1024
|
set: e
|
|
1025
1025
|
};
|
|
1026
|
-
},
|
|
1026
|
+
}, Qe = (t, e, n, o) => {
|
|
1027
1027
|
const { store: i, selection: r, hover: a, viewport: s } = t, u = /* @__PURE__ */ new Map();
|
|
1028
1028
|
let f = [], b;
|
|
1029
1029
|
const l = (v, h) => {
|
|
@@ -1088,7 +1088,7 @@ const Ge = 250, Ke = (t) => {
|
|
|
1088
1088
|
v ? (d || []).forEach((c) => p("updateAnnotation", c.oldValue, c.newValue)) : (d || []).forEach((c) => p("updateAnnotation", c.newValue, c.oldValue));
|
|
1089
1089
|
};
|
|
1090
1090
|
return e.on("undo", y(!0)), e.on("redo", y(!1)), { on: l, off: m, emit: p };
|
|
1091
|
-
},
|
|
1091
|
+
}, Je = (t) => (e) => e.reduce((n, o) => {
|
|
1092
1092
|
const { parsed: i, error: r } = t.parse(o);
|
|
1093
1093
|
return r ? {
|
|
1094
1094
|
parsed: n.parsed,
|
|
@@ -1099,7 +1099,7 @@ const Ge = 250, Ke = (t) => {
|
|
|
1099
1099
|
} : {
|
|
1100
1100
|
...n
|
|
1101
1101
|
};
|
|
1102
|
-
}, { parsed: [], failed: [] }),
|
|
1102
|
+
}, { parsed: [], failed: [] }), Ze = (t, e, n) => {
|
|
1103
1103
|
const { store: o, selection: i } = t, r = (h) => {
|
|
1104
1104
|
if (n) {
|
|
1105
1105
|
const { parsed: d, error: c } = n.parse(h);
|
|
@@ -1125,7 +1125,7 @@ const Ge = 250, Ke = (t) => {
|
|
|
1125
1125
|
}
|
|
1126
1126
|
}, p = (h, d = !0) => {
|
|
1127
1127
|
if (n) {
|
|
1128
|
-
const { parsed: c, failed: w } =
|
|
1128
|
+
const { parsed: c, failed: w } = Je(n)(h);
|
|
1129
1129
|
w.length > 0 && console.warn(`Discarded ${w.length} invalid annotations`, w), o.bulkAddAnnotation(c, d, R.REMOTE);
|
|
1130
1130
|
} else
|
|
1131
1131
|
o.bulkAddAnnotation(h, d, R.REMOTE);
|
|
@@ -1157,8 +1157,8 @@ const Ge = 250, Ke = (t) => {
|
|
|
1157
1157
|
undo: e.undo,
|
|
1158
1158
|
updateAnnotation: v
|
|
1159
1159
|
};
|
|
1160
|
-
},
|
|
1161
|
-
let
|
|
1160
|
+
}, tn = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
1161
|
+
let en = (t) => crypto.getRandomValues(new Uint8Array(t)), nn = (t, e, n) => {
|
|
1162
1162
|
let o = (2 << Math.log(t.length - 1) / Math.LN2) - 1, i = -~(1.6 * o * e / t.length);
|
|
1163
1163
|
return (r = e) => {
|
|
1164
1164
|
let a = "";
|
|
@@ -1169,13 +1169,13 @@ let nn = (t) => crypto.getRandomValues(new Uint8Array(t)), on = (t, e, n) => {
|
|
|
1169
1169
|
return a;
|
|
1170
1170
|
}
|
|
1171
1171
|
};
|
|
1172
|
-
},
|
|
1172
|
+
}, on = (t, e = 21) => nn(t, e, en), rn = (t = 21) => {
|
|
1173
1173
|
let e = "", n = crypto.getRandomValues(new Uint8Array(t));
|
|
1174
1174
|
for (; t--; )
|
|
1175
|
-
e +=
|
|
1175
|
+
e += tn[n[t] & 63];
|
|
1176
1176
|
return e;
|
|
1177
1177
|
};
|
|
1178
|
-
const
|
|
1178
|
+
const sn = () => ({ isGuest: !0, id: on("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() }), an = (t) => {
|
|
1179
1179
|
const e = JSON.stringify(t);
|
|
1180
1180
|
let n = 0;
|
|
1181
1181
|
for (let o = 0, i = e.length; o < i; o++) {
|
|
@@ -1183,28 +1183,28 @@ const an = () => ({ isGuest: !0, id: rn("1234567890abcdefghijklmnopqrstuvwxyzABC
|
|
|
1183
1183
|
n = (n << 5) - n + r, n |= 0;
|
|
1184
1184
|
}
|
|
1185
1185
|
return `${n}`;
|
|
1186
|
-
},
|
|
1186
|
+
}, Xt = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, ln = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
|
|
1187
1187
|
const { id: o, type: i, purpose: r, value: a, created: s, creator: u, ...f } = n;
|
|
1188
1188
|
return {
|
|
1189
|
-
id: o || `temp-${
|
|
1189
|
+
id: o || `temp-${an(n)}`,
|
|
1190
1190
|
annotation: e,
|
|
1191
1191
|
type: i,
|
|
1192
1192
|
purpose: r,
|
|
1193
1193
|
value: a,
|
|
1194
1194
|
created: s ? new Date(s) : void 0,
|
|
1195
|
-
creator:
|
|
1195
|
+
creator: Xt(u),
|
|
1196
1196
|
...f
|
|
1197
1197
|
};
|
|
1198
|
-
}),
|
|
1198
|
+
}), cn = (t) => t.map((e) => {
|
|
1199
1199
|
var n, o;
|
|
1200
1200
|
const i = { ...e };
|
|
1201
1201
|
return delete i.annotation, (n = i.id) != null && n.startsWith("temp-") && delete i.id, { ...i, created: (o = i.created) == null ? void 0 : o.toISOString() };
|
|
1202
1202
|
});
|
|
1203
|
-
|
|
1203
|
+
rn();
|
|
1204
1204
|
const On = (t, e) => ({
|
|
1205
|
-
parse: (n) =>
|
|
1206
|
-
serialize: (n) =>
|
|
1207
|
-
}),
|
|
1205
|
+
parse: (n) => hn(n),
|
|
1206
|
+
serialize: (n) => fn(n, t, e)
|
|
1207
|
+
}), dn = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, un = (t) => {
|
|
1208
1208
|
const {
|
|
1209
1209
|
id: e,
|
|
1210
1210
|
creator: n,
|
|
@@ -1215,7 +1215,7 @@ const On = (t, e) => ({
|
|
|
1215
1215
|
if (a.length === 0)
|
|
1216
1216
|
return { error: Error(`No targets found for annotation: ${t.id}`) };
|
|
1217
1217
|
const s = {
|
|
1218
|
-
creator:
|
|
1218
|
+
creator: Xt(n),
|
|
1219
1219
|
created: o ? new Date(o) : void 0,
|
|
1220
1220
|
updated: i ? new Date(i) : void 0,
|
|
1221
1221
|
annotation: e,
|
|
@@ -1234,7 +1234,7 @@ const On = (t, e) => ({
|
|
|
1234
1234
|
}
|
|
1235
1235
|
return l;
|
|
1236
1236
|
}, {});
|
|
1237
|
-
if (
|
|
1237
|
+
if (dn(b))
|
|
1238
1238
|
s.selector.push({ id: u.id, ...b });
|
|
1239
1239
|
else {
|
|
1240
1240
|
const l = [
|
|
@@ -1245,14 +1245,14 @@ const On = (t, e) => ({
|
|
|
1245
1245
|
}
|
|
1246
1246
|
}
|
|
1247
1247
|
return { parsed: s };
|
|
1248
|
-
},
|
|
1248
|
+
}, hn = (t) => {
|
|
1249
1249
|
const e = t.id || Yt(), {
|
|
1250
1250
|
creator: n,
|
|
1251
1251
|
created: o,
|
|
1252
1252
|
modified: i,
|
|
1253
1253
|
body: r,
|
|
1254
1254
|
...a
|
|
1255
|
-
} = t, s =
|
|
1255
|
+
} = t, s = ln(r, e), u = un(t);
|
|
1256
1256
|
return "error" in u ? { error: u.error } : {
|
|
1257
1257
|
parsed: {
|
|
1258
1258
|
...a,
|
|
@@ -1261,7 +1261,7 @@ const On = (t, e) => ({
|
|
|
1261
1261
|
target: u.parsed
|
|
1262
1262
|
}
|
|
1263
1263
|
};
|
|
1264
|
-
},
|
|
1264
|
+
}, fn = (t, e, n) => {
|
|
1265
1265
|
const { bodies: o, target: i, ...r } = t, {
|
|
1266
1266
|
selector: a,
|
|
1267
1267
|
creator: s,
|
|
@@ -1269,7 +1269,7 @@ const On = (t, e) => ({
|
|
|
1269
1269
|
updated: f,
|
|
1270
1270
|
...b
|
|
1271
1271
|
} = i, l = a.map((m) => {
|
|
1272
|
-
const { quote: p, start: y, end: v, range: h } = m, { prefix: d, suffix: c } =
|
|
1272
|
+
const { quote: p, start: y, end: v, range: h } = m, { prefix: d, suffix: c } = Zt(h, n), w = [{
|
|
1273
1273
|
type: "TextQuoteSelector",
|
|
1274
1274
|
exact: p,
|
|
1275
1275
|
prefix: d,
|
|
@@ -1291,21 +1291,21 @@ const On = (t, e) => ({
|
|
|
1291
1291
|
"@context": "http://www.w3.org/ns/anno.jsonld",
|
|
1292
1292
|
id: t.id,
|
|
1293
1293
|
type: "Annotation",
|
|
1294
|
-
body:
|
|
1294
|
+
body: cn(t.bodies),
|
|
1295
1295
|
creator: s,
|
|
1296
1296
|
created: u == null ? void 0 : u.toISOString(),
|
|
1297
1297
|
modified: f == null ? void 0 : f.toISOString(),
|
|
1298
1298
|
target: l
|
|
1299
1299
|
};
|
|
1300
1300
|
};
|
|
1301
|
-
function
|
|
1302
|
-
|
|
1301
|
+
function pn(t, e, n, o, i) {
|
|
1302
|
+
Dt(t, e, n || 0, o || t.length - 1, i || gn);
|
|
1303
1303
|
}
|
|
1304
|
-
function
|
|
1304
|
+
function Dt(t, e, n, o, i) {
|
|
1305
1305
|
for (; o > n; ) {
|
|
1306
1306
|
if (o - n > 600) {
|
|
1307
1307
|
var r = o - n + 1, a = e - n + 1, s = Math.log(r), u = 0.5 * Math.exp(2 * s / 3), f = 0.5 * Math.sqrt(s * u * (r - u) / r) * (a - r / 2 < 0 ? -1 : 1), b = Math.max(n, Math.floor(e - a * u / r + f)), l = Math.min(o, Math.floor(e + (r - a) * u / r + f));
|
|
1308
|
-
|
|
1308
|
+
Dt(t, e, b, l, i);
|
|
1309
1309
|
}
|
|
1310
1310
|
var m = t[e], p = n, y = o;
|
|
1311
1311
|
for (W(t, n, e), i(t[o], m) > 0 && W(t, n, o); p < y; ) {
|
|
@@ -1321,10 +1321,10 @@ function W(t, e, n) {
|
|
|
1321
1321
|
var o = t[e];
|
|
1322
1322
|
t[e] = t[n], t[n] = o;
|
|
1323
1323
|
}
|
|
1324
|
-
function
|
|
1324
|
+
function gn(t, e) {
|
|
1325
1325
|
return t < e ? -1 : t > e ? 1 : 0;
|
|
1326
1326
|
}
|
|
1327
|
-
class
|
|
1327
|
+
class mn {
|
|
1328
1328
|
constructor(e = 9) {
|
|
1329
1329
|
this._maxEntries = Math.max(4, e), this._minEntries = Math.max(2, Math.ceil(this._maxEntries * 0.4)), this.clear();
|
|
1330
1330
|
}
|
|
@@ -1400,7 +1400,7 @@ class bn {
|
|
|
1400
1400
|
let s, u, f;
|
|
1401
1401
|
for (; o || r.length; ) {
|
|
1402
1402
|
if (o || (o = r.pop(), u = r[r.length - 1], s = a.pop(), f = !0), o.leaf) {
|
|
1403
|
-
const b =
|
|
1403
|
+
const b = bn(e, o.children, n);
|
|
1404
1404
|
if (b !== -1)
|
|
1405
1405
|
return o.children.splice(b, 1), r.push(o), this._condense(r), this;
|
|
1406
1406
|
}
|
|
@@ -1451,7 +1451,7 @@ class bn {
|
|
|
1451
1451
|
for (; i.push(n), !(n.leaf || i.length - 1 === o); ) {
|
|
1452
1452
|
let r = 1 / 0, a = 1 / 0, s;
|
|
1453
1453
|
for (let u = 0; u < n.children.length; u++) {
|
|
1454
|
-
const f = n.children[u], b = lt(f), l =
|
|
1454
|
+
const f = n.children[u], b = lt(f), l = yn(e, f) - b;
|
|
1455
1455
|
l < a ? (a = l, r = b < r ? b : r, s = f) : l === a && b < r && (r = b, s = f);
|
|
1456
1456
|
}
|
|
1457
1457
|
n = s || n.children[0];
|
|
@@ -1477,14 +1477,14 @@ class bn {
|
|
|
1477
1477
|
_chooseSplitIndex(e, n, o) {
|
|
1478
1478
|
let i, r = 1 / 0, a = 1 / 0;
|
|
1479
1479
|
for (let s = n; s <= o - n; s++) {
|
|
1480
|
-
const u = q(e, 0, s, this.toBBox), f = q(e, s, o, this.toBBox), b =
|
|
1480
|
+
const u = q(e, 0, s, this.toBBox), f = q(e, s, o, this.toBBox), b = xn(u, f), l = lt(u) + lt(f);
|
|
1481
1481
|
b < r ? (r = b, i = s, a = l < a ? l : a) : b === r && l < a && (a = l, i = s);
|
|
1482
1482
|
}
|
|
1483
1483
|
return i || o - n;
|
|
1484
1484
|
}
|
|
1485
1485
|
// sorts node children by the best axis for split
|
|
1486
1486
|
_chooseSplitAxis(e, n, o) {
|
|
1487
|
-
const i = e.leaf ? this.compareMinX :
|
|
1487
|
+
const i = e.leaf ? this.compareMinX : vn, r = e.leaf ? this.compareMinY : wn, a = this._allDistMargin(e, n, o, i), s = this._allDistMargin(e, n, o, r);
|
|
1488
1488
|
a < s && e.children.sort(i);
|
|
1489
1489
|
}
|
|
1490
1490
|
// total margin of all possible split distributions where each node is at least m full
|
|
@@ -1511,7 +1511,7 @@ class bn {
|
|
|
1511
1511
|
e[n].children.length === 0 ? n > 0 ? (o = e[n - 1].children, o.splice(o.indexOf(e[n]), 1)) : this.clear() : P(e[n], this.toBBox);
|
|
1512
1512
|
}
|
|
1513
1513
|
}
|
|
1514
|
-
function
|
|
1514
|
+
function bn(t, e, n) {
|
|
1515
1515
|
if (!n)
|
|
1516
1516
|
return e.indexOf(t);
|
|
1517
1517
|
for (let o = 0; o < e.length; o++)
|
|
@@ -1533,10 +1533,10 @@ function q(t, e, n, o, i) {
|
|
|
1533
1533
|
function j(t, e) {
|
|
1534
1534
|
return t.minX = Math.min(t.minX, e.minX), t.minY = Math.min(t.minY, e.minY), t.maxX = Math.max(t.maxX, e.maxX), t.maxY = Math.max(t.maxY, e.maxY), t;
|
|
1535
1535
|
}
|
|
1536
|
-
function
|
|
1536
|
+
function vn(t, e) {
|
|
1537
1537
|
return t.minX - e.minX;
|
|
1538
1538
|
}
|
|
1539
|
-
function
|
|
1539
|
+
function wn(t, e) {
|
|
1540
1540
|
return t.minY - e.minY;
|
|
1541
1541
|
}
|
|
1542
1542
|
function lt(t) {
|
|
@@ -1545,10 +1545,10 @@ function lt(t) {
|
|
|
1545
1545
|
function Z(t) {
|
|
1546
1546
|
return t.maxX - t.minX + (t.maxY - t.minY);
|
|
1547
1547
|
}
|
|
1548
|
-
function
|
|
1548
|
+
function yn(t, e) {
|
|
1549
1549
|
return (Math.max(e.maxX, t.maxX) - Math.min(e.minX, t.minX)) * (Math.max(e.maxY, t.maxY) - Math.min(e.minY, t.minY));
|
|
1550
1550
|
}
|
|
1551
|
-
function
|
|
1551
|
+
function xn(t, e) {
|
|
1552
1552
|
const n = Math.max(t.minX, e.minX), o = Math.max(t.minY, e.minY), i = Math.min(t.maxX, e.maxX), r = Math.min(t.maxY, e.maxY);
|
|
1553
1553
|
return Math.max(0, i - n) * Math.max(0, r - o);
|
|
1554
1554
|
}
|
|
@@ -1575,15 +1575,15 @@ function It(t, e, n, o, i) {
|
|
|
1575
1575
|
if (n = r.pop(), e = r.pop(), n - e <= o)
|
|
1576
1576
|
continue;
|
|
1577
1577
|
const a = e + Math.ceil((n - e) / o / 2) * o;
|
|
1578
|
-
|
|
1578
|
+
pn(t, a, e, n, i), r.push(e, a, a, n);
|
|
1579
1579
|
}
|
|
1580
1580
|
}
|
|
1581
|
-
const
|
|
1582
|
-
const n = new
|
|
1581
|
+
const An = (t, e) => {
|
|
1582
|
+
const n = new mn(), o = /* @__PURE__ */ new Map(), i = (d, c) => {
|
|
1583
1583
|
const w = d.selector.flatMap((C) => {
|
|
1584
1584
|
const E = X([C]) ? C.range : Nt(C, e).range;
|
|
1585
1585
|
return Array.from(E.getClientRects());
|
|
1586
|
-
}), L =
|
|
1586
|
+
}), L = ie(w).map(({ left: C, top: E, right: T, bottom: g }) => new DOMRect(C - c.left, E - c.top, T - C, g - E));
|
|
1587
1587
|
return L.map((C) => {
|
|
1588
1588
|
const { x: E, y: T, width: g, height: A } = C;
|
|
1589
1589
|
return {
|
|
@@ -1656,8 +1656,8 @@ const En = (t, e) => {
|
|
|
1656
1656
|
size: () => n.all().length,
|
|
1657
1657
|
update: f
|
|
1658
1658
|
};
|
|
1659
|
-
},
|
|
1660
|
-
const n =
|
|
1659
|
+
}, En = (t, e) => {
|
|
1660
|
+
const n = We(), o = An(n, t), i = Oe(n, e), r = Ie(n), a = Ke(), s = (v, h = R.LOCAL) => {
|
|
1661
1661
|
const d = nt(v, t), c = X(d.target.selector);
|
|
1662
1662
|
return c && n.addAnnotation(d, h), c;
|
|
1663
1663
|
}, u = (v, h = !0, d = R.LOCAL) => {
|
|
@@ -1708,13 +1708,13 @@ const En = (t, e) => {
|
|
|
1708
1708
|
hover: r,
|
|
1709
1709
|
viewport: a
|
|
1710
1710
|
};
|
|
1711
|
-
},
|
|
1711
|
+
}, Sn = () => {
|
|
1712
1712
|
const t = document.createElement("canvas");
|
|
1713
1713
|
t.width = 2 * window.innerWidth, t.height = 2 * window.innerHeight, t.className = "r6o-highlight-layer presence";
|
|
1714
1714
|
const e = t.getContext("2d");
|
|
1715
1715
|
return e.scale(2, 2), e.translate(0.5, 0.5), t;
|
|
1716
|
-
},
|
|
1717
|
-
const o =
|
|
1716
|
+
}, Cn = (t, e, n = {}) => {
|
|
1717
|
+
const o = Sn(), i = o.getContext("2d");
|
|
1718
1718
|
t.appendChild(o);
|
|
1719
1719
|
const r = /* @__PURE__ */ new Map(), a = (l) => Array.from(r.entries()).filter(([m, p]) => p.presenceKey === l.presenceKey).map(([m, p]) => m);
|
|
1720
1720
|
return e.on("selectionChange", (l, m) => {
|
|
@@ -1746,16 +1746,16 @@ const En = (t, e) => {
|
|
|
1746
1746
|
l.scale(2, 2), l.translate(0.5, 0.5);
|
|
1747
1747
|
}
|
|
1748
1748
|
};
|
|
1749
|
-
},
|
|
1749
|
+
}, $t = (t) => {
|
|
1750
1750
|
if (t === null)
|
|
1751
1751
|
return document.scrollingElement;
|
|
1752
1752
|
const { overflowY: e } = window.getComputedStyle(t);
|
|
1753
|
-
return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t :
|
|
1754
|
-
},
|
|
1753
|
+
return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : $t(t.parentElement);
|
|
1754
|
+
}, Ln = (t, e) => (n) => {
|
|
1755
1755
|
const o = (r) => {
|
|
1756
1756
|
const a = i.getBoundingClientRect(), s = i.clientHeight, u = i.clientWidth, f = r.selector[0].range.getBoundingClientRect(), { width: b, height: l } = e.getAnnotationBounds(n.id), m = f.top - a.top, p = f.left - a.left, y = i.parentElement ? i.scrollTop : 0, v = i.parentElement ? i.scrollLeft : 0, h = m + y - (s - l) / 2, d = p + v - (u - b) / 2;
|
|
1757
1757
|
i.scroll({ top: h, left: d, behavior: "smooth" });
|
|
1758
|
-
}, i =
|
|
1758
|
+
}, i = $t(t);
|
|
1759
1759
|
if (i) {
|
|
1760
1760
|
const r = e.getAnnotation(n.id), { range: a } = r.target.selector[0];
|
|
1761
1761
|
if (a && !a.collapsed)
|
|
@@ -1767,10 +1767,10 @@ const En = (t, e) => {
|
|
|
1767
1767
|
}
|
|
1768
1768
|
}
|
|
1769
1769
|
return !1;
|
|
1770
|
-
},
|
|
1770
|
+
}, Tn = (t, e) => ({
|
|
1771
1771
|
...t,
|
|
1772
1772
|
annotationEnabled: t.annotationEnabled === void 0 ? e.annotationEnabled : t.annotationEnabled
|
|
1773
|
-
}),
|
|
1773
|
+
}), Bn = (t, e, n, o) => {
|
|
1774
1774
|
const { store: i, selection: r } = e;
|
|
1775
1775
|
let a, s;
|
|
1776
1776
|
const u = (h) => a = h;
|
|
@@ -1792,15 +1792,15 @@ const En = (t, e) => {
|
|
|
1792
1792
|
if (h.timeStamp - ((b == null ? void 0 : b.timeStamp) || h.timeStamp) < 1e3 && !s && l(b), d.isCollapsed || !f || !s)
|
|
1793
1793
|
return;
|
|
1794
1794
|
const c = d.getRangeAt(0);
|
|
1795
|
-
if (
|
|
1795
|
+
if (ee(c))
|
|
1796
1796
|
return;
|
|
1797
|
-
const w =
|
|
1797
|
+
const w = Kt(c.cloneRange());
|
|
1798
1798
|
(w.length !== s.selector.length || w.some((C, E) => {
|
|
1799
1799
|
var T;
|
|
1800
1800
|
return C.toString() !== ((T = s.selector[E]) == null ? void 0 : T.quote);
|
|
1801
1801
|
})) && (s = {
|
|
1802
1802
|
...s,
|
|
1803
|
-
selector: w.map((C) =>
|
|
1803
|
+
selector: w.map((C) => re(C, t, o))
|
|
1804
1804
|
}, i.getAnnotation(s.annotation) ? i.updateTarget(s, R.LOCAL) : (i.addAnnotation({
|
|
1805
1805
|
id: s.annotation,
|
|
1806
1806
|
bodies: [],
|
|
@@ -1835,17 +1835,17 @@ const En = (t, e) => {
|
|
|
1835
1835
|
};
|
|
1836
1836
|
}, Mt = "SPANS", Nn = (t, e = {}) => {
|
|
1837
1837
|
t.addEventListener("click", (E) => !E.target.closest("a") && E.preventDefault());
|
|
1838
|
-
const n =
|
|
1838
|
+
const n = Tn(e, {
|
|
1839
1839
|
annotationEnabled: !0
|
|
1840
|
-
}), o =
|
|
1841
|
-
let f =
|
|
1842
|
-
const b = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : Mt : n.renderer || Mt, l = b === "SPANS" ?
|
|
1840
|
+
}), o = En(t, n.pointerAction), { selection: i, viewport: r } = o, a = o.store, s = Ge(a), u = Qe(o, s, n.adapter);
|
|
1841
|
+
let f = sn();
|
|
1842
|
+
const b = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : Mt : n.renderer || Mt, l = b === "SPANS" ? Se(t, o, r) : b === "CSS_HIGHLIGHTS" ? xe(t, o, r) : b === "CANVAS" ? ue(t, o, r) : void 0;
|
|
1843
1843
|
if (!l)
|
|
1844
1844
|
throw `Unknown renderer implementation: ${b}`;
|
|
1845
1845
|
console.debug(`Using ${b} renderer`), n.style && l.setStyle(n.style);
|
|
1846
|
-
const m =
|
|
1846
|
+
const m = Bn(t, o, n.annotationEnabled, n.offsetReferenceSelector);
|
|
1847
1847
|
return m.setUser(f), {
|
|
1848
|
-
...
|
|
1848
|
+
...Ze(o, s, n.adapter),
|
|
1849
1849
|
destroy: () => {
|
|
1850
1850
|
l.destroy(), m.destroy(), s.destroy();
|
|
1851
1851
|
},
|
|
@@ -1860,47 +1860,47 @@ const En = (t, e) => {
|
|
|
1860
1860
|
E ? i.setSelected(E) : i.clear();
|
|
1861
1861
|
},
|
|
1862
1862
|
setPresenceProvider: (E) => {
|
|
1863
|
-
E && (l.setPainter(
|
|
1863
|
+
E && (l.setPainter(Cn(t, E, n.presence)), E.on("selectionChange", () => l.redraw()));
|
|
1864
1864
|
},
|
|
1865
1865
|
setVisible: (E) => l.setVisible(E),
|
|
1866
1866
|
on: u.on,
|
|
1867
1867
|
off: u.off,
|
|
1868
|
-
scrollIntoView:
|
|
1868
|
+
scrollIntoView: Ln(t, a),
|
|
1869
1869
|
state: o
|
|
1870
1870
|
};
|
|
1871
|
-
}
|
|
1871
|
+
};
|
|
1872
1872
|
export {
|
|
1873
1873
|
ht as DEFAULT_SELECTED_STYLE,
|
|
1874
1874
|
$ as DEFAULT_STYLE,
|
|
1875
1875
|
Ot as NOT_ANNOTATABLE_CLASS,
|
|
1876
1876
|
D as NOT_ANNOTATABLE_SELECTOR,
|
|
1877
|
-
|
|
1878
|
-
|
|
1877
|
+
R as Origin,
|
|
1878
|
+
Me as PointerSelectAction,
|
|
1879
1879
|
On as W3CTextFormat,
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1880
|
+
Mn as createBody,
|
|
1881
|
+
ue as createCanvasRenderer,
|
|
1882
|
+
xe as createHighlightsRenderer,
|
|
1883
|
+
ye as createRenderer,
|
|
1884
|
+
Se as createSpansRenderer,
|
|
1885
1885
|
Nn as createTextAnnotator,
|
|
1886
|
-
|
|
1886
|
+
En as createTextAnnotatorState,
|
|
1887
1887
|
ft as debounce,
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1888
|
+
Tn as fillDefaults,
|
|
1889
|
+
Rn as getAnnotatableFragment,
|
|
1890
|
+
In as getClientRectsPonyfill,
|
|
1891
|
+
Zt as getQuoteContext,
|
|
1892
1892
|
dt as getRangeAnnotatableContents,
|
|
1893
1893
|
X as isRevived,
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1894
|
+
ee as isWhitespaceOrEmpty,
|
|
1895
|
+
ie as mergeClientRects,
|
|
1896
|
+
qt as paint,
|
|
1897
|
+
hn as parseW3CTextAnnotation,
|
|
1898
|
+
re as rangeToSelector,
|
|
1899
1899
|
nt as reviveAnnotation,
|
|
1900
1900
|
Nt as reviveSelector,
|
|
1901
1901
|
et as reviveTarget,
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1902
|
+
fn as serializeW3CTextAnnotation,
|
|
1903
|
+
Kt as splitAnnotatableRanges,
|
|
1904
|
+
te as whitespaceOrEmptyRegex
|
|
1905
1905
|
};
|
|
1906
1906
|
//# sourceMappingURL=text-annotator.es.js.map
|