kitzo 2.3.37 → 2.3.39

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,59 +1,61 @@
1
- import { jsxs as d, jsx as h } from "react/jsx-runtime";
2
- import y from "./helpers/addTooltipStyles.js";
3
- import D from "./helpers/getPositionClass.js";
4
- import b from "./partials/TooltipWrapper.js";
5
- import T from "./helpers/getAnimationProperties.js";
6
- const x = () => window.matchMedia("(prefers-color-scheme: dark)").matches;
7
- function H(n) {
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) {
8
8
  const {
9
9
  content: r,
10
10
  children: t,
11
- position: c = "top",
12
- animation: i = !0,
13
- isHidden: s = !1,
14
- offset: m = 8,
15
- smartHover: l = !0,
16
- hideOnTouch: f = !0
17
- } = n;
18
- let { isDark: o } = n;
19
- if (typeof s == "boolean" && s || r == null)
20
- return t;
21
- const e = {
22
- offset: isNaN(Number(m)) ? 8 : Number(m),
23
- // arrow: typeof arrow === 'boolean' ? arrow : false,
24
- smartHover: typeof l == "boolean" ? l : !0,
25
- hideOnTouch: typeof f == "boolean" ? f : !0
11
+ position: y = "top",
12
+ animation: a = !0,
13
+ isHidden: n = !1,
14
+ offset: s = 8,
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 });
23
+ if (r == null)
24
+ return /* @__PURE__ */ i(d, { children: t });
25
+ const o = {
26
+ offset: isNaN(Number(s)) ? 8 : Number(s),
27
+ smartHover: typeof f == "boolean" ? f : !0,
28
+ hideOnTouch: typeof m == "boolean" ? m : !0
26
29
  };
27
- if (window.matchMedia("(pointer: coarse)").matches && e.hideOnTouch) return t;
28
- const p = D(c), u = !!i, a = T(
29
- i === !0 ? {} : i
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(
33
+ a === !0 ? {} : a
30
34
  );
31
- return o = typeof o == "boolean" ? o : x(), y(), /* @__PURE__ */ d(
35
+ return /* @__PURE__ */ T(
32
36
  "div",
33
37
  {
34
38
  style: {
35
39
  position: "relative",
36
40
  width: "fit-content",
37
- "--offset": Math.max(0, e.offset),
41
+ "--offset": Math.max(0, o.offset),
38
42
  "--startDuration": Math.max(
39
43
  0,
40
- a.startDuration
44
+ e.startDuration
41
45
  ),
42
- "--endDuration": Math.max(0, a.endDuration),
43
- "--startDelay": Math.max(0, a.startDelay),
44
- "--endDelay": Math.max(0, a.endDelay)
45
- // '--arrow-color': arrowStyle?.['--arrow-color'],
46
- // '--arrow-size': arrowStyle?.['--arrow-size'],
46
+ "--endDuration": Math.max(0, e.endDuration),
47
+ "--startDelay": Math.max(0, e.startDelay),
48
+ "--endDelay": Math.max(0, e.endDelay)
47
49
  },
48
- className: `kitzo-tooltip-root ${o ? "tooltip-theme-dark" : ""} ${e.smartHover ? "smart-hover" : ""} ${u ? "animate-tooltip" : ""}`,
50
+ className: `kitzo-tooltip-root ${u ? "tooltip-theme-dark" : ""} ${o.smartHover ? "smart-hover" : ""} ${M ? "animate-tooltip" : ""}`,
49
51
  children: [
50
52
  t,
51
- /* @__PURE__ */ h(
52
- b,
53
+ /* @__PURE__ */ i(
54
+ O,
53
55
  {
54
56
  content: r,
55
- positionClass: p,
56
- finalOptions: e
57
+ positionClass: x,
58
+ finalOptions: o
57
59
  }
58
60
  )
59
61
  ]
@@ -61,5 +63,5 @@ function H(n) {
61
63
  );
62
64
  }
63
65
  export {
64
- H as default
66
+ C as default
65
67
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kitzo",
3
- "version": "2.3.37",
3
+ "version": "2.3.39",
4
4
  "description": "A lightweight React micro-utility.",
5
5
  "type": "module",
6
6
  "files": [