@annotorious/react 3.1.0 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,129 +1,469 @@
1
- const l = Math.min, a = Math.max, P = Math.round, M = Math.floor, O = (t) => ({
2
- x: t,
3
- y: t
4
- }), m = {
5
- left: "right",
6
- right: "left",
7
- bottom: "top",
8
- top: "bottom"
9
- }, p = {
10
- start: "end",
11
- end: "start"
12
- };
13
- function S(t, n, e) {
14
- return a(t, l(n, e));
15
- }
16
- function w(t, n) {
17
- return typeof t == "function" ? t(n) : t;
18
- }
19
- function f(t) {
20
- return t.split("-")[0];
21
- }
22
- function g(t) {
23
- return t.split("-")[1];
24
- }
25
- function h(t) {
26
- return t === "x" ? "y" : "x";
27
- }
28
- function x(t) {
29
- return t === "y" ? "height" : "width";
30
- }
31
- function b(t) {
32
- return ["top", "bottom"].includes(f(t)) ? "y" : "x";
33
- }
34
- function d(t) {
35
- return h(b(t));
36
- }
37
- function j(t, n, e) {
38
- e === void 0 && (e = !1);
39
- const r = g(t), o = d(t), i = x(o);
40
- let c = o === "x" ? r === (e ? "end" : "start") ? "right" : "left" : r === "start" ? "bottom" : "top";
41
- return n.reference[i] > n.floating[i] && (c = u(c)), [c, u(c)];
42
- }
43
- function C(t) {
44
- const n = u(t);
45
- return [s(t), n, s(n)];
46
- }
47
- function s(t) {
48
- return t.replace(/start|end/g, (n) => p[n]);
49
- }
50
- function A(t, n, e) {
51
- const r = ["left", "right"], o = ["right", "left"], i = ["top", "bottom"], c = ["bottom", "top"];
52
- switch (t) {
1
+ import { evaluate as Y, getSide as F, getSideAxis as M, getOppositePlacement as Q, getExpandedPlacements as U, getOppositeAxisPlacements as Z, getAlignmentSides as ee, rectToClientRect as $, getPaddingObject as H, clamp as _, getAlignmentAxis as q, getAlignment as I, min as X, max as z, getOppositeAxis as te, getAxisLength as G } from "./annotorious-react.es27.js";
2
+ function W(s, c, l) {
3
+ let {
4
+ reference: t,
5
+ floating: o
6
+ } = s;
7
+ const e = M(c), a = q(c), r = G(a), d = F(c), u = e === "y", g = t.x + t.width / 2 - o.width / 2, i = t.y + t.height / 2 - o.height / 2, m = t[r] / 2 - o[r] / 2;
8
+ let n;
9
+ switch (d) {
53
10
  case "top":
11
+ n = {
12
+ x: g,
13
+ y: t.y - o.height
14
+ };
15
+ break;
54
16
  case "bottom":
55
- return e ? n ? o : r : n ? r : o;
56
- case "left":
17
+ n = {
18
+ x: g,
19
+ y: t.y + t.height
20
+ };
21
+ break;
57
22
  case "right":
58
- return n ? i : c;
23
+ n = {
24
+ x: t.x + t.width,
25
+ y: i
26
+ };
27
+ break;
28
+ case "left":
29
+ n = {
30
+ x: t.x - o.width,
31
+ y: i
32
+ };
33
+ break;
59
34
  default:
60
- return [];
35
+ n = {
36
+ x: t.x,
37
+ y: t.y
38
+ };
61
39
  }
40
+ switch (I(c)) {
41
+ case "start":
42
+ n[a] -= m * (l && u ? -1 : 1);
43
+ break;
44
+ case "end":
45
+ n[a] += m * (l && u ? -1 : 1);
46
+ break;
47
+ }
48
+ return n;
62
49
  }
63
- function L(t, n, e, r) {
64
- const o = g(t);
65
- let i = A(f(t), e === "start", r);
66
- return o && (i = i.map((c) => c + "-" + o), n && (i = i.concat(i.map(s)))), i;
67
- }
68
- function u(t) {
69
- return t.replace(/left|right|bottom|top/g, (n) => m[n]);
70
- }
71
- function y(t) {
50
+ const oe = async (s, c, l) => {
51
+ const {
52
+ placement: t = "bottom",
53
+ strategy: o = "absolute",
54
+ middleware: e = [],
55
+ platform: a
56
+ } = l, r = e.filter(Boolean), d = await (a.isRTL == null ? void 0 : a.isRTL(c));
57
+ let u = await a.getElementRects({
58
+ reference: s,
59
+ floating: c,
60
+ strategy: o
61
+ }), {
62
+ x: g,
63
+ y: i
64
+ } = W(u, t, d), m = t, n = {}, f = 0;
65
+ for (let h = 0; h < r.length; h++) {
66
+ const {
67
+ name: x,
68
+ fn: w
69
+ } = r[h], {
70
+ x: b,
71
+ y,
72
+ data: P,
73
+ reset: p
74
+ } = await w({
75
+ x: g,
76
+ y: i,
77
+ initialPlacement: t,
78
+ placement: m,
79
+ strategy: o,
80
+ middlewareData: n,
81
+ rects: u,
82
+ platform: a,
83
+ elements: {
84
+ reference: s,
85
+ floating: c
86
+ }
87
+ });
88
+ g = b ?? g, i = y ?? i, n = {
89
+ ...n,
90
+ [x]: {
91
+ ...n[x],
92
+ ...P
93
+ }
94
+ }, p && f <= 50 && (f++, typeof p == "object" && (p.placement && (m = p.placement), p.rects && (u = p.rects === !0 ? await a.getElementRects({
95
+ reference: s,
96
+ floating: c,
97
+ strategy: o
98
+ }) : p.rects), {
99
+ x: g,
100
+ y: i
101
+ } = W(u, m, d)), h = -1);
102
+ }
103
+ return {
104
+ x: g,
105
+ y: i,
106
+ placement: m,
107
+ strategy: o,
108
+ middlewareData: n
109
+ };
110
+ };
111
+ async function J(s, c) {
112
+ var l;
113
+ c === void 0 && (c = {});
114
+ const {
115
+ x: t,
116
+ y: o,
117
+ platform: e,
118
+ rects: a,
119
+ elements: r,
120
+ strategy: d
121
+ } = s, {
122
+ boundary: u = "clippingAncestors",
123
+ rootBoundary: g = "viewport",
124
+ elementContext: i = "floating",
125
+ altBoundary: m = !1,
126
+ padding: n = 0
127
+ } = Y(c, s), f = H(n), x = r[m ? i === "floating" ? "reference" : "floating" : i], w = $(await e.getClippingRect({
128
+ element: (l = await (e.isElement == null ? void 0 : e.isElement(x))) == null || l ? x : x.contextElement || await (e.getDocumentElement == null ? void 0 : e.getDocumentElement(r.floating)),
129
+ boundary: u,
130
+ rootBoundary: g,
131
+ strategy: d
132
+ })), b = i === "floating" ? {
133
+ x: t,
134
+ y: o,
135
+ width: a.floating.width,
136
+ height: a.floating.height
137
+ } : a.reference, y = await (e.getOffsetParent == null ? void 0 : e.getOffsetParent(r.floating)), P = await (e.isElement == null ? void 0 : e.isElement(y)) ? await (e.getScale == null ? void 0 : e.getScale(y)) || {
138
+ x: 1,
139
+ y: 1
140
+ } : {
141
+ x: 1,
142
+ y: 1
143
+ }, p = $(e.convertOffsetParentRelativeRectToViewportRelativeRect ? await e.convertOffsetParentRelativeRectToViewportRelativeRect({
144
+ elements: r,
145
+ rect: b,
146
+ offsetParent: y,
147
+ strategy: d
148
+ }) : b);
72
149
  return {
73
- top: 0,
74
- right: 0,
75
- bottom: 0,
76
- left: 0,
77
- ...t
150
+ top: (w.top - p.top + f.top) / P.y,
151
+ bottom: (p.bottom - w.bottom + f.bottom) / P.y,
152
+ left: (w.left - p.left + f.left) / P.x,
153
+ right: (p.right - w.right + f.right) / P.x
78
154
  };
79
155
  }
80
- function E(t) {
81
- return typeof t != "number" ? y(t) : {
82
- top: t,
83
- right: t,
84
- bottom: t,
85
- left: t
156
+ const ce = (s) => ({
157
+ name: "arrow",
158
+ options: s,
159
+ async fn(c) {
160
+ const {
161
+ x: l,
162
+ y: t,
163
+ placement: o,
164
+ rects: e,
165
+ platform: a,
166
+ elements: r,
167
+ middlewareData: d
168
+ } = c, {
169
+ element: u,
170
+ padding: g = 0
171
+ } = Y(s, c) || {};
172
+ if (u == null)
173
+ return {};
174
+ const i = H(g), m = {
175
+ x: l,
176
+ y: t
177
+ }, n = q(o), f = G(n), h = await a.getDimensions(u), x = n === "y", w = x ? "top" : "left", b = x ? "bottom" : "right", y = x ? "clientHeight" : "clientWidth", P = e.reference[f] + e.reference[n] - m[n] - e.floating[f], p = m[n] - e.reference[n], C = await (a.getOffsetParent == null ? void 0 : a.getOffsetParent(u));
178
+ let k = C ? C[y] : 0;
179
+ (!k || !await (a.isElement == null ? void 0 : a.isElement(C))) && (k = r.floating[y] || e.floating[f]);
180
+ const j = P / 2 - p / 2, T = k / 2 - h[f] / 2 - 1, A = X(i[w], T), L = X(i[b], T), S = A, B = k - h[f] - L, R = k / 2 - h[f] / 2 + j, D = _(S, R, B), v = !d.arrow && I(o) != null && R !== D && e.reference[f] / 2 - (R < S ? A : L) - h[f] / 2 < 0, O = v ? R < S ? R - S : R - B : 0;
181
+ return {
182
+ [n]: m[n] + O,
183
+ data: {
184
+ [n]: D,
185
+ centerOffset: R - D - O,
186
+ ...v && {
187
+ alignmentOffset: O
188
+ }
189
+ },
190
+ reset: v
191
+ };
192
+ }
193
+ }), le = function(s) {
194
+ return s === void 0 && (s = {}), {
195
+ name: "flip",
196
+ options: s,
197
+ async fn(c) {
198
+ var l, t;
199
+ const {
200
+ placement: o,
201
+ middlewareData: e,
202
+ rects: a,
203
+ initialPlacement: r,
204
+ platform: d,
205
+ elements: u
206
+ } = c, {
207
+ mainAxis: g = !0,
208
+ crossAxis: i = !0,
209
+ fallbackPlacements: m,
210
+ fallbackStrategy: n = "bestFit",
211
+ fallbackAxisSideDirection: f = "none",
212
+ flipAlignment: h = !0,
213
+ ...x
214
+ } = Y(s, c);
215
+ if ((l = e.arrow) != null && l.alignmentOffset)
216
+ return {};
217
+ const w = F(o), b = M(r), y = F(r) === r, P = await (d.isRTL == null ? void 0 : d.isRTL(u.floating)), p = m || (y || !h ? [Q(r)] : U(r)), C = f !== "none";
218
+ !m && C && p.push(...Z(r, h, f, P));
219
+ const k = [r, ...p], j = await J(c, x), T = [];
220
+ let A = ((t = e.flip) == null ? void 0 : t.overflows) || [];
221
+ if (g && T.push(j[w]), i) {
222
+ const R = ee(o, a, P);
223
+ T.push(j[R[0]], j[R[1]]);
224
+ }
225
+ if (A = [...A, {
226
+ placement: o,
227
+ overflows: T
228
+ }], !T.every((R) => R <= 0)) {
229
+ var L, S;
230
+ const R = (((L = e.flip) == null ? void 0 : L.index) || 0) + 1, D = k[R];
231
+ if (D)
232
+ return {
233
+ data: {
234
+ index: R,
235
+ overflows: A
236
+ },
237
+ reset: {
238
+ placement: D
239
+ }
240
+ };
241
+ let v = (S = A.filter((O) => O.overflows[0] <= 0).sort((O, E) => O.overflows[1] - E.overflows[1])[0]) == null ? void 0 : S.placement;
242
+ if (!v)
243
+ switch (n) {
244
+ case "bestFit": {
245
+ var B;
246
+ const O = (B = A.filter((E) => {
247
+ if (C) {
248
+ const V = M(E.placement);
249
+ return V === b || // Create a bias to the `y` side axis due to horizontal
250
+ // reading directions favoring greater width.
251
+ V === "y";
252
+ }
253
+ return !0;
254
+ }).map((E) => [E.placement, E.overflows.filter((V) => V > 0).reduce((V, N) => V + N, 0)]).sort((E, V) => E[1] - V[1])[0]) == null ? void 0 : B[0];
255
+ O && (v = O);
256
+ break;
257
+ }
258
+ case "initialPlacement":
259
+ v = r;
260
+ break;
261
+ }
262
+ if (o !== v)
263
+ return {
264
+ reset: {
265
+ placement: v
266
+ }
267
+ };
268
+ }
269
+ return {};
270
+ }
271
+ };
272
+ };
273
+ function K(s) {
274
+ const c = X(...s.map((e) => e.left)), l = X(...s.map((e) => e.top)), t = z(...s.map((e) => e.right)), o = z(...s.map((e) => e.bottom));
275
+ return {
276
+ x: c,
277
+ y: l,
278
+ width: t - c,
279
+ height: o - l
86
280
  };
87
281
  }
88
- function R(t) {
282
+ function ne(s) {
283
+ const c = s.slice().sort((o, e) => o.y - e.y), l = [];
284
+ let t = null;
285
+ for (let o = 0; o < c.length; o++) {
286
+ const e = c[o];
287
+ !t || e.y - t.y > t.height / 2 ? l.push([e]) : l[l.length - 1].push(e), t = e;
288
+ }
289
+ return l.map((o) => $(K(o)));
290
+ }
291
+ const ae = function(s) {
292
+ return s === void 0 && (s = {}), {
293
+ name: "inline",
294
+ options: s,
295
+ async fn(c) {
296
+ const {
297
+ placement: l,
298
+ elements: t,
299
+ rects: o,
300
+ platform: e,
301
+ strategy: a
302
+ } = c, {
303
+ padding: r = 2,
304
+ x: d,
305
+ y: u
306
+ } = Y(s, c), g = Array.from(await (e.getClientRects == null ? void 0 : e.getClientRects(t.reference)) || []), i = ne(g), m = $(K(g)), n = H(r);
307
+ function f() {
308
+ if (i.length === 2 && i[0].left > i[1].right && d != null && u != null)
309
+ return i.find((x) => d > x.left - n.left && d < x.right + n.right && u > x.top - n.top && u < x.bottom + n.bottom) || m;
310
+ if (i.length >= 2) {
311
+ if (M(l) === "y") {
312
+ const A = i[0], L = i[i.length - 1], S = F(l) === "top", B = A.top, R = L.bottom, D = S ? A.left : L.left, v = S ? A.right : L.right, O = v - D, E = R - B;
313
+ return {
314
+ top: B,
315
+ bottom: R,
316
+ left: D,
317
+ right: v,
318
+ width: O,
319
+ height: E,
320
+ x: D,
321
+ y: B
322
+ };
323
+ }
324
+ const x = F(l) === "left", w = z(...i.map((A) => A.right)), b = X(...i.map((A) => A.left)), y = i.filter((A) => x ? A.left === b : A.right === w), P = y[0].top, p = y[y.length - 1].bottom, C = b, k = w, j = k - C, T = p - P;
325
+ return {
326
+ top: P,
327
+ bottom: p,
328
+ left: C,
329
+ right: k,
330
+ width: j,
331
+ height: T,
332
+ x: C,
333
+ y: P
334
+ };
335
+ }
336
+ return m;
337
+ }
338
+ const h = await e.getElementRects({
339
+ reference: {
340
+ getBoundingClientRect: f
341
+ },
342
+ floating: t.floating,
343
+ strategy: a
344
+ });
345
+ return o.reference.x !== h.reference.x || o.reference.y !== h.reference.y || o.reference.width !== h.reference.width || o.reference.height !== h.reference.height ? {
346
+ reset: {
347
+ rects: h
348
+ }
349
+ } : {};
350
+ }
351
+ };
352
+ };
353
+ async function ie(s, c) {
89
354
  const {
90
- x: n,
91
- y: e,
92
- width: r,
93
- height: o
94
- } = t;
95
- return {
96
- width: r,
97
- height: o,
98
- top: e,
99
- left: n,
100
- right: n + r,
101
- bottom: e + o,
102
- x: n,
103
- y: e
355
+ placement: l,
356
+ platform: t,
357
+ elements: o
358
+ } = s, e = await (t.isRTL == null ? void 0 : t.isRTL(o.floating)), a = F(l), r = I(l), d = M(l) === "y", u = ["left", "top"].includes(a) ? -1 : 1, g = e && d ? -1 : 1, i = Y(c, s);
359
+ let {
360
+ mainAxis: m,
361
+ crossAxis: n,
362
+ alignmentAxis: f
363
+ } = typeof i == "number" ? {
364
+ mainAxis: i,
365
+ crossAxis: 0,
366
+ alignmentAxis: null
367
+ } : {
368
+ mainAxis: i.mainAxis || 0,
369
+ crossAxis: i.crossAxis || 0,
370
+ alignmentAxis: i.alignmentAxis
371
+ };
372
+ return r && typeof f == "number" && (n = r === "end" ? f * -1 : f), d ? {
373
+ x: n * g,
374
+ y: m * u
375
+ } : {
376
+ x: m * u,
377
+ y: n * g
104
378
  };
105
379
  }
380
+ const re = function(s) {
381
+ return s === void 0 && (s = 0), {
382
+ name: "offset",
383
+ options: s,
384
+ async fn(c) {
385
+ var l, t;
386
+ const {
387
+ x: o,
388
+ y: e,
389
+ placement: a,
390
+ middlewareData: r
391
+ } = c, d = await ie(c, s);
392
+ return a === ((l = r.offset) == null ? void 0 : l.placement) && (t = r.arrow) != null && t.alignmentOffset ? {} : {
393
+ x: o + d.x,
394
+ y: e + d.y,
395
+ data: {
396
+ ...d,
397
+ placement: a
398
+ }
399
+ };
400
+ }
401
+ };
402
+ }, fe = function(s) {
403
+ return s === void 0 && (s = {}), {
404
+ name: "shift",
405
+ options: s,
406
+ async fn(c) {
407
+ const {
408
+ x: l,
409
+ y: t,
410
+ placement: o
411
+ } = c, {
412
+ mainAxis: e = !0,
413
+ crossAxis: a = !1,
414
+ limiter: r = {
415
+ fn: (x) => {
416
+ let {
417
+ x: w,
418
+ y: b
419
+ } = x;
420
+ return {
421
+ x: w,
422
+ y: b
423
+ };
424
+ }
425
+ },
426
+ ...d
427
+ } = Y(s, c), u = {
428
+ x: l,
429
+ y: t
430
+ }, g = await J(c, d), i = M(F(o)), m = te(i);
431
+ let n = u[m], f = u[i];
432
+ if (e) {
433
+ const x = m === "y" ? "top" : "left", w = m === "y" ? "bottom" : "right", b = n + g[x], y = n - g[w];
434
+ n = _(b, n, y);
435
+ }
436
+ if (a) {
437
+ const x = i === "y" ? "top" : "left", w = i === "y" ? "bottom" : "right", b = f + g[x], y = f - g[w];
438
+ f = _(b, f, y);
439
+ }
440
+ const h = r.fn({
441
+ ...c,
442
+ [m]: n,
443
+ [i]: f
444
+ });
445
+ return {
446
+ ...h,
447
+ data: {
448
+ x: h.x - l,
449
+ y: h.y - t,
450
+ enabled: {
451
+ [m]: e,
452
+ [i]: a
453
+ }
454
+ }
455
+ };
456
+ }
457
+ };
458
+ };
106
459
  export {
107
- S as clamp,
108
- O as createCoords,
109
- w as evaluate,
110
- y as expandPaddingObject,
111
- M as floor,
112
- g as getAlignment,
113
- d as getAlignmentAxis,
114
- j as getAlignmentSides,
115
- x as getAxisLength,
116
- C as getExpandedPlacements,
117
- s as getOppositeAlignmentPlacement,
118
- h as getOppositeAxis,
119
- L as getOppositeAxisPlacements,
120
- u as getOppositePlacement,
121
- E as getPaddingObject,
122
- f as getSide,
123
- b as getSideAxis,
124
- a as max,
125
- l as min,
126
- R as rectToClientRect,
127
- P as round
460
+ ce as arrow,
461
+ oe as computePosition,
462
+ J as detectOverflow,
463
+ le as flip,
464
+ ae as inline,
465
+ re as offset,
466
+ $ as rectToClientRect,
467
+ fe as shift
128
468
  };
129
469
  //# sourceMappingURL=annotorious-react.es28.js.map