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