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