kitzo 2.5.0 → 2.5.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.
package/dist/index.d.ts CHANGED
@@ -42,6 +42,7 @@ export declare type ToasterProps = {
42
42
  pauseOnHover?: boolean;
43
43
  swipeToClose?: boolean;
44
44
  animateTransformOrigin?: boolean;
45
+ animateScale?: boolean;
45
46
  };
46
47
 
47
48
  declare type ToastFn = {
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Toaster as r } from "./react/components/toast/Toaster.js";
2
2
  import { Tooltip as p } from "./react/components/tooltip/Tooltip.js";
3
- import { toast as m } from "./react/components/toast/helpers/triggerToasts.js";
3
+ import { toast as m } from "./react/components/toast/service/triggerToasts.js";
4
4
  import { useCopy as s } from "./react/hooks/useCopy.js";
5
5
  import { useDebounce as i } from "./react/hooks/useDebounce.js";
6
6
  import { useThrottle as a } from "./react/hooks/useThrottle.js";
@@ -1,38 +1,40 @@
1
- import { jsx as n } from "react/jsx-runtime";
1
+ import { jsx as i } from "react/jsx-runtime";
2
2
  import t from "react";
3
- import { subscribe as w } from "./helpers/listenars.js";
4
- import M from "./helpers/manageToasts/manageToasts.js";
3
+ import { subscribe as w } from "./service/listenars.js";
4
+ import z from "./service/manageToasts/manageToasts.js";
5
5
  import O from "./partials/ToastContainer.js";
