Skip to content
TypeScript

feat(desktop): dictate into browser annotations with the same consent (#30624)

Julius Marmingeaabd5629c940
diff --git a/apps/desktop/src/ipc/channels.ts b/apps/desktop/src/ipc/channels.ts
index 05c72eb7078..1d7edaf6832 100644
--- a/apps/desktop/src/ipc/channels.ts
+++ b/apps/desktop/src/ipc/channels.ts
@@ -121,6 +121,9 @@ export const CHECK_SYSTEM_PERMISSION_CHANNEL = "desktop:check-system-permission"
export const PREVIEW_RECORDING_INPUT_CHANNEL = "desktop:preview-recording-input";
+export const PREVIEW_ANNOTATION_VOICE_EVENT_CHANNEL = "desktop:preview-annotation-voice-event";
+export const PREVIEW_ANNOTATION_VOICE_STATE_CHANNEL = "desktop:preview-annotation-voice-state";
+
export const RECEIVE_PROVIDER_AUTH_CALLBACK_CHANNEL = "desktop:receive-provider-auth-callback";
export const CANCEL_PROVIDER_AUTH_CALLBACK_CHANNEL = "desktop:cancel-provider-auth-callback";
export const TAKE_LEGACY_LOCAL_STORAGE_CHANNEL = "desktop:take-legacy-local-storage";
diff --git a/apps/desktop/src/ipc/methods/preview.ts b/apps/desktop/src/ipc/methods/preview.ts
index c4c33f6b8dc..98a0aab8316 100644
--- a/apps/desktop/src/ipc/methods/preview.ts
+++ b/apps/desktop/src/ipc/methods/preview.ts
@@ -1,6 +1,8 @@
import {
DesktopPreviewAnnotationSendEnabledInputSchema,
DesktopPreviewAnnotationThemeInputSchema,
+ DesktopPreviewAnnotationVoiceStateSchema,
+ DesktopPreviewPickElementInputSchema,
DesktopPreviewArtifactInputSchema,
DesktopPreviewConfigInputSchema,
DesktopPreviewNavigateInputSchema,
@@ -363,11 +365,21 @@ const setAnnotationTheme = DesktopIpc.makeIpcMethod({
const pickElement = DesktopIpc.makeIpcMethod({
channel: IpcChannels.PREVIEW_PICK_ELEMENT_CHANNEL,
- payload: DesktopPreviewTabInputSchema,
+ payload: DesktopPreviewPickElementInputSchema,
result: Schema.NullOr(PreviewAnnotationSubmissionResultSchema),
- handler: Effect.fn("desktop.ipc.preview.pickElement")(function* ({ tabId }) {
+ handler: Effect.fn("desktop.ipc.preview.pickElement")(function* ({ tabId, voice }) {
+ const manager = yield* PreviewManager.PreviewManager;
+ return yield* manager.pickElement(tabId, voice);
+ }),
+});
+
+const updateAnnotationVoice = DesktopIpc.makeIpcMethod({
+ channel: IpcChannels.PREVIEW_ANNOTATION_VOICE_STATE_CHANNEL,
+ payload: DesktopPreviewAnnotationVoiceStateSchema,
+ result: Schema.Void,
+ handler: Effect.fn("desktop.ipc.preview.updateAnnotationVoice")(function* (state) {
const manager = yield* PreviewManager.PreviewManager;
- return yield* manager.pickElement(tabId);
+ yield* manager.updateAnnotationVoice(state);
}),
});
@@ -428,6 +440,7 @@ const saveRecording = DesktopIpc.makeIpcMethod({
export const methods = [
setForwardedShortcuts,
+ updateAnnotationVoice,
createTab,
closeTab,
registerWebview,
diff --git a/apps/desktop/src/preload.ts b/apps/desktop/src/preload.ts
index 72245779b9c..800f1e744c9 100644
--- a/apps/desktop/src/preload.ts
+++ b/apps/desktop/src/preload.ts
@@ -1,5 +1,6 @@
import type {
DesktopBridge,
+ DesktopPreviewAnnotationVoiceEvent,
DesktopPreviewOpenLinkEvent,
DesktopPreviewPointerEvent,
DesktopPreviewRecordingInputEvent,
@@ -368,7 +369,20 @@ contextBridge.exposeInMainWorld("desktopBridge", {
tabId,
enabled,
}),
- pickElement: (tabId) => ipcRenderer.invoke(IpcChannels.PREVIEW_PICK_ELEMENT_CHANNEL, { tabId }),
+ annotationVoice: {
+ onEvent: (listener) => {
+ const onEvent = (_event: Electron.IpcRendererEvent, tabId: string, value: unknown) => {
+ if (typeof tabId !== "string" || typeof value !== "object" || value === null) return;
+ listener(tabId, value as DesktopPreviewAnnotationVoiceEvent);
+ };
+ ipcRenderer.on(IpcChannels.PREVIEW_ANNOTATION_VOICE_EVENT_CHANNEL, onEvent);
+ return () => ipcRenderer.off(IpcChannels.PREVIEW_ANNOTATION_VOICE_EVENT_CHANNEL, onEvent);
+ },
+ update: (state) =>
+ ipcRenderer.invoke(IpcChannels.PREVIEW_ANNOTATION_VOICE_STATE_CHANNEL, state),
+ },
+ pickElement: (tabId, voice) =>
+ ipcRenderer.invoke(IpcChannels.PREVIEW_PICK_ELEMENT_CHANNEL, { tabId, voice }),
cancelPickElement: (tabId) =>
ipcRenderer.invoke(IpcChannels.PREVIEW_CANCEL_PICK_ELEMENT_CHANNEL, { tabId }),
captureScreenshot: (tabId) =>
diff --git a/apps/desktop/src/preview/Annotation.css b/apps/desktop/src/preview/Annotation.css
index 0897aad4f86..3c5604e1b8c 100644
--- a/apps/desktop/src/preview/Annotation.css
+++ b/apps/desktop/src/preview/Annotation.css
@@ -36,6 +36,7 @@
--t3-popover-foreground: oklch(0.269 0 0);
--t3-primary: oklch(0.488 0.217 264);
--t3-primary-foreground: white;
+ --t3-destructive: oklch(0.577 0.245 27.325);
--t3-muted: rgb(0 0 0 / 4%);
--t3-muted-foreground: oklch(0.556 0 0);
--t3-accent: rgb(0 0 0 / 4%);
@@ -66,3 +67,8 @@ textarea:focus-visible {
outline: 2px solid color-mix(in srgb, var(--t3-ring) 72%, transparent);
outline-offset: -2px;
}
+
+/* Utility display classes must not override the native hidden state. */
+[hidden] {
+ display: none !important;
+}
diff --git a/apps/desktop/src/preview/AnnotationStyles.generated.ts b/apps/desktop/src/preview/AnnotationStyles.generated.ts
index d02abc8ac61..a8c70b5cece 100644
--- a/apps/desktop/src/preview/AnnotationStyles.generated.ts
+++ b/apps/desktop/src/preview/AnnotationStyles.generated.ts
@@ -1,3 +1,3 @@
// Generated by scripts/build-preview-annotation-css.mjs. Do not edit.
export const previewAnnotationStyles =
- '/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n@layer properties;\n:root, :host {\n --spacing: 0.25rem;\n --text-xs: 0.75rem;\n --text-xs--line-height: calc(1 / 0.75);\n --text-sm: 0.875rem;\n --text-sm--line-height: calc(1.25 / 0.875);\n --text-lg: 1.125rem;\n --text-lg--line-height: calc(1.75 / 1.125);\n --font-weight-medium: 500;\n --font-weight-semibold: 600;\n --font-weight-bold: 700;\n --blur-xl: 24px;\n --default-font-family: var(--t3-font-sans);\n --default-mono-font-family: var(--t3-font-mono);\n}\n*, ::after, ::before, ::backdrop, ::file-selector-button {\n box-sizing: border-box;\n margin: 0;\n padding: 0;\n border: 0 solid;\n}\nhtml, :host {\n line-height: 1.5;\n -webkit-text-size-adjust: 100%;\n tab-size: 4;\n font-family: var(--default-font-family, -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, \'Helvetica Neue\', \'Noto Sans\', Arial, sans-serif, \'Apple Color Emoji\', \'Segoe UI Emoji\', \'Segoe UI Symbol\', \'Noto Color Emoji\');\n font-feature-settings: var(--default-font-feature-settings, normal);\n font-variation-settings: var(--default-font-variation-settings, normal);\n -webkit-tap-highlight-color: transparent;\n}\nhr {\n height: 0;\n color: inherit;\n border-top-width: 1px;\n}\nabbr:where([title]) {\n -webkit-text-decoration: underline dotted;\n text-decoration: underline dotted;\n}\nh1, h2, h3, h4, h5, h6 {\n font-size: inherit;\n font-weight: inherit;\n}\na {\n color: inherit;\n -webkit-text-decoration: inherit;\n text-decoration: inherit;\n}\nb, strong {\n font-weight: bolder;\n}\ncode, kbd, samp, pre {\n font-family: var(--default-mono-font-family, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, \'Liberation Mono\', \'Courier New\', monospace);\n font-feature-settings: var(--default-mono-font-feature-settings, normal);\n font-variation-settings: var(--default-mono-font-variation-settings, normal);\n font-size: 1em;\n}\nsmall {\n font-size: 80%;\n}\nsub, sup {\n font-size: 75%;\n line-height: 0;\n position: relative;\n vertical-align: baseline;\n}\nsub {\n bottom: -0.25em;\n}\nsup {\n top: -0.5em;\n}\ntable {\n text-indent: 0;\n border-color: inherit;\n border-collapse: collapse;\n}\n:-moz-focusring:where(:not(iframe)) {\n outline: auto;\n}\nprogress {\n vertical-align: baseline;\n}\nsummary {\n display: list-item;\n}\nol, ul, menu {\n list-style: none;\n}\nimg, svg, video, canvas, audio, iframe, embed, object {\n display: block;\n vertical-align: middle;\n}\nimg, video {\n max-width: 100%;\n height: auto;\n}\nbutton, input, select, optgroup, textarea, ::file-selector-button {\n font: inherit;\n font-feature-settings: inherit;\n font-variation-settings: inherit;\n letter-spacing: inherit;\n color: inherit;\n border-radius: 0;\n background-color: transparent;\n opacity: 1;\n}\n:where(select:is([multiple], [size])) optgroup {\n font-weight: bolder;\n}\n:where(select:is([multiple], [size])) optgroup option {\n padding-inline-start: 20px;\n}\n::file-selector-button {\n margin-inline-end: 4px;\n}\n::placeholder {\n opacity: 1;\n}\n@supports (not (-webkit-appearance: -apple-pay-button)) or (contain-intrinsic-size: 1px) {\n ::placeholder {\n color: currentcolor;\n @supports (color: color-mix(in lab, red, red)) {\n color: color-mix(in oklab, currentcolor 50%, transparent);\n }\n }\n}\ntextarea {\n resize: vertical;\n}\n::-webkit-search-decoration {\n -webkit-appearance: none;\n}\n::-webkit-date-and-time-value {\n min-height: 1lh;\n text-align: inherit;\n}\n::-webkit-datetime-edit {\n display: inline-flex;\n}\n::-webkit-datetime-edit-fields-wrapper {\n padding: 0;\n}\n::-webkit-datetime-edit, ::-webkit-datetime-edit-year-field, ::-webkit-datetime-edit-month-field, ::-webkit-datetime-edit-day-field, ::-webkit-datetime-edit-hour-field, ::-webkit-datetime-edit-minute-field, ::-webkit-datetime-edit-second-field, ::-webkit-datetime-edit-millisecond-field, ::-webkit-datetime-edit-meridiem-field {\n padding-block: 0;\n}\n::-webkit-calendar-picker-indicator {\n line-height: 1;\n}\n:-moz-ui-invalid {\n box-shadow: none;\n}\nbutton, input:where([type=\'button\'], [type=\'reset\'], [type=\'submit\']), ::file-selector-button {\n appearance: button;\n}\n::-webkit-inner-spin-button, ::-webkit-outer-spin-button {\n height: auto;\n}\n[hidden]:where(:not([hidden=\'until-found\'])) {\n display: none !important;\n}\n.pointer-events-auto {\n pointer-events: auto;\n}\n.pointer-events-none {\n pointer-events: none;\n}\n.visible {\n visibility: visible;\n}\n.absolute {\n position: absolute;\n}\n.fixed {\n position: fixed;\n}\n.inset-0 {\n inset: 0px;\n}\n.top-1\\/2 {\n top: calc(1 / 2 * 100%);\n}\n.top-2\\.5 {\n top: calc(var(--spacing) * 2.5);\n}\n.right-2 {\n right: calc(var(--spacing) * 2);\n}\n.left-1\\/2 {\n left: calc(1 / 2 * 100%);\n}\n.z-1 {\n z-index: 1;\n}\n.block {\n display: block;\n}\n.flex {\n display: flex;\n}\n.grid {\n display: grid;\n}\n.hidden {\n display: none;\n}\n.inline-flex {\n display: inline-flex;\n}\n.h-7 {\n height: calc(var(--spacing) * 7);\n}\n.h-8 {\n height: calc(var(--spacing) * 8);\n}\n.max-h-24 {\n max-height: calc(var(--spacing) * 24);\n}\n.max-h-\\[calc\\(100vh-16px\\)\\] {\n max-height: calc(100vh - 16px);\n}\n.max-h-\\[min\\(176px\\,calc\\(100vh-180px\\)\\)\\] {\n max-height: min(176px, calc(100vh - 180px));\n}\n.min-h-7 {\n min-height: calc(var(--spacing) * 7);\n}\n.min-h-8 {\n min-height: calc(var(--spacing) * 8);\n}\n.w-6 {\n width: calc(var(--spacing) * 6);\n}\n.w-8 {\n width: calc(var(--spacing) * 8);\n}\n.w-\\[min\\(360px\\,calc\\(100vw-16px\\)\\)\\] {\n width: min(360px, calc(100vw - 16px));\n}\n.w-full {\n width: 100%;\n}\n.max-w-70 {\n max-width: calc(var(--spacing) * 70);\n}\n.min-w-0 {\n min-width: 0px;\n}\n.flex-1 {\n flex: 1;\n}\n.shrink-0 {\n flex-shrink: 0;\n}\n.-translate-x-1\\/2 {\n --tw-translate-x: calc(calc(1 / 2 * 100%) * -1);\n translate: var(--tw-translate-x) var(--tw-translate-y);\n}\n.-translate-y-1\\/2 {\n --tw-translate-y: calc(calc(1 / 2 * 100%) * -1);\n translate: var(--tw-translate-x) var(--tw-translate-y);\n}\n.cursor-grab {\n cursor: grab;\n}\n.cursor-pointer {\n cursor: pointer;\n}\n.resize {\n resize: both;\n}\n.resize-none {\n resize: none;\n}\n.appearance-none {\n appearance: none;\n}\n.grid-cols-\\[22px_minmax\\(0\\,1fr\\)\\] {\n grid-template-columns: 22px minmax(0,1fr);\n}\n.grid-cols-\\[82px_minmax\\(0\\,1fr\\)\\] {\n grid-template-columns: 82px minmax(0,1fr);\n}\n.flex-col {\n flex-direction: column;\n}\n.items-center {\n align-items: center;\n}\n.items-start {\n align-items: flex-start;\n}\n.justify-center {\n justify-content: center;\n}\n.gap-0\\.5 {\n gap: calc(var(--spacing) * 0.5);\n}\n.gap-1 {\n gap: var(--spacing);\n}\n.gap-2 {\n gap: calc(var(--spacing) * 2);\n}\n.overflow-auto {\n overflow: auto;\n}\n.overflow-hidden {\n overflow: hidden;\n}\n.overflow-y-hidden {\n overflow-y: hidden;\n}\n.rounded-lg {\n border-radius: var(--t3-radius);\n}\n.rounded-md {\n border-radius: calc(var(--t3-radius) - 2px);\n}\n.rounded-xl {\n border-radius: calc(var(--t3-radius) + 4px);\n}\n.border {\n border-style: var(--tw-border-style);\n border-width: 1px;\n}\n.border-0 {\n border-style: var(--tw-border-style);\n border-width: 0px;\n}\n.border-t {\n border-top-style: var(--tw-border-style);\n border-top-width: 1px;\n}\n.border-b {\n border-bottom-style: var(--tw-border-style);\n border-bottom-width: 1px;\n}\n.border-border {\n border-color: var(--t3-border);\n}\n.border-input {\n border-color: var(--t3-input);\n}\n.border-primary {\n border-color: var(--t3-primary);\n}\n.border-transparent {\n border-color: transparent;\n}\n.border-b-transparent {\n border-bottom-color: transparent;\n}\n.bg-background {\n background-color: var(--t3-background);\n}\n.bg-muted {\n background-color: var(--t3-muted);\n}\n.bg-muted\\/40 {\n background-color: var(--t3-muted);\n @supports (color: color-mix(in lab, red, red)) {\n background-color: color-mix(in oklab, var(--t3-muted) 40%, transparent);\n }\n}\n.bg-popover\\/95 {\n background-color: var(--t3-popover);\n @supports (color: color-mix(in lab, red, red)) {\n background-color: color-mix(in oklab, var(--t3-popover) 95%, transparent);\n }\n}\n.bg-popover\\/96 {\n background-color: var(--t3-popover);\n @supports (color: color-mix(in lab, red, red)) {\n background-color: color-mix(in oklab, var(--t3-popover) 96%, transparent);\n }\n}\n.bg-primary {\n background-color: var(--t3-primary);\n}\n.bg-primary\\/10 {\n background-color: var(--t3-primary);\n @supports (color: color-mix(in lab, red, red)) {\n background-color: color-mix(in oklab, var(--t3-primary) 10%, transparent);\n }\n}\n.bg-transparent {\n background-color: transparent;\n}\n.p-0 {\n padding: 0px;\n}\n.p-1 {\n padding: var(--spacing);\n}\n.p-2 {\n padding: calc(var(--spacing) * 2);\n}\n.px-0 {\n padding-inline: 0px;\n}\n.px-1 {\n padding-inline: var(--spacing);\n}\n.px-2 {\n padding-inline: calc(var(--spacing) * 2);\n}\n.px-2\\.5 {\n padding-inline: calc(var(--spacing) * 2.5);\n}\n.px-3 {\n padding-inline: calc(var(--spacing) * 3);\n}\n.py-1 {\n padding-block: var(--spacing);\n}\n.py-1\\.5 {\n padding-block: calc(var(--spacing) * 1.5);\n}\n.py-2 {\n padding-block: calc(var(--spacing) * 2);\n}\n.font-mono {\n font-family: var(--t3-font-mono);\n}\n.font-sans {\n font-family: var(--t3-font-sans);\n}\n.text-lg {\n font-size: var(--text-lg);\n line-height: var(--tw-leading, var(--text-lg--line-height));\n}\n.text-sm {\n font-size: var(--text-sm);\n line-height: var(--tw-leading, var(--text-sm--line-height));\n}\n.text-xs {\n font-size: var(--text-xs);\n line-height: var(--tw-leading, var(--text-xs--line-height));\n}\n.leading-5 {\n --tw-leading: calc(var(--spacing) * 5);\n line-height: calc(var(--spacing) * 5);\n}\n.font-bold {\n --tw-font-weight: var(--font-weight-bold);\n font-weight: var(--font-weight-bold);\n}\n.font-medium {\n --tw-font-weight: var(--font-weight-medium);\n font-weight: var(--font-weight-medium);\n}\n.font-semibold {\n --tw-font-weight: var(--font-weight-semibold);\n font-weight: var(--font-weight-semibold);\n}\n.text-foreground {\n color: var(--t3-foreground);\n}\n.text-muted-foreground {\n color: var(--t3-muted-foreground);\n}\n.text-popover-foreground {\n color: var(--t3-popover-foreground);\n}\n.text-primary {\n color: var(--t3-primary);\n}\n.text-primary-foreground {\n color: var(--t3-primary-foreground);\n}\n.shadow-2xl {\n --tw-shadow: 0 25px 50px -12px var(--tw-shadow-color, rgb(0 0 0 / 0.25));\n box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);\n}\n.shadow-lg {\n --tw-shadow: 0 10px 15px -3px var(--tw-shadow-color, rgb(0 0 0 / 0.1)), 0 4px 6px -4px var(--tw-shadow-color, rgb(0 0 0 / 0.1));\n box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);\n}\n.shadow-md {\n --tw-shadow: 0 4px 6px -1px var(--tw-shadow-color, rgb(0 0 0 / 0.1)), 0 2px 4px -2px var(--tw-shadow-color, rgb(0 0 0 / 0.1));\n box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);\n}\n.shadow-sm {\n --tw-shadow: 0 1px 3px 0 var(--tw-shadow-color, rgb(0 0 0 / 0.1)), 0 1px 2px -1px var(--tw-shadow-color, rgb(0 0 0 / 0.1));\n box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);\n}\n.shadow-xs {\n --tw-shadow: 0 1px 2px 0 var(--tw-shadow-color, rgb(0 0 0 / 0.05));\n box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);\n}\n.ring-0 {\n --tw-ring-shadow: var(--tw-ring-inset,) 0 0 0 calc(0px + var(--tw-ring-offset-width)) var(--tw-ring-color, currentcolor);\n box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);\n}\n.blur {\n --tw-blur: blur(8px);\n filter: var(--tw-blur,) var(--tw-brightness,) var(--tw-contrast,) var(--tw-grayscale,) var(--tw-hue-rotate,) var(--tw-invert,) var(--tw-saturate,) var(--tw-sepia,) var(--tw-drop-shadow,);\n}\n.backdrop-blur-xl {\n --tw-backdrop-blur: blur(var(--blur-xl));\n -webkit-backdrop-filter: var(--tw-backdrop-blur,) var(--tw-backdrop-brightness,) var(--tw-backdrop-contrast,) var(--tw-backdrop-grayscale,) var(--tw-backdrop-hue-rotate,) var(--tw-backdrop-invert,) var(--tw-backdrop-opacity,) var(--tw-backdrop-saturate,) var(--tw-backdrop-sepia,);\n backdrop-filter: var(--tw-backdrop-blur,) var(--tw-backdrop-brightness,) var(--tw-backdrop-contrast,) var(--tw-backdrop-grayscale,) var(--tw-backdrop-hue-rotate,) var(--tw-backdrop-invert,) var(--tw-backdrop-opacity,) var(--tw-backdrop-saturate,) var(--tw-backdrop-sepia,);\n}\n.outline-none {\n --tw-outline-style: none;\n outline-style: none;\n}\n.select-none {\n -webkit-user-select: none;\n user-select: none;\n}\n.placeholder\\:text-muted-foreground::placeholder {\n color: var(--t3-muted-foreground);\n}\n@media (hover: hover) {\n .hover\\:bg-accent:hover {\n background-color: var(--t3-accent);\n }\n .hover\\:bg-primary\\/90:hover {\n background-color: var(--t3-primary);\n }\n @supports (color: color-mix(in lab, red, red)) {\n .hover\\:bg-primary\\/90:hover {\n background-color: color-mix(in oklab, var(--t3-primary) 90%, transparent);\n }\n }\n .hover\\:text-accent-foreground:hover {\n color: var(--t3-accent-foreground);\n }\n}\n.focus\\:border-b-primary:focus {\n border-bottom-color: var(--t3-primary);\n}\n.focus\\:ring-0:focus {\n --tw-ring-shadow: var(--tw-ring-inset,) 0 0 0 calc(0px + var(--tw-ring-offset-width)) var(--tw-ring-color, currentcolor);\n box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);\n}\n.focus\\:outline-none:focus {\n --tw-outline-style: none;\n outline-style: none;\n}\n.disabled\\:pointer-events-none:disabled {\n pointer-events: none;\n}\n.disabled\\:opacity-60:disabled {\n opacity: 60%;\n}\n:host {\n --t3-font-sans: "DM Sans Variable", "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui,\n sans-serif;\n --t3-font-mono: "SF Mono", "SFMono-Regular", "JetBrains Mono", Consolas, "Liberation Mono", Menlo, monospace;\n --t3-radius: 0.625rem;\n --t3-background: white;\n --t3-foreground: oklch(0.269 0 0);\n --t3-popover: white;\n --t3-popover-foreground: oklch(0.269 0 0);\n --t3-primary: oklch(0.488 0.217 264);\n --t3-primary-foreground: white;\n --t3-muted: rgb(0 0 0 / 4%);\n --t3-muted-foreground: oklch(0.556 0 0);\n --t3-accent: rgb(0 0 0 / 4%);\n --t3-accent-foreground: oklch(0.269 0 0);\n --t3-border: rgb(0 0 0 / 8%);\n --t3-input: rgb(0 0 0 / 10%);\n --t3-ring: oklch(0.488 0.217 264);\n color: var(--t3-foreground);\n font-family: var(--t3-font-sans);\n}\n* {\n box-sizing: border-box;\n border-color: var(--t3-border);\n}\nbutton, input, select, textarea {\n font: inherit;\n}\nbutton:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {\n outline: 2px solid var(--t3-ring);\n @supports (color: color-mix(in lab, red, red)) {\n outline: 2px solid color-mix(in srgb, var(--t3-ring) 72%, transparent);\n }\n outline-offset: -2px;\n}\n@property --tw-translate-x {\n syntax: "*";\n inherits: false;\n initial-value: 0;\n}\n@property --tw-translate-y {\n syntax: "*";\n inherits: false;\n initial-value: 0;\n}\n@property --tw-translate-z {\n syntax: "*";\n inherits: false;\n initial-value: 0;\n}\n@property --tw-border-style {\n syntax: "*";\n inherits: false;\n initial-value: solid;\n}\n@property --tw-leading {\n syntax: "*";\n inherits: false;\n}\n@property --tw-font-weight {\n syntax: "*";\n inherits: false;\n}\n@property --tw-shadow {\n syntax: "*";\n inherits: false;\n initial-value: 0 0 #0000;\n}\n@property --tw-shadow-color {\n syntax: "*";\n inherits: false;\n}\n@property --tw-shadow-alpha {\n syntax: "<percentage>";\n inherits: false;\n initial-value: 100%;\n}\n@property --tw-inset-shadow {\n syntax: "*";\n inherits: false;\n initial-value: 0 0 #0000;\n}\n@property --tw-inset-shadow-color {\n syntax: "*";\n inherits: false;\n}\n@property --tw-inset-shadow-alpha {\n syntax: "<percentage>";\n inherits: false;\n initial-value: 100%;\n}\n@property --tw-ring-color {\n syntax: "*";\n inherits: false;\n}\n@property --tw-ring-shadow {\n syntax: "*";\n inherits: false;\n initial-value: 0 0 #0000;\n}\n@property --tw-inset-ring-color {\n syntax: "*";\n inherits: false;\n}\n@property --tw-inset-ring-shadow {\n syntax: "*";\n inherits: false;\n initial-value: 0 0 #0000;\n}\n@property --tw-ring-inset {\n syntax: "*";\n inherits: false;\n}\n@property --tw-ring-offset-width {\n syntax: "<length>";\n inherits: false;\n initial-value: 0px;\n}\n@property --tw-ring-offset-color {\n syntax: "*";\n inherits: false;\n initial-value: #fff;\n}\n@property --tw-ring-offset-shadow {\n syntax: "*";\n inherits: false;\n initial-value: 0 0 #0000;\n}\n@property --tw-blur {\n syntax: "*";\n inherits: false;\n}\n@property --tw-brightness {\n syntax: "*";\n inherits: false;\n}\n@property --tw-contrast {\n syntax: "*";\n inherits: false;\n}\n@property --tw-grayscale {\n syntax: "*";\n inherits: false;\n}\n@property --tw-hue-rotate {\n syntax: "*";\n inherits: false;\n}\n@property --tw-invert {\n syntax: "*";\n inherits: false;\n}\n@property --tw-opacity {\n syntax: "*";\n inherits: false;\n}\n@property --tw-saturate {\n syntax: "*";\n inherits: false;\n}\n@property --tw-sepia {\n syntax: "*";\n inherits: false;\n}\n@property --tw-drop-shadow {\n syntax: "*";\n inherits: false;\n}\n@property --tw-drop-shadow-color {\n syntax: "*";\n inherits: false;\n}\n@property --tw-drop-shadow-alpha {\n syntax: "<percentage>";\n inherits: false;\n initial-value: 100%;\n}\n@property --tw-drop-shadow-size {\n syntax: "*";\n inherits: false;\n}\n@property --tw-backdrop-blur {\n syntax: "*";\n inherits: false;\n}\n@property --tw-backdrop-brightness {\n syntax: "*";\n inherits: false;\n}\n@property --tw-backdrop-contrast {\n syntax: "*";\n inherits: false;\n}\n@property --tw-backdrop-grayscale {\n syntax: "*";\n inherits: false;\n}\n@property --tw-backdrop-hue-rotate {\n syntax: "*";\n inherits: false;\n}\n@property --tw-backdrop-invert {\n syntax: "*";\n inherits: false;\n}\n@property --tw-backdrop-opacity {\n syntax: "*";\n inherits: false;\n}\n@property --tw-backdrop-saturate {\n syntax: "*";\n inherits: false;\n}\n@property --tw-backdrop-sepia {\n syntax: "*";\n inherits: false;\n}\n@layer properties {\n *, ::before, ::after, ::backdrop {\n --tw-translate-x: 0;\n --tw-translate-y: 0;\n --tw-translate-z: 0;\n --tw-border-style: solid;\n --tw-leading: initial;\n --tw-font-weight: initial;\n --tw-shadow: 0 0 #0000;\n --tw-shadow-color: initial;\n --tw-shadow-alpha: 100%;\n --tw-inset-shadow: 0 0 #0000;\n --tw-inset-shadow-color: initial;\n --tw-inset-shadow-alpha: 100%;\n --tw-ring-color: initial;\n --tw-ring-shadow: 0 0 #0000;\n --tw-inset-ring-color: initial;\n --tw-inset-ring-shadow: 0 0 #0000;\n --tw-ring-inset: initial;\n --tw-ring-offset-width: 0px;\n --tw-ring-offset-color: #fff;\n --tw-ring-offset-shadow: 0 0 #0000;\n --tw-blur: initial;\n --tw-brightness: initial;\n --tw-contrast: initial;\n --tw-grayscale: initial;\n --tw-hue-rotate: initial;\n --tw-invert: initial;\n --tw-opacity: initial;\n --tw-saturate: initial;\n --tw-sepia: initial;\n --tw-drop-shadow: initial;\n --tw-drop-shadow-color: initial;\n --tw-drop-shadow-alpha: 100%;\n --tw-drop-shadow-size: initial;\n --tw-backdrop-blur: initial;\n --tw-backdrop-brightness: initial;\n --tw-backdrop-contrast: initial;\n --tw-backdrop-grayscale: initial;\n --tw-backdrop-hue-rotate: initial;\n --tw-backdrop-invert: initial;\n --tw-backdrop-opacity: initial;\n --tw-backdrop-saturate: initial;\n --tw-backdrop-sepia: initial;\n }\n}\n';
+ '/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n@layer properties;\n:root, :host {\n --spacing: 0.25rem;\n --text-xs: 0.75rem;\n --text-xs--line-height: calc(1 / 0.75);\n --text-sm: 0.875rem;\n --text-sm--line-height: calc(1.25 / 0.875);\n --text-lg: 1.125rem;\n --text-lg--line-height: calc(1.75 / 1.125);\n --font-weight-medium: 500;\n --font-weight-semibold: 600;\n --font-weight-bold: 700;\n --blur-xl: 24px;\n --default-font-family: var(--t3-font-sans);\n --default-mono-font-family: var(--t3-font-mono);\n}\n*, ::after, ::before, ::backdrop, ::file-selector-button {\n box-sizing: border-box;\n margin: 0;\n padding: 0;\n border: 0 solid;\n}\nhtml, :host {\n line-height: 1.5;\n -webkit-text-size-adjust: 100%;\n tab-size: 4;\n font-family: var(--default-font-family, -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, \'Helvetica Neue\', \'Noto Sans\', Arial, sans-serif, \'Apple Color Emoji\', \'Segoe UI Emoji\', \'Segoe UI Symbol\', \'Noto Color Emoji\');\n font-feature-settings: var(--default-font-feature-settings, normal);\n font-variation-settings: var(--default-font-variation-settings, normal);\n -webkit-tap-highlight-color: transparent;\n}\nhr {\n height: 0;\n color: inherit;\n border-top-width: 1px;\n}\nabbr:where([title]) {\n -webkit-text-decoration: underline dotted;\n text-decoration: underline dotted;\n}\nh1, h2, h3, h4, h5, h6 {\n font-size: inherit;\n font-weight: inherit;\n}\na {\n color: inherit;\n -webkit-text-decoration: inherit;\n text-decoration: inherit;\n}\nb, strong {\n font-weight: bolder;\n}\ncode, kbd, samp, pre {\n font-family: var(--default-mono-font-family, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, \'Liberation Mono\', \'Courier New\', monospace);\n font-feature-settings: var(--default-mono-font-feature-settings, normal);\n font-variation-settings: var(--default-mono-font-variation-settings, normal);\n font-size: 1em;\n}\nsmall {\n font-size: 80%;\n}\nsub, sup {\n font-size: 75%;\n line-height: 0;\n position: relative;\n vertical-align: baseline;\n}\nsub {\n bottom: -0.25em;\n}\nsup {\n top: -0.5em;\n}\ntable {\n text-indent: 0;\n border-color: inherit;\n border-collapse: collapse;\n}\n:-moz-focusring:where(:not(iframe)) {\n outline: auto;\n}\nprogress {\n vertical-align: baseline;\n}\nsummary {\n display: list-item;\n}\nol, ul, menu {\n list-style: none;\n}\nimg, svg, video, canvas, audio, iframe, embed, object {\n display: block;\n vertical-align: middle;\n}\nimg, video {\n max-width: 100%;\n height: auto;\n}\nbutton, input, select, optgroup, textarea, ::file-selector-button {\n font: inherit;\n font-feature-settings: inherit;\n font-variation-settings: inherit;\n letter-spacing: inherit;\n color: inherit;\n border-radius: 0;\n background-color: transparent;\n opacity: 1;\n}\n:where(select:is([multiple], [size])) optgroup {\n font-weight: bolder;\n}\n:where(select:is([multiple], [size])) optgroup option {\n padding-inline-start: 20px;\n}\n::file-selector-button {\n margin-inline-end: 4px;\n}\n::placeholder {\n opacity: 1;\n}\n@supports (not (-webkit-appearance: -apple-pay-button)) or (contain-intrinsic-size: 1px) {\n ::placeholder {\n color: currentcolor;\n @supports (color: color-mix(in lab, red, red)) {\n color: color-mix(in oklab, currentcolor 50%, transparent);\n }\n }\n}\ntextarea {\n resize: vertical;\n}\n::-webkit-search-decoration {\n -webkit-appearance: none;\n}\n::-webkit-date-and-time-value {\n min-height: 1lh;\n text-align: inherit;\n}\n::-webkit-datetime-edit {\n display: inline-flex;\n}\n::-webkit-datetime-edit-fields-wrapper {\n padding: 0;\n}\n::-webkit-datetime-edit, ::-webkit-datetime-edit-year-field, ::-webkit-datetime-edit-month-field, ::-webkit-datetime-edit-day-field, ::-webkit-datetime-edit-hour-field, ::-webkit-datetime-edit-minute-field, ::-webkit-datetime-edit-second-field, ::-webkit-datetime-edit-millisecond-field, ::-webkit-datetime-edit-meridiem-field {\n padding-block: 0;\n}\n::-webkit-calendar-picker-indicator {\n line-height: 1;\n}\n:-moz-ui-invalid {\n box-shadow: none;\n}\nbutton, input:where([type=\'button\'], [type=\'reset\'], [type=\'submit\']), ::file-selector-button {\n appearance: button;\n}\n::-webkit-inner-spin-button, ::-webkit-outer-spin-button {\n height: auto;\n}\n[hidden]:where(:not([hidden=\'until-found\'])) {\n display: none !important;\n}\n.pointer-events-auto {\n pointer-events: auto;\n}\n.pointer-events-none {\n pointer-events: none;\n}\n.visible {\n visibility: visible;\n}\n.absolute {\n position: absolute;\n}\n.fixed {\n position: fixed;\n}\n.inset-0 {\n inset: 0px;\n}\n.top-1\\/2 {\n top: calc(1 / 2 * 100%);\n}\n.top-2\\.5 {\n top: calc(var(--spacing) * 2.5);\n}\n.right-2 {\n right: calc(var(--spacing) * 2);\n}\n.left-1\\/2 {\n left: calc(1 / 2 * 100%);\n}\n.z-1 {\n z-index: 1;\n}\n.block {\n display: block;\n}\n.flex {\n display: flex;\n}\n.grid {\n display: grid;\n}\n.hidden {\n display: none;\n}\n.inline-flex {\n display: inline-flex;\n}\n.h-5 {\n height: calc(var(--spacing) * 5);\n}\n.h-7 {\n height: calc(var(--spacing) * 7);\n}\n.h-8 {\n height: calc(var(--spacing) * 8);\n}\n.h-9 {\n height: calc(var(--spacing) * 9);\n}\n.h-full {\n height: 100%;\n}\n.max-h-24 {\n max-height: calc(var(--spacing) * 24);\n}\n.max-h-\\[calc\\(100vh-16px\\)\\] {\n max-height: calc(100vh - 16px);\n}\n.max-h-\\[min\\(176px\\,calc\\(100vh-180px\\)\\)\\] {\n max-height: min(176px, calc(100vh - 180px));\n}\n.min-h-7 {\n min-height: calc(var(--spacing) * 7);\n}\n.min-h-8 {\n min-height: calc(var(--spacing) * 8);\n}\n.w-0\\.5 {\n width: calc(var(--spacing) * 0.5);\n}\n.w-6 {\n width: calc(var(--spacing) * 6);\n}\n.w-7 {\n width: calc(var(--spacing) * 7);\n}\n.w-8 {\n width: calc(var(--spacing) * 8);\n}\n.w-64 {\n width: calc(var(--spacing) * 64);\n}\n.w-\\[min\\(360px\\,calc\\(100vw-16px\\)\\)\\] {\n width: min(360px, calc(100vw - 16px));\n}\n.w-full {\n width: 100%;\n}\n.max-w-70 {\n max-width: calc(var(--spacing) * 70);\n}\n.min-w-0 {\n min-width: 0px;\n}\n.flex-1 {\n flex: 1;\n}\n.shrink-0 {\n flex-shrink: 0;\n}\n.origin-center {\n transform-origin: center;\n}\n.-translate-x-1\\/2 {\n --tw-translate-x: calc(calc(1 / 2 * 100%) * -1);\n translate: var(--tw-translate-x) var(--tw-translate-y);\n}\n.-translate-y-1\\/2 {\n --tw-translate-y: calc(calc(1 / 2 * 100%) * -1);\n translate: var(--tw-translate-x) var(--tw-translate-y);\n}\n.cursor-grab {\n cursor: grab;\n}\n.cursor-pointer {\n cursor: pointer;\n}\n.resize {\n resize: both;\n}\n.resize-none {\n resize: none;\n}\n.appearance-none {\n appearance: none;\n}\n.grid-cols-\\[22px_minmax\\(0\\,1fr\\)\\] {\n grid-template-columns: 22px minmax(0,1fr);\n}\n.grid-cols-\\[82px_minmax\\(0\\,1fr\\)\\] {\n grid-template-columns: 82px minmax(0,1fr);\n}\n.flex-col {\n flex-direction: column;\n}\n.items-center {\n align-items: center;\n}\n.items-start {\n align-items: flex-start;\n}\n.justify-between {\n justify-content: space-between;\n}\n.justify-center {\n justify-content: center;\n}\n.justify-end {\n justify-content: flex-end;\n}\n.gap-0\\.5 {\n gap: calc(var(--spacing) * 0.5);\n}\n.gap-1 {\n gap: var(--spacing);\n}\n.gap-2 {\n gap: calc(var(--spacing) * 2);\n}\n.gap-px {\n gap: 1px;\n}\n.truncate {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n.overflow-auto {\n overflow: auto;\n}\n.overflow-hidden {\n overflow: hidden;\n}\n.overflow-y-hidden {\n overflow-y: hidden;\n}\n.rounded-full {\n border-radius: calc(infinity * 1px);\n}\n.rounded-lg {\n border-radius: var(--t3-radius);\n}\n.rounded-md {\n border-radius: calc(var(--t3-radius) - 2px);\n}\n.rounded-xl {\n border-radius: calc(var(--t3-radius) + 4px);\n}\n.border {\n border-style: var(--tw-border-style);\n border-width: 1px;\n}\n.border-0 {\n border-style: var(--tw-border-style);\n border-width: 0px;\n}\n.border-t {\n border-top-style: var(--tw-border-style);\n border-top-width: 1px;\n}\n.border-b {\n border-bottom-style: var(--tw-border-style);\n border-bottom-width: 1px;\n}\n.border-border {\n border-color: var(--t3-border);\n}\n.border-input {\n border-color: var(--t3-input);\n}\n.border-primary {\n border-color: var(--t3-primary);\n}\n.border-transparent {\n border-color: transparent;\n}\n.border-b-transparent {\n border-bottom-color: transparent;\n}\n.bg-background {\n background-color: var(--t3-background);\n}\n.bg-muted {\n background-color: var(--t3-muted);\n}\n.bg-muted\\/40 {\n background-color: var(--t3-muted);\n @supports (color: color-mix(in lab, red, red)) {\n background-color: color-mix(in oklab, var(--t3-muted) 40%, transparent);\n }\n}\n.bg-popover\\/95 {\n background-color: var(--t3-popover);\n @supports (color: color-mix(in lab, red, red)) {\n background-color: color-mix(in oklab, var(--t3-popover) 95%, transparent);\n }\n}\n.bg-popover\\/96 {\n background-color: var(--t3-popover);\n @supports (color: color-mix(in lab, red, red)) {\n background-color: color-mix(in oklab, var(--t3-popover) 96%, transparent);\n }\n}\n.bg-primary {\n background-color: var(--t3-primary);\n}\n.bg-primary\\/10 {\n background-color: var(--t3-primary);\n @supports (color: color-mix(in lab, red, red)) {\n background-color: color-mix(in oklab, var(--t3-primary) 10%, transparent);\n }\n}\n.bg-transparent {\n background-color: transparent;\n}\n.p-0 {\n padding: 0px;\n}\n.p-1 {\n padding: var(--spacing);\n}\n.p-2 {\n padding: calc(var(--spacing) * 2);\n}\n.px-0 {\n padding-inline: 0px;\n}\n.px-1 {\n padding-inline: var(--spacing);\n}\n.px-2 {\n padding-inline: calc(var(--spacing) * 2);\n}\n.px-2\\.5 {\n padding-inline: calc(var(--spacing) * 2.5);\n}\n.px-3 {\n padding-inline: calc(var(--spacing) * 3);\n}\n.py-1 {\n padding-block: var(--spacing);\n}\n.py-1\\.5 {\n padding-block: calc(var(--spacing) * 1.5);\n}\n.py-2 {\n padding-block: calc(var(--spacing) * 2);\n}\n.pb-2 {\n padding-bottom: calc(var(--spacing) * 2);\n}\n.text-right {\n text-align: right;\n}\n.font-mono {\n font-family: var(--t3-font-mono);\n}\n.font-sans {\n font-family: var(--t3-font-sans);\n}\n.text-lg {\n font-size: var(--text-lg);\n line-height: var(--tw-leading, var(--text-lg--line-height));\n}\n.text-sm {\n font-size: var(--text-sm);\n line-height: var(--tw-leading, var(--text-sm--line-height));\n}\n.text-xs {\n font-size: var(--text-xs);\n line-height: var(--tw-leading, var(--text-xs--line-height));\n}\n.leading-5 {\n --tw-leading: calc(var(--spacing) * 5);\n line-height: calc(var(--spacing) * 5);\n}\n.font-bold {\n --tw-font-weight: var(--font-weight-bold);\n font-weight: var(--font-weight-bold);\n}\n.font-medium {\n --tw-font-weight: var(--font-weight-medium);\n font-weight: var(--font-weight-medium);\n}\n.font-semibold {\n --tw-font-weight: var(--font-weight-semibold);\n font-weight: var(--font-weight-semibold);\n}\n.text-foreground {\n color: var(--t3-foreground);\n}\n.text-muted-foreground {\n color: var(--t3-muted-foreground);\n}\n.text-popover-foreground {\n color: var(--t3-popover-foreground);\n}\n.text-primary {\n color: var(--t3-primary);\n}\n.text-primary-foreground {\n color: var(--t3-primary-foreground);\n}\n.tabular-nums {\n --tw-numeric-spacing: tabular-nums;\n font-variant-numeric: var(--tw-ordinal,) var(--tw-slashed-zero,) var(--tw-numeric-figure,) var(--tw-numeric-spacing,) var(--tw-numeric-fraction,);\n}\n.shadow {\n --tw-shadow: 0 1px 3px 0 var(--tw-shadow-color, rgb(0 0 0 / 0.1)), 0 1px 2px -1px var(--tw-shadow-color, rgb(0 0 0 / 0.1));\n box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);\n}\n.shadow-2xl {\n --tw-shadow: 0 25px 50px -12px var(--tw-shadow-color, rgb(0 0 0 / 0.25));\n box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);\n}\n.shadow-lg {\n --tw-shadow: 0 10px 15px -3px var(--tw-shadow-color, rgb(0 0 0 / 0.1)), 0 4px 6px -4px var(--tw-shadow-color, rgb(0 0 0 / 0.1));\n box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);\n}\n.shadow-md {\n --tw-shadow: 0 4px 6px -1px var(--tw-shadow-color, rgb(0 0 0 / 0.1)), 0 2px 4px -2px var(--tw-shadow-color, rgb(0 0 0 / 0.1));\n box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);\n}\n.shadow-sm {\n --tw-shadow: 0 1px 3px 0 var(--tw-shadow-color, rgb(0 0 0 / 0.1)), 0 1px 2px -1px var(--tw-shadow-color, rgb(0 0 0 / 0.1));\n box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);\n}\n.shadow-xs {\n --tw-shadow: 0 1px 2px 0 var(--tw-shadow-color, rgb(0 0 0 / 0.05));\n box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);\n}\n.ring-0 {\n --tw-ring-shadow: var(--tw-ring-inset,) 0 0 0 calc(0px + var(--tw-ring-offset-width)) var(--tw-ring-color, currentcolor);\n box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);\n}\n.blur {\n --tw-blur: blur(8px);\n filter: var(--tw-blur,) var(--tw-brightness,) var(--tw-contrast,) var(--tw-grayscale,) var(--tw-hue-rotate,) var(--tw-invert,) var(--tw-saturate,) var(--tw-sepia,) var(--tw-drop-shadow,);\n}\n.backdrop-blur-xl {\n --tw-backdrop-blur: blur(var(--blur-xl));\n -webkit-backdrop-filter: var(--tw-backdrop-blur,) var(--tw-backdrop-brightness,) var(--tw-backdrop-contrast,) var(--tw-backdrop-grayscale,) var(--tw-backdrop-hue-rotate,) var(--tw-backdrop-invert,) var(--tw-backdrop-opacity,) var(--tw-backdrop-saturate,) var(--tw-backdrop-sepia,);\n backdrop-filter: var(--tw-backdrop-blur,) var(--tw-backdrop-brightness,) var(--tw-backdrop-contrast,) var(--tw-backdrop-grayscale,) var(--tw-backdrop-hue-rotate,) var(--tw-backdrop-invert,) var(--tw-backdrop-opacity,) var(--tw-backdrop-saturate,) var(--tw-backdrop-sepia,);\n}\n.outline-none {\n --tw-outline-style: none;\n outline-style: none;\n}\n.select-none {\n -webkit-user-select: none;\n user-select: none;\n}\n.placeholder\\:text-muted-foreground::placeholder {\n color: var(--t3-muted-foreground);\n}\n@media (hover: hover) {\n .hover\\:bg-accent:hover {\n background-color: var(--t3-accent);\n }\n .hover\\:bg-primary\\/90:hover {\n background-color: var(--t3-primary);\n }\n @supports (color: color-mix(in lab, red, red)) {\n .hover\\:bg-primary\\/90:hover {\n background-color: color-mix(in oklab, var(--t3-primary) 90%, transparent);\n }\n }\n .hover\\:text-accent-foreground:hover {\n color: var(--t3-accent-foreground);\n }\n}\n.focus\\:border-b-primary:focus {\n border-bottom-color: var(--t3-primary);\n}\n.focus\\:ring-0:focus {\n --tw-ring-shadow: var(--tw-ring-inset,) 0 0 0 calc(0px + var(--tw-ring-offset-width)) var(--tw-ring-color, currentcolor);\n box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);\n}\n.focus\\:outline-none:focus {\n --tw-outline-style: none;\n outline-style: none;\n}\n.disabled\\:pointer-events-none:disabled {\n pointer-events: none;\n}\n.disabled\\:opacity-60:disabled {\n opacity: 60%;\n}\n:host {\n --t3-font-sans: "DM Sans Variable", "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui,\n sans-serif;\n --t3-font-mono: "SF Mono", "SFMono-Regular", "JetBrains Mono", Consolas, "Liberation Mono", Menlo, monospace;\n --t3-radius: 0.625rem;\n --t3-background: white;\n --t3-foreground: oklch(0.269 0 0);\n --t3-popover: white;\n --t3-popover-foreground: oklch(0.269 0 0);\n --t3-primary: oklch(0.488 0.217 264);\n --t3-primary-foreground: white;\n --t3-destructive: oklch(0.577 0.245 27.325);\n --t3-muted: rgb(0 0 0 / 4%);\n --t3-muted-foreground: oklch(0.556 0 0);\n --t3-accent: rgb(0 0 0 / 4%);\n --t3-accent-foreground: oklch(0.269 0 0);\n --t3-border: rgb(0 0 0 / 8%);\n --t3-input: rgb(0 0 0 / 10%);\n --t3-ring: oklch(0.488 0.217 264);\n color: var(--t3-foreground);\n font-family: var(--t3-font-sans);\n}\n* {\n box-sizing: border-box;\n border-color: var(--t3-border);\n}\nbutton, input, select, textarea {\n font: inherit;\n}\nbutton:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {\n outline: 2px solid var(--t3-ring);\n @supports (color: color-mix(in lab, red, red)) {\n outline: 2px solid color-mix(in srgb, var(--t3-ring) 72%, transparent);\n }\n outline-offset: -2px;\n}\n[hidden] {\n display: none !important;\n}\n@property --tw-translate-x {\n syntax: "*";\n inherits: false;\n initial-value: 0;\n}\n@property --tw-translate-y {\n syntax: "*";\n inherits: false;\n initial-value: 0;\n}\n@property --tw-translate-z {\n syntax: "*";\n inherits: false;\n initial-value: 0;\n}\n@property --tw-border-style {\n syntax: "*";\n inherits: false;\n initial-value: solid;\n}\n@property --tw-leading {\n syntax: "*";\n inherits: false;\n}\n@property --tw-font-weight {\n syntax: "*";\n inherits: false;\n}\n@property --tw-ordinal {\n syntax: "*";\n inherits: false;\n}\n@property --tw-slashed-zero {\n syntax: "*";\n inherits: false;\n}\n@property --tw-numeric-figure {\n syntax: "*";\n inherits: false;\n}\n@property --tw-numeric-spacing {\n syntax: "*";\n inherits: false;\n}\n@property --tw-numeric-fraction {\n syntax: "*";\n inherits: false;\n}\n@property --tw-shadow {\n syntax: "*";\n inherits: false;\n initial-value: 0 0 #0000;\n}\n@property --tw-shadow-color {\n syntax: "*";\n inherits: false;\n}\n@property --tw-shadow-alpha {\n syntax: "<percentage>";\n inherits: false;\n initial-value: 100%;\n}\n@property --tw-inset-shadow {\n syntax: "*";\n inherits: false;\n initial-value: 0 0 #0000;\n}\n@property --tw-inset-shadow-color {\n syntax: "*";\n inherits: false;\n}\n@property --tw-inset-shadow-alpha {\n syntax: "<percentage>";\n inherits: false;\n initial-value: 100%;\n}\n@property --tw-ring-color {\n syntax: "*";\n inherits: false;\n}\n@property --tw-ring-shadow {\n syntax: "*";\n inherits: false;\n initial-value: 0 0 #0000;\n}\n@property --tw-inset-ring-color {\n syntax: "*";\n inherits: false;\n}\n@property --tw-inset-ring-shadow {\n syntax: "*";\n inherits: false;\n initial-value: 0 0 #0000;\n}\n@property --tw-ring-inset {\n syntax: "*";\n inherits: false;\n}\n@property --tw-ring-offset-width {\n syntax: "<length>";\n inherits: false;\n initial-value: 0px;\n}\n@property --tw-ring-offset-color {\n syntax: "*";\n inherits: false;\n initial-value: #fff;\n}\n@property --tw-ring-offset-shadow {\n syntax: "*";\n inherits: false;\n initial-value: 0 0 #0000;\n}\n@property --tw-blur {\n syntax: "*";\n inherits: false;\n}\n@property --tw-brightness {\n syntax: "*";\n inherits: false;\n}\n@property --tw-contrast {\n syntax: "*";\n inherits: false;\n}\n@property --tw-grayscale {\n syntax: "*";\n inherits: false;\n}\n@property --tw-hue-rotate {\n syntax: "*";\n inherits: false;\n}\n@property --tw-invert {\n syntax: "*";\n inherits: false;\n}\n@property --tw-opacity {\n syntax: "*";\n inherits: false;\n}\n@property --tw-saturate {\n syntax: "*";\n inherits: false;\n}\n@property --tw-sepia {\n syntax: "*";\n inherits: false;\n}\n@property --tw-drop-shadow {\n syntax: "*";\n inherits: false;\n}\n@property --tw-drop-shadow-color {\n syntax: "*";\n inherits: false;\n}\n@property --tw-drop-shadow-alpha {\n syntax: "<percentage>";\n inherits: false;\n initial-value: 100%;\n}\n@property --tw-drop-shadow-size {\n syntax: "*";\n inherits: false;\n}\n@property --tw-backdrop-blur {\n syntax: "*";\n inherits: false;\n}\n@property --tw-backdrop-brightness {\n syntax: "*";\n inherits: false;\n}\n@property --tw-backdrop-contrast {\n syntax: "*";\n inherits: false;\n}\n@property --tw-backdrop-grayscale {\n syntax: "*";\n inherits: false;\n}\n@property --tw-backdrop-hue-rotate {\n syntax: "*";\n inherits: false;\n}\n@property --tw-backdrop-invert {\n syntax: "*";\n inherits: false;\n}\n@property --tw-backdrop-opacity {\n syntax: "*";\n inherits: false;\n}\n@property --tw-backdrop-saturate {\n syntax: "*";\n inherits: false;\n}\n@property --tw-backdrop-sepia {\n syntax: "*";\n inherits: false;\n}\n@layer properties {\n *, ::before, ::after, ::backdrop {\n --tw-translate-x: 0;\n --tw-translate-y: 0;\n --tw-translate-z: 0;\n --tw-border-style: solid;\n --tw-leading: initial;\n --tw-font-weight: initial;\n --tw-ordinal: initial;\n --tw-slashed-zero: initial;\n --tw-numeric-figure: initial;\n --tw-numeric-spacing: initial;\n --tw-numeric-fraction: initial;\n --tw-shadow: 0 0 #0000;\n --tw-shadow-color: initial;\n --tw-shadow-alpha: 100%;\n --tw-inset-shadow: 0 0 #0000;\n --tw-inset-shadow-color: initial;\n --tw-inset-shadow-alpha: 100%;\n --tw-ring-color: initial;\n --tw-ring-shadow: 0 0 #0000;\n --tw-inset-ring-color: initial;\n --tw-inset-ring-shadow: 0 0 #0000;\n --tw-ring-inset: initial;\n --tw-ring-offset-width: 0px;\n --tw-ring-offset-color: #fff;\n --tw-ring-offset-shadow: 0 0 #0000;\n --tw-blur: initial;\n --tw-brightness: initial;\n --tw-contrast: initial;\n --tw-grayscale: initial;\n --tw-hue-rotate: initial;\n --tw-invert: initial;\n --tw-opacity: initial;\n --tw-saturate: initial;\n --tw-sepia: initial;\n --tw-drop-shadow: initial;\n --tw-drop-shadow-color: initial;\n --tw-drop-shadow-alpha: 100%;\n --tw-drop-shadow-size: initial;\n --tw-backdrop-blur: initial;\n --tw-backdrop-brightness: initial;\n --tw-backdrop-contrast: initial;\n --tw-backdrop-grayscale: initial;\n --tw-backdrop-hue-rotate: initial;\n --tw-backdrop-invert: initial;\n --tw-backdrop-opacity: initial;\n --tw-backdrop-saturate: initial;\n --tw-backdrop-sepia: initial;\n }\n}\n';
diff --git a/apps/desktop/src/preview/GuestProtocol.ts b/apps/desktop/src/preview/GuestProtocol.ts
index 29011a3db7e..a4fd88c475b 100644
--- a/apps/desktop/src/preview/GuestProtocol.ts
+++ b/apps/desktop/src/preview/GuestProtocol.ts
@@ -14,3 +14,5 @@ export const RECORDING_CONTROLLER_CHANNEL = "preview:recording-controller";
export const PASSKEY_CREATE_CHANNEL = "preview:passkey-create";
export const PASSKEY_GET_CHANNEL = "preview:passkey-get";
export const PASSKEY_BRIDGE_ARGUMENT = "--t3code-preview-passkey-bridge";
+export const ANNOTATION_VOICE_EVENT_CHANNEL = "preview:annotation-voice-event";
+export const ANNOTATION_VOICE_STATE_CHANNEL = "preview:annotation-voice-state";
diff --git a/apps/desktop/src/preview/Manager.test.ts b/apps/desktop/src/preview/Manager.test.ts
index 32b9ad23f9c..26a6386a9ab 100644
--- a/apps/desktop/src/preview/Manager.test.ts
+++ b/apps/desktop/src/preview/Manager.test.ts
@@ -2443,6 +2443,70 @@ describe("PreviewManager", () => {
),
);
+ effectIt.effect("delivers annotation voice state only to the pick session that owns it", () =>
+ withManager((manager) =>
+ Effect.gen(function* () {
+ const firstReady = yield* Deferred.make<void>();
+ const secondReady = yield* Deferred.make<void>();
+ let registrations = 0;
+ const guest = {
+ ...makeTestPreviewWebContents(async () => ({
+ toPNG: () => Buffer.from("unused"),
+ toJPEG: () => Buffer.from("unused"),
+ getSize: () => ({ width: 1, height: 1 }),
+ })),
+ isFocused: () => true,
+ focus: vi.fn(),
+ send: (channel: string, ...args: unknown[]) => {
+ webviewSend(channel, ...args);
+ if (channel === "preview:start-pick")
+ Deferred.doneUnsafe(registrations++ === 0 ? firstReady : secondReady, Effect.void);
+ },
+ once: vi.fn(),
+ ipc: { on: vi.fn(), off: vi.fn(), removeListener: vi.fn() },
+ };
+ fromId.mockReturnValue(guest as never);
+ yield* manager.createTab("tab_1");
+ yield* manager.registerWebview("tab_1", 42);
+ const first = yield* manager
+ .pickElement("tab_1", { sessionId: "first", shortcuts: [] })
+ .pipe(Effect.forkChild);
+ yield* Deferred.await(firstReady);
+ const state = {
+ tabId: "tab_1",
+ sessionId: "first",
+ available: true,
+ phase: "recording" as const,
+ status: "Recording",
+ errorAction: null,
+ preview: null,
+ freezesEditor: true,
+ blocksSubmission: true,
+ level: 0,
+ shortcutLabel: "Ctrl+D",
+ draft: { text: "Tighten spacing", cursor: 15 },
+ };
+ yield* manager.updateAnnotationVoice(state);
+ expect(webviewSend).toHaveBeenCalledWith("preview:annotation-voice-state", state);
+ const second = yield* manager
+ .pickElement("tab_1", { sessionId: "second", shortcuts: [] })
+ .pipe(Effect.forkChild);
+ yield* Deferred.await(secondReady);
+ expect(yield* Fiber.join(first)).toBeNull();
+ webviewSend.mockClear();
+ yield* manager.updateAnnotationVoice(state);
+ expect(webviewSend).not.toHaveBeenCalled();
+ yield* manager.updateAnnotationVoice({ ...state, sessionId: "second" });
+ expect(webviewSend).toHaveBeenCalledOnce();
+ yield* manager.cancelPickElement("tab_1");
+ expect(yield* Fiber.join(second)).toBeNull();
+ webviewSend.mockClear();
+ yield* manager.updateAnnotationVoice({ ...state, sessionId: "second" });
+ expect(webviewSend).not.toHaveBeenCalled();
+ }),
+ ),
+ );
+
effectIt.effect("keeps annotation send grants isolated and updates an active pick", () =>
withManager((manager) =>
Effect.gen(function* () {
diff --git a/apps/desktop/src/preview/Manager.ts b/apps/desktop/src/preview/Manager.ts
index 81ffa8aa8cd..8c090419992 100644
--- a/apps/desktop/src/preview/Manager.ts
+++ b/apps/desktop/src/preview/Manager.ts
@@ -1,10 +1,13 @@
import * as NodeZlib from "node:zlib";
import {
+ DesktopPreviewAnnotationVoiceEventSchema,
DesktopPreviewRecordingInputSchema,
DESKTOP_PREVIEW_RECORDING_CAPTURE_TRIGGER,
} from "@t3tools/contracts";
import type {
DesktopPreviewAnnotationTheme,
+ DesktopPreviewAnnotationVoiceConfig,
+ DesktopPreviewAnnotationVoiceState,
DesktopPreviewColorScheme,
DesktopPreviewFavicon,
DesktopPreviewOpenLinkEvent,
@@ -56,13 +59,19 @@ import * as SynchronizedRef from "effect/SynchronizedRef";
import * as DesktopEnvironment from "../app/DesktopEnvironment.ts";
import * as DesktopRendererHistory from "../telemetry/DesktopRendererHistory.ts";
-import { MENU_ACTION_CHANNEL, PREVIEW_PICTURE_IN_PICTURE_FRAME_CHANNEL } from "../ipc/channels.ts";
+import {
+ MENU_ACTION_CHANNEL,
+ PREVIEW_ANNOTATION_VOICE_EVENT_CHANNEL,
+ PREVIEW_PICTURE_IN_PICTURE_FRAME_CHANNEL,
+} from "../ipc/channels.ts";
import * as DesktopBrowserHost from "./DesktopBrowserHost.ts";
import * as PreviewPasskeys from "./Passkeys.ts";
import * as BrowserSession from "./BrowserSession.ts";
import {
ANNOTATION_CAPTURED_CHANNEL,
ANNOTATION_SEND_ENABLED_CHANNEL,
+ ANNOTATION_VOICE_EVENT_CHANNEL,
+ ANNOTATION_VOICE_STATE_CHANNEL,
ANNOTATION_THEME_CHANNEL,
CANCEL_PICK_CHANNEL,
ELEMENT_PICKED_CHANNEL,
@@ -396,9 +405,14 @@ interface PendingRecording {
}
interface PickSession {
+ readonly voiceSessionId?: string | undefined;
readonly cancel: Effect.Effect<void>;
}
+const decodeAnnotationVoiceEvent = Schema.decodeUnknownOption(
+ DesktopPreviewAnnotationVoiceEventSchema,
+);
+
interface BrowserControlSession {
readonly webContentsId: number;
// Retain the attached Debugger to prevent GC crashes (electron/electron#53376); wc.debugger throws after destruction.
@@ -2074,16 +2088,35 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
});
});
- const pickElement = Effect.fn("PreviewManager.pickElement")(function* (tabId: string) {
+ // Voice state reaches a guest only while its pick session, by id, still owns the tab.
+ const updateAnnotationVoice = Effect.fn("PreviewManager.updateAnnotationVoice")(function* (
+ state: DesktopPreviewAnnotationVoiceState,
+ ) {
+ const sessions = yield* Ref.get(pickSessionsRef);
+ if (sessions.get(state.tabId)?.voiceSessionId !== state.sessionId) return;
+ const wc = yield* requireWebContents(state.tabId);
+ yield* attempt({ operation: "annotationVoice.update", tabId: state.tabId }, () =>
+ wc.send(ANNOTATION_VOICE_STATE_CHANNEL, state),
+ );
+ });
+
+ const pickElement = Effect.fn("PreviewManager.pickElement")(function* (
+ tabId: string,
+ voice?: DesktopPreviewAnnotationVoiceConfig,
+ ) {
const wc = yield* requireWebContents(tabId);
yield* cancelPickElement(tabId);
const annotationTheme = yield* Ref.get(annotationThemeRef);
return yield* Effect.callback<PreviewAnnotationSubmissionResult | null, PreviewManagerError>(
(resume) => {
- const session: PickSession = { cancel: Effect.suspend(() => cancelPickSession()) };
+ const session: PickSession = {
+ voiceSessionId: voice?.sessionId,
+ cancel: Effect.suspend(() => cancelPickSession()),
+ };
const cleanup = Effect.fn("PreviewManager.cleanupPickElement")(function* () {
yield* attempt({ operation: "pickElement.cleanup", tabId, webContentsId: wc.id }, () => {
wc.ipc.removeListener(ELEMENT_PICKED_CHANNEL, onMessage);
+ wc.ipc.removeListener(ANNOTATION_VOICE_EVENT_CHANNEL, onVoiceEvent);
wc.off("destroyed", onDestroyed);
wc.off("did-start-navigation", onNavigated);
}).pipe(Effect.ignore);
@@ -2191,6 +2224,25 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
),
);
};
+ // Only this guest's listener sees these; the renderer still checks the session id.
+ const onVoiceEvent = (_event: Electron.IpcMainEvent, value: unknown) => {
+ const decoded = decodeAnnotationVoiceEvent(value);
+ if (settled || !voice || Option.isNone(decoded)) return;
+ if (decoded.value.sessionId !== voice.sessionId) return;
+ runFork(
+ Effect.gen(function* () {
+ const window = yield* Ref.get(mainWindowRef);
+ if (Option.isNone(window) || window.value.isDestroyed()) return;
+ yield* attempt({ operation: "annotationVoice.forward", tabId }, () =>
+ window.value.webContents.send(
+ PREVIEW_ANNOTATION_VOICE_EVENT_CHANNEL,
+ tabId,
+ decoded.value,
+ ),
+ ).pipe(Effect.ignore);
+ }),
+ );
+ };
const onDestroyed = () => settle(null);
const onNavigated = (
event: Electron.Event<Electron.WebContentsDidStartNavigationEventParams>,
@@ -2210,10 +2262,16 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
if (settled) return;
yield* attempt({ operation: "pickElement.register", tabId, webContentsId: wc.id }, () => {
wc.ipc.on(ELEMENT_PICKED_CHANNEL, onMessage);
+ if (voice) wc.ipc.on(ANNOTATION_VOICE_EVENT_CHANNEL, onVoiceEvent);
wc.once("destroyed", onDestroyed);
wc.on("did-start-navigation", onNavigated);
if (!wc.isFocused()) wc.focus();
- wc.send(START_PICK_CHANNEL, annotationTheme, annotationSendEnabled.get(tabId) === true);
+ wc.send(
+ START_PICK_CHANNEL,
+ annotationTheme,
+ annotationSendEnabled.get(tabId) === true,
+ voice,
+ );
});
});
runFork(
@@ -3312,6 +3370,7 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
openPictureInPicture,
openDevTools,
pickElement,
+ updateAnnotationVoice,
prepareWebview,
reapplyZoom,
refresh,
@@ -3552,7 +3611,11 @@ export class PreviewManager extends Context.Service<
) => Effect.Effect<void, PreviewManagerError>;
readonly pickElement: (
tabId: string,
+ voice?: DesktopPreviewAnnotationVoiceConfig,
) => Effect.Effect<PreviewAnnotationSubmissionResult | null, PreviewManagerError>;
+ readonly updateAnnotationVoice: (
+ state: DesktopPreviewAnnotationVoiceState,
+ ) => Effect.Effect<void, PreviewManagerError>;
readonly cancelPickElement: (tabId: string) => Effect.Effect<void, PreviewManagerError>;
readonly captureScreenshot: (
tabId: string,
@@ -3703,6 +3766,7 @@ export const make = Effect.gen(function* PreviewManagerMake() {
setAnnotationTheme: operations.setAnnotationTheme,
setAnnotationSendEnabled: operations.setAnnotationSendEnabled,
pickElement: operations.pickElement,
+ updateAnnotationVoice: operations.updateAnnotationVoice,
cancelPickElement: operations.cancelPickElement,
captureScreenshot: operations.captureScreenshot,
revealArtifact: operations.revealArtifact,
diff --git a/apps/desktop/src/preview/PickPreload.ts b/apps/desktop/src/preview/PickPreload.ts
index 4cb5987cdeb..0549e166dd6 100644
--- a/apps/desktop/src/preview/PickPreload.ts
+++ b/apps/desktop/src/preview/PickPreload.ts
@@ -1,8 +1,12 @@
// @effect-diagnostics globalDate:off globalTimers:off - This isolated Electron preload does not run inside an Effect runtime.
import { ipcRenderer } from "electron";
import { getElementContext } from "react-grab/primitives";
+import { matchesKeybindingShortcut } from "@t3tools/shared/keybindingMatching";
import type {
DesktopPreviewAnnotationTheme,
+ DesktopPreviewAnnotationVoiceConfig,
+ DesktopPreviewAnnotationVoiceEvent,
+ DesktopPreviewAnnotationVoiceState,
PickedElementPayload,
PickedElementStackFrame,
PreviewAnnotationPayload,
@@ -23,6 +27,8 @@ import {
ANNOTATION_CAPTURED_CHANNEL,
ANNOTATION_SEND_ENABLED_CHANNEL,
ANNOTATION_THEME_CHANNEL,
+ ANNOTATION_VOICE_EVENT_CHANNEL,
+ ANNOTATION_VOICE_STATE_CHANNEL,
CANCEL_PICK_CHANNEL,
ELEMENT_PICKED_CHANNEL,
HUMAN_INPUT_CHANNEL,
@@ -524,7 +530,10 @@ function strokeBounds(
return { x: left, y: top, width: right - left, height: bottom - top };
}
-function startAnnotation(sendEnabled: boolean): void {
+function startAnnotation(
+ sendEnabled: boolean,
+ voice: DesktopPreviewAnnotationVoiceConfig | undefined,
+): void {
activeSession?.teardown(false);
let finished = false;
const host = document.createElement("div");
@@ -595,6 +604,212 @@ function startAnnotation(sendEnabled: boolean): void {
"min-h-8 max-h-24 min-w-0 flex-1 resize-none overflow-y-hidden border-0 border-b border-b-transparent bg-transparent px-0 py-1.5 font-sans text-sm leading-5 text-foreground outline-none ring-0 placeholder:text-muted-foreground focus:border-b-primary focus:outline-none focus:ring-0";
composerRow.appendChild(comment);
+ // Recording happens in the application renderer, which owns the microphone consent.
+ // This guest only draws the controls, forwards trusted gestures, and mirrors state.
+ let voicePhase: DesktopPreviewAnnotationVoiceState["phase"] = "idle";
+ let voiceSettings = false;
+ let voiceBusy = false;
+ let voiceAvailable = false;
+ let voiceKeyCode: string | null = null;
+ let pendingVoiceSubmission: PreviewAnnotationSubmission | null = null;
+ let voiceSubmissionReady = false;
+ const voiceButton = createButton("", "Start voice input");
+ voiceButton.innerHTML =
+ '<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 19v3"/><path d="M19 10v2a7 7 0 0 1-14 0v-2"/><rect x="9" y="2" width="6" height="13" rx="3"/></svg>';
+ voiceButton.className += " h-8 w-8 shrink-0 p-0 text-muted-foreground";
+ voiceButton.hidden = true;
+ voiceButton.setAttribute("aria-label", "Start voice input");
+ composerRow.appendChild(voiceButton);
+ const voiceRow = document.createElement("div");
+ voiceRow.className = "flex min-w-0 items-center justify-end gap-1 px-2 pb-2";
+ voiceRow.hidden = true;
+ const voicePill = document.createElement("div");
+ const voiceCancel = createButton("", "Cancel voice input");
+ voiceCancel.innerHTML =
+ '<svg viewBox="0 0 24 24" width="16" height="16" aria-hidden="true"><path d="m18 6-12 12M6 6l12 12" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>';
+ voiceCancel.className += " h-7 w-7 shrink-0 rounded-full p-0";
+ const voiceFinish = createButton("", "Finish voice input");
+ voiceFinish.className +=
+ " h-7 w-7 shrink-0 rounded-full border-primary bg-primary p-0 text-primary-foreground hover:bg-primary/90";
+ const voiceSkip = createButton("Skip", "Skip transcript cleanup");
+ voiceSkip.className += " h-7 shrink-0 rounded-full px-2.5";
+ const voiceStatus = document.createElement("div");
+ voiceStatus.className = "flex h-7 min-w-0 flex-1 items-center gap-2";
+ voiceStatus.setAttribute("role", "status");
+ const voiceStatusText = document.createElement("span");
+ voiceStatusText.className = "min-w-0 flex-1 truncate text-right text-sm text-muted-foreground";
+ const waveform = document.createElement("div");
+ waveform.className =
+ "flex h-5 min-w-0 flex-1 items-center justify-between gap-px overflow-hidden";
+ waveform.setAttribute("aria-hidden", "true");
+ const waveformLevels = Array<number>(24).fill(0);
+ const waveformBars = waveformLevels.map(() => {
+ const bar = document.createElement("span");
+ bar.className = "h-full w-0.5 shrink-0 origin-center rounded-full bg-primary";
+ bar.style.transform = "scaleY(0.08)";
+ bar.style.opacity = "0.25";
+ waveform.appendChild(bar);
+ return bar;
+ });
+ const voiceElapsed = document.createElement("span");
+ voiceElapsed.className = "shrink-0 text-xs tabular-nums text-muted-foreground";
+ let recordingStartedAt = 0;
+ let elapsedTimer: ReturnType<typeof setInterval> | null = null;
+ const updateElapsed = () => {
+ const seconds = Math.floor((Date.now() - recordingStartedAt) / 1_000);
+ voiceElapsed.textContent = `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, "0")}`;
+ };
+ voiceStatus.append(voiceStatusText, waveform, voiceElapsed);
+ voicePill.append(voiceCancel, voiceStatus, voiceSkip, voiceFinish);
+ voiceRow.appendChild(voicePill);
+ const voicePreview = document.createElement("p");
+ voicePreview.className = "px-2 pb-2 text-sm text-muted-foreground";
+ voicePreview.setAttribute("role", "status");
+ voicePreview.hidden = true;
+ const sendVoice = (
+ action: DesktopPreviewAnnotationVoiceEvent["action"],
+ keyboard?: KeyboardEvent,
+ ) => {
+ if (!voice || finished) return;
+ const event: DesktopPreviewAnnotationVoiceEvent = {
+ sessionId: voice.sessionId,
+ text: comment.value,
+ cursor: comment.selectionStart,
+ selectionEnd: comment.selectionEnd,
+ action,
+ ...(keyboard
+ ? {
+ keyboard: {
+ type: keyboard.type === "keyup" ? ("keyup" as const) : ("keydown" as const),
+ key: keyboard.key,
+ code: keyboard.code,
+ metaKey: keyboard.metaKey,
+ ctrlKey: keyboard.ctrlKey,
+ shiftKey: keyboard.shiftKey,
+ altKey: keyboard.altKey,
+ repeat: keyboard.repeat,
+ },
+ }
+ : {}),
+ };
+ ipcRenderer.send(ANNOTATION_VOICE_EVENT_CHANNEL, event);
+ };
+ const isDictationChord = (event: KeyboardEvent) =>
+ voice !== undefined &&
+ voice.shortcuts.some((shortcut) =>
+ matchesKeybindingShortcut(event, shortcut, navigator.platform),
+ );
+ for (const button of [voiceButton, voiceFinish, voiceCancel, voiceSkip]) {
+ button.addEventListener("pointerdown", (event) => event.preventDefault());
+ }
+ // Page scripts cannot reach the closed shadow root, and a synthetic click never counts.
+ voiceButton.addEventListener("click", (event) => {
+ if (!event.isTrusted) return;
+ if (voiceSettings) {
+ sendVoice("settings");
+ return;
+ }
+ if (!voiceAvailable || (voiceBusy && voicePhase !== "recording")) return;
+ sendVoice(voicePhase === "recording" ? "stop" : "start");
+ });
+ voiceFinish.addEventListener("click", (event) => {
+ if (event.isTrusted) sendVoice("stop");
+ });
+ voiceCancel.addEventListener("click", (event) => {
+ if (!event.isTrusted) return;
+ pendingVoiceSubmission = null;
+ sendVoice("cancel");
+ });
+ voiceSkip.addEventListener("click", (event) => {
+ if (event.isTrusted) sendVoice("skip");
+ });
+ const onVoiceState = (
+ _event: Electron.IpcRendererEvent,
+ state: DesktopPreviewAnnotationVoiceState,
+ ) => {
+ if (finished || state.sessionId !== voice?.sessionId) return;
+ const phaseChanged = voicePhase !== state.phase;
+ const submissionChanged = voiceBusy !== state.blocksSubmission;
+ const previewChanged = voicePreview.textContent !== (state.preview ?? "");
+ voicePhase = state.phase;
+ voiceSettings = state.errorAction === "settings";
+ voiceBusy = state.blocksSubmission;
+ voiceAvailable = state.available;
+ comment.readOnly = state.freezesEditor;
+ if (state.draft) {
+ voiceSubmissionReady = pendingVoiceSubmission !== null;
+ comment.value = state.draft.text;
+ comment.setSelectionRange(state.draft.cursor, state.draft.cursor);
+ resizeComment();
+ }
+ const recording = state.phase === "recording";
+ const active = state.phase !== "idle" && state.phase !== "error";
+ voiceButton.hidden = !state.available || active;
+ voiceButton.disabled = voiceBusy;
+ const label = voiceSettings ? "Open voice settings" : "Start voice input";
+ voiceButton.title =
+ !voiceSettings && state.shortcutLabel ? `${label} (${state.shortcutLabel})` : label;
+ voiceButton.setAttribute("aria-label", label);
+ voiceRow.hidden = state.phase === "idle";
+ voicePill.className = active
+ ? "flex h-9 w-64 min-w-0 items-center gap-2 rounded-full border border-border bg-background p-1"
+ : "flex min-w-0 items-center gap-1";
+ voiceCancel.title =
+ state.phase === "error" ? "Dismiss voice input error" : "Cancel voice input";
+ voiceCancel.setAttribute("aria-label", voiceCancel.title);
+ voiceStatus.setAttribute("aria-label", state.status ?? "Voice input");
+ voiceStatus.setAttribute("aria-live", recording ? "off" : "polite");
+ voiceStatusText.textContent = state.status;
+ voiceStatusText.style.color = state.phase === "error" ? "var(--t3-destructive)" : "";
+ voiceStatusText.hidden = recording;
+ waveform.hidden = !recording;
+ voiceElapsed.hidden = !recording;
+ if (recording && elapsedTimer === null) {
+ recordingStartedAt = Date.now();
+ waveformLevels.fill(0);
+ updateElapsed();
+ elapsedTimer = setInterval(updateElapsed, 250);
+ } else if (!recording && elapsedTimer !== null) {
+ clearInterval(elapsedTimer);
+ elapsedTimer = null;
+ }
+ if (recording) {
+ waveformLevels.copyWithin(0, 1);
+ waveformLevels[waveformLevels.length - 1] = state.level;
+ const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
+ waveformBars.forEach((bar, index) => {
+ const level = waveformLevels[index] ?? 0;
+ bar.style.opacity = String(0.25 + level * 0.75);
+ bar.style.transform = `scaleY(${reducedMotion ? 0.35 : Math.max(0.08, level)})`;
+ });
+ }
+ voiceSkip.hidden = state.phase !== "post-processing";
+ voiceFinish.hidden = !active || state.phase === "post-processing";
+ voiceFinish.disabled = !recording;
+ voiceFinish.title = recording ? "Finish voice input" : (state.status ?? "Voice input is busy");
+ if (recording && state.shortcutLabel) voiceFinish.title += ` (${state.shortcutLabel})`;
+ voiceFinish.setAttribute("aria-label", voiceFinish.title);
+ if (phaseChanged)
+ voiceFinish.innerHTML = recording
+ ? '<svg viewBox="0 0 24 24" width="16" height="16" aria-hidden="true"><path d="m5 12 4 4L19 6" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>'
+ : '<svg viewBox="0 0 24 24" width="16" height="16" aria-hidden="true"><path d="M12 2a10 10 0 1 0 10 10" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>';
+ if (!active) voicePill.append(voiceStatus, voiceCancel);
+ else if (phaseChanged) voicePill.append(voiceCancel, voiceStatus, voiceSkip, voiceFinish);
+ voicePreview.textContent = state.preview;
+ voicePreview.hidden = !state.preview;
+ if (phaseChanged || submissionChanged || previewChanged || state.draft) updateStatus();
+ if (pendingVoiceSubmission !== null) {
+ if (state.phase === "recording") sendVoice("stop");
+ if (state.phase === "error") pendingVoiceSubmission = null;
+ if (state.phase === "idle") {
+ const submission = pendingVoiceSubmission;
+ pendingVoiceSubmission = null;
+ if (voiceSubmissionReady && submission !== null) submitAnnotation(submission);
+ voiceSubmissionReady = false;
+ }
+ }
+ };
+
const dragHandle = document.createElement("button");
dragHandle.type = "button";
dragHandle.textContent = "⠿";
@@ -613,7 +828,7 @@ function startAnnotation(sendEnabled: boolean): void {
submit.className +=
" h-8 shrink-0 border-primary bg-primary px-3 text-primary-foreground shadow-sm hover:bg-primary/90";
composerRow.appendChild(submit);
- editor.appendChild(composerRow);
+ editor.append(composerRow, voicePreview, voiceRow);
const stylePanel = document.createElement("div");
stylePanel.className =
@@ -654,12 +869,19 @@ function startAnnotation(sendEnabled: boolean): void {
comment.style.overflowY = comment.scrollHeight > maxHeight ? "auto" : "hidden";
queueEditorLayout();
};
- comment.addEventListener("input", resizeComment);
+ comment.addEventListener("input", () => {
+ resizeComment();
+ sendVoice("sync");
+ });
const updateStatus = (): void => {
const hasTargets = selected.size > 0 || regions.length > 0 || strokes.length > 0;
+ if (!hasTargets && voiceBusy) {
+ pendingVoiceSubmission = null;
+ sendVoice("cancel");
+ }
editor.style.display = hasTargets ? "flex" : "none";
- submit.disabled = !hasTargets;
+ submit.disabled = !hasTargets || voicePhase === "preparing" || pendingCapture;
submit.style.opacity = hasTargets ? "1" : "0.45";
adjust.disabled = !hasTargets;
stylePanel.style.display = editorExpanded && selected.size > 0 ? "grid" : "none";
@@ -695,7 +917,6 @@ function startAnnotation(sendEnabled: boolean): void {
for (const [key, change] of styleChanges) {
if (change.targetId === target.id) styleChanges.delete(key);
}
- updateStatus();
};
const addSelected = (element: Element): void => {
@@ -710,7 +931,6 @@ function startAnnotation(sendEnabled: boolean): void {
selected.set(element, target);
root.append(target.outline, target.label);
updateSelectedVisual(target);
- updateStatus();
if (editorExpanded) {
stylePanel.style.display = "grid";
syncStyleControls();
@@ -721,12 +941,13 @@ function startAnnotation(sendEnabled: boolean): void {
const existing = selected.get(element);
if (existing) {
removeSelected(existing);
- return;
- }
- if (!additive) {
- for (const target of Array.from(selected.values())) removeSelected(target);
+ } else {
+ if (!additive) {
+ for (const target of Array.from(selected.values())) removeSelected(target);
+ }
+ addSelected(element);
}
- addSelected(element);
+ updateStatus();
};
const setStyleForSelected = (property: string, value: string): void => {
@@ -1140,6 +1361,7 @@ function startAnnotation(sendEnabled: boolean): void {
const rect = target.element.getBoundingClientRect();
if (x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom) {
removeSelected(target);
+ updateStatus();
return true;
}
}
@@ -1318,7 +1540,11 @@ function startAnnotation(sendEnabled: boolean): void {
if (event.relatedTarget === null) clearHoverOutline();
};
+ const onWindowFocus = (): void => {
+ if (editor.style.display !== "none") sendVoice("focus");
+ };
const onWindowBlur = (): void => {
+ sendVoice("blur");
clearHoverOutline();
};
@@ -1344,7 +1570,9 @@ function startAnnotation(sendEnabled: boolean): void {
window.removeEventListener("pointerout", onPointerOut, true);
window.removeEventListener("click", onClick, true);
window.removeEventListener("blur", onWindowBlur);
+ window.removeEventListener("focus", onWindowFocus);
window.removeEventListener("keydown", onKeyDown, true);
+ window.removeEventListener("keyup", onVoiceKeyUp, true);
window.removeEventListener("scroll", repaint, true);
window.removeEventListener("resize", repaint);
dragHandle.removeEventListener("pointerdown", onEditorPointerDown);
@@ -1354,6 +1582,8 @@ function startAnnotation(sendEnabled: boolean): void {
if (editorLayoutFrame !== null) window.cancelAnimationFrame(editorLayoutFrame);
ipcRenderer.off(CANCEL_PICK_CHANNEL, onCancel);
ipcRenderer.off(ANNOTATION_CAPTURED_CHANNEL, onCaptured);
+ ipcRenderer.off(ANNOTATION_VOICE_STATE_CHANNEL, onVoiceState);
+ if (elapsedTimer !== null) clearInterval(elapsedTimer);
document.documentElement.removeAttribute("data-t3code-annotation-tool");
cursorStyle.remove();
inputLayer?.remove();
@@ -1364,7 +1594,32 @@ function startAnnotation(sendEnabled: boolean): void {
const onCancel = (): void => teardown(false);
const onCaptured = (): void => teardown(false);
+ const onVoiceKeyUp = (event: KeyboardEvent): void => {
+ if (!event.isTrusted || (event.code || event.key) !== voiceKeyCode) return;
+ voiceKeyCode = null;
+ event.preventDefault();
+ event.stopImmediatePropagation();
+ sendVoice("key", event);
+ };
const onKeyDown = (event: KeyboardEvent): void => {
+ // Only the keyboard drives dictation; a page cannot synthesize the chord or Escape.
+ if (voice && event.isTrusted && !event.isComposing && event.keyCode !== 229) {
+ if (event.key === "Escape" && voiceBusy) {
+ event.preventDefault();
+ event.stopImmediatePropagation();
+ voiceKeyCode = null;
+ pendingVoiceSubmission = null;
+ sendVoice("key", event);
+ return;
+ }
+ if (voiceAvailable && editor.style.display !== "none" && isDictationChord(event)) {
+ event.preventDefault();
+ event.stopImmediatePropagation();
+ voiceKeyCode = event.code || event.key;
+ sendVoice("key", event);
+ return;
+ }
+ }
if (isAnnotationNode(event.target as Element) && event.key !== "Escape") return;
if (event.key === "Escape") {
event.preventDefault();
@@ -1382,6 +1637,16 @@ function startAnnotation(sendEnabled: boolean): void {
const submitAnnotation = (submission: PreviewAnnotationSubmission): void => {
if (submission === "send" && !sendEnabled) return;
+ if (voicePhase === "preparing") return;
+ // Submitting while dictating finishes the recording and submits once the text lands.
+ if (voiceBusy) {
+ if (pendingVoiceSubmission === null) {
+ pendingVoiceSubmission = submission;
+ voiceSubmissionReady = false;
+ if (voicePhase === "recording") sendVoice("stop");
+ }
+ return;
+ }
if (pendingCapture || (selected.size === 0 && regions.length === 0 && strokes.length === 0))
return;
pendingCapture = true;
@@ -1460,11 +1725,14 @@ function startAnnotation(sendEnabled: boolean): void {
window.addEventListener("pointerout", onPointerOut, { capture: true, passive: true });
window.addEventListener("click", onClick, { capture: true, passive: false });
window.addEventListener("blur", onWindowBlur);
+ window.addEventListener("focus", onWindowFocus);
window.addEventListener("keydown", onKeyDown, { capture: true });
+ window.addEventListener("keyup", onVoiceKeyUp, { capture: true });
window.addEventListener("scroll", repaint, { capture: true, passive: true });
window.addEventListener("resize", repaint, { passive: true });
ipcRenderer.on(CANCEL_PICK_CHANNEL, onCancel);
ipcRenderer.on(ANNOTATION_CAPTURED_CHANNEL, onCaptured);
+ if (voice) ipcRenderer.on(ANNOTATION_VOICE_STATE_CHANNEL, onVoiceState);
if (inputLayer) {
document.documentElement.appendChild(inputLayer);
inputLayer.focus({ preventScroll: true });
@@ -1473,6 +1741,7 @@ function startAnnotation(sendEnabled: boolean): void {
rootResizeObserver.observe(document.documentElement);
refreshToolButtons();
updateStatus();
+ sendVoice(document.hasFocus() ? "focus" : "sync");
activeSession = {
teardown,
applyTheme: (theme) => applyAnnotationTheme(host, theme),
@@ -1485,9 +1754,14 @@ function startAnnotation(sendEnabled: boolean): void {
ipcRenderer.on(
START_PICK_CHANNEL,
- (_event, theme: DesktopPreviewAnnotationTheme | undefined, sendEnabled?: boolean) => {
+ (
+ _event,
+ theme: DesktopPreviewAnnotationTheme | undefined,
+ sendEnabled?: boolean,
+ voice?: DesktopPreviewAnnotationVoiceConfig,
+ ) => {
if (theme) annotationTheme = theme;
- startAnnotation(sendEnabled === true);
+ startAnnotation(sendEnabled === true, voice);
},
);
ipcRenderer.on(ANNOTATION_SEND_ENABLED_CHANNEL, (_event, enabled: boolean) => {
diff --git a/apps/desktop/vite.config.ts b/apps/desktop/vite.config.ts
index 0d0a74d510b..d06efd4d9d7 100644
--- a/apps/desktop/vite.config.ts
+++ b/apps/desktop/vite.config.ts
@@ -120,7 +120,10 @@ export default defineConfig({
outExtensions: () => ({ js: ".cjs" }),
entry: ["src/preview-pick-preload.ts"],
deps: {
- alwaysBundle: (id) => id === "react-grab" || id.startsWith("react-grab/"),
+ alwaysBundle: (id) =>
+ id === "react-grab" ||
+ id.startsWith("react-grab/") ||
+ id === "@t3tools/shared/keybindingMatching",
},
},
{
diff --git a/apps/web/src/components/chat/ComposerSpeechButton.tsx b/apps/web/src/components/chat/ComposerSpeechButton.tsx
index c0047b255ed..8a258f47e32 100644
--- a/apps/web/src/components/chat/ComposerSpeechButton.tsx
+++ b/apps/web/src/components/chat/ComposerSpeechButton.tsx
@@ -17,7 +17,7 @@ type SpeechPresentation = {
showsSend: boolean;
};
-function resolveSpeechPresentation(
+export function resolveSpeechPresentation(
state: VoiceInputState,
progress: { downloaded: number; total: number } | null,
): SpeechPresentation {
diff --git a/apps/web/src/components/preview/PreviewAnnotationSpeech.tsx b/apps/web/src/components/preview/PreviewAnnotationSpeech.tsx
new file mode 100644
index 00000000000..5bb06553b25
--- /dev/null
+++ b/apps/web/src/components/preview/PreviewAnnotationSpeech.tsx
@@ -0,0 +1,194 @@
+import { scopeProjectRef } from "@t3tools/client-runtime/environment";
+import type {
+ DesktopPreviewAnnotationVoiceConfig,
+ DesktopPreviewAnnotationVoiceEvent,
+ ScopedThreadRef,
+} from "@t3tools/contracts";
+import { useNavigate } from "@tanstack/react-router";
+import { useEffect, useRef, useState } from "react";
+
+import { resolveSpeechPresentation } from "~/components/chat/ComposerSpeechButton";
+import { VoiceInputSetup } from "~/components/chat/VoiceInputSetup";
+import { toastManager } from "~/components/ui/toast";
+import { useComposerDraftStore } from "~/composerDraftStore";
+import { useStableCallback } from "~/hooks/useStableCallback";
+import { useDictationShortcut, type DictationKeyHandlers } from "~/speech/useDictationShortcut";
+import { useEnvironmentSpeechInput } from "~/speech/useEnvironmentSpeechInput";
+import { useProject, useThreadShell } from "~/state/entities";
+import { previewBridge } from "./previewBridge";
+
+/**
+ * The annotation editor lives inside the preview guest, which only forwards trusted gestures
+ * and mirrors state. Recording, consent, and transcription stay in this renderer.
+ */
+export function PreviewAnnotationSpeech({
+ threadRef,
+ tabId,
+ config,
+ keybindings,
+}: {
+ threadRef: ScopedThreadRef;
+ tabId: string;
+ config: DesktopPreviewAnnotationVoiceConfig;
+ keybindings: Parameters<typeof useDictationShortcut>[0]["keybindings"];
+}) {
+ const navigate = useNavigate();
+ const thread = useThreadShell(threadRef);
+ const draftThread = useComposerDraftStore((store) => store.getDraftThreadByRef(threadRef));
+ const projectId = thread?.projectId ?? draftThread?.projectId ?? null;
+ const project = useProject(
+ projectId ? scopeProjectRef(threadRef.environmentId, projectId) : null,
+ );
+ const draft = useRef({ text: "", cursor: 0, selectionEnd: 0 });
+ const [text, setText] = useState("");
+ const keys = useRef<DictationKeyHandlers | null>(null);
+ const guestFocused = useRef(false);
+ // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- notices focus returning from the preview guest to this window
+ useEffect(() => {
+ const onFocus = () => {
+ guestFocused.current = false;
+ };
+ window.addEventListener("focus", onFocus);
+ window.addEventListener("focusin", onFocus);
+ return () => {
+ window.removeEventListener("focus", onFocus);
+ window.removeEventListener("focusin", onFocus);
+ };
+ }, []);
+ const speech = useEnvironmentSpeechInput({
+ environmentId: threadRef.environmentId,
+ projectId,
+ projectName: project?.title,
+ ownerKey: JSON.stringify(["preview-annotation", threadRef, tabId, config.sessionId]),
+ draftText: text,
+ readDraft: () => ({
+ text: draft.current.text,
+ selection: { start: draft.current.cursor, end: draft.current.selectionEnd },
+ }),
+ commitDraft: (next, selection) => {
+ draft.current = { text: next, cursor: selection.start, selectionEnd: selection.end };
+ setText(next);
+ void publish(current.current.voiceState, { text: next, cursor: selection.start });
+ },
+ });
+ const subscribeKeys = useStableCallback((handlers: DictationKeyHandlers) => {
+ keys.current = handlers;
+ return () => {
+ keys.current = null;
+ };
+ });
+ const shortcutLabel = useDictationShortcut({
+ keybindings,
+ speech,
+ disabled: false,
+ terminalOpen: false,
+ modelPickerOpen: false,
+ previewFocus: true,
+ ownsFocus: () => guestFocused.current,
+ subscribeKeys,
+ });
+ const { available, state, preview, freezesEditor, blocksSubmission, level } = speech;
+ const voiceState = {
+ tabId,
+ sessionId: config.sessionId,
+ available,
+ phase: state.phase,
+ errorAction: state.errorAction,
+ status: resolveSpeechPresentation(state, null).status,
+ preview: preview ? preview.committed + preview.tentative : null,
+ level,
+ shortcutLabel,
+ freezesEditor,
+ blocksSubmission,
+ };
+ const current = useRef({ speech, voiceState });
+ // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- publishes committed speech actions and state to the desktop IPC listener
+ useEffect(() => {
+ current.current = { speech, voiceState };
+ });
+ const publish = useStableCallback(
+ async (voice: typeof voiceState, nextDraft: { text: string; cursor: number } | null) => {
+ try {
+ await previewBridge?.annotationVoice.update({ ...voice, draft: nextDraft });
+ } catch (error) {
+ current.current.speech.cancel();
+ toastManager.add({
+ type: "error",
+ title: "Could not update annotation voice input",
+ description: error instanceof Error ? error.message : String(error),
+ });
+ }
+ },
+ );
+ // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- mirrors every committed voice state change into the preview guest
+ useEffect(() => {
+ void publish(voiceState, null);
+ }, [publish, voiceState]);
+ // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes to gestures the preview guest relays for this session
+ useEffect(
+ () =>
+ previewBridge?.annotationVoice.onEvent(
+ (eventTabId, event: DesktopPreviewAnnotationVoiceEvent) => {
+ if (eventTabId !== tabId || event.sessionId !== config.sessionId) return;
+ draft.current = {
+ text: event.text,
+ cursor: Math.min(event.cursor, event.text.length),
+ selectionEnd: Math.min(event.selectionEnd ?? event.cursor, event.text.length),
+ };
+ setText(event.text);
+ if (event.action === "focus" || event.action === "key" || event.action === "start")
+ guestFocused.current = true;
+ if (event.action === "blur") guestFocused.current = false;
+ const value = current.current.speech;
+ switch (event.action) {
+ case "focus":
+ case "sync":
+ void publish(current.current.voiceState, null);
+ break;
+ case "start":
+ void value.start();
+ break;
+ case "stop":
+ void value.stop();
+ break;
+ case "cancel":
+ value.cancel();
+ break;
+ case "settings":
+ value.cancel();
+ void navigate({ to: "/settings/voice" });
+ break;
+ case "skip":
+ value.skipPostProcessing();
+ break;
+ case "blur":
+ keys.current?.blur();
+ break;
+ case "key": {
+ if (!event.keyboard) break;
+ keys.current?.[event.keyboard.type](
+ new KeyboardEvent(event.keyboard.type, event.keyboard),
+ );
+ break;
+ }
+ }
+ },
+ ),
+ [tabId, config.sessionId, publish, navigate],
+ );
+ return (
+ <VoiceInputSetup
+ environmentId={speech.transcriptionEnvironmentId}
+ open={speech.setup.open}
+ step={speech.setup.step}
+ status={speech.status}
+ model={speech.setup.model}
+ downloading={speech.setup.downloading}
+ error={speech.setup.error}
+ onOpenChange={speech.setup.setOpen}
+ onDownload={() => void speech.setup.download()}
+ onCancelDownload={() => void speech.setup.cancelDownload()}
+ onStartRecording={() => void speech.setup.startRecording()}
+ />
+ );
+}
diff --git a/apps/web/src/components/preview/PreviewView.browser.test.tsx b/apps/web/src/components/preview/PreviewView.browser.test.tsx
index cdc49b336f4..a73f88be9fd 100644
--- a/apps/web/src/components/preview/PreviewView.browser.test.tsx
+++ b/apps/web/src/components/preview/PreviewView.browser.test.tsx
@@ -54,6 +54,7 @@ vi.mock(import("./previewBridge"), async (original) => ({
previewBridge: {
navigate: mocks.navigate,
pickElement: mocks.pickElement,
+ annotationVoice: { onEvent: () => () => {}, update: async () => {} },
setAnnotationSendEnabled: mocks.setAnnotationSendEnabled,
cancelPickElement: mocks.cancelPickElement,
refresh: vi.fn(async () => undefined),
diff --git a/apps/web/src/components/preview/PreviewView.tsx b/apps/web/src/components/preview/PreviewView.tsx
index 28779191d77..253a4fc14e5 100644
--- a/apps/web/src/components/preview/PreviewView.tsx
+++ b/apps/web/src/components/preview/PreviewView.tsx
@@ -1,5 +1,7 @@
+import { useAtomValue } from "@effect/atom-react";
import { scopedThreadKey } from "@t3tools/client-runtime/environment";
import { settlePromise } from "@t3tools/client-runtime/state/runtime";
+import type { DesktopPreviewAnnotationVoiceConfig } from "@t3tools/contracts";
import { previewStreamDownloadUrl } from "@t3tools/client-runtime/preview/server-browser-stream";
import {
isAtomCommandInterrupted,
@@ -57,6 +59,10 @@ import {
import { readEnvironmentScope, useEnvironmentScope } from "~/state/session";
import { useRightPanelStore } from "~/rightPanelStore";
+import { effectiveShortcutsForCommand } from "~/keybindings";
+import { randomUUID } from "~/lib/utils";
+import { primaryServerKeybindingsAtom } from "~/state/server";
+import { PreviewAnnotationSpeech } from "./PreviewAnnotationSpeech";
import { previewBridge } from "./previewBridge";
import { subscribePreviewAction } from "./previewActionBus";
import { closePreviewSession } from "./closePreviewSession";
@@ -153,6 +159,9 @@ export function PreviewView({
Boolean(onSendAnnotation);
const activeRecordingTabIds = useActiveBrowserRecordingTabIds();
const pickActiveRef = useRef<{ cancelled: boolean } | null>(null);
+ const [annotationVoice, setAnnotationVoice] =
+ useState<DesktopPreviewAnnotationVoiceConfig | null>(null);
+ const keybindings = useAtomValue(primaryServerKeybindingsAtom);
const previewState = useThreadPreviewState(threadRef);
const recentHistoryEntries = useThreadRecentHistory(
threadRef,
@@ -738,11 +747,20 @@ export function PreviewView({
let submitted = false;
pickActiveRef.current = pickRequest;
setPickActive(true);
+ // The guest learns only the dictation chords, never the whole keybinding config.
+ const voice: DesktopPreviewAnnotationVoiceConfig = {
+ sessionId: randomUUID(),
+ shortcuts: effectiveShortcutsForCommand(keybindings, "composer.dictation", {
+ context: { previewFocus: true, previewOpen: true, editableFocus: true },
+ }),
+ };
+ setAnnotationVoice(voice);
const finishPick = () => {
const isCurrentPick = pickActiveRef.current === pickRequest;
if (isCurrentPick) {
pickActiveRef.current = null;
setPickActive(false);
+ setAnnotationVoice(null);
}
if (
(isCurrentPick || submitted) &&
@@ -763,12 +781,13 @@ export function PreviewView({
readEnvironmentScope(threadRef.environmentId, AuthOrchestrationOperateScope),
);
if (pickRequest.cancelled) return;
- const result = await bridge.pickElement(runtimeTabId);
+ const result = await bridge.pickElement(runtimeTabId, voice);
if (!result || pickRequest.cancelled) return;
// The accepted pick must survive further clicks, tab changes, and unmount; stop cancellation here.
if (pickActiveRef.current === pickRequest) {
pickActiveRef.current = null;
setPickActive(false);
+ setAnnotationVoice(null);
submitted = true;
}
const { annotation: picked, submission, screenshotFailed = false } = result;
@@ -830,6 +849,7 @@ export function PreviewView({
void previewBridge.cancelPickElement(runtimeTabId).catch(() => undefined);
}
setPickActive(false);
+ setAnnotationVoice(null);
};
}, [runtimeTabId]);
@@ -875,6 +895,15 @@ export function PreviewView({
className="flex min-h-0 flex-1 flex-col bg-background"
data-thread-key={scopedThreadKey(threadRef)}
>
+ {pickActive && runtimeTabId && annotationVoice ? (
+ <PreviewAnnotationSpeech
+ key={annotationVoice.sessionId}
+ threadRef={threadRef}
+ tabId={runtimeTabId}
+ config={annotationVoice}
+ keybindings={keybindings}
+ />
+ ) : null}
<PreviewChromeRow
url={url}
loading={loading || serverStreamPending}
diff --git a/apps/web/src/speech/useDictationShortcut.ts b/apps/web/src/speech/useDictationShortcut.ts
index 955bd9e5c4f..6acbe5fac1e 100644
--- a/apps/web/src/speech/useDictationShortcut.ts
+++ b/apps/web/src/speech/useDictationShortcut.ts
@@ -21,14 +21,26 @@ type SpeechActions = {
cancel(): void;
};
+export type DictationKeyHandlers = {
+ keydown(event: KeyboardEvent): void;
+ keyup(event: KeyboardEvent): void;
+ blur(): void;
+};
+
type ShortcutInput = {
keybindings: ResolvedKeybindingsConfig;
speech: SpeechActions;
disabled: boolean;
terminalOpen: boolean;
modelPickerOpen: boolean;
+ /** Resolve the chord as if the preview had focus; the keys arrive relayed from its guest. */
+ previewFocus?: boolean;
/** When set, the chord targets this editor only while it has focus. */
targetRef?: RefObject<HTMLElement | null>;
+ /** An editor outside this document reports whether it holds the keyboard. */
+ ownsFocus?: () => boolean;
+ /** Receives handlers that replay keys an outside editor relayed, as if typed here. */
+ subscribeKeys?: (handlers: DictationKeyHandlers) => () => void;
};
// Several editors can bind the chord; the busy one, then the focused one, then the untargeted one wins.
@@ -41,15 +53,16 @@ function ownsShortcut(id: symbol) {
return phase !== "idle" && phase !== "error";
});
if (busy) return busy[0] === id;
- const focused = entries.find(([, read]) =>
- read().targetRef?.current?.contains(document.activeElement),
- );
+ const focused =
+ entries.find(([, read]) => read().ownsFocus?.()) ??
+ entries.find(([, read]) => read().targetRef?.current?.contains(document.activeElement));
if (focused) return focused[0] === id;
- return entries.find(([, read]) => !read().targetRef)?.[0] === id;
+ return entries.find(([, read]) => !read().targetRef && !read().ownsFocus)?.[0] === id;
}
export function useDictationShortcut(input: ShortcutInput) {
const id = useRef(Symbol("dictation-target"));
+ const subscribeKeys = input.subscribeKeys;
const mode = useClientSettings((settings) => settings.voiceShortcutMode);
const current = useRef(input);
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- publishes committed actions to the window keyboard listener and shortcut registry
@@ -100,11 +113,15 @@ export function useDictationShortcut(input: ShortcutInput) {
return;
}
const { keybindings, terminalOpen, modelPickerOpen, disabled } = current.current;
+ const previewFocus = current.current.previewFocus ?? false;
const command = resolveShortcutCommand(event, keybindings, {
context: {
terminalFocus: getTerminalFocusOwner() !== null,
terminalOpen,
modelPickerOpen,
+ previewFocus,
+ previewOpen: previewFocus,
+ ...(previewFocus ? { editableFocus: true } : {}),
},
});
if (command !== "composer.dictation") return;
@@ -129,6 +146,11 @@ export function useDictationShortcut(input: ShortcutInput) {
};
};
const onBlur = () => finish(null);
+ const unsubscribe = subscribeKeys?.({
+ keydown: (event) => window.dispatchEvent(event),
+ keyup: (event) => window.dispatchEvent(event),
+ blur: onBlur,
+ });
window.addEventListener("keydown", onKeyDown, true);
window.addEventListener("keyup", finish, true);
window.addEventListener("blur", onBlur);
@@ -136,11 +158,12 @@ export function useDictationShortcut(input: ShortcutInput) {
disposed = true;
pressed.current = null;
shortcutTargets.delete(id.current);
+ unsubscribe?.();
window.removeEventListener("keydown", onKeyDown, true);
window.removeEventListener("keyup", finish, true);
window.removeEventListener("blur", onBlur);
};
- }, [mode]);
+ }, [mode, subscribeKeys]);
return shortcutLabelForCommand(input.keybindings, "composer.dictation", {
context: { terminalFocus: false, terminalOpen: input.terminalOpen },
diff --git a/docs/user/voice-input.md b/docs/user/voice-input.md
index 33da1b4ac3a..0f43c1022e5 100644
--- a/docs/user/voice-input.md
+++ b/docs/user/voice-input.md
@@ -2,8 +2,9 @@
Dictate into the composer instead of typing. The transcript lands in your draft
for review, and only sending the message sends anything to an agent. Dictation
-also works in citation comments, diff and file annotations, and pull request
-comments, replies, and review summaries.
+also works in citation comments, diff and file annotations, pull request
+comments, replies, and review summaries, and in the desktop app's browser
+annotation editor.
On iPhone and Android, voice input transcribes on the device. See
[Voice input on mobile](./composer.md#voice-input-on-mobile).
@@ -47,9 +48,11 @@ when recording started, and the editor is read-only while dictation runs.
Pressing Send while dictating finishes the recording and sends the draft once
the transcript has been inserted. Cancelling also cancels that queued send. In
-the other editors, Save, Comment, Reply, or Submit review works the same way,
-and the shortcut targets the editor that has focus, or the composer when none
-does.
+the other editors, Save, Comment, Reply, Submit review, or Attach works the
+same way, and the shortcut targets the editor that has focus, or the composer
+when none does. In the desktop browser's annotation editor, the microphone and
+the shortcut work while the page has focus; the page you are annotating never
+sees the recording, which runs in T3 Code itself.
**Dictation shortcut** in Voice settings picks how the keybinding behaves:
**Auto** tap-toggles or records while held, **Hold** records only while the keys
diff --git a/packages/contracts/src/ipc.ts b/packages/contracts/src/ipc.ts
index b2f12cb83d6..6f1354dcdd9 100644
--- a/packages/contracts/src/ipc.ts
+++ b/packages/contracts/src/ipc.ts
@@ -14,7 +14,7 @@ import { AdvertisedEndpoint } from "./remoteAccess.ts";
import { ExecutionEnvironmentDescriptor } from "./environment.ts";
import { type ClientSettings, type QuitConfirmationMode, SnapShotShortcut } from "./settings.ts";
import type { EditorId } from "./editor.ts";
-import type { PreviewForwardedShortcut } from "./keybindings.ts";
+import { KeybindingShortcut, type PreviewForwardedShortcut } from "./keybindings.ts";
import type {
DesktopAppActivationRequest,
@@ -1154,6 +1154,79 @@ export interface DesktopBridge {
/** Renderer callback invoked by Electron with a fresh user gesture before display-media capture. */
export const DESKTOP_PREVIEW_RECORDING_CAPTURE_TRIGGER = "__t3DesktopPreviewRecordingCapture";
+/**
+ * Dictation for the annotation editor drawn inside a preview guest. The guest only shows
+ * controls and forwards trusted user gestures; the renderer records, with its consent
+ * checks, and publishes state back. `shortcuts` are the dictation chords in effect.
+ */
+export const DesktopPreviewAnnotationVoiceConfigSchema = Schema.Struct({
+ sessionId: Schema.String.check(Schema.isMaxLength(64)),
+ shortcuts: Schema.Array(KeybindingShortcut).check(Schema.isMaxLength(16)),
+});
+export type DesktopPreviewAnnotationVoiceConfig =
+ typeof DesktopPreviewAnnotationVoiceConfigSchema.Type;
+
+export const DesktopPreviewAnnotationVoiceEventSchema = Schema.Struct({
+ sessionId: Schema.String.check(Schema.isMaxLength(64)),
+ text: Schema.String.check(Schema.isMaxLength(100_000)),
+ cursor: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
+ selectionEnd: Schema.optional(Schema.Int.check(Schema.isGreaterThanOrEqualTo(0))),
+ action: Schema.Literals([
+ "sync",
+ "start",
+ "stop",
+ "cancel",
+ "skip",
+ "settings",
+ "key",
+ "focus",
+ "blur",
+ ]),
+ keyboard: Schema.optional(
+ Schema.Struct({
+ type: Schema.Literals(["keydown", "keyup"]),
+ key: Schema.String.check(Schema.isMaxLength(32)),
+ code: Schema.String.check(Schema.isMaxLength(64)),
+ metaKey: Schema.Boolean,
+ ctrlKey: Schema.Boolean,
+ shiftKey: Schema.Boolean,
+ altKey: Schema.Boolean,
+ repeat: Schema.Boolean,
+ }),
+ ),
+});
+export type DesktopPreviewAnnotationVoiceEvent =
+ typeof DesktopPreviewAnnotationVoiceEventSchema.Type;
+
+export const DesktopPreviewAnnotationVoiceStateSchema = Schema.Struct({
+ tabId: DesktopPreviewTabIdSchema,
+ sessionId: Schema.String.check(Schema.isMaxLength(64)),
+ available: Schema.Boolean,
+ phase: Schema.Literals([
+ "idle",
+ "preparing",
+ "recording",
+ "transcribing",
+ "post-processing",
+ "error",
+ ]),
+ status: Schema.NullOr(Schema.String),
+ errorAction: Schema.NullOr(Schema.Literals(["retry", "settings"])),
+ preview: Schema.NullOr(Schema.String),
+ level: Schema.Number,
+ shortcutLabel: Schema.NullOr(Schema.String),
+ freezesEditor: Schema.Boolean,
+ blocksSubmission: Schema.Boolean,
+ draft: Schema.NullOr(Schema.Struct({ text: Schema.String, cursor: Schema.Int })),
+});
+export type DesktopPreviewAnnotationVoiceState =
+ typeof DesktopPreviewAnnotationVoiceStateSchema.Type;
+
+export const DesktopPreviewPickElementInputSchema = Schema.Struct({
+ tabId: DesktopPreviewTabIdSchema,
+ voice: Schema.optional(DesktopPreviewAnnotationVoiceConfigSchema),
+});
+
export interface DesktopPreviewBridge {
setForwardedShortcuts: (shortcuts: ReadonlyArray<PreviewForwardedShortcut>) => Promise<void>;
createTab: (tabId: string, defaults?: DesktopPreviewTabDefaults) => Promise<void>;
@@ -1188,8 +1261,17 @@ export interface DesktopPreviewBridge {
}) => Promise<BrowserImportResult>;
setAnnotationTheme: (theme: DesktopPreviewAnnotationTheme) => Promise<void>;
setAnnotationSendEnabled: (tabId: string, enabled: boolean) => Promise<void>;
+ annotationVoice: {
+ onEvent: (
+ listener: (tabId: string, event: DesktopPreviewAnnotationVoiceEvent) => void,
+ ) => () => void;
+ update: (state: DesktopPreviewAnnotationVoiceState) => Promise<void>;
+ };
/** Resolves with the annotation and attach/send intent, or null on cancellation. Rejects if activation fails. */
- pickElement: (tabId: string) => Promise<PreviewAnnotationSubmissionResult | null>;
+ pickElement: (
+ tabId: string,
+ voice?: DesktopPreviewAnnotationVoiceConfig,
+ ) => Promise<PreviewAnnotationSubmissionResult | null>;
cancelPickElement: (tabId: string) => Promise<void>;
captureScreenshot: (
tabId: string,
diff --git a/packages/shared/package.json b/packages/shared/package.json
index e485402c766..6dfe675900e 100644
--- a/packages/shared/package.json
+++ b/packages/shared/package.json
@@ -243,6 +243,10 @@
"types": "./src/keybindings.ts",
"import": "./src/keybindings.ts"
},
+ "./keybindingMatching": {
+ "types": "./src/keybindingMatching.ts",
+ "import": "./src/keybindingMatching.ts"
+ },
"./threadTranscript": {
"types": "./src/threadTranscript.ts",
"import": "./src/threadTranscript.ts"
diff --git a/packages/shared/src/keybindingMatching.ts b/packages/shared/src/keybindingMatching.ts
new file mode 100644
index 00000000000..0bcb6304f50
--- /dev/null
+++ b/packages/shared/src/keybindingMatching.ts
@@ -0,0 +1,106 @@
+import type { KeybindingShortcut } from "@t3tools/contracts";
+
+// Matching only: the desktop preview guest bundles this file without the rest of the
+// keybindings module, so it stays free of parsing, defaults, and contracts runtime code.
+
+export interface ShortcutEventLike {
+ getModifierState?: (key: "AltGraph") => boolean;
+ type?: string;
+ code?: string;
+ key: string;
+ repeat?: boolean;
+ metaKey: boolean;
+ ctrlKey: boolean;
+ shiftKey: boolean;
+ altKey: boolean;
+}
+
+export interface ShortcutModifierStateLike {
+ metaKey: boolean;
+ ctrlKey: boolean;
+ shiftKey: boolean;
+ altKey: boolean;
+}
+
+export const EVENT_CODE_SHORTCUT_KEYS: Readonly<Record<string, string>> = {
+ Backquote: "`",
+ Backslash: "\\",
+ BracketLeft: "[",
+ BracketRight: "]",
+ Comma: ",",
+ Digit0: "0",
+ Digit1: "1",
+ Digit2: "2",
+ Digit3: "3",
+ Digit4: "4",
+ Digit5: "5",
+ Digit6: "6",
+ Digit7: "7",
+ Digit8: "8",
+ Digit9: "9",
+ Equal: "=",
+ Minus: "-",
+ Period: ".",
+ Quote: "'",
+ Semicolon: ";",
+ Slash: "/",
+};
+
+export function isMacPlatform(platform: string): boolean {
+ return /mac|iphone|ipad|ipod/i.test(platform);
+}
+
+export function normalizeEventKey(key: string): string {
+ const normalized = key.toLowerCase();
+ if (normalized === "esc") return "escape";
+ return normalized;
+}
+
+export function shortcutKeyFromEvent(event: Pick<ShortcutEventLike, "key" | "code">): string {
+ const layoutKey = normalizeEventKey(event.key);
+ if (/^[a-z]$/.test(layoutKey)) return layoutKey;
+ const physicalKey = event.code ? EVENT_CODE_SHORTCUT_KEYS[event.code] : undefined;
+ return physicalKey ?? layoutKey;
+}
+
+export function resolveEventKeys(event: ShortcutEventLike): Set<string> {
+ const layoutKey = normalizeEventKey(event.key);
+ const keys = new Set([layoutKey]);
+ const letterCode = event.code?.match(/^Key([A-Z])$/)?.[1];
+ if (letterCode && !/^[a-z]$/.test(layoutKey)) {
+ keys.add(letterCode.toLowerCase());
+ }
+ keys.add(shortcutKeyFromEvent(event));
+ return keys;
+}
+
+export function matchesKeybindingShortcutModifiers(
+ event: ShortcutModifierStateLike,
+ shortcut: KeybindingShortcut,
+ platform: string,
+): boolean {
+ const useMetaForMod = isMacPlatform(platform);
+ const expectedMeta = shortcut.metaKey || (shortcut.modKey && useMetaForMod);
+ const expectedCtrl = shortcut.ctrlKey || (shortcut.modKey && !useMetaForMod);
+ return (
+ event.metaKey === expectedMeta &&
+ event.ctrlKey === expectedCtrl &&
+ event.shiftKey === shortcut.shiftKey &&
+ event.altKey === shortcut.altKey
+ );
+}
+
+export function matchesKeybindingShortcut(
+ event: ShortcutEventLike,
+ shortcut: KeybindingShortcut,
+ platform: string,
+): boolean {
+ if (
+ !isMacPlatform(platform) &&
+ event.getModifierState?.("AltGraph") &&
+ !/^[a-z0-9]$/i.test(event.key)
+ )
+ return false;
+ if (!matchesKeybindingShortcutModifiers(event, shortcut, platform)) return false;
+ return resolveEventKeys(event).has(shortcut.key);
+}
diff --git a/packages/shared/src/keybindings.ts b/packages/shared/src/keybindings.ts
index 999c00d5317..ba4d1d925be 100644
--- a/packages/shared/src/keybindings.ts
+++ b/packages/shared/src/keybindings.ts
@@ -10,48 +10,17 @@ import {
THREAD_JUMP_KEYBINDING_COMMANDS,
} from "@t3tools/contracts";
-export interface ShortcutEventLike {
- getModifierState?: (key: "AltGraph") => boolean;
- type?: string;
- code?: string;
- key: string;
- repeat?: boolean;
- metaKey: boolean;
- ctrlKey: boolean;
- shiftKey: boolean;
- altKey: boolean;
-}
-
-export interface ShortcutModifierStateLike {
- metaKey: boolean;
- ctrlKey: boolean;
- shiftKey: boolean;
- altKey: boolean;
-}
-
-export const EVENT_CODE_SHORTCUT_KEYS: Readonly<Record<string, string>> = {
- Backquote: "`",
- Backslash: "\\",
- BracketLeft: "[",
- BracketRight: "]",
- Comma: ",",
- Digit0: "0",
- Digit1: "1",
- Digit2: "2",
- Digit3: "3",
- Digit4: "4",
- Digit5: "5",
- Digit6: "6",
- Digit7: "7",
- Digit8: "8",
- Digit9: "9",
- Equal: "=",
- Minus: "-",
- Period: ".",
- Quote: "'",
- Semicolon: ";",
- Slash: "/",
-};
+export {
+ EVENT_CODE_SHORTCUT_KEYS,
+ isMacPlatform,
+ matchesKeybindingShortcut,
+ matchesKeybindingShortcutModifiers,
+ normalizeEventKey,
+ resolveEventKeys,
+ shortcutKeyFromEvent,
+ type ShortcutEventLike,
+ type ShortcutModifierStateLike,
+} from "./keybindingMatching.ts";
export const US_SHIFTED_TO_UNSHIFTED_KEYS: ReadonlyMap<string, string> = new Map([
["!", "1"],
@@ -77,65 +46,6 @@ export const US_SHIFTED_TO_UNSHIFTED_KEYS: ReadonlyMap<string, string> = new Map
["?", "/"],
]);
-export function isMacPlatform(platform: string): boolean {
- return /mac|iphone|ipad|ipod/i.test(platform);
-}
-
-export function normalizeEventKey(key: string): string {
- const normalized = key.toLowerCase();
- if (normalized === "esc") return "escape";
- return normalized;
-}
-
-export function shortcutKeyFromEvent(event: Pick<ShortcutEventLike, "key" | "code">): string {
- const layoutKey = normalizeEventKey(event.key);
- if (/^[a-z]$/.test(layoutKey)) return layoutKey;
- const physicalKey = event.code ? EVENT_CODE_SHORTCUT_KEYS[event.code] : undefined;
- return physicalKey ?? layoutKey;
-}
-
-export function resolveEventKeys(event: ShortcutEventLike): Set<string> {
- const layoutKey = normalizeEventKey(event.key);
- const keys = new Set([layoutKey]);
- const letterCode = event.code?.match(/^Key([A-Z])$/)?.[1];
- if (letterCode && !/^[a-z]$/.test(layoutKey)) {
- keys.add(letterCode.toLowerCase());
- }
- keys.add(shortcutKeyFromEvent(event));
- return keys;
-}
-
-export function matchesKeybindingShortcutModifiers(
- event: ShortcutModifierStateLike,
- shortcut: KeybindingShortcut,
- platform: string,
-): boolean {
- const useMetaForMod = isMacPlatform(platform);
- const expectedMeta = shortcut.metaKey || (shortcut.modKey && useMetaForMod);
- const expectedCtrl = shortcut.ctrlKey || (shortcut.modKey && !useMetaForMod);
- return (
- event.metaKey === expectedMeta &&
- event.ctrlKey === expectedCtrl &&
- event.shiftKey === shortcut.shiftKey &&
- event.altKey === shortcut.altKey
- );
-}
-
-export function matchesKeybindingShortcut(
- event: ShortcutEventLike,
- shortcut: KeybindingShortcut,
- platform: string,
-): boolean {
- if (
- !isMacPlatform(platform) &&
- event.getModifierState?.("AltGraph") &&
- !/^[a-z0-9]$/i.test(event.key)
- )
- return false;
- if (!matchesKeybindingShortcutModifiers(event, shortcut, platform)) return false;
- return resolveEventKeys(event).has(shortcut.key);
-}
-
type WhenToken =
| { type: "identifier"; value: string }
| { type: "not" }