@soomo/react-text-annotator 3.0.0-staging.9 → 3.1.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 (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 +5 -2
  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 +442 -521
  20. package/dist/react-text-annotator.es10.js.map +1 -1
  21. package/dist/react-text-annotator.es11.js +9 -488
  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 +238 -891
  26. package/dist/react-text-annotator.es14.js.map +1 -1
  27. package/dist/react-text-annotator.es15.js +554 -197
  28. package/dist/react-text-annotator.es15.js.map +1 -1
  29. package/dist/react-text-annotator.es16.js +72 -126
  30. package/dist/react-text-annotator.es16.js.map +1 -1
  31. package/dist/react-text-annotator.es17.js +43 -112
  32. package/dist/react-text-annotator.es17.js.map +1 -1
  33. package/dist/react-text-annotator.es18.js +2 -309
  34. package/dist/react-text-annotator.es18.js.map +1 -1
  35. package/dist/react-text-annotator.es19.js +29 -56
  36. package/dist/react-text-annotator.es19.js.map +1 -1
  37. package/dist/react-text-annotator.es2.js +2 -2
  38. package/dist/react-text-annotator.es20.js +897 -19
  39. package/dist/react-text-annotator.es20.js.map +1 -1
  40. package/dist/react-text-annotator.es23.js +113 -120
  41. package/dist/react-text-annotator.es23.js.map +1 -1
  42. package/dist/react-text-annotator.es24.js +276 -519
  43. package/dist/react-text-annotator.es24.js.map +1 -1
  44. package/dist/react-text-annotator.es25.js +61 -0
  45. package/dist/react-text-annotator.es25.js.map +1 -0
  46. package/dist/react-text-annotator.es26.js +23 -0
  47. package/dist/react-text-annotator.es26.js.map +1 -0
  48. package/dist/react-text-annotator.es27.js +130 -0
  49. package/dist/react-text-annotator.es27.js.map +1 -0
  50. package/dist/react-text-annotator.es28.js +167 -0
  51. package/dist/react-text-annotator.es28.js.map +1 -0
  52. package/dist/react-text-annotator.es29.js +314 -0
  53. package/dist/react-text-annotator.es29.js.map +1 -0
  54. package/dist/react-text-annotator.es3.js +2 -2
  55. package/dist/react-text-annotator.es30.js +152 -0
  56. package/dist/react-text-annotator.es30.js.map +1 -0
  57. package/dist/react-text-annotator.es31.js +566 -0
  58. package/dist/react-text-annotator.es31.js.map +1 -0
  59. package/dist/react-text-annotator.es4.js +38 -28
  60. package/dist/react-text-annotator.es4.js.map +1 -1
  61. package/dist/react-text-annotator.es5.js +24 -72
  62. package/dist/react-text-annotator.es5.js.map +1 -1
  63. package/dist/react-text-annotator.es6.js +127 -10
  64. package/dist/react-text-annotator.es6.js.map +1 -1
  65. package/dist/react-text-annotator.es7.js +546 -1
  66. package/dist/react-text-annotator.es7.js.map +1 -1
  67. package/dist/react-text-annotator.es8.js +10 -24
  68. package/dist/react-text-annotator.es8.js.map +1 -1
  69. package/dist/tei/TEIAnnotator.d.ts +2 -3
  70. package/package.json +23 -17
  71. package/dist/TextAnnotatorPopup.d.ts +0 -15
  72. package/dist/TextAnnotatorPopup.d.ts.map +0 -1
  73. package/dist/react-text-annotator.es13.js +0 -38
  74. package/dist/react-text-annotator.es13.js.map +0 -1
  75. package/dist/react-text-annotator.es9.js +0 -199
  76. package/dist/react-text-annotator.es9.js.map +0 -1
  77. package/dist/utils.d.ts +0 -14
  78. package/dist/utils.d.ts.map +0 -1
@@ -1,555 +1,312 @@
1
- import { evaluate, placements, getAlignmentSides, getSide, getAlignment, rectToClientRect, getPaddingObject, getSideAxis, clamp, getOppositeAlignmentPlacement, min, max, getOppositeAxis, getAlignmentAxis, getAxisLength } from "./react-text-annotator.es23.js";
2
- function computeCoordsFromPlacement(_ref, placement, rtl) {
3
- let {
4
- reference,
5
- floating
6
- } = _ref;
7
- const sideAxis = getSideAxis(placement);
8
- const alignmentAxis = getAlignmentAxis(placement);
9
- const alignLength = getAxisLength(alignmentAxis);
10
- const side = getSide(placement);
11
- const isVertical = sideAxis === "y";
12
- const commonX = reference.x + reference.width / 2 - floating.width / 2;
13
- const commonY = reference.y + reference.height / 2 - floating.height / 2;
14
- const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
15
- let coords;
16
- switch (side) {
17
- case "top":
18
- coords = {
19
- x: commonX,
20
- y: reference.y - floating.height
21
- };
22
- break;
23
- case "bottom":
24
- coords = {
25
- x: commonX,
26
- y: reference.y + reference.height
27
- };
28
- break;
29
- case "right":
30
- coords = {
31
- x: reference.x + reference.width,
32
- y: commonY
33
- };
34
- break;
35
- case "left":
36
- coords = {
37
- x: reference.x - floating.width,
38
- y: commonY
39
- };
40
- break;
41
- default:
42
- coords = {
43
- x: reference.x,
44
- y: reference.y
45
- };
46
- }
47
- switch (getAlignment(placement)) {
48
- case "start":
49
- coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
50
- break;
51
- case "end":
52
- coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
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) {
53
8
  break;
9
+ }
54
10
  }
55
- return coords;
11
+ return pos;
56
12
  }
