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