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