kitzo 2.5.0 → 2.5.2

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.
Files changed (22) hide show
  1. package/dist/index.d.ts +3 -2
  2. package/dist/index.js +1 -1
  3. package/dist/react/components/toast/Toaster.js +48 -45
  4. package/dist/react/components/toast/partials/Toast.js +45 -44
  5. package/dist/react/components/toast/partials/ToastContainer.js +32 -29
  6. package/dist/react/components/toast/{helpers → service}/addToastStyles.js +32 -26
  7. package/dist/react/components/toast/service/manageToasts/swipeClose.js +71 -0
  8. package/dist/react/components/toast/service/utils.js +6 -0
  9. package/dist/react/components/tooltip/Tooltip.js +26 -26
  10. package/dist/react/components/tooltip/helpers/addTooltipStyles.js +74 -80
  11. package/dist/react/components/tooltip/helpers/getPositionClass.js +9 -14
  12. package/dist/react/components/tooltip/partials/TooltipWrapper.js +8 -8
  13. package/package.json +1 -1
  14. package/dist/react/components/toast/helpers/manageToasts/swipeClose.js +0 -76
  15. /package/dist/react/components/toast/{helpers → service}/createToast.js +0 -0
  16. /package/dist/react/components/toast/{helpers → service}/listenars.js +0 -0
  17. /package/dist/react/components/toast/{helpers → service}/manageToasts/addToasts.js +0 -0
  18. /package/dist/react/components/toast/{helpers → service}/manageToasts/dismissToasts.js +0 -0
  19. /package/dist/react/components/toast/{helpers → service}/manageToasts/manageToasts.js +0 -0
  20. /package/dist/react/components/toast/{helpers → service}/manageToasts/timers.js +0 -0
  21. /package/dist/react/components/toast/{helpers → service}/manageToasts/updateToasts.js +0 -0
  22. /package/dist/react/components/toast/{helpers → service}/triggerToasts.js +0 -0
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 = {
@@ -89,8 +90,8 @@ declare type TooltipCoreProps = {
89
90
  smartHover?: boolean;
90
91
  hideOnTouch?: boolean;
91
92
  animation?: TooltipAnimation;
92
- isHidden?: boolean;
93
- isDark?: boolean;
93
+ hidden?: boolean;
94
+ dark?: boolean;
94
95
  };
95
96
 
96
97
  export declare type TooltipPosition = 'top' | 'top-start' | 'top-end' | 'right' | 'right-start' | 'right-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'left' | 'left-start' | 'left-end';
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
+ };
@@ -1,35 +1,35 @@
1
1
  import { jsx as a, Fragment as r, jsxs as T } from "react/jsx-runtime";
2
- import d from "react";
2
+ import c from "react";
3
3
  import v from "./helpers/addTooltipStyles.js";