57
- const computePosition = async (reference, floating, config) => {
58
- const {
59
- placement = "bottom",
60
- strategy = "absolute",
61
- middleware = [],
62
- platform
63
- } = config;
64
- const validMiddleware = middleware.filter(Boolean);
65
- const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(floating));
66
- let rects = await platform.getElementRects({
67
- reference,
68
- floating,
69
- strategy
70
- });
71
- let {
72
- x,
73
- y
74
- } = computeCoordsFromPlacement(rects, placement, rtl);
75
- let statefulPlacement = placement;
76
- let middlewareData = {};
77
- let resetCount = 0;
78
- for (let i = 0; i < validMiddleware.length; i++) {
79
- const {
80
- name,
81
- fn
82
- } = validMiddleware[i];
83
- const {
84
- x: nextX,
85
- y: nextY,
86
- data,
87
- reset
88
- } = await fn({
89
- x,
90
- y,
91
- initialPlacement: placement,
92
- placement: statefulPlacement,
93
- strategy,
94
- middlewareData,
95
- rects,
96
- platform,
97
- elements: {
98
- reference,
99
- floating
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
+ }
100
35
  }
101
- });
102
- x = nextX != null ? nextX : x;
103
- y = nextY != null ? nextY : y;
104
- middlewareData = {
105
- ...middlewareData,
106
- [name]: {
107
- ...middlewareData[name],
108
- ...data
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());
109
53
  }
110
- };
111
- if (reset && resetCount <= 50) {
112
- resetCount++;
113
- if (typeof reset === "object") {
114
- if (reset.placement) {
115
- statefulPlacement = reset.placement;
54
+ }
55
+ return result;
56
+ };
57
+ return clone(node);
58
+ }
59
+ function first(urls) {
60
+ return urls.replace(/ .*$/, "");
61
+ }
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
+ }
116
76
  }
117
- if (reset.rects) {
118
- rects = reset.rects === true ? await platform.getElementRects({
119
- reference,
120
- floating,
121
- strategy
122
- }) : reset.rects;
77
+ hidden.appendChild(elt.removeChild(node));
78
+ }
79
+ }
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");
123
85
  }
124
- ({
125
- x,
126
- y
127
- } = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
128
86
  }
129
- i = -1;
130
87
  }
131
88
  }
