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