@soomo/react-text-annotator 3.1.0-staging.18 → 3.1.0-staging.19

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 (47) hide show
  1. package/dist/TextAnnotationPopup/TextAnnotationPopup.d.ts.map +1 -1
  2. package/dist/hooks/index.d.ts +1 -1
  3. package/dist/hooks/index.d.ts.map +1 -1
  4. package/dist/hooks/useAnnotationQuoteIdling.d.ts +4 -0
  5. package/dist/hooks/useAnnotationQuoteIdling.d.ts.map +1 -0
  6. package/dist/react-text-annotator.es.js +2 -2
  7. package/dist/react-text-annotator.es11.js +5 -5
  8. package/dist/react-text-annotator.es12.js +3 -3
  9. package/dist/react-text-annotator.es16.js +3 -3
  10. package/dist/react-text-annotator.es19.js +25 -2
  11. package/dist/react-text-annotator.es19.js.map +1 -1
  12. package/dist/react-text-annotator.es20.js +2 -31
  13. package/dist/react-text-annotator.es20.js.map +1 -1
  14. package/dist/react-text-annotator.es21.js +20 -887
  15. package/dist/react-text-annotator.es21.js.map +1 -1
  16. package/dist/react-text-annotator.es22.js +898 -2
  17. package/dist/react-text-annotator.es22.js.map +1 -1
  18. package/dist/react-text-annotator.es23.js +114 -2
  19. package/dist/react-text-annotator.es23.js.map +1 -1
  20. package/dist/react-text-annotator.es24.js +302 -107
  21. package/dist/react-text-annotator.es24.js.map +1 -1
  22. package/dist/react-text-annotator.es25.js +39 -290
  23. package/dist/react-text-annotator.es25.js.map +1 -1
  24. package/dist/react-text-annotator.es26.js +17 -55
  25. package/dist/react-text-annotator.es26.js.map +1 -1
  26. package/dist/react-text-annotator.es27.js +2 -20
  27. package/dist/react-text-annotator.es27.js.map +1 -1
  28. package/dist/react-text-annotator.es28.js +2 -127
  29. package/dist/react-text-annotator.es28.js.map +1 -1
  30. package/dist/react-text-annotator.es29.js +107 -144
  31. package/dist/react-text-annotator.es29.js.map +1 -1
  32. package/dist/react-text-annotator.es30.js +156 -303
  33. package/dist/react-text-annotator.es30.js.map +1 -1
  34. package/dist/react-text-annotator.es31.js +308 -146
  35. package/dist/react-text-annotator.es31.js.map +1 -1
  36. package/dist/react-text-annotator.es32.js +130 -607
  37. package/dist/react-text-annotator.es32.js.map +1 -1
  38. package/dist/react-text-annotator.es33.js +629 -0
  39. package/dist/react-text-annotator.es33.js.map +1 -0
  40. package/dist/react-text-annotator.es5.js +32 -17
  41. package/dist/react-text-annotator.es5.js.map +1 -1
  42. package/dist/react-text-annotator.es7.js +11 -7
  43. package/dist/react-text-annotator.es7.js.map +1 -1
  44. package/dist/react-text-annotator.es9.js +3 -3
  45. package/package.json +3 -2
  46. package/dist/hooks/useAnnotationTargetIdling.d.ts +0 -4
  47. package/dist/hooks/useAnnotationTargetIdling.d.ts.map +0 -1