132
- return {
133
- x,
134
- y,
135
- placement: statefulPlacement,
136
- strategy,
137
- middlewareData
138
- };
139
- };
140
- async function detectOverflow(state, options) {
141
- var _await$platform$isEle;
142
- if (options === void 0) {
143
- options = {};
89
+ }
90
+ function normalizeURI(urls) {
91
+ return this.rw(this.first(urls));
92
+ }
93
+ function repeat(str, times) {
94
+ let result = "";
95
+ for (let i = 0; i < times; i++) {
96
+ result += str;
144
97
  }
145
- const {
146
- x,
147
- y,
148
- platform,
149
- rects,
150
- elements,
151
- strategy
152
- } = state;
153
- const {
154
- boundary = "clippingAncestors",
155
- rootBoundary = "viewport",
156
- elementContext = "floating",
157
- altBoundary = false,
158
- padding = 0
159
- } = evaluate(options, state);
160
- const paddingObject = getPaddingObject(padding);
161
- const altContext = elementContext === "floating" ? "reference" : "floating";
162
- const element = elements[altBoundary ? altContext : elementContext];
163
- const clippingClientRect = rectToClientRect(await platform.getClippingRect({
164
- element: ((_await$platform$isEle = await (platform.isElement == null ? void 0 : platform.isElement(element))) != null ? _await$platform$isEle : true) ? element : element.contextElement || await (platform.getDocumentElement == null ? void 0 : platform.getDocumentElement(elements.floating)),
165
- boundary,
166
- rootBoundary,
167
- strategy
168
- }));
169
- const rect = elementContext === "floating" ? {
170
- x,
171
- y,
172
- width: rects.floating.width,
173
- height: rects.floating.height
174
- } : rects.reference;
175
- const offsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(elements.floating));
176
- const offsetScale = await (platform.isElement == null ? void 0 : platform.isElement(offsetParent)) ? await (platform.getScale == null ? void 0 : platform.getScale(offsetParent)) || {
177
- x: 1,
178
- y: 1
179
- } : {
180
- x: 1,
181
- y: 1
182
- };
183
- const elementClientRect = rectToClientRect(platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
184
- elements,
185
- rect,
186
- offsetParent,
187
- strategy
188
- }) : rect);
189
- return {
190
- top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
191
- bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
192
- left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
193
- right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
194
- };
98
+ return result;
195
99
  }
