kitzo 2.3.25 → 2.3.27

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
@@ -27,7 +27,7 @@ declare type PromiseToastMsgs<T, E = unknown> = {
27
27
  error: ReactNode | ((err: E) => ReactNode | Promise<ReactNode>);
28
28
  };
29
29
 
30
- declare type PromiseToastOptions = Omit<ToastOptions, 'id' | 'type'>;
30
+ declare type PromiseToastOptions = Omit<ToastOptions, 'id' | 'type' | 'swipeToClose'>;
31
31
 
32
32
  export declare const toast: ToastFn;
33
33
 
@@ -43,6 +43,7 @@ declare type ToasterProps = {
43
43
  edgeOffset?: number | `${number}`;
44
44
  isDark?: boolean;
45
45
  pauseOnHover?: boolean;
46
+ swipeToClose?: boolean;
46
47
  };
47
48
 
48
49
  declare type ToastFn = {
@@ -66,6 +67,7 @@ declare type ToastOptions = {
66
67
  animateTransformOrigin?: boolean;
67
68
  id?: string | number;
68
69
  type?: ToastType;
70
+ swipeToClose?: boolean;
69
71
  };
70
72
 
71
73
  declare type ToastOptionsWithoutType = Omit<ToastOptions, 'type'>;
package/dist/kitzo.css ADDED
@@ -0,0 +1 @@
1
+ .kitzo-toaster{--default-bg: hsl(0, 0%, 100%);--default-text: hsl(0, 0%, 10%);--default-border: hsl(0, 0%, 94%);--success-bg: var(--default-bg);--success-text: var(--default-text);--success-border: var(--default-border);--warning-bg: var(--default-bg);--warning-text: var(--default-text);--warning-border: var(--default-border);--error-bg: var(--default-bg);--error-text: var(--default-text);--error-border: var(--default-border);--info-bg: var(--default-bg);--info-text: var(--default-text);--info-border: var(--default-border);--loader-stroke: hsl(0, 0%, 20%);--loader-bg: hsl(0, 0%, 80%)}.kitzo-toaster.kitzo-toaster-dark{--default-bg: hsl(0, 0%, 15%);--default-text: hsl(0, 0%, 95%);--default-border: hsl(0, 0%, 17%);--success-bg: var(--default-bg);--success-text: var(--default-text);--success-border: var(--default-border);--warning-bg: var(--default-bg);--warning-text: var(--default-text);--warning-border: var(--default-border);--error-bg: var(--default-bg);--error-text: var(--default-text);--error-border: var(--default-border);--info-bg: var(--default-bg);--info-text: var(--default-text);--info-border: var(--default-border);--loader-stroke: hsl(0, 0%, 90%);--loader-bg: hsl(0, 0%, 40%)}.kitzo-toaster.kitzo-toaster-rich-colors{--success-bg: hsl(142, 65%, 95%);--success-text: hsl(142, 98%, 30%);--success-border: hsl(142, 100%, 93%);--warning-bg: hsl(35, 68%, 95%);--warning-text: hsl(35, 98%, 40%);--warning-border: hsl(35, 100%, 94%);--error-bg: hsl(0, 65%, 95%);--error-text: hsl(0, 98%, 40%);--error-border: hsl(0, 100%, 94%);--info-bg: hsl(210, 65%, 95%);--info-text: hsl(210, 100%, 20%);--info-border: hsl(210, 100%, 94%)}.kitzo-toaster.kitzo-toaster-rich-colors.kitzo-toaster-dark{--success-bg: hsl(142, 65%, 15%);--success-text: hsl(142, 98%, 70%);--success-border: hsl(142, 100%, 15%);--warning-bg: hsl(35, 65%, 15%);--warning-text: hsl(35, 98%, 70%);--warning-border: hsl(35, 100%, 15%);--error-bg: hsl(0, 65%, 15%);--error-text: hsl(0, 98%, 70%);--error-border: hsl(0, 100%, 15%);--info-bg: hsl(210, 65%, 15%);--info-text: hsl(210, 100%, 70%);--info-border: hsl(210, 100%, 16%)}.kitzo-toast{font-family:inherit;font-size:.875rem;transition:transform .28s,opacity .28s;will-change:transform,opacity;touch-action:pan-y}.kitzo-toast.is-swiping{transition:none!important;-webkit-user-select:none;user-select:none}.kitzo-toast.transform-origin-top-left{transform-origin:top left}.kitzo-toast.transform-origin-top-center{transform-origin:top center}.kitzo-toast.transform-origin-top-right{transform-origin:top right}.kitzo-toast.transform-origin-bottom-left{transform-origin:bottom left}.kitzo-toast.transform-origin-bottom-center{transform-origin:bottom center}.kitzo-toast.transform-origin-bottom-right{transform-origin:bottom right}.kitzo-toast[data-type=default],.kitzo-toast[data-type=loading]{background-color:var(--default-bg);color:var(--default-text);border:1px solid var(--default-border)}.kitzo-toast[data-type=success]{background-color:var(--success-bg);color:var(--success-text);border:1px solid var(--success-border)}.kitzo-toast[data-type=warning]{background-color:var(--warning-bg);color:var(--warning-text);border:1px solid var(--warning-border)}.kitzo-toast[data-type=error]{background-color:var(--error-bg);color:var(--error-text);border:1px solid var(--error-border)}.kitzo-toast[data-type=info]{background-color:var(--info-bg);color:var(--info-text);border:1px solid var(--info-border)}.kitzo-toast[data-type=default],.kitzo-toast[data-type=loading],.kitzo-toast[data-type=success],.kitzo-toast[data-type=warning],.kitzo-toast[data-type=error],.kitzo-toast[data-type=info]{border-radius:.425rem;padding:.375rem .625rem;box-shadow:0 3px 8px -3px #00000026}.kitzo-toast{--swipe-x: 0px;--motion-y: 0%;--scale: .6;--exit-x: 0px}.kitzo-toast[data-screen-y=top]{--motion-y: -120%;transform-origin:top}.kitzo-toast[data-screen-y=bottom]{--motion-y: 120%;transform-origin:bottom}.kitzo-toast[data-status=leaving][data-exit=swipe]{--motion-y: 0%;--scale: 1}.kitzo-toast[data-status=entering]{opacity:0;transform:translate(0) translateY(var(--motion-y)) scale(var(--scale))}.kitzo-toast[data-status=visible]{opacity:1;transform:translate(var(--swipe-x)) translateY(0) scale(1)}.kitzo-toast[data-status=leaving]{opacity:0;transform:translate(calc(var(--swipe-x) + var(--exit-x))) translateY(var(--motion-y)) scale(var(--scale))}.kitzo-toast[data-action=update]{animation:update .15s ease}@keyframes update{0%{transform:scale(.95);opacity:.5}to{opacity:1;transform:scale(1)}}.svg-container{display:grid;place-items:center;height:20px;width:20px;overflow:hidden}.loading-svg-container{width:20px;height:20px;display:grid;place-items:center}.loading-svg-container .loader{width:14px;height:14px;background-image:conic-gradient(var(--loader-stroke) 0 25%,var(--loader-bg) 0 100%);border-radius:10rem;position:relative;animation:rotate-infinity 1s linear infinite}.loading-svg-container .loader:before{content:"";position:absolute;inset:2px;border-radius:inherit;background-color:var(--default-bg)}@keyframes rotate-infinity{to{rotate:360deg}}
@@ -1,10 +1,11 @@
1
1
  import { jsx as s } from "react/jsx-runtime";
2
- import { useState as k, useEffect as v, useRef as x, useCallback as T, useLayoutEffect as E } from "react";
2
+ /* empty css */
3
+ import { useState as v, useEffect as x, useRef as T, useCallback as C, useLayoutEffect as E } from "react";
3
4
  import { subscribe as O } from "./helpers/listenar.js";
4
5
  import z from "./helpers/manageToasts/manageToasts.js";
5
- import C from "./partials/ToastContainer.js";
6
- import { ToasterContext as $ } from "./context/ToasterContext.js";
7
- function S(m) {
6
+ import $ from "./partials/ToastContainer.js";
7
+ import { ToasterContext as w } from "./context/ToasterContext.js";
8
+ function q(m) {
8
9
  const {
9
10
  position: d = "top-center",
10
11
  richColors: c = !1,
@@ -12,10 +13,11 @@ function S(m) {
12
13
  gap: e = 8,
13
14
  edgeOffset: r = 16,
14
15
  isDark: f = window.matchMedia("(prefers-color-scheme: dark)").matches,
15
- pauseOnHover: g = !0
16
- } = m, [p, l] = k([]);
17
- v(() => O((o) => z({ toast: o, setToasts: l })), []);
18
- const a = x(null), i = T(() => {
16
+ pauseOnHover: g = !0,
17
+ swipeToClose: y = !0
18
+ } = m, [p, l] = v([]);
19
+ x(() => O((o) => z({ toast: o, setToasts: l })), []);
20
+ const a = T(null), i = C(() => {
19
21
  if (!a.current) return;
20
22
  const t = a.current.querySelectorAll("[data-toast-container]"), o = {
21
23
  "top-left": 0,
@@ -26,10 +28,10 @@ function S(m) {
26
28
  "bottom-right": 0
27
29
  };
28
30
  t.forEach((n) => {
29
- const u = n.getAttribute("data-toast-position") || "top-center", y = parseFloat(n.style.getPropertyValue("--toast-height")) || 0;
31
+ const u = n.getAttribute("data-toast-position") || "top-center", b = parseFloat(n.style.getPropertyValue("--toast-height")) || 0;
30
32
  n.style.setProperty("--toast-offset-y", `${o[u]}px`);
31
- const b = isNaN(+e) ? 8 : +e;
32
- o[u] += y + b;
33
+ const k = isNaN(+e) ? 8 : +e;
34
+ o[u] += b + k;
33
35
  });
34
36
  }, [e]);
35
37
  return E(() => {
@@ -54,7 +56,7 @@ function S(m) {
54
56
  position: "relative"
55
57
  },
56
58
  children: /* @__PURE__ */ s(
57
- $.Provider,
59
+ w.Provider,
58
60
  {
59
61
  value: {
60
62
  position: d,
@@ -64,10 +66,11 @@ function S(m) {
64
66
  edgeOffset: r,
65
67
  animateTransformOrigin: h,
66
68
  pauseOnHover: g,
69
+ swipeToClose: y,
67
70
  setToasts: l,
68
71
  updateOffsets: i
69
72
  },
70
- children: p.map((t) => /* @__PURE__ */ s(C, { t }, t.id))
73
+ children: p.map((t) => /* @__PURE__ */ s($, { t }, t.id))
71
74
  }
72
75
  )
73
76
  }
@@ -76,5 +79,5 @@ function S(m) {
76
79
  );
77
80
  }
78
81
  export {
79
- S as default
82
+ q as default
80
83
  };
@@ -91,6 +91,12 @@ const r = `.kitzo-toaster {
91
91
  transform 280ms,
92
92
  opacity 280ms;
93
93
  will-change: transform, opacity;
94
+ touch-action: pan-y;
95
+ }
96
+
97
+ .kitzo-toast.is-swiping {
98
+ transition: none !important;
99
+ user-select: none;
94
100
  }
95
101
 
96
102
  /*! toast transfor origin */
@@ -114,86 +120,92 @@ const r = `.kitzo-toaster {
114
120
  }
115
121
 
116
122
  /*! Toast theme styles */
117
- .kitzo-toast.type-default {
123
+ .kitzo-toast[data-type='default'] {
118
124
  background-color: var(--default-bg);
119
125
  color: var(--default-text);
120
126
  border: 1px solid var(--default-border);
121
127
  }
122
- .kitzo-toast.type-loading {
128
+ .kitzo-toast[data-type='loading'] {
123
129
  background-color: var(--default-bg);
124
130
  color: var(--default-text);
125
131
  border: 1px solid var(--default-border);
126
132
  }
127
133
 
128
- .kitzo-toast.type-success {
134
+ .kitzo-toast[data-type='success'] {
129
135
  background-color: var(--success-bg);
130
136
  color: var(--success-text);
131
137
  border: 1px solid var(--success-border);
132
138
  }
133
139
 
134
- .kitzo-toast.type-warning {
140
+ .kitzo-toast[data-type='warning'] {
135
141
  background-color: var(--warning-bg);
136
142
  color: var(--warning-text);
137
143
  border: 1px solid var(--warning-border);
138
144
  }
139
145
 
140
- .kitzo-toast.type-error {
146
+ .kitzo-toast[data-type='error'] {
141
147
  background-color: var(--error-bg);
142
148
  color: var(--error-text);
143
149
  border: 1px solid var(--error-border);
144
150
  }
145
151
 
146
- .kitzo-toast.type-info {
152
+ .kitzo-toast[data-type='info'] {
147
153
  background-color: var(--info-bg);
148
154
  color: var(--info-text);
149
155
  border: 1px solid var(--info-border);
150
156
  }
151
157
 
152
- .kitzo-toast.type-default,
153
- .kitzo-toast.type-loading,
154
- .kitzo-toast.type-success,
155
- .kitzo-toast.type-warning,
156
- .kitzo-toast.type-error,
157
- .kitzo-toast.type-info {
158
+ .kitzo-toast[data-type='default'],
159
+ .kitzo-toast[data-type='loading'],
160
+ .kitzo-toast[data-type='success'],
161
+ .kitzo-toast[data-type='warning'],
162
+ .kitzo-toast[data-type='error'],
163
+ .kitzo-toast[data-type='info'] {
158
164
  border-radius: 0.425rem;
159
165
  padding: 0.375rem 0.625rem;
160
166
  box-shadow: 0 3px 8px -3px hsl(0, 0%, 0%, 0.15);
161
167
  }
162
168
 
163
169
  /*! toast transition styles */
164
- .kitzo-toast.status-entering.pos-y-top {
165
- opacity: 0;
166
- transform: translateY(-120%) scale(0.6);
170
+ .kitzo-toast {
171
+ --swipe-x: 0px;
172
+ --motion-y: 0%;
173
+ --scale: 0.6;
174
+ --exit-x: 0px;
167
175
  }
168
176
 
169
- .kitzo-toast.status-visible.pos-y-top {
170
- opacity: 1;
171
- transform: translateY(0) scale(1);
177
+ .kitzo-toast[data-screen-y='top'] {
178
+ --motion-y: -120%;
179
+ transform-origin: top;
172
180
  }
173
181
 
174
- .kitzo-toast.status-leaving.pos-y-top {
175
- transform-origin: top;
176
- opacity: 0;
177
- transform: translateY(-120%) scale(0.6);
182
+ .kitzo-toast[data-screen-y='bottom'] {
183
+ --motion-y: 120%;
184
+ transform-origin: bottom;
178
185
  }
179
186
 
180
- .kitzo-toast.status-entering.pos-y-bottom {
187
+ .kitzo-toast[data-status='leaving'][data-exit='swipe'] {
188
+ --motion-y: 0%;
189
+ --scale: 1;
190
+ }
191
+
192
+ .kitzo-toast[data-status='entering'] {
181
193
  opacity: 0;
182
- transform: translateY(120%) scale(0.6);
194
+ transform: translateX(0) translateY(var(--motion-y)) scale(var(--scale));
183
195
  }
184
196
 
185
- .kitzo-toast.status-visible.pos-y-bottom {
197
+ .kitzo-toast[data-status='visible'] {
186
198
  opacity: 1;
187
- transform: translateY(0) scale(1);
199
+ transform: translateX(var(--swipe-x)) translateY(0) scale(1);
188
200
  }
189
201
 
190
- .kitzo-toast.status-leaving.pos-y-bottom {
191
- transform-origin: bottom;
202
+ .kitzo-toast[data-status='leaving'] {
192
203
  opacity: 0;
193
- transform: translateY(120%) scale(0.6);
204
+ transform: translateX(calc(var(--swipe-x) + var(--exit-x)))
205
+ translateY(var(--motion-y)) scale(var(--scale));
194
206
  }
195
207
 
196
- .action-update {
208
+ .kitzo-toast[data-action='update'] {
197
209
  animation: update 150ms ease;
198
210
  }
199
211
 
@@ -1,44 +1,49 @@
1
- const i = {
1
+ const n = {
2
2
  duration: 2800,
3
3
  showIcon: !0,
4
- animateTransformOrigin: void 0
4
+ animateTransformOrigin: void 0,
5
+ swipeToClose: !0
5
6
  };
6
7
  let r = 0;
7
- const d = () => crypto.randomUUID?.() ?? `kitzo_toast_id_${++r}`;
8
- let s = 1;
9
- function c({
10
- type: a,
11
- action: e,
12
- content: o,
13
- options: n
8
+ const d = () => crypto.randomUUID?.() ?? ++r;
9
+ let u = 1;
10
+ function T({
11
+ type: e,
12
+ action: s,
13
+ content: t,
14
+ isPromise: i,
15
+ options: a
14
16
  }) {
15
- const t = typeof n == "object" && n !== null ? n : {};
17
+ const o = typeof a == "object" && a !== null ? a : {};
16
18
  return {
17
- id: t.id ?? d(),
18
- duration: t.duration ?? i.duration,
19
- showIcon: t.showIcon ?? i.showIcon,
20
- animateTransformOrigin: t.animateTransformOrigin ?? i.animateTransformOrigin,
21
- position: t.position,
22
- icon: t.icon,
23
- type: a === "default" ? t.type ?? "default" : a,
19
+ id: `toast-id:${o.id ?? d()}`,
20
+ duration: o.duration ?? n.duration,
21
+ showIcon: o.showIcon ?? n.showIcon,
22
+ animateTransformOrigin: o.animateTransformOrigin ?? n.animateTransformOrigin,
23
+ position: o.position,
24
+ icon: o.icon,
25
+ type: e === "default" ? o.type ?? "default" : e,
24
26
  status: "entering",
25
- zIndex: ++s,
26
- content: o,
27
- action: e
27
+ zIndex: ++u,
28
+ content: t,
29
+ action: s,
30
+ isPromise: !!i,
31
+ swipeToClose: o.swipeToClose ?? n.swipeToClose
28
32
  };
29
33
  }
30
- function T({ id: a, content: e, options: o }) {
31
- const n = typeof o == "object" && o !== null ? o : {};
34
+ function l({ id: e, content: s, options: t }) {
35
+ const i = typeof t == "object" && t !== null ? t : {};
32
36
  return {
33
- ...n,
34
- id: a,
35
- content: e,
37
+ ...i,
38
+ id: `toast-id:${e}`,
39
+ content: s,
36
40
  action: "update",
37
- duration: n.duration ?? i.duration
41
+ isPromise: !1,
42
+ duration: i.duration ?? n.duration
38
43
  };
39
44
  }
40
45
  export {
41
- c as createToast,
46
+ T as createToast,
42
47
  d as genId,
43
- T as updateToast
48
+ l as updateToast
44
49
  };
@@ -1,12 +1,11 @@
1
- import { addTimers as f } from "./timers.js";
2
- function m({ toast: r, setToasts: e }) {
3
- let n = !1;
4
- e((i) => (n = !!i.find((d) => d.id === r.id), n ? i : [r, ...i])), !n && (requestAnimationFrame(() => {
5
- e(
6
- (i) => i.map((d) => d.id === r.id ? { ...d, status: "visible" } : d)
1
+ import { addTimers as s } from "./timers.js";
2
+ function e({ toast: d, setToasts: r }) {
3
+ r((i) => i.find((m) => m.id === d.id) ? i : [d, ...i]), requestAnimationFrame(() => {
4
+ r(
5
+ (i) => i.map((n) => n.id === d.id ? { ...n, status: "visible" } : n)
7
6
  );
8
- }), f(r, e));
7
+ }), s(d, r);
9
8
  }
10
9
  export {
11
- m as default
10
+ e as default
12
11
  };
@@ -0,0 +1,68 @@
1
+ import f from "../triggerToasts.js";
2
+ let e = null, l = null, d = 0, r = 0, o = !1, i = !1, a = null;
3
+ const w = 0, m = 90, v = 90, E = 120;
4
+ function b(t) {
5
+ const s = Math.sign(t) || 1, n = Math.abs(t), p = v * (1 - Math.exp(-n / E));
6
+ return s * p;
7
+ }
8
+ function u(t) {
9
+ if (!t) return !1;
10
+ const s = t.dataset.swipeable === "true", n = t.dataset.isPromise === "true";
11
+ return s && !n;
12
+ }
13
+ function c(t = !0) {
14
+ if (!e) return;
15
+ if (document.body.style.userSelect = "auto", t && a != null)
16
+ try {
17
+ e.releasePointerCapture(a);
18
+ } catch {
19
+ console.error("");
20
+ }
21
+ e.style.setProperty("--swipe-x", "0px"), e.classList.remove("is-swiping");
22
+ const s = e;
23
+ if (e = null, l = null, a = null, o = !1, i = !1, r = 0, !s.matches(":hover")) {
24
+ const n = new MouseEvent("mouseleave", {
25
+ bubbles: !0,
26
+ cancelable: !0,
27
+ view: window
28
+ });
29
+ s.dispatchEvent(n);
30
+ }
31
+ }
32
+ document.addEventListener("pointerdown", (t) => {
33
+ const n = t.target.closest(".kitzo-toast");
34
+ if (n) {
35
+ document.body.style.userSelect = "none", e = n, l = n.id, d = t.clientX, r = 0, o = !0, i = !1, a = t.pointerId;
36
+ try {
37
+ n.setPointerCapture(t.pointerId);
38
+ } catch {
39
+ console.error("");
40
+ }
41
+ }
42
+ });
43
+ document.addEventListener("pointermove", (t) => {
44
+ if (!o || !e || (r = t.clientX - d, !i && Math.abs(r) > w && (i = !0, e.classList.add("is-swiping")), !i)) return;
45
+ const n = u(e) ? r : b(r);
46
+ e.style.setProperty("--swipe-x", `${n}px`);
47
+ });
48
+ document.addEventListener("pointerup", () => {
49
+ if (!o || !e || l == null) {
50
+ c();
51
+ return;
52
+ }
53
+ const t = u(e);
54
+ if (i && t && Math.abs(r) > m) {
55
+ const s = r > 0 ? 1 : -1, n = window.innerWidth / 2 + 50;
56
+ e.style.setProperty("--exit-x", `${s * n}px`), e.dataset.exit = "swipe", f.dismiss(l);
57
+ }
58
+ c();
59
+ });
60
+ document.addEventListener("pointercancel", () => {
61
+ c();
62
+ });
63
+ window.addEventListener("blur", () => {
64
+ o && c();
65
+ });
66
+ export {
67
+ i as dragStarted
68
+ };
@@ -1,76 +1,79 @@
1
- const o = /* @__PURE__ */ new Map(), u = 280, s = 500, f = 0;
2
- function c(e) {
3
- const i = Number(e);
4
- if (!isFinite(i)) return null;
5
- const t = Math.max(f, i);
1
+ import { dragStarted as c } from "./swipeClose.js";
2
+ const r = /* @__PURE__ */ new Map(), m = 280, f = 500, d = 0;
3
+ function T(e) {
4
+ const t = Number(e);
5
+ if (!isFinite(t)) return null;
6
+ const i = Math.max(d, t);
6
7
  return {
7
- totalTime: t,
8
- leavingDuration: t,
9
- leftDuration: t + s
8
+ totalTime: i,
9
+ leavingDuration: i,
10
+ leftDuration: i + f
10
11
  };
11
12
  }
12
- function T(e) {
13
- const i = o.get(e);
14
- i && (clearTimeout(i.leavingTimeoutId), clearTimeout(i.leftTimeoutId), o.delete(e));
13
+ function s(e) {
14
+ const t = r.get(e);
15
+ t && (clearTimeout(t.leavingTimeoutId), clearTimeout(t.leftTimeoutId), r.delete(e));
15
16
  }
16
- function g() {
17
- o.forEach(({ leavingTimeoutId: e, leftTimeoutId: i }) => {
18
- clearTimeout(e), clearTimeout(i);
19
- }), o.clear();
17
+ function I() {
18
+ r.forEach(({ leavingTimeoutId: e, leftTimeoutId: t }) => {
19
+ clearTimeout(e), clearTimeout(t);
20
+ }), r.clear();
20
21
  }
21
- function d(e, i) {
22
- const t = c(e.duration);
23
- if (!t) return;
24
- T(e.id);
25
- const r = setTimeout(() => {
26
- i(
22
+ function p(e, t) {
23
+ const i = T(e.duration);
24
+ if (!i) return;
25
+ s(e.id);
26
+ const o = setTimeout(() => {
27
+ t(
27
28
  (a) => a.map((n) => n.id === e.id ? { ...n, status: "leaving" } : n)
28
29
  );
29
- }, t.leavingDuration + u), m = setTimeout(() => {
30
- i((a) => a.filter((n) => n.id !== e.id)), T(e.id), o.delete(e.id);
31
- }, t.leftDuration + u), l = Date.now();
32
- o.set(e.id, {
33
- leavingTimeoutId: r,
34
- leftTimeoutId: m,
30
+ }, i.leavingDuration + m), u = setTimeout(() => {
31
+ t((a) => a.filter((n) => n.id !== e.id)), s(e.id), r.delete(e.id);
32
+ }, i.leftDuration + m), l = Date.now();
33
+ r.set(e.id, {
34
+ leavingTimeoutId: o,
35
+ leftTimeoutId: u,
35
36
  startingTime: l,
36
- totalTime: t.totalTime,
37
- remainningTime: 0
37
+ totalTime: i.totalTime,
38
+ remainningTime: 0,
39
+ paused: !1
38
40
  });
39
41
  }
40
- function I(e) {
41
- const i = o.get(e);
42
- if (!i || i.remainningTime > 0) return;
43
- const r = Date.now() - i.startingTime, m = Math.max(i.totalTime - r, 0);
44
- m !== 0 && (o.set(e, { ...i, remainningTime: m }), clearTimeout(i.leavingTimeoutId), clearTimeout(i.leftTimeoutId));
42
+ function D(e) {
43
+ const t = r.get(e);
44
+ if (!t || t.paused) return;
45
+ const o = Date.now() - t.startingTime, u = Math.max(t.totalTime - o, 0);
46
+ u !== 0 && (r.set(e, { ...t, remainningTime: u, paused: !0 }), clearTimeout(t.leavingTimeoutId), clearTimeout(t.leftTimeoutId));
45
47
  }
46
- function D(e, i) {
47
- const t = o.get(e);
48
- if (!t) return;
49
- const r = c(t.remainningTime);
50
- if (!r) return;
51
- const m = setTimeout(() => {
52
- i(
48
+ function v(e, t) {
49
+ if (c) return;
50
+ const i = r.get(e);
51
+ if (!i || !i.paused) return;
52
+ const o = T(i.remainningTime);
53
+ if (!o) return;
54
+ const u = setTimeout(() => {
55
+ t(
53
56
  (a) => a.map((n) => n.id === e ? { ...n, status: "leaving" } : n)
54
57
  );
55
- }, r.leavingDuration + u), l = setTimeout(() => {
56
- i((a) => a.filter((n) => n.id !== e)), T(e), o.delete(e);
57
- }, r.leftDuration + u);
58
- o.set(e, {
59
- ...t,
58
+ }, o.leavingDuration + m), l = setTimeout(() => {
59
+ t((a) => a.filter((n) => n.id !== e)), s(e), r.delete(e);
60
+ }, o.leftDuration + m);
61
+ r.set(e, {
60
62
  startingTime: Date.now(),
61
- totalTime: t.remainningTime,
63
+ totalTime: i.remainningTime,
62
64
  remainningTime: 0,
63
- leavingTimeoutId: m,
64
- leftTimeoutId: l
65
+ leavingTimeoutId: u,
66
+ leftTimeoutId: l,
67
+ paused: !1
65
68
  });
66
69
  }
67
70
  export {
68
- s as LEAVE_DELAY,
69
- f as MIN_VISIBLE,
70
- u as TRANSITION_DURATION,
71
- d as addTimers,
72
- g as clearAllTimers,
73
- T as clearTimer,
74
- I as pauseToast,
75
- D as resumeToast
71
+ f as LEAVE_DELAY,
72
+ d as MIN_VISIBLE,
73
+ m as TRANSITION_DURATION,
74
+ p as addTimers,
75
+ I as clearAllTimers,
76
+ s as clearTimer,
77
+ D as pauseToast,
78
+ v as resumeToast
76
79
  };
@@ -1,10 +1,9 @@
1
- import { addTimers as u } from "./timers.js";
2
- function t({ toast: e, setToasts: d }) {
3
- let r = !0;
4
- d((s) => s.find((i) => i.id === e.id) ? s.map(
5
- (i) => i.id === e.id ? { ...i, ...e, status: "visible" } : i
6
- ) : (r = !1, s)), r && u(e, d);
1
+ import { clearTimer as n, addTimers as u } from "./timers.js";
2
+ function s({ toast: i, setToasts: r }) {
3
+ r((e) => e.find((d) => d.id === i.id) ? (n(i.id), u(i, r), e.map(
4
+ (d) => d.id === i.id ? { ...d, ...i, status: "visible" } : d
5
+ )) : e);
7
6
  }
8
7
  export {
9
- t as default
8
+ s as default
10
9
  };
@@ -1,8 +1,8 @@
1
- import { createToast as n, updateToast as c, genId as s } from "./createToast.js";
2
- import { notify as a } from "./listenar.js";
1
+ import { createToast as a, updateToast as s, genId as c } from "./createToast.js";
2
+ import { notify as e } from "./listenar.js";
3
3
  const i = (r, t) => {
4
- r != null && a(
5
- n({
4
+ r != null && e(
5
+ a({
6
6
  type: "default",
7
7
  action: "add",
8
8
  content: r,
@@ -11,11 +11,11 @@ const i = (r, t) => {
11
11
  );
12
12
  };
13
13
  i.dismiss = (r) => {
14
- a({ action: "dismiss", id: r });
14
+ e({ action: "dismiss", id: `${r}` });
15
15
  };
16
16
  i.info = (r, t) => {
17
- r != null && a(
18
- n({
17
+ r != null && e(
18
+ a({
19
19
  action: "add",
20
20
  type: "info",
21
21
  content: r,
@@ -24,8 +24,8 @@ i.info = (r, t) => {
24
24
  );
25
25
  };
26
26
  i.success = (r, t) => {
27
- r != null && a(
28
- n({
27
+ r != null && e(
28
+ a({
29
29
  action: "add",
30
30
  type: "success",
31
31
  content: r,
@@ -34,8 +34,8 @@ i.success = (r, t) => {
34
34
  );
35
35
  };
36
36
  i.warning = (r, t) => {
37
- r != null && a(
38
- n({
37
+ r != null && e(
38
+ a({
39
39
  action: "add",
40
40
  type: "warning",
41
41
  content: r,
@@ -44,8 +44,8 @@ i.warning = (r, t) => {
44
44
  );
45
45
  };
46
46
  i.error = (r, t) => {
47
- r != null && a(
48
- n({
47
+ r != null && e(
48
+ a({
49
49
  action: "add",
50
50
  type: "error",
51
51
  content: r,
@@ -54,8 +54,8 @@ i.error = (r, t) => {
54
54
  );
55
55
  };
56
56
  i.loading = (r, t) => {
57
- r != null && a(
58
- n({
57
+ r != null && e(
58
+ a({
59
59
  action: "add",
60
60
  type: "loading",
61
61
  content: r,
@@ -64,8 +64,8 @@ i.loading = (r, t) => {
64
64
  );
65
65
  };
66
66
  i.custom = (r, t) => {
67
- r != null && a(
68
- n({
67
+ r != null && e(
68
+ a({
69
69
  action: "add",
70
70
  type: "custom",
71
71
  content: r,
@@ -73,25 +73,26 @@ i.custom = (r, t) => {
73
73
  })
74
74
  );
75
75
  };
76
- i.update = (r, t, e) => {
77
- t != null && a(c({ id: r, content: t, options: e }));
76
+ i.update = (r, t, n) => {
77
+ t != null && e(s({ id: `${r}`, content: t, options: n }));
78
78
  };
79
- i.promise = (async (r, t, e) => {
80
- const u = s();
81
- a(
82
- n({
79
+ i.promise = (async (r, t, n) => {
80
+ const u = c();
81
+ e(
82
+ a({
83
83
  action: "add",
84
84
  type: "loading",
85
85
  content: t.loading,
86
- options: { ...e, id: u, duration: 1 / 0 }
86
+ isPromise: !0,
87
+ options: { ...n, id: u, duration: 1 / 0 }
87
88
  })
88
89
  );
89
90
  try {
90
91
  const o = await r, d = typeof t.success == "function" ? await t.success(o) : t.success;
91
- return i.update(u, d, { ...e, type: "success" }), o;
92
+ return i.update(u, d, { ...n, type: "success" }), o;
92
93
  } catch (o) {
93
94
  const d = typeof t.error == "function" ? await t.error(o) : t.error;
94
- throw i.update(u, d, { ...e, type: "error" }), o;
95
+ throw i.update(u, d, { ...n, type: "error" }), o;
95
96
  }
96
97
  });
97
98
  export {
@@ -1,53 +1,65 @@
1
- import { jsxs as g, jsx as t, Fragment as s } from "react/jsx-runtime";
2
- import { resumeToast as v, pauseToast as h } from "../helpers/manageToasts/timers.js";
3
- import y from "../helpers/triggerToasts.js";
4
- import { InfoSvg as x, ErrorSvg as S, WarningSvg as $, SuccessSvg as T, LoadingSvg as k } from "./Svgs.js";
5
- import { useToasterContext as E } from "../context/ToasterContext.js";
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";
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";
5
+ import { useToasterContext as L } from "../context/ToasterContext.js";
6
6
  function C({
7
- t: n,
7
+ t: p,
8
8
  position: o,
9
- shouldAnimateTransformOrigin: d
9
+ shouldAnimateTransformOrigin: u,
10
+ swipeToClose: f
10
11
  }) {
11
- const { setToasts: m, pauseOnHover: a } = E(), { id: l, type: r, action: f, content: i, status: p, showIcon: u, icon: e } = n, c = {
12
- loading: /* @__PURE__ */ t(k, {}),
13
- success: /* @__PURE__ */ t(T, {}),
14
- warning: /* @__PURE__ */ t($, {}),
15
- error: /* @__PURE__ */ t(S, {}),
16
- info: /* @__PURE__ */ t(x, {}),
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, {}),
17
18
  default: null,
18
19
  custom: null
19
20
  };
20
- return /* @__PURE__ */ g(
21
+ return /* @__PURE__ */ x(
21
22
  "div",
22
23
  {
23
- id: `toast-id-${l}`,
24
+ id: t,
24
25
  style: {
25
26
  pointerEvents: "all",
26
27
  display: "flex",
27
28
  alignItems: "center",
28
- gap: 8
29
+ gap: 8,
30
+ whiteSpace: "pre-wrap"
29
31
  },
30
- onMouseEnter: () => a && h(n.id),
31
- onMouseLeave: () => a && v(n.id, m),
32
- className: `kitzo-toast type-${r} action-${f} status-${p} pos-y-${o.split("-")[0]} pos-x-${o.split("-")[1]} ${d ? `transform-origin-${o}` : ""}`,
32
+ "data-action": g,
33
+ "data-status": v,
34
+ "data-type": r,
35
+ "data-screen-x": o.split("-")[1],
36
+ "data-screen-y": o.split("-")[0],
37
+ "data-exit": "auto",
38
+ "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),
33
45
  children: [
34
- u && /* @__PURE__ */ t(s, { children: e ? /* @__PURE__ */ t(s, { children: typeof e == "string" || typeof e == "number" ? /* @__PURE__ */ t(
46
+ h && /* @__PURE__ */ e(a, { children: n ? /* @__PURE__ */ e(a, { children: typeof n == "string" || typeof n == "number" ? /* @__PURE__ */ e(
35
47
  "div",
36
48
  {
37
49
  style: {
38
50
  flexShrink: 0
39
51
  },
40
52
  className: "svg-container",
41
- children: e
53
+ children: n
42
54
  }
43
- ) : /* @__PURE__ */ t(s, { children: e }) }) : /* @__PURE__ */ t(s, { children: c[r] && /* @__PURE__ */ t("div", { style: { flexShrink: 0 }, className: "svg-container", children: c[r] }) }) }),
44
- /* @__PURE__ */ t(
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(
45
57
  "div",
46
58
  {
47
59
  style: {
48
60
  flex: 1
49
61
  },
50
- children: typeof i == "function" ? i(() => y.dismiss(l)) : i
62
+ children: typeof i == "function" ? i(() => S.dismiss(t)) : i
51
63
  }
52
64
  )
53
65
  ]
@@ -1,19 +1,20 @@
1
- import { jsx as f } from "react/jsx-runtime";
2
- import { useRef as d, useLayoutEffect as b } from "react";
3
- import g from "./Toast.js";
4
- import { useToasterContext as h } from "../context/ToasterContext.js";
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
5
  function v({ t }) {
6
6
  const {
7
7
  updateOffsets: s,
8
- position: c,
9
- animateTransformOrigin: l
10
- } = h(), r = d(null);
11
- b(() => {
12
- const e = r.current;
8
+ position: f,
9
+ animateTransformOrigin: c,
10
+ swipeToClose: p
11
+ } = x(), i = b(null);
12
+ g(() => {
13
+ const e = i.current;
13
14
  if (!e) return;
14
15
  const a = new ResizeObserver(() => {
15
- const p = e.offsetHeight;
16
- e.style.setProperty("--toast-height", `${p}px`), s();
16
+ const T = e.offsetHeight;
17
+ e.style.setProperty("--toast-height", `${T}px`), s();
17
18
  });
18
19
  return a.observe(e), () => a.disconnect();
19
20
  }, [s]);
@@ -24,11 +25,11 @@ function v({ t }) {
24
25
  "bottom-left",
25
26
  "bottom-center",
26
27
  "bottom-right"
27
- ], i = t.position || c, o = m.includes(i) ? i : "top-center", n = o?.includes("bottom"), u = typeof t.animateTransformOrigin == "boolean" ? t.animateTransformOrigin : l;
28
- return /* @__PURE__ */ f(
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
30
  "div",
30
31
  {
31
- ref: r,
32
+ ref: i,
32
33
  "data-toast-container": !0,
33
34
  "data-toast-position": o,
34
35
  style: {
@@ -43,12 +44,13 @@ function v({ t }) {
43
44
  bottom: n ? 0 : "auto",
44
45
  transform: `translateY(calc(var(--toast-offset-y, 0px) * ${n ? -1 : 1}))`
45
46
  },
46
- children: /* @__PURE__ */ f(
47
- g,
47
+ children: /* @__PURE__ */ l(
48
+ h,
48
49
  {
49
50
  t,
50
51
  position: o,
51
- shouldAnimateTransformOrigin: u
52
+ shouldAnimateTransformOrigin: u,
53
+ swipeToClose: d
52
54
  }
53
55
  )
54
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kitzo",
3
- "version": "2.3.25",
3
+ "version": "2.3.27",
4
4
  "description": "A lightweight React micro-utility.",
5
5
  "type": "module",
6
6
  "files": [