@soomo/react-text-annotator 3.0.0-staging.16 → 3.0.0-staging.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/react-text-annotator.es.js +2 -0
- package/dist/react-text-annotator.es.js.map +1 -1
- package/dist/react-text-annotator.es10.js +210 -562
- package/dist/react-text-annotator.es10.js.map +1 -1
- package/dist/react-text-annotator.es11.js +535 -444
- package/dist/react-text-annotator.es11.js.map +1 -1
- package/dist/react-text-annotator.es12.js +488 -2
- package/dist/react-text-annotator.es12.js.map +1 -1
- package/dist/react-text-annotator.es13.js +2 -35
- package/dist/react-text-annotator.es13.js.map +1 -1
- package/dist/react-text-annotator.es14.js +24 -888
- package/dist/react-text-annotator.es14.js.map +1 -1
- package/dist/react-text-annotator.es15.js +891 -220
- package/dist/react-text-annotator.es15.js.map +1 -1
- package/dist/react-text-annotator.es16.js +218 -126
- package/dist/react-text-annotator.es16.js.map +1 -1
- package/dist/react-text-annotator.es17.js +136 -2
- package/dist/react-text-annotator.es17.js.map +1 -1
- package/dist/react-text-annotator.es18.js +2 -2
- package/dist/react-text-annotator.es19.js +2 -114
- package/dist/react-text-annotator.es19.js.map +1 -1
- package/dist/react-text-annotator.es2.js +2 -2
- package/dist/react-text-annotator.es20.js +107 -302
- package/dist/react-text-annotator.es20.js.map +1 -1
- package/dist/react-text-annotator.es21.js +290 -39
- package/dist/react-text-annotator.es21.js.map +1 -1
- package/dist/react-text-annotator.es22.js +55 -17
- package/dist/react-text-annotator.es22.js.map +1 -1
- package/dist/react-text-annotator.es23.js +17 -118
- package/dist/react-text-annotator.es23.js.map +1 -1
- package/dist/react-text-annotator.es24.js +107 -538
- package/dist/react-text-annotator.es24.js.map +1 -1
- package/dist/react-text-annotator.es25.js +555 -0
- package/dist/react-text-annotator.es25.js.map +1 -0
- package/dist/react-text-annotator.es3.js +2 -2
- package/dist/react-text-annotator.es4.js +2 -2
- package/dist/react-text-annotator.es5.js +4 -4
- package/dist/react-text-annotator.es6.js +178 -9
- package/dist/react-text-annotator.es6.js.map +1 -1
- package/dist/react-text-annotator.es7.js +12 -1
- package/dist/react-text-annotator.es7.js.map +1 -1
- package/dist/react-text-annotator.es9.js +20 -223
- package/dist/react-text-annotator.es9.js.map +1 -1
- package/package.json +13 -7
- package/dist/react-text-annotator.es8.js +0 -27
- package/dist/react-text-annotator.es8.js.map +0 -1
|
@@ -1,582 +1,230 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return {
|
|
17
|
-
width,
|
|
18
|
-
height,
|
|
19
|
-
$: shouldFallback
|
|
20
|
-
};
|
|
21
|
-
}
|
|
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
|
|
47
|
-
};
|
|
48
|
-
}
|
|
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
|
-
};
|
|
59
|
-
}
|
|
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);
|
|
83
|
-
}
|
|
84
|
-
} else {
|
|
85
|
-
scale = getScale(element);
|
|
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 = currentWin.frameElement;
|
|
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 = currentWin.frameElement;
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useLayoutEffect, useEffect } from "react";
|
|
3
|
+
import { useFloating as useFloating$1 } from "./react-text-annotator.es16.js";
|
|
4
|
+
import { isElement } from "./react-text-annotator.es17.js";
|
|
5
|
+
import { getOverflowAncestors } from "./react-text-annotator.es17.js";
|
|
6
|
+
import "react-dom";
|
|
7
|
+
const SafeReact = {
|
|
8
|
+
...React
|
|
9
|
+
};
|
|
10
|
+
const useInsertionEffect = SafeReact.useInsertionEffect;
|
|
11
|
+
const useSafeInsertionEffect = useInsertionEffect || ((fn) => fn());
|
|
12
|
+
function useEffectEvent(callback) {
|
|
13
|
+
const ref = React.useRef(() => {
|
|
14
|
+
if (process.env.NODE_ENV !== "production") {
|
|
15
|
+
throw new Error("Cannot call an event handler while rendering.");
|
|
112
16
|
}
|
|
113
|
-
}
|
|
114
|
-
return rectToClientRect({
|
|
115
|
-
width,
|
|
116
|
-
height,
|
|
117
|
-
x,
|
|
118
|
-
y
|
|
119
17
|
});
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
function isTopLayer(element) {
|
|
123
|
-
return topLayerSelectors.some((selector) => {
|
|
124
|
-
try {
|
|
125
|
-
return element.matches(selector);
|
|
126
|
-
} catch (e) {
|
|
127
|
-
return false;
|
|
128
|
-
}
|
|
18
|
+
useSafeInsertionEffect(() => {
|
|
19
|
+
ref.current = callback;
|
|
129
20
|
});
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
function
|
|
176
|
-
const
|
|
177
|
-
const scroll = getNodeScroll(element);
|
|
178
|
-
const body = element.ownerDocument.body;
|
|
179
|
-
const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);
|
|
180
|
-
const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
|
|
181
|
-
let x = -scroll.scrollLeft + getWindowScrollBarX(element);
|
|
182
|
-
const y = -scroll.scrollTop;
|
|
183
|
-
if (getComputedStyle(body).direction === "rtl") {
|
|
184
|
-
x += max(html.clientWidth, body.clientWidth) - width;
|
|
185
|
-
}
|
|
186
|
-
return {
|
|
187
|
-
width,
|
|
188
|
-
height,
|
|
189
|
-
x,
|
|
190
|
-
y
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
function getViewportRect(element, strategy) {
|
|
194
|
-
const win = getWindow(element);
|
|
195
|
-
const html = getDocumentElement(element);
|
|
196
|
-
const visualViewport = win.visualViewport;
|
|
197
|
-
let width = html.clientWidth;
|
|
198
|
-
let height = html.clientHeight;
|
|
199
|
-
let x = 0;
|
|
200
|
-
let y = 0;
|
|
201
|
-
if (visualViewport) {
|
|
202
|
-
width = visualViewport.width;
|
|
203
|
-
height = visualViewport.height;
|
|
204
|
-
const visualViewportBased = isWebKit();
|
|
205
|
-
if (!visualViewportBased || visualViewportBased && strategy === "fixed") {
|
|
206
|
-
x = visualViewport.offsetLeft;
|
|
207
|
-
y = visualViewport.offsetTop;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
return {
|
|
211
|
-
width,
|
|
212
|
-
height,
|
|
213
|
-
x,
|
|
214
|
-
y
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
function getInnerBoundingClientRect(element, strategy) {
|
|
218
|
-
const clientRect = getBoundingClientRect(element, true, strategy === "fixed");
|
|
219
|
-
const top = clientRect.top + element.clientTop;
|
|
220
|
-
const left = clientRect.left + element.clientLeft;
|
|
221
|
-
const scale = isHTMLElement(element) ? getScale(element) : createCoords(1);
|
|
222
|
-
const width = element.clientWidth * scale.x;
|
|
223
|
-
const height = element.clientHeight * scale.y;
|
|
224
|
-
const x = left * scale.x;
|
|
225
|
-
const y = top * scale.y;
|
|
226
|
-
return {
|
|
227
|
-
width,
|
|
228
|
-
height,
|
|
229
|
-
x,
|
|
230
|
-
y
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {
|
|
234
|
-
let rect;
|
|
235
|
-
if (clippingAncestor === "viewport") {
|
|
236
|
-
rect = getViewportRect(element, strategy);
|
|
237
|
-
} else if (clippingAncestor === "document") {
|
|
238
|
-
rect = getDocumentRect(getDocumentElement(element));
|
|
239
|
-
} else if (isElement(clippingAncestor)) {
|
|
240
|
-
rect = getInnerBoundingClientRect(clippingAncestor, strategy);
|
|
241
|
-
} else {
|
|
242
|
-
const visualOffsets = getVisualOffsets(element);
|
|
243
|
-
rect = {
|
|
244
|
-
...clippingAncestor,
|
|
245
|
-
x: clippingAncestor.x - visualOffsets.x,
|
|
246
|
-
y: clippingAncestor.y - visualOffsets.y
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
return rectToClientRect(rect);
|
|
250
|
-
}
|
|
251
|
-
function hasFixedPositionAncestor(element, stopNode) {
|
|
252
|
-
const parentNode = getParentNode(element);
|
|
253
|
-
if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {
|
|
254
|
-
return false;
|
|
255
|
-
}
|
|
256
|
-
return getComputedStyle(parentNode).position === "fixed" || hasFixedPositionAncestor(parentNode, stopNode);
|
|
257
|
-
}
|
|
258
|
-
function getClippingElementAncestors(element, cache) {
|
|
259
|
-
const cachedResult = cache.get(element);
|
|
260
|
-
if (cachedResult) {
|
|
261
|
-
return cachedResult;
|
|
262
|
-
}
|
|
263
|
-
let result = getOverflowAncestors(element, [], false).filter((el) => isElement(el) && getNodeName(el) !== "body");
|
|
264
|
-
let currentContainingBlockComputedStyle = null;
|
|
265
|
-
const elementIsFixed = getComputedStyle(element).position === "fixed";
|
|
266
|
-
let currentNode = elementIsFixed ? getParentNode(element) : element;
|
|
267
|
-
while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
|
|
268
|
-
const computedStyle = getComputedStyle(currentNode);
|
|
269
|
-
const currentNodeIsContaining = isContainingBlock(currentNode);
|
|
270
|
-
if (!currentNodeIsContaining && computedStyle.position === "fixed") {
|
|
271
|
-
currentContainingBlockComputedStyle = null;
|
|
272
|
-
}
|
|
273
|
-
const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === "static" && !!currentContainingBlockComputedStyle && ["absolute", "fixed"].includes(currentContainingBlockComputedStyle.position) || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode);
|
|
274
|
-
if (shouldDropCurrentNode) {
|
|
275
|
-
result = result.filter((ancestor) => ancestor !== currentNode);
|
|
276
|
-
} else {
|
|
277
|
-
currentContainingBlockComputedStyle = computedStyle;
|
|
278
|
-
}
|
|
279
|
-
currentNode = getParentNode(currentNode);
|
|
280
|
-
}
|
|
281
|
-
cache.set(element, result);
|
|
282
|
-
return result;
|
|
283
|
-
}
|
|
284
|
-
function getClippingRect(_ref) {
|
|
285
|
-
let {
|
|
286
|
-
element,
|
|
287
|
-
boundary,
|
|
288
|
-
rootBoundary,
|
|
289
|
-
strategy
|
|
290
|
-
} = _ref;
|
|
291
|
-
const elementClippingAncestors = boundary === "clippingAncestors" ? isTopLayer(element) ? [] : getClippingElementAncestors(element, this._c) : [].concat(boundary);
|
|
292
|
-
const clippingAncestors = [...elementClippingAncestors, rootBoundary];
|
|
293
|
-
const firstClippingAncestor = clippingAncestors[0];
|
|
294
|
-
const clippingRect = clippingAncestors.reduce((accRect, clippingAncestor) => {
|
|
295
|
-
const rect = getClientRectFromClippingAncestor(element, clippingAncestor, strategy);
|
|
296
|
-
accRect.top = max(rect.top, accRect.top);
|
|
297
|
-
accRect.right = min(rect.right, accRect.right);
|
|
298
|
-
accRect.bottom = min(rect.bottom, accRect.bottom);
|
|
299
|
-
accRect.left = max(rect.left, accRect.left);
|
|
300
|
-
return accRect;
|
|
301
|
-
}, getClientRectFromClippingAncestor(element, firstClippingAncestor, strategy));
|
|
302
|
-
return {
|
|
303
|
-
width: clippingRect.right - clippingRect.left,
|
|
304
|
-
height: clippingRect.bottom - clippingRect.top,
|
|
305
|
-
x: clippingRect.left,
|
|
306
|
-
y: clippingRect.top
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
function getDimensions(element) {
|
|
310
|
-
const {
|
|
311
|
-
width,
|
|
312
|
-
height
|
|
313
|
-
} = getCssDimensions(element);
|
|
314
|
-
return {
|
|
315
|
-
width,
|
|
316
|
-
height
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
|
|
320
|
-
const isOffsetParentAnElement = isHTMLElement(offsetParent);
|
|
321
|
-
const documentElement = getDocumentElement(offsetParent);
|
|
322
|
-
const isFixed = strategy === "fixed";
|
|
323
|
-
const rect = getBoundingClientRect(element, true, isFixed, offsetParent);
|
|
324
|
-
let scroll = {
|
|
325
|
-
scrollLeft: 0,
|
|
326
|
-
scrollTop: 0
|
|
327
|
-
};
|
|
328
|
-
const offsets = createCoords(0);
|
|
329
|
-
if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
|
|
330
|
-
if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
|
|
331
|
-
scroll = getNodeScroll(offsetParent);
|
|
332
|
-
}
|
|
333
|
-
if (isOffsetParentAnElement) {
|
|
334
|
-
const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
|
|
335
|
-
offsets.x = offsetRect.x + offsetParent.clientLeft;
|
|
336
|
-
offsets.y = offsetRect.y + offsetParent.clientTop;
|
|
337
|
-
} else if (documentElement) {
|
|
338
|
-
offsets.x = getWindowScrollBarX(documentElement);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
const x = rect.left + scroll.scrollLeft - offsets.x;
|
|
342
|
-
const y = rect.top + scroll.scrollTop - offsets.y;
|
|
343
|
-
return {
|
|
344
|
-
x,
|
|
345
|
-
y,
|
|
346
|
-
width: rect.width,
|
|
347
|
-
height: rect.height
|
|
348
|
-
};
|
|
349
|
-
}
|
|
350
|
-
function isStaticPositioned(element) {
|
|
351
|
-
return getComputedStyle(element).position === "static";
|
|
352
|
-
}
|
|
353
|
-
function getTrueOffsetParent(element, polyfill) {
|
|
354
|
-
if (!isHTMLElement(element) || getComputedStyle(element).position === "fixed") {
|
|
355
|
-
return null;
|
|
356
|
-
}
|
|
357
|
-
if (polyfill) {
|
|
358
|
-
return polyfill(element);
|
|
359
|
-
}
|
|
360
|
-
return element.offsetParent;
|
|
361
|
-
}
|
|
362
|
-
function getOffsetParent(element, polyfill) {
|
|
363
|
-
const win = getWindow(element);
|
|
364
|
-
if (isTopLayer(element)) {
|
|
365
|
-
return win;
|
|
366
|
-
}
|
|
367
|
-
if (!isHTMLElement(element)) {
|
|
368
|
-
let svgOffsetParent = getParentNode(element);
|
|
369
|
-
while (svgOffsetParent && !isLastTraversableNode(svgOffsetParent)) {
|
|
370
|
-
if (isElement(svgOffsetParent) && !isStaticPositioned(svgOffsetParent)) {
|
|
371
|
-
return svgOffsetParent;
|
|
372
|
-
}
|
|
373
|
-
svgOffsetParent = getParentNode(svgOffsetParent);
|
|
374
|
-
}
|
|
375
|
-
return win;
|
|
376
|
-
}
|
|
377
|
-
let offsetParent = getTrueOffsetParent(element, polyfill);
|
|
378
|
-
while (offsetParent && isTableElement(offsetParent) && isStaticPositioned(offsetParent)) {
|
|
379
|
-
offsetParent = getTrueOffsetParent(offsetParent, polyfill);
|
|
380
|
-
}
|
|
381
|
-
if (offsetParent && isLastTraversableNode(offsetParent) && isStaticPositioned(offsetParent) && !isContainingBlock(offsetParent)) {
|
|
382
|
-
return win;
|
|
383
|
-
}
|
|
384
|
-
return offsetParent || getContainingBlock(element) || win;
|
|
385
|
-
}
|
|
386
|
-
const getElementRects = async function(data) {
|
|
387
|
-
const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
|
|
388
|
-
const getDimensionsFn = this.getDimensions;
|
|
389
|
-
const floatingDimensions = await getDimensionsFn(data.floating);
|
|
21
|
+
return React.useCallback(function() {
|
|
22
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
23
|
+
args[_key] = arguments[_key];
|
|
24
|
+
}
|
|
25
|
+
return ref.current == null ? void 0 : ref.current(...args);
|
|
26
|
+
}, []);
|
|
27
|
+
}
|
|
28
|
+
var index = typeof document !== "undefined" ? useLayoutEffect : useEffect;
|
|
29
|
+
let serverHandoffComplete = false;
|
|
30
|
+
let count = 0;
|
|
31
|
+
const genId = () => (
|
|
32
|
+
// Ensure the id is unique with multiple independent versions of Floating UI
|
|
33
|
+
// on <React 18
|
|
34
|
+
"floating-ui-" + Math.random().toString(36).slice(2, 6) + count++
|
|
35
|
+
);
|
|
36
|
+
function useFloatingId() {
|
|
37
|
+
const [id, setId] = React.useState(() => serverHandoffComplete ? genId() : void 0);
|
|
38
|
+
index(() => {
|
|
39
|
+
if (id == null) {
|
|
40
|
+
setId(genId());
|
|
41
|
+
}
|
|
42
|
+
}, []);
|
|
43
|
+
React.useEffect(() => {
|
|
44
|
+
serverHandoffComplete = true;
|
|
45
|
+
}, []);
|
|
46
|
+
return id;
|
|
47
|
+
}
|
|
48
|
+
const useReactId = SafeReact.useId;
|
|
49
|
+
const useId = useReactId || useFloatingId;
|
|
50
|
+
let devMessageSet;
|
|
51
|
+
if (process.env.NODE_ENV !== "production") {
|
|
52
|
+
devMessageSet = /* @__PURE__ */ new Set();
|
|
53
|
+
}
|
|
54
|
+
function error() {
|
|
55
|
+
var _devMessageSet3;
|
|
56
|
+
for (var _len2 = arguments.length, messages = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
57
|
+
messages[_key2] = arguments[_key2];
|
|
58
|
+
}
|
|
59
|
+
const message = "Floating UI: " + messages.join(" ");
|
|
60
|
+
if (!((_devMessageSet3 = devMessageSet) != null && _devMessageSet3.has(message))) {
|
|
61
|
+
var _devMessageSet4;
|
|
62
|
+
(_devMessageSet4 = devMessageSet) == null || _devMessageSet4.add(message);
|
|
63
|
+
console.error(message);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function createPubSub() {
|
|
67
|
+
const map = /* @__PURE__ */ new Map();
|
|
390
68
|
return {
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
getClientRects,
|
|
410
|
-
getDimensions,
|
|
411
|
-
getScale,
|
|
412
|
-
isElement,
|
|
413
|
-
isRTL
|
|
69
|
+
emit(event, data) {
|
|
70
|
+
var _map$get;
|
|
71
|
+
(_map$get = map.get(event)) == null || _map$get.forEach((handler) => handler(data));
|
|
72
|
+
},
|
|
73
|
+
on(event, listener) {
|
|
74
|
+
map.set(event, [...map.get(event) || [], listener]);
|
|
75
|
+
},
|
|
76
|
+
off(event, listener) {
|
|
77
|
+
var _map$get2;
|
|
78
|
+
map.set(event, ((_map$get2 = map.get(event)) == null ? void 0 : _map$get2.filter((l) => l !== listener)) || []);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
const FloatingNodeContext = /* @__PURE__ */ React.createContext(null);
|
|
83
|
+
const FloatingTreeContext = /* @__PURE__ */ React.createContext(null);
|
|
84
|
+
const useFloatingParentNodeId = () => {
|
|
85
|
+
var _React$useContext;
|
|
86
|
+
return ((_React$useContext = React.useContext(FloatingNodeContext)) == null ? void 0 : _React$useContext.id) || null;
|
|
414
87
|
};
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
}
|
|
461
|
-
if (!ratio) {
|
|
462
|
-
timeoutId = setTimeout(() => {
|
|
463
|
-
refresh(false, 1e-7);
|
|
464
|
-
}, 1e3);
|
|
465
|
-
} else {
|
|
466
|
-
refresh(false, ratio);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
isFirstUpdate = false;
|
|
470
|
-
}
|
|
471
|
-
try {
|
|
472
|
-
io = new IntersectionObserver(handleObserve, {
|
|
473
|
-
...options,
|
|
474
|
-
// Handle <iframe>s
|
|
475
|
-
root: root.ownerDocument
|
|
476
|
-
});
|
|
477
|
-
} catch (e) {
|
|
478
|
-
io = new IntersectionObserver(handleObserve, options);
|
|
479
|
-
}
|
|
480
|
-
io.observe(element);
|
|
481
|
-
}
|
|
482
|
-
refresh(true);
|
|
483
|
-
return cleanup;
|
|
88
|
+
const useFloatingTree = () => React.useContext(FloatingTreeContext);
|
|
89
|
+
function useFloatingRootContext(options) {
|
|
90
|
+
const {
|
|
91
|
+
open = false,
|
|
92
|
+
onOpenChange: onOpenChangeProp,
|
|
93
|
+
elements: elementsProp
|
|
94
|
+
} = options;
|
|
95
|
+
const floatingId = useId();
|
|
96
|
+
const dataRef = React.useRef({});
|
|
97
|
+
const [events] = React.useState(() => createPubSub());
|
|
98
|
+
const nested = useFloatingParentNodeId() != null;
|
|
99
|
+
if (process.env.NODE_ENV !== "production") {
|
|
100
|
+
const optionDomReference = elementsProp.reference;
|
|
101
|
+
if (optionDomReference && !isElement(optionDomReference)) {
|
|
102
|
+
error("Cannot pass a virtual element to the `elements.reference` option,", "as it must be a real DOM element. Use `refs.setPositionReference()`", "instead.");
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const [positionReference, setPositionReference] = React.useState(elementsProp.reference);
|
|
106
|
+
const onOpenChange = useEffectEvent((open2, event, reason) => {
|
|
107
|
+
dataRef.current.openEvent = open2 ? event : void 0;
|
|
108
|
+
events.emit("openchange", {
|
|
109
|
+
open: open2,
|
|
110
|
+
event,
|
|
111
|
+
reason,
|
|
112
|
+
nested
|
|
113
|
+
});
|
|
114
|
+
onOpenChangeProp == null || onOpenChangeProp(open2, event, reason);
|
|
115
|
+
});
|
|
116
|
+
const refs = React.useMemo(() => ({
|
|
117
|
+
setPositionReference
|
|
118
|
+
}), []);
|
|
119
|
+
const elements = React.useMemo(() => ({
|
|
120
|
+
reference: positionReference || elementsProp.reference || null,
|
|
121
|
+
floating: elementsProp.floating || null,
|
|
122
|
+
domReference: elementsProp.reference
|
|
123
|
+
}), [positionReference, elementsProp.reference, elementsProp.floating]);
|
|
124
|
+
return React.useMemo(() => ({
|
|
125
|
+
dataRef,
|
|
126
|
+
open,
|
|
127
|
+
onOpenChange,
|
|
128
|
+
elements,
|
|
129
|
+
events,
|
|
130
|
+
floatingId,
|
|
131
|
+
refs
|
|
132
|
+
}), [open, onOpenChange, elements, events, floatingId, refs]);
|
|
484
133
|
}
|
|
485
|
-
function
|
|
134
|
+
function useFloating(options) {
|
|
486
135
|
if (options === void 0) {
|
|
487
136
|
options = {};
|
|
488
137
|
}
|
|
489
138
|
const {
|
|
490
|
-
|
|
491
|
-
ancestorResize = true,
|
|
492
|
-
elementResize = typeof ResizeObserver === "function",
|
|
493
|
-
layoutShift = typeof IntersectionObserver === "function",
|
|
494
|
-
animationFrame = false
|
|
139
|
+
nodeId
|
|
495
140
|
} = options;
|
|
496
|
-
const
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
141
|
+
const internalRootContext = useFloatingRootContext({
|
|
142
|
+
...options,
|
|
143
|
+
elements: {
|
|
144
|
+
reference: null,
|
|
145
|
+
floating: null,
|
|
146
|
+
...options.elements
|
|
147
|
+
}
|
|
503
148
|
});
|
|
504
|
-
const
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
149
|
+
const rootContext = options.rootContext || internalRootContext;
|
|
150
|
+
const computedElements = rootContext.elements;
|
|
151
|
+
const [_domReference, setDomReference] = React.useState(null);
|
|
152
|
+
const [positionReference, _setPositionReference] = React.useState(null);
|
|
153
|
+
const optionDomReference = computedElements == null ? void 0 : computedElements.reference;
|
|
154
|
+
const domReference = optionDomReference || _domReference;
|
|
155
|
+
const domReferenceRef = React.useRef(null);
|
|
156
|
+
const tree = useFloatingTree();
|
|
157
|
+
index(() => {
|
|
158
|
+
if (domReference) {
|
|
159
|
+
domReferenceRef.current = domReference;
|
|
160
|
+
}
|
|
161
|
+
}, [domReference]);
|
|
162
|
+
const position = useFloating$1({
|
|
163
|
+
...options,
|
|
164
|
+
elements: {
|
|
165
|
+
...computedElements,
|
|
166
|
+
...positionReference && {
|
|
167
|
+
reference: positionReference
|
|
517
168
|
}
|
|
518
|
-
update();
|
|
519
|
-
});
|
|
520
|
-
if (referenceEl && !animationFrame) {
|
|
521
|
-
resizeObserver.observe(referenceEl);
|
|
522
|
-
}
|
|
523
|
-
resizeObserver.observe(floating);
|
|
524
|
-
}
|
|
525
|
-
let frameId;
|
|
526
|
-
let prevRefRect = animationFrame ? getBoundingClientRect(reference) : null;
|
|
527
|
-
if (animationFrame) {
|
|
528
|
-
frameLoop();
|
|
529
|
-
}
|
|
530
|
-
function frameLoop() {
|
|
531
|
-
const nextRefRect = getBoundingClientRect(reference);
|
|
532
|
-
if (prevRefRect && (nextRefRect.x !== prevRefRect.x || nextRefRect.y !== prevRefRect.y || nextRefRect.width !== prevRefRect.width || nextRefRect.height !== prevRefRect.height)) {
|
|
533
|
-
update();
|
|
534
169
|
}
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
170
|
+
});
|
|
171
|
+
const setPositionReference = React.useCallback((node) => {
|
|
172
|
+
const computedPositionReference = isElement(node) ? {
|
|
173
|
+
getBoundingClientRect: () => node.getBoundingClientRect(),
|
|
174
|
+
contextElement: node
|
|
175
|
+
} : node;
|
|
176
|
+
_setPositionReference(computedPositionReference);
|
|
177
|
+
position.refs.setReference(computedPositionReference);
|
|
178
|
+
}, [position.refs]);
|
|
179
|
+
const setReference = React.useCallback((node) => {
|
|
180
|
+
if (isElement(node) || node === null) {
|
|
181
|
+
domReferenceRef.current = node;
|
|
182
|
+
setDomReference(node);
|
|
183
|
+
}
|
|
184
|
+
if (isElement(position.refs.reference.current) || position.refs.reference.current === null || // Don't allow setting virtual elements using the old technique back to
|
|
185
|
+
// `null` to support `positionReference` + an unstable `reference`
|
|
186
|
+
// callback ref.
|
|
187
|
+
node !== null && !isElement(node)) {
|
|
188
|
+
position.refs.setReference(node);
|
|
189
|
+
}
|
|
190
|
+
}, [position.refs]);
|
|
191
|
+
const refs = React.useMemo(() => ({
|
|
192
|
+
...position.refs,
|
|
193
|
+
setReference,
|
|
194
|
+
setPositionReference,
|
|
195
|
+
domReference: domReferenceRef
|
|
196
|
+
}), [position.refs, setReference, setPositionReference]);
|
|
197
|
+
const elements = React.useMemo(() => ({
|
|
198
|
+
...position.elements,
|
|
199
|
+
domReference
|
|
200
|
+
}), [position.elements, domReference]);
|
|
201
|
+
const context = React.useMemo(() => ({
|
|
202
|
+
...position,
|
|
203
|
+
...rootContext,
|
|
204
|
+
refs,
|
|
205
|
+
elements,
|
|
206
|
+
nodeId
|
|
207
|
+
}), [position, refs, elements, nodeId, rootContext]);
|
|
208
|
+
index(() => {
|
|
209
|
+
rootContext.dataRef.current.floatingContext = context;
|
|
210
|
+
const node = tree == null ? void 0 : tree.nodesRef.current.find((node2) => node2.id === nodeId);
|
|
211
|
+
if (node) {
|
|
212
|
+
node.context = context;
|
|
550
213
|
}
|
|
551
|
-
};
|
|
552
|
-
}
|
|
553
|
-
const offset = offset$1;
|
|
554
|
-
const autoPlacement = autoPlacement$1;
|
|
555
|
-
const shift = shift$1;
|
|
556
|
-
const inline = inline$1;
|
|
557
|
-
const computePosition = (reference, floating, options) => {
|
|
558
|
-
const cache = /* @__PURE__ */ new Map();
|
|
559
|
-
const mergedOptions = {
|
|
560
|
-
platform,
|
|
561
|
-
...options
|
|
562
|
-
};
|
|
563
|
-
const platformWithCache = {
|
|
564
|
-
...mergedOptions.platform,
|
|
565
|
-
_c: cache
|
|
566
|
-
};
|
|
567
|
-
return computePosition$1(reference, floating, {
|
|
568
|
-
...mergedOptions,
|
|
569
|
-
platform: platformWithCache
|
|
570
214
|
});
|
|
571
|
-
|
|
215
|
+
return React.useMemo(() => ({
|
|
216
|
+
...position,
|
|
217
|
+
context,
|
|
218
|
+
refs,
|
|
219
|
+
elements
|
|
220
|
+
}), [position, refs, elements, context]);
|
|
221
|
+
}
|
|
572
222
|
export {
|
|
573
|
-
autoPlacement,
|
|
574
|
-
autoUpdate,
|
|
575
|
-
computePosition,
|
|
576
223
|
getOverflowAncestors,
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
224
|
+
useFloating,
|
|
225
|
+
useFloatingParentNodeId,
|
|
226
|
+
useFloatingRootContext,
|
|
227
|
+
useFloatingTree,
|
|
228
|
+
useId
|
|
581
229
|
};
|
|
582
230
|
//# sourceMappingURL=react-text-annotator.es10.js.map
|