4
- import w from "./helpers/getPositionClass.js";
5
- import O from "./partials/TooltipWrapper.js";
6
- import k from "./helpers/getAnimationProperties.js";
7
- function C(h) {
4
+ import k from "./helpers/getPositionClass.js";
5
+ import w from "./partials/TooltipWrapper.js";
6
+ import O from "./helpers/getAnimationProperties.js";
7
+ function z(h) {
8
8
  const {
9
9
  content: n,
10
10
  children: t,
11
11
  position: y = "top",
12
12
  animation: i = !0,
13
- isHidden: s = !1,
13
+ hidden: s = !1,
14
14
  offset: m = 8,
15
15
  smartHover: f = !0,
16
16
  hideOnTouch: l = !0,
17
- isDark: u
18
- } = h, [D, b] = d.useState(!1);
19
- if (d.useEffect(() => {
20
- b(!0), v();
21
- }, []), !D) return /* @__PURE__ */ a(r, { children: t });
17
+ dark: u
18
+ } = h, [b, x] = c.useState(!1);
19
+ if (c.useEffect(() => {
20
+ x(!0), v();
21
+ }, []), !b) return /* @__PURE__ */ a(r, { children: t });
22
22
  if (typeof s == "boolean" && s) return /* @__PURE__ */ a(r, { children: t });
23
23
  if (n == null)
24
24
  return /* @__PURE__ */ a(r, { children: t });
25
- const o = {
25
+ const e = {
26
26
  offset: isNaN(Number(m)) ? 8 : Number(m),
27
27
  smartHover: typeof f == "boolean" ? f : !0,
28
28
  hideOnTouch: typeof l == "boolean" ? l : !0
29
29
  };
30
- let p = !1, c = !1;
31
- if (typeof window < "u" && (c = window.matchMedia("(pointer: coarse)").matches || navigator.maxTouchPoints > 0, p = typeof u == "boolean" ? u : window.matchMedia("(prefers-color-scheme: dark)").matches), c && o.hideOnTouch) return t;
32
- const x = w(y), M = !!i, e = k(
30
+ let p = !1, d = !1;
31
+ if (typeof window < "u" && (d = window.matchMedia("(pointer: coarse)").matches || navigator.maxTouchPoints > 0, p = typeof u == "boolean" ? u : window.matchMedia("(prefers-color-scheme: dark)").matches), d && e.hideOnTouch) return t;
32
+ const D = k(y), M = !!i, o = O(
33
33
  i === !0 ? {} : i
34
34
  );
35
35
  return /* @__PURE__ */ T(
@@ -37,25 +37,25 @@ function C(h) {
37
37
  {
38
38
  style: {
39
39
  position: "relative",
40
- width: "fit-content",
41
- "--offset": Math.max(0, o.offset),
40
+ inlineSize: "fit-content",
41
+ "--offset": Math.max(0, e.offset),
42
42
  "--startDuration": Math.max(
43
43
  0,
44
- e.startDuration
44
+ o.startDuration
45
45
  ),
46
- "--endDuration": Math.max(0, e.endDuration),
47
- "--startDelay": Math.max(0, e.startDelay),
48
- "--endDelay": Math.max(0, e.endDelay)
46
+ "--endDuration": Math.max(0, o.endDuration),
47
+ "--startDelay": Math.max(0, o.startDelay),
48
+ "--endDelay": Math.max(0, o.endDelay)
49
49
  },
50
- className: `kitzo-tooltip-root ${p ? "tooltip-theme-dark" : ""} ${o.smartHover ? "smart-hover" : ""} ${M ? "animate-tooltip" : ""}`,
50
+ className: `kitzo-tooltip-root ${p ? "dark tooltip-theme-dark" : ""} ${e.smartHover ? "smart-hover" : ""} ${M ? "animate-tooltip" : ""}`,
51
51
  children: [
52
52
  t,
53
53
  /* @__PURE__ */ a(
54
- O,
54
+ w,
55
55
  {
56
56
  content: n,
57
- positionClass: x,
58
- finalOptions: o
57
+ positionClass: D,
58
+ finalOptions: e
59
59
  }
60
60
  )
61
61
  ]
@@ -63,5 +63,5 @@ function C(h) {
63
63
  );
64
64
  }
65
65
  export {
66
- C as Tooltip
66
+ z as Tooltip
67
67
  };
@@ -1,4 +1,5 @@
1
- const o = `.kitzo-tooltip-root {
1
+ const o = `/*! Default styling */
2
+ .kitzo-tooltip-root {
2
3
  --bg-clr: hsl(0, 0%, 15%);
3
4
  --text-clr: hsl(0, 0%, 95%);
4
5
 
@@ -6,6 +7,8 @@ const o = `.kitzo-tooltip-root {
6
7
  --transition-endDuration: calc(var(--endDuration) * 1ms);
7
8
  --transition-startDelay: calc(var(--startDelay) * 1ms);
8
9
  --transition-endDelay: calc(var(--endDelay) * 1ms);
10
+
11
+ --tooltip-offset: calc(var(--offset) * 1px + 1px);
9
12
  }
10
13
 
11
14
  .kitzo-tooltip-root.tooltip-theme-dark {
@@ -32,12 +35,11 @@ const o = `.kitzo-tooltip-root {
32
35
  color: var(--text-clr);
33
36
  padding-block: 0.25rem;
34
37
  padding-inline: 0.5rem;
35
- border-radius: 0.325rem;
38
+ border-radius: 0.425rem;
36
39
  }
37
40
 
38
- /* Tooltip positioning */
41
+ /*! Tooltip transitions */
39
42
  .kitzo-tooltip-wrapper {
40
- --tooltip-offset: calc(var(--offset) * 1px + 1px);
41
43
  opacity: 0;
42
44
  transition-property: opacity;
43
45
  transition-delay: calc(
@@ -50,80 +52,6 @@ const o = `.kitzo-tooltip-root {
50
52
  transition-delay: 0ms;
51
53
  }
52
54
 
53
- /* Top */
54
- .kitzo-tooltip-wrapper.top {
55
- bottom: 100%;
56
- padding-block-end: var(--tooltip-offset);
57
- }
58
- .kitzo-tooltip-wrapper.top {
59
- left: 50%;
60
- translate: -50% 0;
61
- }
62
- .kitzo-tooltip-wrapper.top.start {
63
- left: 0;
64
- translate: 0 0;
65
- }
66
- .kitzo-tooltip-wrapper.top.end {
67
- left: auto;
68
- right: 0;
69
- translate: 0 0;
70
- }
71
-
72
- /* Right */
73
- .kitzo-tooltip-wrapper.right {
74
- left: 100%;
75
- padding-inline-start: var(--tooltip-offset);
76
- }
77
- .kitzo-tooltip-wrapper.right {
78
- top: 50%;
79
- translate: 0 -50%;
80
- }
81
- .kitzo-tooltip-wrapper.right.start {
82
- top: 0;
83
- translate: 0 0;
84
- }
85
- .kitzo-tooltip-wrapper.right.end {
86
- top: 100%;
87
- translate: 0 -100%;
88
- }
89
-
90
- /* Bottom */
91
- .kitzo-tooltip-wrapper.bottom {
92
- top: 100%;
93
- padding-block-start: var(--tooltip-offset);
94
- }
95
- .kitzo-tooltip-wrapper.bottom {
96
- left: 50%;
97
- translate: -50% 0;
98
- }
99
- .kitzo-tooltip-wrapper.bottom.start {
100
- left: 0;
101
- translate: 0 0;
102
- }
103
- .kitzo-tooltip-wrapper.bottom.end {
104
- left: 100%;
105
- translate: -100% 0;
106
- }
107
-
108
- /* Left */
109
- .kitzo-tooltip-wrapper.left {
110
- right: 100%;
111
- padding-inline-end: var(--tooltip-offset);
112
- }
113
- .kitzo-tooltip-wrapper.left {
114
- top: 50%;
115
- translate: 0 -50%;
116
- }
117
- .kitzo-tooltip-wrapper.left.start {
118
- top: 0;
119
- translate: 0 0;
120
- }
121
- .kitzo-tooltip-wrapper.left.end {
122
- top: 100%;
123
- translate: 0 -100%;
124
- }
125
-
126
- /* Tooltip transitions */
127
55
  .kitzo-tooltip-root.animate-tooltip {
128
56
  .kitzo-tooltip-content {
129
57
  text-rendering: optimizeLegibility;
@@ -170,7 +98,7 @@ const o = `.kitzo-tooltip-root {
170
98
  }
171
99
  }
172
100
 
173
- /* smart hover persistence feature */
101
+ /*! smart hover persistence feature */
174
102
  .kitzo-tooltip-root {
175
103
  .kitzo-tooltip-wrapper {
176
104
  pointer-events: none;
@@ -180,7 +108,73 @@ const o = `.kitzo-tooltip-root {
180
108
  .kitzo-tooltip-wrapper {
181
109
  pointer-events: all;
182
110
  }
183
- }`;
111
+ }
112
+
113
+ /*! Tooltip positioning */
114
+ /*? Top */
115
+ .kitzo-tooltip-wrapper[data-position^='top'] {
116
+ bottom: 100%;
117
+ padding-block-end: var(--tooltip-offset);
118
+ }
119
+ .kitzo-tooltip-wrapper[data-position='top'] {
120
+ left: 50%;
121
+ translate: -50% 0;
122
+ }
123
+ .kitzo-tooltip-wrapper[data-position='top-start'] {
124
+ left: 0;
125
+ }
126
+ .kitzo-tooltip-wrapper[data-position='top-end'] {
127
+ right: 0;
128
+ }
129
+
130
+ /*? Right */
131
+ .kitzo-tooltip-wrapper[data-position^='right'] {
132
+ inset-inline-start: 100%;
133
+ padding-inline-start: var(--tooltip-offset);
134
+ }
135
+ .kitzo-tooltip-wrapper[data-position='right'] {
136
+ top: 50%;
137
+ translate: 0 -50%;
138
+ }
139
+ .kitzo-tooltip-wrapper[data-position='right-start'] {
140
+ top: 0;
141
+ }
142
+ .kitzo-tooltip-wrapper[data-position='right-end'] {
143
+ bottom: 0;
144
+ }
145
+
146
+ /*? Bottom */
147
+ .kitzo-tooltip-wrapper[data-position^='bottom'] {
148
+ top: 100%;
149
+ padding-block-start: var(--tooltip-offset);
150
+ }
151
+ .kitzo-tooltip-wrapper[data-position='bottom'] {
152
+ left: 50%;
153
+ translate: -50% 0;
154
+ }
155
+ .kitzo-tooltip-wrapper[data-position='bottom-start'] {
156
+ left: 0;
157
+ }
158
+ .kitzo-tooltip-wrapper[data-position='bottom-end'] {
159
+ right: 0;
160
+ }
161
+
162
+ /*? Left */
163
+ .kitzo-tooltip-wrapper[data-position^='left'] {
164
+ inset-inline-end: 100%;
165
+ padding-inline-end: var(--tooltip-offset);
166
+ }
167
+ .kitzo-tooltip-wrapper[data-position='left'] {
168
+ top: 50%;
169
+ translate: 0 -50%;
170
+ }
171
+ .kitzo-tooltip-wrapper[data-position='left-start'] {
172
+ top: 0;
173
+ }
174
+ .kitzo-tooltip-wrapper[data-position='left-end'] {
175
+ bottom: 0;
176
+ }
177
+ `;
184
178
  function i() {
185
179
  if (!document.getElementById("kitzo-tooltip-styles")) {
186
180
  const t = document.createElement("style");
@@ -1,27 +1,22 @@
1
- const s = [
2
- "top-start",
1
+ const r = [
3
2
  "top",
3
+ "top-start",
4
4
  "top-end",
5
- "right-start",
6
5
  "right",
6
+ "right-start",
7
7
  "right-end",
8
- "bottom-start",
9
8
  "bottom",
9
+ "bottom-start",
10
10
  "bottom-end",
11
- "left-start",
12
11
  "left",
12
+ "left-start",
13
13
  "left-end"
14
14
  ];
15
- function n(t = "") {
15
+ function s(t = "") {
16
16
  t = typeof t == "string" ? t.trim().toLowerCase() : "top";
17
- const e = s.find((o) => o === t);
18
- if (!e) return "top";
19
- if (e.includes("-")) {
20
- const [o, r] = e.split("-");
21
- return `${o} ${r}`;
22
- } else
23
- return e;
17
+ const o = r.find((e) => e === t);
18
+ return o || "top";
24
19
  }
25
20
  export {
26
- n as default
21
+ s as default
27
22
  };
@@ -1,8 +1,8 @@
1
- import { jsx as e, Fragment as i } from "react/jsx-runtime";
1
+ import { jsx as e, Fragment as r } from "react/jsx-runtime";
2
2
  function l({
3
3
  content: t,
4
- positionClass: o,
5
- finalOptions: r
4
+ positionClass: i,
5
+ finalOptions: o
6
6
  }) {
7
7
  return /* @__PURE__ */ e(
8
8
  "div",
@@ -10,15 +10,15 @@ function l({
10
10
  style: {
11
11
  position: "absolute",
12
12
  whiteSpace: "pre-wrap",
13
- width: "max-content"
13
+ inlineSize: "max-content"
14
14
  },
15
- tabIndex: -1,
16
- className: `kitzo-tooltip-wrapper ${o}`,
15
+ className: `kitzo-tooltip-wrapper ${i}`,
16
+ "data-position": i,
17
17
  children: /* @__PURE__ */ e(
18
18
  "div",
19
19
  {
20
- className: `kitzo-tooltip-content ${o} ${r.arrow ? "tooltip-arrow" : ""}`,
21
- children: typeof t == "string" || typeof t == "number" ? /* @__PURE__ */ e("div", { className: "kitzo-tooltip-content-default-style", children: t }) : /* @__PURE__ */ e(i, { children: t })
20
+ className: `kitzo-tooltip-content ${i} ${o.arrow ? "tooltip-arrow" : ""}`,
21
+ children: typeof t == "string" || typeof t == "number" ? /* @__PURE__ */ e("div", { className: "kitzo-tooltip-content-default-style", children: t }) : /* @__PURE__ */ e(r, { children: t })
22
22
  }
23
23
  )
24
24
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kitzo",
3
- "version": "2.5.0",
3
+ "version": "2.5.2",
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
- };