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