@alfadocs/ui-kit 0.57.0 → 0.58.0

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,6 +1,6 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "packageVersion": "0.57.0",
3
+ "packageVersion": "0.58.0",
4
4
  "components": [
5
5
  {
6
6
  "kind": "component",
@@ -19,4 +19,5 @@ export { useIsomorphicLayoutEffect } from './use-isomorphic-layout-effect';
19
19
  export { useWebOtp, type UseWebOtpOptions } from './use-web-otp';
20
20
  export { useEdgeResize, type UseEdgeResizeOptions, type UseEdgeResizeReturn, type EdgeResizeSeparatorProps, } from './use-edge-resize';
21
21
  export { useSigningSession, type SigningField, type SigningFieldBase, type UseSigningSessionReturn, } from './use-signing-session';
22
+ export { useCountdown, type UseCountdownOptions, type UseCountdownReturn, } from './use-countdown';
22
23
  //# sourceMappingURL=index.d.ts.map
@@ -1,32 +1,32 @@
1
- import { u as v } from "../_chunks/use-prefers-reduced-motion-BMwIQRjB.js";
2
- import { u as D } from "../_chunks/use-media-query-CcAx5SMM.js";
3
- import { u as g, a as _ } from "../_chunks/use-signing-session-CyOZWinp.js";
4
- import { u as O } from "../_chunks/use-count-up-BLLetaZ8.js";
5
- import { u as k } from "../_chunks/use-locale-BkCIHujH.js";
6
- import { A as K, T as H, a as M, r as Y, t as q, u as B } from "../_chunks/use-theme-CAuo6EYT.js";
7
- import { u as P } from "../_chunks/use-controllable-state-BiY4xTzM.js";
8
- import { u as V } from "../_chunks/use-copy-to-clipboard-Cyfc_dlv.js";
9
- import { u as z } from "../_chunks/use-debounced-callback-BisrB-Fq.js";
10
- import { useState as x, useRef as b, useEffect as E } from "react";
11
- import { u as W, a as J } from "../_chunks/use-direction-Dp8h70PP.js";
12
- import { u as X } from "../_chunks/use-persistent-state-i23OWy6G.js";
13
- import { u as $ } from "../_chunks/use-isomorphic-layout-effect-BGfaCOP1.js";
14
- import { u as te } from "../_chunks/use-web-otp-D_utzp6S.js";
15
- import { u as oe } from "../_chunks/use-edge-resize-ZnGG7gyO.js";
16
- function h(e, o) {
17
- const [t, i] = x(e), u = b(null);
18
- return E(() => {
19
- if (o <= 0) {
20
- u.current !== null && (clearTimeout(u.current), u.current = null), i(e);
1
+ import { u as L } from "../_chunks/use-prefers-reduced-motion-BMwIQRjB.js";
2
+ import { u as F } from "../_chunks/use-media-query-CcAx5SMM.js";
3
+ import { u as R, a as _ } from "../_chunks/use-signing-session-CyOZWinp.js";
4
+ import { u as w } from "../_chunks/use-count-up-BLLetaZ8.js";
5
+ import { u as K } from "../_chunks/use-locale-BkCIHujH.js";
6
+ import { A as H, T as Y, a as q, r as B, t as G, u as P } from "../_chunks/use-theme-CAuo6EYT.js";
7
+ import { u as V } from "../_chunks/use-controllable-state-BiY4xTzM.js";
8
+ import { u as z } from "../_chunks/use-copy-to-clipboard-Cyfc_dlv.js";
9
+ import { u as W } from "../_chunks/use-debounced-callback-BisrB-Fq.js";
10
+ import { useState as b, useRef as E, useEffect as m, useCallback as x } from "react";
11
+ import { u as N, a as X } from "../_chunks/use-direction-Dp8h70PP.js";
12
+ import { u as $ } from "../_chunks/use-persistent-state-i23OWy6G.js";
13
+ import { u as te } from "../_chunks/use-isomorphic-layout-effect-BGfaCOP1.js";
14
+ import { u as ne } from "../_chunks/use-web-otp-D_utzp6S.js";
15
+ import { u as ue } from "../_chunks/use-edge-resize-ZnGG7gyO.js";
16
+ function C(e, u) {
17
+ const [r, i] = b(e), n = E(null);
18
+ return m(() => {
19
+ if (u <= 0) {
20
+ n.current !== null && (clearTimeout(n.current), n.current = null), i(e);
21
21
  return;
22
22
  }
23
23
  const s = setTimeout(() => {
24
- i(e), u.current = null;
25
- }, o);
26
- return u.current = s, () => clearTimeout(s);
27
- }, [e, o]), t;
24
+ i(e), n.current = null;
25
+ }, u);
26
+ return n.current = s, () => clearTimeout(s);
27
+ }, [e, u]), r;
28
28
  }
29
- const T = [
29
+ const S = [
30
30
  "a[href]",
31
31
  "button:not([disabled])",
32
32
  'input:not([disabled]):not([type="hidden"])',
@@ -37,74 +37,96 @@ const T = [
37
37
  "audio[controls]",
38
38
  "video[controls]"
39
39
  ].join(",");
40
- function p(e) {
40
+ function T(e) {
41
41
  return Array.from(
42
- e.querySelectorAll(T)
43
- ).filter((o) => {
44
- if (o.hidden) return !1;
45
- let t = o;
46
- for (; t; ) {
47
- if (t.hasAttribute("inert") || t.getAttribute("aria-hidden") === "true") return !1;
48
- t = t.parentElement;
42
+ e.querySelectorAll(S)
43
+ ).filter((u) => {
44
+ if (u.hidden) return !1;
45
+ let r = u;
46
+ for (; r; ) {
47
+ if (r.hasAttribute("inert") || r.getAttribute("aria-hidden") === "true") return !1;
48
+ r = r.parentElement;
49
49
  }
50
50
  return !0;
51
51
  });
52
52
  }
53
- function C(e, o = {}) {
54
- const { enabled: t = !0, autoFocus: i = !0, restoreFocus: u = !0 } = o, s = b(null);
55
- E(() => {
56
- if (!t) return;
57
- const a = e.current;
58
- if (!a) return;
53
+ function v(e, u = {}) {
54
+ const { enabled: r = !0, autoFocus: i = !0, restoreFocus: n = !0 } = u, s = E(null);
55
+ m(() => {
56
+ if (!r) return;
57
+ const o = e.current;
58
+ if (!o) return;
59
59
  if (s.current = typeof document < "u" && document.activeElement instanceof HTMLElement ? document.activeElement : null, i) {
60
- const n = p(a)[0] ?? (a.tabIndex >= -1 ? a : null);
61
- n == null || n.focus();
60
+ const a = T(o)[0] ?? (o.tabIndex >= -1 ? o : null);
61
+ a == null || a.focus();
62
62
  }
63
- function f(r) {
64
- if (r.key !== "Tab") return;
65
- const n = e.current;
66
- if (!n) return;
67
- const c = p(n);
68
- if (c.length === 0) {
69
- r.preventDefault();
63
+ function l(t) {
64
+ if (t.key !== "Tab") return;
65
+ const a = e.current;
66
+ if (!a) return;
67
+ const f = T(a);
68
+ if (f.length === 0) {
69
+ t.preventDefault();
70
70
  return;
71
71
  }
72
- const d = c[0], m = c[c.length - 1], l = document.activeElement;
73
- r.shiftKey ? (l === d || !n.contains(l)) && (r.preventDefault(), m.focus()) : (l === m || !n.contains(l)) && (r.preventDefault(), d.focus());
72
+ const c = f[0], d = f[f.length - 1], p = document.activeElement;
73
+ t.shiftKey ? (p === c || !a.contains(p)) && (t.preventDefault(), d.focus()) : (p === d || !a.contains(p)) && (t.preventDefault(), c.focus());
74
74
  }
75
- return a.addEventListener("keydown", f), () => {
76
- if (a.removeEventListener("keydown", f), u && s.current) {
77
- const r = s.current;
75
+ return o.addEventListener("keydown", l), () => {
76
+ if (o.removeEventListener("keydown", l), n && s.current) {
77
+ const t = s.current;
78
78
  requestAnimationFrame(() => {
79
- r.isConnected && r.focus();
79
+ t.isConnected && t.focus();
80
80
  });
81
81
  }
82
82
  };
83
- }, [t, i, u, e]);
83
+ }, [r, i, n, e]);
84
+ }
85
+ function g(e, u = {}) {
86
+ const { autoStart: r = !0, onElapsed: i } = u, [n, s] = b(e), [o, l] = b(r), t = E(i);
87
+ m(() => {
88
+ t.current = i;
89
+ }, [i]);
90
+ const a = x(() => {
91
+ s(e), l(!0);
92
+ }, [e]), f = x(() => {
93
+ s(e), l(!1);
94
+ }, [e]);
95
+ return m(() => {
96
+ if (!o) return;
97
+ const c = setInterval(() => {
98
+ s((d) => Math.max(0, d - 1));
99
+ }, 1e3);
100
+ return () => clearInterval(c);
101
+ }, [o]), m(() => {
102
+ var c;
103
+ o && n <= 0 && (l(!1), (c = t.current) == null || c.call(t));
104
+ }, [o, n]), { remaining: n, isRunning: o, start: a, reset: f };
84
105
  }
85
106
  export {
86
- K as ACCESSIBILITY_STORAGE_KEY,
87
- H as THEME_CLASS,
88
- M as THEME_STORAGE_KEY,
89
- Y as resolveTheme,
90
- q as themeClassList,
91
- P as useControllableState,
92
- V as useCopyToClipboard,
93
- O as useCountUp,
94
- z as useDebouncedCallback,
95
- h as useDebouncedValue,
96
- W as useDirection,
97
- J as useDocumentDirection,
98
- oe as useEdgeResize,
99
- C as useFocusTrap,
100
- $ as useIsomorphicLayoutEffect,
101
- k as useLocale,
102
- D as useMediaQuery,
103
- X as usePersistentState,
104
- v as usePrefersReducedMotion,
105
- g as useScrollToFirstError,
107
+ H as ACCESSIBILITY_STORAGE_KEY,
108
+ Y as THEME_CLASS,
109
+ q as THEME_STORAGE_KEY,
110
+ B as resolveTheme,
111
+ G as themeClassList,
112
+ V as useControllableState,
113
+ z as useCopyToClipboard,
114
+ w as useCountUp,
115
+ g as useCountdown,
116
+ W as useDebouncedCallback,
117
+ C as useDebouncedValue,
118
+ N as useDirection,
119
+ X as useDocumentDirection,
120
+ ue as useEdgeResize,
121
+ v as useFocusTrap,
122
+ te as useIsomorphicLayoutEffect,
123
+ K as useLocale,
124
+ F as useMediaQuery,
125
+ $ as usePersistentState,
126
+ L as usePrefersReducedMotion,
127
+ R as useScrollToFirstError,
106
128
  _ as useSigningSession,
107
- B as useTheme,
108
- te as useWebOtp
129
+ P as useTheme,
130
+ ne as useWebOtp
109
131
  };
110
132
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,34 @@
1
+ export interface UseCountdownOptions {
2
+ /** Begin counting down on mount. Default `true`. */
3
+ autoStart?: boolean;
4
+ /** Called exactly once when the countdown reaches zero. */
5
+ onElapsed?: () => void;
6
+ }
7
+ export interface UseCountdownReturn {
8
+ /** Whole seconds remaining; counts down to 0. */
9
+ remaining: number;
10
+ /** Whether the countdown is actively ticking. */
11
+ isRunning: boolean;
12
+ /** (Re)start from the full duration. */
13
+ start: () => void;
14
+ /** Stop and reset to the full duration without firing `onElapsed`. */
15
+ reset: () => void;
16
+ }
17
+ /**
18
+ * A pure, render-friendly seconds countdown. It owns no side effects — when
19
+ * it reaches zero it calls `onElapsed` and the CONSUMER decides what to do
20
+ * (close the tab, redirect, …). Same "no I/O" contract as `useSigningSession`.
21
+ *
22
+ * `onElapsed` is read through a ref, so changing the callback doesn't restart
23
+ * the timer. SSR-safe: the timer only ticks inside an effect (client-only).
24
+ *
25
+ * @example
26
+ * const { remaining } = useCountdown(10, {
27
+ * onElapsed: () => {
28
+ * window.close(); // best-effort — blocked for user-opened tabs
29
+ * window.location.assign('https://www.alfadocs.com'); // fallback
30
+ * },
31
+ * });
32
+ */
33
+ export declare function useCountdown(seconds: number, options?: UseCountdownOptions): UseCountdownReturn;
34
+ //# sourceMappingURL=use-countdown.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alfadocs/ui-kit",
3
- "version": "0.57.0",
3
+ "version": "0.58.0",
4
4
  "type": "module",
5
5
  "description": "AlfaDocs shared design system — tokens, components, patterns, and translations for platform, booking, and alfascribe.",
6
6
  "license": "BUSL-1.1",