@recogito/text-annotator 3.3.3 → 3.4.0
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/SelectionHandler.d.ts +10 -0
- package/dist/TextAnnotator.d.ts +15 -0
- package/dist/TextAnnotatorOptions.d.ts +34 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api/scrollIntoView.d.ts +3 -0
- package/dist/highlight/Highlight.d.ts +5 -0
- package/dist/highlight/HighlightPainter.d.ts +11 -0
- package/dist/highlight/HighlightStyle.d.ts +11 -0
- package/dist/highlight/baseRenderer.d.ts +20 -0
- package/dist/highlight/canvas/canvasRenderer.d.ts +5 -0
- package/dist/highlight/canvas/index.d.ts +1 -0
- package/dist/highlight/highlights/highlightsRenderer.d.ts +6 -0
- package/dist/highlight/highlights/index.d.ts +1 -0
- package/dist/highlight/index.d.ts +6 -0
- package/dist/highlight/span/color.d.ts +2 -0
- package/dist/highlight/span/index.d.ts +1 -0
- package/dist/highlight/span/spansRenderer.d.ts +5 -0
- package/dist/highlight/viewport.d.ts +12 -0
- package/dist/index.d.ts +11 -0
- package/dist/model/core/TextAnnotation.d.ts +15 -0
- package/dist/model/core/index.d.ts +1 -0
- package/dist/model/index.d.ts +2 -0
- package/dist/model/w3c/W3CTextAnnotation.d.ts +34 -0
- package/dist/model/w3c/W3CTextFormatAdapter.d.ts +12 -0
- package/dist/model/w3c/index.d.ts +2 -0
- package/dist/presence/PresencePainter.d.ts +5 -0
- package/dist/presence/PresencePainterOptions.d.ts +3 -0
- package/dist/presence/index.d.ts +2 -0
- package/dist/src/utils/isWhitespaceOrEmpty.d.ts +1 -2
- package/dist/state/TextAnnotationStore.d.ts +25 -0
- package/dist/state/TextAnnotatorState.d.ts +12 -0
- package/dist/state/index.d.ts +2 -0
- package/dist/state/spatialTree.d.ts +28 -0
- package/dist/text-annotator.es.js +614 -603
- package/dist/text-annotator.es.js.map +1 -1
- package/dist/text-annotator.umd.js +2 -2
- package/dist/text-annotator.umd.js.map +1 -1
- package/dist/utils/cancelSingleClickEvents.d.ts +6 -0
- package/dist/utils/cloneEvents.d.ts +11 -0
- package/dist/utils/device.d.ts +1 -0
- package/dist/utils/getHighlightClientRects.d.ts +1 -0
- package/dist/utils/getQuoteContext.d.ts +4 -0
- package/dist/utils/index.d.ts +17 -0
- package/dist/utils/isNotAnnotatable.d.ts +4 -0
- package/dist/utils/isRevived.d.ts +2 -0
- package/dist/utils/isWhitespaceOrEmpty.d.ts +3 -0
- package/dist/utils/mergeClientRects.d.ts +2 -0
- package/dist/utils/programmaticallyFocusable.d.ts +6 -0
- package/dist/utils/rangeToSelector.d.ts +2 -0
- package/dist/utils/rectsToBounds.d.ts +8 -0
- package/dist/utils/reviveAnnotation.d.ts +2 -0
- package/dist/utils/reviveSelector.d.ts +11 -0
- package/dist/utils/reviveTarget.d.ts +2 -0
- package/dist/utils/splitAnnotatableRanges.d.ts +5 -0
- package/dist/utils/trimRangeToContainer.d.ts +1 -0
- package/package.json +6 -6
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
import { UAParser as
|
|
2
|
-
import { OS as
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { Origin as
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { UAParser as ft } from "ua-parser-js";
|
|
2
|
+
import { OS as ut } from "ua-parser-js/enums";
|
|
3
|
+
import $ from "debounce";
|
|
4
|
+
import { colord as Z } from "colord";
|
|
5
|
+
import { dequal as gt } from "dequal/lite";
|
|
6
|
+
import { v4 as st } from "uuid";
|
|
7
|
+
import { serializeW3CBodies as mt, parseW3CBodies as pt, parseW3CUser as ht, createStore as bt, createSelectionState as yt, createHoverState as St, createViewportState as Ct, Origin as K, createAnonymousGuest as Et, createUndoStack as wt, createLifecycleObserver as At, createBaseAnnotator as vt } from "@annotorious/core";
|
|
8
|
+
import { Origin as Ie, UserSelectAction as Me, createBody as He } from "@annotorious/core";
|
|
9
|
+
import xt from "rbush";
|
|
10
|
+
import Y from "hotkeys-js";
|
|
11
|
+
import { poll as Tt } from "poll";
|
|
12
|
+
const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
|
|
13
|
+
var r;
|
|
14
|
+
return t.contains(e) ? !!(e instanceof HTMLElement ? e.closest(W) : (r = e.parentElement) == null ? void 0 : r.closest(W)) : !0;
|
|
15
|
+
}, Rt = (t, e) => {
|
|
15
16
|
const n = e.commonAncestorContainer;
|
|
16
|
-
return !
|
|
17
|
-
},
|
|
17
|
+
return !z(t, n);
|
|
18
|
+
}, Lt = (t) => t.addEventListener("click", (e) => {
|
|
18
19
|
// Allow clicks within not-annotatable elements
|
|
19
|
-
!e.target.closest(
|
|
20
|
-
}),
|
|
20
|
+
!e.target.closest(W) && !e.target.closest("a") && e.preventDefault();
|
|
21
|
+
}), G = (t) => ({
|
|
21
22
|
...t,
|
|
22
23
|
type: t.type,
|
|
23
24
|
x: t.x,
|
|
@@ -43,7 +44,7 @@ const ot = "not-annotatable", K = `.${ot}`, Y = (t, e) => {
|
|
|
43
44
|
pointerId: t.pointerId,
|
|
44
45
|
pointerType: t.pointerType,
|
|
45
46
|
timeStamp: t.timeStamp
|
|
46
|
-
}),
|
|
47
|
+
}), X = (t) => ({
|
|
47
48
|
...t,
|
|
48
49
|
type: t.type,
|
|
49
50
|
key: t.key,
|
|
@@ -59,327 +60,326 @@ const ot = "not-annotatable", K = `.${ot}`, Y = (t, e) => {
|
|
|
59
60
|
defaultPrevented: t.defaultPrevented,
|
|
60
61
|
detail: t.detail,
|
|
61
62
|
timeStamp: t.timeStamp
|
|
62
|
-
}),
|
|
63
|
+
}), Nt = ft(), Ot = Nt.os.is(ut.MACOS), kt = (t) => {
|
|
63
64
|
!t.hasAttribute("tabindex") && t.tabIndex < 0 && t.setAttribute("tabindex", "-1"), t.classList.add("no-focus-outline");
|
|
64
|
-
},
|
|
65
|
-
let n;
|
|
66
|
-
return ((...i) => {
|
|
67
|
-
clearTimeout(n), n = setTimeout(() => t.apply(void 0, i), e);
|
|
68
|
-
});
|
|
69
|
-
}, Ot = (t) => {
|
|
65
|
+
}, Bt = (t) => {
|
|
70
66
|
const e = [], n = document.createNodeIterator(
|
|
71
67
|
t.commonAncestorContainer,
|
|
72
68
|
NodeFilter.SHOW_TEXT
|
|
73
69
|
);
|
|
74
|
-
let
|
|
75
|
-
for (;
|
|
76
|
-
t.intersectsNode(
|
|
70
|
+
let r;
|
|
71
|
+
for (; r = n.nextNode(); )
|
|
72
|
+
t.intersectsNode(r) && e.push(r);
|
|
77
73
|
if (e.length < 2)
|
|
78
74
|
return Array.from(t.getClientRects());
|
|
79
75
|
{
|
|
80
|
-
const
|
|
81
|
-
if (
|
|
82
|
-
|
|
76
|
+
const o = e[0], s = e[e.length - 1], i = document.createRange();
|
|
77
|
+
if (i.selectNode(o), t.startContainer.nodeType === Node.TEXT_NODE)
|
|
78
|
+
i.setStart(o, t.startOffset);
|
|
83
79
|
else {
|
|
84
|
-
const
|
|
85
|
-
|
|
80
|
+
const u = t.startContainer.childNodes[t.startOffset];
|
|
81
|
+
u ? i.setStartBefore(u) : i.setStartAfter(t.startContainer);
|
|
86
82
|
}
|
|
87
83
|
const a = document.createRange();
|
|
88
|
-
if (a.selectNode(
|
|
89
|
-
a.setEnd(
|
|
84
|
+
if (a.selectNode(s), t.endContainer.nodeType === Node.TEXT_NODE)
|
|
85
|
+
a.setEnd(s, t.endOffset);
|
|
90
86
|
else {
|
|
91
|
-
const
|
|
92
|
-
|
|
87
|
+
const u = t.endContainer.childNodes[t.endOffset];
|
|
88
|
+
u ? a.setEndBefore(u) : a.setEndAfter(t.endContainer);
|
|
93
89
|
}
|
|
94
|
-
const
|
|
90
|
+
const c = (u) => {
|
|
95
91
|
const b = document.createRange();
|
|
96
|
-
return b.selectNode(
|
|
92
|
+
return b.selectNode(u), Array.from(b.getClientRects());
|
|
97
93
|
};
|
|
98
94
|
return [
|
|
99
|
-
...Array.from(
|
|
100
|
-
...e.slice(1, -1).flatMap(
|
|
95
|
+
...Array.from(i.getClientRects()),
|
|
96
|
+
...e.slice(1, -1).flatMap(c),
|
|
101
97
|
...Array.from(a.getClientRects())
|
|
102
98
|
];
|
|
103
99
|
}
|
|
104
|
-
},
|
|
100
|
+
}, It = function* (t) {
|
|
105
101
|
const e = document.createNodeIterator(
|
|
106
102
|
t.commonAncestorContainer,
|
|
107
103
|
NodeFilter.SHOW_ELEMENT,
|
|
108
|
-
(
|
|
104
|
+
(r) => r instanceof HTMLElement && r.classList.contains(rt) && !r.parentElement.closest(W) && t.intersectsNode(r) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
|
|
109
105
|
);
|
|
110
106
|
let n;
|
|
111
107
|
for (; n = e.nextNode(); )
|
|
112
108
|
n instanceof HTMLElement && (yield n);
|
|
113
|
-
},
|
|
114
|
-
if (!
|
|
109
|
+
}, Mt = (t, e) => {
|
|
110
|
+
if (!Rt(t, e)) return [];
|
|
115
111
|
const n = [];
|
|
116
|
-
let
|
|
117
|
-
for (const
|
|
118
|
-
let
|
|
119
|
-
|
|
112
|
+
let r = null;
|
|
113
|
+
for (const o of It(e)) {
|
|
114
|
+
let s;
|
|
115
|
+
r ? (s = document.createRange(), s.setStartAfter(r), s.setEndBefore(o)) : (s = e.cloneRange(), s.setEndBefore(o)), s.collapsed || n.push(s), r = o;
|
|
120
116
|
}
|
|
121
|
-
if (
|
|
122
|
-
const
|
|
123
|
-
|
|
117
|
+
if (r) {
|
|
118
|
+
const o = e.cloneRange();
|
|
119
|
+
o.setStartAfter(r), o.collapsed || n.push(o);
|
|
124
120
|
}
|
|
125
121
|
return n.length > 0 ? n : [e];
|
|
126
|
-
},
|
|
122
|
+
}, J = (t) => {
|
|
127
123
|
const e = t.cloneContents();
|
|
128
|
-
return e.querySelectorAll(
|
|
129
|
-
},
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
a.setStart(t.endContainer, t.endOffset),
|
|
134
|
-
const
|
|
124
|
+
return e.querySelectorAll(W).forEach((n) => n.remove()), e;
|
|
125
|
+
}, Ht = (t, e, n = 10, r) => {
|
|
126
|
+
const o = r ? t.startContainer.parentElement.closest(r) : e, s = document.createRange();
|
|
127
|
+
s.setStart(o, 0), s.setEnd(t.startContainer, t.startOffset);
|
|
128
|
+
const i = J(s).textContent, a = document.createRange();
|
|
129
|
+
a.setStart(t.endContainer, t.endOffset), o === document.body ? a.setEnd(o, o.childNodes.length) : a.setEndAfter(o);
|
|
130
|
+
const c = J(a).textContent;
|
|
135
131
|
return {
|
|
136
|
-
prefix:
|
|
137
|
-
suffix:
|
|
132
|
+
prefix: i.substring(i.length - n),
|
|
133
|
+
suffix: c.substring(0, n)
|
|
138
134
|
};
|
|
139
|
-
}, H = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed),
|
|
140
|
-
const
|
|
141
|
-
top:
|
|
142
|
-
bottom:
|
|
143
|
-
left:
|
|
144
|
-
right:
|
|
145
|
-
},
|
|
146
|
-
top:
|
|
147
|
-
bottom:
|
|
148
|
-
left:
|
|
149
|
-
right:
|
|
135
|
+
}, H = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), it = /^\s*$/, _t = (t) => it.test(t.toString()), Te = (t) => it.test(t.textContent || ""), Dt = (t, e, n, r) => {
|
|
136
|
+
const o = (a) => Math.round(a * 10) / 10, s = {
|
|
137
|
+
top: o(t.top),
|
|
138
|
+
bottom: o(t.bottom),
|
|
139
|
+
left: o(t.left),
|
|
140
|
+
right: o(t.right)
|
|
141
|
+
}, i = {
|
|
142
|
+
top: o(e.top),
|
|
143
|
+
bottom: o(e.bottom),
|
|
144
|
+
left: o(e.left),
|
|
145
|
+
right: o(e.right)
|
|
150
146
|
};
|
|
151
|
-
if (Math.abs(
|
|
152
|
-
if (Math.abs(
|
|
147
|
+
if (Math.abs(s.top - i.top) < r && Math.abs(s.bottom - i.bottom) < r) {
|
|
148
|
+
if (Math.abs(s.left - i.right) < n || Math.abs(s.right - i.left) < n)
|
|
153
149
|
return "inline-adjacent";
|
|
154
|
-
if (
|
|
150
|
+
if (s.left >= i.left && s.right <= i.right)
|
|
155
151
|
return "inline-is-contained";
|
|
156
|
-
if (
|
|
152
|
+
if (s.left <= i.left && s.right >= i.right)
|
|
157
153
|
return "inline-contains";
|
|
158
|
-
} else if (
|
|
159
|
-
if (
|
|
154
|
+
} else if (s.top <= i.top && s.bottom >= i.bottom) {
|
|
155
|
+
if (s.left <= i.left && s.right >= i.right)
|
|
160
156
|
return "block-contains";
|
|
161
|
-
} else if (
|
|
157
|
+
} else if (s.top >= i.top && s.bottom <= i.bottom && s.left >= i.left && s.right <= i.right)
|
|
162
158
|
return "block-is-contained";
|
|
163
159
|
}, Pt = (t, e) => {
|
|
164
|
-
const n = Math.min(t.left, e.left),
|
|
165
|
-
return new DOMRect(n,
|
|
166
|
-
}, Ut = (t, e = 0.5, n = 0.5) => t.reduce((
|
|
167
|
-
if (
|
|
168
|
-
return
|
|
169
|
-
let
|
|
170
|
-
for (const a of
|
|
171
|
-
const
|
|
172
|
-
if (
|
|
173
|
-
|
|
160
|
+
const n = Math.min(t.left, e.left), r = Math.max(t.right, e.right), o = Math.min(t.top, e.top), s = Math.max(t.bottom, e.bottom);
|
|
161
|
+
return new DOMRect(n, o, r - n, s - o);
|
|
162
|
+
}, Ut = (t, e = 0.5, n = 0.5) => t.reduce((r, o) => {
|
|
163
|
+
if (o.width === 0 || o.height === 0)
|
|
164
|
+
return r;
|
|
165
|
+
let s = [...r], i = !1;
|
|
166
|
+
for (const a of r) {
|
|
167
|
+
const c = Dt(o, a, e, n);
|
|
168
|
+
if (c === "inline-adjacent") {
|
|
169
|
+
s = s.map((u) => u === a ? Pt(o, a) : u), i = !0;
|
|
174
170
|
break;
|
|
175
|
-
} else if (
|
|
176
|
-
|
|
171
|
+
} else if (c === "inline-contains") {
|
|
172
|
+
s = s.map((u) => u === a ? o : u), i = !0;
|
|
177
173
|
break;
|
|
178
|
-
} else if (
|
|
179
|
-
|
|
174
|
+
} else if (c === "inline-is-contained") {
|
|
175
|
+
i = !0;
|
|
180
176
|
break;
|
|
181
|
-
} else if (
|
|
182
|
-
|
|
177
|
+
} else if (c === "block-contains" || c === "block-is-contained") {
|
|
178
|
+
o.width < a.width && (s = s.map((u) => u === a ? o : u)), o.width === a.width && o.height < a.width && (s = s.map((u) => u === a ? o : u)), i = !0;
|
|
183
179
|
break;
|
|
184
180
|
}
|
|
185
181
|
}
|
|
186
|
-
return
|
|
187
|
-
}, []),
|
|
182
|
+
return i ? s : [...s, o];
|
|
183
|
+
}, []), Re = (t) => ({
|
|
188
184
|
length: t.length,
|
|
189
185
|
item: (e) => t[e],
|
|
190
186
|
[Symbol.iterator]: function* () {
|
|
191
187
|
for (let e = 0; e < this.length; e++)
|
|
192
188
|
yield this.item(e);
|
|
193
189
|
}
|
|
194
|
-
}),
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
const
|
|
198
|
-
return n ? { quote:
|
|
199
|
-
},
|
|
200
|
-
|
|
201
|
-
|
|
190
|
+
}), Ft = (t, e, n) => {
|
|
191
|
+
const r = document.createRange(), o = n ? t.startContainer.parentElement.closest(n) : e;
|
|
192
|
+
r.setStart(o, 0), r.setEnd(t.startContainer, t.startOffset);
|
|
193
|
+
const s = J(r).textContent, i = t.toString(), a = s.length || 0, c = a + i.length;
|
|
194
|
+
return n ? { quote: i, start: a, end: c, range: t, offsetReference: o } : { quote: i, start: a, end: c, range: t };
|
|
195
|
+
}, Kt = (t, e) => {
|
|
196
|
+
const { left: n, top: r, right: o, bottom: s } = t;
|
|
197
|
+
return new DOMRect(n - e.left, r - e.top, o - n, s - r);
|
|
198
|
+
}, Le = (t, e) => {
|
|
199
|
+
const { left: n, top: r, right: o, bottom: s } = t;
|
|
200
|
+
return new DOMRect(n + e.left, r + e.top, o - n, s - r);
|
|
201
|
+
}, at = (t, e) => {
|
|
202
|
+
var b, g;
|
|
203
|
+
const { start: n, end: r } = t, o = t.offsetReference || e, s = document.createNodeIterator(
|
|
202
204
|
e,
|
|
203
205
|
NodeFilter.SHOW_TEXT,
|
|
204
|
-
(
|
|
205
|
-
var
|
|
206
|
-
return (
|
|
206
|
+
(p) => {
|
|
207
|
+
var l;
|
|
208
|
+
return (l = p.parentElement) != null && l.closest(W) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
|
|
207
209
|
}
|
|
208
210
|
);
|
|
209
|
-
let
|
|
211
|
+
let i = 0;
|
|
210
212
|
const a = document.createRange();
|
|
211
|
-
let
|
|
212
|
-
|
|
213
|
-
let
|
|
214
|
-
for (;
|
|
215
|
-
if (
|
|
216
|
-
const
|
|
217
|
-
if (
|
|
218
|
-
a.setStart(
|
|
213
|
+
let c = s.nextNode();
|
|
214
|
+
c === null && console.error("Could not revive annotation target. Content missing.");
|
|
215
|
+
let u = !o;
|
|
216
|
+
for (; c !== null; ) {
|
|
217
|
+
if (u || (u = typeof (o == null ? void 0 : o.contains) == "function" ? o.contains(c) : !1), u) {
|
|
218
|
+
const p = ((b = c.textContent) == null ? void 0 : b.length) || 0;
|
|
219
|
+
if (i + p > n) {
|
|
220
|
+
a.setStart(c, n - i);
|
|
219
221
|
break;
|
|
220
222
|
}
|
|
221
|
-
|
|
223
|
+
i += p;
|
|
222
224
|
}
|
|
223
|
-
|
|
225
|
+
c = s.nextNode();
|
|
224
226
|
}
|
|
225
|
-
for (;
|
|
226
|
-
const
|
|
227
|
-
if (
|
|
228
|
-
a.setEnd(
|
|
227
|
+
for (; c !== null; ) {
|
|
228
|
+
const p = ((g = c.textContent) == null ? void 0 : g.length) || 0;
|
|
229
|
+
if (i + p >= r) {
|
|
230
|
+
a.setEnd(c, r - i);
|
|
229
231
|
break;
|
|
230
232
|
}
|
|
231
|
-
|
|
233
|
+
i += p, c = s.nextNode();
|
|
232
234
|
}
|
|
233
235
|
return {
|
|
234
236
|
...t,
|
|
235
237
|
range: a
|
|
236
238
|
};
|
|
237
|
-
},
|
|
239
|
+
}, q = (t, e) => H(t.selector) ? t : {
|
|
238
240
|
...t,
|
|
239
|
-
selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n :
|
|
240
|
-
},
|
|
241
|
+
selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : at(n, e))
|
|
242
|
+
}, Q = (t, e) => H(t.target.selector) ? t : { ...t, target: q(t.target, e) }, $t = (t, e) => {
|
|
241
243
|
const n = t.cloneRange();
|
|
242
244
|
return e.contains(n.startContainer) || n.setStart(e, 0), e.contains(n.endContainer) || n.setEnd(e, e.childNodes.length), n;
|
|
243
|
-
},
|
|
244
|
-
if (t
|
|
245
|
+
}, ct = (t) => {
|
|
246
|
+
if (!t)
|
|
245
247
|
return document.scrollingElement;
|
|
246
248
|
const { overflowY: e } = window.getComputedStyle(t);
|
|
247
|
-
return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t :
|
|
248
|
-
},
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
if (!
|
|
254
|
-
return console.warn(`The scroll parent is missing for the annotation: ${
|
|
255
|
-
const
|
|
256
|
-
if (!
|
|
257
|
-
return console.warn(`The annotation is missing in the store: ${
|
|
258
|
-
const { range: a } =
|
|
249
|
+
return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : ct(t.parentElement);
|
|
250
|
+
}, et = (t, e, n) => {
|
|
251
|
+
const r = n.getBoundingClientRect(), o = n.clientHeight, s = n.clientWidth, i = e.selector[0].range.getBoundingClientRect(), { width: a, height: c } = t.getAnnotationBounds(e.annotation), u = i.top - r.top, b = i.left - r.left, g = n.parentElement ? n.scrollTop : 0, p = n.parentElement ? n.scrollLeft : 0, l = u + g - (o - c) / 2, T = b + p - (s - a) / 2;
|
|
252
|
+
n.scroll({ top: l, left: T, behavior: "smooth" });
|
|
253
|
+
}, Wt = (t, e) => (n, r) => {
|
|
254
|
+
const o = typeof n == "string" ? n : n.id, s = r ? typeof r == "string" ? document.getElementById(r) : r : ct(t);
|
|
255
|
+
if (!s)
|
|
256
|
+
return console.warn(`The scroll parent is missing for the annotation: ${o}`, { container: t }), !1;
|
|
257
|
+
const i = e.getAnnotation(o);
|
|
258
|
+
if (!i)
|
|
259
|
+
return console.warn(`The annotation is missing in the store: ${o}`), !1;
|
|
260
|
+
const { range: a } = i.target.selector[0];
|
|
259
261
|
if (a && !a.collapsed)
|
|
260
|
-
return
|
|
261
|
-
const
|
|
262
|
-
return
|
|
263
|
-
},
|
|
262
|
+
return et(e, i.target, s), !0;
|
|
263
|
+
const c = q(i.target, t), { range: u } = c.selector[0];
|
|
264
|
+
return u && !u.collapsed ? (et(e, c, s), !0) : !1;
|
|
265
|
+
}, _ = {
|
|
264
266
|
fill: "rgb(0, 128, 255)",
|
|
265
267
|
fillOpacity: 0.18
|
|
266
|
-
},
|
|
268
|
+
}, j = {
|
|
267
269
|
fill: "rgb(0, 128, 255)",
|
|
268
270
|
fillOpacity: 0.45
|
|
269
|
-
},
|
|
270
|
-
var
|
|
271
|
-
const
|
|
272
|
-
return
|
|
273
|
-
},
|
|
274
|
-
const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth:
|
|
275
|
-
return { top: e, left: n, minX:
|
|
276
|
-
},
|
|
271
|
+
}, Vt = (t, e, n, r, o) => {
|
|
272
|
+
var i, a;
|
|
273
|
+
const s = n ? typeof n == "function" ? n(t.annotation, t.state, o) || ((i = t.state) != null && i.selected ? j : _) : n : (a = t.state) != null && a.selected ? j : _;
|
|
274
|
+
return r && r.paint(t, e) || s;
|
|
275
|
+
}, Yt = (t) => {
|
|
276
|
+
const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: r, innerHeight: o } = window, s = -n, i = -e, a = r - n, c = o - e;
|
|
277
|
+
return { top: e, left: n, minX: s, minY: i, maxX: a, maxY: c };
|
|
278
|
+
}, Xt = (t) => {
|
|
277
279
|
let e = /* @__PURE__ */ new Set();
|
|
278
|
-
return (
|
|
279
|
-
const
|
|
280
|
-
(e.size !==
|
|
280
|
+
return (r) => {
|
|
281
|
+
const o = r.map((s) => s.id);
|
|
282
|
+
(e.size !== o.length || o.some((s) => !e.has(s))) && t.set(o), e = new Set(o);
|
|
281
283
|
};
|
|
282
|
-
},
|
|
283
|
-
const { store:
|
|
284
|
-
let a,
|
|
285
|
-
const b =
|
|
286
|
-
const { x:
|
|
287
|
-
|
|
284
|
+
}, tt = (t, e, n, r) => {
|
|
285
|
+
const { store: o, selection: s, hover: i } = e;
|
|
286
|
+
let a, c, u;
|
|
287
|
+
const b = Xt(n), g = $((E) => {
|
|
288
|
+
const { x: L, y: k } = t.getBoundingClientRect(), D = o.getAt(E.clientX - L, E.clientY - k, !1, c);
|
|
289
|
+
D ? i.current !== D.id && (t.classList.add("hovered"), i.set(D.id)) : i.current && (t.classList.remove("hovered"), i.set(null));
|
|
288
290
|
}, 10);
|
|
289
|
-
t.addEventListener("pointermove",
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
const
|
|
293
|
-
const
|
|
291
|
+
t.addEventListener("pointermove", g);
|
|
292
|
+
const p = $((E = !1) => requestAnimationFrame(() => {
|
|
293
|
+
u && u.clear();
|
|
294
|
+
const L = Yt(t), { minX: k, minY: D, maxX: S, maxY: v } = L, B = c ? o.getIntersecting(k, D, S, v).filter(({ annotation: N }) => c(N)) : o.getIntersecting(k, D, S, v), P = s.selected.map(({ id: N }) => N), I = B.map(({ annotation: N, rects: M }) => {
|
|
295
|
+
const O = P.includes(N.id), U = N.id === i.current;
|
|
294
296
|
return {
|
|
295
|
-
annotation:
|
|
296
|
-
rects:
|
|
297
|
-
state: { selected:
|
|
297
|
+
annotation: N,
|
|
298
|
+
rects: M,
|
|
299
|
+
state: { selected: O, hovered: U }
|
|
298
300
|
};
|
|
299
301
|
});
|
|
300
|
-
|
|
301
|
-
}), 10),
|
|
302
|
-
|
|
303
|
-
},
|
|
304
|
-
a =
|
|
305
|
-
},
|
|
306
|
-
|
|
307
|
-
},
|
|
308
|
-
|
|
309
|
-
const x =
|
|
310
|
-
document.addEventListener("scroll",
|
|
311
|
-
const m =
|
|
312
|
-
|
|
313
|
-
});
|
|
302
|
+
r.redraw(I, L, a, u, E), setTimeout(() => b(B.map(({ annotation: N }) => N)), 1);
|
|
303
|
+
}), 10), l = (E) => {
|
|
304
|
+
u = E, p();
|
|
305
|
+
}, T = (E) => {
|
|
306
|
+
a = E, p();
|
|
307
|
+
}, A = (E) => {
|
|
308
|
+
c = E, p(!1);
|
|
309
|
+
}, R = () => p();
|
|
310
|
+
o.observe(R);
|
|
311
|
+
const x = s.subscribe(() => p()), C = i.subscribe(() => p()), d = () => p(!0);
|
|
312
|
+
document.addEventListener("scroll", d, { capture: !0, passive: !0 });
|
|
313
|
+
const m = $(() => {
|
|
314
|
+
o.recalculatePositions(), u == null || u.reset(), p();
|
|
315
|
+
}, 10);
|
|
314
316
|
window.addEventListener("resize", m);
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
const
|
|
318
|
-
|
|
317
|
+
const f = new ResizeObserver(m);
|
|
318
|
+
f.observe(t);
|
|
319
|
+
const y = { attributes: !0, childList: !0, subtree: !0 }, h = new MutationObserver($((E) => {
|
|
320
|
+
E.every((k) => k.target === t || t.contains(k.target)) || p(!0);
|
|
319
321
|
}, 150));
|
|
320
|
-
return h.observe(document.body,
|
|
322
|
+
return h.observe(document.body, y), {
|
|
321
323
|
destroy: () => {
|
|
322
|
-
t.removeEventListener("pointermove",
|
|
324
|
+
t.removeEventListener("pointermove", g), r.destroy(), o.unobserve(R), x(), C(), document.removeEventListener("scroll", d), m.clear(), window.removeEventListener("resize", m), f.disconnect(), h.disconnect();
|
|
323
325
|
},
|
|
324
|
-
redraw:
|
|
325
|
-
setStyle:
|
|
326
|
-
setFilter:
|
|
327
|
-
setPainter:
|
|
328
|
-
setVisible:
|
|
326
|
+
redraw: p,
|
|
327
|
+
setStyle: T,
|
|
328
|
+
setFilter: A,
|
|
329
|
+
setPainter: l,
|
|
330
|
+
setVisible: r.setVisible
|
|
329
331
|
};
|
|
330
|
-
},
|
|
332
|
+
}, zt = () => {
|
|
331
333
|
const t = document.createElement("canvas");
|
|
332
334
|
return t.width = window.innerWidth, t.height = window.innerHeight, t.className = "r6o-canvas-highlight-layer bg", t;
|
|
333
|
-
},
|
|
335
|
+
}, qt = (t, e) => {
|
|
334
336
|
t.width = window.innerWidth, t.height = window.innerHeight;
|
|
335
|
-
},
|
|
337
|
+
}, jt = (t) => {
|
|
336
338
|
t.classList.add("r6o-annotatable");
|
|
337
|
-
const e =
|
|
339
|
+
const e = zt(), n = e.getContext("2d");
|
|
338
340
|
document.body.appendChild(e);
|
|
339
|
-
const
|
|
340
|
-
const { width:
|
|
341
|
-
n.clearRect(-0.5, -0.5,
|
|
342
|
-
const { top:
|
|
343
|
-
[...a].sort((
|
|
344
|
-
const { annotation: { target: { created:
|
|
345
|
-
return
|
|
346
|
-
}).forEach((
|
|
341
|
+
const r = (a, c, u, b) => requestAnimationFrame(() => {
|
|
342
|
+
const { width: g, height: p } = e;
|
|
343
|
+
n.clearRect(-0.5, -0.5, g + 1, p + 1), b && b.clear();
|
|
344
|
+
const { top: l, left: T } = c;
|
|
345
|
+
[...a].sort((R, x) => {
|
|
346
|
+
const { annotation: { target: { created: C } } } = R, { annotation: { target: { created: d } } } = x;
|
|
347
|
+
return C.getTime() - d.getTime();
|
|
348
|
+
}).forEach((R) => {
|
|
347
349
|
var m;
|
|
348
|
-
const x =
|
|
349
|
-
x:
|
|
350
|
-
y:
|
|
350
|
+
const x = u ? typeof u == "function" ? u(R.annotation, R.state) : u : (m = R.state) != null && m.selected ? j : _, C = b && b.paint(R, c) || x, d = R.rects.map(({ x: f, y, width: h, height: w }) => ({
|
|
351
|
+
x: f + T,
|
|
352
|
+
y: y + l,
|
|
351
353
|
width: h,
|
|
352
|
-
height:
|
|
354
|
+
height: w
|
|
353
355
|
}));
|
|
354
|
-
if (n.fillStyle =
|
|
355
|
-
({ x:
|
|
356
|
-
),
|
|
357
|
-
n.globalAlpha = 1, n.strokeStyle =
|
|
358
|
-
const
|
|
359
|
-
|
|
360
|
-
n.beginPath(), n.moveTo(
|
|
356
|
+
if (n.fillStyle = C.fill, n.globalAlpha = C.fillOpacity || 1, d.forEach(
|
|
357
|
+
({ x: f, y, width: h, height: w }) => n.fillRect(f, y, h, w)
|
|
358
|
+
), C.underlineColor) {
|
|
359
|
+
n.globalAlpha = 1, n.strokeStyle = C.underlineColor, n.lineWidth = C.underlineThickness ?? 1;
|
|
360
|
+
const f = C.underlineOffset ?? 0;
|
|
361
|
+
d.forEach(({ x: y, y: h, width: w, height: E }) => {
|
|
362
|
+
n.beginPath(), n.moveTo(y, h + E + f), n.lineTo(y + w, h + E + f), n.stroke();
|
|
361
363
|
});
|
|
362
364
|
}
|
|
363
365
|
});
|
|
364
|
-
}),
|
|
365
|
-
|
|
366
|
-
});
|
|
367
|
-
return window.addEventListener("resize", s), {
|
|
366
|
+
}), o = $(() => qt(e), 10);
|
|
367
|
+
return window.addEventListener("resize", o), {
|
|
368
368
|
destroy: () => {
|
|
369
|
-
e.remove(), window.removeEventListener("resize",
|
|
369
|
+
e.remove(), o.clear(), window.removeEventListener("resize", o);
|
|
370
370
|
},
|
|
371
371
|
setVisible: (a) => {
|
|
372
372
|
console.log("setVisible not implemented on Canvas renderer");
|
|
373
373
|
},
|
|
374
|
-
redraw:
|
|
374
|
+
redraw: r
|
|
375
375
|
};
|
|
376
|
-
},
|
|
377
|
-
`background-color:${
|
|
376
|
+
}, Gt = (t, e, n) => tt(t, e, n, jt(t)), Qt = (t) => [
|
|
377
|
+
`background-color:${Z((t == null ? void 0 : t.fill) || _.fill).alpha((t == null ? void 0 : t.fillOpacity) === void 0 ? _.fillOpacity : t.fillOpacity).toHex()}`,
|
|
378
378
|
t != null && t.underlineThickness ? "text-decoration:underline" : void 0,
|
|
379
379
|
t != null && t.underlineColor ? `text-decoration-color:${t.underlineColor}` : void 0,
|
|
380
380
|
t != null && t.underlineOffset ? `text-underline-offset:${t.underlineOffset}px` : void 0,
|
|
381
381
|
t != null && t.underlineThickness ? `text-decoration-thickness:${t.underlineThickness}px` : void 0
|
|
382
|
-
].filter(Boolean).join(";"),
|
|
382
|
+
].filter(Boolean).join(";"), Zt = () => {
|
|
383
383
|
const t = document.createElement("style");
|
|
384
384
|
document.getElementsByTagName("head")[0].appendChild(t);
|
|
385
385
|
let e = /* @__PURE__ */ new Set();
|
|
@@ -387,29 +387,29 @@ const ot = "not-annotatable", K = `.${ot}`, Y = (t, e) => {
|
|
|
387
387
|
destroy: () => {
|
|
388
388
|
CSS.highlights.clear(), t.remove();
|
|
389
389
|
},
|
|
390
|
-
setVisible: (
|
|
390
|
+
setVisible: (s) => {
|
|
391
391
|
console.log("setVisible not implemented on CSS Custom Highlights renderer");
|
|
392
392
|
},
|
|
393
|
-
redraw: (
|
|
394
|
-
|
|
395
|
-
const
|
|
396
|
-
Array.from(e).filter((
|
|
397
|
-
const b =
|
|
398
|
-
var
|
|
399
|
-
const
|
|
400
|
-
return `::highlight(_${
|
|
393
|
+
redraw: (s, i, a, c) => {
|
|
394
|
+
c && c.clear();
|
|
395
|
+
const u = new Set(s.map((g) => g.annotation.id));
|
|
396
|
+
Array.from(e).filter((g) => !u.has(g));
|
|
397
|
+
const b = s.map((g) => {
|
|
398
|
+
var T;
|
|
399
|
+
const p = a ? typeof a == "function" ? a(g.annotation, g.state) : a : (T = g.state) != null && T.selected ? j : _, l = c && c.paint(g, i) || p;
|
|
400
|
+
return `::highlight(_${g.annotation.id}) { ${Qt(l)} }`;
|
|
401
401
|
});
|
|
402
402
|
t.innerHTML = b.join(`
|
|
403
|
-
`), CSS.highlights.clear(),
|
|
404
|
-
const
|
|
405
|
-
CSS.highlights.set(`_${
|
|
406
|
-
}), e =
|
|
403
|
+
`), CSS.highlights.clear(), s.forEach(({ annotation: g }) => {
|
|
404
|
+
const p = g.target.selector.map((T) => T.range), l = new Highlight(...p);
|
|
405
|
+
CSS.highlights.set(`_${g.id}`, l);
|
|
406
|
+
}), e = u;
|
|
407
407
|
}
|
|
408
408
|
};
|
|
409
|
-
},
|
|
410
|
-
const n = (
|
|
411
|
-
return
|
|
412
|
-
},
|
|
409
|
+
}, Jt = (t, e, n) => tt(t, e, n, Zt()), te = (t) => (t == null ? void 0 : t.fillOpacity) !== void 0 ? Z((t == null ? void 0 : t.fill) || _.fill).alpha(t.fillOpacity).toHex() : t != null && t.fill ? t.fill : Z(_.fill).alpha(_.fillOpacity).toHex(), ee = (t, e) => {
|
|
410
|
+
const n = (s, i) => s.x <= i.x + i.width && s.x + s.width >= i.x && s.y <= i.y + i.height && s.y + s.height >= i.y, r = (s) => s.rects.reduce((i, a) => i + a.width, 0), o = e.filter(({ rects: s }) => s.some((i) => n(t, i)));
|
|
411
|
+
return o.sort((s, i) => r(i) - r(s)), o.findIndex((s) => s.rects.includes(t));
|
|
412
|
+
}, ne = (t) => {
|
|
413
413
|
t.classList.add("r6o-annotatable");
|
|
414
414
|
const e = document.createElement("div");
|
|
415
415
|
e.className = "r6o-span-highlight-layer", t.insertBefore(e, t.firstChild);
|
|
@@ -418,293 +418,290 @@ const ot = "not-annotatable", K = `.${ot}`, Y = (t, e) => {
|
|
|
418
418
|
destroy: () => {
|
|
419
419
|
e.remove();
|
|
420
420
|
},
|
|
421
|
-
redraw: (
|
|
422
|
-
const
|
|
423
|
-
if (!
|
|
424
|
-
|
|
425
|
-
const { annotation: { target: { created:
|
|
426
|
-
return
|
|
427
|
-
}).forEach((
|
|
428
|
-
|
|
429
|
-
const
|
|
430
|
-
if (
|
|
431
|
-
const
|
|
432
|
-
|
|
421
|
+
redraw: (i, a, c, u, b) => {
|
|
422
|
+
const p = !(gt(n, i) && b);
|
|
423
|
+
if (!u && !p) return;
|
|
424
|
+
p && (e.innerHTML = ""), [...i].sort((T, A) => {
|
|
425
|
+
const { annotation: { target: { created: R } } } = T, { annotation: { target: { created: x } } } = A;
|
|
426
|
+
return R && x ? R.getTime() - x.getTime() : 0;
|
|
427
|
+
}).forEach((T) => {
|
|
428
|
+
T.rects.map((A) => {
|
|
429
|
+
const R = ee(A, i), x = Vt(T, a, c, u, R);
|
|
430
|
+
if (p) {
|
|
431
|
+
const C = document.createElement("span");
|
|
432
|
+
C.className = "r6o-annotation", C.dataset.annotation = T.annotation.id, C.style.left = `${A.x}px`, C.style.top = `${A.y}px`, C.style.width = `${A.width}px`, C.style.height = `${A.height}px`, C.style.backgroundColor = te(x), x.underlineStyle && (C.style.borderStyle = x.underlineStyle), x.underlineColor && (C.style.borderColor = x.underlineColor), x.underlineThickness && (C.style.borderBottomWidth = `${x.underlineThickness}px`), x.underlineOffset && (C.style.paddingBottom = `${x.underlineOffset}px`), e.appendChild(C);
|
|
433
433
|
}
|
|
434
434
|
});
|
|
435
|
-
}), n =
|
|
435
|
+
}), n = i;
|
|
436
436
|
},
|
|
437
|
-
setVisible: (
|
|
438
|
-
|
|
437
|
+
setVisible: (i) => {
|
|
438
|
+
i ? e.classList.remove("hidden") : e.classList.add("hidden");
|
|
439
439
|
}
|
|
440
440
|
};
|
|
441
|
-
},
|
|
442
|
-
parse: (n) =>
|
|
443
|
-
serialize: (n) =>
|
|
444
|
-
}),
|
|
441
|
+
}, oe = (t, e, n) => tt(t, e, n, ne(t)), Ne = (t, e) => ({
|
|
442
|
+
parse: (n) => ie(n),
|
|
443
|
+
serialize: (n) => ae(n, t, e)
|
|
444
|
+
}), se = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, re = (t) => {
|
|
445
445
|
const {
|
|
446
446
|
id: e,
|
|
447
447
|
creator: n,
|
|
448
|
-
created:
|
|
449
|
-
modified:
|
|
450
|
-
target:
|
|
451
|
-
} = t,
|
|
452
|
-
if (
|
|
448
|
+
created: r,
|
|
449
|
+
modified: o,
|
|
450
|
+
target: s
|
|
451
|
+
} = t, i = Array.isArray(s) ? s : [s];
|
|
452
|
+
if (i.length === 0)
|
|
453
453
|
return { error: Error(`No targets found for annotation: ${t.id}`) };
|
|
454
454
|
const a = {
|
|
455
|
-
creator:
|
|
456
|
-
created:
|
|
457
|
-
updated:
|
|
455
|
+
creator: ht(n),
|
|
456
|
+
created: r ? new Date(r) : void 0,
|
|
457
|
+
updated: o ? new Date(o) : void 0,
|
|
458
458
|
annotation: e,
|
|
459
459
|
selector: [],
|
|
460
460
|
// @ts-expect-error: `styleClass` is not part of the core `TextAnnotationTarget` type
|
|
461
|
-
styleClass: "styleClass" in
|
|
461
|
+
styleClass: "styleClass" in i[0] ? i[0].styleClass : void 0
|
|
462
462
|
};
|
|
463
|
-
for (const
|
|
464
|
-
const b = (Array.isArray(
|
|
465
|
-
switch (
|
|
463
|
+
for (const c of i) {
|
|
464
|
+
const b = (Array.isArray(c.selector) ? c.selector : [c.selector]).reduce((g, p) => {
|
|
465
|
+
switch (p.type) {
|
|
466
466
|
case "TextQuoteSelector":
|
|
467
|
-
|
|
467
|
+
g.quote = p.exact;
|
|
468
468
|
break;
|
|
469
469
|
case "TextPositionSelector":
|
|
470
|
-
|
|
470
|
+
g.start = p.start, g.end = p.end;
|
|
471
471
|
break;
|
|
472
472
|
}
|
|
473
|
-
return
|
|
473
|
+
return g;
|
|
474
474
|
}, {});
|
|
475
|
-
if (
|
|
475
|
+
if (se(b))
|
|
476
476
|
a.selector.push(
|
|
477
477
|
{
|
|
478
478
|
...b,
|
|
479
|
-
id:
|
|
479
|
+
id: c.id,
|
|
480
480
|
// @ts-expect-error: `scope` is not part of the core `TextSelector` type
|
|
481
|
-
scope:
|
|
481
|
+
scope: c.scope
|
|
482
482
|
}
|
|
483
483
|
);
|
|
484
484
|
else {
|
|
485
|
-
const
|
|
485
|
+
const g = [
|
|
486
486
|
b.start ? void 0 : "TextPositionSelector",
|
|
487
487
|
b.quote ? void 0 : "TextQuoteSelector"
|
|
488
488
|
].filter(Boolean);
|
|
489
|
-
return { error: Error(`Missing selector types: ${
|
|
489
|
+
return { error: Error(`Missing selector types: ${g.join(" and ")} for annotation: ${t.id}`) };
|
|
490
490
|
}
|
|
491
491
|
}
|
|
492
492
|
return { parsed: a };
|
|
493
|
-
},
|
|
494
|
-
const e = t.id ||
|
|
493
|
+
}, ie = (t) => {
|
|
494
|
+
const e = t.id || st(), {
|
|
495
495
|
creator: n,
|
|
496
|
-
created:
|
|
497
|
-
modified:
|
|
498
|
-
body:
|
|
499
|
-
...
|
|
500
|
-
} = t, a =
|
|
501
|
-
return "error" in
|
|
496
|
+
created: r,
|
|
497
|
+
modified: o,
|
|
498
|
+
body: s,
|
|
499
|
+
...i
|
|
500
|
+
} = t, a = pt(s, e), c = re(t);
|
|
501
|
+
return "error" in c ? { error: c.error } : {
|
|
502
502
|
parsed: {
|
|
503
|
-
...
|
|
503
|
+
...i,
|
|
504
504
|
id: e,
|
|
505
505
|
bodies: a,
|
|
506
|
-
target:
|
|
506
|
+
target: c.parsed
|
|
507
507
|
}
|
|
508
508
|
};
|
|
509
|
-
},
|
|
510
|
-
const { bodies:
|
|
511
|
-
selector:
|
|
509
|
+
}, ae = (t, e, n) => {
|
|
510
|
+
const { bodies: r, target: o, ...s } = t, {
|
|
511
|
+
selector: i,
|
|
512
512
|
creator: a,
|
|
513
|
-
created:
|
|
514
|
-
updated:
|
|
513
|
+
created: c,
|
|
514
|
+
updated: u,
|
|
515
515
|
...b
|
|
516
|
-
} =
|
|
517
|
-
const { id:
|
|
516
|
+
} = o, g = i.map((p) => {
|
|
517
|
+
const { id: l, quote: T, start: A, end: R, range: x } = p, C = {
|
|
518
518
|
type: "TextQuoteSelector",
|
|
519
|
-
exact:
|
|
519
|
+
exact: T
|
|
520
520
|
};
|
|
521
521
|
if (n) {
|
|
522
|
-
const { prefix: m, suffix:
|
|
523
|
-
|
|
522
|
+
const { prefix: m, suffix: f } = Ht(x, n);
|
|
523
|
+
C.prefix = m, C.suffix = f;
|
|
524
524
|
}
|
|
525
|
-
const
|
|
525
|
+
const d = {
|
|
526
526
|
type: "TextPositionSelector",
|
|
527
|
-
start:
|
|
528
|
-
end:
|
|
527
|
+
start: A,
|
|
528
|
+
end: R
|
|
529
529
|
};
|
|
530
530
|
return {
|
|
531
531
|
...b,
|
|
532
|
-
id:
|
|
532
|
+
id: l,
|
|
533
533
|
// @ts-expect-error: `scope` is not part of the core `TextSelector` type
|
|
534
|
-
scope: "scope" in
|
|
534
|
+
scope: "scope" in p ? p.scope : void 0,
|
|
535
535
|
source: e,
|
|
536
|
-
selector: [
|
|
536
|
+
selector: [C, d]
|
|
537
537
|
};
|
|
538
538
|
});
|
|
539
539
|
return {
|
|
540
|
-
...
|
|
540
|
+
...s,
|
|
541
541
|
"@context": "http://www.w3.org/ns/anno.jsonld",
|
|
542
542
|
id: t.id,
|
|
543
543
|
type: "Annotation",
|
|
544
|
-
body:
|
|
544
|
+
body: mt(t.bodies),
|
|
545
545
|
creator: a,
|
|
546
|
-
created:
|
|
547
|
-
modified:
|
|
548
|
-
target:
|
|
546
|
+
created: c == null ? void 0 : c.toISOString(),
|
|
547
|
+
modified: u == null ? void 0 : u.toISOString(),
|
|
548
|
+
target: g
|
|
549
549
|
};
|
|
550
|
-
},
|
|
551
|
-
const
|
|
552
|
-
const
|
|
553
|
-
const
|
|
554
|
-
return
|
|
555
|
-
}),
|
|
556
|
-
return
|
|
557
|
-
const { x:
|
|
550
|
+
}, ce = (t, e, n, r) => {
|
|
551
|
+
const o = new xt(), s = /* @__PURE__ */ new Map(), i = (d, m) => {
|
|
552
|
+
const f = d.selector.flatMap((h) => {
|
|
553
|
+
const w = H([h]) ? h.range : at(h, e).range;
|
|
554
|
+
return Bt(w);
|
|
555
|
+
}), y = Ut(f, n, r).map((h) => Kt(h, m));
|
|
556
|
+
return y.map((h) => {
|
|
557
|
+
const { x: w, y: E, width: L, height: k } = h;
|
|
558
558
|
return {
|
|
559
|
-
minX:
|
|
560
|
-
minY:
|
|
561
|
-
maxX:
|
|
562
|
-
maxY:
|
|
559
|
+
minX: w,
|
|
560
|
+
minY: E,
|
|
561
|
+
maxX: w + L,
|
|
562
|
+
maxY: E + k,
|
|
563
563
|
annotation: {
|
|
564
|
-
id:
|
|
565
|
-
rects:
|
|
564
|
+
id: d.annotation,
|
|
565
|
+
rects: y
|
|
566
566
|
}
|
|
567
567
|
};
|
|
568
568
|
});
|
|
569
|
-
}, a = () => [...
|
|
570
|
-
|
|
571
|
-
},
|
|
572
|
-
const m =
|
|
573
|
-
m.length !== 0 && (m.forEach((
|
|
574
|
-
}, b = (
|
|
575
|
-
const m =
|
|
576
|
-
m && (m.forEach((
|
|
577
|
-
},
|
|
578
|
-
b(
|
|
579
|
-
},
|
|
580
|
-
m &&
|
|
581
|
-
const
|
|
582
|
-
|
|
583
|
-
|
|
569
|
+
}, a = () => [...s.values()], c = () => {
|
|
570
|
+
o.clear(), s.clear();
|
|
571
|
+
}, u = (d) => {
|
|
572
|
+
const m = i(d, e.getBoundingClientRect());
|
|
573
|
+
m.length !== 0 && (m.forEach((f) => o.insert(f)), s.set(d.annotation, m));
|
|
574
|
+
}, b = (d) => {
|
|
575
|
+
const m = s.get(d.annotation);
|
|
576
|
+
m && (m.forEach((f) => o.remove(f)), s.delete(d.annotation));
|
|
577
|
+
}, g = (d) => {
|
|
578
|
+
b(d), u(d);
|
|
579
|
+
}, p = (d, m = !0) => {
|
|
580
|
+
m && c();
|
|
581
|
+
const f = e.getBoundingClientRect(), y = d.map((w) => ({ target: w, rects: i(w, f) }));
|
|
582
|
+
y.forEach(({ target: w, rects: E }) => {
|
|
583
|
+
E.length > 0 && s.set(w.annotation, E);
|
|
584
584
|
});
|
|
585
|
-
const h =
|
|
586
|
-
|
|
587
|
-
},
|
|
588
|
-
const
|
|
589
|
-
minX:
|
|
585
|
+
const h = y.flatMap(({ rects: w }) => w);
|
|
586
|
+
o.load(h);
|
|
587
|
+
}, l = (d, m, f = !1) => {
|
|
588
|
+
const y = o.search({
|
|
589
|
+
minX: d,
|
|
590
590
|
minY: m,
|
|
591
|
-
maxX:
|
|
591
|
+
maxX: d,
|
|
592
592
|
maxY: m
|
|
593
|
-
}), h = (
|
|
594
|
-
return
|
|
595
|
-
},
|
|
596
|
-
const m =
|
|
593
|
+
}), h = (w) => w.annotation.rects.reduce((E, L) => E + L.width * L.height, 0);
|
|
594
|
+
return y.length > 0 ? (y.sort((w, E) => h(w) - h(E)), f ? y.map((w) => w.annotation.id) : [y[0].annotation.id]) : [];
|
|
595
|
+
}, T = (d) => {
|
|
596
|
+
const m = A(d);
|
|
597
597
|
if (m.length === 0)
|
|
598
598
|
return;
|
|
599
|
-
let
|
|
600
|
-
for (let
|
|
601
|
-
const
|
|
602
|
-
|
|
599
|
+
let f = m[0].left, y = m[0].top, h = m[0].right, w = m[0].bottom;
|
|
600
|
+
for (let E = 1; E < m.length; E++) {
|
|
601
|
+
const L = m[E];
|
|
602
|
+
f = Math.min(f, L.left), y = Math.min(y, L.top), h = Math.max(h, L.right), w = Math.max(w, L.bottom);
|
|
603
603
|
}
|
|
604
|
-
return new DOMRect(
|
|
605
|
-
},
|
|
606
|
-
const m =
|
|
604
|
+
return new DOMRect(f, y, h - f, w - y);
|
|
605
|
+
}, A = (d) => {
|
|
606
|
+
const m = s.get(d);
|
|
607
607
|
return m ? m[0].annotation.rects : [];
|
|
608
608
|
};
|
|
609
609
|
return {
|
|
610
610
|
all: a,
|
|
611
|
-
clear:
|
|
612
|
-
getAt:
|
|
613
|
-
getAnnotationBounds:
|
|
614
|
-
getAnnotationRects:
|
|
615
|
-
getIntersecting: (
|
|
616
|
-
const h =
|
|
617
|
-
return Array.from(
|
|
618
|
-
annotation: t.getAnnotation(
|
|
619
|
-
rects:
|
|
620
|
-
})).filter((
|
|
611
|
+
clear: c,
|
|
612
|
+
getAt: l,
|
|
613
|
+
getAnnotationBounds: T,
|
|
614
|
+
getAnnotationRects: A,
|
|
615
|
+
getIntersecting: (d, m, f, y) => {
|
|
616
|
+
const h = o.search({ minX: d, minY: m, maxX: f, maxY: y }), w = new Set(h.map((E) => E.annotation.id));
|
|
617
|
+
return Array.from(w).map((E) => ({
|
|
618
|
+
annotation: t.getAnnotation(E),
|
|
619
|
+
rects: A(E)
|
|
620
|
+
})).filter((E) => !!E.annotation);
|
|
621
621
|
},
|
|
622
|
-
insert:
|
|
623
|
-
recalculate: () =>
|
|
622
|
+
insert: u,
|
|
623
|
+
recalculate: () => p(t.all().map((d) => d.target), !0),
|
|
624
624
|
remove: b,
|
|
625
|
-
set:
|
|
626
|
-
size: () =>
|
|
627
|
-
update:
|
|
625
|
+
set: p,
|
|
626
|
+
size: () => o.all().length,
|
|
627
|
+
update: g
|
|
628
628
|
};
|
|
629
|
-
},
|
|
630
|
-
var x,
|
|
631
|
-
const n =
|
|
632
|
-
const
|
|
633
|
-
return
|
|
634
|
-
},
|
|
635
|
-
const
|
|
636
|
-
return n.bulkAddAnnotations(
|
|
637
|
-
},
|
|
638
|
-
const
|
|
639
|
-
return
|
|
629
|
+
}, le = (t, e) => {
|
|
630
|
+
var x, C;
|
|
631
|
+
const n = bt(), r = ce(n, t, (x = e.mergeHighlights) == null ? void 0 : x.horizontalTolerance, (C = e.mergeHighlights) == null ? void 0 : C.verticalTolerance), o = yt(n, e.userSelectAction, e.adapter), s = St(n), i = Ct(), a = (d, m = K.LOCAL) => {
|
|
632
|
+
const f = Q(d, t), y = H(f.target.selector);
|
|
633
|
+
return y && n.addAnnotation(f, m), y;
|
|
634
|
+
}, c = (d, m = !0, f = K.LOCAL) => {
|
|
635
|
+
const y = d.map((w) => Q(w, t)), h = y.filter((w) => !H(w.target.selector));
|
|
636
|
+
return n.bulkAddAnnotations(y, m, f), h;
|
|
637
|
+
}, u = (d, m = K.LOCAL) => {
|
|
638
|
+
const f = d.map((h) => Q(h, t)), y = f.filter((h) => !H(h.target.selector));
|
|
639
|
+
return f.forEach((h) => {
|
|
640
640
|
n.getAnnotation(h.id) ? n.updateAnnotation(h, m) : n.addAnnotation(h, m);
|
|
641
|
-
}),
|
|
642
|
-
}, b = (
|
|
643
|
-
const
|
|
644
|
-
n.updateTarget(
|
|
645
|
-
},
|
|
646
|
-
const
|
|
647
|
-
n.bulkUpdateTargets(
|
|
641
|
+
}), y;
|
|
642
|
+
}, b = (d, m = K.LOCAL) => {
|
|
643
|
+
const f = q(d, t);
|
|
644
|
+
n.updateTarget(f, m);
|
|
645
|
+
}, g = (d, m = K.LOCAL) => {
|
|
646
|
+
const f = d.map((y) => q(y, t));
|
|
647
|
+
n.bulkUpdateTargets(f, m);
|
|
648
648
|
};
|
|
649
|
-
function
|
|
650
|
-
const h =
|
|
651
|
-
if (
|
|
652
|
-
return
|
|
649
|
+
function p(d, m, f, y) {
|
|
650
|
+
const h = f || !!y, w = r.getAt(d, m, h).map((L) => n.getAnnotation(L)), E = y ? w.filter(y) : w;
|
|
651
|
+
if (E.length !== 0)
|
|
652
|
+
return f ? E : E[0];
|
|
653
653
|
}
|
|
654
|
-
const
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
return n.observe(({ changes: g }) => {
|
|
659
|
-
const m = (g.deleted || []).filter((h) => H(h.target.selector)), y = (g.created || []).filter((h) => H(h.target.selector)), l = (g.updated || []).filter((h) => H(h.newValue.target.selector));
|
|
660
|
-
(m == null ? void 0 : m.length) > 0 && m.forEach((h) => i.remove(h.target)), y.length > 0 && i.set(y.map((h) => h.target), !1), (l == null ? void 0 : l.length) > 0 && l.forEach(({ newValue: h }) => i.update(h.target));
|
|
654
|
+
const l = (d) => r.getAnnotationRects(d).length > 0 ? r.getAnnotationBounds(d) : void 0, T = (d, m, f, y) => r.getIntersecting(d, m, f, y), A = (d) => r.getAnnotationRects(d), R = () => r.recalculate();
|
|
655
|
+
return n.observe(({ changes: d }) => {
|
|
656
|
+
const m = (d.deleted || []).filter((h) => H(h.target.selector)), f = (d.created || []).filter((h) => H(h.target.selector)), y = (d.updated || []).filter((h) => H(h.newValue.target.selector));
|
|
657
|
+
(m == null ? void 0 : m.length) > 0 && m.forEach((h) => r.remove(h.target)), f.length > 0 && r.set(f.map((h) => h.target), !1), (y == null ? void 0 : y.length) > 0 && y.forEach(({ newValue: h }) => r.update(h.target));
|
|
661
658
|
}), {
|
|
662
659
|
store: {
|
|
663
660
|
...n,
|
|
664
661
|
addAnnotation: a,
|
|
665
|
-
bulkAddAnnotations:
|
|
666
|
-
bulkUpdateTargets:
|
|
667
|
-
bulkUpsertAnnotations:
|
|
668
|
-
getAnnotationBounds:
|
|
669
|
-
getAnnotationRects:
|
|
670
|
-
getIntersecting:
|
|
671
|
-
getAt:
|
|
672
|
-
recalculatePositions:
|
|
662
|
+
bulkAddAnnotations: c,
|
|
663
|
+
bulkUpdateTargets: g,
|
|
664
|
+
bulkUpsertAnnotations: u,
|
|
665
|
+
getAnnotationBounds: l,
|
|
666
|
+
getAnnotationRects: A,
|
|
667
|
+
getIntersecting: T,
|
|
668
|
+
getAt: p,
|
|
669
|
+
recalculatePositions: R,
|
|
673
670
|
updateTarget: b
|
|
674
671
|
},
|
|
675
|
-
selection:
|
|
676
|
-
hover:
|
|
677
|
-
viewport:
|
|
672
|
+
selection: o,
|
|
673
|
+
hover: s,
|
|
674
|
+
viewport: i
|
|
678
675
|
};
|
|
679
|
-
},
|
|
676
|
+
}, de = () => {
|
|
680
677
|
const t = document.createElement("canvas");
|
|
681
678
|
t.width = 2 * window.innerWidth, t.height = 2 * window.innerHeight, t.className = "r6o-presence-layer";
|
|
682
679
|
const e = t.getContext("2d");
|
|
683
680
|
return e.scale(2, 2), e.translate(0.5, 0.5), t;
|
|
684
|
-
},
|
|
685
|
-
const n =
|
|
681
|
+
}, fe = (t, e = {}) => {
|
|
682
|
+
const n = de(), r = n.getContext("2d");
|
|
686
683
|
document.body.appendChild(n);
|
|
687
|
-
const
|
|
688
|
-
return t.on("selectionChange", (b,
|
|
689
|
-
|
|
684
|
+
const o = /* @__PURE__ */ new Map(), s = (b) => Array.from(o.entries()).filter(([g, p]) => p.presenceKey === b.presenceKey).map(([g, p]) => g);
|
|
685
|
+
return t.on("selectionChange", (b, g) => {
|
|
686
|
+
s(b).forEach((l) => o.delete(l)), g && g.forEach((l) => o.set(l, b));
|
|
690
687
|
}), {
|
|
691
688
|
clear: () => {
|
|
692
|
-
const { width: b, height:
|
|
693
|
-
|
|
689
|
+
const { width: b, height: g } = n;
|
|
690
|
+
r.clearRect(-0.5, -0.5, b + 1, g + 1);
|
|
694
691
|
},
|
|
695
692
|
destroy: () => {
|
|
696
693
|
n.remove();
|
|
697
694
|
},
|
|
698
|
-
paint: (b,
|
|
699
|
-
e.font && (
|
|
700
|
-
const
|
|
701
|
-
if (
|
|
702
|
-
const { height:
|
|
703
|
-
|
|
704
|
-
const x =
|
|
705
|
-
return
|
|
706
|
-
fill:
|
|
707
|
-
fillOpacity:
|
|
695
|
+
paint: (b, g, p) => {
|
|
696
|
+
e.font && (r.font = e.font);
|
|
697
|
+
const l = o.get(b.annotation.id);
|
|
698
|
+
if (l) {
|
|
699
|
+
const { height: T } = b.rects[0], A = b.rects[0].x + g.left, R = b.rects[0].y + g.top;
|
|
700
|
+
r.fillStyle = l.appearance.color, r.fillRect(A - 2, R - 2.5, 2, T + 5);
|
|
701
|
+
const x = r.measureText(l.appearance.label), C = x.width + 6, d = x.actualBoundingBoxAscent + x.actualBoundingBoxDescent + 8, m = x.fontBoundingBoxAscent ? 8 : 6.5;
|
|
702
|
+
return r.fillRect(A - 2, R - 2.5 - d, C, d), r.fillStyle = "#fff", r.fillText(l.appearance.label, A + 1, R - m), {
|
|
703
|
+
fill: l.appearance.color,
|
|
704
|
+
fillOpacity: p ? 0.45 : 0.18
|
|
708
705
|
};
|
|
709
706
|
}
|
|
710
707
|
},
|
|
@@ -714,219 +711,233 @@ const ot = "not-annotatable", K = `.${ot}`, Y = (t, e) => {
|
|
|
714
711
|
b.scale(2, 2), b.translate(0.5, 0.5);
|
|
715
712
|
}
|
|
716
713
|
};
|
|
717
|
-
},
|
|
718
|
-
...
|
|
719
|
-
|
|
720
|
-
],
|
|
721
|
-
|
|
714
|
+
}, nt = 300, lt = ["up", "down", "left", "right"], dt = Ot ? "⌘+a" : "ctrl+a", ue = [
|
|
715
|
+
...lt.map((t) => `shift+${t}`),
|
|
716
|
+
dt
|
|
717
|
+
], ge = (t, e, n) => {
|
|
718
|
+
const { store: r, selection: o } = e;
|
|
719
|
+
let s;
|
|
722
720
|
const {
|
|
723
|
-
annotatingEnabled:
|
|
724
|
-
offsetReferenceSelector:
|
|
725
|
-
selectionMode:
|
|
726
|
-
dismissOnNotAnnotatable:
|
|
727
|
-
} = n,
|
|
728
|
-
let
|
|
729
|
-
const
|
|
730
|
-
let
|
|
731
|
-
const
|
|
732
|
-
R
|
|
733
|
-
|
|
721
|
+
annotatingEnabled: i,
|
|
722
|
+
offsetReferenceSelector: a,
|
|
723
|
+
selectionMode: c,
|
|
724
|
+
dismissOnNotAnnotatable: u = "NEVER"
|
|
725
|
+
} = n, b = (S) => s = S;
|
|
726
|
+
let g;
|
|
727
|
+
const p = (S) => g = S;
|
|
728
|
+
let l, T, A, R = i;
|
|
729
|
+
const x = (S) => {
|
|
730
|
+
R = S, d.clear(), S || (l = void 0, T = void 0, A = void 0);
|
|
731
|
+
}, C = () => {
|
|
732
|
+
R && T !== !1 && (l = {
|
|
733
|
+
annotation: st(),
|
|
734
734
|
selector: [],
|
|
735
|
-
creator:
|
|
735
|
+
creator: s,
|
|
736
736
|
created: /* @__PURE__ */ new Date()
|
|
737
737
|
});
|
|
738
|
-
},
|
|
739
|
-
|
|
740
|
-
|
|
738
|
+
}, d = $((S) => {
|
|
739
|
+
if (!R) return;
|
|
740
|
+
const v = document.getSelection();
|
|
741
|
+
if (!(v != null && v.anchorNode))
|
|
741
742
|
return;
|
|
742
|
-
const
|
|
743
|
-
if (!
|
|
744
|
-
|
|
743
|
+
const B = Array.from(Array(v.rangeCount).keys()).map((O) => v.getRangeAt(O));
|
|
744
|
+
if (!B.some((O) => O.intersectsNode(t))) {
|
|
745
|
+
l = void 0;
|
|
745
746
|
return;
|
|
746
747
|
}
|
|
747
|
-
const P = S.timeStamp - ((
|
|
748
|
-
if ((
|
|
749
|
-
|
|
748
|
+
const P = S.timeStamp - ((A == null ? void 0 : A.timeStamp) || S.timeStamp);
|
|
749
|
+
if ((A == null ? void 0 : A.type) === "pointerdown" && (P < 1e3 && !l || v.isCollapsed && P < nt) && C(), l || C(), v.isCollapsed) {
|
|
750
|
+
r.getAnnotation(l.annotation) && (o.clear(), r.deleteAnnotation(l.annotation));
|
|
750
751
|
return;
|
|
751
752
|
}
|
|
752
|
-
const
|
|
753
|
-
if (
|
|
754
|
-
const
|
|
755
|
-
(
|
|
756
|
-
var
|
|
757
|
-
return
|
|
758
|
-
})) && (
|
|
759
|
-
...
|
|
760
|
-
selector:
|
|
753
|
+
const I = B.map((O) => $t(O, t));
|
|
754
|
+
if (I.every((O) => _t(O))) return;
|
|
755
|
+
const N = I.flatMap((O) => Mt(t, O.cloneRange()));
|
|
756
|
+
(N.length > 0 && !l || N.length !== l.selector.length || N.some((O, U) => {
|
|
757
|
+
var F;
|
|
758
|
+
return O.toString() !== ((F = l.selector[U]) == null ? void 0 : F.quote);
|
|
759
|
+
})) && (l = {
|
|
760
|
+
...l,
|
|
761
|
+
selector: N.map((O) => Ft(O, t, a)),
|
|
761
762
|
updated: /* @__PURE__ */ new Date()
|
|
762
|
-
},
|
|
763
|
-
}),
|
|
764
|
-
|
|
765
|
-
},
|
|
766
|
-
if (!
|
|
767
|
-
const
|
|
768
|
-
const { x:
|
|
769
|
-
if (
|
|
770
|
-
(typeof
|
|
763
|
+
}, r.getAnnotation(l.annotation) ? r.updateTarget(l, K.LOCAL) : o.clear());
|
|
764
|
+
}, 10), m = (S) => {
|
|
765
|
+
A = G(S), T = A.button === 0;
|
|
766
|
+
}, f = async (S) => {
|
|
767
|
+
if (!T) return;
|
|
768
|
+
const v = G(S), B = () => {
|
|
769
|
+
const { x: I, y: N } = t.getBoundingClientRect();
|
|
770
|
+
if (z(t, v.target)) {
|
|
771
|
+
(typeof u == "function" ? u(v, t) : u === "ALWAYS") && o.clear();
|
|
771
772
|
return;
|
|
772
773
|
}
|
|
773
|
-
const
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
774
|
+
const M = v.target instanceof Node && t.contains(v.target) && r.getAt(
|
|
775
|
+
v.clientX - I,
|
|
776
|
+
v.clientY - N,
|
|
777
|
+
c === "all",
|
|
778
|
+
g
|
|
778
779
|
);
|
|
779
|
-
if (
|
|
780
|
-
const { selected:
|
|
781
|
-
(
|
|
780
|
+
if (M) {
|
|
781
|
+
const { selected: O } = o, U = new Set(O.map((V) => V.id)), F = Array.isArray(M) ? M.map((V) => V.id) : [M.id];
|
|
782
|
+
(U.size !== F.length || !F.every((V) => U.has(V))) && o.userSelect(F, v);
|
|
782
783
|
} else
|
|
783
|
-
|
|
784
|
+
o.clear();
|
|
784
785
|
};
|
|
785
|
-
if (
|
|
786
|
-
await
|
|
787
|
-
const
|
|
788
|
-
if (
|
|
789
|
-
|
|
786
|
+
if (v.timeStamp - A.timeStamp < nt) {
|
|
787
|
+
await y();
|
|
788
|
+
const I = document.getSelection(), N = z(t, A.target), M = z(t, v.target);
|
|
789
|
+
if (I != null && I.isCollapsed || N && M) {
|
|
790
|
+
l = void 0, B();
|
|
790
791
|
return;
|
|
791
792
|
}
|
|
792
793
|
}
|
|
793
|
-
|
|
794
|
-
},
|
|
794
|
+
l && l.selector.length > 0 && (k(), o.userSelect(l.annotation, v));
|
|
795
|
+
}, y = async () => {
|
|
795
796
|
const S = document.getSelection();
|
|
796
|
-
let
|
|
797
|
-
const P = () =>
|
|
798
|
-
return setTimeout(() =>
|
|
799
|
-
}, y = (S) => {
|
|
800
|
-
const A = document.getSelection();
|
|
801
|
-
A != null && A.isCollapsed || ((!u || u.selector.length === 0) && x(S), u && (C(), c.userSelect(u.annotation, q(S))));
|
|
802
|
-
}, l = (S) => {
|
|
803
|
-
S.key === "Shift" && u && (document.getSelection().isCollapsed || (C(), c.userSelect(u.annotation, V(S))));
|
|
797
|
+
let v = !1, B = S == null ? void 0 : S.isCollapsed;
|
|
798
|
+
const P = () => B || v, I = 1;
|
|
799
|
+
return setTimeout(() => v = !0, 50), Tt(() => B = S == null ? void 0 : S.isCollapsed, I, P);
|
|
804
800
|
}, h = (S) => {
|
|
805
|
-
const
|
|
806
|
-
|
|
807
|
-
|
|
801
|
+
const v = document.getSelection();
|
|
802
|
+
v != null && v.isCollapsed || ((!l || l.selector.length === 0) && d(S), l && (k(), o.userSelect(l.annotation, G(S))));
|
|
803
|
+
}, w = (S) => {
|
|
804
|
+
R && S.key === "Shift" && l && (document.getSelection().isCollapsed || (k(), o.userSelect(l.annotation, X(S))));
|
|
805
|
+
}, E = (S) => {
|
|
806
|
+
const v = () => setTimeout(() => {
|
|
807
|
+
(l == null ? void 0 : l.selector.length) > 0 && (o.clear(), r.addAnnotation({
|
|
808
|
+
id: l.annotation,
|
|
808
809
|
bodies: [],
|
|
809
|
-
target:
|
|
810
|
-
}),
|
|
810
|
+
target: l
|
|
811
|
+
}), o.userSelect(l.annotation, X(S))), document.removeEventListener("selectionchange", v);
|
|
811
812
|
}, 100);
|
|
812
|
-
document.addEventListener("selectionchange",
|
|
813
|
+
document.addEventListener("selectionchange", v), C();
|
|
813
814
|
};
|
|
814
|
-
|
|
815
|
-
S.repeat || (
|
|
816
|
-
}),
|
|
817
|
-
|
|
815
|
+
Y(ue.join(","), { element: t, keydown: !0, keyup: !1 }, (S) => {
|
|
816
|
+
S.repeat || (A = X(S));
|
|
817
|
+
}), Y(dt, { keydown: !0, keyup: !1 }, (S) => {
|
|
818
|
+
A = X(S), E(S);
|
|
818
819
|
});
|
|
819
|
-
const
|
|
820
|
-
S.repeat || S.target !== t && S.target !== document.body || (
|
|
820
|
+
const L = (S) => {
|
|
821
|
+
S.repeat || S.target !== t && S.target !== document.body || (l = void 0, o.clear());
|
|
821
822
|
};
|
|
822
|
-
|
|
823
|
-
const
|
|
824
|
-
const S =
|
|
823
|
+
Y(lt.join(","), { keydown: !0, keyup: !1 }, L);
|
|
824
|
+
const k = () => {
|
|
825
|
+
const S = r.getAnnotation(l.annotation);
|
|
825
826
|
if (!S) {
|
|
826
|
-
|
|
827
|
-
id:
|
|
827
|
+
r.addAnnotation({
|
|
828
|
+
id: l.annotation,
|
|
828
829
|
bodies: [],
|
|
829
|
-
target:
|
|
830
|
+
target: l
|
|
830
831
|
});
|
|
831
832
|
return;
|
|
832
833
|
}
|
|
833
|
-
const { target: { updated:
|
|
834
|
-
(!
|
|
834
|
+
const { target: { updated: v } } = S, { updated: B } = l;
|
|
835
|
+
(!v || !B || v < B) && r.updateTarget(l);
|
|
835
836
|
};
|
|
836
|
-
return document.addEventListener("pointerdown",
|
|
837
|
+
return document.addEventListener("pointerdown", m), document.addEventListener("pointerup", f), document.addEventListener("contextmenu", h), t.addEventListener("keyup", w), t.addEventListener("selectstart", C), document.addEventListener("selectionchange", d), {
|
|
837
838
|
destroy: () => {
|
|
838
|
-
document.removeEventListener("pointerdown",
|
|
839
|
+
l = void 0, T = void 0, A = void 0, d.clear(), document.removeEventListener("pointerdown", m), document.removeEventListener("pointerup", f), document.removeEventListener("contextmenu", h), t.removeEventListener("keyup", w), t.removeEventListener("selectstart", C), document.removeEventListener("selectionchange", d), Y.unbind();
|
|
839
840
|
},
|
|
840
|
-
setFilter:
|
|
841
|
-
setUser:
|
|
841
|
+
setFilter: p,
|
|
842
|
+
setUser: b,
|
|
843
|
+
setAnnotatingEnabled: x
|
|
842
844
|
};
|
|
843
|
-
},
|
|
845
|
+
}, me = (t, e) => ({
|
|
844
846
|
...t,
|
|
845
847
|
annotatingEnabled: t.annotatingEnabled ?? e.annotatingEnabled,
|
|
846
848
|
user: t.user || e.user
|
|
847
|
-
}),
|
|
848
|
-
|
|
849
|
-
const n =
|
|
849
|
+
}), ot = "SPANS", Oe = (t, e = {}) => {
|
|
850
|
+
Lt(t), kt(t);
|
|
851
|
+
const n = me(e, {
|
|
850
852
|
annotatingEnabled: !0,
|
|
851
|
-
user:
|
|
852
|
-
}),
|
|
853
|
-
let
|
|
854
|
-
const b = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" :
|
|
855
|
-
if (!
|
|
853
|
+
user: Et()
|
|
854
|
+
}), r = le(t, n), { selection: o, viewport: s } = r, i = r.store, a = wt(i), c = At(r, a, n.adapter);
|
|
855
|
+
let u = n.user;
|
|
856
|
+
const b = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : ot : n.renderer || ot, g = b === "SPANS" ? oe(t, r, s) : b === "CSS_HIGHLIGHTS" ? Jt(t, r, s) : b === "CANVAS" ? Gt(t, r, s) : void 0;
|
|
857
|
+
if (!g)
|
|
856
858
|
throw `Unknown renderer implementation: ${b}`;
|
|
857
|
-
console.debug(`Using ${b} renderer`), n.style &&
|
|
858
|
-
const
|
|
859
|
-
|
|
860
|
-
|
|
859
|
+
console.debug(`Using ${b} renderer`), n.style && g.setStyle(n.style);
|
|
860
|
+
const p = ge(t, r, n);
|
|
861
|
+
p.setUser(u);
|
|
862
|
+
const l = vt(r, a, n.adapter), T = () => u, A = (f) => {
|
|
863
|
+
p.setAnnotatingEnabled(
|
|
864
|
+
f === void 0 ? !0 : f
|
|
865
|
+
);
|
|
866
|
+
}, R = (f) => {
|
|
867
|
+
g.setFilter(f), p.setFilter(f);
|
|
868
|
+
}, x = (f) => {
|
|
869
|
+
u = f, p.setUser(f);
|
|
870
|
+
}, C = (f) => {
|
|
871
|
+
f && (g.setPainter(fe(f, n.presence)), f.on("selectionChange", () => g.redraw()));
|
|
872
|
+
}, d = (f) => {
|
|
873
|
+
f ? o.setSelected(f) : o.clear();
|
|
874
|
+
};
|
|
875
|
+
return {
|
|
876
|
+
...l,
|
|
861
877
|
destroy: () => {
|
|
862
|
-
|
|
878
|
+
g.destroy(), p.destroy(), a.destroy();
|
|
863
879
|
},
|
|
864
880
|
element: t,
|
|
865
|
-
getUser:
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
setUser:
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
},
|
|
879
|
-
setVisible: (l) => f.setVisible(l),
|
|
880
|
-
on: d.on,
|
|
881
|
-
off: d.off,
|
|
882
|
-
scrollIntoView: Dt(t, r),
|
|
883
|
-
state: i
|
|
881
|
+
getUser: T,
|
|
882
|
+
setAnnotatingEnabled: A,
|
|
883
|
+
setFilter: R,
|
|
884
|
+
setStyle: g.setStyle.bind(g),
|
|
885
|
+
redraw: g.redraw.bind(g),
|
|
886
|
+
setUser: x,
|
|
887
|
+
setSelected: d,
|
|
888
|
+
setPresenceProvider: C,
|
|
889
|
+
setVisible: g.setVisible.bind(g),
|
|
890
|
+
on: c.on,
|
|
891
|
+
off: c.off,
|
|
892
|
+
scrollIntoView: Wt(t, i),
|
|
893
|
+
state: r
|
|
884
894
|
};
|
|
885
895
|
};
|
|
886
896
|
export {
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
Ht as isRangeWhitespaceOrEmpty,
|
|
897
|
+
j as DEFAULT_SELECTED_STYLE,
|
|
898
|
+
_ as DEFAULT_STYLE,
|
|
899
|
+
rt as NOT_ANNOTATABLE_CLASS,
|
|
900
|
+
W as NOT_ANNOTATABLE_SELECTOR,
|
|
901
|
+
Ie as Origin,
|
|
902
|
+
Me as UserSelectAction,
|
|
903
|
+
Ne as W3CTextFormat,
|
|
904
|
+
Lt as cancelSingleClickEvents,
|
|
905
|
+
X as cloneKeyboardEvent,
|
|
906
|
+
G as clonePointerEvent,
|
|
907
|
+
He as createBody,
|
|
908
|
+
Gt as createCanvasRenderer,
|
|
909
|
+
Jt as createHighlightsRenderer,
|
|
910
|
+
fe as createPresencePainter,
|
|
911
|
+
Zt as createRenderer,
|
|
912
|
+
ge as createSelectionHandler,
|
|
913
|
+
oe as createSpansRenderer,
|
|
914
|
+
Oe as createTextAnnotator,
|
|
915
|
+
le as createTextAnnotatorState,
|
|
916
|
+
me as fillDefaults,
|
|
917
|
+
Bt as getHighlightClientRects,
|
|
918
|
+
Ht as getQuoteContext,
|
|
919
|
+
J as getRangeAnnotatableContents,
|
|
920
|
+
Ot as isMac,
|
|
921
|
+
Te as isNodeWhitespaceOrEmpty,
|
|
922
|
+
z as isNotAnnotatable,
|
|
923
|
+
Rt as isRangeAnnotatable,
|
|
924
|
+
_t as isRangeWhitespaceOrEmpty,
|
|
916
925
|
H as isRevived,
|
|
917
926
|
Ut as mergeClientRects,
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
927
|
+
Vt as paint,
|
|
928
|
+
ie as parseW3CTextAnnotation,
|
|
929
|
+
kt as programmaticallyFocusable,
|
|
930
|
+
Ft as rangeToSelector,
|
|
931
|
+
Q as reviveAnnotation,
|
|
932
|
+
at as reviveSelector,
|
|
933
|
+
q as reviveTarget,
|
|
934
|
+
Wt as scrollIntoView,
|
|
935
|
+
ae as serializeW3CTextAnnotation,
|
|
936
|
+
Mt as splitAnnotatableRanges,
|
|
937
|
+
Re as toDomRectList,
|
|
938
|
+
Kt as toParentBounds,
|
|
939
|
+
Le as toViewportBounds,
|
|
940
|
+
$t as trimRangeToContainer,
|
|
941
|
+
it as whitespaceOrEmptyRegex
|
|
931
942
|
};
|
|
932
943
|
//# sourceMappingURL=text-annotator.es.js.map
|