@soomo/text-annotator 3.0.0-staging.8 → 3.0.0-staging.9
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.
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
const $ = {
|
|
2
2
|
fill: "rgb(0, 128, 255)",
|
|
3
3
|
fillOpacity: 0.18
|
|
4
|
-
},
|
|
4
|
+
}, et = {
|
|
5
5
|
fill: "rgb(0, 128, 255)",
|
|
6
6
|
fillOpacity: 0.45
|
|
7
7
|
}, qt = (t, e, n, o, i) => {
|
|
8
|
-
var a;
|
|
9
|
-
const r = n ? typeof n == "function" ? n(t.annotation, t.state, i) : n : (
|
|
8
|
+
var a, s;
|
|
9
|
+
const r = n ? typeof n == "function" ? n(t.annotation, t.state, i) || ((a = t.state) != null && a.selected ? et : $) : n : (s = t.state) != null && s.selected ? et : $;
|
|
10
10
|
return o && o.paint(t, e) || r;
|
|
11
|
-
}, ft = (t, e = 10) => {
|
|
12
|
-
let n;
|
|
13
|
-
return (...o) => {
|
|
14
|
-
clearTimeout(n), n = setTimeout(() => t.apply(void 0, o), e);
|
|
15
|
-
};
|
|
16
11
|
}, Ot = "not-annotatable", D = `.${Ot}`, jt = (t) => {
|
|
17
12
|
var n;
|
|
18
13
|
const e = t.commonAncestorContainer;
|
|
@@ -40,10 +35,20 @@ const $ = {
|
|
|
40
35
|
o.setStartAfter(n), o.collapsed || e.push(o);
|
|
41
36
|
}
|
|
42
37
|
return e.length > 0 ? e : [t];
|
|
43
|
-
},
|
|
38
|
+
}, ut = (t) => {
|
|
44
39
|
const e = t.cloneContents();
|
|
45
40
|
return e.querySelectorAll(D).forEach((n) => n.remove()), e;
|
|
46
|
-
},
|
|
41
|
+
}, Qt = (t) => {
|
|
42
|
+
t.addEventListener("click", (e) => {
|
|
43
|
+
// Allow clicks within not-annotatable elements
|
|
44
|
+
!e.target.closest(D) && !e.target.closest("a") && e.preventDefault();
|
|
45
|
+
});
|
|
46
|
+
}, ft = (t, e = 10) => {
|
|
47
|
+
let n;
|
|
48
|
+
return (...o) => {
|
|
49
|
+
clearTimeout(n), n = setTimeout(() => t.apply(void 0, o), e);
|
|
50
|
+
};
|
|
51
|
+
}, In = (t) => {
|
|
47
52
|
const e = t.cloneContents();
|
|
48
53
|
return e.querySelectorAll(D).forEach((n) => n.remove()), e;
|
|
49
54
|
}, mt = (t, e) => {
|
|
@@ -60,7 +65,7 @@ const $ = {
|
|
|
60
65
|
for (let i = 0; i < t + 1; i++)
|
|
61
66
|
o = n.nextNode();
|
|
62
67
|
return o;
|
|
63
|
-
},
|
|
68
|
+
}, Jt = (t) => {
|
|
64
69
|
const {
|
|
65
70
|
commonAncestorContainer: e,
|
|
66
71
|
startContainer: n,
|
|
@@ -73,8 +78,8 @@ const $ = {
|
|
|
73
78
|
}), s = mt(n, e), u = mt(i, e), f = () => {
|
|
74
79
|
const l = e;
|
|
75
80
|
l.replaceChildren(...a);
|
|
76
|
-
const m = bt(s, l),
|
|
77
|
-
return t.setStart(m, o), t.setEnd(
|
|
81
|
+
const m = bt(s, l), p = bt(u, l);
|
|
82
|
+
return t.setStart(m, o), t.setEnd(p, r), t;
|
|
78
83
|
}, b = (l) => {
|
|
79
84
|
const m = document.createElement("SPAN");
|
|
80
85
|
return l.surroundContents(m), m;
|
|
@@ -84,16 +89,16 @@ const $ = {
|
|
|
84
89
|
{
|
|
85
90
|
const l = document.createRange();
|
|
86
91
|
l.selectNodeContents(n), l.setStart(n, o);
|
|
87
|
-
const m = b(l),
|
|
88
|
-
|
|
89
|
-
const y = b(
|
|
92
|
+
const m = b(l), p = document.createRange();
|
|
93
|
+
p.selectNode(i), p.setEnd(i, r);
|
|
94
|
+
const y = b(p), h = Zt(t).reverse().map((d) => {
|
|
90
95
|
var w;
|
|
91
96
|
const c = document.createElement("SPAN");
|
|
92
97
|
return (w = d.parentNode) == null || w.insertBefore(c, d), c.appendChild(d), c;
|
|
93
98
|
});
|
|
94
99
|
return { unwrap: f, nodes: [m, ...h, y] };
|
|
95
100
|
}
|
|
96
|
-
},
|
|
101
|
+
}, Zt = (t) => {
|
|
97
102
|
const {
|
|
98
103
|
commonAncestorContainer: e,
|
|
99
104
|
startContainer: n,
|
|
@@ -104,25 +109,25 @@ const $ = {
|
|
|
104
109
|
for (; r != null; )
|
|
105
110
|
r === o && (a = !1), a && s.push(r), r === n && (a = !0), r = i.nextNode();
|
|
106
111
|
return s;
|
|
107
|
-
},
|
|
112
|
+
}, Mn = (t) => {
|
|
108
113
|
const { startContainer: e, endContainer: n } = t;
|
|
109
114
|
if (e === n)
|
|
110
115
|
return Array.from(t.getClientRects());
|
|
111
116
|
{
|
|
112
|
-
const { unwrap: o, nodes: i } =
|
|
117
|
+
const { unwrap: o, nodes: i } = Jt(t), r = i.reduce((a, s) => [...a, ...s.getClientRects()], []);
|
|
113
118
|
return o(), r;
|
|
114
119
|
}
|
|
115
|
-
},
|
|
120
|
+
}, te = (t, e, n = 10, o) => {
|
|
116
121
|
const i = o ? t.startContainer.parentElement.closest(o) : e, r = document.createRange();
|
|
117
122
|
r.setStart(i, 0), r.setEnd(t.startContainer, t.startOffset);
|
|
118
|
-
const a =
|
|
123
|
+
const a = ut(r).textContent, s = document.createRange();
|
|
119
124
|
s.setStart(t.endContainer, t.endOffset), i === document.body ? s.setEnd(i, i.childNodes.length) : s.setEndAfter(i);
|
|
120
|
-
const u =
|
|
125
|
+
const u = ut(s).textContent;
|
|
121
126
|
return {
|
|
122
127
|
prefix: a.substring(a.length - n),
|
|
123
128
|
suffix: u.substring(0, n)
|
|
124
129
|
};
|
|
125
|
-
},
|
|
130
|
+
}, ee = /^\s*$/, ne = (t) => ee.test(t.toString()), X = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), oe = (t, e) => {
|
|
126
131
|
const n = (r) => Math.round(r * 10) / 10, o = {
|
|
127
132
|
top: n(t.top),
|
|
128
133
|
bottom: n(t.bottom),
|
|
@@ -146,17 +151,17 @@ const $ = {
|
|
|
146
151
|
return "block-contains";
|
|
147
152
|
} else if (o.top >= i.top && o.bottom <= i.bottom && o.left >= i.left && o.right <= i.right)
|
|
148
153
|
return "block-is-contained";
|
|
149
|
-
},
|
|
154
|
+
}, ie = (t, e) => {
|
|
150
155
|
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
156
|
return new DOMRect(n, i, o - n, r - i);
|
|
152
|
-
},
|
|
157
|
+
}, re = (t) => t.reduce((e, n) => {
|
|
153
158
|
if (n.width === 0 || n.height === 0)
|
|
154
159
|
return e;
|
|
155
160
|
let o = [...e], i = !1;
|
|
156
161
|
for (const r of e) {
|
|
157
|
-
const a =
|
|
162
|
+
const a = oe(n, r);
|
|
158
163
|
if (a === "inline-adjacent") {
|
|
159
|
-
o = o.map((s) => s === r ?
|
|
164
|
+
o = o.map((s) => s === r ? ie(n, r) : s), i = !0;
|
|
160
165
|
break;
|
|
161
166
|
} else if (a === "inline-contains") {
|
|
162
167
|
o = o.map((s) => s === r ? n : s), i = !0;
|
|
@@ -170,10 +175,10 @@ const $ = {
|
|
|
170
175
|
}
|
|
171
176
|
}
|
|
172
177
|
return i ? o : [...o, n];
|
|
173
|
-
}, []),
|
|
178
|
+
}, []), se = (t, e, n) => {
|
|
174
179
|
const o = document.createRange(), i = n ? t.startContainer.parentElement.closest(n) : e;
|
|
175
180
|
o.setStart(i, 0), o.setEnd(t.startContainer, t.startOffset);
|
|
176
|
-
const r =
|
|
181
|
+
const r = ut(o).textContent, a = t.toString(), s = r.length || 0, u = s + a.length;
|
|
177
182
|
return n ? { quote: a, start: s, end: u, range: t, offsetReference: i } : { quote: a, start: s, end: u, range: t };
|
|
178
183
|
}, Nt = (t, e) => {
|
|
179
184
|
var b, l;
|
|
@@ -181,8 +186,8 @@ const $ = {
|
|
|
181
186
|
e,
|
|
182
187
|
NodeFilter.SHOW_TEXT,
|
|
183
188
|
(m) => {
|
|
184
|
-
var
|
|
185
|
-
return (
|
|
189
|
+
var p;
|
|
190
|
+
return (p = m.parentElement) != null && p.closest(D) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
|
|
186
191
|
}
|
|
187
192
|
);
|
|
188
193
|
let a = 0;
|
|
@@ -213,39 +218,39 @@ const $ = {
|
|
|
213
218
|
...t,
|
|
214
219
|
range: s
|
|
215
220
|
};
|
|
216
|
-
},
|
|
221
|
+
}, nt = (t, e) => X(t.selector) ? t : {
|
|
217
222
|
...t,
|
|
218
223
|
selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : Nt(n, e))
|
|
219
|
-
},
|
|
224
|
+
}, ot = (t, e) => X(t.target.selector) ? t : { ...t, target: nt(t.target, e) }, ae = (t) => {
|
|
220
225
|
const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: o, innerHeight: i } = window, r = -n, a = -e, s = o - n, u = i - e;
|
|
221
226
|
return { top: e, left: n, minX: r, minY: a, maxX: s, maxY: u };
|
|
222
|
-
},
|
|
227
|
+
}, le = (t) => {
|
|
223
228
|
let e = /* @__PURE__ */ new Set();
|
|
224
229
|
return (o) => {
|
|
225
230
|
const i = o.map((r) => r.id);
|
|
226
231
|
(e.size !== i.length || i.some((r) => !e.has(r))) && t.set(i), e = new Set(i);
|
|
227
232
|
};
|
|
228
|
-
},
|
|
233
|
+
}, pt = (t, e, n, o) => {
|
|
229
234
|
const { store: i, selection: r, hover: a } = e;
|
|
230
235
|
let s, u, f;
|
|
231
|
-
const b =
|
|
232
|
-
const { x: A, y: x } = t.getBoundingClientRect(), S = i.getAt(
|
|
236
|
+
const b = le(n), l = (g) => {
|
|
237
|
+
const { x: A, y: x } = t.getBoundingClientRect(), S = i.getAt(g.clientX - A, g.clientY - x);
|
|
233
238
|
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
239
|
};
|
|
235
240
|
t.addEventListener("pointermove", l);
|
|
236
|
-
const m = (
|
|
241
|
+
const m = (g = !1) => {
|
|
237
242
|
f && f.clear();
|
|
238
|
-
const A =
|
|
243
|
+
const A = ae(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
244
|
const Ft = Ht.includes(Y.id), Wt = Y.id === a.current;
|
|
240
245
|
return { annotation: Y, rects: zt, state: { selected: Ft, hover: Wt, custom: {} } };
|
|
241
246
|
});
|
|
242
|
-
o.redraw(Pt, A, s, f,
|
|
243
|
-
},
|
|
244
|
-
f =
|
|
245
|
-
}, y = (
|
|
246
|
-
s =
|
|
247
|
-
}, v = (
|
|
248
|
-
u =
|
|
247
|
+
o.redraw(Pt, A, s, f, g), setTimeout(() => b(k.map(({ annotation: Y }) => Y)), 1);
|
|
248
|
+
}, p = (g) => {
|
|
249
|
+
f = g, m();
|
|
250
|
+
}, y = (g) => {
|
|
251
|
+
s = g, m();
|
|
252
|
+
}, v = (g) => {
|
|
253
|
+
u = g, m(!1);
|
|
249
254
|
}, h = () => m();
|
|
250
255
|
i.observe(h);
|
|
251
256
|
const d = r.subscribe(() => m()), c = () => m(!0);
|
|
@@ -256,8 +261,8 @@ const $ = {
|
|
|
256
261
|
window.addEventListener("resize", w);
|
|
257
262
|
const L = new ResizeObserver(w);
|
|
258
263
|
L.observe(t);
|
|
259
|
-
const C = { attributes: !0, childList: !0, subtree: !0 }, E = new MutationObserver((
|
|
260
|
-
|
|
264
|
+
const C = { attributes: !0, childList: !0, subtree: !0 }, E = new MutationObserver((g) => {
|
|
265
|
+
g.every((x) => x.target === t || t.contains(x.target)) || m(!0);
|
|
261
266
|
});
|
|
262
267
|
return E.observe(document.body, C), {
|
|
263
268
|
destroy: () => {
|
|
@@ -266,49 +271,49 @@ const $ = {
|
|
|
266
271
|
redraw: m,
|
|
267
272
|
setStyle: y,
|
|
268
273
|
setFilter: v,
|
|
269
|
-
setPainter:
|
|
274
|
+
setPainter: p,
|
|
270
275
|
setVisible: o.setVisible
|
|
271
276
|
};
|
|
272
|
-
},
|
|
277
|
+
}, ce = () => {
|
|
273
278
|
const t = document.createElement("canvas");
|
|
274
279
|
return t.width = window.innerWidth, t.height = window.innerHeight, t.className = "r6o-highlight-layer bg", t;
|
|
275
|
-
},
|
|
280
|
+
}, de = (t, e) => {
|
|
276
281
|
t.width = window.innerWidth, t.height = window.innerHeight;
|
|
277
|
-
},
|
|
282
|
+
}, ue = (t) => {
|
|
278
283
|
t.classList.add("r6o-annotatable");
|
|
279
|
-
const e =
|
|
284
|
+
const e = ce(), n = e.getContext("2d");
|
|
280
285
|
t.insertBefore(e, t.firstChild);
|
|
281
286
|
const o = (s, u, f, b) => requestAnimationFrame(() => {
|
|
282
287
|
const { width: l, height: m } = e;
|
|
283
288
|
n.clearRect(-0.5, -0.5, l + 1, m + 1), b && b.clear();
|
|
284
|
-
const { top:
|
|
289
|
+
const { top: p, left: y } = u;
|
|
285
290
|
s.forEach((v) => {
|
|
286
291
|
var L;
|
|
287
|
-
const h = f ? typeof f == "function" ? f(v.annotation, v.state) : f : (L = v.state) != null && L.selected ?
|
|
292
|
+
const h = f ? typeof f == "function" ? f(v.annotation, v.state) : f : (L = v.state) != null && L.selected ? et : $, d = b && b.paint(v, u) || h, c = v.rects.map(({ x: C, y: E, width: T, height: g }) => ({
|
|
288
293
|
x: C + y,
|
|
289
|
-
y: E +
|
|
294
|
+
y: E + p,
|
|
290
295
|
width: T,
|
|
291
|
-
height:
|
|
296
|
+
height: g
|
|
292
297
|
}));
|
|
293
298
|
n.fillStyle = d.fill, n.globalAlpha = d.fillOpacity || 1;
|
|
294
299
|
const w = 5;
|
|
295
300
|
if (c.forEach(
|
|
296
|
-
({ x: C, y: E, width: T, height:
|
|
301
|
+
({ x: C, y: E, width: T, height: g }) => n.fillRect(
|
|
297
302
|
C,
|
|
298
303
|
E - w / 2,
|
|
299
304
|
T,
|
|
300
|
-
|
|
305
|
+
g + w
|
|
301
306
|
)
|
|
302
307
|
), d.underlineColor) {
|
|
303
308
|
n.globalAlpha = 1, n.strokeStyle = d.underlineColor, n.lineWidth = d.underlineThickness ?? 1;
|
|
304
309
|
const C = w / 2 + (d.underlineOffset ?? 0);
|
|
305
|
-
c.forEach(({ x: E, y: T, width:
|
|
306
|
-
n.beginPath(), n.moveTo(E, T + A + C), n.lineTo(E +
|
|
310
|
+
c.forEach(({ x: E, y: T, width: g, height: A }) => {
|
|
311
|
+
n.beginPath(), n.moveTo(E, T + A + C), n.lineTo(E + g, T + A + C), n.stroke();
|
|
307
312
|
});
|
|
308
313
|
}
|
|
309
314
|
});
|
|
310
315
|
}), i = ft(() => {
|
|
311
|
-
|
|
316
|
+
de(e);
|
|
312
317
|
});
|
|
313
318
|
return window.addEventListener("resize", i), {
|
|
314
319
|
destroy: () => {
|
|
@@ -319,8 +324,8 @@ const $ = {
|
|
|
319
324
|
},
|
|
320
325
|
redraw: o
|
|
321
326
|
};
|
|
322
|
-
},
|
|
323
|
-
var
|
|
327
|
+
}, he = (t, e, n) => pt(t, e, n, ue(t));
|
|
328
|
+
var fe = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, _ = function(t) {
|
|
324
329
|
return typeof t == "string" ? t.length > 0 : typeof t == "number";
|
|
325
330
|
}, M = function(t, e, n) {
|
|
326
331
|
return e === void 0 && (e = 0), n === void 0 && (n = Math.pow(10, e)), Math.round(n * t) / n + 0;
|
|
@@ -330,9 +335,9 @@ var he = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, _ = function(t) {
|
|
|
330
335
|
return (t = isFinite(t) ? t % 360 : 0) > 0 ? t : t + 360;
|
|
331
336
|
}, vt = function(t) {
|
|
332
337
|
return { r: U(t.r, 0, 255), g: U(t.g, 0, 255), b: U(t.b, 0, 255), a: U(t.a) };
|
|
333
|
-
},
|
|
338
|
+
}, it = function(t) {
|
|
334
339
|
return { r: M(t.r), g: M(t.g), b: M(t.b), a: M(t.a, 3) };
|
|
335
|
-
},
|
|
340
|
+
}, pe = /^#([0-9a-f]{3,8})$/i, K = function(t) {
|
|
336
341
|
var e = t.toString(16);
|
|
337
342
|
return e.length < 2 ? "0" + e : e;
|
|
338
343
|
}, Vt = function(t) {
|
|
@@ -353,17 +358,17 @@ var he = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, _ = function(t) {
|
|
|
353
358
|
}, G = function(t) {
|
|
354
359
|
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
360
|
var e, n, o, i;
|
|
356
|
-
}, ge = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,
|
|
357
|
-
var e =
|
|
361
|
+
}, ge = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, me = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, be = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, ve = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, At = { string: [[function(t) {
|
|
362
|
+
var e = pe.exec(t);
|
|
358
363
|
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
364
|
}, "hex"], [function(t) {
|
|
360
|
-
var e =
|
|
365
|
+
var e = be.exec(t) || ve.exec(t);
|
|
361
366
|
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
367
|
}, "rgb"], [function(t) {
|
|
363
|
-
var e = ge.exec(t) ||
|
|
368
|
+
var e = ge.exec(t) || me.exec(t);
|
|
364
369
|
if (!e)
|
|
365
370
|
return null;
|
|
366
|
-
var n, o, i = wt({ h: (n = e[1], o = e[2], o === void 0 && (o = "deg"), Number(n) * (
|
|
371
|
+
var n, o, i = wt({ h: (n = e[1], o = e[2], o === void 0 && (o = "deg"), Number(n) * (fe[o] || 1)), s: Number(e[3]), l: Number(e[4]), a: e[5] === void 0 ? 1 : Number(e[5]) / (e[6] ? 100 : 1) });
|
|
367
372
|
return xt(i);
|
|
368
373
|
}, "hsl"]], object: [[function(t) {
|
|
369
374
|
var e = t.r, n = t.g, o = t.b, i = t.a, r = i === void 0 ? 1 : i;
|
|
@@ -389,35 +394,35 @@ var he = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, _ = function(t) {
|
|
|
389
394
|
return [o, e[n][1]];
|
|
390
395
|
}
|
|
391
396
|
return [null, void 0];
|
|
392
|
-
},
|
|
397
|
+
}, we = function(t) {
|
|
393
398
|
return typeof t == "string" ? Et(t.trim(), At.string) : typeof t == "object" && t !== null ? Et(t, At.object) : [null, void 0];
|
|
394
|
-
},
|
|
399
|
+
}, rt = function(t, e) {
|
|
395
400
|
var n = G(t);
|
|
396
401
|
return { h: n.h, s: U(n.s + 100 * e, 0, 100), l: n.l, a: n.a };
|
|
397
|
-
},
|
|
402
|
+
}, st = function(t) {
|
|
398
403
|
return (299 * t.r + 587 * t.g + 114 * t.b) / 1e3 / 255;
|
|
399
404
|
}, St = function(t, e) {
|
|
400
405
|
var n = G(t);
|
|
401
406
|
return { h: n.h, s: n.s, l: U(n.l + 100 * e, 0, 100), a: n.a };
|
|
402
407
|
}, Ct = function() {
|
|
403
408
|
function t(e) {
|
|
404
|
-
this.parsed =
|
|
409
|
+
this.parsed = we(e)[0], this.rgba = this.parsed || { r: 0, g: 0, b: 0, a: 1 };
|
|
405
410
|
}
|
|
406
411
|
return t.prototype.isValid = function() {
|
|
407
412
|
return this.parsed !== null;
|
|
408
413
|
}, t.prototype.brightness = function() {
|
|
409
|
-
return M(
|
|
414
|
+
return M(st(this.rgba), 2);
|
|
410
415
|
}, t.prototype.isDark = function() {
|
|
411
|
-
return
|
|
416
|
+
return st(this.rgba) < 0.5;
|
|
412
417
|
}, t.prototype.isLight = function() {
|
|
413
|
-
return
|
|
418
|
+
return st(this.rgba) >= 0.5;
|
|
414
419
|
}, t.prototype.toHex = function() {
|
|
415
|
-
return e =
|
|
420
|
+
return e = it(this.rgba), n = e.r, o = e.g, i = e.b, a = (r = e.a) < 1 ? K(M(255 * r)) : "", "#" + K(n) + K(o) + K(i) + a;
|
|
416
421
|
var e, n, o, i, r, a;
|
|
417
422
|
}, t.prototype.toRgb = function() {
|
|
418
|
-
return
|
|
423
|
+
return it(this.rgba);
|
|
419
424
|
}, t.prototype.toRgbString = function() {
|
|
420
|
-
return e =
|
|
425
|
+
return e = it(this.rgba), n = e.r, o = e.g, i = e.b, (r = e.a) < 1 ? "rgba(" + n + ", " + o + ", " + i + ", " + r + ")" : "rgb(" + n + ", " + o + ", " + i + ")";
|
|
421
426
|
var e, n, o, i, r;
|
|
422
427
|
}, t.prototype.toHsl = function() {
|
|
423
428
|
return yt(G(this.rgba));
|
|
@@ -431,11 +436,11 @@ var he = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, _ = function(t) {
|
|
|
431
436
|
return V({ r: 255 - (e = this.rgba).r, g: 255 - e.g, b: 255 - e.b, a: e.a });
|
|
432
437
|
var e;
|
|
433
438
|
}, t.prototype.saturate = function(e) {
|
|
434
|
-
return e === void 0 && (e = 0.1), V(
|
|
439
|
+
return e === void 0 && (e = 0.1), V(rt(this.rgba, e));
|
|
435
440
|
}, t.prototype.desaturate = function(e) {
|
|
436
|
-
return e === void 0 && (e = 0.1), V(
|
|
441
|
+
return e === void 0 && (e = 0.1), V(rt(this.rgba, -e));
|
|
437
442
|
}, t.prototype.grayscale = function() {
|
|
438
|
-
return V(
|
|
443
|
+
return V(rt(this.rgba, -1));
|
|
439
444
|
}, t.prototype.lighten = function(e) {
|
|
440
445
|
return e === void 0 && (e = 0.1), V(St(this.rgba, e));
|
|
441
446
|
}, t.prototype.darken = function(e) {
|
|
@@ -454,13 +459,13 @@ var he = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, _ = function(t) {
|
|
|
454
459
|
}(), V = function(t) {
|
|
455
460
|
return t instanceof Ct ? t : new Ct(t);
|
|
456
461
|
};
|
|
457
|
-
const
|
|
462
|
+
const ye = (t) => [
|
|
458
463
|
`background-color:${V((t == null ? void 0 : t.fill) || $.fill).alpha((t == null ? void 0 : t.fillOpacity) === void 0 ? $.fillOpacity : t.fillOpacity).toHex()}`,
|
|
459
464
|
t != null && t.underlineThickness ? "text-decoration:underline" : void 0,
|
|
460
465
|
t != null && t.underlineColor ? `text-decoration-color:${t.underlineColor}` : void 0,
|
|
461
466
|
t != null && t.underlineOffset ? `text-underline-offset:${t.underlineOffset}px` : void 0,
|
|
462
467
|
t != null && t.underlineThickness ? `text-decoration-thickness:${t.underlineThickness}px` : void 0
|
|
463
|
-
].filter(Boolean).join(";"),
|
|
468
|
+
].filter(Boolean).join(";"), xe = () => {
|
|
464
469
|
const t = document.createElement("style");
|
|
465
470
|
document.getElementsByTagName("head")[0].appendChild(t);
|
|
466
471
|
let e = /* @__PURE__ */ new Set();
|
|
@@ -477,19 +482,19 @@ const we = (t) => [
|
|
|
477
482
|
Array.from(e).filter((l) => !f.has(l));
|
|
478
483
|
const b = r.map((l) => {
|
|
479
484
|
var y;
|
|
480
|
-
const m = s ? typeof s == "function" ? s(l.annotation, l.state) : s : (y = l.state) != null && y.selected ?
|
|
481
|
-
return `::highlight(_${l.annotation.id}) { ${
|
|
485
|
+
const m = s ? typeof s == "function" ? s(l.annotation, l.state) : s : (y = l.state) != null && y.selected ? et : $, p = u && u.paint(l, a) || m;
|
|
486
|
+
return `::highlight(_${l.annotation.id}) { ${ye(p)} }`;
|
|
482
487
|
});
|
|
483
488
|
t.innerHTML = b.join(`
|
|
484
489
|
`), CSS.highlights.clear(), r.forEach(({ annotation: l }) => {
|
|
485
|
-
const m = l.target.selector.map((y) => y.range),
|
|
486
|
-
CSS.highlights.set(`_${l.id}`,
|
|
490
|
+
const m = l.target.selector.map((y) => y.range), p = new Highlight(...m);
|
|
491
|
+
CSS.highlights.set(`_${l.id}`, p);
|
|
487
492
|
}), e = f;
|
|
488
493
|
}
|
|
489
494
|
};
|
|
490
|
-
},
|
|
495
|
+
}, Ae = (t, e, n) => pt(t, e, n, xe());
|
|
491
496
|
var Lt = Object.prototype.hasOwnProperty;
|
|
492
|
-
function
|
|
497
|
+
function ht(t, e) {
|
|
493
498
|
var n, o;
|
|
494
499
|
if (t === e)
|
|
495
500
|
return !0;
|
|
@@ -500,24 +505,24 @@ function ut(t, e) {
|
|
|
500
505
|
return t.toString() === e.toString();
|
|
501
506
|
if (n === Array) {
|
|
502
507
|
if ((o = t.length) === e.length)
|
|
503
|
-
for (; o-- &&
|
|
508
|
+
for (; o-- && ht(t[o], e[o]); )
|
|
504
509
|
;
|
|
505
510
|
return o === -1;
|
|
506
511
|
}
|
|
507
512
|
if (!n || typeof t == "object") {
|
|
508
513
|
o = 0;
|
|
509
514
|
for (n in t)
|
|
510
|
-
if (Lt.call(t, n) && ++o && !Lt.call(e, n) || !(n in e) || !
|
|
515
|
+
if (Lt.call(t, n) && ++o && !Lt.call(e, n) || !(n in e) || !ht(t[n], e[n]))
|
|
511
516
|
return !1;
|
|
512
517
|
return Object.keys(e).length === o;
|
|
513
518
|
}
|
|
514
519
|
}
|
|
515
520
|
return t !== t && e !== e;
|
|
516
521
|
}
|
|
517
|
-
const
|
|
522
|
+
const Ee = (t, e) => {
|
|
518
523
|
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
524
|
return e.filter((o) => t !== o && n(t, o) && o.width > t.width).length;
|
|
520
|
-
},
|
|
525
|
+
}, Se = (t) => {
|
|
521
526
|
t.classList.add("r6o-annotatable");
|
|
522
527
|
const e = document.createElement("div");
|
|
523
528
|
e.className = "r6o-span-highlight-layer", t.insertBefore(e, t.firstChild);
|
|
@@ -527,47 +532,47 @@ const Ae = (t, e) => {
|
|
|
527
532
|
e.remove();
|
|
528
533
|
},
|
|
529
534
|
redraw: (a, s, u, f, b) => {
|
|
530
|
-
if (
|
|
535
|
+
if (ht(n, a) && b)
|
|
531
536
|
return;
|
|
532
537
|
e.innerHTML = "";
|
|
533
|
-
const m = a.reduce((
|
|
534
|
-
a.forEach((
|
|
535
|
-
const y =
|
|
538
|
+
const m = a.reduce((p, { rects: y }) => [...p, ...y], []);
|
|
539
|
+
a.forEach((p) => {
|
|
540
|
+
const y = p.rects.map((v) => {
|
|
536
541
|
const h = document.createElement("span");
|
|
537
|
-
h.className = "r6o-annotation", h.dataset.annotation =
|
|
538
|
-
const d =
|
|
542
|
+
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`;
|
|
543
|
+
const d = Ee(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
544
|
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
545
|
});
|
|
541
|
-
return { id:
|
|
546
|
+
return { id: p.annotation.id, spans: y };
|
|
542
547
|
}), n = a;
|
|
543
548
|
},
|
|
544
549
|
setVisible: (a) => {
|
|
545
550
|
a ? e.classList.remove("hidden") : e.classList.add("hidden");
|
|
546
551
|
}
|
|
547
552
|
};
|
|
548
|
-
},
|
|
553
|
+
}, Ce = (t, e, n) => pt(t, e, n, Se(t));
|
|
549
554
|
let Q;
|
|
550
|
-
const
|
|
551
|
-
function
|
|
555
|
+
const Le = new Uint8Array(16);
|
|
556
|
+
function Te() {
|
|
552
557
|
if (!Q && (Q = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !Q))
|
|
553
558
|
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
554
|
-
return Q(
|
|
559
|
+
return Q(Le);
|
|
555
560
|
}
|
|
556
561
|
const O = [];
|
|
557
562
|
for (let t = 0; t < 256; ++t)
|
|
558
563
|
O.push((t + 256).toString(16).slice(1));
|
|
559
|
-
function
|
|
564
|
+
function Be(t, e = 0) {
|
|
560
565
|
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
566
|
}
|
|
562
|
-
const
|
|
563
|
-
randomUUID:
|
|
567
|
+
const Re = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Tt = {
|
|
568
|
+
randomUUID: Re
|
|
564
569
|
};
|
|
565
570
|
function Yt(t, e, n) {
|
|
566
571
|
if (Tt.randomUUID && !e && !t)
|
|
567
572
|
return Tt.randomUUID();
|
|
568
573
|
t = t || {};
|
|
569
|
-
const o = t.random || (t.rng ||
|
|
570
|
-
return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128,
|
|
574
|
+
const o = t.random || (t.rng || Te)();
|
|
575
|
+
return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, Be(o);
|
|
571
576
|
}
|
|
572
577
|
var Bt = Object.prototype.hasOwnProperty;
|
|
573
578
|
function F(t, e) {
|
|
@@ -595,17 +600,17 @@ function F(t, e) {
|
|
|
595
600
|
}
|
|
596
601
|
return t !== t && e !== e;
|
|
597
602
|
}
|
|
598
|
-
function
|
|
603
|
+
function at() {
|
|
599
604
|
}
|
|
600
|
-
function
|
|
605
|
+
function Ie(t, e) {
|
|
601
606
|
return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function";
|
|
602
607
|
}
|
|
603
608
|
const H = [];
|
|
604
|
-
function
|
|
609
|
+
function gt(t, e = at) {
|
|
605
610
|
let n;
|
|
606
611
|
const o = /* @__PURE__ */ new Set();
|
|
607
612
|
function i(s) {
|
|
608
|
-
if (
|
|
613
|
+
if (Ie(t, s) && (t = s, n)) {
|
|
609
614
|
const u = !H.length;
|
|
610
615
|
for (const f of o)
|
|
611
616
|
f[1](), H.push(f, t);
|
|
@@ -619,16 +624,16 @@ function pt(t, e = st) {
|
|
|
619
624
|
function r(s) {
|
|
620
625
|
i(s(t));
|
|
621
626
|
}
|
|
622
|
-
function a(s, u =
|
|
627
|
+
function a(s, u = at) {
|
|
623
628
|
const f = [s, u];
|
|
624
|
-
return o.add(f), o.size === 1 && (n = e(i, r) ||
|
|
629
|
+
return o.add(f), o.size === 1 && (n = e(i, r) || at), s(t), () => {
|
|
625
630
|
o.delete(f), o.size === 0 && n && (n(), n = null);
|
|
626
631
|
};
|
|
627
632
|
}
|
|
628
633
|
return { set: i, update: r, subscribe: a };
|
|
629
634
|
}
|
|
630
|
-
const
|
|
631
|
-
const { subscribe: e, set: n } =
|
|
635
|
+
const Me = (t) => {
|
|
636
|
+
const { subscribe: e, set: n } = gt();
|
|
632
637
|
let o;
|
|
633
638
|
return e((i) => o = i), t.observe(({ changes: i }) => {
|
|
634
639
|
if (o) {
|
|
@@ -644,34 +649,34 @@ const Ie = (t) => {
|
|
|
644
649
|
set: n
|
|
645
650
|
};
|
|
646
651
|
};
|
|
647
|
-
var
|
|
648
|
-
const
|
|
649
|
-
const { subscribe: n, set: o } =
|
|
650
|
-
let i =
|
|
652
|
+
var Oe = /* @__PURE__ */ ((t) => (t.EDIT = "EDIT", t.SELECT = "SELECT", t.NONE = "NONE", t))(Oe || {});
|
|
653
|
+
const lt = { selected: [] }, Ne = (t, e = "EDIT") => {
|
|
654
|
+
const { subscribe: n, set: o } = gt(lt);
|
|
655
|
+
let i = lt;
|
|
651
656
|
n((l) => i = l);
|
|
652
|
-
const r = () => o(
|
|
657
|
+
const r = () => o(lt), a = () => {
|
|
653
658
|
var l;
|
|
654
659
|
return ((l = i.selected) == null ? void 0 : l.length) === 0;
|
|
655
660
|
}, s = (l) => {
|
|
656
661
|
if (i.selected.length === 0)
|
|
657
662
|
return !1;
|
|
658
663
|
const m = typeof l == "string" ? l : l.id;
|
|
659
|
-
return i.selected.some((
|
|
664
|
+
return i.selected.some((p) => p.id === m);
|
|
660
665
|
}, u = (l, m) => {
|
|
661
|
-
const
|
|
662
|
-
if (
|
|
663
|
-
const y =
|
|
666
|
+
const p = t.getAnnotation(l);
|
|
667
|
+
if (p) {
|
|
668
|
+
const y = Ue(p, e);
|
|
664
669
|
o(y === "EDIT" ? { selected: [{ id: l, editable: !0 }], pointerEvent: m } : y === "SELECT" ? { selected: [{ id: l }], pointerEvent: m } : { selected: [], pointerEvent: m });
|
|
665
670
|
} else
|
|
666
671
|
console.warn("Invalid selection: " + l);
|
|
667
672
|
}, f = (l, m = !0) => {
|
|
668
|
-
const
|
|
669
|
-
o({ selected: y.map(({ id: v }) => ({ id: v, editable: m })) }), y.length !==
|
|
673
|
+
const p = Array.isArray(l) ? l : [l], y = p.map((v) => t.getAnnotation(v)).filter(Boolean);
|
|
674
|
+
o({ selected: y.map(({ id: v }) => ({ id: v, editable: m })) }), y.length !== p.length && console.warn("Invalid selection", l);
|
|
670
675
|
}, b = (l) => {
|
|
671
676
|
if (i.selected.length === 0)
|
|
672
677
|
return !1;
|
|
673
678
|
const { selected: m } = i;
|
|
674
|
-
m.filter(({ id:
|
|
679
|
+
m.filter(({ id: p }) => l.includes(p)).length > 0 && o({ selected: m.filter(({ id: p }) => !l.includes(p)) });
|
|
675
680
|
};
|
|
676
681
|
return t.observe(({ changes: l }) => b((l.deleted || []).map((m) => m.id))), {
|
|
677
682
|
clear: r,
|
|
@@ -687,58 +692,58 @@ const at = { selected: [] }, Oe = (t, e = "EDIT") => {
|
|
|
687
692
|
setSelected: f,
|
|
688
693
|
subscribe: n
|
|
689
694
|
};
|
|
690
|
-
},
|
|
695
|
+
}, Ue = (t, e) => typeof e == "function" ? e(t) || "EDIT" : e || "EDIT";
|
|
691
696
|
let J;
|
|
692
|
-
const
|
|
693
|
-
function
|
|
697
|
+
const Ve = new Uint8Array(16);
|
|
698
|
+
function ke() {
|
|
694
699
|
if (!J && (J = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !J))
|
|
695
700
|
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
696
|
-
return J(
|
|
701
|
+
return J(Ve);
|
|
697
702
|
}
|
|
698
703
|
const N = [];
|
|
699
704
|
for (let t = 0; t < 256; ++t)
|
|
700
705
|
N.push((t + 256).toString(16).slice(1));
|
|
701
|
-
function
|
|
706
|
+
function Ye(t, e = 0) {
|
|
702
707
|
return N[t[e + 0]] + N[t[e + 1]] + N[t[e + 2]] + N[t[e + 3]] + "-" + N[t[e + 4]] + N[t[e + 5]] + "-" + N[t[e + 6]] + N[t[e + 7]] + "-" + N[t[e + 8]] + N[t[e + 9]] + "-" + N[t[e + 10]] + N[t[e + 11]] + N[t[e + 12]] + N[t[e + 13]] + N[t[e + 14]] + N[t[e + 15]];
|
|
703
708
|
}
|
|
704
|
-
const
|
|
705
|
-
randomUUID:
|
|
709
|
+
const _e = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Rt = {
|
|
710
|
+
randomUUID: _e
|
|
706
711
|
};
|
|
707
|
-
function
|
|
712
|
+
function Xe(t, e, n) {
|
|
708
713
|
if (Rt.randomUUID && !e && !t)
|
|
709
714
|
return Rt.randomUUID();
|
|
710
715
|
t = t || {};
|
|
711
|
-
const o = t.random || (t.rng ||
|
|
712
|
-
return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128,
|
|
716
|
+
const o = t.random || (t.rng || ke)();
|
|
717
|
+
return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, Ye(o);
|
|
713
718
|
}
|
|
714
|
-
const
|
|
715
|
-
id:
|
|
719
|
+
const On = (t, e, n, o) => ({
|
|
720
|
+
id: Xe(),
|
|
716
721
|
annotation: t.id,
|
|
717
722
|
created: n || /* @__PURE__ */ new Date(),
|
|
718
723
|
creator: o,
|
|
719
724
|
...e
|
|
720
|
-
}),
|
|
725
|
+
}), De = (t, e) => {
|
|
721
726
|
const n = new Set(t.bodies.map((o) => o.id));
|
|
722
727
|
return e.bodies.filter((o) => !n.has(o.id));
|
|
723
|
-
},
|
|
728
|
+
}, $e = (t, e) => {
|
|
724
729
|
const n = new Set(e.bodies.map((o) => o.id));
|
|
725
730
|
return t.bodies.filter((o) => !n.has(o.id));
|
|
726
|
-
},
|
|
731
|
+
}, He = (t, e) => e.bodies.map((n) => {
|
|
727
732
|
const o = t.bodies.find((i) => i.id === n.id);
|
|
728
733
|
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 =
|
|
734
|
+
}).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), Pe = (t, e) => !F(t.target, e.target), _t = (t, e) => {
|
|
735
|
+
const n = De(t, e), o = $e(t, e), i = He(t, e);
|
|
731
736
|
return {
|
|
732
737
|
oldValue: t,
|
|
733
738
|
newValue: e,
|
|
734
739
|
bodiesCreated: n.length > 0 ? n : void 0,
|
|
735
740
|
bodiesDeleted: o.length > 0 ? o : void 0,
|
|
736
741
|
bodiesUpdated: i.length > 0 ? i : void 0,
|
|
737
|
-
targetUpdated:
|
|
742
|
+
targetUpdated: Pe(t, e) ? { oldTarget: t.target, newTarget: e.target } : void 0
|
|
738
743
|
};
|
|
739
744
|
};
|
|
740
745
|
var R = /* @__PURE__ */ ((t) => (t.LOCAL = "LOCAL", t.REMOTE = "REMOTE", t))(R || {});
|
|
741
|
-
const
|
|
746
|
+
const ze = (t, e) => {
|
|
742
747
|
var n, o;
|
|
743
748
|
const { changes: i, origin: r } = e;
|
|
744
749
|
if (!(!t.options.origin || t.options.origin === r))
|
|
@@ -760,7 +765,7 @@ const Pe = (t, e) => {
|
|
|
760
765
|
return !!(Array.isArray(t.options.annotations) ? t.options.annotations : [t.options.annotations]).find((s) => a.has(s));
|
|
761
766
|
} else
|
|
762
767
|
return !0;
|
|
763
|
-
},
|
|
768
|
+
}, Fe = (t, e) => {
|
|
764
769
|
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
770
|
...(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
771
|
...e.created || []
|
|
@@ -769,9 +774,9 @@ const Pe = (t, e) => {
|
|
|
769
774
|
...(e.deleted || []).filter((l) => !n.has(l.id))
|
|
770
775
|
], b = [
|
|
771
776
|
...(t.updated || []).filter(({ newValue: l }) => !r.has(l.id)).map((l) => {
|
|
772
|
-
const { oldValue: m, newValue:
|
|
773
|
-
if (a.has(
|
|
774
|
-
const y = e.updated.find((v) => v.oldValue.id ===
|
|
777
|
+
const { oldValue: m, newValue: p } = l;
|
|
778
|
+
if (a.has(p.id)) {
|
|
779
|
+
const y = e.updated.find((v) => v.oldValue.id === p.id).newValue;
|
|
775
780
|
return _t(m, y);
|
|
776
781
|
} else
|
|
777
782
|
return l;
|
|
@@ -779,13 +784,13 @@ const Pe = (t, e) => {
|
|
|
779
784
|
...(e.updated || []).filter(({ oldValue: l }) => !s.has(l.id))
|
|
780
785
|
];
|
|
781
786
|
return { created: u, deleted: f, updated: b };
|
|
782
|
-
},
|
|
783
|
-
const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (
|
|
784
|
-
const A = n.findIndex((x) => x.onChange ==
|
|
787
|
+
}, We = (t) => t.id !== void 0, qe = () => {
|
|
788
|
+
const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (g, A = {}) => n.push({ onChange: g, options: A }), i = (g) => {
|
|
789
|
+
const A = n.findIndex((x) => x.onChange == g);
|
|
785
790
|
A > -1 && n.splice(A, 1);
|
|
786
|
-
}, r = (
|
|
791
|
+
}, r = (g, A) => {
|
|
787
792
|
const x = {
|
|
788
|
-
origin:
|
|
793
|
+
origin: g,
|
|
789
794
|
changes: {
|
|
790
795
|
created: A.created || [],
|
|
791
796
|
updated: A.updated || [],
|
|
@@ -794,85 +799,85 @@ const Pe = (t, e) => {
|
|
|
794
799
|
state: [...t.values()]
|
|
795
800
|
};
|
|
796
801
|
n.forEach((S) => {
|
|
797
|
-
|
|
802
|
+
ze(S, x) && S.onChange(x);
|
|
798
803
|
});
|
|
799
|
-
}, a = (
|
|
800
|
-
if (t.get(
|
|
801
|
-
throw Error(`Cannot add annotation ${
|
|
802
|
-
t.set(
|
|
803
|
-
}, s = (
|
|
804
|
-
const x = typeof
|
|
804
|
+
}, a = (g, A = R.LOCAL) => {
|
|
805
|
+
if (t.get(g.id))
|
|
806
|
+
throw Error(`Cannot add annotation ${g.id} - exists already`);
|
|
807
|
+
t.set(g.id, g), g.bodies.forEach((x) => e.set(x.id, g.id)), r(A, { created: [g] });
|
|
808
|
+
}, s = (g, A) => {
|
|
809
|
+
const x = typeof g == "string" ? A : g, S = typeof g == "string" ? g : g.id, B = t.get(S);
|
|
805
810
|
if (B) {
|
|
806
811
|
const I = _t(B, x);
|
|
807
812
|
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
813
|
} else
|
|
809
814
|
console.warn(`Cannot update annotation ${S} - does not exist`);
|
|
810
|
-
}, u = (
|
|
811
|
-
const S =
|
|
815
|
+
}, u = (g, A = R.LOCAL, x = R.LOCAL) => {
|
|
816
|
+
const S = We(A) ? x : A, B = s(g, A);
|
|
812
817
|
B && r(S, { updated: [B] });
|
|
813
|
-
}, f = (
|
|
814
|
-
const x =
|
|
818
|
+
}, f = (g, A = R.LOCAL) => {
|
|
819
|
+
const x = g.reduce((S, B) => {
|
|
815
820
|
const I = s(B);
|
|
816
821
|
return I ? [...S, I] : S;
|
|
817
822
|
}, []);
|
|
818
823
|
x.length > 0 && r(A, { updated: x });
|
|
819
|
-
}, b = (
|
|
820
|
-
const x = t.get(
|
|
824
|
+
}, b = (g, A = R.LOCAL) => {
|
|
825
|
+
const x = t.get(g.annotation);
|
|
821
826
|
if (x) {
|
|
822
827
|
const S = {
|
|
823
828
|
...x,
|
|
824
|
-
bodies: [...x.bodies,
|
|
829
|
+
bodies: [...x.bodies, g]
|
|
825
830
|
};
|
|
826
|
-
t.set(x.id, S), e.set(
|
|
831
|
+
t.set(x.id, S), e.set(g.id, S.id), r(A, { updated: [{
|
|
827
832
|
oldValue: x,
|
|
828
833
|
newValue: S,
|
|
829
|
-
bodiesCreated: [
|
|
834
|
+
bodiesCreated: [g]
|
|
830
835
|
}] });
|
|
831
836
|
} else
|
|
832
|
-
console.warn(`Attempt to add body to missing annotation: ${
|
|
833
|
-
}, l = () => [...t.values()], m = (
|
|
837
|
+
console.warn(`Attempt to add body to missing annotation: ${g.annotation}`);
|
|
838
|
+
}, l = () => [...t.values()], m = (g = R.LOCAL) => {
|
|
834
839
|
const A = [...t.values()];
|
|
835
|
-
t.clear(), e.clear(), r(
|
|
836
|
-
},
|
|
840
|
+
t.clear(), e.clear(), r(g, { deleted: A });
|
|
841
|
+
}, p = (g, A = !0, x = R.LOCAL) => {
|
|
837
842
|
if (A) {
|
|
838
843
|
const S = [...t.values()];
|
|
839
|
-
t.clear(), e.clear(),
|
|
844
|
+
t.clear(), e.clear(), g.forEach((B) => {
|
|
840
845
|
t.set(B.id, B), B.bodies.forEach((I) => e.set(I.id, B.id));
|
|
841
|
-
}), r(x, { created:
|
|
846
|
+
}), r(x, { created: g, deleted: S });
|
|
842
847
|
} else {
|
|
843
|
-
const S =
|
|
848
|
+
const S = g.reduce((B, I) => {
|
|
844
849
|
const k = t.get(I.id);
|
|
845
850
|
return k ? [...B, k] : B;
|
|
846
851
|
}, []);
|
|
847
852
|
if (S.length > 0)
|
|
848
853
|
throw Error(`Bulk insert would overwrite the following annotations: ${S.map((B) => B.id).join(", ")}`);
|
|
849
|
-
|
|
854
|
+
g.forEach((B) => {
|
|
850
855
|
t.set(B.id, B), B.bodies.forEach((I) => e.set(I.id, B.id));
|
|
851
|
-
}), r(x, { created:
|
|
856
|
+
}), r(x, { created: g });
|
|
852
857
|
}
|
|
853
|
-
}, y = (
|
|
854
|
-
const A = typeof
|
|
858
|
+
}, y = (g) => {
|
|
859
|
+
const A = typeof g == "string" ? g : g.id, x = t.get(A);
|
|
855
860
|
if (x)
|
|
856
861
|
return t.delete(A), x.bodies.forEach((S) => e.delete(S.id)), x;
|
|
857
862
|
console.warn(`Attempt to delete missing annotation: ${A}`);
|
|
858
|
-
}, v = (
|
|
859
|
-
const x = y(
|
|
863
|
+
}, v = (g, A = R.LOCAL) => {
|
|
864
|
+
const x = y(g);
|
|
860
865
|
x && r(A, { deleted: [x] });
|
|
861
|
-
}, h = (
|
|
862
|
-
const x =
|
|
866
|
+
}, h = (g, A = R.LOCAL) => {
|
|
867
|
+
const x = g.reduce((S, B) => {
|
|
863
868
|
const I = y(B);
|
|
864
869
|
return I ? [...S, I] : S;
|
|
865
870
|
}, []);
|
|
866
871
|
x.length > 0 && r(A, { deleted: x });
|
|
867
|
-
}, d = (
|
|
868
|
-
const x = t.get(
|
|
872
|
+
}, d = (g, A = R.LOCAL) => {
|
|
873
|
+
const x = t.get(g.annotation);
|
|
869
874
|
if (x) {
|
|
870
|
-
const S = x.bodies.find((B) => B.id ===
|
|
875
|
+
const S = x.bodies.find((B) => B.id === g.id);
|
|
871
876
|
if (S) {
|
|
872
877
|
e.delete(S.id);
|
|
873
878
|
const B = {
|
|
874
879
|
...x,
|
|
875
|
-
bodies: x.bodies.filter((I) => I.id !==
|
|
880
|
+
bodies: x.bodies.filter((I) => I.id !== g.id)
|
|
876
881
|
};
|
|
877
882
|
t.set(x.id, B), r(A, { updated: [{
|
|
878
883
|
oldValue: x,
|
|
@@ -880,27 +885,27 @@ const Pe = (t, e) => {
|
|
|
880
885
|
bodiesDeleted: [S]
|
|
881
886
|
}] });
|
|
882
887
|
} else
|
|
883
|
-
console.warn(`Attempt to delete missing body ${
|
|
888
|
+
console.warn(`Attempt to delete missing body ${g.id} from annotation ${g.annotation}`);
|
|
884
889
|
} else
|
|
885
|
-
console.warn(`Attempt to delete body from missing annotation ${
|
|
886
|
-
}, c = (
|
|
887
|
-
const A = t.get(
|
|
890
|
+
console.warn(`Attempt to delete body from missing annotation ${g.annotation}`);
|
|
891
|
+
}, c = (g) => {
|
|
892
|
+
const A = t.get(g);
|
|
888
893
|
return A ? { ...A } : void 0;
|
|
889
|
-
}, w = (
|
|
890
|
-
const A = e.get(
|
|
894
|
+
}, w = (g) => {
|
|
895
|
+
const A = e.get(g);
|
|
891
896
|
if (A) {
|
|
892
|
-
const x = c(A).bodies.find((S) => S.id ===
|
|
897
|
+
const x = c(A).bodies.find((S) => S.id === g);
|
|
893
898
|
if (x)
|
|
894
899
|
return x;
|
|
895
|
-
console.error(`Store integrity error: body ${
|
|
900
|
+
console.error(`Store integrity error: body ${g} in index, but not in annotation`);
|
|
896
901
|
} else
|
|
897
|
-
console.warn(`Attempt to retrieve missing body: ${
|
|
898
|
-
}, L = (
|
|
899
|
-
if (
|
|
902
|
+
console.warn(`Attempt to retrieve missing body: ${g}`);
|
|
903
|
+
}, L = (g, A) => {
|
|
904
|
+
if (g.annotation !== A.annotation)
|
|
900
905
|
throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
|
|
901
|
-
const x = t.get(
|
|
906
|
+
const x = t.get(g.annotation);
|
|
902
907
|
if (x) {
|
|
903
|
-
const S = x.bodies.find((I) => I.id ===
|
|
908
|
+
const S = x.bodies.find((I) => I.id === g.id), B = {
|
|
904
909
|
...x,
|
|
905
910
|
bodies: x.bodies.map((I) => I.id === S.id ? A : I)
|
|
906
911
|
};
|
|
@@ -910,21 +915,21 @@ const Pe = (t, e) => {
|
|
|
910
915
|
bodiesUpdated: [{ oldBody: S, newBody: A }]
|
|
911
916
|
};
|
|
912
917
|
} else
|
|
913
|
-
console.warn(`Attempt to add body to missing annotation ${
|
|
914
|
-
}, C = (
|
|
915
|
-
const S = L(
|
|
918
|
+
console.warn(`Attempt to add body to missing annotation ${g.annotation}`);
|
|
919
|
+
}, C = (g, A, x = R.LOCAL) => {
|
|
920
|
+
const S = L(g, A);
|
|
916
921
|
S && r(x, { updated: [S] });
|
|
917
|
-
}, E = (
|
|
918
|
-
const x =
|
|
922
|
+
}, E = (g, A = R.LOCAL) => {
|
|
923
|
+
const x = g.map((S) => L({ id: S.id, annotation: S.annotation }, S)).filter(Boolean);
|
|
919
924
|
r(A, { updated: x });
|
|
920
|
-
}, T = (
|
|
921
|
-
const A = t.get(
|
|
925
|
+
}, T = (g) => {
|
|
926
|
+
const A = t.get(g.annotation);
|
|
922
927
|
if (A) {
|
|
923
928
|
const x = {
|
|
924
929
|
...A,
|
|
925
930
|
target: {
|
|
926
931
|
...A.target,
|
|
927
|
-
...
|
|
932
|
+
...g
|
|
928
933
|
}
|
|
929
934
|
};
|
|
930
935
|
return t.set(A.id, x), {
|
|
@@ -932,22 +937,22 @@ const Pe = (t, e) => {
|
|
|
932
937
|
newValue: x,
|
|
933
938
|
targetUpdated: {
|
|
934
939
|
oldTarget: A.target,
|
|
935
|
-
newTarget:
|
|
940
|
+
newTarget: g
|
|
936
941
|
}
|
|
937
942
|
};
|
|
938
943
|
} else
|
|
939
|
-
console.warn(`Attempt to update target on missing annotation: ${
|
|
944
|
+
console.warn(`Attempt to update target on missing annotation: ${g.annotation}`);
|
|
940
945
|
};
|
|
941
946
|
return {
|
|
942
947
|
addAnnotation: a,
|
|
943
948
|
addBody: b,
|
|
944
949
|
all: l,
|
|
945
|
-
bulkAddAnnotation:
|
|
950
|
+
bulkAddAnnotation: p,
|
|
946
951
|
bulkDeleteAnnotation: h,
|
|
947
952
|
bulkUpdateAnnotation: f,
|
|
948
953
|
bulkUpdateBodies: E,
|
|
949
|
-
bulkUpdateTargets: (
|
|
950
|
-
const x =
|
|
954
|
+
bulkUpdateTargets: (g, A = R.LOCAL) => {
|
|
955
|
+
const x = g.map((S) => T(S)).filter(Boolean);
|
|
951
956
|
x.length > 0 && r(A, { updated: x });
|
|
952
957
|
},
|
|
953
958
|
clear: m,
|
|
@@ -959,13 +964,13 @@ const Pe = (t, e) => {
|
|
|
959
964
|
unobserve: i,
|
|
960
965
|
updateAnnotation: u,
|
|
961
966
|
updateBody: C,
|
|
962
|
-
updateTarget: (
|
|
963
|
-
const x = T(
|
|
967
|
+
updateTarget: (g, A = R.LOCAL) => {
|
|
968
|
+
const x = T(g);
|
|
964
969
|
x && r(A, { updated: [x] });
|
|
965
970
|
}
|
|
966
971
|
};
|
|
967
972
|
};
|
|
968
|
-
let
|
|
973
|
+
let je = () => ({
|
|
969
974
|
emit(t, ...e) {
|
|
970
975
|
for (let n = 0, o = this.events[t] || [], i = o.length; n < i; n++)
|
|
971
976
|
o[n](...e);
|
|
@@ -979,51 +984,51 @@ let qe = () => ({
|
|
|
979
984
|
};
|
|
980
985
|
}
|
|
981
986
|
});
|
|
982
|
-
const
|
|
983
|
-
const e =
|
|
987
|
+
const Ge = 250, Ke = (t) => {
|
|
988
|
+
const e = je(), n = [];
|
|
984
989
|
let o = -1, i = !1, r = 0;
|
|
985
|
-
const a = (
|
|
990
|
+
const a = (p) => {
|
|
986
991
|
if (!i) {
|
|
987
|
-
const { changes: y } =
|
|
988
|
-
if (v - r >
|
|
992
|
+
const { changes: y } = p, v = performance.now();
|
|
993
|
+
if (v - r > Ge)
|
|
989
994
|
n.splice(o + 1), n.push(y), o = n.length - 1;
|
|
990
995
|
else {
|
|
991
996
|
const h = n.length - 1;
|
|
992
|
-
n[h] =
|
|
997
|
+
n[h] = Fe(n[h], y);
|
|
993
998
|
}
|
|
994
999
|
r = v;
|
|
995
1000
|
}
|
|
996
1001
|
i = !1;
|
|
997
1002
|
};
|
|
998
1003
|
t.observe(a, { origin: R.LOCAL });
|
|
999
|
-
const s = (
|
|
1004
|
+
const s = (p) => p && p.length > 0 && t.bulkDeleteAnnotation(p), u = (p) => p && p.length > 0 && t.bulkAddAnnotation(p, !1), f = (p) => p && p.length > 0 && t.bulkUpdateAnnotation(p.map(({ oldValue: y }) => y)), b = (p) => p && p.length > 0 && t.bulkUpdateAnnotation(p.map(({ newValue: y }) => y)), l = (p) => p && p.length > 0 && t.bulkAddAnnotation(p, !1), m = (p) => p && p.length > 0 && t.bulkDeleteAnnotation(p);
|
|
1000
1005
|
return {
|
|
1001
1006
|
canRedo: () => n.length - 1 > o,
|
|
1002
1007
|
canUndo: () => o > -1,
|
|
1003
1008
|
destroy: () => t.unobserve(a),
|
|
1004
|
-
on: (
|
|
1009
|
+
on: (p, y) => e.on(p, y),
|
|
1005
1010
|
redo: () => {
|
|
1006
1011
|
if (n.length - 1 > o) {
|
|
1007
1012
|
i = !0;
|
|
1008
|
-
const { created:
|
|
1009
|
-
u(
|
|
1013
|
+
const { created: p, updated: y, deleted: v } = n[o + 1];
|
|
1014
|
+
u(p), b(y), m(v), e.emit("redo", n[o + 1]), o += 1;
|
|
1010
1015
|
}
|
|
1011
1016
|
},
|
|
1012
1017
|
undo: () => {
|
|
1013
1018
|
if (o > -1) {
|
|
1014
1019
|
i = !0;
|
|
1015
|
-
const { created:
|
|
1016
|
-
s(
|
|
1020
|
+
const { created: p, updated: y, deleted: v } = n[o];
|
|
1021
|
+
s(p), f(y), l(v), e.emit("undo", n[o]), o -= 1;
|
|
1017
1022
|
}
|
|
1018
1023
|
}
|
|
1019
1024
|
};
|
|
1020
|
-
},
|
|
1021
|
-
const { subscribe: t, set: e } =
|
|
1025
|
+
}, Qe = () => {
|
|
1026
|
+
const { subscribe: t, set: e } = gt([]);
|
|
1022
1027
|
return {
|
|
1023
1028
|
subscribe: t,
|
|
1024
1029
|
set: e
|
|
1025
1030
|
};
|
|
1026
|
-
},
|
|
1031
|
+
}, Je = (t, e, n, o) => {
|
|
1027
1032
|
const { store: i, selection: r, hover: a, viewport: s } = t, u = /* @__PURE__ */ new Map();
|
|
1028
1033
|
let f = [], b;
|
|
1029
1034
|
const l = (v, h) => {
|
|
@@ -1031,7 +1036,7 @@ const je = 250, Ge = (t) => {
|
|
|
1031
1036
|
}, m = (v, h) => {
|
|
1032
1037
|
const d = u.get(v);
|
|
1033
1038
|
d && d.indexOf(h) > 0 && d.splice(d.indexOf(h), 1);
|
|
1034
|
-
},
|
|
1039
|
+
}, p = (v, h, d) => {
|
|
1035
1040
|
u.has(v) && setTimeout(() => {
|
|
1036
1041
|
u.get(v).forEach((c) => {
|
|
1037
1042
|
if (n) {
|
|
@@ -1049,13 +1054,13 @@ const je = 250, Ge = (t) => {
|
|
|
1049
1054
|
else if (f.length > 0 && v.length === 0)
|
|
1050
1055
|
f.forEach((h) => {
|
|
1051
1056
|
const d = i.getAnnotation(h.id);
|
|
1052
|
-
d && !F(d, h) &&
|
|
1057
|
+
d && !F(d, h) && p("updateAnnotation", d, h);
|
|
1053
1058
|
}), f = [];
|
|
1054
1059
|
else {
|
|
1055
1060
|
const h = new Set(f.map((c) => c.id)), d = new Set(v.map(({ id: c }) => c));
|
|
1056
1061
|
f.filter((c) => !d.has(c.id)).forEach((c) => {
|
|
1057
1062
|
const w = i.getAnnotation(c.id);
|
|
1058
|
-
w && !F(w, c) &&
|
|
1063
|
+
w && !F(w, c) && p("updateAnnotation", w, c);
|
|
1059
1064
|
}), f = [
|
|
1060
1065
|
// Remove annotations that were deselected
|
|
1061
1066
|
...f.filter((c) => d.has(c.id)),
|
|
@@ -1063,19 +1068,19 @@ const je = 250, Ge = (t) => {
|
|
|
1063
1068
|
...v.filter(({ id: c }) => !h.has(c)).map(({ id: c }) => i.getAnnotation(c))
|
|
1064
1069
|
];
|
|
1065
1070
|
}
|
|
1066
|
-
|
|
1071
|
+
p("selectionChanged", f);
|
|
1067
1072
|
}
|
|
1068
1073
|
}), a.subscribe((v) => {
|
|
1069
|
-
!b && v ?
|
|
1070
|
-
}), s == null || s.subscribe((v) =>
|
|
1074
|
+
!b && v ? p("mouseEnterAnnotation", i.getAnnotation(v)) : b && !v ? p("mouseLeaveAnnotation", i.getAnnotation(b)) : b && v && (p("mouseLeaveAnnotation", i.getAnnotation(b)), p("mouseEnterAnnotation", i.getAnnotation(v))), b = v;
|
|
1075
|
+
}), s == null || s.subscribe((v) => p("viewportIntersect", v.map((h) => i.getAnnotation(h)))), i.observe((v) => {
|
|
1071
1076
|
const { created: h, deleted: d } = v.changes;
|
|
1072
|
-
(h || []).forEach((c) =>
|
|
1077
|
+
(h || []).forEach((c) => p("createAnnotation", c)), (d || []).forEach((c) => p("deleteAnnotation", c)), (v.changes.updated || []).filter((c) => [
|
|
1073
1078
|
...c.bodiesCreated || [],
|
|
1074
1079
|
...c.bodiesDeleted || [],
|
|
1075
1080
|
...c.bodiesUpdated || []
|
|
1076
1081
|
].length > 0).forEach(({ oldValue: c, newValue: w }) => {
|
|
1077
1082
|
const L = f.find((C) => C.id === c.id) || c;
|
|
1078
|
-
f = f.map((C) => C.id === c.id ? w : C),
|
|
1083
|
+
f = f.map((C) => C.id === c.id ? w : C), p("updateAnnotation", w, L);
|
|
1079
1084
|
});
|
|
1080
1085
|
}, { origin: R.LOCAL }), i.observe((v) => {
|
|
1081
1086
|
if (f) {
|
|
@@ -1085,10 +1090,10 @@ const je = 250, Ge = (t) => {
|
|
|
1085
1090
|
}, { origin: R.REMOTE });
|
|
1086
1091
|
const y = (v) => (h) => {
|
|
1087
1092
|
const { updated: d } = h;
|
|
1088
|
-
v ? (d || []).forEach((c) =>
|
|
1093
|
+
v ? (d || []).forEach((c) => p("updateAnnotation", c.oldValue, c.newValue)) : (d || []).forEach((c) => p("updateAnnotation", c.newValue, c.oldValue));
|
|
1089
1094
|
};
|
|
1090
|
-
return e.on("undo", y(!0)), e.on("redo", y(!1)), { on: l, off: m, emit:
|
|
1091
|
-
},
|
|
1095
|
+
return e.on("undo", y(!0)), e.on("redo", y(!1)), { on: l, off: m, emit: p };
|
|
1096
|
+
}, Ze = (t) => (e) => e.reduce((n, o) => {
|
|
1092
1097
|
const { parsed: i, error: r } = t.parse(o);
|
|
1093
1098
|
return r ? {
|
|
1094
1099
|
parsed: n.parsed,
|
|
@@ -1099,7 +1104,7 @@ const je = 250, Ge = (t) => {
|
|
|
1099
1104
|
} : {
|
|
1100
1105
|
...n
|
|
1101
1106
|
};
|
|
1102
|
-
}, { parsed: [], failed: [] }),
|
|
1107
|
+
}, { parsed: [], failed: [] }), tn = (t, e, n) => {
|
|
1103
1108
|
const { store: o, selection: i } = t, r = (h) => {
|
|
1104
1109
|
if (n) {
|
|
1105
1110
|
const { parsed: d, error: c } = n.parse(h);
|
|
@@ -1113,7 +1118,7 @@ const je = 250, Ge = (t) => {
|
|
|
1113
1118
|
var h;
|
|
1114
1119
|
const d = (((h = i.selected) == null ? void 0 : h.map((c) => c.id)) || []).map((c) => o.getAnnotation(c)).filter(Boolean);
|
|
1115
1120
|
return n ? d.map(n.serialize) : d;
|
|
1116
|
-
}, l = (h, d = !0) => fetch(h).then((c) => c.json()).then((c) => (
|
|
1121
|
+
}, l = (h, d = !0) => fetch(h).then((c) => c.json()).then((c) => (p(c, d), c)), m = (h) => {
|
|
1117
1122
|
if (typeof h == "string") {
|
|
1118
1123
|
const d = o.getAnnotation(h);
|
|
1119
1124
|
if (o.deleteAnnotation(h), d)
|
|
@@ -1123,9 +1128,9 @@ const je = 250, Ge = (t) => {
|
|
|
1123
1128
|
if (d)
|
|
1124
1129
|
return o.deleteAnnotation(d), h;
|
|
1125
1130
|
}
|
|
1126
|
-
},
|
|
1131
|
+
}, p = (h, d = !0) => {
|
|
1127
1132
|
if (n) {
|
|
1128
|
-
const { parsed: c, failed: w } =
|
|
1133
|
+
const { parsed: c, failed: w } = Ze(n)(h);
|
|
1129
1134
|
w.length > 0 && console.warn(`Discarded ${w.length} invalid annotations`, w), o.bulkAddAnnotation(c, d, R.REMOTE);
|
|
1130
1135
|
} else
|
|
1131
1136
|
o.bulkAddAnnotation(h, d, R.REMOTE);
|
|
@@ -1152,13 +1157,13 @@ const je = 250, Ge = (t) => {
|
|
|
1152
1157
|
loadAnnotations: l,
|
|
1153
1158
|
redo: e.redo,
|
|
1154
1159
|
removeAnnotation: m,
|
|
1155
|
-
setAnnotations:
|
|
1160
|
+
setAnnotations: p,
|
|
1156
1161
|
setSelected: y,
|
|
1157
1162
|
undo: e.undo,
|
|
1158
1163
|
updateAnnotation: v
|
|
1159
1164
|
};
|
|
1160
|
-
},
|
|
1161
|
-
let
|
|
1165
|
+
}, en = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
1166
|
+
let nn = (t) => crypto.getRandomValues(new Uint8Array(t)), on = (t, e, n) => {
|
|
1162
1167
|
let o = (2 << Math.log(t.length - 1) / Math.LN2) - 1, i = -~(1.6 * o * e / t.length);
|
|
1163
1168
|
return (r = e) => {
|
|
1164
1169
|
let a = "";
|
|
@@ -1169,13 +1174,13 @@ let en = (t) => crypto.getRandomValues(new Uint8Array(t)), nn = (t, e, n) => {
|
|
|
1169
1174
|
return a;
|
|
1170
1175
|
}
|
|
1171
1176
|
};
|
|
1172
|
-
},
|
|
1177
|
+
}, rn = (t, e = 21) => on(t, e, nn), sn = (t = 21) => {
|
|
1173
1178
|
let e = "", n = crypto.getRandomValues(new Uint8Array(t));
|
|
1174
1179
|
for (; t--; )
|
|
1175
|
-
e +=
|
|
1180
|
+
e += en[n[t] & 63];
|
|
1176
1181
|
return e;
|
|
1177
1182
|
};
|
|
1178
|
-
const
|
|
1183
|
+
const an = () => ({ isGuest: !0, id: rn("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() }), ln = (t) => {
|
|
1179
1184
|
const e = JSON.stringify(t);
|
|
1180
1185
|
let n = 0;
|
|
1181
1186
|
for (let o = 0, i = e.length; o < i; o++) {
|
|
@@ -1183,10 +1188,10 @@ const sn = () => ({ isGuest: !0, id: on("1234567890abcdefghijklmnopqrstuvwxyzABC
|
|
|
1183
1188
|
n = (n << 5) - n + r, n |= 0;
|
|
1184
1189
|
}
|
|
1185
1190
|
return `${n}`;
|
|
1186
|
-
}, Xt = (t) => t ? typeof t == "object" ? { ...t } : t : void 0,
|
|
1191
|
+
}, Xt = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, cn = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
|
|
1187
1192
|
const { id: o, type: i, purpose: r, value: a, created: s, creator: u, ...f } = n;
|
|
1188
1193
|
return {
|
|
1189
|
-
id: o || `temp-${
|
|
1194
|
+
id: o || `temp-${ln(n)}`,
|
|
1190
1195
|
annotation: e,
|
|
1191
1196
|
type: i,
|
|
1192
1197
|
purpose: r,
|
|
@@ -1195,16 +1200,16 @@ const sn = () => ({ isGuest: !0, id: on("1234567890abcdefghijklmnopqrstuvwxyzABC
|
|
|
1195
1200
|
creator: Xt(u),
|
|
1196
1201
|
...f
|
|
1197
1202
|
};
|
|
1198
|
-
}),
|
|
1203
|
+
}), dn = (t) => t.map((e) => {
|
|
1199
1204
|
var n, o;
|
|
1200
1205
|
const i = { ...e };
|
|
1201
1206
|
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
1207
|
});
|
|
1203
|
-
|
|
1204
|
-
const
|
|
1205
|
-
parse: (n) =>
|
|
1206
|
-
serialize: (n) =>
|
|
1207
|
-
}),
|
|
1208
|
+
sn();
|
|
1209
|
+
const Nn = (t, e) => ({
|
|
1210
|
+
parse: (n) => fn(n),
|
|
1211
|
+
serialize: (n) => pn(n, t, e)
|
|
1212
|
+
}), un = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, hn = (t) => {
|
|
1208
1213
|
const {
|
|
1209
1214
|
id: e,
|
|
1210
1215
|
creator: n,
|
|
@@ -1234,7 +1239,7 @@ const On = (t, e) => ({
|
|
|
1234
1239
|
}
|
|
1235
1240
|
return l;
|
|
1236
1241
|
}, {});
|
|
1237
|
-
if (
|
|
1242
|
+
if (un(b))
|
|
1238
1243
|
s.selector.push({ id: u.id, ...b });
|
|
1239
1244
|
else {
|
|
1240
1245
|
const l = [
|
|
@@ -1245,14 +1250,14 @@ const On = (t, e) => ({
|
|
|
1245
1250
|
}
|
|
1246
1251
|
}
|
|
1247
1252
|
return { parsed: s };
|
|
1248
|
-
},
|
|
1253
|
+
}, fn = (t) => {
|
|
1249
1254
|
const e = t.id || Yt(), {
|
|
1250
1255
|
creator: n,
|
|
1251
1256
|
created: o,
|
|
1252
1257
|
modified: i,
|
|
1253
1258
|
body: r,
|
|
1254
1259
|
...a
|
|
1255
|
-
} = t, s =
|
|
1260
|
+
} = t, s = cn(r, e), u = hn(t);
|
|
1256
1261
|
return "error" in u ? { error: u.error } : {
|
|
1257
1262
|
parsed: {
|
|
1258
1263
|
...a,
|
|
@@ -1261,7 +1266,7 @@ const On = (t, e) => ({
|
|
|
1261
1266
|
target: u.parsed
|
|
1262
1267
|
}
|
|
1263
1268
|
};
|
|
1264
|
-
},
|
|
1269
|
+
}, pn = (t, e, n) => {
|
|
1265
1270
|
const { bodies: o, target: i, ...r } = t, {
|
|
1266
1271
|
selector: a,
|
|
1267
1272
|
creator: s,
|
|
@@ -1269,9 +1274,9 @@ const On = (t, e) => ({
|
|
|
1269
1274
|
updated: f,
|
|
1270
1275
|
...b
|
|
1271
1276
|
} = i, l = a.map((m) => {
|
|
1272
|
-
const { quote:
|
|
1277
|
+
const { quote: p, start: y, end: v, range: h } = m, { prefix: d, suffix: c } = te(h, n), w = [{
|
|
1273
1278
|
type: "TextQuoteSelector",
|
|
1274
|
-
exact:
|
|
1279
|
+
exact: p,
|
|
1275
1280
|
prefix: d,
|
|
1276
1281
|
suffix: c
|
|
1277
1282
|
}, {
|
|
@@ -1291,7 +1296,7 @@ const On = (t, e) => ({
|
|
|
1291
1296
|
"@context": "http://www.w3.org/ns/anno.jsonld",
|
|
1292
1297
|
id: t.id,
|
|
1293
1298
|
type: "Annotation",
|
|
1294
|
-
body:
|
|
1299
|
+
body: dn(t.bodies),
|
|
1295
1300
|
creator: s,
|
|
1296
1301
|
created: u == null ? void 0 : u.toISOString(),
|
|
1297
1302
|
modified: f == null ? void 0 : f.toISOString(),
|
|
@@ -1299,7 +1304,7 @@ const On = (t, e) => ({
|
|
|
1299
1304
|
};
|
|
1300
1305
|
};
|
|
1301
1306
|
function gn(t, e, n, o, i) {
|
|
1302
|
-
Dt(t, e, n || 0, o || t.length - 1, i ||
|
|
1307
|
+
Dt(t, e, n || 0, o || t.length - 1, i || mn);
|
|
1303
1308
|
}
|
|
1304
1309
|
function Dt(t, e, n, o, i) {
|
|
1305
1310
|
for (; o > n; ) {
|
|
@@ -1307,10 +1312,10 @@ function Dt(t, e, n, o, i) {
|
|
|
1307
1312
|
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
1313
|
Dt(t, e, b, l, i);
|
|
1309
1314
|
}
|
|
1310
|
-
var m = t[e],
|
|
1311
|
-
for (W(t, n, e), i(t[o], m) > 0 && W(t, n, o);
|
|
1312
|
-
for (W(t,
|
|
1313
|
-
|
|
1315
|
+
var m = t[e], p = n, y = o;
|
|
1316
|
+
for (W(t, n, e), i(t[o], m) > 0 && W(t, n, o); p < y; ) {
|
|
1317
|
+
for (W(t, p, y), p++, y--; i(t[p], m) < 0; )
|
|
1318
|
+
p++;
|
|
1314
1319
|
for (; i(t[y], m) > 0; )
|
|
1315
1320
|
y--;
|
|
1316
1321
|
}
|
|
@@ -1321,10 +1326,10 @@ function W(t, e, n) {
|
|
|
1321
1326
|
var o = t[e];
|
|
1322
1327
|
t[e] = t[n], t[n] = o;
|
|
1323
1328
|
}
|
|
1324
|
-
function
|
|
1329
|
+
function mn(t, e) {
|
|
1325
1330
|
return t < e ? -1 : t > e ? 1 : 0;
|
|
1326
1331
|
}
|
|
1327
|
-
class
|
|
1332
|
+
class bn {
|
|
1328
1333
|
constructor(e = 9) {
|
|
1329
1334
|
this._maxEntries = Math.max(4, e), this._minEntries = Math.max(2, Math.ceil(this._maxEntries * 0.4)), this.clear();
|
|
1330
1335
|
}
|
|
@@ -1340,7 +1345,7 @@ class mn {
|
|
|
1340
1345
|
for (; n; ) {
|
|
1341
1346
|
for (let a = 0; a < n.children.length; a++) {
|
|
1342
1347
|
const s = n.children[a], u = n.leaf ? i(s) : s;
|
|
1343
|
-
tt(e, u) && (n.leaf ? o.push(s) :
|
|
1348
|
+
tt(e, u) && (n.leaf ? o.push(s) : dt(e, u) ? this._all(s, o) : r.push(s));
|
|
1344
1349
|
}
|
|
1345
1350
|
n = r.pop();
|
|
1346
1351
|
}
|
|
@@ -1355,7 +1360,7 @@ class mn {
|
|
|
1355
1360
|
for (let i = 0; i < n.children.length; i++) {
|
|
1356
1361
|
const r = n.children[i], a = n.leaf ? this.toBBox(r) : r;
|
|
1357
1362
|
if (tt(e, a)) {
|
|
1358
|
-
if (n.leaf ||
|
|
1363
|
+
if (n.leaf || dt(e, a))
|
|
1359
1364
|
return !0;
|
|
1360
1365
|
o.push(r);
|
|
1361
1366
|
}
|
|
@@ -1400,11 +1405,11 @@ class mn {
|
|
|
1400
1405
|
let s, u, f;
|
|
1401
1406
|
for (; o || r.length; ) {
|
|
1402
1407
|
if (o || (o = r.pop(), u = r[r.length - 1], s = a.pop(), f = !0), o.leaf) {
|
|
1403
|
-
const b =
|
|
1408
|
+
const b = vn(e, o.children, n);
|
|
1404
1409
|
if (b !== -1)
|
|
1405
1410
|
return o.children.splice(b, 1), r.push(o), this._condense(r), this;
|
|
1406
1411
|
}
|
|
1407
|
-
!f && !o.leaf &&
|
|
1412
|
+
!f && !o.leaf && dt(o, i) ? (r.push(o), a.push(s), s = 0, u = o, o = o.children[0]) : u ? (s++, o = u.children[s], f = !1) : o = null;
|
|
1408
1413
|
}
|
|
1409
1414
|
return this;
|
|
1410
1415
|
}
|
|
@@ -1441,8 +1446,8 @@ class mn {
|
|
|
1441
1446
|
const l = Math.min(b + f - 1, o);
|
|
1442
1447
|
It(e, b, l, u, this.compareMinY);
|
|
1443
1448
|
for (let m = b; m <= l; m += u) {
|
|
1444
|
-
const
|
|
1445
|
-
s.children.push(this._build(e, m,
|
|
1449
|
+
const p = Math.min(m + u - 1, l);
|
|
1450
|
+
s.children.push(this._build(e, m, p, i - 1));
|
|
1446
1451
|
}
|
|
1447
1452
|
}
|
|
1448
1453
|
return P(s, this.toBBox), s;
|
|
@@ -1451,7 +1456,7 @@ class mn {
|
|
|
1451
1456
|
for (; i.push(n), !(n.leaf || i.length - 1 === o); ) {
|
|
1452
1457
|
let r = 1 / 0, a = 1 / 0, s;
|
|
1453
1458
|
for (let u = 0; u < n.children.length; u++) {
|
|
1454
|
-
const f = n.children[u], b =
|
|
1459
|
+
const f = n.children[u], b = ct(f), l = xn(e, f) - b;
|
|
1455
1460
|
l < a ? (a = l, r = b < r ? b : r, s = f) : l === a && b < r && (r = b, s = f);
|
|
1456
1461
|
}
|
|
1457
1462
|
n = s || n.children[0];
|
|
@@ -1477,14 +1482,14 @@ class mn {
|
|
|
1477
1482
|
_chooseSplitIndex(e, n, o) {
|
|
1478
1483
|
let i, r = 1 / 0, a = 1 / 0;
|
|
1479
1484
|
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 =
|
|
1485
|
+
const u = q(e, 0, s, this.toBBox), f = q(e, s, o, this.toBBox), b = An(u, f), l = ct(u) + ct(f);
|
|
1481
1486
|
b < r ? (r = b, i = s, a = l < a ? l : a) : b === r && l < a && (a = l, i = s);
|
|
1482
1487
|
}
|
|
1483
1488
|
return i || o - n;
|
|
1484
1489
|
}
|
|
1485
1490
|
// sorts node children by the best axis for split
|
|
1486
1491
|
_chooseSplitAxis(e, n, o) {
|
|
1487
|
-
const i = e.leaf ? this.compareMinX :
|
|
1492
|
+
const i = e.leaf ? this.compareMinX : wn, r = e.leaf ? this.compareMinY : yn, a = this._allDistMargin(e, n, o, i), s = this._allDistMargin(e, n, o, r);
|
|
1488
1493
|
a < s && e.children.sort(i);
|
|
1489
1494
|
}
|
|
1490
1495
|
// total margin of all possible split distributions where each node is at least m full
|
|
@@ -1511,7 +1516,7 @@ class mn {
|
|
|
1511
1516
|
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
1517
|
}
|
|
1513
1518
|
}
|
|
1514
|
-
function
|
|
1519
|
+
function vn(t, e, n) {
|
|
1515
1520
|
if (!n)
|
|
1516
1521
|
return e.indexOf(t);
|
|
1517
1522
|
for (let o = 0; o < e.length; o++)
|
|
@@ -1533,26 +1538,26 @@ function q(t, e, n, o, i) {
|
|
|
1533
1538
|
function j(t, e) {
|
|
1534
1539
|
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
1540
|
}
|
|
1536
|
-
function
|
|
1541
|
+
function wn(t, e) {
|
|
1537
1542
|
return t.minX - e.minX;
|
|
1538
1543
|
}
|
|
1539
|
-
function
|
|
1544
|
+
function yn(t, e) {
|
|
1540
1545
|
return t.minY - e.minY;
|
|
1541
1546
|
}
|
|
1542
|
-
function
|
|
1547
|
+
function ct(t) {
|
|
1543
1548
|
return (t.maxX - t.minX) * (t.maxY - t.minY);
|
|
1544
1549
|
}
|
|
1545
1550
|
function Z(t) {
|
|
1546
1551
|
return t.maxX - t.minX + (t.maxY - t.minY);
|
|
1547
1552
|
}
|
|
1548
|
-
function
|
|
1553
|
+
function xn(t, e) {
|
|
1549
1554
|
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
1555
|
}
|
|
1551
|
-
function
|
|
1556
|
+
function An(t, e) {
|
|
1552
1557
|
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
1558
|
return Math.max(0, i - n) * Math.max(0, r - o);
|
|
1554
1559
|
}
|
|
1555
|
-
function
|
|
1560
|
+
function dt(t, e) {
|
|
1556
1561
|
return t.minX <= e.minX && t.minY <= e.minY && e.maxX <= t.maxX && e.maxY <= t.maxY;
|
|
1557
1562
|
}
|
|
1558
1563
|
function tt(t, e) {
|
|
@@ -1578,18 +1583,18 @@ function It(t, e, n, o, i) {
|
|
|
1578
1583
|
gn(t, a, e, n, i), r.push(e, a, a, n);
|
|
1579
1584
|
}
|
|
1580
1585
|
}
|
|
1581
|
-
const
|
|
1582
|
-
const n = new
|
|
1586
|
+
const En = (t, e) => {
|
|
1587
|
+
const n = new bn(), o = /* @__PURE__ */ new Map(), i = (d, c) => {
|
|
1583
1588
|
const w = d.selector.flatMap((C) => {
|
|
1584
1589
|
const E = X([C]) ? C.range : Nt(C, e).range;
|
|
1585
1590
|
return Array.from(E.getClientRects());
|
|
1586
|
-
}), L =
|
|
1591
|
+
}), L = re(w).map(({ left: C, top: E, right: T, bottom: g }) => new DOMRect(C - c.left, E - c.top, T - C, g - E));
|
|
1587
1592
|
return L.map((C) => {
|
|
1588
|
-
const { x: E, y: T, width:
|
|
1593
|
+
const { x: E, y: T, width: g, height: A } = C;
|
|
1589
1594
|
return {
|
|
1590
1595
|
minX: E,
|
|
1591
1596
|
minY: T,
|
|
1592
|
-
maxX: E +
|
|
1597
|
+
maxX: E + g,
|
|
1593
1598
|
maxY: T + A,
|
|
1594
1599
|
annotation: {
|
|
1595
1600
|
id: d.annotation,
|
|
@@ -1623,16 +1628,16 @@ const An = (t, e) => {
|
|
|
1623
1628
|
if (w.length > 0)
|
|
1624
1629
|
return w.sort((C, E) => L(C) - L(E)), w[0].annotation.id;
|
|
1625
1630
|
}, m = (d) => {
|
|
1626
|
-
const c =
|
|
1631
|
+
const c = p(d);
|
|
1627
1632
|
if (c.length === 0)
|
|
1628
1633
|
return;
|
|
1629
1634
|
let w = c[0].left, L = c[0].top, C = c[0].right, E = c[0].bottom;
|
|
1630
1635
|
for (let T = 1; T < c.length; T++) {
|
|
1631
|
-
const
|
|
1632
|
-
w = Math.min(w,
|
|
1636
|
+
const g = c[T];
|
|
1637
|
+
w = Math.min(w, g.left), L = Math.min(L, g.top), C = Math.max(C, g.right), E = Math.max(E, g.bottom);
|
|
1633
1638
|
}
|
|
1634
1639
|
return new DOMRect(w, L, C - w, E - L);
|
|
1635
|
-
},
|
|
1640
|
+
}, p = (d) => {
|
|
1636
1641
|
const c = o.get(d);
|
|
1637
1642
|
return c ? c[0].annotation.rects : [];
|
|
1638
1643
|
};
|
|
@@ -1641,12 +1646,12 @@ const An = (t, e) => {
|
|
|
1641
1646
|
clear: a,
|
|
1642
1647
|
getAt: l,
|
|
1643
1648
|
getAnnotationBounds: m,
|
|
1644
|
-
getAnnotationRects:
|
|
1649
|
+
getAnnotationRects: p,
|
|
1645
1650
|
getIntersecting: (d, c, w, L) => {
|
|
1646
|
-
const C = n.search({ minX: d, minY: c, maxX: w, maxY: L }), E = new Set(C.reduce((T,
|
|
1651
|
+
const C = n.search({ minX: d, minY: c, maxX: w, maxY: L }), E = new Set(C.reduce((T, g) => [...T, g.annotation.id], []));
|
|
1647
1652
|
return Array.from(E).map((T) => ({
|
|
1648
1653
|
annotation: t.getAnnotation(T),
|
|
1649
|
-
rects:
|
|
1654
|
+
rects: p(T)
|
|
1650
1655
|
})).filter((T) => !!T.annotation);
|
|
1651
1656
|
},
|
|
1652
1657
|
insert: s,
|
|
@@ -1656,32 +1661,32 @@ const An = (t, e) => {
|
|
|
1656
1661
|
size: () => n.all().length,
|
|
1657
1662
|
update: f
|
|
1658
1663
|
};
|
|
1659
|
-
},
|
|
1660
|
-
const n =
|
|
1661
|
-
const d =
|
|
1664
|
+
}, Sn = (t, e) => {
|
|
1665
|
+
const n = qe(), o = En(n, t), i = Ne(n, e), r = Me(n), a = Qe(), s = (v, h = R.LOCAL) => {
|
|
1666
|
+
const d = ot(v, t), c = X(d.target.selector);
|
|
1662
1667
|
return c && n.addAnnotation(d, h), c;
|
|
1663
1668
|
}, u = (v, h = !0, d = R.LOCAL) => {
|
|
1664
|
-
const c = v.map((L) =>
|
|
1669
|
+
const c = v.map((L) => ot(L, t)), w = c.filter((L) => !X(L.target.selector));
|
|
1665
1670
|
return w.length > 0 ? (console.warn("Could not revive all targets for these annotations:", w), n.bulkAddAnnotation(c, h, d), w) : (n.bulkAddAnnotation(c, h, d), []);
|
|
1666
1671
|
}, f = (v, h = R.LOCAL) => {
|
|
1667
|
-
const d = v.map((w) =>
|
|
1672
|
+
const d = v.map((w) => ot(w, t)), c = d.filter((w) => !X(w.target.selector));
|
|
1668
1673
|
return c.length > 0 && console.warn("Could not revive all targets for these annotations:", c), d.forEach((w) => {
|
|
1669
1674
|
n.getAnnotation(w.id) ? n.updateAnnotation(w, h) : n.addAnnotation(w, h);
|
|
1670
1675
|
}), c;
|
|
1671
1676
|
}, b = (v, h = R.LOCAL) => {
|
|
1672
|
-
const d =
|
|
1677
|
+
const d = nt(v, t);
|
|
1673
1678
|
n.updateTarget(d, h);
|
|
1674
1679
|
}, l = (v, h = R.LOCAL) => {
|
|
1675
|
-
const d = v.map((c) =>
|
|
1680
|
+
const d = v.map((c) => nt(c, t));
|
|
1676
1681
|
n.bulkUpdateTargets(d, h);
|
|
1677
1682
|
}, m = (v, h) => {
|
|
1678
1683
|
const d = o.getAt(v, h);
|
|
1679
1684
|
return d ? n.getAnnotation(d) : void 0;
|
|
1680
|
-
},
|
|
1685
|
+
}, p = (v, h, d, c = 5) => {
|
|
1681
1686
|
const w = o.getAnnotationRects(v);
|
|
1682
1687
|
if (w.length !== 0) {
|
|
1683
1688
|
if (h && d) {
|
|
1684
|
-
const L = w.find(({ top: C, right: E, bottom: T, left:
|
|
1689
|
+
const L = w.find(({ top: C, right: E, bottom: T, left: g }) => h >= g - c && h <= E + c && d >= C - c && d <= T + c);
|
|
1685
1690
|
if (L)
|
|
1686
1691
|
return L;
|
|
1687
1692
|
}
|
|
@@ -1698,7 +1703,7 @@ const An = (t, e) => {
|
|
|
1698
1703
|
bulkAddAnnotation: u,
|
|
1699
1704
|
bulkUpdateTargets: l,
|
|
1700
1705
|
bulkUpsertAnnotations: f,
|
|
1701
|
-
getAnnotationBounds:
|
|
1706
|
+
getAnnotationBounds: p,
|
|
1702
1707
|
getAt: m,
|
|
1703
1708
|
getIntersecting: o.getIntersecting,
|
|
1704
1709
|
recalculatePositions: y,
|
|
@@ -1708,15 +1713,15 @@ const An = (t, e) => {
|
|
|
1708
1713
|
hover: r,
|
|
1709
1714
|
viewport: a
|
|
1710
1715
|
};
|
|
1711
|
-
},
|
|
1716
|
+
}, Cn = () => {
|
|
1712
1717
|
const t = document.createElement("canvas");
|
|
1713
1718
|
t.width = 2 * window.innerWidth, t.height = 2 * window.innerHeight, t.className = "r6o-highlight-layer presence";
|
|
1714
1719
|
const e = t.getContext("2d");
|
|
1715
1720
|
return e.scale(2, 2), e.translate(0.5, 0.5), t;
|
|
1716
|
-
},
|
|
1717
|
-
const o =
|
|
1721
|
+
}, Ln = (t, e, n = {}) => {
|
|
1722
|
+
const o = Cn(), i = o.getContext("2d");
|
|
1718
1723
|
t.appendChild(o);
|
|
1719
|
-
const r = /* @__PURE__ */ new Map(), a = (l) => Array.from(r.entries()).filter(([m,
|
|
1724
|
+
const r = /* @__PURE__ */ new Map(), a = (l) => Array.from(r.entries()).filter(([m, p]) => p.presenceKey === l.presenceKey).map(([m, p]) => m);
|
|
1720
1725
|
return e.on("selectionChange", (l, m) => {
|
|
1721
1726
|
a(l).forEach((y) => r.delete(y)), m && m.forEach((y) => r.set(y, l));
|
|
1722
1727
|
}), {
|
|
@@ -1727,7 +1732,7 @@ const An = (t, e) => {
|
|
|
1727
1732
|
destroy: () => {
|
|
1728
1733
|
o.remove();
|
|
1729
1734
|
},
|
|
1730
|
-
paint: (l, m,
|
|
1735
|
+
paint: (l, m, p) => {
|
|
1731
1736
|
n.font && (i.font = n.font);
|
|
1732
1737
|
const y = r.get(l.annotation.id);
|
|
1733
1738
|
if (y) {
|
|
@@ -1736,7 +1741,7 @@ const An = (t, e) => {
|
|
|
1736
1741
|
const c = i.measureText(y.appearance.label), w = c.width + 6, L = c.actualBoundingBoxAscent + c.actualBoundingBoxDescent + 8, C = c.fontBoundingBoxAscent ? 8 : 6.5;
|
|
1737
1742
|
return i.fillRect(h - 2, d - 2.5 - L, w, L), i.fillStyle = "#fff", i.fillText(y.appearance.label, h + 1, d - C), {
|
|
1738
1743
|
fill: y.appearance.color,
|
|
1739
|
-
fillOpacity:
|
|
1744
|
+
fillOpacity: p ? 0.45 : 0.18
|
|
1740
1745
|
};
|
|
1741
1746
|
}
|
|
1742
1747
|
},
|
|
@@ -1751,9 +1756,9 @@ const An = (t, e) => {
|
|
|
1751
1756
|
return document.scrollingElement;
|
|
1752
1757
|
const { overflowY: e } = window.getComputedStyle(t);
|
|
1753
1758
|
return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : $t(t.parentElement);
|
|
1754
|
-
},
|
|
1759
|
+
}, Tn = (t, e) => (n) => {
|
|
1755
1760
|
const o = (r) => {
|
|
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,
|
|
1761
|
+
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
1762
|
i.scroll({ top: h, left: d, behavior: "smooth" });
|
|
1758
1763
|
}, i = $t(t);
|
|
1759
1764
|
if (i) {
|
|
@@ -1761,16 +1766,16 @@ const An = (t, e) => {
|
|
|
1761
1766
|
if (a && !a.collapsed)
|
|
1762
1767
|
return o(r.target), !0;
|
|
1763
1768
|
{
|
|
1764
|
-
const s =
|
|
1769
|
+
const s = nt(r.target, t), { range: u } = s.selector[0];
|
|
1765
1770
|
if (u && !u.collapsed)
|
|
1766
1771
|
return o(s), !0;
|
|
1767
1772
|
}
|
|
1768
1773
|
}
|
|
1769
1774
|
return !1;
|
|
1770
|
-
},
|
|
1775
|
+
}, Bn = (t, e) => ({
|
|
1771
1776
|
...t,
|
|
1772
1777
|
annotationEnabled: t.annotationEnabled === void 0 ? e.annotationEnabled : t.annotationEnabled
|
|
1773
|
-
}),
|
|
1778
|
+
}), Rn = (t, e, n, o) => {
|
|
1774
1779
|
const { store: i, selection: r } = e;
|
|
1775
1780
|
let a, s;
|
|
1776
1781
|
const u = (h) => a = h;
|
|
@@ -1792,7 +1797,7 @@ const An = (t, e) => {
|
|
|
1792
1797
|
if (h.timeStamp - ((b == null ? void 0 : b.timeStamp) || h.timeStamp) < 1e3 && !s && l(b), d.isCollapsed || !f || !s)
|
|
1793
1798
|
return;
|
|
1794
1799
|
const c = d.getRangeAt(0);
|
|
1795
|
-
if (
|
|
1800
|
+
if (ne(c))
|
|
1796
1801
|
return;
|
|
1797
1802
|
const w = Kt(c.cloneRange());
|
|
1798
1803
|
(w.length !== s.selector.length || w.some((C, E) => {
|
|
@@ -1800,7 +1805,7 @@ const An = (t, e) => {
|
|
|
1800
1805
|
return C.toString() !== ((T = s.selector[E]) == null ? void 0 : T.quote);
|
|
1801
1806
|
})) && (s = {
|
|
1802
1807
|
...s,
|
|
1803
|
-
selector: w.map((C) =>
|
|
1808
|
+
selector: w.map((C) => se(C, t, o))
|
|
1804
1809
|
}, i.getAnnotation(s.annotation) ? i.updateTarget(s, R.LOCAL) : (i.addAnnotation({
|
|
1805
1810
|
id: s.annotation,
|
|
1806
1811
|
bodies: [],
|
|
@@ -1808,11 +1813,11 @@ const An = (t, e) => {
|
|
|
1808
1813
|
}, R.LOCAL), r.clickSelect(s.annotation, b)));
|
|
1809
1814
|
});
|
|
1810
1815
|
n && document.addEventListener("selectionchange", m);
|
|
1811
|
-
const
|
|
1816
|
+
const p = (h) => {
|
|
1812
1817
|
const { target: d, timeStamp: c, offsetX: w, offsetY: L, type: C } = h;
|
|
1813
1818
|
b = { ...h, target: d, timeStamp: c, offsetX: w, offsetY: L, type: C }, f = h.button === 0;
|
|
1814
1819
|
};
|
|
1815
|
-
t.addEventListener("pointerdown",
|
|
1820
|
+
t.addEventListener("pointerdown", p);
|
|
1816
1821
|
const y = (h) => {
|
|
1817
1822
|
var L;
|
|
1818
1823
|
if (!!((L = h.target.parentElement) != null && L.closest(D)) || !f)
|
|
@@ -1820,8 +1825,8 @@ const An = (t, e) => {
|
|
|
1820
1825
|
const c = () => {
|
|
1821
1826
|
const { x: C, y: E } = t.getBoundingClientRect(), T = i.getAt(h.clientX - C, h.clientY - E);
|
|
1822
1827
|
if (T) {
|
|
1823
|
-
const { selected:
|
|
1824
|
-
(
|
|
1828
|
+
const { selected: g } = r;
|
|
1829
|
+
(g.length !== 1 || g[0].id !== T.id) && r.clickSelect(T.id, h);
|
|
1825
1830
|
} else
|
|
1826
1831
|
r.isEmpty() || r.clear();
|
|
1827
1832
|
}, w = h.timeStamp - b.timeStamp;
|
|
@@ -1829,25 +1834,23 @@ const An = (t, e) => {
|
|
|
1829
1834
|
};
|
|
1830
1835
|
return document.addEventListener("pointerup", y), {
|
|
1831
1836
|
destroy: () => {
|
|
1832
|
-
t.removeEventListener("selectstart", l), document.removeEventListener("selectionchange", m), t.removeEventListener("pointerdown",
|
|
1837
|
+
t.removeEventListener("selectstart", l), document.removeEventListener("selectionchange", m), t.removeEventListener("pointerdown", p), document.removeEventListener("pointerup", y);
|
|
1833
1838
|
},
|
|
1834
1839
|
setUser: u
|
|
1835
1840
|
};
|
|
1836
|
-
}, Mt = "SPANS",
|
|
1837
|
-
t
|
|
1838
|
-
|
|
1839
|
-
});
|
|
1840
|
-
const n = Tn(e, {
|
|
1841
|
+
}, Mt = "SPANS", Un = (t, e = {}) => {
|
|
1842
|
+
Qt(t);
|
|
1843
|
+
const n = Bn(e, {
|
|
1841
1844
|
annotationEnabled: !0
|
|
1842
|
-
}), o =
|
|
1843
|
-
let f =
|
|
1844
|
-
const b = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : Mt : n.renderer || Mt, l = b === "SPANS" ?
|
|
1845
|
+
}), o = Sn(t, n.pointerAction), { selection: i, viewport: r } = o, a = o.store, s = Ke(a), u = Je(o, s, n.adapter);
|
|
1846
|
+
let f = an();
|
|
1847
|
+
const b = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : Mt : n.renderer || Mt, l = b === "SPANS" ? Ce(t, o, r) : b === "CSS_HIGHLIGHTS" ? Ae(t, o, r) : b === "CANVAS" ? he(t, o, r) : void 0;
|
|
1845
1848
|
if (!l)
|
|
1846
1849
|
throw `Unknown renderer implementation: ${b}`;
|
|
1847
1850
|
console.debug(`Using ${b} renderer`), n.style && l.setStyle(n.style);
|
|
1848
|
-
const m =
|
|
1851
|
+
const m = Rn(t, o, n.annotationEnabled, n.offsetReferenceSelector);
|
|
1849
1852
|
return m.setUser(f), {
|
|
1850
|
-
...
|
|
1853
|
+
...tn(o, s, n.adapter),
|
|
1851
1854
|
destroy: () => {
|
|
1852
1855
|
l.destroy(), m.destroy(), s.destroy();
|
|
1853
1856
|
},
|
|
@@ -1862,47 +1865,48 @@ const An = (t, e) => {
|
|
|
1862
1865
|
E ? i.setSelected(E) : i.clear();
|
|
1863
1866
|
},
|
|
1864
1867
|
setPresenceProvider: (E) => {
|
|
1865
|
-
E && (l.setPainter(
|
|
1868
|
+
E && (l.setPainter(Ln(t, E, n.presence)), E.on("selectionChange", () => l.redraw()));
|
|
1866
1869
|
},
|
|
1867
1870
|
setVisible: (E) => l.setVisible(E),
|
|
1868
1871
|
on: u.on,
|
|
1869
1872
|
off: u.off,
|
|
1870
|
-
scrollIntoView:
|
|
1873
|
+
scrollIntoView: Tn(t, a),
|
|
1871
1874
|
state: o
|
|
1872
1875
|
};
|
|
1873
1876
|
};
|
|
1874
1877
|
export {
|
|
1875
|
-
|
|
1878
|
+
et as DEFAULT_SELECTED_STYLE,
|
|
1876
1879
|
$ as DEFAULT_STYLE,
|
|
1877
1880
|
Ot as NOT_ANNOTATABLE_CLASS,
|
|
1878
1881
|
D as NOT_ANNOTATABLE_SELECTOR,
|
|
1879
1882
|
R as Origin,
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1883
|
+
Oe as PointerSelectAction,
|
|
1884
|
+
Nn as W3CTextFormat,
|
|
1885
|
+
Qt as cancelSingleClickEvents,
|
|
1886
|
+
On as createBody,
|
|
1887
|
+
he as createCanvasRenderer,
|
|
1888
|
+
Ae as createHighlightsRenderer,
|
|
1889
|
+
xe as createRenderer,
|
|
1890
|
+
Ce as createSpansRenderer,
|
|
1891
|
+
Un as createTextAnnotator,
|
|
1892
|
+
Sn as createTextAnnotatorState,
|
|
1889
1893
|
ft as debounce,
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1894
|
+
Bn as fillDefaults,
|
|
1895
|
+
In as getAnnotatableFragment,
|
|
1896
|
+
Mn as getClientRectsPonyfill,
|
|
1897
|
+
te as getQuoteContext,
|
|
1898
|
+
ut as getRangeAnnotatableContents,
|
|
1895
1899
|
X as isRevived,
|
|
1896
|
-
|
|
1897
|
-
|
|
1900
|
+
ne as isWhitespaceOrEmpty,
|
|
1901
|
+
re as mergeClientRects,
|
|
1898
1902
|
qt as paint,
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1903
|
+
fn as parseW3CTextAnnotation,
|
|
1904
|
+
se as rangeToSelector,
|
|
1905
|
+
ot as reviveAnnotation,
|
|
1902
1906
|
Nt as reviveSelector,
|
|
1903
|
-
|
|
1904
|
-
|
|
1907
|
+
nt as reviveTarget,
|
|
1908
|
+
pn as serializeW3CTextAnnotation,
|
|
1905
1909
|
Kt as splitAnnotatableRanges,
|
|
1906
|
-
|
|
1910
|
+
ee as whitespaceOrEmptyRegex
|
|
1907
1911
|
};
|
|
1908
1912
|
//# sourceMappingURL=text-annotator.es.js.map
|