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