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