@devries-cameron20 / t3code Mirror · read-only / commits / aabd5629c9
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 03:15 UTC

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

Julius Marminge committed Nov 5, 2026 at 15:59 UTC aabd5629c9408c4da3903c5efb2705999a942907
20 files changed +933 -138
apps/desktop/src/ipc/channels.ts
+3
@@ -121,6 +121,9 @@ export const CHECK_SYSTEM_PERMISSION_CHANNEL = "desktop:check-system-permission"
121
122 export const PREVIEW_RECORDING_INPUT_CHANNEL = "desktop:preview-recording-input";
123
124 +export const PREVIEW_ANNOTATION_VOICE_EVENT_CHANNEL = "desktop:preview-annotation-voice-event";
125 +export const PREVIEW_ANNOTATION_VOICE_STATE_CHANNEL = "desktop:preview-annotation-voice-state";
126 +
127 export const RECEIVE_PROVIDER_AUTH_CALLBACK_CHANNEL = "desktop:receive-provider-auth-callback";
128 export const CANCEL_PROVIDER_AUTH_CALLBACK_CHANNEL = "desktop:cancel-provider-auth-callback";
129 export const TAKE_LEGACY_LOCAL_STORAGE_CHANNEL = "desktop:take-legacy-local-storage";
apps/desktop/src/ipc/methods/preview.ts
+16 -3
@@ -1,6 +1,8 @@
1 import {
2 DesktopPreviewAnnotationSendEnabledInputSchema,
3 DesktopPreviewAnnotationThemeInputSchema,
4 + DesktopPreviewAnnotationVoiceStateSchema,
5 + DesktopPreviewPickElementInputSchema,
6 DesktopPreviewArtifactInputSchema,
7 DesktopPreviewConfigInputSchema,
8 DesktopPreviewNavigateInputSchema,
@@ -363,11 +365,21 @@ const setAnnotationTheme = DesktopIpc.makeIpcMethod({
365
366 const pickElement = DesktopIpc.makeIpcMethod({
367 channel: IpcChannels.PREVIEW_PICK_ELEMENT_CHANNEL,
366 - payload: DesktopPreviewTabInputSchema,
368 + payload: DesktopPreviewPickElementInputSchema,
369 result: Schema.NullOr(PreviewAnnotationSubmissionResultSchema),
368 - handler: Effect.fn("desktop.ipc.preview.pickElement")(function* ({ tabId }) {
370 + handler: Effect.fn("desktop.ipc.preview.pickElement")(function* ({ tabId, voice }) {
371 + const manager = yield* PreviewManager.PreviewManager;
372 + return yield* manager.pickElement(tabId, voice);
373 + }),
374 +});
375 +
376 +const updateAnnotationVoice = DesktopIpc.makeIpcMethod({
377 + channel: IpcChannels.PREVIEW_ANNOTATION_VOICE_STATE_CHANNEL,
378 + payload: DesktopPreviewAnnotationVoiceStateSchema,
379 + result: Schema.Void,
380 + handler: Effect.fn("desktop.ipc.preview.updateAnnotationVoice")(function* (state) {
381 const manager = yield* PreviewManager.PreviewManager;
370 - return yield* manager.pickElement(tabId);
382 + yield* manager.updateAnnotationVoice(state);
383 }),
384 });
385
@@ -428,6 +440,7 @@ const saveRecording = DesktopIpc.makeIpcMethod({
440
441 export const methods = [
442 setForwardedShortcuts,
443 + updateAnnotationVoice,
444 createTab,
445 closeTab,
446 registerWebview,
apps/desktop/src/preload.ts
+15 -1
@@ -1,5 +1,6 @@
1 import type {
2 DesktopBridge,
3 + DesktopPreviewAnnotationVoiceEvent,
4 DesktopPreviewOpenLinkEvent,
5 DesktopPreviewPointerEvent,
6 DesktopPreviewRecordingInputEvent,
@@ -368,7 +369,20 @@ contextBridge.exposeInMainWorld("desktopBridge", {
369 tabId,
370 enabled,
371 }),
371 - pickElement: (tabId) => ipcRenderer.invoke(IpcChannels.PREVIEW_PICK_ELEMENT_CHANNEL, { tabId }),
372 + annotationVoice: {
373 + onEvent: (listener) => {
374 + const onEvent = (_event: Electron.IpcRendererEvent, tabId: string, value: unknown) => {
375 + if (typeof tabId !== "string" || typeof value !== "object" || value === null) return;
376 + listener(tabId, value as DesktopPreviewAnnotationVoiceEvent);
377 + };
378 + ipcRenderer.on(IpcChannels.PREVIEW_ANNOTATION_VOICE_EVENT_CHANNEL, onEvent);
379 + return () => ipcRenderer.off(IpcChannels.PREVIEW_ANNOTATION_VOICE_EVENT_CHANNEL, onEvent);
380 + },
381 + update: (state) =>
382 + ipcRenderer.invoke(IpcChannels.PREVIEW_ANNOTATION_VOICE_STATE_CHANNEL, state),
383 + },
384 + pickElement: (tabId, voice) =>
385 + ipcRenderer.invoke(IpcChannels.PREVIEW_PICK_ELEMENT_CHANNEL, { tabId, voice }),
386 cancelPickElement: (tabId) =>
387 ipcRenderer.invoke(IpcChannels.PREVIEW_CANCEL_PICK_ELEMENT_CHANNEL, { tabId }),
388 captureScreenshot: (tabId) =>
apps/desktop/src/preview/Annotation.css
+6
@@ -36,6 +36,7 @@
36 --t3-popover-foreground: oklch(0.269 0 0);
37 --t3-primary: oklch(0.488 0.217 264);
38 --t3-primary-foreground: white;
39 + --t3-destructive: oklch(0.577 0.245 27.325);
40 --t3-muted: rgb(0 0 0 / 4%);
41 --t3-muted-foreground: oklch(0.556 0 0);
42 --t3-accent: rgb(0 0 0 / 4%);
@@ -66,3 +67,8 @@ textarea:focus-visible {
67 outline: 2px solid color-mix(in srgb, var(--t3-ring) 72%, transparent);
68 outline-offset: -2px;
69 }
70 +
71 +/* Utility display classes must not override the native hidden state. */
72 +[hidden] {
73 + display: none !important;
74 +}
apps/desktop/src/preview/AnnotationStyles.generated.ts
+1 -1
@@ -1,3 +1,3 @@
1 // Generated by scripts/build-preview-annotation-css.mjs. Do not edit.
2 export const previewAnnotationStyles =
3 - '/*! 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';
3 + '/*! 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';
apps/desktop/src/preview/GuestProtocol.ts
+2
@@ -14,3 +14,5 @@ export const RECORDING_CONTROLLER_CHANNEL = "preview:recording-controller";
14 export const PASSKEY_CREATE_CHANNEL = "preview:passkey-create";
15 export const PASSKEY_GET_CHANNEL = "preview:passkey-get";
16 export const PASSKEY_BRIDGE_ARGUMENT = "--t3code-preview-passkey-bridge";
17 +export const ANNOTATION_VOICE_EVENT_CHANNEL = "preview:annotation-voice-event";
18 +export const ANNOTATION_VOICE_STATE_CHANNEL = "preview:annotation-voice-state";
apps/desktop/src/preview/Manager.test.ts
+64
@@ -2443,6 +2443,70 @@ describe("PreviewManager", () => {
2443 ),
2444 );
2445
2446 + effectIt.effect("delivers annotation voice state only to the pick session that owns it", () =>
2447 + withManager((manager) =>
2448 + Effect.gen(function* () {
2449 + const firstReady = yield* Deferred.make<void>();
2450 + const secondReady = yield* Deferred.make<void>();
2451 + let registrations = 0;
2452 + const guest = {
2453 + ...makeTestPreviewWebContents(async () => ({
2454 + toPNG: () => Buffer.from("unused"),
2455 + toJPEG: () => Buffer.from("unused"),
2456 + getSize: () => ({ width: 1, height: 1 }),
2457 + })),
2458 + isFocused: () => true,
2459 + focus: vi.fn(),
2460 + send: (channel: string, ...args: unknown[]) => {
2461 + webviewSend(channel, ...args);
2462 + if (channel === "preview:start-pick")
2463 + Deferred.doneUnsafe(registrations++ === 0 ? firstReady : secondReady, Effect.void);
2464 + },
2465 + once: vi.fn(),
2466 + ipc: { on: vi.fn(), off: vi.fn(), removeListener: vi.fn() },
2467 + };
2468 + fromId.mockReturnValue(guest as never);
2469 + yield* manager.createTab("tab_1");
2470 + yield* manager.registerWebview("tab_1", 42);
2471 + const first = yield* manager
2472 + .pickElement("tab_1", { sessionId: "first", shortcuts: [] })
2473 + .pipe(Effect.forkChild);
2474 + yield* Deferred.await(firstReady);
2475 + const state = {
2476 + tabId: "tab_1",
2477 + sessionId: "first",
2478 + available: true,
2479 + phase: "recording" as const,
2480 + status: "Recording",
2481 + errorAction: null,
2482 + preview: null,
2483 + freezesEditor: true,
2484 + blocksSubmission: true,
2485 + level: 0,
2486 + shortcutLabel: "Ctrl+D",
2487 + draft: { text: "Tighten spacing", cursor: 15 },
2488 + };
2489 + yield* manager.updateAnnotationVoice(state);
2490 + expect(webviewSend).toHaveBeenCalledWith("preview:annotation-voice-state", state);
2491 + const second = yield* manager
2492 + .pickElement("tab_1", { sessionId: "second", shortcuts: [] })
2493 + .pipe(Effect.forkChild);
2494 + yield* Deferred.await(secondReady);
2495 + expect(yield* Fiber.join(first)).toBeNull();
2496 + webviewSend.mockClear();
2497 + yield* manager.updateAnnotationVoice(state);
2498 + expect(webviewSend).not.toHaveBeenCalled();
2499 + yield* manager.updateAnnotationVoice({ ...state, sessionId: "second" });
2500 + expect(webviewSend).toHaveBeenCalledOnce();
2501 + yield* manager.cancelPickElement("tab_1");
2502 + expect(yield* Fiber.join(second)).toBeNull();
2503 + webviewSend.mockClear();
2504 + yield* manager.updateAnnotationVoice({ ...state, sessionId: "second" });
2505 + expect(webviewSend).not.toHaveBeenCalled();
2506 + }),
2507 + ),
2508 + );
2509 +
2510 effectIt.effect("keeps annotation send grants isolated and updates an active pick", () =>
2511 withManager((manager) =>
2512 Effect.gen(function* () {
apps/desktop/src/preview/Manager.ts
+68 -4
@@ -1,10 +1,13 @@
1 import * as NodeZlib from "node:zlib";
2 import {
3 + DesktopPreviewAnnotationVoiceEventSchema,
4 DesktopPreviewRecordingInputSchema,
5 DESKTOP_PREVIEW_RECORDING_CAPTURE_TRIGGER,
6 } from "@t3tools/contracts";
7 import type {
8 DesktopPreviewAnnotationTheme,
9 + DesktopPreviewAnnotationVoiceConfig,
10 + DesktopPreviewAnnotationVoiceState,
11 DesktopPreviewColorScheme,
12 DesktopPreviewFavicon,
13 DesktopPreviewOpenLinkEvent,
@@ -56,13 +59,19 @@ import * as SynchronizedRef from "effect/SynchronizedRef";
59
60 import * as DesktopEnvironment from "../app/DesktopEnvironment.ts";
61 import * as DesktopRendererHistory from "../telemetry/DesktopRendererHistory.ts";
59 -import { MENU_ACTION_CHANNEL, PREVIEW_PICTURE_IN_PICTURE_FRAME_CHANNEL } from "../ipc/channels.ts";
62 +import {
63 + MENU_ACTION_CHANNEL,
64 + PREVIEW_ANNOTATION_VOICE_EVENT_CHANNEL,
65 + PREVIEW_PICTURE_IN_PICTURE_FRAME_CHANNEL,
66 +} from "../ipc/channels.ts";
67 import * as DesktopBrowserHost from "./DesktopBrowserHost.ts";
68 import * as PreviewPasskeys from "./Passkeys.ts";
69 import * as BrowserSession from "./BrowserSession.ts";
70 import {
71 ANNOTATION_CAPTURED_CHANNEL,
72 ANNOTATION_SEND_ENABLED_CHANNEL,
73 + ANNOTATION_VOICE_EVENT_CHANNEL,
74 + ANNOTATION_VOICE_STATE_CHANNEL,
75 ANNOTATION_THEME_CHANNEL,
76 CANCEL_PICK_CHANNEL,
77 ELEMENT_PICKED_CHANNEL,
@@ -396,9 +405,14 @@ interface PendingRecording {
405 }
406
407 interface PickSession {
408 + readonly voiceSessionId?: string | undefined;
409 readonly cancel: Effect.Effect<void>;
410 }
411
412 +const decodeAnnotationVoiceEvent = Schema.decodeUnknownOption(
413 + DesktopPreviewAnnotationVoiceEventSchema,
414 +);
415 +
416 interface BrowserControlSession {
417 readonly webContentsId: number;
418 // 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
2088 });
2089 });
2090
2077 - const pickElement = Effect.fn("PreviewManager.pickElement")(function* (tabId: string) {
2091 + // Voice state reaches a guest only while its pick session, by id, still owns the tab.
2092 + const updateAnnotationVoice = Effect.fn("PreviewManager.updateAnnotationVoice")(function* (
2093 + state: DesktopPreviewAnnotationVoiceState,
2094 + ) {
2095 + const sessions = yield* Ref.get(pickSessionsRef);
2096 + if (sessions.get(state.tabId)?.voiceSessionId !== state.sessionId) return;
2097 + const wc = yield* requireWebContents(state.tabId);
2098 + yield* attempt({ operation: "annotationVoice.update", tabId: state.tabId }, () =>
2099 + wc.send(ANNOTATION_VOICE_STATE_CHANNEL, state),
2100 + );
2101 + });
2102 +
2103 + const pickElement = Effect.fn("PreviewManager.pickElement")(function* (
2104 + tabId: string,
2105 + voice?: DesktopPreviewAnnotationVoiceConfig,
2106 + ) {
2107 const wc = yield* requireWebContents(tabId);
2108 yield* cancelPickElement(tabId);
2109 const annotationTheme = yield* Ref.get(annotationThemeRef);
2110 return yield* Effect.callback<PreviewAnnotationSubmissionResult | null, PreviewManagerError>(
2111 (resume) => {
2083 - const session: PickSession = { cancel: Effect.suspend(() => cancelPickSession()) };
2112 + const session: PickSession = {
2113 + voiceSessionId: voice?.sessionId,
2114 + cancel: Effect.suspend(() => cancelPickSession()),
2115 + };
2116 const cleanup = Effect.fn("PreviewManager.cleanupPickElement")(function* () {
2117 yield* attempt({ operation: "pickElement.cleanup", tabId, webContentsId: wc.id }, () => {
2118 wc.ipc.removeListener(ELEMENT_PICKED_CHANNEL, onMessage);
2119 + wc.ipc.removeListener(ANNOTATION_VOICE_EVENT_CHANNEL, onVoiceEvent);
2120 wc.off("destroyed", onDestroyed);
2121 wc.off("did-start-navigation", onNavigated);
2122 }).pipe(Effect.ignore);
@@ -2191,6 +2224,25 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
2224 ),
2225 );
2226 };
2227 + // Only this guest's listener sees these; the renderer still checks the session id.
2228 + const onVoiceEvent = (_event: Electron.IpcMainEvent, value: unknown) => {
2229 + const decoded = decodeAnnotationVoiceEvent(value);
2230 + if (settled || !voice || Option.isNone(decoded)) return;
2231 + if (decoded.value.sessionId !== voice.sessionId) return;
2232 + runFork(
2233 + Effect.gen(function* () {
2234 + const window = yield* Ref.get(mainWindowRef);
2235 + if (Option.isNone(window) || window.value.isDestroyed()) return;
2236 + yield* attempt({ operation: "annotationVoice.forward", tabId }, () =>
2237 + window.value.webContents.send(
2238 + PREVIEW_ANNOTATION_VOICE_EVENT_CHANNEL,
2239 + tabId,
2240 + decoded.value,
2241 + ),
2242 + ).pipe(Effect.ignore);
2243 + }),
2244 + );
2245 + };
2246 const onDestroyed = () => settle(null);
2247 const onNavigated = (
2248 event: Electron.Event<Electron.WebContentsDidStartNavigationEventParams>,
@@ -2210,10 +2262,16 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
2262 if (settled) return;
2263 yield* attempt({ operation: "pickElement.register", tabId, webContentsId: wc.id }, () => {
2264 wc.ipc.on(ELEMENT_PICKED_CHANNEL, onMessage);
2265 + if (voice) wc.ipc.on(ANNOTATION_VOICE_EVENT_CHANNEL, onVoiceEvent);
2266 wc.once("destroyed", onDestroyed);
2267 wc.on("did-start-navigation", onNavigated);
2268 if (!wc.isFocused()) wc.focus();
2216 - wc.send(START_PICK_CHANNEL, annotationTheme, annotationSendEnabled.get(tabId) === true);
2269 + wc.send(
2270 + START_PICK_CHANNEL,
2271 + annotationTheme,
2272 + annotationSendEnabled.get(tabId) === true,
2273 + voice,
2274 + );
2275 });
2276 });
2277 runFork(
@@ -3312,6 +3370,7 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
3370 openPictureInPicture,
3371 openDevTools,
3372 pickElement,
3373 + updateAnnotationVoice,
3374 prepareWebview,
3375 reapplyZoom,
3376 refresh,
@@ -3552,7 +3611,11 @@ export class PreviewManager extends Context.Service<
3611 ) => Effect.Effect<void, PreviewManagerError>;
3612 readonly pickElement: (
3613 tabId: string,
3614 + voice?: DesktopPreviewAnnotationVoiceConfig,
3615 ) => Effect.Effect<PreviewAnnotationSubmissionResult | null, PreviewManagerError>;
3616 + readonly updateAnnotationVoice: (
3617 + state: DesktopPreviewAnnotationVoiceState,
3618 + ) => Effect.Effect<void, PreviewManagerError>;
3619 readonly cancelPickElement: (tabId: string) => Effect.Effect<void, PreviewManagerError>;
3620 readonly captureScreenshot: (
3621 tabId: string,
@@ -3703,6 +3766,7 @@ export const make = Effect.gen(function* PreviewManagerMake() {
3766 setAnnotationTheme: operations.setAnnotationTheme,
3767 setAnnotationSendEnabled: operations.setAnnotationSendEnabled,
3768 pickElement: operations.pickElement,
3769 + updateAnnotationVoice: operations.updateAnnotationVoice,
3770 cancelPickElement: operations.cancelPickElement,
3771 captureScreenshot: operations.captureScreenshot,
3772 revealArtifact: operations.revealArtifact,
apps/desktop/src/preview/PickPreload.ts
+287 -13
@@ -1,8 +1,12 @@
1 // @effect-diagnostics globalDate:off globalTimers:off - This isolated Electron preload does not run inside an Effect runtime.
2 import { ipcRenderer } from "electron";
3 import { getElementContext } from "react-grab/primitives";
4 +import { matchesKeybindingShortcut } from "@t3tools/shared/keybindingMatching";
5 import type {
6 DesktopPreviewAnnotationTheme,
7 + DesktopPreviewAnnotationVoiceConfig,
8 + DesktopPreviewAnnotationVoiceEvent,
9 + DesktopPreviewAnnotationVoiceState,
10 PickedElementPayload,
11 PickedElementStackFrame,
12 PreviewAnnotationPayload,
@@ -23,6 +27,8 @@ import {
27 ANNOTATION_CAPTURED_CHANNEL,
28 ANNOTATION_SEND_ENABLED_CHANNEL,
29 ANNOTATION_THEME_CHANNEL,
30 + ANNOTATION_VOICE_EVENT_CHANNEL,
31 + ANNOTATION_VOICE_STATE_CHANNEL,
32 CANCEL_PICK_CHANNEL,
33 ELEMENT_PICKED_CHANNEL,
34 HUMAN_INPUT_CHANNEL,
@@ -524,7 +530,10 @@ function strokeBounds(
530 return { x: left, y: top, width: right - left, height: bottom - top };
531 }
532
527 -function startAnnotation(sendEnabled: boolean): void {
533 +function startAnnotation(
534 + sendEnabled: boolean,
535 + voice: DesktopPreviewAnnotationVoiceConfig | undefined,
536 +): void {
537 activeSession?.teardown(false);
538 let finished = false;
539 const host = document.createElement("div");
@@ -595,6 +604,212 @@ function startAnnotation(sendEnabled: boolean): void {
604 "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";
605 composerRow.appendChild(comment);
606
607 + // Recording happens in the application renderer, which owns the microphone consent.
608 + // This guest only draws the controls, forwards trusted gestures, and mirrors state.
609 + let voicePhase: DesktopPreviewAnnotationVoiceState["phase"] = "idle";
610 + let voiceSettings = false;
611 + let voiceBusy = false;
612 + let voiceAvailable = false;
613 + let voiceKeyCode: string | null = null;
614 + let pendingVoiceSubmission: PreviewAnnotationSubmission | null = null;
615 + let voiceSubmissionReady = false;
616 + const voiceButton = createButton("", "Start voice input");
617 + voiceButton.innerHTML =
618 + '<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>';
619 + voiceButton.className += " h-8 w-8 shrink-0 p-0 text-muted-foreground";
620 + voiceButton.hidden = true;
621 + voiceButton.setAttribute("aria-label", "Start voice input");
622 + composerRow.appendChild(voiceButton);
623 + const voiceRow = document.createElement("div");
624 + voiceRow.className = "flex min-w-0 items-center justify-end gap-1 px-2 pb-2";
625 + voiceRow.hidden = true;
626 + const voicePill = document.createElement("div");
627 + const voiceCancel = createButton("", "Cancel voice input");
628 + voiceCancel.innerHTML =
629 + '<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>';
630 + voiceCancel.className += " h-7 w-7 shrink-0 rounded-full p-0";
631 + const voiceFinish = createButton("", "Finish voice input");
632 + voiceFinish.className +=
633 + " h-7 w-7 shrink-0 rounded-full border-primary bg-primary p-0 text-primary-foreground hover:bg-primary/90";
634 + const voiceSkip = createButton("Skip", "Skip transcript cleanup");
635 + voiceSkip.className += " h-7 shrink-0 rounded-full px-2.5";
636 + const voiceStatus = document.createElement("div");
637 + voiceStatus.className = "flex h-7 min-w-0 flex-1 items-center gap-2";
638 + voiceStatus.setAttribute("role", "status");
639 + const voiceStatusText = document.createElement("span");
640 + voiceStatusText.className = "min-w-0 flex-1 truncate text-right text-sm text-muted-foreground";
641 + const waveform = document.createElement("div");
642 + waveform.className =
643 + "flex h-5 min-w-0 flex-1 items-center justify-between gap-px overflow-hidden";
644 + waveform.setAttribute("aria-hidden", "true");
645 + const waveformLevels = Array<number>(24).fill(0);
646 + const waveformBars = waveformLevels.map(() => {
647 + const bar = document.createElement("span");
648 + bar.className = "h-full w-0.5 shrink-0 origin-center rounded-full bg-primary";
649 + bar.style.transform = "scaleY(0.08)";
650 + bar.style.opacity = "0.25";
651 + waveform.appendChild(bar);
652 + return bar;
653 + });
654 + const voiceElapsed = document.createElement("span");
655 + voiceElapsed.className = "shrink-0 text-xs tabular-nums text-muted-foreground";
656 + let recordingStartedAt = 0;
657 + let elapsedTimer: ReturnType<typeof setInterval> | null = null;
658 + const updateElapsed = () => {
659 + const seconds = Math.floor((Date.now() - recordingStartedAt) / 1_000);
660 + voiceElapsed.textContent = `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, "0")}`;
661 + };
662 + voiceStatus.append(voiceStatusText, waveform, voiceElapsed);
663 + voicePill.append(voiceCancel, voiceStatus, voiceSkip, voiceFinish);
664 + voiceRow.appendChild(voicePill);
665 + const voicePreview = document.createElement("p");
666 + voicePreview.className = "px-2 pb-2 text-sm text-muted-foreground";
667 + voicePreview.setAttribute("role", "status");
668 + voicePreview.hidden = true;
669 + const sendVoice = (
670 + action: DesktopPreviewAnnotationVoiceEvent["action"],
671 + keyboard?: KeyboardEvent,
672 + ) => {
673 + if (!voice || finished) return;
674 + const event: DesktopPreviewAnnotationVoiceEvent = {
675 + sessionId: voice.sessionId,
676 + text: comment.value,
677 + cursor: comment.selectionStart,
678 + selectionEnd: comment.selectionEnd,
679 + action,
680 + ...(keyboard
681 + ? {
682 + keyboard: {
683 + type: keyboard.type === "keyup" ? ("keyup" as const) : ("keydown" as const),
684 + key: keyboard.key,
685 + code: keyboard.code,
686 + metaKey: keyboard.metaKey,
687 + ctrlKey: keyboard.ctrlKey,
688 + shiftKey: keyboard.shiftKey,
689 + altKey: keyboard.altKey,
690 + repeat: keyboard.repeat,
691 + },
692 + }
693 + : {}),
694 + };
695 + ipcRenderer.send(ANNOTATION_VOICE_EVENT_CHANNEL, event);
696 + };
697 + const isDictationChord = (event: KeyboardEvent) =>
698 + voice !== undefined &&
699 + voice.shortcuts.some((shortcut) =>
700 + matchesKeybindingShortcut(event, shortcut, navigator.platform),
701 + );
702 + for (const button of [voiceButton, voiceFinish, voiceCancel, voiceSkip]) {
703 + button.addEventListener("pointerdown", (event) => event.preventDefault());
704 + }
705 + // Page scripts cannot reach the closed shadow root, and a synthetic click never counts.
706 + voiceButton.addEventListener("click", (event) => {
707 + if (!event.isTrusted) return;
708 + if (voiceSettings) {
709 + sendVoice("settings");
710 + return;
711 + }
712 + if (!voiceAvailable || (voiceBusy && voicePhase !== "recording")) return;
713 + sendVoice(voicePhase === "recording" ? "stop" : "start");
714 + });
715 + voiceFinish.addEventListener("click", (event) => {
716 + if (event.isTrusted) sendVoice("stop");
717 + });
718 + voiceCancel.addEventListener("click", (event) => {
719 + if (!event.isTrusted) return;
720 + pendingVoiceSubmission = null;
721 + sendVoice("cancel");
722 + });
723 + voiceSkip.addEventListener("click", (event) => {
724 + if (event.isTrusted) sendVoice("skip");
725 + });
726 + const onVoiceState = (
727 + _event: Electron.IpcRendererEvent,
728 + state: DesktopPreviewAnnotationVoiceState,
729 + ) => {
730 + if (finished || state.sessionId !== voice?.sessionId) return;
731 + const phaseChanged = voicePhase !== state.phase;
732 + const submissionChanged = voiceBusy !== state.blocksSubmission;
733 + const previewChanged = voicePreview.textContent !== (state.preview ?? "");
734 + voicePhase = state.phase;
735 + voiceSettings = state.errorAction === "settings";
736 + voiceBusy = state.blocksSubmission;
737 + voiceAvailable = state.available;
738 + comment.readOnly = state.freezesEditor;
739 + if (state.draft) {
740 + voiceSubmissionReady = pendingVoiceSubmission !== null;
741 + comment.value = state.draft.text;
742 + comment.setSelectionRange(state.draft.cursor, state.draft.cursor);
743 + resizeComment();
744 + }
745 + const recording = state.phase === "recording";
746 + const active = state.phase !== "idle" && state.phase !== "error";
747 + voiceButton.hidden = !state.available || active;
748 + voiceButton.disabled = voiceBusy;
749 + const label = voiceSettings ? "Open voice settings" : "Start voice input";
750 + voiceButton.title =
751 + !voiceSettings && state.shortcutLabel ? `${label} (${state.shortcutLabel})` : label;
752 + voiceButton.setAttribute("aria-label", label);
753 + voiceRow.hidden = state.phase === "idle";
754 + voicePill.className = active
755 + ? "flex h-9 w-64 min-w-0 items-center gap-2 rounded-full border border-border bg-background p-1"
756 + : "flex min-w-0 items-center gap-1";
757 + voiceCancel.title =
758 + state.phase === "error" ? "Dismiss voice input error" : "Cancel voice input";
759 + voiceCancel.setAttribute("aria-label", voiceCancel.title);
760 + voiceStatus.setAttribute("aria-label", state.status ?? "Voice input");
761 + voiceStatus.setAttribute("aria-live", recording ? "off" : "polite");
762 + voiceStatusText.textContent = state.status;
763 + voiceStatusText.style.color = state.phase === "error" ? "var(--t3-destructive)" : "";
764 + voiceStatusText.hidden = recording;
765 + waveform.hidden = !recording;
766 + voiceElapsed.hidden = !recording;
767 + if (recording && elapsedTimer === null) {
768 + recordingStartedAt = Date.now();
769 + waveformLevels.fill(0);
770 + updateElapsed();
771 + elapsedTimer = setInterval(updateElapsed, 250);
772 + } else if (!recording && elapsedTimer !== null) {
773 + clearInterval(elapsedTimer);
774 + elapsedTimer = null;
775 + }
776 + if (recording) {
777 + waveformLevels.copyWithin(0, 1);
778 + waveformLevels[waveformLevels.length - 1] = state.level;
779 + const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
780 + waveformBars.forEach((bar, index) => {
781 + const level = waveformLevels[index] ?? 0;
782 + bar.style.opacity = String(0.25 + level * 0.75);
783 + bar.style.transform = `scaleY(${reducedMotion ? 0.35 : Math.max(0.08, level)})`;
784 + });
785 + }
786 + voiceSkip.hidden = state.phase !== "post-processing";
787 + voiceFinish.hidden = !active || state.phase === "post-processing";
788 + voiceFinish.disabled = !recording;
789 + voiceFinish.title = recording ? "Finish voice input" : (state.status ?? "Voice input is busy");
790 + if (recording && state.shortcutLabel) voiceFinish.title += ` (${state.shortcutLabel})`;
791 + voiceFinish.setAttribute("aria-label", voiceFinish.title);
792 + if (phaseChanged)
793 + voiceFinish.innerHTML = recording
794 + ? '<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>'
795 + : '<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>';
796 + if (!active) voicePill.append(voiceStatus, voiceCancel);
797 + else if (phaseChanged) voicePill.append(voiceCancel, voiceStatus, voiceSkip, voiceFinish);
798 + voicePreview.textContent = state.preview;
799 + voicePreview.hidden = !state.preview;
800 + if (phaseChanged || submissionChanged || previewChanged || state.draft) updateStatus();
801 + if (pendingVoiceSubmission !== null) {
802 + if (state.phase === "recording") sendVoice("stop");
803 + if (state.phase === "error") pendingVoiceSubmission = null;
804 + if (state.phase === "idle") {
805 + const submission = pendingVoiceSubmission;
806 + pendingVoiceSubmission = null;
807 + if (voiceSubmissionReady && submission !== null) submitAnnotation(submission);
808 + voiceSubmissionReady = false;
809 + }
810 + }
811 + };
812 +
813 const dragHandle = document.createElement("button");
814 dragHandle.type = "button";
815 dragHandle.textContent = "⠿";
@@ -613,7 +828,7 @@ function startAnnotation(sendEnabled: boolean): void {
828 submit.className +=
829 " h-8 shrink-0 border-primary bg-primary px-3 text-primary-foreground shadow-sm hover:bg-primary/90";
830 composerRow.appendChild(submit);
616 - editor.appendChild(composerRow);
831 + editor.append(composerRow, voicePreview, voiceRow);
832
833 const stylePanel = document.createElement("div");
834 stylePanel.className =
@@ -654,12 +869,19 @@ function startAnnotation(sendEnabled: boolean): void {
869 comment.style.overflowY = comment.scrollHeight > maxHeight ? "auto" : "hidden";
870 queueEditorLayout();
871 };
657 - comment.addEventListener("input", resizeComment);
872 + comment.addEventListener("input", () => {
873 + resizeComment();
874 + sendVoice("sync");
875 + });
876
877 const updateStatus = (): void => {
878 const hasTargets = selected.size > 0 || regions.length > 0 || strokes.length > 0;
879 + if (!hasTargets && voiceBusy) {
880 + pendingVoiceSubmission = null;
881 + sendVoice("cancel");
882 + }
883 editor.style.display = hasTargets ? "flex" : "none";
662 - submit.disabled = !hasTargets;
884 + submit.disabled = !hasTargets || voicePhase === "preparing" || pendingCapture;
885 submit.style.opacity = hasTargets ? "1" : "0.45";
886 adjust.disabled = !hasTargets;
887 stylePanel.style.display = editorExpanded && selected.size > 0 ? "grid" : "none";
@@ -695,7 +917,6 @@ function startAnnotation(sendEnabled: boolean): void {
917 for (const [key, change] of styleChanges) {
918 if (change.targetId === target.id) styleChanges.delete(key);
919 }
698 - updateStatus();
920 };
921
922 const addSelected = (element: Element): void => {
@@ -710,7 +931,6 @@ function startAnnotation(sendEnabled: boolean): void {
931 selected.set(element, target);
932 root.append(target.outline, target.label);
933 updateSelectedVisual(target);
713 - updateStatus();
934 if (editorExpanded) {
935 stylePanel.style.display = "grid";
936 syncStyleControls();
@@ -721,12 +941,13 @@ function startAnnotation(sendEnabled: boolean): void {
941 const existing = selected.get(element);
942 if (existing) {
943 removeSelected(existing);
724 - return;
725 - }
726 - if (!additive) {
727 - for (const target of Array.from(selected.values())) removeSelected(target);
944 + } else {
945 + if (!additive) {
946 + for (const target of Array.from(selected.values())) removeSelected(target);
947 + }
948 + addSelected(element);
949 }
729 - addSelected(element);
950 + updateStatus();
951 };
952
953 const setStyleForSelected = (property: string, value: string): void => {
@@ -1140,6 +1361,7 @@ function startAnnotation(sendEnabled: boolean): void {
1361 const rect = target.element.getBoundingClientRect();
1362 if (x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom) {
1363 removeSelected(target);
1364 + updateStatus();
1365 return true;
1366 }
1367 }
@@ -1318,7 +1540,11 @@ function startAnnotation(sendEnabled: boolean): void {
1540 if (event.relatedTarget === null) clearHoverOutline();
1541 };
1542
1543 + const onWindowFocus = (): void => {
1544 + if (editor.style.display !== "none") sendVoice("focus");
1545 + };
1546 const onWindowBlur = (): void => {
1547 + sendVoice("blur");
1548 clearHoverOutline();
1549 };
1550
@@ -1344,7 +1570,9 @@ function startAnnotation(sendEnabled: boolean): void {
1570 window.removeEventListener("pointerout", onPointerOut, true);
1571 window.removeEventListener("click", onClick, true);
1572 window.removeEventListener("blur", onWindowBlur);
1573 + window.removeEventListener("focus", onWindowFocus);
1574 window.removeEventListener("keydown", onKeyDown, true);
1575 + window.removeEventListener("keyup", onVoiceKeyUp, true);
1576 window.removeEventListener("scroll", repaint, true);
1577 window.removeEventListener("resize", repaint);
1578 dragHandle.removeEventListener("pointerdown", onEditorPointerDown);
@@ -1354,6 +1582,8 @@ function startAnnotation(sendEnabled: boolean): void {
1582 if (editorLayoutFrame !== null) window.cancelAnimationFrame(editorLayoutFrame);
1583 ipcRenderer.off(CANCEL_PICK_CHANNEL, onCancel);
1584 ipcRenderer.off(ANNOTATION_CAPTURED_CHANNEL, onCaptured);
1585 + ipcRenderer.off(ANNOTATION_VOICE_STATE_CHANNEL, onVoiceState);
1586 + if (elapsedTimer !== null) clearInterval(elapsedTimer);
1587 document.documentElement.removeAttribute("data-t3code-annotation-tool");
1588 cursorStyle.remove();
1589 inputLayer?.remove();
@@ -1364,7 +1594,32 @@ function startAnnotation(sendEnabled: boolean): void {
1594
1595 const onCancel = (): void => teardown(false);
1596 const onCaptured = (): void => teardown(false);
1597 + const onVoiceKeyUp = (event: KeyboardEvent): void => {
1598 + if (!event.isTrusted || (event.code || event.key) !== voiceKeyCode) return;
1599 + voiceKeyCode = null;
1600 + event.preventDefault();
1601 + event.stopImmediatePropagation();
1602 + sendVoice("key", event);
1603 + };
1604 const onKeyDown = (event: KeyboardEvent): void => {
1605 + // Only the keyboard drives dictation; a page cannot synthesize the chord or Escape.
1606 + if (voice && event.isTrusted && !event.isComposing && event.keyCode !== 229) {
1607 + if (event.key === "Escape" && voiceBusy) {
1608 + event.preventDefault();
1609 + event.stopImmediatePropagation();
1610 + voiceKeyCode = null;
1611 + pendingVoiceSubmission = null;
1612 + sendVoice("key", event);
1613 + return;
1614 + }
1615 + if (voiceAvailable && editor.style.display !== "none" && isDictationChord(event)) {
1616 + event.preventDefault();
1617 + event.stopImmediatePropagation();
1618 + voiceKeyCode = event.code || event.key;
1619 + sendVoice("key", event);
1620 + return;
1621 + }
1622 + }
1623 if (isAnnotationNode(event.target as Element) && event.key !== "Escape") return;
1624 if (event.key === "Escape") {
1625 event.preventDefault();
@@ -1382,6 +1637,16 @@ function startAnnotation(sendEnabled: boolean): void {
1637
1638 const submitAnnotation = (submission: PreviewAnnotationSubmission): void => {
1639 if (submission === "send" && !sendEnabled) return;
1640 + if (voicePhase === "preparing") return;
1641 + // Submitting while dictating finishes the recording and submits once the text lands.
1642 + if (voiceBusy) {
1643 + if (pendingVoiceSubmission === null) {
1644 + pendingVoiceSubmission = submission;
1645 + voiceSubmissionReady = false;
1646 + if (voicePhase === "recording") sendVoice("stop");
1647 + }
1648 + return;
1649 + }
1650 if (pendingCapture || (selected.size === 0 && regions.length === 0 && strokes.length === 0))
1651 return;
1652 pendingCapture = true;
@@ -1460,11 +1725,14 @@ function startAnnotation(sendEnabled: boolean): void {
1725 window.addEventListener("pointerout", onPointerOut, { capture: true, passive: true });
1726 window.addEventListener("click", onClick, { capture: true, passive: false });
1727 window.addEventListener("blur", onWindowBlur);
1728 + window.addEventListener("focus", onWindowFocus);
1729 window.addEventListener("keydown", onKeyDown, { capture: true });
1730 + window.addEventListener("keyup", onVoiceKeyUp, { capture: true });
1731 window.addEventListener("scroll", repaint, { capture: true, passive: true });
1732 window.addEventListener("resize", repaint, { passive: true });
1733 ipcRenderer.on(CANCEL_PICK_CHANNEL, onCancel);
1734 ipcRenderer.on(ANNOTATION_CAPTURED_CHANNEL, onCaptured);
1735 + if (voice) ipcRenderer.on(ANNOTATION_VOICE_STATE_CHANNEL, onVoiceState);
1736 if (inputLayer) {
1737 document.documentElement.appendChild(inputLayer);
1738 inputLayer.focus({ preventScroll: true });
@@ -1473,6 +1741,7 @@ function startAnnotation(sendEnabled: boolean): void {
1741 rootResizeObserver.observe(document.documentElement);
1742 refreshToolButtons();
1743 updateStatus();
1744 + sendVoice(document.hasFocus() ? "focus" : "sync");
1745 activeSession = {
1746 teardown,
1747 applyTheme: (theme) => applyAnnotationTheme(host, theme),
@@ -1485,9 +1754,14 @@ function startAnnotation(sendEnabled: boolean): void {
1754
1755 ipcRenderer.on(
1756 START_PICK_CHANNEL,
1488 - (_event, theme: DesktopPreviewAnnotationTheme | undefined, sendEnabled?: boolean) => {
1757 + (
1758 + _event,
1759 + theme: DesktopPreviewAnnotationTheme | undefined,
1760 + sendEnabled?: boolean,
1761 + voice?: DesktopPreviewAnnotationVoiceConfig,
1762 + ) => {
1763 if (theme) annotationTheme = theme;
1490 - startAnnotation(sendEnabled === true);
1764 + startAnnotation(sendEnabled === true, voice);
1765 },
1766 );
1767 ipcRenderer.on(ANNOTATION_SEND_ENABLED_CHANNEL, (_event, enabled: boolean) => {
apps/desktop/vite.config.ts
+4 -1
@@ -120,7 +120,10 @@ export default defineConfig({
120 outExtensions: () => ({ js: ".cjs" }),
121 entry: ["src/preview-pick-preload.ts"],
122 deps: {
123 - alwaysBundle: (id) => id === "react-grab" || id.startsWith("react-grab/"),
123 + alwaysBundle: (id) =>
124 + id === "react-grab" ||
125 + id.startsWith("react-grab/") ||
126 + id === "@t3tools/shared/keybindingMatching",
127 },
128 },
129 {
apps/web/src/components/chat/ComposerSpeechButton.tsx
+1 -1
@@ -17,7 +17,7 @@ type SpeechPresentation = {
17 showsSend: boolean;
18 };
19
20 -function resolveSpeechPresentation(
20 +export function resolveSpeechPresentation(
21 state: VoiceInputState,
22 progress: { downloaded: number; total: number } | null,
23 ): SpeechPresentation {
apps/web/src/components/preview/PreviewAnnotationSpeech.tsx new
+194
@@ -0,0 +1,194 @@
1 +import { scopeProjectRef } from "@t3tools/client-runtime/environment";
2 +import type {
3 + DesktopPreviewAnnotationVoiceConfig,
4 + DesktopPreviewAnnotationVoiceEvent,
5 + ScopedThreadRef,
6 +} from "@t3tools/contracts";
7 +import { useNavigate } from "@tanstack/react-router";
8 +import { useEffect, useRef, useState } from "react";
9 +
10 +import { resolveSpeechPresentation } from "~/components/chat/ComposerSpeechButton";
11 +import { VoiceInputSetup } from "~/components/chat/VoiceInputSetup";
12 +import { toastManager } from "~/components/ui/toast";
13 +import { useComposerDraftStore } from "~/composerDraftStore";
14 +import { useStableCallback } from "~/hooks/useStableCallback";
15 +import { useDictationShortcut, type DictationKeyHandlers } from "~/speech/useDictationShortcut";
16 +import { useEnvironmentSpeechInput } from "~/speech/useEnvironmentSpeechInput";
17 +import { useProject, useThreadShell } from "~/state/entities";
18 +import { previewBridge } from "./previewBridge";
19 +
20 +/**
21 + * The annotation editor lives inside the preview guest, which only forwards trusted gestures
22 + * and mirrors state. Recording, consent, and transcription stay in this renderer.
23 + */
24 +export function PreviewAnnotationSpeech({
25 + threadRef,
26 + tabId,
27 + config,
28 + keybindings,
29 +}: {
30 + threadRef: ScopedThreadRef;
31 + tabId: string;
32 + config: DesktopPreviewAnnotationVoiceConfig;
33 + keybindings: Parameters<typeof useDictationShortcut>[0]["keybindings"];
34 +}) {
35 + const navigate = useNavigate();
36 + const thread = useThreadShell(threadRef);
37 + const draftThread = useComposerDraftStore((store) => store.getDraftThreadByRef(threadRef));
38 + const projectId = thread?.projectId ?? draftThread?.projectId ?? null;
39 + const project = useProject(
40 + projectId ? scopeProjectRef(threadRef.environmentId, projectId) : null,
41 + );
42 + const draft = useRef({ text: "", cursor: 0, selectionEnd: 0 });
43 + const [text, setText] = useState("");
44 + const keys = useRef<DictationKeyHandlers | null>(null);
45 + const guestFocused = useRef(false);
46 + // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- notices focus returning from the preview guest to this window
47 + useEffect(() => {
48 + const onFocus = () => {
49 + guestFocused.current = false;
50 + };
51 + window.addEventListener("focus", onFocus);
52 + window.addEventListener("focusin", onFocus);
53 + return () => {
54 + window.removeEventListener("focus", onFocus);
55 + window.removeEventListener("focusin", onFocus);
56 + };
57 + }, []);
58 + const speech = useEnvironmentSpeechInput({
59 + environmentId: threadRef.environmentId,
60 + projectId,
61 + projectName: project?.title,
62 + ownerKey: JSON.stringify(["preview-annotation", threadRef, tabId, config.sessionId]),
63 + draftText: text,
64 + readDraft: () => ({
65 + text: draft.current.text,
66 + selection: { start: draft.current.cursor, end: draft.current.selectionEnd },
67 + }),
68 + commitDraft: (next, selection) => {
69 + draft.current = { text: next, cursor: selection.start, selectionEnd: selection.end };
70 + setText(next);
71 + void publish(current.current.voiceState, { text: next, cursor: selection.start });
72 + },
73 + });
74 + const subscribeKeys = useStableCallback((handlers: DictationKeyHandlers) => {
75 + keys.current = handlers;
76 + return () => {
77 + keys.current = null;
78 + };
79 + });
80 + const shortcutLabel = useDictationShortcut({
81 + keybindings,
82 + speech,
83 + disabled: false,
84 + terminalOpen: false,
85 + modelPickerOpen: false,
86 + previewFocus: true,
87 + ownsFocus: () => guestFocused.current,
88 + subscribeKeys,
89 + });
90 + const { available, state, preview, freezesEditor, blocksSubmission, level } = speech;
91 + const voiceState = {
92 + tabId,
93 + sessionId: config.sessionId,
94 + available,
95 + phase: state.phase,
96 + errorAction: state.errorAction,
97 + status: resolveSpeechPresentation(state, null).status,
98 + preview: preview ? preview.committed + preview.tentative : null,
99 + level,
100 + shortcutLabel,
101 + freezesEditor,
102 + blocksSubmission,
103 + };
104 + const current = useRef({ speech, voiceState });
105 + // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- publishes committed speech actions and state to the desktop IPC listener
106 + useEffect(() => {
107 + current.current = { speech, voiceState };
108 + });
109 + const publish = useStableCallback(
110 + async (voice: typeof voiceState, nextDraft: { text: string; cursor: number } | null) => {
111 + try {
112 + await previewBridge?.annotationVoice.update({ ...voice, draft: nextDraft });
113 + } catch (error) {
114 + current.current.speech.cancel();
115 + toastManager.add({
116 + type: "error",
117 + title: "Could not update annotation voice input",
118 + description: error instanceof Error ? error.message : String(error),
119 + });
120 + }
121 + },
122 + );
123 + // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- mirrors every committed voice state change into the preview guest
124 + useEffect(() => {
125 + void publish(voiceState, null);
126 + }, [publish, voiceState]);
127 + // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes to gestures the preview guest relays for this session
128 + useEffect(
129 + () =>
130 + previewBridge?.annotationVoice.onEvent(
131 + (eventTabId, event: DesktopPreviewAnnotationVoiceEvent) => {
132 + if (eventTabId !== tabId || event.sessionId !== config.sessionId) return;
133 + draft.current = {
134 + text: event.text,
135 + cursor: Math.min(event.cursor, event.text.length),
136 + selectionEnd: Math.min(event.selectionEnd ?? event.cursor, event.text.length),
137 + };
138 + setText(event.text);
139 + if (event.action === "focus" || event.action === "key" || event.action === "start")
140 + guestFocused.current = true;
141 + if (event.action === "blur") guestFocused.current = false;
142 + const value = current.current.speech;
143 + switch (event.action) {
144 + case "focus":
145 + case "sync":
146 + void publish(current.current.voiceState, null);
147 + break;
148 + case "start":
149 + void value.start();
150 + break;
151 + case "stop":
152 + void value.stop();
153 + break;
154 + case "cancel":
155 + value.cancel();
156 + break;
157 + case "settings":
158 + value.cancel();
159 + void navigate({ to: "/settings/voice" });
160 + break;
161 + case "skip":
162 + value.skipPostProcessing();
163 + break;
164 + case "blur":
165 + keys.current?.blur();
166 + break;
167 + case "key": {
168 + if (!event.keyboard) break;
169 + keys.current?.[event.keyboard.type](
170 + new KeyboardEvent(event.keyboard.type, event.keyboard),
171 + );
172 + break;
173 + }
174 + }
175 + },
176 + ),
177 + [tabId, config.sessionId, publish, navigate],
178 + );
179 + return (
180 + <VoiceInputSetup
181 + environmentId={speech.transcriptionEnvironmentId}
182 + open={speech.setup.open}
183 + step={speech.setup.step}
184 + status={speech.status}
185 + model={speech.setup.model}
186 + downloading={speech.setup.downloading}
187 + error={speech.setup.error}
188 + onOpenChange={speech.setup.setOpen}
189 + onDownload={() => void speech.setup.download()}
190 + onCancelDownload={() => void speech.setup.cancelDownload()}
191 + onStartRecording={() => void speech.setup.startRecording()}
192 + />
193 + );
194 +}
apps/web/src/components/preview/PreviewView.browser.test.tsx
+1
@@ -54,6 +54,7 @@ vi.mock(import("./previewBridge"), async (original) => ({
54 previewBridge: {
55 navigate: mocks.navigate,
56 pickElement: mocks.pickElement,
57 + annotationVoice: { onEvent: () => () => {}, update: async () => {} },
58 setAnnotationSendEnabled: mocks.setAnnotationSendEnabled,
59 cancelPickElement: mocks.cancelPickElement,
60 refresh: vi.fn(async () => undefined),
apps/web/src/components/preview/PreviewView.tsx
+30 -1
@@ -1,5 +1,7 @@
1 +import { useAtomValue } from "@effect/atom-react";
2 import { scopedThreadKey } from "@t3tools/client-runtime/environment";
3 import { settlePromise } from "@t3tools/client-runtime/state/runtime";
4 +import type { DesktopPreviewAnnotationVoiceConfig } from "@t3tools/contracts";
5 import { previewStreamDownloadUrl } from "@t3tools/client-runtime/preview/server-browser-stream";
6 import {
7 isAtomCommandInterrupted,
@@ -57,6 +59,10 @@ import {
59 import { readEnvironmentScope, useEnvironmentScope } from "~/state/session";
60 import { useRightPanelStore } from "~/rightPanelStore";
61
62 +import { effectiveShortcutsForCommand } from "~/keybindings";
63 +import { randomUUID } from "~/lib/utils";
64 +import { primaryServerKeybindingsAtom } from "~/state/server";
65 +import { PreviewAnnotationSpeech } from "./PreviewAnnotationSpeech";
66 import { previewBridge } from "./previewBridge";
67 import { subscribePreviewAction } from "./previewActionBus";
68 import { closePreviewSession } from "./closePreviewSession";
@@ -153,6 +159,9 @@ export function PreviewView({
159 Boolean(onSendAnnotation);
160 const activeRecordingTabIds = useActiveBrowserRecordingTabIds();
161 const pickActiveRef = useRef<{ cancelled: boolean } | null>(null);
162 + const [annotationVoice, setAnnotationVoice] =
163 + useState<DesktopPreviewAnnotationVoiceConfig | null>(null);
164 + const keybindings = useAtomValue(primaryServerKeybindingsAtom);
165 const previewState = useThreadPreviewState(threadRef);
166 const recentHistoryEntries = useThreadRecentHistory(
167 threadRef,
@@ -738,11 +747,20 @@ export function PreviewView({
747 let submitted = false;
748 pickActiveRef.current = pickRequest;
749 setPickActive(true);
750 + // The guest learns only the dictation chords, never the whole keybinding config.
751 + const voice: DesktopPreviewAnnotationVoiceConfig = {
752 + sessionId: randomUUID(),
753 + shortcuts: effectiveShortcutsForCommand(keybindings, "composer.dictation", {
754 + context: { previewFocus: true, previewOpen: true, editableFocus: true },
755 + }),
756 + };
757 + setAnnotationVoice(voice);
758 const finishPick = () => {
759 const isCurrentPick = pickActiveRef.current === pickRequest;
760 if (isCurrentPick) {
761 pickActiveRef.current = null;
762 setPickActive(false);
763 + setAnnotationVoice(null);
764 }
765 if (
766 (isCurrentPick || submitted) &&
@@ -763,12 +781,13 @@ export function PreviewView({
781 readEnvironmentScope(threadRef.environmentId, AuthOrchestrationOperateScope),
782 );
783 if (pickRequest.cancelled) return;
766 - const result = await bridge.pickElement(runtimeTabId);
784 + const result = await bridge.pickElement(runtimeTabId, voice);
785 if (!result || pickRequest.cancelled) return;
786 // The accepted pick must survive further clicks, tab changes, and unmount; stop cancellation here.
787 if (pickActiveRef.current === pickRequest) {
788 pickActiveRef.current = null;
789 setPickActive(false);
790 + setAnnotationVoice(null);
791 submitted = true;
792 }
793 const { annotation: picked, submission, screenshotFailed = false } = result;
@@ -830,6 +849,7 @@ export function PreviewView({
849 void previewBridge.cancelPickElement(runtimeTabId).catch(() => undefined);
850 }
851 setPickActive(false);
852 + setAnnotationVoice(null);
853 };
854 }, [runtimeTabId]);
855
@@ -875,6 +895,15 @@ export function PreviewView({
895 className="flex min-h-0 flex-1 flex-col bg-background"
896 data-thread-key={scopedThreadKey(threadRef)}
897 >
898 + {pickActive && runtimeTabId && annotationVoice ? (
899 + <PreviewAnnotationSpeech
900 + key={annotationVoice.sessionId}
901 + threadRef={threadRef}
902 + tabId={runtimeTabId}
903 + config={annotationVoice}
904 + keybindings={keybindings}
905 + />
906 + ) : null}
907 <PreviewChromeRow
908 url={url}
909 loading={loading || serverStreamPending}
apps/web/src/speech/useDictationShortcut.ts
+28 -5
@@ -21,14 +21,26 @@ type SpeechActions = {
21 cancel(): void;
22 };
23
24 +export type DictationKeyHandlers = {
25 + keydown(event: KeyboardEvent): void;
26 + keyup(event: KeyboardEvent): void;
27 + blur(): void;
28 +};
29 +
30 type ShortcutInput = {
31 keybindings: ResolvedKeybindingsConfig;
32 speech: SpeechActions;
33 disabled: boolean;
34 terminalOpen: boolean;
35 modelPickerOpen: boolean;
36 + /** Resolve the chord as if the preview had focus; the keys arrive relayed from its guest. */
37 + previewFocus?: boolean;
38 /** When set, the chord targets this editor only while it has focus. */
39 targetRef?: RefObject<HTMLElement | null>;
40 + /** An editor outside this document reports whether it holds the keyboard. */
41 + ownsFocus?: () => boolean;
42 + /** Receives handlers that replay keys an outside editor relayed, as if typed here. */
43 + subscribeKeys?: (handlers: DictationKeyHandlers) => () => void;
44 };
45
46 // 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) {
53 return phase !== "idle" && phase !== "error";
54 });
55 if (busy) return busy[0] === id;
44 - const focused = entries.find(([, read]) =>
45 - read().targetRef?.current?.contains(document.activeElement),
46 - );
56 + const focused =
57 + entries.find(([, read]) => read().ownsFocus?.()) ??
58 + entries.find(([, read]) => read().targetRef?.current?.contains(document.activeElement));
59 if (focused) return focused[0] === id;
48 - return entries.find(([, read]) => !read().targetRef)?.[0] === id;
60 + return entries.find(([, read]) => !read().targetRef && !read().ownsFocus)?.[0] === id;
61 }
62
63 export function useDictationShortcut(input: ShortcutInput) {
64 const id = useRef(Symbol("dictation-target"));
65 + const subscribeKeys = input.subscribeKeys;
66 const mode = useClientSettings((settings) => settings.voiceShortcutMode);
67 const current = useRef(input);
68 // 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) {
113 return;
114 }
115 const { keybindings, terminalOpen, modelPickerOpen, disabled } = current.current;
116 + const previewFocus = current.current.previewFocus ?? false;
117 const command = resolveShortcutCommand(event, keybindings, {
118 context: {
119 terminalFocus: getTerminalFocusOwner() !== null,
120 terminalOpen,
121 modelPickerOpen,
122 + previewFocus,
123 + previewOpen: previewFocus,
124 + ...(previewFocus ? { editableFocus: true } : {}),
125 },
126 });
127 if (command !== "composer.dictation") return;
@@ -129,6 +146,11 @@ export function useDictationShortcut(input: ShortcutInput) {
146 };
147 };
148 const onBlur = () => finish(null);
149 + const unsubscribe = subscribeKeys?.({
150 + keydown: (event) => window.dispatchEvent(event),
151 + keyup: (event) => window.dispatchEvent(event),
152 + blur: onBlur,
153 + });
154 window.addEventListener("keydown", onKeyDown, true);
155 window.addEventListener("keyup", finish, true);
156 window.addEventListener("blur", onBlur);
@@ -136,11 +158,12 @@ export function useDictationShortcut(input: ShortcutInput) {
158 disposed = true;
159 pressed.current = null;
160 shortcutTargets.delete(id.current);
161 + unsubscribe?.();
162 window.removeEventListener("keydown", onKeyDown, true);
163 window.removeEventListener("keyup", finish, true);
164 window.removeEventListener("blur", onBlur);
165 };
143 - }, [mode]);
166 + }, [mode, subscribeKeys]);
167
168 return shortcutLabelForCommand(input.keybindings, "composer.dictation", {
169 context: { terminalFocus: false, terminalOpen: input.terminalOpen },
docs/user/voice-input.md
+8 -5
@@ -2,8 +2,9 @@
2
3 Dictate into the composer instead of typing. The transcript lands in your draft
4 for review, and only sending the message sends anything to an agent. Dictation
5 -also works in citation comments, diff and file annotations, and pull request
6 -comments, replies, and review summaries.
5 +also works in citation comments, diff and file annotations, pull request
6 +comments, replies, and review summaries, and in the desktop app's browser
7 +annotation editor.
8
9 On iPhone and Android, voice input transcribes on the device. See
10 [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.
48
49 Pressing Send while dictating finishes the recording and sends the draft once
50 the transcript has been inserted. Cancelling also cancels that queued send. In
50 -the other editors, Save, Comment, Reply, or Submit review works the same way,
51 -and the shortcut targets the editor that has focus, or the composer when none
52 -does.
51 +the other editors, Save, Comment, Reply, Submit review, or Attach works the
52 +same way, and the shortcut targets the editor that has focus, or the composer
53 +when none does. In the desktop browser's annotation editor, the microphone and
54 +the shortcut work while the page has focus; the page you are annotating never
55 +sees the recording, which runs in T3 Code itself.
56
57 **Dictation shortcut** in Voice settings picks how the keybinding behaves:
58 **Auto** tap-toggles or records while held, **Hold** records only while the keys
packages/contracts/src/ipc.ts
+84 -2
@@ -14,7 +14,7 @@ import { AdvertisedEndpoint } from "./remoteAccess.ts";
14 import { ExecutionEnvironmentDescriptor } from "./environment.ts";
15 import { type ClientSettings, type QuitConfirmationMode, SnapShotShortcut } from "./settings.ts";
16 import type { EditorId } from "./editor.ts";
17 -import type { PreviewForwardedShortcut } from "./keybindings.ts";
17 +import { KeybindingShortcut, type PreviewForwardedShortcut } from "./keybindings.ts";
18
19 import type {
20 DesktopAppActivationRequest,
@@ -1154,6 +1154,79 @@ export interface DesktopBridge {
1154 /** Renderer callback invoked by Electron with a fresh user gesture before display-media capture. */
1155 export const DESKTOP_PREVIEW_RECORDING_CAPTURE_TRIGGER = "__t3DesktopPreviewRecordingCapture";
1156
1157 +/**
1158 + * Dictation for the annotation editor drawn inside a preview guest. The guest only shows
1159 + * controls and forwards trusted user gestures; the renderer records, with its consent
1160 + * checks, and publishes state back. `shortcuts` are the dictation chords in effect.
1161 + */
1162 +export const DesktopPreviewAnnotationVoiceConfigSchema = Schema.Struct({
1163 + sessionId: Schema.String.check(Schema.isMaxLength(64)),
1164 + shortcuts: Schema.Array(KeybindingShortcut).check(Schema.isMaxLength(16)),
1165 +});
1166 +export type DesktopPreviewAnnotationVoiceConfig =
1167 + typeof DesktopPreviewAnnotationVoiceConfigSchema.Type;
1168 +
1169 +export const DesktopPreviewAnnotationVoiceEventSchema = Schema.Struct({
1170 + sessionId: Schema.String.check(Schema.isMaxLength(64)),
1171 + text: Schema.String.check(Schema.isMaxLength(100_000)),
1172 + cursor: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
1173 + selectionEnd: Schema.optional(Schema.Int.check(Schema.isGreaterThanOrEqualTo(0))),
1174 + action: Schema.Literals([
1175 + "sync",
1176 + "start",
1177 + "stop",
1178 + "cancel",
1179 + "skip",
1180 + "settings",
1181 + "key",
1182 + "focus",
1183 + "blur",
1184 + ]),
1185 + keyboard: Schema.optional(
1186 + Schema.Struct({
1187 + type: Schema.Literals(["keydown", "keyup"]),
1188 + key: Schema.String.check(Schema.isMaxLength(32)),
1189 + code: Schema.String.check(Schema.isMaxLength(64)),
1190 + metaKey: Schema.Boolean,
1191 + ctrlKey: Schema.Boolean,
1192 + shiftKey: Schema.Boolean,
1193 + altKey: Schema.Boolean,
1194 + repeat: Schema.Boolean,
1195 + }),
1196 + ),
1197 +});
1198 +export type DesktopPreviewAnnotationVoiceEvent =
1199 + typeof DesktopPreviewAnnotationVoiceEventSchema.Type;
1200 +
1201 +export const DesktopPreviewAnnotationVoiceStateSchema = Schema.Struct({
1202 + tabId: DesktopPreviewTabIdSchema,
1203 + sessionId: Schema.String.check(Schema.isMaxLength(64)),
1204 + available: Schema.Boolean,
1205 + phase: Schema.Literals([
1206 + "idle",
1207 + "preparing",
1208 + "recording",
1209 + "transcribing",
1210 + "post-processing",
1211 + "error",
1212 + ]),
1213 + status: Schema.NullOr(Schema.String),
1214 + errorAction: Schema.NullOr(Schema.Literals(["retry", "settings"])),
1215 + preview: Schema.NullOr(Schema.String),
1216 + level: Schema.Number,
1217 + shortcutLabel: Schema.NullOr(Schema.String),
1218 + freezesEditor: Schema.Boolean,
1219 + blocksSubmission: Schema.Boolean,
1220 + draft: Schema.NullOr(Schema.Struct({ text: Schema.String, cursor: Schema.Int })),
1221 +});
1222 +export type DesktopPreviewAnnotationVoiceState =
1223 + typeof DesktopPreviewAnnotationVoiceStateSchema.Type;
1224 +
1225 +export const DesktopPreviewPickElementInputSchema = Schema.Struct({
1226 + tabId: DesktopPreviewTabIdSchema,
1227 + voice: Schema.optional(DesktopPreviewAnnotationVoiceConfigSchema),
1228 +});
1229 +
1230 export interface DesktopPreviewBridge {
1231 setForwardedShortcuts: (shortcuts: ReadonlyArray<PreviewForwardedShortcut>) => Promise<void>;
1232 createTab: (tabId: string, defaults?: DesktopPreviewTabDefaults) => Promise<void>;
@@ -1188,8 +1261,17 @@ export interface DesktopPreviewBridge {
1261 }) => Promise<BrowserImportResult>;
1262 setAnnotationTheme: (theme: DesktopPreviewAnnotationTheme) => Promise<void>;
1263 setAnnotationSendEnabled: (tabId: string, enabled: boolean) => Promise<void>;
1264 + annotationVoice: {
1265 + onEvent: (
1266 + listener: (tabId: string, event: DesktopPreviewAnnotationVoiceEvent) => void,
1267 + ) => () => void;
1268 + update: (state: DesktopPreviewAnnotationVoiceState) => Promise<void>;
1269 + };
1270 /** Resolves with the annotation and attach/send intent, or null on cancellation. Rejects if activation fails. */
1192 - pickElement: (tabId: string) => Promise<PreviewAnnotationSubmissionResult | null>;
1271 + pickElement: (
1272 + tabId: string,
1273 + voice?: DesktopPreviewAnnotationVoiceConfig,
1274 + ) => Promise<PreviewAnnotationSubmissionResult | null>;
1275 cancelPickElement: (tabId: string) => Promise<void>;
1276 captureScreenshot: (
1277 tabId: string,
packages/shared/package.json
+4
@@ -243,6 +243,10 @@
243 "types": "./src/keybindings.ts",
244 "import": "./src/keybindings.ts"
245 },
246 + "./keybindingMatching": {
247 + "types": "./src/keybindingMatching.ts",
248 + "import": "./src/keybindingMatching.ts"
249 + },
250 "./threadTranscript": {
251 "types": "./src/threadTranscript.ts",
252 "import": "./src/threadTranscript.ts"
packages/shared/src/keybindingMatching.ts new
+106
@@ -0,0 +1,106 @@
1 +import type { KeybindingShortcut } from "@t3tools/contracts";
2 +
3 +// Matching only: the desktop preview guest bundles this file without the rest of the
4 +// keybindings module, so it stays free of parsing, defaults, and contracts runtime code.
5 +
6 +export interface ShortcutEventLike {
7 + getModifierState?: (key: "AltGraph") => boolean;
8 + type?: string;
9 + code?: string;
10 + key: string;
11 + repeat?: boolean;
12 + metaKey: boolean;
13 + ctrlKey: boolean;
14 + shiftKey: boolean;
15 + altKey: boolean;
16 +}
17 +
18 +export interface ShortcutModifierStateLike {
19 + metaKey: boolean;
20 + ctrlKey: boolean;
21 + shiftKey: boolean;
22 + altKey: boolean;
23 +}
24 +
25 +export const EVENT_CODE_SHORTCUT_KEYS: Readonly<Record<string, string>> = {
26 + Backquote: "`",
27 + Backslash: "\\",
28 + BracketLeft: "[",
29 + BracketRight: "]",
30 + Comma: ",",
31 + Digit0: "0",
32 + Digit1: "1",
33 + Digit2: "2",
34 + Digit3: "3",
35 + Digit4: "4",
36 + Digit5: "5",
37 + Digit6: "6",
38 + Digit7: "7",
39 + Digit8: "8",
40 + Digit9: "9",
41 + Equal: "=",
42 + Minus: "-",
43 + Period: ".",
44 + Quote: "'",
45 + Semicolon: ";",
46 + Slash: "/",
47 +};
48 +
49 +export function isMacPlatform(platform: string): boolean {
50 + return /mac|iphone|ipad|ipod/i.test(platform);
51 +}
52 +
53 +export function normalizeEventKey(key: string): string {
54 + const normalized = key.toLowerCase();
55 + if (normalized === "esc") return "escape";
56 + return normalized;
57 +}
58 +
59 +export function shortcutKeyFromEvent(event: Pick<ShortcutEventLike, "key" | "code">): string {
60 + const layoutKey = normalizeEventKey(event.key);
61 + if (/^[a-z]$/.test(layoutKey)) return layoutKey;
62 + const physicalKey = event.code ? EVENT_CODE_SHORTCUT_KEYS[event.code] : undefined;
63 + return physicalKey ?? layoutKey;
64 +}
65 +
66 +export function resolveEventKeys(event: ShortcutEventLike): Set<string> {
67 + const layoutKey = normalizeEventKey(event.key);
68 + const keys = new Set([layoutKey]);
69 + const letterCode = event.code?.match(/^Key([A-Z])$/)?.[1];
70 + if (letterCode && !/^[a-z]$/.test(layoutKey)) {
71 + keys.add(letterCode.toLowerCase());
72 + }
73 + keys.add(shortcutKeyFromEvent(event));
74 + return keys;
75 +}
76 +
77 +export function matchesKeybindingShortcutModifiers(
78 + event: ShortcutModifierStateLike,
79 + shortcut: KeybindingShortcut,
80 + platform: string,
81 +): boolean {
82 + const useMetaForMod = isMacPlatform(platform);
83 + const expectedMeta = shortcut.metaKey || (shortcut.modKey && useMetaForMod);
84 + const expectedCtrl = shortcut.ctrlKey || (shortcut.modKey && !useMetaForMod);
85 + return (
86 + event.metaKey === expectedMeta &&
87 + event.ctrlKey === expectedCtrl &&
88 + event.shiftKey === shortcut.shiftKey &&
89 + event.altKey === shortcut.altKey
90 + );
91 +}
92 +
93 +export function matchesKeybindingShortcut(
94 + event: ShortcutEventLike,
95 + shortcut: KeybindingShortcut,
96 + platform: string,
97 +): boolean {
98 + if (
99 + !isMacPlatform(platform) &&
100 + event.getModifierState?.("AltGraph") &&
101 + !/^[a-z0-9]$/i.test(event.key)
102 + )
103 + return false;
104 + if (!matchesKeybindingShortcutModifiers(event, shortcut, platform)) return false;
105 + return resolveEventKeys(event).has(shortcut.key);
106 +}
packages/shared/src/keybindings.ts
+11 -101
@@ -10,48 +10,17 @@ import {
10 THREAD_JUMP_KEYBINDING_COMMANDS,
11 } from "@t3tools/contracts";
12
13 -export interface ShortcutEventLike {
14 - getModifierState?: (key: "AltGraph") => boolean;
15 - type?: string;
16 - code?: string;
17 - key: string;
18 - repeat?: boolean;
19 - metaKey: boolean;
20 - ctrlKey: boolean;
21 - shiftKey: boolean;
22 - altKey: boolean;
23 -}
24 -
25 -export interface ShortcutModifierStateLike {
26 - metaKey: boolean;
27 - ctrlKey: boolean;
28 - shiftKey: boolean;
29 - altKey: boolean;
30 -}
31 -
32 -export const EVENT_CODE_SHORTCUT_KEYS: Readonly<Record<string, string>> = {
33 - Backquote: "`",
34 - Backslash: "\\",
35 - BracketLeft: "[",
36 - BracketRight: "]",
37 - Comma: ",",
38 - Digit0: "0",
39 - Digit1: "1",
40 - Digit2: "2",
41 - Digit3: "3",
42 - Digit4: "4",
43 - Digit5: "5",
44 - Digit6: "6",
45 - Digit7: "7",
46 - Digit8: "8",
47 - Digit9: "9",
48 - Equal: "=",
49 - Minus: "-",
50 - Period: ".",
51 - Quote: "'",
52 - Semicolon: ";",
53 - Slash: "/",
54 -};
13 +export {
14 + EVENT_CODE_SHORTCUT_KEYS,
15 + isMacPlatform,
16 + matchesKeybindingShortcut,
17 + matchesKeybindingShortcutModifiers,
18 + normalizeEventKey,
19 + resolveEventKeys,
20 + shortcutKeyFromEvent,
21 + type ShortcutEventLike,
22 + type ShortcutModifierStateLike,
23 +} from "./keybindingMatching.ts";
24
25 export const US_SHIFTED_TO_UNSHIFTED_KEYS: ReadonlyMap<string, string> = new Map([
26 ["!", "1"],
@@ -77,65 +46,6 @@ export const US_SHIFTED_TO_UNSHIFTED_KEYS: ReadonlyMap<string, string> = new Map
46 ["?", "/"],
47 ]);
48
80 -export function isMacPlatform(platform: string): boolean {
81 - return /mac|iphone|ipad|ipod/i.test(platform);
82 -}
83 -
84 -export function normalizeEventKey(key: string): string {
85 - const normalized = key.toLowerCase();
86 - if (normalized === "esc") return "escape";
87 - return normalized;
88 -}
89 -
90 -export function shortcutKeyFromEvent(event: Pick<ShortcutEventLike, "key" | "code">): string {
91 - const layoutKey = normalizeEventKey(event.key);
92 - if (/^[a-z]$/.test(layoutKey)) return layoutKey;
93 - const physicalKey = event.code ? EVENT_CODE_SHORTCUT_KEYS[event.code] : undefined;
94 - return physicalKey ?? layoutKey;
95 -}
96 -
97 -export function resolveEventKeys(event: ShortcutEventLike): Set<string> {
98 - const layoutKey = normalizeEventKey(event.key);
99 - const keys = new Set([layoutKey]);
100 - const letterCode = event.code?.match(/^Key([A-Z])$/)?.[1];
101 - if (letterCode && !/^[a-z]$/.test(layoutKey)) {
102 - keys.add(letterCode.toLowerCase());
103 - }
104 - keys.add(shortcutKeyFromEvent(event));
105 - return keys;
106 -}
107 -
108 -export function matchesKeybindingShortcutModifiers(
109 - event: ShortcutModifierStateLike,
110 - shortcut: KeybindingShortcut,
111 - platform: string,
112 -): boolean {
113 - const useMetaForMod = isMacPlatform(platform);
114 - const expectedMeta = shortcut.metaKey || (shortcut.modKey && useMetaForMod);
115 - const expectedCtrl = shortcut.ctrlKey || (shortcut.modKey && !useMetaForMod);
116 - return (
117 - event.metaKey === expectedMeta &&
118 - event.ctrlKey === expectedCtrl &&
119 - event.shiftKey === shortcut.shiftKey &&
120 - event.altKey === shortcut.altKey
121 - );
122 -}
123 -
124 -export function matchesKeybindingShortcut(
125 - event: ShortcutEventLike,
126 - shortcut: KeybindingShortcut,
127 - platform: string,
128 -): boolean {
129 - if (
130 - !isMacPlatform(platform) &&
131 - event.getModifierState?.("AltGraph") &&
132 - !/^[a-z0-9]$/i.test(event.key)
133 - )
134 - return false;
135 - if (!matchesKeybindingShortcutModifiers(event, shortcut, platform)) return false;
136 - return resolveEventKeys(event).has(shortcut.key);
137 -}
138 -
49 type WhenToken =
50 | { type: "identifier"; value: string }
51 | { type: "not" }