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