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