@soomo/react-text-annotator 3.1.0-staging.13 → 3.1.0-staging.15

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 (68) hide show
  1. package/dist/TextAnnotatorPopup/TextAnnotatorPopup.d.ts +1 -11
  2. package/dist/TextAnnotatorPopup/TextAnnotatorPopup.d.ts.map +1 -1
  3. package/dist/hooks/index.d.ts +2 -1
  4. package/dist/hooks/index.d.ts.map +1 -1
  5. package/dist/hooks/useAnnotationTargetIdling.d.ts +4 -0
  6. package/dist/hooks/useAnnotationTargetIdling.d.ts.map +1 -0
  7. package/dist/react-text-annotator.es.js +5 -4
  8. package/dist/react-text-annotator.es.js.map +1 -1
  9. package/dist/react-text-annotator.es11.js +483 -78
  10. package/dist/react-text-annotator.es11.js.map +1 -1
  11. package/dist/react-text-annotator.es12.js +77 -40
  12. package/dist/react-text-annotator.es12.js.map +1 -1
  13. package/dist/react-text-annotator.es13.js +45 -9
  14. package/dist/react-text-annotator.es13.js.map +1 -1
  15. package/dist/react-text-annotator.es14.js +45 -10
  16. package/dist/react-text-annotator.es14.js.map +1 -1
  17. package/dist/react-text-annotator.es15.js +12 -0
  18. package/dist/react-text-annotator.es15.js.map +1 -0
  19. package/dist/react-text-annotator.es17.js +215 -554
  20. package/dist/react-text-annotator.es17.js.map +1 -1
  21. package/dist/react-text-annotator.es18.js +585 -2
  22. package/dist/react-text-annotator.es18.js.map +1 -1
  23. package/dist/react-text-annotator.es19.js +2 -31
  24. package/dist/react-text-annotator.es19.js.map +1 -1
  25. package/dist/react-text-annotator.es2.js +2 -2
  26. package/dist/react-text-annotator.es20.js +20 -887
  27. package/dist/react-text-annotator.es20.js.map +1 -1
  28. package/dist/react-text-annotator.es21.js +893 -109
  29. package/dist/react-text-annotator.es21.js.map +1 -1
  30. package/dist/react-text-annotator.es22.js +2 -309
  31. package/dist/react-text-annotator.es22.js.map +1 -1
  32. package/dist/react-text-annotator.es23.js +2 -58
  33. package/dist/react-text-annotator.es23.js.map +1 -1
  34. package/dist/react-text-annotator.es24.js +113 -19
  35. package/dist/react-text-annotator.es24.js.map +1 -1
  36. package/dist/react-text-annotator.es25.js +309 -2
  37. package/dist/react-text-annotator.es25.js.map +1 -1
  38. package/dist/react-text-annotator.es26.js +58 -2
  39. package/dist/react-text-annotator.es26.js.map +1 -1
  40. package/dist/react-text-annotator.es27.js +17 -124
  41. package/dist/react-text-annotator.es27.js.map +1 -1
  42. package/dist/react-text-annotator.es28.js +107 -144
  43. package/dist/react-text-annotator.es28.js.map +1 -1
  44. package/dist/react-text-annotator.es29.js +156 -303
  45. package/dist/react-text-annotator.es29.js.map +1 -1
  46. package/dist/react-text-annotator.es3.js +2 -2
  47. package/dist/react-text-annotator.es30.js +308 -146
  48. package/dist/react-text-annotator.es30.js.map +1 -1
  49. package/dist/react-text-annotator.es31.js +130 -544
  50. package/dist/react-text-annotator.es31.js.map +1 -1
  51. package/dist/react-text-annotator.es32.js +566 -0
  52. package/dist/react-text-annotator.es32.js.map +1 -0
  53. package/dist/react-text-annotator.es4.js +2 -2
  54. package/dist/react-text-annotator.es5.js +28 -24
  55. package/dist/react-text-annotator.es5.js.map +1 -1
  56. package/dist/react-text-annotator.es6.js +23 -124
  57. package/dist/react-text-annotator.es6.js.map +1 -1
  58. package/dist/react-text-annotator.es7.js +121 -538
  59. package/dist/react-text-annotator.es7.js.map +1 -1
  60. package/dist/react-text-annotator.es8.js +545 -10
  61. package/dist/react-text-annotator.es8.js.map +1 -1
  62. package/dist/react-text-annotator.es9.js +13 -0
  63. package/dist/react-text-annotator.es9.js.map +1 -0
  64. package/package.json +11 -11
  65. package/dist/react-text-annotator.es10.js +0 -490
  66. package/dist/react-text-annotator.es10.js.map +0 -1
  67. package/dist/react-text-annotator.es16.js +0 -249
  68. package/dist/react-text-annotator.es16.js.map +0 -1