6
- import { ToasterContext as S } from "./context/ToasterContext.js";
7
- import { initSwipeToClose as z } from "./helpers/manageToasts/swipeClose.js";
8
- function q(s) {
6
+ import { ToasterContext as I } from "./context/ToasterContext.js";
7
+ import { initSwipeToClose as $ } from "./service/manageToasts/swipeClose.js";
8
+ import { clampedValue as h } from "./service/utils.js";
9
+ function F(e) {
9
10
  const {
10
- position: h = "top-center",
11
- richColors: u = !1,
12
- animateTransformOrigin: g = !0,
13
- gap: r = s?.compact ? 8 : 12,
14
- edgeOffset: i = 16,
11
+ position: b = "top-center",
12
+ gap: r = e?.compact ? 8 : 12,
13
+ edgeOffset: n = 16,
15
14
  dark: c,
16
- pauseOnHover: b = !0,
15
+ compact: g = !1,
16
+ richColors: u = !1,
17
+ pauseOnHover: k = !0,
17
18
  swipeToClose: y = !0,
18
- compact: k = !1
19
- } = s, [T, v] = t.useState(!1);
19
+ animateScale: T = !1,
20
+ animateTransformOrigin: v = !0
21
+ } = e, [x, C] = t.useState(!1);
20
22
  t.useEffect(() => {
21
- v(!0);
23
+ C(!0);
22
24
  }, []);
23
- const [p, m] = t.useState([]);
25
+ const [m, p] = t.useState([]);
24
26
  t.useEffect(() => {
25
- const e = w(
26
- (o) => M({ toast: o, setToasts: m }),
27
- s.toasterId
28
- ), a = z();
27
+ const o = w(
28
+ (s) => z({ toast: s, setToasts: p }),
29
+ e.toasterId
30
+ ), a = $();
29
31
  return () => {
30
- e(), a();
32
+ o(), a();
31
33
  };
32
- }, [s.toasterId]);
34
+ }, [e.toasterId]);
33
35
  const f = t.useRef(null), l = t.useCallback(() => {
34
36
  if (!f.current) return;
35
- const e = f.current.querySelectorAll("[data-toast-container]"), a = {
37
+ const o = f.current.querySelectorAll("[data-kitzo-toast-container]"), a = {
36
38
  "top-left": 0,
37
39
  "top-center": 0,
38
40
  "top-right": 0,
@@ -40,18 +42,18 @@ function q(s) {
40
42
  "bottom-center": 0,
41
43
  "bottom-right": 0
42
44
  };
43
- e.forEach((o) => {
44
- const d = o.getAttribute("data-toast-position") || "top-center", C = parseFloat(o.style.getPropertyValue("--toast-height")) || 0;
45
- o.style.setProperty("--toast-offset-y", `${a[d]}px`);
46
- const E = isNaN(+r) ? 8 : +r;
47
- a[d] += C + E;
45
+ o.forEach((s) => {
46
+ const d = s.getAttribute("data-toast-position") || "top-center", N = parseFloat(s.style.getPropertyValue("--toast-height")) || 0;
47
+ s.style.setProperty("--toast-offset-y", `${a[d]}px`);
48
+ const S = isNaN(Number(r)) ? e?.compact ? 8 : 12 : Number(r);
49
+ a[d] += N + h(S, 0, 32);
48
50
  });
49
- }, [r]);
51
+ }, [r, e?.compact]);
50
52
  if (t.useLayoutEffect(() => {
51
53
  l();
52
- }, [p, l]), !T) return null;
53
- const x = typeof c == "boolean" ? c : window.matchMedia("(prefers-color-scheme: dark)").matches;
54
- return /* @__PURE__ */ n(
54
+ }, [m, l]), !x) return null;
55
+ const E = typeof c == "boolean" ? c : window.matchMedia("(prefers-color-scheme: dark)").matches;
56
+ return /* @__PURE__ */ i(
55
57
  "div",
56
58
  {
57
59
  ref: f,
@@ -61,32 +63,33 @@ function q(s) {
61
63
  zIndex: 2147483647,
62
64
  pointerEvents: "none",
63
65
  display: "grid",
64
- padding: i != null ? `${Math.max(Math.min(+i, 200), 0)}px` : 16
66
+ padding: n != null ? `${h(Number(n), 0, 32)}px` : 16
65
67
  },
66
- className: `kitzo-toaster ${u ? "kitzo-toaster-rich-colors" : ""} ${x ? "kitzo-toaster-dark" : ""}`,
67
- children: /* @__PURE__ */ n(
68
+ className: `kitzo-toaster ${u ? "kitzo-toaster-rich-colors" : ""} ${E ? "dark kitzo-toaster-dark" : ""}`,
69
+ children: /* @__PURE__ */ i(
68
70
  "div",
69
71
  {
70
72
  style: {
71
73
  position: "relative"
72
74
  },
73
- children: /* @__PURE__ */ n(
74
- S.Provider,
75
+ children: /* @__PURE__ */ i(
76
+ I.Provider,
75
77
  {
76
78
  value: {
77
- position: h,
79
+ position: b,
78
80
  gap: r,
79
- edgeOffset: i,
80
- setToasts: m,
81
+ edgeOffset: n,
82
+ setToasts: p,
81
83
  updateOffsets: l,
82
84
  dark: c,
83
- compact: k,
85
+ compact: g,
84
86
  richColors: u,
85
87
  swipeToClose: y,
86
- pauseOnHover: b,
87
- animateTransformOrigin: g
88
+ pauseOnHover: k,
89
+ animateScale: T,
90
+ animateTransformOrigin: v
88
91
  },
89
- children: p.map((e) => /* @__PURE__ */ n(O, { t: e }, e.id))
92
+ children: m.map((o) => /* @__PURE__ */ i(O, { t: o }, o.id))
90
93
  }
91
94
  )
92
95
  }
@@ -95,5 +98,5 @@ function q(s) {
95
98
  );
96
99
  }
97
100
  export {
98
- q as Toaster
101
+ F as Toaster
99
102
  };
@@ -1,34 +1,34 @@
1
- import { jsxs as S, jsx as t, Fragment as o } from "react/jsx-runtime";
2
- import { resumeToast as l, pauseToast as m } from "../helpers/manageToasts/timers.js";
3
- import { toast as I } from "../helpers/triggerToasts.js";
4
- import { InfoSvg as E, ErrorSvg as T, WarningSvg as k, SuccessSvg as w, LoadingSvg as L } from "./Svgs.js";
5
- import { useToasterContext as M } from "../context/ToasterContext.js";
6
- function z({
7
- t: c,
8
- position: s,
9
- shouldAnimateTransformOrigin: p,
10
- swipeToClose: u
1
+ import { jsxs as x, jsx as t, Fragment as n } from "react/jsx-runtime";
2
+ import { resumeToast as S, pauseToast as I } from "../service/manageToasts/timers.js";
3
+ import { toast as T } from "../service/triggerToasts.js";
4
+ import { InfoSvg as k, ErrorSvg as w, WarningSvg as E, SuccessSvg as N, LoadingSvg as b } from "./Svgs.js";
5
+ import { useToasterContext as j } from "../context/ToasterContext.js";
6
+ function H({
7
+ t: i,
8
+ position: o,
9
+ shouldAnimateTransformOrigin: l,
10
+ swipeToClose: p
11
11
  }) {
12
- const { pauseOnHover: n, compact: f } = M(), {
12
+ const { pauseOnHover: d, compact: m } = j(), {
13
13
  id: e,
14
- type: r,
15
- action: g,
16
- content: i,
17
- status: v,
18
- showIcon: h,
14
+ type: s,
15
+ action: u,
16
+ content: r,
17
+ status: f,
18
+ showIcon: g,
19
19
  icon: a,
20
- toasterId: y,
21
- updateState: x
22
- } = c, d = {
23
- loading: /* @__PURE__ */ t(L, {}),
24
- success: /* @__PURE__ */ t(w, {}),
25
- warning: /* @__PURE__ */ t(k, {}),
26
- error: /* @__PURE__ */ t(T, {}),
27
- info: /* @__PURE__ */ t(E, {}),
20
+ toasterId: v,
21
+ updateState: h
22
+ } = i, c = {
23
+ loading: /* @__PURE__ */ t(b, {}),
24
+ success: /* @__PURE__ */ t(N, {}),
25
+ warning: /* @__PURE__ */ t(E, {}),
26
+ error: /* @__PURE__ */ t(w, {}),
27
+ info: /* @__PURE__ */ t(k, {}),
28
28
  default: null,
29
29
  custom: null
30
30
  };
31
- return /* @__PURE__ */ S(
31
+ return /* @__PURE__ */ x(
32
32
  "div",
33
33
  {
34
34
  id: e,
@@ -38,25 +38,26 @@ function z({
38
38
  alignItems: "center",
39
39
  gap: 8
40
40
  },
41
- "data-toaster-id": y,
42
- "data-action": g,
43
- "data-status": v,
44
- "data-type": r,
45
- "data-position": s,
46
- "data-screen-x": s.split("-")[1],
47
- "data-screen-y": s.split("-")[0],
41
+ "data-toaster-id": v,
42
+ "data-action": u,
43
+ "data-status": f,
44
+ "data-type": s,
45
+ "data-position": o,
46
+ "data-screen-x": o.split("-")[1],
47
+ "data-screen-y": o.split("-")[0],
48
48
  "data-exit": "auto",
49
- "data-swipeable": u,
50
- "data-animate-transform-origin": p,
51
- "data-compact": f,
52
- "data-update-state": x,
53
- onPointerEnter: () => n && m(e),
54
- onPointerLeave: () => n && l(e),
55
- onMouseEnter: () => n && m(e),
56
- onMouseLeave: () => n && l(e),
49
+ "data-swipeable": p,
50
+ "data-animate-transform-origin": l,
51
+ "data-compact": m,
52
+ "data-update-state": h,
53
+ "data-pause-on-hover": d,
54
+ onPointerEnter: (y) => {
55
+ d && y.pointerType === "mouse" && I(e);
56
+ },
57
+ onPointerLeave: () => S(e),
57
58
  className: "kitzo-toast",
58
59
  children: [
59
- h && /* @__PURE__ */ t(o, { children: a ? /* @__PURE__ */ t(o, { children: typeof a == "string" || typeof a == "number" ? /* @__PURE__ */ t(
60
+ g && /* @__PURE__ */ t(n, { children: a ? /* @__PURE__ */ t(n, { children: typeof a == "string" || typeof a == "number" ? /* @__PURE__ */ t(
60
61
  "div",
61
62
  {
62
63
  style: {
@@ -65,14 +66,14 @@ function z({
65
66
  className: "svg-container",
66
67
  children: a
67
68
  }
68
- ) : /* @__PURE__ */ t(o, { children: a }) }) : /* @__PURE__ */ t(o, { children: d[r] && /* @__PURE__ */ t("div", { style: { flexShrink: 0 }, className: "svg-container", children: d[r] }) }) }),
69
+ ) : /* @__PURE__ */ t(n, { children: a }) }) : /* @__PURE__ */ t(n, { children: c[s] && /* @__PURE__ */ t("div", { style: { flexShrink: 0 }, className: "svg-container", children: c[s] }) }) }),
69
70
  /* @__PURE__ */ t(
70
71
  "div",
71
72
  {
72
73
  style: {
73
74
  flex: 1
74
75
  },
75
- children: typeof i == "function" ? i(() => I.dismiss(e, c.toasterId)) : i
76
+ children: typeof r == "function" ? r(() => T.dismiss(e, i.toasterId)) : r
76
77
  }
77
78
  )
78
79
  ]
@@ -80,5 +81,5 @@ function z({
80
81
  );
81
82
  }
82
83
  export {
83
- z as default
84
+ H as default
84
85
  };
@@ -1,61 +1,64 @@
1
- import { jsx as l } from "react/jsx-runtime";
2
- import { useRef as b, useLayoutEffect as g } from "react";
3
- import h from "./Toast.js";
4
- import { useToasterContext as x } from "../context/ToasterContext.js";
5
- function v({ t }) {
1
+ import { jsx as c } from "react/jsx-runtime";
2
+ import { useRef as g, useLayoutEffect as h } from "react";
3
+ import x from "./Toast.js";
4
+ import { useToasterContext as y } from "../context/ToasterContext.js";
5
+ function z({ t }) {
6
6
  const {
7
- updateOffsets: s,
7
+ updateOffsets: n,
8
8
  position: f,
9
- animateTransformOrigin: c,
9
+ animateScale: i,
10
+ animateTransformOrigin: m,
10
11
  swipeToClose: p
11
- } = x(), i = b(null);
12
- g(() => {
13
- const e = i.current;
12
+ } = y(), r = g(null);
13
+ h(() => {
14
+ const e = r.current;
14
15
  if (!e) return;
15
- const a = new ResizeObserver(() => {
16
- const T = e.offsetHeight;
17
- e.style.setProperty("--toast-height", `${T}px`), s();
16
+ const l = new ResizeObserver(() => {
17
+ const b = e.offsetHeight;
18
+ e.style.setProperty("--toast-height", `${b}px`), n();
18
19
  });
19
- return a.observe(e), () => a.disconnect();
20
- }, [s]);
21
- const m = [
20
+ return l.observe(e), () => l.disconnect();
21
+ }, [n]);
22
+ const u = [
22
23
  "top-left",
23
24
  "top-center",
24
25
  "top-right",
25
26
  "bottom-left",
26
27
  "bottom-center",
27
28
  "bottom-right"
28
- ], r = t.position || f, o = m.includes(r) ? r : "top-center", n = o?.includes("bottom"), u = typeof t.animateTransformOrigin == "boolean" ? t.animateTransformOrigin : !!c, d = typeof t.swipeToClose == "boolean" ? t.swipeToClose : !!p;
29
- return /* @__PURE__ */ l(
29
+ ], a = t.position || f, o = u.includes(a) ? a : "top-center", s = o?.includes("bottom"), d = typeof t.animateTransformOrigin == "boolean" ? t.animateTransformOrigin : !!m, T = typeof t.swipeToClose == "boolean" ? t.swipeToClose : !!p;
30
+ return /* @__PURE__ */ c(
30
31
  "div",
31
32
  {
32
- ref: i,
33
- "data-toast-container": !0,
33
+ ref: r,
34
+ "data-kitzo-toast-container": !0,
34
35
  "data-toast-position": o,
36
+ "data-animate-scale": i,
37
+ className: "kitzo-toast-container",
35
38
  style: {
36
39
  position: "absolute",
37
40
  zIndex: t.zIndex,
38
41
  left: 0,
39
42
  right: 0,
40
- transition: "transform 180ms",
43
+ transition: `transform ${i ? "220ms" : "280ms"}`,
41
44
  display: "flex",
42
45
  justifyContent: o?.includes("left") ? "flex-start" : o?.includes("center") ? "center" : "flex-end",
43
- top: n ? "auto" : 0,
44
- bottom: n ? 0 : "auto",
45
- transform: `translateY(calc(var(--toast-offset-y, 0px) * ${n ? -1 : 1}))`
46
+ top: s ? "auto" : 0,
47
+ bottom: s ? 0 : "auto",
48
+ transform: `translateY(calc(var(--toast-offset-y, 0px) * ${s ? -1 : 1}))`
46
49
  },
47
- children: /* @__PURE__ */ l(
48
- h,
50
+ children: /* @__PURE__ */ c(
51
+ x,
49
52
  {
50
53
  t,
51
54
  position: o,
52
- shouldAnimateTransformOrigin: u,
53
- swipeToClose: d
55
+ shouldAnimateTransformOrigin: d,
56
+ swipeToClose: T
54
57
  }
55
58
  )
56
59
  }
57
60
  );
58
61
  }
59
62
  export {
60
- v as default
63
+ z as default
61
64
  };
@@ -94,7 +94,6 @@ const a = `.kitzo-toaster {
94
94
  font-family: inherit;
95
95
  font-size: 0.875rem;
96
96
  white-space: pre-wrap;
97
- text-wrap: balance;
98
97
  }
99
98
 
100
99
  .kitzo-toast.is-swiping {
@@ -143,7 +142,7 @@ const a = `.kitzo-toaster {
143
142
  .kitzo-toast[data-type='warning'],
144
143
  .kitzo-toast[data-type='error'],
145
144
  .kitzo-toast[data-type='info'] {
146
- border-radius: 0.425rem;
145
+ border-radius: 0.5525rem;
147
146
  padding: 0.375rem 0.625rem;
148
147
  box-shadow: 0 3px 8px -3px hsl(0, 0%, 0%, 0.15);
149
148
  }
@@ -162,16 +161,22 @@ const a = `.kitzo-toaster {
162
161
  .kitzo-toast {
163
162
  --swipe-x: 0px;
164
163
  --motion-y: 0%;
165
- --scale: 0.6;
164
+ --scale: 1;
166
165
  --exit-x: 0px;
167
166
  }
168
167
 
168
+ .kitzo-toast-container[data-animate-scale='true'] {
169
+ .kitzo-toast {
170
+ --scale: 0.6;
171
+ }
172
+ }
173
+
169
174
  .kitzo-toast[data-screen-y='top'] {
170
- --motion-y: -120%;
175
+ --motion-y: -100%;
171
176
  }
172
177
 
173
178
  .kitzo-toast[data-screen-y='bottom'] {
174
- --motion-y: 120%;
179
+ --motion-y: 100%;
175
180
  }
176
181
 
177
182
  .kitzo-toast[data-status='leaving'][data-exit='swipe'] {
@@ -196,10 +201,10 @@ const a = `.kitzo-toaster {
196
201
  }
197
202
 
198
203
  .kitzo-toast[data-update-state='updated'] {
199
- animation: update 250ms ease;
204
+ animation: update 280ms ease;
200
205
  }
201
206
  .kitzo-toast[data-update-state='updated-again'] {
202
- animation: update-again 250ms ease;
207
+ animation: update-again 280ms ease;
203
208
  }
204
209
 
205
210
  @keyframes update {
@@ -223,31 +228,32 @@ const a = `.kitzo-toaster {
223
228
  }
224
229
  }
225
230
 
226
- /*! toast transfor origin */
231
+ /*! toast transform origin */
227
232
  .kitzo-toast[data-position^='top'] {
228
233
  transform-origin: top;
229
234
  }
230
235
  .kitzo-toast[data-position^='bottom'] {
231
236
  transform-origin: bottom;
232
237
  }
233
-
234
- .kitzo-toast[data-animate-transform-origin='true'][data-position='top-left'] {
235
- transform-origin: top left;
236
- }
237
- .kitzo-toast[data-animate-transform-origin='true'][data-position='top-center'] {
238
- transform-origin: top;
239
- }
240
- .kitzo-toast[data-animate-transform-origin='true'][data-position='top-right'] {
241
- transform-origin: top right;
242
- }
243
- .kitzo-toast[data-animate-transform-origin='true'][data-position='bottom-left'] {
244
- transform-origin: bottom left;
245
- }
246
- .kitzo-toast[data-animate-transform-origin='true'][data-position='bottom-center'] {
247
- transform-origin: bottom;
248
- }
249
- .kitzo-toast[data-animate-transform-origin='true'][data-position='bottom-right'] {
250
- transform-origin: bottom right;
238
+ @media (width > 380px) {
239
+ .kitzo-toast[data-animate-transform-origin='true'][data-position='top-left'] {
240
+ transform-origin: top left;
241
+ }
242
+ .kitzo-toast[data-animate-transform-origin='true'][data-position='top-center'] {
243
+ transform-origin: top;
244
+ }
245
+ .kitzo-toast[data-animate-transform-origin='true'][data-position='top-right'] {
246
+ transform-origin: top right;
247
+ }
248
+ .kitzo-toast[data-animate-transform-origin='true'][data-position='bottom-left'] {
249
+ transform-origin: bottom left;
250
+ }
251
+ .kitzo-toast[data-animate-transform-origin='true'][data-position='bottom-center'] {
252
+ transform-origin: bottom;
253
+ }
254
+ .kitzo-toast[data-animate-transform-origin='true'][data-position='bottom-right'] {
255
+ transform-origin: bottom right;
256
+ }
251
257
  }
252
258
 
253
259
  .kitzo-toast[data-status='leaving'][data-position^='top'] {
@@ -0,0 +1,71 @@
1
+ import { toast as y } from "../triggerToasts.js";
2
+ import { pauseToast as g, resumeToast as L } from "./timers.js";
3
+ let r = !1, e = null, i = null, h = 0, s = 0, l = !1, u = null;
4
+ const b = 2, P = 65, S = 25;
5
+ function x(t) {
6
+ if (!e) return;
7
+ const n = Math.sign(t) || 1, o = Math.abs(t), c = S * (1 - Math.exp(-o / 400 * 0.75));
8
+ return n * c;
9
+ }
10
+ function E(t) {
11
+ return t ? t.dataset.swipeable === "true" : !1;
12
+ }
13
+ function a(t = !0) {
14
+ if (!e) return;
15
+ if (document.body.style.userSelect = "auto", t && u != null)
16
+ try {
17
+ e.releasePointerCapture(u);
18
+ } catch {
19
+ console.log("Failed to release pointer");
20
+ }
21
+ e.style.setProperty("--swipe-x", "0px"), e.classList.remove("is-swiping");
22
+ const n = e, o = e.id, c = n.dataset.pauseOnHover === "true";
23
+ e = null, i = null, u = null, l = !1, r = !1, s = 0, n && document.body.contains(n) && (n.matches(":hover") && c || L(o));
24
+ }
25
+ function p(t) {
26
+ const o = t.target.closest(".kitzo-toast");
27
+ o && (e = o, i = o.id, h = t.clientX, s = 0, l = !0, r = !1, u = t.pointerId);
28
+ }
29
+ function f(t) {
30
+ if (!l || !e || i == null) return;
31
+ if (s = t.clientX - h, !r && Math.abs(s) > b) {
32
+ r = !0, g(i), e.classList.add("is-swiping");
33
+ try {
34
+ e.setPointerCapture(t.pointerId), document.body.style.userSelect = "none";
35
+ } catch {
36
+ console.error("Failed to capture pointer");
37
+ }
38
+ }
39
+ if (!r) return;
40
+ const o = E(e) ? s : x(s);
41
+ e.style.setProperty("--swipe-x", `${o}px`);
42
+ }
43
+ function m() {
44
+ if (!l || !e || i == null) {
45
+ a();
46
+ return;
47
+ }
48
+ const t = E(e);
49
+ if (r && t && Math.abs(s) > P) {
50
+ const n = s > 0 ? 1 : -1, o = Math.abs(s) + 220;
51
+ e.style.setProperty("--exit-x", `${n * o}px`), e.dataset.exit = "swipe", y.dismiss(i, e.dataset.toasterId);
52
+ }
53
+ a();
54
+ }
55
+ function v() {
56
+ a();
57
+ }
58
+ function w() {
59
+ l && a();
60
+ }
61
+ let d = !1;
62
+ function C() {
63
+ return d ? () => {
64
+ } : (d = !0, document.addEventListener("pointerdown", p), document.addEventListener("pointermove", f), document.addEventListener("pointerup", m), document.addEventListener("pointercancel", v), window.addEventListener("blur", w), () => {
65
+ a(), d = !1, document.removeEventListener("pointerdown", p), document.removeEventListener("pointermove", f), document.removeEventListener("pointerup", m), document.removeEventListener("pointercancel", v), window.removeEventListener("blur", w);
66
+ });
67
+ }
68
+ export {
69
+ r as dragStarted,
70
+ C as initSwipeToClose
71
+ };
@@ -0,0 +1,6 @@
1
+ function n(a, t, e) {
2
+ return Math.max(t, Math.min(a, e));
3
+ }
4
+ export {
5
+ n as clampedValue
6
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kitzo",
3
- "version": "2.5.0",
3
+ "version": "2.5.1",
4
4
  "description": "A lightweight React micro-utility.",
5
5
  "type": "module",
6
6
  "files": [
@@ -1,76 +0,0 @@
1
- import { toast as b } from "../triggerToasts.js";
2
- let s = !1, e = null, c = null, m = 0, r = 0, a = !1, l = null;
3
- const L = 2, y = 65, S = 20, g = 100;
4
- function x(t) {
5
- const o = Math.sign(t) || 1, n = Math.abs(t), h = S * (1 - Math.exp(-n / g));
6
- return o * h;
7
- }
8
- function E(t) {
9
- return t ? t.dataset.swipeable === "true" : !1;
10
- }
11
- function i(t = !0) {
12
- if (!e) return;
13
- if (document.body.style.userSelect = "auto", t && l != null)
14
- try {
15
- e.releasePointerCapture(l);
16
- } catch {
17
- console.error("");
18
- }
19
- e.style.setProperty("--swipe-x", "0px"), e.classList.remove("is-swiping");
20
- const o = e;
21
- if (e = null, c = null, l = null, a = !1, s = !1, r = 0, !o.matches(":hover")) {
22
- const n = new MouseEvent("mouseleave", {
23
- bubbles: !0,
24
- cancelable: !0,
25
- view: window
26
- });
27
- o.dispatchEvent(n);
28
- }
29
- }
30
- function d(t) {
31
- const n = t.target.closest(".kitzo-toast");
32
- n && (e = n, c = n.id, m = t.clientX, r = 0, a = !0, s = !1, l = t.pointerId);
33
- }
34
- function p(t) {
35
- if (!a || !e) return;
36
- if (r = t.clientX - m, !s && Math.abs(r) > L) {
37
- s = !0, e.classList.add("is-swiping");
38
- try {
39
- e.setPointerCapture(t.pointerId), document.body.style.userSelect = "none";
40
- } catch {
41
- console.error("Failed to capture pointer");
42
- }
43
- }
44
- if (!s) return;
45
- const n = E(e) ? r : x(r);
46
- e.style.setProperty("--swipe-x", `${n}px`);
47
- }
48
- function f() {
49
- if (!a || !e || c == null) {
50
- i();
51
- return;
52
- }
53
- const t = E(e);
54
- if (s && t && Math.abs(r) > y) {
55
- const o = r > 0 ? 1 : -1, n = Math.abs(r) + 220;
56
- e.style.setProperty("--exit-x", `${o * n}px`), e.dataset.exit = "swipe", b.dismiss(c, e.dataset.toasterId);
57
- }
58
- i();
59
- }
60
- function v() {
61
- i();
62
- }
63
- function w() {
64
- a && i();
65
- }
66
- let u = !1;
67
- function P() {
68
- return u ? () => {
69
- } : (u = !0, document.addEventListener("pointerdown", d), document.addEventListener("pointermove", p), document.addEventListener("pointerup", f), document.addEventListener("pointercancel", v), window.addEventListener("blur", w), () => {
70
- i(), u = !1, document.removeEventListener("pointerdown", d), document.removeEventListener("pointermove", p), document.removeEventListener("pointerup", f), document.removeEventListener("pointercancel", v), window.removeEventListener("blur", w);
71
- });
72
- }
73
- export {
74
- s as dragStarted,
75
- P as initSwipeToClose
76
- };