@recogito/text-annotator 3.0.0-rc.1 → 3.0.0-rc.10
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/api/scrollIntoView.d.ts +1 -1
- package/dist/src/highlight/highlightLayer.d.ts +2 -1
- package/dist/src/index.d.ts +3 -3
- package/dist/src/utils/getContext.d.ts +4 -0
- package/dist/text-annotator.css +1 -1
- package/dist/text-annotator.es.js +936 -851
- package/dist/text-annotator.es.js.map +1 -1
- package/dist/text-annotator.umd.js +1 -1
- package/dist/text-annotator.umd.js.map +1 -1
- package/package.json +10 -10
|
@@ -1,697 +1,747 @@
|
|
|
1
|
-
const
|
|
2
|
-
paint: (
|
|
3
|
-
const
|
|
4
|
-
n.fillStyle =
|
|
1
|
+
const ft = { fill: "rgb(0, 128, 255", fillOpacity: 0.18 }, pt = { fill: "rgb(0, 128, 255)", fillOpacity: 0.45 }, nt = {
|
|
2
|
+
paint: (e, t, n, o, i, s) => {
|
|
3
|
+
const a = s ? typeof s == "function" ? s(e, i) : s : i ? pt : ft;
|
|
4
|
+
n.fillStyle = a.fill, n.globalAlpha = a.fillOpacity || 1, t.forEach(({ x: r, y: d, width: h, height: w }) => n.fillRect(r, d - 2.5, h, w + 5));
|
|
5
5
|
}
|
|
6
|
-
},
|
|
7
|
-
let
|
|
6
|
+
}, gt = (e) => {
|
|
7
|
+
let t = /* @__PURE__ */ new Set();
|
|
8
8
|
return (o) => {
|
|
9
9
|
const i = o.map((s) => s.id);
|
|
10
|
-
(
|
|
10
|
+
(t.size !== i.length || i.some((s) => !t.has(s))) && e.set(i), t = new Set(i);
|
|
11
11
|
};
|
|
12
|
-
}
|
|
13
|
-
const ft = (t, e = 10) => {
|
|
12
|
+
}, mt = (e, t = 10) => {
|
|
14
13
|
let n;
|
|
15
14
|
return (...o) => {
|
|
16
|
-
clearTimeout(n), n = setTimeout(() =>
|
|
15
|
+
clearTimeout(n), n = setTimeout(() => e.apply(void 0, o), t);
|
|
17
16
|
};
|
|
18
|
-
},
|
|
17
|
+
}, j = (e, t) => {
|
|
19
18
|
const n = document.createElement("canvas");
|
|
20
|
-
if (n.width =
|
|
19
|
+
if (n.width = t ? 2 * window.innerWidth : window.innerWidth, n.height = t ? 2 * window.innerHeight : window.innerHeight, n.className = e, t) {
|
|
21
20
|
const o = n.getContext("2d");
|
|
22
21
|
o.scale(2, 2), o.translate(0.5, 0.5);
|
|
23
22
|
}
|
|
24
23
|
return n;
|
|
25
|
-
}, Z = (
|
|
26
|
-
if (
|
|
27
|
-
const n =
|
|
24
|
+
}, Z = (e, t) => {
|
|
25
|
+
if (e.width = t ? 2 * window.innerWidth : window.innerWidth, e.height = t ? 2 * window.innerHeight : window.innerHeight, t) {
|
|
26
|
+
const n = e.getContext("2d");
|
|
28
27
|
n.scale(2, 2), n.translate(0.5, 0.5);
|
|
29
28
|
}
|
|
30
|
-
},
|
|
31
|
-
const { store: o, selection: i, hover: s } =
|
|
32
|
-
let
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
const { x:
|
|
38
|
-
|
|
29
|
+
}, bt = (e, t, n) => {
|
|
30
|
+
const { store: o, selection: i, hover: s } = t;
|
|
31
|
+
let a, r, d = nt;
|
|
32
|
+
const h = gt(n);
|
|
33
|
+
e.classList.add("r6o-annotatable");
|
|
34
|
+
const w = j("r6o-highlight-layer bg"), f = j("r6o-highlight-layer fg", !0), T = w.getContext("2d"), g = f.getContext("2d");
|
|
35
|
+
e.insertBefore(w, e.firstChild), e.appendChild(f), e.addEventListener("pointermove", (E) => {
|
|
36
|
+
const { x: v, y: C } = e.getBoundingClientRect(), p = o.getAt(E.clientX - v, E.clientY - C);
|
|
37
|
+
p && (!r || r(p)) ? s.current !== p.id && (e.classList.add("hovered"), s.set(p.id)) : s.current && (e.classList.remove("hovered"), s.set(null));
|
|
39
38
|
});
|
|
40
|
-
const
|
|
41
|
-
const { top:
|
|
42
|
-
return { top:
|
|
43
|
-
},
|
|
44
|
-
document.addEventListener("scroll",
|
|
45
|
-
const
|
|
46
|
-
Z(
|
|
39
|
+
const y = () => {
|
|
40
|
+
const { top: E, left: v } = e.getBoundingClientRect(), { innerWidth: C, innerHeight: p } = window, x = -v, b = -E, S = C - v, M = p - E;
|
|
41
|
+
return { top: E, left: v, minX: x, minY: b, maxX: S, maxY: M };
|
|
42
|
+
}, B = () => c();
|
|
43
|
+
document.addEventListener("scroll", B, { capture: !0, passive: !0 });
|
|
44
|
+
const A = mt(() => {
|
|
45
|
+
Z(w), Z(f, !0), o.recalculatePositions(), c();
|
|
47
46
|
});
|
|
48
|
-
window.addEventListener("resize",
|
|
49
|
-
const
|
|
50
|
-
const { top:
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
x:
|
|
54
|
-
y:
|
|
55
|
-
width:
|
|
56
|
-
height:
|
|
57
|
-
})),
|
|
58
|
-
|
|
59
|
-
}), setTimeout(() =>
|
|
47
|
+
window.addEventListener("resize", A), new ResizeObserver(A).observe(e);
|
|
48
|
+
const c = () => requestAnimationFrame(() => {
|
|
49
|
+
const { top: E, left: v, minX: C, minY: p, maxX: x, maxY: b } = y(), S = r ? o.getIntersectingRects(C, p, x, b).filter(({ annotation: Y }) => r(Y)) : o.getIntersectingRects(C, p, x, b), { width: M, height: R } = f, X = new Set(i.selected.map(({ id: Y }) => Y));
|
|
50
|
+
g.clearRect(-0.5, -0.5, M + 1, R + 1), T.clearRect(-0.5, -0.5, M + 1, R + 1), S.forEach(({ annotation: Y, rects: at }) => {
|
|
51
|
+
const rt = at.map(({ x: ct, y: dt, width: ut, height: ht }) => ({
|
|
52
|
+
x: ct + v,
|
|
53
|
+
y: dt + E,
|
|
54
|
+
width: ut,
|
|
55
|
+
height: ht
|
|
56
|
+
})), lt = X.has(Y.id);
|
|
57
|
+
d.paint(Y, rt, T, g, lt, a);
|
|
58
|
+
}), setTimeout(() => h(S.map(({ annotation: Y }) => Y)), 1);
|
|
60
59
|
});
|
|
61
|
-
return o.observe(() =>
|
|
62
|
-
redraw:
|
|
63
|
-
setDrawingStyle: (
|
|
64
|
-
|
|
60
|
+
return o.observe(() => c()), i.subscribe(() => c()), {
|
|
61
|
+
redraw: c,
|
|
62
|
+
setDrawingStyle: (E) => {
|
|
63
|
+
a = E, c();
|
|
64
|
+
},
|
|
65
|
+
setFilter: (E) => {
|
|
66
|
+
r = E, c();
|
|
65
67
|
},
|
|
66
|
-
setPainter: (
|
|
68
|
+
setPainter: (E) => d = E
|
|
67
69
|
};
|
|
68
|
-
},
|
|
69
|
-
const {
|
|
70
|
-
if (!
|
|
71
|
-
return
|
|
72
|
-
const
|
|
73
|
-
let
|
|
74
|
-
|
|
75
|
-
let
|
|
76
|
-
for (;
|
|
77
|
-
const
|
|
78
|
-
if (!
|
|
79
|
-
if (
|
|
80
|
-
|
|
70
|
+
}, _ = (e, t) => {
|
|
71
|
+
const { start: n, end: o } = e.selector, i = e.selector.offsetReference ? e.selector.offsetReference : t;
|
|
72
|
+
if (!i)
|
|
73
|
+
return e;
|
|
74
|
+
const s = document.createNodeIterator(t, NodeFilter.SHOW_TEXT);
|
|
75
|
+
let a = 0, r = document.createRange(), d = s.nextNode();
|
|
76
|
+
d === null && console.error("Could not revive annotation target. Content missing.");
|
|
77
|
+
let h = !i;
|
|
78
|
+
for (; d !== null; ) {
|
|
79
|
+
const w = d.textContent.length;
|
|
80
|
+
if (!h && i && (h = i.contains(d)), h) {
|
|
81
|
+
if (a + w > n) {
|
|
82
|
+
r.setStart(d, n - a);
|
|
81
83
|
break;
|
|
82
84
|
}
|
|
83
|
-
|
|
85
|
+
a += w;
|
|
84
86
|
}
|
|
85
|
-
|
|
87
|
+
d = s.nextNode();
|
|
86
88
|
}
|
|
87
|
-
for (;
|
|
88
|
-
const
|
|
89
|
-
if (
|
|
90
|
-
|
|
89
|
+
for (; d !== null; ) {
|
|
90
|
+
const w = d.textContent.length;
|
|
91
|
+
if (a + w > o) {
|
|
92
|
+
r.setEnd(d, o - a);
|
|
91
93
|
break;
|
|
92
94
|
}
|
|
93
|
-
|
|
95
|
+
a += w, d = s.nextNode();
|
|
94
96
|
}
|
|
95
97
|
return {
|
|
96
|
-
...
|
|
98
|
+
...e,
|
|
97
99
|
selector: {
|
|
98
|
-
...
|
|
99
|
-
|
|
100
|
-
start: o,
|
|
101
|
-
end: i,
|
|
102
|
-
range: l
|
|
100
|
+
...e.selector,
|
|
101
|
+
range: r
|
|
103
102
|
}
|
|
104
103
|
};
|
|
105
104
|
};
|
|
106
|
-
var
|
|
107
|
-
function
|
|
105
|
+
var Q = Object.prototype.hasOwnProperty;
|
|
106
|
+
function U(e, t) {
|
|
108
107
|
var n, o;
|
|
109
|
-
if (
|
|
108
|
+
if (e === t)
|
|
110
109
|
return !0;
|
|
111
|
-
if (
|
|
110
|
+
if (e && t && (n = e.constructor) === t.constructor) {
|
|
112
111
|
if (n === Date)
|
|
113
|
-
return
|
|
112
|
+
return e.getTime() === t.getTime();
|
|
114
113
|
if (n === RegExp)
|
|
115
|
-
return
|
|
114
|
+
return e.toString() === t.toString();
|
|
116
115
|
if (n === Array) {
|
|
117
|
-
if ((o =
|
|
118
|
-
for (; o-- &&
|
|
116
|
+
if ((o = e.length) === t.length)
|
|
117
|
+
for (; o-- && U(e[o], t[o]); )
|
|
119
118
|
;
|
|
120
119
|
return o === -1;
|
|
121
120
|
}
|
|
122
|
-
if (!n || typeof
|
|
121
|
+
if (!n || typeof e == "object") {
|
|
123
122
|
o = 0;
|
|
124
|
-
for (n in
|
|
125
|
-
if (
|
|
123
|
+
for (n in e)
|
|
124
|
+
if (Q.call(e, n) && ++o && !Q.call(t, n) || !(n in t) || !U(e[n], t[n]))
|
|
126
125
|
return !1;
|
|
127
|
-
return Object.keys(
|
|
126
|
+
return Object.keys(t).length === o;
|
|
128
127
|
}
|
|
129
128
|
}
|
|
130
|
-
return
|
|
129
|
+
return e !== e && t !== t;
|
|
131
130
|
}
|
|
132
|
-
function
|
|
131
|
+
function W() {
|
|
133
132
|
}
|
|
134
|
-
function
|
|
135
|
-
return
|
|
133
|
+
function wt(e, t) {
|
|
134
|
+
return e != e ? t == t : e !== t || e && typeof e == "object" || typeof e == "function";
|
|
136
135
|
}
|
|
137
|
-
const
|
|
138
|
-
function
|
|
136
|
+
const D = [];
|
|
137
|
+
function J(e, t = W) {
|
|
139
138
|
let n;
|
|
140
139
|
const o = /* @__PURE__ */ new Set();
|
|
141
140
|
function i(r) {
|
|
142
|
-
if (
|
|
143
|
-
const
|
|
141
|
+
if (wt(e, r) && (e = r, n)) {
|
|
142
|
+
const d = !D.length;
|
|
144
143
|
for (const h of o)
|
|
145
|
-
h[1](),
|
|
146
|
-
if (
|
|
147
|
-
for (let h = 0; h <
|
|
148
|
-
|
|
149
|
-
|
|
144
|
+
h[1](), D.push(h, e);
|
|
145
|
+
if (d) {
|
|
146
|
+
for (let h = 0; h < D.length; h += 2)
|
|
147
|
+
D[h][0](D[h + 1]);
|
|
148
|
+
D.length = 0;
|
|
150
149
|
}
|
|
151
150
|
}
|
|
152
151
|
}
|
|
153
152
|
function s(r) {
|
|
154
|
-
i(r(
|
|
153
|
+
i(r(e));
|
|
155
154
|
}
|
|
156
|
-
function
|
|
157
|
-
const h = [r,
|
|
158
|
-
return o.add(h), o.size === 1 && (n =
|
|
155
|
+
function a(r, d = W) {
|
|
156
|
+
const h = [r, d];
|
|
157
|
+
return o.add(h), o.size === 1 && (n = t(i, s) || W), r(e), () => {
|
|
159
158
|
o.delete(h), o.size === 0 && n && (n(), n = null);
|
|
160
159
|
};
|
|
161
160
|
}
|
|
162
|
-
return { set: i, update: s, subscribe:
|
|
161
|
+
return { set: i, update: s, subscribe: a };
|
|
163
162
|
}
|
|
164
|
-
const
|
|
165
|
-
const { subscribe:
|
|
166
|
-
let o
|
|
167
|
-
return
|
|
163
|
+
const At = (e) => {
|
|
164
|
+
const { subscribe: t, set: n } = J();
|
|
165
|
+
let o;
|
|
166
|
+
return t((i) => o = i), e.observe(({ changes: i }) => {
|
|
168
167
|
if (o) {
|
|
169
|
-
i.deleted.some((
|
|
170
|
-
const
|
|
171
|
-
|
|
168
|
+
(i.deleted || []).some((a) => a.id === o) && n(void 0);
|
|
169
|
+
const s = (i.updated || []).find(({ oldValue: a }) => a.id === o);
|
|
170
|
+
s && n(s.newValue.id);
|
|
172
171
|
}
|
|
173
172
|
}), {
|
|
174
173
|
get current() {
|
|
175
174
|
return o;
|
|
176
175
|
},
|
|
177
|
-
subscribe:
|
|
176
|
+
subscribe: t,
|
|
178
177
|
set: n
|
|
179
178
|
};
|
|
180
|
-
},
|
|
181
|
-
const { subscribe: n, set: o } =
|
|
182
|
-
let i =
|
|
183
|
-
n((
|
|
184
|
-
const s = () => o(
|
|
185
|
-
var
|
|
186
|
-
return ((
|
|
187
|
-
}, r = (
|
|
179
|
+
}, q = { selected: [] }, xt = (e, t = "EDIT") => {
|
|
180
|
+
const { subscribe: n, set: o } = J(q);
|
|
181
|
+
let i = q;
|
|
182
|
+
n((f) => i = f);
|
|
183
|
+
const s = () => o(q), a = () => {
|
|
184
|
+
var f;
|
|
185
|
+
return ((f = i.selected) == null ? void 0 : f.length) === 0;
|
|
186
|
+
}, r = (f) => {
|
|
188
187
|
if (i.selected.length === 0)
|
|
189
188
|
return !1;
|
|
190
|
-
const
|
|
191
|
-
return i.selected.some((
|
|
192
|
-
},
|
|
193
|
-
const
|
|
194
|
-
if (
|
|
195
|
-
const
|
|
196
|
-
o(
|
|
189
|
+
const T = typeof f == "string" ? f : f.id;
|
|
190
|
+
return i.selected.some((g) => g.id === T);
|
|
191
|
+
}, d = (f, T) => {
|
|
192
|
+
const g = e.getAnnotation(f);
|
|
193
|
+
if (g) {
|
|
194
|
+
const y = yt(g, t);
|
|
195
|
+
o(y === "EDIT" ? { selected: [{ id: f, editable: !0 }], pointerEvent: T } : y === "SELECT" ? { selected: [{ id: f }], pointerEvent: T } : { selected: [], pointerEvent: T });
|
|
197
196
|
} else
|
|
198
|
-
console.warn("Invalid selection: " +
|
|
199
|
-
}, h = (
|
|
200
|
-
const
|
|
201
|
-
o({ selected:
|
|
202
|
-
},
|
|
197
|
+
console.warn("Invalid selection: " + f);
|
|
198
|
+
}, h = (f, T = !0) => {
|
|
199
|
+
const g = Array.isArray(f) ? f : [f], y = g.map((B) => e.getAnnotation(B)).filter(Boolean);
|
|
200
|
+
o({ selected: y.map(({ id: B }) => ({ id: B, editable: T })) }), y.length !== g.length && console.warn("Invalid selection", f);
|
|
201
|
+
}, w = (f) => {
|
|
203
202
|
if (i.selected.length === 0)
|
|
204
203
|
return !1;
|
|
205
|
-
const { selected:
|
|
206
|
-
|
|
204
|
+
const { selected: T } = i;
|
|
205
|
+
T.filter(({ id: g }) => f.includes(g)).length > 0 && o({ selected: T.filter(({ id: g }) => !f.includes(g)) });
|
|
207
206
|
};
|
|
208
|
-
return
|
|
207
|
+
return e.observe(({ changes: f }) => w((f.deleted || []).map((T) => T.id))), {
|
|
209
208
|
clear: s,
|
|
210
|
-
clickSelect:
|
|
209
|
+
clickSelect: d,
|
|
211
210
|
get selected() {
|
|
212
211
|
return i ? [...i.selected] : null;
|
|
213
212
|
},
|
|
214
213
|
get pointerEvent() {
|
|
215
214
|
return i ? i.pointerEvent : null;
|
|
216
215
|
},
|
|
217
|
-
isEmpty:
|
|
216
|
+
isEmpty: a,
|
|
218
217
|
isSelected: r,
|
|
219
218
|
setSelected: h,
|
|
220
219
|
subscribe: n
|
|
221
220
|
};
|
|
222
|
-
},
|
|
223
|
-
let
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
228
|
-
return H(yt);
|
|
229
|
-
}
|
|
230
|
-
const O = [];
|
|
231
|
-
for (let t = 0; t < 256; ++t)
|
|
232
|
-
O.push((t + 256).toString(16).slice(1));
|
|
233
|
-
function wt(t, e = 0) {
|
|
234
|
-
return O[t[e + 0]] + O[t[e + 1]] + O[t[e + 2]] + O[t[e + 3]] + "-" + O[t[e + 4]] + O[t[e + 5]] + "-" + O[t[e + 6]] + O[t[e + 7]] + "-" + O[t[e + 8]] + O[t[e + 9]] + "-" + O[t[e + 10]] + O[t[e + 11]] + O[t[e + 12]] + O[t[e + 13]] + O[t[e + 14]] + O[t[e + 15]];
|
|
235
|
-
}
|
|
236
|
-
const bt = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), et = {
|
|
237
|
-
randomUUID: bt
|
|
238
|
-
};
|
|
239
|
-
function Tt(t, e, n) {
|
|
240
|
-
if (et.randomUUID && !e && !t)
|
|
241
|
-
return et.randomUUID();
|
|
242
|
-
t = t || {};
|
|
243
|
-
const o = t.random || (t.rng || Et)();
|
|
244
|
-
if (o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, e) {
|
|
245
|
-
n = n || 0;
|
|
246
|
-
for (let i = 0; i < 16; ++i)
|
|
247
|
-
e[n + i] = o[i];
|
|
248
|
-
return e;
|
|
249
|
-
}
|
|
250
|
-
return wt(o);
|
|
251
|
-
}
|
|
252
|
-
const vt = (t, e) => {
|
|
253
|
-
const n = new Set(t.bodies.map((o) => o.id));
|
|
254
|
-
return e.bodies.filter((o) => !n.has(o.id));
|
|
255
|
-
}, Ct = (t, e) => {
|
|
221
|
+
}, yt = (e, t) => typeof t == "function" ? t(e) || "EDIT" : t || "EDIT", Et = [];
|
|
222
|
+
for (let e = 0; e < 256; ++e)
|
|
223
|
+
Et.push((e + 256).toString(16).slice(1));
|
|
224
|
+
typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
225
|
+
const vt = (e, t) => {
|
|
256
226
|
const n = new Set(e.bodies.map((o) => o.id));
|
|
257
227
|
return t.bodies.filter((o) => !n.has(o.id));
|
|
258
|
-
},
|
|
259
|
-
const
|
|
260
|
-
return
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
228
|
+
}, St = (e, t) => {
|
|
229
|
+
const n = new Set(t.bodies.map((o) => o.id));
|
|
230
|
+
return e.bodies.filter((o) => !n.has(o.id));
|
|
231
|
+
}, Tt = (e, t) => t.bodies.map((n) => {
|
|
232
|
+
const o = e.bodies.find((i) => i.id === n.id);
|
|
233
|
+
return { newBody: n, oldBody: o && !U(o, n) ? o : void 0 };
|
|
234
|
+
}).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), Bt = (e, t) => !U(e.target, t.target), ot = (e, t) => {
|
|
235
|
+
const n = vt(e, t), o = St(e, t), i = Tt(e, t);
|
|
236
|
+
return {
|
|
237
|
+
oldValue: e,
|
|
238
|
+
newValue: t,
|
|
239
|
+
bodiesCreated: n.length > 0 ? n : void 0,
|
|
240
|
+
bodiesDeleted: o.length > 0 ? o : void 0,
|
|
241
|
+
bodiesUpdated: i.length > 0 ? i : void 0,
|
|
242
|
+
targetUpdated: Bt(e, t) ? { oldTarget: e.target, newTarget: t.target } : void 0
|
|
243
|
+
};
|
|
244
|
+
};
|
|
245
|
+
var L = /* @__PURE__ */ ((e) => (e.LOCAL = "LOCAL", e.REMOTE = "REMOTE", e))(L || {});
|
|
246
|
+
const Mt = (e, t) => {
|
|
247
|
+
var n, o;
|
|
248
|
+
const { changes: i, origin: s } = t;
|
|
249
|
+
if (!(!e.options.origin || e.options.origin === s))
|
|
274
250
|
return !1;
|
|
275
|
-
if (
|
|
276
|
-
const { ignore:
|
|
277
|
-
if (!(
|
|
278
|
-
const
|
|
279
|
-
if (
|
|
251
|
+
if (e.options.ignore) {
|
|
252
|
+
const { ignore: a } = e.options, r = (d) => d && d.length > 0;
|
|
253
|
+
if (!(r(i.created) || r(i.deleted))) {
|
|
254
|
+
const d = (n = i.updated) == null ? void 0 : n.some((w) => r(w.bodiesCreated) || r(w.bodiesDeleted) || r(w.bodiesUpdated)), h = (o = i.updated) == null ? void 0 : o.some((w) => w.targetUpdated);
|
|
255
|
+
if (a === "BODY_ONLY" && d && !h || a === "TARGET_ONLY" && h && !d)
|
|
280
256
|
return !1;
|
|
281
257
|
}
|
|
282
258
|
}
|
|
283
|
-
if (
|
|
284
|
-
const
|
|
285
|
-
...
|
|
286
|
-
...
|
|
287
|
-
...
|
|
259
|
+
if (e.options.annotations) {
|
|
260
|
+
const a = /* @__PURE__ */ new Set([
|
|
261
|
+
...(i.created || []).map((r) => r.id),
|
|
262
|
+
...(i.deleted || []).map((r) => r.id),
|
|
263
|
+
...(i.updated || []).map(({ oldValue: r }) => r.id)
|
|
288
264
|
]);
|
|
289
|
-
return !!(Array.isArray(
|
|
265
|
+
return !!(Array.isArray(e.options.annotations) ? e.options.annotations : [e.options.annotations]).find((r) => a.has(r));
|
|
290
266
|
} else
|
|
291
267
|
return !0;
|
|
292
|
-
},
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
268
|
+
}, Ct = (e, t) => {
|
|
269
|
+
const n = new Set((e.created || []).map((f) => f.id)), o = new Set((e.updated || []).map(({ newValue: f }) => f.id)), i = new Set((t.created || []).map((f) => f.id)), s = new Set((t.deleted || []).map((f) => f.id)), a = new Set((t.updated || []).map(({ oldValue: f }) => f.id)), r = new Set((t.updated || []).filter(({ oldValue: f }) => n.has(f.id) || o.has(f.id)).map(({ oldValue: f }) => f.id)), d = [
|
|
270
|
+
...(e.created || []).filter((f) => !s.has(f.id)).map((f) => a.has(f.id) ? t.updated.find(({ oldValue: T }) => T.id === f.id).newValue : f),
|
|
271
|
+
...t.created || []
|
|
272
|
+
], h = [
|
|
273
|
+
...(e.deleted || []).filter((f) => !i.has(f.id)),
|
|
274
|
+
...(t.deleted || []).filter((f) => !n.has(f.id))
|
|
275
|
+
], w = [
|
|
276
|
+
...(e.updated || []).filter(({ newValue: f }) => !s.has(f.id)).map((f) => {
|
|
277
|
+
const { oldValue: T, newValue: g } = f;
|
|
278
|
+
if (a.has(g.id)) {
|
|
279
|
+
const y = t.updated.find((B) => B.oldValue.id === g.id).newValue;
|
|
280
|
+
return ot(T, y);
|
|
281
|
+
} else
|
|
282
|
+
return f;
|
|
283
|
+
}),
|
|
284
|
+
...(t.updated || []).filter(({ oldValue: f }) => !r.has(f.id))
|
|
285
|
+
];
|
|
286
|
+
return { created: d, deleted: h, updated: w };
|
|
287
|
+
}, Lt = (e) => e.id !== void 0, Rt = () => {
|
|
288
|
+
const e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map(), n = [], o = (p, x = {}) => n.push({ onChange: p, options: x }), i = (p) => {
|
|
289
|
+
const x = n.findIndex((b) => b.onChange == p);
|
|
290
|
+
x > -1 && n.splice(x, 1);
|
|
291
|
+
}, s = (p, x) => {
|
|
292
|
+
const b = {
|
|
293
|
+
origin: p,
|
|
299
294
|
changes: {
|
|
300
|
-
created:
|
|
301
|
-
updated:
|
|
302
|
-
deleted:
|
|
295
|
+
created: x.created || [],
|
|
296
|
+
updated: x.updated || [],
|
|
297
|
+
deleted: x.deleted || []
|
|
303
298
|
},
|
|
304
|
-
state: [...
|
|
299
|
+
state: [...e.values()]
|
|
305
300
|
};
|
|
306
|
-
n.forEach((
|
|
307
|
-
|
|
301
|
+
n.forEach((S) => {
|
|
302
|
+
Mt(S, b) && S.onChange(b);
|
|
308
303
|
});
|
|
309
|
-
},
|
|
310
|
-
if (
|
|
311
|
-
throw Error(`Cannot add annotation ${
|
|
312
|
-
|
|
313
|
-
}, r = (
|
|
314
|
-
const
|
|
315
|
-
if (
|
|
316
|
-
const
|
|
317
|
-
|
|
304
|
+
}, a = (p, x = L.LOCAL) => {
|
|
305
|
+
if (e.get(p.id))
|
|
306
|
+
throw Error(`Cannot add annotation ${p.id} - exists already`);
|
|
307
|
+
e.set(p.id, p), p.bodies.forEach((b) => t.set(b.id, p.id)), s(x, { created: [p] });
|
|
308
|
+
}, r = (p, x) => {
|
|
309
|
+
const b = typeof p == "string" ? x : p, S = typeof p == "string" ? p : p.id, M = e.get(S);
|
|
310
|
+
if (M) {
|
|
311
|
+
const R = ot(M, b);
|
|
312
|
+
return S === b.id ? e.set(S, b) : (e.delete(S), e.set(b.id, b)), M.bodies.forEach((X) => t.delete(X.id)), b.bodies.forEach((X) => t.set(X.id, b.id)), R;
|
|
318
313
|
} else
|
|
319
|
-
|
|
320
|
-
},
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
314
|
+
console.warn(`Cannot update annotation ${S} - does not exist`);
|
|
315
|
+
}, d = (p, x = L.LOCAL, b = L.LOCAL) => {
|
|
316
|
+
const S = Lt(x) ? b : x, M = r(p, x);
|
|
317
|
+
M && s(S, { updated: [M] });
|
|
318
|
+
}, h = (p, x = L.LOCAL) => {
|
|
319
|
+
const b = p.reduce((S, M) => {
|
|
320
|
+
const R = r(M);
|
|
321
|
+
return R ? [...S, R] : S;
|
|
322
|
+
}, []);
|
|
323
|
+
b.length > 0 && s(x, { updated: b });
|
|
324
|
+
}, w = (p, x = L.LOCAL) => {
|
|
325
|
+
const b = e.get(p.annotation);
|
|
326
|
+
if (b) {
|
|
327
|
+
const S = {
|
|
328
|
+
...b,
|
|
329
|
+
bodies: [...b.bodies, p]
|
|
326
330
|
};
|
|
327
|
-
|
|
328
|
-
oldValue:
|
|
329
|
-
newValue:
|
|
330
|
-
bodiesCreated: [
|
|
331
|
+
e.set(b.id, S), t.set(p.id, S.id), s(x, { updated: [{
|
|
332
|
+
oldValue: b,
|
|
333
|
+
newValue: S,
|
|
334
|
+
bodiesCreated: [p]
|
|
331
335
|
}] });
|
|
332
336
|
} else
|
|
333
|
-
console.warn(`Attempt to add body to missing annotation: ${
|
|
334
|
-
},
|
|
335
|
-
const
|
|
336
|
-
|
|
337
|
-
},
|
|
338
|
-
if (
|
|
339
|
-
const
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
}), s(
|
|
337
|
+
console.warn(`Attempt to add body to missing annotation: ${p.annotation}`);
|
|
338
|
+
}, f = () => [...e.values()], T = (p = L.LOCAL) => {
|
|
339
|
+
const x = [...e.values()];
|
|
340
|
+
e.clear(), t.clear(), s(p, { deleted: x });
|
|
341
|
+
}, g = (p, x = !0, b = L.LOCAL) => {
|
|
342
|
+
if (x) {
|
|
343
|
+
const S = [...e.values()];
|
|
344
|
+
e.clear(), t.clear(), p.forEach((M) => {
|
|
345
|
+
e.set(M.id, M), M.bodies.forEach((R) => t.set(R.id, M.id));
|
|
346
|
+
}), s(b, { created: p, deleted: S });
|
|
343
347
|
} else {
|
|
344
|
-
const
|
|
345
|
-
const X =
|
|
348
|
+
const S = p.reduce((M, R) => {
|
|
349
|
+
const X = e.get(R.id);
|
|
346
350
|
return X ? [...M, X] : M;
|
|
347
351
|
}, []);
|
|
348
|
-
if (
|
|
349
|
-
throw Error(`Bulk insert would overwrite the following annotations: ${
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
}), s(
|
|
352
|
+
if (S.length > 0)
|
|
353
|
+
throw Error(`Bulk insert would overwrite the following annotations: ${S.map((M) => M.id).join(", ")}`);
|
|
354
|
+
p.forEach((M) => {
|
|
355
|
+
e.set(M.id, M), M.bodies.forEach((R) => t.set(R.id, M.id));
|
|
356
|
+
}), s(b, { created: p });
|
|
353
357
|
}
|
|
354
|
-
},
|
|
355
|
-
const
|
|
356
|
-
if (
|
|
357
|
-
return
|
|
358
|
-
console.warn(`Attempt to delete missing annotation: ${
|
|
359
|
-
}, B = (
|
|
360
|
-
const
|
|
361
|
-
|
|
362
|
-
},
|
|
363
|
-
const
|
|
364
|
-
const R =
|
|
365
|
-
return R ? [...
|
|
358
|
+
}, y = (p) => {
|
|
359
|
+
const x = typeof p == "string" ? p : p.id, b = e.get(x);
|
|
360
|
+
if (b)
|
|
361
|
+
return e.delete(x), b.bodies.forEach((S) => t.delete(S.id)), b;
|
|
362
|
+
console.warn(`Attempt to delete missing annotation: ${x}`);
|
|
363
|
+
}, B = (p, x = L.LOCAL) => {
|
|
364
|
+
const b = y(p);
|
|
365
|
+
b && s(x, { deleted: [b] });
|
|
366
|
+
}, A = (p, x = L.LOCAL) => {
|
|
367
|
+
const b = p.reduce((S, M) => {
|
|
368
|
+
const R = y(M);
|
|
369
|
+
return R ? [...S, R] : S;
|
|
366
370
|
}, []);
|
|
367
|
-
|
|
368
|
-
},
|
|
369
|
-
const
|
|
370
|
-
if (
|
|
371
|
-
const
|
|
372
|
-
if (
|
|
373
|
-
|
|
371
|
+
b.length > 0 && s(x, { deleted: b });
|
|
372
|
+
}, l = (p, x = L.LOCAL) => {
|
|
373
|
+
const b = e.get(p.annotation);
|
|
374
|
+
if (b) {
|
|
375
|
+
const S = b.bodies.find((M) => M.id === p.id);
|
|
376
|
+
if (S) {
|
|
377
|
+
t.delete(S.id);
|
|
374
378
|
const M = {
|
|
375
|
-
...
|
|
376
|
-
bodies:
|
|
379
|
+
...b,
|
|
380
|
+
bodies: b.bodies.filter((R) => R.id !== p.id)
|
|
377
381
|
};
|
|
378
|
-
|
|
379
|
-
oldValue:
|
|
382
|
+
e.set(b.id, M), s(x, { updated: [{
|
|
383
|
+
oldValue: b,
|
|
380
384
|
newValue: M,
|
|
381
|
-
bodiesDeleted: [
|
|
385
|
+
bodiesDeleted: [S]
|
|
382
386
|
}] });
|
|
383
387
|
} else
|
|
384
|
-
console.warn(`Attempt to delete missing body ${
|
|
388
|
+
console.warn(`Attempt to delete missing body ${p.id} from annotation ${p.annotation}`);
|
|
385
389
|
} else
|
|
386
|
-
console.warn(`Attempt to delete body from missing annotation ${
|
|
387
|
-
},
|
|
388
|
-
const
|
|
389
|
-
return
|
|
390
|
-
}, u = (
|
|
391
|
-
const
|
|
392
|
-
if (
|
|
393
|
-
const
|
|
394
|
-
if (
|
|
395
|
-
return
|
|
396
|
-
console.error(`Store integrity error: body ${
|
|
390
|
+
console.warn(`Attempt to delete body from missing annotation ${p.annotation}`);
|
|
391
|
+
}, c = (p) => {
|
|
392
|
+
const x = e.get(p);
|
|
393
|
+
return x ? { ...x } : void 0;
|
|
394
|
+
}, u = (p) => {
|
|
395
|
+
const x = t.get(p);
|
|
396
|
+
if (x) {
|
|
397
|
+
const b = c(x).bodies.find((S) => S.id === p);
|
|
398
|
+
if (b)
|
|
399
|
+
return b;
|
|
400
|
+
console.error(`Store integrity error: body ${p} in index, but not in annotation`);
|
|
397
401
|
} else
|
|
398
|
-
console.warn(`Attempt to retrieve missing body: ${
|
|
399
|
-
},
|
|
400
|
-
if (
|
|
402
|
+
console.warn(`Attempt to retrieve missing body: ${p}`);
|
|
403
|
+
}, m = (p, x) => {
|
|
404
|
+
if (p.annotation !== x.annotation)
|
|
401
405
|
throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
|
|
402
|
-
const
|
|
403
|
-
if (
|
|
404
|
-
const
|
|
405
|
-
...
|
|
406
|
-
bodies:
|
|
406
|
+
const b = e.get(p.annotation);
|
|
407
|
+
if (b) {
|
|
408
|
+
const S = b.bodies.find((R) => R.id === p.id), M = {
|
|
409
|
+
...b,
|
|
410
|
+
bodies: b.bodies.map((R) => R.id === S.id ? x : R)
|
|
407
411
|
};
|
|
408
|
-
return
|
|
409
|
-
oldValue:
|
|
412
|
+
return e.set(b.id, M), S.id !== x.id && (t.delete(S.id), t.set(x.id, M.id)), {
|
|
413
|
+
oldValue: b,
|
|
410
414
|
newValue: M,
|
|
411
|
-
bodiesUpdated: [{ oldBody:
|
|
415
|
+
bodiesUpdated: [{ oldBody: S, newBody: x }]
|
|
412
416
|
};
|
|
413
417
|
} else
|
|
414
|
-
console.warn(`Attempt to add body to missing annotation ${
|
|
415
|
-
},
|
|
416
|
-
const
|
|
417
|
-
s(
|
|
418
|
-
},
|
|
419
|
-
const
|
|
420
|
-
s(
|
|
421
|
-
},
|
|
422
|
-
const
|
|
423
|
-
if (
|
|
424
|
-
const
|
|
425
|
-
...
|
|
418
|
+
console.warn(`Attempt to add body to missing annotation ${p.annotation}`);
|
|
419
|
+
}, E = (p, x, b = L.LOCAL) => {
|
|
420
|
+
const S = m(p, x);
|
|
421
|
+
S && s(b, { updated: [S] });
|
|
422
|
+
}, v = (p, x = L.LOCAL) => {
|
|
423
|
+
const b = p.map((S) => m({ id: S.id, annotation: S.annotation }, S)).filter(Boolean);
|
|
424
|
+
s(x, { updated: b });
|
|
425
|
+
}, C = (p) => {
|
|
426
|
+
const x = e.get(p.annotation);
|
|
427
|
+
if (x) {
|
|
428
|
+
const b = {
|
|
429
|
+
...x,
|
|
426
430
|
target: {
|
|
427
|
-
...
|
|
428
|
-
...
|
|
431
|
+
...x.target,
|
|
432
|
+
...p
|
|
429
433
|
}
|
|
430
434
|
};
|
|
431
|
-
return
|
|
432
|
-
oldValue:
|
|
433
|
-
newValue:
|
|
435
|
+
return e.set(x.id, b), {
|
|
436
|
+
oldValue: x,
|
|
437
|
+
newValue: b,
|
|
434
438
|
targetUpdated: {
|
|
435
|
-
oldTarget:
|
|
436
|
-
newTarget:
|
|
439
|
+
oldTarget: x.target,
|
|
440
|
+
newTarget: p
|
|
437
441
|
}
|
|
438
442
|
};
|
|
439
443
|
} else
|
|
440
|
-
console.warn(`Attempt to update target on missing annotation: ${
|
|
444
|
+
console.warn(`Attempt to update target on missing annotation: ${p.annotation}`);
|
|
441
445
|
};
|
|
442
446
|
return {
|
|
443
|
-
addAnnotation:
|
|
444
|
-
addBody:
|
|
445
|
-
all:
|
|
446
|
-
bulkAddAnnotation:
|
|
447
|
-
bulkDeleteAnnotation:
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
447
|
+
addAnnotation: a,
|
|
448
|
+
addBody: w,
|
|
449
|
+
all: f,
|
|
450
|
+
bulkAddAnnotation: g,
|
|
451
|
+
bulkDeleteAnnotation: A,
|
|
452
|
+
bulkUpdateAnnotation: h,
|
|
453
|
+
bulkUpdateBodies: v,
|
|
454
|
+
bulkUpdateTargets: (p, x = L.LOCAL) => {
|
|
455
|
+
const b = p.map((S) => C(S)).filter(Boolean);
|
|
456
|
+
b.length > 0 && s(x, { updated: b });
|
|
452
457
|
},
|
|
453
|
-
clear:
|
|
458
|
+
clear: T,
|
|
454
459
|
deleteAnnotation: B,
|
|
455
|
-
deleteBody:
|
|
456
|
-
getAnnotation:
|
|
460
|
+
deleteBody: l,
|
|
461
|
+
getAnnotation: c,
|
|
457
462
|
getBody: u,
|
|
458
463
|
observe: o,
|
|
459
464
|
unobserve: i,
|
|
460
|
-
updateAnnotation:
|
|
461
|
-
updateBody:
|
|
462
|
-
updateTarget: (
|
|
463
|
-
const
|
|
464
|
-
|
|
465
|
+
updateAnnotation: d,
|
|
466
|
+
updateBody: E,
|
|
467
|
+
updateTarget: (p, x = L.LOCAL) => {
|
|
468
|
+
const b = C(p);
|
|
469
|
+
b && s(x, { updated: [b] });
|
|
465
470
|
}
|
|
466
471
|
};
|
|
467
|
-
}
|
|
468
|
-
|
|
472
|
+
};
|
|
473
|
+
let Ot = () => ({
|
|
474
|
+
emit(e, ...t) {
|
|
475
|
+
for (let n = 0, o = this.events[e] || [], i = o.length; n < i; n++)
|
|
476
|
+
o[n](...t);
|
|
477
|
+
},
|
|
478
|
+
events: {},
|
|
479
|
+
on(e, t) {
|
|
480
|
+
var n;
|
|
481
|
+
return ((n = this.events)[e] || (n[e] = [])).push(t), () => {
|
|
482
|
+
var o;
|
|
483
|
+
this.events[e] = (o = this.events[e]) == null ? void 0 : o.filter((i) => t !== i);
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
const Xt = 250, Yt = (e) => {
|
|
488
|
+
const t = Ot(), n = [];
|
|
489
|
+
let o = -1, i = !1, s = 0;
|
|
490
|
+
const a = (g) => {
|
|
491
|
+
if (!i) {
|
|
492
|
+
const { changes: y } = g, B = performance.now();
|
|
493
|
+
if (B - s > Xt)
|
|
494
|
+
n.splice(o + 1), n.push(y), o = n.length - 1;
|
|
495
|
+
else {
|
|
496
|
+
const A = n.length - 1;
|
|
497
|
+
n[A] = Ct(n[A], y);
|
|
498
|
+
}
|
|
499
|
+
s = B;
|
|
500
|
+
}
|
|
501
|
+
i = !1;
|
|
502
|
+
};
|
|
503
|
+
e.observe(a, { origin: L.LOCAL });
|
|
504
|
+
const r = (g) => g && g.length > 0 && e.bulkDeleteAnnotation(g), d = (g) => g && g.length > 0 && e.bulkAddAnnotation(g, !1), h = (g) => g && g.length > 0 && e.bulkUpdateAnnotation(g.map(({ oldValue: y }) => y)), w = (g) => g && g.length > 0 && e.bulkUpdateAnnotation(g.map(({ newValue: y }) => y)), f = (g) => g && g.length > 0 && e.bulkAddAnnotation(g, !1), T = (g) => g && g.length > 0 && e.bulkDeleteAnnotation(g);
|
|
469
505
|
return {
|
|
470
|
-
|
|
471
|
-
|
|
506
|
+
canRedo: () => n.length - 1 > o,
|
|
507
|
+
canUndo: () => o > -1,
|
|
508
|
+
destroy: () => e.unobserve(a),
|
|
509
|
+
on: (g, y) => t.on(g, y),
|
|
510
|
+
redo: () => {
|
|
511
|
+
if (n.length - 1 > o) {
|
|
512
|
+
i = !0;
|
|
513
|
+
const { created: g, updated: y, deleted: B } = n[o + 1];
|
|
514
|
+
d(g), w(y), T(B), t.emit("redo", n[o + 1]), o += 1;
|
|
515
|
+
}
|
|
516
|
+
},
|
|
517
|
+
undo: () => {
|
|
518
|
+
if (o > -1) {
|
|
519
|
+
i = !0;
|
|
520
|
+
const { created: g, updated: y, deleted: B } = n[o];
|
|
521
|
+
r(g), h(y), f(B), t.emit("undo", n[o]), o -= 1;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
};
|
|
525
|
+
}, Ut = () => {
|
|
526
|
+
const { subscribe: e, set: t } = J([]);
|
|
527
|
+
return {
|
|
528
|
+
subscribe: e,
|
|
529
|
+
set: t
|
|
472
530
|
};
|
|
473
|
-
},
|
|
474
|
-
const
|
|
475
|
-
let
|
|
476
|
-
const
|
|
477
|
-
|
|
478
|
-
},
|
|
479
|
-
const
|
|
480
|
-
|
|
481
|
-
},
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
if (
|
|
485
|
-
const
|
|
486
|
-
|
|
531
|
+
}, Dt = (e, t, n, o) => {
|
|
532
|
+
const { store: i, selection: s, hover: a, viewport: r } = e, d = /* @__PURE__ */ new Map();
|
|
533
|
+
let h = [], w, f;
|
|
534
|
+
const T = (l, c) => {
|
|
535
|
+
d.has(l) ? d.get(l).push(c) : d.set(l, [c]);
|
|
536
|
+
}, g = (l, c) => {
|
|
537
|
+
const u = d.get(l);
|
|
538
|
+
u && u.indexOf(c) > 0 && u.splice(u.indexOf(c), 1);
|
|
539
|
+
}, y = (l, c, u) => {
|
|
540
|
+
d.has(l) && setTimeout(() => {
|
|
541
|
+
d.get(l).forEach((m) => {
|
|
542
|
+
if (n) {
|
|
543
|
+
const E = Array.isArray(c) ? c.map((C) => n.serialize(C)) : n.serialize(c), v = u ? u instanceof PointerEvent ? u : n.serialize(u) : void 0;
|
|
544
|
+
m(E, v);
|
|
487
545
|
} else
|
|
488
|
-
|
|
546
|
+
m(c, u);
|
|
489
547
|
});
|
|
490
548
|
}, 1);
|
|
491
549
|
}, B = () => {
|
|
492
|
-
const { selected:
|
|
493
|
-
|
|
494
|
-
const
|
|
495
|
-
(!
|
|
496
|
-
}),
|
|
497
|
-
const u = w.find(({ id: a }) => a === A.id);
|
|
498
|
-
return u || A;
|
|
499
|
-
});
|
|
550
|
+
const { selected: l } = s, c = (l || []).map(({ id: u }) => i.getAnnotation(u));
|
|
551
|
+
c.forEach((u) => {
|
|
552
|
+
const m = h.find((E) => E.id === u.id);
|
|
553
|
+
(!m || !U(m, u)) && y("updateAnnotation", u, m);
|
|
554
|
+
}), h = h.map((u) => c.find(({ id: E }) => E === u.id) || u);
|
|
500
555
|
};
|
|
501
|
-
|
|
502
|
-
if (!(
|
|
503
|
-
if (
|
|
504
|
-
|
|
505
|
-
else if (
|
|
506
|
-
|
|
507
|
-
const
|
|
508
|
-
|
|
509
|
-
}),
|
|
556
|
+
s.subscribe(({ selected: l }) => {
|
|
557
|
+
if (!(h.length === 0 && l.length === 0)) {
|
|
558
|
+
if (h.length === 0 && l.length > 0)
|
|
559
|
+
h = l.map(({ id: c }) => i.getAnnotation(c));
|
|
560
|
+
else if (h.length > 0 && l.length === 0)
|
|
561
|
+
h.forEach((c) => {
|
|
562
|
+
const u = i.getAnnotation(c.id);
|
|
563
|
+
u && !U(u, c) && y("updateAnnotation", u, c);
|
|
564
|
+
}), h = [];
|
|
510
565
|
else {
|
|
511
|
-
const
|
|
512
|
-
|
|
513
|
-
const
|
|
514
|
-
|
|
515
|
-
}),
|
|
566
|
+
const c = new Set(h.map((m) => m.id)), u = new Set(l.map(({ id: m }) => m));
|
|
567
|
+
h.filter((m) => !u.has(m.id)).forEach((m) => {
|
|
568
|
+
const E = i.getAnnotation(m.id);
|
|
569
|
+
E && !U(E, m) && y("updateAnnotation", E, m);
|
|
570
|
+
}), h = [
|
|
516
571
|
// Remove annotations that were deselected
|
|
517
|
-
...
|
|
572
|
+
...h.filter((m) => u.has(m.id)),
|
|
518
573
|
// Add editable annotations that were selected
|
|
519
|
-
...
|
|
574
|
+
...l.filter(({ id: m }) => !c.has(m)).map(({ id: m }) => i.getAnnotation(m))
|
|
520
575
|
];
|
|
521
576
|
}
|
|
522
|
-
|
|
577
|
+
y("selectionChanged", h);
|
|
523
578
|
}
|
|
524
|
-
}),
|
|
525
|
-
!
|
|
526
|
-
}),
|
|
527
|
-
|
|
528
|
-
const { created:
|
|
529
|
-
|
|
530
|
-
...
|
|
531
|
-
...
|
|
532
|
-
...
|
|
533
|
-
].length > 0).forEach(({ oldValue:
|
|
534
|
-
const
|
|
535
|
-
|
|
579
|
+
}), a.subscribe((l) => {
|
|
580
|
+
!w && l ? y("mouseEnterAnnotation", i.getAnnotation(l)) : w && !l ? y("mouseLeaveAnnotation", i.getAnnotation(w)) : w && l && (y("mouseLeaveAnnotation", i.getAnnotation(w)), y("mouseEnterAnnotation", i.getAnnotation(l))), w = l;
|
|
581
|
+
}), r == null || r.subscribe((l) => y("viewportIntersect", l.map((c) => i.getAnnotation(c)))), i.observe((l) => {
|
|
582
|
+
o && (f && clearTimeout(f), f = setTimeout(B, 1e3));
|
|
583
|
+
const { created: c, deleted: u } = l.changes;
|
|
584
|
+
(c || []).forEach((m) => y("createAnnotation", m)), (u || []).forEach((m) => y("deleteAnnotation", m)), (l.changes.updated || []).filter((m) => [
|
|
585
|
+
...m.bodiesCreated || [],
|
|
586
|
+
...m.bodiesDeleted || [],
|
|
587
|
+
...m.bodiesUpdated || []
|
|
588
|
+
].length > 0).forEach(({ oldValue: m, newValue: E }) => {
|
|
589
|
+
const v = h.find((C) => C.id === m.id) || m;
|
|
590
|
+
h = h.map((C) => C.id === m.id ? E : C), y("updateAnnotation", E, v);
|
|
536
591
|
});
|
|
537
|
-
}, { origin: L.LOCAL }),
|
|
538
|
-
if (
|
|
539
|
-
const
|
|
540
|
-
|
|
541
|
-
const a = A.find((m) => m.id === u.id);
|
|
542
|
-
return a || u;
|
|
543
|
-
}));
|
|
592
|
+
}, { origin: L.LOCAL }), i.observe((l) => {
|
|
593
|
+
if (h) {
|
|
594
|
+
const c = new Set(h.map((m) => m.id)), u = (l.changes.updated || []).filter(({ newValue: m }) => c.has(m.id)).map(({ newValue: m }) => m);
|
|
595
|
+
u.length > 0 && (h = h.map((m) => u.find((v) => v.id === m.id) || m));
|
|
544
596
|
}
|
|
545
|
-
}, { origin: L.REMOTE })
|
|
546
|
-
|
|
547
|
-
|
|
597
|
+
}, { origin: L.REMOTE });
|
|
598
|
+
const A = (l) => (c) => {
|
|
599
|
+
const { created: u, deleted: m, updated: E } = c;
|
|
600
|
+
(u || []).forEach((v) => y("createAnnotation", v)), (m || []).forEach((v) => y("deleteAnnotation", v)), l ? (E || []).forEach((v) => y("updateAnnotation", v.oldValue, v.newValue)) : (E || []).forEach((v) => y("updateAnnotation", v.newValue, v.oldValue));
|
|
601
|
+
};
|
|
602
|
+
return t.on("undo", A(!0)), t.on("redo", A(!1)), { on: T, off: g, emit: y };
|
|
603
|
+
}, It = (e) => (t) => t.reduce((n, o) => {
|
|
604
|
+
const { parsed: i, error: s } = e.parse(o);
|
|
548
605
|
return s ? {
|
|
549
606
|
parsed: n.parsed,
|
|
550
607
|
failed: [...n.failed, o]
|
|
551
|
-
} : {
|
|
608
|
+
} : i ? {
|
|
552
609
|
parsed: [...n.parsed, i],
|
|
553
610
|
failed: n.failed
|
|
611
|
+
} : {
|
|
612
|
+
...n
|
|
554
613
|
};
|
|
555
|
-
}, { parsed: [], failed: [] }),
|
|
556
|
-
const
|
|
557
|
-
if (
|
|
558
|
-
const { parsed:
|
|
559
|
-
|
|
614
|
+
}, { parsed: [], failed: [] }), Vt = (e, t, n) => {
|
|
615
|
+
const { store: o, selection: i } = e, s = (A) => {
|
|
616
|
+
if (n) {
|
|
617
|
+
const { parsed: l, error: c } = n.parse(A);
|
|
618
|
+
l ? o.addAnnotation(l, L.REMOTE) : console.error(c);
|
|
560
619
|
} else
|
|
561
|
-
|
|
562
|
-
},
|
|
563
|
-
const
|
|
564
|
-
return
|
|
565
|
-
},
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
620
|
+
o.addAnnotation(A, L.REMOTE);
|
|
621
|
+
}, a = () => i.clear(), r = () => o.clear(), d = (A) => {
|
|
622
|
+
const l = o.getAnnotation(A);
|
|
623
|
+
return n && l ? n.serialize(l) : l;
|
|
624
|
+
}, h = () => n ? o.all().map(n.serialize) : o.all(), w = () => {
|
|
625
|
+
var A;
|
|
626
|
+
const l = (((A = i.selected) == null ? void 0 : A.map((c) => c.id)) || []).map((c) => o.getAnnotation(c)).filter(Boolean);
|
|
627
|
+
return n ? l.map(n.serialize) : l;
|
|
628
|
+
}, f = (A) => fetch(A).then((l) => l.json()).then((l) => (g(l), l)), T = (A) => {
|
|
629
|
+
if (typeof A == "string") {
|
|
630
|
+
const l = o.getAnnotation(A);
|
|
631
|
+
if (o.deleteAnnotation(A), l)
|
|
632
|
+
return n ? n.serialize(l) : l;
|
|
569
633
|
} else {
|
|
570
|
-
const
|
|
571
|
-
|
|
634
|
+
const l = n ? n.parse(A).parsed : A;
|
|
635
|
+
if (l)
|
|
636
|
+
return o.deleteAnnotation(l), A;
|
|
572
637
|
}
|
|
573
|
-
},
|
|
574
|
-
if (
|
|
575
|
-
const { parsed:
|
|
576
|
-
|
|
638
|
+
}, g = (A) => {
|
|
639
|
+
if (n) {
|
|
640
|
+
const { parsed: l, failed: c } = It(n)(A);
|
|
641
|
+
c.length > 0 && console.warn(`Discarded ${c.length} invalid annotations`, c), o.bulkAddAnnotation(l, !0, L.REMOTE);
|
|
577
642
|
} else
|
|
578
|
-
|
|
643
|
+
o.bulkAddAnnotation(A, !0, L.REMOTE);
|
|
644
|
+
}, y = (A) => {
|
|
645
|
+
A ? i.setSelected(A) : i.clear();
|
|
646
|
+
}, B = (A) => {
|
|
647
|
+
if (n) {
|
|
648
|
+
const l = n.parse(A).parsed, c = n.serialize(o.getAnnotation(l.id));
|
|
649
|
+
return o.updateAnnotation(l), c;
|
|
650
|
+
} else {
|
|
651
|
+
const l = o.getAnnotation(A.id);
|
|
652
|
+
return o.updateAnnotation(A), l;
|
|
653
|
+
}
|
|
579
654
|
};
|
|
580
655
|
return {
|
|
581
|
-
addAnnotation:
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
}
|
|
656
|
+
addAnnotation: s,
|
|
657
|
+
cancelSelected: a,
|
|
658
|
+
canRedo: t.canRedo,
|
|
659
|
+
canUndo: t.canUndo,
|
|
660
|
+
clearAnnotations: r,
|
|
661
|
+
getAnnotationById: d,
|
|
662
|
+
getAnnotations: h,
|
|
663
|
+
getSelected: w,
|
|
664
|
+
loadAnnotations: f,
|
|
665
|
+
redo: t.redo,
|
|
666
|
+
removeAnnotation: T,
|
|
667
|
+
setAnnotations: g,
|
|
668
|
+
setSelected: y,
|
|
669
|
+
undo: t.undo,
|
|
670
|
+
updateAnnotation: B
|
|
597
671
|
};
|
|
598
672
|
};
|
|
599
|
-
let
|
|
600
|
-
let o = (2 << Math.log(
|
|
601
|
-
return (s =
|
|
602
|
-
let
|
|
673
|
+
let _t = (e) => crypto.getRandomValues(new Uint8Array(e)), kt = (e, t, n) => {
|
|
674
|
+
let o = (2 << Math.log(e.length - 1) / Math.LN2) - 1, i = -~(1.6 * o * t / e.length);
|
|
675
|
+
return (s = t) => {
|
|
676
|
+
let a = "";
|
|
603
677
|
for (; ; ) {
|
|
604
|
-
let r = n(i),
|
|
605
|
-
for (;
|
|
606
|
-
if (
|
|
607
|
-
return
|
|
678
|
+
let r = n(i), d = i;
|
|
679
|
+
for (; d--; )
|
|
680
|
+
if (a += e[r[d] & o] || "", a.length === s)
|
|
681
|
+
return a;
|
|
608
682
|
}
|
|
609
683
|
};
|
|
610
|
-
},
|
|
611
|
-
const zt = () => ({ isGuest: !0, id:
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
let s = e.charCodeAt(o);
|
|
616
|
-
n = (n << 5) - n + s, n |= 0;
|
|
617
|
-
}
|
|
618
|
-
return `${n}`;
|
|
619
|
-
}, ce = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
|
|
620
|
-
const { id: o, type: i, purpose: s, value: c, created: r, creator: l, ...h } = n;
|
|
621
|
-
return {
|
|
622
|
-
id: o || `temp-${Pt(n)}`,
|
|
623
|
-
annotation: e,
|
|
624
|
-
type: i,
|
|
625
|
-
purpose: s,
|
|
626
|
-
value: c,
|
|
627
|
-
created: r,
|
|
628
|
-
creator: l ? typeof l == "object" ? { ...l } : l : void 0,
|
|
629
|
-
...h
|
|
630
|
-
};
|
|
631
|
-
}), ae = (t) => t.map((e) => {
|
|
632
|
-
var o;
|
|
633
|
-
const n = { ...e };
|
|
634
|
-
return delete n.annotation, (o = n.id) != null && o.startsWith("temp-") && delete n.id, n;
|
|
635
|
-
});
|
|
636
|
-
kt();
|
|
637
|
-
function Ht(t, e, n, o, i) {
|
|
638
|
-
it(t, e, n || 0, o || t.length - 1, i || $t);
|
|
684
|
+
}, Nt = (e, t = 21) => kt(e, t, _t), Pt = (e = 21) => crypto.getRandomValues(new Uint8Array(e)).reduce((t, n) => (n &= 63, n < 36 ? t += n.toString(36) : n < 62 ? t += (n - 26).toString(36).toUpperCase() : n > 62 ? t += "-" : t += "_", t), "");
|
|
685
|
+
const zt = () => ({ isGuest: !0, id: Nt("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() });
|
|
686
|
+
Pt();
|
|
687
|
+
function Ht(e, t, n, o, i) {
|
|
688
|
+
it(e, t, n || 0, o || e.length - 1, i || Ft);
|
|
639
689
|
}
|
|
640
|
-
function it(
|
|
690
|
+
function it(e, t, n, o, i) {
|
|
641
691
|
for (; o > n; ) {
|
|
642
692
|
if (o - n > 600) {
|
|
643
|
-
var s = o - n + 1,
|
|
644
|
-
it(
|
|
693
|
+
var s = o - n + 1, a = t - n + 1, r = Math.log(s), d = 0.5 * Math.exp(2 * r / 3), h = 0.5 * Math.sqrt(r * d * (s - d) / s) * (a - s / 2 < 0 ? -1 : 1), w = Math.max(n, Math.floor(t - a * d / s + h)), f = Math.min(o, Math.floor(t + (s - a) * d / s + h));
|
|
694
|
+
it(e, t, w, f, i);
|
|
645
695
|
}
|
|
646
|
-
var
|
|
647
|
-
for (
|
|
648
|
-
for (
|
|
649
|
-
|
|
650
|
-
for (; i(
|
|
651
|
-
|
|
696
|
+
var T = e[t], g = n, y = o;
|
|
697
|
+
for (k(e, n, t), i(e[o], T) > 0 && k(e, n, o); g < y; ) {
|
|
698
|
+
for (k(e, g, y), g++, y--; i(e[g], T) < 0; )
|
|
699
|
+
g++;
|
|
700
|
+
for (; i(e[y], T) > 0; )
|
|
701
|
+
y--;
|
|
652
702
|
}
|
|
653
|
-
i(
|
|
703
|
+
i(e[n], T) === 0 ? k(e, n, y) : (y++, k(e, y, o)), y <= t && (n = y + 1), t <= y && (o = y - 1);
|
|
654
704
|
}
|
|
655
705
|
}
|
|
656
|
-
function
|
|
657
|
-
var o = t
|
|
658
|
-
t
|
|
706
|
+
function k(e, t, n) {
|
|
707
|
+
var o = e[t];
|
|
708
|
+
e[t] = e[n], e[n] = o;
|
|
659
709
|
}
|
|
660
|
-
function
|
|
661
|
-
return
|
|
710
|
+
function Ft(e, t) {
|
|
711
|
+
return e < t ? -1 : e > t ? 1 : 0;
|
|
662
712
|
}
|
|
663
|
-
class
|
|
664
|
-
constructor(
|
|
665
|
-
this._maxEntries = Math.max(4,
|
|
713
|
+
class $t {
|
|
714
|
+
constructor(t = 9) {
|
|
715
|
+
this._maxEntries = Math.max(4, t), this._minEntries = Math.max(2, Math.ceil(this._maxEntries * 0.4)), this.clear();
|
|
666
716
|
}
|
|
667
717
|
all() {
|
|
668
718
|
return this._all(this.data, []);
|
|
669
719
|
}
|
|
670
|
-
search(
|
|
720
|
+
search(t) {
|
|
671
721
|
let n = this.data;
|
|
672
722
|
const o = [];
|
|
673
|
-
if (!
|
|
723
|
+
if (!H(t, n))
|
|
674
724
|
return o;
|
|
675
725
|
const i = this.toBBox, s = [];
|
|
676
726
|
for (; n; ) {
|
|
677
|
-
for (let
|
|
678
|
-
const r = n.children[
|
|
679
|
-
|
|
727
|
+
for (let a = 0; a < n.children.length; a++) {
|
|
728
|
+
const r = n.children[a], d = n.leaf ? i(r) : r;
|
|
729
|
+
H(t, d) && (n.leaf ? o.push(r) : K(t, d) ? this._all(r, o) : s.push(r));
|
|
680
730
|
}
|
|
681
731
|
n = s.pop();
|
|
682
732
|
}
|
|
683
733
|
return o;
|
|
684
734
|
}
|
|
685
|
-
collides(
|
|
735
|
+
collides(t) {
|
|
686
736
|
let n = this.data;
|
|
687
|
-
if (!
|
|
737
|
+
if (!H(t, n))
|
|
688
738
|
return !1;
|
|
689
739
|
const o = [];
|
|
690
740
|
for (; n; ) {
|
|
691
741
|
for (let i = 0; i < n.children.length; i++) {
|
|
692
|
-
const s = n.children[i],
|
|
693
|
-
if (
|
|
694
|
-
if (n.leaf ||
|
|
742
|
+
const s = n.children[i], a = n.leaf ? this.toBBox(s) : s;
|
|
743
|
+
if (H(t, a)) {
|
|
744
|
+
if (n.leaf || K(t, a))
|
|
695
745
|
return !0;
|
|
696
746
|
o.push(s);
|
|
697
747
|
}
|
|
@@ -700,15 +750,15 @@ class Vt {
|
|
|
700
750
|
}
|
|
701
751
|
return !1;
|
|
702
752
|
}
|
|
703
|
-
load(
|
|
704
|
-
if (!(
|
|
753
|
+
load(t) {
|
|
754
|
+
if (!(t && t.length))
|
|
705
755
|
return this;
|
|
706
|
-
if (
|
|
707
|
-
for (let o = 0; o <
|
|
708
|
-
this.insert(
|
|
756
|
+
if (t.length < this._minEntries) {
|
|
757
|
+
for (let o = 0; o < t.length; o++)
|
|
758
|
+
this.insert(t[o]);
|
|
709
759
|
return this;
|
|
710
760
|
}
|
|
711
|
-
let n = this._build(
|
|
761
|
+
let n = this._build(t.slice(), 0, t.length - 1, 0);
|
|
712
762
|
if (!this.data.children.length)
|
|
713
763
|
this.data = n;
|
|
714
764
|
else if (this.data.height === n.height)
|
|
@@ -722,181 +772,181 @@ class Vt {
|
|
|
722
772
|
}
|
|
723
773
|
return this;
|
|
724
774
|
}
|
|
725
|
-
insert(
|
|
726
|
-
return
|
|
775
|
+
insert(t) {
|
|
776
|
+
return t && this._insert(t, this.data.height - 1), this;
|
|
727
777
|
}
|
|
728
778
|
clear() {
|
|
729
|
-
return this.data =
|
|
779
|
+
return this.data = V([]), this;
|
|
730
780
|
}
|
|
731
|
-
remove(
|
|
732
|
-
if (!
|
|
781
|
+
remove(t, n) {
|
|
782
|
+
if (!t)
|
|
733
783
|
return this;
|
|
734
784
|
let o = this.data;
|
|
735
|
-
const i = this.toBBox(
|
|
736
|
-
let r,
|
|
785
|
+
const i = this.toBBox(t), s = [], a = [];
|
|
786
|
+
let r, d, h;
|
|
737
787
|
for (; o || s.length; ) {
|
|
738
|
-
if (o || (o = s.pop(),
|
|
739
|
-
const
|
|
740
|
-
if (
|
|
741
|
-
return o.children.splice(
|
|
788
|
+
if (o || (o = s.pop(), d = s[s.length - 1], r = a.pop(), h = !0), o.leaf) {
|
|
789
|
+
const w = Wt(t, o.children, n);
|
|
790
|
+
if (w !== -1)
|
|
791
|
+
return o.children.splice(w, 1), s.push(o), this._condense(s), this;
|
|
742
792
|
}
|
|
743
|
-
!h && !o.leaf &&
|
|
793
|
+
!h && !o.leaf && K(o, i) ? (s.push(o), a.push(r), r = 0, d = o, o = o.children[0]) : d ? (r++, o = d.children[r], h = !1) : o = null;
|
|
744
794
|
}
|
|
745
795
|
return this;
|
|
746
796
|
}
|
|
747
|
-
toBBox(
|
|
748
|
-
return
|
|
797
|
+
toBBox(t) {
|
|
798
|
+
return t;
|
|
749
799
|
}
|
|
750
|
-
compareMinX(
|
|
751
|
-
return
|
|
800
|
+
compareMinX(t, n) {
|
|
801
|
+
return t.minX - n.minX;
|
|
752
802
|
}
|
|
753
|
-
compareMinY(
|
|
754
|
-
return
|
|
803
|
+
compareMinY(t, n) {
|
|
804
|
+
return t.minY - n.minY;
|
|
755
805
|
}
|
|
756
806
|
toJSON() {
|
|
757
807
|
return this.data;
|
|
758
808
|
}
|
|
759
|
-
fromJSON(
|
|
760
|
-
return this.data =
|
|
809
|
+
fromJSON(t) {
|
|
810
|
+
return this.data = t, this;
|
|
761
811
|
}
|
|
762
|
-
_all(
|
|
812
|
+
_all(t, n) {
|
|
763
813
|
const o = [];
|
|
764
|
-
for (;
|
|
765
|
-
|
|
814
|
+
for (; t; )
|
|
815
|
+
t.leaf ? n.push(...t.children) : o.push(...t.children), t = o.pop();
|
|
766
816
|
return n;
|
|
767
817
|
}
|
|
768
|
-
_build(
|
|
818
|
+
_build(t, n, o, i) {
|
|
769
819
|
const s = o - n + 1;
|
|
770
|
-
let
|
|
771
|
-
if (s <=
|
|
772
|
-
return r =
|
|
773
|
-
i || (i = Math.ceil(Math.log(s) / Math.log(
|
|
774
|
-
const
|
|
775
|
-
|
|
776
|
-
for (let
|
|
777
|
-
const
|
|
778
|
-
|
|
779
|
-
for (let
|
|
780
|
-
const
|
|
781
|
-
r.children.push(this._build(
|
|
820
|
+
let a = this._maxEntries, r;
|
|
821
|
+
if (s <= a)
|
|
822
|
+
return r = V(t.slice(n, o + 1)), I(r, this.toBBox), r;
|
|
823
|
+
i || (i = Math.ceil(Math.log(s) / Math.log(a)), a = Math.ceil(s / Math.pow(a, i - 1))), r = V([]), r.leaf = !1, r.height = i;
|
|
824
|
+
const d = Math.ceil(s / a), h = d * Math.ceil(Math.sqrt(a));
|
|
825
|
+
tt(t, n, o, h, this.compareMinX);
|
|
826
|
+
for (let w = n; w <= o; w += h) {
|
|
827
|
+
const f = Math.min(w + h - 1, o);
|
|
828
|
+
tt(t, w, f, d, this.compareMinY);
|
|
829
|
+
for (let T = w; T <= f; T += d) {
|
|
830
|
+
const g = Math.min(T + d - 1, f);
|
|
831
|
+
r.children.push(this._build(t, T, g, i - 1));
|
|
782
832
|
}
|
|
783
833
|
}
|
|
784
834
|
return I(r, this.toBBox), r;
|
|
785
835
|
}
|
|
786
|
-
_chooseSubtree(
|
|
836
|
+
_chooseSubtree(t, n, o, i) {
|
|
787
837
|
for (; i.push(n), !(n.leaf || i.length - 1 === o); ) {
|
|
788
|
-
let s = 1 / 0,
|
|
789
|
-
for (let
|
|
790
|
-
const h = n.children[
|
|
791
|
-
|
|
838
|
+
let s = 1 / 0, a = 1 / 0, r;
|
|
839
|
+
for (let d = 0; d < n.children.length; d++) {
|
|
840
|
+
const h = n.children[d], w = G(h), f = Kt(t, h) - w;
|
|
841
|
+
f < a ? (a = f, s = w < s ? w : s, r = h) : f === a && w < s && (s = w, r = h);
|
|
792
842
|
}
|
|
793
843
|
n = r || n.children[0];
|
|
794
844
|
}
|
|
795
845
|
return n;
|
|
796
846
|
}
|
|
797
|
-
_insert(
|
|
798
|
-
const i = o ?
|
|
799
|
-
for (
|
|
847
|
+
_insert(t, n, o) {
|
|
848
|
+
const i = o ? t : this.toBBox(t), s = [], a = this._chooseSubtree(i, this.data, n, s);
|
|
849
|
+
for (a.children.push(t), P(a, i); n >= 0 && s[n].children.length > this._maxEntries; )
|
|
800
850
|
this._split(s, n), n--;
|
|
801
851
|
this._adjustParentBBoxes(i, s, n);
|
|
802
852
|
}
|
|
803
853
|
// split overflowed node into two
|
|
804
|
-
_split(
|
|
805
|
-
const o =
|
|
854
|
+
_split(t, n) {
|
|
855
|
+
const o = t[n], i = o.children.length, s = this._minEntries;
|
|
806
856
|
this._chooseSplitAxis(o, s, i);
|
|
807
|
-
const
|
|
808
|
-
r.height = o.height, r.leaf = o.leaf, I(o, this.toBBox), I(r, this.toBBox), n ?
|
|
857
|
+
const a = this._chooseSplitIndex(o, s, i), r = V(o.children.splice(a, o.children.length - a));
|
|
858
|
+
r.height = o.height, r.leaf = o.leaf, I(o, this.toBBox), I(r, this.toBBox), n ? t[n - 1].children.push(r) : this._splitRoot(o, r);
|
|
809
859
|
}
|
|
810
|
-
_splitRoot(
|
|
811
|
-
this.data =
|
|
860
|
+
_splitRoot(t, n) {
|
|
861
|
+
this.data = V([t, n]), this.data.height = t.height + 1, this.data.leaf = !1, I(this.data, this.toBBox);
|
|
812
862
|
}
|
|
813
|
-
_chooseSplitIndex(
|
|
814
|
-
let i, s = 1 / 0,
|
|
863
|
+
_chooseSplitIndex(t, n, o) {
|
|
864
|
+
let i, s = 1 / 0, a = 1 / 0;
|
|
815
865
|
for (let r = n; r <= o - n; r++) {
|
|
816
|
-
const
|
|
817
|
-
|
|
866
|
+
const d = N(t, 0, r, this.toBBox), h = N(t, r, o, this.toBBox), w = Jt(d, h), f = G(d) + G(h);
|
|
867
|
+
w < s ? (s = w, i = r, a = f < a ? f : a) : w === s && f < a && (a = f, i = r);
|
|
818
868
|
}
|
|
819
869
|
return i || o - n;
|
|
820
870
|
}
|
|
821
871
|
// sorts node children by the best axis for split
|
|
822
|
-
_chooseSplitAxis(
|
|
823
|
-
const i =
|
|
824
|
-
|
|
872
|
+
_chooseSplitAxis(t, n, o) {
|
|
873
|
+
const i = t.leaf ? this.compareMinX : qt, s = t.leaf ? this.compareMinY : Gt, a = this._allDistMargin(t, n, o, i), r = this._allDistMargin(t, n, o, s);
|
|
874
|
+
a < r && t.children.sort(i);
|
|
825
875
|
}
|
|
826
876
|
// total margin of all possible split distributions where each node is at least m full
|
|
827
|
-
_allDistMargin(
|
|
828
|
-
|
|
829
|
-
const s = this.toBBox,
|
|
830
|
-
let
|
|
877
|
+
_allDistMargin(t, n, o, i) {
|
|
878
|
+
t.children.sort(i);
|
|
879
|
+
const s = this.toBBox, a = N(t, 0, n, s), r = N(t, o - n, o, s);
|
|
880
|
+
let d = z(a) + z(r);
|
|
831
881
|
for (let h = n; h < o - n; h++) {
|
|
832
|
-
const
|
|
833
|
-
P(
|
|
882
|
+
const w = t.children[h];
|
|
883
|
+
P(a, t.leaf ? s(w) : w), d += z(a);
|
|
834
884
|
}
|
|
835
885
|
for (let h = o - n - 1; h >= n; h--) {
|
|
836
|
-
const
|
|
837
|
-
P(r,
|
|
886
|
+
const w = t.children[h];
|
|
887
|
+
P(r, t.leaf ? s(w) : w), d += z(r);
|
|
838
888
|
}
|
|
839
|
-
return
|
|
889
|
+
return d;
|
|
840
890
|
}
|
|
841
|
-
_adjustParentBBoxes(
|
|
891
|
+
_adjustParentBBoxes(t, n, o) {
|
|
842
892
|
for (let i = o; i >= 0; i--)
|
|
843
|
-
P(n[i],
|
|
893
|
+
P(n[i], t);
|
|
844
894
|
}
|
|
845
|
-
_condense(
|
|
846
|
-
for (let n =
|
|
847
|
-
|
|
895
|
+
_condense(t) {
|
|
896
|
+
for (let n = t.length - 1, o; n >= 0; n--)
|
|
897
|
+
t[n].children.length === 0 ? n > 0 ? (o = t[n - 1].children, o.splice(o.indexOf(t[n]), 1)) : this.clear() : I(t[n], this.toBBox);
|
|
848
898
|
}
|
|
849
899
|
}
|
|
850
|
-
function Wt(
|
|
900
|
+
function Wt(e, t, n) {
|
|
851
901
|
if (!n)
|
|
852
|
-
return
|
|
853
|
-
for (let o = 0; o <
|
|
854
|
-
if (n(
|
|
902
|
+
return t.indexOf(e);
|
|
903
|
+
for (let o = 0; o < t.length; o++)
|
|
904
|
+
if (n(e, t[o]))
|
|
855
905
|
return o;
|
|
856
906
|
return -1;
|
|
857
907
|
}
|
|
858
|
-
function I(
|
|
859
|
-
|
|
908
|
+
function I(e, t) {
|
|
909
|
+
N(e, 0, e.children.length, t, e);
|
|
860
910
|
}
|
|
861
|
-
function
|
|
862
|
-
i || (i =
|
|
863
|
-
for (let s =
|
|
864
|
-
const
|
|
865
|
-
P(i,
|
|
911
|
+
function N(e, t, n, o, i) {
|
|
912
|
+
i || (i = V(null)), i.minX = 1 / 0, i.minY = 1 / 0, i.maxX = -1 / 0, i.maxY = -1 / 0;
|
|
913
|
+
for (let s = t; s < n; s++) {
|
|
914
|
+
const a = e.children[s];
|
|
915
|
+
P(i, e.leaf ? o(a) : a);
|
|
866
916
|
}
|
|
867
917
|
return i;
|
|
868
918
|
}
|
|
869
|
-
function P(
|
|
870
|
-
return
|
|
919
|
+
function P(e, t) {
|
|
920
|
+
return e.minX = Math.min(e.minX, t.minX), e.minY = Math.min(e.minY, t.minY), e.maxX = Math.max(e.maxX, t.maxX), e.maxY = Math.max(e.maxY, t.maxY), e;
|
|
871
921
|
}
|
|
872
|
-
function qt(
|
|
873
|
-
return
|
|
922
|
+
function qt(e, t) {
|
|
923
|
+
return e.minX - t.minX;
|
|
874
924
|
}
|
|
875
|
-
function
|
|
876
|
-
return
|
|
925
|
+
function Gt(e, t) {
|
|
926
|
+
return e.minY - t.minY;
|
|
877
927
|
}
|
|
878
|
-
function G(
|
|
879
|
-
return (
|
|
928
|
+
function G(e) {
|
|
929
|
+
return (e.maxX - e.minX) * (e.maxY - e.minY);
|
|
880
930
|
}
|
|
881
|
-
function
|
|
882
|
-
return
|
|
931
|
+
function z(e) {
|
|
932
|
+
return e.maxX - e.minX + (e.maxY - e.minY);
|
|
883
933
|
}
|
|
884
|
-
function
|
|
885
|
-
return (Math.max(
|
|
934
|
+
function Kt(e, t) {
|
|
935
|
+
return (Math.max(t.maxX, e.maxX) - Math.min(t.minX, e.minX)) * (Math.max(t.maxY, e.maxY) - Math.min(t.minY, e.minY));
|
|
886
936
|
}
|
|
887
|
-
function
|
|
888
|
-
const n = Math.max(
|
|
937
|
+
function Jt(e, t) {
|
|
938
|
+
const n = Math.max(e.minX, t.minX), o = Math.max(e.minY, t.minY), i = Math.min(e.maxX, t.maxX), s = Math.min(e.maxY, t.maxY);
|
|
889
939
|
return Math.max(0, i - n) * Math.max(0, s - o);
|
|
890
940
|
}
|
|
891
|
-
function
|
|
892
|
-
return
|
|
941
|
+
function K(e, t) {
|
|
942
|
+
return e.minX <= t.minX && e.minY <= t.minY && t.maxX <= e.maxX && t.maxY <= e.maxY;
|
|
893
943
|
}
|
|
894
|
-
function
|
|
895
|
-
return
|
|
944
|
+
function H(e, t) {
|
|
945
|
+
return t.minX <= e.maxX && t.minY <= e.maxY && t.maxX >= e.minX && t.maxY >= e.minY;
|
|
896
946
|
}
|
|
897
|
-
function
|
|
947
|
+
function V(e) {
|
|
898
948
|
return {
|
|
899
|
-
children:
|
|
949
|
+
children: e,
|
|
900
950
|
height: 1,
|
|
901
951
|
leaf: !0,
|
|
902
952
|
minX: 1 / 0,
|
|
@@ -905,26 +955,26 @@ function D(t) {
|
|
|
905
955
|
maxY: -1 / 0
|
|
906
956
|
};
|
|
907
957
|
}
|
|
908
|
-
function
|
|
909
|
-
const s = [
|
|
958
|
+
function tt(e, t, n, o, i) {
|
|
959
|
+
const s = [t, n];
|
|
910
960
|
for (; s.length; ) {
|
|
911
|
-
if (n = s.pop(),
|
|
961
|
+
if (n = s.pop(), t = s.pop(), n - t <= o)
|
|
912
962
|
continue;
|
|
913
|
-
const
|
|
914
|
-
Ht(
|
|
963
|
+
const a = t + Math.ceil((n - t) / o / 2) * o;
|
|
964
|
+
Ht(e, a, t, n, i), s.push(t, a, a, n);
|
|
915
965
|
}
|
|
916
966
|
}
|
|
917
|
-
const
|
|
967
|
+
const jt = (e, t) => {
|
|
918
968
|
const n = (s) => Math.round(s * 10) / 10, o = {
|
|
919
|
-
top: n(t.top),
|
|
920
|
-
bottom: n(t.bottom),
|
|
921
|
-
left: n(t.left),
|
|
922
|
-
right: n(t.right)
|
|
923
|
-
}, i = {
|
|
924
969
|
top: n(e.top),
|
|
925
970
|
bottom: n(e.bottom),
|
|
926
971
|
left: n(e.left),
|
|
927
972
|
right: n(e.right)
|
|
973
|
+
}, i = {
|
|
974
|
+
top: n(t.top),
|
|
975
|
+
bottom: n(t.bottom),
|
|
976
|
+
left: n(t.left),
|
|
977
|
+
right: n(t.right)
|
|
928
978
|
};
|
|
929
979
|
if (Math.abs(o.top - i.top) < 0.5 && Math.abs(o.bottom - i.bottom) < 0.5) {
|
|
930
980
|
if (Math.abs(o.left - i.right) < 0.5 || Math.abs(o.right - i.left) < 0.5)
|
|
@@ -938,305 +988,340 @@ const Jt = (t, e) => {
|
|
|
938
988
|
return "block-contains";
|
|
939
989
|
} else if (o.top >= i.top && o.bottom <= i.bottom && o.left >= i.left && o.right <= i.right)
|
|
940
990
|
return "block-is-contained";
|
|
941
|
-
},
|
|
942
|
-
const n = Math.min(
|
|
991
|
+
}, Zt = (e, t) => {
|
|
992
|
+
const n = Math.min(e.left, t.left), o = Math.max(e.right, t.right), i = Math.min(e.top, t.top), s = Math.max(e.bottom, t.bottom);
|
|
943
993
|
return new DOMRect(n, i, o - n, s - i);
|
|
944
|
-
}, Qt = (
|
|
994
|
+
}, Qt = (e) => e.reduce((t, n) => {
|
|
945
995
|
if (n.width === 0 || n.height === 0)
|
|
946
|
-
return
|
|
947
|
-
let o = [...
|
|
948
|
-
for (const s of
|
|
949
|
-
const
|
|
950
|
-
if (
|
|
951
|
-
o = o.map((r) => r === s ?
|
|
996
|
+
return t;
|
|
997
|
+
let o = [...t], i = !1;
|
|
998
|
+
for (const s of t) {
|
|
999
|
+
const a = jt(n, s);
|
|
1000
|
+
if (a === "inline-adjacent") {
|
|
1001
|
+
o = o.map((r) => r === s ? Zt(n, s) : r), i = !0;
|
|
952
1002
|
break;
|
|
953
|
-
} else if (
|
|
1003
|
+
} else if (a === "inline-contains") {
|
|
954
1004
|
o = o.map((r) => r === s ? n : r), i = !0;
|
|
955
1005
|
break;
|
|
956
|
-
} else if (
|
|
1006
|
+
} else if (a === "inline-is-contained") {
|
|
957
1007
|
i = !0;
|
|
958
1008
|
break;
|
|
959
|
-
} else if (
|
|
1009
|
+
} else if (a === "block-contains" || a === "block-is-contained") {
|
|
960
1010
|
n.width < s.width && (o = o.map((r) => r === s ? n : r)), i = !0;
|
|
961
1011
|
break;
|
|
962
1012
|
}
|
|
963
1013
|
}
|
|
964
1014
|
return i ? o : [...o, n];
|
|
965
|
-
}, []),
|
|
966
|
-
const { startContainer:
|
|
967
|
-
if (
|
|
968
|
-
return
|
|
969
|
-
if (
|
|
970
|
-
const i =
|
|
971
|
-
|
|
1015
|
+
}, []), te = (e) => {
|
|
1016
|
+
const { startContainer: t, endContainer: n } = e;
|
|
1017
|
+
if (t.nodeType === Node.TEXT_NODE && n.nodeType === Node.TEXT_NODE)
|
|
1018
|
+
return e;
|
|
1019
|
+
if (t.nodeType !== Node.TEXT_NODE) {
|
|
1020
|
+
const i = t.nextSibling || t.parentNode, s = i.nodeType === Node.TEXT_NODE ? i : Array.from(i.childNodes).filter((a) => a.nodeType === Node.TEXT_NODE).shift();
|
|
1021
|
+
e.setEnd(s, 0);
|
|
972
1022
|
}
|
|
973
1023
|
if (n.nodeType !== Node.TEXT_NODE) {
|
|
974
|
-
const i = n.previousSibling || n.parentNode, s = i.nodeType === Node.TEXT_NODE ? i : Array.from(i.childNodes).filter((
|
|
975
|
-
|
|
1024
|
+
const i = n.previousSibling || n.parentNode, s = i.nodeType === Node.TEXT_NODE ? i : Array.from(i.childNodes).filter((a) => a.nodeType === Node.TEXT_NODE).pop();
|
|
1025
|
+
e.setEnd(s, s.textContent.length);
|
|
976
1026
|
}
|
|
977
|
-
return
|
|
978
|
-
},
|
|
979
|
-
const n = new
|
|
980
|
-
const
|
|
981
|
-
return
|
|
982
|
-
const { x:
|
|
1027
|
+
return e;
|
|
1028
|
+
}, ee = (e, t) => {
|
|
1029
|
+
const n = new $t(), o = /* @__PURE__ */ new Map(), i = (l) => {
|
|
1030
|
+
const c = t.getBoundingClientRect(), m = l.selector.range instanceof Range && !l.selector.range.collapsed && l.selector.range.startContainer.nodeType === Node.TEXT_NODE && l.selector.range.endContainer.nodeType === Node.TEXT_NODE ? l : _(l, t), E = Array.from(m.selector.range.getClientRects()), v = Qt(E);
|
|
1031
|
+
return v.map((C) => {
|
|
1032
|
+
const { x: p, y: x, width: b, height: S } = C;
|
|
983
1033
|
return {
|
|
984
|
-
minX:
|
|
985
|
-
minY:
|
|
986
|
-
maxX:
|
|
987
|
-
maxY:
|
|
1034
|
+
minX: p - c.x,
|
|
1035
|
+
minY: x - c.y,
|
|
1036
|
+
maxX: p - c.x + b,
|
|
1037
|
+
maxY: x - c.y + S,
|
|
988
1038
|
annotation: {
|
|
989
|
-
id:
|
|
990
|
-
rects:
|
|
1039
|
+
id: l.annotation,
|
|
1040
|
+
rects: v
|
|
991
1041
|
}
|
|
992
1042
|
};
|
|
993
1043
|
});
|
|
994
|
-
}, s = () => [...o.values()],
|
|
1044
|
+
}, s = () => [...o.values()], a = () => {
|
|
995
1045
|
n.clear(), o.clear();
|
|
996
|
-
}, r = (
|
|
997
|
-
const
|
|
998
|
-
|
|
999
|
-
},
|
|
1000
|
-
o.get(
|
|
1001
|
-
}, h = (
|
|
1002
|
-
l
|
|
1003
|
-
},
|
|
1004
|
-
|
|
1005
|
-
const
|
|
1006
|
-
|
|
1007
|
-
const
|
|
1008
|
-
n.load(
|
|
1009
|
-
},
|
|
1010
|
-
const
|
|
1011
|
-
minX:
|
|
1012
|
-
minY:
|
|
1013
|
-
maxX:
|
|
1014
|
-
maxY:
|
|
1015
|
-
}),
|
|
1016
|
-
if (
|
|
1017
|
-
return
|
|
1018
|
-
},
|
|
1019
|
-
const
|
|
1020
|
-
if (
|
|
1046
|
+
}, r = (l) => {
|
|
1047
|
+
const c = i(l);
|
|
1048
|
+
c.forEach((u) => n.insert(u)), o.set(l.annotation, c);
|
|
1049
|
+
}, d = (l) => {
|
|
1050
|
+
o.get(l.annotation).forEach((u) => n.remove(u)), o.delete(l.annotation);
|
|
1051
|
+
}, h = (l) => {
|
|
1052
|
+
d(l), r(l);
|
|
1053
|
+
}, w = (l, c = !0) => {
|
|
1054
|
+
c && a();
|
|
1055
|
+
const u = l.map((E) => ({ target: E, rects: i(E) }));
|
|
1056
|
+
u.forEach(({ target: E, rects: v }) => o.set(E.annotation, v));
|
|
1057
|
+
const m = u.reduce((E, { rects: v }) => [...E, ...v], []);
|
|
1058
|
+
n.load(m);
|
|
1059
|
+
}, f = (l, c) => {
|
|
1060
|
+
const u = n.search({
|
|
1061
|
+
minX: l,
|
|
1062
|
+
minY: c,
|
|
1063
|
+
maxX: l,
|
|
1064
|
+
maxY: c
|
|
1065
|
+
}), m = (E) => E.annotation.rects.reduce((v, C) => v + C.width * C.height, 0);
|
|
1066
|
+
if (u.length > 0)
|
|
1067
|
+
return u.sort((E, v) => m(E) - m(v)), u[0].annotation.id;
|
|
1068
|
+
}, T = (l) => {
|
|
1069
|
+
const c = g(l);
|
|
1070
|
+
if (c.length === 0)
|
|
1021
1071
|
return;
|
|
1022
|
-
let
|
|
1023
|
-
for (let
|
|
1024
|
-
const
|
|
1025
|
-
|
|
1072
|
+
let u = c[0].left, m = c[0].top, E = c[0].right, v = c[0].bottom;
|
|
1073
|
+
for (let C = 1; C < c.length; C++) {
|
|
1074
|
+
const p = c[C];
|
|
1075
|
+
u = Math.min(u, p.left), m = Math.min(m, p.top), E = Math.max(E, p.right), v = Math.max(v, p.bottom);
|
|
1026
1076
|
}
|
|
1027
|
-
return new DOMRect(
|
|
1028
|
-
},
|
|
1029
|
-
const
|
|
1030
|
-
return
|
|
1077
|
+
return new DOMRect(u, m, E - u, v - m);
|
|
1078
|
+
}, g = (l) => {
|
|
1079
|
+
const c = o.get(l);
|
|
1080
|
+
return c ? c[0].annotation.rects : [];
|
|
1031
1081
|
};
|
|
1032
1082
|
return {
|
|
1033
1083
|
all: s,
|
|
1034
|
-
clear:
|
|
1035
|
-
getAt:
|
|
1036
|
-
getBoundsForAnnotation:
|
|
1037
|
-
getDOMRectsForAnnotation:
|
|
1038
|
-
getIntersectingRects: (
|
|
1084
|
+
clear: a,
|
|
1085
|
+
getAt: f,
|
|
1086
|
+
getBoundsForAnnotation: T,
|
|
1087
|
+
getDOMRectsForAnnotation: g,
|
|
1088
|
+
getIntersectingRects: (l, c, u, m) => n.search({ minX: l, minY: c, maxX: u, maxY: m }),
|
|
1039
1089
|
insert: r,
|
|
1040
|
-
recalculate: () =>
|
|
1041
|
-
remove:
|
|
1042
|
-
set:
|
|
1090
|
+
recalculate: () => w(e.all().map((l) => l.target), !0),
|
|
1091
|
+
remove: d,
|
|
1092
|
+
set: w,
|
|
1043
1093
|
size: () => n.all().length,
|
|
1044
1094
|
update: h
|
|
1045
1095
|
};
|
|
1046
|
-
},
|
|
1047
|
-
const { range:
|
|
1048
|
-
return
|
|
1049
|
-
},
|
|
1050
|
-
const n =
|
|
1051
|
-
const
|
|
1052
|
-
return
|
|
1053
|
-
},
|
|
1054
|
-
const
|
|
1055
|
-
if (
|
|
1056
|
-
const
|
|
1057
|
-
return console.warn("Could not revive all targets"), console.warn(
|
|
1096
|
+
}, F = (e) => {
|
|
1097
|
+
const { range: t } = e.target.selector;
|
|
1098
|
+
return t instanceof Range && !t.collapsed;
|
|
1099
|
+
}, ne = (e, t) => {
|
|
1100
|
+
const n = Rt(), o = ee(n, e), i = xt(n, t), s = At(n), a = Ut(), r = (A, l = L.LOCAL) => {
|
|
1101
|
+
const c = A.target.selector.range instanceof Range ? A : { ...A, target: _(A.target, e) }, { range: u } = c.target.selector, m = u && !u.collapsed;
|
|
1102
|
+
return m && n.addAnnotation(c, l), m;
|
|
1103
|
+
}, d = (A, l = !0, c = L.LOCAL) => {
|
|
1104
|
+
const u = A.map((E) => F(E) ? E : { ...E, target: _(E.target, e) });
|
|
1105
|
+
if (u.some((E) => E.target.selector.range.collapsed)) {
|
|
1106
|
+
const E = u.filter((v) => v.target.selector.range.collapsed);
|
|
1107
|
+
return console.warn("Could not revive all targets"), console.warn(E), n.bulkAddAnnotation(u, l, c), E;
|
|
1058
1108
|
} else
|
|
1059
|
-
return n.bulkAddAnnotation(
|
|
1060
|
-
}, h = (A,
|
|
1061
|
-
const
|
|
1062
|
-
n.updateTarget(
|
|
1063
|
-
},
|
|
1064
|
-
const
|
|
1065
|
-
n.bulkUpdateTargets(
|
|
1066
|
-
},
|
|
1067
|
-
const
|
|
1068
|
-
return
|
|
1069
|
-
},
|
|
1070
|
-
const
|
|
1071
|
-
return Array.from(new Set(
|
|
1072
|
-
},
|
|
1073
|
-
const
|
|
1074
|
-
if (
|
|
1075
|
-
if (
|
|
1076
|
-
const
|
|
1077
|
-
if (
|
|
1078
|
-
return
|
|
1109
|
+
return n.bulkAddAnnotation(u, l, c), [];
|
|
1110
|
+
}, h = (A, l = L.LOCAL) => {
|
|
1111
|
+
const c = A.selector.range instanceof Range ? A : _(A, e);
|
|
1112
|
+
n.updateTarget(c, l);
|
|
1113
|
+
}, w = (A, l = L.LOCAL) => {
|
|
1114
|
+
const c = A.map((u) => u.selector.range instanceof Range ? u : _(u, e));
|
|
1115
|
+
n.bulkUpdateTargets(c, l);
|
|
1116
|
+
}, f = (A, l) => {
|
|
1117
|
+
const c = o.getAt(A, l);
|
|
1118
|
+
return c ? n.getAnnotation(c) : void 0;
|
|
1119
|
+
}, T = (A, l, c, u) => {
|
|
1120
|
+
const m = o.getIntersectingRects(A, l, c, u);
|
|
1121
|
+
return Array.from(new Set(m.map((v) => v.annotation.id))).map((v) => n.getAnnotation(v)).filter((v) => v);
|
|
1122
|
+
}, g = (A, l, c, u = 5) => {
|
|
1123
|
+
const m = o.getDOMRectsForAnnotation(A);
|
|
1124
|
+
if (m.length > 0) {
|
|
1125
|
+
if (l && c) {
|
|
1126
|
+
const E = m.find(({ top: v, right: C, bottom: p, left: x }) => l >= x - u && l <= C + u && c >= v - u && c <= p + u);
|
|
1127
|
+
if (E)
|
|
1128
|
+
return E;
|
|
1079
1129
|
}
|
|
1080
1130
|
return o.getBoundsForAnnotation(A);
|
|
1081
1131
|
}
|
|
1082
|
-
},
|
|
1083
|
-
const
|
|
1084
|
-
return Object.entries(
|
|
1085
|
-
annotation: n.getAnnotation(
|
|
1086
|
-
rects:
|
|
1132
|
+
}, y = (A, l, c, u) => {
|
|
1133
|
+
const E = o.getIntersectingRects(A, l, c, u).reduce((v, C) => ((v[C.annotation.id] = v[C.annotation.id] || []).push(C), v), {});
|
|
1134
|
+
return Object.entries(E).map(([v, C]) => ({
|
|
1135
|
+
annotation: n.getAnnotation(v),
|
|
1136
|
+
rects: C.map(({ minX: p, minY: x, maxX: b, maxY: S }) => ({ x: p, y: x, width: b - p, height: S - x }))
|
|
1087
1137
|
}));
|
|
1088
|
-
},
|
|
1138
|
+
}, B = () => o.recalculate();
|
|
1089
1139
|
return n.observe(({ changes: A }) => {
|
|
1090
|
-
const
|
|
1091
|
-
|
|
1140
|
+
const l = (A.created || []).filter(F), c = (A.deleted || []).filter(F), u = (A.updated || []).filter((m) => F(m.newValue));
|
|
1141
|
+
l.length > 0 && o.set(l.map((m) => m.target), !1), (c == null ? void 0 : c.length) > 0 && c.forEach((m) => o.remove(m.target)), (u == null ? void 0 : u.length) > 0 && u.forEach(({ newValue: m }) => o.update(m.target));
|
|
1092
1142
|
}), {
|
|
1093
1143
|
store: {
|
|
1094
1144
|
...n,
|
|
1095
1145
|
addAnnotation: r,
|
|
1096
|
-
bulkAddAnnotation:
|
|
1097
|
-
bulkUpdateTargets:
|
|
1098
|
-
getAnnotationBounds:
|
|
1099
|
-
getAt:
|
|
1100
|
-
getIntersecting:
|
|
1101
|
-
getIntersectingRects:
|
|
1102
|
-
recalculatePositions:
|
|
1146
|
+
bulkAddAnnotation: d,
|
|
1147
|
+
bulkUpdateTargets: w,
|
|
1148
|
+
getAnnotationBounds: g,
|
|
1149
|
+
getAt: f,
|
|
1150
|
+
getIntersecting: T,
|
|
1151
|
+
getIntersectingRects: y,
|
|
1152
|
+
recalculatePositions: B,
|
|
1103
1153
|
updateTarget: h
|
|
1104
1154
|
},
|
|
1105
1155
|
selection: i,
|
|
1106
1156
|
hover: s,
|
|
1107
|
-
viewport:
|
|
1157
|
+
viewport: a
|
|
1108
1158
|
};
|
|
1109
|
-
},
|
|
1110
|
-
const n = /* @__PURE__ */ new Map(), o = (s) => Array.from(n.entries()).filter(([
|
|
1111
|
-
return
|
|
1112
|
-
o(s).forEach((
|
|
1113
|
-
}), { paint: (s,
|
|
1114
|
-
|
|
1115
|
-
const
|
|
1116
|
-
if (
|
|
1117
|
-
const { x:
|
|
1118
|
-
|
|
1119
|
-
const
|
|
1120
|
-
|
|
1159
|
+
}, oe = (e, t = {}) => {
|
|
1160
|
+
const n = /* @__PURE__ */ new Map(), o = (s) => Array.from(n.entries()).filter(([a, r]) => r.presenceKey === s.presenceKey).map(([a, r]) => a);
|
|
1161
|
+
return e.on("selectionChange", (s, a) => {
|
|
1162
|
+
o(s).forEach((d) => n.delete(d)), a && a.forEach((d) => n.set(d, s));
|
|
1163
|
+
}), { paint: (s, a, r, d, h, w) => {
|
|
1164
|
+
t.font && (d.font = t.font);
|
|
1165
|
+
const f = n.get(s.id);
|
|
1166
|
+
if (f) {
|
|
1167
|
+
const { x: T, y: g, height: y } = a[0];
|
|
1168
|
+
d.fillStyle = f.appearance.color, d.fillRect(T - 2, g - 2.5, 2, y + 5);
|
|
1169
|
+
const B = d.measureText(f.appearance.label), A = B.width + 6, l = B.actualBoundingBoxAscent + B.actualBoundingBoxDescent + 8, c = B.fontBoundingBoxAscent ? 8 : 6.5;
|
|
1170
|
+
d.fillRect(T - 2, g - 2.5 - l, A, l), d.fillStyle = "#fff", d.fillText(f.appearance.label, T + 1, g - c), r.fillStyle = f.appearance.color, r.globalAlpha = h ? 0.45 : 0.18, a.forEach(({ x: u, y: m, width: E, height: v }) => r.fillRect(u, m - 2.5, E, v + 5));
|
|
1121
1171
|
} else
|
|
1122
|
-
|
|
1172
|
+
nt.paint(s, a, r, d, h, w);
|
|
1123
1173
|
} };
|
|
1124
|
-
}, st = (
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1174
|
+
}, st = (e) => {
|
|
1175
|
+
if (e === null)
|
|
1176
|
+
return document.scrollingElement;
|
|
1177
|
+
const { overflowY: t } = window.getComputedStyle(e);
|
|
1178
|
+
return t !== "visible" && t !== "hidden" && e.scrollHeight > e.clientHeight ? e : st(e.parentElement);
|
|
1179
|
+
}, ie = (e, t) => (n) => {
|
|
1180
|
+
const o = (s) => {
|
|
1181
|
+
const a = i.getBoundingClientRect(), r = i.clientHeight, d = i.clientWidth, h = s.selector.range.getBoundingClientRect(), { width: w, height: f } = t.getAnnotationBounds(n.id), T = h.top - a.top, g = h.left - a.left, y = i.parentElement ? i.scrollTop : 0, B = i.parentElement ? i.scrollLeft : 0, A = T + y - (r - f) / 2, l = g + B - (d - w) / 2;
|
|
1182
|
+
i.scroll({ top: A, left: l, behavior: "smooth" });
|
|
1183
|
+
}, i = st(e);
|
|
1184
|
+
if (i) {
|
|
1185
|
+
const s = t.getAnnotation(n.id), { range: a } = s.target.selector;
|
|
1186
|
+
if (a && !a.collapsed)
|
|
1187
|
+
return o(s.target), !0;
|
|
1188
|
+
{
|
|
1189
|
+
const r = _(s.target, e);
|
|
1190
|
+
if (r.selector.range && !r.selector.range.collapsed)
|
|
1191
|
+
return o(r), !0;
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
return !1;
|
|
1195
|
+
};
|
|
1196
|
+
let $;
|
|
1197
|
+
const se = new Uint8Array(16);
|
|
1198
|
+
function ae() {
|
|
1199
|
+
if (!$ && ($ = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !$))
|
|
1200
|
+
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
1201
|
+
return $(se);
|
|
1202
|
+
}
|
|
1203
|
+
const O = [];
|
|
1204
|
+
for (let e = 0; e < 256; ++e)
|
|
1205
|
+
O.push((e + 256).toString(16).slice(1));
|
|
1206
|
+
function re(e, t = 0) {
|
|
1207
|
+
return O[e[t + 0]] + O[e[t + 1]] + O[e[t + 2]] + O[e[t + 3]] + "-" + O[e[t + 4]] + O[e[t + 5]] + "-" + O[e[t + 6]] + O[e[t + 7]] + "-" + O[e[t + 8]] + O[e[t + 9]] + "-" + O[e[t + 10]] + O[e[t + 11]] + O[e[t + 12]] + O[e[t + 13]] + O[e[t + 14]] + O[e[t + 15]];
|
|
1208
|
+
}
|
|
1209
|
+
const le = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), et = {
|
|
1210
|
+
randomUUID: le
|
|
1211
|
+
};
|
|
1212
|
+
function ce(e, t, n) {
|
|
1213
|
+
if (et.randomUUID && !t && !e)
|
|
1214
|
+
return et.randomUUID();
|
|
1215
|
+
e = e || {};
|
|
1216
|
+
const o = e.random || (e.rng || ae)();
|
|
1217
|
+
if (o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, t) {
|
|
1218
|
+
n = n || 0;
|
|
1219
|
+
for (let i = 0; i < 16; ++i)
|
|
1220
|
+
t[n + i] = o[i];
|
|
1221
|
+
return t;
|
|
1132
1222
|
}
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
const
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
const
|
|
1142
|
-
let
|
|
1143
|
-
|
|
1144
|
-
|
|
1223
|
+
return re(o);
|
|
1224
|
+
}
|
|
1225
|
+
const de = (e, t, n) => {
|
|
1226
|
+
const o = document.createRange(), i = n ? e.startContainer.parentElement.closest(n) : t;
|
|
1227
|
+
o.setStart(i, 0), o.setEnd(e.startContainer, e.startOffset);
|
|
1228
|
+
const s = e.toString(), a = o.toString().length, r = a + s.length;
|
|
1229
|
+
return n ? { quote: s, start: a, end: r, range: e, offsetReference: i } : { quote: s, start: a, end: r, range: e };
|
|
1230
|
+
}, ue = (e, t, n) => {
|
|
1231
|
+
const { store: o, selection: i } = t;
|
|
1232
|
+
let s, a;
|
|
1233
|
+
const r = (g) => s = g;
|
|
1234
|
+
let d = !1, h;
|
|
1235
|
+
const w = (g) => {
|
|
1236
|
+
var B;
|
|
1237
|
+
if (!d)
|
|
1145
1238
|
return;
|
|
1146
|
-
!
|
|
1147
|
-
annotation:
|
|
1239
|
+
!((B = g.target.parentElement) != null && B.closest(".not-annotatable")) ? a = {
|
|
1240
|
+
annotation: ce(),
|
|
1148
1241
|
selector: void 0,
|
|
1149
1242
|
creator: s,
|
|
1150
1243
|
created: /* @__PURE__ */ new Date()
|
|
1151
|
-
} :
|
|
1152
|
-
}
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
}, o.getAnnotation(c.annotation) ? o.updateTarget(c, L.LOCAL) : (o.addAnnotation({
|
|
1166
|
-
id: c.annotation,
|
|
1244
|
+
} : a = void 0;
|
|
1245
|
+
};
|
|
1246
|
+
e.addEventListener("selectstart", w);
|
|
1247
|
+
let f;
|
|
1248
|
+
const T = (g) => {
|
|
1249
|
+
var B;
|
|
1250
|
+
const y = document.getSelection();
|
|
1251
|
+
if (g.timeStamp - h.timeStamp < 1e3 && !a && w(h), !y.isCollapsed && d && a) {
|
|
1252
|
+
const A = Array.from(Array(y.rangeCount).keys()).map((u) => y.getRangeAt(u));
|
|
1253
|
+
te(A[0]).toString() !== ((B = a.selector) == null ? void 0 : B.quote) && (a = {
|
|
1254
|
+
...a,
|
|
1255
|
+
selector: de(A[0], e, n)
|
|
1256
|
+
}, o.getAnnotation(a.annotation) ? o.updateTarget(a, L.LOCAL) : (o.addAnnotation({
|
|
1257
|
+
id: a.annotation,
|
|
1167
1258
|
bodies: [],
|
|
1168
|
-
target:
|
|
1169
|
-
}), i.clickSelect(
|
|
1259
|
+
target: a
|
|
1260
|
+
}), i.clickSelect(a.annotation, h)));
|
|
1170
1261
|
}
|
|
1171
1262
|
};
|
|
1172
|
-
return
|
|
1173
|
-
|
|
1174
|
-
}),
|
|
1175
|
-
|
|
1176
|
-
h =
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
}
|
|
1185
|
-
|
|
1186
|
-
}
|
|
1187
|
-
|
|
1263
|
+
return document.addEventListener("selectionchange", (g) => {
|
|
1264
|
+
f && clearTimeout(f), f = setTimeout(() => T(g), 10);
|
|
1265
|
+
}), e.addEventListener("pointerdown", (g) => {
|
|
1266
|
+
const { target: y, timeStamp: B, offsetX: A, offsetY: l, type: c } = g;
|
|
1267
|
+
h = { ...g, target: y, timeStamp: B, offsetX: A, offsetY: l, type: c }, d = g.button === 0;
|
|
1268
|
+
}), document.addEventListener("pointerup", (g) => {
|
|
1269
|
+
var l;
|
|
1270
|
+
if (!!((l = g.target.parentElement) != null && l.closest(".not-annotatable")) || !d)
|
|
1271
|
+
return;
|
|
1272
|
+
const B = () => {
|
|
1273
|
+
const { x: c, y: u } = e.getBoundingClientRect(), m = o.getAt(g.clientX - c, g.clientY - u);
|
|
1274
|
+
if (m) {
|
|
1275
|
+
const { selected: E } = i;
|
|
1276
|
+
(E.length !== 1 || E[0].id !== m.id) && i.clickSelect(m.id, g);
|
|
1277
|
+
} else
|
|
1278
|
+
i.isEmpty() || i.clear();
|
|
1279
|
+
}, A = g.timeStamp - h.timeStamp;
|
|
1280
|
+
document.getSelection().isCollapsed && A < 300 ? (a = void 0, B()) : i.clickSelect(a.annotation, g);
|
|
1188
1281
|
}), {
|
|
1189
1282
|
setUser: r
|
|
1190
1283
|
};
|
|
1191
|
-
}
|
|
1192
|
-
|
|
1193
|
-
const n =
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1284
|
+
}, he = (e, t = {}) => {
|
|
1285
|
+
e.addEventListener("click", (u) => u.preventDefault());
|
|
1286
|
+
const n = ne(e, t.pointerAction), { selection: o, viewport: i } = n, s = n.store, a = Yt(s), r = Dt(
|
|
1287
|
+
n,
|
|
1288
|
+
a,
|
|
1289
|
+
t.adapter
|
|
1290
|
+
);
|
|
1291
|
+
let d = zt();
|
|
1292
|
+
const h = bt(e, n, i);
|
|
1293
|
+
t.style && h.setDrawingStyle(t.style);
|
|
1294
|
+
const w = ue(e, n, t.offsetReferenceSelector);
|
|
1295
|
+
return w.setUser(d), {
|
|
1296
|
+
...Vt(n, a, t.adapter),
|
|
1202
1297
|
destroy: () => {
|
|
1203
1298
|
throw "Not implemented yet";
|
|
1204
1299
|
},
|
|
1205
|
-
element:
|
|
1206
|
-
getUser: () =>
|
|
1207
|
-
|
|
1208
|
-
|
|
1300
|
+
element: e,
|
|
1301
|
+
getUser: () => d,
|
|
1302
|
+
setFilter: (u) => h.setFilter(u),
|
|
1303
|
+
setStyle: (u) => h.setDrawingStyle(u),
|
|
1304
|
+
setUser: (u) => {
|
|
1305
|
+
d = u, w.setUser(u);
|
|
1209
1306
|
},
|
|
1210
|
-
setSelected: (
|
|
1211
|
-
|
|
1307
|
+
setSelected: (u) => {
|
|
1308
|
+
u ? o.setSelected(u) : o.clear();
|
|
1212
1309
|
},
|
|
1213
|
-
setPresenceProvider: (
|
|
1214
|
-
|
|
1310
|
+
setPresenceProvider: (u) => {
|
|
1311
|
+
u && (h.setPainter(oe(u, t.presence)), u.on("selectionChange", () => h.redraw()));
|
|
1215
1312
|
},
|
|
1216
1313
|
on: r.on,
|
|
1217
1314
|
off: r.off,
|
|
1218
|
-
scrollIntoView:
|
|
1219
|
-
state: n
|
|
1220
|
-
get style() {
|
|
1221
|
-
return h;
|
|
1222
|
-
},
|
|
1223
|
-
set style(m) {
|
|
1224
|
-
B(m);
|
|
1225
|
-
}
|
|
1315
|
+
scrollIntoView: ie(e, s),
|
|
1316
|
+
state: n
|
|
1226
1317
|
};
|
|
1227
|
-
}
|
|
1318
|
+
};
|
|
1228
1319
|
export {
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
ot as defaultPainter,
|
|
1236
|
-
_t as parseAll,
|
|
1237
|
-
ce as parseW3CBodies,
|
|
1238
|
-
k as reviveTarget,
|
|
1239
|
-
re as serializeAll,
|
|
1240
|
-
ae as serializeW3CBodies
|
|
1320
|
+
L as Origin,
|
|
1321
|
+
bt as createHighlightLayer,
|
|
1322
|
+
he as createTextAnnotator,
|
|
1323
|
+
ne as createTextAnnotatorState,
|
|
1324
|
+
nt as defaultPainter,
|
|
1325
|
+
_ as reviveTarget
|
|
1241
1326
|
};
|
|
1242
1327
|
//# sourceMappingURL=text-annotator.es.js.map
|