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