@soomo/react-text-annotator 3.2.0-staging.5 → 3.2.0-staging.7
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/TextAnnotationPopup/TextAnnotationPopup.d.ts.map +1 -1
- package/dist/TextAnnotationPopup/useAnnouncePopupNavigation.d.ts.map +1 -0
- package/dist/hooks/index.d.ts +1 -2
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/useAnnotationQuoteIdle.d.ts +4 -0
- package/dist/hooks/useAnnotationQuoteIdle.d.ts.map +1 -0
- package/dist/react-text-annotator.css +1 -31
- package/dist/react-text-annotator.es.js +212 -25
- package/dist/react-text-annotator.es.js.map +1 -1
- package/package.json +14 -13
- package/dist/hooks/useAnnotationQuoteIdling.d.ts +0 -4
- package/dist/hooks/useAnnotationQuoteIdling.d.ts.map +0 -1
- package/dist/hooks/useAnnouncePopupNavigation.d.ts.map +0 -1
- package/dist/react-text-annotator.es10.js +0 -504
- package/dist/react-text-annotator.es10.js.map +0 -1
- package/dist/react-text-annotator.es11.js +0 -85
- package/dist/react-text-annotator.es11.js.map +0 -1
- package/dist/react-text-annotator.es12.js +0 -48
- package/dist/react-text-annotator.es12.js.map +0 -1
- package/dist/react-text-annotator.es13.js +0 -28
- package/dist/react-text-annotator.es13.js.map +0 -1
- package/dist/react-text-annotator.es14.js +0 -1646
- package/dist/react-text-annotator.es14.js.map +0 -1
- package/dist/react-text-annotator.es15.js +0 -13
- package/dist/react-text-annotator.es15.js.map +0 -1
- package/dist/react-text-annotator.es17.js +0 -607
- package/dist/react-text-annotator.es17.js.map +0 -1
- package/dist/react-text-annotator.es18.js +0 -285
- package/dist/react-text-annotator.es18.js.map +0 -1
- package/dist/react-text-annotator.es19.js +0 -18
- package/dist/react-text-annotator.es19.js.map +0 -1
- package/dist/react-text-annotator.es2.js +0 -67
- package/dist/react-text-annotator.es2.js.map +0 -1
- package/dist/react-text-annotator.es20.js +0 -5
- package/dist/react-text-annotator.es20.js.map +0 -1
- package/dist/react-text-annotator.es21.js +0 -34
- package/dist/react-text-annotator.es21.js.map +0 -1
- package/dist/react-text-annotator.es22.js +0 -891
- package/dist/react-text-annotator.es22.js.map +0 -1
- package/dist/react-text-annotator.es23.js +0 -5
- package/dist/react-text-annotator.es23.js.map +0 -1
- package/dist/react-text-annotator.es24.js +0 -5
- package/dist/react-text-annotator.es24.js.map +0 -1
- package/dist/react-text-annotator.es25.js +0 -117
- package/dist/react-text-annotator.es25.js.map +0 -1
- package/dist/react-text-annotator.es26.js +0 -312
- package/dist/react-text-annotator.es26.js.map +0 -1
- package/dist/react-text-annotator.es27.js +0 -61
- package/dist/react-text-annotator.es27.js.map +0 -1
- package/dist/react-text-annotator.es28.js +0 -23
- package/dist/react-text-annotator.es28.js.map +0 -1
- package/dist/react-text-annotator.es29.js +0 -130
- package/dist/react-text-annotator.es29.js.map +0 -1
- package/dist/react-text-annotator.es3.js +0 -29
- package/dist/react-text-annotator.es3.js.map +0 -1
- package/dist/react-text-annotator.es30.js +0 -167
- package/dist/react-text-annotator.es30.js.map +0 -1
- package/dist/react-text-annotator.es31.js +0 -314
- package/dist/react-text-annotator.es31.js.map +0 -1
- package/dist/react-text-annotator.es32.js +0 -152
- package/dist/react-text-annotator.es32.js.map +0 -1
- package/dist/react-text-annotator.es33.js +0 -629
- package/dist/react-text-annotator.es33.js.map +0 -1
- package/dist/react-text-annotator.es4.js +0 -43
- package/dist/react-text-annotator.es4.js.map +0 -1
- package/dist/react-text-annotator.es5.js +0 -48
- package/dist/react-text-annotator.es5.js.map +0 -1
- package/dist/react-text-annotator.es6.js +0 -29
- package/dist/react-text-annotator.es6.js.map +0 -1
- package/dist/react-text-annotator.es7.js +0 -143
- package/dist/react-text-annotator.es7.js.map +0 -1
- package/dist/react-text-annotator.es8.js +0 -6
- package/dist/react-text-annotator.es8.js.map +0 -1
- /package/dist/{hooks → TextAnnotationPopup}/useAnnouncePopupNavigation.d.ts +0 -0
|
@@ -1,629 +0,0 @@
|
|
|
1
|
-
import { evaluate, rectToClientRect, getPaddingObject, getSide, getSideAxis, getOppositePlacement, getExpandedPlacements, getOppositeAxisPlacements, getAlignmentSides, clamp, min, max, getAlignment, getOppositeAxis, getAlignmentAxis, getAxisLength } from "./react-text-annotator.es32.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);
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
return coords;
|
|
56
|
-
}
|
|
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
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
x = nextX != null ? nextX : x;
|
|
103
|
-
y = nextY != null ? nextY : y;
|
|
104
|
-
middlewareData = {
|
|
105
|
-
...middlewareData,
|
|
106
|
-
[name]: {
|
|
107
|
-
...middlewareData[name],
|
|
108
|
-
...data
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
if (reset && resetCount <= 50) {
|
|
112
|
-
resetCount++;
|
|
113
|
-
if (typeof reset === "object") {
|
|
114
|
-
if (reset.placement) {
|
|
115
|
-
statefulPlacement = reset.placement;
|
|
116
|
-
}
|
|
117
|
-
if (reset.rects) {
|
|
118
|
-
rects = reset.rects === true ? await platform.getElementRects({
|
|
119
|
-
reference,
|
|
120
|
-
floating,
|
|
121
|
-
strategy
|
|
122
|
-
}) : reset.rects;
|
|
123
|
-
}
|
|
124
|
-
({
|
|
125
|
-
x,
|
|
126
|
-
y
|
|
127
|
-
} = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
|
|
128
|
-
}
|
|
129
|
-
i = -1;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
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 = {};
|
|
144
|
-
}
|
|
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
|
-
};
|
|
195
|
-
}
|
|
196
|
-
const arrow = (options) => ({
|
|
197
|
-
name: "arrow",
|
|
198
|
-
options,
|
|
199
|
-
async fn(state) {
|
|
200
|
-
const {
|
|
201
|
-
x,
|
|
202
|
-
y,
|
|
203
|
-
placement,
|
|
204
|
-
rects,
|
|
205
|
-
platform,
|
|
206
|
-
elements,
|
|
207
|
-
middlewareData
|
|
208
|
-
} = state;
|
|
209
|
-
const {
|
|
210
|
-
element,
|
|
211
|
-
padding = 0
|
|
212
|
-
} = evaluate(options, state) || {};
|
|
213
|
-
if (element == null) {
|
|
214
|
-
return {};
|
|
215
|
-
}
|
|
216
|
-
const paddingObject = getPaddingObject(padding);
|
|
217
|
-
const coords = {
|
|
218
|
-
x,
|
|
219
|
-
y
|
|
220
|
-
};
|
|
221
|
-
const axis = getAlignmentAxis(placement);
|
|
222
|
-
const length = getAxisLength(axis);
|
|
223
|
-
const arrowDimensions = await platform.getDimensions(element);
|
|
224
|
-
const isYAxis = axis === "y";
|
|
225
|
-
const minProp = isYAxis ? "top" : "left";
|
|
226
|
-
const maxProp = isYAxis ? "bottom" : "right";
|
|
227
|
-
const clientProp = isYAxis ? "clientHeight" : "clientWidth";
|
|
228
|
-
const endDiff = rects.reference[length] + rects.reference[axis] - coords[axis] - rects.floating[length];
|
|
229
|
-
const startDiff = coords[axis] - rects.reference[axis];
|
|
230
|
-
const arrowOffsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(element));
|
|
231
|
-
let clientSize = arrowOffsetParent ? arrowOffsetParent[clientProp] : 0;
|
|
232
|
-
if (!clientSize || !await (platform.isElement == null ? void 0 : platform.isElement(arrowOffsetParent))) {
|
|
233
|
-
clientSize = elements.floating[clientProp] || rects.floating[length];
|
|
234
|
-
}
|
|
235
|
-
const centerToReference = endDiff / 2 - startDiff / 2;
|
|
236
|
-
const largestPossiblePadding = clientSize / 2 - arrowDimensions[length] / 2 - 1;
|
|
237
|
-
const minPadding = min(paddingObject[minProp], largestPossiblePadding);
|
|
238
|
-
const maxPadding = min(paddingObject[maxProp], largestPossiblePadding);
|
|
239
|
-
const min$1 = minPadding;
|
|
240
|
-
const max2 = clientSize - arrowDimensions[length] - maxPadding;
|
|
241
|
-
const center = clientSize / 2 - arrowDimensions[length] / 2 + centerToReference;
|
|
242
|
-
const offset2 = clamp(min$1, center, max2);
|
|
243
|
-
const shouldAddOffset = !middlewareData.arrow && getAlignment(placement) != null && center !== offset2 && rects.reference[length] / 2 - (center < min$1 ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0;
|
|
244
|
-
const alignmentOffset = shouldAddOffset ? center < min$1 ? center - min$1 : center - max2 : 0;
|
|
245
|
-
return {
|
|
246
|
-
[axis]: coords[axis] + alignmentOffset,
|
|
247
|
-
data: {
|
|
248
|
-
[axis]: offset2,
|
|
249
|
-
centerOffset: center - offset2 - alignmentOffset,
|
|
250
|
-
...shouldAddOffset && {
|
|
251
|
-
alignmentOffset
|
|
252
|
-
}
|
|
253
|
-
},
|
|
254
|
-
reset: shouldAddOffset
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
const flip = function(options) {
|
|
259
|
-
if (options === void 0) {
|
|
260
|
-
options = {};
|
|
261
|
-
}
|
|
262
|
-
return {
|
|
263
|
-
name: "flip",
|
|
264
|
-
options,
|
|
265
|
-
async fn(state) {
|
|
266
|
-
var _middlewareData$arrow, _middlewareData$flip;
|
|
267
|
-
const {
|
|
268
|
-
placement,
|
|
269
|
-
middlewareData,
|
|
270
|
-
rects,
|
|
271
|
-
initialPlacement,
|
|
272
|
-
platform,
|
|
273
|
-
elements
|
|
274
|
-
} = state;
|
|
275
|
-
const {
|
|
276
|
-
mainAxis: checkMainAxis = true,
|
|
277
|
-
crossAxis: checkCrossAxis = true,
|
|
278
|
-
fallbackPlacements: specifiedFallbackPlacements,
|
|
279
|
-
fallbackStrategy = "bestFit",
|
|
280
|
-
fallbackAxisSideDirection = "none",
|
|
281
|
-
flipAlignment = true,
|
|
282
|
-
...detectOverflowOptions
|
|
283
|
-
} = evaluate(options, state);
|
|
284
|
-
if ((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
|
|
285
|
-
return {};
|
|
286
|
-
}
|
|
287
|
-
const side = getSide(placement);
|
|
288
|
-
const initialSideAxis = getSideAxis(initialPlacement);
|
|
289
|
-
const isBasePlacement = getSide(initialPlacement) === initialPlacement;
|
|
290
|
-
const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
|
|
291
|
-
const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));
|
|
292
|
-
const hasFallbackAxisSideDirection = fallbackAxisSideDirection !== "none";
|
|
293
|
-
if (!specifiedFallbackPlacements && hasFallbackAxisSideDirection) {
|
|
294
|
-
fallbackPlacements.push(...getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl));
|
|
295
|
-
}
|
|
296
|
-
const placements = [initialPlacement, ...fallbackPlacements];
|
|
297
|
-
const overflow = await detectOverflow(state, detectOverflowOptions);
|
|
298
|
-
const overflows = [];
|
|
299
|
-
let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
|
|
300
|
-
if (checkMainAxis) {
|
|
301
|
-
overflows.push(overflow[side]);
|
|
302
|
-
}
|
|
303
|
-
if (checkCrossAxis) {
|
|
304
|
-
const sides = getAlignmentSides(placement, rects, rtl);
|
|
305
|
-
overflows.push(overflow[sides[0]], overflow[sides[1]]);
|
|
306
|
-
}
|
|
307
|
-
overflowsData = [...overflowsData, {
|
|
308
|
-
placement,
|
|
309
|
-
overflows
|
|
310
|
-
}];
|
|
311
|
-
if (!overflows.every((side2) => side2 <= 0)) {
|
|
312
|
-
var _middlewareData$flip2, _overflowsData$filter;
|
|
313
|
-
const nextIndex = (((_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) || 0) + 1;
|
|
314
|
-
const nextPlacement = placements[nextIndex];
|
|
315
|
-
if (nextPlacement) {
|
|
316
|
-
return {
|
|
317
|
-
data: {
|
|
318
|
-
index: nextIndex,
|
|
319
|
-
overflows: overflowsData
|
|
320
|
-
},
|
|
321
|
-
reset: {
|
|
322
|
-
placement: nextPlacement
|
|
323
|
-
}
|
|
324
|
-
};
|
|
325
|
-
}
|
|
326
|
-
let resetPlacement = (_overflowsData$filter = overflowsData.filter((d) => d.overflows[0] <= 0).sort((a, b) => a.overflows[1] - b.overflows[1])[0]) == null ? void 0 : _overflowsData$filter.placement;
|
|
327
|
-
if (!resetPlacement) {
|
|
328
|
-
switch (fallbackStrategy) {
|
|
329
|
-
case "bestFit": {
|
|
330
|
-
var _overflowsData$filter2;
|
|
331
|
-
const placement2 = (_overflowsData$filter2 = overflowsData.filter((d) => {
|
|
332
|
-
if (hasFallbackAxisSideDirection) {
|
|
333
|
-
const currentSideAxis = getSideAxis(d.placement);
|
|
334
|
-
return currentSideAxis === initialSideAxis || // Create a bias to the `y` side axis due to horizontal
|
|
335
|
-
// reading directions favoring greater width.
|
|
336
|
-
currentSideAxis === "y";
|
|
337
|
-
}
|
|
338
|
-
return true;
|
|
339
|
-
}).map((d) => [d.placement, d.overflows.filter((overflow2) => overflow2 > 0).reduce((acc, overflow2) => acc + overflow2, 0)]).sort((a, b) => a[1] - b[1])[0]) == null ? void 0 : _overflowsData$filter2[0];
|
|
340
|
-
if (placement2) {
|
|
341
|
-
resetPlacement = placement2;
|
|
342
|
-
}
|
|
343
|
-
break;
|
|
344
|
-
}
|
|
345
|
-
case "initialPlacement":
|
|
346
|
-
resetPlacement = initialPlacement;
|
|
347
|
-
break;
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
if (placement !== resetPlacement) {
|
|
351
|
-
return {
|
|
352
|
-
reset: {
|
|
353
|
-
placement: resetPlacement
|
|
354
|
-
}
|
|
355
|
-
};
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
return {};
|
|
359
|
-
}
|
|
360
|
-
};
|
|
361
|
-
};
|
|
362
|
-
function getBoundingRect(rects) {
|
|
363
|
-
const minX = min(...rects.map((rect) => rect.left));
|
|
364
|
-
const minY = min(...rects.map((rect) => rect.top));
|
|
365
|
-
const maxX = max(...rects.map((rect) => rect.right));
|
|
366
|
-
const maxY = max(...rects.map((rect) => rect.bottom));
|
|
367
|
-
return {
|
|
368
|
-
x: minX,
|
|
369
|
-
y: minY,
|
|
370
|
-
width: maxX - minX,
|
|
371
|
-
height: maxY - minY
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
function getRectsByLine(rects) {
|
|
375
|
-
const sortedRects = rects.slice().sort((a, b) => a.y - b.y);
|
|
376
|
-
const groups = [];
|
|
377
|
-
let prevRect = null;
|
|
378
|
-
for (let i = 0; i < sortedRects.length; i++) {
|
|
379
|
-
const rect = sortedRects[i];
|
|
380
|
-
if (!prevRect || rect.y - prevRect.y > prevRect.height / 2) {
|
|
381
|
-
groups.push([rect]);
|
|
382
|
-
} else {
|
|
383
|
-
groups[groups.length - 1].push(rect);
|
|
384
|
-
}
|
|
385
|
-
prevRect = rect;
|
|
386
|
-
}
|
|
387
|
-
return groups.map((rect) => rectToClientRect(getBoundingRect(rect)));
|
|
388
|
-
}
|
|
389
|
-
const inline = function(options) {
|
|
390
|
-
if (options === void 0) {
|
|
391
|
-
options = {};
|
|
392
|
-
}
|
|
393
|
-
return {
|
|
394
|
-
name: "inline",
|
|
395
|
-
options,
|
|
396
|
-
async fn(state) {
|
|
397
|
-
const {
|
|
398
|
-
placement,
|
|
399
|
-
elements,
|
|
400
|
-
rects,
|
|
401
|
-
platform,
|
|
402
|
-
strategy
|
|
403
|
-
} = state;
|
|
404
|
-
const {
|
|
405
|
-
padding = 2,
|
|
406
|
-
x,
|
|
407
|
-
y
|
|
408
|
-
} = evaluate(options, state);
|
|
409
|
-
const nativeClientRects = Array.from(await (platform.getClientRects == null ? void 0 : platform.getClientRects(elements.reference)) || []);
|
|
410
|
-
const clientRects = getRectsByLine(nativeClientRects);
|
|
411
|
-
const fallback = rectToClientRect(getBoundingRect(nativeClientRects));
|
|
412
|
-
const paddingObject = getPaddingObject(padding);
|
|
413
|
-
function getBoundingClientRect() {
|
|
414
|
-
if (clientRects.length === 2 && clientRects[0].left > clientRects[1].right && x != null && y != null) {
|
|
415
|
-
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;
|
|
416
|
-
}
|
|
417
|
-
if (clientRects.length >= 2) {
|
|
418
|
-
if (getSideAxis(placement) === "y") {
|
|
419
|
-
const firstRect = clientRects[0];
|
|
420
|
-
const lastRect = clientRects[clientRects.length - 1];
|
|
421
|
-
const isTop = getSide(placement) === "top";
|
|
422
|
-
const top2 = firstRect.top;
|
|
423
|
-
const bottom2 = lastRect.bottom;
|
|
424
|
-
const left2 = isTop ? firstRect.left : lastRect.left;
|
|
425
|
-
const right2 = isTop ? firstRect.right : lastRect.right;
|
|
426
|
-
const width2 = right2 - left2;
|
|
427
|
-
const height2 = bottom2 - top2;
|
|
428
|
-
return {
|
|
429
|
-
top: top2,
|
|
430
|
-
bottom: bottom2,
|
|
431
|
-
left: left2,
|
|
432
|
-
right: right2,
|
|
433
|
-
width: width2,
|
|
434
|
-
height: height2,
|
|
435
|
-
x: left2,
|
|
436
|
-
y: top2
|
|
437
|
-
};
|
|
438
|
-
}
|
|
439
|
-
const isLeftSide = getSide(placement) === "left";
|
|
440
|
-
const maxRight = max(...clientRects.map((rect) => rect.right));
|
|
441
|
-
const minLeft = min(...clientRects.map((rect) => rect.left));
|
|
442
|
-
const measureRects = clientRects.filter((rect) => isLeftSide ? rect.left === minLeft : rect.right === maxRight);
|
|
443
|
-
const top = measureRects[0].top;
|
|
444
|
-
const bottom = measureRects[measureRects.length - 1].bottom;
|
|
445
|
-
const left = minLeft;
|
|
446
|
-
const right = maxRight;
|
|
447
|
-
const width = right - left;
|
|
448
|
-
const height = bottom - top;
|
|
449
|
-
return {
|
|
450
|
-
top,
|
|
451
|
-
bottom,
|
|
452
|
-
left,
|
|
453
|
-
right,
|
|
454
|
-
width,
|
|
455
|
-
height,
|
|
456
|
-
x: left,
|
|
457
|
-
y: top
|
|
458
|
-
};
|
|
459
|
-
}
|
|
460
|
-
return fallback;
|
|
461
|
-
}
|
|
462
|
-
const resetRects = await platform.getElementRects({
|
|
463
|
-
reference: {
|
|
464
|
-
getBoundingClientRect
|
|
465
|
-
},
|
|
466
|
-
floating: elements.floating,
|
|
467
|
-
strategy
|
|
468
|
-
});
|
|
469
|
-
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) {
|
|
470
|
-
return {
|
|
471
|
-
reset: {
|
|
472
|
-
rects: resetRects
|
|
473
|
-
}
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
|
-
return {};
|
|
477
|
-
}
|
|
478
|
-
};
|
|
479
|
-
};
|
|
480
|
-
async function convertValueToCoords(state, options) {
|
|
481
|
-
const {
|
|
482
|
-
placement,
|
|
483
|
-
platform,
|
|
484
|
-
elements
|
|
485
|
-
} = state;
|
|
486
|
-
const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
|
|
487
|
-
const side = getSide(placement);
|
|
488
|
-
const alignment = getAlignment(placement);
|
|
489
|
-
const isVertical = getSideAxis(placement) === "y";
|
|
490
|
-
const mainAxisMulti = ["left", "top"].includes(side) ? -1 : 1;
|
|
491
|
-
const crossAxisMulti = rtl && isVertical ? -1 : 1;
|
|
492
|
-
const rawValue = evaluate(options, state);
|
|
493
|
-
let {
|
|
494
|
-
mainAxis,
|
|
495
|
-
crossAxis,
|
|
496
|
-
alignmentAxis
|
|
497
|
-
} = typeof rawValue === "number" ? {
|
|
498
|
-
mainAxis: rawValue,
|
|
499
|
-
crossAxis: 0,
|
|
500
|
-
alignmentAxis: null
|
|
501
|
-
} : {
|
|
502
|
-
mainAxis: rawValue.mainAxis || 0,
|
|
503
|
-
crossAxis: rawValue.crossAxis || 0,
|
|
504
|
-
alignmentAxis: rawValue.alignmentAxis
|
|
505
|
-
};
|
|
506
|
-
if (alignment && typeof alignmentAxis === "number") {
|
|
507
|
-
crossAxis = alignment === "end" ? alignmentAxis * -1 : alignmentAxis;
|
|
508
|
-
}
|
|
509
|
-
return isVertical ? {
|
|
510
|
-
x: crossAxis * crossAxisMulti,
|
|
511
|
-
y: mainAxis * mainAxisMulti
|
|
512
|
-
} : {
|
|
513
|
-
x: mainAxis * mainAxisMulti,
|
|
514
|
-
y: crossAxis * crossAxisMulti
|
|
515
|
-
};
|
|
516
|
-
}
|
|
517
|
-
const offset = function(options) {
|
|
518
|
-
if (options === void 0) {
|
|
519
|
-
options = 0;
|
|
520
|
-
}
|
|
521
|
-
return {
|
|
522
|
-
name: "offset",
|
|
523
|
-
options,
|
|
524
|
-
async fn(state) {
|
|
525
|
-
var _middlewareData$offse, _middlewareData$arrow;
|
|
526
|
-
const {
|
|
527
|
-
x,
|
|
528
|
-
y,
|
|
529
|
-
placement,
|
|
530
|
-
middlewareData
|
|
531
|
-
} = state;
|
|
532
|
-
const diffCoords = await convertValueToCoords(state, options);
|
|
533
|
-
if (placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
|
|
534
|
-
return {};
|
|
535
|
-
}
|
|
536
|
-
return {
|
|
537
|
-
x: x + diffCoords.x,
|
|
538
|
-
y: y + diffCoords.y,
|
|
539
|
-
data: {
|
|
540
|
-
...diffCoords,
|
|
541
|
-
placement
|
|
542
|
-
}
|
|
543
|
-
};
|
|
544
|
-
}
|
|
545
|
-
};
|
|
546
|
-
};
|
|
547
|
-
const shift = function(options) {
|
|
548
|
-
if (options === void 0) {
|
|
549
|
-
options = {};
|
|
550
|
-
}
|
|
551
|
-
return {
|
|
552
|
-
name: "shift",
|
|
553
|
-
options,
|
|
554
|
-
async fn(state) {
|
|
555
|
-
const {
|
|
556
|
-
x,
|
|
557
|
-
y,
|
|
558
|
-
placement
|
|
559
|
-
} = state;
|
|
560
|
-
const {
|
|
561
|
-
mainAxis: checkMainAxis = true,
|
|
562
|
-
crossAxis: checkCrossAxis = false,
|
|
563
|
-
limiter = {
|
|
564
|
-
fn: (_ref) => {
|
|
565
|
-
let {
|
|
566
|
-
x: x2,
|
|
567
|
-
y: y2
|
|
568
|
-
} = _ref;
|
|
569
|
-
return {
|
|
570
|
-
x: x2,
|
|
571
|
-
y: y2
|
|
572
|
-
};
|
|
573
|
-
}
|
|
574
|
-
},
|
|
575
|
-
...detectOverflowOptions
|
|
576
|
-
} = evaluate(options, state);
|
|
577
|
-
const coords = {
|
|
578
|
-
x,
|
|
579
|
-
y
|
|
580
|
-
};
|
|
581
|
-
const overflow = await detectOverflow(state, detectOverflowOptions);
|
|
582
|
-
const crossAxis = getSideAxis(getSide(placement));
|
|
583
|
-
const mainAxis = getOppositeAxis(crossAxis);
|
|
584
|
-
let mainAxisCoord = coords[mainAxis];
|
|
585
|
-
let crossAxisCoord = coords[crossAxis];
|
|
586
|
-
if (checkMainAxis) {
|
|
587
|
-
const minSide = mainAxis === "y" ? "top" : "left";
|
|
588
|
-
const maxSide = mainAxis === "y" ? "bottom" : "right";
|
|
589
|
-
const min2 = mainAxisCoord + overflow[minSide];
|
|
590
|
-
const max2 = mainAxisCoord - overflow[maxSide];
|
|
591
|
-
mainAxisCoord = clamp(min2, mainAxisCoord, max2);
|
|
592
|
-
}
|
|
593
|
-
if (checkCrossAxis) {
|
|
594
|
-
const minSide = crossAxis === "y" ? "top" : "left";
|
|
595
|
-
const maxSide = crossAxis === "y" ? "bottom" : "right";
|
|
596
|
-
const min2 = crossAxisCoord + overflow[minSide];
|
|
597
|
-
const max2 = crossAxisCoord - overflow[maxSide];
|
|
598
|
-
crossAxisCoord = clamp(min2, crossAxisCoord, max2);
|
|
599
|
-
}
|
|
600
|
-
const limitedCoords = limiter.fn({
|
|
601
|
-
...state,
|
|
602
|
-
[mainAxis]: mainAxisCoord,
|
|
603
|
-
[crossAxis]: crossAxisCoord
|
|
604
|
-
});
|
|
605
|
-
return {
|
|
606
|
-
...limitedCoords,
|
|
607
|
-
data: {
|
|
608
|
-
x: limitedCoords.x - x,
|
|
609
|
-
y: limitedCoords.y - y,
|
|
610
|
-
enabled: {
|
|
611
|
-
[mainAxis]: checkMainAxis,
|
|
612
|
-
[crossAxis]: checkCrossAxis
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
};
|
|
616
|
-
}
|
|
617
|
-
};
|
|
618
|
-
};
|
|
619
|
-
export {
|
|
620
|
-
arrow,
|
|
621
|
-
computePosition,
|
|
622
|
-
detectOverflow,
|
|
623
|
-
flip,
|
|
624
|
-
inline,
|
|
625
|
-
offset,
|
|
626
|
-
rectToClientRect,
|
|
627
|
-
shift
|
|
628
|
-
};
|
|
629
|
-
//# sourceMappingURL=react-text-annotator.es33.js.map
|