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