kitzo 2.4.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.
Files changed (25) hide show
  1. package/dist/fns.js +2 -2
  2. package/dist/functions/copy/{copy.js → index.js} +7 -7
  3. package/dist/index.d.ts +14 -12
  4. package/dist/index.js +13 -13
  5. package/dist/react/components/toast/Toaster.js +55 -50
  6. package/dist/react/components/toast/partials/Toast.js +45 -44
  7. package/dist/react/components/toast/partials/ToastContainer.js +32 -29
  8. package/dist/react/components/toast/{helpers → service}/addToastStyles.js +46 -27
  9. package/dist/react/components/toast/service/manageToasts/swipeClose.js +71 -0
  10. package/dist/react/components/toast/{helpers → service}/triggerToasts.js +28 -28
  11. package/dist/react/components/toast/service/utils.js +6 -0
  12. package/dist/react/components/tooltip/Tooltip.js +10 -10
  13. package/dist/react/hooks/useCopy.js +6 -6
  14. package/dist/react/hooks/useDebounce.js +4 -4
  15. package/dist/react/hooks/useThrottle.js +2 -2
  16. package/dist/react/hooks/useWindowSize.js +2 -2
  17. package/package.json +1 -1
  18. package/dist/react/components/toast/helpers/manageToasts/swipeClose.js +0 -76
  19. /package/dist/react/components/toast/{helpers → service}/createToast.js +0 -0
  20. /package/dist/react/components/toast/{helpers → service}/listenars.js +0 -0
  21. /package/dist/react/components/toast/{helpers → service}/manageToasts/addToasts.js +0 -0
  22. /package/dist/react/components/toast/{helpers → service}/manageToasts/dismissToasts.js +0 -0
  23. /package/dist/react/components/toast/{helpers → service}/manageToasts/manageToasts.js +0 -0
  24. /package/dist/react/components/toast/{helpers → service}/manageToasts/timers.js +0 -0
  25. /package/dist/react/components/toast/{helpers → service}/manageToasts/updateToasts.js +0 -0
package/dist/fns.js CHANGED
@@ -1,4 +1,4 @@
1
- import { default as e } from "./functions/copy/copy.js";
1
+ import { copy as r } from "./functions/copy/index.js";
2
2
  export {
3
- e as copy
3
+ r as copy
4
4
  };
