kitzo 2.3.38 → 2.3.40

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
@@ -33,7 +33,7 @@ export declare const toast: ToastFn;
33
33
 
34
34
  declare type ToastContent = ((dismiss: () => void) => ReactNode) | ReactNode;
35
35
 
36
- export declare function Toaster(props: ToasterProps): JSX.Element;
36
+ export declare function Toaster(props: ToasterProps): JSX.Element | null;
37
37
 
38
38
  declare type ToasterProps = {
39
39
  position?: Positions;
@@ -1,30 +1,34 @@
1
- import { jsx as r } from "react/jsx-runtime";
2
- import { useState as k, useEffect as v, useRef as x, useCallback as C, useLayoutEffect as w } from "react";
1
+ import { jsx as a } from "react/jsx-runtime";
2
+ import t from "react";
3
3
  import { subscribe as E } from "./helpers/listenar.js";
4
- import O from "./helpers/manageToasts/manageToasts.js";
5
- import z from "./partials/ToastContainer.js";
6
- import { ToasterContext as S } from "./context/ToasterContext.js";
7
- import { initSwipeToClose as $ } from "./helpers/manageToasts/swipeClose.js";
8
- function D(m) {
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 I(d) {
9
9
  const {
10
- position: d = "top-center",
11
- richColors: c = !1,
12
- animateTransformOrigin: h = !0,
13
- gap: o = 8,
14
- edgeOffset: a = 16,
15
- isDark: p = window.matchMedia("(prefers-color-scheme: dark)").matches,
16
- pauseOnHover: g = !0,
17
- swipeToClose: b = !0
18
- } = m, [f, l] = k([]);
19
- v(() => {
20
- const t = E((e) => O({ toast: e, setToasts: l })), s = $();
10
+ position: h = "top-center",
11
+ richColors: p = !1,
12
+ animateTransformOrigin: g = !0,
13
+ gap: s = 8,
14
+ edgeOffset: i = 16,
15
+ isDark: n,
16
+ pauseOnHover: b = !0,
17
+ swipeToClose: y = !0
18
+ } = d, [k, T] = t.useState(!1);
19
+ t.useEffect(() => {
20
+ T(!0);
21
+ }, []);
22
+ const [u, l] = t.useState([]);
23
+ t.useEffect(() => {
24
+ const e = E((o) => w({ toast: o, setToasts: l })), r = S();
21
25
  return () => {
22
- t(), s();
26
+ e(), r();
23
27
  };
24
28
  }, []);
25
- const i = x(null), n = C(() => {
26
- if (!i.current) return;
27
- const t = i.current.querySelectorAll("[data-toast-container]"), s = {
29
+ const c = t.useRef(null), f = t.useCallback(() => {
30
+ if (!c.current) return;
31
+ const e = c.current.querySelectorAll("[data-toast-container]"), r = {
28
32
  "top-left": 0,
29
33
  "top-center": 0,
30
34
  "top-right": 0,
@@ -32,50 +36,52 @@ function D(m) {
32
36
  "bottom-center": 0,
33
37
  "bottom-right": 0
34
38
  };
35
- t.forEach((e) => {
36
- const u = e.getAttribute("data-toast-position") || "top-center", y = parseFloat(e.style.getPropertyValue("--toast-height")) || 0;
37
- e.style.setProperty("--toast-offset-y", `${s[u]}px`);
38
- const T = isNaN(+o) ? 8 : +o;
39
- s[u] += y + T;
39
+ e.forEach((o) => {
40
+ const m = o.getAttribute("data-toast-position") || "top-center", x = parseFloat(o.style.getPropertyValue("--toast-height")) || 0;
41
+ o.style.setProperty("--toast-offset-y", `${r[m]}px`);
42
+ const C = isNaN(+s) ? 8 : +s;
43
+ r[m] += x + C;
40
44
  });
41
- }, [o]);
42
- return w(() => {
43
- n();
44
- }, [f, n]), /* @__PURE__ */ r(
45
+ }, [s]);
46
+ if (t.useLayoutEffect(() => {
47
+ f();
48
+ }, [u, f]), !k) return null;
49
+ const v = typeof n == "boolean" ? n : window.matchMedia("(prefers-color-scheme: dark)").matches;
50
+ return /* @__PURE__ */ a(
45
51
  "div",
46
52
  {
47
- ref: i,
53
+ ref: c,
48
54
  style: {
49
55
  position: "fixed",
50
56
  inset: 0,
51
57
  zIndex: 2147483647,
52
58
  pointerEvents: "none",
53
59
  display: "grid",
54
- padding: a != null ? `${Math.max(Math.min(+a, 200), 0)}px` : 16
60
+ padding: i != null ? `${Math.max(Math.min(+i, 200), 0)}px` : 16
55
61
  },
56
- className: `kitzo-toaster ${c ? "kitzo-toaster-rich-colors" : ""} ${p ? "kitzo-toaster-dark" : ""}`,
57
- children: /* @__PURE__ */ r(
62
+ className: `kitzo-toaster ${p ? "kitzo-toaster-rich-colors" : ""} ${v ? "kitzo-toaster-dark" : ""}`,
63
+ children: /* @__PURE__ */ a(
58
64
  "div",
59
65
  {
60
66
  style: {
61
67
  position: "relative"
62
68
  },
63
- children: /* @__PURE__ */ r(
64
- S.Provider,
69
+ children: /* @__PURE__ */ a(
70
+ O.Provider,
65
71
  {
66
72
  value: {
67
- position: d,
68
- richColors: c,
69
- isDark: p,
70
- gap: o,
71
- edgeOffset: a,
72
- animateTransformOrigin: h,
73
- pauseOnHover: g,
74
- swipeToClose: b,
73
+ position: h,
74
+ richColors: p,
75
+ isDark: n,
76
+ gap: s,
77
+ edgeOffset: i,
78
+ animateTransformOrigin: g,
79
+ pauseOnHover: b,
80
+ swipeToClose: y,
75
81
  setToasts: l,
76
- updateOffsets: n
82
+ updateOffsets: f
77
83
  },
78
- children: f.map((t) => /* @__PURE__ */ r(z, { t }, t.id))
84
+ children: u.map((e) => /* @__PURE__ */ a(M, { t: e }, e.id))
79
85
  }
80
86
  )
81
87
  }
@@ -84,5 +90,5 @@ function D(m) {
84
90
  );
85
91
  }
86
92
  export {
87
- D as default
93
+ I as default
88
94
  };
@@ -1,34 +1,38 @@
1
- import { jsx as i, Fragment as u, jsxs as b } from "react/jsx-runtime";
2
- import x from "./helpers/addTooltipStyles.js";
3
- import T from "./helpers/getPositionClass.js";
4
- import v from "./partials/TooltipWrapper.js";
5
- import w from "./helpers/getAnimationProperties.js";
6
- function H(c) {
1
+ import { jsx as i, Fragment as d, jsxs as T } from "react/jsx-runtime";
2
+ import c from "react";
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) {
7
8
  const {
8
9
  content: r,
9
10
  children: t,
10
- position: h = "top",
11
+ position: y = "top",
11
12
  animation: a = !0,
12
13
  isHidden: n = !1,
13
14
  offset: s = 8,
14
- smartHover: m = !0,
15
- hideOnTouch: l = !0,
16
- isDark: f
17
- } = c;
18
- if (typeof n == "boolean" && n) return /* @__PURE__ */ i(u, { children: t });
15
+ smartHover: f = !0,
16
+ hideOnTouch: m = !0,
17
+ isDark: l
18
+ } = h, [D, b] = c.useState(!1);
19
+ if (c.useEffect(() => {
20
+ b(!0), v();
21
+ }, []), !D) return null;
22
+ if (typeof n == "boolean" && n) return /* @__PURE__ */ i(d, { children: t });
19
23
  if (r == null)
20
- return /* @__PURE__ */ i(u, { children: t });
24
+ return /* @__PURE__ */ i(d, { children: t });
21
25
  const o = {
22
26
  offset: isNaN(Number(s)) ? 8 : Number(s),
23
- smartHover: typeof m == "boolean" ? m : !0,
24
- hideOnTouch: typeof l == "boolean" ? l : !0
27
+ smartHover: typeof f == "boolean" ? f : !0,
28
+ hideOnTouch: typeof m == "boolean" ? m : !0
25
29
  };
26
- let p = !1, d = !1;
27
- if (typeof window < "u" && (d = window.matchMedia("(pointer: coarse)").matches || navigator.maxTouchPoints > 0, p = typeof f == "boolean" ? f : window.matchMedia("(prefers-color-scheme: dark)").matches), d && o.hideOnTouch) return t;
28
- const y = T(h), D = !!a, e = w(
30
+ let u = !1, p = !1;
31
+ if (typeof window < "u" && (p = window.matchMedia("(pointer: coarse)").matches || navigator.maxTouchPoints > 0, u = typeof l == "boolean" ? l : window.matchMedia("(prefers-color-scheme: dark)").matches), p && o.hideOnTouch) return t;
32
+ const x = w(y), M = !!a, e = k(
29
33
  a === !0 ? {} : a
30
34
  );
31
- return x(), /* @__PURE__ */ b(
35
+ return /* @__PURE__ */ T(
32
36
  "div",
33
37
  {
34
38
  style: {
@@ -43,14 +47,14 @@ function H(c) {
43
47
  "--startDelay": Math.max(0, e.startDelay),
44
48
  "--endDelay": Math.max(0, e.endDelay)
45
49
  },
46
- className: `kitzo-tooltip-root ${p ? "tooltip-theme-dark" : ""} ${o.smartHover ? "smart-hover" : ""} ${D ? "animate-tooltip" : ""}`,
50
+ className: `kitzo-tooltip-root ${u ? "tooltip-theme-dark" : ""} ${o.smartHover ? "smart-hover" : ""} ${M ? "animate-tooltip" : ""}`,
47
51
  children: [
48
52
  t,
49
53
  /* @__PURE__ */ i(
50
- v,
54
+ O,
51
55
  {
52
56
  content: r,
53
- positionClass: y,
57
+ positionClass: x,
54
58
  finalOptions: o
55
59
  }
56
60
  )
@@ -59,5 +63,5 @@ function H(c) {
59
63
  );
60
64
  }
61
65
  export {
62
- H as default
66
+ C as default
63
67
  };
@@ -1,26 +1,26 @@
1
- import { useState as o, useRef as u, useEffect as c } from "react";
2
- function d(n = 30) {
3
- const [t, r] = o({
4
- screenWidth: window.innerWidth,
5
- screenHeight: window.innerHeight
6
- }), e = u(null);
7
- return c(() => {
8
- function i() {
1
+ import t from "react";
2
+ function o(i = 30) {
3
+ const [r, c] = t.useState({
4
+ screenWidth: 0,
5
+ screenHeight: 0
6
+ }), e = t.useRef(null);
7
+ return t.useEffect(() => {
8
+ function n() {
9
9
  e.current && clearTimeout(e.current), e.current = setTimeout(
10
10
  () => {
11
- r({
11
+ c({
12
12
  screenWidth: window.innerWidth,
13
13
  screenHeight: window.innerHeight
14
14
  });
15
15
  },
16
- Math.max(0, +n)
16
+ Math.max(0, +i)
17
17
  );
18
18
  }
19
- return typeof window < "u" && window.addEventListener("resize", i), () => {
20
- e.current && clearTimeout(e.current), window.removeEventListener("resize", i);
19
+ return typeof window < "u" && (n(), window.addEventListener("resize", n)), () => {
20
+ e.current && clearTimeout(e.current), window.removeEventListener("resize", n);
21
21
  };
22
- }, [n]), t;
22
+ }, [i]), r;
23
23
  }
24
24
  export {
25
- d as default
25
+ o as default
26
26
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kitzo",
3
- "version": "2.3.38",
3
+ "version": "2.3.40",
4
4
  "description": "A lightweight React micro-utility.",
5
5
  "type": "module",
6
6
  "files": [