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