@zentauri-ui/zentauri-components 2.3.0 → 2.3.2

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.
Files changed (243) hide show
  1. package/README.md +9 -5
  2. package/cli/props.json +2508 -1458
  3. package/cli/registry.json +20 -0
  4. package/dist/chunk-2RBBXVFA.js +19 -0
  5. package/dist/{chunk-ENKXB2BA.js.map → chunk-2RBBXVFA.js.map} +1 -1
  6. package/dist/{chunk-BFHJF4MV.mjs → chunk-425DAZTS.mjs} +4 -4
  7. package/dist/{chunk-BFHJF4MV.mjs.map → chunk-425DAZTS.mjs.map} +1 -1
  8. package/dist/chunk-4U6PVVST.mjs +15 -0
  9. package/dist/chunk-4U6PVVST.mjs.map +1 -0
  10. package/dist/{chunk-AARJLZXP.js → chunk-6GP74P4F.js} +6 -6
  11. package/dist/{chunk-AARJLZXP.js.map → chunk-6GP74P4F.js.map} +1 -1
  12. package/dist/{chunk-DIAA5VH4.mjs → chunk-CIZQQ32L.mjs} +3 -3
  13. package/dist/chunk-CIZQQ32L.mjs.map +1 -0
  14. package/dist/chunk-DUKHIN2W.js +44 -0
  15. package/dist/chunk-DUKHIN2W.js.map +1 -0
  16. package/dist/{chunk-PQ2XTY3M.js → chunk-G36ZV446.js} +13 -13
  17. package/dist/{chunk-PQ2XTY3M.js.map → chunk-G36ZV446.js.map} +1 -1
  18. package/dist/chunk-HJ7EFBED.js +86 -0
  19. package/dist/chunk-HJ7EFBED.js.map +1 -0
  20. package/dist/{chunk-H3BJOK22.js → chunk-HNAUUCR5.js} +3 -3
  21. package/dist/chunk-HNAUUCR5.js.map +1 -0
  22. package/dist/chunk-K2VCZK4I.mjs +75 -0
  23. package/dist/chunk-K2VCZK4I.mjs.map +1 -0
  24. package/dist/{chunk-DSX6RUYI.js → chunk-KVBFWRPF.js} +12 -12
  25. package/dist/{chunk-DSX6RUYI.js.map → chunk-KVBFWRPF.js.map} +1 -1
  26. package/dist/chunk-N4MLFU2Q.mjs +69 -0
  27. package/dist/chunk-N4MLFU2Q.mjs.map +1 -0
  28. package/dist/{chunk-ATE5SCTR.mjs → chunk-N6Q4ZLQR.mjs} +3 -3
  29. package/dist/{chunk-ATE5SCTR.mjs.map → chunk-N6Q4ZLQR.mjs.map} +1 -1
  30. package/dist/{chunk-YY7G4NV3.js → chunk-NZQA4M35.js} +49 -17
  31. package/dist/chunk-NZQA4M35.js.map +1 -0
  32. package/dist/chunk-OME7XOPN.js +78 -0
  33. package/dist/chunk-OME7XOPN.js.map +1 -0
  34. package/dist/chunk-PVDWJUMF.mjs +34 -0
  35. package/dist/chunk-PVDWJUMF.mjs.map +1 -0
  36. package/dist/chunk-PVVYOIU2.js +38 -0
  37. package/dist/chunk-PVVYOIU2.js.map +1 -0
  38. package/dist/chunk-PWEZB53R.js +90 -0
  39. package/dist/chunk-PWEZB53R.js.map +1 -0
  40. package/dist/chunk-PWYEC3KY.mjs +30 -0
  41. package/dist/chunk-PWYEC3KY.mjs.map +1 -0
  42. package/dist/{chunk-JKKF5DCF.mjs → chunk-R2JXARKB.mjs} +3 -3
  43. package/dist/{chunk-JKKF5DCF.mjs.map → chunk-R2JXARKB.mjs.map} +1 -1
  44. package/dist/chunk-SD7YXMNV.js +40 -0
  45. package/dist/chunk-SD7YXMNV.js.map +1 -0
  46. package/dist/{chunk-ZB6C6CJQ.mjs → chunk-TZTUL6C4.mjs} +40 -8
  47. package/dist/chunk-TZTUL6C4.mjs.map +1 -0
  48. package/dist/chunk-UBQY572I.mjs +81 -0
  49. package/dist/chunk-UBQY572I.mjs.map +1 -0
  50. package/dist/chunk-V5EE5ATH.mjs +36 -0
  51. package/dist/chunk-V5EE5ATH.mjs.map +1 -0
  52. package/dist/chunk-XUK5P37Y.js +19 -0
  53. package/dist/chunk-XUK5P37Y.js.map +1 -0
  54. package/dist/{chunk-WZY32L6K.mjs → chunk-YDD5HQGX.mjs} +3 -3
  55. package/dist/{chunk-WZY32L6K.mjs.map → chunk-YDD5HQGX.mjs.map} +1 -1
  56. package/dist/design-system/facade.js +12 -8
  57. package/dist/design-system/facade.js.map +1 -1
  58. package/dist/design-system/facade.mjs +11 -7
  59. package/dist/design-system/facade.mjs.map +1 -1
  60. package/dist/design-system/index.d.ts +4 -0
  61. package/dist/design-system/index.d.ts.map +1 -1
  62. package/dist/design-system/qr-code.d.ts +4 -0
  63. package/dist/design-system/qr-code.d.ts.map +1 -0
  64. package/dist/design-system/qr-scanner.d.ts +11 -0
  65. package/dist/design-system/qr-scanner.d.ts.map +1 -0
  66. package/dist/design-system/secret-reveal.d.ts +1 -1
  67. package/dist/design-system/secret-reveal.d.ts.map +1 -1
  68. package/dist/design-system/speech-recognition.d.ts +39 -0
  69. package/dist/design-system/speech-recognition.d.ts.map +1 -0
  70. package/dist/design-system/speech-synthesizer.d.ts +41 -0
  71. package/dist/design-system/speech-synthesizer.d.ts.map +1 -0
  72. package/dist/ui/buttons/animated.js +14 -10
  73. package/dist/ui/buttons/animated.js.map +1 -1
  74. package/dist/ui/buttons/animated.mjs +12 -8
  75. package/dist/ui/buttons/animated.mjs.map +1 -1
  76. package/dist/ui/buttons.js +15 -11
  77. package/dist/ui/buttons.mjs +13 -9
  78. package/dist/ui/data-table.js +25 -21
  79. package/dist/ui/data-table.js.map +1 -1
  80. package/dist/ui/data-table.mjs +15 -11
  81. package/dist/ui/data-table.mjs.map +1 -1
  82. package/dist/ui/dynamic-stepper.js +24 -20
  83. package/dist/ui/dynamic-stepper.js.map +1 -1
  84. package/dist/ui/dynamic-stepper.mjs +13 -9
  85. package/dist/ui/dynamic-stepper.mjs.map +1 -1
  86. package/dist/ui/pagination.js +16 -12
  87. package/dist/ui/pagination.mjs +13 -9
  88. package/dist/ui/qr-code/animated/animations.d.ts +8 -0
  89. package/dist/ui/qr-code/animated/animations.d.ts.map +1 -0
  90. package/dist/ui/qr-code/animated/index.d.ts +4 -0
  91. package/dist/ui/qr-code/animated/index.d.ts.map +1 -0
  92. package/dist/ui/qr-code/animated/qr-code-animated.d.ts +6 -0
  93. package/dist/ui/qr-code/animated/qr-code-animated.d.ts.map +1 -0
  94. package/dist/ui/qr-code/animated/types.d.ts +9 -0
  95. package/dist/ui/qr-code/animated/types.d.ts.map +1 -0
  96. package/dist/ui/qr-code/animated.js +156 -0
  97. package/dist/ui/qr-code/animated.js.map +1 -0
  98. package/dist/ui/qr-code/animated.mjs +149 -0
  99. package/dist/ui/qr-code/animated.mjs.map +1 -0
  100. package/dist/ui/qr-code/index.d.ts +5 -0
  101. package/dist/ui/qr-code/index.d.ts.map +1 -0
  102. package/dist/ui/qr-code/qr-code-base.d.ts +47 -0
  103. package/dist/ui/qr-code/qr-code-base.d.ts.map +1 -0
  104. package/dist/ui/qr-code/qr-code.d.ts +2 -0
  105. package/dist/ui/qr-code/qr-code.d.ts.map +1 -0
  106. package/dist/ui/qr-code/types.d.ts +14 -0
  107. package/dist/ui/qr-code/types.d.ts.map +1 -0
  108. package/dist/ui/qr-code/variants.d.ts +4 -0
  109. package/dist/ui/qr-code/variants.d.ts.map +1 -0
  110. package/dist/ui/qr-code.js +35 -0
  111. package/dist/ui/qr-code.js.map +1 -0
  112. package/dist/ui/qr-code.mjs +17 -0
  113. package/dist/ui/qr-code.mjs.map +1 -0
  114. package/dist/ui/qr-scanner/index.d.ts +4 -0
  115. package/dist/ui/qr-scanner/index.d.ts.map +1 -0
  116. package/dist/ui/qr-scanner/qr-scanner-base.d.ts +62 -0
  117. package/dist/ui/qr-scanner/qr-scanner-base.d.ts.map +1 -0
  118. package/dist/ui/qr-scanner/qr-scanner.d.ts +2 -0
  119. package/dist/ui/qr-scanner/qr-scanner.d.ts.map +1 -0
  120. package/dist/ui/qr-scanner/types.d.ts +28 -0
  121. package/dist/ui/qr-scanner/types.d.ts.map +1 -0
  122. package/dist/ui/qr-scanner/variants.d.ts +9 -0
  123. package/dist/ui/qr-scanner/variants.d.ts.map +1 -0
  124. package/dist/ui/qr-scanner.js +316 -0
  125. package/dist/ui/qr-scanner.js.map +1 -0
  126. package/dist/ui/qr-scanner.mjs +308 -0
  127. package/dist/ui/qr-scanner.mjs.map +1 -0
  128. package/dist/ui/secret-reveal/animated/secret-reveal-animated.d.ts.map +1 -1
  129. package/dist/ui/secret-reveal/animated.js +10 -7
  130. package/dist/ui/secret-reveal/animated.js.map +1 -1
  131. package/dist/ui/secret-reveal/animated.mjs +6 -3
  132. package/dist/ui/secret-reveal/animated.mjs.map +1 -1
  133. package/dist/ui/secret-reveal/secret-reveal-base.d.ts.map +1 -1
  134. package/dist/ui/secret-reveal.js +14 -11
  135. package/dist/ui/secret-reveal.js.map +1 -1
  136. package/dist/ui/secret-reveal.mjs +7 -4
  137. package/dist/ui/secret-reveal.mjs.map +1 -1
  138. package/dist/ui/speech-recognition/animated/animations.d.ts +8 -0
  139. package/dist/ui/speech-recognition/animated/animations.d.ts.map +1 -0
  140. package/dist/ui/speech-recognition/animated/index.d.ts +4 -0
  141. package/dist/ui/speech-recognition/animated/index.d.ts.map +1 -0
  142. package/dist/ui/speech-recognition/animated/speech-recognition-animated.d.ts +6 -0
  143. package/dist/ui/speech-recognition/animated/speech-recognition-animated.d.ts.map +1 -0
  144. package/dist/ui/speech-recognition/animated/types.d.ts +9 -0
  145. package/dist/ui/speech-recognition/animated/types.d.ts.map +1 -0
  146. package/dist/ui/speech-recognition/animated.js +288 -0
  147. package/dist/ui/speech-recognition/animated.js.map +1 -0
  148. package/dist/ui/speech-recognition/animated.mjs +285 -0
  149. package/dist/ui/speech-recognition/animated.mjs.map +1 -0
  150. package/dist/ui/speech-recognition/index.d.ts +4 -0
  151. package/dist/ui/speech-recognition/index.d.ts.map +1 -0
  152. package/dist/ui/speech-recognition/speech-recognition-base.d.ts +6 -0
  153. package/dist/ui/speech-recognition/speech-recognition-base.d.ts.map +1 -0
  154. package/dist/ui/speech-recognition/speech-recognition.d.ts +2 -0
  155. package/dist/ui/speech-recognition/speech-recognition.d.ts.map +1 -0
  156. package/dist/ui/speech-recognition/types.d.ts +31 -0
  157. package/dist/ui/speech-recognition/types.d.ts.map +1 -0
  158. package/dist/ui/speech-recognition/variants.d.ts +11 -0
  159. package/dist/ui/speech-recognition/variants.d.ts.map +1 -0
  160. package/dist/ui/speech-recognition.js +242 -0
  161. package/dist/ui/speech-recognition.js.map +1 -0
  162. package/dist/ui/speech-recognition.mjs +233 -0
  163. package/dist/ui/speech-recognition.mjs.map +1 -0
  164. package/dist/ui/speech-synthesizer/animated/animations.d.ts +8 -0
  165. package/dist/ui/speech-synthesizer/animated/animations.d.ts.map +1 -0
  166. package/dist/ui/speech-synthesizer/animated/index.d.ts +4 -0
  167. package/dist/ui/speech-synthesizer/animated/index.d.ts.map +1 -0
  168. package/dist/ui/speech-synthesizer/animated/speech-synthesizer-animated.d.ts +6 -0
  169. package/dist/ui/speech-synthesizer/animated/speech-synthesizer-animated.d.ts.map +1 -0
  170. package/dist/ui/speech-synthesizer/animated/types.d.ts +9 -0
  171. package/dist/ui/speech-synthesizer/animated/types.d.ts.map +1 -0
  172. package/dist/ui/speech-synthesizer/animated.js +269 -0
  173. package/dist/ui/speech-synthesizer/animated.js.map +1 -0
  174. package/dist/ui/speech-synthesizer/animated.mjs +266 -0
  175. package/dist/ui/speech-synthesizer/animated.mjs.map +1 -0
  176. package/dist/ui/speech-synthesizer/index.d.ts +4 -0
  177. package/dist/ui/speech-synthesizer/index.d.ts.map +1 -0
  178. package/dist/ui/speech-synthesizer/speech-synthesizer-base.d.ts +6 -0
  179. package/dist/ui/speech-synthesizer/speech-synthesizer-base.d.ts.map +1 -0
  180. package/dist/ui/speech-synthesizer/speech-synthesizer.d.ts +2 -0
  181. package/dist/ui/speech-synthesizer/speech-synthesizer.d.ts.map +1 -0
  182. package/dist/ui/speech-synthesizer/types.d.ts +43 -0
  183. package/dist/ui/speech-synthesizer/types.d.ts.map +1 -0
  184. package/dist/ui/speech-synthesizer/variants.d.ts +13 -0
  185. package/dist/ui/speech-synthesizer/variants.d.ts.map +1 -0
  186. package/dist/ui/speech-synthesizer.js +220 -0
  187. package/dist/ui/speech-synthesizer.js.map +1 -0
  188. package/dist/ui/speech-synthesizer.mjs +211 -0
  189. package/dist/ui/speech-synthesizer.mjs.map +1 -0
  190. package/dist/ui/split-button.js +26 -22
  191. package/dist/ui/split-button.js.map +1 -1
  192. package/dist/ui/split-button.mjs +13 -9
  193. package/dist/ui/split-button.mjs.map +1 -1
  194. package/package.json +5 -2
  195. package/src/design-system/index.ts +4 -0
  196. package/src/design-system/qr-code.ts +13 -0
  197. package/src/design-system/qr-scanner.ts +32 -0
  198. package/src/design-system/secret-reveal.ts +1 -1
  199. package/src/design-system/speech-recognition.ts +82 -0
  200. package/src/design-system/speech-synthesizer.ts +90 -0
  201. package/src/ui/qr-code/animated/animations.ts +51 -0
  202. package/src/ui/qr-code/animated/index.ts +5 -0
  203. package/src/ui/qr-code/animated/qr-code-animated.tsx +111 -0
  204. package/src/ui/qr-code/animated/types.ts +10 -0
  205. package/src/ui/qr-code/index.ts +10 -0
  206. package/src/ui/qr-code/qr-code-base.tsx +149 -0
  207. package/src/ui/qr-code/qr-code.test.tsx +58 -0
  208. package/src/ui/qr-code/qr-code.tsx +2 -0
  209. package/src/ui/qr-code/types.ts +22 -0
  210. package/src/ui/qr-code/variants.ts +11 -0
  211. package/src/ui/qr-scanner/index.ts +17 -0
  212. package/src/ui/qr-scanner/qr-scanner-base.tsx +568 -0
  213. package/src/ui/qr-scanner/qr-scanner.test.tsx +61 -0
  214. package/src/ui/qr-scanner/qr-scanner.tsx +2 -0
  215. package/src/ui/qr-scanner/types.ts +32 -0
  216. package/src/ui/qr-scanner/variants.ts +26 -0
  217. package/src/ui/secret-reveal/animated/secret-reveal-animated.tsx +4 -1
  218. package/src/ui/secret-reveal/secret-reveal-base.tsx +4 -1
  219. package/src/ui/speech-recognition/animated/animations.ts +62 -0
  220. package/src/ui/speech-recognition/animated/index.ts +8 -0
  221. package/src/ui/speech-recognition/animated/speech-recognition-animated.tsx +276 -0
  222. package/src/ui/speech-recognition/animated/types.ts +11 -0
  223. package/src/ui/speech-recognition/index.ts +15 -0
  224. package/src/ui/speech-recognition/speech-recognition-base.tsx +276 -0
  225. package/src/ui/speech-recognition/speech-recognition.test.tsx +74 -0
  226. package/src/ui/speech-recognition/speech-recognition.tsx +1 -0
  227. package/src/ui/speech-recognition/types.ts +50 -0
  228. package/src/ui/speech-recognition/variants.ts +47 -0
  229. package/src/ui/speech-synthesizer/animated/animations.ts +62 -0
  230. package/src/ui/speech-synthesizer/animated/index.ts +8 -0
  231. package/src/ui/speech-synthesizer/animated/speech-synthesizer-animated.tsx +260 -0
  232. package/src/ui/speech-synthesizer/animated/types.ts +11 -0
  233. package/src/ui/speech-synthesizer/index.ts +14 -0
  234. package/src/ui/speech-synthesizer/speech-synthesizer-base.tsx +255 -0
  235. package/src/ui/speech-synthesizer/speech-synthesizer.test.tsx +87 -0
  236. package/src/ui/speech-synthesizer/speech-synthesizer.tsx +1 -0
  237. package/src/ui/speech-synthesizer/types.ts +57 -0
  238. package/src/ui/speech-synthesizer/variants.ts +55 -0
  239. package/dist/chunk-DIAA5VH4.mjs.map +0 -1
  240. package/dist/chunk-ENKXB2BA.js +0 -19
  241. package/dist/chunk-H3BJOK22.js.map +0 -1
  242. package/dist/chunk-YY7G4NV3.js.map +0 -1
  243. package/dist/chunk-ZB6C6CJQ.mjs.map +0 -1
