@voiceinput/react 0.1.0-beta.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/LICENSE +21 -0
- package/README.md +267 -0
- package/dist/index.cjs +701 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +110 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +110 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +690 -0
- package/dist/index.js.map +1 -0
- package/package.json +77 -0
- package/styles.css +157 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["#generation","#requested","#queue","#isCurrentRequest","#active","createContext","useMemo","createBrowserAudioSource","useEffect","useLayoutEffect","useContext","VoiceInputError","useRef","useMemo","createBrowserAudioSource","useState","createVoiceInputTextEngine","createVoiceInputSession","useCallback","useSyncExternalStore","getBrowserVoiceInputSupport","composeEventHandlers","useId","useRef","useCallback"],"sources":["../src/coordinator.ts","../src/context.tsx","../src/use-voice-input.ts","../src/components.tsx"],"sourcesContent":["import type { VoiceInputStopReason } from \"@voiceinput/core\";\n\nexport interface CoordinatedVoiceInputSession {\n stop(reason: VoiceInputStopReason): Promise<void>;\n}\n\nexport class VoiceInputCoordinator {\n #active: CoordinatedVoiceInputSession | undefined;\n #requested: CoordinatedVoiceInputSession | undefined;\n #generation = 0;\n #queue: Promise<void> = Promise.resolve();\n\n activate(session: CoordinatedVoiceInputSession): Promise<boolean> {\n const generation = ++this.#generation;\n this.#requested = session;\n const activation = this.#queue.then(async () => {\n if (!this.#isCurrentRequest(session, generation)) {\n return false;\n }\n\n const previous = this.#active;\n if (previous !== undefined && previous !== session) {\n try {\n await previous.stop(\"replaced\");\n } catch (error) {\n reportUnhandledError(error);\n }\n if (this.#active === previous) {\n this.#active = undefined;\n }\n }\n\n if (!this.#isCurrentRequest(session, generation)) {\n return false;\n }\n this.#active = session;\n return true;\n });\n this.#queue = activation.then(\n () => {},\n () => {},\n );\n return activation;\n }\n\n release(session: CoordinatedVoiceInputSession): void {\n this.cancel(session);\n if (this.#active === session) {\n this.#active = undefined;\n }\n }\n\n cancel(session: CoordinatedVoiceInputSession): void {\n if (this.#requested === session) {\n this.#requested = undefined;\n this.#generation += 1;\n }\n }\n\n #isCurrentRequest(\n session: CoordinatedVoiceInputSession,\n generation: number,\n ): boolean {\n return this.#requested === session && this.#generation === generation;\n }\n}\n\nfunction reportUnhandledError(error: unknown): void {\n const reportError = (\n globalThis as typeof globalThis & {\n reportError?: (error: unknown) => void;\n }\n ).reportError;\n reportError?.(error);\n}\n","import {\n createBrowserAudioSource,\n type VoiceAudioSource,\n} from \"@voiceinput/core\";\nimport type { VoiceInputProviderV1 } from \"@voiceinput/provider\";\nimport { createContext, useMemo, type ReactNode } from \"react\";\n\nimport { VoiceInputCoordinator } from \"./coordinator.js\";\n\nexport interface VoiceInputProviderProps {\n readonly provider: VoiceInputProviderV1;\n readonly audioSource?: VoiceAudioSource;\n readonly children?: ReactNode;\n}\n\nexport interface VoiceInputContextValue {\n readonly provider: VoiceInputProviderV1;\n readonly audioSource: VoiceAudioSource;\n readonly coordinator: VoiceInputCoordinator;\n}\n\nexport const VoiceInputContext = createContext<VoiceInputContextValue | null>(\n null,\n);\n\nexport function VoiceInputProvider({\n provider,\n audioSource,\n children,\n}: VoiceInputProviderProps): ReactNode {\n const browserAudioSource = useMemo(() => createBrowserAudioSource(), []);\n const resolvedAudioSource = audioSource ?? browserAudioSource;\n const coordinator = useMemo(() => new VoiceInputCoordinator(), []);\n const value = useMemo<VoiceInputContextValue>(\n () => ({\n provider,\n audioSource: resolvedAudioSource,\n coordinator,\n }),\n [coordinator, provider, resolvedAudioSource],\n );\n\n return (\n <VoiceInputContext.Provider value={value}>\n {children}\n </VoiceInputContext.Provider>\n );\n}\n","import {\n VoiceInputError,\n createBrowserAudioSource,\n createVoiceInputSession,\n createVoiceInputTextEngine,\n getBrowserVoiceInputSupport,\n type VoiceInputSessionEvent,\n type VoiceInputStatus,\n type VoiceInputStopReason,\n type VoiceInputTextTarget,\n} from \"@voiceinput/core\";\nimport {\n type ButtonHTMLAttributes,\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n useSyncExternalStore,\n} from \"react\";\n\nimport {\n type CoordinatedVoiceInputSession,\n VoiceInputCoordinator,\n} from \"./coordinator.js\";\nimport { VoiceInputContext } from \"./context.js\";\nimport type {\n UseVoiceInputOptions,\n UseVoiceInputResult,\n VoiceInputTriggerProps,\n} from \"./types.js\";\n\nconst ACTIVE_KEYS = new Set([\"Enter\", \" \"]);\nconst useIsomorphicLayoutEffect =\n typeof window === \"undefined\" ? useEffect : useLayoutEffect;\n\nexport function useVoiceInput(\n options: UseVoiceInputOptions = {},\n): UseVoiceInputResult {\n return useVoiceInputInternal(options);\n}\n\nexport function useVoiceInputInternal(\n options: UseVoiceInputOptions = {},\n dispatchInput = false,\n): UseVoiceInputResult {\n const context = useContext(VoiceInputContext);\n const provider = options.provider ?? context?.provider;\n if (provider === undefined) {\n throw new VoiceInputError({\n code: \"invalid-configuration\",\n message:\n \"useVoiceInput requires a provider option or a parent VoiceInputProvider.\",\n });\n }\n\n const controlled =\n options.value !== undefined || options.onValueChange !== undefined;\n if (\n controlled &&\n (typeof options.value !== \"string\" ||\n typeof options.onValueChange !== \"function\")\n ) {\n throw new VoiceInputError({\n code: \"invalid-configuration\",\n message:\n \"Controlled voice input requires both value and onValueChange options.\",\n });\n }\n\n const initialControlled = useRef(controlled);\n if (initialControlled.current !== controlled) {\n throw new VoiceInputError({\n code: \"invalid-configuration\",\n message:\n \"A voice field cannot switch between controlled and uncontrolled modes. Remount it with a new key.\",\n });\n }\n const latest = useRef(options);\n latest.current = options;\n const disabled = options.disabled ?? false;\n const disabledRef = useRef(disabled);\n disabledRef.current = disabled;\n const disposedRef = useRef(false);\n const selectionCapturedRef = useRef(false);\n const heldPointerRef = useRef<number | null>(null);\n const heldKeyRef = useRef<string | null>(null);\n const targetNodeRef = useRef<VoiceInputTextTarget | null>(null);\n\n const browserAudioSource = useMemo(() => createBrowserAudioSource(), []);\n const audioSource =\n options.audioSource ?? context?.audioSource ?? browserAudioSource;\n const standaloneCoordinator = useMemo(() => new VoiceInputCoordinator(), []);\n const coordinator = context?.coordinator ?? standaloneCoordinator;\n\n const vocabularyKey = JSON.stringify(options.vocabulary ?? null);\n const vocabulary = useMemo(\n () =>\n options.vocabulary === undefined ? undefined : [...options.vocabulary],\n // The serialized key prevents inline string-array options from recreating a live session.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [vocabularyKey],\n );\n const endpointingKey = JSON.stringify(options.endpointing ?? null);\n const endpointing = useMemo(\n () =>\n typeof options.endpointing === \"object\"\n ? { ...options.endpointing }\n : options.endpointing,\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [endpointingKey],\n );\n const hasTransform = options.transformTranscript !== undefined;\n\n const [textEngine] = useState(() => {\n const nextTextEngine = createVoiceInputTextEngine({\n ...(controlled\n ? {\n controlled: {\n getValue: () => latest.current.value ?? \"\",\n dispatchInput,\n onValueChange: (value: string) =>\n latest.current.onValueChange?.(value),\n },\n }\n : {}),\n ...(options.interimBehavior === undefined\n ? {}\n : { interimBehavior: options.interimBehavior }),\n ...(!hasTransform\n ? {}\n : {\n transformTranscript: (text: string) => {\n const transform = latest.current.transformTranscript;\n if (transform === undefined) {\n throw new TypeError(\"transformTranscript is unavailable.\");\n }\n return transform(text);\n },\n }),\n ...(options.transformTimeoutMs === undefined\n ? {}\n : { transformTimeoutMs: options.transformTimeoutMs }),\n });\n return nextTextEngine;\n });\n const [session] = useState(() =>\n createVoiceInputSession({ provider, audioSource, textEngine }),\n );\n useIsomorphicLayoutEffect(() => {\n textEngine.updateOptions({\n ...(options.interimBehavior === undefined\n ? {}\n : { interimBehavior: options.interimBehavior }),\n ...(options.transformTranscript === undefined\n ? {}\n : { transformTranscript: options.transformTranscript }),\n ...(options.transformTimeoutMs === undefined\n ? {}\n : { transformTimeoutMs: options.transformTimeoutMs }),\n });\n session.updateOptions({\n provider,\n audioSource,\n ...(options.language === undefined ? {} : { language: options.language }),\n ...(vocabulary === undefined ? {} : { vocabulary }),\n ...(endpointing === undefined ? {} : { endpointing }),\n ...(options.maxDurationMs === undefined\n ? {}\n : { maxDurationMs: options.maxDurationMs }),\n ...(options.connectionTimeoutMs === undefined\n ? {}\n : { connectionTimeoutMs: options.connectionTimeoutMs }),\n });\n }, [\n session,\n provider,\n audioSource,\n textEngine,\n options.language,\n vocabulary,\n endpointing,\n options.maxDurationMs,\n options.connectionTimeoutMs,\n options.interimBehavior,\n options.transformTranscript,\n options.transformTimeoutMs,\n ]);\n const currentTextEngineRef = useRef(textEngine);\n currentTextEngineRef.current = textEngine;\n const undo = useCallback(() => textEngine.undo(), [textEngine]);\n const redo = useCallback(() => textEngine.redo(), [textEngine]);\n const getTextSnapshot = useCallback(\n () => textEngine.getSnapshot(),\n [textEngine],\n );\n\n useEffect(\n () => () => {\n queueMicrotask(() => {\n if (\n disposedRef.current ||\n currentTextEngineRef.current !== textEngine\n ) {\n textEngine.destroy();\n }\n });\n },\n [textEngine],\n );\n\n const coordinatedSession = useMemo<CoordinatedVoiceInputSession>(\n () => ({ stop: (reason) => session.stop(reason) }),\n [session],\n );\n\n const subscribe = useCallback(\n (listener: () => void) => session.subscribe(() => listener()),\n [session],\n );\n const getSnapshot = useCallback(() => session.getSnapshot(), [session]);\n const snapshot = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n const [isSupported, setIsSupported] = useState(false);\n\n useEffect(() => {\n setIsSupported(getBrowserVoiceInputSupport().isSupported);\n }, []);\n\n useIsomorphicLayoutEffect(() => {\n if (controlled) {\n textEngine.reconcileControlledValue(latest.current.value ?? \"\");\n }\n }, [controlled, options.value, textEngine]);\n\n useEffect(() => {\n return session.subscribe((event) => {\n dispatchCallback(latest.current, event);\n if (\n (event.type === \"status-change\" && event.status === \"error\") ||\n event.type === \"stop\" ||\n event.type === \"cancel\"\n ) {\n coordinator.release(coordinatedSession);\n }\n });\n }, [coordinatedSession, coordinator, session]);\n\n const captureSelection = useCallback(() => {\n selectionCapturedRef.current = textEngine.captureSelection() !== null;\n }, [textEngine]);\n\n const startInternal = useCallback(\n async (capture = true): Promise<void> => {\n if (\n disabledRef.current ||\n disposedRef.current ||\n (targetNodeRef.current !== null && !textEngine.isWritable())\n ) {\n return;\n }\n if (capture && !selectionCapturedRef.current) {\n captureSelection();\n }\n selectionCapturedRef.current = false;\n const acquired = await coordinator.activate(coordinatedSession);\n if (!acquired) {\n return;\n }\n if (\n disabledRef.current ||\n disposedRef.current ||\n (targetNodeRef.current !== null && !textEngine.isWritable())\n ) {\n coordinator.release(coordinatedSession);\n return;\n }\n await session.start();\n const status = session.getSnapshot().status;\n if (status === \"idle\" || status === \"error\") {\n coordinator.release(coordinatedSession);\n }\n },\n [captureSelection, coordinatedSession, coordinator, session, textEngine],\n );\n\n const start = useCallback(() => startInternal(true), [startInternal]);\n const stop = useCallback(\n async (reason: VoiceInputStopReason = \"user\") => {\n await session.stop(reason);\n coordinator.release(coordinatedSession);\n },\n [coordinatedSession, coordinator, session],\n );\n const cancel = useCallback(async () => {\n await session.cancel();\n coordinator.release(coordinatedSession);\n }, [coordinatedSession, coordinator, session]);\n const toggle = useCallback(async () => {\n const status = session.getSnapshot().status;\n if (status === \"idle\" || status === \"error\") {\n await startInternal(true);\n } else {\n await stop();\n }\n }, [session, startInternal, stop]);\n\n const targetRef = useCallback(\n (target: VoiceInputTextTarget | null) => {\n const previousTarget = targetNodeRef.current;\n targetNodeRef.current = target;\n if (target === null && previousTarget !== null) {\n void stop(\"replaced\");\n }\n textEngine.setTarget(target);\n },\n [stop, textEngine],\n );\n\n useEffect(() => {\n disposedRef.current = false;\n return () => {\n disposedRef.current = true;\n coordinator.cancel(coordinatedSession);\n void session.stop(\"replaced\").then(\n () => coordinator.release(coordinatedSession),\n () => coordinator.release(coordinatedSession),\n );\n };\n }, [coordinatedSession, coordinator, session]);\n\n const releaseHold = useCallback(() => {\n if (heldPointerRef.current === null && heldKeyRef.current === null) {\n return;\n }\n heldPointerRef.current = null;\n heldKeyRef.current = null;\n void stop();\n }, [stop]);\n\n useEffect(() => {\n if (disabled) {\n releaseHold();\n }\n }, [disabled, releaseHold]);\n\n useEffect(() => {\n window.addEventListener(\"blur\", releaseHold);\n return () => window.removeEventListener(\"blur\", releaseHold);\n }, [releaseHold]);\n\n const [targetWritable, setTargetWritable] = useState(true);\n useIsomorphicLayoutEffect(() => {\n const target = targetNodeRef.current;\n const update = (): void =>\n setTargetWritable(target === null || textEngine.isWritable());\n update();\n if (target === null) return;\n const observer = new MutationObserver(update);\n observer.observe(target, {\n attributes: true,\n attributeFilter: [\"disabled\", \"readonly\", \"type\"],\n });\n for (\n let ancestor = target.parentElement;\n ancestor;\n ancestor = ancestor.parentElement\n ) {\n observer.observe(ancestor, {\n attributes: true,\n attributeFilter: [\"disabled\"],\n });\n }\n return () => observer.disconnect();\n });\n useEffect(() => {\n if (disabled || !targetWritable) void stop(\"target-unavailable\");\n }, [disabled, targetWritable, stop]);\n const resolvedDisabled = disabled || !targetWritable || !isSupported;\n const active = snapshot.status !== \"idle\" && snapshot.status !== \"error\";\n const activationMode = options.activationMode ?? \"toggle\";\n const triggerProps = useMemo<VoiceInputTriggerProps>(\n () => ({\n type: \"button\",\n disabled: resolvedDisabled,\n \"aria-pressed\": active,\n onPointerDown(event) {\n if (resolvedDisabled || event.button !== 0) {\n return;\n }\n event.preventDefault();\n if (isStartable(session.getSnapshot().status)) {\n captureSelection();\n }\n if (activationMode === \"hold\") {\n heldPointerRef.current = event.pointerId;\n try {\n event.currentTarget.setPointerCapture?.(event.pointerId);\n } catch {\n // Pointer capture is an enhancement; some synthetic or older\n // browser pointer implementations reject it.\n }\n void startInternal(false);\n }\n },\n onPointerUp(event) {\n if (\n activationMode === \"hold\" &&\n heldPointerRef.current === event.pointerId\n ) {\n heldPointerRef.current = null;\n try {\n event.currentTarget.releasePointerCapture?.(event.pointerId);\n } catch {\n // The pointer may already have been released by the browser.\n }\n void stop();\n }\n },\n onPointerCancel(event) {\n if (\n activationMode === \"hold\" &&\n heldPointerRef.current === event.pointerId\n ) {\n heldPointerRef.current = null;\n void stop();\n }\n },\n onLostPointerCapture() {\n releaseHold();\n },\n onBlur() {\n if (heldKeyRef.current !== null) {\n releaseHold();\n }\n },\n onClick(event) {\n if (resolvedDisabled || activationMode === \"hold\") {\n event.preventDefault();\n return;\n }\n void toggle();\n },\n onKeyDown(event) {\n if (resolvedDisabled || !ACTIVE_KEYS.has(event.key) || event.repeat) {\n return;\n }\n if (isStartable(session.getSnapshot().status)) {\n captureSelection();\n }\n if (activationMode === \"hold\") {\n event.preventDefault();\n heldKeyRef.current = event.key;\n void startInternal(false);\n }\n },\n onKeyUp(event) {\n if (activationMode === \"hold\" && heldKeyRef.current === event.key) {\n event.preventDefault();\n heldKeyRef.current = null;\n void stop();\n }\n },\n }),\n [\n activationMode,\n active,\n captureSelection,\n releaseHold,\n resolvedDisabled,\n session,\n startInternal,\n stop,\n toggle,\n ],\n );\n const getTriggerProps = useCallback(\n (props: ButtonHTMLAttributes<HTMLButtonElement> = {}) =>\n composeTriggerProps(triggerProps, props),\n [triggerProps],\n );\n\n return useMemo(\n () => ({\n ...snapshot,\n targetRef,\n triggerProps,\n getTriggerProps,\n isSupported,\n getTextSnapshot,\n undo,\n redo,\n start,\n stop,\n cancel,\n toggle,\n }),\n [\n cancel,\n getTriggerProps,\n getTextSnapshot,\n undo,\n redo,\n isSupported,\n snapshot,\n start,\n stop,\n targetRef,\n toggle,\n triggerProps,\n ],\n );\n}\n\nfunction composeTriggerProps(\n trigger: VoiceInputTriggerProps,\n props: ButtonHTMLAttributes<HTMLButtonElement>,\n): ButtonHTMLAttributes<HTMLButtonElement> & VoiceInputTriggerProps {\n return {\n ...props,\n type: props.type ?? trigger.type,\n disabled: props.disabled === true || trigger.disabled,\n \"aria-pressed\": trigger[\"aria-pressed\"],\n onBlur: composeEventHandlers(props.onBlur, trigger.onBlur),\n onClick: composeEventHandlers(props.onClick, trigger.onClick),\n onKeyDown: composeEventHandlers(props.onKeyDown, trigger.onKeyDown),\n onKeyUp: composeEventHandlers(props.onKeyUp, trigger.onKeyUp),\n onLostPointerCapture: composeEventHandlers(\n props.onLostPointerCapture,\n trigger.onLostPointerCapture,\n ),\n onPointerCancel: composeEventHandlers(\n props.onPointerCancel,\n trigger.onPointerCancel,\n ),\n onPointerDown: composeEventHandlers(\n props.onPointerDown,\n trigger.onPointerDown,\n ),\n onPointerUp: composeEventHandlers(props.onPointerUp, trigger.onPointerUp),\n };\n}\n\nfunction composeEventHandlers<E extends { readonly defaultPrevented: boolean }>(\n consumer: ((event: E) => void) | undefined,\n internal: (event: E) => void,\n): (event: E) => void {\n return (event) => {\n consumer?.(event);\n if (!event.defaultPrevented) internal(event);\n };\n}\n\nfunction isStartable(status: VoiceInputStatus): boolean {\n return status === \"idle\" || status === \"error\";\n}\n\nfunction dispatchCallback(\n callbacks: UseVoiceInputOptions,\n event: VoiceInputSessionEvent,\n): void {\n callbacks.onEvent?.(event);\n switch (event.type) {\n case \"status-change\": {\n callbacks.onStatusChange?.(event.status, event.previousStatus);\n break;\n }\n case \"interim\": {\n callbacks.onInterimTranscript?.(event.text);\n if (event.transcriptChanged) {\n callbacks.onTranscriptChange?.(event.transcript);\n }\n break;\n }\n case \"final\": {\n callbacks.onFinalTranscriptPart?.(event.text);\n if (event.finalTranscriptChanged) {\n callbacks.onFinalTranscript?.(event.transcript);\n }\n if (event.transcriptChanged) {\n callbacks.onTranscriptChange?.(event.transcript);\n }\n break;\n }\n case \"text-limit\": {\n callbacks.onTextLimit?.(event);\n break;\n }\n case \"duration-warning\": {\n callbacks.onDurationWarning?.(event.remainingMs, event.maxDurationMs);\n break;\n }\n case \"stop\": {\n callbacks.onStop?.(event.reason);\n break;\n }\n case \"error\": {\n callbacks.onError?.(event.error);\n break;\n }\n case \"cancel\": {\n break;\n }\n case \"speech-start\":\n case \"speech-end\": {\n break;\n }\n }\n}\n","import {\n forwardRef,\n useCallback,\n useId,\n useImperativeHandle,\n useRef,\n type ButtonHTMLAttributes,\n type CSSProperties,\n type ForwardedRef,\n type InputHTMLAttributes,\n type ReactNode,\n type RefCallback,\n type TextareaHTMLAttributes,\n} from \"react\";\n\nimport type { UseVoiceInputOptions, UseVoiceInputResult } from \"./types.js\";\nimport { useVoiceInput, useVoiceInputInternal } from \"./use-voice-input.js\";\n\nexport type VoiceButtonChildren =\n ReactNode | ((voice: UseVoiceInputResult) => ReactNode);\n\nexport interface VoiceButtonProps extends Omit<\n ButtonHTMLAttributes<HTMLButtonElement>,\n \"children\"\n> {\n /** Options passed directly to the underlying useVoiceInput call. */\n readonly voice?: UseVoiceInputOptions;\n readonly children?: VoiceButtonChildren;\n /** Set false when the application provides its own live region. */\n readonly announce?: boolean;\n readonly getAnnouncement?: (voice: UseVoiceInputResult) => string;\n}\n\nexport interface VoiceFieldButtonProps extends Omit<\n ButtonHTMLAttributes<HTMLButtonElement>,\n \"children\"\n> {\n readonly children?: VoiceButtonChildren;\n readonly announce?: boolean;\n readonly getAnnouncement?: (voice: UseVoiceInputResult) => string;\n}\n\ninterface SharedVoiceFieldOptions {\n /** Options passed directly to the underlying useVoiceInput call. */\n readonly voice?: Omit<UseVoiceInputOptions, \"value\" | \"onValueChange\">;\n readonly containerClassName?: string;\n readonly voiceButtonProps?: VoiceFieldButtonProps;\n}\n\ntype VoiceFieldBinding =\n | {\n readonly value: string;\n readonly onValueChange: (value: string) => void;\n }\n | {\n readonly value?: never;\n readonly onValueChange?: never;\n };\n\nexport type VoiceInputProps = Omit<\n InputHTMLAttributes<HTMLInputElement>,\n \"children\" | \"type\" | \"value\"\n> &\n SharedVoiceFieldOptions &\n VoiceFieldBinding & {\n readonly type?: \"search\" | \"tel\" | \"text\" | \"url\";\n };\n\nexport type VoiceTextareaProps = Omit<\n TextareaHTMLAttributes<HTMLTextAreaElement>,\n \"children\" | \"value\"\n> &\n SharedVoiceFieldOptions &\n VoiceFieldBinding;\n\nconst visuallyHiddenStyle: CSSProperties = {\n border: 0,\n clip: \"rect(0 0 0 0)\",\n clipPath: \"inset(50%)\",\n height: 1,\n margin: -1,\n overflow: \"hidden\",\n padding: 0,\n position: \"absolute\",\n whiteSpace: \"nowrap\",\n width: 1,\n};\n\nexport const VoiceButton = /* @__PURE__ */ forwardRef<\n HTMLButtonElement,\n VoiceButtonProps\n>(function VoiceButton({ voice: options, ...props }, forwardedRef) {\n const voice = useVoiceInput({\n ...options,\n disabled: props.disabled === true || options?.disabled === true,\n });\n return <VoiceButtonElement {...props} ref={forwardedRef} voice={voice} />;\n});\n\nexport const VoiceInput = /* @__PURE__ */ forwardRef<\n HTMLInputElement,\n VoiceInputProps\n>(function VoiceInput(\n {\n className,\n containerClassName,\n disabled,\n readOnly,\n onChange,\n onValueChange,\n type = \"text\",\n value,\n voice: options,\n voiceButtonProps,\n ...props\n },\n forwardedRef,\n) {\n const voice = useVoiceField({\n disabled:\n disabled === true ||\n readOnly === true ||\n voiceButtonProps?.disabled === true,\n onValueChange,\n options,\n value,\n });\n const targetRef = useComposedTargetRef(voice, forwardedRef);\n return (\n <span\n className={joinClassNames(\"voiceinput-field\", containerClassName)}\n {...voiceDataAttributes(voice)}\n >\n <input\n {...props}\n ref={targetRef}\n className={joinClassNames(\"voiceinput-field__input\", className)}\n disabled={disabled}\n readOnly={readOnly}\n onChange={(event) => {\n onValueChange?.(event.currentTarget.value);\n onChange?.(event);\n }}\n type={type}\n value={value}\n />\n <VoiceButtonElement\n {...voiceButtonProps}\n className={joinClassNames(\n \"voiceinput-field__button\",\n voiceButtonProps?.className,\n )}\n voice={voice}\n />\n </span>\n );\n});\n\nexport const VoiceTextarea = /* @__PURE__ */ forwardRef<\n HTMLTextAreaElement,\n VoiceTextareaProps\n>(function VoiceTextarea(\n {\n className,\n containerClassName,\n disabled,\n readOnly,\n onChange,\n onValueChange,\n value,\n voice: options,\n voiceButtonProps,\n ...props\n },\n forwardedRef,\n) {\n const voice = useVoiceField({\n disabled:\n disabled === true ||\n readOnly === true ||\n voiceButtonProps?.disabled === true,\n onValueChange,\n options,\n value,\n });\n const targetRef = useComposedTargetRef(voice, forwardedRef);\n return (\n <span\n className={joinClassNames(\n \"voiceinput-field voiceinput-field--textarea\",\n containerClassName,\n )}\n {...voiceDataAttributes(voice)}\n >\n <textarea\n {...props}\n ref={targetRef}\n className={joinClassNames(\"voiceinput-field__input\", className)}\n disabled={disabled}\n readOnly={readOnly}\n onChange={(event) => {\n onValueChange?.(event.currentTarget.value);\n onChange?.(event);\n }}\n value={value}\n />\n <VoiceButtonElement\n {...voiceButtonProps}\n className={joinClassNames(\n \"voiceinput-field__button\",\n voiceButtonProps?.className,\n )}\n voice={voice}\n />\n </span>\n );\n});\n\ninterface VoiceButtonElementProps extends VoiceFieldButtonProps {\n readonly voice: UseVoiceInputResult;\n}\n\nconst VoiceButtonElement = /* @__PURE__ */ forwardRef<\n HTMLButtonElement,\n VoiceButtonElementProps\n>(function VoiceButtonElement(\n {\n announce = true,\n children,\n className,\n disabled,\n getAnnouncement = defaultAnnouncement,\n onBlur,\n onClick,\n onKeyDown,\n onKeyUp,\n onLostPointerCapture,\n onPointerCancel,\n onPointerDown,\n onPointerUp,\n type,\n voice,\n ...props\n },\n forwardedRef,\n) {\n const announcementId = useId();\n const active = isActive(voice);\n const label = defaultButtonLabel(voice);\n const describedBy = [props[\"aria-describedby\"], announce && announcementId]\n .filter(Boolean)\n .join(\" \");\n const trigger = voice.triggerProps;\n\n return (\n <>\n <button\n {...props}\n {...voiceDataAttributes(voice)}\n ref={forwardedRef}\n aria-describedby={describedBy || undefined}\n aria-label={props[\"aria-label\"] ?? label}\n aria-pressed={trigger[\"aria-pressed\"]}\n className={joinClassNames(\"voiceinput-button\", className)}\n disabled={disabled === true || trigger.disabled}\n type={type ?? trigger.type}\n onBlur={composeEventHandlers(onBlur, trigger.onBlur)}\n onClick={composeEventHandlers(onClick, trigger.onClick)}\n onKeyDown={composeEventHandlers(onKeyDown, trigger.onKeyDown)}\n onKeyUp={composeEventHandlers(onKeyUp, trigger.onKeyUp)}\n onLostPointerCapture={composeEventHandlers(\n onLostPointerCapture,\n trigger.onLostPointerCapture,\n )}\n onPointerCancel={composeEventHandlers(\n onPointerCancel,\n trigger.onPointerCancel,\n )}\n onPointerDown={composeEventHandlers(\n onPointerDown,\n trigger.onPointerDown,\n )}\n onPointerUp={composeEventHandlers(onPointerUp, trigger.onPointerUp)}\n >\n {typeof children === \"function\"\n ? children(voice)\n : (children ?? (\n <DefaultButtonContent active={active} label={label} />\n ))}\n </button>\n {announce ? (\n <span\n id={announcementId}\n aria-live={voice.error === null ? \"polite\" : \"assertive\"}\n className=\"voiceinput-sr-only\"\n role={voice.error === null ? \"status\" : \"alert\"}\n style={visuallyHiddenStyle}\n >\n {getAnnouncement(voice)}\n </span>\n ) : null}\n </>\n );\n});\n\nfunction DefaultButtonContent({\n active,\n label,\n}: {\n readonly active: boolean;\n readonly label: string;\n}): ReactNode {\n return (\n <>\n <span aria-hidden=\"true\" className=\"voiceinput-button__icon\">\n {active ? <StopIcon /> : <MicrophoneIcon />}\n </span>\n <span className=\"voiceinput-button__label\">{label}</span>\n </>\n );\n}\n\nfunction MicrophoneIcon(): ReactNode {\n return (\n <svg viewBox=\"0 0 24 24\" width=\"18\" height=\"18\" fill=\"none\">\n <path\n d=\"M12 3a3 3 0 0 0-3 3v6a3 3 0 1 0 6 0V6a3 3 0 0 0-3-3Z\"\n fill=\"currentColor\"\n />\n <path\n d=\"M6.5 11.5a5.5 5.5 0 0 0 11 0M12 17v4m-3 0h6\"\n stroke=\"currentColor\"\n strokeWidth=\"1.75\"\n strokeLinecap=\"round\"\n />\n </svg>\n );\n}\n\nfunction StopIcon(): ReactNode {\n return (\n <svg viewBox=\"0 0 24 24\" width=\"18\" height=\"18\" fill=\"none\">\n <rect x=\"6\" y=\"6\" width=\"12\" height=\"12\" rx=\"2\" fill=\"currentColor\" />\n </svg>\n );\n}\n\nfunction useVoiceField(options: {\n readonly disabled: boolean | undefined;\n readonly onValueChange: ((value: string) => void) | undefined;\n readonly options:\n Omit<UseVoiceInputOptions, \"value\" | \"onValueChange\"> | undefined;\n readonly value: string | undefined;\n}): UseVoiceInputResult {\n const controlled =\n options.value !== undefined || options.onValueChange !== undefined;\n return useVoiceInputInternal(\n {\n ...options.options,\n disabled: options.disabled === true || options.options?.disabled === true,\n ...(controlled && options.value !== undefined\n ? { value: options.value }\n : {}),\n ...(controlled && options.onValueChange !== undefined\n ? { onValueChange: options.onValueChange }\n : {}),\n },\n true,\n );\n}\n\nfunction useComposedTargetRef<T extends HTMLInputElement | HTMLTextAreaElement>(\n voice: UseVoiceInputResult,\n forwardedRef: ForwardedRef<T>,\n): RefCallback<T> {\n const { targetRef } = voice;\n const nodeRef = useRef<T | null>(null);\n\n useImperativeHandle(forwardedRef, () => nodeRef.current as T, []);\n\n return useCallback(\n (node: T | null) => {\n nodeRef.current = node;\n targetRef(node);\n },\n [targetRef],\n );\n}\n\nfunction voiceDataAttributes(\n voice: UseVoiceInputResult,\n): Record<string, string> {\n return {\n \"data-voiceinput-active\": String(isActive(voice)),\n \"data-voiceinput-error\": voice.error?.code ?? \"\",\n \"data-voiceinput-status\": voice.status,\n \"data-voiceinput-supported\": String(voice.isSupported),\n };\n}\n\nfunction isActive(voice: UseVoiceInputResult): boolean {\n return voice.status !== \"error\" && voice.status !== \"idle\";\n}\n\nfunction defaultButtonLabel(voice: UseVoiceInputResult): string {\n if (!voice.isSupported) {\n return \"Voice input unavailable\";\n }\n switch (voice.status) {\n case \"requesting-permission\":\n return \"Requesting access\";\n case \"connecting\":\n return \"Connecting\";\n case \"listening\":\n return \"Stop voice input\";\n case \"stopping\":\n return \"Finishing\";\n case \"processing\":\n return \"Processing\";\n case \"error\":\n case \"idle\":\n return \"Start voice input\";\n }\n}\n\nfunction defaultAnnouncement(voice: UseVoiceInputResult): string {\n if (!voice.isSupported) {\n return \"Voice input is unavailable in this browser.\";\n }\n if (voice.error !== null) {\n return `Voice input error: ${voice.error.message}`;\n }\n switch (voice.status) {\n case \"idle\":\n return \"Voice input ready.\";\n case \"requesting-permission\":\n return \"Requesting microphone permission.\";\n case \"connecting\":\n return \"Connecting voice input.\";\n case \"listening\":\n return \"Voice input is listening.\";\n case \"stopping\":\n return \"Finishing voice input.\";\n case \"processing\":\n return \"Processing the transcript.\";\n case \"error\":\n return \"Voice input stopped with an error.\";\n }\n}\n\ntype SupportedEvent = {\n readonly defaultPrevented: boolean;\n};\n\nfunction composeEventHandlers<E extends SupportedEvent>(\n consumer: ((event: E) => void) | undefined,\n internal: (event: E) => void,\n): (event: E) => void {\n return (event) => {\n consumer?.(event);\n if (!event.defaultPrevented) {\n internal(event);\n }\n };\n}\n\nfunction joinClassNames(...values: Array<string | undefined>): string {\n return values.filter(Boolean).join(\" \");\n}\n"],"mappings":";;;;;;AAMA,IAAa,wBAAb,MAAmC;CACjC;CACA;CACA,cAAc;CACd,SAAwB,QAAQ,QAAQ;CAExC,SAAS,SAAyD;EAChE,MAAM,aAAa,EAAE,KAAKA;EAC1B,KAAKC,aAAa;EAClB,MAAM,aAAa,KAAKC,OAAO,KAAK,YAAY;GAC9C,IAAI,CAAC,KAAKC,kBAAkB,SAAS,UAAU,GAC7C,OAAO;GAGT,MAAM,WAAW,KAAKC;GACtB,IAAI,aAAa,KAAA,KAAa,aAAa,SAAS;IAClD,IAAI;KACF,MAAM,SAAS,KAAK,UAAU;IAChC,SAAS,OAAO;KACd,qBAAqB,KAAK;IAC5B;IACA,IAAI,KAAKA,YAAY,UACnB,KAAKA,UAAU,KAAA;GAEnB;GAEA,IAAI,CAAC,KAAKD,kBAAkB,SAAS,UAAU,GAC7C,OAAO;GAET,KAAKC,UAAU;GACf,OAAO;EACT,CAAC;EACD,KAAKF,SAAS,WAAW,WACjB,CAAC,SACD,CAAC,CACT;EACA,OAAO;CACT;CAEA,QAAQ,SAA6C;EACnD,KAAK,OAAO,OAAO;EACnB,IAAI,KAAKE,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;EAChB,IAAI,CAAC,MAAM,kBACT,SAAS,KAAK;CAElB;AACF;AAEA,SAAS,eAAe,GAAG,QAA2C;CACpE,OAAO,OAAO,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;AACxC"}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { VoiceAudioSource, VoiceInputError, VoiceInputError as VoiceInputError$1, VoiceInputInterimBehavior, VoiceInputSessionEvent, VoiceInputSessionEvent as VoiceInputSessionEvent$1, VoiceInputSnapshot, VoiceInputSnapshot as VoiceInputSnapshot$1, VoiceInputStatus, VoiceInputStatus as VoiceInputStatus$1, VoiceInputStopReason, VoiceInputStopReason as VoiceInputStopReason$1, VoiceInputTextEngineSnapshot, VoiceInputTextLimit, VoiceInputTextLimit as VoiceInputTextLimit$1, VoiceInputTextTarget, VoiceInputTransformTranscript } from "@voiceinput/core";
|
|
2
|
+
import { VoiceEndpointingOptions, VoiceEndpointingOptions as VoiceEndpointingOptions$1, VoiceInputProviderV1, VoiceInputProviderV1 as VoiceInputProviderV1$1 } from "@voiceinput/provider";
|
|
3
|
+
import { ButtonHTMLAttributes, FocusEventHandler, InputHTMLAttributes, KeyboardEventHandler, MouseEventHandler, PointerEventHandler, ReactNode, RefCallback, TextareaHTMLAttributes } from "react";
|
|
4
|
+
//#region src/context.d.ts
|
|
5
|
+
interface VoiceInputProviderProps {
|
|
6
|
+
readonly provider: VoiceInputProviderV1$1;
|
|
7
|
+
readonly audioSource?: VoiceAudioSource;
|
|
8
|
+
readonly children?: ReactNode;
|
|
9
|
+
}
|
|
10
|
+
declare function VoiceInputProvider({ provider, audioSource, children }: VoiceInputProviderProps): ReactNode;
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/types.d.ts
|
|
13
|
+
type VoiceInputActivationMode = "toggle" | "hold";
|
|
14
|
+
interface UseVoiceInputCommonOptions {
|
|
15
|
+
provider?: VoiceInputProviderV1$1;
|
|
16
|
+
audioSource?: VoiceAudioSource;
|
|
17
|
+
language?: string;
|
|
18
|
+
vocabulary?: readonly string[];
|
|
19
|
+
endpointing?: false | VoiceEndpointingOptions$1;
|
|
20
|
+
maxDurationMs?: number;
|
|
21
|
+
connectionTimeoutMs?: number;
|
|
22
|
+
interimBehavior?: VoiceInputInterimBehavior;
|
|
23
|
+
transformTranscript?: VoiceInputTransformTranscript;
|
|
24
|
+
transformTimeoutMs?: number;
|
|
25
|
+
activationMode?: VoiceInputActivationMode;
|
|
26
|
+
disabled?: boolean;
|
|
27
|
+
onTextLimit?: (event: VoiceInputTextLimit$1) => void;
|
|
28
|
+
onEvent?: (event: VoiceInputSessionEvent$1) => void;
|
|
29
|
+
onStatusChange?: (status: VoiceInputStatus$1, previousStatus: VoiceInputStatus$1) => void;
|
|
30
|
+
onInterimTranscript?: (text: string) => void;
|
|
31
|
+
onFinalTranscriptPart?: (text: string) => void;
|
|
32
|
+
onFinalTranscript?: (transcript: string) => void;
|
|
33
|
+
onTranscriptChange?: (transcript: string) => void;
|
|
34
|
+
onDurationWarning?: (remainingMs: number, maxDurationMs: number) => void;
|
|
35
|
+
onStop?: (reason: VoiceInputStopReason$1) => void;
|
|
36
|
+
onError?: (error: VoiceInputError$1) => void;
|
|
37
|
+
}
|
|
38
|
+
type UseVoiceInputOptions = UseVoiceInputCommonOptions & ({
|
|
39
|
+
readonly value: string;
|
|
40
|
+
readonly onValueChange: (value: string) => void;
|
|
41
|
+
} | {
|
|
42
|
+
readonly value?: never;
|
|
43
|
+
readonly onValueChange?: never;
|
|
44
|
+
});
|
|
45
|
+
interface VoiceInputTriggerProps extends Pick<ButtonHTMLAttributes<HTMLButtonElement>, "aria-pressed" | "disabled" | "type"> {
|
|
46
|
+
onBlur: FocusEventHandler<HTMLButtonElement>;
|
|
47
|
+
onClick: MouseEventHandler<HTMLButtonElement>;
|
|
48
|
+
onKeyDown: KeyboardEventHandler<HTMLButtonElement>;
|
|
49
|
+
onKeyUp: KeyboardEventHandler<HTMLButtonElement>;
|
|
50
|
+
onPointerCancel: PointerEventHandler<HTMLButtonElement>;
|
|
51
|
+
onPointerDown: PointerEventHandler<HTMLButtonElement>;
|
|
52
|
+
onLostPointerCapture: PointerEventHandler<HTMLButtonElement>;
|
|
53
|
+
onPointerUp: PointerEventHandler<HTMLButtonElement>;
|
|
54
|
+
}
|
|
55
|
+
interface UseVoiceInputResult extends VoiceInputSnapshot$1 {
|
|
56
|
+
readonly targetRef: RefCallback<VoiceInputTextTarget>;
|
|
57
|
+
/** Prefer getTriggerProps when adding application event handlers. */
|
|
58
|
+
readonly triggerProps: VoiceInputTriggerProps;
|
|
59
|
+
readonly isSupported: boolean;
|
|
60
|
+
getTriggerProps(this: void, props?: ButtonHTMLAttributes<HTMLButtonElement>): ButtonHTMLAttributes<HTMLButtonElement> & VoiceInputTriggerProps;
|
|
61
|
+
getTextSnapshot(this: void): VoiceInputTextEngineSnapshot;
|
|
62
|
+
start(this: void): Promise<void>;
|
|
63
|
+
stop(this: void, reason?: VoiceInputStopReason$1): Promise<void>;
|
|
64
|
+
cancel(this: void): Promise<void>;
|
|
65
|
+
undo(this: void): void;
|
|
66
|
+
redo(this: void): void;
|
|
67
|
+
toggle(this: void): Promise<void>;
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/components.d.ts
|
|
71
|
+
type VoiceButtonChildren = ReactNode | ((voice: UseVoiceInputResult) => ReactNode);
|
|
72
|
+
interface VoiceButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, "children"> {
|
|
73
|
+
/** Options passed directly to the underlying useVoiceInput call. */
|
|
74
|
+
readonly voice?: UseVoiceInputOptions;
|
|
75
|
+
readonly children?: VoiceButtonChildren;
|
|
76
|
+
/** Set false when the application provides its own live region. */
|
|
77
|
+
readonly announce?: boolean;
|
|
78
|
+
readonly getAnnouncement?: (voice: UseVoiceInputResult) => string;
|
|
79
|
+
}
|
|
80
|
+
interface VoiceFieldButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, "children"> {
|
|
81
|
+
readonly children?: VoiceButtonChildren;
|
|
82
|
+
readonly announce?: boolean;
|
|
83
|
+
readonly getAnnouncement?: (voice: UseVoiceInputResult) => string;
|
|
84
|
+
}
|
|
85
|
+
interface SharedVoiceFieldOptions {
|
|
86
|
+
/** Options passed directly to the underlying useVoiceInput call. */
|
|
87
|
+
readonly voice?: Omit<UseVoiceInputOptions, "value" | "onValueChange">;
|
|
88
|
+
readonly containerClassName?: string;
|
|
89
|
+
readonly voiceButtonProps?: VoiceFieldButtonProps;
|
|
90
|
+
}
|
|
91
|
+
type VoiceFieldBinding = {
|
|
92
|
+
readonly value: string;
|
|
93
|
+
readonly onValueChange: (value: string) => void;
|
|
94
|
+
} | {
|
|
95
|
+
readonly value?: never;
|
|
96
|
+
readonly onValueChange?: never;
|
|
97
|
+
};
|
|
98
|
+
type VoiceInputProps = Omit<InputHTMLAttributes<HTMLInputElement>, "children" | "type" | "value"> & SharedVoiceFieldOptions & VoiceFieldBinding & {
|
|
99
|
+
readonly type?: "search" | "tel" | "text" | "url";
|
|
100
|
+
};
|
|
101
|
+
type VoiceTextareaProps = Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, "children" | "value"> & SharedVoiceFieldOptions & VoiceFieldBinding;
|
|
102
|
+
declare const VoiceButton: import("react").ForwardRefExoticComponent<VoiceButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
103
|
+
declare const VoiceInput: import("react").ForwardRefExoticComponent<VoiceInputProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
104
|
+
declare const VoiceTextarea: import("react").ForwardRefExoticComponent<VoiceTextareaProps & import("react").RefAttributes<HTMLTextAreaElement>>;
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/use-voice-input.d.ts
|
|
107
|
+
declare function useVoiceInput(options?: UseVoiceInputOptions): UseVoiceInputResult;
|
|
108
|
+
//#endregion
|
|
109
|
+
export { type UseVoiceInputOptions, type UseVoiceInputResult, VoiceButton, type VoiceButtonChildren, type VoiceButtonProps, type VoiceEndpointingOptions, type VoiceFieldButtonProps, VoiceInput, type VoiceInputActivationMode, VoiceInputError, type VoiceInputProps, VoiceInputProvider, type VoiceInputProviderProps, type VoiceInputProviderV1, type VoiceInputSessionEvent, type VoiceInputSnapshot, type VoiceInputStatus, type VoiceInputStopReason, type VoiceInputTextLimit, type VoiceInputTriggerProps, VoiceTextarea, type VoiceTextareaProps, useVoiceInput };
|
|
110
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/context.tsx","../src/types.ts","../src/components.tsx","../src/use-voice-input.ts"],"mappings":";;;;UASiB;WACN,UAAU;WACV,cAAc;WACd,WAAW;;iBAaN,qBACd,UACA,aACA,YACC,0BAA0B;;;KCHjB;UAEF;EACR,WAAW;EACX,cAAc;EACd;EACA;EACA,sBAAsB;EACtB;EACA;EACA,kBAAkB;EAClB,sBAAsB;EACtB;EACA,iBAAiB;EACjB;EACA,eAAe,OAAO;EACtB,WAAW,OAAO;EAClB,kBACE,QAAQ,oBACR,gBAAgB;EAElB,uBAAuB;EACvB,yBAAyB;EACzB,qBAAqB;EACrB,sBAAsB;EACtB,qBAAqB,qBAAqB;EAC1C,UAAU,QAAQ;EAClB,WAAW,OAAO;;KAGR,uBAAuB;WAGlB;WACA,gBAAgB;;WAGhB;WACA;;UAIA,+BAA+B,KAC9C,qBAAqB;EAGrB,QAAQ,kBAAkB;EAC1B,SAAS,kBAAkB;EAC3B,WAAW,qBAAqB;EAChC,SAAS,qBAAqB;EAC9B,iBAAiB,oBAAoB;EACrC,eAAe,oBAAoB;EACnC,sBAAsB,oBAAoB;EAC1C,aAAa,oBAAoB;;UAGlB,4BAA4B;WAClC,WAAW,YAAY;;WAEvB,cAAc;WACd;EACT,gBACE,YACA,QAAQ,qBAAqB,qBAC5B,qBAAqB,qBAAqB;EAC7C,gBAAgB,aAAa;EAC7B,MAAM,aAAa;EACnB,KAAK,YAAY,SAAS,yBAAuB;EACjD,OAAO,aAAa;EACpB,KAAK;EACL,KAAK;EACL,OAAO,aAAa;;;;KC/EV,sBACV,cAAc,OAAO,wBAAwB;UAE9B,yBAAyB,KACxC,qBAAqB;;WAIZ,QAAQ;WACR,WAAW;;WAEX;WACA,mBAAmB,OAAO;;UAGpB,8BAA8B,KAC7C,qBAAqB;WAGZ,WAAW;WACX;WACA,mBAAmB,OAAO;;UAG3B;;WAEC,QAAQ,KAAK;WACb;WACA,mBAAmB;;KAGzB;WAEU;WACA,gBAAgB;;WAGhB;WACA;;KAGH,kBAAkB,KAC5B,oBAAoB,oDAGpB,0BACA;WACW;;KAGD,qBAAqB,KAC/B,uBAAuB,8CAGvB,0BACA;cAeW,6BAAW,0BAAA,mCAAA,cAAA;cAWX,4BAAU,0BAAA,kCAAA,cAAA;cA2DV,+BAAa,0BAAA,qCAAA,cAAA;;;iBCxHV,cACd,UAAS,uBACR"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { VoiceAudioSource, VoiceInputError, VoiceInputError as VoiceInputError$1, VoiceInputInterimBehavior, VoiceInputSessionEvent, VoiceInputSessionEvent as VoiceInputSessionEvent$1, VoiceInputSnapshot, VoiceInputSnapshot as VoiceInputSnapshot$1, VoiceInputStatus, VoiceInputStatus as VoiceInputStatus$1, VoiceInputStopReason, VoiceInputStopReason as VoiceInputStopReason$1, VoiceInputTextEngineSnapshot, VoiceInputTextLimit, VoiceInputTextLimit as VoiceInputTextLimit$1, VoiceInputTextTarget, VoiceInputTransformTranscript } from "@voiceinput/core";
|
|
2
|
+
import { ButtonHTMLAttributes, FocusEventHandler, InputHTMLAttributes, KeyboardEventHandler, MouseEventHandler, PointerEventHandler, ReactNode, RefCallback, TextareaHTMLAttributes } from "react";
|
|
3
|
+
import { VoiceEndpointingOptions, VoiceEndpointingOptions as VoiceEndpointingOptions$1, VoiceInputProviderV1, VoiceInputProviderV1 as VoiceInputProviderV1$1 } from "@voiceinput/provider";
|
|
4
|
+
//#region src/context.d.ts
|
|
5
|
+
interface VoiceInputProviderProps {
|
|
6
|
+
readonly provider: VoiceInputProviderV1$1;
|
|
7
|
+
readonly audioSource?: VoiceAudioSource;
|
|
8
|
+
readonly children?: ReactNode;
|
|
9
|
+
}
|
|
10
|
+
declare function VoiceInputProvider({ provider, audioSource, children }: VoiceInputProviderProps): ReactNode;
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/types.d.ts
|
|
13
|
+
type VoiceInputActivationMode = "toggle" | "hold";
|
|
14
|
+
interface UseVoiceInputCommonOptions {
|
|
15
|
+
provider?: VoiceInputProviderV1$1;
|
|
16
|
+
audioSource?: VoiceAudioSource;
|
|
17
|
+
language?: string;
|
|
18
|
+
vocabulary?: readonly string[];
|
|
19
|
+
endpointing?: false | VoiceEndpointingOptions$1;
|
|
20
|
+
maxDurationMs?: number;
|
|
21
|
+
connectionTimeoutMs?: number;
|
|
22
|
+
interimBehavior?: VoiceInputInterimBehavior;
|
|
23
|
+
transformTranscript?: VoiceInputTransformTranscript;
|
|
24
|
+
transformTimeoutMs?: number;
|
|
25
|
+
activationMode?: VoiceInputActivationMode;
|
|
26
|
+
disabled?: boolean;
|
|
27
|
+
onTextLimit?: (event: VoiceInputTextLimit$1) => void;
|
|
28
|
+
onEvent?: (event: VoiceInputSessionEvent$1) => void;
|
|
29
|
+
onStatusChange?: (status: VoiceInputStatus$1, previousStatus: VoiceInputStatus$1) => void;
|
|
30
|
+
onInterimTranscript?: (text: string) => void;
|
|
31
|
+
onFinalTranscriptPart?: (text: string) => void;
|
|
32
|
+
onFinalTranscript?: (transcript: string) => void;
|
|
33
|
+
onTranscriptChange?: (transcript: string) => void;
|
|
34
|
+
onDurationWarning?: (remainingMs: number, maxDurationMs: number) => void;
|
|
35
|
+
onStop?: (reason: VoiceInputStopReason$1) => void;
|
|
36
|
+
onError?: (error: VoiceInputError$1) => void;
|
|
37
|
+
}
|
|
38
|
+
type UseVoiceInputOptions = UseVoiceInputCommonOptions & ({
|
|
39
|
+
readonly value: string;
|
|
40
|
+
readonly onValueChange: (value: string) => void;
|
|
41
|
+
} | {
|
|
42
|
+
readonly value?: never;
|
|
43
|
+
readonly onValueChange?: never;
|
|
44
|
+
});
|
|
45
|
+
interface VoiceInputTriggerProps extends Pick<ButtonHTMLAttributes<HTMLButtonElement>, "aria-pressed" | "disabled" | "type"> {
|
|
46
|
+
onBlur: FocusEventHandler<HTMLButtonElement>;
|
|
47
|
+
onClick: MouseEventHandler<HTMLButtonElement>;
|
|
48
|
+
onKeyDown: KeyboardEventHandler<HTMLButtonElement>;
|
|
49
|
+
onKeyUp: KeyboardEventHandler<HTMLButtonElement>;
|
|
50
|
+
onPointerCancel: PointerEventHandler<HTMLButtonElement>;
|
|
51
|
+
onPointerDown: PointerEventHandler<HTMLButtonElement>;
|
|
52
|
+
onLostPointerCapture: PointerEventHandler<HTMLButtonElement>;
|
|
53
|
+
onPointerUp: PointerEventHandler<HTMLButtonElement>;
|
|
54
|
+
}
|
|
55
|
+
interface UseVoiceInputResult extends VoiceInputSnapshot$1 {
|
|
56
|
+
readonly targetRef: RefCallback<VoiceInputTextTarget>;
|
|
57
|
+
/** Prefer getTriggerProps when adding application event handlers. */
|
|
58
|
+
readonly triggerProps: VoiceInputTriggerProps;
|
|
59
|
+
readonly isSupported: boolean;
|
|
60
|
+
getTriggerProps(this: void, props?: ButtonHTMLAttributes<HTMLButtonElement>): ButtonHTMLAttributes<HTMLButtonElement> & VoiceInputTriggerProps;
|
|
61
|
+
getTextSnapshot(this: void): VoiceInputTextEngineSnapshot;
|
|
62
|
+
start(this: void): Promise<void>;
|
|
63
|
+
stop(this: void, reason?: VoiceInputStopReason$1): Promise<void>;
|
|
64
|
+
cancel(this: void): Promise<void>;
|
|
65
|
+
undo(this: void): void;
|
|
66
|
+
redo(this: void): void;
|
|
67
|
+
toggle(this: void): Promise<void>;
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/components.d.ts
|
|
71
|
+
type VoiceButtonChildren = ReactNode | ((voice: UseVoiceInputResult) => ReactNode);
|
|
72
|
+
interface VoiceButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, "children"> {
|
|
73
|
+
/** Options passed directly to the underlying useVoiceInput call. */
|
|
74
|
+
readonly voice?: UseVoiceInputOptions;
|
|
75
|
+
readonly children?: VoiceButtonChildren;
|
|
76
|
+
/** Set false when the application provides its own live region. */
|
|
77
|
+
readonly announce?: boolean;
|
|
78
|
+
readonly getAnnouncement?: (voice: UseVoiceInputResult) => string;
|
|
79
|
+
}
|
|
80
|
+
interface VoiceFieldButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, "children"> {
|
|
81
|
+
readonly children?: VoiceButtonChildren;
|
|
82
|
+
readonly announce?: boolean;
|
|
83
|
+
readonly getAnnouncement?: (voice: UseVoiceInputResult) => string;
|
|
84
|
+
}
|
|
85
|
+
interface SharedVoiceFieldOptions {
|
|
86
|
+
/** Options passed directly to the underlying useVoiceInput call. */
|
|
87
|
+
readonly voice?: Omit<UseVoiceInputOptions, "value" | "onValueChange">;
|
|
88
|
+
readonly containerClassName?: string;
|
|
89
|
+
readonly voiceButtonProps?: VoiceFieldButtonProps;
|
|
90
|
+
}
|
|
91
|
+
type VoiceFieldBinding = {
|
|
92
|
+
readonly value: string;
|
|
93
|
+
readonly onValueChange: (value: string) => void;
|
|
94
|
+
} | {
|
|
95
|
+
readonly value?: never;
|
|
96
|
+
readonly onValueChange?: never;
|
|
97
|
+
};
|
|
98
|
+
type VoiceInputProps = Omit<InputHTMLAttributes<HTMLInputElement>, "children" | "type" | "value"> & SharedVoiceFieldOptions & VoiceFieldBinding & {
|
|
99
|
+
readonly type?: "search" | "tel" | "text" | "url";
|
|
100
|
+
};
|
|
101
|
+
type VoiceTextareaProps = Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, "children" | "value"> & SharedVoiceFieldOptions & VoiceFieldBinding;
|
|
102
|
+
declare const VoiceButton: import("react").ForwardRefExoticComponent<VoiceButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
103
|
+
declare const VoiceInput: import("react").ForwardRefExoticComponent<VoiceInputProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
104
|
+
declare const VoiceTextarea: import("react").ForwardRefExoticComponent<VoiceTextareaProps & import("react").RefAttributes<HTMLTextAreaElement>>;
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/use-voice-input.d.ts
|
|
107
|
+
declare function useVoiceInput(options?: UseVoiceInputOptions): UseVoiceInputResult;
|
|
108
|
+
//#endregion
|
|
109
|
+
export { type UseVoiceInputOptions, type UseVoiceInputResult, VoiceButton, type VoiceButtonChildren, type VoiceButtonProps, type VoiceEndpointingOptions, type VoiceFieldButtonProps, VoiceInput, type VoiceInputActivationMode, VoiceInputError, type VoiceInputProps, VoiceInputProvider, type VoiceInputProviderProps, type VoiceInputProviderV1, type VoiceInputSessionEvent, type VoiceInputSnapshot, type VoiceInputStatus, type VoiceInputStopReason, type VoiceInputTextLimit, type VoiceInputTriggerProps, VoiceTextarea, type VoiceTextareaProps, useVoiceInput };
|
|
110
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/context.tsx","../src/types.ts","../src/components.tsx","../src/use-voice-input.ts"],"mappings":";;;;UASiB;WACN,UAAU;WACV,cAAc;WACd,WAAW;;iBAaN,qBACd,UACA,aACA,YACC,0BAA0B;;;KCHjB;UAEF;EACR,WAAW;EACX,cAAc;EACd;EACA;EACA,sBAAsB;EACtB;EACA;EACA,kBAAkB;EAClB,sBAAsB;EACtB;EACA,iBAAiB;EACjB;EACA,eAAe,OAAO;EACtB,WAAW,OAAO;EAClB,kBACE,QAAQ,oBACR,gBAAgB;EAElB,uBAAuB;EACvB,yBAAyB;EACzB,qBAAqB;EACrB,sBAAsB;EACtB,qBAAqB,qBAAqB;EAC1C,UAAU,QAAQ;E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