@@ -1,27 +1,27 @@
1
- function a(e) {
1
+ function o(e) {
2
2
  const t = document.createElement("textarea");
3
3
  t.value = e, document.body.appendChild(t), t.select(), document.execCommand("copy"), document.body.removeChild(t);
4
4
  }
5
- async function o(e) {
5
+ async function r(e) {
6
6
  if (!navigator.clipboard?.writeText) {
7
- a(e);
7
+ o(e);
8
8
  return;
9
9
  }
10
10
  try {
11
11
  await navigator.clipboard.writeText(e);
12
12
  } catch (t) {
13
- a(e), console.error(t);
13
+ o(e), console.error(t);
14
14
  }
15
15
  }
16
- async function r(e) {
16
+ async function a(e) {
17
17
  let t;
18
18
  try {
19
19
  t = typeof e == "string" || typeof e == "number" || typeof e == "boolean" ? String(e) : JSON.stringify(e);
20
20
  } catch {
21
21
  t = "[Cannot copy circular object]";
22
22
  }
23
- await o(t);
23
+ await r(t);
24
24
  }
25
25
  export {
26
- r as default
26
+ a as copy
27
27
  };
package/dist/index.d.ts CHANGED
@@ -15,10 +15,6 @@ declare type CopyStatus = 'standby' | 'copying' | 'copied' | 'error';
15
15
 
16
16
  declare type Options = ToastOptionsWithoutType;
17
17
 
18
- declare type Position = 'top' | 'top-start' | 'top-end' | 'right' | 'right-start' | 'right-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'left' | 'left-start' | 'left-end';
19
-
20
- declare type Positions = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
21
-
22
18
  declare type PromiseToastFn = <T, E = unknown>(promise: Promise<T>, msgs: PromiseToastMsgs<T, E>, options?: PromiseToastOptions) => Promise<T>;
23
19
 
24
20
  declare type PromiseToastMsgs<T, E = unknown> = {
@@ -35,16 +31,18 @@ declare type ToastContent = ((dismiss: () => void) => ReactNode) | ReactNode;
35
31
 
36
32
  export declare function Toaster(props: ToasterProps): JSX.Element | null;
37
33
 
38
- declare type ToasterProps = {
39
- position?: Positions;
40
- richColors?: boolean;
41
- animateTransformOrigin?: boolean;
34
+ export declare type ToasterProps = {
35
+ position?: ToastPositions;
42
36
  gap?: number | `${number}`;
43
37
  edgeOffset?: number | `${number}`;
44
- isDark?: boolean;
38
+ toasterId?: string | number;
39
+ dark?: boolean;
40
+ compact?: boolean;
41
+ richColors?: boolean;
45
42
  pauseOnHover?: boolean;
46
43
  swipeToClose?: boolean;
47
- toasterId?: string | number;
44
+ animateTransformOrigin?: boolean;
45
+ animateScale?: boolean;
48
46
  };
49
47
 
50
48
  declare type ToastFn = {
@@ -64,7 +62,7 @@ declare type ToastOptions = {
64
62
  duration?: number;
65
63
  showIcon?: boolean;
66
64
  icon?: ReactNode;
67
- position?: Positions;
65
+ position?: ToastPositions;
68
66
  animateTransformOrigin?: boolean;
69
67
  id?: string | number;
70
68
  type?: ToastType;
@@ -74,6 +72,8 @@ declare type ToastOptions = {
74
72
 
75
73
  declare type ToastOptionsWithoutType = Omit<ToastOptions, 'type'>;
76
74
 
75
+ export declare type ToastPositions = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
76
+
77
77
  declare type ToastType = 'default' | 'success' | 'warning' | 'error' | 'info' | 'custom' | 'loading';
78
78
 
79
79
  export declare function Tooltip(props: TooltipProps): ReactNode;
@@ -85,7 +85,7 @@ declare type TooltipCoreProps = {
85
85
  * content is necessary
86
86
  */
87
87
  content: ReactNode;
88
- position?: Position;
88
+ position?: TooltipPosition;
89
89
  offset?: number;
90
90
  smartHover?: boolean;
91
91
  hideOnTouch?: boolean;
@@ -94,6 +94,8 @@ declare type TooltipCoreProps = {
94
94
  isDark?: boolean;
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';
98
+
97
99
  declare type TooltipProps = PropsWithChildren<TooltipCoreProps>;
98
100
 
99
101
  declare type UpdateToastOptions = Omit<ToastOptions, 'id'>;
package/dist/index.js CHANGED
@@ -1,16 +1,16 @@
1
- import { default as t } from "./react/hooks/useWindowSize.js";
2
- import { default as r } from "./react/hooks/useDebounce.js";
3
- import { default as s } from "./react/hooks/useCopy.js";
4
- import { default as l } from "./react/hooks/useThrottle.js";
5
- import { default as d } from "./react/components/tooltip/Tooltip.js";
6
- import { default as x } from "./react/components/toast/Toaster.js";
7
- import { default as T } from "./react/components/toast/helpers/triggerToasts.js";
1
+ import { Toaster as r } from "./react/components/toast/Toaster.js";
2
+ import { Tooltip as p } from "./react/components/tooltip/Tooltip.js";
3
+ import { toast as m } from "./react/components/toast/service/triggerToasts.js";
4
+ import { useCopy as s } from "./react/hooks/useCopy.js";
5
+ import { useDebounce as i } from "./react/hooks/useDebounce.js";
6
+ import { useThrottle as a } from "./react/hooks/useThrottle.js";
7
+ import { useWindowSize as n } from "./react/hooks/useWindowSize.js";
8
8
  export {
9
- x as Toaster,
10
- d as Tooltip,
11
- T as toast,
9
+ r as Toaster,
10
+ p as Tooltip,
11
+ m as toast,
12
12
  s as useCopy,
13
- r as useDebounce,
14
- l as useThrottle,
15
- t as useWindowSize
13
+ i as useDebounce,
14
+ a as useThrottle,
15
+ n as useWindowSize
16
16
  };
@@ -1,37 +1,40 @@
1
- import { jsx as a } from "react/jsx-runtime";
1
+ import { jsx as i } from "react/jsx-runtime";
2
2
  import t from "react";
3
- import { subscribe as E } from "./helpers/listenars.js";
4
- import w from "./helpers/manageToasts/manageToasts.js";
5
- import M from "./partials/ToastContainer.js";
6
- import { ToasterContext as O } from "./context/ToasterContext.js";
7
- import { initSwipeToClose as S } from "./helpers/manageToasts/swipeClose.js";
8
- function D(i) {
3
+ import { subscribe as w } from "./service/listenars.js";
4
+ import z from "./service/manageToasts/manageToasts.js";
5
+ import O from "./partials/ToastContainer.js";
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: l = !1,
12
- animateTransformOrigin: g = !0,
13
- gap: s = 8,
11
+ position: b = "top-center",
12
+ gap: r = e?.compact ? 8 : 12,
14
13
  edgeOffset: n = 16,
15
- isDark: c,
16
- pauseOnHover: b = !0,
17
- swipeToClose: y = !0
18
- } = i, [k, T] = t.useState(!1);
14
+ dark: c,
15
+ compact: g = !1,
16
+ richColors: u = !1,
17
+ pauseOnHover: k = !0,
18
+ swipeToClose: y = !0,
19
+ animateScale: T = !1,
20
+ animateTransformOrigin: v = !0
21
+ } = e, [x, C] = t.useState(!1);
19
22
  t.useEffect(() => {
20
- T(!0);
23
+ C(!0);
21
24
  }, []);
22
- const [p, m] = t.useState([]);
25
+ const [m, p] = t.useState([]);
23
26
  t.useEffect(() => {
24
- const e = E(
25
- (o) => w({ toast: o, setToasts: m }),
26
- i.toasterId
27
- ), r = S();
27
+ const o = w(
28
+ (s) => z({ toast: s, setToasts: p }),
29
+ e.toasterId
30
+ ), a = $();
28
31
  return () => {
29
- e(), r();
32
+ o(), a();
30
33
  };
31
- }, [i.toasterId]);
32
- const f = t.useRef(null), u = t.useCallback(() => {
34
+ }, [e.toasterId]);
35
+ const f = t.useRef(null), l = t.useCallback(() => {
33
36
  if (!f.current) return;
34
- const e = f.current.querySelectorAll("[data-toast-container]"), r = {
37
+ const o = f.current.querySelectorAll("[data-kitzo-toast-container]"), a = {
35
38
  "top-left": 0,
36
39
  "top-center": 0,
37
40
  "top-right": 0,
@@ -39,18 +42,18 @@ function D(i) {
39
42
  "bottom-center": 0,
40
43
  "bottom-right": 0
41
44
  };
42
- e.forEach((o) => {
43
- const d = o.getAttribute("data-toast-position") || "top-center", x = parseFloat(o.style.getPropertyValue("--toast-height")) || 0;
44
- o.style.setProperty("--toast-offset-y", `${r[d]}px`);
45
- const C = isNaN(+s) ? 8 : +s;
46
- r[d] += x + C;
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);
47
50
  });
48
- }, [s]);
51
+ }, [r, e?.compact]);
49
52
  if (t.useLayoutEffect(() => {
50
- u();
51
- }, [p, u]), !k) return null;
52
- const v = typeof c == "boolean" ? c : window.matchMedia("(prefers-color-scheme: dark)").matches;
53
- return /* @__PURE__ */ a(
53
+ l();
54
+ }, [m, l]), !x) return null;
55
+ const E = typeof c == "boolean" ? c : window.matchMedia("(prefers-color-scheme: dark)").matches;
56
+ return /* @__PURE__ */ i(
54
57
  "div",
55
58
  {
56
59
  ref: f,
@@ -60,31 +63,33 @@ function D(i) {
60
63
  zIndex: 2147483647,
61
64
  pointerEvents: "none",
62
65
  display: "grid",
63
- padding: n != null ? `${Math.max(Math.min(+n, 200), 0)}px` : 16
66
+ padding: n != null ? `${h(Number(n), 0, 32)}px` : 16
64
67
  },
65
- className: `kitzo-toaster ${l ? "kitzo-toaster-rich-colors" : ""} ${v ? "kitzo-toaster-dark" : ""}`,
66
- children: /* @__PURE__ */ a(
68
+ className: `kitzo-toaster ${u ? "kitzo-toaster-rich-colors" : ""} ${E ? "dark kitzo-toaster-dark" : ""}`,
69
+ children: /* @__PURE__ */ i(
67
70
  "div",
68
71
  {
69
72
  style: {
70
73
  position: "relative"
71
74
  },
72
- children: /* @__PURE__ */ a(
73
- O.Provider,
75
+ children: /* @__PURE__ */ i(
76
+ I.Provider,
74
77
  {
75
78
  value: {
76
- position: h,
77
- richColors: l,
78
- isDark: c,
79
- gap: s,
79
+ position: b,
80
+ gap: r,
80
81
  edgeOffset: n,
81
- animateTransformOrigin: g,
82
- pauseOnHover: b,
82
+ setToasts: p,
83
+ updateOffsets: l,
84
+ dark: c,
85
+ compact: g,
86
+ richColors: u,
83
87
  swipeToClose: y,
84
- setToasts: m,
85
- updateOffsets: u
88
+ pauseOnHover: k,
89
+ animateScale: T,
90
+ animateTransformOrigin: v
86
91
  },
87
- children: p.map((e) => /* @__PURE__ */ a(M, { t: e }, e.id))
92
+ children: m.map((o) => /* @__PURE__ */ i(O, { t: o }, o.id))
88
93
  }
89
94
  )
90
95
  }
@@ -93,5 +98,5 @@ function D(i) {
93
98
  );
94
99
  }
95
100
  export {
96
- D as default
101
+ F as Toaster
97
102
  };
@@ -1,30 +1,30 @@
1
- import { jsxs as x, jsx as t, Fragment as s } from "react/jsx-runtime";
2
- import { resumeToast as p, pauseToast as u } from "../helpers/manageToasts/timers.js";
3
- import S from "../helpers/triggerToasts.js";
4
- import { InfoSvg as w, ErrorSvg as I, WarningSvg as E, SuccessSvg as k, LoadingSvg as L } from "./Svgs.js";
5
- import { useToasterContext as M } from "../context/ToasterContext.js";
6
- function P({
7
- t: d,
8
- position: n,
9
- shouldAnimateTransformOrigin: c,
10
- swipeToClose: m
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: o } = M(), {
12
+ const { pauseOnHover: d, compact: m } = j(), {
13
13
  id: e,
14
- type: r,
15
- action: f,
16
- content: i,
17
- status: g,
18
- showIcon: v,
14
+ type: s,
15
+ action: u,
16
+ content: r,
17
+ status: f,
18
+ showIcon: g,
19
19
  icon: a,
20
- toasterId: h,
21
- updateState: y
22
- } = d, l = {
23
- loading: /* @__PURE__ */ t(L, {}),
24
- success: /* @__PURE__ */ t(k, {}),
20
+ toasterId: v,
21
+ updateState: h
22
+ } = i, c = {
23
+ loading: /* @__PURE__ */ t(b, {}),
24
+ success: /* @__PURE__ */ t(N, {}),
25
25
  warning: /* @__PURE__ */ t(E, {}),
26
- error: /* @__PURE__ */ t(I, {}),
27
- info: /* @__PURE__ */ t(w, {}),
26
+ error: /* @__PURE__ */ t(w, {}),
27
+ info: /* @__PURE__ */ t(k, {}),
28
28
  default: null,
29
29
  custom: null
30
30
  };
@@ -36,27 +36,28 @@ function P({
36
36
  pointerEvents: "all",
37
37
  display: "flex",
38
38
  alignItems: "center",
39
- gap: 8,
40
- whiteSpace: "pre-wrap"
39
+ gap: 8
41
40
  },
42
- "data-toaster-id": h,
43
- "data-action": f,
44
- "data-status": g,
45
- "data-type": r,
46
- "data-position": n,
47
- "data-screen-x": n.split("-")[1],
48
- "data-screen-y": n.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],
49
48
  "data-exit": "auto",
50
- "data-swipeable": m,
51
- "data-animate-transform-origin": c,
52
- "data-update-state": y,
53
- onPointerEnter: () => o && u(e),
54
- onPointerLeave: () => o && p(e),
55
- onMouseEnter: () => o && u(e),
56
- onMouseLeave: () => o && p(e),
57
- className: `kitzo-toast ${c ? `transform-origin-${n}` : ""}`,
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),
58
+ className: "kitzo-toast",
58
59
  children: [
59
- v && /* @__PURE__ */ t(s, { children: a ? /* @__PURE__ */ t(s, { 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 P({
65
66
  className: "svg-container",
66
67
  children: a
67
68
  }
68
- ) : /* @__PURE__ */ t(s, { children: a }) }) : /* @__PURE__ */ t(s, { children: l[r] && /* @__PURE__ */ t("div", { style: { flexShrink: 0 }, className: "svg-container", children: l[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(() => S.dismiss(e, d.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 P({
80
81
  );
81
82
  }
82
83
  export {
83
- P 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
  };
@@ -85,13 +85,15 @@ const a = `.kitzo-toaster {
85
85
  }
86
86
 
87
87
  .kitzo-toast {
88
- font-family: inherit;
89
- font-size: 0.875rem;
90
88
  transition:
91
89
  transform 280ms,
92
90
  opacity 280ms;
93
91
  will-change: transform, opacity;
94
92
  touch-action: pan-y;
93
+
94
+ font-family: inherit;
95
+ font-size: 0.875rem;
96
+ white-space: pre-wrap;
95
97
  }
96
98
 
97
99
  .kitzo-toast.is-swiping {
@@ -140,25 +142,41 @@ const a = `.kitzo-toaster {
140
142
  .kitzo-toast[data-type='warning'],
141
143
  .kitzo-toast[data-type='error'],
142
144
  .kitzo-toast[data-type='info'] {
143
- border-radius: 0.425rem;
145
+ border-radius: 0.5525rem;
144
146
  padding: 0.375rem 0.625rem;
145
147
  box-shadow: 0 3px 8px -3px hsl(0, 0%, 0%, 0.15);
146
148
  }
147
149
 
150
+ /*! toast size */
151
+ .kitzo-toast[data-compact='false']:not([data-type='custom']) {
152
+ flex: 1;
153
+ min-height: 40px;
154
+
155
+ @media (width > 380px) {
156
+ max-width: 250px;
157
+ }
158
+ }
159
+
148
160
  /*! toast transition styles */
149
161
  .kitzo-toast {
150
162
  --swipe-x: 0px;
151
163
  --motion-y: 0%;
152
- --scale: 0.6;
164
+ --scale: 1;
153
165
  --exit-x: 0px;
154
166
  }
155
167
 
168
+ .kitzo-toast-container[data-animate-scale='true'] {
169
+ .kitzo-toast {
170
+ --scale: 0.6;
171
+ }
172
+ }
173
+
156
174
  .kitzo-toast[data-screen-y='top'] {
157
- --motion-y: -120%;
175
+ --motion-y: -100%;
158
176
  }
159
177
 
160
178
  .kitzo-toast[data-screen-y='bottom'] {
161
- --motion-y: 120%;
179
+ --motion-y: 100%;
162
180
  }
163
181
 
164
182
  .kitzo-toast[data-status='leaving'][data-exit='swipe'] {
@@ -183,10 +201,10 @@ const a = `.kitzo-toaster {
183
201
  }
184
202
 
185
203
  .kitzo-toast[data-update-state='updated'] {
186
- animation: update 250ms ease;
204
+ animation: update 280ms ease;
187
205
  }
188
206
  .kitzo-toast[data-update-state='updated-again'] {
189
- animation: update-again 250ms ease;
207
+ animation: update-again 280ms ease;
190
208
  }
191
209
 
192
210
  @keyframes update {
@@ -210,31 +228,32 @@ const a = `.kitzo-toaster {
210
228
  }
211
229
  }
212
230
 
213
- /*! toast transfor origin */
231
+ /*! toast transform origin */
214
232
  .kitzo-toast[data-position^='top'] {
215
233
  transform-origin: top;
216
234
  }
217
235
  .kitzo-toast[data-position^='bottom'] {
218
236
  transform-origin: bottom;
219
237
  }
220
-
221
- .kitzo-toast[data-animate-transform-origin='true'][data-position='top-left'] {
222
- transform-origin: top left;
223
- }
224
- .kitzo-toast[data-animate-transform-origin='true'][data-position='top-center'] {
225
- transform-origin: top;
226
- }
227
- .kitzo-toast[data-animate-transform-origin='true'][data-position='top-right'] {
228
- transform-origin: top right;
229
- }
230
- .kitzo-toast[data-animate-transform-origin='true'][data-position='bottom-left'] {
231
- transform-origin: bottom left;
232
- }
233
- .kitzo-toast[data-animate-transform-origin='true'][data-position='bottom-center'] {
234
- transform-origin: bottom;
235
- }
236
- .kitzo-toast[data-animate-transform-origin='true'][data-position='bottom-right'] {
237
- 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
+ }
238
257
  }
239
258
 
240
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
+ };
@@ -1,7 +1,7 @@
1
1
  import { createToast as n, updateToast as s, genId as c } from "./createToast.js";
2
- import { notify as i } from "./listenars.js";
3
- const e = (r, t) => {
4
- r != null && i(
2
+ import { notify as e } from "./listenars.js";
3
+ const i = (r, t) => {
4
+ r != null && e(
5
5
  n({
6
6
  type: "default",
7
7
  action: "add",
@@ -10,15 +10,15 @@ const e = (r, t) => {
10
10
  })
11
11
  );
12
12
  };
13
- e.dismiss = (r, t) => {
14
- i({
13
+ i.dismiss = (r, t) => {
14
+ e({
15
15
  action: "dismiss",
16
16
  id: r,
17
17
  toasterId: t
18
18
  });
19
19
  };
20
- e.info = (r, t) => {
21
- r != null && i(
20
+ i.info = (r, t) => {
21
+ r != null && e(
22
22
  n({
23
23
  action: "add",
24
24
  type: "info",
@@ -27,8 +27,8 @@ e.info = (r, t) => {
27
27
  })
28
28
  );
29
29
  };
30
- e.success = (r, t) => {
31
- r != null && i(
30
+ i.success = (r, t) => {
31
+ r != null && e(
32
32
  n({
33
33
  action: "add",
34
34
  type: "success",
@@ -37,8 +37,8 @@ e.success = (r, t) => {
37
37
  })
38
38
  );
39
39
  };
40
- e.warning = (r, t) => {
41
- r != null && i(
40
+ i.warning = (r, t) => {
41
+ r != null && e(
42
42
  n({
43
43
  action: "add",
44
44
  type: "warning",
@@ -47,8 +47,8 @@ e.warning = (r, t) => {
47
47
  })
48
48
  );
49
49
  };
50
- e.error = (r, t) => {
51
- r != null && i(
50
+ i.error = (r, t) => {
51
+ r != null && e(
52
52
  n({
53
53
  action: "add",
54
54
  type: "error",
@@ -57,8 +57,8 @@ e.error = (r, t) => {
57
57
  })
58
58
  );
59
59
  };
60
- e.loading = (r, t) => {
61
- r != null && i(
60
+ i.loading = (r, t) => {
61
+ r != null && e(
62
62
  n({
63
63
  action: "add",
64
64
  type: "loading",
@@ -67,8 +67,8 @@ e.loading = (r, t) => {
67
67
  })
68
68
  );
69
69
  };
70
- e.custom = (r, t) => {
71
- r != null && i(
70
+ i.custom = (r, t) => {
71
+ r != null && e(
72
72
  n({
73
73
  action: "add",
74
74
  type: "custom",
@@ -77,27 +77,27 @@ e.custom = (r, t) => {
77
77
  })
78
78
  );
79
79
  };
80
- e.update = (r, t, a) => {
81
- r != null && t != null && i(s({ id: `${r}`, content: t, options: a }));
80
+ i.update = (r, t, o) => {
81
+ r != null && t != null && e(s({ id: `${r}`, content: t, options: o }));
82
82
  };
83
- e.promise = (async (r, t, a) => {
83
+ i.promise = (async (r, t, o) => {
84
84
  const u = c();
85
- i(
85
+ e(
86
86
  n({
87
87
  action: "add",
88
88
  type: "loading",
89
89
  content: t.loading,
90
- options: { ...a, id: u, duration: 1 / 0, swipeToClose: !1 }
90
+ options: { ...o, id: u, duration: 1 / 0, swipeToClose: !1 }
91
91
  })
92
92
  );
93
93
  try {
94
- const o = await r, d = typeof t.success == "function" ? await t.success(o) : t.success;
95
- return e.update(u, d, { ...a, type: "success" }), o;
96
- } catch (o) {
97
- const d = typeof t.error == "function" ? await t.error(o) : t.error;
98
- throw e.update(u, d, { ...a, type: "error" }), o;
94
+ const a = await r, d = typeof t.success == "function" ? await t.success(a) : t.success;
95
+ return i.update(u, d, { ...o, type: "success" }), a;
96
+ } catch (a) {
97
+ const d = typeof t.error == "function" ? await t.error(a) : t.error;
98
+ throw i.update(u, d, { ...o, type: "error" }), a;
99
99
  }
100
100
  });
101
101
  export {
102
- e as default
102
+ i as toast
103
103
  };
@@ -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,5 +1,5 @@
1
1
  import { jsx as a, Fragment as r, jsxs as T } from "react/jsx-runtime";
2
- import c from "react";
2
+ import d from "react";
3
3
  import v from "./helpers/addTooltipStyles.js";
4
4
  import w from "./helpers/getPositionClass.js";
5
5
  import O from "./partials/TooltipWrapper.js";
@@ -11,24 +11,24 @@ function C(h) {
11
11
  position: y = "top",
12
12
  animation: i = !0,
13
13
  isHidden: s = !1,
14
- offset: f = 8,
15
- smartHover: m = !0,
14
+ offset: m = 8,
15
+ smartHover: f = !0,
16
16
  hideOnTouch: l = !0,
17
17
  isDark: u
18
- } = h, [D, b] = c.useState(!1);
19
- if (c.useEffect(() => {
18
+ } = h, [D, b] = d.useState(!1);
19
+ if (d.useEffect(() => {
20
20
  b(!0), v();
21
21
  }, []), !D) 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
25
  const o = {
26
- offset: isNaN(Number(f)) ? 8 : Number(f),
27
- smartHover: typeof m == "boolean" ? m : !0,
26
+ offset: isNaN(Number(m)) ? 8 : Number(m),
27
+ smartHover: typeof f == "boolean" ? f : !0,
28
28
  hideOnTouch: typeof l == "boolean" ? l : !0
29
29
  };
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 && o.hideOnTouch) return t;
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
32
  const x = w(y), M = !!i, e = k(
33
33
  i === !0 ? {} : i
34
34
  );
@@ -63,5 +63,5 @@ function C(h) {
63
63
  );
64
64
  }
65
65
  export {
66
- C as default
66
+ C as Tooltip
67
67
  };
@@ -1,12 +1,12 @@
1
- import { useState as u, useRef as i, useCallback as y, useEffect as p } from "react";
2
- import m from "../../functions/copy/copy.js";
1
+ import { useState as u, useRef as i, useCallback as l, useEffect as p } from "react";
2
+ import { copy as m } from "../../functions/copy/index.js";
3
3
  function E(c = 1500) {
4
- const [r, e] = u("standby"), [a, s] = u(null), t = i(null), n = i(!1), f = y(
5
- async (l) => {
4
+ const [r, e] = u("standby"), [a, s] = u(null), t = i(null), n = i(!1), f = l(
5
+ async (y) => {
6
6
  if (!n.current) {
7
7
  t.current && clearTimeout(t.current);
8
8
  try {
9
- n.current = !0, s(null), e("copying"), await m(l), e("copied");
9
+ n.current = !0, s(null), e("copying"), await m(y), e("copied");
10
10
  } catch (o) {
11
11
  s(o instanceof Error ? o : new Error(String(o))), e("error");
12
12
  } finally {
@@ -34,5 +34,5 @@ function E(c = 1500) {
34
34
  };
35
35
  }
36
36
  export {
37
- E as default
37
+ E as useCopy
38
38
  };
@@ -1,16 +1,16 @@
1
1
  import { useState as r, useEffect as c } from "react";
2
2
  function f(e, t) {
3
3
  t ??= 500;
4
- const [u, o] = r(e);
4
+ const [o, u] = r(e);
5
5
  return c(() => {
6
6
  const n = setTimeout(() => {
7
- o(e);
7
+ u(e);
8
8
  }, t);
9
9
  return () => {
10
10
  clearTimeout(n);
11
11
  };
12
- }, [e, t]), u;
12
+ }, [e, t]), o;
13
13
  }
14
14
  export {
15
- f as default
15
+ f as useDebounce
16
16
  };
@@ -1,5 +1,5 @@
1
1
  import { useState as c, useRef as f, useEffect as i } from "react";
2
- function a(t, e = 500) {
2
+ function l(t, e = 500) {
3
3
  const [n, u] = c(t), r = f(0);
4
4
  return i(() => {
5
5
  function s() {
@@ -10,5 +10,5 @@ function a(t, e = 500) {
10
10
  }, [t, e]), n;
11
11
  }
12
12
  export {
13
- a as default
13
+ l as useThrottle
14
14
  };
@@ -1,5 +1,5 @@
1
1
  import t from "react";
2
- function c(i = 30) {
2
+ function u(i = 30) {
3
3
  const [r, o] = t.useState({
4
4
  screenWidth: 0,
5
5
  screenHeight: 0
@@ -22,5 +22,5 @@ function c(i = 30) {
22
22
  }, [i]), r;
23
23
  }
24
24
  export {
25
- c as default
25
+ u as useWindowSize
26
26
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kitzo",
3
- "version": "2.4.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 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
- };