@@ -0,0 +1,74 @@
1
+ import { createRef } from "react";
2
+ import { render } from "@testing-library/react";
3
+ import { describe, expect, it } from "vitest";
4
+
5
+ import { SpeechRecognition } from "./speech-recognition";
6
+
7
+ describe("SpeechRecognition", () => {
8
+ it("should set displayName", () => {
9
+ expect(SpeechRecognition.displayName).toBe("SpeechRecognition");
10
+ });
11
+
12
+ it("should stamp data-slot on the root container", () => {
13
+ const { container } = render(<SpeechRecognition />);
14
+ const root = container.querySelector('[data-slot="speech-recognition"]');
15
+ expect(root).toBeTruthy();
16
+ });
17
+
18
+ it("should render a mic button", () => {
19
+ const { container } = render(<SpeechRecognition />);
20
+ const btn = container.querySelector('[data-slot="speech-recognition-btn"]');
21
+ expect(btn).toBeTruthy();
22
+ });
23
+
24
+ it("should render a status label", () => {
25
+ const { container } = render(<SpeechRecognition />);
26
+ const status = container.querySelector(
27
+ '[data-slot="speech-recognition-status"]',
28
+ );
29
+ expect(status).toBeTruthy();
30
+ expect(status?.textContent).toContain("start listening");
31
+ });
32
+
33
+ it("should render children when provided", () => {
34
+ const { container } = render(
35
+ <SpeechRecognition>
36
+ <div data-testid="child" />
37
+ </SpeechRecognition>,
38
+ );
39
+ expect(container.querySelector('[data-testid="child"]')).toBeTruthy();
40
+ });
41
+
42
+ it("should expose an imperative handle with start, stop, abort methods", () => {
43
+ const ref = createRef<{
44
+ start: () => void;
45
+ stop: () => void;
46
+ abort: () => void;
47
+ state: string;
48
+ }>();
49
+ render(<SpeechRecognition ref={ref as any} />);
50
+ expect(ref.current).toBeTruthy();
51
+ expect(typeof ref.current?.start).toBe("function");
52
+ expect(typeof ref.current?.stop).toBe("function");
53
+ expect(typeof ref.current?.abort).toBe("function");
54
+ });
55
+
56
+ it("should set default state to idle", () => {
57
+ const ref = createRef<{
58
+ start: () => void;
59
+ stop: () => void;
60
+ abort: () => void;
61
+ state: string;
62
+ }>();
63
+ render(<SpeechRecognition ref={ref as any} />);
64
+ expect(ref.current?.state).toBe("idle");
65
+ });
66
+
67
+ it("should apply custom className", () => {
68
+ const { container } = render(
69
+ <SpeechRecognition className="custom-class" />,
70
+ );
71
+ const root = container.querySelector('[data-slot="speech-recognition"]');
72
+ expect(root?.className).toMatch(/custom-class/);
73
+ });
74
+ });
@@ -0,0 +1 @@
1
+ export { SpeechRecognitionBase as SpeechRecognition } from "./speech-recognition-base";
@@ -0,0 +1,50 @@
1
+ import type { VariantProps } from "class-variance-authority";
2
+ import type { ComponentPropsWithRef, Ref } from "react";
3
+
4
+ import type {
5
+ speechRecognitionBtnVariants,
6
+ speechRecognitionVariants,
7
+ } from "./variants";
8
+
9
+ export type SpeechRecognitionVariantProps = VariantProps<
10
+ typeof speechRecognitionBtnVariants
11
+ >;
12
+
13
+ export type SpeechRecognitionState =
14
+ | "idle"
15
+ | "listening"
16
+ | "processing"
17
+ | "error";
18
+
19
+ export interface SpeechRecognitionResult {
20
+ transcript: string;
21
+ isFinal: boolean;
22
+ }
23
+
24
+ export type SpeechRecognitionBaseProps = VariantProps<
25
+ typeof speechRecognitionVariants
26
+ > &
27
+ VariantProps<typeof speechRecognitionBtnVariants> &
28
+ ComponentPropsWithRef<"div"> & {
29
+ lang?: string;
30
+ continuous?: boolean;
31
+ interimResults?: boolean;
32
+ autoStart?: boolean;
33
+ onResult?: (result: SpeechRecognitionResult) => void;
34
+ onError?: (error: string) => void;
35
+ onStateChange?: (state: SpeechRecognitionState) => void;
36
+ renderMic?: (props: {
37
+ isListening: boolean;
38
+ state: SpeechRecognitionState;
39
+ }) => React.ReactNode;
40
+ children?: React.ReactNode;
41
+ };
42
+
43
+ export type SpeechRecognitionProps = SpeechRecognitionBaseProps;
44
+
45
+ export type SpeechRecognitionRef = {
46
+ start: () => void;
47
+ stop: () => void;
48
+ abort: () => void;
49
+ state: SpeechRecognitionState;
50
+ };
@@ -0,0 +1,47 @@
1
+ import { cva } from "class-variance-authority";
2
+
3
+ import {
4
+ zuiSpeechRecognitionAppearances,
5
+ zuiSpeechRecognitionBase,
6
+ zuiSpeechRecognitionBtnActive,
7
+ zuiSpeechRecognitionBtnBase,
8
+ zuiSpeechRecognitionBtnSizes,
9
+ zuiSpeechRecognitionSizes,
10
+ zuiSpeechRecognitionStatusBase,
11
+ zuiSpeechRecognitionTranscriptBase,
12
+ } from "../../design-system/speech-recognition";
13
+
14
+ export const speechRecognitionVariants = cva(
15
+ zuiSpeechRecognitionBase.join(" "),
16
+ {
17
+ variants: {
18
+ size: zuiSpeechRecognitionSizes,
19
+ },
20
+ defaultVariants: {
21
+ size: "md",
22
+ },
23
+ },
24
+ );
25
+
26
+ export const speechRecognitionBtnVariants = cva(
27
+ zuiSpeechRecognitionBtnBase.join(" "),
28
+ {
29
+ variants: {
30
+ appearance: zuiSpeechRecognitionAppearances,
31
+ size: zuiSpeechRecognitionBtnSizes,
32
+ },
33
+ defaultVariants: {
34
+ appearance: "default",
35
+ size: "md",
36
+ },
37
+ },
38
+ );
39
+
40
+ export const speechRecognitionStatusClasses =
41
+ zuiSpeechRecognitionStatusBase.join(" ");
42
+
43
+ export const speechRecognitionTranscriptClasses =
44
+ zuiSpeechRecognitionTranscriptBase.join(" ");
45
+
46
+ export const speechRecognitionBtnActiveClasses =
47
+ zuiSpeechRecognitionBtnActive.join(" ");
@@ -0,0 +1,62 @@
1
+ import type { Transition, Variants } from "framer-motion";
2
+
3
+ export type SpeechSynthesizerAnimation = "none" | "pulse" | "wave" | "glow";
4
+
5
+ export type SpeechSynthesizerAnimationPresets = Record<
6
+ SpeechSynthesizerAnimation,
7
+ {
8
+ transition: Transition;
9
+ variants: Variants;
10
+ }
11
+ >;
12
+
13
+ export const speechSynthesizerAnimationPresets: SpeechSynthesizerAnimationPresets =
14
+ {
15
+ none: {
16
+ transition: { duration: 0 },
17
+ variants: {
18
+ initial: { scale: 1 },
19
+ animate: { scale: 1 },
20
+ },
21
+ },
22
+ pulse: {
23
+ transition: {
24
+ duration: 1,
25
+ repeat: Infinity,
26
+ repeatType: "reverse",
27
+ ease: "easeInOut",
28
+ },
29
+ variants: {
30
+ initial: { scale: 1, opacity: 0.7 },
31
+ animate: { scale: 1.15, opacity: 1 },
32
+ },
33
+ },
34
+ wave: {
35
+ transition: {
36
+ duration: 0.8,
37
+ repeat: Infinity,
38
+ repeatType: "reverse",
39
+ ease: "easeInOut",
40
+ },
41
+ variants: {
42
+ initial: { scale: 1, rotate: 0 },
43
+ animate: { scale: 1.1, rotate: -5 },
44
+ },
45
+ },
46
+ glow: {
47
+ transition: {
48
+ duration: 1.5,
49
+ repeat: Infinity,
50
+ repeatType: "reverse",
51
+ ease: "easeInOut",
52
+ },
53
+ variants: {
54
+ initial: {
55
+ boxShadow: "0 0 0px rgba(59,130,246,0)",
56
+ },
57
+ animate: {
58
+ boxShadow: "0 0 20px rgba(59,130,246,0.5)",
59
+ },
60
+ },
61
+ },
62
+ };
@@ -0,0 +1,8 @@
1
+ "use client";
2
+
3
+ export { SpeechSynthesizerAnimated } from "./speech-synthesizer-animated";
4
+ export type {
5
+ SpeechSynthesizerAnimation,
6
+ SpeechSynthesizerAnimatedProps,
7
+ } from "./types";
8
+ export { speechSynthesizerAnimationPresets } from "./animations";
@@ -0,0 +1,260 @@
1
+ "use client";
2
+
3
+ import { motion } from "framer-motion";
4
+ import {
5
+ useCallback,
6
+ useEffect,
7
+ useImperativeHandle,
8
+ useRef,
9
+ useState,
10
+ } from "react";
11
+
12
+ import { cn } from "../../../lib/utils";
13
+
14
+ import type { SpeechSynthesizerRef, SpeechSynthesizerState } from "../types";
15
+ import {
16
+ speechSynthesizerBtnActiveClasses,
17
+ speechSynthesizerBtnVariants,
18
+ speechSynthesizerControlsClasses,
19
+ speechSynthesizerProgressBarClasses,
20
+ speechSynthesizerProgressClasses,
21
+ speechSynthesizerTextClasses,
22
+ speechSynthesizerVariants,
23
+ } from "../variants";
24
+
25
+ import { speechSynthesizerAnimationPresets } from "./animations";
26
+ import type { SpeechSynthesizerAnimatedProps } from "./types";
27
+
28
+ function DefaultPlayIcon() {
29
+ return (
30
+ <svg viewBox="0 0 24 24" fill="currentColor" className="size-5">
31
+ <path d="M8 5v14l11-7z" />
32
+ </svg>
33
+ );
34
+ }
35
+
36
+ function DefaultPauseIcon() {
37
+ return (
38
+ <svg viewBox="0 0 24 24" fill="currentColor" className="size-5">
39
+ <rect x="6" y="4" width="4" height="16" />
40
+ <rect x="14" y="4" width="4" height="16" />
41
+ </svg>
42
+ );
43
+ }
44
+
45
+ function DefaultStopIcon() {
46
+ return (
47
+ <svg viewBox="0 0 24 24" fill="currentColor" className="size-5">
48
+ <rect x="6" y="6" width="12" height="12" />
49
+ </svg>
50
+ );
51
+ }
52
+
53
+ export function SpeechSynthesizerAnimated({
54
+ appearance,
55
+ size,
56
+ text,
57
+ lang,
58
+ rate = 1,
59
+ pitch = 1,
60
+ volume = 1,
61
+ autoSpeak = false,
62
+ onStart,
63
+ onEnd,
64
+ onError,
65
+ onStateChange,
66
+ renderPlay,
67
+ renderPause,
68
+ renderStop,
69
+ showProgress = false,
70
+ animation = "pulse",
71
+ className,
72
+ children,
73
+ ...rest
74
+ }: SpeechSynthesizerAnimatedProps) {
75
+ const [state, setState] = useState<SpeechSynthesizerState>("idle");
76
+ const utteranceRef = useRef<SpeechSynthesisUtterance | null>(null);
77
+ const stateRef = useRef<SpeechSynthesizerState>("idle");
78
+ const preset = speechSynthesizerAnimationPresets[animation];
79
+
80
+ const setStateSafe = useCallback(
81
+ (newState: SpeechSynthesizerState) => {
82
+ stateRef.current = newState;
83
+ setState(newState);
84
+ onStateChange?.(newState);
85
+ },
86
+ [onStateChange],
87
+ );
88
+
89
+ const speak = useCallback(() => {
90
+ if (!text || typeof window === "undefined") return;
91
+ window.speechSynthesis.cancel();
92
+
93
+ const utterance = new SpeechSynthesisUtterance(text);
94
+ if (lang) utterance.lang = lang;
95
+ utterance.rate = rate;
96
+ utterance.pitch = pitch;
97
+ utterance.volume = volume;
98
+
99
+ utterance.onstart = () => {
100
+ setStateSafe("speaking");
101
+ onStart?.();
102
+ };
103
+ utterance.onend = () => {
104
+ setStateSafe("idle");
105
+ onEnd?.();
106
+ };
107
+ utterance.onerror = (event) => {
108
+ setStateSafe("idle");
109
+ onError?.(event.error);
110
+ };
111
+ utterance.onpause = () => setStateSafe("paused");
112
+ utterance.onresume = () => setStateSafe("speaking");
113
+
114
+ utteranceRef.current = utterance;
115
+ window.speechSynthesis.speak(utterance);
116
+ }, [text, lang, rate, pitch, volume, onStart, onEnd, onError, setStateSafe]);
117
+
118
+ const pauseFn = useCallback(() => {
119
+ if (typeof window !== "undefined") window.speechSynthesis.pause();
120
+ }, []);
121
+
122
+ const resumeFn = useCallback(() => {
123
+ if (typeof window !== "undefined") window.speechSynthesis.resume();
124
+ }, []);
125
+
126
+ const stop = useCallback(() => {
127
+ if (typeof window !== "undefined") window.speechSynthesis.cancel();
128
+ setStateSafe("idle");
129
+ }, [setStateSafe]);
130
+
131
+ const imperativeHandle: SpeechSynthesizerRef = {
132
+ speak,
133
+ pause: pauseFn,
134
+ resume: resumeFn,
135
+ stop,
136
+ get state() {
137
+ return stateRef.current;
138
+ },
139
+ };
140
+
141
+ useImperativeHandle((rest as any).ref, () => imperativeHandle, [
142
+ speak,
143
+ pauseFn,
144
+ resumeFn,
145
+ stop,
146
+ ]);
147
+
148
+ useEffect(() => {
149
+ if (autoSpeak && text) speak();
150
+ return () => {
151
+ if (typeof window !== "undefined") window.speechSynthesis.cancel();
152
+ };
153
+ }, []);
154
+
155
+ const isSpeaking = state === "speaking";
156
+ const isPaused = state === "paused";
157
+ const showPlay = state === "idle" || state === "paused";
158
+ const showPause = state === "speaking";
159
+
160
+ return (
161
+ <motion.div
162
+ data-slot="speech-synthesizer"
163
+ className={cn(speechSynthesizerVariants({ size }), className)}
164
+ {...(rest as any)}
165
+ >
166
+ {text && (
167
+ <motion.p
168
+ data-slot="speech-synthesizer-text"
169
+ className={speechSynthesizerTextClasses}
170
+ initial="initial"
171
+ animate={isSpeaking ? "animate" : "initial"}
172
+ variants={preset.variants}
173
+ transition={preset.transition}
174
+ >
175
+ {text}
176
+ </motion.p>
177
+ )}
178
+ {showProgress && isSpeaking && (
179
+ <motion.div
180
+ data-slot="speech-synthesizer-progress"
181
+ className={speechSynthesizerProgressClasses}
182
+ initial={{ scaleX: 0 }}
183
+ animate={{ scaleX: 1 }}
184
+ transition={{ duration: 0.3 }}
185
+ style={{ originX: 0 }}
186
+ >
187
+ <div
188
+ data-slot="speech-synthesizer-progress-bar"
189
+ className={cn(
190
+ speechSynthesizerProgressBarClasses,
191
+ "w-full animate-pulse",
192
+ )}
193
+ />
194
+ </motion.div>
195
+ )}
196
+ <motion.div
197
+ data-slot="speech-synthesizer-controls"
198
+ className={speechSynthesizerControlsClasses}
199
+ >
200
+ {showPlay && (
201
+ <motion.button
202
+ type="button"
203
+ data-slot="speech-synthesizer-play-btn"
204
+ className={cn(
205
+ speechSynthesizerBtnVariants({ appearance, size }),
206
+ isPaused && speechSynthesizerBtnActiveClasses,
207
+ )}
208
+ onClick={isPaused ? resumeFn : speak}
209
+ aria-label={isPaused ? "Resume" : "Play"}
210
+ whileHover={{ scale: 1.1 }}
211
+ whileTap={{ scale: 0.9 }}
212
+ >
213
+ {renderPlay ? (
214
+ renderPlay({ isSpeaking, isPaused, state })
215
+ ) : (
216
+ <DefaultPlayIcon />
217
+ )}
218
+ </motion.button>
219
+ )}
220
+ {showPause && (
221
+ <motion.button
222
+ type="button"
223
+ data-slot="speech-synthesizer-pause-btn"
224
+ className={speechSynthesizerBtnVariants({ appearance, size })}
225
+ onClick={pauseFn}
226
+ aria-label="Pause"
227
+ whileHover={{ scale: 1.1 }}
228
+ whileTap={{ scale: 0.9 }}
229
+ >
230
+ {renderPause ? (
231
+ renderPause({ isSpeaking, isPaused, state })
232
+ ) : (
233
+ <DefaultPauseIcon />
234
+ )}
235
+ </motion.button>
236
+ )}
237
+ {(isSpeaking || isPaused) && (
238
+ <motion.button
239
+ type="button"
240
+ data-slot="speech-synthesizer-stop-btn"
241
+ className={speechSynthesizerBtnVariants({ appearance, size })}
242
+ onClick={stop}
243
+ aria-label="Stop"
244
+ whileHover={{ scale: 1.1 }}
245
+ whileTap={{ scale: 0.9 }}
246
+ >
247
+ {renderStop ? (
248
+ renderStop({ isSpeaking, isPaused, state })
249
+ ) : (
250
+ <DefaultStopIcon />
251
+ )}
252
+ </motion.button>
253
+ )}
254
+ </motion.div>
255
+ {children}
256
+ </motion.div>
257
+ );
258
+ }
259
+
260
+ SpeechSynthesizerAnimated.displayName = "SpeechSynthesizerAnimated";
@@ -0,0 +1,11 @@
1
+ import type { Ref } from "react";
2
+
3
+ import type { SpeechSynthesizerBaseProps } from "../types";
4
+ import type { SpeechSynthesizerAnimation } from "./animations";
5
+
6
+ export type { SpeechSynthesizerAnimation };
7
+
8
+ export type SpeechSynthesizerAnimatedProps = SpeechSynthesizerBaseProps & {
9
+ animation?: SpeechSynthesizerAnimation;
10
+ ref?: Ref<HTMLDivElement>;
11
+ };
@@ -0,0 +1,14 @@
1
+ "use client";
2
+
3
+ export { SpeechSynthesizer } from "./speech-synthesizer";
4
+ export type {
5
+ SpeechSynthesizerBaseProps,
6
+ SpeechSynthesizerProps,
7
+ SpeechSynthesizerRef,
8
+ SpeechSynthesizerState,
9
+ SpeechSynthesizerVariantProps,
10
+ } from "./types";
11
+ export {
12
+ speechSynthesizerBtnVariants,
13
+ speechSynthesizerVariants,
14
+ } from "./variants";