@soomo/react-text-annotator 3.1.0-staging.14 → 3.1.0-staging.16

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.
Files changed (82) hide show
  1. package/dist/TextAnnotationPopup/TextAnnotationPopup.d.ts +21 -0
  2. package/dist/TextAnnotationPopup/TextAnnotationPopup.d.ts.map +1 -0
  3. package/dist/TextAnnotationPopup/index.d.ts +2 -0
  4. package/dist/TextAnnotationPopup/index.d.ts.map +1 -0
  5. package/dist/TextAnnotationPopup/isMobile.d.ts.map +1 -0
  6. package/dist/hooks/index.d.ts +2 -1
  7. package/dist/hooks/index.d.ts.map +1 -1
  8. package/dist/hooks/useAnnotationTargetIdling.d.ts +4 -0
  9. package/dist/hooks/useAnnotationTargetIdling.d.ts.map +1 -0
  10. package/dist/index.d.ts +1 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/react-text-annotator.es.js +6 -4
  13. package/dist/react-text-annotator.es.js.map +1 -1
  14. package/dist/react-text-annotator.es11.js +483 -78
  15. package/dist/react-text-annotator.es11.js.map +1 -1
  16. package/dist/react-text-annotator.es12.js +77 -40
  17. package/dist/react-text-annotator.es12.js.map +1 -1
  18. package/dist/react-text-annotator.es13.js +33 -1471
  19. package/dist/react-text-annotator.es13.js.map +1 -1
  20. package/dist/react-text-annotator.es14.js +1596 -8
  21. package/dist/react-text-annotator.es14.js.map +1 -1
  22. package/dist/react-text-annotator.es15.js +12 -0
  23. package/dist/react-text-annotator.es15.js.map +1 -0
  24. package/dist/react-text-annotator.es17.js +245 -548
  25. package/dist/react-text-annotator.es17.js.map +1 -1
  26. package/dist/react-text-annotator.es18.js +587 -2
  27. package/dist/react-text-annotator.es18.js.map +1 -1
  28. package/dist/react-text-annotator.es19.js +2 -31
  29. package/dist/react-text-annotator.es19.js.map +1 -1
  30. package/dist/react-text-annotator.es2.js +2 -2
  31. package/dist/react-text-annotator.es2.js.map +1 -1
  32. package/dist/react-text-annotator.es20.js +20 -887
  33. package/dist/react-text-annotator.es20.js.map +1 -1
  34. package/dist/react-text-annotator.es21.js +893 -109
  35. package/dist/react-text-annotator.es21.js.map +1 -1
  36. package/dist/react-text-annotator.es22.js +2 -309
  37. package/dist/react-text-annotator.es22.js.map +1 -1
  38. package/dist/react-text-annotator.es23.js +2 -58
  39. package/dist/react-text-annotator.es23.js.map +1 -1
  40. package/dist/react-text-annotator.es24.js +113 -19
  41. package/dist/react-text-annotator.es24.js.map +1 -1
  42. package/dist/react-text-annotator.es25.js +309 -2
  43. package/dist/react-text-annotator.es25.js.map +1 -1
  44. package/dist/react-text-annotator.es26.js +58 -2
  45. package/dist/react-text-annotator.es26.js.map +1 -1
  46. package/dist/react-text-annotator.es27.js +17 -124
  47. package/dist/react-text-annotator.es27.js.map +1 -1
  48. package/dist/react-text-annotator.es28.js +107 -144
  49. package/dist/react-text-annotator.es28.js.map +1 -1
  50. package/dist/react-text-annotator.es29.js +156 -303
  51. package/dist/react-text-annotator.es29.js.map +1 -1
  52. package/dist/react-text-annotator.es3.js +2 -2
  53. package/dist/react-text-annotator.es3.js.map +1 -1
  54. package/dist/react-text-annotator.es30.js +308 -146
  55. package/dist/react-text-annotator.es30.js.map +1 -1
  56. package/dist/react-text-annotator.es31.js +130 -544
  57. package/dist/react-text-annotator.es31.js.map +1 -1
  58. package/dist/react-text-annotator.es32.js +629 -0
  59. package/dist/react-text-annotator.es32.js.map +1 -0
  60. package/dist/react-text-annotator.es4.js +2 -2
  61. package/dist/react-text-annotator.es4.js.map +1 -1
  62. package/dist/react-text-annotator.es5.js +28 -24
  63. package/dist/react-text-annotator.es5.js.map +1 -1
  64. package/dist/react-text-annotator.es6.js +23 -123
  65. package/dist/react-text-annotator.es6.js.map +1 -1
  66. package/dist/react-text-annotator.es7.js +138 -539
  67. package/dist/react-text-annotator.es7.js.map +1 -1
  68. package/dist/react-text-annotator.es8.js +559 -10
  69. package/dist/react-text-annotator.es8.js.map +1 -1
  70. package/dist/react-text-annotator.es9.js +13 -0
  71. package/dist/react-text-annotator.es9.js.map +1 -0
  72. package/package.json +7 -7
  73. package/dist/TextAnnotatorPopup/TextAnnotatorPopup.d.ts +0 -25
  74. package/dist/TextAnnotatorPopup/TextAnnotatorPopup.d.ts.map +0 -1
  75. package/dist/TextAnnotatorPopup/index.d.ts +0 -2
  76. package/dist/TextAnnotatorPopup/index.d.ts.map +0 -1
  77. package/dist/TextAnnotatorPopup/isMobile.d.ts.map +0 -1
  78. package/dist/react-text-annotator.es10.js +0 -490
  79. package/dist/react-text-annotator.es10.js.map +0 -1
  80. package/dist/react-text-annotator.es16.js +0 -249
  81. package/dist/react-text-annotator.es16.js.map +0 -1
  82. /package/dist/{TextAnnotatorPopup → TextAnnotationPopup}/isMobile.d.ts +0 -0
