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