@fiscozen/composables 0.1.33 → 0.1.35-beta

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,452 +1,212 @@
1
- import { ref as m, reactive as ne, onUnmounted as ee, nextTick as te, onMounted as L, watch as k, onBeforeUnmount as O, getCurrentInstance as ie, computed as oe, defineComponent as ae, useSlots as se, toRef as X, toRefs as le, openBlock as B, createElementBlock as Y, renderSlot as R, createElementVNode as J, unref as F, withDirectives as Z, normalizeClass as _, vShow as j, createCommentVNode as V, createBlock as re, Teleport as ue } from "vue";
2
- const E = new DOMRect(0, 0, window.innerWidth, window.innerHeight), w = (o, n, e, u, i) => {
3
- let a = i ? "bottom" : "right", h = i ? "bottom-start" : "right-start";
4
- E.width = window.innerWidth, E.height = window.innerHeight, E.x = 0, E.y = 0;
5
- const r = o ? o.getBoundingClientRect() : E, t = n.getBoundingClientRect(), d = e.getBoundingClientRect(), g = (d.left - r.left - t.width) / r.width, s = (r.right - d.right - t.width) / r.width, v = (d.top - r.top - t.height) / r.height, l = (r.bottom - d.bottom - t.height) / r.height;
6
- let c = [
1
+ import { ref as d, reactive as w, onUnmounted as O, nextTick as B, defineComponent as $, useSlots as C, computed as P, toRef as S, watch as y, openBlock as z, createElementBlock as F, createElementVNode as k, renderSlot as R, unref as x, withDirectives as N, vShow as E } from "vue";
2
+ const g = (s, n, l, p) => {
3
+ let i = "right", e = "right-start";
4
+ const r = s.getBoundingClientRect(), c = n.getBoundingClientRect(), h = l.getBoundingClientRect(), m = (h.left - r.left - c.width) / r.width, t = (r.right - h.right - c.width) / r.width, o = (h.top - r.top - c.height) / r.height, f = (r.bottom - h.bottom - c.height) / r.height;
5
+ if (i = [
7
6
  {
8
7
  key: "right",
9
- space: s
8
+ space: t
10
9
  },
11
10
  {
12
11
  key: "top",
13
- space: v
12
+ space: o
14
13
  },
15
14
  {
16
15
  key: "bottom",
17
- space: l
16
+ space: f
18
17
  },
19
18
  {
20
19
  key: "left",
21
- space: g
20
+ space: m
22
21
  }
23
- ].sort((p, f) => f.space - p.space);
24
- if (i && (c = c.filter((p) => p.key === "top" || p.key === "bottom")), a = c[0].key, !u)
25
- switch (a) {
22
+ ].sort((a, v) => v.space - a.space)[0].key, !p)
23
+ switch (i) {
26
24
  case "right":
27
25
  case "left":
28
- const p = (t.height - d.height) / 2;
29
- r.top > d.top - p && (u = "end"), r.bottom < d.top - p && (u = "start");
26
+ const a = (c.height - h.height) / 2;
27
+ r.top > h.top - a && (p = "end"), r.bottom < h.top - a && (p = "start");
30
28
  break;
31
29
  }
32
- return h = u ? `${a}-${u}` : a, h;
33
- }, ve = (o, n, e, u) => ({
34
- x: n.x + o.width * e / 100,
35
- y: n.y + o.height * u / 100
36
- }), pe = (o) => {
37
- const n = m(null), e = m(null), u = m(null), i = m(), a = m(), h = m("auto"), r = m(), t = ne({
30
+ return e = p ? `${i}-${p}` : i, e;
31
+ }, q = (s, n, l, p) => ({
32
+ x: n.x + s.width * l / 100,
33
+ y: n.y + s.height * p / 100
34
+ }), D = (s) => {
35
+ const n = d(null), l = d(null), p = d(null), i = d(null), e = w({
38
36
  position: { x: 0, y: 0 }
39
- }), d = {
37
+ }), r = {
40
38
  root: null,
41
39
  rootMargin: "0px",
42
40
  threshold: 1,
43
- ...o.element.value.intersectionOptions
44
- }, g = (c, p) => {
45
- }, s = m(new IntersectionObserver(g, d)), v = m(), l = () => te(() => {
46
- var $, N, z, P, S, D, M, A, W, I, q, T, G, H, U;
47
- if (v.value = o.position ? o.position.value : "auto", n.value = typeof o.element.value.domRef.value == "string" ? document.querySelector(o.element.value.domRef.value) : o.element.value.domRef.value, ($ = o.container) != null && $.value ? (e.value = typeof ((N = o.container.value) == null ? void 0 : N.domRef.value) == "string" ? document.querySelector(o.container.value.domRef.value) : (z = o.container.value) == null ? void 0 : z.domRef.value, e.value ?? (e.value = document.body)) : e.value = document.body, !n.value)
41
+ ...s.element.intersectionOptions
42
+ }, c = (t, o) => {
43
+ }, h = d(new IntersectionObserver(c, r)), m = () => B(() => {
44
+ var b;
45
+ if (n.value = typeof s.element.domRef.value == "string" ? document.querySelector(s.element.domRef.value) : s.element.domRef.value, s.container ? (l.value = typeof s.container.domRef.value == "string" ? document.querySelector(s.container.domRef.value) : s.container.domRef.value, l.value ?? (l.value = document.body)) : l.value = document.body, !n.value)
48
46
  throw new Error("missing reference element for floating behavior");
49
- (P = o.opener) != null && P.value && (u.value = typeof ((S = o.opener.value) == null ? void 0 : S.domRef.value) == "string" ? document.querySelector(o.opener.value.domRef.value) : (D = o.opener.value) == null ? void 0 : D.domRef.value), r.value = n.value.getBoundingClientRect(), i.value = (M = u.value) == null ? void 0 : M.getBoundingClientRect(), a.value = e.value.getBoundingClientRect();
50
- const c = window.getComputedStyle(n.value);
51
- s.value.observe(n.value), s.value.observe(e.value);
52
- let p = 0, f = 0;
53
- if ((A = o.opener) != null && A.value && u.value && (i != null && i.value)) {
54
- const y = i.value.left - parseFloat(c.marginLeft) - parseFloat(c.marginRight), K = i.value.left - parseFloat(c.marginLeft), x = i.value.top - parseFloat(c.marginTop) - parseFloat(c.marginBottom), Q = i.value.top - parseFloat(c.marginTop);
55
- switch (v.value) {
47
+ s.opener && (p.value = typeof s.opener.domRef.value == "string" ? document.querySelector(s.opener.domRef.value) : s.opener.domRef.value), i.value = n.value.getBoundingClientRect();
48
+ const t = (b = p.value) == null ? void 0 : b.getBoundingClientRect(), o = l.value.getBoundingClientRect();
49
+ h.value.observe(n.value), h.value.observe(l.value);
50
+ let f = s.position ? s.position.value : "auto", u = 0, a = 0;
51
+ if (s.opener && p.value && t) {
52
+ switch (f) {
56
53
  case "auto":
57
- v.value = w(
58
- (W = o.useViewport) != null && W.value ? null : e.value,
54
+ f = g(
55
+ l.value,
59
56
  n.value,
60
- u.value
61
- );
62
- break;
63
- case "auto-vertical":
64
- v.value = w(
65
- (I = o.useViewport) != null && I.value ? null : e.value,
66
- n.value,
67
- u.value,
68
- void 0,
69
- !0
57
+ p.value
70
58
  );
71
59
  break;
72
60
  case "auto-start":
73
- v.value = w(
74
- (q = o.useViewport) != null && q.value ? null : e.value,
61
+ f = g(
62
+ l.value,
75
63
  n.value,
76
- u.value,
64
+ p.value,
77
65
  "start"
78
66
  );
79
67
  break;
80
- case "auto-vertical-start":
81
- v.value = w(
82
- (T = o.useViewport) != null && T.value ? null : e.value,
83
- n.value,
84
- u.value,
85
- "start",
86
- !0
87
- );
88
- break;
89
68
  case "auto-end":
90
- v.value = w(
91
- (G = o.useViewport) != null && G.value ? null : e.value,
69
+ f = g(
70
+ l.value,
92
71
  n.value,
93
- u.value,
72
+ p.value,
94
73
  "end"
95
74
  );
96
75
  break;
97
- case "auto-vertical-end":
98
- v.value = w(
99
- (H = o.useViewport) != null && H.value ? null : e.value,
100
- n.value,
101
- u.value,
102
- "end",
103
- !0
104
- );
105
- break;
106
76
  }
107
- switch (v.value) {
77
+ switch (f) {
108
78
  case "bottom":
109
- t.position.y = i.value.bottom, t.position.x = K + i.value.width / 2, f = -50, p = 0;
79
+ e.position.y = t.bottom, e.position.x = t.left + t.width / 2, a = -50, u = 0;
110
80
  break;
111
81
  case "bottom-start":
112
- t.position.y = i.value.bottom, t.position.x = y, f = 0, p = 0;
82
+ e.position.y = t.bottom, e.position.x = t.left, a = 0, u = 0;
113
83
  break;
114
84
  case "bottom-end":
115
- t.position.y = i.value.bottom, t.position.x = i.value.right, f = -100, p = 0;
85
+ e.position.y = t.bottom, e.position.x = t.right, a = -100, u = 0;
116
86
  break;
117
87
  case "left-start":
118
- t.position.y = x, t.position.x = y, f = -100, p = 0;
88
+ e.position.y = t.top, e.position.x = t.left, a = -100, u = 0;
119
89
  break;
120
90
  case "left":
121
- t.position.y = Q + i.value.height / 2, t.position.x = y, p = -50, f = -100;
91
+ e.position.y = t.top + t.height / 2, e.position.x = t.left, u = -50, a = -100;
122
92
  break;
123
93
  case "left-end":
124
- t.position.y = i.value.bottom, t.position.x = y, p = -100, f = -100;
94
+ e.position.y = t.bottom, e.position.x = t.left, u = -100, a = -100;
125
95
  break;
126
96
  case "top-start":
127
- t.position.y = x, t.position.x = y, p = -100, f = 0;
97
+ e.position.y = t.top, e.position.x = t.left, u = -100, a = 0;
128
98
  break;
129
99
  case "top":
130
- t.position.y = x, t.position.x = K + i.value.width / 2, f = -50, p = -100;
100
+ e.position.y = t.top, e.position.x = t.left + t.width / 2, a = -50, u = -100;
131
101
  break;
132
102
  case "top-end":
133
- t.position.y = x, t.position.x = i.value.right, f = -100, p = -100;
103
+ e.position.y = t.top, e.position.x = t.right, a = -100, u = -100;
134
104
  break;
135
105
  case "right-start":
136
- t.position.y = x, t.position.x = i.value.right, f = 0, p = 0;
106
+ e.position.y = t.top, e.position.x = t.right, a = 0, u = 0;
137
107
  break;
138
108
  case "right":
139
- t.position.y = Q + i.value.height / 2, t.position.x = i.value.right, p = -50, f = 0;
109
+ e.position.y = t.top + t.height / 2, e.position.x = t.right, u = -50, a = 0;
140
110
  break;
141
111
  case "right-end":
142
- t.position.y = i.value.bottom, t.position.x = i.value.right, p = -100, f = 0;
112
+ e.position.y = t.bottom, e.position.x = t.right, u = -100, a = 0;
143
113
  break;
144
114
  }
145
115
  } else
146
- switch (v.value) {
116
+ switch (f) {
147
117
  case "bottom":
148
- t.position.y = a.value.bottom - r.value.height, t.position.x = a.value.left + a.value.width / 2, f = -50;
118
+ e.position.y = o.bottom - i.value.height, e.position.x = o.left + o.width / 2, a = -50;
149
119
  break;
150
120
  case "left-end":
151
121
  case "bottom-start":
152
- t.position.y = a.value.bottom - r.value.height, t.position.x = a.value.left;
122
+ e.position.y = o.bottom - i.value.height, e.position.x = o.left;
153
123
  break;
154
124
  case "right-end":
155
125
  case "bottom-end":
156
- t.position.y = a.value.bottom - r.value.height, t.position.x = a.value.right - r.value.width;
126
+ e.position.y = o.bottom - i.value.height, e.position.x = o.right - i.value.width;
157
127
  break;
158
128
  case "left":
159
- t.position.y = a.value.top + (a.value.height - r.value.height) / 2, t.position.x = a.value.left;
129
+ e.position.y = o.top + (o.height - i.value.height) / 2, e.position.x = o.left;
160
130
  break;
161
131
  case "top-start":
162
132
  case "left-start":
163
- t.position.y = a.value.top, t.position.x = a.value.left;
133
+ e.position.y = o.top, e.position.x = o.left;
164
134
  break;
165
135
  case "top":
166
- t.position.y = a.value.top, t.position.x = a.value.left + (a.value.width - r.value.width) / 2;
136
+ e.position.y = o.top, e.position.x = o.left + (o.width - i.value.width) / 2;
167
137
  break;
168
138
  case "top-end":
169
139
  case "right-start":
170
- t.position.y = a.value.top, t.position.x = a.value.right - r.value.width;
140
+ e.position.y = o.top, e.position.x = o.right - i.value.width;
171
141
  case "right":
172
- t.position.y = a.value.top + (a.value.height - r.value.height) / 2, t.position.x = a.value.right - r.value.width;
142
+ e.position.y = o.top + (o.height - i.value.height) / 2, e.position.x = o.right - i.value.width;
173
143
  break;
174
144
  }
175
- const b = ve(r.value, t.position, f, p);
176
- if (t.position.x = b.x, t.position.y = b.y, b.x < a.value.left && (t.position.x = a.value.left, f = 0), b.x + r.value.width > a.value.right) {
177
- const y = a.value.right - r.value.width;
178
- y > 0 && (t.position.x = y), f = 0;
179
- }
180
- if (b.y < a.value.top && (t.position.y = a.value.top, p = 0), b.y + r.value.height > a.value.bottom) {
181
- const y = a.value.bottom - r.value.height;
182
- y > 0 && (t.position.y = y), p = 0;
183
- }
184
- n.value.style.top = `${t.position.y}px`, n.value.style.left = `${t.position.x}px`, n.value.style.position = "fixed", n.value.style.display = "flex", r.value = n.value.getBoundingClientRect(), (U = o.callback) != null && U.value && o.callback.value(r, i, a, h, v);
185
- });
186
- return ee(() => {
187
- s.value.disconnect();
188
- }), {
189
- float: t,
190
- rect: r,
191
- setPosition: l,
192
- position: h,
193
- actualPosition: v,
194
- openerRect: i,
195
- containerRect: a
196
- };
197
- };
198
- function C(o) {
199
- const n = window.matchMedia(o), e = m(n.matches);
200
- function u(i) {
201
- e.value = i.matches;
202
- }
203
- return L(() => {
204
- n.addEventListener("change", u);
205
- }), ee(() => {
206
- n.removeEventListener("change", u);
207
- }), e;
208
- }
209
- function fe(o) {
210
- return {
211
- isGreater(n) {
212
- return C(`(min-width: ${o[n]})`);
213
- },
214
- isSmaller(n) {
215
- return C(`(max-width: ${o[n]})`);
216
- },
217
- isInBetween(n, e) {
218
- return C(`(min-width: ${o[n]}) and (max-width: ${o[e]})`);
219
- }
220
- };
221
- }
222
- function de(o, n, e) {
223
- if (!o)
224
- throw new Error("A target component has to be provided.");
225
- if (!n)
226
- throw new Error("A callback has to be provided.");
227
- const u = (i) => {
228
- !o.value || i.target === o.value || i.composedPath().includes(o.value) || typeof n == "function" && n();
229
- };
230
- e && k(e, (i, a) => {
231
- a && a.removeEventListener("click", u), i == null || i.addEventListener("click", u);
232
- }), L(() => {
233
- e || document.addEventListener("click", u);
234
- }), O(() => {
235
- var i;
236
- if (e) {
237
- (i = e.value) == null || i.removeEventListener("click", u);
238
- return;
239
- }
240
- document.removeEventListener("click", u);
241
- });
242
- }
243
- function me(o, n) {
244
- if (!o)
245
- throw new Error("A target component has to be provided.");
246
- if (!n || typeof n != "function")
247
- throw new Error("A callback has to be provided.");
248
- const e = (u) => {
249
- n(u);
250
- };
251
- L(() => {
252
- o.value.addEventListener("keydown", e);
253
- }), O(() => {
254
- o.value.removeEventListener("keydown", e);
255
- });
256
- }
257
- function he(o, n) {
258
- if (!o || typeof o != "function")
259
- throw new Error("A callback has to be provided.");
260
- const e = (u) => {
261
- o(u);
262
- };
263
- L(() => {
264
- if (!n) {
265
- document.addEventListener("keyup", e);
266
- return;
267
- }
268
- n.value.addEventListener("keyup", e);
269
- }), O(() => {
270
- if (!n) {
271
- document.removeEventListener("keyup", e);
272
- return;
273
- }
274
- n.value.removeEventListener("keyup", e);
145
+ const v = q(i.value, e.position, a, u);
146
+ v.x < o.left && (e.position.x = o.left, a = 0), v.x + i.value.width > o.right && (e.position.x = o.right - i.value.width, a = 0), v.y < o.top && (e.position.y = o.top, u = 0), v.y + i.value.height > o.bottom && (e.position.y = o.bottom - i.value.height, u = 0), n.value.style.top = `${e.position.y}px`, n.value.style.left = `${e.position.x}px`, n.value.style.transform = `translateY(${u}%) translateX(${a}%)`, n.value.style.position = "absolute", i.value = n.value.getBoundingClientRect();
275
147
  });
276
- }
277
- const ge = (o) => {
278
- const n = m(null), e = ie(), u = oe(() => e == null ? void 0 : e.props.amount), i = m(), a = (s) => {
279
- if (s === null)
280
- return "";
281
- const v = {
282
- minimumFractionDigits: o.minimumFractionDigits,
283
- useGrouping: o.useGrouping || !1
284
- };
285
- return o.maximumFractionDigits !== null && (v.maximumFractionDigits = o.maximumFractionDigits), s.toLocaleString("it-IT", v);
286
- }, h = (s) => parseFloat(s.replace(/,/g, ".")), r = (s) => {
287
- if (!Number.isNaN(s) && e) {
288
- if (i.value = s, e.props.nullOnEmpty && !s) {
289
- e.emit("update:amount", null);
290
- return;
291
- }
292
- e.emit("update:amount", typeof u.value == "number" ? s : s == null ? void 0 : s.toString());
293
- }
294
- }, t = (s) => {
295
- setTimeout(() => {
296
- n.value && (n.value.value = s);
297
- }, 0);
298
- }, d = (s) => (v) => {
299
- if (!n.value || !v.target)
300
- return;
301
- let { value: l } = s;
302
- l = l.replace(/[^0-9,.-]/g, ""), t(l);
303
- const c = e != null && e.props.nullOnEmpty && l === "" ? null : h(l);
304
- r(Number.isNaN(c) ? 0 : c);
305
- }, g = (s) => {
306
- if (!n.value || !s.target)
307
- return;
308
- const v = s.target.value.replace(/,/g, ".");
309
- let l;
310
- v === "" && (e != null && e.props.nullOnEmpty) ? l = null : (l = h(v), Number.isNaN(l) && (l = 0));
311
- const c = a(l);
312
- t(c), r(h(c));
313
- };
314
- return k(n, (s, v) => {
315
- s && (v && (v == null || v.removeEventListener("input", d(s)), v == null || v.removeEventListener("blur", g)), s.addEventListener("input", d(s)), s.addEventListener("blur", g), e != null && e.props.amount && (s.value = a(u.value)));
316
- }), k(u, (s) => {
317
- te(() => {
318
- if (!(!n.value || s === null || s === void 0) && i.value !== s) {
319
- const v = a(s);
320
- n.value.value = v, i.value = s;
321
- }
322
- });
148
+ return O(() => {
149
+ h.value.disconnect();
323
150
  }), {
324
- inputRef: n,
325
- parse: h,
326
- format: a,
327
- emitAmount: r,
328
- setValue: t
151
+ float: e,
152
+ rect: i,
153
+ floatObserver: h,
154
+ setPosition: m
329
155
  };
330
- }, ye = /* @__PURE__ */ ae({
156
+ }, I = /* @__PURE__ */ $({
331
157
  __name: "FzFloating",
332
158
  props: {
333
159
  isOpen: { type: Boolean, default: !1 },
334
160
  position: { default: "auto" },
335
- container: {},
336
- contentClass: {},
337
- openerClass: {},
338
- overrideContentClass: { type: Boolean },
339
- overrideOpener: {},
340
- teleport: { type: Boolean, default: !1 },
341
- useViewport: { type: Boolean }
161
+ container: {}
342
162
  },
343
- emits: ["fzfloating:setPosition"],
344
- setup(o, { emit: n }) {
345
- const e = o, u = n, i = m(null), a = m(null), h = se();
346
- let r = !1;
347
- const t = {
348
- position: e.position,
163
+ setup(s) {
164
+ const n = s, l = d(null), p = d(null), i = C(), e = {
165
+ position: P(() => n.position),
349
166
  element: {
350
- // @ts-ignore
351
- domRef: i
167
+ domRef: p
352
168
  },
353
169
  container: {
354
- // @ts-ignore
355
- domRef: X(e.container || document.body)
356
- },
357
- opener: {
358
- domRef: X(null)
359
- },
360
- useViewport: e.useViewport,
361
- callback(...l) {
362
- u("fzfloating:setPosition", ...l);
170
+ domRef: S(n.container || document.body)
363
171
  }
364
- }, d = le(t);
365
- h.opener && (t.opener = {
366
- // @ts-ignore
367
- domRef: a
368
- });
369
- const g = pe(d), s = () => {
370
- r || (r = !0, requestAnimationFrame(() => {
371
- e.isOpen && g.setPosition(), r = !1;
372
- }));
373
172
  };
374
- k(
375
- () => e.position,
376
- () => s()
377
- ), k(
378
- () => e.isOpen,
379
- (l) => {
380
- if (!l || !i.value) {
381
- window.removeEventListener("scroll", s);
382
- return;
383
- }
384
- window.addEventListener("scroll", s), i.value.style.top = "0px", i.value.style.left = "0px", i.value.style.transform = "none", g.setPosition();
385
- }
386
- ), k(
387
- () => e.overrideOpener,
388
- (l) => {
389
- l && d.opener && d.opener.value && (d.opener.value = {
390
- domRef: l
391
- });
392
- }
393
- ), O(() => {
394
- window.removeEventListener("scroll", s);
173
+ i.opener && (e.opener = {
174
+ domRef: l
395
175
  });
396
- const v = oe(() => e.overrideContentClass ? e.contentClass : ["bg-core-white fixed p-4 z-10", e.contentClass]);
397
- return (l, c) => (B(), Y("div", null, [
398
- R(l.$slots, "opener-start"),
399
- J("div", {
176
+ const r = D(e);
177
+ return y(
178
+ () => n.position,
179
+ () => n.isOpen && r.setPosition()
180
+ ), y(
181
+ () => n.isOpen,
182
+ (c) => c && r.setPosition()
183
+ ), (c, h) => (z(), F("div", null, [
184
+ k("div", {
400
185
  ref_key: "opener",
401
- ref: a,
186
+ ref: l,
402
187
  class: "inline-flex"
403
188
  }, [
404
- R(l.$slots, "opener", {
405
- isOpen: l.isOpen,
406
- floating: F(g)
189
+ R(c.$slots, "opener", {
190
+ isOpen: c.isOpen,
191
+ floating: x(r)
407
192
  })
408
193
  ], 512),
409
- R(l.$slots, "opener-end"),
410
- l.teleport ? V("", !0) : Z((B(), Y("div", {
411
- key: 0,
194
+ N(k("div", {
412
195
  ref_key: "content",
413
- ref: i,
414
- class: _(["fz__floating__content", v.value])
196
+ ref: p,
197
+ class: "bg-core-white absolute p-4"
415
198
  }, [
416
- R(l.$slots, "default", {
417
- isOpen: l.isOpen,
418
- floating: F(g)
199
+ R(c.$slots, "default", {
200
+ isOpen: c.isOpen,
201
+ floating: x(r)
419
202
  })
420
- ], 2)), [
421
- [j, l.$slots.default && (!l.$slots.opener || l.$slots.opener && l.isOpen)]
422
- ]),
423
- l.teleport ? (B(), re(ue, {
424
- key: 1,
425
- to: "body"
426
- }, [
427
- Z(J("div", {
428
- ref_key: "content",
429
- ref: i,
430
- class: _(["fz__floating__content", v.value])
431
- }, [
432
- R(l.$slots, "default", {
433
- isOpen: l.isOpen,
434
- floating: F(g)
435
- })
436
- ], 2), [
437
- [j, l.$slots.default && (!l.$slots.opener || l.$slots.opener && l.isOpen)]
438
- ])
439
- ])) : V("", !0)
203
+ ], 512), [
204
+ [E, !c.$slots.opener || c.$slots.opener && c.isOpen]
205
+ ])
440
206
  ]));
441
207
  }
442
208
  });
443
209
  export {
444
- ye as FzFloating,
445
- fe as useBreakpoints,
446
- de as useClickOutside,
447
- ge as useCurrency,
448
- pe as useFloating,
449
- me as useKeyDown,
450
- he as useKeyUp,
451
- C as useMediaQuery
210
+ I as FzFloating,
211
+ D as useFloating
452
212
  };
@@ -1 +1 @@
1
- (function(h,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(h=typeof globalThis<"u"?globalThis:h||self,e(h.FzComposables={},h.Vue))})(this,function(h,e){"use strict";const E=new DOMRect(0,0,window.innerWidth,window.innerHeight),w=(n,i,t,c,a)=>{let r=a?"bottom":"right",g=a?"bottom-start":"right-start";E.width=window.innerWidth,E.height=window.innerHeight,E.x=0,E.y=0;const u=n?n.getBoundingClientRect():E,o=i.getBoundingClientRect(),m=t.getBoundingClientRect(),y=(m.left-u.left-o.width)/u.width,l=(u.right-m.right-o.width)/u.width,p=(m.top-u.top-o.height)/u.height,s=(u.bottom-m.bottom-o.height)/u.height;let d=[{key:"right",space:l},{key:"top",space:p},{key:"bottom",space:s},{key:"left",space:y}].sort((f,v)=>v.space-f.space);if(a&&(d=d.filter(f=>f.key==="top"||f.key==="bottom")),r=d[0].key,!c)switch(r){case"right":case"left":const f=(o.height-m.height)/2;u.top>m.top-f&&(c="end"),u.bottom<m.top-f&&(c="start");break}return g=c?`${r}-${c}`:r,g},K=(n,i,t,c)=>({x:i.x+n.width*t/100,y:i.y+n.height*c/100}),B=n=>{const i=e.ref(null),t=e.ref(null),c=e.ref(null),a=e.ref(),r=e.ref(),g=e.ref("auto"),u=e.ref(),o=e.reactive({position:{x:0,y:0}}),m={root:null,rootMargin:"0px",threshold:1,...n.element.value.intersectionOptions},y=(d,f)=>{},l=e.ref(new IntersectionObserver(y,m)),p=e.ref(),s=()=>e.nextTick(()=>{var C,L,O,F,S,$,N,M,z,D,P,A,T,U,W;if(p.value=n.position?n.position.value:"auto",i.value=typeof n.element.value.domRef.value=="string"?document.querySelector(n.element.value.domRef.value):n.element.value.domRef.value,(C=n.container)!=null&&C.value?(t.value=typeof((L=n.container.value)==null?void 0:L.domRef.value)=="string"?document.querySelector(n.container.value.domRef.value):(O=n.container.value)==null?void 0:O.domRef.value,t.value??(t.value=document.body)):t.value=document.body,!i.value)throw new Error("missing reference element for floating behavior");(F=n.opener)!=null&&F.value&&(c.value=typeof((S=n.opener.value)==null?void 0:S.domRef.value)=="string"?document.querySelector(n.opener.value.domRef.value):($=n.opener.value)==null?void 0:$.domRef.value),u.value=i.value.getBoundingClientRect(),a.value=(N=c.value)==null?void 0:N.getBoundingClientRect(),r.value=t.value.getBoundingClientRect();const d=window.getComputedStyle(i.value);l.value.observe(i.value),l.value.observe(t.value);let f=0,v=0;if((M=n.opener)!=null&&M.value&&c.value&&(a!=null&&a.value)){const b=a.value.left-parseFloat(d.marginLeft)-parseFloat(d.marginRight),I=a.value.left-parseFloat(d.marginLeft),R=a.value.top-parseFloat(d.marginTop)-parseFloat(d.marginBottom),q=a.value.top-parseFloat(d.marginTop);switch(p.value){case"auto":p.value=w((z=n.useViewport)!=null&&z.value?null:t.value,i.value,c.value);break;case"auto-vertical":p.value=w((D=n.useViewport)!=null&&D.value?null:t.value,i.value,c.value,void 0,!0);break;case"auto-start":p.value=w((P=n.useViewport)!=null&&P.value?null:t.value,i.value,c.value,"start");break;case"auto-vertical-start":p.value=w((A=n.useViewport)!=null&&A.value?null:t.value,i.value,c.value,"start",!0);break;case"auto-end":p.value=w((T=n.useViewport)!=null&&T.value?null:t.value,i.value,c.value,"end");break;case"auto-vertical-end":p.value=w((U=n.useViewport)!=null&&U.value?null:t.value,i.value,c.value,"end",!0);break}switch(p.value){case"bottom":o.position.y=a.value.bottom,o.position.x=I+a.value.width/2,v=-50,f=0;break;case"bottom-start":o.position.y=a.value.bottom,o.position.x=b,v=0,f=0;break;case"bottom-end":o.position.y=a.value.bottom,o.position.x=a.value.right,v=-100,f=0;break;case"left-start":o.position.y=R,o.position.x=b,v=-100,f=0;break;case"left":o.position.y=q+a.value.height/2,o.position.x=b,f=-50,v=-100;break;case"left-end":o.position.y=a.value.bottom,o.position.x=b,f=-100,v=-100;break;case"top-start":o.position.y=R,o.position.x=b,f=-100,v=0;break;case"top":o.position.y=R,o.position.x=I+a.value.width/2,v=-50,f=-100;break;case"top-end":o.position.y=R,o.position.x=a.value.right,v=-100,f=-100;break;case"right-start":o.position.y=R,o.position.x=a.value.right,v=0,f=0;break;case"right":o.position.y=q+a.value.height/2,o.position.x=a.value.right,f=-50,v=0;break;case"right-end":o.position.y=a.value.bottom,o.position.x=a.value.right,f=-100,v=0;break}}else switch(p.value){case"bottom":o.position.y=r.value.bottom-u.value.height,o.position.x=r.value.left+r.value.width/2,v=-50;break;case"left-end":case"bottom-start":o.position.y=r.value.bottom-u.value.height,o.position.x=r.value.left;break;case"right-end":case"bottom-end":o.position.y=r.value.bottom-u.value.height,o.position.x=r.value.right-u.value.width;break;case"left":o.position.y=r.value.top+(r.value.height-u.value.height)/2,o.position.x=r.value.left;break;case"top-start":case"left-start":o.position.y=r.value.top,o.position.x=r.value.left;break;case"top":o.position.y=r.value.top,o.position.x=r.value.left+(r.value.width-u.value.width)/2;break;case"top-end":case"right-start":o.position.y=r.value.top,o.position.x=r.value.right-u.value.width;case"right":o.position.y=r.value.top+(r.value.height-u.value.height)/2,o.position.x=r.value.right-u.value.width;break}const k=K(u.value,o.position,v,f);if(o.position.x=k.x,o.position.y=k.y,k.x<r.value.left&&(o.position.x=r.value.left,v=0),k.x+u.value.width>r.value.right){const b=r.value.right-u.value.width;b>0&&(o.position.x=b),v=0}if(k.y<r.value.top&&(o.position.y=r.value.top,f=0),k.y+u.value.height>r.value.bottom){const b=r.value.bottom-u.value.height;b>0&&(o.position.y=b),f=0}i.value.style.top=`${o.position.y}px`,i.value.style.left=`${o.position.x}px`,i.value.style.position="fixed",i.value.style.display="flex",u.value=i.value.getBoundingClientRect(),(W=n.callback)!=null&&W.value&&n.callback.value(u,a,r,g,p)});return e.onUnmounted(()=>{l.value.disconnect()}),{float:o,rect:u,setPosition:s,position:g,actualPosition:p,openerRect:a,containerRect:r}};function x(n){const i=window.matchMedia(n),t=e.ref(i.matches);function c(a){t.value=a.matches}return e.onMounted(()=>{i.addEventListener("change",c)}),e.onUnmounted(()=>{i.removeEventListener("change",c)}),t}function G(n){return{isGreater(i){return x(`(min-width: ${n[i]})`)},isSmaller(i){return x(`(max-width: ${n[i]})`)},isInBetween(i,t){return x(`(min-width: ${n[i]}) and (max-width: ${n[t]})`)}}}function H(n,i,t){if(!n)throw new Error("A target component has to be provided.");if(!i)throw new Error("A callback has to be provided.");const c=a=>{!n.value||a.target===n.value||a.composedPath().includes(n.value)||typeof i=="function"&&i()};t&&e.watch(t,(a,r)=>{r&&r.removeEventListener("click",c),a==null||a.addEventListener("click",c)}),e.onMounted(()=>{t||document.addEventListener("click",c)}),e.onBeforeUnmount(()=>{var a;if(t){(a=t.value)==null||a.removeEventListener("click",c);return}document.removeEventListener("click",c)})}function Q(n,i){if(!n)throw new Error("A target component has to be provided.");if(!i||typeof i!="function")throw new Error("A callback has to be provided.");const t=c=>{i(c)};e.onMounted(()=>{n.value.addEventListener("keydown",t)}),e.onBeforeUnmount(()=>{n.value.removeEventListener("keydown",t)})}function X(n,i){if(!n||typeof n!="function")throw new Error("A callback has to be provided.");const t=c=>{n(c)};e.onMounted(()=>{if(!i){document.addEventListener("keyup",t);return}i.value.addEventListener("keyup",t)}),e.onBeforeUnmount(()=>{if(!i){document.removeEventListener("keyup",t);return}i.value.removeEventListener("keyup",t)})}const Y=n=>{const i=e.ref(null),t=e.getCurrentInstance(),c=e.computed(()=>t==null?void 0:t.props.amount),a=e.ref(),r=l=>{if(l===null)return"";const p={minimumFractionDigits:n.minimumFractionDigits,useGrouping:n.useGrouping||!1};return n.maximumFractionDigits!==null&&(p.maximumFractionDigits=n.maximumFractionDigits),l.toLocaleString("it-IT",p)},g=l=>parseFloat(l.replace(/,/g,".")),u=l=>{if(!Number.isNaN(l)&&t){if(a.value=l,t.props.nullOnEmpty&&!l){t.emit("update:amount",null);return}t.emit("update:amount",typeof c.value=="number"?l:l==null?void 0:l.toString())}},o=l=>{setTimeout(()=>{i.value&&(i.value.value=l)},0)},m=l=>p=>{if(!i.value||!p.target)return;let{value:s}=l;s=s.replace(/[^0-9,.-]/g,""),o(s);const d=t!=null&&t.props.nullOnEmpty&&s===""?null:g(s);u(Number.isNaN(d)?0:d)},y=l=>{if(!i.value||!l.target)return;const p=l.target.value.replace(/,/g,".");let s;p===""&&(t!=null&&t.props.nullOnEmpty)?s=null:(s=g(p),Number.isNaN(s)&&(s=0));const d=r(s);o(d),u(g(d))};return e.watch(i,(l,p)=>{l&&(p&&(p==null||p.removeEventListener("input",m(l)),p==null||p.removeEventListener("blur",y)),l.addEventListener("input",m(l)),l.addEventListener("blur",y),t!=null&&t.props.amount&&(l.value=r(c.value)))}),e.watch(c,l=>{e.nextTick(()=>{if(!(!i.value||l===null||l===void 0)&&a.value!==l){const p=r(l);i.value.value=p,a.value=l}})}),{inputRef:i,parse:g,format:r,emitAmount:u,setValue:o}},J=e.defineComponent({__name:"FzFloating",props:{isOpen:{type:Boolean,default:!1},position:{default:"auto"},container:{},contentClass:{},openerClass:{},overrideContentClass:{type:Boolean},overrideOpener:{},teleport:{type:Boolean,default:!1},useViewport:{type:Boolean}},emits:["fzfloating:setPosition"],setup(n,{emit:i}){const t=n,c=i,a=e.ref(null),r=e.ref(null),g=e.useSlots();let u=!1;const o={position:t.position,element:{domRef:a},container:{domRef:e.toRef(t.container||document.body)},opener:{domRef:e.toRef(null)},useViewport:t.useViewport,callback(...s){c("fzfloating:setPosition",...s)}},m=e.toRefs(o);g.opener&&(o.opener={domRef:r});const y=B(m),l=()=>{u||(u=!0,requestAnimationFrame(()=>{t.isOpen&&y.setPosition(),u=!1}))};e.watch(()=>t.position,()=>l()),e.watch(()=>t.isOpen,s=>{if(!s||!a.value){window.removeEventListener("scroll",l);return}window.addEventListener("scroll",l),a.value.style.top="0px",a.value.style.left="0px",a.value.style.transform="none",y.setPosition()}),e.watch(()=>t.overrideOpener,s=>{s&&m.opener&&m.opener.value&&(m.opener.value={domRef:s})}),e.onBeforeUnmount(()=>{window.removeEventListener("scroll",l)});const p=e.computed(()=>t.overrideContentClass?t.contentClass:["bg-core-white fixed p-4 z-10",t.contentClass]);return(s,d)=>(e.openBlock(),e.createElementBlock("div",null,[e.renderSlot(s.$slots,"opener-start"),e.createElementVNode("div",{ref_key:"opener",ref:r,class:"inline-flex"},[e.renderSlot(s.$slots,"opener",{isOpen:s.isOpen,floating:e.unref(y)})],512),e.renderSlot(s.$slots,"opener-end"),s.teleport?e.createCommentVNode("",!0):e.withDirectives((e.openBlock(),e.createElementBlock("div",{key:0,ref_key:"content",ref:a,class:e.normalizeClass(["fz__floating__content",p.value])},[e.renderSlot(s.$slots,"default",{isOpen:s.isOpen,floating:e.unref(y)})],2)),[[e.vShow,s.$slots.default&&(!s.$slots.opener||s.$slots.opener&&s.isOpen)]]),s.teleport?(e.openBlock(),e.createBlock(e.Teleport,{key:1,to:"body"},[e.withDirectives(e.createElementVNode("div",{ref_key:"content",ref:a,class:e.normalizeClass(["fz__floating__content",p.value])},[e.renderSlot(s.$slots,"default",{isOpen:s.isOpen,floating:e.unref(y)})],2),[[e.vShow,s.$slots.default&&(!s.$slots.opener||s.$slots.opener&&s.isOpen)]])])):e.createCommentVNode("",!0)]))}});h.FzFloating=J,h.useBreakpoints=G,h.useClickOutside=H,h.useCurrency=Y,h.useFloating=B,h.useKeyDown=Q,h.useKeyUp=X,h.useMediaQuery=x,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
1
+ (function(d,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],i):(d=typeof globalThis<"u"?globalThis:d||self,i(d.FzComposables={},d.Vue))})(this,function(d,i){"use strict";const g=(a,s,r,p)=>{let n="right",e="right-start";const c=a.getBoundingClientRect(),f=s.getBoundingClientRect(),u=r.getBoundingClientRect(),y=(u.left-c.left-f.width)/c.width,t=(c.right-u.right-f.width)/c.width,o=(u.top-c.top-f.height)/c.height,m=(c.bottom-u.bottom-f.height)/c.height;if(n=[{key:"right",space:t},{key:"top",space:o},{key:"bottom",space:m},{key:"left",space:y}].sort((l,b)=>b.space-l.space)[0].key,!p)switch(n){case"right":case"left":const l=(f.height-u.height)/2;c.top>u.top-l&&(p="end"),c.bottom<u.top-l&&(p="start");break}return e=p?`${n}-${p}`:n,e},R=(a,s,r,p)=>({x:s.x+a.width*r/100,y:s.y+a.height*p/100}),v=a=>{const s=i.ref(null),r=i.ref(null),p=i.ref(null),n=i.ref(null),e=i.reactive({position:{x:0,y:0}}),c={root:null,rootMargin:"0px",threshold:1,...a.element.intersectionOptions},f=(t,o)=>{},u=i.ref(new IntersectionObserver(f,c)),y=()=>i.nextTick(()=>{var k;if(s.value=typeof a.element.domRef.value=="string"?document.querySelector(a.element.domRef.value):a.element.domRef.value,a.container?(r.value=typeof a.container.domRef.value=="string"?document.querySelector(a.container.domRef.value):a.container.domRef.value,r.value??(r.value=document.body)):r.value=document.body,!s.value)throw new Error("missing reference element for floating behavior");a.opener&&(p.value=typeof a.opener.domRef.value=="string"?document.querySelector(a.opener.domRef.value):a.opener.domRef.value),n.value=s.value.getBoundingClientRect();const t=(k=p.value)==null?void 0:k.getBoundingClientRect(),o=r.value.getBoundingClientRect();u.value.observe(s.value),u.value.observe(r.value);let m=a.position?a.position.value:"auto",h=0,l=0;if(a.opener&&p.value&&t){switch(m){case"auto":m=g(r.value,s.value,p.value);break;case"auto-start":m=g(r.value,s.value,p.value,"start");break;case"auto-end":m=g(r.value,s.value,p.value,"end");break}switch(m){case"bottom":e.position.y=t.bottom,e.position.x=t.left+t.width/2,l=-50,h=0;break;case"bottom-start":e.position.y=t.bottom,e.position.x=t.left,l=0,h=0;break;case"bottom-end":e.position.y=t.bottom,e.position.x=t.right,l=-100,h=0;break;case"left-start":e.position.y=t.top,e.position.x=t.left,l=-100,h=0;break;case"left":e.position.y=t.top+t.height/2,e.position.x=t.left,h=-50,l=-100;break;case"left-end":e.position.y=t.bottom,e.position.x=t.left,h=-100,l=-100;break;case"top-start":e.position.y=t.top,e.position.x=t.left,h=-100,l=0;break;case"top":e.position.y=t.top,e.position.x=t.left+t.width/2,l=-50,h=-100;break;case"top-end":e.position.y=t.top,e.position.x=t.right,l=-100,h=-100;break;case"right-start":e.position.y=t.top,e.position.x=t.right,l=0,h=0;break;case"right":e.position.y=t.top+t.height/2,e.position.x=t.right,h=-50,l=0;break;case"right-end":e.position.y=t.bottom,e.position.x=t.right,h=-100,l=0;break}}else switch(m){case"bottom":e.position.y=o.bottom-n.value.height,e.position.x=o.left+o.width/2,l=-50;break;case"left-end":case"bottom-start":e.position.y=o.bottom-n.value.height,e.position.x=o.left;break;case"right-end":case"bottom-end":e.position.y=o.bottom-n.value.height,e.position.x=o.right-n.value.width;break;case"left":e.position.y=o.top+(o.height-n.value.height)/2,e.position.x=o.left;break;case"top-start":case"left-start":e.position.y=o.top,e.position.x=o.left;break;case"top":e.position.y=o.top,e.position.x=o.left+(o.width-n.value.width)/2;break;case"top-end":case"right-start":e.position.y=o.top,e.position.x=o.right-n.value.width;case"right":e.position.y=o.top+(o.height-n.value.height)/2,e.position.x=o.right-n.value.width;break}const b=R(n.value,e.position,l,h);b.x<o.left&&(e.position.x=o.left,l=0),b.x+n.value.width>o.right&&(e.position.x=o.right-n.value.width,l=0),b.y<o.top&&(e.position.y=o.top,h=0),b.y+n.value.height>o.bottom&&(e.position.y=o.bottom-n.value.height,h=0),s.value.style.top=`${e.position.y}px`,s.value.style.left=`${e.position.x}px`,s.value.style.transform=`translateY(${h}%) translateX(${l}%)`,s.value.style.position="absolute",n.value=s.value.getBoundingClientRect()});return i.onUnmounted(()=>{u.value.disconnect()}),{float:e,rect:n,floatObserver:u,setPosition:y}},x=i.defineComponent({__name:"FzFloating",props:{isOpen:{type:Boolean,default:!1},position:{default:"auto"},container:{}},setup(a){const s=a,r=i.ref(null),p=i.ref(null),n=i.useSlots(),e={position:i.computed(()=>s.position),element:{domRef:p},container:{domRef:i.toRef(s.container||document.body)}};n.opener&&(e.opener={domRef:r});const c=v(e);return i.watch(()=>s.position,()=>s.isOpen&&c.setPosition()),i.watch(()=>s.isOpen,f=>f&&c.setPosition()),(f,u)=>(i.openBlock(),i.createElementBlock("div",null,[i.createElementVNode("div",{ref_key:"opener",ref:r,class:"inline-flex"},[i.renderSlot(f.$slots,"opener",{isOpen:f.isOpen,floating:i.unref(c)})],512),i.withDirectives(i.createElementVNode("div",{ref_key:"content",ref:p,class:"bg-core-white absolute p-4"},[i.renderSlot(f.$slots,"default",{isOpen:f.isOpen,floating:i.unref(c)})],512),[[i.vShow,!f.$slots.opener||f.$slots.opener&&f.isOpen]])]))}});d.FzFloating=x,d.useFloating=v,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fiscozen/composables",
3
- "version": "0.1.33",
3
+ "version": "0.1.35-beta",
4
4
  "description": "Design System utility composables",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
@@ -25,9 +25,9 @@
25
25
  "vite": "^5.0.10",
26
26
  "vitest": "^1.2.0",
27
27
  "vue-tsc": "^1.8.25",
28
- "@fiscozen/tsconfig": "^0.1.0",
28
+ "@fiscozen/eslint-config": "^0.1.0",
29
29
  "@fiscozen/prettier-config": "^0.1.0",
30
- "@fiscozen/eslint-config": "^0.1.0"
30
+ "@fiscozen/tsconfig": "^0.1.0"
31
31
  },
32
32
  "license": "ISC",
33
33
  "scripts": {
@@ -1,12 +1,12 @@
1
1
  import { Ref, watch, getCurrentInstance, computed, ref, nextTick } from 'vue'
2
2
  import { FzUseCurrencyOptions } from '../types'
3
- import { format as formatNumber, parse } from '../utils'
3
+ import { format as formatNumber, parse, roundTo } from '../utils'
4
4
 
5
5
  export const useCurrency = (options: FzUseCurrencyOptions) => {
6
6
  const inputRef: Ref<HTMLInputElement | null | undefined> = ref(null)
7
7
  const vm = getCurrentInstance()
8
8
 
9
- const computedModel = computed<number | null>(() => vm?.props.amount as unknown as number | null)
9
+ const computedModel = computed<number | null>(() => vm?.props.amount as number | null)
10
10
  const internalVal = ref<number | null>()
11
11
 
12
12
  const format = formatNumber(options)
@@ -21,7 +21,7 @@ export const useCurrency = (options: FzUseCurrencyOptions) => {
21
21
  vm.emit('update:amount', null)
22
22
  return
23
23
  }
24
- vm.emit('update:amount', typeof computedModel.value === 'number' ? val : val?.toString())
24
+ vm.emit('update:amount', val)
25
25
  }
26
26
  }
27
27
 
@@ -41,8 +41,10 @@ export const useCurrency = (options: FzUseCurrencyOptions) => {
41
41
  }
42
42
  let { value } = el
43
43
  value = value.replace(/[^0-9,.-]/g, '')
44
+ const parsed: number = parse(value);
45
+
44
46
  setValue(value)
45
- const numberValue = vm?.props.nullOnEmpty && value === '' ? null : parse(value)
47
+ const numberValue = vm?.props.nullOnEmpty && value === '' ? null : parsed
46
48
  emitAmount(Number.isNaN(numberValue) ? 0 : numberValue)
47
49
  }
48
50
 
@@ -60,6 +62,15 @@ export const useCurrency = (options: FzUseCurrencyOptions) => {
60
62
  if (Number.isNaN(number)) {
61
63
  number = 0
62
64
  }
65
+ if (options.step && vm?.props.forceStep) {
66
+ number = roundTo(options.step, number)
67
+ }
68
+ if (options.min && options.min > number) {
69
+ number = options.min
70
+ }
71
+ if (options.max && options.max < number) {
72
+ number = options.max
73
+ }
63
74
  }
64
75
  const text = format(number)
65
76
  setValue(text)
@@ -40,6 +40,7 @@ export const useFloating = (
40
40
 
41
41
  const setPosition = () =>
42
42
  nextTick(() => {
43
+ console.log("ENTRO")
43
44
  actualPosition.value = args.position ? args.position.value : 'auto'
44
45
  safeElementDomRef.value = (
45
46
  typeof args.element.value.domRef.value === 'string'
@@ -297,6 +298,9 @@ export const useFloating = (
297
298
  translateY = 0
298
299
  }
299
300
 
301
+ if(float.position.y < 0) float.position.y = 0
302
+ if(float.position.x < 0) float.position.x = 0
303
+
300
304
  safeElementDomRef.value.style.top = `${float.position.y}px`
301
305
  safeElementDomRef.value.style.left = `${float.position.x}px`
302
306
  safeElementDomRef.value.style.position = 'fixed'
package/src/types.ts CHANGED
@@ -56,4 +56,7 @@ export interface FzUseCurrencyOptions {
56
56
  minimumFractionDigits: number
57
57
  maximumFractionDigits?: number
58
58
  useGrouping?: boolean
59
+ min?: number
60
+ max?: number
61
+ step?: number
59
62
  }
@@ -13,7 +13,17 @@ export const format = (options: FzUseCurrencyOptions) => (input: number | null)
13
13
  return input.toLocaleString('it-IT', safeOptions)
14
14
  }
15
15
 
16
- export const parse = (text: string) => {
16
+ export const parse = (text: string): number => {
17
17
  // strip currency, handle edge cases...
18
18
  return parseFloat(text.replace(/,/g, '.'))
19
19
  }
20
+
21
+ export const roundTo = (step: number, val: number) => {
22
+ let result = val;
23
+ const remainder = val % step
24
+ const safeStep = val >= 0 ? step : -step
25
+ if (remainder !== 0) {
26
+ result = Math.abs(remainder) >= step / 2 ? val + safeStep - remainder : val - remainder
27
+ }
28
+ return result
29
+ }