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