@@ -1,566 +1,152 @@
1
- import { evaluate, getSide, getSideAxis, getOppositePlacement, getExpandedPlacements, getOppositeAxisPlacements, getAlignmentSides, rectToClientRect, getPaddingObject, clamp, getAlignmentAxis, getAlignment, min, max, getOppositeAxis, getAxisLength } from "./react-text-annotator.es30.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;
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));
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 = {};
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 flip = function(options) {
197
- if (options === void 0) {
198
- options = {};
199
- }
200
- return {
201
- name: "flip",
202
- options,
203
- async fn(state) {
204
- var _middlewareData$arrow, _middlewareData$flip;
205
- const {
206
- placement,
207
- middlewareData,
208
- rects,
209
- initialPlacement,
210
- platform,
211
- elements
212
- } = state;
213
- const {
214
- mainAxis: checkMainAxis = true,
215
- crossAxis: checkCrossAxis = true,
216
- fallbackPlacements: specifiedFallbackPlacements,
217
- fallbackStrategy = "bestFit",
218
- fallbackAxisSideDirection = "none",
219
- flipAlignment = true,
220
- ...detectOverflowOptions
221
- } = evaluate(options, state);
222
- if ((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
223
- return {};
224
- }
225
- const side = getSide(placement);
226
- const initialSideAxis = getSideAxis(initialPlacement);
227
- const isBasePlacement = getSide(initialPlacement) === initialPlacement;
228
- const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
229
- const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));
230
- const hasFallbackAxisSideDirection = fallbackAxisSideDirection !== "none";
231
- if (!specifiedFallbackPlacements && hasFallbackAxisSideDirection) {
232
- fallbackPlacements.push(...getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl));
233
- }
234
- const placements = [initialPlacement, ...fallbackPlacements];
235
- const overflow = await detectOverflow(state, detectOverflowOptions);
236
- const overflows = [];
237
- let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
238
- if (checkMainAxis) {
239
- overflows.push(overflow[side]);
240
- }
241
- if (checkCrossAxis) {
242
- const sides = getAlignmentSides(placement, rects, rtl);
243
- overflows.push(overflow[sides[0]], overflow[sides[1]]);
244
- }
245
- overflowsData = [...overflowsData, {
246
- placement,
247
- overflows
248
- }];
249
- if (!overflows.every((side2) => side2 <= 0)) {
250
- var _middlewareData$flip2, _overflowsData$filter;
251
- const nextIndex = (((_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) || 0) + 1;
252
- const nextPlacement = placements[nextIndex];
253
- if (nextPlacement) {
254
- return {
255
- data: {
256
- index: nextIndex,
257
- overflows: overflowsData
258
- },
259
- reset: {
260
- placement: nextPlacement
261
- }
262
- };
263
- }
264
- 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;
265
- if (!resetPlacement) {
266
- switch (fallbackStrategy) {
267
- case "bestFit": {
268
- var _overflowsData$filter2;
269
- const placement2 = (_overflowsData$filter2 = overflowsData.filter((d) => {
270
- if (hasFallbackAxisSideDirection) {
271
- const currentSideAxis = getSideAxis(d.placement);
272
- return currentSideAxis === initialSideAxis || // Create a bias to the `y` side axis due to horizontal
273
- // reading directions favoring greater width.
274
- currentSideAxis === "y";
275
- }
276
- return true;
277
- }).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];
278
- if (placement2) {
279
- resetPlacement = placement2;
280
- }
281
- break;
282
- }
283
- case "initialPlacement":
284
- resetPlacement = initialPlacement;
285
- break;
286
- }
287
- }
288
- if (placement !== resetPlacement) {
289
- return {
290
- reset: {
291
- placement: resetPlacement
292
- }
293
- };
294
- }
295
- }
296
- return {};
297
- }
298
- };
299
- };
300
- function getBoundingRect(rects) {
301
- const minX = min(...rects.map((rect) => rect.left));
302
- const minY = min(...rects.map((rect) => rect.top));
303
- const maxX = max(...rects.map((rect) => rect.right));
304
- const maxY = max(...rects.map((rect) => rect.bottom));
305
- return {
306
- x: minX,
307
- y: minY,
308
- width: maxX - minX,
309
- height: maxY - minY
310
- };
89
+ return list;
311
90
  }
