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