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