@@ -1,548 +1,147 @@
1
- const se = "not-annotatable", Z = `.${se}`;
2
- /mac/i.test(navigator.userAgentData ? navigator.userAgentData.platform : navigator.platform);
3
- const _t = (t) => {
4
- const e = t.cloneContents();
5
- return e.querySelectorAll(Z).forEach((n) => n.remove()), e;
6
- }, ke = (t, e, n = 10, o) => {
7
- const i = e, s = document.createRange();
8
- s.setStart(i, 0), s.setEnd(t.startContainer, t.startOffset);
9
- const a = _t(s).textContent, r = document.createRange();
10
- r.setStart(t.endContainer, t.endOffset), i === document.body ? r.setEnd(i, i.childNodes.length) : r.setEndAfter(i);
11
- const l = _t(r).textContent;
12
- return {
13
- prefix: a.substring(a.length - n),
14
- suffix: l.substring(0, n)
15
- };
16
- };
17
- const U = [];
18
- for (let t = 0; t < 256; ++t)
19
- U.push((t + 256).toString(16).slice(1));
20
- function cn(t, e = 0) {
21
- return (U[t[e + 0]] + U[t[e + 1]] + U[t[e + 2]] + U[t[e + 3]] + "-" + U[t[e + 4]] + U[t[e + 5]] + "-" + U[t[e + 6]] + U[t[e + 7]] + "-" + U[t[e + 8]] + U[t[e + 9]] + "-" + U[t[e + 10]] + U[t[e + 11]] + U[t[e + 12]] + U[t[e + 13]] + U[t[e + 14]] + U[t[e + 15]]).toLowerCase();
22
- }
23
- let St;
24
- const ln = new Uint8Array(16);
25
- function dn() {
26
- if (!St) {
27
- if (typeof crypto > "u" || !crypto.getRandomValues)
28
- throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
29
- St = crypto.getRandomValues.bind(crypto);
30
- }
31
- return St(ln);
32
- }
33
- const un = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Gt = { randomUUID: un };
34
- function ue(t, e, n) {
35
- if (Gt.randomUUID && !e && !t)
36
- return Gt.randomUUID();
37
- t = t || {};
38
- const o = t.random || (t.rng || dn)();
39
- return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, cn(o);
40
- }
41
- var V = [];
42
- for (var Lt = 0; Lt < 256; ++Lt)
43
- V.push((Lt + 256).toString(16).slice(1));
44
- typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
45
- const Nn = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
46
- let Yn = (t = 21) => {
47
- let e = "", n = crypto.getRandomValues(new Uint8Array(t));
48
- for (; t--; )
49
- e += Nn[n[t] & 63];
50
- return e;
51
- };
52
- const Xn = (t) => {
53
- const e = JSON.stringify(t);
54
- let n = 0;
55
- for (let o = 0, i = e.length; o < i; o++) {
56
- let s = e.charCodeAt(o);
57
- n = (n << 5) - n + s, n |= 0;
58
- }
59
- return `${n}`;
60
- }, pe = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, Pn = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
61
- const { id: o, type: i, purpose: s, value: a, created: r, modified: l, creator: f, ...u } = n;
62
- return {
63
- id: o || `temp-${Xn(n)}`,
64
- annotation: e,
65
- type: i,
66
- purpose: s,
67
- value: a,
68
- creator: pe(f),
69
- created: r ? new Date(r) : void 0,
70
- updated: l ? new Date(l) : void 0,
71
- ...u
72
- };
73
- }), $n = (t) => t.map((e) => {
74
- var n;
75
- const { annotation: o, created: i, updated: s, ...a } = e, r = {
76
- ...a,
77
- created: i == null ? void 0 : i.toISOString(),
78
- modified: s == null ? void 0 : s.toISOString()
79
- };
80
- return (n = r.id) != null && n.startsWith("temp-") && delete r.id, r;
81
- });
82
- Yn();
83
- const Ao = (t, e) => ({
84
- parse: (n) => zn(n),
85
- serialize: (n) => Fn(n, t, e)
86
- }), Hn = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, jn = (t) => {
87
- const {
88
- id: e,
89
- creator: n,
90
- created: o,
91
- modified: i,
92
- target: s
93
- } = t, a = Array.isArray(s) ? s : [s], r = {
94
- creator: pe(n),
95
- created: o ? new Date(o) : void 0,
96
- updated: i ? new Date(i) : void 0,
97
- annotation: e,
98
- selector: []
99
- };
100
- for (const l of a) {
101
- const u = (Array.isArray(l.selector) ? l.selector : [l.selector]).reduce((h, g) => {
102
- switch (g.type) {
103
- case "TextQuoteSelector":
104
- h.quote = g.exact;
105
- break;
106
- case "TextPositionSelector":
107
- h.start = g.start, h.end = g.end;
108
- break;
1
+ import { j as jsxRuntimeExports } from "./react-text-annotator.es9.js";
2
+ import { useState, useCallback, useEffect, useRef, useMemo } from "react";
3
+ import { useAnnotator, useSelection } from "@annotorious/react";
4
+ import { isRevived, denormalizeRectWithOffset, toDomRectList, NOT_ANNOTATABLE_CLASS } from "@soomo/text-annotator";
5
+ import { useFloating, useDismiss, useRole, useInteractions, FloatingPortal, FloatingFocusManager, FloatingArrow } from "./react-text-annotator.es14.js";
6
+ import { isMobile } from "./react-text-annotator.es15.js";
7
+ import { useAnnouncePopupNavigation } from "./react-text-annotator.es4.js";
8
+ import { useAnnotationTargetIdling } from "./react-text-annotator.es5.js";
9
+ /* empty css */
10
+ import { inline, offset, flip, shift, arrow } from "./react-text-annotator.es17.js";
11
+ import { autoUpdate } from "./react-text-annotator.es18.js";
12
+ const TextAnnotationPopup = (props) => {
13
+ var _a, _b;
14
+ const { popup, ariaNavigationMessage } = props;
15
+ const r = useAnnotator();
16
+ const { selected, event } = useSelection();
17
+ const annotation = (_a = selected[0]) == null ? void 0 : _a.annotation;
18
+ const isAnnotationIdling = useAnnotationTargetIdling(annotation == null ? void 0 : annotation.id);
19
+ const [isOpen, setOpen] = useState((selected == null ? void 0 : selected.length) > 0);
20
+ const handleClose = () => r == null ? void 0 : r.cancelSelected();
21
+ const [isFocused, setFocused] = useState(false);
22
+ const handleFocus = useCallback(() => setFocused(true), []);
23
+ const handleBlur = useCallback(() => setFocused(false), []);
24
+ useEffect(() => {
25
+ if (!isOpen) handleBlur();
26
+ }, [isOpen, handleBlur]);
27
+ const arrowRef = useRef(null);
28
+ const { refs, floatingStyles, update, context } = useFloating({
29
+ placement: isMobile() ? "bottom" : "top",
30
+ open: isOpen,
31
+ onOpenChange: (open, _event, reason) => {
32
+ if (!open && (reason === "escape-key" || reason === "focus-out")) {
33
+ setOpen(open);
34
+ handleClose();
109
35
  }
110
- return h;
111
- }, {});
112
- if (Hn(u))
113
- r.selector.push({ id: l.id, ...u });
114
- else {
115
- const h = [
116
- u.start ? void 0 : "TextPositionSelector",
117
- u.quote ? void 0 : "TextQuoteSelector"
118
- ].filter(Boolean);
119
- return { error: Error(`Missing selector types: ${h.join(" and ")} for annotation: ${t.id}`) };
120
- }
121
- }
122
- return { parsed: r };
123
- }, zn = (t) => {
124
- const e = t.id || ue(), {
125
- creator: n,
126
- created: o,
127
- modified: i,
128
- body: s,
129
- ...a
130
- } = t, r = Pn(s, e), l = jn(t);
131
- return "error" in l ? { error: l.error } : {
132
- parsed: {
133
- ...a,
134
- id: e,
135
- bodies: r,
136
- target: l.parsed
137
- }
138
- };
139
- }, Fn = (t, e, n) => {
140
- const { bodies: o, target: i, ...s } = t, {
141
- selector: a,
142
- creator: r,
143
- created: l,
144
- updated: f,
145
- ...u
146
- } = i, h = a.map((g) => {
147
- const { quote: p, start: v, end: y, range: m } = g, { prefix: d, suffix: c } = ke(m, n), b = [{
148
- type: "TextQuoteSelector",
149
- exact: p,
150
- prefix: d,
151
- suffix: c
152
- }, {
153
- type: "TextPositionSelector",
154
- start: v,
155
- end: y
156
- }];
157
- return {
158
- ...u,
159
- id: g.id,
160
- source: e,
161
- selector: b
162
- };
36
+ },
37
+ middleware: [
38
+ inline(),
39
+ offset(10),
40
+ flip({ crossAxis: true }),
41
+ shift({ crossAxis: true, padding: 10 }),
42
+ arrow({ element: arrowRef })
43
+ ],
44
+ whileElementsMounted: autoUpdate
163
45
  });
164
- return {
165
- ...s,
166
- "@context": "http://www.w3.org/ns/anno.jsonld",
167
- id: t.id,
168
- type: "Annotation",
169
- body: $n(t.bodies),
170
- creator: r,
171
- created: l == null ? void 0 : l.toISOString(),
172
- modified: f == null ? void 0 : f.toISOString(),
173
- target: h
174
- };
175
- };
176
- const Bt = typeof navigator < "u" ? navigator.userAgent.toLowerCase().indexOf("firefox") > 0 : false;
177
- function kt(t, e, n, o) {
178
- t.addEventListener ? t.addEventListener(e, n, o) : t.attachEvent && t.attachEvent("on".concat(e), n);
179
- }
180
- function et(t, e, n, o) {
181
- t.removeEventListener ? t.removeEventListener(e, n, o) : t.detachEvent && t.detachEvent("on".concat(e), n);
182
- }
183
- function me(t, e) {
184
- const n = e.slice(0, e.length - 1);
185
- for (let o = 0; o < n.length; o++) n[o] = t[n[o].toLowerCase()];
186
- return n;
187
- }
188
- function ye(t) {
189
- typeof t != "string" && (t = ""), t = t.replace(/\s/g, "");
190
- const e = t.split(",");
191
- let n = e.lastIndexOf("");
192
- for (; n >= 0; )
193
- e[n - 1] += ",", e.splice(n, 1), n = e.lastIndexOf("");
194
- return e;
195
- }
196
- function so(t, e) {
197
- const n = t.length >= e.length ? t : e, o = t.length >= e.length ? e : t;
198
- let i = true;
199
- for (let s = 0; s < n.length; s++)
200
- o.indexOf(n[s]) === -1 && (i = false);
201
- return i;
202
- }
203
- const at = {
204
- backspace: 8,
205
- "⌫": 8,
206
- tab: 9,
207
- clear: 12,
208
- enter: 13,
209
- "↩": 13,
210
- return: 13,
211
- esc: 27,
212
- escape: 27,
213
- space: 32,
214
- left: 37,
215
- up: 38,
216
- right: 39,
217
- down: 40,
218
- del: 46,
219
- delete: 46,
220
- ins: 45,
221
- insert: 45,
222
- home: 36,
223
- end: 35,
224
- pageup: 33,
225
- pagedown: 34,
226
- capslock: 20,
227
- num_0: 96,
228
- num_1: 97,
229
- num_2: 98,
230
- num_3: 99,
231
- num_4: 100,
232
- num_5: 101,
233
- num_6: 102,
234
- num_7: 103,
235
- num_8: 104,
236
- num_9: 105,
237
- num_multiply: 106,
238
- num_add: 107,
239
- num_enter: 108,
240
- num_subtract: 109,
241
- num_decimal: 110,
242
- num_divide: 111,
243
- "⇪": 20,
244
- ",": 188,
245
- ".": 190,
246
- "/": 191,
247
- "`": 192,
248
- "-": Bt ? 173 : 189,
249
- "=": Bt ? 61 : 187,
250
- ";": Bt ? 59 : 186,
251
- "'": 222,
252
- "[": 219,
253
- "]": 221,
254
- "\\": 220
255
- }, H = {
256
- // shiftKey
257
- "⇧": 16,
258
- shift: 16,
259
- // altKey
260
- "⌥": 18,
261
- alt: 18,
262
- option: 18,
263
- // ctrlKey
264
- "⌃": 17,
265
- ctrl: 17,
266
- control: 17,
267
- // metaKey
268
- "⌘": 91,
269
- cmd: 91,
270
- command: 91
271
- }, Ut = {
272
- 16: "shiftKey",
273
- 18: "altKey",
274
- 17: "ctrlKey",
275
- 91: "metaKey",
276
- shiftKey: 16,
277
- ctrlKey: 17,
278
- altKey: 18,
279
- metaKey: 91
280
- }, K = {
281
- 16: false,
282
- 18: false,
283
- 17: false,
284
- 91: false
285
- }, _ = {};
286
- for (let t = 1; t < 20; t++)
287
- at["f".concat(t)] = 111 + t;
288
- let I = [], rt = null, be = "all";
289
- const z = /* @__PURE__ */ new Map(), lt = (t) => at[t.toLowerCase()] || H[t.toLowerCase()] || t.toUpperCase().charCodeAt(0), ro = (t) => Object.keys(at).find((e) => at[e] === t), ao = (t) => Object.keys(H).find((e) => H[e] === t);
290
- function we(t) {
291
- be = t || "all";
292
- }
293
- function ct() {
294
- return be || "all";
295
- }
296
- function co() {
297
- return I.slice(0);
298
- }
299
- function lo() {
300
- return I.map((t) => ro(t) || ao(t) || String.fromCharCode(t));
301
- }
302
- function uo() {
303
- const t = [];
304
- return Object.keys(_).forEach((e) => {
305
- _[e].forEach((n) => {
306
- let {
307
- key: o,
308
- scope: i,
309
- mods: s,
310
- shortcut: a
311
- } = n;
312
- t.push({
313
- scope: i,
314
- shortcut: a,
315
- mods: s,
316
- keys: o.split("+").map((r) => lt(r))
46
+ const dismiss = useDismiss(context);
47
+ const role = useRole(context, { role: "dialog" });
48
+ const { getFloatingProps } = useInteractions([dismiss, role]);
49
+ useEffect(() => {
50
+ const annotationSelector = annotation == null ? void 0 : annotation.target.selector;
51
+ setOpen(isAnnotationIdling && (annotationSelector == null ? void 0 : annotationSelector.length) > 0 ? isRevived(annotationSelector) : false);
52
+ }, [(_b = annotation == null ? void 0 : annotation.target) == null ? void 0 : _b.selector, isAnnotationIdling]);
53
+ useEffect(() => {
54
+ if (!r) return;
55
+ if (isOpen && (annotation == null ? void 0 : annotation.id)) {
56
+ refs.setPositionReference({
57
+ getBoundingClientRect: () => {
58
+ const bounds = r.state.store.getAnnotationBounds(annotation.id);
59
+ return bounds ? denormalizeRectWithOffset(bounds, r.element.getBoundingClientRect()) : new DOMRect();
60
+ },
61
+ getClientRects: () => {
62
+ const rects = r.state.store.getAnnotationRects(annotation.id);
63
+ const denormalizedRects = rects.map(
64
+ (rect) => denormalizeRectWithOffset(rect, r.element.getBoundingClientRect())
65
+ );
66
+ return toDomRectList(denormalizedRects);
67
+ }
317
68
  });
318
- });
319
- }), t;
320
- }
321
- function fo(t) {
322
- const e = t.target || t.srcElement, {
323
- tagName: n
324
- } = e;
325
- let o = true;
326
- const i = n === "INPUT" && !["checkbox", "radio", "range", "button", "file", "reset", "submit", "color"].includes(e.type);
327
- return (e.isContentEditable || (i || n === "TEXTAREA" || n === "SELECT") && !e.readOnly) && (o = false), o;
328
- }
329
- function ho(t) {
330
- return typeof t == "string" && (t = lt(t)), I.indexOf(t) !== -1;
331
- }
332
- function po(t, e) {
333
- let n, o;
334
- t || (t = ct());
335
- for (const i in _)
336
- if (Object.prototype.hasOwnProperty.call(_, i))
337
- for (n = _[i], o = 0; o < n.length; )
338
- n[o].scope === t ? n.splice(o, 1).forEach((a) => {
339
- let {
340
- element: r
341
- } = a;
342
- return Dt(r);
343
- }) : o++;
344
- ct() === t && we(e || "all");
345
- }
346
- function go(t) {
347
- let e = t.keyCode || t.which || t.charCode;
348
- const n = I.indexOf(e);
349
- if (n >= 0 && I.splice(n, 1), t.key && t.key.toLowerCase() === "meta" && I.splice(0, I.length), (e === 93 || e === 224) && (e = 91), e in K) {
350
- K[e] = false;
351
- for (const o in H) H[o] === e && (P[o] = false);
352
- }
353
- }
354
- function ve(t) {
355
- if (typeof t > "u")
356
- Object.keys(_).forEach((i) => {
357
- Array.isArray(_[i]) && _[i].forEach((s) => mt(s)), delete _[i];
358
- }), Dt(null);
359
- else if (Array.isArray(t))
360
- t.forEach((i) => {
361
- i.key && mt(i);
362
- });
363
- else if (typeof t == "object")
364
- t.key && mt(t);
365
- else if (typeof t == "string") {
366
- for (var e = arguments.length, n = new Array(e > 1 ? e - 1 : 0), o = 1; o < e; o++)
367
- n[o - 1] = arguments[o];
368
- let [i, s] = n;
369
- typeof i == "function" && (s = i, i = ""), mt({
370
- key: t,
371
- scope: i,
372
- method: s,
373
- splitKey: "+"
374
- });
375
- }
376
- }
377
- const mt = (t) => {
378
- let {
379
- key: e,
380
- scope: n,
381
- method: o,
382
- splitKey: i = "+"
383
- } = t;
384
- ye(e).forEach((a) => {
385
- const r = a.split(i), l = r.length, f = r[l - 1], u = f === "*" ? "*" : lt(f);
386
- if (!_[u]) return;
387
- n || (n = ct());
388
- const h = l > 1 ? me(H, r) : [], g = [];
389
- _[u] = _[u].filter((p) => {
390
- const y = (o ? p.method === o : true) && p.scope === n && so(p.mods, h);
391
- return y && g.push(p.element), !y;
392
- }), g.forEach((p) => Dt(p));
393
- });
394
- };
395
- function ee(t, e, n, o) {
396
- if (e.element !== o)
397
- return;
398
- let i;
399
- if (e.scope === n || e.scope === "all") {
400
- i = e.mods.length > 0;
401
- for (const s in K)
402
- Object.prototype.hasOwnProperty.call(K, s) && (!K[s] && e.mods.indexOf(+s) > -1 || K[s] && e.mods.indexOf(+s) === -1) && (i = false);
403
- (e.mods.length === 0 && !K[16] && !K[18] && !K[17] && !K[91] || i || e.shortcut === "*") && (e.keys = [], e.keys = e.keys.concat(I), e.method(t, e) === false && (t.preventDefault ? t.preventDefault() : t.returnValue = false, t.stopPropagation && t.stopPropagation(), t.cancelBubble && (t.cancelBubble = true)));
404
- }
405
- }
406
- function ne(t, e) {
407
- const n = _["*"];
408
- let o = t.keyCode || t.which || t.charCode;
409
- if (!P.filter.call(this, t)) return;
410
- if ((o === 93 || o === 224) && (o = 91), I.indexOf(o) === -1 && o !== 229 && I.push(o), ["ctrlKey", "altKey", "shiftKey", "metaKey"].forEach((r) => {
411
- const l = Ut[r];
412
- t[r] && I.indexOf(l) === -1 ? I.push(l) : !t[r] && I.indexOf(l) > -1 ? I.splice(I.indexOf(l), 1) : r === "metaKey" && t[r] && I.length === 3 && (t.ctrlKey || t.shiftKey || t.altKey || (I = I.slice(I.indexOf(l))));
413
- }), o in K) {
414
- K[o] = true;
415
- for (const r in H)
416
- H[r] === o && (P[r] = true);
417
- if (!n) return;
418
- }
419
- for (const r in K)
420
- Object.prototype.hasOwnProperty.call(K, r) && (K[r] = t[Ut[r]]);
421
- t.getModifierState && !(t.altKey && !t.ctrlKey) && t.getModifierState("AltGraph") && (I.indexOf(17) === -1 && I.push(17), I.indexOf(18) === -1 && I.push(18), K[17] = true, K[18] = true);
422
- const i = ct();
423
- if (n)
424
- for (let r = 0; r < n.length; r++)
425
- n[r].scope === i && (t.type === "keydown" && n[r].keydown || t.type === "keyup" && n[r].keyup) && ee(t, n[r], i, e);
426
- if (!(o in _)) return;
427
- const s = _[o], a = s.length;
428
- for (let r = 0; r < a; r++)
429
- if ((t.type === "keydown" && s[r].keydown || t.type === "keyup" && s[r].keyup) && s[r].key) {
430
- const l = s[r], {
431
- splitKey: f
432
- } = l, u = l.key.split(f), h = [];
433
- for (let g = 0; g < u.length; g++)
434
- h.push(lt(u[g]));
435
- h.sort().join("") === I.sort().join("") && ee(t, l, i, e);
436
- }
437
- }
438
- function P(t, e, n) {
439
- I = [];
440
- const o = ye(t);
441
- let i = [], s = "all", a = document, r = 0, l = false, f = true, u = "+", h = false, g = false;
442
- for (n === void 0 && typeof e == "function" && (n = e), Object.prototype.toString.call(e) === "[object Object]" && (e.scope && (s = e.scope), e.element && (a = e.element), e.keyup && (l = e.keyup), e.keydown !== void 0 && (f = e.keydown), e.capture !== void 0 && (h = e.capture), typeof e.splitKey == "string" && (u = e.splitKey), e.single === true && (g = true)), typeof e == "string" && (s = e), g && ve(t, s); r < o.length; r++)
443
- t = o[r].split(u), i = [], t.length > 1 && (i = me(H, t)), t = t[t.length - 1], t = t === "*" ? "*" : lt(t), t in _ || (_[t] = []), _[t].push({
444
- keyup: l,
445
- keydown: f,
446
- scope: s,
447
- mods: i,
448
- shortcut: o[r],
449
- method: n,
450
- key: o[r],
451
- splitKey: u,
452
- element: a
453
- });
454
- if (typeof a < "u" && window) {
455
- if (!z.has(a)) {
456
- const p = function() {
457
- let y = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
458
- return ne(y, a);
459
- }, v = function() {
460
- let y = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
461
- ne(y, a), go(y);
462
- };
463
- z.set(a, {
464
- keydownListener: p,
465
- keyupListenr: v,
466
- capture: h
467
- }), kt(a, "keydown", p, h), kt(a, "keyup", v, h);
69
+ } else {
70
+ refs.setPositionReference(null);
468
71
  }
469
- if (!rt) {
470
- const p = () => {
471
- I = [];
472
- };
473
- rt = {
474
- listener: p,
475
- capture: h
476
- }, kt(window, "focus", p, h);
477
- }
478
- }
479
- }
480
- function mo(t) {
481
- let e = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "all";
482
- Object.keys(_).forEach((n) => {
483
- _[n].filter((i) => i.scope === e && i.shortcut === t).forEach((i) => {
484
- i && i.method && i.method();
485
- });
72
+ }, [isOpen, annotation == null ? void 0 : annotation.id, annotation == null ? void 0 : annotation.target, r]);
73
+ useEffect(() => {
74
+ const config = { attributes: true, childList: true, subtree: true };
75
+ const mutationObserver = new MutationObserver(() => update());
76
+ mutationObserver.observe(document.body, config);
77
+ window.document.addEventListener("scroll", update, true);
78
+ return () => {
79
+ mutationObserver.disconnect();
80
+ window.document.removeEventListener("scroll", update, true);
81
+ };
82
+ }, [update]);
83
+ const initialFocus = useMemo(() => {
84
+ return (event == null ? void 0 : event.type) === "keyup" || (event == null ? void 0 : event.type) === "contextmenu" || isMobile() ? -1 : 0;
85
+ }, [event]);
86
+ useAnnouncePopupNavigation({
87
+ disabled: isFocused,
88
+ floatingOpen: isOpen,
89
+ message: ariaNavigationMessage
486
90
  });
487
- }
488
- function Dt(t) {
489
- const e = Object.values(_).flat();
490
- if (e.findIndex((o) => {
491
- let {
492
- element: i
493
- } = o;
494
- return i === t;
495
- }) < 0) {
496
- const {
497
- keydownListener: o,
498
- keyupListenr: i,
499
- capture: s
500
- } = z.get(t) || {};
501
- o && i && (et(t, "keyup", i, s), et(t, "keydown", o, s), z.delete(t));
502
- }
503
- if ((e.length <= 0 || z.size <= 0) && (Object.keys(z).forEach((i) => {
504
- const {
505
- keydownListener: s,
506
- keyupListenr: a,
507
- capture: r
508
- } = z.get(i) || {};
509
- s && a && (et(i, "keyup", a, r), et(i, "keydown", s, r), z.delete(i));
510
- }), z.clear(), Object.keys(_).forEach((i) => delete _[i]), rt)) {
511
- const {
512
- listener: i,
513
- capture: s
514
- } = rt;
515
- et(window, "focus", i, s), rt = null;
516
- }
517
- }
518
- const It = {
519
- getPressedKeyString: lo,
520
- setScope: we,
521
- getScope: ct,
522
- deleteScope: po,
523
- getPressedKeyCodes: co,
524
- getAllKeyCodes: uo,
525
- isPressed: ho,
526
- filter: fo,
527
- trigger: mo,
528
- unbind: ve,
529
- keyMap: at,
530
- modifier: H,
531
- modifierMap: Ut
91
+ return isOpen && annotation ? /* @__PURE__ */ jsxRuntimeExports.jsx(FloatingPortal, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(
92
+ FloatingFocusManager,
93
+ {
94
+ context,
95
+ modal: false,
96
+ closeOnFocusOut: true,
97
+ returnFocus: false,
98
+ initialFocus,
99
+ children: /* @__PURE__ */ jsxRuntimeExports.jsxs(
100
+ "div",
101
+ {
102
+ className: `a9s-popup r6o-popup annotation-popup r6o-text-popup ${NOT_ANNOTATABLE_CLASS}`,
103
+ ref: refs.setFloating,
104
+ style: floatingStyles,
105
+ ...getFloatingProps({
106
+ onFocus: handleFocus,
107
+ onBlur: handleBlur,
108
+ ...getStopEventsPropagationProps()
109
+ }),
110
+ children: [
111
+ popup({
112
+ annotation: selected[0].annotation,
113
+ editable: selected[0].editable,
114
+ event
115
+ }),
116
+ props.arrow && /* @__PURE__ */ jsxRuntimeExports.jsx(
117
+ FloatingArrow,
118
+ {
119
+ ref: arrowRef,
120
+ context,
121
+ ...props.arrowProps || {}
122
+ }
123
+ ),
124
+ /* @__PURE__ */ jsxRuntimeExports.jsx("button", { className: "r6o-popup-sr-only", "aria-live": "assertive", onClick: handleClose, children: props.ariaCloseWarning || "Click or leave this dialog to close it." })
125
+ ]
126
+ }
127
+ )
128
+ }
129
+ ) }) : null;
130
+ };
131
+ const getStopEventsPropagationProps = () => ({
132
+ onPointerUp: (event) => event.stopPropagation(),
133
+ onPointerDown: (event) => event.stopPropagation(),
134
+ onMouseDown: (event) => event.stopPropagation(),
135
+ onMouseUp: (event) => event.stopPropagation()
136
+ });
137
+ const TextAnnotatorPopup = (props) => {
138
+ useEffect(() => {
139
+ console.warn("TextAnnotatorPopup is deprecated and will be removed in a future version. Please use TextAnnotationPopup instead.");
140
+ }, []);
141
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(TextAnnotationPopup, { ...props });
532
142
  };
533
- for (const t in It)
534
- Object.prototype.hasOwnProperty.call(It, t) && (P[t] = It[t]);
535
- if (typeof window < "u") {
536
- const t = window.hotkeys;
537
- P.noConflict = (e) => (e && window.hotkeys === P && (window.hotkeys = t), P), window.hotkeys = P;
538
- }
539
143
  export {
540
- se as NOT_ANNOTATABLE_CLASS,
541
- Z as NOT_ANNOTATABLE_SELECTOR,
542
- Ao as W3CTextFormat,
543
- ke as getQuoteContext,
544
- _t as getRangeAnnotatableContents,
545
- zn as parseW3CTextAnnotation,
546
- Fn as serializeW3CTextAnnotation
144
+ TextAnnotationPopup,
145
+ TextAnnotatorPopup
547
146
  };
548
147
  //# sourceMappingURL=react-text-annotator.es7.js.map