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