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