Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
fix(canvas): match legacy select object layout
joshistoast37001ef8104f
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.jsonindex b40ebfe0ea..2af132bc0a 100644--- a/invokeai/frontend/webv2/public/locales/en.json+++ b/invokeai/frontend/webv2/public/locales/en.json@@ -1327,6 +1327,7 @@},"selectObject": {"autoProcess": "Auto Process",+ "autoProcessCompact": "Auto","bboxActive": "Bounding box active","bboxInactive": "No bounding box","errorDecode": "The object preview could not be decoded.",@@ -1346,6 +1347,7 @@"includeCount": "Include · {{count}}","invert": "Invert","isolatedPreview": "Isolated Preview",+ "isolatedPreviewCompact": "Isolate","model": "Model","modelHuge": "SAM Huge","modelSam2Large": "SAM 2 Large",@@ -1362,6 +1364,8 @@"saveAs_inpaint_mask": "Inpaint mask","saveAs_raster": "Raster layer","saveAs_regional_guidance": "Regional guidance",+ "sourceDimensions": "{{width}} × {{height}}",+ "sourceDimensionsLabel": "Generation area: {{width}} × {{height}}","statusCommitting": "Applying object result…","statusError": "Select Object needs attention.","statusPreparingComposite": "Preparing canvas composite…",@@ -1370,6 +1374,7 @@"statusRenderingPreview": "Rendering object preview…","statusScheduled": "Waiting to process object…","statusUploading": "Uploading canvas composite…",+ "technicalDetails": "Technical details","title": "Select Object","visual": "Visual","visualGuidance": "Click to add · drag to move · Shift flips type"diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/CanvasOperationPanel.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/CanvasOperationPanel.test.tsxindex 7c8cddfa52..90b8d59291 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/CanvasOperationPanel.test.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/CanvasOperationPanel.test.tsx@@ -68,7 +68,7 @@ describe('CanvasOperationPanel', () => {w: '26.25rem',});expect(CANVAS_OPERATION_PANEL_LAYOUT.w).toBe('30rem');- expect(CANVAS_SELECT_OBJECT_SLOT_LAYOUT).toMatchObject({ px: '4', py: '3' });+ expect(CANVAS_SELECT_OBJECT_SLOT_LAYOUT).toMatchObject({ px: '3', py: '2' });});it('keeps vertical overflow on the body while fixed sections retain their order', () => {diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/CanvasOperationPanel.tsx b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/CanvasOperationPanel.tsxindex d52f611401..3188a1d8d2 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/CanvasOperationPanel.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/CanvasOperationPanel.tsx@@ -27,8 +27,8 @@ export const CANVAS_SELECT_OBJECT_PANEL_LAYOUT = {} satisfies BoxProps;export const CANVAS_SELECT_OBJECT_SLOT_LAYOUT = {- px: '4',- py: '3',+ px: '3',+ py: '2',} satisfies BoxProps;export const CANVAS_OPERATION_FOOTER_LAYOUT = {diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/SamOptions.test.ts b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/SamOptions.test.tsindex 4631124ce8..def0579e8e 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/SamOptions.test.ts+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/SamOptions.test.ts@@ -3,21 +3,28 @@ import type { ComponentProps } from 'react';import { ChakraProvider } from '@chakra-ui/react';import { system } from '@theme/system';+import { createInstance } from 'i18next';import { createElement } from 'react';import { renderToStaticMarkup } from 'react-dom/server';-import { describe, expect, it } from 'vitest';+import { I18nextProvider } from 'react-i18next';+import { describe, expect, it, vi } from 'vitest';import {getSamPanelViewModel,getSamActionEligibility,+ getSamActionHandlers,getSamErrorTranslationKey,getSamStatusTranslationKey,+ SAM_COMPACT_BUTTON_LAYOUT,SAM_COMPACT_CONTROL_LAYOUT,SAM_COMPACT_FOOTER_LAYOUT,+ SAM_COMPACT_GROUP_LAYOUT,SAM_MODEL_SELECT_LAYOUT,SamPromptBody,SamModeToggle,+ SamOptionsPanel,SamProcessFeedback,+ SamSwitch,SamVisualBody,} from './SamOptions';@@ -25,9 +32,18 @@ const englishCatalogModules = import.meta.glob('../../../../../public/locales/eneager: true,import: 'default',});-const en = Object.values(englishCatalogModules)[0] as {+const enCatalog = Object.values(englishCatalogModules)[0] as {+ common: Record<string, string>;widgets: { layers: { selectObject: Record<string, string> } };};+const en = enCatalog;+const testI18n = createInstance();+await testI18n.init({+ initImmediate: false,+ lng: 'en',+ resources: { en: { translation: enCatalog } },+ showSupportNotice: false,+});const snapshot = (overrides: Partial<SamSessionSnapshot> = {}): SamSessionSnapshot => ({applyPolygonRefinement: false,@@ -130,23 +146,30 @@ describe('getSamPanelViewModel', () => {},sourceRect: { height: 768, width: 1024, x: 64, y: 32 },}),- (width, height) => `Área de generación ${width} por ${height}`+ (width, height) => `Área de generación ${width} por ${height}`,+ (width, height) => `Generation area ${width} by ${height}`)).toEqual({bboxActive: true,excludeCount: 1,includeCount: 2,+ sourceLabel: 'Generation area 1024 by 768',sourceSummary: 'Área de generación 1024 por 768',});});it('returns zero visual counts for prompt mode', () => {expect(- getSamPanelViewModel(snapshot({ input: { prompt: 'cat', type: 'prompt' } }), (w, h) => `${w} × ${h}`)+ getSamPanelViewModel(+ snapshot({ input: { prompt: 'cat', type: 'prompt' } }),+ (w, h) => `${w} × ${h}`,+ (w, h) => `Generation area ${w} × ${h}`+ )).toEqual({bboxActive: false,excludeCount: 0,includeCount: 0,+ sourceLabel: 'Generation area 20 × 20',sourceSummary: '20 × 20',});});@@ -154,11 +177,32 @@ describe('getSamPanelViewModel', () => {describe('SamModeToggle', () => {it('uses compact controls and wraps only when the card runs out of inline space', () => {- expect(SAM_COMPACT_CONTROL_LAYOUT).toEqual({ h: '8', minH: '8', size: 'sm' });- expect(SAM_COMPACT_FOOTER_LAYOUT).toMatchObject({ flexWrap: 'wrap', gap: '2' });+ expect(SAM_COMPACT_CONTROL_LAYOUT).toEqual({ h: '8', minH: '8', size: 'xs' });+ expect(SAM_COMPACT_BUTTON_LAYOUT).toEqual({ h: '8', minH: '8', px: '2', size: 'xs' });+ expect(SAM_COMPACT_FOOTER_LAYOUT).toMatchObject({ flexWrap: 'wrap', gap: '1' });+ expect(SAM_COMPACT_GROUP_LAYOUT).toEqual({ maxW: 'full', minW: '0' });expect(SAM_MODEL_SELECT_LAYOUT).toEqual({ flex: '0 1 11rem', maxW: 'full', minW: '0', w: '11rem' });});+ it('renders compact switch copy with the full localized accessible name', () => {+ const markup = renderToStaticMarkup(+ createElement(+ ChakraProvider,+ { value: system } as ComponentProps<typeof ChakraProvider>,+ createElement(SamSwitch, {+ accessibleLabel: 'Auto Process',+ checked: false,+ disabled: false,+ label: 'Auto',+ onChange: () => undefined,+ })+ )+ );++ expect(markup).toContain('>Auto<');+ expect(markup).toContain('aria-label="Auto Process"');+ });+it('uses ordinary pressed buttons without incomplete tab relationships', () => {const markup = renderToStaticMarkup(createElement(@@ -229,6 +273,7 @@ describe('SamProcessFeedback', () => {errorText: null,isBusy: true,statusText: 'Rendering object preview…',+ technicalDetailsLabel: 'Technical details',})));@@ -246,6 +291,7 @@ describe('SamProcessFeedback', () => {errorText: null,isBusy: false,statusText: 'Ready',+ technicalDetailsLabel: 'Technical details',}));@@ -254,12 +300,17 @@ describe('SamProcessFeedback', () => {it('server-renders a known localized error as the assertive primary message', () => {const markup = renderToStaticMarkup(- createElement(SamProcessFeedback, {- error: { code: 'decode' },- errorText: 'The object preview could not be decoded.',- isBusy: false,- statusText: 'Select Object needs attention.',- })+ createElement(+ ChakraProvider,+ { value: system } as ComponentProps<typeof ChakraProvider>,+ createElement(SamProcessFeedback, {+ error: { code: 'decode' },+ errorText: 'The object preview could not be decoded.',+ isBusy: false,+ statusText: 'Select Object needs attention.',+ technicalDetailsLabel: 'Technical details',+ })+ ));expect(markup).toContain('role="alert"');@@ -269,15 +320,23 @@ describe('SamProcessFeedback', () => {it('server-renders unknown diagnostics only after a localized primary message', () => {const markup = renderToStaticMarkup(- createElement(SamProcessFeedback, {- error: { code: 'unknown', detail: 'GPU worker disconnected' },- errorText: 'Select Object could not finish.',- isBusy: false,- statusText: 'Select Object needs attention.',- })+ createElement(+ ChakraProvider,+ { value: system } as ComponentProps<typeof ChakraProvider>,+ createElement(SamProcessFeedback, {+ error: { code: 'unknown', detail: 'GPU worker disconnected' },+ errorText: 'Select Object could not finish.',+ isBusy: false,+ statusText: 'Select Object needs attention.',+ technicalDetailsLabel: 'Technical details',+ })+ ));- expect(markup).toContain('title="GPU worker disconnected"');+ expect(markup).not.toContain('title=');+ expect(markup).toContain('aria-label="Technical details"');+ expect(markup).toContain('tabindex="0"');+ expect(markup).toContain('data-scope="tooltip"');expect(markup).not.toContain('>GPU worker disconnected<');expect(markup).toContain('role="alert"');});@@ -285,15 +344,22 @@ describe('SamProcessFeedback', () => {it('server-renders a localized queue error before its backend exception type', () => {const errorText = en.widgets.layers.selectObject.errorQueue;const markup = renderToStaticMarkup(- createElement(SamProcessFeedback, {- error: { code: 'queue', detail: 'AttributeError' },- errorText,- isBusy: false,- statusText: 'Select Object needs attention.',- })+ createElement(+ ChakraProvider,+ { value: system } as ComponentProps<typeof ChakraProvider>,+ createElement(SamProcessFeedback, {+ error: { code: 'queue', detail: 'AttributeError' },+ errorText,+ isBusy: false,+ statusText: 'Select Object needs attention.',+ technicalDetailsLabel: 'Technical details',+ })+ ));- expect(markup).toContain('title="AttributeError"');+ expect(markup).not.toContain('title=');+ expect(markup).toContain('aria-label="Technical details"');+ expect(markup).toContain('data-scope="tooltip"');expect(markup).not.toContain('>AttributeError<');expect(markup).toContain('role="alert"');});@@ -303,6 +369,11 @@ describe('compact SAM inputs', () => {it('uses compact model-row copy without the removed stacked section heading', () => {expect(en.widgets.layers.selectObject.model).toBe('Model');expect(en.widgets.layers.selectObject.refine).toBe('Refine');+ expect(en.widgets.layers.selectObject.autoProcessCompact).toBe('Auto');+ expect(en.widgets.layers.selectObject.isolatedPreviewCompact).toBe('Isolate');+ expect(en.widgets.layers.selectObject.technicalDetails).toBe('Technical details');+ expect(en.widgets.layers.selectObject.sourceDimensions).toBe('{{width}} × {{height}}');+ expect(en.widgets.layers.selectObject.sourceDimensionsLabel).toContain('{{width}}');expect(en.widgets.layers.selectObject).not.toHaveProperty('modelAndRefinement');expect(en.widgets.layers.selectObject).not.toHaveProperty('sourceSummary');});@@ -318,6 +389,8 @@ describe('compact SAM inputs', () => {expect(markup).toContain('<input');expect(markup).toContain('aria-label=');+ expect(markup).toContain('aria-describedby="sam-prompt-guidance"');+ expect(markup).toContain('id="sam-prompt-guidance"');expect(markup).toContain('placeholder=');expect(markup).not.toContain('<textarea');});@@ -342,15 +415,87 @@ describe('compact SAM inputs', () => {session: session as SamSessionSnapshot & {input: Extract<SamSessionSnapshot['input'], { type: 'visual' }>;},- viewModel: getSamPanelViewModel(session, (width, height) => `${width} × ${height}`),+ viewModel: getSamPanelViewModel(+ session,+ (width, height) => `${width} × ${height}`,+ (width, height) => `Generation area ${width} × ${height}`+ ),})));expect(markup).toContain('role="group"');expect(markup).toContain('aria-pressed="true"');- expect(markup).toContain('title=');+ expect(markup).not.toContain('title=');+ expect(markup).toContain('aria-describedby="sam-visual-guidance"');+ expect(markup).toContain('id="sam-visual-guidance"');expect(markup).not.toContain('>widgets.layers.selectObject.pointType<');- expect(markup).not.toContain('widgets.layers.selectObject.visualGuidance</');+ });+});++describe('getSamActionHandlers', () => {+ it('wires every compact footer action and save target to the engine', () => {+ const engine = {+ applySelectObjectSession: vi.fn(),+ cancelSelectObjectSession: vi.fn(),+ processSelectObjectSession: vi.fn(),+ resetSelectObjectSession: vi.fn(),+ saveSelectObjectSession: vi.fn(),+ };+ const actions = getSamActionHandlers(engine as never);++ actions.process();+ actions.apply();+ actions.reset();+ actions.save('control');+ actions.cancel();++ expect(engine.processSelectObjectSession).toHaveBeenCalledOnce();+ expect(engine.applySelectObjectSession).toHaveBeenCalledOnce();+ expect(engine.resetSelectObjectSession).toHaveBeenCalledOnce();+ expect(engine.saveSelectObjectSession).toHaveBeenCalledWith('control', expect.any(Function));+ expect(engine.cancelSelectObjectSession).toHaveBeenCalledOnce();+ });+});++describe('SamOptionsPanel', () => {+ it('server-renders the compact ready state in semantic order with one footer action row', () => {+ const engine = {+ applySelectObjectSession: vi.fn(),+ cancelSelectObjectSession: vi.fn(),+ processSelectObjectSession: vi.fn(),+ resetSelectObjectSession: vi.fn(),+ saveSelectObjectSession: vi.fn(),+ updateSelectObjectSession: vi.fn(),+ };+ const markup = renderToStaticMarkup(+ createElement(+ ChakraProvider,+ { value: system } as ComponentProps<typeof ChakraProvider>,+ createElement(+ I18nextProvider,+ { i18n: testI18n },+ createElement(SamOptionsPanel, {+ engine: engine as never,+ session: snapshot({+ hasPreview: true,+ input: { bbox: null, excludePoints: [], includePoints: [{ x: 4, y: 5 }], type: 'visual' },+ sourceRect: { height: 768, width: 1024, x: 0, y: 0 },+ }),+ })+ )+ )+ );++ expect(markup.indexOf('data-slot="header"')).toBeLessThan(markup.indexOf('data-slot="body"'));+ expect(markup.indexOf('data-slot="body"')).toBeLessThan(markup.indexOf('data-slot="footer"'));+ expect(markup).not.toContain('data-slot="feedback"');+ expect(markup).toContain('>Auto<');+ expect(markup).toContain('>Isolate<');+ expect(markup).toContain('aria-label="Generation area: 1024 × 768"');+ expect(markup.indexOf('>Process<')).toBeLessThan(markup.indexOf('>Apply<'));+ expect(markup.indexOf('>Apply<')).toBeLessThan(markup.indexOf('>Reset<'));+ expect(markup.indexOf('>Reset<')).toBeLessThan(markup.indexOf('Save As'));+ expect(markup.indexOf('Save As')).toBeLessThan(markup.indexOf('>Cancel<'));});});diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/SamOptions.tsx b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/SamOptions.tsxindex cd0ffb27aa..e7d63c30f2 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/SamOptions.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/SamOptions.tsx@@ -9,6 +9,7 @@ import {Flex,Group,Heading,+ IconButton,Input,Menu,NativeSelect,@@ -17,12 +18,13 @@ import {Stack,Switch,Text,+ VisuallyHidden,} from '@chakra-ui/react';-import { Button, MenuContent } from '@workbench/components/ui';+import { Button, MenuContent, Tooltip } from '@workbench/components/ui';import { makeImageDurable } from '@workbench/gallery/api';import { isSamDocumentInputValid } from '@workbench/generation/canvas/samGraph';import { useSamSession } from '@workbench/widgets/canvas/engineStoreHooks';-import { ChevronDownIcon } from 'lucide-react';+import { ChevronDownIcon, InfoIcon } from 'lucide-react';import { useTranslation } from 'react-i18next';import type { ToolOptionsComponentProps } from './ToolOptionsBar';@@ -42,13 +44,26 @@ export interface SamPanelViewModel {bboxActive: boolean;excludeCount: number;includeCount: number;+ sourceLabel: string;sourceSummary: string;}-export const SAM_COMPACT_CONTROL_LAYOUT = { h: '8', minH: '8', size: 'sm' } as const;-export const SAM_COMPACT_FOOTER_LAYOUT = { flexWrap: 'wrap', gap: '2' } satisfies FlexProps;+export const SAM_COMPACT_CONTROL_LAYOUT = { h: '8', minH: '8', size: 'xs' } as const;+export const SAM_COMPACT_BUTTON_LAYOUT = { ...SAM_COMPACT_CONTROL_LAYOUT, px: '2' } as const;+export const SAM_COMPACT_FOOTER_LAYOUT = { flexWrap: 'wrap', gap: '1' } satisfies FlexProps;+export const SAM_COMPACT_GROUP_LAYOUT = { maxW: 'full', minW: '0' } as const;export const SAM_MODEL_SELECT_LAYOUT = { flex: '0 1 11rem', maxW: 'full', minW: '0', w: '11rem' } as const;+const SAM_SEGMENT_BUTTON_LAYOUT = {+ ...SAM_COMPACT_BUTTON_LAYOUT,+ flex: '1 1 0',+ minW: '0',+ overflow: 'hidden',+} as const;++const SAM_PROMPT_GUIDANCE_ID = 'sam-prompt-guidance';+const SAM_VISUAL_GUIDANCE_ID = 'sam-visual-guidance';+const SAM_STATUS_TRANSLATION_KEYS: Record<SamSessionSnapshot['status'], string> = {committing: 'widgets.layers.selectObject.statusCommitting',error: 'widgets.layers.selectObject.statusError',@@ -83,11 +98,13 @@ export const getSamErrorTranslationKey = (code: SamSessionErrorCode): string =>export const getSamPanelViewModel = (session: SamSessionSnapshot,- formatSourceSummary: (width: number, height: number) => string+ formatSourceSummary: (width: number, height: number) => string,+ formatSourceLabel: (width: number, height: number) => string): SamPanelViewModel => ({bboxActive: session.input.type === 'visual' && session.input.bbox !== null,excludeCount: session.input.type === 'visual' ? session.input.excludePoints.length : 0,includeCount: session.input.type === 'visual' ? session.input.includePoints.length : 0,+ sourceLabel: formatSourceLabel(session.sourceRect.width, session.sourceRect.height),sourceSummary: formatSourceSummary(session.sourceRect.width, session.sourceRect.height),});@@ -96,23 +113,33 @@ export const SamProcessFeedback = ({errorText,isBusy,statusText,+ technicalDetailsLabel,}: {error: SamSessionError | null;errorText: string | null;isBusy: boolean;statusText: string;+ technicalDetailsLabel: string;}) => {const detail = error?.detail?.trim();if (error && errorText) {return (- <span- aria-live="assertive"- role="alert"- style={{ WebkitBoxOrient: 'vertical', WebkitLineClamp: 2, display: '-webkit-box', overflow: 'hidden' }}- title={detail && detail !== errorText ? detail : undefined}- >- {errorText}- </span>+ <Flex align="center" gap="1" minW="0">+ <span+ aria-live="assertive"+ role="alert"+ style={{ WebkitBoxOrient: 'vertical', WebkitLineClamp: 2, display: '-webkit-box', overflow: 'hidden' }}+ >+ {errorText}+ </span>+ {detail && detail !== errorText ? (+ <Tooltip content={detail}>+ <IconButton aria-label={technicalDetailsLabel} flexShrink="0" size="xs" tabIndex={0} variant="ghost">+ <InfoIcon />+ </IconButton>+ </Tooltip>+ ) : null}+ </Flex>);}if (isBusy) {@@ -126,6 +153,14 @@ export const SamProcessFeedback = ({return null;};+export const getSamActionHandlers = (engine: ToolOptionsComponentProps['engine']) => ({+ apply: () => void engine.applySelectObjectSession(),+ cancel: () => engine.cancelSelectObjectSession(),+ process: () => void engine.processSelectObjectSession(),+ reset: () => engine.resetSelectObjectSession(),+ save: (target: SelectObjectSaveTarget) => void engine.saveSelectObjectSession(target, makeImageDurable),+});+export const getSamActionEligibility = (session: SamSessionSnapshot,isExternalInteractionLocked = false@@ -147,29 +182,36 @@ export const getSamActionEligibility = (};};-const SamSwitch = ({+export const SamSwitch = ({+ accessibleLabel,checked,disabled,label,onChange,}: {+ accessibleLabel: string;checked: boolean;disabled?: boolean;label: string;onChange(checked: boolean): void;}) => (- <Switch.Root- checked={checked}- disabled={disabled}- {...SAM_COMPACT_CONTROL_LAYOUT}- onCheckedChange={({ checked: next }) => onChange(next)}- >- <Switch.HiddenInput />- <Switch.Control>- <Switch.Thumb />- </Switch.Control>- <Switch.Label fontSize="xs">{label}</Switch.Label>- </Switch.Root>+ <Tooltip content={accessibleLabel}>+ <Switch.Root+ checked={checked}+ disabled={disabled}+ minW="0"+ {...SAM_COMPACT_CONTROL_LAYOUT}+ onCheckedChange={({ checked: next }) => onChange(next)}+ >+ <Switch.HiddenInput aria-label={accessibleLabel} />+ <Switch.Control flexShrink="0">+ <Switch.Thumb />+ </Switch.Control>+ <Switch.Label fontSize="xs" whiteSpace="nowrap">+ {label}+ </Switch.Label>+ </Switch.Root>+ </Tooltip>);export const SamModeToggle = ({@@ -189,11 +231,11 @@ export const SamModeToggle = ({promptLabel: string;visualLabel: string;}) => (- <Group aria-label={groupLabel} attached role="group">+ <Group aria-label={groupLabel} attached flex="1 1 10rem" role="group" {...SAM_COMPACT_GROUP_LAYOUT}><Buttonaria-pressed={mode === 'visual'}disabled={disabled}- {...SAM_COMPACT_CONTROL_LAYOUT}+ {...SAM_SEGMENT_BUTTON_LAYOUT}variant={mode === 'visual' ? 'solid' : 'ghost'}onClick={onVisual}>@@ -202,7 +244,7 @@ export const SamModeToggle = ({<Buttonaria-pressed={mode === 'prompt'}disabled={disabled}- {...SAM_COMPACT_CONTROL_LAYOUT}+ {...SAM_SEGMENT_BUTTON_LAYOUT}variant={mode === 'prompt' ? 'solid' : 'ghost'}onClick={onPrompt}>@@ -228,37 +270,38 @@ export const SamVisualBody = ({return (<Flexalign="center"+ aria-describedby={SAM_VISUAL_GUIDANCE_ID}aria-label={t('widgets.layers.selectObject.pointType')}flexWrap="wrap"gap="2"role="group"- title={t('widgets.layers.selectObject.visualGuidance')}>- <Group attached>+ <VisuallyHidden id={SAM_VISUAL_GUIDANCE_ID}>{t('widgets.layers.selectObject.visualGuidance')}</VisuallyHidden>+ <Group attached flex="1 1 10rem" {...SAM_COMPACT_GROUP_LAYOUT}><Buttonaria-pressed={session.pointLabel === 'include'}disabled={disabled}- {...SAM_COMPACT_CONTROL_LAYOUT}+ {...SAM_SEGMENT_BUTTON_LAYOUT}variant={session.pointLabel === 'include' ? 'solid' : 'outline'}onClick={onInclude}>- <Text as="span" fontVariantNumeric="tabular-nums">+ <Text as="span" fontVariantNumeric="tabular-nums" overflow="hidden" textOverflow="ellipsis">{t('widgets.layers.selectObject.includeCount', { count: viewModel.includeCount })}</Text></Button><Buttonaria-pressed={session.pointLabel === 'exclude'}disabled={disabled}- {...SAM_COMPACT_CONTROL_LAYOUT}+ {...SAM_SEGMENT_BUTTON_LAYOUT}variant={session.pointLabel === 'exclude' ? 'solid' : 'outline'}onClick={onExclude}>- <Text as="span" fontVariantNumeric="tabular-nums">+ <Text as="span" fontVariantNumeric="tabular-nums" overflow="hidden" textOverflow="ellipsis">{t('widgets.layers.selectObject.excludeCount', { count: viewModel.excludeCount })}</Text></Button></Group>- <Text color={viewModel.bboxActive ? 'fg' : 'fg.muted'} fontSize="xs" fontWeight="medium">+ <Text color={viewModel.bboxActive ? 'fg' : 'fg.muted'} flex="0 1 auto" fontSize="xs" fontWeight="medium" minW="0">{viewModel.bboxActive? t('widgets.layers.selectObject.bboxActive'): t('widgets.layers.selectObject.bboxInactive')}@@ -278,47 +321,56 @@ export const SamPromptBody = ({}) => {const { t } = useTranslation();return (- <Input- aria-label={t('widgets.layers.selectObject.prompt')}- autoComplete="off"- disabled={disabled}- placeholder={t('widgets.layers.selectObject.promptGuidance')}- value={prompt}- {...SAM_COMPACT_CONTROL_LAYOUT}- onChange={onChange}- />+ <>+ <Input+ aria-describedby={SAM_PROMPT_GUIDANCE_ID}+ aria-label={t('widgets.layers.selectObject.prompt')}+ autoComplete="off"+ disabled={disabled}+ minW="0"+ placeholder={t('widgets.layers.selectObject.promptGuidance')}+ value={prompt}+ {...SAM_COMPACT_CONTROL_LAYOUT}+ onChange={onChange}+ />+ <VisuallyHidden id={SAM_PROMPT_GUIDANCE_ID}>{t('widgets.layers.selectObject.promptGuidance')}</VisuallyHidden>+ </>);};const SamSaveItem = ({disabled,- engine,+ onSave,target,-}: ToolOptionsComponentProps & { disabled: boolean; target: SelectObjectSaveTarget }) => {+}: {+ disabled: boolean;+ onSave(target: SelectObjectSaveTarget): void;+ target: SelectObjectSaveTarget;+}) => {const { t } = useTranslation();return (- <Menu.Item- disabled={disabled}- value={target}- onClick={() => void engine.saveSelectObjectSession(target, makeImageDurable)}- >+ <Menu.Item disabled={disabled} value={target} onClick={() => onSave(target)}><Menu.ItemText>{t(`widgets.layers.selectObject.saveAs_${target}`)}</Menu.ItemText></Menu.Item>);};-export const SamOptions = ({+export const SamOptionsPanel = ({engine,+ session,isExternalInteractionLocked = false,-}: ToolOptionsComponentProps & { isExternalInteractionLocked?: boolean }) => {+}: ToolOptionsComponentProps & {+ isExternalInteractionLocked?: boolean;+ session: SamSessionSnapshot;+}) => {const { t } = useTranslation();- const session = useSamSession(engine);- if (!session) {- return null;- }-const eligibility = getSamActionEligibility(session, isExternalInteractionLocked);- const viewModel = getSamPanelViewModel(session, (width, height) => `${width} × ${height}`);+ const viewModel = getSamPanelViewModel(+ session,+ (width, height) => t('widgets.layers.selectObject.sourceDimensions', { height, width }),+ (width, height) => t('widgets.layers.selectObject.sourceDimensionsLabel', { height, width })+ );+ const actions = getSamActionHandlers(engine);const isProcessing =session.status === 'preparing-composite' ||session.status === 'uploading' ||@@ -330,34 +382,42 @@ export const SamOptions = ({return (<CanvasOperationPanel.Root aria-labelledby="sam-operation-title" operation="select-object"><CanvasOperationPanel.Header>- <Flex align="center" flexWrap="wrap" gap="3" justify="space-between">- <Flex align="baseline" gap="2" minW="0">- <Heading fontSize="md" id="sam-operation-title">+ <Flex align="center" flexWrap="wrap" gap="2" justify="space-between">+ <Flex align="baseline" gap="1" minW="0">+ <Heading fontSize="sm" id="sam-operation-title" whiteSpace="nowrap">{t('widgets.layers.selectObject.title')}</Heading>- <Text color="fg.muted" fontSize="xs" fontVariantNumeric="tabular-nums" whiteSpace="nowrap">+ <Text+ aria-label={viewModel.sourceLabel}+ color="fg.muted"+ fontSize="xs"+ fontVariantNumeric="tabular-nums"+ whiteSpace="nowrap"+ >{viewModel.sourceSummary}</Text></Flex>- <Flex align="center" flexWrap="wrap" gap="3">+ <Flex align="center" flexWrap="wrap" gap="2" minW="0"><SamSwitch+ accessibleLabel={t('widgets.layers.selectObject.autoProcess')}checked={session.autoProcess}disabled={!eligibility.canEditInputs}- label={t('widgets.layers.selectObject.autoProcess')}+ label={t('widgets.layers.selectObject.autoProcessCompact')}onChange={(value) => setBoolean('autoProcess', value)}/><SamSwitch+ accessibleLabel={t('widgets.layers.selectObject.isolatedPreview')}checked={session.isolatedPreview}disabled={!eligibility.canEditInputs}- label={t('widgets.layers.selectObject.isolatedPreview')}+ label={t('widgets.layers.selectObject.isolatedPreviewCompact')}onChange={(value) => setBoolean('isolatedPreview', value)}/></Flex></Flex></CanvasOperationPanel.Header><CanvasOperationPanel.Body>- <Stack gap="3">- <Flex align="center" gap="2" justify="space-between">+ <Stack gap="2">+ <Flex align="center" flexWrap="wrap" gap="1" justify="space-between" minW="0"><SamModeToggledisabled={!eligibility.canEditInputs}groupLabel={t('widgets.layers.selectObject.mode')}@@ -372,6 +432,7 @@ export const SamOptions = ({}/><SamSwitch+ accessibleLabel={t('widgets.layers.selectObject.invert')}checked={session.invert}disabled={!eligibility.canEditInputs}label={t('widgets.layers.selectObject.invert')}@@ -395,7 +456,7 @@ export const SamOptions = ({}/>)}- <Flex align="center" flexWrap="wrap" gap="2">+ <Flex align="center" flexWrap="wrap" gap="1" minW="0"><Text asChild fontSize="xs" fontWeight="semibold"><label htmlFor="sam-model">{t('widgets.layers.selectObject.model')}</label></Text>@@ -416,6 +477,7 @@ export const SamOptions = ({<NativeSelect.Indicator /></NativeSelect.Root><SamSwitch+ accessibleLabel={t('widgets.layers.selectObject.refine')}checked={session.applyPolygonRefinement}disabled={isProcessing || !eligibility.canEditInputs}label={t('widgets.layers.selectObject.refine')}@@ -431,6 +493,7 @@ export const SamOptions = ({errorText={session.error ? t(getSamErrorTranslationKey(session.error.code)) : null}isBusy={!session.error}statusText={t(getSamStatusTranslationKey(session.status))}+ technicalDetailsLabel={t('widgets.layers.selectObject.technicalDetails')}/></CanvasOperationPanel.Feedback>) : null}@@ -438,30 +501,25 @@ export const SamOptions = ({<Buttondisabled={!eligibility.canProcess}loading={isProcessing}- {...SAM_COMPACT_CONTROL_LAYOUT}- onClick={() => void engine.processSelectObjectSession()}+ {...SAM_COMPACT_BUTTON_LAYOUT}+ onClick={actions.process}>{t('widgets.layers.selectObject.process')}</Button><ButtoncolorPalette="accent"disabled={!eligibility.canApply}- {...SAM_COMPACT_CONTROL_LAYOUT}- onClick={() => void engine.applySelectObjectSession()}+ {...SAM_COMPACT_BUTTON_LAYOUT}+ onClick={actions.apply}>{t('common.apply')}</Button>- <Button- disabled={!eligibility.canReset}- variant="ghost"- {...SAM_COMPACT_CONTROL_LAYOUT}- onClick={() => engine.resetSelectObjectSession()}- >+ <Button disabled={!eligibility.canReset} variant="ghost" {...SAM_COMPACT_BUTTON_LAYOUT} onClick={actions.reset}>{t('widgets.layers.selectObject.reset')}</Button><Menu.Root><Menu.Trigger asChild>- <Button disabled={!eligibility.canSave} variant="outline" {...SAM_COMPACT_CONTROL_LAYOUT}>+ <Button disabled={!eligibility.canSave} variant="outline" {...SAM_COMPACT_BUTTON_LAYOUT}>{t('widgets.layers.selectObject.saveAs')} <ChevronDownIcon size={14} /></Button></Menu.Trigger>@@ -469,7 +527,7 @@ export const SamOptions = ({<Menu.Positioner><MenuContent minW="11rem" py="1">{SAVE_TARGETS.map((target) => (- <SamSaveItem key={target} disabled={!eligibility.canSave} engine={engine} target={target} />+ <SamSaveItem key={target} disabled={!eligibility.canSave} target={target} onSave={actions.save} />))}</MenuContent></Menu.Positioner>@@ -478,8 +536,8 @@ export const SamOptions = ({<Buttondisabled={!eligibility.canCancel}variant="ghost"- {...SAM_COMPACT_CONTROL_LAYOUT}- onClick={() => engine.cancelSelectObjectSession()}+ {...SAM_COMPACT_BUTTON_LAYOUT}+ onClick={actions.cancel}>{t('common.cancel')}</Button>@@ -487,3 +545,16 @@ export const SamOptions = ({</CanvasOperationPanel.Root>);};++export const SamOptions = ({+ engine,+ isExternalInteractionLocked = false,+}: ToolOptionsComponentProps & { isExternalInteractionLocked?: boolean }) => {+ const session = useSamSession(engine);+ if (!session) {+ return null;+ }+ return (+ <SamOptionsPanel engine={engine} isExternalInteractionLocked={isExternalInteractionLocked} session={session} />+ );+};