@soomo/react-text-annotator 3.1.0-staging.9 → 3.2.0-staging.1

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