@@ -1,629 +1,152 @@
1
- import { evaluate, getSide, getSideAxis, getOppositePlacement, getExpandedPlacements, getOppositeAxisPlacements, getAlignmentSides, rectToClientRect, getPaddingObject, clamp, getAlignmentAxis, getAlignment, min, max, getOppositeAxis, getAxisLength } from "./react-text-annotator.es31.js";
2
- function computeCoordsFromPlacement(_ref, placement, rtl) {
3
- let {
4
- reference,
5
- floating
6
- } = _ref;
7
- const sideAxis = getSideAxis(placement);
1
+ const min = Math.min;
2
+ const max = Math.max;
3
+ const round = Math.round;
4
+ const floor = Math.floor;
5
+ const createCoords = (v) => ({
6
+ x: v,
7
+ y: v
8
+ });
9
+ const oppositeSideMap = {
10
+ left: "right",
11
+ right: "left",
12
+ bottom: "top",
13
+ top: "bottom"
14
+ };
15
+ const oppositeAlignmentMap = {
16
+ start: "end",
17
+ end: "start"
18
+ };
19
+ function clamp(start, value, end) {
20
+ return max(start, min(value, end));
21
+ }
22
+ function evaluate(value, param) {
23
+ return typeof value === "function" ? value(param) : value;
24
+ }
25
+ function getSide(placement) {
26
+ return placement.split("-")[0];
27
+ }
28
+ function getAlignment(placement) {
29
+ return placement.split("-")[1];
30
+ }
31
+ function getOppositeAxis(axis) {
32
+ return axis === "x" ? "y" : "x";
33
+ }
34
+ function getAxisLength(axis) {
35
+ return axis === "y" ? "height" : "width";
36
+ }
37
+ function getSideAxis(placement) {
38
+ return ["top", "bottom"].includes(getSide(placement)) ? "y" : "x";
39
+ }
40
+ function getAlignmentAxis(placement) {
41
+ return getOppositeAxis(getSideAxis(placement));
42
+ }
43
+ function getAlignmentSides(placement, rects, rtl) {
44
+ if (rtl === void 0) {
45
+ rtl = false;
46
+ }
47
+ const alignment = getAlignment(placement);
8
48
  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;
49
+ const length = getAxisLength(alignmentAxis);
50
+ let mainAlignmentSide = alignmentAxis === "x" ? alignment === (rtl ? "end" : "start") ? "right" : "left" : alignment === "start" ? "bottom" : "top";
51
+ if (rects.reference[length] > rects.floating[length]) {
52
+ mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
53
+ }
54
+ return [mainAlignmentSide, getOppositePlacement(mainAlignmentSide)];
55
+ }
56
+ function getExpandedPlacements(placement) {
57
+ const oppositePlacement = getOppositePlacement(placement);
58
+ return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
59
+ }
60
+ function getOppositeAlignmentPlacement(placement) {
61
+ return placement.replace(/start|end/g, (alignment) => oppositeAlignmentMap[alignment]);
62
+ }
63
+ function getSideList(side, isStart, rtl) {
64
+ const lr = ["left", "right"];
65
+ const rl = ["right", "left"];
66
+ const tb = ["top", "bottom"];
67
+ const bt = ["bottom", "top"];
16
68
  switch (side) {
17
69
  case "top":
18
- coords = {
19
- x: commonX,
20
- y: reference.y - floating.height
21
- };
22
- break;
23
70
  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;
71
+ if (rtl) return isStart ? rl : lr;
72
+ return isStart ? lr : rl;
35
73
  case "left":
36
- coords = {
37
- x: reference.x - floating.width,
38
- y: commonY
39
- };
40
- break;
74
+ case "right":
75
+ return isStart ? tb : bt;
41
76
  default:
42
- coords = {
43
- x: reference.x,
44
- y: reference.y
45
- };
77
+ return [];
46
78
  }
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
79
  }
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];
80
+ function getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {
81
+ const alignment = getAlignment(placement);
82
+ let list = getSideList(getSide(placement), direction === "start", rtl);
83
+ if (alignment) {
84
+ list = list.map((side) => side + "-" + alignment);
85
+ if (flipAlignment) {
86
+ list = list.concat(list.map(getOppositeAlignmentPlacement));
234
87
  }
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
88
  }
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
- };
89
+ return list;
373
90
  }
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)));
91
+ function getOppositePlacement(placement) {
92
+ return placement.replace(/left|right|bottom|top/g, (side) => oppositeSideMap[side]);
388
93
  }
389
- const inline = function(options) {
390
- if (options === void 0) {
391
- options = {};
392
- }
94
+ function expandPaddingObject(padding) {
393
95
  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
96
+ top: 0,
97
+ right: 0,
98
+ bottom: 0,
99
+ left: 0,
100
+ ...padding
515
101
  };
516
102
  }
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
- }
103
+ function getPaddingObject(padding) {
104
+ return typeof padding !== "number" ? expandPaddingObject(padding) : {
105
+ top: padding,
106
+ right: padding,
107
+ bottom: padding,
108
+ left: padding
545
109
  };
546
- };
547
- const shift = function(options) {
548
- if (options === void 0) {
549
- options = {};
550
- }
110
+ }
111
+ function rectToClientRect(rect) {
112
+ const {
113
+ x,
114
+ y,
115
+ width,
116
+ height
117
+ } = rect;
551
118
  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
- }
119
+ width,
120
+ height,
121
+ top: y,
122
+ left: x,
123
+ right: x + width,
124
+ bottom: y + height,
125
+ x,
126
+ y
617
127
  };
618
- };
128
+ }
619
129
  export {
620
- arrow,
621
- computePosition,
622
- detectOverflow,
623
- flip,
624
- inline,
625
- offset,
130
+ clamp,
131
+ createCoords,
132
+ evaluate,
133
+ expandPaddingObject,
134
+ floor,
135
+ getAlignment,
136
+ getAlignmentAxis,
137
+ getAlignmentSides,
138
+ getAxisLength,
139
+ getExpandedPlacements,
140
+ getOppositeAlignmentPlacement,
141
+ getOppositeAxis,
142
+ getOppositeAxisPlacements,
143
+ getOppositePlacement,
144
+ getPaddingObject,
145
+ getSide,
146
+ getSideAxis,
147
+ max,
148
+ min,
626
149
  rectToClientRect,
627
- shift
150
+ round
628
151
  };
629
152
  //# sourceMappingURL=react-text-annotator.es32.js.map