196
- function getPlacementList(alignment, autoAlignment, allowedPlacements) {
197
- const allowedPlacementsSortedByAlignment = alignment ? [...allowedPlacements.filter((placement) => getAlignment(placement) === alignment), ...allowedPlacements.filter((placement) => getAlignment(placement) !== alignment)] : allowedPlacements.filter((placement) => getSide(placement) === placement);
198
- return allowedPlacementsSortedByAlignment.filter((placement) => {
199
- if (alignment) {
200
- return getAlignment(placement) === alignment || (autoAlignment ? getOppositeAlignmentPlacement(placement) !== placement : false);
201
- }
202
- return true;
203
- });
100
+ function resolveURI(uri) {
101
+ let prefixdef = this.prefixDefs[uri.substring(0, uri.indexOf(":"))];
102
+ return uri.replace(new RegExp(prefixdef["matchPattern"]), prefixdef["replacementPattern"]);
103
+ }
104
+ function getPrefixDef(prefix) {
105
+ return this.prefixDefs[prefix];
204
106
  }
205
- const autoPlacement = function(options) {
206
- if (options === void 0) {
207
- options = {};
107
+ function rw(url) {
108
+ if (!url.match(/^(?:http|mailto|file|\/|#).*$/)) {
109
+ return this.base + first(url);
110
+ } else {
111
+ return url;
208
112
  }
209
- return {
210
- name: "autoPlacement",
211
- options,
212
- async fn(state) {
213
- var _middlewareData$autoP, _middlewareData$autoP2, _placementsThatFitOnE;
214
- const {
215
- rects,
216
- middlewareData,
217
- placement,
218
- platform,
219
- elements
220
- } = state;
221
- const {
222
- crossAxis = false,
223
- alignment,
224
- allowedPlacements = placements,
225
- autoAlignment = true,
226
- ...detectOverflowOptions
227
- } = evaluate(options, state);
228
- const placements$1 = alignment !== void 0 || allowedPlacements === placements ? getPlacementList(alignment || null, autoAlignment, allowedPlacements) : allowedPlacements;
229
- const overflow = await detectOverflow(state, detectOverflowOptions);
230
- const currentIndex = ((_middlewareData$autoP = middlewareData.autoPlacement) == null ? void 0 : _middlewareData$autoP.index) || 0;
231
- const currentPlacement = placements$1[currentIndex];
232
- if (currentPlacement == null) {
233
- return {};
234
- }
235
- const alignmentSides = getAlignmentSides(currentPlacement, rects, await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating)));
236
- if (placement !== currentPlacement) {
237
- return {
238
- reset: {
239
- placement: placements$1[0]
240
- }
241
- };
242
- }
243
- const currentOverflows = [overflow[getSide(currentPlacement)], overflow[alignmentSides[0]], overflow[alignmentSides[1]]];
244
- const allOverflows = [...((_middlewareData$autoP2 = middlewareData.autoPlacement) == null ? void 0 : _middlewareData$autoP2.overflows) || [], {
245
- placement: currentPlacement,
246
- overflows: currentOverflows
247
- }];
248
- const nextPlacement = placements$1[currentIndex + 1];
249
- if (nextPlacement) {
250
- return {
251
- data: {
252
- index: currentIndex + 1,
253
- overflows: allOverflows
254
- },
255
- reset: {
256
- placement: nextPlacement
257
- }
258
- };
113
+ }
114
+ function resetAndSerialize(el, stripElt, ws) {
115
+ return serialize(copyAndReset(el), stripElt, ws);
116
+ }
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';
124
+ }
125
+ if (!stripElt && el.nodeType == 1) {
126
+ if (typeof ws === "string" && ws !== "") {
127
+ str += "\n" + ws + "<";
128
+ } else {
129
+ str += "<";
130
+ }
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 + '"';
259
138
  }
260
- const placementsSortedByMostSpace = allOverflows.map((d) => {
261
- const alignment2 = getAlignment(d.placement);
262
- return [d.placement, alignment2 && crossAxis ? (
263
- // Check along the mainAxis and main crossAxis side.
264
- d.overflows.slice(0, 2).reduce((acc, v) => acc + v, 0)
265
- ) : (
266
- // Check only the mainAxis.
267
- d.overflows[0]
268
- ), d.overflows];
269
- }).sort((a, b) => a[1] - b[1]);
270
- const placementsThatFitOnEachSide = placementsSortedByMostSpace.filter((d) => d[2].slice(
271
- 0,
272
- // Aligned placements should not check their opposite crossAxis
273
- // side.
274
- getAlignment(d[0]) ? 2 : 3
275
- ).every((v) => v <= 0));
276
- const resetPlacement = ((_placementsThatFitOnE = placementsThatFitOnEachSide[0]) == null ? void 0 : _placementsThatFitOnE[0]) || placementsSortedByMostSpace[0][0];
277
- if (resetPlacement !== placement) {
278
- return {
279
- data: {
280
- index: currentIndex + 1,
281
- overflows: allOverflows
282
- },
283
- reset: {
284
- placement: resetPlacement
285
- }
286
- };
139
+ if (attr.name == "data-xmlns") {
140
+ str += ' xmlns="' + attr.value + '"';
287
141
  }
288
- return {};
289
142
  }
290
- };
291
- };
292
- function getBoundingRect(rects) {
293
- const minX = min(...rects.map((rect) => rect.left));
294
- const minY = min(...rects.map((rect) => rect.top));
295
- const maxX = max(...rects.map((rect) => rect.right));
296
- const maxY = max(...rects.map((rect) => rect.bottom));
297
- return {
298
- x: minX,
299
- y: minY,
300
- width: maxX - minX,
301
- height: maxY - minY
302
- };
303
- }
304
- function getRectsByLine(rects) {
305
- const sortedRects = rects.slice().sort((a, b) => a.y - b.y);
306
- const groups = [];
307
- let prevRect = null;
308
- for (let i = 0; i < sortedRects.length; i++) {
309
- const rect = sortedRects[i];
310
- if (!prevRect || rect.y - prevRect.y > prevRect.height / 2) {
311
- groups.push([rect]);
143
+ if (el.childNodes.length > 0) {
144
+ str += ">";
312
145
  } else {
313
- groups[groups.length - 1].push(rect);
146
+ str += "/>";
314
147
  }
315
- prevRect = rect;
316
- }
317
- return groups.map((rect) => rectToClientRect(getBoundingRect(rect)));
318
- }
319
- const inline = function(options) {
320
- if (options === void 0) {
321
- options = {};
322
148
  }
323
- return {
324
- name: "inline",
325
- options,
326
- async fn(state) {
327
- const {
328
- placement,
329
- elements,
330
- rects,
331
- platform,
332
- strategy
333
- } = state;
334
- const {
335
- padding = 2,
336
- x,
337
- y
338
- } = evaluate(options, state);
339
- const nativeClientRects = Array.from(await (platform.getClientRects == null ? void 0 : platform.getClientRects(elements.reference)) || []);
340
- const clientRects = getRectsByLine(nativeClientRects);
341
- const fallback = rectToClientRect(getBoundingRect(nativeClientRects));
342
- const paddingObject = getPaddingObject(padding);
343
- function getBoundingClientRect() {
344
- if (clientRects.length === 2 && clientRects[0].left > clientRects[1].right && x != null && y != null) {
345
- return clientRects.find((rect) => x > rect.left - paddingObject.left && x < rect.right + paddingObject.right && y > rect.top - paddingObject.top && y < rect.bottom + paddingObject.bottom) || fallback;
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);
346
156
  }
347
- if (clientRects.length >= 2) {
348
- if (getSideAxis(placement) === "y") {
349
- const firstRect = clientRects[0];
350
- const lastRect = clientRects[clientRects.length - 1];
351
- const isTop = getSide(placement) === "top";
352
- const top2 = firstRect.top;
353
- const bottom2 = lastRect.bottom;
354
- const left2 = isTop ? firstRect.left : lastRect.left;
355
- const right2 = isTop ? firstRect.right : lastRect.right;
356
- const width2 = right2 - left2;
357
- const height2 = bottom2 - top2;
358
- return {
359
- top: top2,
360
- bottom: bottom2,
361
- left: left2,
362
- right: right2,
363
- width: width2,
364
- height: height2,
365
- x: left2,
366
- y: top2
367
- };
368
- }
369
- const isLeftSide = getSide(placement) === "left";
370
- const maxRight = max(...clientRects.map((rect) => rect.right));
371
- const minLeft = min(...clientRects.map((rect) => rect.left));
372
- const measureRects = clientRects.filter((rect) => isLeftSide ? rect.left === minLeft : rect.right === maxRight);
373
- const top = measureRects[0].top;
374
- const bottom = measureRects[measureRects.length - 1].bottom;
375
- const left = minLeft;
376
- const right = maxRight;
377
- const width = right - left;
378
- const height = bottom - top;
379
- return {
380
- top,
381
- bottom,
382
- left,
383
- right,
384
- width,
385
- height,
386
- x: left,
387
- y: top
388
- };
157
+ break;
158
+ case 7:
159
+ str += `<?${node.nodeName} ${node.nodeValue}?>`;
160
+ if (el.nodeType === 9 || el.nodeType === 11) {
161
+ str += "\n";
389
162
  }
390
- return fallback;
391
- }
392
- const resetRects = await platform.getElementRects({
393
- reference: {
394
- getBoundingClientRect
395
- },
396
- floating: elements.floating,
397
- strategy
398
- });
399
- if (rects.reference.x !== resetRects.reference.x || rects.reference.y !== resetRects.reference.y || rects.reference.width !== resetRects.reference.width || rects.reference.height !== resetRects.reference.height) {
400
- return {
401
- reset: {
402
- rects: resetRects
403
- }
404
- };
405
- }
406
- return {};
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;
407
178
  }
408
- };
409
- };
410
- async function convertValueToCoords(state, options) {
411
- const {
412
- placement,
413
- platform,
414
- elements
415
- } = state;
416
- const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
417
- const side = getSide(placement);
418
- const alignment = getAlignment(placement);
419
- const isVertical = getSideAxis(placement) === "y";
420
- const mainAxisMulti = ["left", "top"].includes(side) ? -1 : 1;
421
- const crossAxisMulti = rtl && isVertical ? -1 : 1;
422
- const rawValue = evaluate(options, state);
423
- let {
424
- mainAxis,
425
- crossAxis,
426
- alignmentAxis
427
- } = typeof rawValue === "number" ? {
428
- mainAxis: rawValue,
429
- crossAxis: 0,
430
- alignmentAxis: null
431
- } : {
432
- mainAxis: 0,
433
- crossAxis: 0,
434
- alignmentAxis: null,
435
- ...rawValue
436
- };
437
- if (alignment && typeof alignmentAxis === "number") {
438
- crossAxis = alignment === "end" ? alignmentAxis * -1 : alignmentAxis;
439
179
  }
440
- return isVertical ? {
441
- x: crossAxis * crossAxisMulti,
442
- y: mainAxis * mainAxisMulti
443
- } : {
444
- x: mainAxis * mainAxisMulti,
445
- y: crossAxis * crossAxisMulti
446
- };
180
+ if (!stripElt && el.nodeType == 1 && el.childNodes.length > 0) {
181
+ if (typeof ws === "string") {
182
+ str += "\n" + ws + "</";
183
+ } else {
184
+ str += "</";
185
+ }
186
+ str += el.getAttribute("data-origname") + ">";
187
+ }
188
+ if (el.nodeType === 9 || el.nodeType === 11) {
189
+ str += "\n";
190
+ }
191
+ return str;
447
192
  }
448
- const offset = function(options) {
449
- if (options === void 0) {
450
- options = 0;
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);
198
+ };
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 += ">";
451
210
  }
452
- return {
453
- name: "offset",
454
- options,
455
- async fn(state) {
456
- var _middlewareData$offse, _middlewareData$arrow;
457
- const {
458
- x,
459
- y,
460
- placement,
461
- middlewareData
462
- } = state;
463
- const diffCoords = await convertValueToCoords(state, options);
464
- if (placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
465
- return {};
466
- }
467
- return {
468
- x: x + diffCoords.x,
469
- y: y + diffCoords.y,
470
- data: {
471
- ...diffCoords,
472
- placement
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";
473
224
  }
474
- };
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;");
475
240
  }
476
- };
477
- };
478
- const shift = function(options) {
479
- if (options === void 0) {
480
- options = {};
481
241
  }
482
- return {
483
- name: "shift",
484
- options,
485
- async fn(state) {
486
- const {
487
- x,
488
- y,
489
- placement
490
- } = state;
491
- const {
492
- mainAxis: checkMainAxis = true,
493
- crossAxis: checkCrossAxis = false,
494
- limiter = {
495
- fn: (_ref) => {
496
- let {
497
- x: x2,
498
- y: y2
499
- } = _ref;
500
- return {
501
- x: x2,
502
- y: y2
503
- };
504
- }
505
- },
506
- ...detectOverflowOptions
507
- } = evaluate(options, state);
508
- const coords = {
509
- x,
510
- y
511
- };
512
- const overflow = await detectOverflow(state, detectOverflowOptions);
513
- const crossAxis = getSideAxis(getSide(placement));
514
- const mainAxis = getOppositeAxis(crossAxis);
515
- let mainAxisCoord = coords[mainAxis];
516
- let crossAxisCoord = coords[crossAxis];
517
- if (checkMainAxis) {
518
- const minSide = mainAxis === "y" ? "top" : "left";
519
- const maxSide = mainAxis === "y" ? "bottom" : "right";
520
- const min2 = mainAxisCoord + overflow[minSide];
521
- const max2 = mainAxisCoord - overflow[maxSide];
522
- mainAxisCoord = clamp(min2, mainAxisCoord, max2);
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 += "</";
523
249
  }
524
- if (checkCrossAxis) {
525
- const minSide = crossAxis === "y" ? "top" : "left";
526
- const maxSide = crossAxis === "y" ? "bottom" : "right";
527
- const min2 = crossAxisCoord + overflow[minSide];
528
- const max2 = crossAxisCoord - overflow[maxSide];
529
- crossAxisCoord = clamp(min2, crossAxisCoord, max2);
250
+ str += `${el.nodeName}>`;
251
+ }
252
+ }
253
+ if (el.nodeType === 9 || el.nodeType === 11) {
254
+ str += "\n";
255
+ }
256
+ return str;
257
+ }
258
+ function unEscapeEntities(str) {
259
+ return str.replace(/&gt;/, ">").replace(/&quot;/, '"').replace(/&apos;/, "'").replace(/&amp;/, "&");
260
+ }
261
+ function tagName(name) {
262
+ if (name.includes(":"), 1) {
263
+ return name.replace(/:/, "-").toLowerCase();
264
+ }
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
+ }
276
+ }
530
277
  }
531
- const limitedCoords = limiter.fn({
532
- ...state,
533
- [mainAxis]: mainAxisCoord,
534
- [crossAxis]: crossAxisCoord
535
- });
536
- return {
537
- ...limitedCoords,
538
- data: {
539
- x: limitedCoords.x - x,
540
- y: limitedCoords.y - y
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
+ }
541
285
  }
542
- };
286
+ }
287
+ });
288
+ } catch (error) {
289
+ if (debug) {
290
+ console.log(tagName(name) + " couldn't be registered or is already registered.");
291
+ console.log(error);
543
292
  }
544
- };
545
- };
293
+ }
294
+ }
546
295
  export {
547
- autoPlacement,
548
- computePosition,
549
- detectOverflow,
550
- inline,
551
- offset,
552
- rectToClientRect,
553
- shift
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
554
311
  };
555
312
  //# sourceMappingURL=react-text-annotator.es24.js.map