kitzo 2.3.36 → 2.3.37

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.
@@ -1,24 +1,30 @@
1
- import { jsx as s } from "react/jsx-runtime";
2
- import { useState as v, useEffect as x, useRef as T, useCallback as C, useLayoutEffect as E } from "react";
3
- import { subscribe as O } from "./helpers/listenar.js";
4
- import z from "./helpers/manageToasts/manageToasts.js";
5
- import $ from "./partials/ToastContainer.js";
6
- import { ToasterContext as w } from "./context/ToasterContext.js";
7
- function j(m) {
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";
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) {
8
9
  const {
9
10
  position: d = "top-center",
10
11
  richColors: c = !1,
11
12
  animateTransformOrigin: h = !0,
12
- gap: e = 8,
13
- edgeOffset: r = 16,
14
- isDark: f = window.matchMedia("(prefers-color-scheme: dark)").matches,
13
+ gap: o = 8,
14
+ edgeOffset: a = 16,
15
+ isDark: p = window.matchMedia("(prefers-color-scheme: dark)").matches,
15
16
  pauseOnHover: g = !0,
16
- swipeToClose: y = !0
17
- } = m, [p, l] = v([]);
18
- x(() => O((o) => z({ toast: o, setToasts: l })), []);
19
- const a = T(null), i = C(() => {
20
- if (!a.current) return;
21
- const t = a.current.querySelectorAll("[data-toast-container]"), o = {
17
+ swipeToClose: b = !0
18
+ } = m, [f, l] = k([]);
19
+ v(() => {
20
+ const t = E((e) => O({ toast: e, setToasts: l })), s = $();
21
+ return () => {
22
+ t(), s();
23
+ };
24
+ }, []);
25
+ const i = x(null), n = C(() => {
26
+ if (!i.current) return;
27
+ const t = i.current.querySelectorAll("[data-toast-container]"), s = {
22
28
  "top-left": 0,
23
29
  "top-center": 0,
24
30
  "top-right": 0,
@@ -26,50 +32,50 @@ function j(m) {
26
32
  "bottom-center": 0,
27
33
  "bottom-right": 0
28
34
  };
29
- t.forEach((n) => {
30
- const u = n.getAttribute("data-toast-position") || "top-center", b = parseFloat(n.style.getPropertyValue("--toast-height")) || 0;
31
- n.style.setProperty("--toast-offset-y", `${o[u]}px`);
32
- const k = isNaN(+e) ? 8 : +e;
33
- o[u] += b + k;
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;
34
40
  });
35
- }, [e]);
36
- return E(() => {
37
- i();
38
- }, [p, i]), /* @__PURE__ */ s(
41
+ }, [o]);
42
+ return w(() => {
43
+ n();
44
+ }, [f, n]), /* @__PURE__ */ r(
39
45
  "div",
40
46
  {
41
- ref: a,
47
+ ref: i,
42
48
  style: {
43
49
  position: "fixed",
44
50
  inset: 0,
45
51
  zIndex: 2147483647,
46
52
  pointerEvents: "none",
47
53
  display: "grid",
48
- padding: r != null ? `${Math.max(Math.min(+r, 200), 0)}px` : 16
54
+ padding: a != null ? `${Math.max(Math.min(+a, 200), 0)}px` : 16
49
55
  },
50
- className: `kitzo-toaster ${c ? "kitzo-toaster-rich-colors" : ""} ${f ? "kitzo-toaster-dark" : ""}`,
51
- children: /* @__PURE__ */ s(
56
+ className: `kitzo-toaster ${c ? "kitzo-toaster-rich-colors" : ""} ${p ? "kitzo-toaster-dark" : ""}`,
57
+ children: /* @__PURE__ */ r(
52
58
  "div",
53
59
  {
54
60
  style: {
55
61
  position: "relative"
56
62
  },
57
- children: /* @__PURE__ */ s(
58
- w.Provider,
63
+ children: /* @__PURE__ */ r(
64
+ S.Provider,
59
65
  {
60
66
  value: {
61
67
  position: d,
62
68
  richColors: c,
63
- isDark: f,
64
- gap: e,
65
- edgeOffset: r,
69
+ isDark: p,
70
+ gap: o,
71
+ edgeOffset: a,
66
72
  animateTransformOrigin: h,
67
73
  pauseOnHover: g,
68
- swipeToClose: y,
74
+ swipeToClose: b,
69
75
  setToasts: l,
70
- updateOffsets: i
76
+ updateOffsets: n
71
77
  },
72
- children: p.map((t) => /* @__PURE__ */ s($, { t }, t.id))
78
+ children: f.map((t) => /* @__PURE__ */ r(z, { t }, t.id))
73
79
  }
74
80
  )
75
81
  }
@@ -78,5 +84,5 @@ function j(m) {
78
84
  );
79
85
  }
80
86
  export {
81
- j as default
87
+ D as default
82
88
  };
@@ -1,70 +1,78 @@
1
- import f from "../triggerToasts.js";
2
- let e = null, l = null, u = 0, r = 0, i = !1, o = !1, a = null;
3
- const w = 2, m = 90, v = 20, E = 100;
4
- function b(t) {
5
- const n = Math.sign(t) || 1, s = Math.abs(t), p = v * (1 - Math.exp(-s / E));
6
- return n * p;
1
+ import b from "../triggerToasts.js";
2
+ let s = !1, t = null, c = null, w = 0, r = 0, a = !1, l = null;
3
+ const L = 2, y = 90, S = 20, g = 100;
4
+ function P(e) {
5
+ const o = Math.sign(e) || 1, n = Math.abs(e), h = S * (1 - Math.exp(-n / g));
6
+ return o * h;
7
7
  }
8
- function d(t) {
9
- if (!t) return !1;
10
- const n = t.dataset.swipeable === "true", s = t.dataset.isPromise === "true";
11
- return n && !s;
8
+ function E(e) {
9
+ if (!e) return !1;
10
+ const o = e.dataset.swipeable === "true", n = e.dataset.isPromise === "true";
11
+ return o && !n;
12
12
  }
13
- function c(t = !0) {
14
- if (!e) return;
15
- if (document.body.style.userSelect = "auto", t && a != null)
13
+ function i(e = !0) {
14
+ if (!t) return;
15
+ if (document.body.style.userSelect = "auto", e && l != null)
16
16
  try {
17
- e.releasePointerCapture(a);
17
+ t.releasePointerCapture(l);
18
18
  } catch {
19
19
  console.error("");
20
20
  }
21
- e.style.setProperty("--swipe-x", "0px"), e.classList.remove("is-swiping");
22
- const n = e;
23
- if (e = null, l = null, a = null, i = !1, o = !1, r = 0, !n.matches(":hover")) {
24
- const s = new MouseEvent("mouseleave", {
21
+ t.style.setProperty("--swipe-x", "0px"), t.classList.remove("is-swiping");
22
+ const o = t;
23
+ if (t = null, c = null, l = null, a = !1, s = !1, r = 0, !o.matches(":hover")) {
24
+ const n = new MouseEvent("mouseleave", {
25
25
  bubbles: !0,
26
26
  cancelable: !0,
27
27
  view: window
28
28
  });
29
- n.dispatchEvent(s);
29
+ o.dispatchEvent(n);
30
30
  }
31
31
  }
32
- document.addEventListener("pointerdown", (t) => {
33
- const s = t.target.closest(".kitzo-toast");
34
- s && (e = s, l = s.id, u = t.clientX, r = 0, i = !0, o = !1, a = t.pointerId);
35
- });
36
- document.addEventListener("pointermove", (t) => {
37
- if (!i || !e) return;
38
- if (r = t.clientX - u, !o && Math.abs(r) > w) {
39
- o = !0, e.classList.add("is-swiping");
32
+ function d(e) {
33
+ const n = e.target.closest(".kitzo-toast");
34
+ n && (t = n, c = n.id, w = e.clientX, r = 0, a = !0, s = !1, l = e.pointerId);
35
+ }
36
+ function p(e) {
37
+ if (!a || !t) return;
38
+ if (r = e.clientX - w, !s && Math.abs(r) > L) {
39
+ s = !0, t.classList.add("is-swiping");
40
40
  try {
41
- e.setPointerCapture(t.pointerId), document.body.style.userSelect = "none";
41
+ t.setPointerCapture(e.pointerId), document.body.style.userSelect = "none";
42
42
  } catch {
43
43
  console.error("Failed to capture pointer");
44
44
  }
45
45
  }
46
- if (!o) return;
47
- const s = d(e) ? r : b(r);
48
- e.style.setProperty("--swipe-x", `${s}px`);
49
- });
50
- document.addEventListener("pointerup", () => {
51
- if (!i || !e || l == null) {
52
- c();
46
+ if (!s) return;
47
+ const n = E(t) ? r : P(r);
48
+ t.style.setProperty("--swipe-x", `${n}px`);
49
+ }
50
+ function f() {
51
+ if (!a || !t || c == null) {
52
+ i();
53
53
  return;
54
54
  }
55
- const t = d(e);
56
- if (o && t && Math.abs(r) > m) {
57
- const n = r > 0 ? 1 : -1, s = Math.abs(r) + 300;
58
- e.style.setProperty("--exit-x", `${n * s}px`), e.dataset.exit = "swipe", f.dismiss(l);
55
+ const e = E(t);
56
+ if (s && e && Math.abs(r) > y) {
57
+ const o = r > 0 ? 1 : -1, n = Math.abs(r) + 220;
58
+ t.style.setProperty("--exit-x", `${o * n}px`), t.dataset.exit = "swipe", b.dismiss(c);
59
59
  }
60
- c();
61
- });
62
- document.addEventListener("pointercancel", () => {
63
- c();
64
- });
65
- window.addEventListener("blur", () => {
66
- i && c();
67
- });
60
+ i();
61
+ }
62
+ function v() {
63
+ i();
64
+ }
65
+ function m() {
66
+ a && i();
67
+ }
68
+ let u = !1;
69
+ function M() {
70
+ return u ? () => {
71
+ } : (u = !0, document.addEventListener("pointerdown", d), document.addEventListener("pointermove", p), document.addEventListener("pointerup", f), document.addEventListener("pointercancel", v), window.addEventListener("blur", m), () => {
72
+ i(), u = !1, document.removeEventListener("pointerdown", d), document.removeEventListener("pointermove", p), document.removeEventListener("pointerup", f), document.removeEventListener("pointercancel", v), window.removeEventListener("blur", m);
73
+ });
74
+ }
68
75
  export {
69
- o as dragStarted
76
+ s as dragStarted,
77
+ M as initSwipeToClose
70
78
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kitzo",
3
- "version": "2.3.36",
3
+ "version": "2.3.37",
4
4
  "description": "A lightweight React micro-utility.",
5
5
  "type": "module",
6
6
  "files": [