@vvedantb/ui 0.12.0 → 0.12.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vvedantb/ui",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "license": "MIT",
5
5
  "description": "Shared React 19 UI for web apps: one JavaScript entry (primitives, shell pieces, app helpers including the Convex and Clerk provider, VITE env parsing and ensure-user, native tokens), design-token CSS, shared Tailwind v4 CSS and a Tailwind preset.",
6
6
  "type": "module",
@@ -177,7 +177,7 @@
177
177
  "scripts": {
178
178
  "check:tokens": "node tokens/scripts/check-component-tokens.mjs",
179
179
  "build": "node tokens/scripts/check-exports.mjs && node tokens/scripts/check-component-tokens.mjs && tsc -p tsconfig.json",
180
- "typecheck": "tsc -p tsconfig.json && tsc -p tokens/tsconfig.json",
180
+ "typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.consumer.json && tsc -p tokens/tsconfig.json",
181
181
  "test": "node tokens/scripts/check-component-tokens.mjs && vitest run && node --test tokens/test/*.test.mjs app/tests-node/*.test.mjs",
182
182
  "verify": "node tokens/scripts/check-component-tokens.mjs && node tokens/verify/run.mjs",
183
183
  "analyze": "node tokens/verify/analyze.mjs"
@@ -5,21 +5,16 @@ import { Button } from "../ui/button";
5
5
  import { Spinner } from "../ui/spinner";
6
6
  import { cn } from "../utils/cn";
7
7
  import { useEffect, useRef, useState } from "react";
8
- interface SpeechRecognition extends EventTarget {
8
+ // Only the members this component uses, so an app's own (wider or narrower)
9
+ // speech recognition typings stay assignable to it.
10
+ interface SpeechRecognitionInstance extends EventTarget {
9
11
  continuous: boolean;
10
12
  interimResults: boolean;
11
13
  lang: string;
12
14
  start(): void;
13
15
  stop(): void;
14
- onstart: ((this: SpeechRecognition, ev: Event) => void) | null;
15
- onend: ((this: SpeechRecognition, ev: Event) => void) | null;
16
- onresult:
17
- | ((this: SpeechRecognition, ev: SpeechRecognitionEvent) => void)
18
- | null;
19
- onerror:
20
- | ((this: SpeechRecognition, ev: SpeechRecognitionErrorEvent) => void)
21
- | null;
22
16
  }
17
+ type SpeechRecognitionConstructor = new () => SpeechRecognitionInstance;
23
18
  interface SpeechRecognitionEvent extends Event {
24
19
  results: SpeechRecognitionResultList;
25
20
  resultIndex: number;
@@ -39,15 +34,18 @@ interface SpeechRecognitionAlternative {
39
34
  transcript: string;
40
35
  confidence: number;
41
36
  }
42
- interface SpeechRecognitionErrorEvent extends Event {
43
- error: string;
44
- }
45
- declare global {
46
- interface Window {
47
- SpeechRecognition: new () => SpeechRecognition;
48
- webkitSpeechRecognition: new () => SpeechRecognition;
49
- }
50
- }
37
+ // Read the constructors through a local type: a package must not augment the
38
+ // global Window, which would clash with apps and the DOM lib.
39
+ type SpeechRecognitionWindow = Window & {
40
+ SpeechRecognition?: SpeechRecognitionConstructor;
41
+ webkitSpeechRecognition?: SpeechRecognitionConstructor;
42
+ };
43
+ const getSpeechRecognitionConstructor = ():
44
+ | SpeechRecognitionConstructor
45
+ | undefined => {
46
+ const speechWindow: SpeechRecognitionWindow = window;
47
+ return speechWindow.SpeechRecognition || speechWindow.webkitSpeechRecognition;
48
+ };
51
49
  type SpeechInputMode = "speech-recognition" | "media-recorder" | "none";
52
50
  export type SpeechInputProps = ComponentProps<typeof Button> & {
53
51
  onTranscriptionChange?: (text: string) => void;
@@ -77,7 +75,7 @@ export const SpeechInput = ({
77
75
  const [isProcessing, setIsProcessing] = useState(false);
78
76
  const [mode] = useState<SpeechInputMode>(detectSpeechInputMode);
79
77
  const [isRecognitionReady, setIsRecognitionReady] = useState(false);
80
- const recognitionRef = useRef<SpeechRecognition | null>(null);
78
+ const recognitionRef = useRef<SpeechRecognitionInstance | null>(null);
81
79
  const mediaRecorderRef = useRef<MediaRecorder | null>(null);
82
80
  const streamRef = useRef<MediaStream | null>(null);
83
81
  const audioChunksRef = useRef<Blob[]>([]);
@@ -92,8 +90,10 @@ export const SpeechInput = ({
92
90
  if (mode !== "speech-recognition") {
93
91
  return;
94
92
  }
95
- const SpeechRecognitionCtor =
96
- window.SpeechRecognition || window.webkitSpeechRecognition;
93
+ const SpeechRecognitionCtor = getSpeechRecognitionConstructor();
94
+ if (!SpeechRecognitionCtor) {
95
+ return;
96
+ }
97
97
  const speechRecognition = new SpeechRecognitionCtor();
98
98
  speechRecognition.continuous = true;
99
99
  speechRecognition.interimResults = true;
@@ -1,4 +1,3 @@
1
- import * as React from "react";
2
1
  import { cn } from "../utils/cn";
3
2
  import { Button } from "./button";
4
3