@recogito/text-annotator 3.0.0-rc.46 → 3.0.0-rc.47
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/utils/cloneEvents.d.ts +11 -0
- package/dist/src/utils/device.d.ts +1 -0
- package/dist/src/utils/index.d.ts +3 -0
- package/dist/src/utils/programmaticallyFocusable.d.ts +6 -0
- package/dist/text-annotator.css +1 -1
- package/dist/text-annotator.es.js +1478 -1036
- package/dist/text-annotator.es.js.map +1 -1
- package/dist/text-annotator.umd.js +2 -2
- package/dist/text-annotator.umd.js.map +1 -1
- package/package.json +6 -5
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
const
|
|
1
|
+
const ce = "not-annotatable", H = `.${ce}`, Le = (t) => {
|
|
2
2
|
var n;
|
|
3
3
|
const e = t.commonAncestorContainer;
|
|
4
|
-
return e instanceof HTMLElement ? !e.closest(
|
|
5
|
-
},
|
|
4
|
+
return e instanceof HTMLElement ? !e.closest(H) : !((n = e.parentElement) != null && n.closest(H));
|
|
5
|
+
}, Te = function* (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(ce) && !o.parentElement.closest(H) && t.intersectsNode(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
|
|
10
10
|
);
|
|
11
11
|
let n;
|
|
12
12
|
for (; n = e.nextNode(); )
|
|
13
13
|
n instanceof HTMLElement && (yield n);
|
|
14
|
-
},
|
|
15
|
-
if (!
|
|
14
|
+
}, Oe = (t) => {
|
|
15
|
+
if (!Le(t)) return [];
|
|
16
16
|
const e = [];
|
|
17
17
|
let n = null;
|
|
18
|
-
for (const o of
|
|
18
|
+
for (const o of Te(t)) {
|
|
19
19
|
let i;
|
|
20
20
|
n ? (i = document.createRange(), i.setStartAfter(n), i.setEndBefore(o)) : (i = t.cloneRange(), i.setEndBefore(o)), i.collapsed || e.push(i), n = o;
|
|
21
21
|
}
|
|
@@ -24,33 +24,33 @@ const _t = "not-annotatable", X = `.${_t}`, Qt = (t) => {
|
|
|
24
24
|
o.setStartAfter(n), o.collapsed || e.push(o);
|
|
25
25
|
}
|
|
26
26
|
return e.length > 0 ? e : [t];
|
|
27
|
-
},
|
|
27
|
+
}, Vt = (t) => {
|
|
28
28
|
const e = t.cloneContents();
|
|
29
|
-
return e.querySelectorAll(
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
},
|
|
29
|
+
return e.querySelectorAll(H).forEach((n) => n.remove()), e;
|
|
30
|
+
}, Me = (t) => t.addEventListener("click", (e) => {
|
|
31
|
+
// Allow clicks within not-annotatable elements
|
|
32
|
+
!e.target.closest(H) && !e.target.closest("a") && e.preventDefault();
|
|
33
|
+
}), Re = /mac/i.test(navigator.userAgentData ? navigator.userAgentData.platform : navigator.platform), Be = (t) => {
|
|
34
|
+
!t.hasAttribute("tabindex") && t.tabIndex < 0 && t.setAttribute("tabindex", "-1"), t.classList.add("no-focus-outline");
|
|
35
|
+
}, Dt = (t, e = 10) => {
|
|
36
36
|
let n;
|
|
37
37
|
return (...o) => {
|
|
38
38
|
clearTimeout(n), n = setTimeout(() => t.apply(void 0, o), e);
|
|
39
39
|
};
|
|
40
|
-
},
|
|
40
|
+
}, vo = (t) => {
|
|
41
41
|
const e = t.cloneContents();
|
|
42
|
-
return e.querySelectorAll(
|
|
43
|
-
},
|
|
42
|
+
return e.querySelectorAll(H).forEach((n) => n.remove()), e;
|
|
43
|
+
}, ke = (t, e, n = 10, o) => {
|
|
44
44
|
const i = o ? t.startContainer.parentElement.closest(o) : e, s = document.createRange();
|
|
45
45
|
s.setStart(i, 0), s.setEnd(t.startContainer, t.startOffset);
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
const
|
|
46
|
+
const a = Vt(s).textContent, r = document.createRange();
|
|
47
|
+
r.setStart(t.endContainer, t.endOffset), i === document.body ? r.setEnd(i, i.childNodes.length) : r.setEndAfter(i);
|
|
48
|
+
const l = Vt(r).textContent;
|
|
49
49
|
return {
|
|
50
|
-
prefix:
|
|
51
|
-
suffix:
|
|
50
|
+
prefix: a.substring(a.length - n),
|
|
51
|
+
suffix: l.substring(0, n)
|
|
52
52
|
};
|
|
53
|
-
},
|
|
53
|
+
}, Ie = /^\s*$/, _e = (t) => Ie.test(t.toString()), W = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), Ne = (t, e) => {
|
|
54
54
|
const n = (s) => Math.round(s * 10) / 10, o = {
|
|
55
55
|
top: n(t.top),
|
|
56
56
|
bottom: n(t.bottom),
|
|
@@ -74,347 +74,389 @@ const _t = "not-annotatable", X = `.${_t}`, 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
|
-
},
|
|
77
|
+
}, Ue = (t, e) => {
|
|
78
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
79
|
return new DOMRect(n, i, o - n, s - i);
|
|
80
|
-
},
|
|
80
|
+
}, Ve = (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
84
|
for (const s of e) {
|
|
85
|
-
const
|
|
86
|
-
if (
|
|
87
|
-
o = o.map((
|
|
85
|
+
const a = Ne(n, s);
|
|
86
|
+
if (a === "inline-adjacent") {
|
|
87
|
+
o = o.map((r) => r === s ? Ue(n, s) : r), i = !0;
|
|
88
88
|
break;
|
|
89
|
-
} else if (
|
|
90
|
-
o = o.map((
|
|
89
|
+
} else if (a === "inline-contains") {
|
|
90
|
+
o = o.map((r) => r === s ? n : r), i = !0;
|
|
91
91
|
break;
|
|
92
|
-
} else if (
|
|
92
|
+
} else if (a === "inline-is-contained") {
|
|
93
93
|
i = !0;
|
|
94
94
|
break;
|
|
95
|
-
} else if (
|
|
96
|
-
n.width < s.width && (o = o.map((
|
|
95
|
+
} else if (a === "block-contains" || a === "block-is-contained") {
|
|
96
|
+
n.width < s.width && (o = o.map((r) => r === s ? n : r)), i = !0;
|
|
97
97
|
break;
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
return i ? o : [...o, n];
|
|
101
|
-
}, []),
|
|
101
|
+
}, []), Ke = (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 s =
|
|
105
|
-
return n ? { quote:
|
|
106
|
-
},
|
|
107
|
-
var
|
|
104
|
+
const s = Vt(o).textContent, a = t.toString(), r = s.length || 0, l = r + a.length;
|
|
105
|
+
return n ? { quote: a, start: r, end: l, range: t, offsetReference: i } : { quote: a, start: r, end: l, range: t };
|
|
106
|
+
}, le = (t, e) => {
|
|
107
|
+
var u, h;
|
|
108
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
|
+
(g) => {
|
|
112
|
+
var p;
|
|
113
|
+
return (p = g.parentElement) != null && p.closest(H) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
|
|
114
114
|
}
|
|
115
115
|
);
|
|
116
|
-
let
|
|
117
|
-
const
|
|
118
|
-
let
|
|
119
|
-
|
|
120
|
-
let
|
|
121
|
-
for (;
|
|
122
|
-
if (
|
|
123
|
-
const
|
|
124
|
-
if (
|
|
125
|
-
|
|
116
|
+
let a = 0;
|
|
117
|
+
const r = document.createRange();
|
|
118
|
+
let l = s.nextNode();
|
|
119
|
+
l === null && console.error("Could not revive annotation target. Content missing.");
|
|
120
|
+
let f = !i;
|
|
121
|
+
for (; l !== null; ) {
|
|
122
|
+
if (f || (f = i == null ? void 0 : i.contains(l)), f) {
|
|
123
|
+
const g = ((u = l.textContent) == null ? void 0 : u.length) || 0;
|
|
124
|
+
if (a + g > n) {
|
|
125
|
+
r.setStart(l, n - a);
|
|
126
126
|
break;
|
|
127
127
|
}
|
|
128
|
-
|
|
128
|
+
a += g;
|
|
129
129
|
}
|
|
130
|
-
|
|
130
|
+
l = s.nextNode();
|
|
131
131
|
}
|
|
132
|
-
for (;
|
|
133
|
-
const
|
|
134
|
-
if (
|
|
135
|
-
|
|
132
|
+
for (; l !== null; ) {
|
|
133
|
+
const g = ((h = l.textContent) == null ? void 0 : h.length) || 0;
|
|
134
|
+
if (a + g >= o) {
|
|
135
|
+
r.setEnd(l, o - a);
|
|
136
136
|
break;
|
|
137
137
|
}
|
|
138
|
-
|
|
138
|
+
a += g, l = s.nextNode();
|
|
139
139
|
}
|
|
140
140
|
return {
|
|
141
141
|
...t,
|
|
142
|
-
range:
|
|
142
|
+
range: r
|
|
143
143
|
};
|
|
144
|
-
},
|
|
144
|
+
}, wt = (t, e) => W(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 : le(n, e))
|
|
147
|
+
}, xt = (t, e) => W(t.target.selector) ? t : { ...t, target: wt(t.target, e) }, Ye = (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
|
+
}, Et = (t) => ({
|
|
151
|
+
...t,
|
|
152
|
+
type: t.type,
|
|
153
|
+
x: t.x,
|
|
154
|
+
y: t.y,
|
|
155
|
+
clientX: t.clientX,
|
|
156
|
+
clientY: t.clientY,
|
|
157
|
+
offsetX: t.offsetX,
|
|
158
|
+
offsetY: t.offsetY,
|
|
159
|
+
screenX: t.screenX,
|
|
160
|
+
screenY: t.screenY,
|
|
161
|
+
isPrimary: t.isPrimary,
|
|
162
|
+
altKey: t.altKey,
|
|
163
|
+
ctrlKey: t.ctrlKey,
|
|
164
|
+
metaKey: t.metaKey,
|
|
165
|
+
shiftKey: t.shiftKey,
|
|
166
|
+
button: t.button,
|
|
167
|
+
buttons: t.buttons,
|
|
168
|
+
currentTarget: t.currentTarget,
|
|
169
|
+
target: t.target,
|
|
170
|
+
defaultPrevented: t.defaultPrevented,
|
|
171
|
+
detail: t.detail,
|
|
172
|
+
eventPhase: t.eventPhase,
|
|
173
|
+
pointerId: t.pointerId,
|
|
174
|
+
pointerType: t.pointerType,
|
|
175
|
+
timeStamp: t.timeStamp
|
|
176
|
+
}), ut = (t) => ({
|
|
177
|
+
...t,
|
|
178
|
+
type: t.type,
|
|
179
|
+
key: t.key,
|
|
180
|
+
code: t.code,
|
|
181
|
+
location: t.location,
|
|
182
|
+
repeat: t.repeat,
|
|
183
|
+
altKey: t.altKey,
|
|
184
|
+
ctrlKey: t.ctrlKey,
|
|
185
|
+
metaKey: t.metaKey,
|
|
186
|
+
shiftKey: t.shiftKey,
|
|
187
|
+
currentTarget: t.currentTarget,
|
|
188
|
+
target: t.target,
|
|
189
|
+
defaultPrevented: t.defaultPrevented,
|
|
190
|
+
detail: t.detail,
|
|
191
|
+
timeStamp: t.timeStamp
|
|
192
|
+
}), de = (t) => {
|
|
151
193
|
if (t === null)
|
|
152
194
|
return document.scrollingElement;
|
|
153
195
|
const { overflowY: e } = window.getComputedStyle(t);
|
|
154
|
-
return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t :
|
|
155
|
-
},
|
|
156
|
-
const o = typeof n == "string" ? n : n.id, i = (
|
|
157
|
-
const
|
|
158
|
-
s.scroll({ top:
|
|
159
|
-
}, s =
|
|
196
|
+
return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : de(t.parentElement);
|
|
197
|
+
}, De = (t, e) => (n) => {
|
|
198
|
+
const o = typeof n == "string" ? n : n.id, i = (a) => {
|
|
199
|
+
const r = s.getBoundingClientRect(), l = s.clientHeight, f = s.clientWidth, u = a.selector[0].range.getBoundingClientRect(), { width: h, height: g } = e.getAnnotationBounds(o), p = u.top - r.top, v = u.left - r.left, y = s.parentElement ? s.scrollTop : 0, m = s.parentElement ? s.scrollLeft : 0, d = p + y - (l - g) / 2, c = v + m - (f - h) / 2;
|
|
200
|
+
s.scroll({ top: d, left: c, behavior: "smooth" });
|
|
201
|
+
}, s = de(t);
|
|
160
202
|
if (s) {
|
|
161
|
-
const
|
|
162
|
-
if (
|
|
163
|
-
return i(
|
|
203
|
+
const a = e.getAnnotation(o), { range: r } = a.target.selector[0];
|
|
204
|
+
if (r && !r.collapsed)
|
|
205
|
+
return i(a.target), !0;
|
|
164
206
|
{
|
|
165
|
-
const
|
|
166
|
-
if (
|
|
167
|
-
return i(
|
|
207
|
+
const l = wt(a.target, t), { range: f } = l.selector[0];
|
|
208
|
+
if (f && !f.collapsed)
|
|
209
|
+
return i(l), !0;
|
|
168
210
|
}
|
|
169
211
|
}
|
|
170
212
|
return !1;
|
|
171
|
-
},
|
|
213
|
+
}, q = {
|
|
172
214
|
fill: "rgb(0, 128, 255)",
|
|
173
215
|
fillOpacity: 0.18
|
|
174
|
-
},
|
|
216
|
+
}, vt = {
|
|
175
217
|
fill: "rgb(0, 128, 255)",
|
|
176
218
|
fillOpacity: 0.45
|
|
177
|
-
},
|
|
178
|
-
var
|
|
179
|
-
const s = n ? typeof n == "function" ? n(t.annotation, t.state, i) || ((
|
|
219
|
+
}, Xe = (t, e, n, o, i) => {
|
|
220
|
+
var a, r;
|
|
221
|
+
const s = n ? typeof n == "function" ? n(t.annotation, t.state, i) || ((a = t.state) != null && a.selected ? vt : q) : n : (r = t.state) != null && r.selected ? vt : q;
|
|
180
222
|
return o && o.paint(t, e) || s;
|
|
181
|
-
},
|
|
182
|
-
const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: o, innerHeight: i } = window, s = -n,
|
|
183
|
-
return { top: e, left: n, minX: s, minY:
|
|
184
|
-
},
|
|
223
|
+
}, Pe = (t) => {
|
|
224
|
+
const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: o, innerHeight: i } = window, s = -n, a = -e, r = o - n, l = i - e;
|
|
225
|
+
return { top: e, left: n, minX: s, minY: a, maxX: r, maxY: l };
|
|
226
|
+
}, $e = (t) => {
|
|
185
227
|
let e = /* @__PURE__ */ new Set();
|
|
186
228
|
return (o) => {
|
|
187
229
|
const i = o.map((s) => s.id);
|
|
188
230
|
(e.size !== i.length || i.some((s) => !e.has(s))) && t.set(i), e = new Set(i);
|
|
189
231
|
};
|
|
190
|
-
},
|
|
191
|
-
const { store: i, selection: s, hover:
|
|
192
|
-
let
|
|
193
|
-
const
|
|
194
|
-
const { x:
|
|
195
|
-
|
|
232
|
+
}, Xt = (t, e, n, o) => {
|
|
233
|
+
const { store: i, selection: s, hover: a } = e;
|
|
234
|
+
let r, l, f;
|
|
235
|
+
const u = $e(n), h = (E) => {
|
|
236
|
+
const { x: R, y: b } = t.getBoundingClientRect(), x = i.getAt(E.clientX - R, E.clientY - b, l);
|
|
237
|
+
x ? a.current !== x.id && (t.classList.add("hovered"), a.set(x.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
|
|
196
238
|
};
|
|
197
239
|
t.addEventListener("pointermove", h);
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
const
|
|
201
|
-
const
|
|
202
|
-
return { annotation:
|
|
240
|
+
const g = (E = !1) => {
|
|
241
|
+
f && f.clear();
|
|
242
|
+
const R = Pe(t), { minX: b, minY: x, maxX: A, maxY: C } = R, B = l ? i.getIntersecting(b, x, A, C).filter(({ annotation: D }) => l(D)) : i.getIntersecting(b, x, A, C), M = s.selected.map(({ id: D }) => D), N = B.map(({ annotation: D, rects: tt }) => {
|
|
243
|
+
const At = M.includes(D.id), dt = D.id === a.current;
|
|
244
|
+
return { annotation: D, rects: tt, state: { selected: At, hover: dt } };
|
|
203
245
|
});
|
|
204
|
-
o.redraw(
|
|
205
|
-
},
|
|
206
|
-
|
|
207
|
-
},
|
|
208
|
-
|
|
209
|
-
},
|
|
210
|
-
|
|
211
|
-
},
|
|
212
|
-
i.observe(
|
|
213
|
-
const
|
|
214
|
-
document.addEventListener("scroll",
|
|
215
|
-
const
|
|
216
|
-
i.recalculatePositions(),
|
|
246
|
+
o.redraw(N, R, r, f, E), setTimeout(() => u(B.map(({ annotation: D }) => D)), 1);
|
|
247
|
+
}, p = (E) => {
|
|
248
|
+
f = E, g();
|
|
249
|
+
}, v = (E) => {
|
|
250
|
+
r = E, g();
|
|
251
|
+
}, y = (E) => {
|
|
252
|
+
l = E, g(!1);
|
|
253
|
+
}, m = () => g();
|
|
254
|
+
i.observe(m);
|
|
255
|
+
const d = s.subscribe(() => g()), c = () => g(!0);
|
|
256
|
+
document.addEventListener("scroll", c, { capture: !0, passive: !0 });
|
|
257
|
+
const w = Dt(() => {
|
|
258
|
+
i.recalculatePositions(), f && f.reset(), g();
|
|
217
259
|
});
|
|
218
|
-
window.addEventListener("resize",
|
|
219
|
-
const S = new ResizeObserver(
|
|
260
|
+
window.addEventListener("resize", w);
|
|
261
|
+
const S = new ResizeObserver(w);
|
|
220
262
|
S.observe(t);
|
|
221
|
-
const
|
|
222
|
-
|
|
263
|
+
const T = { attributes: !0, childList: !0, subtree: !0 }, L = new MutationObserver((E) => {
|
|
264
|
+
E.every((b) => b.target === t || t.contains(b.target)) || g(!0);
|
|
223
265
|
});
|
|
224
|
-
return
|
|
266
|
+
return L.observe(document.body, T), {
|
|
225
267
|
destroy: () => {
|
|
226
|
-
t.removeEventListener("pointermove", h), o.destroy(), i.unobserve(
|
|
268
|
+
t.removeEventListener("pointermove", h), o.destroy(), i.unobserve(m), d(), document.removeEventListener("scroll", c), window.removeEventListener("resize", w), S.disconnect(), L.disconnect();
|
|
227
269
|
},
|
|
228
|
-
redraw:
|
|
229
|
-
setStyle:
|
|
230
|
-
setFilter:
|
|
231
|
-
setPainter:
|
|
270
|
+
redraw: g,
|
|
271
|
+
setStyle: v,
|
|
272
|
+
setFilter: y,
|
|
273
|
+
setPainter: p,
|
|
232
274
|
setVisible: o.setVisible
|
|
233
275
|
};
|
|
234
|
-
},
|
|
276
|
+
}, He = () => {
|
|
235
277
|
const t = document.createElement("canvas");
|
|
236
278
|
return t.width = window.innerWidth, t.height = window.innerHeight, t.className = "r6o-canvas-highlight-layer bg", t;
|
|
237
|
-
},
|
|
279
|
+
}, je = (t, e) => {
|
|
238
280
|
t.width = window.innerWidth, t.height = window.innerHeight;
|
|
239
|
-
},
|
|
281
|
+
}, ze = (t) => {
|
|
240
282
|
t.classList.add("r6o-annotatable");
|
|
241
|
-
const e =
|
|
283
|
+
const e = He(), n = e.getContext("2d");
|
|
242
284
|
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((
|
|
285
|
+
const o = (r, l, f, u) => requestAnimationFrame(() => {
|
|
286
|
+
const { width: h, height: g } = e;
|
|
287
|
+
n.clearRect(-0.5, -0.5, h + 1, g + 1), u && u.clear();
|
|
288
|
+
const { top: p, left: v } = l;
|
|
289
|
+
[...r].sort((m, d) => {
|
|
290
|
+
const { annotation: { target: { created: c } } } = m, { annotation: { target: { created: w } } } = d;
|
|
291
|
+
return c.getTime() - w.getTime();
|
|
292
|
+
}).forEach((m) => {
|
|
251
293
|
var S;
|
|
252
|
-
const
|
|
253
|
-
x:
|
|
254
|
-
y:
|
|
255
|
-
width:
|
|
256
|
-
height:
|
|
294
|
+
const d = f ? typeof f == "function" ? f(m.annotation, m.state) : f : (S = m.state) != null && S.selected ? vt : q, c = u && u.paint(m, l) || d, w = m.rects.map(({ x: T, y: L, width: O, height: E }) => ({
|
|
295
|
+
x: T + v,
|
|
296
|
+
y: L + p,
|
|
297
|
+
width: O,
|
|
298
|
+
height: E
|
|
257
299
|
}));
|
|
258
|
-
if (n.fillStyle =
|
|
259
|
-
({ x:
|
|
260
|
-
),
|
|
261
|
-
n.globalAlpha = 1, n.strokeStyle =
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
n.beginPath(), n.moveTo(
|
|
300
|
+
if (n.fillStyle = c.fill, n.globalAlpha = c.fillOpacity || 1, w.forEach(
|
|
301
|
+
({ x: T, y: L, width: O, height: E }) => n.fillRect(T, L, O, E)
|
|
302
|
+
), c.underlineColor) {
|
|
303
|
+
n.globalAlpha = 1, n.strokeStyle = c.underlineColor, n.lineWidth = c.underlineThickness ?? 1;
|
|
304
|
+
const T = c.underlineOffset ?? 0;
|
|
305
|
+
w.forEach(({ x: L, y: O, width: E, height: R }) => {
|
|
306
|
+
n.beginPath(), n.moveTo(L, O + R + T), n.lineTo(L + E, O + R + T), n.stroke();
|
|
265
307
|
});
|
|
266
308
|
}
|
|
267
309
|
});
|
|
268
|
-
}), i =
|
|
269
|
-
|
|
310
|
+
}), i = Dt(() => {
|
|
311
|
+
je(e);
|
|
270
312
|
});
|
|
271
313
|
return window.addEventListener("resize", i), {
|
|
272
314
|
destroy: () => {
|
|
273
315
|
e.remove(), window.removeEventListener("resize", i);
|
|
274
316
|
},
|
|
275
|
-
setVisible: (
|
|
317
|
+
setVisible: (r) => {
|
|
276
318
|
console.log("setVisible not implemented on Canvas renderer");
|
|
277
319
|
},
|
|
278
320
|
redraw: o
|
|
279
321
|
};
|
|
280
|
-
},
|
|
281
|
-
var
|
|
322
|
+
}, Fe = (t, e, n) => Xt(t, e, n, ze(t));
|
|
323
|
+
var We = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, z = function(t) {
|
|
282
324
|
return typeof t == "string" ? t.length > 0 : typeof t == "number";
|
|
283
|
-
},
|
|
325
|
+
}, U = function(t, e, n) {
|
|
284
326
|
return e === void 0 && (e = 0), n === void 0 && (n = Math.pow(10, e)), Math.round(n * t) / n + 0;
|
|
285
|
-
},
|
|
327
|
+
}, X = function(t, e, n) {
|
|
286
328
|
return e === void 0 && (e = 0), n === void 0 && (n = 1), t > n ? n : t > e ? t : e;
|
|
287
|
-
},
|
|
329
|
+
}, ue = function(t) {
|
|
288
330
|
return (t = isFinite(t) ? t % 360 : 0) > 0 ? t : t + 360;
|
|
289
|
-
},
|
|
290
|
-
return { r:
|
|
291
|
-
},
|
|
292
|
-
return { r:
|
|
293
|
-
},
|
|
331
|
+
}, Ht = function(t) {
|
|
332
|
+
return { r: X(t.r, 0, 255), g: X(t.g, 0, 255), b: X(t.b, 0, 255), a: X(t.a) };
|
|
333
|
+
}, St = function(t) {
|
|
334
|
+
return { r: U(t.r), g: U(t.g), b: U(t.b), a: U(t.a, 3) };
|
|
335
|
+
}, qe = /^#([0-9a-f]{3,8})$/i, ft = function(t) {
|
|
294
336
|
var e = t.toString(16);
|
|
295
337
|
return e.length < 2 ? "0" + e : e;
|
|
296
|
-
},
|
|
297
|
-
var e = t.r, n = t.g, o = t.b, i = t.a, s = Math.max(e, n, o),
|
|
298
|
-
return { h: 60 * (
|
|
299
|
-
},
|
|
338
|
+
}, fe = function(t) {
|
|
339
|
+
var e = t.r, n = t.g, o = t.b, i = t.a, s = Math.max(e, n, o), a = s - Math.min(e, n, o), r = a ? s === e ? (n - o) / a : s === n ? 2 + (o - e) / a : 4 + (e - n) / a : 0;
|
|
340
|
+
return { h: 60 * (r < 0 ? r + 6 : r), s: s ? a / s * 100 : 0, v: s / 255 * 100, a: i };
|
|
341
|
+
}, he = function(t) {
|
|
300
342
|
var e = t.h, n = t.s, o = t.v, i = t.a;
|
|
301
343
|
e = e / 360 * 6, n /= 100, o /= 100;
|
|
302
|
-
var s = Math.floor(e),
|
|
303
|
-
return { r: 255 * [o,
|
|
304
|
-
},
|
|
305
|
-
return { h:
|
|
306
|
-
},
|
|
307
|
-
return { h:
|
|
308
|
-
},
|
|
309
|
-
return
|
|
344
|
+
var s = Math.floor(e), a = o * (1 - n), r = o * (1 - (e - s) * n), l = o * (1 - (1 - e + s) * n), f = s % 6;
|
|
345
|
+
return { r: 255 * [o, r, a, a, l, o][f], g: 255 * [l, o, o, r, a, a][f], b: 255 * [a, a, l, o, o, r][f], a: i };
|
|
346
|
+
}, jt = function(t) {
|
|
347
|
+
return { h: ue(t.h), s: X(t.s, 0, 100), l: X(t.l, 0, 100), a: X(t.a) };
|
|
348
|
+
}, zt = function(t) {
|
|
349
|
+
return { h: U(t.h), s: U(t.s), l: U(t.l), a: U(t.a, 3) };
|
|
350
|
+
}, Ft = function(t) {
|
|
351
|
+
return he((n = (e = t).s, { h: e.h, s: (n *= ((o = e.l) < 50 ? o : 100 - o) / 100) > 0 ? 2 * n / (o + n) * 100 : 0, v: o + n, a: e.a }));
|
|
310
352
|
var e, n, o;
|
|
311
|
-
},
|
|
312
|
-
return { h: (e =
|
|
353
|
+
}, st = function(t) {
|
|
354
|
+
return { h: (e = fe(t)).h, s: (i = (200 - (n = e.s)) * (o = e.v) / 100) > 0 && i < 200 ? n * o / 100 / (i <= 100 ? i : 200 - i) * 100 : 0, l: i / 2, a: e.a };
|
|
313
355
|
var e, n, o, i;
|
|
314
|
-
},
|
|
315
|
-
var e =
|
|
316
|
-
return e ? (t = e[1]).length <= 4 ? { r: parseInt(t[0] + t[0], 16), g: parseInt(t[1] + t[1], 16), b: parseInt(t[2] + t[2], 16), a: t.length === 4 ?
|
|
356
|
+
}, Ge = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Qe = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Je = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Ze = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Wt = { string: [[function(t) {
|
|
357
|
+
var e = qe.exec(t);
|
|
358
|
+
return e ? (t = e[1]).length <= 4 ? { r: parseInt(t[0] + t[0], 16), g: parseInt(t[1] + t[1], 16), b: parseInt(t[2] + t[2], 16), a: t.length === 4 ? U(parseInt(t[3] + t[3], 16) / 255, 2) : 1 } : t.length === 6 || t.length === 8 ? { r: parseInt(t.substr(0, 2), 16), g: parseInt(t.substr(2, 2), 16), b: parseInt(t.substr(4, 2), 16), a: t.length === 8 ? U(parseInt(t.substr(6, 2), 16) / 255, 2) : 1 } : null : null;
|
|
317
359
|
}, "hex"], [function(t) {
|
|
318
|
-
var e =
|
|
319
|
-
return e ? e[2] !== e[4] || e[4] !== e[6] ? null :
|
|
360
|
+
var e = Je.exec(t) || Ze.exec(t);
|
|
361
|
+
return e ? e[2] !== e[4] || e[4] !== e[6] ? null : Ht({ r: Number(e[1]) / (e[2] ? 100 / 255 : 1), g: Number(e[3]) / (e[4] ? 100 / 255 : 1), b: Number(e[5]) / (e[6] ? 100 / 255 : 1), a: e[7] === void 0 ? 1 : Number(e[7]) / (e[8] ? 100 : 1) }) : null;
|
|
320
362
|
}, "rgb"], [function(t) {
|
|
321
|
-
var e =
|
|
363
|
+
var e = Ge.exec(t) || Qe.exec(t);
|
|
322
364
|
if (!e) return null;
|
|
323
|
-
var n, o, i =
|
|
324
|
-
return
|
|
365
|
+
var n, o, i = jt({ h: (n = e[1], o = e[2], o === void 0 && (o = "deg"), Number(n) * (We[o] || 1)), s: Number(e[3]), l: Number(e[4]), a: e[5] === void 0 ? 1 : Number(e[5]) / (e[6] ? 100 : 1) });
|
|
366
|
+
return Ft(i);
|
|
325
367
|
}, "hsl"]], object: [[function(t) {
|
|
326
368
|
var e = t.r, n = t.g, o = t.b, i = t.a, s = i === void 0 ? 1 : i;
|
|
327
|
-
return
|
|
369
|
+
return z(e) && z(n) && z(o) ? Ht({ r: Number(e), g: Number(n), b: Number(o), a: Number(s) }) : null;
|
|
328
370
|
}, "rgb"], [function(t) {
|
|
329
371
|
var e = t.h, n = t.s, o = t.l, i = t.a, s = i === void 0 ? 1 : i;
|
|
330
|
-
if (
|
|
331
|
-
var
|
|
332
|
-
return
|
|
372
|
+
if (!z(e) || !z(n) || !z(o)) return null;
|
|
373
|
+
var a = jt({ h: Number(e), s: Number(n), l: Number(o), a: Number(s) });
|
|
374
|
+
return Ft(a);
|
|
333
375
|
}, "hsl"], [function(t) {
|
|
334
376
|
var e = t.h, n = t.s, o = t.v, i = t.a, s = i === void 0 ? 1 : i;
|
|
335
|
-
if (
|
|
336
|
-
var
|
|
337
|
-
return { h:
|
|
377
|
+
if (!z(e) || !z(n) || !z(o)) return null;
|
|
378
|
+
var a = function(r) {
|
|
379
|
+
return { h: ue(r.h), s: X(r.s, 0, 100), v: X(r.v, 0, 100), a: X(r.a) };
|
|
338
380
|
}({ h: Number(e), s: Number(n), v: Number(o), a: Number(s) });
|
|
339
|
-
return
|
|
340
|
-
}, "hsv"]] },
|
|
381
|
+
return he(a);
|
|
382
|
+
}, "hsv"]] }, qt = function(t, e) {
|
|
341
383
|
for (var n = 0; n < e.length; n++) {
|
|
342
384
|
var o = e[n][0](t);
|
|
343
385
|
if (o) return [o, e[n][1]];
|
|
344
386
|
}
|
|
345
387
|
return [null, void 0];
|
|
346
|
-
},
|
|
347
|
-
return typeof t == "string" ?
|
|
348
|
-
},
|
|
349
|
-
var n =
|
|
350
|
-
return { h: n.h, s:
|
|
351
|
-
},
|
|
388
|
+
}, tn = function(t) {
|
|
389
|
+
return typeof t == "string" ? qt(t.trim(), Wt.string) : typeof t == "object" && t !== null ? qt(t, Wt.object) : [null, void 0];
|
|
390
|
+
}, Ct = function(t, e) {
|
|
391
|
+
var n = st(t);
|
|
392
|
+
return { h: n.h, s: X(n.s + 100 * e, 0, 100), l: n.l, a: n.a };
|
|
393
|
+
}, Lt = function(t) {
|
|
352
394
|
return (299 * t.r + 587 * t.g + 114 * t.b) / 1e3 / 255;
|
|
353
|
-
},
|
|
354
|
-
var n =
|
|
355
|
-
return { h: n.h, s: n.s, l:
|
|
356
|
-
},
|
|
395
|
+
}, Gt = function(t, e) {
|
|
396
|
+
var n = st(t);
|
|
397
|
+
return { h: n.h, s: n.s, l: X(n.l + 100 * e, 0, 100), a: n.a };
|
|
398
|
+
}, Qt = function() {
|
|
357
399
|
function t(e) {
|
|
358
|
-
this.parsed =
|
|
400
|
+
this.parsed = tn(e)[0], this.rgba = this.parsed || { r: 0, g: 0, b: 0, a: 1 };
|
|
359
401
|
}
|
|
360
402
|
return t.prototype.isValid = function() {
|
|
361
403
|
return this.parsed !== null;
|
|
362
404
|
}, t.prototype.brightness = function() {
|
|
363
|
-
return
|
|
405
|
+
return U(Lt(this.rgba), 2);
|
|
364
406
|
}, t.prototype.isDark = function() {
|
|
365
|
-
return
|
|
407
|
+
return Lt(this.rgba) < 0.5;
|
|
366
408
|
}, t.prototype.isLight = function() {
|
|
367
|
-
return
|
|
409
|
+
return Lt(this.rgba) >= 0.5;
|
|
368
410
|
}, t.prototype.toHex = function() {
|
|
369
|
-
return e =
|
|
370
|
-
var e, n, o, i, s,
|
|
411
|
+
return e = St(this.rgba), n = e.r, o = e.g, i = e.b, a = (s = e.a) < 1 ? ft(U(255 * s)) : "", "#" + ft(n) + ft(o) + ft(i) + a;
|
|
412
|
+
var e, n, o, i, s, a;
|
|
371
413
|
}, t.prototype.toRgb = function() {
|
|
372
|
-
return
|
|
414
|
+
return St(this.rgba);
|
|
373
415
|
}, t.prototype.toRgbString = function() {
|
|
374
|
-
return e =
|
|
416
|
+
return e = St(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
417
|
var e, n, o, i, s;
|
|
376
418
|
}, t.prototype.toHsl = function() {
|
|
377
|
-
return
|
|
419
|
+
return zt(st(this.rgba));
|
|
378
420
|
}, t.prototype.toHslString = function() {
|
|
379
|
-
return e =
|
|
421
|
+
return e = zt(st(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
422
|
var e, n, o, i, s;
|
|
381
423
|
}, t.prototype.toHsv = function() {
|
|
382
|
-
return e =
|
|
424
|
+
return e = fe(this.rgba), { h: U(e.h), s: U(e.s), v: U(e.v), a: U(e.a, 3) };
|
|
383
425
|
var e;
|
|
384
426
|
}, t.prototype.invert = function() {
|
|
385
|
-
return
|
|
427
|
+
return $({ r: 255 - (e = this.rgba).r, g: 255 - e.g, b: 255 - e.b, a: e.a });
|
|
386
428
|
var e;
|
|
387
429
|
}, t.prototype.saturate = function(e) {
|
|
388
|
-
return e === void 0 && (e = 0.1),
|
|
430
|
+
return e === void 0 && (e = 0.1), $(Ct(this.rgba, e));
|
|
389
431
|
}, t.prototype.desaturate = function(e) {
|
|
390
|
-
return e === void 0 && (e = 0.1),
|
|
432
|
+
return e === void 0 && (e = 0.1), $(Ct(this.rgba, -e));
|
|
391
433
|
}, t.prototype.grayscale = function() {
|
|
392
|
-
return
|
|
434
|
+
return $(Ct(this.rgba, -1));
|
|
393
435
|
}, t.prototype.lighten = function(e) {
|
|
394
|
-
return e === void 0 && (e = 0.1),
|
|
436
|
+
return e === void 0 && (e = 0.1), $(Gt(this.rgba, e));
|
|
395
437
|
}, t.prototype.darken = function(e) {
|
|
396
|
-
return e === void 0 && (e = 0.1),
|
|
438
|
+
return e === void 0 && (e = 0.1), $(Gt(this.rgba, -e));
|
|
397
439
|
}, t.prototype.rotate = function(e) {
|
|
398
440
|
return e === void 0 && (e = 15), this.hue(this.hue() + e);
|
|
399
441
|
}, t.prototype.alpha = function(e) {
|
|
400
|
-
return typeof e == "number" ?
|
|
442
|
+
return typeof e == "number" ? $({ r: (n = this.rgba).r, g: n.g, b: n.b, a: e }) : U(this.rgba.a, 3);
|
|
401
443
|
var n;
|
|
402
444
|
}, t.prototype.hue = function(e) {
|
|
403
|
-
var n =
|
|
404
|
-
return typeof e == "number" ?
|
|
445
|
+
var n = st(this.rgba);
|
|
446
|
+
return typeof e == "number" ? $({ h: e, s: n.s, l: n.l, a: n.a }) : U(n.h);
|
|
405
447
|
}, t.prototype.isEqual = function(e) {
|
|
406
|
-
return this.toHex() ===
|
|
448
|
+
return this.toHex() === $(e).toHex();
|
|
407
449
|
}, t;
|
|
408
|
-
}(),
|
|
409
|
-
return t instanceof
|
|
450
|
+
}(), $ = function(t) {
|
|
451
|
+
return t instanceof Qt ? t : new Qt(t);
|
|
410
452
|
};
|
|
411
|
-
const
|
|
412
|
-
`background-color:${
|
|
453
|
+
const en = (t) => [
|
|
454
|
+
`background-color:${$((t == null ? void 0 : t.fill) || q.fill).alpha((t == null ? void 0 : t.fillOpacity) === void 0 ? q.fillOpacity : t.fillOpacity).toHex()}`,
|
|
413
455
|
t != null && t.underlineThickness ? "text-decoration:underline" : void 0,
|
|
414
456
|
t != null && t.underlineColor ? `text-decoration-color:${t.underlineColor}` : void 0,
|
|
415
457
|
t != null && t.underlineOffset ? `text-underline-offset:${t.underlineOffset}px` : void 0,
|
|
416
458
|
t != null && t.underlineThickness ? `text-decoration-thickness:${t.underlineThickness}px` : void 0
|
|
417
|
-
].filter(Boolean).join(";"),
|
|
459
|
+
].filter(Boolean).join(";"), nn = () => {
|
|
418
460
|
const t = document.createElement("style");
|
|
419
461
|
document.getElementsByTagName("head")[0].appendChild(t);
|
|
420
462
|
let e = /* @__PURE__ */ new Set();
|
|
@@ -425,25 +467,25 @@ const Ee = (t) => [
|
|
|
425
467
|
setVisible: (s) => {
|
|
426
468
|
console.log("setVisible not implemented on CSS Custom Highlights renderer");
|
|
427
469
|
},
|
|
428
|
-
redraw: (s,
|
|
429
|
-
|
|
430
|
-
const
|
|
431
|
-
Array.from(e).filter((h) => !
|
|
432
|
-
const
|
|
433
|
-
var
|
|
434
|
-
const
|
|
435
|
-
return `::highlight(_${h.annotation.id}) { ${
|
|
470
|
+
redraw: (s, a, r, l) => {
|
|
471
|
+
l && l.clear();
|
|
472
|
+
const f = new Set(s.map((h) => h.annotation.id));
|
|
473
|
+
Array.from(e).filter((h) => !f.has(h));
|
|
474
|
+
const u = s.map((h) => {
|
|
475
|
+
var v;
|
|
476
|
+
const g = r ? typeof r == "function" ? r(h.annotation, h.state) : r : (v = h.state) != null && v.selected ? vt : q, p = l && l.paint(h, a) || g;
|
|
477
|
+
return `::highlight(_${h.annotation.id}) { ${en(p)} }`;
|
|
436
478
|
});
|
|
437
|
-
t.innerHTML =
|
|
479
|
+
t.innerHTML = u.join(`
|
|
438
480
|
`), CSS.highlights.clear(), s.forEach(({ annotation: h }) => {
|
|
439
|
-
const
|
|
440
|
-
CSS.highlights.set(`_${h.id}`,
|
|
441
|
-
}), e =
|
|
481
|
+
const g = h.target.selector.map((v) => v.range), p = new Highlight(...g);
|
|
482
|
+
CSS.highlights.set(`_${h.id}`, p);
|
|
483
|
+
}), e = f;
|
|
442
484
|
}
|
|
443
485
|
};
|
|
444
|
-
},
|
|
445
|
-
var
|
|
446
|
-
function
|
|
486
|
+
}, on = (t, e, n) => Xt(t, e, n, nn());
|
|
487
|
+
var Jt = Object.prototype.hasOwnProperty;
|
|
488
|
+
function Kt(t, e) {
|
|
447
489
|
var n, o;
|
|
448
490
|
if (t === e) return !0;
|
|
449
491
|
if (t && e && (n = t.constructor) === e.constructor) {
|
|
@@ -451,22 +493,22 @@ function vt(t, e) {
|
|
|
451
493
|
if (n === RegExp) return t.toString() === e.toString();
|
|
452
494
|
if (n === Array) {
|
|
453
495
|
if ((o = t.length) === e.length)
|
|
454
|
-
for (; o-- &&
|
|
496
|
+
for (; o-- && Kt(t[o], e[o]); ) ;
|
|
455
497
|
return o === -1;
|
|
456
498
|
}
|
|
457
499
|
if (!n || typeof t == "object") {
|
|
458
500
|
o = 0;
|
|
459
501
|
for (n in t)
|
|
460
|
-
if (
|
|
502
|
+
if (Jt.call(t, n) && ++o && !Jt.call(e, n) || !(n in e) || !Kt(t[n], e[n])) return !1;
|
|
461
503
|
return Object.keys(e).length === o;
|
|
462
504
|
}
|
|
463
505
|
}
|
|
464
506
|
return t !== t && e !== e;
|
|
465
507
|
}
|
|
466
|
-
const
|
|
467
|
-
const n = (s,
|
|
468
|
-
return i.sort((s,
|
|
469
|
-
},
|
|
508
|
+
const sn = (t, e) => {
|
|
509
|
+
const n = (s, a) => s.x <= a.x + a.width && s.x + s.width >= a.x && s.y <= a.y + a.height && s.y + s.height >= a.y, o = (s) => s.rects.reduce((a, r) => a + r.width, 0), i = e.filter(({ rects: s }) => s.some((a) => n(t, a)));
|
|
510
|
+
return i.sort((s, a) => o(a) - o(s)), i.findIndex((s) => s.rects.includes(t));
|
|
511
|
+
}, rn = (t) => {
|
|
470
512
|
t.classList.add("r6o-annotatable");
|
|
471
513
|
const e = document.createElement("div");
|
|
472
514
|
e.className = "r6o-span-highlight-layer", t.insertBefore(e, t.firstChild);
|
|
@@ -475,52 +517,52 @@ const Te = (t, e) => {
|
|
|
475
517
|
destroy: () => {
|
|
476
518
|
e.remove();
|
|
477
519
|
},
|
|
478
|
-
redraw: (r,
|
|
479
|
-
const
|
|
480
|
-
if (!
|
|
481
|
-
|
|
482
|
-
const { annotation: { target: { created:
|
|
483
|
-
return
|
|
484
|
-
}).forEach((
|
|
485
|
-
|
|
486
|
-
const
|
|
487
|
-
if (
|
|
488
|
-
const
|
|
489
|
-
|
|
520
|
+
redraw: (a, r, l, f, u) => {
|
|
521
|
+
const g = !(Kt(n, a) && u);
|
|
522
|
+
if (!f && !g) return;
|
|
523
|
+
g && (e.innerHTML = ""), [...a].sort((v, y) => {
|
|
524
|
+
const { annotation: { target: { created: m } } } = v, { annotation: { target: { created: d } } } = y;
|
|
525
|
+
return m && d ? m.getTime() - d.getTime() : 0;
|
|
526
|
+
}).forEach((v) => {
|
|
527
|
+
v.rects.map((y) => {
|
|
528
|
+
const m = sn(y, a), d = Xe(v, r, l, f, m);
|
|
529
|
+
if (g) {
|
|
530
|
+
const c = document.createElement("span");
|
|
531
|
+
c.className = "r6o-annotation", c.dataset.annotation = v.annotation.id, c.style.left = `${y.x}px`, c.style.top = `${y.y}px`, c.style.width = `${y.width}px`, c.style.height = `${y.height}px`, c.style.backgroundColor = $((d == null ? void 0 : d.fill) || q.fill).alpha((d == null ? void 0 : d.fillOpacity) === void 0 ? q.fillOpacity : d.fillOpacity).toHex(), d.underlineStyle && (c.style.borderStyle = d.underlineStyle), d.underlineColor && (c.style.borderColor = d.underlineColor), d.underlineThickness && (c.style.borderBottomWidth = `${d.underlineThickness}px`), d.underlineOffset && (c.style.paddingBottom = `${d.underlineOffset}px`), e.appendChild(c);
|
|
490
532
|
}
|
|
491
533
|
});
|
|
492
|
-
}), n =
|
|
534
|
+
}), n = a;
|
|
493
535
|
},
|
|
494
|
-
setVisible: (
|
|
495
|
-
|
|
536
|
+
setVisible: (a) => {
|
|
537
|
+
a ? e.classList.remove("hidden") : e.classList.add("hidden");
|
|
496
538
|
}
|
|
497
539
|
};
|
|
498
|
-
},
|
|
499
|
-
var
|
|
500
|
-
for (var
|
|
501
|
-
|
|
502
|
-
function
|
|
503
|
-
return (
|
|
540
|
+
}, an = (t, e, n) => Xt(t, e, n, rn(t));
|
|
541
|
+
var V = [];
|
|
542
|
+
for (var Tt = 0; Tt < 256; ++Tt)
|
|
543
|
+
V.push((Tt + 256).toString(16).slice(1));
|
|
544
|
+
function cn(t, e = 0) {
|
|
545
|
+
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();
|
|
504
546
|
}
|
|
505
|
-
var
|
|
506
|
-
function
|
|
507
|
-
if (!
|
|
547
|
+
var ht, ln = new Uint8Array(16);
|
|
548
|
+
function dn() {
|
|
549
|
+
if (!ht && (ht = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !ht))
|
|
508
550
|
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
509
|
-
return
|
|
551
|
+
return ht(ln);
|
|
510
552
|
}
|
|
511
|
-
var
|
|
512
|
-
const
|
|
513
|
-
randomUUID:
|
|
553
|
+
var un = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
554
|
+
const Zt = {
|
|
555
|
+
randomUUID: un
|
|
514
556
|
};
|
|
515
|
-
function
|
|
516
|
-
if (
|
|
517
|
-
return
|
|
557
|
+
function pe(t, e, n) {
|
|
558
|
+
if (Zt.randomUUID && !e && !t)
|
|
559
|
+
return Zt.randomUUID();
|
|
518
560
|
t = t || {};
|
|
519
|
-
var o = t.random || (t.rng ||
|
|
520
|
-
return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128,
|
|
561
|
+
var o = t.random || (t.rng || dn)();
|
|
562
|
+
return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, cn(o);
|
|
521
563
|
}
|
|
522
|
-
var
|
|
523
|
-
function
|
|
564
|
+
var te = Object.prototype.hasOwnProperty;
|
|
565
|
+
function G(t, e) {
|
|
524
566
|
var n, o;
|
|
525
567
|
if (t === e) return !0;
|
|
526
568
|
if (t && e && (n = t.constructor) === e.constructor) {
|
|
@@ -528,57 +570,57 @@ function j(t, e) {
|
|
|
528
570
|
if (n === RegExp) return t.toString() === e.toString();
|
|
529
571
|
if (n === Array) {
|
|
530
572
|
if ((o = t.length) === e.length)
|
|
531
|
-
for (; o-- &&
|
|
573
|
+
for (; o-- && G(t[o], e[o]); ) ;
|
|
532
574
|
return o === -1;
|
|
533
575
|
}
|
|
534
576
|
if (!n || typeof t == "object") {
|
|
535
577
|
o = 0;
|
|
536
578
|
for (n in t)
|
|
537
|
-
if (
|
|
579
|
+
if (te.call(t, n) && ++o && !te.call(e, n) || !(n in e) || !G(t[n], e[n])) return !1;
|
|
538
580
|
return Object.keys(e).length === o;
|
|
539
581
|
}
|
|
540
582
|
}
|
|
541
583
|
return t !== t && e !== e;
|
|
542
584
|
}
|
|
543
|
-
function
|
|
585
|
+
function Ot() {
|
|
544
586
|
}
|
|
545
|
-
function
|
|
587
|
+
function fn(t, e) {
|
|
546
588
|
return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function";
|
|
547
589
|
}
|
|
548
|
-
const
|
|
549
|
-
function
|
|
590
|
+
const Q = [];
|
|
591
|
+
function Pt(t, e = Ot) {
|
|
550
592
|
let n;
|
|
551
593
|
const o = /* @__PURE__ */ new Set();
|
|
552
|
-
function i(
|
|
553
|
-
if (
|
|
554
|
-
const
|
|
555
|
-
for (const
|
|
556
|
-
|
|
557
|
-
if (
|
|
558
|
-
for (let
|
|
559
|
-
|
|
560
|
-
|
|
594
|
+
function i(r) {
|
|
595
|
+
if (fn(t, r) && (t = r, n)) {
|
|
596
|
+
const l = !Q.length;
|
|
597
|
+
for (const f of o)
|
|
598
|
+
f[1](), Q.push(f, t);
|
|
599
|
+
if (l) {
|
|
600
|
+
for (let f = 0; f < Q.length; f += 2)
|
|
601
|
+
Q[f][0](Q[f + 1]);
|
|
602
|
+
Q.length = 0;
|
|
561
603
|
}
|
|
562
604
|
}
|
|
563
605
|
}
|
|
564
|
-
function s(
|
|
565
|
-
i(
|
|
606
|
+
function s(r) {
|
|
607
|
+
i(r(t));
|
|
566
608
|
}
|
|
567
|
-
function r
|
|
568
|
-
const
|
|
569
|
-
return o.add(
|
|
570
|
-
o.delete(
|
|
609
|
+
function a(r, l = Ot) {
|
|
610
|
+
const f = [r, l];
|
|
611
|
+
return o.add(f), o.size === 1 && (n = e(i, s) || Ot), r(t), () => {
|
|
612
|
+
o.delete(f), o.size === 0 && n && (n(), n = null);
|
|
571
613
|
};
|
|
572
614
|
}
|
|
573
|
-
return { set: i, update: s, subscribe:
|
|
615
|
+
return { set: i, update: s, subscribe: a };
|
|
574
616
|
}
|
|
575
|
-
const
|
|
576
|
-
const { subscribe: e, set: n } =
|
|
617
|
+
const hn = (t) => {
|
|
618
|
+
const { subscribe: e, set: n } = Pt();
|
|
577
619
|
let o;
|
|
578
620
|
return e((i) => o = i), t.observe(({ changes: i }) => {
|
|
579
621
|
if (o) {
|
|
580
|
-
(i.deleted || []).some((
|
|
581
|
-
const s = (i.updated || []).find(({ oldValue:
|
|
622
|
+
(i.deleted || []).some((a) => a.id === o) && n(void 0);
|
|
623
|
+
const s = (i.updated || []).find(({ oldValue: a }) => a.id === o);
|
|
582
624
|
s && n(s.newValue.id);
|
|
583
625
|
}
|
|
584
626
|
}), {
|
|
@@ -589,96 +631,96 @@ const Ve = (t) => {
|
|
|
589
631
|
set: n
|
|
590
632
|
};
|
|
591
633
|
};
|
|
592
|
-
var
|
|
593
|
-
const
|
|
594
|
-
const { subscribe: o, set: i } =
|
|
595
|
-
let s = e,
|
|
596
|
-
o((
|
|
597
|
-
const
|
|
598
|
-
|
|
599
|
-
},
|
|
600
|
-
var
|
|
601
|
-
return ((
|
|
602
|
-
},
|
|
603
|
-
if (
|
|
634
|
+
var pn = /* @__PURE__ */ ((t) => (t.EDIT = "EDIT", t.SELECT = "SELECT", t.NONE = "NONE", t))(pn || {});
|
|
635
|
+
const pt = { selected: [] }, gn = (t, e, n) => {
|
|
636
|
+
const { subscribe: o, set: i } = Pt(pt);
|
|
637
|
+
let s = e, a = pt;
|
|
638
|
+
o((v) => a = v);
|
|
639
|
+
const r = () => {
|
|
640
|
+
G(a, pt) || i(pt);
|
|
641
|
+
}, l = () => {
|
|
642
|
+
var v;
|
|
643
|
+
return ((v = a.selected) == null ? void 0 : v.length) === 0;
|
|
644
|
+
}, f = (v) => {
|
|
645
|
+
if (l())
|
|
604
646
|
return !1;
|
|
605
|
-
const
|
|
606
|
-
return
|
|
607
|
-
},
|
|
608
|
-
const
|
|
609
|
-
if (!
|
|
610
|
-
console.warn("Invalid selection: " +
|
|
647
|
+
const y = typeof v == "string" ? v : v.id;
|
|
648
|
+
return a.selected.some((m) => m.id === y);
|
|
649
|
+
}, u = (v, y) => {
|
|
650
|
+
const m = t.getAnnotation(v);
|
|
651
|
+
if (!m) {
|
|
652
|
+
console.warn("Invalid selection: " + v);
|
|
611
653
|
return;
|
|
612
654
|
}
|
|
613
|
-
switch (
|
|
655
|
+
switch (ee(m, s)) {
|
|
614
656
|
case "EDIT":
|
|
615
|
-
i({ selected: [{ id:
|
|
657
|
+
i({ selected: [{ id: v, editable: !0 }], event: y });
|
|
616
658
|
break;
|
|
617
659
|
case "SELECT":
|
|
618
|
-
i({ selected: [{ id:
|
|
660
|
+
i({ selected: [{ id: v }], event: y });
|
|
619
661
|
break;
|
|
620
662
|
default:
|
|
621
|
-
i({ selected: [], event:
|
|
663
|
+
i({ selected: [], event: y });
|
|
622
664
|
}
|
|
623
|
-
}, h = (
|
|
624
|
-
const
|
|
665
|
+
}, h = (v, y) => {
|
|
666
|
+
const m = Array.isArray(v) ? v : [v], d = m.map((c) => t.getAnnotation(c)).filter((c) => !!c);
|
|
625
667
|
i({
|
|
626
|
-
selected:
|
|
627
|
-
const
|
|
628
|
-
return { id:
|
|
668
|
+
selected: d.map((c) => {
|
|
669
|
+
const w = y === void 0 ? ee(c, s) === "EDIT" : y;
|
|
670
|
+
return { id: c.id, editable: w };
|
|
629
671
|
})
|
|
630
|
-
}),
|
|
631
|
-
},
|
|
632
|
-
if (
|
|
672
|
+
}), d.length !== m.length && console.warn("Invalid selection", v);
|
|
673
|
+
}, g = (v) => {
|
|
674
|
+
if (l())
|
|
633
675
|
return !1;
|
|
634
|
-
const { selected:
|
|
635
|
-
|
|
636
|
-
},
|
|
676
|
+
const { selected: y } = a;
|
|
677
|
+
y.some(({ id: m }) => v.includes(m)) && i({ selected: y.filter(({ id: m }) => !v.includes(m)) });
|
|
678
|
+
}, p = (v) => s = v;
|
|
637
679
|
return t.observe(
|
|
638
|
-
({ changes:
|
|
680
|
+
({ changes: v }) => g((v.deleted || []).map((y) => y.id))
|
|
639
681
|
), {
|
|
640
682
|
get event() {
|
|
641
|
-
return
|
|
683
|
+
return a ? a.event : null;
|
|
642
684
|
},
|
|
643
685
|
get selected() {
|
|
644
|
-
return
|
|
686
|
+
return a ? [...a.selected] : null;
|
|
645
687
|
},
|
|
646
688
|
get userSelectAction() {
|
|
647
689
|
return s;
|
|
648
690
|
},
|
|
649
|
-
clear:
|
|
650
|
-
isEmpty:
|
|
651
|
-
isSelected:
|
|
691
|
+
clear: r,
|
|
692
|
+
isEmpty: l,
|
|
693
|
+
isSelected: f,
|
|
652
694
|
setSelected: h,
|
|
653
|
-
setUserSelectAction:
|
|
695
|
+
setUserSelectAction: p,
|
|
654
696
|
subscribe: o,
|
|
655
|
-
userSelect:
|
|
697
|
+
userSelect: u
|
|
656
698
|
};
|
|
657
|
-
},
|
|
658
|
-
var
|
|
659
|
-
for (var
|
|
660
|
-
|
|
661
|
-
function
|
|
662
|
-
return (
|
|
699
|
+
}, ee = (t, e, n) => typeof e == "function" ? e(t) : e || "EDIT";
|
|
700
|
+
var K = [];
|
|
701
|
+
for (var Mt = 0; Mt < 256; ++Mt)
|
|
702
|
+
K.push((Mt + 256).toString(16).slice(1));
|
|
703
|
+
function mn(t, e = 0) {
|
|
704
|
+
return (K[t[e + 0]] + K[t[e + 1]] + K[t[e + 2]] + K[t[e + 3]] + "-" + K[t[e + 4]] + K[t[e + 5]] + "-" + K[t[e + 6]] + K[t[e + 7]] + "-" + K[t[e + 8]] + K[t[e + 9]] + "-" + K[t[e + 10]] + K[t[e + 11]] + K[t[e + 12]] + K[t[e + 13]] + K[t[e + 14]] + K[t[e + 15]]).toLowerCase();
|
|
663
705
|
}
|
|
664
|
-
var
|
|
665
|
-
function
|
|
666
|
-
if (!
|
|
706
|
+
var gt, yn = new Uint8Array(16);
|
|
707
|
+
function bn() {
|
|
708
|
+
if (!gt && (gt = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !gt))
|
|
667
709
|
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
668
|
-
return
|
|
710
|
+
return gt(yn);
|
|
669
711
|
}
|
|
670
|
-
var
|
|
671
|
-
const
|
|
672
|
-
randomUUID:
|
|
712
|
+
var wn = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
713
|
+
const ne = {
|
|
714
|
+
randomUUID: wn
|
|
673
715
|
};
|
|
674
|
-
function
|
|
675
|
-
if (
|
|
676
|
-
return
|
|
716
|
+
function ge(t, e, n) {
|
|
717
|
+
if (ne.randomUUID && !e && !t)
|
|
718
|
+
return ne.randomUUID();
|
|
677
719
|
t = t || {};
|
|
678
|
-
var o = t.random || (t.rng ||
|
|
679
|
-
return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128,
|
|
720
|
+
var o = t.random || (t.rng || bn)();
|
|
721
|
+
return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, mn(o);
|
|
680
722
|
}
|
|
681
|
-
const
|
|
723
|
+
const Rt = (t) => {
|
|
682
724
|
const e = (n) => {
|
|
683
725
|
const o = { ...n };
|
|
684
726
|
return n.created && typeof n.created == "string" && (o.created = new Date(n.created)), n.updated && typeof n.updated == "string" && (o.updated = new Date(n.updated)), o;
|
|
@@ -688,76 +730,76 @@ const ft = (t) => {
|
|
|
688
730
|
bodies: (t.bodies || []).map(e),
|
|
689
731
|
target: e(t.target)
|
|
690
732
|
};
|
|
691
|
-
},
|
|
692
|
-
id:
|
|
733
|
+
}, Ao = (t, e, n, o) => ({
|
|
734
|
+
id: ge(),
|
|
693
735
|
annotation: typeof t == "string" ? t : t.id,
|
|
694
736
|
created: n || /* @__PURE__ */ new Date(),
|
|
695
737
|
creator: o,
|
|
696
738
|
...e
|
|
697
|
-
}),
|
|
739
|
+
}), vn = (t, e) => {
|
|
698
740
|
const n = new Set(t.bodies.map((o) => o.id));
|
|
699
741
|
return e.bodies.filter((o) => !n.has(o.id));
|
|
700
|
-
},
|
|
742
|
+
}, An = (t, e) => {
|
|
701
743
|
const n = new Set(e.bodies.map((o) => o.id));
|
|
702
744
|
return t.bodies.filter((o) => !n.has(o.id));
|
|
703
|
-
},
|
|
745
|
+
}, xn = (t, e) => e.bodies.map((n) => {
|
|
704
746
|
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 =
|
|
747
|
+
return { newBody: n, oldBody: o && !G(o, n) ? o : void 0 };
|
|
748
|
+
}).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), En = (t, e) => !G(t.target, e.target), me = (t, e) => {
|
|
749
|
+
const n = vn(t, e), o = An(t, e), i = xn(t, e);
|
|
708
750
|
return {
|
|
709
751
|
oldValue: t,
|
|
710
752
|
newValue: e,
|
|
711
753
|
bodiesCreated: n.length > 0 ? n : void 0,
|
|
712
754
|
bodiesDeleted: o.length > 0 ? o : void 0,
|
|
713
755
|
bodiesUpdated: i.length > 0 ? i : void 0,
|
|
714
|
-
targetUpdated:
|
|
756
|
+
targetUpdated: En(t, e) ? { oldTarget: t.target, newTarget: e.target } : void 0
|
|
715
757
|
};
|
|
716
758
|
};
|
|
717
|
-
var
|
|
718
|
-
const
|
|
759
|
+
var k = /* @__PURE__ */ ((t) => (t.LOCAL = "LOCAL", t.REMOTE = "REMOTE", t.SILENT = "SILENT", t))(k || {});
|
|
760
|
+
const Sn = (t, e) => {
|
|
719
761
|
var n, o;
|
|
720
762
|
const { changes: i, origin: s } = e;
|
|
721
763
|
if (!(t.options.origin ? t.options.origin === s : s !== "SILENT"))
|
|
722
764
|
return !1;
|
|
723
765
|
if (t.options.ignore) {
|
|
724
|
-
const { ignore:
|
|
725
|
-
if (!(
|
|
726
|
-
const
|
|
727
|
-
if (
|
|
766
|
+
const { ignore: a } = t.options, r = (l) => l && l.length > 0;
|
|
767
|
+
if (!(r(i.created) || r(i.deleted))) {
|
|
768
|
+
const l = (n = i.updated) == null ? void 0 : n.some((u) => r(u.bodiesCreated) || r(u.bodiesDeleted) || r(u.bodiesUpdated)), f = (o = i.updated) == null ? void 0 : o.some((u) => u.targetUpdated);
|
|
769
|
+
if (a === "BODY_ONLY" && l && !f || a === "TARGET_ONLY" && f && !l)
|
|
728
770
|
return !1;
|
|
729
771
|
}
|
|
730
772
|
}
|
|
731
773
|
if (t.options.annotations) {
|
|
732
|
-
const
|
|
733
|
-
...(i.created || []).map((
|
|
734
|
-
...(i.deleted || []).map((
|
|
735
|
-
...(i.updated || []).map(({ oldValue:
|
|
774
|
+
const a = /* @__PURE__ */ new Set([
|
|
775
|
+
...(i.created || []).map((r) => r.id),
|
|
776
|
+
...(i.deleted || []).map((r) => r.id),
|
|
777
|
+
...(i.updated || []).map(({ oldValue: r }) => r.id)
|
|
736
778
|
]);
|
|
737
|
-
return !!(Array.isArray(t.options.annotations) ? t.options.annotations : [t.options.annotations]).find((
|
|
779
|
+
return !!(Array.isArray(t.options.annotations) ? t.options.annotations : [t.options.annotations]).find((r) => a.has(r));
|
|
738
780
|
} else
|
|
739
781
|
return !0;
|
|
740
|
-
},
|
|
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)),
|
|
742
|
-
...(t.created || []).filter((h) => !s.has(h.id)).map((h) =>
|
|
782
|
+
}, Cn = (t, e) => {
|
|
783
|
+
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)), a = new Set((e.updated || []).map(({ oldValue: h }) => h.id)), r = new Set((e.updated || []).filter(({ oldValue: h }) => n.has(h.id) || o.has(h.id)).map(({ oldValue: h }) => h.id)), l = [
|
|
784
|
+
...(t.created || []).filter((h) => !s.has(h.id)).map((h) => a.has(h.id) ? e.updated.find(({ oldValue: g }) => g.id === h.id).newValue : h),
|
|
743
785
|
...e.created || []
|
|
744
|
-
],
|
|
786
|
+
], f = [
|
|
745
787
|
...(t.deleted || []).filter((h) => !i.has(h.id)),
|
|
746
788
|
...(e.deleted || []).filter((h) => !n.has(h.id))
|
|
747
|
-
],
|
|
789
|
+
], u = [
|
|
748
790
|
...(t.updated || []).filter(({ newValue: h }) => !s.has(h.id)).map((h) => {
|
|
749
|
-
const { oldValue:
|
|
750
|
-
if (
|
|
751
|
-
const
|
|
752
|
-
return
|
|
791
|
+
const { oldValue: g, newValue: p } = h;
|
|
792
|
+
if (a.has(p.id)) {
|
|
793
|
+
const v = e.updated.find((y) => y.oldValue.id === p.id).newValue;
|
|
794
|
+
return me(g, v);
|
|
753
795
|
} else
|
|
754
796
|
return h;
|
|
755
797
|
}),
|
|
756
|
-
...(e.updated || []).filter(({ oldValue: h }) => !
|
|
798
|
+
...(e.updated || []).filter(({ oldValue: h }) => !r.has(h.id))
|
|
757
799
|
];
|
|
758
|
-
return { created:
|
|
759
|
-
},
|
|
760
|
-
const e = t.id === void 0 ?
|
|
800
|
+
return { created: l, deleted: f, updated: u };
|
|
801
|
+
}, Bt = (t) => {
|
|
802
|
+
const e = t.id === void 0 ? ge() : t.id;
|
|
761
803
|
return {
|
|
762
804
|
...t,
|
|
763
805
|
id: e,
|
|
@@ -770,171 +812,171 @@ const Fe = (t, e) => {
|
|
|
770
812
|
annotation: e
|
|
771
813
|
}
|
|
772
814
|
};
|
|
773
|
-
},
|
|
774
|
-
const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (b,
|
|
775
|
-
n.push({ onChange: b, options:
|
|
815
|
+
}, Ln = (t) => t.id !== void 0, Tn = () => {
|
|
816
|
+
const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (b, x = {}) => {
|
|
817
|
+
n.push({ onChange: b, options: x });
|
|
776
818
|
}, i = (b) => {
|
|
777
|
-
const
|
|
778
|
-
|
|
779
|
-
}, s = (b,
|
|
780
|
-
const
|
|
819
|
+
const x = n.findIndex((A) => A.onChange == b);
|
|
820
|
+
x > -1 && n.splice(x, 1);
|
|
821
|
+
}, s = (b, x) => {
|
|
822
|
+
const A = {
|
|
781
823
|
origin: b,
|
|
782
824
|
changes: {
|
|
783
|
-
created:
|
|
784
|
-
updated:
|
|
785
|
-
deleted:
|
|
825
|
+
created: x.created || [],
|
|
826
|
+
updated: x.updated || [],
|
|
827
|
+
deleted: x.deleted || []
|
|
786
828
|
},
|
|
787
829
|
state: [...t.values()]
|
|
788
830
|
};
|
|
789
831
|
n.forEach((C) => {
|
|
790
|
-
|
|
832
|
+
Sn(C, A) && C.onChange(A);
|
|
791
833
|
});
|
|
792
|
-
},
|
|
834
|
+
}, a = (b, x = k.LOCAL) => {
|
|
793
835
|
if (b.id && t.get(b.id))
|
|
794
836
|
throw Error(`Cannot add annotation ${b.id} - exists already`);
|
|
795
837
|
{
|
|
796
|
-
const
|
|
797
|
-
t.set(
|
|
838
|
+
const A = Bt(b);
|
|
839
|
+
t.set(A.id, A), A.bodies.forEach((C) => e.set(C.id, A.id)), s(x, { created: [A] });
|
|
798
840
|
}
|
|
799
|
-
},
|
|
800
|
-
const
|
|
801
|
-
if (
|
|
802
|
-
const
|
|
803
|
-
return C ===
|
|
841
|
+
}, r = (b, x) => {
|
|
842
|
+
const A = Bt(typeof b == "string" ? x : b), C = typeof b == "string" ? b : b.id, B = C && t.get(C);
|
|
843
|
+
if (B) {
|
|
844
|
+
const M = me(B, A);
|
|
845
|
+
return C === A.id ? t.set(C, A) : (t.delete(C), t.set(A.id, A)), B.bodies.forEach((N) => e.delete(N.id)), A.bodies.forEach((N) => e.set(N.id, A.id)), M;
|
|
804
846
|
} else
|
|
805
847
|
console.warn(`Cannot update annotation ${C} - does not exist`);
|
|
806
|
-
},
|
|
807
|
-
const C =
|
|
808
|
-
|
|
809
|
-
},
|
|
810
|
-
const
|
|
811
|
-
const
|
|
812
|
-
return
|
|
848
|
+
}, l = (b, x = k.LOCAL, A = k.LOCAL) => {
|
|
849
|
+
const C = Ln(x) ? A : x, B = r(b, x);
|
|
850
|
+
B && s(C, { updated: [B] });
|
|
851
|
+
}, f = (b, x = k.LOCAL) => {
|
|
852
|
+
const A = b.reduce((C, B) => {
|
|
853
|
+
const M = r(B);
|
|
854
|
+
return M ? [...C, M] : C;
|
|
813
855
|
}, []);
|
|
814
|
-
|
|
815
|
-
},
|
|
816
|
-
const
|
|
817
|
-
if (
|
|
856
|
+
A.length > 0 && s(x, { updated: A });
|
|
857
|
+
}, u = (b, x = k.LOCAL) => {
|
|
858
|
+
const A = t.get(b.annotation);
|
|
859
|
+
if (A) {
|
|
818
860
|
const C = {
|
|
819
|
-
...
|
|
820
|
-
bodies: [...
|
|
861
|
+
...A,
|
|
862
|
+
bodies: [...A.bodies, b]
|
|
821
863
|
};
|
|
822
|
-
t.set(
|
|
823
|
-
oldValue:
|
|
864
|
+
t.set(A.id, C), e.set(b.id, C.id), s(x, { updated: [{
|
|
865
|
+
oldValue: A,
|
|
824
866
|
newValue: C,
|
|
825
867
|
bodiesCreated: [b]
|
|
826
868
|
}] });
|
|
827
869
|
} else
|
|
828
870
|
console.warn(`Attempt to add body to missing annotation: ${b.annotation}`);
|
|
829
|
-
}, h = () => [...t.values()],
|
|
830
|
-
const
|
|
831
|
-
t.clear(), e.clear(), s(b, { deleted:
|
|
832
|
-
},
|
|
833
|
-
const C = b.map(
|
|
834
|
-
if (
|
|
835
|
-
const
|
|
836
|
-
t.clear(), e.clear(), C.forEach((
|
|
837
|
-
t.set(
|
|
838
|
-
}), s(
|
|
871
|
+
}, h = () => [...t.values()], g = (b = k.LOCAL) => {
|
|
872
|
+
const x = [...t.values()];
|
|
873
|
+
t.clear(), e.clear(), s(b, { deleted: x });
|
|
874
|
+
}, p = (b, x = !0, A = k.LOCAL) => {
|
|
875
|
+
const C = b.map(Bt);
|
|
876
|
+
if (x) {
|
|
877
|
+
const B = [...t.values()];
|
|
878
|
+
t.clear(), e.clear(), C.forEach((M) => {
|
|
879
|
+
t.set(M.id, M), M.bodies.forEach((N) => e.set(N.id, M.id));
|
|
880
|
+
}), s(A, { created: C, deleted: B });
|
|
839
881
|
} else {
|
|
840
|
-
const
|
|
841
|
-
const
|
|
842
|
-
return
|
|
882
|
+
const B = b.reduce((M, N) => {
|
|
883
|
+
const D = N.id && t.get(N.id);
|
|
884
|
+
return D ? [...M, D] : M;
|
|
843
885
|
}, []);
|
|
844
|
-
if (
|
|
845
|
-
throw Error(`Bulk insert would overwrite the following annotations: ${
|
|
846
|
-
C.forEach((
|
|
847
|
-
t.set(
|
|
848
|
-
}), s(
|
|
886
|
+
if (B.length > 0)
|
|
887
|
+
throw Error(`Bulk insert would overwrite the following annotations: ${B.map((M) => M.id).join(", ")}`);
|
|
888
|
+
C.forEach((M) => {
|
|
889
|
+
t.set(M.id, M), M.bodies.forEach((N) => e.set(N.id, M.id));
|
|
890
|
+
}), s(A, { created: C });
|
|
849
891
|
}
|
|
850
|
-
},
|
|
851
|
-
const
|
|
852
|
-
if (
|
|
853
|
-
return t.delete(
|
|
854
|
-
console.warn(`Attempt to delete missing annotation: ${
|
|
855
|
-
},
|
|
856
|
-
const
|
|
857
|
-
|
|
858
|
-
},
|
|
859
|
-
const
|
|
860
|
-
const
|
|
861
|
-
return
|
|
892
|
+
}, v = (b) => {
|
|
893
|
+
const x = typeof b == "string" ? b : b.id, A = t.get(x);
|
|
894
|
+
if (A)
|
|
895
|
+
return t.delete(x), A.bodies.forEach((C) => e.delete(C.id)), A;
|
|
896
|
+
console.warn(`Attempt to delete missing annotation: ${x}`);
|
|
897
|
+
}, y = (b, x = k.LOCAL) => {
|
|
898
|
+
const A = v(b);
|
|
899
|
+
A && s(x, { deleted: [A] });
|
|
900
|
+
}, m = (b, x = k.LOCAL) => {
|
|
901
|
+
const A = b.reduce((C, B) => {
|
|
902
|
+
const M = v(B);
|
|
903
|
+
return M ? [...C, M] : C;
|
|
862
904
|
}, []);
|
|
863
|
-
|
|
864
|
-
},
|
|
865
|
-
const
|
|
866
|
-
if (
|
|
867
|
-
const
|
|
868
|
-
if (
|
|
869
|
-
e.delete(
|
|
905
|
+
A.length > 0 && s(x, { deleted: A });
|
|
906
|
+
}, d = (b) => {
|
|
907
|
+
const x = t.get(b.annotation);
|
|
908
|
+
if (x) {
|
|
909
|
+
const A = x.bodies.find((C) => C.id === b.id);
|
|
910
|
+
if (A) {
|
|
911
|
+
e.delete(A.id);
|
|
870
912
|
const C = {
|
|
871
|
-
...
|
|
872
|
-
bodies:
|
|
913
|
+
...x,
|
|
914
|
+
bodies: x.bodies.filter((B) => B.id !== b.id)
|
|
873
915
|
};
|
|
874
|
-
return t.set(
|
|
875
|
-
oldValue:
|
|
916
|
+
return t.set(x.id, C), {
|
|
917
|
+
oldValue: x,
|
|
876
918
|
newValue: C,
|
|
877
|
-
bodiesDeleted: [
|
|
919
|
+
bodiesDeleted: [A]
|
|
878
920
|
};
|
|
879
921
|
} else
|
|
880
922
|
console.warn(`Attempt to delete missing body ${b.id} from annotation ${b.annotation}`);
|
|
881
923
|
} else
|
|
882
924
|
console.warn(`Attempt to delete body from missing annotation ${b.annotation}`);
|
|
883
|
-
},
|
|
884
|
-
const
|
|
885
|
-
|
|
886
|
-
},
|
|
887
|
-
const
|
|
888
|
-
|
|
925
|
+
}, c = (b, x = k.LOCAL) => {
|
|
926
|
+
const A = d(b);
|
|
927
|
+
A && s(x, { updated: [A] });
|
|
928
|
+
}, w = (b, x = k.LOCAL) => {
|
|
929
|
+
const A = b.map((C) => d(C)).filter(Boolean);
|
|
930
|
+
A.length > 0 && s(x, { updated: A });
|
|
889
931
|
}, S = (b) => {
|
|
890
|
-
const
|
|
891
|
-
return
|
|
892
|
-
},
|
|
893
|
-
const
|
|
894
|
-
if (
|
|
895
|
-
const
|
|
896
|
-
if (
|
|
897
|
-
return
|
|
932
|
+
const x = t.get(b);
|
|
933
|
+
return x ? { ...x } : void 0;
|
|
934
|
+
}, T = (b) => {
|
|
935
|
+
const x = e.get(b);
|
|
936
|
+
if (x) {
|
|
937
|
+
const A = S(x).bodies.find((C) => C.id === b);
|
|
938
|
+
if (A)
|
|
939
|
+
return A;
|
|
898
940
|
console.error(`Store integrity error: body ${b} in index, but not in annotation`);
|
|
899
941
|
} else
|
|
900
942
|
console.warn(`Attempt to retrieve missing body: ${b}`);
|
|
901
|
-
},
|
|
902
|
-
if (b.annotation !==
|
|
943
|
+
}, L = (b, x) => {
|
|
944
|
+
if (b.annotation !== x.annotation)
|
|
903
945
|
throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
|
|
904
|
-
const
|
|
905
|
-
if (
|
|
906
|
-
const C =
|
|
907
|
-
...
|
|
908
|
-
bodies:
|
|
946
|
+
const A = t.get(b.annotation);
|
|
947
|
+
if (A) {
|
|
948
|
+
const C = A.bodies.find((M) => M.id === b.id), B = {
|
|
949
|
+
...A,
|
|
950
|
+
bodies: A.bodies.map((M) => M.id === C.id ? x : M)
|
|
909
951
|
};
|
|
910
|
-
return t.set(
|
|
911
|
-
oldValue:
|
|
912
|
-
newValue:
|
|
913
|
-
bodiesUpdated: [{ oldBody: C, newBody:
|
|
952
|
+
return t.set(A.id, B), C.id !== x.id && (e.delete(C.id), e.set(x.id, B.id)), {
|
|
953
|
+
oldValue: A,
|
|
954
|
+
newValue: B,
|
|
955
|
+
bodiesUpdated: [{ oldBody: C, newBody: x }]
|
|
914
956
|
};
|
|
915
957
|
} else
|
|
916
958
|
console.warn(`Attempt to add body to missing annotation ${b.annotation}`);
|
|
917
|
-
},
|
|
918
|
-
const C =
|
|
919
|
-
C && s(
|
|
920
|
-
},
|
|
921
|
-
const
|
|
922
|
-
s(
|
|
923
|
-
},
|
|
924
|
-
const
|
|
925
|
-
if (
|
|
926
|
-
const
|
|
927
|
-
...
|
|
959
|
+
}, O = (b, x, A = k.LOCAL) => {
|
|
960
|
+
const C = L(b, x);
|
|
961
|
+
C && s(A, { updated: [C] });
|
|
962
|
+
}, E = (b, x = k.LOCAL) => {
|
|
963
|
+
const A = b.map((C) => L({ id: C.id, annotation: C.annotation }, C)).filter(Boolean);
|
|
964
|
+
s(x, { updated: A });
|
|
965
|
+
}, R = (b) => {
|
|
966
|
+
const x = t.get(b.annotation);
|
|
967
|
+
if (x) {
|
|
968
|
+
const A = {
|
|
969
|
+
...x,
|
|
928
970
|
target: {
|
|
929
|
-
...
|
|
971
|
+
...x.target,
|
|
930
972
|
...b
|
|
931
973
|
}
|
|
932
974
|
};
|
|
933
|
-
return t.set(
|
|
934
|
-
oldValue:
|
|
935
|
-
newValue:
|
|
975
|
+
return t.set(x.id, A), {
|
|
976
|
+
oldValue: x,
|
|
977
|
+
newValue: A,
|
|
936
978
|
targetUpdated: {
|
|
937
|
-
oldTarget:
|
|
979
|
+
oldTarget: x.target,
|
|
938
980
|
newTarget: b
|
|
939
981
|
}
|
|
940
982
|
};
|
|
@@ -942,34 +984,34 @@ const Fe = (t, e) => {
|
|
|
942
984
|
console.warn(`Attempt to update target on missing annotation: ${b.annotation}`);
|
|
943
985
|
};
|
|
944
986
|
return {
|
|
945
|
-
addAnnotation:
|
|
946
|
-
addBody:
|
|
987
|
+
addAnnotation: a,
|
|
988
|
+
addBody: u,
|
|
947
989
|
all: h,
|
|
948
|
-
bulkAddAnnotation:
|
|
949
|
-
bulkDeleteAnnotation:
|
|
950
|
-
bulkDeleteBodies:
|
|
951
|
-
bulkUpdateAnnotation:
|
|
952
|
-
bulkUpdateBodies:
|
|
953
|
-
bulkUpdateTargets: (b,
|
|
954
|
-
const
|
|
955
|
-
|
|
990
|
+
bulkAddAnnotation: p,
|
|
991
|
+
bulkDeleteAnnotation: m,
|
|
992
|
+
bulkDeleteBodies: w,
|
|
993
|
+
bulkUpdateAnnotation: f,
|
|
994
|
+
bulkUpdateBodies: E,
|
|
995
|
+
bulkUpdateTargets: (b, x = k.LOCAL) => {
|
|
996
|
+
const A = b.map((C) => R(C)).filter(Boolean);
|
|
997
|
+
A.length > 0 && s(x, { updated: A });
|
|
956
998
|
},
|
|
957
|
-
clear:
|
|
958
|
-
deleteAnnotation:
|
|
959
|
-
deleteBody:
|
|
999
|
+
clear: g,
|
|
1000
|
+
deleteAnnotation: y,
|
|
1001
|
+
deleteBody: c,
|
|
960
1002
|
getAnnotation: S,
|
|
961
|
-
getBody:
|
|
1003
|
+
getBody: T,
|
|
962
1004
|
observe: o,
|
|
963
1005
|
unobserve: i,
|
|
964
|
-
updateAnnotation:
|
|
965
|
-
updateBody:
|
|
966
|
-
updateTarget: (b,
|
|
967
|
-
const
|
|
968
|
-
|
|
1006
|
+
updateAnnotation: l,
|
|
1007
|
+
updateBody: O,
|
|
1008
|
+
updateTarget: (b, x = k.LOCAL) => {
|
|
1009
|
+
const A = R(b);
|
|
1010
|
+
A && s(x, { updated: [A] });
|
|
969
1011
|
}
|
|
970
1012
|
};
|
|
971
1013
|
};
|
|
972
|
-
let
|
|
1014
|
+
let On = () => ({
|
|
973
1015
|
emit(t, ...e) {
|
|
974
1016
|
for (let n = 0, o = this.events[t] || [], i = o.length; n < i; n++)
|
|
975
1017
|
o[n](...e);
|
|
@@ -983,119 +1025,119 @@ let Ke = () => ({
|
|
|
983
1025
|
};
|
|
984
1026
|
}
|
|
985
1027
|
});
|
|
986
|
-
const
|
|
987
|
-
const e =
|
|
1028
|
+
const Mn = 250, Rn = (t) => {
|
|
1029
|
+
const e = On(), n = [];
|
|
988
1030
|
let o = -1, i = !1, s = 0;
|
|
989
|
-
const
|
|
1031
|
+
const a = (p) => {
|
|
990
1032
|
if (!i) {
|
|
991
|
-
const { changes:
|
|
992
|
-
if (
|
|
993
|
-
n.splice(o + 1), n.push(
|
|
1033
|
+
const { changes: v } = p, y = performance.now();
|
|
1034
|
+
if (y - s > Mn)
|
|
1035
|
+
n.splice(o + 1), n.push(v), o = n.length - 1;
|
|
994
1036
|
else {
|
|
995
|
-
const
|
|
996
|
-
n[
|
|
1037
|
+
const m = n.length - 1;
|
|
1038
|
+
n[m] = Cn(n[m], v);
|
|
997
1039
|
}
|
|
998
|
-
s =
|
|
1040
|
+
s = y;
|
|
999
1041
|
}
|
|
1000
1042
|
i = !1;
|
|
1001
1043
|
};
|
|
1002
|
-
t.observe(
|
|
1003
|
-
const
|
|
1044
|
+
t.observe(a, { origin: k.LOCAL });
|
|
1045
|
+
const r = (p) => p && p.length > 0 && t.bulkDeleteAnnotation(p), l = (p) => p && p.length > 0 && t.bulkAddAnnotation(p, !1), f = (p) => p && p.length > 0 && t.bulkUpdateAnnotation(p.map(({ oldValue: v }) => v)), u = (p) => p && p.length > 0 && t.bulkUpdateAnnotation(p.map(({ newValue: v }) => v)), h = (p) => p && p.length > 0 && t.bulkAddAnnotation(p, !1), g = (p) => p && p.length > 0 && t.bulkDeleteAnnotation(p);
|
|
1004
1046
|
return {
|
|
1005
1047
|
canRedo: () => n.length - 1 > o,
|
|
1006
1048
|
canUndo: () => o > -1,
|
|
1007
|
-
destroy: () => t.unobserve(
|
|
1008
|
-
on: (
|
|
1049
|
+
destroy: () => t.unobserve(a),
|
|
1050
|
+
on: (p, v) => e.on(p, v),
|
|
1009
1051
|
redo: () => {
|
|
1010
1052
|
if (n.length - 1 > o) {
|
|
1011
1053
|
i = !0;
|
|
1012
|
-
const { created:
|
|
1013
|
-
|
|
1054
|
+
const { created: p, updated: v, deleted: y } = n[o + 1];
|
|
1055
|
+
l(p), u(v), g(y), e.emit("redo", n[o + 1]), o += 1;
|
|
1014
1056
|
}
|
|
1015
1057
|
},
|
|
1016
1058
|
undo: () => {
|
|
1017
1059
|
if (o > -1) {
|
|
1018
1060
|
i = !0;
|
|
1019
|
-
const { created:
|
|
1020
|
-
|
|
1061
|
+
const { created: p, updated: v, deleted: y } = n[o];
|
|
1062
|
+
r(p), f(v), h(y), e.emit("undo", n[o]), o -= 1;
|
|
1021
1063
|
}
|
|
1022
1064
|
}
|
|
1023
1065
|
};
|
|
1024
|
-
},
|
|
1025
|
-
const { subscribe: t, set: e } =
|
|
1066
|
+
}, Bn = () => {
|
|
1067
|
+
const { subscribe: t, set: e } = Pt([]);
|
|
1026
1068
|
return {
|
|
1027
1069
|
subscribe: t,
|
|
1028
1070
|
set: e
|
|
1029
1071
|
};
|
|
1030
|
-
},
|
|
1031
|
-
const { hover: i, selection: s, store:
|
|
1032
|
-
let
|
|
1033
|
-
const h = (
|
|
1034
|
-
|
|
1035
|
-
},
|
|
1036
|
-
const
|
|
1037
|
-
if (
|
|
1038
|
-
const
|
|
1039
|
-
|
|
1072
|
+
}, kn = (t, e, n, o) => {
|
|
1073
|
+
const { hover: i, selection: s, store: a, viewport: r } = t, l = /* @__PURE__ */ new Map();
|
|
1074
|
+
let f = [], u;
|
|
1075
|
+
const h = (y, m) => {
|
|
1076
|
+
l.has(y) ? l.get(y).push(m) : l.set(y, [m]);
|
|
1077
|
+
}, g = (y, m) => {
|
|
1078
|
+
const d = l.get(y);
|
|
1079
|
+
if (d) {
|
|
1080
|
+
const c = d.indexOf(m);
|
|
1081
|
+
c !== -1 && d.splice(c, 1);
|
|
1040
1082
|
}
|
|
1041
|
-
},
|
|
1042
|
-
|
|
1043
|
-
|
|
1083
|
+
}, p = (y, m, d) => {
|
|
1084
|
+
l.has(y) && setTimeout(() => {
|
|
1085
|
+
l.get(y).forEach((c) => {
|
|
1044
1086
|
if (n) {
|
|
1045
|
-
const
|
|
1046
|
-
|
|
1087
|
+
const w = Array.isArray(m) ? m.map((T) => n.serialize(T)) : n.serialize(m), S = d ? d instanceof PointerEvent ? d : n.serialize(d) : void 0;
|
|
1088
|
+
c(w, S);
|
|
1047
1089
|
} else
|
|
1048
|
-
|
|
1090
|
+
c(m, d);
|
|
1049
1091
|
});
|
|
1050
1092
|
}, 1);
|
|
1051
1093
|
};
|
|
1052
|
-
s.subscribe(({ selected:
|
|
1053
|
-
if (!(
|
|
1054
|
-
if (
|
|
1055
|
-
|
|
1056
|
-
else if (
|
|
1057
|
-
|
|
1058
|
-
const
|
|
1059
|
-
|
|
1060
|
-
}),
|
|
1094
|
+
s.subscribe(({ selected: y }) => {
|
|
1095
|
+
if (!(f.length === 0 && y.length === 0)) {
|
|
1096
|
+
if (f.length === 0 && y.length > 0)
|
|
1097
|
+
f = y.map(({ id: m }) => a.getAnnotation(m));
|
|
1098
|
+
else if (f.length > 0 && y.length === 0)
|
|
1099
|
+
f.forEach((m) => {
|
|
1100
|
+
const d = a.getAnnotation(m.id);
|
|
1101
|
+
d && !G(d, m) && p("updateAnnotation", d, m);
|
|
1102
|
+
}), f = [];
|
|
1061
1103
|
else {
|
|
1062
|
-
const
|
|
1063
|
-
|
|
1064
|
-
const
|
|
1065
|
-
|
|
1066
|
-
}),
|
|
1104
|
+
const m = new Set(f.map((c) => c.id)), d = new Set(y.map(({ id: c }) => c));
|
|
1105
|
+
f.filter((c) => !d.has(c.id)).forEach((c) => {
|
|
1106
|
+
const w = a.getAnnotation(c.id);
|
|
1107
|
+
w && !G(w, c) && p("updateAnnotation", w, c);
|
|
1108
|
+
}), f = [
|
|
1067
1109
|
// Remove annotations that were deselected
|
|
1068
|
-
...
|
|
1110
|
+
...f.filter((c) => d.has(c.id)),
|
|
1069
1111
|
// Add editable annotations that were selected
|
|
1070
|
-
...
|
|
1112
|
+
...y.filter(({ id: c }) => !m.has(c)).map(({ id: c }) => a.getAnnotation(c))
|
|
1071
1113
|
];
|
|
1072
1114
|
}
|
|
1073
|
-
|
|
1115
|
+
p("selectionChanged", f);
|
|
1074
1116
|
}
|
|
1075
|
-
}), i.subscribe((
|
|
1076
|
-
!
|
|
1077
|
-
}),
|
|
1078
|
-
const { created:
|
|
1079
|
-
(
|
|
1080
|
-
...
|
|
1081
|
-
...
|
|
1082
|
-
...
|
|
1083
|
-
].length > 0).forEach(({ oldValue:
|
|
1084
|
-
const S =
|
|
1085
|
-
|
|
1117
|
+
}), i.subscribe((y) => {
|
|
1118
|
+
!u && y ? p("mouseEnterAnnotation", a.getAnnotation(y)) : u && !y ? p("mouseLeaveAnnotation", a.getAnnotation(u)) : u && y && (p("mouseLeaveAnnotation", a.getAnnotation(u)), p("mouseEnterAnnotation", a.getAnnotation(y))), u = y;
|
|
1119
|
+
}), r == null || r.subscribe((y) => p("viewportIntersect", y.map((m) => a.getAnnotation(m)))), a.observe((y) => {
|
|
1120
|
+
const { created: m, deleted: d } = y.changes;
|
|
1121
|
+
(m || []).forEach((c) => p("createAnnotation", c)), (d || []).forEach((c) => p("deleteAnnotation", c)), (y.changes.updated || []).filter((c) => [
|
|
1122
|
+
...c.bodiesCreated || [],
|
|
1123
|
+
...c.bodiesDeleted || [],
|
|
1124
|
+
...c.bodiesUpdated || []
|
|
1125
|
+
].length > 0).forEach(({ oldValue: c, newValue: w }) => {
|
|
1126
|
+
const S = f.find((T) => T.id === c.id) || c;
|
|
1127
|
+
f = f.map((T) => T.id === c.id ? w : T), p("updateAnnotation", w, S);
|
|
1086
1128
|
});
|
|
1087
|
-
}, { origin:
|
|
1088
|
-
if (
|
|
1089
|
-
const
|
|
1090
|
-
|
|
1129
|
+
}, { origin: k.LOCAL }), a.observe((y) => {
|
|
1130
|
+
if (f) {
|
|
1131
|
+
const m = new Set(f.map((c) => c.id)), d = (y.changes.updated || []).filter(({ newValue: c }) => m.has(c.id)).map(({ newValue: c }) => c);
|
|
1132
|
+
d.length > 0 && (f = f.map((c) => d.find((S) => S.id === c.id) || c));
|
|
1091
1133
|
}
|
|
1092
|
-
}, { origin:
|
|
1093
|
-
const
|
|
1094
|
-
const { updated:
|
|
1095
|
-
|
|
1134
|
+
}, { origin: k.REMOTE });
|
|
1135
|
+
const v = (y) => (m) => {
|
|
1136
|
+
const { updated: d } = m;
|
|
1137
|
+
y ? (d || []).forEach((c) => p("updateAnnotation", c.oldValue, c.newValue)) : (d || []).forEach((c) => p("updateAnnotation", c.newValue, c.oldValue));
|
|
1096
1138
|
};
|
|
1097
|
-
return e.on("undo",
|
|
1098
|
-
},
|
|
1139
|
+
return e.on("undo", v(!0)), e.on("redo", v(!1)), { on: h, off: g, emit: p };
|
|
1140
|
+
}, In = (t) => (e) => e.reduce((n, o) => {
|
|
1099
1141
|
const { parsed: i, error: s } = t.parse(o);
|
|
1100
1142
|
return s ? {
|
|
1101
1143
|
parsed: n.parsed,
|
|
@@ -1106,85 +1148,85 @@ const Qe = 250, Je = (t) => {
|
|
|
1106
1148
|
} : {
|
|
1107
1149
|
...n
|
|
1108
1150
|
};
|
|
1109
|
-
}, { parsed: [], failed: [] }),
|
|
1110
|
-
const { store: o, selection: i } = t, s = (
|
|
1151
|
+
}, { parsed: [], failed: [] }), _n = (t, e, n) => {
|
|
1152
|
+
const { store: o, selection: i } = t, s = (d) => {
|
|
1111
1153
|
if (n) {
|
|
1112
|
-
const { parsed:
|
|
1113
|
-
|
|
1154
|
+
const { parsed: c, error: w } = n.parse(d);
|
|
1155
|
+
c ? o.addAnnotation(c, k.REMOTE) : console.error(w);
|
|
1114
1156
|
} else
|
|
1115
|
-
o.addAnnotation(
|
|
1116
|
-
},
|
|
1117
|
-
const
|
|
1118
|
-
return n &&
|
|
1119
|
-
},
|
|
1120
|
-
var
|
|
1121
|
-
const
|
|
1122
|
-
return n ?
|
|
1123
|
-
}, h = (
|
|
1124
|
-
if (typeof
|
|
1125
|
-
const
|
|
1126
|
-
if (o.deleteAnnotation(
|
|
1127
|
-
return n ? n.serialize(
|
|
1157
|
+
o.addAnnotation(Rt(d), k.REMOTE);
|
|
1158
|
+
}, a = () => i.clear(), r = () => o.clear(), l = (d) => {
|
|
1159
|
+
const c = o.getAnnotation(d);
|
|
1160
|
+
return n && c ? n.serialize(c) : c;
|
|
1161
|
+
}, f = () => n ? o.all().map(n.serialize) : o.all(), u = () => {
|
|
1162
|
+
var d;
|
|
1163
|
+
const c = (((d = i.selected) == null ? void 0 : d.map((w) => w.id)) || []).map((w) => o.getAnnotation(w)).filter(Boolean);
|
|
1164
|
+
return n ? c.map(n.serialize) : c;
|
|
1165
|
+
}, h = (d, c = !0) => fetch(d).then((w) => w.json()).then((w) => (p(w, c), w)), g = (d) => {
|
|
1166
|
+
if (typeof d == "string") {
|
|
1167
|
+
const c = o.getAnnotation(d);
|
|
1168
|
+
if (o.deleteAnnotation(d), c)
|
|
1169
|
+
return n ? n.serialize(c) : c;
|
|
1128
1170
|
} else {
|
|
1129
|
-
const
|
|
1130
|
-
if (
|
|
1131
|
-
return o.deleteAnnotation(
|
|
1171
|
+
const c = n ? n.parse(d).parsed : d;
|
|
1172
|
+
if (c)
|
|
1173
|
+
return o.deleteAnnotation(c), d;
|
|
1132
1174
|
}
|
|
1133
|
-
},
|
|
1175
|
+
}, p = (d, c = !0) => {
|
|
1134
1176
|
if (n) {
|
|
1135
|
-
const
|
|
1136
|
-
|
|
1177
|
+
const w = n.parseAll || In(n), { parsed: S, failed: T } = w(d);
|
|
1178
|
+
T.length > 0 && console.warn(`Discarded ${T.length} invalid annotations`, T), o.bulkAddAnnotation(S, c, k.REMOTE);
|
|
1137
1179
|
} else
|
|
1138
|
-
o.bulkAddAnnotation(
|
|
1139
|
-
},
|
|
1140
|
-
|
|
1141
|
-
},
|
|
1142
|
-
i.clear(), i.setUserSelectAction(
|
|
1143
|
-
},
|
|
1180
|
+
o.bulkAddAnnotation(d.map(Rt), c, k.REMOTE);
|
|
1181
|
+
}, v = (d, c) => {
|
|
1182
|
+
d ? i.setSelected(d, c) : i.clear();
|
|
1183
|
+
}, y = (d) => {
|
|
1184
|
+
i.clear(), i.setUserSelectAction(d);
|
|
1185
|
+
}, m = (d) => {
|
|
1144
1186
|
if (n) {
|
|
1145
|
-
const
|
|
1146
|
-
return o.updateAnnotation(
|
|
1187
|
+
const c = n.parse(d).parsed, w = n.serialize(o.getAnnotation(c.id));
|
|
1188
|
+
return o.updateAnnotation(c), w;
|
|
1147
1189
|
} else {
|
|
1148
|
-
const
|
|
1149
|
-
return o.updateAnnotation(
|
|
1190
|
+
const c = o.getAnnotation(d.id);
|
|
1191
|
+
return o.updateAnnotation(Rt(d)), c;
|
|
1150
1192
|
}
|
|
1151
1193
|
};
|
|
1152
1194
|
return {
|
|
1153
1195
|
addAnnotation: s,
|
|
1154
|
-
cancelSelected:
|
|
1196
|
+
cancelSelected: a,
|
|
1155
1197
|
canRedo: e.canRedo,
|
|
1156
1198
|
canUndo: e.canUndo,
|
|
1157
|
-
clearAnnotations:
|
|
1158
|
-
getAnnotationById:
|
|
1159
|
-
getAnnotations:
|
|
1160
|
-
getSelected:
|
|
1199
|
+
clearAnnotations: r,
|
|
1200
|
+
getAnnotationById: l,
|
|
1201
|
+
getAnnotations: f,
|
|
1202
|
+
getSelected: u,
|
|
1161
1203
|
loadAnnotations: h,
|
|
1162
1204
|
redo: e.redo,
|
|
1163
|
-
removeAnnotation:
|
|
1164
|
-
setAnnotations:
|
|
1165
|
-
setSelected:
|
|
1166
|
-
setUserSelectAction:
|
|
1205
|
+
removeAnnotation: g,
|
|
1206
|
+
setAnnotations: p,
|
|
1207
|
+
setSelected: v,
|
|
1208
|
+
setUserSelectAction: y,
|
|
1167
1209
|
undo: e.undo,
|
|
1168
|
-
updateAnnotation:
|
|
1210
|
+
updateAnnotation: m
|
|
1169
1211
|
};
|
|
1170
|
-
},
|
|
1171
|
-
let
|
|
1212
|
+
}, Nn = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
1213
|
+
let Un = (t) => crypto.getRandomValues(new Uint8Array(t)), Vn = (t, e, n) => {
|
|
1172
1214
|
let o = (2 << Math.log(t.length - 1) / Math.LN2) - 1, i = -~(1.6 * o * e / t.length);
|
|
1173
1215
|
return (s = e) => {
|
|
1174
|
-
let
|
|
1216
|
+
let a = "";
|
|
1175
1217
|
for (; ; ) {
|
|
1176
|
-
let
|
|
1177
|
-
for (;
|
|
1178
|
-
if (
|
|
1218
|
+
let r = n(i), l = i;
|
|
1219
|
+
for (; l--; )
|
|
1220
|
+
if (a += t[r[l] & o] || "", a.length === s) return a;
|
|
1179
1221
|
}
|
|
1180
1222
|
};
|
|
1181
|
-
},
|
|
1223
|
+
}, Kn = (t, e = 21) => Vn(t, e, Un), Yn = (t = 21) => {
|
|
1182
1224
|
let e = "", n = crypto.getRandomValues(new Uint8Array(t));
|
|
1183
1225
|
for (; t--; )
|
|
1184
|
-
e +=
|
|
1226
|
+
e += Nn[n[t] & 63];
|
|
1185
1227
|
return e;
|
|
1186
1228
|
};
|
|
1187
|
-
const
|
|
1229
|
+
const Dn = () => ({ isGuest: !0, id: Kn("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() }), Xn = (t) => {
|
|
1188
1230
|
const e = JSON.stringify(t);
|
|
1189
1231
|
let n = 0;
|
|
1190
1232
|
for (let o = 0, i = e.length; o < i; o++) {
|
|
@@ -1192,108 +1234,108 @@ const ln = () => ({ isGuest: !0, id: an("1234567890abcdefghijklmnopqrstuvwxyzABC
|
|
|
1192
1234
|
n = (n << 5) - n + s, n |= 0;
|
|
1193
1235
|
}
|
|
1194
1236
|
return `${n}`;
|
|
1195
|
-
},
|
|
1196
|
-
const { id: o, type: i, purpose: s, value:
|
|
1237
|
+
}, ye = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, Pn = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
|
|
1238
|
+
const { id: o, type: i, purpose: s, value: a, created: r, modified: l, creator: f, ...u } = n;
|
|
1197
1239
|
return {
|
|
1198
|
-
id: o || `temp-${
|
|
1240
|
+
id: o || `temp-${Xn(n)}`,
|
|
1199
1241
|
annotation: e,
|
|
1200
1242
|
type: i,
|
|
1201
1243
|
purpose: s,
|
|
1202
|
-
value:
|
|
1203
|
-
creator:
|
|
1204
|
-
created:
|
|
1205
|
-
updated:
|
|
1206
|
-
...
|
|
1244
|
+
value: a,
|
|
1245
|
+
creator: ye(f),
|
|
1246
|
+
created: r ? new Date(r) : void 0,
|
|
1247
|
+
updated: l ? new Date(l) : void 0,
|
|
1248
|
+
...u
|
|
1207
1249
|
};
|
|
1208
|
-
}),
|
|
1250
|
+
}), $n = (t) => t.map((e) => {
|
|
1209
1251
|
var n;
|
|
1210
|
-
const { annotation: o, created: i, updated: s, ...
|
|
1211
|
-
...
|
|
1252
|
+
const { annotation: o, created: i, updated: s, ...a } = e, r = {
|
|
1253
|
+
...a,
|
|
1212
1254
|
created: i == null ? void 0 : i.toISOString(),
|
|
1213
1255
|
modified: s == null ? void 0 : s.toISOString()
|
|
1214
1256
|
};
|
|
1215
|
-
return (n =
|
|
1257
|
+
return (n = r.id) != null && n.startsWith("temp-") && delete r.id, r;
|
|
1216
1258
|
});
|
|
1217
|
-
|
|
1218
|
-
const
|
|
1219
|
-
parse: (n) =>
|
|
1220
|
-
serialize: (n) =>
|
|
1221
|
-
}),
|
|
1259
|
+
Yn();
|
|
1260
|
+
const xo = (t, e) => ({
|
|
1261
|
+
parse: (n) => zn(n),
|
|
1262
|
+
serialize: (n) => Fn(n, t, e)
|
|
1263
|
+
}), Hn = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, jn = (t) => {
|
|
1222
1264
|
const {
|
|
1223
1265
|
id: e,
|
|
1224
1266
|
creator: n,
|
|
1225
1267
|
created: o,
|
|
1226
1268
|
modified: i,
|
|
1227
1269
|
target: s
|
|
1228
|
-
} = t,
|
|
1229
|
-
creator:
|
|
1270
|
+
} = t, a = Array.isArray(s) ? s : [s], r = {
|
|
1271
|
+
creator: ye(n),
|
|
1230
1272
|
created: o ? new Date(o) : void 0,
|
|
1231
1273
|
updated: i ? new Date(i) : void 0,
|
|
1232
1274
|
annotation: e,
|
|
1233
1275
|
selector: []
|
|
1234
1276
|
};
|
|
1235
|
-
for (const
|
|
1236
|
-
const
|
|
1237
|
-
switch (
|
|
1277
|
+
for (const l of a) {
|
|
1278
|
+
const u = (Array.isArray(l.selector) ? l.selector : [l.selector]).reduce((h, g) => {
|
|
1279
|
+
switch (g.type) {
|
|
1238
1280
|
case "TextQuoteSelector":
|
|
1239
|
-
h.quote =
|
|
1281
|
+
h.quote = g.exact;
|
|
1240
1282
|
break;
|
|
1241
1283
|
case "TextPositionSelector":
|
|
1242
|
-
h.start =
|
|
1284
|
+
h.start = g.start, h.end = g.end;
|
|
1243
1285
|
break;
|
|
1244
1286
|
}
|
|
1245
1287
|
return h;
|
|
1246
1288
|
}, {});
|
|
1247
|
-
if (
|
|
1248
|
-
|
|
1289
|
+
if (Hn(u))
|
|
1290
|
+
r.selector.push({ id: l.id, ...u });
|
|
1249
1291
|
else {
|
|
1250
1292
|
const h = [
|
|
1251
|
-
|
|
1252
|
-
|
|
1293
|
+
u.start ? void 0 : "TextPositionSelector",
|
|
1294
|
+
u.quote ? void 0 : "TextQuoteSelector"
|
|
1253
1295
|
].filter(Boolean);
|
|
1254
1296
|
return { error: Error(`Missing selector types: ${h.join(" and ")} for annotation: ${t.id}`) };
|
|
1255
1297
|
}
|
|
1256
1298
|
}
|
|
1257
|
-
return { parsed:
|
|
1258
|
-
},
|
|
1259
|
-
const e = t.id ||
|
|
1299
|
+
return { parsed: r };
|
|
1300
|
+
}, zn = (t) => {
|
|
1301
|
+
const e = t.id || pe(), {
|
|
1260
1302
|
creator: n,
|
|
1261
1303
|
created: o,
|
|
1262
1304
|
modified: i,
|
|
1263
1305
|
body: s,
|
|
1264
|
-
...
|
|
1265
|
-
} = t,
|
|
1266
|
-
return "error" in
|
|
1306
|
+
...a
|
|
1307
|
+
} = t, r = Pn(s, e), l = jn(t);
|
|
1308
|
+
return "error" in l ? { error: l.error } : {
|
|
1267
1309
|
parsed: {
|
|
1268
|
-
...
|
|
1310
|
+
...a,
|
|
1269
1311
|
id: e,
|
|
1270
|
-
bodies:
|
|
1271
|
-
target:
|
|
1312
|
+
bodies: r,
|
|
1313
|
+
target: l.parsed
|
|
1272
1314
|
}
|
|
1273
1315
|
};
|
|
1274
|
-
},
|
|
1316
|
+
}, Fn = (t, e, n) => {
|
|
1275
1317
|
const { bodies: o, target: i, ...s } = t, {
|
|
1276
|
-
selector:
|
|
1277
|
-
creator:
|
|
1278
|
-
created:
|
|
1279
|
-
updated:
|
|
1280
|
-
...
|
|
1281
|
-
} = i, h =
|
|
1282
|
-
const { quote:
|
|
1318
|
+
selector: a,
|
|
1319
|
+
creator: r,
|
|
1320
|
+
created: l,
|
|
1321
|
+
updated: f,
|
|
1322
|
+
...u
|
|
1323
|
+
} = i, h = a.map((g) => {
|
|
1324
|
+
const { quote: p, start: v, end: y, range: m } = g, { prefix: d, suffix: c } = ke(m, n), w = [{
|
|
1283
1325
|
type: "TextQuoteSelector",
|
|
1284
|
-
exact:
|
|
1285
|
-
prefix:
|
|
1286
|
-
suffix:
|
|
1326
|
+
exact: p,
|
|
1327
|
+
prefix: d,
|
|
1328
|
+
suffix: c
|
|
1287
1329
|
}, {
|
|
1288
1330
|
type: "TextPositionSelector",
|
|
1289
|
-
start:
|
|
1290
|
-
end:
|
|
1331
|
+
start: v,
|
|
1332
|
+
end: y
|
|
1291
1333
|
}];
|
|
1292
1334
|
return {
|
|
1293
|
-
...
|
|
1294
|
-
id:
|
|
1335
|
+
...u,
|
|
1336
|
+
id: g.id,
|
|
1295
1337
|
source: e,
|
|
1296
|
-
selector:
|
|
1338
|
+
selector: w
|
|
1297
1339
|
};
|
|
1298
1340
|
});
|
|
1299
1341
|
return {
|
|
@@ -1301,36 +1343,36 @@ const In = (t, e) => ({
|
|
|
1301
1343
|
"@context": "http://www.w3.org/ns/anno.jsonld",
|
|
1302
1344
|
id: t.id,
|
|
1303
1345
|
type: "Annotation",
|
|
1304
|
-
body:
|
|
1305
|
-
creator:
|
|
1306
|
-
created:
|
|
1307
|
-
modified:
|
|
1346
|
+
body: $n(t.bodies),
|
|
1347
|
+
creator: r,
|
|
1348
|
+
created: l == null ? void 0 : l.toISOString(),
|
|
1349
|
+
modified: f == null ? void 0 : f.toISOString(),
|
|
1308
1350
|
target: h
|
|
1309
1351
|
};
|
|
1310
1352
|
};
|
|
1311
|
-
function
|
|
1353
|
+
function be(t, e, n = 0, o = t.length - 1, i = Wn) {
|
|
1312
1354
|
for (; o > n; ) {
|
|
1313
1355
|
if (o - n > 600) {
|
|
1314
|
-
const
|
|
1315
|
-
|
|
1356
|
+
const l = o - n + 1, f = e - n + 1, u = Math.log(l), h = 0.5 * Math.exp(2 * u / 3), g = 0.5 * Math.sqrt(u * h * (l - h) / l) * (f - l / 2 < 0 ? -1 : 1), p = Math.max(n, Math.floor(e - f * h / l + g)), v = Math.min(o, Math.floor(e + (l - f) * h / l + g));
|
|
1357
|
+
be(t, e, p, v, i);
|
|
1316
1358
|
}
|
|
1317
1359
|
const s = t[e];
|
|
1318
|
-
let
|
|
1319
|
-
for (
|
|
1320
|
-
for (
|
|
1321
|
-
for (; i(t[
|
|
1360
|
+
let a = n, r = o;
|
|
1361
|
+
for (et(t, n, e), i(t[o], s) > 0 && et(t, n, o); a < r; ) {
|
|
1362
|
+
for (et(t, a, r), a++, r--; i(t[a], s) < 0; ) a++;
|
|
1363
|
+
for (; i(t[r], s) > 0; ) r--;
|
|
1322
1364
|
}
|
|
1323
|
-
i(t[n], s) === 0 ?
|
|
1365
|
+
i(t[n], s) === 0 ? et(t, n, r) : (r++, et(t, r, o)), r <= e && (n = r + 1), e <= r && (o = r - 1);
|
|
1324
1366
|
}
|
|
1325
1367
|
}
|
|
1326
|
-
function
|
|
1368
|
+
function et(t, e, n) {
|
|
1327
1369
|
const o = t[e];
|
|
1328
1370
|
t[e] = t[n], t[n] = o;
|
|
1329
1371
|
}
|
|
1330
|
-
function
|
|
1372
|
+
function Wn(t, e) {
|
|
1331
1373
|
return t < e ? -1 : t > e ? 1 : 0;
|
|
1332
1374
|
}
|
|
1333
|
-
class
|
|
1375
|
+
class qn {
|
|
1334
1376
|
constructor(e = 9) {
|
|
1335
1377
|
this._maxEntries = Math.max(4, e), this._minEntries = Math.max(2, Math.ceil(this._maxEntries * 0.4)), this.clear();
|
|
1336
1378
|
}
|
|
@@ -1340,12 +1382,12 @@ class vn {
|
|
|
1340
1382
|
search(e) {
|
|
1341
1383
|
let n = this.data;
|
|
1342
1384
|
const o = [];
|
|
1343
|
-
if (!
|
|
1385
|
+
if (!yt(e, n)) return o;
|
|
1344
1386
|
const i = this.toBBox, s = [];
|
|
1345
1387
|
for (; n; ) {
|
|
1346
|
-
for (let
|
|
1347
|
-
const
|
|
1348
|
-
|
|
1388
|
+
for (let a = 0; a < n.children.length; a++) {
|
|
1389
|
+
const r = n.children[a], l = n.leaf ? i(r) : r;
|
|
1390
|
+
yt(e, l) && (n.leaf ? o.push(r) : It(e, l) ? this._all(r, o) : s.push(r));
|
|
1349
1391
|
}
|
|
1350
1392
|
n = s.pop();
|
|
1351
1393
|
}
|
|
@@ -1353,13 +1395,13 @@ class vn {
|
|
|
1353
1395
|
}
|
|
1354
1396
|
collides(e) {
|
|
1355
1397
|
let n = this.data;
|
|
1356
|
-
if (!
|
|
1398
|
+
if (!yt(e, n)) return !1;
|
|
1357
1399
|
const o = [];
|
|
1358
1400
|
for (; n; ) {
|
|
1359
1401
|
for (let i = 0; i < n.children.length; i++) {
|
|
1360
|
-
const s = n.children[i],
|
|
1361
|
-
if (
|
|
1362
|
-
if (n.leaf ||
|
|
1402
|
+
const s = n.children[i], a = n.leaf ? this.toBBox(s) : s;
|
|
1403
|
+
if (yt(e, a)) {
|
|
1404
|
+
if (n.leaf || It(e, a)) return !0;
|
|
1363
1405
|
o.push(s);
|
|
1364
1406
|
}
|
|
1365
1407
|
}
|
|
@@ -1392,20 +1434,20 @@ class vn {
|
|
|
1392
1434
|
return e && this._insert(e, this.data.height - 1), this;
|
|
1393
1435
|
}
|
|
1394
1436
|
clear() {
|
|
1395
|
-
return this.data =
|
|
1437
|
+
return this.data = Z([]), this;
|
|
1396
1438
|
}
|
|
1397
1439
|
remove(e, n) {
|
|
1398
1440
|
if (!e) return this;
|
|
1399
1441
|
let o = this.data;
|
|
1400
|
-
const i = this.toBBox(e), s = [],
|
|
1401
|
-
let
|
|
1442
|
+
const i = this.toBBox(e), s = [], a = [];
|
|
1443
|
+
let r, l, f;
|
|
1402
1444
|
for (; o || s.length; ) {
|
|
1403
|
-
if (o || (o = s.pop(),
|
|
1404
|
-
const
|
|
1405
|
-
if (
|
|
1406
|
-
return o.children.splice(
|
|
1445
|
+
if (o || (o = s.pop(), l = s[s.length - 1], r = a.pop(), f = !0), o.leaf) {
|
|
1446
|
+
const u = Gn(e, o.children, n);
|
|
1447
|
+
if (u !== -1)
|
|
1448
|
+
return o.children.splice(u, 1), s.push(o), this._condense(s), this;
|
|
1407
1449
|
}
|
|
1408
|
-
!
|
|
1450
|
+
!f && !o.leaf && It(o, i) ? (s.push(o), a.push(r), r = 0, l = o, o = o.children[0]) : l ? (r++, o = l.children[r], f = !1) : o = null;
|
|
1409
1451
|
}
|
|
1410
1452
|
return this;
|
|
1411
1453
|
}
|
|
@@ -1432,36 +1474,36 @@ class vn {
|
|
|
1432
1474
|
}
|
|
1433
1475
|
_build(e, n, o, i) {
|
|
1434
1476
|
const s = o - n + 1;
|
|
1435
|
-
let
|
|
1436
|
-
if (s <=
|
|
1437
|
-
return
|
|
1438
|
-
i || (i = Math.ceil(Math.log(s) / Math.log(
|
|
1439
|
-
const
|
|
1440
|
-
|
|
1441
|
-
for (let
|
|
1442
|
-
const h = Math.min(
|
|
1443
|
-
|
|
1444
|
-
for (let
|
|
1445
|
-
const
|
|
1446
|
-
|
|
1477
|
+
let a = this._maxEntries, r;
|
|
1478
|
+
if (s <= a)
|
|
1479
|
+
return r = Z(e.slice(n, o + 1)), J(r, this.toBBox), r;
|
|
1480
|
+
i || (i = Math.ceil(Math.log(s) / Math.log(a)), a = Math.ceil(s / Math.pow(a, i - 1))), r = Z([]), r.leaf = !1, r.height = i;
|
|
1481
|
+
const l = Math.ceil(s / a), f = l * Math.ceil(Math.sqrt(a));
|
|
1482
|
+
oe(e, n, o, f, this.compareMinX);
|
|
1483
|
+
for (let u = n; u <= o; u += f) {
|
|
1484
|
+
const h = Math.min(u + f - 1, o);
|
|
1485
|
+
oe(e, u, h, l, this.compareMinY);
|
|
1486
|
+
for (let g = u; g <= h; g += l) {
|
|
1487
|
+
const p = Math.min(g + l - 1, h);
|
|
1488
|
+
r.children.push(this._build(e, g, p, i - 1));
|
|
1447
1489
|
}
|
|
1448
1490
|
}
|
|
1449
|
-
return
|
|
1491
|
+
return J(r, this.toBBox), r;
|
|
1450
1492
|
}
|
|
1451
1493
|
_chooseSubtree(e, n, o, i) {
|
|
1452
1494
|
for (; i.push(n), !(n.leaf || i.length - 1 === o); ) {
|
|
1453
|
-
let s = 1 / 0,
|
|
1454
|
-
for (let
|
|
1455
|
-
const
|
|
1456
|
-
h <
|
|
1495
|
+
let s = 1 / 0, a = 1 / 0, r;
|
|
1496
|
+
for (let l = 0; l < n.children.length; l++) {
|
|
1497
|
+
const f = n.children[l], u = kt(f), h = Zn(e, f) - u;
|
|
1498
|
+
h < a ? (a = h, s = u < s ? u : s, r = f) : h === a && u < s && (s = u, r = f);
|
|
1457
1499
|
}
|
|
1458
|
-
n =
|
|
1500
|
+
n = r || n.children[0];
|
|
1459
1501
|
}
|
|
1460
1502
|
return n;
|
|
1461
1503
|
}
|
|
1462
1504
|
_insert(e, n, o) {
|
|
1463
|
-
const i = o ? e : this.toBBox(e), s = [],
|
|
1464
|
-
for (
|
|
1505
|
+
const i = o ? e : this.toBBox(e), s = [], a = this._chooseSubtree(i, this.data, n, s);
|
|
1506
|
+
for (a.children.push(e), it(a, i); n >= 0 && s[n].children.length > this._maxEntries; )
|
|
1465
1507
|
this._split(s, n), n--;
|
|
1466
1508
|
this._adjustParentBBoxes(i, s, n);
|
|
1467
1509
|
}
|
|
@@ -1469,95 +1511,95 @@ class vn {
|
|
|
1469
1511
|
_split(e, n) {
|
|
1470
1512
|
const o = e[n], i = o.children.length, s = this._minEntries;
|
|
1471
1513
|
this._chooseSplitAxis(o, s, i);
|
|
1472
|
-
const
|
|
1473
|
-
|
|
1514
|
+
const a = this._chooseSplitIndex(o, s, i), r = Z(o.children.splice(a, o.children.length - a));
|
|
1515
|
+
r.height = o.height, r.leaf = o.leaf, J(o, this.toBBox), J(r, this.toBBox), n ? e[n - 1].children.push(r) : this._splitRoot(o, r);
|
|
1474
1516
|
}
|
|
1475
1517
|
_splitRoot(e, n) {
|
|
1476
|
-
this.data =
|
|
1518
|
+
this.data = Z([e, n]), this.data.height = e.height + 1, this.data.leaf = !1, J(this.data, this.toBBox);
|
|
1477
1519
|
}
|
|
1478
1520
|
_chooseSplitIndex(e, n, o) {
|
|
1479
|
-
let i, s = 1 / 0,
|
|
1480
|
-
for (let
|
|
1481
|
-
const
|
|
1482
|
-
|
|
1521
|
+
let i, s = 1 / 0, a = 1 / 0;
|
|
1522
|
+
for (let r = n; r <= o - n; r++) {
|
|
1523
|
+
const l = ot(e, 0, r, this.toBBox), f = ot(e, r, o, this.toBBox), u = to(l, f), h = kt(l) + kt(f);
|
|
1524
|
+
u < s ? (s = u, i = r, a = h < a ? h : a) : u === s && h < a && (a = h, i = r);
|
|
1483
1525
|
}
|
|
1484
1526
|
return i || o - n;
|
|
1485
1527
|
}
|
|
1486
1528
|
// sorts node children by the best axis for split
|
|
1487
1529
|
_chooseSplitAxis(e, n, o) {
|
|
1488
|
-
const i = e.leaf ? this.compareMinX :
|
|
1489
|
-
|
|
1530
|
+
const i = e.leaf ? this.compareMinX : Qn, s = e.leaf ? this.compareMinY : Jn, a = this._allDistMargin(e, n, o, i), r = this._allDistMargin(e, n, o, s);
|
|
1531
|
+
a < r && e.children.sort(i);
|
|
1490
1532
|
}
|
|
1491
1533
|
// total margin of all possible split distributions where each node is at least m full
|
|
1492
1534
|
_allDistMargin(e, n, o, i) {
|
|
1493
1535
|
e.children.sort(i);
|
|
1494
|
-
const s = this.toBBox,
|
|
1495
|
-
let
|
|
1496
|
-
for (let
|
|
1497
|
-
const
|
|
1498
|
-
|
|
1536
|
+
const s = this.toBBox, a = ot(e, 0, n, s), r = ot(e, o - n, o, s);
|
|
1537
|
+
let l = mt(a) + mt(r);
|
|
1538
|
+
for (let f = n; f < o - n; f++) {
|
|
1539
|
+
const u = e.children[f];
|
|
1540
|
+
it(a, e.leaf ? s(u) : u), l += mt(a);
|
|
1499
1541
|
}
|
|
1500
|
-
for (let
|
|
1501
|
-
const
|
|
1502
|
-
|
|
1542
|
+
for (let f = o - n - 1; f >= n; f--) {
|
|
1543
|
+
const u = e.children[f];
|
|
1544
|
+
it(r, e.leaf ? s(u) : u), l += mt(r);
|
|
1503
1545
|
}
|
|
1504
|
-
return
|
|
1546
|
+
return l;
|
|
1505
1547
|
}
|
|
1506
1548
|
_adjustParentBBoxes(e, n, o) {
|
|
1507
1549
|
for (let i = o; i >= 0; i--)
|
|
1508
|
-
|
|
1550
|
+
it(n[i], e);
|
|
1509
1551
|
}
|
|
1510
1552
|
_condense(e) {
|
|
1511
1553
|
for (let n = e.length - 1, o; n >= 0; n--)
|
|
1512
|
-
e[n].children.length === 0 ? n > 0 ? (o = e[n - 1].children, o.splice(o.indexOf(e[n]), 1)) : this.clear() :
|
|
1554
|
+
e[n].children.length === 0 ? n > 0 ? (o = e[n - 1].children, o.splice(o.indexOf(e[n]), 1)) : this.clear() : J(e[n], this.toBBox);
|
|
1513
1555
|
}
|
|
1514
1556
|
}
|
|
1515
|
-
function
|
|
1557
|
+
function Gn(t, e, n) {
|
|
1516
1558
|
if (!n) return e.indexOf(t);
|
|
1517
1559
|
for (let o = 0; o < e.length; o++)
|
|
1518
1560
|
if (n(t, e[o])) return o;
|
|
1519
1561
|
return -1;
|
|
1520
1562
|
}
|
|
1521
|
-
function
|
|
1522
|
-
|
|
1563
|
+
function J(t, e) {
|
|
1564
|
+
ot(t, 0, t.children.length, e, t);
|
|
1523
1565
|
}
|
|
1524
|
-
function
|
|
1525
|
-
i || (i =
|
|
1566
|
+
function ot(t, e, n, o, i) {
|
|
1567
|
+
i || (i = Z(null)), i.minX = 1 / 0, i.minY = 1 / 0, i.maxX = -1 / 0, i.maxY = -1 / 0;
|
|
1526
1568
|
for (let s = e; s < n; s++) {
|
|
1527
|
-
const
|
|
1528
|
-
|
|
1569
|
+
const a = t.children[s];
|
|
1570
|
+
it(i, t.leaf ? o(a) : a);
|
|
1529
1571
|
}
|
|
1530
1572
|
return i;
|
|
1531
1573
|
}
|
|
1532
|
-
function
|
|
1574
|
+
function it(t, e) {
|
|
1533
1575
|
return t.minX = Math.min(t.minX, e.minX), t.minY = Math.min(t.minY, e.minY), t.maxX = Math.max(t.maxX, e.maxX), t.maxY = Math.max(t.maxY, e.maxY), t;
|
|
1534
1576
|
}
|
|
1535
|
-
function
|
|
1577
|
+
function Qn(t, e) {
|
|
1536
1578
|
return t.minX - e.minX;
|
|
1537
1579
|
}
|
|
1538
|
-
function
|
|
1580
|
+
function Jn(t, e) {
|
|
1539
1581
|
return t.minY - e.minY;
|
|
1540
1582
|
}
|
|
1541
|
-
function
|
|
1583
|
+
function kt(t) {
|
|
1542
1584
|
return (t.maxX - t.minX) * (t.maxY - t.minY);
|
|
1543
1585
|
}
|
|
1544
|
-
function
|
|
1586
|
+
function mt(t) {
|
|
1545
1587
|
return t.maxX - t.minX + (t.maxY - t.minY);
|
|
1546
1588
|
}
|
|
1547
|
-
function
|
|
1589
|
+
function Zn(t, e) {
|
|
1548
1590
|
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
1591
|
}
|
|
1550
|
-
function
|
|
1592
|
+
function to(t, e) {
|
|
1551
1593
|
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
1594
|
return Math.max(0, i - n) * Math.max(0, s - o);
|
|
1553
1595
|
}
|
|
1554
|
-
function
|
|
1596
|
+
function It(t, e) {
|
|
1555
1597
|
return t.minX <= e.minX && t.minY <= e.minY && e.maxX <= t.maxX && e.maxY <= t.maxY;
|
|
1556
1598
|
}
|
|
1557
|
-
function
|
|
1599
|
+
function yt(t, e) {
|
|
1558
1600
|
return e.minX <= t.maxX && e.minY <= t.maxY && e.maxX >= t.minX && e.maxY >= t.minY;
|
|
1559
1601
|
}
|
|
1560
|
-
function
|
|
1602
|
+
function Z(t) {
|
|
1561
1603
|
return {
|
|
1562
1604
|
children: t,
|
|
1563
1605
|
height: 1,
|
|
@@ -1568,326 +1610,726 @@ function W(t) {
|
|
|
1568
1610
|
maxY: -1 / 0
|
|
1569
1611
|
};
|
|
1570
1612
|
}
|
|
1571
|
-
function
|
|
1613
|
+
function oe(t, e, n, o, i) {
|
|
1572
1614
|
const s = [e, n];
|
|
1573
1615
|
for (; s.length; ) {
|
|
1574
1616
|
if (n = s.pop(), e = s.pop(), n - e <= o) continue;
|
|
1575
|
-
const
|
|
1576
|
-
|
|
1617
|
+
const a = e + Math.ceil((n - e) / o / 2) * o;
|
|
1618
|
+
be(t, a, e, n, i), s.push(e, a, a, n);
|
|
1577
1619
|
}
|
|
1578
1620
|
}
|
|
1579
|
-
const
|
|
1580
|
-
const n = new
|
|
1581
|
-
const
|
|
1582
|
-
const
|
|
1583
|
-
return Array.from(
|
|
1584
|
-
}), S =
|
|
1585
|
-
return S.map((
|
|
1586
|
-
const { x:
|
|
1621
|
+
const eo = (t, e) => {
|
|
1622
|
+
const n = new qn(), o = /* @__PURE__ */ new Map(), i = (d, c) => {
|
|
1623
|
+
const w = d.selector.flatMap((T) => {
|
|
1624
|
+
const L = W([T]) ? T.range : le(T, e).range;
|
|
1625
|
+
return Array.from(L.getClientRects());
|
|
1626
|
+
}), S = Ve(w).map(({ left: T, top: L, right: O, bottom: E }) => new DOMRect(T - c.left, L - c.top, O - T, E - L));
|
|
1627
|
+
return S.map((T) => {
|
|
1628
|
+
const { x: L, y: O, width: E, height: R } = T;
|
|
1587
1629
|
return {
|
|
1588
|
-
minX:
|
|
1589
|
-
minY:
|
|
1590
|
-
maxX:
|
|
1591
|
-
maxY:
|
|
1630
|
+
minX: L,
|
|
1631
|
+
minY: O,
|
|
1632
|
+
maxX: L + E,
|
|
1633
|
+
maxY: O + R,
|
|
1592
1634
|
annotation: {
|
|
1593
|
-
id:
|
|
1635
|
+
id: d.annotation,
|
|
1594
1636
|
rects: S
|
|
1595
1637
|
}
|
|
1596
1638
|
};
|
|
1597
1639
|
});
|
|
1598
|
-
}, s = () => [...o.values()],
|
|
1640
|
+
}, s = () => [...o.values()], a = () => {
|
|
1599
1641
|
n.clear(), o.clear();
|
|
1600
|
-
},
|
|
1601
|
-
const
|
|
1602
|
-
|
|
1603
|
-
},
|
|
1604
|
-
const
|
|
1605
|
-
|
|
1606
|
-
},
|
|
1607
|
-
d
|
|
1608
|
-
},
|
|
1609
|
-
|
|
1610
|
-
const
|
|
1611
|
-
S.forEach(({ target:
|
|
1612
|
-
const
|
|
1613
|
-
n.load(
|
|
1614
|
-
}, h = (
|
|
1642
|
+
}, r = (d) => {
|
|
1643
|
+
const c = i(d, e.getBoundingClientRect());
|
|
1644
|
+
c.forEach((w) => n.insert(w)), o.set(d.annotation, c);
|
|
1645
|
+
}, l = (d) => {
|
|
1646
|
+
const c = o.get(d.annotation);
|
|
1647
|
+
c && (c.forEach((w) => n.remove(w)), o.delete(d.annotation));
|
|
1648
|
+
}, f = (d) => {
|
|
1649
|
+
l(d), r(d);
|
|
1650
|
+
}, u = (d, c = !0) => {
|
|
1651
|
+
c && a();
|
|
1652
|
+
const w = e.getBoundingClientRect(), S = d.map((L) => ({ target: L, rects: i(L, w) }));
|
|
1653
|
+
S.forEach(({ target: L, rects: O }) => o.set(L.annotation, O));
|
|
1654
|
+
const T = S.flatMap(({ rects: L }) => L);
|
|
1655
|
+
n.load(T);
|
|
1656
|
+
}, h = (d, c, w = !1) => {
|
|
1615
1657
|
const S = n.search({
|
|
1616
|
-
minX:
|
|
1617
|
-
minY:
|
|
1618
|
-
maxX:
|
|
1619
|
-
maxY:
|
|
1620
|
-
}),
|
|
1621
|
-
return S.length > 0 ? (S.sort((
|
|
1622
|
-
},
|
|
1623
|
-
const
|
|
1624
|
-
if (
|
|
1658
|
+
minX: d,
|
|
1659
|
+
minY: c,
|
|
1660
|
+
maxX: d,
|
|
1661
|
+
maxY: c
|
|
1662
|
+
}), T = (L) => L.annotation.rects.reduce((O, E) => O + E.width * E.height, 0);
|
|
1663
|
+
return S.length > 0 ? (S.sort((L, O) => T(L) - T(O)), w ? S.map((L) => L.annotation.id) : [S[0].annotation.id]) : [];
|
|
1664
|
+
}, g = (d) => {
|
|
1665
|
+
const c = p(d);
|
|
1666
|
+
if (c.length === 0)
|
|
1625
1667
|
return;
|
|
1626
|
-
let
|
|
1627
|
-
for (let
|
|
1628
|
-
const
|
|
1629
|
-
|
|
1668
|
+
let w = c[0].left, S = c[0].top, T = c[0].right, L = c[0].bottom;
|
|
1669
|
+
for (let O = 1; O < c.length; O++) {
|
|
1670
|
+
const E = c[O];
|
|
1671
|
+
w = Math.min(w, E.left), S = Math.min(S, E.top), T = Math.max(T, E.right), L = Math.max(L, E.bottom);
|
|
1630
1672
|
}
|
|
1631
|
-
return new DOMRect(
|
|
1632
|
-
},
|
|
1633
|
-
const
|
|
1634
|
-
return
|
|
1673
|
+
return new DOMRect(w, S, T - w, L - S);
|
|
1674
|
+
}, p = (d) => {
|
|
1675
|
+
const c = o.get(d);
|
|
1676
|
+
return c ? c[0].annotation.rects : [];
|
|
1635
1677
|
};
|
|
1636
1678
|
return {
|
|
1637
1679
|
all: s,
|
|
1638
|
-
clear:
|
|
1680
|
+
clear: a,
|
|
1639
1681
|
getAt: h,
|
|
1640
|
-
getAnnotationBounds:
|
|
1641
|
-
getAnnotationRects:
|
|
1642
|
-
getIntersecting: (
|
|
1643
|
-
const
|
|
1644
|
-
return Array.from(
|
|
1645
|
-
annotation: t.getAnnotation(
|
|
1646
|
-
rects:
|
|
1647
|
-
})).filter((
|
|
1682
|
+
getAnnotationBounds: g,
|
|
1683
|
+
getAnnotationRects: p,
|
|
1684
|
+
getIntersecting: (d, c, w, S) => {
|
|
1685
|
+
const T = n.search({ minX: d, minY: c, maxX: w, maxY: S }), L = new Set(T.map((O) => O.annotation.id));
|
|
1686
|
+
return Array.from(L).map((O) => ({
|
|
1687
|
+
annotation: t.getAnnotation(O),
|
|
1688
|
+
rects: p(O)
|
|
1689
|
+
})).filter((O) => !!O.annotation);
|
|
1648
1690
|
},
|
|
1649
|
-
insert:
|
|
1650
|
-
recalculate: () =>
|
|
1651
|
-
remove:
|
|
1652
|
-
set:
|
|
1691
|
+
insert: r,
|
|
1692
|
+
recalculate: () => u(t.all().map((d) => d.target), !0),
|
|
1693
|
+
remove: l,
|
|
1694
|
+
set: u,
|
|
1653
1695
|
size: () => n.all().length,
|
|
1654
|
-
update:
|
|
1696
|
+
update: f
|
|
1655
1697
|
};
|
|
1656
|
-
},
|
|
1657
|
-
const n =
|
|
1698
|
+
}, no = (t, e) => {
|
|
1699
|
+
const n = Tn(), o = eo(n, t), i = gn(n);
|
|
1658
1700
|
i.setUserSelectAction(e);
|
|
1659
|
-
const s =
|
|
1660
|
-
const
|
|
1661
|
-
return
|
|
1662
|
-
},
|
|
1663
|
-
const
|
|
1664
|
-
return S.length > 0 ? (console.warn("Could not revive all targets for these annotations:", S), n.bulkAddAnnotation(
|
|
1665
|
-
},
|
|
1666
|
-
const
|
|
1667
|
-
return
|
|
1668
|
-
n.getAnnotation(S.id) ? n.updateAnnotation(S,
|
|
1669
|
-
}),
|
|
1670
|
-
},
|
|
1671
|
-
const
|
|
1672
|
-
n.updateTarget(
|
|
1673
|
-
}, h = (
|
|
1674
|
-
const
|
|
1675
|
-
n.bulkUpdateTargets(
|
|
1676
|
-
},
|
|
1677
|
-
const
|
|
1701
|
+
const s = hn(n), a = Bn(), r = (m, d = k.LOCAL) => {
|
|
1702
|
+
const c = xt(m, t), w = W(c.target.selector);
|
|
1703
|
+
return w && n.addAnnotation(c, d), w;
|
|
1704
|
+
}, l = (m, d = !0, c = k.LOCAL) => {
|
|
1705
|
+
const w = m.map((T) => xt(T, t)), S = w.filter((T) => !W(T.target.selector));
|
|
1706
|
+
return S.length > 0 ? (console.warn("Could not revive all targets for these annotations:", S), n.bulkAddAnnotation(w, d, c), S) : (n.bulkAddAnnotation(w, d, c), []);
|
|
1707
|
+
}, f = (m, d = k.LOCAL) => {
|
|
1708
|
+
const c = m.map((S) => xt(S, t)), w = c.filter((S) => !W(S.target.selector));
|
|
1709
|
+
return w.length > 0 && console.warn("Could not revive all targets for these annotations:", w), c.forEach((S) => {
|
|
1710
|
+
n.getAnnotation(S.id) ? n.updateAnnotation(S, d) : n.addAnnotation(S, d);
|
|
1711
|
+
}), w;
|
|
1712
|
+
}, u = (m, d = k.LOCAL) => {
|
|
1713
|
+
const c = wt(m, t);
|
|
1714
|
+
n.updateTarget(c, d);
|
|
1715
|
+
}, h = (m, d = k.LOCAL) => {
|
|
1716
|
+
const c = m.map((w) => wt(w, t));
|
|
1717
|
+
n.bulkUpdateTargets(c, d);
|
|
1718
|
+
}, g = (m, d, c) => {
|
|
1719
|
+
const w = o.getAt(m, d, !!c).map((T) => n.getAnnotation(T)), S = c ? w.filter(c) : w;
|
|
1678
1720
|
return S.length > 0 ? S[0] : void 0;
|
|
1679
|
-
},
|
|
1680
|
-
const S = o.getAnnotationRects(
|
|
1721
|
+
}, p = (m, d, c, w = 5) => {
|
|
1722
|
+
const S = o.getAnnotationRects(m);
|
|
1681
1723
|
if (S.length !== 0) {
|
|
1682
|
-
if (
|
|
1683
|
-
const
|
|
1684
|
-
if (
|
|
1724
|
+
if (d && c) {
|
|
1725
|
+
const T = S.find(({ top: L, right: O, bottom: E, left: R }) => d >= R - w && d <= O + w && c >= L - w && c <= E + w);
|
|
1726
|
+
if (T) return T;
|
|
1685
1727
|
}
|
|
1686
|
-
return o.getAnnotationBounds(
|
|
1728
|
+
return o.getAnnotationBounds(m);
|
|
1687
1729
|
}
|
|
1688
|
-
},
|
|
1689
|
-
return n.observe(({ changes:
|
|
1690
|
-
const
|
|
1691
|
-
(
|
|
1730
|
+
}, v = (m) => o.getAnnotationRects(m), y = () => o.recalculate();
|
|
1731
|
+
return n.observe(({ changes: m }) => {
|
|
1732
|
+
const d = (m.deleted || []).filter((S) => W(S.target.selector)), c = (m.created || []).filter((S) => W(S.target.selector)), w = (m.updated || []).filter((S) => W(S.newValue.target.selector));
|
|
1733
|
+
(d == null ? void 0 : d.length) > 0 && d.forEach((S) => o.remove(S.target)), c.length > 0 && o.set(c.map((S) => S.target), !1), (w == null ? void 0 : w.length) > 0 && w.forEach(({ newValue: S }) => o.update(S.target));
|
|
1692
1734
|
}), {
|
|
1693
1735
|
store: {
|
|
1694
1736
|
...n,
|
|
1695
|
-
addAnnotation:
|
|
1696
|
-
bulkAddAnnotation:
|
|
1737
|
+
addAnnotation: r,
|
|
1738
|
+
bulkAddAnnotation: l,
|
|
1697
1739
|
bulkUpdateTargets: h,
|
|
1698
|
-
bulkUpsertAnnotations:
|
|
1699
|
-
getAnnotationBounds:
|
|
1700
|
-
getAnnotationRects:
|
|
1701
|
-
getAt:
|
|
1740
|
+
bulkUpsertAnnotations: f,
|
|
1741
|
+
getAnnotationBounds: p,
|
|
1742
|
+
getAnnotationRects: v,
|
|
1743
|
+
getAt: g,
|
|
1702
1744
|
getIntersecting: o.getIntersecting,
|
|
1703
|
-
recalculatePositions:
|
|
1704
|
-
updateTarget:
|
|
1745
|
+
recalculatePositions: y,
|
|
1746
|
+
updateTarget: u
|
|
1705
1747
|
},
|
|
1706
1748
|
selection: i,
|
|
1707
1749
|
hover: s,
|
|
1708
|
-
viewport:
|
|
1750
|
+
viewport: a
|
|
1709
1751
|
};
|
|
1710
|
-
},
|
|
1752
|
+
}, oo = () => {
|
|
1711
1753
|
const t = document.createElement("canvas");
|
|
1712
1754
|
t.width = 2 * window.innerWidth, t.height = 2 * window.innerHeight, t.className = "r6o-presence-layer";
|
|
1713
1755
|
const e = t.getContext("2d");
|
|
1714
1756
|
return e.scale(2, 2), e.translate(0.5, 0.5), t;
|
|
1715
|
-
},
|
|
1716
|
-
const n =
|
|
1757
|
+
}, io = (t, e = {}) => {
|
|
1758
|
+
const n = oo(), o = n.getContext("2d");
|
|
1717
1759
|
document.body.appendChild(n);
|
|
1718
|
-
const i = /* @__PURE__ */ new Map(), s = (
|
|
1719
|
-
return t.on("selectionChange", (
|
|
1720
|
-
s(
|
|
1760
|
+
const i = /* @__PURE__ */ new Map(), s = (u) => Array.from(i.entries()).filter(([h, g]) => g.presenceKey === u.presenceKey).map(([h, g]) => h);
|
|
1761
|
+
return t.on("selectionChange", (u, h) => {
|
|
1762
|
+
s(u).forEach((p) => i.delete(p)), h && h.forEach((p) => i.set(p, u));
|
|
1721
1763
|
}), {
|
|
1722
1764
|
clear: () => {
|
|
1723
|
-
const { width:
|
|
1724
|
-
o.clearRect(-0.5, -0.5,
|
|
1765
|
+
const { width: u, height: h } = n;
|
|
1766
|
+
o.clearRect(-0.5, -0.5, u + 1, h + 1);
|
|
1725
1767
|
},
|
|
1726
1768
|
destroy: () => {
|
|
1727
1769
|
n.remove();
|
|
1728
1770
|
},
|
|
1729
|
-
paint: (
|
|
1771
|
+
paint: (u, h, g) => {
|
|
1730
1772
|
e.font && (o.font = e.font);
|
|
1731
|
-
const
|
|
1732
|
-
if (
|
|
1733
|
-
const { height:
|
|
1734
|
-
o.fillStyle =
|
|
1735
|
-
const
|
|
1736
|
-
return o.fillRect(
|
|
1737
|
-
fill:
|
|
1738
|
-
fillOpacity:
|
|
1773
|
+
const p = i.get(u.annotation.id);
|
|
1774
|
+
if (p) {
|
|
1775
|
+
const { height: v } = u.rects[0], y = u.rects[0].x + h.left, m = u.rects[0].y + h.top;
|
|
1776
|
+
o.fillStyle = p.appearance.color, o.fillRect(y - 2, m - 2.5, 2, v + 5);
|
|
1777
|
+
const d = o.measureText(p.appearance.label), c = d.width + 6, w = d.actualBoundingBoxAscent + d.actualBoundingBoxDescent + 8, S = d.fontBoundingBoxAscent ? 8 : 6.5;
|
|
1778
|
+
return o.fillRect(y - 2, m - 2.5 - w, c, w), o.fillStyle = "#fff", o.fillText(p.appearance.label, y + 1, m - S), {
|
|
1779
|
+
fill: p.appearance.color,
|
|
1780
|
+
fillOpacity: g ? 0.45 : 0.18
|
|
1739
1781
|
};
|
|
1740
1782
|
}
|
|
1741
1783
|
},
|
|
1742
1784
|
reset: () => {
|
|
1743
1785
|
n.width = 2 * window.innerWidth, n.height = 2 * window.innerHeight;
|
|
1744
|
-
const
|
|
1745
|
-
|
|
1786
|
+
const u = n.getContext("2d");
|
|
1787
|
+
u.scale(2, 2), u.translate(0.5, 0.5);
|
|
1746
1788
|
}
|
|
1747
1789
|
};
|
|
1748
|
-
},
|
|
1790
|
+
}, _t = typeof navigator < "u" ? navigator.userAgent.toLowerCase().indexOf("firefox") > 0 : !1;
|
|
1791
|
+
function Nt(t, e, n, o) {
|
|
1792
|
+
t.addEventListener ? t.addEventListener(e, n, o) : t.attachEvent && t.attachEvent("on".concat(e), n);
|
|
1793
|
+
}
|
|
1794
|
+
function nt(t, e, n, o) {
|
|
1795
|
+
t.removeEventListener ? t.removeEventListener(e, n, o) : t.detachEvent && t.detachEvent("on".concat(e), n);
|
|
1796
|
+
}
|
|
1797
|
+
function we(t, e) {
|
|
1798
|
+
const n = e.slice(0, e.length - 1);
|
|
1799
|
+
for (let o = 0; o < n.length; o++) n[o] = t[n[o].toLowerCase()];
|
|
1800
|
+
return n;
|
|
1801
|
+
}
|
|
1802
|
+
function ve(t) {
|
|
1803
|
+
typeof t != "string" && (t = ""), t = t.replace(/\s/g, "");
|
|
1804
|
+
const e = t.split(",");
|
|
1805
|
+
let n = e.lastIndexOf("");
|
|
1806
|
+
for (; n >= 0; )
|
|
1807
|
+
e[n - 1] += ",", e.splice(n, 1), n = e.lastIndexOf("");
|
|
1808
|
+
return e;
|
|
1809
|
+
}
|
|
1810
|
+
function so(t, e) {
|
|
1811
|
+
const n = t.length >= e.length ? t : e, o = t.length >= e.length ? e : t;
|
|
1812
|
+
let i = !0;
|
|
1813
|
+
for (let s = 0; s < n.length; s++)
|
|
1814
|
+
o.indexOf(n[s]) === -1 && (i = !1);
|
|
1815
|
+
return i;
|
|
1816
|
+
}
|
|
1817
|
+
const at = {
|
|
1818
|
+
backspace: 8,
|
|
1819
|
+
"⌫": 8,
|
|
1820
|
+
tab: 9,
|
|
1821
|
+
clear: 12,
|
|
1822
|
+
enter: 13,
|
|
1823
|
+
"↩": 13,
|
|
1824
|
+
return: 13,
|
|
1825
|
+
esc: 27,
|
|
1826
|
+
escape: 27,
|
|
1827
|
+
space: 32,
|
|
1828
|
+
left: 37,
|
|
1829
|
+
up: 38,
|
|
1830
|
+
right: 39,
|
|
1831
|
+
down: 40,
|
|
1832
|
+
del: 46,
|
|
1833
|
+
delete: 46,
|
|
1834
|
+
ins: 45,
|
|
1835
|
+
insert: 45,
|
|
1836
|
+
home: 36,
|
|
1837
|
+
end: 35,
|
|
1838
|
+
pageup: 33,
|
|
1839
|
+
pagedown: 34,
|
|
1840
|
+
capslock: 20,
|
|
1841
|
+
num_0: 96,
|
|
1842
|
+
num_1: 97,
|
|
1843
|
+
num_2: 98,
|
|
1844
|
+
num_3: 99,
|
|
1845
|
+
num_4: 100,
|
|
1846
|
+
num_5: 101,
|
|
1847
|
+
num_6: 102,
|
|
1848
|
+
num_7: 103,
|
|
1849
|
+
num_8: 104,
|
|
1850
|
+
num_9: 105,
|
|
1851
|
+
num_multiply: 106,
|
|
1852
|
+
num_add: 107,
|
|
1853
|
+
num_enter: 108,
|
|
1854
|
+
num_subtract: 109,
|
|
1855
|
+
num_decimal: 110,
|
|
1856
|
+
num_divide: 111,
|
|
1857
|
+
"⇪": 20,
|
|
1858
|
+
",": 188,
|
|
1859
|
+
".": 190,
|
|
1860
|
+
"/": 191,
|
|
1861
|
+
"`": 192,
|
|
1862
|
+
"-": _t ? 173 : 189,
|
|
1863
|
+
"=": _t ? 61 : 187,
|
|
1864
|
+
";": _t ? 59 : 186,
|
|
1865
|
+
"'": 222,
|
|
1866
|
+
"[": 219,
|
|
1867
|
+
"]": 221,
|
|
1868
|
+
"\\": 220
|
|
1869
|
+
}, j = {
|
|
1870
|
+
// shiftKey
|
|
1871
|
+
"⇧": 16,
|
|
1872
|
+
shift: 16,
|
|
1873
|
+
// altKey
|
|
1874
|
+
"⌥": 18,
|
|
1875
|
+
alt: 18,
|
|
1876
|
+
option: 18,
|
|
1877
|
+
// ctrlKey
|
|
1878
|
+
"⌃": 17,
|
|
1879
|
+
ctrl: 17,
|
|
1880
|
+
control: 17,
|
|
1881
|
+
// metaKey
|
|
1882
|
+
"⌘": 91,
|
|
1883
|
+
cmd: 91,
|
|
1884
|
+
command: 91
|
|
1885
|
+
}, Yt = {
|
|
1886
|
+
16: "shiftKey",
|
|
1887
|
+
18: "altKey",
|
|
1888
|
+
17: "ctrlKey",
|
|
1889
|
+
91: "metaKey",
|
|
1890
|
+
shiftKey: 16,
|
|
1891
|
+
ctrlKey: 17,
|
|
1892
|
+
altKey: 18,
|
|
1893
|
+
metaKey: 91
|
|
1894
|
+
}, Y = {
|
|
1895
|
+
16: !1,
|
|
1896
|
+
18: !1,
|
|
1897
|
+
17: !1,
|
|
1898
|
+
91: !1
|
|
1899
|
+
}, _ = {};
|
|
1900
|
+
for (let t = 1; t < 20; t++)
|
|
1901
|
+
at["f".concat(t)] = 111 + t;
|
|
1902
|
+
let I = [], rt = null, Ae = "all";
|
|
1903
|
+
const F = /* @__PURE__ */ new Map(), lt = (t) => at[t.toLowerCase()] || j[t.toLowerCase()] || t.toUpperCase().charCodeAt(0), ro = (t) => Object.keys(at).find((e) => at[e] === t), ao = (t) => Object.keys(j).find((e) => j[e] === t);
|
|
1904
|
+
function xe(t) {
|
|
1905
|
+
Ae = t || "all";
|
|
1906
|
+
}
|
|
1907
|
+
function ct() {
|
|
1908
|
+
return Ae || "all";
|
|
1909
|
+
}
|
|
1910
|
+
function co() {
|
|
1911
|
+
return I.slice(0);
|
|
1912
|
+
}
|
|
1913
|
+
function lo() {
|
|
1914
|
+
return I.map((t) => ro(t) || ao(t) || String.fromCharCode(t));
|
|
1915
|
+
}
|
|
1916
|
+
function uo() {
|
|
1917
|
+
const t = [];
|
|
1918
|
+
return Object.keys(_).forEach((e) => {
|
|
1919
|
+
_[e].forEach((n) => {
|
|
1920
|
+
let {
|
|
1921
|
+
key: o,
|
|
1922
|
+
scope: i,
|
|
1923
|
+
mods: s,
|
|
1924
|
+
shortcut: a
|
|
1925
|
+
} = n;
|
|
1926
|
+
t.push({
|
|
1927
|
+
scope: i,
|
|
1928
|
+
shortcut: a,
|
|
1929
|
+
mods: s,
|
|
1930
|
+
keys: o.split("+").map((r) => lt(r))
|
|
1931
|
+
});
|
|
1932
|
+
});
|
|
1933
|
+
}), t;
|
|
1934
|
+
}
|
|
1935
|
+
function fo(t) {
|
|
1936
|
+
const e = t.target || t.srcElement, {
|
|
1937
|
+
tagName: n
|
|
1938
|
+
} = e;
|
|
1939
|
+
let o = !0;
|
|
1940
|
+
const i = n === "INPUT" && !["checkbox", "radio", "range", "button", "file", "reset", "submit", "color"].includes(e.type);
|
|
1941
|
+
return (e.isContentEditable || (i || n === "TEXTAREA" || n === "SELECT") && !e.readOnly) && (o = !1), o;
|
|
1942
|
+
}
|
|
1943
|
+
function ho(t) {
|
|
1944
|
+
return typeof t == "string" && (t = lt(t)), I.indexOf(t) !== -1;
|
|
1945
|
+
}
|
|
1946
|
+
function po(t, e) {
|
|
1947
|
+
let n, o;
|
|
1948
|
+
t || (t = ct());
|
|
1949
|
+
for (const i in _)
|
|
1950
|
+
if (Object.prototype.hasOwnProperty.call(_, i))
|
|
1951
|
+
for (n = _[i], o = 0; o < n.length; )
|
|
1952
|
+
n[o].scope === t ? n.splice(o, 1).forEach((a) => {
|
|
1953
|
+
let {
|
|
1954
|
+
element: r
|
|
1955
|
+
} = a;
|
|
1956
|
+
return $t(r);
|
|
1957
|
+
}) : o++;
|
|
1958
|
+
ct() === t && xe(e || "all");
|
|
1959
|
+
}
|
|
1960
|
+
function go(t) {
|
|
1961
|
+
let e = t.keyCode || t.which || t.charCode;
|
|
1962
|
+
const n = I.indexOf(e);
|
|
1963
|
+
if (n >= 0 && I.splice(n, 1), t.key && t.key.toLowerCase() === "meta" && I.splice(0, I.length), (e === 93 || e === 224) && (e = 91), e in Y) {
|
|
1964
|
+
Y[e] = !1;
|
|
1965
|
+
for (const o in j) j[o] === e && (P[o] = !1);
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
function Ee(t) {
|
|
1969
|
+
if (typeof t > "u")
|
|
1970
|
+
Object.keys(_).forEach((i) => {
|
|
1971
|
+
Array.isArray(_[i]) && _[i].forEach((s) => bt(s)), delete _[i];
|
|
1972
|
+
}), $t(null);
|
|
1973
|
+
else if (Array.isArray(t))
|
|
1974
|
+
t.forEach((i) => {
|
|
1975
|
+
i.key && bt(i);
|
|
1976
|
+
});
|
|
1977
|
+
else if (typeof t == "object")
|
|
1978
|
+
t.key && bt(t);
|
|
1979
|
+
else if (typeof t == "string") {
|
|
1980
|
+
for (var e = arguments.length, n = new Array(e > 1 ? e - 1 : 0), o = 1; o < e; o++)
|
|
1981
|
+
n[o - 1] = arguments[o];
|
|
1982
|
+
let [i, s] = n;
|
|
1983
|
+
typeof i == "function" && (s = i, i = ""), bt({
|
|
1984
|
+
key: t,
|
|
1985
|
+
scope: i,
|
|
1986
|
+
method: s,
|
|
1987
|
+
splitKey: "+"
|
|
1988
|
+
});
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
const bt = (t) => {
|
|
1992
|
+
let {
|
|
1993
|
+
key: e,
|
|
1994
|
+
scope: n,
|
|
1995
|
+
method: o,
|
|
1996
|
+
splitKey: i = "+"
|
|
1997
|
+
} = t;
|
|
1998
|
+
ve(e).forEach((a) => {
|
|
1999
|
+
const r = a.split(i), l = r.length, f = r[l - 1], u = f === "*" ? "*" : lt(f);
|
|
2000
|
+
if (!_[u]) return;
|
|
2001
|
+
n || (n = ct());
|
|
2002
|
+
const h = l > 1 ? we(j, r) : [], g = [];
|
|
2003
|
+
_[u] = _[u].filter((p) => {
|
|
2004
|
+
const y = (o ? p.method === o : !0) && p.scope === n && so(p.mods, h);
|
|
2005
|
+
return y && g.push(p.element), !y;
|
|
2006
|
+
}), g.forEach((p) => $t(p));
|
|
2007
|
+
});
|
|
2008
|
+
};
|
|
2009
|
+
function ie(t, e, n, o) {
|
|
2010
|
+
if (e.element !== o)
|
|
2011
|
+
return;
|
|
1749
2012
|
let i;
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
2013
|
+
if (e.scope === n || e.scope === "all") {
|
|
2014
|
+
i = e.mods.length > 0;
|
|
2015
|
+
for (const s in Y)
|
|
2016
|
+
Object.prototype.hasOwnProperty.call(Y, s) && (!Y[s] && e.mods.indexOf(+s) > -1 || Y[s] && e.mods.indexOf(+s) === -1) && (i = !1);
|
|
2017
|
+
(e.mods.length === 0 && !Y[16] && !Y[18] && !Y[17] && !Y[91] || i || e.shortcut === "*") && (e.keys = [], e.keys = e.keys.concat(I), e.method(t, e) === !1 && (t.preventDefault ? t.preventDefault() : t.returnValue = !1, t.stopPropagation && t.stopPropagation(), t.cancelBubble && (t.cancelBubble = !0)));
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
function se(t, e) {
|
|
2021
|
+
const n = _["*"];
|
|
2022
|
+
let o = t.keyCode || t.which || t.charCode;
|
|
2023
|
+
if (!P.filter.call(this, t)) return;
|
|
2024
|
+
if ((o === 93 || o === 224) && (o = 91), I.indexOf(o) === -1 && o !== 229 && I.push(o), ["ctrlKey", "altKey", "shiftKey", "metaKey"].forEach((r) => {
|
|
2025
|
+
const l = Yt[r];
|
|
2026
|
+
t[r] && I.indexOf(l) === -1 ? I.push(l) : !t[r] && I.indexOf(l) > -1 ? I.splice(I.indexOf(l), 1) : r === "metaKey" && t[r] && I.length === 3 && (t.ctrlKey || t.shiftKey || t.altKey || (I = I.slice(I.indexOf(l))));
|
|
2027
|
+
}), o in Y) {
|
|
2028
|
+
Y[o] = !0;
|
|
2029
|
+
for (const r in j)
|
|
2030
|
+
j[r] === o && (P[r] = !0);
|
|
2031
|
+
if (!n) return;
|
|
2032
|
+
}
|
|
2033
|
+
for (const r in Y)
|
|
2034
|
+
Object.prototype.hasOwnProperty.call(Y, r) && (Y[r] = t[Yt[r]]);
|
|
2035
|
+
t.getModifierState && !(t.altKey && !t.ctrlKey) && t.getModifierState("AltGraph") && (I.indexOf(17) === -1 && I.push(17), I.indexOf(18) === -1 && I.push(18), Y[17] = !0, Y[18] = !0);
|
|
2036
|
+
const i = ct();
|
|
2037
|
+
if (n)
|
|
2038
|
+
for (let r = 0; r < n.length; r++)
|
|
2039
|
+
n[r].scope === i && (t.type === "keydown" && n[r].keydown || t.type === "keyup" && n[r].keyup) && ie(t, n[r], i, e);
|
|
2040
|
+
if (!(o in _)) return;
|
|
2041
|
+
const s = _[o], a = s.length;
|
|
2042
|
+
for (let r = 0; r < a; r++)
|
|
2043
|
+
if ((t.type === "keydown" && s[r].keydown || t.type === "keyup" && s[r].keyup) && s[r].key) {
|
|
2044
|
+
const l = s[r], {
|
|
2045
|
+
splitKey: f
|
|
2046
|
+
} = l, u = l.key.split(f), h = [];
|
|
2047
|
+
for (let g = 0; g < u.length; g++)
|
|
2048
|
+
h.push(lt(u[g]));
|
|
2049
|
+
h.sort().join("") === I.sort().join("") && ie(t, l, i, e);
|
|
2050
|
+
}
|
|
2051
|
+
}
|
|
2052
|
+
function P(t, e, n) {
|
|
2053
|
+
I = [];
|
|
2054
|
+
const o = ve(t);
|
|
2055
|
+
let i = [], s = "all", a = document, r = 0, l = !1, f = !0, u = "+", h = !1, g = !1;
|
|
2056
|
+
for (n === void 0 && typeof e == "function" && (n = e), Object.prototype.toString.call(e) === "[object Object]" && (e.scope && (s = e.scope), e.element && (a = e.element), e.keyup && (l = e.keyup), e.keydown !== void 0 && (f = e.keydown), e.capture !== void 0 && (h = e.capture), typeof e.splitKey == "string" && (u = e.splitKey), e.single === !0 && (g = !0)), typeof e == "string" && (s = e), g && Ee(t, s); r < o.length; r++)
|
|
2057
|
+
t = o[r].split(u), i = [], t.length > 1 && (i = we(j, t)), t = t[t.length - 1], t = t === "*" ? "*" : lt(t), t in _ || (_[t] = []), _[t].push({
|
|
2058
|
+
keyup: l,
|
|
2059
|
+
keydown: f,
|
|
2060
|
+
scope: s,
|
|
2061
|
+
mods: i,
|
|
2062
|
+
shortcut: o[r],
|
|
2063
|
+
method: n,
|
|
2064
|
+
key: o[r],
|
|
2065
|
+
splitKey: u,
|
|
2066
|
+
element: a
|
|
2067
|
+
});
|
|
2068
|
+
if (typeof a < "u" && window) {
|
|
2069
|
+
if (!F.has(a)) {
|
|
2070
|
+
const p = function() {
|
|
2071
|
+
let y = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
|
|
2072
|
+
return se(y, a);
|
|
2073
|
+
}, v = function() {
|
|
2074
|
+
let y = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
|
|
2075
|
+
se(y, a), go(y);
|
|
2076
|
+
};
|
|
2077
|
+
F.set(a, {
|
|
2078
|
+
keydownListener: p,
|
|
2079
|
+
keyupListenr: v,
|
|
2080
|
+
capture: h
|
|
2081
|
+
}), Nt(a, "keydown", p, h), Nt(a, "keyup", v, h);
|
|
2082
|
+
}
|
|
2083
|
+
if (!rt) {
|
|
2084
|
+
const p = () => {
|
|
2085
|
+
I = [];
|
|
2086
|
+
};
|
|
2087
|
+
rt = {
|
|
2088
|
+
listener: p,
|
|
2089
|
+
capture: h
|
|
2090
|
+
}, Nt(window, "focus", p, h);
|
|
2091
|
+
}
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
function mo(t) {
|
|
2095
|
+
let e = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "all";
|
|
2096
|
+
Object.keys(_).forEach((n) => {
|
|
2097
|
+
_[n].filter((i) => i.scope === e && i.shortcut === t).forEach((i) => {
|
|
2098
|
+
i && i.method && i.method();
|
|
2099
|
+
});
|
|
2100
|
+
});
|
|
2101
|
+
}
|
|
2102
|
+
function $t(t) {
|
|
2103
|
+
const e = Object.values(_).flat();
|
|
2104
|
+
if (e.findIndex((o) => {
|
|
2105
|
+
let {
|
|
2106
|
+
element: i
|
|
2107
|
+
} = o;
|
|
2108
|
+
return i === t;
|
|
2109
|
+
}) < 0) {
|
|
2110
|
+
const {
|
|
2111
|
+
keydownListener: o,
|
|
2112
|
+
keyupListenr: i,
|
|
2113
|
+
capture: s
|
|
2114
|
+
} = F.get(t) || {};
|
|
2115
|
+
o && i && (nt(t, "keyup", i, s), nt(t, "keydown", o, s), F.delete(t));
|
|
2116
|
+
}
|
|
2117
|
+
if ((e.length <= 0 || F.size <= 0) && (Object.keys(F).forEach((i) => {
|
|
2118
|
+
const {
|
|
2119
|
+
keydownListener: s,
|
|
2120
|
+
keyupListenr: a,
|
|
2121
|
+
capture: r
|
|
2122
|
+
} = F.get(i) || {};
|
|
2123
|
+
s && a && (nt(i, "keyup", a, r), nt(i, "keydown", s, r), F.delete(i));
|
|
2124
|
+
}), F.clear(), Object.keys(_).forEach((i) => delete _[i]), rt)) {
|
|
2125
|
+
const {
|
|
2126
|
+
listener: i,
|
|
2127
|
+
capture: s
|
|
2128
|
+
} = rt;
|
|
2129
|
+
nt(window, "focus", i, s), rt = null;
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2132
|
+
const Ut = {
|
|
2133
|
+
getPressedKeyString: lo,
|
|
2134
|
+
setScope: xe,
|
|
2135
|
+
getScope: ct,
|
|
2136
|
+
deleteScope: po,
|
|
2137
|
+
getPressedKeyCodes: co,
|
|
2138
|
+
getAllKeyCodes: uo,
|
|
2139
|
+
isPressed: ho,
|
|
2140
|
+
filter: fo,
|
|
2141
|
+
trigger: mo,
|
|
2142
|
+
unbind: Ee,
|
|
2143
|
+
keyMap: at,
|
|
2144
|
+
modifier: j,
|
|
2145
|
+
modifierMap: Yt
|
|
2146
|
+
};
|
|
2147
|
+
for (const t in Ut)
|
|
2148
|
+
Object.prototype.hasOwnProperty.call(Ut, t) && (P[t] = Ut[t]);
|
|
2149
|
+
if (typeof window < "u") {
|
|
2150
|
+
const t = window.hotkeys;
|
|
2151
|
+
P.noConflict = (e) => (e && window.hotkeys === P && (window.hotkeys = t), P), window.hotkeys = P;
|
|
2152
|
+
}
|
|
2153
|
+
const re = 300, Se = ["up", "down", "left", "right"], Ce = Re ? "⌘+a" : "ctrl+a", yo = [
|
|
2154
|
+
...Se.map((t) => `shift+${t}`),
|
|
2155
|
+
Ce
|
|
2156
|
+
], bo = (t, e, n, o) => {
|
|
2157
|
+
let i;
|
|
2158
|
+
const s = (E) => i = E;
|
|
2159
|
+
let a;
|
|
2160
|
+
const r = (E) => a = E, { store: l, selection: f } = e;
|
|
2161
|
+
let u, h, g, p = !1;
|
|
2162
|
+
const v = (E) => {
|
|
2163
|
+
var b;
|
|
2164
|
+
if (p = !1, h === !1)
|
|
2165
|
+
return;
|
|
2166
|
+
u = !((b = E.target.parentElement) != null && b.closest(H)) ? {
|
|
2167
|
+
annotation: pe(),
|
|
1759
2168
|
selector: [],
|
|
1760
2169
|
creator: i,
|
|
1761
2170
|
created: /* @__PURE__ */ new Date()
|
|
1762
|
-
} :
|
|
1763
|
-
},
|
|
1764
|
-
var
|
|
1765
|
-
const
|
|
1766
|
-
if (!!((
|
|
1767
|
-
|
|
2171
|
+
} : void 0;
|
|
2172
|
+
}, y = Dt((E) => {
|
|
2173
|
+
var N, D;
|
|
2174
|
+
const R = document.getSelection();
|
|
2175
|
+
if (!!((D = (N = R.anchorNode) == null ? void 0 : N.parentElement) != null && D.closest(H))) {
|
|
2176
|
+
u = void 0;
|
|
2177
|
+
return;
|
|
2178
|
+
}
|
|
2179
|
+
const x = E.timeStamp - ((g == null ? void 0 : g.timeStamp) || E.timeStamp);
|
|
2180
|
+
if ((g == null ? void 0 : g.type) === "pointerdown" && (x < 1e3 && !u || R.isCollapsed && x < re) && v(g || E), !u) return;
|
|
2181
|
+
if (R.isCollapsed) {
|
|
2182
|
+
l.getAnnotation(u.annotation) && (f.clear(), l.deleteAnnotation(u.annotation));
|
|
1768
2183
|
return;
|
|
1769
2184
|
}
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
selector: R.map((w) => ae(w, t, o)),
|
|
2185
|
+
const A = R.getRangeAt(0), C = Ye(A, t);
|
|
2186
|
+
if (_e(C)) return;
|
|
2187
|
+
const B = Oe(C.cloneRange());
|
|
2188
|
+
(B.length !== u.selector.length || B.some((tt, At) => {
|
|
2189
|
+
var dt;
|
|
2190
|
+
return tt.toString() !== ((dt = u.selector[At]) == null ? void 0 : dt.quote);
|
|
2191
|
+
})) && (u = {
|
|
2192
|
+
...u,
|
|
2193
|
+
selector: B.map((tt) => Ke(tt, t, o)),
|
|
1780
2194
|
updated: /* @__PURE__ */ new Date()
|
|
1781
|
-
},
|
|
1782
|
-
|
|
2195
|
+
}, l.getAnnotation(u.annotation) && l.updateTarget(u, k.LOCAL));
|
|
2196
|
+
}), m = (E) => {
|
|
2197
|
+
var b;
|
|
2198
|
+
p || (b = E.target.parentElement) != null && b.closest(H) || (g = Et(E), h = g.button === 0);
|
|
2199
|
+
}, d = () => {
|
|
2200
|
+
l.getAnnotation(u.annotation) ? l.updateTarget(u) : l.addAnnotation({
|
|
2201
|
+
id: u.annotation,
|
|
1783
2202
|
bodies: [],
|
|
1784
|
-
target:
|
|
1785
|
-
})
|
|
1786
|
-
}
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
const { selected: b } = u;
|
|
1797
|
-
(b.length !== 1 || b[0].id !== I.id) && u.userSelect(I.id, a);
|
|
1798
|
-
} else u.isEmpty() || u.clear();
|
|
1799
|
-
}, L = a.timeStamp - y.timeStamp;
|
|
2203
|
+
target: u
|
|
2204
|
+
});
|
|
2205
|
+
}, c = (E) => {
|
|
2206
|
+
var A;
|
|
2207
|
+
if (p || !!((A = E.target.parentElement) != null && A.closest(H)) || !h) return;
|
|
2208
|
+
const b = () => {
|
|
2209
|
+
const { x: C, y: B } = t.getBoundingClientRect(), M = E.target instanceof Node && t.contains(E.target) && l.getAt(E.clientX - C, E.clientY - B, a);
|
|
2210
|
+
if (M) {
|
|
2211
|
+
const { selected: N } = f;
|
|
2212
|
+
(N.length !== 1 || N[0].id !== M.id) && f.userSelect(M.id, E);
|
|
2213
|
+
} else f.isEmpty() || f.clear();
|
|
2214
|
+
}, x = E.timeStamp - g.timeStamp;
|
|
1800
2215
|
setTimeout(() => {
|
|
1801
|
-
const
|
|
1802
|
-
|
|
2216
|
+
const C = document.getSelection();
|
|
2217
|
+
C != null && C.isCollapsed && x < re ? (u = void 0, b()) : u && u.selector.length > 0 && (f.clear(), d(), f.userSelect(u.annotation, Et(E)));
|
|
1803
2218
|
});
|
|
2219
|
+
}, w = (E) => {
|
|
2220
|
+
p = !0;
|
|
2221
|
+
const R = document.getSelection();
|
|
2222
|
+
R != null && R.isCollapsed || ((!u || u.selector.length === 0) && y(E), d(), f.userSelect(u.annotation, Et(E)));
|
|
2223
|
+
}, S = (E) => {
|
|
2224
|
+
E.key === "Shift" && u && (document.getSelection().isCollapsed || (f.clear(), d(), f.userSelect(u.annotation, ut(E))));
|
|
2225
|
+
}, T = (E) => {
|
|
2226
|
+
const R = () => setTimeout(() => {
|
|
2227
|
+
(u == null ? void 0 : u.selector.length) > 0 && (f.clear(), l.addAnnotation({
|
|
2228
|
+
id: u.annotation,
|
|
2229
|
+
bodies: [],
|
|
2230
|
+
target: u
|
|
2231
|
+
}), f.userSelect(u.annotation, ut(E))), document.removeEventListener("selectionchange", R);
|
|
2232
|
+
}, 100);
|
|
2233
|
+
document.addEventListener("selectionchange", R), v(E);
|
|
2234
|
+
};
|
|
2235
|
+
P(yo.join(","), { element: t, keydown: !0, keyup: !1 }, (E) => {
|
|
2236
|
+
E.repeat || (g = ut(E));
|
|
2237
|
+
}), P(Ce, { keydown: !0, keyup: !1 }, (E) => {
|
|
2238
|
+
g = ut(E), T(E);
|
|
2239
|
+
});
|
|
2240
|
+
const L = (E) => {
|
|
2241
|
+
E.repeat || E.target !== t && E.target !== document.body || (u = void 0, f.clear());
|
|
1804
2242
|
};
|
|
1805
|
-
return t.addEventListener("pointerdown",
|
|
2243
|
+
return P(Se.join(","), { keydown: !0, keyup: !1 }, L), t.addEventListener("pointerdown", m), document.addEventListener("pointerup", c), document.addEventListener("contextmenu", w), n && (t.addEventListener("keyup", S), t.addEventListener("selectstart", v), document.addEventListener("selectionchange", y)), {
|
|
1806
2244
|
destroy: () => {
|
|
1807
|
-
t.removeEventListener("pointerdown",
|
|
2245
|
+
t.removeEventListener("pointerdown", m), document.removeEventListener("pointerup", c), document.removeEventListener("contextmenu", w), t.removeEventListener("keyup", S), t.removeEventListener("selectstart", v), document.removeEventListener("selectionchange", y), P.unbind();
|
|
1808
2246
|
},
|
|
1809
|
-
setFilter:
|
|
2247
|
+
setFilter: r,
|
|
1810
2248
|
setUser: s
|
|
1811
2249
|
};
|
|
1812
|
-
},
|
|
2250
|
+
}, wo = (t, e) => ({
|
|
1813
2251
|
...t,
|
|
1814
2252
|
annotatingEnabled: t.annotatingEnabled ?? e.annotatingEnabled,
|
|
1815
2253
|
user: t.user || e.user
|
|
1816
|
-
}),
|
|
1817
|
-
|
|
1818
|
-
const n =
|
|
2254
|
+
}), ae = "SPANS", Eo = (t, e = {}) => {
|
|
2255
|
+
Me(t), Be(t);
|
|
2256
|
+
const n = wo(e, {
|
|
1819
2257
|
annotatingEnabled: !0,
|
|
1820
|
-
user:
|
|
1821
|
-
}), o =
|
|
1822
|
-
let
|
|
1823
|
-
const
|
|
2258
|
+
user: Dn()
|
|
2259
|
+
}), o = no(t, n.userSelectAction), { selection: i, viewport: s } = o, a = o.store, r = Rn(a), l = kn(o, r, n.adapter);
|
|
2260
|
+
let f = n.user;
|
|
2261
|
+
const u = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : ae : n.renderer || ae, h = u === "SPANS" ? an(t, o, s) : u === "CSS_HIGHLIGHTS" ? on(t, o, s) : u === "CANVAS" ? Fe(t, o, s) : void 0;
|
|
1824
2262
|
if (!h)
|
|
1825
|
-
throw `Unknown renderer implementation: ${
|
|
1826
|
-
console.debug(`Using ${
|
|
1827
|
-
const
|
|
1828
|
-
return
|
|
1829
|
-
...
|
|
2263
|
+
throw `Unknown renderer implementation: ${u}`;
|
|
2264
|
+
console.debug(`Using ${u} renderer`), n.style && h.setStyle(n.style);
|
|
2265
|
+
const g = bo(t, o, n.annotatingEnabled, n.offsetReferenceSelector);
|
|
2266
|
+
return g.setUser(f), {
|
|
2267
|
+
..._n(o, r, n.adapter),
|
|
1830
2268
|
destroy: () => {
|
|
1831
|
-
h.destroy(),
|
|
2269
|
+
h.destroy(), g.destroy(), r.destroy();
|
|
1832
2270
|
},
|
|
1833
2271
|
element: t,
|
|
1834
|
-
getUser: () =>
|
|
1835
|
-
setFilter: (
|
|
1836
|
-
h.setFilter(
|
|
2272
|
+
getUser: () => f,
|
|
2273
|
+
setFilter: (L) => {
|
|
2274
|
+
h.setFilter(L), g.setFilter(L);
|
|
1837
2275
|
},
|
|
1838
|
-
setStyle: (
|
|
1839
|
-
setUser: (
|
|
1840
|
-
|
|
2276
|
+
setStyle: (L) => h.setStyle(L),
|
|
2277
|
+
setUser: (L) => {
|
|
2278
|
+
f = L, g.setUser(L);
|
|
1841
2279
|
},
|
|
1842
|
-
setSelected: (
|
|
1843
|
-
|
|
2280
|
+
setSelected: (L) => {
|
|
2281
|
+
L ? i.setSelected(L) : i.clear();
|
|
1844
2282
|
},
|
|
1845
|
-
setPresenceProvider: (
|
|
1846
|
-
|
|
2283
|
+
setPresenceProvider: (L) => {
|
|
2284
|
+
L && (h.setPainter(io(L, n.presence)), L.on("selectionChange", () => h.redraw()));
|
|
1847
2285
|
},
|
|
1848
|
-
setVisible: (
|
|
1849
|
-
on:
|
|
1850
|
-
off:
|
|
1851
|
-
scrollIntoView:
|
|
2286
|
+
setVisible: (L) => h.setVisible(L),
|
|
2287
|
+
on: l.on,
|
|
2288
|
+
off: l.off,
|
|
2289
|
+
scrollIntoView: De(t, a),
|
|
1852
2290
|
state: o
|
|
1853
2291
|
};
|
|
1854
2292
|
};
|
|
1855
2293
|
export {
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
2294
|
+
vt as DEFAULT_SELECTED_STYLE,
|
|
2295
|
+
q as DEFAULT_STYLE,
|
|
2296
|
+
ce as NOT_ANNOTATABLE_CLASS,
|
|
2297
|
+
H as NOT_ANNOTATABLE_SELECTOR,
|
|
2298
|
+
k as Origin,
|
|
2299
|
+
bo as SelectionHandler,
|
|
2300
|
+
pn as UserSelectAction,
|
|
2301
|
+
xo as W3CTextFormat,
|
|
2302
|
+
Me as cancelSingleClickEvents,
|
|
2303
|
+
ut as cloneKeyboardEvent,
|
|
2304
|
+
Et as clonePointerEvent,
|
|
2305
|
+
Ao as createBody,
|
|
2306
|
+
Fe as createCanvasRenderer,
|
|
2307
|
+
on as createHighlightsRenderer,
|
|
2308
|
+
io as createPresencePainter,
|
|
2309
|
+
nn as createRenderer,
|
|
2310
|
+
an as createSpansRenderer,
|
|
2311
|
+
Eo as createTextAnnotator,
|
|
2312
|
+
no as createTextAnnotatorState,
|
|
2313
|
+
Dt as debounce,
|
|
2314
|
+
wo as fillDefaults,
|
|
2315
|
+
vo as getAnnotatableFragment,
|
|
2316
|
+
ke as getQuoteContext,
|
|
2317
|
+
Vt as getRangeAnnotatableContents,
|
|
2318
|
+
Re as isMac,
|
|
2319
|
+
W as isRevived,
|
|
2320
|
+
_e as isWhitespaceOrEmpty,
|
|
2321
|
+
Ve as mergeClientRects,
|
|
2322
|
+
Xe as paint,
|
|
2323
|
+
zn as parseW3CTextAnnotation,
|
|
2324
|
+
Be as programmaticallyFocusable,
|
|
2325
|
+
Ke as rangeToSelector,
|
|
2326
|
+
xt as reviveAnnotation,
|
|
2327
|
+
le as reviveSelector,
|
|
2328
|
+
wt as reviveTarget,
|
|
2329
|
+
De as scrollIntoView,
|
|
2330
|
+
Fn as serializeW3CTextAnnotation,
|
|
2331
|
+
Oe as splitAnnotatableRanges,
|
|
2332
|
+
Ye as trimRangeToContainer,
|
|
2333
|
+
Ie as whitespaceOrEmptyRegex
|
|
1892
2334
|
};
|
|
1893
2335
|
//# sourceMappingURL=text-annotator.es.js.map
|