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