@soomo/react-text-annotator 3.0.0-staging.8 → 3.1.0-staging.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.
Files changed (78) hide show
  1. package/dist/TextAnnotator.d.ts +4 -5
  2. package/dist/TextAnnotator.d.ts.map +1 -1
  3. package/dist/TextAnnotatorPlugin.d.ts +1 -2
  4. package/dist/TextAnnotatorPopup/TextAnnotatorPopup.d.ts +15 -0
  5. package/dist/TextAnnotatorPopup/TextAnnotatorPopup.d.ts.map +1 -0
  6. package/dist/TextAnnotatorPopup/index.d.ts +2 -0
  7. package/dist/TextAnnotatorPopup/index.d.ts.map +1 -0
  8. package/dist/TextAnnotatorPopup/isMobile.d.ts +2 -0
  9. package/dist/TextAnnotatorPopup/isMobile.d.ts.map +1 -0
  10. package/dist/hooks/index.d.ts +2 -0
  11. package/dist/hooks/index.d.ts.map +1 -0
  12. package/dist/hooks/useAnnouncePopupNavigation.d.ts +10 -0
  13. package/dist/hooks/useAnnouncePopupNavigation.d.ts.map +1 -0
  14. package/dist/index.d.ts +6 -3
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/react-text-annotator.css +31 -1
  17. package/dist/react-text-annotator.es.js +9 -5
  18. package/dist/react-text-annotator.es.js.map +1 -1
  19. package/dist/react-text-annotator.es10.js +486 -34
  20. package/dist/react-text-annotator.es10.js.map +1 -1
  21. package/dist/react-text-annotator.es11.js +9 -884
  22. package/dist/react-text-annotator.es11.js.map +1 -1
  23. package/dist/react-text-annotator.es12.js +1448 -2
  24. package/dist/react-text-annotator.es12.js.map +1 -1
  25. package/dist/react-text-annotator.es14.js +241 -109
  26. package/dist/react-text-annotator.es14.js.map +1 -1
  27. package/dist/react-text-annotator.es15.js +540 -264
  28. package/dist/react-text-annotator.es15.js.map +1 -1
  29. package/dist/react-text-annotator.es16.js +73 -49
  30. package/dist/react-text-annotator.es16.js.map +1 -1
  31. package/dist/react-text-annotator.es17.js +41 -16
  32. package/dist/react-text-annotator.es17.js.map +1 -1
  33. package/dist/{react-text-annotator.es9.js → react-text-annotator.es18.js} +1 -1
  34. package/dist/react-text-annotator.es18.js.map +1 -0
  35. package/dist/react-text-annotator.es19.js +34 -0
  36. package/dist/react-text-annotator.es19.js.map +1 -0
  37. package/dist/react-text-annotator.es2.js +2 -2
  38. package/dist/react-text-annotator.es20.js +901 -0
  39. package/dist/react-text-annotator.es20.js.map +1 -0
  40. package/dist/react-text-annotator.es21.js +5 -0
  41. package/dist/react-text-annotator.es21.js.map +1 -0
  42. package/dist/{react-text-annotator.es13.js → react-text-annotator.es22.js} +1 -1
  43. package/dist/react-text-annotator.es22.js.map +1 -0
  44. package/dist/react-text-annotator.es23.js +117 -0
  45. package/dist/react-text-annotator.es23.js.map +1 -0
  46. package/dist/react-text-annotator.es24.js +312 -0
  47. package/dist/react-text-annotator.es24.js.map +1 -0
  48. package/dist/react-text-annotator.es25.js +61 -0
  49. package/dist/react-text-annotator.es25.js.map +1 -0
  50. package/dist/react-text-annotator.es26.js +23 -0
  51. package/dist/react-text-annotator.es26.js.map +1 -0
  52. package/dist/react-text-annotator.es27.js +130 -0
  53. package/dist/react-text-annotator.es27.js.map +1 -0
  54. package/dist/react-text-annotator.es28.js +167 -0
  55. package/dist/react-text-annotator.es28.js.map +1 -0
  56. package/dist/react-text-annotator.es29.js +314 -0
  57. package/dist/react-text-annotator.es29.js.map +1 -0
  58. package/dist/react-text-annotator.es3.js +2 -2
  59. package/dist/react-text-annotator.es30.js +152 -0
  60. package/dist/react-text-annotator.es30.js.map +1 -0
  61. package/dist/react-text-annotator.es31.js +566 -0
  62. package/dist/react-text-annotator.es31.js.map +1 -0
  63. package/dist/react-text-annotator.es4.js +38 -28
  64. package/dist/react-text-annotator.es4.js.map +1 -1
  65. package/dist/react-text-annotator.es5.js +23 -47
  66. package/dist/react-text-annotator.es5.js.map +1 -1
  67. package/dist/react-text-annotator.es6.js +127 -10
  68. package/dist/react-text-annotator.es6.js.map +1 -1
  69. package/dist/react-text-annotator.es7.js +546 -1
  70. package/dist/react-text-annotator.es7.js.map +1 -1
  71. package/dist/react-text-annotator.es8.js +9 -487
  72. package/dist/react-text-annotator.es8.js.map +1 -1
  73. package/dist/tei/TEIAnnotator.d.ts +2 -3
  74. package/package.json +23 -16
  75. package/dist/TextAnnotatorPopup.d.ts +0 -14
  76. package/dist/TextAnnotatorPopup.d.ts.map +0 -1
  77. package/dist/react-text-annotator.es13.js.map +0 -1
  78. package/dist/react-text-annotator.es9.js.map +0 -1
