@phillips/seldon 1.43.0 → 1.44.0

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