kitzo 2.3.35 → 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,4 +1,4 @@
1
- const r = `.kitzo-toaster {
1
+ const o = `.kitzo-toaster {
2
2
  --default-bg: hsl(0, 0%, 100%);
3
3
  --default-text: hsl(0, 0%, 10%);
4
4
  --default-border: hsl(0, 0%, 94%);
@@ -98,26 +98,6 @@ const r = `.kitzo-toaster {
98
98
  transition: none !important;
99
99
  }
100
100
 
101
- /*! toast transfor origin */
102
- .kitzo-toast.transform-origin-top-left {
103
- transform-origin: top left;
104
- }
105
- .kitzo-toast.transform-origin-top-center {
106
- transform-origin: top center;
107
- }
108
- .kitzo-toast.transform-origin-top-right {
109
- transform-origin: top right;
110
- }
111
- .kitzo-toast.transform-origin-bottom-left {
112
- transform-origin: bottom left;
113
- }
114
- .kitzo-toast.transform-origin-bottom-center {
115
- transform-origin: bottom center;
116
- }
117
- .kitzo-toast.transform-origin-bottom-right {
118
- transform-origin: bottom right;
119
- }
120
-
121
101
  /*! Toast theme styles */
122
102
  .kitzo-toast[data-type='default'] {
123
103
  background-color: var(--default-bg);
@@ -175,12 +155,10 @@ const r = `.kitzo-toaster {
175
155
 
176
156
  .kitzo-toast[data-screen-y='top'] {
177
157
  --motion-y: -120%;
178
- transform-origin: top;
179
158
  }
180
159
 
181
160
  .kitzo-toast[data-screen-y='bottom'] {
182
161
  --motion-y: 120%;
183
- transform-origin: bottom;
184
162
  }
185
163
 
186
164
  .kitzo-toast[data-status='leaving'][data-exit='swipe'] {
@@ -219,6 +197,40 @@ const r = `.kitzo-toaster {
219
197
  }
220
198
  }
221
199
 
200
+ /*! toast transfor origin */
201
+ .kitzo-toast[data-position^='top'] {
202
+ transform-origin: top;
203
+ }
204
+ .kitzo-toast[data-position^='bottom'] {
205
+ transform-origin: bottom;
206
+ }
207
+
208
+ .kitzo-toast[data-animate-transform-origin='true'][data-position='top-left'] {
209
+ transform-origin: top left;
210
+ }
211
+ .kitzo-toast[data-animate-transform-origin='true'][data-position='top-center'] {
212
+ transform-origin: top;
213
+ }
214
+ .kitzo-toast[data-animate-transform-origin='true'][data-position='top-right'] {
215
+ transform-origin: top right;
216
+ }
217
+ .kitzo-toast[data-animate-transform-origin='true'][data-position='bottom-left'] {
218
+ transform-origin: bottom left;
219
+ }
220
+ .kitzo-toast[data-animate-transform-origin='true'][data-position='bottom-center'] {
221
+ transform-origin: bottom;
222
+ }
223
+ .kitzo-toast[data-animate-transform-origin='true'][data-position='bottom-right'] {
224
+ transform-origin: bottom right;
225
+ }
226
+
227
+ .kitzo-toast[data-status='leaving'][data-position^='top'] {
228
+ transform-origin: top;
229
+ }
230
+ .kitzo-toast[data-status='leaving'][data-position^='bottom'] {
231
+ transform-origin: bottom;
232
+ }
233
+
222
234
  /*! svg stylings */
223
235
  .svg-container {
224
236
  display: grid;
@@ -259,12 +271,12 @@ const r = `.kitzo-toaster {
259
271
  rotate: 360deg;
260
272
  }
261
273
  }`;
262
- function o() {
274
+ function a() {
263
275
  if (!document.getElementById("kitzo-toast-styles")) {
264
276
  const t = document.createElement("style");
265
- t.id = "kitzo-toast-styles", t.textContent = r, document.head.appendChild(t);
277
+ t.id = "kitzo-toast-styles", t.textContent = o, document.head.appendChild(t);
266
278
  }
267
279
  }
268
280
  export {
269
- o as default
281
+ a as default
270
282
  };
@@ -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
  };
@@ -1,27 +1,27 @@
1
- import { jsxs as x, jsx as e, Fragment as a } from "react/jsx-runtime";
2
- import { resumeToast as d, pauseToast as m } from "../helpers/manageToasts/timers.js";
1
+ import { jsxs as x, jsx as t, Fragment as o } from "react/jsx-runtime";
2
+ import { resumeToast as m, pauseToast as p } from "../helpers/manageToasts/timers.js";
3
3
  import S from "../helpers/triggerToasts.js";
4
- import { InfoSvg as w, ErrorSvg as T, WarningSvg as E, SuccessSvg as k, LoadingSvg as I } from "./Svgs.js";
4
+ import { InfoSvg as w, ErrorSvg as E, WarningSvg as T, SuccessSvg as k, LoadingSvg as I } from "./Svgs.js";
5
5
  import { useToasterContext as L } from "../context/ToasterContext.js";
6
6
  function C({
7
- t: p,
8
- position: o,
9
- shouldAnimateTransformOrigin: u,
10
- swipeToClose: f
7
+ t: f,
8
+ position: n,
9
+ shouldAnimateTransformOrigin: c,
10
+ swipeToClose: u
11
11
  }) {
12
- const { setToasts: c, pauseOnHover: s } = L(), { id: t, type: r, action: g, content: i, status: v, showIcon: h, icon: n, isPromise: y } = p, l = {
13
- loading: /* @__PURE__ */ e(I, {}),
14
- success: /* @__PURE__ */ e(k, {}),
15
- warning: /* @__PURE__ */ e(E, {}),
16
- error: /* @__PURE__ */ e(T, {}),
17
- info: /* @__PURE__ */ e(w, {}),
12
+ const { setToasts: l, pauseOnHover: s } = L(), { id: e, type: r, action: g, content: i, status: v, showIcon: h, icon: a, isPromise: y } = f, d = {
13
+ loading: /* @__PURE__ */ t(I, {}),
14
+ success: /* @__PURE__ */ t(k, {}),
15
+ warning: /* @__PURE__ */ t(T, {}),
16
+ error: /* @__PURE__ */ t(E, {}),
17
+ info: /* @__PURE__ */ t(w, {}),
18
18
  default: null,
19
19
  custom: null
20
20
  };
21
21
  return /* @__PURE__ */ x(
22
22
  "div",
23
23
  {
24
- id: t,
24
+ id: e,
25
25
  style: {
26
26
  pointerEvents: "all",
27
27
  display: "flex",
@@ -32,34 +32,36 @@ function C({
32
32
  "data-action": g,
33
33
  "data-status": v,
34
34
  "data-type": r,
35
- "data-screen-x": o.split("-")[1],
36
- "data-screen-y": o.split("-")[0],
35
+ "data-position": n,
36
+ "data-screen-x": n.split("-")[1],
37
+ "data-screen-y": n.split("-")[0],
37
38
  "data-exit": "auto",
38
39
  "data-is-promise": y,
39
- "data-swipeable": f,
40
- className: `kitzo-toast ${u ? `transform-origin-${o}` : ""}`,
41
- onPointerEnter: () => s && m(t),
42
- onPointerLeave: () => s && d(t, c),
43
- onMouseEnter: () => s && m(t),
44
- onMouseLeave: () => s && d(t, c),
40
+ "data-swipeable": u,
41
+ "data-animate-transform-origin": c,
42
+ className: `kitzo-toast ${c ? `transform-origin-${n}` : ""}`,
43
+ onPointerEnter: () => s && p(e),
44
+ onPointerLeave: () => s && m(e, l),
45
+ onMouseEnter: () => s && p(e),
46
+ onMouseLeave: () => s && m(e, l),
45
47
  children: [
46
- h && /* @__PURE__ */ e(a, { children: n ? /* @__PURE__ */ e(a, { children: typeof n == "string" || typeof n == "number" ? /* @__PURE__ */ e(
48
+ h && /* @__PURE__ */ t(o, { children: a ? /* @__PURE__ */ t(o, { children: typeof a == "string" || typeof a == "number" ? /* @__PURE__ */ t(
47
49
  "div",
48
50
  {
49
51
  style: {
50
52
  flexShrink: 0
51
53
  },
52
54
  className: "svg-container",
53
- children: n
55
+ children: a
54
56
  }
55
- ) : /* @__PURE__ */ e(a, { children: n }) }) : /* @__PURE__ */ e(a, { children: l[r] && /* @__PURE__ */ e("div", { style: { flexShrink: 0 }, className: "svg-container", children: l[r] }) }) }),
56
- /* @__PURE__ */ e(
57
+ ) : /* @__PURE__ */ t(o, { children: a }) }) : /* @__PURE__ */ t(o, { children: d[r] && /* @__PURE__ */ t("div", { style: { flexShrink: 0 }, className: "svg-container", children: d[r] }) }) }),
58
+ /* @__PURE__ */ t(
57
59
  "div",
58
60
  {
59
61
  style: {
60
62
  flex: 1
61
63
  },
62
- children: typeof i == "function" ? i(() => S.dismiss(t)) : i
64
+ children: typeof i == "function" ? i(() => S.dismiss(e)) : i
63
65
  }
64
66
  )
65
67
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kitzo",
3
- "version": "2.3.35",
3
+ "version": "2.3.37",
4
4
  "description": "A lightweight React micro-utility.",
5
5
  "type": "module",
6
6
  "files": [