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