@recogito/text-annotator 3.0.0-rc.45 → 3.0.0-rc.46
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 +2 -1
- package/dist/src/TextAnnotator.d.ts +3 -3
- package/dist/src/TextAnnotatorOptions.d.ts +1 -1
- package/dist/src/highlight/baseRenderer.d.ts +1 -1
- package/dist/src/highlight/canvas/canvasRenderer.d.ts +2 -1
- package/dist/src/highlight/highlights/highlightsRenderer.d.ts +2 -1
- package/dist/src/highlight/span/spansRenderer.d.ts +2 -1
- package/dist/src/state/TextAnnotatorState.d.ts +5 -5
- package/dist/text-annotator.es.js +727 -727
- 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 +7 -7
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const _t = "not-annotatable", X = `.${_t}`, Qt = (t) => {
|
|
2
2
|
var n;
|
|
3
3
|
const e = t.commonAncestorContainer;
|
|
4
4
|
return e instanceof HTMLElement ? !e.closest(X) : !((n = e.parentElement) != null && n.closest(X));
|
|
@@ -6,7 +6,7 @@ const kt = "not-annotatable", X = `.${kt}`, Qt = (t) => {
|
|
|
6
6
|
const e = document.createNodeIterator(
|
|
7
7
|
t.commonAncestorContainer,
|
|
8
8
|
NodeFilter.SHOW_ELEMENT,
|
|
9
|
-
(o) => o instanceof HTMLElement && o.classList.contains(
|
|
9
|
+
(o) => o instanceof HTMLElement && o.classList.contains(_t) && !o.parentElement.closest(X) && t.intersectsNode(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
|
|
10
10
|
);
|
|
11
11
|
let n;
|
|
12
12
|
for (; n = e.nextNode(); )
|
|
@@ -41,17 +41,17 @@ const kt = "not-annotatable", X = `.${kt}`, Qt = (t) => {
|
|
|
41
41
|
const e = t.cloneContents();
|
|
42
42
|
return e.querySelectorAll(X).forEach((n) => n.remove()), e;
|
|
43
43
|
}, ee = (t, e, n = 10, o) => {
|
|
44
|
-
const i = o ? t.startContainer.parentElement.closest(o) : e,
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
const d = bt(
|
|
44
|
+
const i = o ? t.startContainer.parentElement.closest(o) : e, s = document.createRange();
|
|
45
|
+
s.setStart(i, 0), s.setEnd(t.startContainer, t.startOffset);
|
|
46
|
+
const r = bt(s).textContent, c = document.createRange();
|
|
47
|
+
c.setStart(t.endContainer, t.endOffset), i === document.body ? c.setEnd(i, i.childNodes.length) : c.setEndAfter(i);
|
|
48
|
+
const d = bt(c).textContent;
|
|
49
49
|
return {
|
|
50
|
-
prefix:
|
|
50
|
+
prefix: r.substring(r.length - n),
|
|
51
51
|
suffix: d.substring(0, n)
|
|
52
52
|
};
|
|
53
53
|
}, ne = /^\s*$/, oe = (t) => ne.test(t.toString()), H = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), ie = (t, e) => {
|
|
54
|
-
const n = (
|
|
54
|
+
const n = (s) => Math.round(s * 10) / 10, o = {
|
|
55
55
|
top: n(t.top),
|
|
56
56
|
bottom: n(t.bottom),
|
|
57
57
|
left: n(t.left),
|
|
@@ -74,26 +74,26 @@ const kt = "not-annotatable", X = `.${kt}`, Qt = (t) => {
|
|
|
74
74
|
return "block-contains";
|
|
75
75
|
} else if (o.top >= i.top && o.bottom <= i.bottom && o.left >= i.left && o.right <= i.right)
|
|
76
76
|
return "block-is-contained";
|
|
77
|
-
},
|
|
78
|
-
const n = Math.min(t.left, e.left), o = Math.max(t.right, e.right), i = Math.min(t.top, e.top),
|
|
79
|
-
return new DOMRect(n, i, o - n,
|
|
80
|
-
},
|
|
77
|
+
}, se = (t, e) => {
|
|
78
|
+
const n = Math.min(t.left, e.left), o = Math.max(t.right, e.right), i = Math.min(t.top, e.top), s = Math.max(t.bottom, e.bottom);
|
|
79
|
+
return new DOMRect(n, i, o - n, s - i);
|
|
80
|
+
}, re = (t) => t.reduce((e, n) => {
|
|
81
81
|
if (n.width === 0 || n.height === 0)
|
|
82
82
|
return e;
|
|
83
83
|
let o = [...e], i = !1;
|
|
84
|
-
for (const
|
|
85
|
-
const
|
|
86
|
-
if (
|
|
87
|
-
o = o.map((
|
|
84
|
+
for (const s of e) {
|
|
85
|
+
const r = ie(n, s);
|
|
86
|
+
if (r === "inline-adjacent") {
|
|
87
|
+
o = o.map((c) => c === s ? se(n, s) : c), i = !0;
|
|
88
88
|
break;
|
|
89
|
-
} else if (
|
|
90
|
-
o = o.map((
|
|
89
|
+
} else if (r === "inline-contains") {
|
|
90
|
+
o = o.map((c) => c === s ? n : c), i = !0;
|
|
91
91
|
break;
|
|
92
|
-
} else if (
|
|
92
|
+
} else if (r === "inline-is-contained") {
|
|
93
93
|
i = !0;
|
|
94
94
|
break;
|
|
95
|
-
} else if (
|
|
96
|
-
n.width <
|
|
95
|
+
} else if (r === "block-contains" || r === "block-is-contained") {
|
|
96
|
+
n.width < s.width && (o = o.map((c) => c === s ? n : c)), i = !0;
|
|
97
97
|
break;
|
|
98
98
|
}
|
|
99
99
|
}
|
|
@@ -101,50 +101,50 @@ const kt = "not-annotatable", X = `.${kt}`, Qt = (t) => {
|
|
|
101
101
|
}, []), ae = (t, e, n) => {
|
|
102
102
|
const o = document.createRange(), i = n ? t.startContainer.parentElement.closest(n) : e;
|
|
103
103
|
o.setStart(i, 0), o.setEnd(t.startContainer, t.startOffset);
|
|
104
|
-
const
|
|
105
|
-
return n ? { quote:
|
|
106
|
-
},
|
|
107
|
-
var
|
|
108
|
-
const { start: n, end: o } = t, i = t.offsetReference || e,
|
|
104
|
+
const s = bt(o).textContent, r = t.toString(), c = s.length || 0, d = c + r.length;
|
|
105
|
+
return n ? { quote: r, start: c, end: d, range: t, offsetReference: i } : { quote: r, start: c, end: d, range: t };
|
|
106
|
+
}, kt = (t, e) => {
|
|
107
|
+
var f, h;
|
|
108
|
+
const { start: n, end: o } = t, i = t.offsetReference || e, s = document.createNodeIterator(
|
|
109
109
|
e,
|
|
110
110
|
NodeFilter.SHOW_TEXT,
|
|
111
|
-
(
|
|
112
|
-
var
|
|
113
|
-
return (
|
|
111
|
+
(y) => {
|
|
112
|
+
var g;
|
|
113
|
+
return (g = y.parentElement) != null && g.closest(X) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
|
|
114
114
|
}
|
|
115
115
|
);
|
|
116
|
-
let
|
|
117
|
-
const
|
|
118
|
-
let d =
|
|
116
|
+
let r = 0;
|
|
117
|
+
const c = document.createRange();
|
|
118
|
+
let d = s.nextNode();
|
|
119
119
|
d === null && console.error("Could not revive annotation target. Content missing.");
|
|
120
120
|
let u = !i;
|
|
121
121
|
for (; d !== null; ) {
|
|
122
122
|
if (u || (u = i == null ? void 0 : i.contains(d)), u) {
|
|
123
|
-
const
|
|
124
|
-
if (
|
|
125
|
-
|
|
123
|
+
const y = ((f = d.textContent) == null ? void 0 : f.length) || 0;
|
|
124
|
+
if (r + y > n) {
|
|
125
|
+
c.setStart(d, n - r);
|
|
126
126
|
break;
|
|
127
127
|
}
|
|
128
|
-
|
|
128
|
+
r += y;
|
|
129
129
|
}
|
|
130
|
-
d =
|
|
130
|
+
d = s.nextNode();
|
|
131
131
|
}
|
|
132
132
|
for (; d !== null; ) {
|
|
133
|
-
const
|
|
134
|
-
if (
|
|
135
|
-
|
|
133
|
+
const y = ((h = d.textContent) == null ? void 0 : h.length) || 0;
|
|
134
|
+
if (r + y >= o) {
|
|
135
|
+
c.setEnd(d, o - r);
|
|
136
136
|
break;
|
|
137
137
|
}
|
|
138
|
-
|
|
138
|
+
r += y, d = s.nextNode();
|
|
139
139
|
}
|
|
140
140
|
return {
|
|
141
141
|
...t,
|
|
142
|
-
range:
|
|
142
|
+
range: c
|
|
143
143
|
};
|
|
144
144
|
}, it = (t, e) => H(t.selector) ? t : {
|
|
145
145
|
...t,
|
|
146
|
-
selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n :
|
|
147
|
-
},
|
|
146
|
+
selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : kt(n, e))
|
|
147
|
+
}, rt = (t, e) => H(t.target.selector) ? t : { ...t, target: it(t.target, e) }, ce = (t, e) => {
|
|
148
148
|
const n = t.cloneRange();
|
|
149
149
|
return e.contains(n.startContainer) || n.setStart(e, 0), e.contains(n.endContainer) || n.setEnd(e, e.childNodes.length), n;
|
|
150
150
|
}, Yt = (t) => {
|
|
@@ -153,16 +153,16 @@ const kt = "not-annotatable", X = `.${kt}`, Qt = (t) => {
|
|
|
153
153
|
const { overflowY: e } = window.getComputedStyle(t);
|
|
154
154
|
return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : Yt(t.parentElement);
|
|
155
155
|
}, le = (t, e) => (n) => {
|
|
156
|
-
const o = typeof n == "string" ? n : n.id, i = (
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
},
|
|
160
|
-
if (
|
|
161
|
-
const
|
|
162
|
-
if (
|
|
163
|
-
return i(
|
|
156
|
+
const o = typeof n == "string" ? n : n.id, i = (r) => {
|
|
157
|
+
const c = s.getBoundingClientRect(), d = s.clientHeight, u = s.clientWidth, f = r.selector[0].range.getBoundingClientRect(), { width: h, height: y } = e.getAnnotationBounds(o), g = f.top - c.top, x = f.left - c.left, v = s.parentElement ? s.scrollTop : 0, p = s.parentElement ? s.scrollLeft : 0, l = g + v - (d - y) / 2, a = x + p - (u - h) / 2;
|
|
158
|
+
s.scroll({ top: l, left: a, behavior: "smooth" });
|
|
159
|
+
}, s = Yt(t);
|
|
160
|
+
if (s) {
|
|
161
|
+
const r = e.getAnnotation(o), { range: c } = r.target.selector[0];
|
|
162
|
+
if (c && !c.collapsed)
|
|
163
|
+
return i(r.target), !0;
|
|
164
164
|
{
|
|
165
|
-
const d = it(
|
|
165
|
+
const d = it(r.target, t), { range: u } = d.selector[0];
|
|
166
166
|
if (u && !u.collapsed)
|
|
167
167
|
return i(d), !0;
|
|
168
168
|
}
|
|
@@ -171,64 +171,64 @@ const kt = "not-annotatable", X = `.${kt}`, Qt = (t) => {
|
|
|
171
171
|
}, P = {
|
|
172
172
|
fill: "rgb(0, 128, 255)",
|
|
173
173
|
fillOpacity: 0.18
|
|
174
|
-
},
|
|
174
|
+
}, st = {
|
|
175
175
|
fill: "rgb(0, 128, 255)",
|
|
176
176
|
fillOpacity: 0.45
|
|
177
177
|
}, de = (t, e, n, o, i) => {
|
|
178
|
-
var
|
|
179
|
-
const
|
|
180
|
-
return o && o.paint(t, e) ||
|
|
178
|
+
var r, c;
|
|
179
|
+
const s = n ? typeof n == "function" ? n(t.annotation, t.state, i) || ((r = t.state) != null && r.selected ? st : P) : n : (c = t.state) != null && c.selected ? st : P;
|
|
180
|
+
return o && o.paint(t, e) || s;
|
|
181
181
|
}, ue = (t) => {
|
|
182
|
-
const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: o, innerHeight: i } = window,
|
|
183
|
-
return { top: e, left: n, minX:
|
|
182
|
+
const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: o, innerHeight: i } = window, s = -n, r = -e, c = o - n, d = i - e;
|
|
183
|
+
return { top: e, left: n, minX: s, minY: r, maxX: c, maxY: d };
|
|
184
184
|
}, he = (t) => {
|
|
185
185
|
let e = /* @__PURE__ */ new Set();
|
|
186
186
|
return (o) => {
|
|
187
|
-
const i = o.map((
|
|
188
|
-
(e.size !== i.length || i.some((
|
|
187
|
+
const i = o.map((s) => s.id);
|
|
188
|
+
(e.size !== i.length || i.some((s) => !e.has(s))) && t.set(i), e = new Set(i);
|
|
189
189
|
};
|
|
190
190
|
}, wt = (t, e, n, o) => {
|
|
191
|
-
const { store: i, selection:
|
|
192
|
-
let
|
|
193
|
-
const
|
|
194
|
-
const { x: I, y:
|
|
195
|
-
A ?
|
|
191
|
+
const { store: i, selection: s, hover: r } = e;
|
|
192
|
+
let c, d, u;
|
|
193
|
+
const f = he(n), h = (R) => {
|
|
194
|
+
const { x: I, y: b } = t.getBoundingClientRect(), A = i.getAt(R.clientX - I, R.clientY - b, d);
|
|
195
|
+
A ? r.current !== A.id && (t.classList.add("hovered"), r.set(A.id)) : r.current && (t.classList.remove("hovered"), r.set(null));
|
|
196
196
|
};
|
|
197
197
|
t.addEventListener("pointermove", h);
|
|
198
|
-
const
|
|
198
|
+
const y = (R = !1) => {
|
|
199
199
|
u && u.clear();
|
|
200
|
-
const I = ue(t), { minX:
|
|
201
|
-
const Gt = B.includes(
|
|
202
|
-
return { annotation:
|
|
200
|
+
const I = ue(t), { minX: b, minY: A, maxX: w, maxY: C } = I, O = d ? i.getIntersecting(b, A, w, C).filter(({ annotation: _ }) => d(_)) : i.getIntersecting(b, A, w, C), B = s.selected.map(({ id: _ }) => _), D = O.map(({ annotation: _, rects: qt }) => {
|
|
201
|
+
const Gt = B.includes(_.id), Kt = _.id === r.current;
|
|
202
|
+
return { annotation: _, rects: qt, state: { selected: Gt, hover: Kt } };
|
|
203
203
|
});
|
|
204
|
-
o.redraw(D, I,
|
|
205
|
-
},
|
|
206
|
-
u = R,
|
|
207
|
-
},
|
|
208
|
-
|
|
209
|
-
},
|
|
210
|
-
d = R,
|
|
211
|
-
},
|
|
212
|
-
i.observe(
|
|
213
|
-
const l =
|
|
214
|
-
document.addEventListener("scroll",
|
|
215
|
-
const
|
|
216
|
-
i.recalculatePositions(), u && u.reset(),
|
|
204
|
+
o.redraw(D, I, c, u, R), setTimeout(() => f(O.map(({ annotation: _ }) => _)), 1);
|
|
205
|
+
}, g = (R) => {
|
|
206
|
+
u = R, y();
|
|
207
|
+
}, x = (R) => {
|
|
208
|
+
c = R, y();
|
|
209
|
+
}, v = (R) => {
|
|
210
|
+
d = R, y(!1);
|
|
211
|
+
}, p = () => y();
|
|
212
|
+
i.observe(p);
|
|
213
|
+
const l = s.subscribe(() => y()), a = () => y(!0);
|
|
214
|
+
document.addEventListener("scroll", a, { capture: !0, passive: !0 });
|
|
215
|
+
const m = yt(() => {
|
|
216
|
+
i.recalculatePositions(), u && u.reset(), y();
|
|
217
217
|
});
|
|
218
|
-
window.addEventListener("resize",
|
|
219
|
-
const
|
|
220
|
-
|
|
218
|
+
window.addEventListener("resize", m);
|
|
219
|
+
const S = new ResizeObserver(m);
|
|
220
|
+
S.observe(t);
|
|
221
221
|
const L = { attributes: !0, childList: !0, subtree: !0 }, E = new MutationObserver((R) => {
|
|
222
|
-
R.every((
|
|
222
|
+
R.every((b) => b.target === t || t.contains(b.target)) || y(!0);
|
|
223
223
|
});
|
|
224
224
|
return E.observe(document.body, L), {
|
|
225
225
|
destroy: () => {
|
|
226
|
-
t.removeEventListener("pointermove", h), o.destroy(), i.unobserve(
|
|
226
|
+
t.removeEventListener("pointermove", h), o.destroy(), i.unobserve(p), l(), document.removeEventListener("scroll", a), window.removeEventListener("resize", m), S.disconnect(), E.disconnect();
|
|
227
227
|
},
|
|
228
|
-
redraw:
|
|
229
|
-
setStyle:
|
|
230
|
-
setFilter:
|
|
231
|
-
setPainter:
|
|
228
|
+
redraw: y,
|
|
229
|
+
setStyle: x,
|
|
230
|
+
setFilter: v,
|
|
231
|
+
setPainter: g,
|
|
232
232
|
setVisible: o.setVisible
|
|
233
233
|
};
|
|
234
234
|
}, fe = () => {
|
|
@@ -240,27 +240,27 @@ const kt = "not-annotatable", X = `.${kt}`, Qt = (t) => {
|
|
|
240
240
|
t.classList.add("r6o-annotatable");
|
|
241
241
|
const e = fe(), n = e.getContext("2d");
|
|
242
242
|
document.body.appendChild(e);
|
|
243
|
-
const o = (
|
|
244
|
-
const { width: h, height:
|
|
245
|
-
n.clearRect(-0.5, -0.5, h + 1,
|
|
246
|
-
const { top:
|
|
247
|
-
[...
|
|
248
|
-
const { annotation: { target: { created:
|
|
249
|
-
return
|
|
250
|
-
}).forEach((
|
|
251
|
-
var
|
|
252
|
-
const l = u ? typeof u == "function" ? u(
|
|
253
|
-
x: L +
|
|
254
|
-
y: E +
|
|
243
|
+
const o = (c, d, u, f) => requestAnimationFrame(() => {
|
|
244
|
+
const { width: h, height: y } = e;
|
|
245
|
+
n.clearRect(-0.5, -0.5, h + 1, y + 1), f && f.clear();
|
|
246
|
+
const { top: g, left: x } = d;
|
|
247
|
+
[...c].sort((p, l) => {
|
|
248
|
+
const { annotation: { target: { created: a } } } = p, { annotation: { target: { created: m } } } = l;
|
|
249
|
+
return a.getTime() - m.getTime();
|
|
250
|
+
}).forEach((p) => {
|
|
251
|
+
var S;
|
|
252
|
+
const l = u ? typeof u == "function" ? u(p.annotation, p.state) : u : (S = p.state) != null && S.selected ? st : P, a = f && f.paint(p, d) || l, m = p.rects.map(({ x: L, y: E, width: T, height: R }) => ({
|
|
253
|
+
x: L + x,
|
|
254
|
+
y: E + g,
|
|
255
255
|
width: T,
|
|
256
256
|
height: R
|
|
257
257
|
}));
|
|
258
|
-
if (n.fillStyle =
|
|
258
|
+
if (n.fillStyle = a.fill, n.globalAlpha = a.fillOpacity || 1, m.forEach(
|
|
259
259
|
({ x: L, y: E, width: T, height: R }) => n.fillRect(L, E, T, R)
|
|
260
|
-
),
|
|
261
|
-
n.globalAlpha = 1, n.strokeStyle =
|
|
262
|
-
const L =
|
|
263
|
-
|
|
260
|
+
), a.underlineColor) {
|
|
261
|
+
n.globalAlpha = 1, n.strokeStyle = a.underlineColor, n.lineWidth = a.underlineThickness ?? 1;
|
|
262
|
+
const L = a.underlineOffset ?? 0;
|
|
263
|
+
m.forEach(({ x: E, y: T, width: R, height: I }) => {
|
|
264
264
|
n.beginPath(), n.moveTo(E, T + I + L), n.lineTo(E + R, T + I + L), n.stroke();
|
|
265
265
|
});
|
|
266
266
|
}
|
|
@@ -272,7 +272,7 @@ const kt = "not-annotatable", X = `.${kt}`, Qt = (t) => {
|
|
|
272
272
|
destroy: () => {
|
|
273
273
|
e.remove(), window.removeEventListener("resize", i);
|
|
274
274
|
},
|
|
275
|
-
setVisible: (
|
|
275
|
+
setVisible: (c) => {
|
|
276
276
|
console.log("setVisible not implemented on Canvas renderer");
|
|
277
277
|
},
|
|
278
278
|
redraw: o
|
|
@@ -282,27 +282,27 @@ var be = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, $ = function(t) {
|
|
|
282
282
|
return typeof t == "string" ? t.length > 0 : typeof t == "number";
|
|
283
283
|
}, N = function(t, e, n) {
|
|
284
284
|
return e === void 0 && (e = 0), n === void 0 && (n = Math.pow(10, e)), Math.round(n * t) / n + 0;
|
|
285
|
-
},
|
|
285
|
+
}, k = function(t, e, n) {
|
|
286
286
|
return e === void 0 && (e = 0), n === void 0 && (n = 1), t > n ? n : t > e ? t : e;
|
|
287
287
|
}, Xt = function(t) {
|
|
288
288
|
return (t = isFinite(t) ? t % 360 : 0) > 0 ? t : t + 360;
|
|
289
289
|
}, xt = function(t) {
|
|
290
|
-
return { r:
|
|
290
|
+
return { r: k(t.r, 0, 255), g: k(t.g, 0, 255), b: k(t.b, 0, 255), a: k(t.a) };
|
|
291
291
|
}, at = function(t) {
|
|
292
292
|
return { r: N(t.r), g: N(t.g), b: N(t.b), a: N(t.a, 3) };
|
|
293
293
|
}, ve = /^#([0-9a-f]{3,8})$/i, J = function(t) {
|
|
294
294
|
var e = t.toString(16);
|
|
295
295
|
return e.length < 2 ? "0" + e : e;
|
|
296
296
|
}, $t = function(t) {
|
|
297
|
-
var e = t.r, n = t.g, o = t.b, i = t.a,
|
|
298
|
-
return { h: 60 * (
|
|
297
|
+
var e = t.r, n = t.g, o = t.b, i = t.a, s = Math.max(e, n, o), r = s - Math.min(e, n, o), c = r ? s === e ? (n - o) / r : s === n ? 2 + (o - e) / r : 4 + (e - n) / r : 0;
|
|
298
|
+
return { h: 60 * (c < 0 ? c + 6 : c), s: s ? r / s * 100 : 0, v: s / 255 * 100, a: i };
|
|
299
299
|
}, Ht = function(t) {
|
|
300
300
|
var e = t.h, n = t.s, o = t.v, i = t.a;
|
|
301
301
|
e = e / 360 * 6, n /= 100, o /= 100;
|
|
302
|
-
var
|
|
303
|
-
return { r: 255 * [o,
|
|
302
|
+
var s = Math.floor(e), r = o * (1 - n), c = o * (1 - (e - s) * n), d = o * (1 - (1 - e + s) * n), u = s % 6;
|
|
303
|
+
return { r: 255 * [o, c, r, r, d, o][u], g: 255 * [d, o, o, c, r, r][u], b: 255 * [r, r, d, o, o, c][u], a: i };
|
|
304
304
|
}, St = function(t) {
|
|
305
|
-
return { h: Xt(t.h), s:
|
|
305
|
+
return { h: Xt(t.h), s: k(t.s, 0, 100), l: k(t.l, 0, 100), a: k(t.a) };
|
|
306
306
|
}, Et = function(t) {
|
|
307
307
|
return { h: N(t.h), s: N(t.s), l: N(t.l), a: N(t.a, 3) };
|
|
308
308
|
}, Ct = function(t) {
|
|
@@ -323,20 +323,20 @@ var be = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, $ = function(t) {
|
|
|
323
323
|
var n, o, i = St({ h: (n = e[1], o = e[2], o === void 0 && (o = "deg"), Number(n) * (be[o] || 1)), s: Number(e[3]), l: Number(e[4]), a: e[5] === void 0 ? 1 : Number(e[5]) / (e[6] ? 100 : 1) });
|
|
324
324
|
return Ct(i);
|
|
325
325
|
}, "hsl"]], object: [[function(t) {
|
|
326
|
-
var e = t.r, n = t.g, o = t.b, i = t.a,
|
|
327
|
-
return $(e) && $(n) && $(o) ? xt({ r: Number(e), g: Number(n), b: Number(o), a: Number(
|
|
326
|
+
var e = t.r, n = t.g, o = t.b, i = t.a, s = i === void 0 ? 1 : i;
|
|
327
|
+
return $(e) && $(n) && $(o) ? xt({ r: Number(e), g: Number(n), b: Number(o), a: Number(s) }) : null;
|
|
328
328
|
}, "rgb"], [function(t) {
|
|
329
|
-
var e = t.h, n = t.s, o = t.l, i = t.a,
|
|
329
|
+
var e = t.h, n = t.s, o = t.l, i = t.a, s = i === void 0 ? 1 : i;
|
|
330
330
|
if (!$(e) || !$(n) || !$(o)) return null;
|
|
331
|
-
var
|
|
332
|
-
return Ct(
|
|
331
|
+
var r = St({ h: Number(e), s: Number(n), l: Number(o), a: Number(s) });
|
|
332
|
+
return Ct(r);
|
|
333
333
|
}, "hsl"], [function(t) {
|
|
334
|
-
var e = t.h, n = t.s, o = t.v, i = t.a,
|
|
334
|
+
var e = t.h, n = t.s, o = t.v, i = t.a, s = i === void 0 ? 1 : i;
|
|
335
335
|
if (!$(e) || !$(n) || !$(o)) return null;
|
|
336
|
-
var
|
|
337
|
-
return { h: Xt(
|
|
338
|
-
}({ h: Number(e), s: Number(n), v: Number(o), a: Number(
|
|
339
|
-
return Ht(
|
|
336
|
+
var r = function(c) {
|
|
337
|
+
return { h: Xt(c.h), s: k(c.s, 0, 100), v: k(c.v, 0, 100), a: k(c.a) };
|
|
338
|
+
}({ h: Number(e), s: Number(n), v: Number(o), a: Number(s) });
|
|
339
|
+
return Ht(r);
|
|
340
340
|
}, "hsv"]] }, Tt = function(t, e) {
|
|
341
341
|
for (var n = 0; n < e.length; n++) {
|
|
342
342
|
var o = e[n][0](t);
|
|
@@ -347,12 +347,12 @@ var be = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, $ = function(t) {
|
|
|
347
347
|
return typeof t == "string" ? Tt(t.trim(), Lt.string) : typeof t == "object" && t !== null ? Tt(t, Lt.object) : [null, void 0];
|
|
348
348
|
}, ct = function(t, e) {
|
|
349
349
|
var n = Q(t);
|
|
350
|
-
return { h: n.h, s:
|
|
350
|
+
return { h: n.h, s: k(n.s + 100 * e, 0, 100), l: n.l, a: n.a };
|
|
351
351
|
}, lt = function(t) {
|
|
352
352
|
return (299 * t.r + 587 * t.g + 114 * t.b) / 1e3 / 255;
|
|
353
353
|
}, Rt = function(t, e) {
|
|
354
354
|
var n = Q(t);
|
|
355
|
-
return { h: n.h, s: n.s, l:
|
|
355
|
+
return { h: n.h, s: n.s, l: k(n.l + 100 * e, 0, 100), a: n.a };
|
|
356
356
|
}, Bt = function() {
|
|
357
357
|
function t(e) {
|
|
358
358
|
this.parsed = Se(e)[0], this.rgba = this.parsed || { r: 0, g: 0, b: 0, a: 1 };
|
|
@@ -366,18 +366,18 @@ var be = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, $ = function(t) {
|
|
|
366
366
|
}, t.prototype.isLight = function() {
|
|
367
367
|
return lt(this.rgba) >= 0.5;
|
|
368
368
|
}, t.prototype.toHex = function() {
|
|
369
|
-
return e = at(this.rgba), n = e.r, o = e.g, i = e.b,
|
|
370
|
-
var e, n, o, i,
|
|
369
|
+
return e = at(this.rgba), n = e.r, o = e.g, i = e.b, r = (s = e.a) < 1 ? J(N(255 * s)) : "", "#" + J(n) + J(o) + J(i) + r;
|
|
370
|
+
var e, n, o, i, s, r;
|
|
371
371
|
}, t.prototype.toRgb = function() {
|
|
372
372
|
return at(this.rgba);
|
|
373
373
|
}, t.prototype.toRgbString = function() {
|
|
374
|
-
return e = at(this.rgba), n = e.r, o = e.g, i = e.b, (
|
|
375
|
-
var e, n, o, i,
|
|
374
|
+
return e = at(this.rgba), n = e.r, o = e.g, i = e.b, (s = e.a) < 1 ? "rgba(" + n + ", " + o + ", " + i + ", " + s + ")" : "rgb(" + n + ", " + o + ", " + i + ")";
|
|
375
|
+
var e, n, o, i, s;
|
|
376
376
|
}, t.prototype.toHsl = function() {
|
|
377
377
|
return Et(Q(this.rgba));
|
|
378
378
|
}, t.prototype.toHslString = function() {
|
|
379
|
-
return e = Et(Q(this.rgba)), n = e.h, o = e.s, i = e.l, (
|
|
380
|
-
var e, n, o, i,
|
|
379
|
+
return e = Et(Q(this.rgba)), n = e.h, o = e.s, i = e.l, (s = e.a) < 1 ? "hsla(" + n + ", " + o + "%, " + i + "%, " + s + ")" : "hsl(" + n + ", " + o + "%, " + i + "%)";
|
|
380
|
+
var e, n, o, i, s;
|
|
381
381
|
}, t.prototype.toHsv = function() {
|
|
382
382
|
return e = $t(this.rgba), { h: N(e.h), s: N(e.s), v: N(e.v), a: N(e.a, 3) };
|
|
383
383
|
var e;
|
|
@@ -422,22 +422,22 @@ const Ee = (t) => [
|
|
|
422
422
|
destroy: () => {
|
|
423
423
|
CSS.highlights.clear(), t.remove();
|
|
424
424
|
},
|
|
425
|
-
setVisible: (
|
|
425
|
+
setVisible: (s) => {
|
|
426
426
|
console.log("setVisible not implemented on CSS Custom Highlights renderer");
|
|
427
427
|
},
|
|
428
|
-
redraw: (r, c,
|
|
428
|
+
redraw: (s, r, c, d) => {
|
|
429
429
|
d && d.clear();
|
|
430
|
-
const u = new Set(
|
|
430
|
+
const u = new Set(s.map((h) => h.annotation.id));
|
|
431
431
|
Array.from(e).filter((h) => !u.has(h));
|
|
432
|
-
const
|
|
433
|
-
var
|
|
434
|
-
const
|
|
435
|
-
return `::highlight(_${h.annotation.id}) { ${Ee(
|
|
432
|
+
const f = s.map((h) => {
|
|
433
|
+
var x;
|
|
434
|
+
const y = c ? typeof c == "function" ? c(h.annotation, h.state) : c : (x = h.state) != null && x.selected ? st : P, g = d && d.paint(h, r) || y;
|
|
435
|
+
return `::highlight(_${h.annotation.id}) { ${Ee(g)} }`;
|
|
436
436
|
});
|
|
437
|
-
t.innerHTML =
|
|
438
|
-
`), CSS.highlights.clear(),
|
|
439
|
-
const
|
|
440
|
-
CSS.highlights.set(`_${h.id}`,
|
|
437
|
+
t.innerHTML = f.join(`
|
|
438
|
+
`), CSS.highlights.clear(), s.forEach(({ annotation: h }) => {
|
|
439
|
+
const y = h.target.selector.map((x) => x.range), g = new Highlight(...y);
|
|
440
|
+
CSS.highlights.set(`_${h.id}`, g);
|
|
441
441
|
}), e = u;
|
|
442
442
|
}
|
|
443
443
|
};
|
|
@@ -464,8 +464,8 @@ function vt(t, e) {
|
|
|
464
464
|
return t !== t && e !== e;
|
|
465
465
|
}
|
|
466
466
|
const Te = (t, e) => {
|
|
467
|
-
const n = (
|
|
468
|
-
return i.sort((
|
|
467
|
+
const n = (s, r) => s.x <= r.x + r.width && s.x + s.width >= r.x && s.y <= r.y + r.height && s.y + s.height >= r.y, o = (s) => s.rects.reduce((r, c) => r + c.width, 0), i = e.filter(({ rects: s }) => s.some((r) => n(t, r)));
|
|
468
|
+
return i.sort((s, r) => o(r) - o(s)), i.findIndex((s) => s.rects.includes(t));
|
|
469
469
|
}, Re = (t) => {
|
|
470
470
|
t.classList.add("r6o-annotatable");
|
|
471
471
|
const e = document.createElement("div");
|
|
@@ -475,24 +475,24 @@ const Te = (t, e) => {
|
|
|
475
475
|
destroy: () => {
|
|
476
476
|
e.remove();
|
|
477
477
|
},
|
|
478
|
-
redraw: (
|
|
479
|
-
const
|
|
480
|
-
if (!u && !
|
|
481
|
-
|
|
482
|
-
const { annotation: { target: { created:
|
|
483
|
-
return
|
|
484
|
-
}).forEach((
|
|
485
|
-
|
|
486
|
-
const
|
|
487
|
-
if (
|
|
488
|
-
const
|
|
489
|
-
|
|
478
|
+
redraw: (r, c, d, u, f) => {
|
|
479
|
+
const y = !(vt(n, r) && f);
|
|
480
|
+
if (!u && !y) return;
|
|
481
|
+
y && (e.innerHTML = ""), [...r].sort((x, v) => {
|
|
482
|
+
const { annotation: { target: { created: p } } } = x, { annotation: { target: { created: l } } } = v;
|
|
483
|
+
return p && l ? p.getTime() - l.getTime() : 0;
|
|
484
|
+
}).forEach((x) => {
|
|
485
|
+
x.rects.map((v) => {
|
|
486
|
+
const p = Te(v, r), l = de(x, c, d, u, p);
|
|
487
|
+
if (y) {
|
|
488
|
+
const a = document.createElement("span");
|
|
489
|
+
a.className = "r6o-annotation", a.dataset.annotation = x.annotation.id, a.style.left = `${v.x}px`, a.style.top = `${v.y}px`, a.style.width = `${v.width}px`, a.style.height = `${v.height}px`, a.style.backgroundColor = Y((l == null ? void 0 : l.fill) || P.fill).alpha((l == null ? void 0 : l.fillOpacity) === void 0 ? P.fillOpacity : l.fillOpacity).toHex(), l.underlineStyle && (a.style.borderStyle = l.underlineStyle), l.underlineColor && (a.style.borderColor = l.underlineColor), l.underlineThickness && (a.style.borderBottomWidth = `${l.underlineThickness}px`), l.underlineOffset && (a.style.paddingBottom = `${l.underlineOffset}px`), e.appendChild(a);
|
|
490
490
|
}
|
|
491
491
|
});
|
|
492
|
-
}), n =
|
|
492
|
+
}), n = r;
|
|
493
493
|
},
|
|
494
|
-
setVisible: (
|
|
495
|
-
|
|
494
|
+
setVisible: (r) => {
|
|
495
|
+
r ? e.classList.remove("hidden") : e.classList.add("hidden");
|
|
496
496
|
}
|
|
497
497
|
};
|
|
498
498
|
}, Be = (t, e, n) => wt(t, e, n, Re(t));
|
|
@@ -520,7 +520,7 @@ function Pt(t, e, n) {
|
|
|
520
520
|
return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, Me(o);
|
|
521
521
|
}
|
|
522
522
|
var It = Object.prototype.hasOwnProperty;
|
|
523
|
-
function
|
|
523
|
+
function j(t, e) {
|
|
524
524
|
var n, o;
|
|
525
525
|
if (t === e) return !0;
|
|
526
526
|
if (t && e && (n = t.constructor) === e.constructor) {
|
|
@@ -528,13 +528,13 @@ function z(t, e) {
|
|
|
528
528
|
if (n === RegExp) return t.toString() === e.toString();
|
|
529
529
|
if (n === Array) {
|
|
530
530
|
if ((o = t.length) === e.length)
|
|
531
|
-
for (; o-- &&
|
|
531
|
+
for (; o-- && j(t[o], e[o]); ) ;
|
|
532
532
|
return o === -1;
|
|
533
533
|
}
|
|
534
534
|
if (!n || typeof t == "object") {
|
|
535
535
|
o = 0;
|
|
536
536
|
for (n in t)
|
|
537
|
-
if (It.call(t, n) && ++o && !It.call(e, n) || !(n in e) || !
|
|
537
|
+
if (It.call(t, n) && ++o && !It.call(e, n) || !(n in e) || !j(t[n], e[n])) return !1;
|
|
538
538
|
return Object.keys(e).length === o;
|
|
539
539
|
}
|
|
540
540
|
}
|
|
@@ -545,41 +545,41 @@ function ut() {
|
|
|
545
545
|
function Ue(t, e) {
|
|
546
546
|
return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function";
|
|
547
547
|
}
|
|
548
|
-
const
|
|
548
|
+
const z = [];
|
|
549
549
|
function At(t, e = ut) {
|
|
550
550
|
let n;
|
|
551
551
|
const o = /* @__PURE__ */ new Set();
|
|
552
|
-
function i(
|
|
553
|
-
if (Ue(t,
|
|
554
|
-
const d = !
|
|
552
|
+
function i(c) {
|
|
553
|
+
if (Ue(t, c) && (t = c, n)) {
|
|
554
|
+
const d = !z.length;
|
|
555
555
|
for (const u of o)
|
|
556
|
-
u[1](),
|
|
556
|
+
u[1](), z.push(u, t);
|
|
557
557
|
if (d) {
|
|
558
|
-
for (let u = 0; u <
|
|
559
|
-
|
|
560
|
-
|
|
558
|
+
for (let u = 0; u < z.length; u += 2)
|
|
559
|
+
z[u][0](z[u + 1]);
|
|
560
|
+
z.length = 0;
|
|
561
561
|
}
|
|
562
562
|
}
|
|
563
563
|
}
|
|
564
|
-
function
|
|
565
|
-
i(
|
|
564
|
+
function s(c) {
|
|
565
|
+
i(c(t));
|
|
566
566
|
}
|
|
567
|
-
function c
|
|
568
|
-
const u = [
|
|
569
|
-
return o.add(u), o.size === 1 && (n = e(i,
|
|
567
|
+
function r(c, d = ut) {
|
|
568
|
+
const u = [c, d];
|
|
569
|
+
return o.add(u), o.size === 1 && (n = e(i, s) || ut), c(t), () => {
|
|
570
570
|
o.delete(u), o.size === 0 && n && (n(), n = null);
|
|
571
571
|
};
|
|
572
572
|
}
|
|
573
|
-
return { set: i, update:
|
|
573
|
+
return { set: i, update: s, subscribe: r };
|
|
574
574
|
}
|
|
575
575
|
const Ve = (t) => {
|
|
576
576
|
const { subscribe: e, set: n } = At();
|
|
577
577
|
let o;
|
|
578
578
|
return e((i) => o = i), t.observe(({ changes: i }) => {
|
|
579
579
|
if (o) {
|
|
580
|
-
(i.deleted || []).some((
|
|
581
|
-
const
|
|
582
|
-
|
|
580
|
+
(i.deleted || []).some((r) => r.id === o) && n(void 0);
|
|
581
|
+
const s = (i.updated || []).find(({ oldValue: r }) => r.id === o);
|
|
582
|
+
s && n(s.newValue.id);
|
|
583
583
|
}
|
|
584
584
|
}), {
|
|
585
585
|
get current() {
|
|
@@ -590,52 +590,52 @@ const Ve = (t) => {
|
|
|
590
590
|
};
|
|
591
591
|
};
|
|
592
592
|
var De = /* @__PURE__ */ ((t) => (t.EDIT = "EDIT", t.SELECT = "SELECT", t.NONE = "NONE", t))(De || {});
|
|
593
|
-
const tt = { selected: [] },
|
|
594
|
-
const { subscribe:
|
|
595
|
-
let
|
|
596
|
-
|
|
593
|
+
const tt = { selected: [] }, _e = (t, e, n) => {
|
|
594
|
+
const { subscribe: o, set: i } = At(tt);
|
|
595
|
+
let s = e, r = tt;
|
|
596
|
+
o((x) => r = x);
|
|
597
597
|
const c = () => {
|
|
598
|
-
|
|
599
|
-
},
|
|
600
|
-
var
|
|
601
|
-
return ((
|
|
602
|
-
},
|
|
603
|
-
if (
|
|
598
|
+
j(r, tt) || i(tt);
|
|
599
|
+
}, d = () => {
|
|
600
|
+
var x;
|
|
601
|
+
return ((x = r.selected) == null ? void 0 : x.length) === 0;
|
|
602
|
+
}, u = (x) => {
|
|
603
|
+
if (d())
|
|
604
604
|
return !1;
|
|
605
|
-
const
|
|
606
|
-
return r.selected.some((
|
|
607
|
-
},
|
|
608
|
-
const
|
|
609
|
-
if (!
|
|
610
|
-
console.warn("Invalid selection: " +
|
|
605
|
+
const v = typeof x == "string" ? x : x.id;
|
|
606
|
+
return r.selected.some((p) => p.id === v);
|
|
607
|
+
}, f = (x, v) => {
|
|
608
|
+
const p = t.getAnnotation(x);
|
|
609
|
+
if (!p) {
|
|
610
|
+
console.warn("Invalid selection: " + x);
|
|
611
611
|
return;
|
|
612
612
|
}
|
|
613
|
-
switch (Nt(
|
|
613
|
+
switch (Nt(p, s)) {
|
|
614
614
|
case "EDIT":
|
|
615
|
-
|
|
615
|
+
i({ selected: [{ id: x, editable: !0 }], event: v });
|
|
616
616
|
break;
|
|
617
617
|
case "SELECT":
|
|
618
|
-
|
|
618
|
+
i({ selected: [{ id: x }], event: v });
|
|
619
619
|
break;
|
|
620
620
|
default:
|
|
621
|
-
|
|
621
|
+
i({ selected: [], event: v });
|
|
622
622
|
}
|
|
623
|
-
},
|
|
624
|
-
const
|
|
625
|
-
|
|
626
|
-
selected:
|
|
627
|
-
const
|
|
628
|
-
return { id:
|
|
623
|
+
}, h = (x, v) => {
|
|
624
|
+
const p = Array.isArray(x) ? x : [x], l = p.map((a) => t.getAnnotation(a)).filter((a) => !!a);
|
|
625
|
+
i({
|
|
626
|
+
selected: l.map((a) => {
|
|
627
|
+
const m = v === void 0 ? Nt(a, s) === "EDIT" : v;
|
|
628
|
+
return { id: a.id, editable: m };
|
|
629
629
|
})
|
|
630
|
-
}),
|
|
631
|
-
},
|
|
632
|
-
if (
|
|
630
|
+
}), l.length !== p.length && console.warn("Invalid selection", x);
|
|
631
|
+
}, y = (x) => {
|
|
632
|
+
if (d())
|
|
633
633
|
return !1;
|
|
634
|
-
const { selected:
|
|
635
|
-
|
|
636
|
-
},
|
|
634
|
+
const { selected: v } = r;
|
|
635
|
+
v.some(({ id: p }) => x.includes(p)) && i({ selected: v.filter(({ id: p }) => !x.includes(p)) });
|
|
636
|
+
}, g = (x) => s = x;
|
|
637
637
|
return t.observe(
|
|
638
|
-
({ changes:
|
|
638
|
+
({ changes: x }) => y((x.deleted || []).map((v) => v.id))
|
|
639
639
|
), {
|
|
640
640
|
get event() {
|
|
641
641
|
return r ? r.event : null;
|
|
@@ -644,21 +644,21 @@ const tt = { selected: [] }, ke = (t, e) => {
|
|
|
644
644
|
return r ? [...r.selected] : null;
|
|
645
645
|
},
|
|
646
646
|
get userSelectAction() {
|
|
647
|
-
return
|
|
647
|
+
return s;
|
|
648
648
|
},
|
|
649
649
|
clear: c,
|
|
650
|
-
isEmpty:
|
|
651
|
-
isSelected:
|
|
652
|
-
setSelected:
|
|
653
|
-
setUserSelectAction:
|
|
654
|
-
subscribe:
|
|
655
|
-
userSelect:
|
|
650
|
+
isEmpty: d,
|
|
651
|
+
isSelected: u,
|
|
652
|
+
setSelected: h,
|
|
653
|
+
setUserSelectAction: g,
|
|
654
|
+
subscribe: o,
|
|
655
|
+
userSelect: f
|
|
656
656
|
};
|
|
657
|
-
}, Nt = (t, e) => typeof e == "function" ? e(t) : e || "EDIT";
|
|
657
|
+
}, Nt = (t, e, n) => typeof e == "function" ? e(t) : e || "EDIT";
|
|
658
658
|
var V = [];
|
|
659
659
|
for (var ht = 0; ht < 256; ++ht)
|
|
660
660
|
V.push((ht + 256).toString(16).slice(1));
|
|
661
|
-
function
|
|
661
|
+
function ke(t, e = 0) {
|
|
662
662
|
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();
|
|
663
663
|
}
|
|
664
664
|
var et, Ye = new Uint8Array(16);
|
|
@@ -671,12 +671,12 @@ var $e = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(cryp
|
|
|
671
671
|
const Ut = {
|
|
672
672
|
randomUUID: $e
|
|
673
673
|
};
|
|
674
|
-
function
|
|
674
|
+
function jt(t, e, n) {
|
|
675
675
|
if (Ut.randomUUID && !e && !t)
|
|
676
676
|
return Ut.randomUUID();
|
|
677
677
|
t = t || {};
|
|
678
678
|
var o = t.random || (t.rng || Xe)();
|
|
679
|
-
return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128,
|
|
679
|
+
return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, ke(o);
|
|
680
680
|
}
|
|
681
681
|
const ft = (t) => {
|
|
682
682
|
const e = (n) => {
|
|
@@ -689,7 +689,7 @@ const ft = (t) => {
|
|
|
689
689
|
target: e(t.target)
|
|
690
690
|
};
|
|
691
691
|
}, On = (t, e, n, o) => ({
|
|
692
|
-
id:
|
|
692
|
+
id: jt(),
|
|
693
693
|
annotation: typeof t == "string" ? t : t.id,
|
|
694
694
|
created: n || /* @__PURE__ */ new Date(),
|
|
695
695
|
creator: o,
|
|
@@ -700,64 +700,64 @@ const ft = (t) => {
|
|
|
700
700
|
}, Pe = (t, e) => {
|
|
701
701
|
const n = new Set(e.bodies.map((o) => o.id));
|
|
702
702
|
return t.bodies.filter((o) => !n.has(o.id));
|
|
703
|
-
},
|
|
703
|
+
}, je = (t, e) => e.bodies.map((n) => {
|
|
704
704
|
const o = t.bodies.find((i) => i.id === n.id);
|
|
705
|
-
return { newBody: n, oldBody: o && !
|
|
706
|
-
}).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })),
|
|
707
|
-
const n = He(t, e), o = Pe(t, e), i =
|
|
705
|
+
return { newBody: n, oldBody: o && !j(o, n) ? o : void 0 };
|
|
706
|
+
}).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), ze = (t, e) => !j(t.target, e.target), zt = (t, e) => {
|
|
707
|
+
const n = He(t, e), o = Pe(t, e), i = je(t, e);
|
|
708
708
|
return {
|
|
709
709
|
oldValue: t,
|
|
710
710
|
newValue: e,
|
|
711
711
|
bodiesCreated: n.length > 0 ? n : void 0,
|
|
712
712
|
bodiesDeleted: o.length > 0 ? o : void 0,
|
|
713
713
|
bodiesUpdated: i.length > 0 ? i : void 0,
|
|
714
|
-
targetUpdated:
|
|
714
|
+
targetUpdated: ze(t, e) ? { oldTarget: t.target, newTarget: e.target } : void 0
|
|
715
715
|
};
|
|
716
716
|
};
|
|
717
717
|
var M = /* @__PURE__ */ ((t) => (t.LOCAL = "LOCAL", t.REMOTE = "REMOTE", t.SILENT = "SILENT", t))(M || {});
|
|
718
718
|
const Fe = (t, e) => {
|
|
719
719
|
var n, o;
|
|
720
|
-
const { changes: i, origin:
|
|
721
|
-
if (!(t.options.origin ? t.options.origin ===
|
|
720
|
+
const { changes: i, origin: s } = e;
|
|
721
|
+
if (!(t.options.origin ? t.options.origin === s : s !== "SILENT"))
|
|
722
722
|
return !1;
|
|
723
723
|
if (t.options.ignore) {
|
|
724
|
-
const { ignore:
|
|
725
|
-
if (!(
|
|
726
|
-
const d = (n = i.updated) == null ? void 0 : n.some((
|
|
727
|
-
if (
|
|
724
|
+
const { ignore: r } = t.options, c = (d) => d && d.length > 0;
|
|
725
|
+
if (!(c(i.created) || c(i.deleted))) {
|
|
726
|
+
const d = (n = i.updated) == null ? void 0 : n.some((f) => c(f.bodiesCreated) || c(f.bodiesDeleted) || c(f.bodiesUpdated)), u = (o = i.updated) == null ? void 0 : o.some((f) => f.targetUpdated);
|
|
727
|
+
if (r === "BODY_ONLY" && d && !u || r === "TARGET_ONLY" && u && !d)
|
|
728
728
|
return !1;
|
|
729
729
|
}
|
|
730
730
|
}
|
|
731
731
|
if (t.options.annotations) {
|
|
732
|
-
const
|
|
733
|
-
...(i.created || []).map((
|
|
734
|
-
...(i.deleted || []).map((
|
|
735
|
-
...(i.updated || []).map(({ oldValue:
|
|
732
|
+
const r = /* @__PURE__ */ new Set([
|
|
733
|
+
...(i.created || []).map((c) => c.id),
|
|
734
|
+
...(i.deleted || []).map((c) => c.id),
|
|
735
|
+
...(i.updated || []).map(({ oldValue: c }) => c.id)
|
|
736
736
|
]);
|
|
737
|
-
return !!(Array.isArray(t.options.annotations) ? t.options.annotations : [t.options.annotations]).find((
|
|
737
|
+
return !!(Array.isArray(t.options.annotations) ? t.options.annotations : [t.options.annotations]).find((c) => r.has(c));
|
|
738
738
|
} else
|
|
739
739
|
return !0;
|
|
740
740
|
}, We = (t, e) => {
|
|
741
|
-
const n = new Set((t.created || []).map((h) => h.id)), o = new Set((t.updated || []).map(({ newValue: h }) => h.id)), i = new Set((e.created || []).map((h) => h.id)),
|
|
742
|
-
...(t.created || []).filter((h) => !
|
|
741
|
+
const n = new Set((t.created || []).map((h) => h.id)), o = new Set((t.updated || []).map(({ newValue: h }) => h.id)), i = new Set((e.created || []).map((h) => h.id)), s = new Set((e.deleted || []).map((h) => h.id)), r = new Set((e.updated || []).map(({ oldValue: h }) => h.id)), c = new Set((e.updated || []).filter(({ oldValue: h }) => n.has(h.id) || o.has(h.id)).map(({ oldValue: h }) => h.id)), d = [
|
|
742
|
+
...(t.created || []).filter((h) => !s.has(h.id)).map((h) => r.has(h.id) ? e.updated.find(({ oldValue: y }) => y.id === h.id).newValue : h),
|
|
743
743
|
...e.created || []
|
|
744
744
|
], u = [
|
|
745
745
|
...(t.deleted || []).filter((h) => !i.has(h.id)),
|
|
746
746
|
...(e.deleted || []).filter((h) => !n.has(h.id))
|
|
747
|
-
],
|
|
748
|
-
...(t.updated || []).filter(({ newValue: h }) => !
|
|
749
|
-
const { oldValue:
|
|
750
|
-
if (
|
|
751
|
-
const
|
|
752
|
-
return
|
|
747
|
+
], f = [
|
|
748
|
+
...(t.updated || []).filter(({ newValue: h }) => !s.has(h.id)).map((h) => {
|
|
749
|
+
const { oldValue: y, newValue: g } = h;
|
|
750
|
+
if (r.has(g.id)) {
|
|
751
|
+
const x = e.updated.find((v) => v.oldValue.id === g.id).newValue;
|
|
752
|
+
return zt(y, x);
|
|
753
753
|
} else
|
|
754
754
|
return h;
|
|
755
755
|
}),
|
|
756
|
-
...(e.updated || []).filter(({ oldValue: h }) => !
|
|
756
|
+
...(e.updated || []).filter(({ oldValue: h }) => !c.has(h.id))
|
|
757
757
|
];
|
|
758
|
-
return { created: d, deleted: u, updated:
|
|
758
|
+
return { created: d, deleted: u, updated: f };
|
|
759
759
|
}, gt = (t) => {
|
|
760
|
-
const e = t.id === void 0 ?
|
|
760
|
+
const e = t.id === void 0 ? jt() : t.id;
|
|
761
761
|
return {
|
|
762
762
|
...t,
|
|
763
763
|
id: e,
|
|
@@ -771,14 +771,14 @@ const Fe = (t, e) => {
|
|
|
771
771
|
}
|
|
772
772
|
};
|
|
773
773
|
}, qe = (t) => t.id !== void 0, Ge = () => {
|
|
774
|
-
const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (
|
|
775
|
-
n.push({ onChange:
|
|
776
|
-
}, i = (
|
|
777
|
-
const A = n.findIndex((w) => w.onChange ==
|
|
774
|
+
const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (b, A = {}) => {
|
|
775
|
+
n.push({ onChange: b, options: A });
|
|
776
|
+
}, i = (b) => {
|
|
777
|
+
const A = n.findIndex((w) => w.onChange == b);
|
|
778
778
|
A > -1 && n.splice(A, 1);
|
|
779
|
-
},
|
|
779
|
+
}, s = (b, A) => {
|
|
780
780
|
const w = {
|
|
781
|
-
origin:
|
|
781
|
+
origin: b,
|
|
782
782
|
changes: {
|
|
783
783
|
created: A.created || [],
|
|
784
784
|
updated: A.updated || [],
|
|
@@ -789,87 +789,87 @@ const Fe = (t, e) => {
|
|
|
789
789
|
n.forEach((C) => {
|
|
790
790
|
Fe(C, w) && C.onChange(w);
|
|
791
791
|
});
|
|
792
|
-
},
|
|
793
|
-
if (
|
|
794
|
-
throw Error(`Cannot add annotation ${
|
|
792
|
+
}, r = (b, A = M.LOCAL) => {
|
|
793
|
+
if (b.id && t.get(b.id))
|
|
794
|
+
throw Error(`Cannot add annotation ${b.id} - exists already`);
|
|
795
795
|
{
|
|
796
|
-
const w = gt(
|
|
797
|
-
t.set(w.id, w), w.bodies.forEach((C) => e.set(C.id, w.id)),
|
|
796
|
+
const w = gt(b);
|
|
797
|
+
t.set(w.id, w), w.bodies.forEach((C) => e.set(C.id, w.id)), s(A, { created: [w] });
|
|
798
798
|
}
|
|
799
|
-
},
|
|
800
|
-
const w = gt(typeof
|
|
799
|
+
}, c = (b, A) => {
|
|
800
|
+
const w = gt(typeof b == "string" ? A : b), C = typeof b == "string" ? b : b.id, O = C && t.get(C);
|
|
801
801
|
if (O) {
|
|
802
|
-
const B =
|
|
802
|
+
const B = zt(O, w);
|
|
803
803
|
return C === w.id ? t.set(C, w) : (t.delete(C), t.set(w.id, w)), O.bodies.forEach((D) => e.delete(D.id)), w.bodies.forEach((D) => e.set(D.id, w.id)), B;
|
|
804
804
|
} else
|
|
805
805
|
console.warn(`Cannot update annotation ${C} - does not exist`);
|
|
806
|
-
}, d = (
|
|
807
|
-
const C = qe(A) ? w : A, O =
|
|
808
|
-
O &&
|
|
809
|
-
}, u = (
|
|
810
|
-
const w =
|
|
811
|
-
const B =
|
|
806
|
+
}, d = (b, A = M.LOCAL, w = M.LOCAL) => {
|
|
807
|
+
const C = qe(A) ? w : A, O = c(b, A);
|
|
808
|
+
O && s(C, { updated: [O] });
|
|
809
|
+
}, u = (b, A = M.LOCAL) => {
|
|
810
|
+
const w = b.reduce((C, O) => {
|
|
811
|
+
const B = c(O);
|
|
812
812
|
return B ? [...C, B] : C;
|
|
813
813
|
}, []);
|
|
814
|
-
w.length > 0 &&
|
|
815
|
-
},
|
|
816
|
-
const w = t.get(
|
|
814
|
+
w.length > 0 && s(A, { updated: w });
|
|
815
|
+
}, f = (b, A = M.LOCAL) => {
|
|
816
|
+
const w = t.get(b.annotation);
|
|
817
817
|
if (w) {
|
|
818
818
|
const C = {
|
|
819
819
|
...w,
|
|
820
|
-
bodies: [...w.bodies,
|
|
820
|
+
bodies: [...w.bodies, b]
|
|
821
821
|
};
|
|
822
|
-
t.set(w.id, C), e.set(
|
|
822
|
+
t.set(w.id, C), e.set(b.id, C.id), s(A, { updated: [{
|
|
823
823
|
oldValue: w,
|
|
824
824
|
newValue: C,
|
|
825
|
-
bodiesCreated: [
|
|
825
|
+
bodiesCreated: [b]
|
|
826
826
|
}] });
|
|
827
827
|
} else
|
|
828
|
-
console.warn(`Attempt to add body to missing annotation: ${
|
|
829
|
-
}, h = () => [...t.values()],
|
|
828
|
+
console.warn(`Attempt to add body to missing annotation: ${b.annotation}`);
|
|
829
|
+
}, h = () => [...t.values()], y = (b = M.LOCAL) => {
|
|
830
830
|
const A = [...t.values()];
|
|
831
|
-
t.clear(), e.clear(),
|
|
832
|
-
},
|
|
833
|
-
const C =
|
|
831
|
+
t.clear(), e.clear(), s(b, { deleted: A });
|
|
832
|
+
}, g = (b, A = !0, w = M.LOCAL) => {
|
|
833
|
+
const C = b.map(gt);
|
|
834
834
|
if (A) {
|
|
835
835
|
const O = [...t.values()];
|
|
836
836
|
t.clear(), e.clear(), C.forEach((B) => {
|
|
837
837
|
t.set(B.id, B), B.bodies.forEach((D) => e.set(D.id, B.id));
|
|
838
|
-
}),
|
|
838
|
+
}), s(w, { created: C, deleted: O });
|
|
839
839
|
} else {
|
|
840
|
-
const O =
|
|
841
|
-
const
|
|
842
|
-
return
|
|
840
|
+
const O = b.reduce((B, D) => {
|
|
841
|
+
const _ = D.id && t.get(D.id);
|
|
842
|
+
return _ ? [...B, _] : B;
|
|
843
843
|
}, []);
|
|
844
844
|
if (O.length > 0)
|
|
845
845
|
throw Error(`Bulk insert would overwrite the following annotations: ${O.map((B) => B.id).join(", ")}`);
|
|
846
846
|
C.forEach((B) => {
|
|
847
847
|
t.set(B.id, B), B.bodies.forEach((D) => e.set(D.id, B.id));
|
|
848
|
-
}),
|
|
848
|
+
}), s(w, { created: C });
|
|
849
849
|
}
|
|
850
|
-
},
|
|
851
|
-
const A = typeof
|
|
850
|
+
}, x = (b) => {
|
|
851
|
+
const A = typeof b == "string" ? b : b.id, w = t.get(A);
|
|
852
852
|
if (w)
|
|
853
853
|
return t.delete(A), w.bodies.forEach((C) => e.delete(C.id)), w;
|
|
854
854
|
console.warn(`Attempt to delete missing annotation: ${A}`);
|
|
855
|
-
},
|
|
856
|
-
const w =
|
|
857
|
-
w &&
|
|
858
|
-
},
|
|
859
|
-
const w =
|
|
860
|
-
const B =
|
|
855
|
+
}, v = (b, A = M.LOCAL) => {
|
|
856
|
+
const w = x(b);
|
|
857
|
+
w && s(A, { deleted: [w] });
|
|
858
|
+
}, p = (b, A = M.LOCAL) => {
|
|
859
|
+
const w = b.reduce((C, O) => {
|
|
860
|
+
const B = x(O);
|
|
861
861
|
return B ? [...C, B] : C;
|
|
862
862
|
}, []);
|
|
863
|
-
w.length > 0 &&
|
|
864
|
-
}, l = (
|
|
865
|
-
const A = t.get(
|
|
863
|
+
w.length > 0 && s(A, { deleted: w });
|
|
864
|
+
}, l = (b) => {
|
|
865
|
+
const A = t.get(b.annotation);
|
|
866
866
|
if (A) {
|
|
867
|
-
const w = A.bodies.find((C) => C.id ===
|
|
867
|
+
const w = A.bodies.find((C) => C.id === b.id);
|
|
868
868
|
if (w) {
|
|
869
869
|
e.delete(w.id);
|
|
870
870
|
const C = {
|
|
871
871
|
...A,
|
|
872
|
-
bodies: A.bodies.filter((O) => O.id !==
|
|
872
|
+
bodies: A.bodies.filter((O) => O.id !== b.id)
|
|
873
873
|
};
|
|
874
874
|
return t.set(A.id, C), {
|
|
875
875
|
oldValue: A,
|
|
@@ -877,33 +877,33 @@ const Fe = (t, e) => {
|
|
|
877
877
|
bodiesDeleted: [w]
|
|
878
878
|
};
|
|
879
879
|
} else
|
|
880
|
-
console.warn(`Attempt to delete missing body ${
|
|
880
|
+
console.warn(`Attempt to delete missing body ${b.id} from annotation ${b.annotation}`);
|
|
881
881
|
} else
|
|
882
|
-
console.warn(`Attempt to delete body from missing annotation ${
|
|
883
|
-
},
|
|
884
|
-
const w = l(
|
|
885
|
-
w &&
|
|
886
|
-
},
|
|
887
|
-
const w =
|
|
888
|
-
w.length > 0 &&
|
|
889
|
-
},
|
|
890
|
-
const A = t.get(
|
|
882
|
+
console.warn(`Attempt to delete body from missing annotation ${b.annotation}`);
|
|
883
|
+
}, a = (b, A = M.LOCAL) => {
|
|
884
|
+
const w = l(b);
|
|
885
|
+
w && s(A, { updated: [w] });
|
|
886
|
+
}, m = (b, A = M.LOCAL) => {
|
|
887
|
+
const w = b.map((C) => l(C)).filter(Boolean);
|
|
888
|
+
w.length > 0 && s(A, { updated: w });
|
|
889
|
+
}, S = (b) => {
|
|
890
|
+
const A = t.get(b);
|
|
891
891
|
return A ? { ...A } : void 0;
|
|
892
|
-
}, L = (
|
|
893
|
-
const A = e.get(
|
|
892
|
+
}, L = (b) => {
|
|
893
|
+
const A = e.get(b);
|
|
894
894
|
if (A) {
|
|
895
|
-
const w =
|
|
895
|
+
const w = S(A).bodies.find((C) => C.id === b);
|
|
896
896
|
if (w)
|
|
897
897
|
return w;
|
|
898
|
-
console.error(`Store integrity error: body ${
|
|
898
|
+
console.error(`Store integrity error: body ${b} in index, but not in annotation`);
|
|
899
899
|
} else
|
|
900
|
-
console.warn(`Attempt to retrieve missing body: ${
|
|
901
|
-
}, E = (
|
|
902
|
-
if (
|
|
900
|
+
console.warn(`Attempt to retrieve missing body: ${b}`);
|
|
901
|
+
}, E = (b, A) => {
|
|
902
|
+
if (b.annotation !== A.annotation)
|
|
903
903
|
throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
|
|
904
|
-
const w = t.get(
|
|
904
|
+
const w = t.get(b.annotation);
|
|
905
905
|
if (w) {
|
|
906
|
-
const C = w.bodies.find((B) => B.id ===
|
|
906
|
+
const C = w.bodies.find((B) => B.id === b.id), O = {
|
|
907
907
|
...w,
|
|
908
908
|
bodies: w.bodies.map((B) => B.id === C.id ? A : B)
|
|
909
909
|
};
|
|
@@ -913,21 +913,21 @@ const Fe = (t, e) => {
|
|
|
913
913
|
bodiesUpdated: [{ oldBody: C, newBody: A }]
|
|
914
914
|
};
|
|
915
915
|
} else
|
|
916
|
-
console.warn(`Attempt to add body to missing annotation ${
|
|
917
|
-
}, T = (
|
|
918
|
-
const C = E(
|
|
919
|
-
C &&
|
|
920
|
-
}, R = (
|
|
921
|
-
const w =
|
|
922
|
-
|
|
923
|
-
}, I = (
|
|
924
|
-
const A = t.get(
|
|
916
|
+
console.warn(`Attempt to add body to missing annotation ${b.annotation}`);
|
|
917
|
+
}, T = (b, A, w = M.LOCAL) => {
|
|
918
|
+
const C = E(b, A);
|
|
919
|
+
C && s(w, { updated: [C] });
|
|
920
|
+
}, R = (b, A = M.LOCAL) => {
|
|
921
|
+
const w = b.map((C) => E({ id: C.id, annotation: C.annotation }, C)).filter(Boolean);
|
|
922
|
+
s(A, { updated: w });
|
|
923
|
+
}, I = (b) => {
|
|
924
|
+
const A = t.get(b.annotation);
|
|
925
925
|
if (A) {
|
|
926
926
|
const w = {
|
|
927
927
|
...A,
|
|
928
928
|
target: {
|
|
929
929
|
...A.target,
|
|
930
|
-
...
|
|
930
|
+
...b
|
|
931
931
|
}
|
|
932
932
|
};
|
|
933
933
|
return t.set(A.id, w), {
|
|
@@ -935,37 +935,37 @@ const Fe = (t, e) => {
|
|
|
935
935
|
newValue: w,
|
|
936
936
|
targetUpdated: {
|
|
937
937
|
oldTarget: A.target,
|
|
938
|
-
newTarget:
|
|
938
|
+
newTarget: b
|
|
939
939
|
}
|
|
940
940
|
};
|
|
941
941
|
} else
|
|
942
|
-
console.warn(`Attempt to update target on missing annotation: ${
|
|
942
|
+
console.warn(`Attempt to update target on missing annotation: ${b.annotation}`);
|
|
943
943
|
};
|
|
944
944
|
return {
|
|
945
|
-
addAnnotation:
|
|
946
|
-
addBody:
|
|
945
|
+
addAnnotation: r,
|
|
946
|
+
addBody: f,
|
|
947
947
|
all: h,
|
|
948
|
-
bulkAddAnnotation:
|
|
949
|
-
bulkDeleteAnnotation:
|
|
950
|
-
bulkDeleteBodies:
|
|
948
|
+
bulkAddAnnotation: g,
|
|
949
|
+
bulkDeleteAnnotation: p,
|
|
950
|
+
bulkDeleteBodies: m,
|
|
951
951
|
bulkUpdateAnnotation: u,
|
|
952
952
|
bulkUpdateBodies: R,
|
|
953
|
-
bulkUpdateTargets: (
|
|
954
|
-
const w =
|
|
955
|
-
w.length > 0 &&
|
|
953
|
+
bulkUpdateTargets: (b, A = M.LOCAL) => {
|
|
954
|
+
const w = b.map((C) => I(C)).filter(Boolean);
|
|
955
|
+
w.length > 0 && s(A, { updated: w });
|
|
956
956
|
},
|
|
957
|
-
clear:
|
|
958
|
-
deleteAnnotation:
|
|
959
|
-
deleteBody:
|
|
960
|
-
getAnnotation:
|
|
957
|
+
clear: y,
|
|
958
|
+
deleteAnnotation: v,
|
|
959
|
+
deleteBody: a,
|
|
960
|
+
getAnnotation: S,
|
|
961
961
|
getBody: L,
|
|
962
962
|
observe: o,
|
|
963
963
|
unobserve: i,
|
|
964
964
|
updateAnnotation: d,
|
|
965
965
|
updateBody: T,
|
|
966
|
-
updateTarget: (
|
|
967
|
-
const w = I(
|
|
968
|
-
w &&
|
|
966
|
+
updateTarget: (b, A = M.LOCAL) => {
|
|
967
|
+
const w = I(b);
|
|
968
|
+
w && s(A, { updated: [w] });
|
|
969
969
|
}
|
|
970
970
|
};
|
|
971
971
|
};
|
|
@@ -985,39 +985,39 @@ let Ke = () => ({
|
|
|
985
985
|
});
|
|
986
986
|
const Qe = 250, Je = (t) => {
|
|
987
987
|
const e = Ke(), n = [];
|
|
988
|
-
let o = -1, i = !1,
|
|
989
|
-
const
|
|
988
|
+
let o = -1, i = !1, s = 0;
|
|
989
|
+
const r = (g) => {
|
|
990
990
|
if (!i) {
|
|
991
|
-
const { changes:
|
|
992
|
-
if (
|
|
993
|
-
n.splice(o + 1), n.push(
|
|
991
|
+
const { changes: x } = g, v = performance.now();
|
|
992
|
+
if (v - s > Qe)
|
|
993
|
+
n.splice(o + 1), n.push(x), o = n.length - 1;
|
|
994
994
|
else {
|
|
995
|
-
const
|
|
996
|
-
n[
|
|
995
|
+
const p = n.length - 1;
|
|
996
|
+
n[p] = We(n[p], x);
|
|
997
997
|
}
|
|
998
|
-
|
|
998
|
+
s = v;
|
|
999
999
|
}
|
|
1000
1000
|
i = !1;
|
|
1001
1001
|
};
|
|
1002
|
-
t.observe(
|
|
1003
|
-
const
|
|
1002
|
+
t.observe(r, { origin: M.LOCAL });
|
|
1003
|
+
const c = (g) => g && g.length > 0 && t.bulkDeleteAnnotation(g), d = (g) => g && g.length > 0 && t.bulkAddAnnotation(g, !1), u = (g) => g && g.length > 0 && t.bulkUpdateAnnotation(g.map(({ oldValue: x }) => x)), f = (g) => g && g.length > 0 && t.bulkUpdateAnnotation(g.map(({ newValue: x }) => x)), h = (g) => g && g.length > 0 && t.bulkAddAnnotation(g, !1), y = (g) => g && g.length > 0 && t.bulkDeleteAnnotation(g);
|
|
1004
1004
|
return {
|
|
1005
1005
|
canRedo: () => n.length - 1 > o,
|
|
1006
1006
|
canUndo: () => o > -1,
|
|
1007
|
-
destroy: () => t.unobserve(
|
|
1008
|
-
on: (
|
|
1007
|
+
destroy: () => t.unobserve(r),
|
|
1008
|
+
on: (g, x) => e.on(g, x),
|
|
1009
1009
|
redo: () => {
|
|
1010
1010
|
if (n.length - 1 > o) {
|
|
1011
1011
|
i = !0;
|
|
1012
|
-
const { created:
|
|
1013
|
-
d(
|
|
1012
|
+
const { created: g, updated: x, deleted: v } = n[o + 1];
|
|
1013
|
+
d(g), f(x), y(v), e.emit("redo", n[o + 1]), o += 1;
|
|
1014
1014
|
}
|
|
1015
1015
|
},
|
|
1016
1016
|
undo: () => {
|
|
1017
1017
|
if (o > -1) {
|
|
1018
1018
|
i = !0;
|
|
1019
|
-
const { created:
|
|
1020
|
-
|
|
1019
|
+
const { created: g, updated: x, deleted: v } = n[o];
|
|
1020
|
+
c(g), u(x), h(v), e.emit("undo", n[o]), o -= 1;
|
|
1021
1021
|
}
|
|
1022
1022
|
}
|
|
1023
1023
|
};
|
|
@@ -1028,76 +1028,76 @@ const Qe = 250, Je = (t) => {
|
|
|
1028
1028
|
set: e
|
|
1029
1029
|
};
|
|
1030
1030
|
}, tn = (t, e, n, o) => {
|
|
1031
|
-
const {
|
|
1032
|
-
let u = [],
|
|
1033
|
-
const h = (
|
|
1034
|
-
d.has(
|
|
1035
|
-
},
|
|
1036
|
-
const l = d.get(
|
|
1031
|
+
const { hover: i, selection: s, store: r, viewport: c } = t, d = /* @__PURE__ */ new Map();
|
|
1032
|
+
let u = [], f;
|
|
1033
|
+
const h = (v, p) => {
|
|
1034
|
+
d.has(v) ? d.get(v).push(p) : d.set(v, [p]);
|
|
1035
|
+
}, y = (v, p) => {
|
|
1036
|
+
const l = d.get(v);
|
|
1037
1037
|
if (l) {
|
|
1038
|
-
const
|
|
1039
|
-
|
|
1038
|
+
const a = l.indexOf(p);
|
|
1039
|
+
a !== -1 && l.splice(a, 1);
|
|
1040
1040
|
}
|
|
1041
|
-
},
|
|
1042
|
-
d.has(
|
|
1043
|
-
d.get(
|
|
1041
|
+
}, g = (v, p, l) => {
|
|
1042
|
+
d.has(v) && setTimeout(() => {
|
|
1043
|
+
d.get(v).forEach((a) => {
|
|
1044
1044
|
if (n) {
|
|
1045
|
-
const
|
|
1046
|
-
|
|
1045
|
+
const m = Array.isArray(p) ? p.map((L) => n.serialize(L)) : n.serialize(p), S = l ? l instanceof PointerEvent ? l : n.serialize(l) : void 0;
|
|
1046
|
+
a(m, S);
|
|
1047
1047
|
} else
|
|
1048
|
-
|
|
1048
|
+
a(p, l);
|
|
1049
1049
|
});
|
|
1050
1050
|
}, 1);
|
|
1051
1051
|
};
|
|
1052
|
-
|
|
1053
|
-
if (!(u.length === 0 &&
|
|
1054
|
-
if (u.length === 0 &&
|
|
1055
|
-
u =
|
|
1056
|
-
else if (u.length > 0 &&
|
|
1057
|
-
u.forEach((
|
|
1058
|
-
const l =
|
|
1059
|
-
l && !
|
|
1052
|
+
s.subscribe(({ selected: v }) => {
|
|
1053
|
+
if (!(u.length === 0 && v.length === 0)) {
|
|
1054
|
+
if (u.length === 0 && v.length > 0)
|
|
1055
|
+
u = v.map(({ id: p }) => r.getAnnotation(p));
|
|
1056
|
+
else if (u.length > 0 && v.length === 0)
|
|
1057
|
+
u.forEach((p) => {
|
|
1058
|
+
const l = r.getAnnotation(p.id);
|
|
1059
|
+
l && !j(l, p) && g("updateAnnotation", l, p);
|
|
1060
1060
|
}), u = [];
|
|
1061
1061
|
else {
|
|
1062
|
-
const
|
|
1063
|
-
u.filter((
|
|
1064
|
-
const
|
|
1065
|
-
|
|
1062
|
+
const p = new Set(u.map((a) => a.id)), l = new Set(v.map(({ id: a }) => a));
|
|
1063
|
+
u.filter((a) => !l.has(a.id)).forEach((a) => {
|
|
1064
|
+
const m = r.getAnnotation(a.id);
|
|
1065
|
+
m && !j(m, a) && g("updateAnnotation", m, a);
|
|
1066
1066
|
}), u = [
|
|
1067
1067
|
// Remove annotations that were deselected
|
|
1068
|
-
...u.filter((
|
|
1068
|
+
...u.filter((a) => l.has(a.id)),
|
|
1069
1069
|
// Add editable annotations that were selected
|
|
1070
|
-
...
|
|
1070
|
+
...v.filter(({ id: a }) => !p.has(a)).map(({ id: a }) => r.getAnnotation(a))
|
|
1071
1071
|
];
|
|
1072
1072
|
}
|
|
1073
|
-
|
|
1073
|
+
g("selectionChanged", u);
|
|
1074
1074
|
}
|
|
1075
|
-
}),
|
|
1076
|
-
!
|
|
1077
|
-
}),
|
|
1078
|
-
const { created:
|
|
1079
|
-
(
|
|
1080
|
-
...
|
|
1081
|
-
...
|
|
1082
|
-
...
|
|
1083
|
-
].length > 0).forEach(({ oldValue:
|
|
1084
|
-
const
|
|
1085
|
-
u = u.map((L) => L.id ===
|
|
1075
|
+
}), i.subscribe((v) => {
|
|
1076
|
+
!f && v ? g("mouseEnterAnnotation", r.getAnnotation(v)) : f && !v ? g("mouseLeaveAnnotation", r.getAnnotation(f)) : f && v && (g("mouseLeaveAnnotation", r.getAnnotation(f)), g("mouseEnterAnnotation", r.getAnnotation(v))), f = v;
|
|
1077
|
+
}), c == null || c.subscribe((v) => g("viewportIntersect", v.map((p) => r.getAnnotation(p)))), r.observe((v) => {
|
|
1078
|
+
const { created: p, deleted: l } = v.changes;
|
|
1079
|
+
(p || []).forEach((a) => g("createAnnotation", a)), (l || []).forEach((a) => g("deleteAnnotation", a)), (v.changes.updated || []).filter((a) => [
|
|
1080
|
+
...a.bodiesCreated || [],
|
|
1081
|
+
...a.bodiesDeleted || [],
|
|
1082
|
+
...a.bodiesUpdated || []
|
|
1083
|
+
].length > 0).forEach(({ oldValue: a, newValue: m }) => {
|
|
1084
|
+
const S = u.find((L) => L.id === a.id) || a;
|
|
1085
|
+
u = u.map((L) => L.id === a.id ? m : L), g("updateAnnotation", m, S);
|
|
1086
1086
|
});
|
|
1087
|
-
}, { origin: M.LOCAL }),
|
|
1087
|
+
}, { origin: M.LOCAL }), r.observe((v) => {
|
|
1088
1088
|
if (u) {
|
|
1089
|
-
const
|
|
1090
|
-
l.length > 0 && (u = u.map((
|
|
1089
|
+
const p = new Set(u.map((a) => a.id)), l = (v.changes.updated || []).filter(({ newValue: a }) => p.has(a.id)).map(({ newValue: a }) => a);
|
|
1090
|
+
l.length > 0 && (u = u.map((a) => l.find((S) => S.id === a.id) || a));
|
|
1091
1091
|
}
|
|
1092
1092
|
}, { origin: M.REMOTE });
|
|
1093
|
-
const
|
|
1094
|
-
const { updated: l } =
|
|
1095
|
-
|
|
1093
|
+
const x = (v) => (p) => {
|
|
1094
|
+
const { updated: l } = p;
|
|
1095
|
+
v ? (l || []).forEach((a) => g("updateAnnotation", a.oldValue, a.newValue)) : (l || []).forEach((a) => g("updateAnnotation", a.newValue, a.oldValue));
|
|
1096
1096
|
};
|
|
1097
|
-
return e.on("undo",
|
|
1097
|
+
return e.on("undo", x(!0)), e.on("redo", x(!1)), { on: h, off: y, emit: g };
|
|
1098
1098
|
}, en = (t) => (e) => e.reduce((n, o) => {
|
|
1099
|
-
const { parsed: i, error:
|
|
1100
|
-
return
|
|
1099
|
+
const { parsed: i, error: s } = t.parse(o);
|
|
1100
|
+
return s ? {
|
|
1101
1101
|
parsed: n.parsed,
|
|
1102
1102
|
failed: [...n.failed, o]
|
|
1103
1103
|
} : i ? {
|
|
@@ -1107,78 +1107,78 @@ const Qe = 250, Je = (t) => {
|
|
|
1107
1107
|
...n
|
|
1108
1108
|
};
|
|
1109
1109
|
}, { parsed: [], failed: [] }), nn = (t, e, n) => {
|
|
1110
|
-
const { store: o, selection: i } = t,
|
|
1110
|
+
const { store: o, selection: i } = t, s = (l) => {
|
|
1111
1111
|
if (n) {
|
|
1112
|
-
const { parsed:
|
|
1113
|
-
|
|
1112
|
+
const { parsed: a, error: m } = n.parse(l);
|
|
1113
|
+
a ? o.addAnnotation(a, M.REMOTE) : console.error(m);
|
|
1114
1114
|
} else
|
|
1115
1115
|
o.addAnnotation(ft(l), M.REMOTE);
|
|
1116
|
-
},
|
|
1117
|
-
const
|
|
1118
|
-
return n &&
|
|
1119
|
-
}, u = () => n ? o.all().map(n.serialize) : o.all(),
|
|
1116
|
+
}, r = () => i.clear(), c = () => o.clear(), d = (l) => {
|
|
1117
|
+
const a = o.getAnnotation(l);
|
|
1118
|
+
return n && a ? n.serialize(a) : a;
|
|
1119
|
+
}, u = () => n ? o.all().map(n.serialize) : o.all(), f = () => {
|
|
1120
1120
|
var l;
|
|
1121
|
-
const
|
|
1122
|
-
return n ?
|
|
1123
|
-
}, h = (l,
|
|
1121
|
+
const a = (((l = i.selected) == null ? void 0 : l.map((m) => m.id)) || []).map((m) => o.getAnnotation(m)).filter(Boolean);
|
|
1122
|
+
return n ? a.map(n.serialize) : a;
|
|
1123
|
+
}, h = (l, a = !0) => fetch(l).then((m) => m.json()).then((m) => (g(m, a), m)), y = (l) => {
|
|
1124
1124
|
if (typeof l == "string") {
|
|
1125
|
-
const
|
|
1126
|
-
if (o.deleteAnnotation(l),
|
|
1127
|
-
return n ? n.serialize(
|
|
1125
|
+
const a = o.getAnnotation(l);
|
|
1126
|
+
if (o.deleteAnnotation(l), a)
|
|
1127
|
+
return n ? n.serialize(a) : a;
|
|
1128
1128
|
} else {
|
|
1129
|
-
const
|
|
1130
|
-
if (
|
|
1131
|
-
return o.deleteAnnotation(
|
|
1129
|
+
const a = n ? n.parse(l).parsed : l;
|
|
1130
|
+
if (a)
|
|
1131
|
+
return o.deleteAnnotation(a), l;
|
|
1132
1132
|
}
|
|
1133
|
-
},
|
|
1133
|
+
}, g = (l, a = !0) => {
|
|
1134
1134
|
if (n) {
|
|
1135
|
-
const
|
|
1136
|
-
L.length > 0 && console.warn(`Discarded ${L.length} invalid annotations`, L), o.bulkAddAnnotation(
|
|
1135
|
+
const m = n.parseAll || en(n), { parsed: S, failed: L } = m(l);
|
|
1136
|
+
L.length > 0 && console.warn(`Discarded ${L.length} invalid annotations`, L), o.bulkAddAnnotation(S, a, M.REMOTE);
|
|
1137
1137
|
} else
|
|
1138
|
-
o.bulkAddAnnotation(l.map(ft),
|
|
1139
|
-
},
|
|
1140
|
-
l ? i.setSelected(l,
|
|
1141
|
-
},
|
|
1138
|
+
o.bulkAddAnnotation(l.map(ft), a, M.REMOTE);
|
|
1139
|
+
}, x = (l, a) => {
|
|
1140
|
+
l ? i.setSelected(l, a) : i.clear();
|
|
1141
|
+
}, v = (l) => {
|
|
1142
1142
|
i.clear(), i.setUserSelectAction(l);
|
|
1143
|
-
},
|
|
1143
|
+
}, p = (l) => {
|
|
1144
1144
|
if (n) {
|
|
1145
|
-
const
|
|
1146
|
-
return o.updateAnnotation(
|
|
1145
|
+
const a = n.parse(l).parsed, m = n.serialize(o.getAnnotation(a.id));
|
|
1146
|
+
return o.updateAnnotation(a), m;
|
|
1147
1147
|
} else {
|
|
1148
|
-
const
|
|
1149
|
-
return o.updateAnnotation(ft(l)),
|
|
1148
|
+
const a = o.getAnnotation(l.id);
|
|
1149
|
+
return o.updateAnnotation(ft(l)), a;
|
|
1150
1150
|
}
|
|
1151
1151
|
};
|
|
1152
1152
|
return {
|
|
1153
|
-
addAnnotation:
|
|
1154
|
-
cancelSelected:
|
|
1153
|
+
addAnnotation: s,
|
|
1154
|
+
cancelSelected: r,
|
|
1155
1155
|
canRedo: e.canRedo,
|
|
1156
1156
|
canUndo: e.canUndo,
|
|
1157
|
-
clearAnnotations:
|
|
1157
|
+
clearAnnotations: c,
|
|
1158
1158
|
getAnnotationById: d,
|
|
1159
1159
|
getAnnotations: u,
|
|
1160
|
-
getSelected:
|
|
1160
|
+
getSelected: f,
|
|
1161
1161
|
loadAnnotations: h,
|
|
1162
1162
|
redo: e.redo,
|
|
1163
|
-
removeAnnotation:
|
|
1164
|
-
setAnnotations:
|
|
1165
|
-
setSelected:
|
|
1166
|
-
setUserSelectAction:
|
|
1163
|
+
removeAnnotation: y,
|
|
1164
|
+
setAnnotations: g,
|
|
1165
|
+
setSelected: x,
|
|
1166
|
+
setUserSelectAction: v,
|
|
1167
1167
|
undo: e.undo,
|
|
1168
|
-
updateAnnotation:
|
|
1168
|
+
updateAnnotation: p
|
|
1169
1169
|
};
|
|
1170
1170
|
}, on = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
1171
|
-
let
|
|
1171
|
+
let sn = (t) => crypto.getRandomValues(new Uint8Array(t)), rn = (t, e, n) => {
|
|
1172
1172
|
let o = (2 << Math.log(t.length - 1) / Math.LN2) - 1, i = -~(1.6 * o * e / t.length);
|
|
1173
|
-
return (
|
|
1174
|
-
let
|
|
1173
|
+
return (s = e) => {
|
|
1174
|
+
let r = "";
|
|
1175
1175
|
for (; ; ) {
|
|
1176
|
-
let
|
|
1176
|
+
let c = n(i), d = i;
|
|
1177
1177
|
for (; d--; )
|
|
1178
|
-
if (
|
|
1178
|
+
if (r += t[c[d] & o] || "", r.length === s) return r;
|
|
1179
1179
|
}
|
|
1180
1180
|
};
|
|
1181
|
-
}, an = (t, e = 21) =>
|
|
1181
|
+
}, an = (t, e = 21) => rn(t, e, sn), cn = (t = 21) => {
|
|
1182
1182
|
let e = "", n = crypto.getRandomValues(new Uint8Array(t));
|
|
1183
1183
|
for (; t--; )
|
|
1184
1184
|
e += on[n[t] & 63];
|
|
@@ -1188,31 +1188,31 @@ const ln = () => ({ isGuest: !0, id: an("1234567890abcdefghijklmnopqrstuvwxyzABC
|
|
|
1188
1188
|
const e = JSON.stringify(t);
|
|
1189
1189
|
let n = 0;
|
|
1190
1190
|
for (let o = 0, i = e.length; o < i; o++) {
|
|
1191
|
-
let
|
|
1192
|
-
n = (n << 5) - n +
|
|
1191
|
+
let s = e.charCodeAt(o);
|
|
1192
|
+
n = (n << 5) - n + s, n |= 0;
|
|
1193
1193
|
}
|
|
1194
1194
|
return `${n}`;
|
|
1195
1195
|
}, Ft = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, un = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
|
|
1196
|
-
const { id: o, type: i, purpose:
|
|
1196
|
+
const { id: o, type: i, purpose: s, value: r, created: c, modified: d, creator: u, ...f } = n;
|
|
1197
1197
|
return {
|
|
1198
1198
|
id: o || `temp-${dn(n)}`,
|
|
1199
1199
|
annotation: e,
|
|
1200
1200
|
type: i,
|
|
1201
|
-
purpose:
|
|
1202
|
-
value:
|
|
1201
|
+
purpose: s,
|
|
1202
|
+
value: r,
|
|
1203
1203
|
creator: Ft(u),
|
|
1204
|
-
created:
|
|
1204
|
+
created: c ? new Date(c) : void 0,
|
|
1205
1205
|
updated: d ? new Date(d) : void 0,
|
|
1206
|
-
...
|
|
1206
|
+
...f
|
|
1207
1207
|
};
|
|
1208
1208
|
}), hn = (t) => t.map((e) => {
|
|
1209
1209
|
var n;
|
|
1210
|
-
const { annotation: o, created: i, updated:
|
|
1211
|
-
...
|
|
1210
|
+
const { annotation: o, created: i, updated: s, ...r } = e, c = {
|
|
1211
|
+
...r,
|
|
1212
1212
|
created: i == null ? void 0 : i.toISOString(),
|
|
1213
|
-
modified:
|
|
1213
|
+
modified: s == null ? void 0 : s.toISOString()
|
|
1214
1214
|
};
|
|
1215
|
-
return (n =
|
|
1215
|
+
return (n = c.id) != null && n.startsWith("temp-") && delete c.id, c;
|
|
1216
1216
|
});
|
|
1217
1217
|
cn();
|
|
1218
1218
|
const In = (t, e) => ({
|
|
@@ -1224,85 +1224,85 @@ const In = (t, e) => ({
|
|
|
1224
1224
|
creator: n,
|
|
1225
1225
|
created: o,
|
|
1226
1226
|
modified: i,
|
|
1227
|
-
target:
|
|
1228
|
-
} = t,
|
|
1227
|
+
target: s
|
|
1228
|
+
} = t, r = Array.isArray(s) ? s : [s], c = {
|
|
1229
1229
|
creator: Ft(n),
|
|
1230
1230
|
created: o ? new Date(o) : void 0,
|
|
1231
1231
|
updated: i ? new Date(i) : void 0,
|
|
1232
1232
|
annotation: e,
|
|
1233
1233
|
selector: []
|
|
1234
1234
|
};
|
|
1235
|
-
for (const d of
|
|
1236
|
-
const
|
|
1237
|
-
switch (
|
|
1235
|
+
for (const d of r) {
|
|
1236
|
+
const f = (Array.isArray(d.selector) ? d.selector : [d.selector]).reduce((h, y) => {
|
|
1237
|
+
switch (y.type) {
|
|
1238
1238
|
case "TextQuoteSelector":
|
|
1239
|
-
h.quote =
|
|
1239
|
+
h.quote = y.exact;
|
|
1240
1240
|
break;
|
|
1241
1241
|
case "TextPositionSelector":
|
|
1242
|
-
h.start =
|
|
1242
|
+
h.start = y.start, h.end = y.end;
|
|
1243
1243
|
break;
|
|
1244
1244
|
}
|
|
1245
1245
|
return h;
|
|
1246
1246
|
}, {});
|
|
1247
|
-
if (fn(
|
|
1248
|
-
|
|
1247
|
+
if (fn(f))
|
|
1248
|
+
c.selector.push({ id: d.id, ...f });
|
|
1249
1249
|
else {
|
|
1250
1250
|
const h = [
|
|
1251
|
-
|
|
1252
|
-
|
|
1251
|
+
f.start ? void 0 : "TextPositionSelector",
|
|
1252
|
+
f.quote ? void 0 : "TextQuoteSelector"
|
|
1253
1253
|
].filter(Boolean);
|
|
1254
1254
|
return { error: Error(`Missing selector types: ${h.join(" and ")} for annotation: ${t.id}`) };
|
|
1255
1255
|
}
|
|
1256
1256
|
}
|
|
1257
|
-
return { parsed:
|
|
1257
|
+
return { parsed: c };
|
|
1258
1258
|
}, pn = (t) => {
|
|
1259
1259
|
const e = t.id || Pt(), {
|
|
1260
1260
|
creator: n,
|
|
1261
1261
|
created: o,
|
|
1262
1262
|
modified: i,
|
|
1263
|
-
body:
|
|
1264
|
-
...
|
|
1265
|
-
} = t,
|
|
1263
|
+
body: s,
|
|
1264
|
+
...r
|
|
1265
|
+
} = t, c = un(s, e), d = gn(t);
|
|
1266
1266
|
return "error" in d ? { error: d.error } : {
|
|
1267
1267
|
parsed: {
|
|
1268
|
-
...
|
|
1268
|
+
...r,
|
|
1269
1269
|
id: e,
|
|
1270
|
-
bodies:
|
|
1270
|
+
bodies: c,
|
|
1271
1271
|
target: d.parsed
|
|
1272
1272
|
}
|
|
1273
1273
|
};
|
|
1274
1274
|
}, mn = (t, e, n) => {
|
|
1275
|
-
const { bodies: o, target: i, ...
|
|
1276
|
-
selector:
|
|
1277
|
-
creator:
|
|
1275
|
+
const { bodies: o, target: i, ...s } = t, {
|
|
1276
|
+
selector: r,
|
|
1277
|
+
creator: c,
|
|
1278
1278
|
created: d,
|
|
1279
1279
|
updated: u,
|
|
1280
|
-
...
|
|
1281
|
-
} = i, h =
|
|
1282
|
-
const { quote:
|
|
1280
|
+
...f
|
|
1281
|
+
} = i, h = r.map((y) => {
|
|
1282
|
+
const { quote: g, start: x, end: v, range: p } = y, { prefix: l, suffix: a } = ee(p, n), m = [{
|
|
1283
1283
|
type: "TextQuoteSelector",
|
|
1284
|
-
exact:
|
|
1284
|
+
exact: g,
|
|
1285
1285
|
prefix: l,
|
|
1286
|
-
suffix:
|
|
1286
|
+
suffix: a
|
|
1287
1287
|
}, {
|
|
1288
1288
|
type: "TextPositionSelector",
|
|
1289
|
-
start:
|
|
1290
|
-
end:
|
|
1289
|
+
start: x,
|
|
1290
|
+
end: v
|
|
1291
1291
|
}];
|
|
1292
1292
|
return {
|
|
1293
|
-
...
|
|
1294
|
-
id:
|
|
1293
|
+
...f,
|
|
1294
|
+
id: y.id,
|
|
1295
1295
|
source: e,
|
|
1296
|
-
selector:
|
|
1296
|
+
selector: m
|
|
1297
1297
|
};
|
|
1298
1298
|
});
|
|
1299
1299
|
return {
|
|
1300
|
-
...
|
|
1300
|
+
...s,
|
|
1301
1301
|
"@context": "http://www.w3.org/ns/anno.jsonld",
|
|
1302
1302
|
id: t.id,
|
|
1303
1303
|
type: "Annotation",
|
|
1304
1304
|
body: hn(t.bodies),
|
|
1305
|
-
creator:
|
|
1305
|
+
creator: c,
|
|
1306
1306
|
created: d == null ? void 0 : d.toISOString(),
|
|
1307
1307
|
modified: u == null ? void 0 : u.toISOString(),
|
|
1308
1308
|
target: h
|
|
@@ -1311,16 +1311,16 @@ const In = (t, e) => ({
|
|
|
1311
1311
|
function Wt(t, e, n = 0, o = t.length - 1, i = bn) {
|
|
1312
1312
|
for (; o > n; ) {
|
|
1313
1313
|
if (o - n > 600) {
|
|
1314
|
-
const d = o - n + 1, u = e - n + 1,
|
|
1315
|
-
Wt(t, e,
|
|
1314
|
+
const d = o - n + 1, u = e - n + 1, f = Math.log(d), h = 0.5 * Math.exp(2 * f / 3), y = 0.5 * Math.sqrt(f * h * (d - h) / d) * (u - d / 2 < 0 ? -1 : 1), g = Math.max(n, Math.floor(e - u * h / d + y)), x = Math.min(o, Math.floor(e + (d - u) * h / d + y));
|
|
1315
|
+
Wt(t, e, g, x, i);
|
|
1316
1316
|
}
|
|
1317
|
-
const
|
|
1318
|
-
let
|
|
1319
|
-
for (q(t, n, e), i(t[o],
|
|
1320
|
-
for (q(t,
|
|
1321
|
-
for (; i(t[
|
|
1317
|
+
const s = t[e];
|
|
1318
|
+
let r = n, c = o;
|
|
1319
|
+
for (q(t, n, e), i(t[o], s) > 0 && q(t, n, o); r < c; ) {
|
|
1320
|
+
for (q(t, r, c), r++, c--; i(t[r], s) < 0; ) r++;
|
|
1321
|
+
for (; i(t[c], s) > 0; ) c--;
|
|
1322
1322
|
}
|
|
1323
|
-
i(t[n],
|
|
1323
|
+
i(t[n], s) === 0 ? q(t, n, c) : (c++, q(t, c, o)), c <= e && (n = c + 1), e <= c && (o = c - 1);
|
|
1324
1324
|
}
|
|
1325
1325
|
}
|
|
1326
1326
|
function q(t, e, n) {
|
|
@@ -1341,13 +1341,13 @@ class vn {
|
|
|
1341
1341
|
let n = this.data;
|
|
1342
1342
|
const o = [];
|
|
1343
1343
|
if (!ot(e, n)) return o;
|
|
1344
|
-
const i = this.toBBox,
|
|
1344
|
+
const i = this.toBBox, s = [];
|
|
1345
1345
|
for (; n; ) {
|
|
1346
|
-
for (let
|
|
1347
|
-
const
|
|
1348
|
-
ot(e, d) && (n.leaf ? o.push(
|
|
1346
|
+
for (let r = 0; r < n.children.length; r++) {
|
|
1347
|
+
const c = n.children[r], d = n.leaf ? i(c) : c;
|
|
1348
|
+
ot(e, d) && (n.leaf ? o.push(c) : mt(e, d) ? this._all(c, o) : s.push(c));
|
|
1349
1349
|
}
|
|
1350
|
-
n =
|
|
1350
|
+
n = s.pop();
|
|
1351
1351
|
}
|
|
1352
1352
|
return o;
|
|
1353
1353
|
}
|
|
@@ -1357,10 +1357,10 @@ class vn {
|
|
|
1357
1357
|
const o = [];
|
|
1358
1358
|
for (; n; ) {
|
|
1359
1359
|
for (let i = 0; i < n.children.length; i++) {
|
|
1360
|
-
const
|
|
1361
|
-
if (ot(e,
|
|
1362
|
-
if (n.leaf || mt(e,
|
|
1363
|
-
o.push(
|
|
1360
|
+
const s = n.children[i], r = n.leaf ? this.toBBox(s) : s;
|
|
1361
|
+
if (ot(e, r)) {
|
|
1362
|
+
if (n.leaf || mt(e, r)) return !0;
|
|
1363
|
+
o.push(s);
|
|
1364
1364
|
}
|
|
1365
1365
|
}
|
|
1366
1366
|
n = o.pop();
|
|
@@ -1397,15 +1397,15 @@ class vn {
|
|
|
1397
1397
|
remove(e, n) {
|
|
1398
1398
|
if (!e) return this;
|
|
1399
1399
|
let o = this.data;
|
|
1400
|
-
const i = this.toBBox(e),
|
|
1401
|
-
let
|
|
1402
|
-
for (; o ||
|
|
1403
|
-
if (o || (o =
|
|
1404
|
-
const
|
|
1405
|
-
if (
|
|
1406
|
-
return o.children.splice(
|
|
1400
|
+
const i = this.toBBox(e), s = [], r = [];
|
|
1401
|
+
let c, d, u;
|
|
1402
|
+
for (; o || s.length; ) {
|
|
1403
|
+
if (o || (o = s.pop(), d = s[s.length - 1], c = r.pop(), u = !0), o.leaf) {
|
|
1404
|
+
const f = yn(e, o.children, n);
|
|
1405
|
+
if (f !== -1)
|
|
1406
|
+
return o.children.splice(f, 1), s.push(o), this._condense(s), this;
|
|
1407
1407
|
}
|
|
1408
|
-
!u && !o.leaf && mt(o, i) ? (
|
|
1408
|
+
!u && !o.leaf && mt(o, i) ? (s.push(o), r.push(c), c = 0, d = o, o = o.children[0]) : d ? (c++, o = d.children[c], u = !1) : o = null;
|
|
1409
1409
|
}
|
|
1410
1410
|
return this;
|
|
1411
1411
|
}
|
|
@@ -1431,75 +1431,75 @@ class vn {
|
|
|
1431
1431
|
return n;
|
|
1432
1432
|
}
|
|
1433
1433
|
_build(e, n, o, i) {
|
|
1434
|
-
const
|
|
1435
|
-
let
|
|
1436
|
-
if (
|
|
1437
|
-
return
|
|
1438
|
-
i || (i = Math.ceil(Math.log(
|
|
1439
|
-
const d = Math.ceil(
|
|
1434
|
+
const s = o - n + 1;
|
|
1435
|
+
let r = this._maxEntries, c;
|
|
1436
|
+
if (s <= r)
|
|
1437
|
+
return c = W(e.slice(n, o + 1)), F(c, this.toBBox), c;
|
|
1438
|
+
i || (i = Math.ceil(Math.log(s) / Math.log(r)), r = Math.ceil(s / Math.pow(r, i - 1))), c = W([]), c.leaf = !1, c.height = i;
|
|
1439
|
+
const d = Math.ceil(s / r), u = d * Math.ceil(Math.sqrt(r));
|
|
1440
1440
|
Vt(e, n, o, u, this.compareMinX);
|
|
1441
|
-
for (let
|
|
1442
|
-
const h = Math.min(
|
|
1443
|
-
Vt(e,
|
|
1444
|
-
for (let
|
|
1445
|
-
const
|
|
1446
|
-
|
|
1441
|
+
for (let f = n; f <= o; f += u) {
|
|
1442
|
+
const h = Math.min(f + u - 1, o);
|
|
1443
|
+
Vt(e, f, h, d, this.compareMinY);
|
|
1444
|
+
for (let y = f; y <= h; y += d) {
|
|
1445
|
+
const g = Math.min(y + d - 1, h);
|
|
1446
|
+
c.children.push(this._build(e, y, g, i - 1));
|
|
1447
1447
|
}
|
|
1448
1448
|
}
|
|
1449
|
-
return F(
|
|
1449
|
+
return F(c, this.toBBox), c;
|
|
1450
1450
|
}
|
|
1451
1451
|
_chooseSubtree(e, n, o, i) {
|
|
1452
1452
|
for (; i.push(n), !(n.leaf || i.length - 1 === o); ) {
|
|
1453
|
-
let
|
|
1453
|
+
let s = 1 / 0, r = 1 / 0, c;
|
|
1454
1454
|
for (let d = 0; d < n.children.length; d++) {
|
|
1455
|
-
const u = n.children[d],
|
|
1456
|
-
h <
|
|
1455
|
+
const u = n.children[d], f = pt(u), h = xn(e, u) - f;
|
|
1456
|
+
h < r ? (r = h, s = f < s ? f : s, c = u) : h === r && f < s && (s = f, c = u);
|
|
1457
1457
|
}
|
|
1458
|
-
n =
|
|
1458
|
+
n = c || n.children[0];
|
|
1459
1459
|
}
|
|
1460
1460
|
return n;
|
|
1461
1461
|
}
|
|
1462
1462
|
_insert(e, n, o) {
|
|
1463
|
-
const i = o ? e : this.toBBox(e),
|
|
1464
|
-
for (
|
|
1465
|
-
this._split(
|
|
1466
|
-
this._adjustParentBBoxes(i,
|
|
1463
|
+
const i = o ? e : this.toBBox(e), s = [], r = this._chooseSubtree(i, this.data, n, s);
|
|
1464
|
+
for (r.children.push(e), K(r, i); n >= 0 && s[n].children.length > this._maxEntries; )
|
|
1465
|
+
this._split(s, n), n--;
|
|
1466
|
+
this._adjustParentBBoxes(i, s, n);
|
|
1467
1467
|
}
|
|
1468
1468
|
// split overflowed node into two
|
|
1469
1469
|
_split(e, n) {
|
|
1470
|
-
const o = e[n], i = o.children.length,
|
|
1471
|
-
this._chooseSplitAxis(o,
|
|
1472
|
-
const
|
|
1473
|
-
|
|
1470
|
+
const o = e[n], i = o.children.length, s = this._minEntries;
|
|
1471
|
+
this._chooseSplitAxis(o, s, i);
|
|
1472
|
+
const r = this._chooseSplitIndex(o, s, i), c = W(o.children.splice(r, o.children.length - r));
|
|
1473
|
+
c.height = o.height, c.leaf = o.leaf, F(o, this.toBBox), F(c, this.toBBox), n ? e[n - 1].children.push(c) : this._splitRoot(o, c);
|
|
1474
1474
|
}
|
|
1475
1475
|
_splitRoot(e, n) {
|
|
1476
1476
|
this.data = W([e, n]), this.data.height = e.height + 1, this.data.leaf = !1, F(this.data, this.toBBox);
|
|
1477
1477
|
}
|
|
1478
1478
|
_chooseSplitIndex(e, n, o) {
|
|
1479
|
-
let i,
|
|
1480
|
-
for (let
|
|
1481
|
-
const d = G(e, 0,
|
|
1482
|
-
|
|
1479
|
+
let i, s = 1 / 0, r = 1 / 0;
|
|
1480
|
+
for (let c = n; c <= o - n; c++) {
|
|
1481
|
+
const d = G(e, 0, c, this.toBBox), u = G(e, c, o, this.toBBox), f = Sn(d, u), h = pt(d) + pt(u);
|
|
1482
|
+
f < s ? (s = f, i = c, r = h < r ? h : r) : f === s && h < r && (r = h, i = c);
|
|
1483
1483
|
}
|
|
1484
1484
|
return i || o - n;
|
|
1485
1485
|
}
|
|
1486
1486
|
// sorts node children by the best axis for split
|
|
1487
1487
|
_chooseSplitAxis(e, n, o) {
|
|
1488
|
-
const i = e.leaf ? this.compareMinX : wn,
|
|
1489
|
-
|
|
1488
|
+
const i = e.leaf ? this.compareMinX : wn, s = e.leaf ? this.compareMinY : An, r = this._allDistMargin(e, n, o, i), c = this._allDistMargin(e, n, o, s);
|
|
1489
|
+
r < c && e.children.sort(i);
|
|
1490
1490
|
}
|
|
1491
1491
|
// total margin of all possible split distributions where each node is at least m full
|
|
1492
1492
|
_allDistMargin(e, n, o, i) {
|
|
1493
1493
|
e.children.sort(i);
|
|
1494
|
-
const
|
|
1495
|
-
let d = nt(
|
|
1494
|
+
const s = this.toBBox, r = G(e, 0, n, s), c = G(e, o - n, o, s);
|
|
1495
|
+
let d = nt(r) + nt(c);
|
|
1496
1496
|
for (let u = n; u < o - n; u++) {
|
|
1497
|
-
const
|
|
1498
|
-
K(
|
|
1497
|
+
const f = e.children[u];
|
|
1498
|
+
K(r, e.leaf ? s(f) : f), d += nt(r);
|
|
1499
1499
|
}
|
|
1500
1500
|
for (let u = o - n - 1; u >= n; u--) {
|
|
1501
|
-
const
|
|
1502
|
-
K(
|
|
1501
|
+
const f = e.children[u];
|
|
1502
|
+
K(c, e.leaf ? s(f) : f), d += nt(c);
|
|
1503
1503
|
}
|
|
1504
1504
|
return d;
|
|
1505
1505
|
}
|
|
@@ -1523,9 +1523,9 @@ function F(t, e) {
|
|
|
1523
1523
|
}
|
|
1524
1524
|
function G(t, e, n, o, i) {
|
|
1525
1525
|
i || (i = W(null)), i.minX = 1 / 0, i.minY = 1 / 0, i.maxX = -1 / 0, i.maxY = -1 / 0;
|
|
1526
|
-
for (let
|
|
1527
|
-
const
|
|
1528
|
-
K(i, t.leaf ? o(
|
|
1526
|
+
for (let s = e; s < n; s++) {
|
|
1527
|
+
const r = t.children[s];
|
|
1528
|
+
K(i, t.leaf ? o(r) : r);
|
|
1529
1529
|
}
|
|
1530
1530
|
return i;
|
|
1531
1531
|
}
|
|
@@ -1548,8 +1548,8 @@ function xn(t, e) {
|
|
|
1548
1548
|
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));
|
|
1549
1549
|
}
|
|
1550
1550
|
function Sn(t, e) {
|
|
1551
|
-
const n = Math.max(t.minX, e.minX), o = Math.max(t.minY, e.minY), i = Math.min(t.maxX, e.maxX),
|
|
1552
|
-
return Math.max(0, i - n) * Math.max(0,
|
|
1551
|
+
const n = Math.max(t.minX, e.minX), o = Math.max(t.minY, e.minY), i = Math.min(t.maxX, e.maxX), s = Math.min(t.maxY, e.maxY);
|
|
1552
|
+
return Math.max(0, i - n) * Math.max(0, s - o);
|
|
1553
1553
|
}
|
|
1554
1554
|
function mt(t, e) {
|
|
1555
1555
|
return t.minX <= e.minX && t.minY <= e.minY && e.maxX <= t.maxX && e.maxY <= t.maxY;
|
|
@@ -1569,20 +1569,20 @@ function W(t) {
|
|
|
1569
1569
|
};
|
|
1570
1570
|
}
|
|
1571
1571
|
function Vt(t, e, n, o, i) {
|
|
1572
|
-
const
|
|
1573
|
-
for (;
|
|
1574
|
-
if (n =
|
|
1575
|
-
const
|
|
1576
|
-
Wt(t,
|
|
1572
|
+
const s = [e, n];
|
|
1573
|
+
for (; s.length; ) {
|
|
1574
|
+
if (n = s.pop(), e = s.pop(), n - e <= o) continue;
|
|
1575
|
+
const r = e + Math.ceil((n - e) / o / 2) * o;
|
|
1576
|
+
Wt(t, r, e, n, i), s.push(e, r, r, n);
|
|
1577
1577
|
}
|
|
1578
1578
|
}
|
|
1579
1579
|
const En = (t, e) => {
|
|
1580
|
-
const n = new vn(), o = /* @__PURE__ */ new Map(), i = (l,
|
|
1581
|
-
const
|
|
1582
|
-
const E = H([L]) ? L.range :
|
|
1580
|
+
const n = new vn(), o = /* @__PURE__ */ new Map(), i = (l, a) => {
|
|
1581
|
+
const m = l.selector.flatMap((L) => {
|
|
1582
|
+
const E = H([L]) ? L.range : kt(L, e).range;
|
|
1583
1583
|
return Array.from(E.getClientRects());
|
|
1584
|
-
}),
|
|
1585
|
-
return
|
|
1584
|
+
}), S = re(m).map(({ left: L, top: E, right: T, bottom: R }) => new DOMRect(L - a.left, E - a.top, T - L, R - E));
|
|
1585
|
+
return S.map((L) => {
|
|
1586
1586
|
const { x: E, y: T, width: R, height: I } = L;
|
|
1587
1587
|
return {
|
|
1588
1588
|
minX: E,
|
|
@@ -1591,121 +1591,121 @@ const En = (t, e) => {
|
|
|
1591
1591
|
maxY: T + I,
|
|
1592
1592
|
annotation: {
|
|
1593
1593
|
id: l.annotation,
|
|
1594
|
-
rects:
|
|
1594
|
+
rects: S
|
|
1595
1595
|
}
|
|
1596
1596
|
};
|
|
1597
1597
|
});
|
|
1598
|
-
},
|
|
1598
|
+
}, s = () => [...o.values()], r = () => {
|
|
1599
1599
|
n.clear(), o.clear();
|
|
1600
|
-
},
|
|
1601
|
-
const
|
|
1602
|
-
|
|
1600
|
+
}, c = (l) => {
|
|
1601
|
+
const a = i(l, e.getBoundingClientRect());
|
|
1602
|
+
a.forEach((m) => n.insert(m)), o.set(l.annotation, a);
|
|
1603
1603
|
}, d = (l) => {
|
|
1604
|
-
const
|
|
1605
|
-
|
|
1604
|
+
const a = o.get(l.annotation);
|
|
1605
|
+
a && (a.forEach((m) => n.remove(m)), o.delete(l.annotation));
|
|
1606
1606
|
}, u = (l) => {
|
|
1607
|
-
d(l),
|
|
1608
|
-
},
|
|
1609
|
-
|
|
1610
|
-
const
|
|
1611
|
-
|
|
1612
|
-
const L =
|
|
1607
|
+
d(l), c(l);
|
|
1608
|
+
}, f = (l, a = !0) => {
|
|
1609
|
+
a && r();
|
|
1610
|
+
const m = e.getBoundingClientRect(), S = l.map((E) => ({ target: E, rects: i(E, m) }));
|
|
1611
|
+
S.forEach(({ target: E, rects: T }) => o.set(E.annotation, T));
|
|
1612
|
+
const L = S.flatMap(({ rects: E }) => E);
|
|
1613
1613
|
n.load(L);
|
|
1614
|
-
}, h = (l,
|
|
1615
|
-
const
|
|
1614
|
+
}, h = (l, a, m = !1) => {
|
|
1615
|
+
const S = n.search({
|
|
1616
1616
|
minX: l,
|
|
1617
|
-
minY:
|
|
1617
|
+
minY: a,
|
|
1618
1618
|
maxX: l,
|
|
1619
|
-
maxY:
|
|
1619
|
+
maxY: a
|
|
1620
1620
|
}), L = (E) => E.annotation.rects.reduce((T, R) => T + R.width * R.height, 0);
|
|
1621
|
-
return
|
|
1622
|
-
},
|
|
1623
|
-
const
|
|
1624
|
-
if (
|
|
1621
|
+
return S.length > 0 ? (S.sort((E, T) => L(E) - L(T)), m ? S.map((E) => E.annotation.id) : [S[0].annotation.id]) : [];
|
|
1622
|
+
}, y = (l) => {
|
|
1623
|
+
const a = g(l);
|
|
1624
|
+
if (a.length === 0)
|
|
1625
1625
|
return;
|
|
1626
|
-
let
|
|
1627
|
-
for (let T = 1; T <
|
|
1628
|
-
const R =
|
|
1629
|
-
|
|
1626
|
+
let m = a[0].left, S = a[0].top, L = a[0].right, E = a[0].bottom;
|
|
1627
|
+
for (let T = 1; T < a.length; T++) {
|
|
1628
|
+
const R = a[T];
|
|
1629
|
+
m = Math.min(m, R.left), S = Math.min(S, R.top), L = Math.max(L, R.right), E = Math.max(E, R.bottom);
|
|
1630
1630
|
}
|
|
1631
|
-
return new DOMRect(
|
|
1632
|
-
},
|
|
1633
|
-
const
|
|
1634
|
-
return
|
|
1631
|
+
return new DOMRect(m, S, L - m, E - S);
|
|
1632
|
+
}, g = (l) => {
|
|
1633
|
+
const a = o.get(l);
|
|
1634
|
+
return a ? a[0].annotation.rects : [];
|
|
1635
1635
|
};
|
|
1636
1636
|
return {
|
|
1637
|
-
all:
|
|
1638
|
-
clear:
|
|
1637
|
+
all: s,
|
|
1638
|
+
clear: r,
|
|
1639
1639
|
getAt: h,
|
|
1640
|
-
getAnnotationBounds:
|
|
1641
|
-
getAnnotationRects:
|
|
1642
|
-
getIntersecting: (l,
|
|
1643
|
-
const L = n.search({ minX: l, minY:
|
|
1640
|
+
getAnnotationBounds: y,
|
|
1641
|
+
getAnnotationRects: g,
|
|
1642
|
+
getIntersecting: (l, a, m, S) => {
|
|
1643
|
+
const L = n.search({ minX: l, minY: a, maxX: m, maxY: S }), E = new Set(L.map((T) => T.annotation.id));
|
|
1644
1644
|
return Array.from(E).map((T) => ({
|
|
1645
1645
|
annotation: t.getAnnotation(T),
|
|
1646
|
-
rects:
|
|
1646
|
+
rects: g(T)
|
|
1647
1647
|
})).filter((T) => !!T.annotation);
|
|
1648
1648
|
},
|
|
1649
|
-
insert:
|
|
1650
|
-
recalculate: () =>
|
|
1649
|
+
insert: c,
|
|
1650
|
+
recalculate: () => f(t.all().map((l) => l.target), !0),
|
|
1651
1651
|
remove: d,
|
|
1652
|
-
set:
|
|
1652
|
+
set: f,
|
|
1653
1653
|
size: () => n.all().length,
|
|
1654
1654
|
update: u
|
|
1655
1655
|
};
|
|
1656
1656
|
}, Cn = (t, e) => {
|
|
1657
|
-
const n = Ge(), o = En(n, t), i =
|
|
1657
|
+
const n = Ge(), o = En(n, t), i = _e(n);
|
|
1658
1658
|
i.setUserSelectAction(e);
|
|
1659
|
-
const
|
|
1660
|
-
const
|
|
1661
|
-
return
|
|
1662
|
-
}, d = (
|
|
1663
|
-
const
|
|
1664
|
-
return
|
|
1665
|
-
}, u = (
|
|
1666
|
-
const
|
|
1667
|
-
return
|
|
1668
|
-
n.getAnnotation(
|
|
1669
|
-
}),
|
|
1670
|
-
},
|
|
1671
|
-
const
|
|
1672
|
-
n.updateTarget(
|
|
1673
|
-
}, h = (
|
|
1674
|
-
const
|
|
1675
|
-
n.bulkUpdateTargets(
|
|
1676
|
-
},
|
|
1677
|
-
const
|
|
1678
|
-
return
|
|
1679
|
-
},
|
|
1680
|
-
const
|
|
1681
|
-
if (
|
|
1682
|
-
if (l &&
|
|
1683
|
-
const L =
|
|
1659
|
+
const s = Ve(n), r = Ze(), c = (p, l = M.LOCAL) => {
|
|
1660
|
+
const a = rt(p, t), m = H(a.target.selector);
|
|
1661
|
+
return m && n.addAnnotation(a, l), m;
|
|
1662
|
+
}, d = (p, l = !0, a = M.LOCAL) => {
|
|
1663
|
+
const m = p.map((L) => rt(L, t)), S = m.filter((L) => !H(L.target.selector));
|
|
1664
|
+
return S.length > 0 ? (console.warn("Could not revive all targets for these annotations:", S), n.bulkAddAnnotation(m, l, a), S) : (n.bulkAddAnnotation(m, l, a), []);
|
|
1665
|
+
}, u = (p, l = M.LOCAL) => {
|
|
1666
|
+
const a = p.map((S) => rt(S, t)), m = a.filter((S) => !H(S.target.selector));
|
|
1667
|
+
return m.length > 0 && console.warn("Could not revive all targets for these annotations:", m), a.forEach((S) => {
|
|
1668
|
+
n.getAnnotation(S.id) ? n.updateAnnotation(S, l) : n.addAnnotation(S, l);
|
|
1669
|
+
}), m;
|
|
1670
|
+
}, f = (p, l = M.LOCAL) => {
|
|
1671
|
+
const a = it(p, t);
|
|
1672
|
+
n.updateTarget(a, l);
|
|
1673
|
+
}, h = (p, l = M.LOCAL) => {
|
|
1674
|
+
const a = p.map((m) => it(m, t));
|
|
1675
|
+
n.bulkUpdateTargets(a, l);
|
|
1676
|
+
}, y = (p, l, a) => {
|
|
1677
|
+
const m = o.getAt(p, l, !!a).map((L) => n.getAnnotation(L)), S = a ? m.filter(a) : m;
|
|
1678
|
+
return S.length > 0 ? S[0] : void 0;
|
|
1679
|
+
}, g = (p, l, a, m = 5) => {
|
|
1680
|
+
const S = o.getAnnotationRects(p);
|
|
1681
|
+
if (S.length !== 0) {
|
|
1682
|
+
if (l && a) {
|
|
1683
|
+
const L = S.find(({ top: E, right: T, bottom: R, left: I }) => l >= I - m && l <= T + m && a >= E - m && a <= R + m);
|
|
1684
1684
|
if (L) return L;
|
|
1685
1685
|
}
|
|
1686
|
-
return o.getAnnotationBounds(
|
|
1686
|
+
return o.getAnnotationBounds(p);
|
|
1687
1687
|
}
|
|
1688
|
-
},
|
|
1689
|
-
return n.observe(({ changes:
|
|
1690
|
-
const l = (
|
|
1691
|
-
(l == null ? void 0 : l.length) > 0 && l.forEach((
|
|
1688
|
+
}, x = (p) => o.getAnnotationRects(p), v = () => o.recalculate();
|
|
1689
|
+
return n.observe(({ changes: p }) => {
|
|
1690
|
+
const l = (p.deleted || []).filter((S) => H(S.target.selector)), a = (p.created || []).filter((S) => H(S.target.selector)), m = (p.updated || []).filter((S) => H(S.newValue.target.selector));
|
|
1691
|
+
(l == null ? void 0 : l.length) > 0 && l.forEach((S) => o.remove(S.target)), a.length > 0 && o.set(a.map((S) => S.target), !1), (m == null ? void 0 : m.length) > 0 && m.forEach(({ newValue: S }) => o.update(S.target));
|
|
1692
1692
|
}), {
|
|
1693
1693
|
store: {
|
|
1694
1694
|
...n,
|
|
1695
|
-
addAnnotation:
|
|
1695
|
+
addAnnotation: c,
|
|
1696
1696
|
bulkAddAnnotation: d,
|
|
1697
1697
|
bulkUpdateTargets: h,
|
|
1698
1698
|
bulkUpsertAnnotations: u,
|
|
1699
|
-
getAnnotationBounds:
|
|
1700
|
-
getAnnotationRects:
|
|
1701
|
-
getAt:
|
|
1699
|
+
getAnnotationBounds: g,
|
|
1700
|
+
getAnnotationRects: x,
|
|
1701
|
+
getAt: y,
|
|
1702
1702
|
getIntersecting: o.getIntersecting,
|
|
1703
|
-
recalculatePositions:
|
|
1704
|
-
updateTarget:
|
|
1703
|
+
recalculatePositions: v,
|
|
1704
|
+
updateTarget: f
|
|
1705
1705
|
},
|
|
1706
1706
|
selection: i,
|
|
1707
|
-
hover:
|
|
1708
|
-
viewport:
|
|
1707
|
+
hover: s,
|
|
1708
|
+
viewport: r
|
|
1709
1709
|
};
|
|
1710
1710
|
}, Ln = () => {
|
|
1711
1711
|
const t = document.createElement("canvas");
|
|
@@ -1715,99 +1715,99 @@ const En = (t, e) => {
|
|
|
1715
1715
|
}, Tn = (t, e = {}) => {
|
|
1716
1716
|
const n = Ln(), o = n.getContext("2d");
|
|
1717
1717
|
document.body.appendChild(n);
|
|
1718
|
-
const i = /* @__PURE__ */ new Map(),
|
|
1719
|
-
return t.on("selectionChange", (
|
|
1720
|
-
|
|
1718
|
+
const i = /* @__PURE__ */ new Map(), s = (f) => Array.from(i.entries()).filter(([h, y]) => y.presenceKey === f.presenceKey).map(([h, y]) => h);
|
|
1719
|
+
return t.on("selectionChange", (f, h) => {
|
|
1720
|
+
s(f).forEach((g) => i.delete(g)), h && h.forEach((g) => i.set(g, f));
|
|
1721
1721
|
}), {
|
|
1722
1722
|
clear: () => {
|
|
1723
|
-
const { width:
|
|
1724
|
-
o.clearRect(-0.5, -0.5,
|
|
1723
|
+
const { width: f, height: h } = n;
|
|
1724
|
+
o.clearRect(-0.5, -0.5, f + 1, h + 1);
|
|
1725
1725
|
},
|
|
1726
1726
|
destroy: () => {
|
|
1727
1727
|
n.remove();
|
|
1728
1728
|
},
|
|
1729
|
-
paint: (
|
|
1729
|
+
paint: (f, h, y) => {
|
|
1730
1730
|
e.font && (o.font = e.font);
|
|
1731
|
-
const
|
|
1732
|
-
if (
|
|
1733
|
-
const { height:
|
|
1734
|
-
o.fillStyle =
|
|
1735
|
-
const l = o.measureText(
|
|
1736
|
-
return o.fillRect(
|
|
1737
|
-
fill:
|
|
1738
|
-
fillOpacity:
|
|
1731
|
+
const g = i.get(f.annotation.id);
|
|
1732
|
+
if (g) {
|
|
1733
|
+
const { height: x } = f.rects[0], v = f.rects[0].x + h.left, p = f.rects[0].y + h.top;
|
|
1734
|
+
o.fillStyle = g.appearance.color, o.fillRect(v - 2, p - 2.5, 2, x + 5);
|
|
1735
|
+
const l = o.measureText(g.appearance.label), a = l.width + 6, m = l.actualBoundingBoxAscent + l.actualBoundingBoxDescent + 8, S = l.fontBoundingBoxAscent ? 8 : 6.5;
|
|
1736
|
+
return o.fillRect(v - 2, p - 2.5 - m, a, m), o.fillStyle = "#fff", o.fillText(g.appearance.label, v + 1, p - S), {
|
|
1737
|
+
fill: g.appearance.color,
|
|
1738
|
+
fillOpacity: y ? 0.45 : 0.18
|
|
1739
1739
|
};
|
|
1740
1740
|
}
|
|
1741
1741
|
},
|
|
1742
1742
|
reset: () => {
|
|
1743
1743
|
n.width = 2 * window.innerWidth, n.height = 2 * window.innerHeight;
|
|
1744
|
-
const
|
|
1745
|
-
|
|
1744
|
+
const f = n.getContext("2d");
|
|
1745
|
+
f.scale(2, 2), f.translate(0.5, 0.5);
|
|
1746
1746
|
}
|
|
1747
1747
|
};
|
|
1748
1748
|
}, Rn = (t, e, n, o) => {
|
|
1749
1749
|
let i;
|
|
1750
|
-
const
|
|
1751
|
-
let
|
|
1752
|
-
const
|
|
1753
|
-
let
|
|
1754
|
-
const
|
|
1755
|
-
var
|
|
1750
|
+
const s = (a) => i = a;
|
|
1751
|
+
let r;
|
|
1752
|
+
const c = (a) => r = a, { store: d, selection: u } = e;
|
|
1753
|
+
let f, h = !1, y;
|
|
1754
|
+
const g = (a) => {
|
|
1755
|
+
var S;
|
|
1756
1756
|
if (!h) return;
|
|
1757
|
-
!((
|
|
1757
|
+
!((S = a.target.parentElement) != null && S.closest(X)) ? f = {
|
|
1758
1758
|
annotation: Pt(),
|
|
1759
1759
|
selector: [],
|
|
1760
1760
|
creator: i,
|
|
1761
1761
|
created: /* @__PURE__ */ new Date()
|
|
1762
|
-
} :
|
|
1763
|
-
},
|
|
1764
|
-
var
|
|
1765
|
-
const
|
|
1766
|
-
if (!!((A = (
|
|
1767
|
-
|
|
1762
|
+
} : f = void 0;
|
|
1763
|
+
}, x = yt((a) => {
|
|
1764
|
+
var b, A;
|
|
1765
|
+
const m = document.getSelection();
|
|
1766
|
+
if (!!((A = (b = m.anchorNode) == null ? void 0 : b.parentElement) != null && A.closest(X))) {
|
|
1767
|
+
f = void 0;
|
|
1768
1768
|
return;
|
|
1769
1769
|
}
|
|
1770
|
-
if (
|
|
1771
|
-
const E =
|
|
1770
|
+
if (a.timeStamp - ((y == null ? void 0 : y.timeStamp) || a.timeStamp) < 1e3 && !f && g(y), m.isCollapsed || !h || !f) return;
|
|
1771
|
+
const E = m.getRangeAt(0), T = ce(E, t);
|
|
1772
1772
|
if (oe(T)) return;
|
|
1773
1773
|
const R = Zt(T.cloneRange());
|
|
1774
|
-
(R.length !==
|
|
1774
|
+
(R.length !== f.selector.length || R.some((w, C) => {
|
|
1775
1775
|
var O;
|
|
1776
|
-
return w.toString() !== ((O =
|
|
1777
|
-
})) && (
|
|
1778
|
-
...
|
|
1776
|
+
return w.toString() !== ((O = f.selector[C]) == null ? void 0 : O.quote);
|
|
1777
|
+
})) && (f = {
|
|
1778
|
+
...f,
|
|
1779
1779
|
selector: R.map((w) => ae(w, t, o)),
|
|
1780
1780
|
updated: /* @__PURE__ */ new Date()
|
|
1781
|
-
}, d.getAnnotation(
|
|
1782
|
-
id:
|
|
1781
|
+
}, d.getAnnotation(f.annotation) ? d.updateTarget(f, M.LOCAL) : (u.clear(), d.addAnnotation({
|
|
1782
|
+
id: f.annotation,
|
|
1783
1783
|
bodies: [],
|
|
1784
|
-
target:
|
|
1785
|
-
}), u.userSelect(
|
|
1786
|
-
}),
|
|
1787
|
-
const { target:
|
|
1788
|
-
|
|
1789
|
-
},
|
|
1784
|
+
target: f
|
|
1785
|
+
}), u.userSelect(f.annotation, y)));
|
|
1786
|
+
}), v = (a) => {
|
|
1787
|
+
const { target: m, timeStamp: S, offsetX: L, offsetY: E, type: T } = a;
|
|
1788
|
+
y = { ...a, target: m, timeStamp: S, offsetX: L, offsetY: E, type: T }, h = a.button === 0;
|
|
1789
|
+
}, p = (a) => {
|
|
1790
1790
|
var E;
|
|
1791
|
-
if (!!((E =
|
|
1791
|
+
if (!!((E = a.target.parentElement) != null && E.closest(X)) || !h)
|
|
1792
1792
|
return;
|
|
1793
|
-
const
|
|
1794
|
-
const { x: T, y: R } = t.getBoundingClientRect(), I =
|
|
1793
|
+
const S = () => {
|
|
1794
|
+
const { x: T, y: R } = t.getBoundingClientRect(), I = a.target instanceof Node && t.contains(a.target) && d.getAt(a.clientX - T, a.clientY - R, r);
|
|
1795
1795
|
if (I) {
|
|
1796
|
-
const { selected:
|
|
1797
|
-
(
|
|
1796
|
+
const { selected: b } = u;
|
|
1797
|
+
(b.length !== 1 || b[0].id !== I.id) && u.userSelect(I.id, a);
|
|
1798
1798
|
} else u.isEmpty() || u.clear();
|
|
1799
|
-
}, L =
|
|
1799
|
+
}, L = a.timeStamp - y.timeStamp;
|
|
1800
1800
|
setTimeout(() => {
|
|
1801
1801
|
const T = document.getSelection();
|
|
1802
|
-
T != null && T.isCollapsed && L < 300 ? (
|
|
1802
|
+
T != null && T.isCollapsed && L < 300 ? (f = void 0, S()) : f && u.userSelect(f.annotation, a);
|
|
1803
1803
|
});
|
|
1804
1804
|
};
|
|
1805
|
-
return t.addEventListener("pointerdown",
|
|
1805
|
+
return t.addEventListener("pointerdown", v), document.addEventListener("pointerup", p), n && (t.addEventListener("selectstart", g), document.addEventListener("selectionchange", x)), {
|
|
1806
1806
|
destroy: () => {
|
|
1807
|
-
t.removeEventListener("pointerdown",
|
|
1807
|
+
t.removeEventListener("pointerdown", v), document.removeEventListener("pointerup", p), t.removeEventListener("selectstart", g), document.removeEventListener("selectionchange", x);
|
|
1808
1808
|
},
|
|
1809
|
-
setFilter:
|
|
1810
|
-
setUser:
|
|
1809
|
+
setFilter: c,
|
|
1810
|
+
setUser: s
|
|
1811
1811
|
};
|
|
1812
1812
|
}, Bn = (t, e) => ({
|
|
1813
1813
|
...t,
|
|
@@ -1818,26 +1818,26 @@ const En = (t, e) => {
|
|
|
1818
1818
|
const n = Bn(e, {
|
|
1819
1819
|
annotatingEnabled: !0,
|
|
1820
1820
|
user: ln()
|
|
1821
|
-
}), o = Cn(t, n.userSelectAction), { selection: i, viewport:
|
|
1821
|
+
}), o = Cn(t, n.userSelectAction), { selection: i, viewport: s } = o, r = o.store, c = Je(r), d = tn(o, c, n.adapter);
|
|
1822
1822
|
let u = n.user;
|
|
1823
|
-
const
|
|
1823
|
+
const f = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : Dt : n.renderer || Dt, h = f === "SPANS" ? Be(t, o, s) : f === "CSS_HIGHLIGHTS" ? Le(t, o, s) : f === "CANVAS" ? me(t, o, s) : void 0;
|
|
1824
1824
|
if (!h)
|
|
1825
|
-
throw `Unknown renderer implementation: ${
|
|
1826
|
-
console.debug(`Using ${
|
|
1827
|
-
const
|
|
1828
|
-
return
|
|
1829
|
-
...nn(o,
|
|
1825
|
+
throw `Unknown renderer implementation: ${f}`;
|
|
1826
|
+
console.debug(`Using ${f} renderer`), n.style && h.setStyle(n.style);
|
|
1827
|
+
const y = Rn(t, o, n.annotatingEnabled, n.offsetReferenceSelector);
|
|
1828
|
+
return y.setUser(u), {
|
|
1829
|
+
...nn(o, c, n.adapter),
|
|
1830
1830
|
destroy: () => {
|
|
1831
|
-
h.destroy(),
|
|
1831
|
+
h.destroy(), y.destroy(), c.destroy();
|
|
1832
1832
|
},
|
|
1833
1833
|
element: t,
|
|
1834
1834
|
getUser: () => u,
|
|
1835
1835
|
setFilter: (E) => {
|
|
1836
|
-
h.setFilter(E),
|
|
1836
|
+
h.setFilter(E), y.setFilter(E);
|
|
1837
1837
|
},
|
|
1838
1838
|
setStyle: (E) => h.setStyle(E),
|
|
1839
1839
|
setUser: (E) => {
|
|
1840
|
-
u = E,
|
|
1840
|
+
u = E, y.setUser(E);
|
|
1841
1841
|
},
|
|
1842
1842
|
setSelected: (E) => {
|
|
1843
1843
|
E ? i.setSelected(E) : i.clear();
|
|
@@ -1848,14 +1848,14 @@ const En = (t, e) => {
|
|
|
1848
1848
|
setVisible: (E) => h.setVisible(E),
|
|
1849
1849
|
on: d.on,
|
|
1850
1850
|
off: d.off,
|
|
1851
|
-
scrollIntoView: le(t,
|
|
1851
|
+
scrollIntoView: le(t, r),
|
|
1852
1852
|
state: o
|
|
1853
1853
|
};
|
|
1854
1854
|
};
|
|
1855
1855
|
export {
|
|
1856
|
-
|
|
1856
|
+
st as DEFAULT_SELECTED_STYLE,
|
|
1857
1857
|
P as DEFAULT_STYLE,
|
|
1858
|
-
|
|
1858
|
+
_t as NOT_ANNOTATABLE_CLASS,
|
|
1859
1859
|
X as NOT_ANNOTATABLE_SELECTOR,
|
|
1860
1860
|
M as Origin,
|
|
1861
1861
|
Rn as SelectionHandler,
|
|
@@ -1877,12 +1877,12 @@ export {
|
|
|
1877
1877
|
bt as getRangeAnnotatableContents,
|
|
1878
1878
|
H as isRevived,
|
|
1879
1879
|
oe as isWhitespaceOrEmpty,
|
|
1880
|
-
|
|
1880
|
+
re as mergeClientRects,
|
|
1881
1881
|
de as paint,
|
|
1882
1882
|
pn as parseW3CTextAnnotation,
|
|
1883
1883
|
ae as rangeToSelector,
|
|
1884
|
-
|
|
1885
|
-
|
|
1884
|
+
rt as reviveAnnotation,
|
|
1885
|
+
kt as reviveSelector,
|
|
1886
1886
|
it as reviveTarget,
|
|
1887
1887
|
le as scrollIntoView,
|
|
1888
1888
|
mn as serializeW3CTextAnnotation,
|