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