@@ -1,312 +1,588 @@
1
- function getOrdinality(elt, name) {
2
- let pos = 1;
3
- let e = elt;
4
- while (e && e.previousElementSibling !== null && (name ? e.previousElementSibling.localName == name : true)) {
5
- pos++;
6
- e = e.previousElementSibling;
7
- if (!e.previousElementSibling) {
8
- break;
9
- }
1
+ import { offset as offset$1, shift as shift$1, flip as flip$1, inline as inline$1, computePosition as computePosition$1 } from "./react-text-annotator.es31.js";
2
+ import { createCoords, rectToClientRect, round, floor, max, min } from "./react-text-annotator.es30.js";
3
+ import { getOverflowAncestors, isElement, getWindow, getFrameElement, getComputedStyle, getDocumentElement, isHTMLElement, isWebKit, isTopLayer, getNodeName, isOverflowElement, getNodeScroll, getParentNode, isLastTraversableNode, isTableElement, isContainingBlock, getContainingBlock } from "./react-text-annotator.es28.js";
4
+ function getCssDimensions(element) {
5
+ const css = getComputedStyle(element);
6
+ let width = parseFloat(css.width) || 0;
7
+ let height = parseFloat(css.height) || 0;
8
+ const hasOffset = isHTMLElement(element);
9
+ const offsetWidth = hasOffset ? element.offsetWidth : width;
10
+ const offsetHeight = hasOffset ? element.offsetHeight : height;
11
+ const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;
12
+ if (shouldFallback) {
13
+ width = offsetWidth;
14
+ height = offsetHeight;
10
15
  }
11
- return pos;
16
+ return {
17
+ width,
18
+ height,
19
+ $: shouldFallback
20
+ };
12
21
  }
13
- function copyAndReset(node) {
14
- const doc = node.ownerDocument;
15
- let clone = (n) => {
16
- let result;
17
- switch (n.nodeType) {
18
- case 1:
19
- result = doc.createElement(n.nodeName);
20
- break;
21
- case 9:
22
- result = doc.implementation.createDocument();
23
- break;
24
- case 11:
25
- result = doc.createDocumentFragment();
26
- break;
27
- default:
28
- result = n.cloneNode(true);
29
- }
30
- if (n.attributes) {
31
- for (let att of Array.from(n.attributes)) {
32
- if (att.name !== "data-processed") {
33
- result.setAttribute(att.name, att.value);
34
- }
35
- }
36
- }
37
- for (let nd of Array.from(n.childNodes)) {
38
- if (nd.nodeType == 1) {
39
- if (nd.hasAttribute("data-original")) {
40
- for (let childNode of Array.from(nd.childNodes)) {
41
- let child = result.appendChild(clone(childNode));
42
- if (child.nodeType === 1 && child.hasAttribute("data-origid")) {
43
- child.setAttribute("id", child.getAttribute("data-origid"));
44
- child.removeAttribute("data-origid");
45
- }
46
- }
47
- return result;
48
- } else if (nd.hasAttribute("data-origname")) {
49
- result.appendChild(clone(nd));
50
- }
51
- } else {
52
- result.appendChild(nd.cloneNode());
53
- }
54
- }
55
- return result;
22
+ function unwrapElement(element) {
23
+ return !isElement(element) ? element.contextElement : element;
24
+ }
25
+ function getScale(element) {
26
+ const domElement = unwrapElement(element);
27
+ if (!isHTMLElement(domElement)) {
28
+ return createCoords(1);
29
+ }
30
+ const rect = domElement.getBoundingClientRect();
31
+ const {
32
+ width,
33
+ height,
34
+ $
35
+ } = getCssDimensions(domElement);
36
+ let x = ($ ? round(rect.width) : rect.width) / width;
37
+ let y = ($ ? round(rect.height) : rect.height) / height;
38
+ if (!x || !Number.isFinite(x)) {
39
+ x = 1;
40
+ }
41
+ if (!y || !Number.isFinite(y)) {
42
+ y = 1;
43
+ }
44
+ return {
45
+ x,
46
+ y
56
47
  };
57
- return clone(node);
58
48
  }
59
- function first(urls) {
60
- return urls.replace(/ .*$/, "");
49
+ const noOffsets = /* @__PURE__ */ createCoords(0);
50
+ function getVisualOffsets(element) {
51
+ const win = getWindow(element);
52
+ if (!isWebKit() || !win.visualViewport) {
53
+ return noOffsets;
54
+ }
55
+ return {
56
+ x: win.visualViewport.offsetLeft,
57
+ y: win.visualViewport.offsetTop
58
+ };
61
59
  }
62
- function hideContent(elt, rewriteIds = true) {
63
- const doc = elt.ownerDocument;
64
- if (elt.childNodes.length > 0) {
65
- let hidden = doc.createElement("cetei-original");
66
- elt.appendChild(hidden);
67
- hidden.setAttribute("hidden", "");
68
- hidden.setAttribute("data-original", "");
69
- for (let node of Array.from(elt.childNodes)) {
70
- if (node !== hidden) {
71
- if (node.nodeType === 1) {
72
- node.setAttribute("data-processed", "");
73
- for (let e of node.querySelectorAll("*")) {
74
- e.setAttribute("data-processed", "");
75
- }
76
- }
77
- hidden.appendChild(elt.removeChild(node));
60
+ function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {
61
+ if (isFixed === void 0) {
62
+ isFixed = false;
63
+ }
64
+ if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) {
65
+ return false;
66
+ }
67
+ return isFixed;
68
+ }
69
+ function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {
70
+ if (includeScale === void 0) {
71
+ includeScale = false;
72
+ }
73
+ if (isFixedStrategy === void 0) {
74
+ isFixedStrategy = false;
75
+ }
76
+ const clientRect = element.getBoundingClientRect();
77
+ const domElement = unwrapElement(element);
78
+ let scale = createCoords(1);
79
+ if (includeScale) {
80
+ if (offsetParent) {
81
+ if (isElement(offsetParent)) {
82
+ scale = getScale(offsetParent);
78
83
  }
84
+ } else {
85
+ scale = getScale(element);
79
86
  }
80
- if (rewriteIds) {
81
- for (let e of Array.from(hidden.querySelectorAll("*"))) {
82
- if (e.hasAttribute("id")) {
83
- e.setAttribute("data-origid", e.getAttribute("id"));
84
- e.removeAttribute("id");
85
- }
86
- }
87
+ }
88
+ const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0);
89
+ let x = (clientRect.left + visualOffsets.x) / scale.x;
90
+ let y = (clientRect.top + visualOffsets.y) / scale.y;
91
+ let width = clientRect.width / scale.x;
92
+ let height = clientRect.height / scale.y;
93
+ if (domElement) {
94
+ const win = getWindow(domElement);
95
+ const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
96
+ let currentWin = win;
97
+ let currentIFrame = getFrameElement(currentWin);
98
+ while (currentIFrame && offsetParent && offsetWin !== currentWin) {
99
+ const iframeScale = getScale(currentIFrame);
100
+ const iframeRect = currentIFrame.getBoundingClientRect();
101
+ const css = getComputedStyle(currentIFrame);
102
+ const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
103
+ const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
104
+ x *= iframeScale.x;
105
+ y *= iframeScale.y;
106
+ width *= iframeScale.x;
107
+ height *= iframeScale.y;
108
+ x += left;
109
+ y += top;
110
+ currentWin = getWindow(currentIFrame);
111
+ currentIFrame = getFrameElement(currentWin);
87
112
  }
88
113
  }
114
+ return rectToClientRect({
115
+ width,
116
+ height,
117
+ x,
118
+ y
119
+ });
89
120
  }
90
- function normalizeURI(urls) {
91
- return this.rw(this.first(urls));
121
+ function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
122
+ let {
123
+ elements,
124
+ rect,
125
+ offsetParent,
126
+ strategy
127
+ } = _ref;
128
+ const isFixed = strategy === "fixed";
129
+ const documentElement = getDocumentElement(offsetParent);
130
+ const topLayer = elements ? isTopLayer(elements.floating) : false;
131
+ if (offsetParent === documentElement || topLayer && isFixed) {
132
+ return rect;
133
+ }
134
+ let scroll = {
135
+ scrollLeft: 0,
136
+ scrollTop: 0
137
+ };
138
+ let scale = createCoords(1);
139
+ const offsets = createCoords(0);
140
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
141
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
142
+ if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
143
+ scroll = getNodeScroll(offsetParent);
144
+ }
145
+ if (isHTMLElement(offsetParent)) {
146
+ const offsetRect = getBoundingClientRect(offsetParent);
147
+ scale = getScale(offsetParent);
148
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
149
+ offsets.y = offsetRect.y + offsetParent.clientTop;
150
+ }
151
+ }
152
+ return {
153
+ width: rect.width * scale.x,
154
+ height: rect.height * scale.y,
155
+ x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x,
156
+ y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y
157
+ };
92
158
  }
93
- function repeat(str, times) {
94
- let result = "";
95
- for (let i = 0; i < times; i++) {
96
- result += str;
159
+ function getClientRects(element) {
160
+ return Array.from(element.getClientRects());
161
+ }
162
+ function getWindowScrollBarX(element, rect) {
163
+ const leftScroll = getNodeScroll(element).scrollLeft;
164
+ if (!rect) {
165
+ return getBoundingClientRect(getDocumentElement(element)).left + leftScroll;
97
166
  }
98
- return result;
167
+ return rect.left + leftScroll;
99
168
  }
100
- function resolveURI(uri) {
101
- let prefixdef = this.prefixDefs[uri.substring(0, uri.indexOf(":"))];
102
- return uri.replace(new RegExp(prefixdef["matchPattern"]), prefixdef["replacementPattern"]);
169
+ function getDocumentRect(element) {
170
+ const html = getDocumentElement(element);
171
+ const scroll = getNodeScroll(element);
172
+ const body = element.ownerDocument.body;
173
+ const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);
174
+ const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
175
+ let x = -scroll.scrollLeft + getWindowScrollBarX(element);
176
+ const y = -scroll.scrollTop;
177
+ if (getComputedStyle(body).direction === "rtl") {
178
+ x += max(html.clientWidth, body.clientWidth) - width;
179
+ }
180
+ return {
181
+ width,
182
+ height,
183
+ x,
184
+ y
185
+ };
186
+ }
187
+ function getViewportRect(element, strategy) {
188
+ const win = getWindow(element);
189
+ const html = getDocumentElement(element);
190
+ const visualViewport = win.visualViewport;
191
+ let width = html.clientWidth;
192
+ let height = html.clientHeight;
193
+ let x = 0;
194
+ let y = 0;
195
+ if (visualViewport) {
196
+ width = visualViewport.width;
197
+ height = visualViewport.height;
198
+ const visualViewportBased = isWebKit();
199
+ if (!visualViewportBased || visualViewportBased && strategy === "fixed") {
200
+ x = visualViewport.offsetLeft;
201
+ y = visualViewport.offsetTop;
202
+ }
203
+ }
204
+ return {
205
+ width,
206
+ height,
207
+ x,
208
+ y
209
+ };
103
210
  }
104
- function getPrefixDef(prefix) {
105
- return this.prefixDefs[prefix];
211
+ function getInnerBoundingClientRect(element, strategy) {
212
+ const clientRect = getBoundingClientRect(element, true, strategy === "fixed");
213
+ const top = clientRect.top + element.clientTop;
214
+ const left = clientRect.left + element.clientLeft;
215
+ const scale = isHTMLElement(element) ? getScale(element) : createCoords(1);
216
+ const width = element.clientWidth * scale.x;
217
+ const height = element.clientHeight * scale.y;
218
+ const x = left * scale.x;
219
+ const y = top * scale.y;
220
+ return {
221
+ width,
222
+ height,
223
+ x,
224
+ y
225
+ };
106
226
  }
107
- function rw(url) {
108
- if (!url.match(/^(?:http|mailto|file|\/|#).*$/)) {
109
- return this.base + first(url);
227
+ function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {
228
+ let rect;
229
+ if (clippingAncestor === "viewport") {
230
+ rect = getViewportRect(element, strategy);
231
+ } else if (clippingAncestor === "document") {
232
+ rect = getDocumentRect(getDocumentElement(element));
233
+ } else if (isElement(clippingAncestor)) {
234
+ rect = getInnerBoundingClientRect(clippingAncestor, strategy);
110
235
  } else {
111
- return url;
236
+ const visualOffsets = getVisualOffsets(element);
237
+ rect = {
238
+ ...clippingAncestor,
239
+ x: clippingAncestor.x - visualOffsets.x,
240
+ y: clippingAncestor.y - visualOffsets.y
241
+ };
112
242
  }
243
+ return rectToClientRect(rect);
113
244
  }
114
- function resetAndSerialize(el, stripElt, ws) {
115
- return serialize(copyAndReset(el), stripElt, ws);
245
+ function hasFixedPositionAncestor(element, stopNode) {
246
+ const parentNode = getParentNode(element);
247
+ if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {
248
+ return false;
249
+ }
250
+ return getComputedStyle(parentNode).position === "fixed" || hasFixedPositionAncestor(parentNode, stopNode);
116
251
  }
117
- function serialize(el, stripElt, ws) {
118
- let str = "";
119
- const ignorable = (txt) => {
120
- return !/[^\t\n\r ]/.test(txt);
121
- };
122
- if (el.nodeType === 9 || el.nodeType === 11) {
123
- str += '<?xml version="1.0" encoding="UTF-8"?>\n';
252
+ function getClippingElementAncestors(element, cache) {
253
+ const cachedResult = cache.get(element);
254
+ if (cachedResult) {
255
+ return cachedResult;
124
256
  }
125
- if (!stripElt && el.nodeType == 1) {
126
- if (typeof ws === "string" && ws !== "") {
127
- str += "\n" + ws + "<";
128
- } else {
129
- str += "<";
257
+ let result = getOverflowAncestors(element, [], false).filter((el) => isElement(el) && getNodeName(el) !== "body");
258
+ let currentContainingBlockComputedStyle = null;
259
+ const elementIsFixed = getComputedStyle(element).position === "fixed";
260
+ let currentNode = elementIsFixed ? getParentNode(element) : element;
261
+ while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
262
+ const computedStyle = getComputedStyle(currentNode);
263
+ const currentNodeIsContaining = isContainingBlock(currentNode);
264
+ if (!currentNodeIsContaining && computedStyle.position === "fixed") {
265
+ currentContainingBlockComputedStyle = null;
130
266
  }
131
- str += el.getAttribute("data-origname");
132
- let attrNames = el.hasAttribute("data-origatts") ? el.getAttribute("data-origatts").split(" ") : [];
133
- for (let attr of Array.from(el.attributes)) {
134
- if (!attr.name.startsWith("data-") && !["id", "lang", "class"].includes(attr.name)) {
135
- str += " " + attrNames.find(function(e) {
136
- return e.toLowerCase() == attr.name;
137
- }) + '="' + attr.value + '"';
138
- }
139
- if (attr.name == "data-xmlns") {
140
- str += ' xmlns="' + attr.value + '"';
141
- }
142
- }
143
- if (el.childNodes.length > 0) {
144
- str += ">";
267
+ const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === "static" && !!currentContainingBlockComputedStyle && ["absolute", "fixed"].includes(currentContainingBlockComputedStyle.position) || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode);
268
+ if (shouldDropCurrentNode) {
269
+ result = result.filter((ancestor) => ancestor !== currentNode);
145
270
  } else {
146
- str += "/>";
271
+ currentContainingBlockComputedStyle = computedStyle;
147
272
  }
273
+ currentNode = getParentNode(currentNode);
148
274
  }
149
- for (let node of Array.from(el.childNodes)) {
150
- switch (node.nodeType) {
151
- case 1:
152
- if (typeof ws === "string") {
153
- str += serialize(node, false, ws + " ");
154
- } else {
155
- str += serialize(node, false, ws);
156
- }
157
- break;
158
- case 7:
159
- str += `<?${node.nodeName} ${node.nodeValue}?>`;
160
- if (el.nodeType === 9 || el.nodeType === 11) {
161
- str += "\n";
162
- }
163
- break;
164
- case 8:
165
- str += `<!--${node.nodeValue}-->`;
166
- if (el.nodeType === 9 || el.nodeType === 11) {
167
- str += "\n";
168
- }
169
- break;
170
- default:
171
- if (stripElt && ignorable(node.nodeValue)) {
172
- str += node.nodeValue.replace(/^\s*\n/, "");
173
- }
174
- if (typeof ws === "string" && ignorable(node.nodeValue)) {
175
- break;
176
- }
177
- str += node.nodeValue;
275
+ cache.set(element, result);
276
+ return result;
277
+ }
278
+ function getClippingRect(_ref) {
279
+ let {
280
+ element,
281
+ boundary,
282
+ rootBoundary,
283
+ strategy
284
+ } = _ref;
285
+ const elementClippingAncestors = boundary === "clippingAncestors" ? isTopLayer(element) ? [] : getClippingElementAncestors(element, this._c) : [].concat(boundary);
286
+ const clippingAncestors = [...elementClippingAncestors, rootBoundary];
287
+ const firstClippingAncestor = clippingAncestors[0];
288
+ const clippingRect = clippingAncestors.reduce((accRect, clippingAncestor) => {
289
+ const rect = getClientRectFromClippingAncestor(element, clippingAncestor, strategy);
290
+ accRect.top = max(rect.top, accRect.top);
291
+ accRect.right = min(rect.right, accRect.right);
292
+ accRect.bottom = min(rect.bottom, accRect.bottom);
293
+ accRect.left = max(rect.left, accRect.left);
294
+ return accRect;
295
+ }, getClientRectFromClippingAncestor(element, firstClippingAncestor, strategy));
296
+ return {
297
+ width: clippingRect.right - clippingRect.left,
298
+ height: clippingRect.bottom - clippingRect.top,
299
+ x: clippingRect.left,
300
+ y: clippingRect.top
301
+ };
302
+ }
303
+ function getDimensions(element) {
304
+ const {
305
+ width,
306
+ height
307
+ } = getCssDimensions(element);
308
+ return {
309
+ width,
310
+ height
311
+ };
312
+ }
313
+ function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
314
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
315
+ const documentElement = getDocumentElement(offsetParent);
316
+ const isFixed = strategy === "fixed";
317
+ const rect = getBoundingClientRect(element, true, isFixed, offsetParent);
318
+ let scroll = {
319
+ scrollLeft: 0,
320
+ scrollTop: 0
321
+ };
322
+ const offsets = createCoords(0);
323
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
324
+ if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
325
+ scroll = getNodeScroll(offsetParent);
178
326
  }
179
- }
180
- if (!stripElt && el.nodeType == 1 && el.childNodes.length > 0) {
181
- if (typeof ws === "string") {
182
- str += "\n" + ws + "</";
183
- } else {
184
- str += "</";
327
+ if (isOffsetParentAnElement) {
328
+ const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
329
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
330
+ offsets.y = offsetRect.y + offsetParent.clientTop;
331
+ } else if (documentElement) {
332
+ offsets.x = getWindowScrollBarX(documentElement);
185
333
  }
186
- str += el.getAttribute("data-origname") + ">";
187
334
  }
188
- if (el.nodeType === 9 || el.nodeType === 11) {
189
- str += "\n";
335
+ let htmlX = 0;
336
+ let htmlY = 0;
337
+ if (documentElement && !isOffsetParentAnElement && !isFixed) {
338
+ const htmlRect = documentElement.getBoundingClientRect();
339
+ htmlY = htmlRect.top + scroll.scrollTop;
340
+ htmlX = htmlRect.left + scroll.scrollLeft - // RTL <body> scrollbar.
341
+ getWindowScrollBarX(documentElement, htmlRect);
190
342
  }
191
- return str;
192
- }
193
- function serializeHTML(el, stripElt, ws) {
194
- const EMPTY_ELEMENTS = ["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"];
195
- let str = "";
196
- const ignorable = (txt) => {
197
- return !/[^\t\n\r ]/.test(txt);
343
+ const x = rect.left + scroll.scrollLeft - offsets.x - htmlX;
344
+ const y = rect.top + scroll.scrollTop - offsets.y - htmlY;
345
+ return {
346
+ x,
347
+ y,
348
+ width: rect.width,
349
+ height: rect.height
198
350
  };
199
- if (!stripElt && el.nodeType == 1) {
200
- if (typeof ws === "string" && ws !== "") {
201
- str += "\n" + ws + "<";
202
- } else {
203
- str += "<";
204
- }
205
- str += el.nodeName;
206
- for (let attr of Array.from(el.attributes)) {
207
- str += " " + attr.name + '="' + attr.value + '"';
208
- }
209
- str += ">";
351
+ }
352
+ function isStaticPositioned(element) {
353
+ return getComputedStyle(element).position === "static";
354
+ }
355
+ function getTrueOffsetParent(element, polyfill) {
356
+ if (!isHTMLElement(element) || getComputedStyle(element).position === "fixed") {
357
+ return null;
210
358
  }
211
- for (let node of Array.from(el.childNodes)) {
212
- switch (node.nodeType) {
213
- case 1:
214
- if (typeof ws === "string") {
215
- str += serializeHTML(node, false, ws + " ");
216
- } else {
217
- str += serializeHTML(node, false, ws);
218
- }
219
- break;
220
- case 7:
221
- str += `<?${node.nodeName} ${node.nodeValue}?>`;
222
- if (el.nodeType === 9 || el.nodeType === 11) {
223
- str += "\n";
224
- }
225
- break;
226
- case 8:
227
- str += `<!--${node.nodeValue}-->`;
228
- if (el.nodeType === 9 || el.nodeType === 11) {
229
- str += "\n";
230
- }
231
- break;
232
- default:
233
- if (stripElt && ignorable(node.nodeValue)) {
234
- str += node.nodeValue.replace(/^\s*\n/, "");
235
- }
236
- if (typeof ws === "string" && ignorable(node.nodeValue)) {
237
- break;
238
- }
239
- str += node.nodeValue.replace(/</g, "&lt;");
240
- }
359
+ if (polyfill) {
360
+ return polyfill(element);
361
+ }
362
+ let rawOffsetParent = element.offsetParent;
363
+ if (getDocumentElement(element) === rawOffsetParent) {
364
+ rawOffsetParent = rawOffsetParent.ownerDocument.body;
365
+ }
366
+ return rawOffsetParent;
367
+ }
368
+ function getOffsetParent(element, polyfill) {
369
+ const win = getWindow(element);
370
+ if (isTopLayer(element)) {
371
+ return win;
241
372
  }
242
- if (!EMPTY_ELEMENTS.includes(el.nodeName)) {
243
- if (!stripElt && el.nodeType == 1) {
244
- if (typeof ws === "string") {
245
- str += `
246
- ${ws}</`;
247
- } else {
248
- str += "</";
373
+ if (!isHTMLElement(element)) {
374
+ let svgOffsetParent = getParentNode(element);
375
+ while (svgOffsetParent && !isLastTraversableNode(svgOffsetParent)) {
376
+ if (isElement(svgOffsetParent) && !isStaticPositioned(svgOffsetParent)) {
377
+ return svgOffsetParent;
249
378
  }
250
- str += `${el.nodeName}>`;
379
+ svgOffsetParent = getParentNode(svgOffsetParent);
251
380
  }
381
+ return win;
382
+ }
383
+ let offsetParent = getTrueOffsetParent(element, polyfill);
384
+ while (offsetParent && isTableElement(offsetParent) && isStaticPositioned(offsetParent)) {
385
+ offsetParent = getTrueOffsetParent(offsetParent, polyfill);
252
386
  }
253
- if (el.nodeType === 9 || el.nodeType === 11) {
254
- str += "\n";
387
+ if (offsetParent && isLastTraversableNode(offsetParent) && isStaticPositioned(offsetParent) && !isContainingBlock(offsetParent)) {
388
+ return win;
255
389
  }
256
- return str;
390
+ return offsetParent || getContainingBlock(element) || win;
257
391
  }
258
- function unEscapeEntities(str) {
259
- return str.replace(/&gt;/, ">").replace(/&quot;/, '"').replace(/&apos;/, "'").replace(/&amp;/, "&");
392
+ const getElementRects = async function(data) {
393
+ const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
394
+ const getDimensionsFn = this.getDimensions;
395
+ const floatingDimensions = await getDimensionsFn(data.floating);
396
+ return {
397
+ reference: getRectRelativeToOffsetParent(data.reference, await getOffsetParentFn(data.floating), data.strategy),
398
+ floating: {
399
+ x: 0,
400
+ y: 0,
401
+ width: floatingDimensions.width,
402
+ height: floatingDimensions.height
403
+ }
404
+ };
405
+ };
406
+ function isRTL(element) {
407
+ return getComputedStyle(element).direction === "rtl";
260
408
  }
261
- function tagName(name) {
262
- if (name.includes(":"), 1) {
263
- return name.replace(/:/, "-").toLowerCase();
409
+ const platform = {
410
+ convertOffsetParentRelativeRectToViewportRelativeRect,
411
+ getDocumentElement,
412
+ getClippingRect,
413
+ getOffsetParent,
414
+ getElementRects,
415
+ getClientRects,
416
+ getDimensions,
417
+ getScale,
418
+ isElement,
419
+ isRTL
420
+ };
421
+ function observeMove(element, onMove) {
422
+ let io = null;
423
+ let timeoutId;
424
+ const root = getDocumentElement(element);
425
+ function cleanup() {
426
+ var _io;
427
+ clearTimeout(timeoutId);
428
+ (_io = io) == null || _io.disconnect();
429
+ io = null;
264
430
  }
265
- }
266
- function defineCustomElement(name, behavior = null, debug = false) {
267
- try {
268
- window.customElements.define(tagName(name), class extends HTMLElement {
269
- constructor() {
270
- super();
271
- if (!this.matches(":defined")) {
272
- if (behavior) {
273
- behavior.call(this);
274
- this.setAttribute("data-processed", "");
275
- }
431
+ function refresh(skip, threshold) {
432
+ if (skip === void 0) {
433
+ skip = false;
434
+ }
435
+ if (threshold === void 0) {
436
+ threshold = 1;
437
+ }
438
+ cleanup();
439
+ const {
440
+ left,
441
+ top,
442
+ width,
443
+ height
444
+ } = element.getBoundingClientRect();
445
+ if (!skip) {
446
+ onMove();
447
+ }
448
+ if (!width || !height) {
449
+ return;
450
+ }
451
+ const insetTop = floor(top);
452
+ const insetRight = floor(root.clientWidth - (left + width));
453
+ const insetBottom = floor(root.clientHeight - (top + height));
454
+ const insetLeft = floor(left);
455
+ const rootMargin = -insetTop + "px " + -insetRight + "px " + -insetBottom + "px " + -insetLeft + "px";
456
+ const options = {
457
+ rootMargin,
458
+ threshold: max(0, min(1, threshold)) || 1
459
+ };
460
+ let isFirstUpdate = true;
461
+ function handleObserve(entries) {
462
+ const ratio = entries[0].intersectionRatio;
463
+ if (ratio !== threshold) {
464
+ if (!isFirstUpdate) {
465
+ return refresh();
276
466
  }
277
- }
278
- // Process new elements when they are connected to the browser DOM
279
- connectedCallback() {
280
- if (!this.hasAttribute("data-processed")) {
281
- if (behavior) {
282
- behavior.call(this);
283
- this.setAttribute("data-processed", "");
284
- }
467
+ if (!ratio) {
468
+ timeoutId = setTimeout(() => {
469
+ refresh(false, 1e-7);
470
+ }, 1e3);
471
+ } else {
472
+ refresh(false, ratio);
285
473
  }
286
474
  }
475
+ isFirstUpdate = false;
476
+ }
477
+ try {
478
+ io = new IntersectionObserver(handleObserve, {
479
+ ...options,
480
+ // Handle <iframe>s
481
+ root: root.ownerDocument
482
+ });
483
+ } catch (e) {
484
+ io = new IntersectionObserver(handleObserve, options);
485
+ }
486
+ io.observe(element);
487
+ }
488
+ refresh(true);
489
+ return cleanup;
490
+ }
491
+ function autoUpdate(reference, floating, update, options) {
492
+ if (options === void 0) {
493
+ options = {};
494
+ }
495
+ const {
496
+ ancestorScroll = true,
497
+ ancestorResize = true,
498
+ elementResize = typeof ResizeObserver === "function",
499
+ layoutShift = typeof IntersectionObserver === "function",
500
+ animationFrame = false
501
+ } = options;
502
+ const referenceEl = unwrapElement(reference);
503
+ const ancestors = ancestorScroll || ancestorResize ? [...referenceEl ? getOverflowAncestors(referenceEl) : [], ...getOverflowAncestors(floating)] : [];
504
+ ancestors.forEach((ancestor) => {
505
+ ancestorScroll && ancestor.addEventListener("scroll", update, {
506
+ passive: true
507
+ });
508
+ ancestorResize && ancestor.addEventListener("resize", update);
509
+ });
510
+ const cleanupIo = referenceEl && layoutShift ? observeMove(referenceEl, update) : null;
511
+ let reobserveFrame = -1;
512
+ let resizeObserver = null;
513
+ if (elementResize) {
514
+ resizeObserver = new ResizeObserver((_ref) => {
515
+ let [firstEntry] = _ref;
516
+ if (firstEntry && firstEntry.target === referenceEl && resizeObserver) {
517
+ resizeObserver.unobserve(floating);
518
+ cancelAnimationFrame(reobserveFrame);
519
+ reobserveFrame = requestAnimationFrame(() => {
520
+ var _resizeObserver;
521
+ (_resizeObserver = resizeObserver) == null || _resizeObserver.observe(floating);
522
+ });
523
+ }
524
+ update();
287
525
  });
288
- } catch (error) {
289
- if (debug) {
290
- console.log(tagName(name) + " couldn't be registered or is already registered.");
291
- console.log(error);
526
+ if (referenceEl && !animationFrame) {
527
+ resizeObserver.observe(referenceEl);
528
+ }
529
+ resizeObserver.observe(floating);
530
+ }
531
+ let frameId;
532
+ let prevRefRect = animationFrame ? getBoundingClientRect(reference) : null;
533
+ if (animationFrame) {
534
+ frameLoop();
535
+ }
536
+ function frameLoop() {
537
+ const nextRefRect = getBoundingClientRect(reference);
538
+ if (prevRefRect && (nextRefRect.x !== prevRefRect.x || nextRefRect.y !== prevRefRect.y || nextRefRect.width !== prevRefRect.width || nextRefRect.height !== prevRefRect.height)) {
539
+ update();
292
540
  }
541
+ prevRefRect = nextRefRect;
542
+ frameId = requestAnimationFrame(frameLoop);
293
543
  }
544
+ update();
545
+ return () => {
546
+ var _resizeObserver2;
547
+ ancestors.forEach((ancestor) => {
548
+ ancestorScroll && ancestor.removeEventListener("scroll", update);
549
+ ancestorResize && ancestor.removeEventListener("resize", update);
550
+ });
551
+ cleanupIo == null || cleanupIo();
552
+ (_resizeObserver2 = resizeObserver) == null || _resizeObserver2.disconnect();
553
+ resizeObserver = null;
554
+ if (animationFrame) {
555
+ cancelAnimationFrame(frameId);
556
+ }
557
+ };
294
558
  }
559
+ const offset = offset$1;
560
+ const shift = shift$1;
561
+ const flip = flip$1;
562
+ const inline = inline$1;
563
+ const computePosition = (reference, floating, options) => {
564
+ const cache = /* @__PURE__ */ new Map();
565
+ const mergedOptions = {
566
+ platform,
567
+ ...options
568
+ };
569
+ const platformWithCache = {
570
+ ...mergedOptions.platform,
571
+ _c: cache
572
+ };
573
+ return computePosition$1(reference, floating, {
574
+ ...mergedOptions,
575
+ platform: platformWithCache
576
+ });
577
+ };
295
578
  export {
296
- copyAndReset,
297
- defineCustomElement,
298
- first,
299
- getOrdinality,
300
- getPrefixDef,
301
- hideContent,
302
- normalizeURI,
303
- repeat,
304
- resetAndSerialize,
305
- resolveURI,
306
- rw,
307
- serialize,
308
- serializeHTML,
309
- tagName,
310
- unEscapeEntities
579
+ autoUpdate,
580
+ computePosition,
581
+ flip,
582
+ getOverflowAncestors,
583
+ inline,
584
+ offset,
585
+ platform,
586
+ shift
311
587
  };
312
588
  //# sourceMappingURL=react-text-annotator.es15.js.map