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