312
- function getRectsByLine(rects) {
313
- const sortedRects = rects.slice().sort((a, b) => a.y - b.y);
314
- const groups = [];
315
- let prevRect = null;
316
- for (let i = 0; i < sortedRects.length; i++) {
317
- const rect = sortedRects[i];
318
- if (!prevRect || rect.y - prevRect.y > prevRect.height / 2) {
319
- groups.push([rect]);
320
- } else {
321
- groups[groups.length - 1].push(rect);
322
- }
323
- prevRect = rect;
324
- }
325
- return groups.map((rect) => rectToClientRect(getBoundingRect(rect)));
91
+ function getOppositePlacement(placement) {
92
+ return placement.replace(/left|right|bottom|top/g, (side) => oppositeSideMap[side]);
326
93
  }
327
- const inline = function(options) {
328
- if (options === void 0) {
329
- options = {};
330
- }
94
+ function expandPaddingObject(padding) {
331
95
  return {
332
- name: "inline",
333
- options,
334
- async fn(state) {
335
- const {
336
- placement,
337
- elements,
338
- rects,
339
- platform,
340
- strategy
341
- } = state;
342
- const {
343
- padding = 2,
344
- x,
345
- y
346
- } = evaluate(options, state);
347
- const nativeClientRects = Array.from(await (platform.getClientRects == null ? void 0 : platform.getClientRects(elements.reference)) || []);
348
- const clientRects = getRectsByLine(nativeClientRects);
349
- const fallback = rectToClientRect(getBoundingRect(nativeClientRects));
350
- const paddingObject = getPaddingObject(padding);
351
- function getBoundingClientRect() {
352
- if (clientRects.length === 2 && clientRects[0].left > clientRects[1].right && x != null && y != null) {
353
- 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;
354
- }
355
- if (clientRects.length >= 2) {
356
- if (getSideAxis(placement) === "y") {
357
- const firstRect = clientRects[0];
358
- const lastRect = clientRects[clientRects.length - 1];
359
- const isTop = getSide(placement) === "top";
360
- const top2 = firstRect.top;
361
- const bottom2 = lastRect.bottom;
362
- const left2 = isTop ? firstRect.left : lastRect.left;
363
- const right2 = isTop ? firstRect.right : lastRect.right;
364
- const width2 = right2 - left2;
365
- const height2 = bottom2 - top2;
366
- return {
367
- top: top2,
368
- bottom: bottom2,
369
- left: left2,
370
- right: right2,
371
- width: width2,
372
- height: height2,
373
- x: left2,
374
- y: top2
375
- };
376
- }
377
- const isLeftSide = getSide(placement) === "left";
378
- const maxRight = max(...clientRects.map((rect) => rect.right));
379
- const minLeft = min(...clientRects.map((rect) => rect.left));
380
- const measureRects = clientRects.filter((rect) => isLeftSide ? rect.left === minLeft : rect.right === maxRight);
381
- const top = measureRects[0].top;
382
- const bottom = measureRects[measureRects.length - 1].bottom;
383
- const left = minLeft;
384
- const right = maxRight;
385
- const width = right - left;
386
- const height = bottom - top;
387
- return {
388
- top,
389
- bottom,
390
- left,
391
- right,
392
- width,
393
- height,
394
- x: left,
395
- y: top
396
- };
397
- }
398
- return fallback;
399
- }
400
- const resetRects = await platform.getElementRects({
401
- reference: {
402
- getBoundingClientRect
403
- },
404
- floating: elements.floating,
405
- strategy
406
- });
407
- 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) {
408
- return {
409
- reset: {
410
- rects: resetRects
411
- }
412
- };
413
- }
414
- return {};
415
- }
416
- };
417
- };
418
- async function convertValueToCoords(state, options) {
419
- const {
420
- placement,
421
- platform,
422
- elements
423
- } = state;
424
- const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
425
- const side = getSide(placement);
426
- const alignment = getAlignment(placement);
427
- const isVertical = getSideAxis(placement) === "y";
428
- const mainAxisMulti = ["left", "top"].includes(side) ? -1 : 1;
429
- const crossAxisMulti = rtl && isVertical ? -1 : 1;
430
- const rawValue = evaluate(options, state);
431
- let {
432
- mainAxis,
433
- crossAxis,
434
- alignmentAxis
435
- } = typeof rawValue === "number" ? {
436
- mainAxis: rawValue,
437
- crossAxis: 0,
438
- alignmentAxis: null
439
- } : {
440
- mainAxis: rawValue.mainAxis || 0,
441
- crossAxis: rawValue.crossAxis || 0,
442
- alignmentAxis: rawValue.alignmentAxis
443
- };
444
- if (alignment && typeof alignmentAxis === "number") {
445
- crossAxis = alignment === "end" ? alignmentAxis * -1 : alignmentAxis;
446
- }
447
- return isVertical ? {
448
- x: crossAxis * crossAxisMulti,
449
- y: mainAxis * mainAxisMulti
450
- } : {
451
- x: mainAxis * mainAxisMulti,
452
- y: crossAxis * crossAxisMulti
96
+ top: 0,
97
+ right: 0,
98
+ bottom: 0,
99
+ left: 0,
100
+ ...padding
453
101
  };
454
102
  }
455
- const offset = function(options) {
456
- if (options === void 0) {
457
- options = 0;
458
- }
459
- return {
460
- name: "offset",
461
- options,
462
- async fn(state) {
463
- var _middlewareData$offse, _middlewareData$arrow;
464
- const {
465
- x,
466
- y,
467
- placement,
468
- middlewareData
469
- } = state;
470
- const diffCoords = await convertValueToCoords(state, options);
471
- if (placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
472
- return {};
473
- }
474
- return {
475
- x: x + diffCoords.x,
476
- y: y + diffCoords.y,
477
- data: {
478
- ...diffCoords,
479
- placement
480
- }
481
- };
482
- }
103
+ function getPaddingObject(padding) {
104
+ return typeof padding !== "number" ? expandPaddingObject(padding) : {
105
+ top: padding,
106
+ right: padding,
107
+ bottom: padding,
108
+ left: padding
483
109
  };
484
- };
485
- const shift = function(options) {
486
- if (options === void 0) {
487
- options = {};
488
- }
110
+ }
111
+ function rectToClientRect(rect) {
112
+ const {
113
+ x,
114
+ y,
115
+ width,
116
+ height
117
+ } = rect;
489
118
  return {
490
- name: "shift",
491
- options,
492
- async fn(state) {
493
- const {
494
- x,
495
- y,
496
- placement
497
- } = state;
498
- const {
499
- mainAxis: checkMainAxis = true,
500
- crossAxis: checkCrossAxis = false,
501
- limiter = {
502
- fn: (_ref) => {
503
- let {
504
- x: x2,
505
- y: y2
506
- } = _ref;
507
- return {
508
- x: x2,
509
- y: y2
510
- };
511
- }
512
- },
513
- ...detectOverflowOptions
514
- } = evaluate(options, state);
515
- const coords = {
516
- x,
517
- y
518
- };
519
- const overflow = await detectOverflow(state, detectOverflowOptions);
520
- const crossAxis = getSideAxis(getSide(placement));
521
- const mainAxis = getOppositeAxis(crossAxis);
522
- let mainAxisCoord = coords[mainAxis];
523
- let crossAxisCoord = coords[crossAxis];
524
- if (checkMainAxis) {
525
- const minSide = mainAxis === "y" ? "top" : "left";
526
- const maxSide = mainAxis === "y" ? "bottom" : "right";
527
- const min2 = mainAxisCoord + overflow[minSide];
528
- const max2 = mainAxisCoord - overflow[maxSide];
529
- mainAxisCoord = clamp(min2, mainAxisCoord, max2);
530
- }
531
- if (checkCrossAxis) {
532
- const minSide = crossAxis === "y" ? "top" : "left";
533
- const maxSide = crossAxis === "y" ? "bottom" : "right";
534
- const min2 = crossAxisCoord + overflow[minSide];
535
- const max2 = crossAxisCoord - overflow[maxSide];
536
- crossAxisCoord = clamp(min2, crossAxisCoord, max2);
537
- }
538
- const limitedCoords = limiter.fn({
539
- ...state,
540
- [mainAxis]: mainAxisCoord,
541
- [crossAxis]: crossAxisCoord
542
- });
543
- return {
544
- ...limitedCoords,
545
- data: {
546
- x: limitedCoords.x - x,
547
- y: limitedCoords.y - y,
548
- enabled: {
549
- [mainAxis]: checkMainAxis,
550
- [crossAxis]: checkCrossAxis
551
- }
552
- }
553
- };
554
- }
119
+ width,
120
+ height,
121
+ top: y,
122
+ left: x,
123
+ right: x + width,
124
+ bottom: y + height,
125
+ x,
126
+ y
555
127
  };
556
- };
128
+ }
557
129
  export {
558
- computePosition,
559
- detectOverflow,
560
- flip,
561
- inline,
562
- 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,
563
149
  rectToClientRect,
564
- shift
150
+ round
565
151
  };
566
152
  //# sourceMappingURL=react-text-annotator.es31.js.map