Skip to content

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.

feat(properties): object-tool forms with edit-target chips (U1)

Josh Corbettfb1272e9fbf5
diff --git a/invokeai/frontend/webv2/performance/browser-baseline.json b/invokeai/frontend/webv2/performance/browser-baseline.json
index f046bd57d2..04acd3439a 100644
--- a/invokeai/frontend/webv2/performance/browser-baseline.json
+++ b/invokeai/frontend/webv2/performance/browser-baseline.json
@@ -25,13 +25,13 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 113,
+ "domContentLoadedMedianMs": 117.29999999701977,
"id": "launchpad",
"layoutAckMedianMs": 0,
"layoutReturnSwitchMedianMs": 0,
"layoutSwitchMedianMs": 0,
- "loadMedianMs": 113.1000000089407,
- "longestTaskMaxMs": 67,
+ "loadMedianMs": 117.40000000596046,
+ "longestTaskMaxMs": 80,
"owner": "app",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:launchpad",
@@ -41,24 +41,24 @@
"fontRawBytes": 23664,
"imageRawBytes": 0,
"largestAssetRawBytes": 746376,
- "otherRawBytes": 161115,
+ "otherRawBytes": 161604,
"requestCount": 38,
"scriptRawBytes": 1636198,
"scriptRequestCount": 34,
- "totalRawBytes": 1823136
+ "totalRawBytes": 1823625
},
"resourceLimits": {
"cssRawBytes": 2181,
"fontRawBytes": 23901,
"imageRawBytes": 0,
"largestAssetRawBytes": 753840,
- "otherRawBytes": 162727,
+ "otherRawBytes": 163221,
"requestCount": 38,
"scriptRawBytes": 1652560,
"scriptRequestCount": 34,
- "totalRawBytes": 1841368
+ "totalRawBytes": 1841862
},
- "routeReadyMedianMs": 252.40000000596046,
+ "routeReadyMedianMs": 261.29999999701977,
"scriptSourceOwnerSet": "launchpad-static",
"stateProfile": "empty"
},
@@ -85,13 +85,13 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 115.20000000298023,
+ "domContentLoadedMedianMs": 116,
"id": "launchpad",
"layoutAckMedianMs": 0,
"layoutReturnSwitchMedianMs": 0,
"layoutSwitchMedianMs": 0,
- "loadMedianMs": 115.3999999910593,
- "longestTaskMaxMs": 68,
+ "loadMedianMs": 116.09999999403954,
+ "longestTaskMaxMs": 70,
"owner": "app",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:launchpad",
@@ -101,24 +101,24 @@
"fontRawBytes": 23664,
"imageRawBytes": 0,
"largestAssetRawBytes": 746376,
- "otherRawBytes": 161115,
+ "otherRawBytes": 161604,
"requestCount": 38,
"scriptRawBytes": 1636198,
"scriptRequestCount": 34,
- "totalRawBytes": 1823136
+ "totalRawBytes": 1823625
},
"resourceLimits": {
"cssRawBytes": 2181,
"fontRawBytes": 23901,
"imageRawBytes": 0,
"largestAssetRawBytes": 753840,
- "otherRawBytes": 162727,
+ "otherRawBytes": 163221,
"requestCount": 38,
"scriptRawBytes": 1652560,
"scriptRequestCount": 34,
- "totalRawBytes": 1841368
+ "totalRawBytes": 1841862
},
- "routeReadyMedianMs": 274.29999999701977,
+ "routeReadyMedianMs": 279,
"scriptSourceOwnerSet": "launchpad-static",
"stateProfile": "representative"
},
@@ -145,15 +145,15 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 118,
+ "domContentLoadedMedianMs": 116.70000000298023,
"id": "editor-minimal",
"layoutAckMedianMs": 0,
"layoutReturnSwitchMedianMs": 0,
"layoutSwitchMedianMs": 0,
- "loadMedianMs": 118.20000000298023,
- "longestTaskMaxMs": 96,
+ "loadMedianMs": 116.70000000298023,
+ "longestTaskMaxMs": 97,
"owner": "workbench",
- "projectSwitchMedianMs": 34,
+ "projectSwitchMedianMs": 36.20000000298023,
"readyMark": "invokeai:ready:widget:center:preview",
"remediationTicket": "deepen-widget-registry-loading",
"resourceBaseline": {
@@ -161,24 +161,24 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 746376,
- "otherRawBytes": 161115,
+ "otherRawBytes": 161604,
"requestCount": 115,
"scriptRawBytes": 3286480,
"scriptRequestCount": 110,
- "totalRawBytes": 3629794
+ "totalRawBytes": 3630283
},
"resourceLimits": {
"cssRawBytes": 2181,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 753840,
- "otherRawBytes": 162727,
+ "otherRawBytes": 163221,
"requestCount": 115,
"scriptRawBytes": 3319345,
"scriptRequestCount": 110,
- "totalRawBytes": 3666092
+ "totalRawBytes": 3666586
},
- "routeReadyMedianMs": 666.8000000119209,
+ "routeReadyMedianMs": 667.0999999940395,
"scriptSourceOwnerSet": "editor-minimal-static",
"stateProfile": "empty"
},
@@ -205,15 +205,15 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 117.20000000298023,
+ "domContentLoadedMedianMs": 114.40000000596046,
"id": "editor-minimal",
"layoutAckMedianMs": 0,
"layoutReturnSwitchMedianMs": 0,
"layoutSwitchMedianMs": 0,
- "loadMedianMs": 117.30000001192093,
- "longestTaskMaxMs": 176,
+ "loadMedianMs": 114.6000000089407,
+ "longestTaskMaxMs": 178,
"owner": "workbench",
- "projectSwitchMedianMs": 67.29999999701977,
+ "projectSwitchMedianMs": 71.40000000596046,
"readyMark": "invokeai:ready:widget:center:preview",
"remediationTicket": "deepen-widget-registry-loading",
"resourceBaseline": {
@@ -221,24 +221,24 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 746376,
- "otherRawBytes": 161115,
+ "otherRawBytes": 161604,
"requestCount": 115,
"scriptRawBytes": 3286480,
"scriptRequestCount": 110,
- "totalRawBytes": 3629794
+ "totalRawBytes": 3630283
},
"resourceLimits": {
"cssRawBytes": 2181,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 753840,
- "otherRawBytes": 162727,
+ "otherRawBytes": 163221,
"requestCount": 115,
"scriptRawBytes": 3319345,
"scriptRequestCount": 110,
- "totalRawBytes": 3666092
+ "totalRawBytes": 3666586
},
- "routeReadyMedianMs": 433,
+ "routeReadyMedianMs": 445,
"scriptSourceOwnerSet": "editor-minimal-static",
"stateProfile": "representative"
},
@@ -247,31 +247,31 @@
"cssRawBytes": 0,
"fontRawBytes": 0,
"imageRawBytes": 0,
- "largestAssetRawBytes": 301354,
+ "largestAssetRawBytes": 313135,
"otherRawBytes": 0,
"requestCount": 7,
- "scriptRawBytes": 460979,
+ "scriptRawBytes": 472760,
"scriptRequestCount": 7,
- "totalRawBytes": 460979
+ "totalRawBytes": 472760
},
"activatedResourceLimits": {
"cssRawBytes": 0,
"fontRawBytes": 0,
"imageRawBytes": 0,
- "largestAssetRawBytes": 304368,
+ "largestAssetRawBytes": 316267,
"otherRawBytes": 0,
"requestCount": 7,
- "scriptRawBytes": 465589,
+ "scriptRawBytes": 477488,
"scriptRequestCount": 7,
- "totalRawBytes": 465589
+ "totalRawBytes": 477488
},
- "domContentLoadedMedianMs": 114.5,
+ "domContentLoadedMedianMs": 120.3999999910593,
"id": "editor-canvas",
- "layoutAckMedianMs": 2.6000000089406967,
- "layoutReturnSwitchMedianMs": 53.79999999701977,
- "layoutSwitchMedianMs": 94.90000000596046,
- "loadMedianMs": 114.5,
- "longestTaskMaxMs": 119,
+ "layoutAckMedianMs": 2.2000000029802322,
+ "layoutReturnSwitchMedianMs": 55,
+ "layoutSwitchMedianMs": 86.70000000298023,
+ "loadMedianMs": 120.59999999403954,
+ "longestTaskMaxMs": 124,
"owner": "canvas",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:canvas",
@@ -281,24 +281,24 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 746376,
- "otherRawBytes": 161115,
+ "otherRawBytes": 161604,
"requestCount": 122,
- "scriptRawBytes": 3747459,
+ "scriptRawBytes": 3759240,
"scriptRequestCount": 117,
- "totalRawBytes": 4090773
+ "totalRawBytes": 4103043
},
"resourceLimits": {
"cssRawBytes": 2181,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 753840,
- "otherRawBytes": 162727,
+ "otherRawBytes": 163221,
"requestCount": 122,
- "scriptRawBytes": 3784934,
+ "scriptRawBytes": 3796833,
"scriptRequestCount": 117,
- "totalRawBytes": 4131681
+ "totalRawBytes": 4144074
},
- "routeReadyMedianMs": 1050.6000000089407,
+ "routeReadyMedianMs": 1056.2999999970198,
"scriptSourceOwnerSet": "editor-canvas-static",
"stateProfile": "empty"
},
@@ -307,31 +307,31 @@
"cssRawBytes": 0,
"fontRawBytes": 0,
"imageRawBytes": 0,
- "largestAssetRawBytes": 301354,
+ "largestAssetRawBytes": 313135,
"otherRawBytes": 0,
"requestCount": 7,
- "scriptRawBytes": 460979,
+ "scriptRawBytes": 472760,
"scriptRequestCount": 7,
- "totalRawBytes": 460979
+ "totalRawBytes": 472760
},
"activatedResourceLimits": {
"cssRawBytes": 0,
"fontRawBytes": 0,
"imageRawBytes": 0,
- "largestAssetRawBytes": 304368,
+ "largestAssetRawBytes": 316267,
"otherRawBytes": 0,
"requestCount": 7,
- "scriptRawBytes": 465589,
+ "scriptRawBytes": 477488,
"scriptRequestCount": 7,
- "totalRawBytes": 465589
+ "totalRawBytes": 477488
},
- "domContentLoadedMedianMs": 113.90000000596046,
+ "domContentLoadedMedianMs": 114.90000000596046,
"id": "editor-canvas",
- "layoutAckMedianMs": 2.5999999940395355,
- "layoutReturnSwitchMedianMs": 44,
- "layoutSwitchMedianMs": 93.3999999910593,
- "loadMedianMs": 114,
- "longestTaskMaxMs": 176,
+ "layoutAckMedianMs": 2.5,
+ "layoutReturnSwitchMedianMs": 45.70000000298023,
+ "layoutSwitchMedianMs": 83.5,
+ "loadMedianMs": 115,
+ "longestTaskMaxMs": 182,
"owner": "canvas",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:canvas",
@@ -341,24 +341,24 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 746376,
- "otherRawBytes": 161115,
+ "otherRawBytes": 161604,
"requestCount": 122,
- "scriptRawBytes": 3747459,
+ "scriptRawBytes": 3759240,
"scriptRequestCount": 117,
- "totalRawBytes": 4090773
+ "totalRawBytes": 4103043
},
"resourceLimits": {
"cssRawBytes": 2181,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 753840,
- "otherRawBytes": 162727,
+ "otherRawBytes": 163221,
"requestCount": 122,
- "scriptRawBytes": 3784934,
+ "scriptRawBytes": 3796833,
"scriptRequestCount": 117,
- "totalRawBytes": 4131681
+ "totalRawBytes": 4144074
},
- "routeReadyMedianMs": 1143.1000000089407,
+ "routeReadyMedianMs": 1137.5,
"scriptSourceOwnerSet": "editor-canvas-static",
"stateProfile": "representative"
},
@@ -385,13 +385,13 @@
"scriptRequestCount": 6,
"totalRawBytes": 383447
},
- "domContentLoadedMedianMs": 113.5,
+ "domContentLoadedMedianMs": 115,
"id": "editor-workflow",
- "layoutAckMedianMs": 2.3999999910593033,
- "layoutReturnSwitchMedianMs": 32.5,
- "layoutSwitchMedianMs": 91.3999999910593,
- "loadMedianMs": 113.70000000298023,
- "longestTaskMaxMs": 96,
+ "layoutAckMedianMs": 2.2000000029802322,
+ "layoutReturnSwitchMedianMs": 33.6000000089407,
+ "layoutSwitchMedianMs": 91.6000000089407,
+ "loadMedianMs": 115,
+ "longestTaskMaxMs": 97,
"owner": "workflow",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:workflow",
@@ -401,24 +401,24 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 746376,
- "otherRawBytes": 161115,
+ "otherRawBytes": 161604,
"requestCount": 122,
"scriptRawBytes": 3650717,
"scriptRequestCount": 116,
- "totalRawBytes": 4009444
+ "totalRawBytes": 4009933
},
"resourceLimits": {
"cssRawBytes": 17748,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 753840,
- "otherRawBytes": 162727,
+ "otherRawBytes": 163221,
"requestCount": 122,
"scriptRawBytes": 3687225,
"scriptRequestCount": 116,
- "totalRawBytes": 4049539
+ "totalRawBytes": 4050033
},
- "routeReadyMedianMs": 1054.199999988079,
+ "routeReadyMedianMs": 1042,
"scriptSourceOwnerSet": "editor-workflow-static",
"stateProfile": "empty"
},
@@ -445,13 +445,13 @@
"scriptRequestCount": 6,
"totalRawBytes": 383447
},
- "domContentLoadedMedianMs": 114.90000000596046,
+ "domContentLoadedMedianMs": 114.80000001192093,
"id": "editor-workflow",
- "layoutAckMedianMs": 2.6000000089406967,
- "layoutReturnSwitchMedianMs": 38.79999999701977,
- "layoutSwitchMedianMs": 124.70000000298023,
- "loadMedianMs": 115,
- "longestTaskMaxMs": 333,
+ "layoutAckMedianMs": 2.5999999940395355,
+ "layoutReturnSwitchMedianMs": 40.3999999910593,
+ "layoutSwitchMedianMs": 122.40000000596046,
+ "loadMedianMs": 114.80000001192093,
+ "longestTaskMaxMs": 343,
"owner": "workflow",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:workflow",
@@ -461,24 +461,24 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 746376,
- "otherRawBytes": 161115,
+ "otherRawBytes": 161604,
"requestCount": 122,
"scriptRawBytes": 3650717,
"scriptRequestCount": 116,
- "totalRawBytes": 4009444
+ "totalRawBytes": 4009933
},
"resourceLimits": {
"cssRawBytes": 17748,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 753840,
- "otherRawBytes": 162727,
+ "otherRawBytes": 163221,
"requestCount": 122,
"scriptRawBytes": 3687225,
"scriptRequestCount": 116,
- "totalRawBytes": 4049539
+ "totalRawBytes": 4050033
},
- "routeReadyMedianMs": 1174.5,
+ "routeReadyMedianMs": 1184.300000011921,
"scriptSourceOwnerSet": "editor-workflow-static",
"stateProfile": "representative"
},
@@ -505,13 +505,13 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 113.20000000298023,
+ "domContentLoadedMedianMs": 117.59999999403954,
"id": "editor-gallery",
"layoutAckMedianMs": 0,
"layoutReturnSwitchMedianMs": 0,
- "layoutSwitchMedianMs": 23.900000005960464,
- "loadMedianMs": 113.29999999701977,
- "longestTaskMaxMs": 94,
+ "layoutSwitchMedianMs": 26.799999997019768,
+ "loadMedianMs": 117.79999999701977,
+ "longestTaskMaxMs": 95,
"owner": "gallery",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:gallery",
@@ -521,24 +521,24 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 746376,
- "otherRawBytes": 161115,
+ "otherRawBytes": 161604,
"requestCount": 115,
"scriptRawBytes": 3286480,
"scriptRequestCount": 110,
- "totalRawBytes": 3629794
+ "totalRawBytes": 3630283
},
"resourceLimits": {
"cssRawBytes": 2181,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 753840,
- "otherRawBytes": 162727,
+ "otherRawBytes": 163221,
"requestCount": 115,
"scriptRawBytes": 3319345,
"scriptRequestCount": 110,
- "totalRawBytes": 3666092
+ "totalRawBytes": 3666586
},
- "routeReadyMedianMs": 1254.5,
+ "routeReadyMedianMs": 1267.9000000059605,
"scriptSourceOwnerSet": "editor-minimal-static",
"stateProfile": "empty"
},
@@ -565,13 +565,13 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 115.29999999701977,
+ "domContentLoadedMedianMs": 116.6000000089407,
"id": "editor-gallery",
"layoutAckMedianMs": 0,
"layoutReturnSwitchMedianMs": 0,
- "layoutSwitchMedianMs": 85.09999999403954,
- "loadMedianMs": 115.5,
- "longestTaskMaxMs": 178,
+ "layoutSwitchMedianMs": 88.5,
+ "loadMedianMs": 116.70000000298023,
+ "longestTaskMaxMs": 174,
"owner": "gallery",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:gallery",
@@ -581,24 +581,24 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 746376,
- "otherRawBytes": 161115,
+ "otherRawBytes": 161604,
"requestCount": 115,
"scriptRawBytes": 3286480,
"scriptRequestCount": 110,
- "totalRawBytes": 3629794
+ "totalRawBytes": 3630283
},
"resourceLimits": {
"cssRawBytes": 2181,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 753840,
- "otherRawBytes": 162727,
+ "otherRawBytes": 163221,
"requestCount": 115,
"scriptRawBytes": 3319345,
"scriptRequestCount": 110,
- "totalRawBytes": 3666092
+ "totalRawBytes": 3666586
},
- "routeReadyMedianMs": 1426.5,
+ "routeReadyMedianMs": 1447.1000000089407,
"scriptSourceOwnerSet": "editor-minimal-static",
"stateProfile": "representative"
}
@@ -2837,6 +2837,7 @@
"source:src/workbench/widgets/canvas/tool-options/ShapeOptions.tsx",
"source:src/workbench/widgets/canvas/tool-options/TextOptions.tsx",
"source:src/workbench/widgets/canvas/tool-options/TransformOptions.tsx",
+ "source:src/workbench/widgets/canvas/tool-options/gradientStops.ts",
"source:src/workbench/widgets/canvas/tool-options/paintForm.tsx",
"source:src/workbench/widgets/canvas/tool-options/useBboxEditor.ts",
"source:src/workbench/widgets/canvas/tool-presentation/PropertyPrimitives.tsx",
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.json
index 8b81893bf1..ac94beb327 100644
--- a/invokeai/frontend/webv2/public/locales/en.json
+++ b/invokeai/frontend/webv2/public/locales/en.json
@@ -1526,15 +1526,35 @@
"noCanvas": "Open a canvas to edit its properties.",
"groups": {
"stroke": "Stroke",
- "dynamics": "Dynamics"
+ "dynamics": "Dynamics",
+ "shape": "Shape",
+ "gradient": "Gradient",
+ "stops": "Stops",
+ "font": "Font",
+ "paragraph": "Paragraph"
},
"foreground": "Foreground",
+ "target": {
+ "defaults": "Defaults",
+ "editing": "Editing: {{name}}",
+ "newText": "New text"
+ },
"rows": {
"color": "Color",
"geometry": "Geometry",
"intensity": "Intensity",
"modes": "Modes",
- "more": "More"
+ "more": "More",
+ "kind": "Kind",
+ "width": "Width",
+ "angle": "Angle",
+ "stop": "Stop",
+ "offset": "Offset",
+ "family": "Family",
+ "size": "Size",
+ "weight": "Weight",
+ "lineHeight": "Leading",
+ "align": "Align"
},
"sections": {
"operation": "Operation",
@@ -2405,11 +2425,12 @@
"frameWidth": "W",
"gradientAngle": "Angle",
"gradientEdit": "Edit gradient",
- "gradientEnd": "End",
- "gradientKind": "Gradient type",
"gradientLinear": "Linear",
"gradientRadial": "Radial",
- "gradientStart": "Start",
+ "gradientAddStop": "Add stop",
+ "gradientRemoveStop": "Remove stop",
+ "gradientStopAt": "Gradient stop at {{percent}}%",
+ "gradientStopColor": "Stop color",
"gradientStops": "Stops",
"invertSelection": "Invert",
"lassoFreehand": "Freehand",
@@ -2436,12 +2457,10 @@
"selectionReplace": "Replace",
"selectionSubtract": "Subtract",
"setFrame": "Set generation frame",
- "shapeColors": "Colors",
"shapeEdit": "Edit shape",
"shapeEllipse": "Ellipse",
"shapeFill": "Fill",
"shapeHint": "Drag to draw a shape.",
- "shapeKind": "Shape type",
"shapeRect": "Rectangle",
"shapeStroke": "Stroke",
"shapeStrokeWidth": "Stroke width",
@@ -2454,7 +2473,6 @@
"textFont": "Font",
"textLineHeight": "Line height",
"textSize": "Font size",
- "textStyle": "Style",
"textWeight": "Weight",
"gradientPairPreset": "Foreground to background preset"
},
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/GradientOptions.tsx b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/GradientOptions.tsx
index bd75f398f1..dc1adc19d6 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/GradientOptions.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/GradientOptions.tsx
@@ -1,42 +1,51 @@
-import type { SelectValueChangeDetails } from '@chakra-ui/react';
import type { CanvasLayerSourceContract, GradientStop, GradientToolOptions } from '@workbench/canvas-engine/api';
import type {
ToolbarRegionProps,
- ToolPresentationAdapter,
+ ToolPropertyForm,
} from '@workbench/widgets/canvas/tool-presentation/toolbarContracts';
+import type { KeyboardEvent, PointerEvent as ReactPointerEvent } from 'react';
-import { createListCollection } from '@chakra-ui/react';
-import { ToggleIconButton } from '@platform/ui/Button';
+import { Box, chakra, Flex, IconButton as ChakraIconButton, Icon } from '@chakra-ui/react';
import { ColorPicker } from '@platform/ui/ColorPicker';
-import { Select } from '@platform/ui/Select';
import { getDocumentLayer } from '@workbench/canvas-engine/api';
import { useActiveColorPair } from '@workbench/widgets/canvas/color-system/useActiveColors';
import { useGradientOptions } from '@workbench/widgets/canvas/engineStoreHooks';
-import { ToolbarNumberField, useNumberCommit } from '@workbench/widgets/canvas/tool-presentation/ToolbarPrimitives';
+import {
+ EditTargetChip,
+ PropertyControlRow,
+ PropertySegmentedRow,
+ PropertySwitchRow,
+} from '@workbench/widgets/canvas/tool-presentation/PropertyPrimitives';
+import {
+ ToolbarNumberField,
+ ToolbarSlider,
+ useNumberCommit,
+ useSliderGesture,
+} from '@workbench/widgets/canvas/tool-presentation/ToolbarPrimitives';
import { useColorSampler } from '@workbench/widgets/canvas/useColorSampler';
import { usePreparedCommit } from '@workbench/widgets/canvas/useStructuralCommit';
import { useActiveProjectSelector } from '@workbench/WorkbenchContext';
-import { PaletteIcon } from 'lucide-react';
-import { useCallback, useMemo } from 'react';
+import { PlusIcon, Trash2Icon } from 'lucide-react';
+import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
+import { insertStopAt, moveStop, recolorStop, removeStop, stopsToCssGradient } from './gradientStops';
+
type GradientSource = Extract<CanvasLayerSourceContract, { type: 'gradient' }>;
type GradientKind = GradientToolOptions['kind'];
interface SelectedGradient {
id: string;
+ name: string;
source: GradientSource;
}
-const SELECT_POSITIONING = { placement: 'bottom-start', sameWidth: false } as const;
-const SELECT_TRIGGER_PROPS = { minW: '6rem', w: '6rem' } as const;
-
/**
- * Kind, angle and a minimal two-stop editor. Displayed values follow the
- * selected gradient layer, else the tool defaults — where the built-in FG→BG
- * preset shows the live pair (resolved for real at gesture start) and editing
- * a stop switches to explicit custom stops, independent of later pair edits.
- * Edits commit to a selected gradient layer (colors once on release).
+ * Kind, angle and the stop strip. Displayed values follow the selected
+ * gradient layer, else the tool defaults — where the built-in FG→BG preset
+ * shows the live pair (resolved for real at gesture start) and editing a stop
+ * switches to explicit custom stops, independent of later pair edits. Edits
+ * commit to a selected gradient layer (stop gestures once on release).
*/
const useGradientEditor = (engine: ToolbarRegionProps['engine']) => {
const { t } = useTranslation();
@@ -48,10 +57,10 @@ const useGradientEditor = (engine: ToolbarRegionProps['engine']) => {
const { document } = project.canvas;
const layer = document.selectedLayerId ? getDocumentLayer(document, document.selectedLayerId) : undefined;
return layer && layer.type === 'raster' && layer.source.type === 'gradient'
- ? { id: layer.id, source: layer.source }
+ ? { id: layer.id, name: layer.name, source: layer.source }
: null;
},
- (a, b) => a?.id === b?.id && a?.source === b?.source
+ (a, b) => a?.id === b?.id && a?.name === b?.name && a?.source === b?.source
);
const kind: GradientKind = selected ? selected.source.kind : options.kind;
const angle = selected ? selected.source.angle : options.angle;
@@ -84,7 +93,7 @@ const useGradientEditor = (engine: ToolbarRegionProps['engine']) => {
);
const setPreset = useCallback(
(preset: 'pair' | 'custom') => {
- // Leaving the preset keeps what the chips currently show as the custom set.
+ // Leaving the preset keeps what the strip currently shows as the custom set.
engine.interaction.set('gradientOptions', {
...options,
preset,
@@ -94,136 +103,412 @@ const useGradientEditor = (engine: ToolbarRegionProps['engine']) => {
},
[engine, options, pairStops]
);
- return { angle, apply, kind, preset: selected ? null : options.preset, setCustomStops, setPreset, stops };
+ /** Routes a settled stop list to its owner: the selected layer (one entry) or the custom defaults. */
+ const commitStops = useCallback(
+ (nextStops: GradientStop[]) => {
+ if (selected) {
+ apply({ angle, kind, stops: nextStops }, true);
+ return;
+ }
+ setCustomStops(nextStops);
+ },
+ [angle, apply, kind, selected, setCustomStops]
+ );
+ return {
+ angle,
+ apply,
+ commitStops,
+ kind,
+ preset: selected ? null : options.preset,
+ selectedName: selected?.name ?? null,
+ setPreset,
+ stops,
+ };
};
-const GradientAngle = ({ engine }: ToolbarRegionProps) => {
+const STRIP_CHECKER = 'repeating-conic-gradient(#00000022 0% 25%, transparent 0% 50%) 0 0 / 10px 10px';
+
+/**
+ * The stop strip: a ramp with draggable stop handles. Click an empty spot to
+ * add a stop with the ramp's color there; drag or arrow-key a handle to move
+ * it. Gestures preview locally and commit once on release, so a selected
+ * gradient records one history entry per gesture.
+ */
+const GradientStopStrip = ({
+ onCommit,
+ onSelect,
+ selectedIndex,
+ stops,
+}: {
+ onCommit: (stops: GradientStop[]) => void;
+ onSelect: (index: number) => void;
+ selectedIndex: number;
+ stops: readonly GradientStop[];
+}) => {
const { t } = useTranslation();
- const { angle, apply, kind, stops } = useGradientEditor(engine);
- const onCommit = useNumberCommit(
- useCallback(
- (value: number) => apply({ angle: Math.round(value), kind, stops: [...stops] }, true),
- [apply, kind, stops]
- )
+ const rampRef = useRef<HTMLDivElement | null>(null);
+ const [draft, setDraft] = useState<GradientStop[] | null>(null);
+ const dragIndex = useRef<number>(-1);
+ const shown = draft ?? stops;
+
+ const offsetFromClientX = useCallback((clientX: number): number => {
+ const rect = rampRef.current?.getBoundingClientRect();
+ if (!rect || rect.width <= 0) {
+ return 0;
+ }
+ return Math.min(1, Math.max(0, (clientX - rect.left) / rect.width));
+ }, []);
+
+ const onRampPointerDown = useCallback(
+ (event: ReactPointerEvent<HTMLDivElement>) => {
+ if (event.target !== rampRef.current) {
+ return;
+ }
+ const { index, stops: next } = insertStopAt(stops, offsetFromClientX(event.clientX));
+ onCommit(next);
+ onSelect(index);
+ },
+ [offsetFromClientX, onCommit, onSelect, stops]
);
+
+ const onDragStart = useCallback((index: number) => {
+ dragIndex.current = index;
+ }, []);
+ const onDragMove = useCallback(
+ (clientX: number) => {
+ if (dragIndex.current < 0) {
+ return;
+ }
+ // The base index stays fixed while the gesture runs; only the draft shows the reorder.
+ setDraft(moveStop(stops, dragIndex.current, offsetFromClientX(clientX)).stops);
+ },
+ [offsetFromClientX, stops]
+ );
+ const onDragEnd = useCallback(
+ (clientX: number) => {
+ if (dragIndex.current < 0) {
+ return;
+ }
+ const settled = moveStop(stops, dragIndex.current, offsetFromClientX(clientX));
+ dragIndex.current = -1;
+ setDraft(null);
+ onCommit(settled.stops);
+ onSelect(settled.index);
+ },
+ [offsetFromClientX, onCommit, onSelect, stops]
+ );
+ const rampStyle = useMemo(() => ({ background: `${stopsToCssGradient(shown)}, ${STRIP_CHECKER}` }), [shown]);
+ const rootRef = useRef<HTMLDivElement | null>(null);
+ const pendingFocus = useRef<number>(-1);
+ // A key-move can reorder past a neighbour, so the handle at the OLD index now
+ // renders a different stop; refocus the moved stop at its new index.
+ useEffect(() => {
+ if (pendingFocus.current < 0) {
+ return;
+ }
+ const handle = rootRef.current?.querySelector<HTMLButtonElement>(`[data-stop-index="${pendingFocus.current}"]`);
+ pendingFocus.current = -1;
+ handle?.focus();
+ });
+ const onKeyMove = useCallback(
+ (index: number, direction: -1 | 1, big: boolean) => {
+ const target = stops[index];
+ if (!target) {
+ return;
+ }
+ const moved = moveStop(stops, index, target.offset + direction * (big ? 0.1 : 0.01));
+ pendingFocus.current = moved.index;
+ onCommit(moved.stops);
+ onSelect(moved.index);
+ },
+ [onCommit, onSelect, stops]
+ );
+ const onDragCancel = useCallback(() => {
+ dragIndex.current = -1;
+ setDraft(null);
+ }, []);
+
return (
- <ToolbarNumberField
- aria-label={t('widgets.canvas.toolOptions.gradientAngle')}
- disabled={kind === 'radial'}
- max={360}
- min={-360}
- suffix="°"
- value={String(Math.round(angle))}
- onValueCommit={onCommit}
- />
+ <Box ref={rootRef} position="relative" py="1" w="full">
+ <Box
+ ref={rampRef}
+ aria-label={t('widgets.canvas.toolOptions.gradientStops')}
+ cursor="copy"
+ h="6"
+ role="img"
+ rounded="sm"
+ style={rampStyle}
+ w="full"
+ onPointerDown={onRampPointerDown}
+ />
+ {shown.map((stop, index) => (
+ <StopHandle
+ // Offsets can collide mid-drag, so position in the list is the identity.
+ // oxlint-disable-next-line react/no-array-index-key
+ key={index}
+ index={index}
+ selected={index === selectedIndex}
+ stop={stop}
+ onDragCancel={onDragCancel}
+ onDragEnd={onDragEnd}
+ onDragMove={onDragMove}
+ onDragStart={onDragStart}
+ onKeyMove={onKeyMove}
+ onSelect={onSelect}
+ />
+ ))}
+ </Box>
);
};
-const GradientKindSelect = ({ engine }: ToolbarRegionProps) => {
+const StopHandle = ({
+ index,
+ onDragCancel,
+ onDragEnd,
+ onDragMove,
+ onDragStart,
+ onKeyMove,
+ onSelect,
+ selected,
+ stop,
+}: {
+ index: number;
+ onDragCancel: () => void;
+ onDragEnd: (clientX: number) => void;
+ onDragMove: (clientX: number) => void;
+ onDragStart: (index: number) => void;
+ onKeyMove: (index: number, direction: -1 | 1, big: boolean) => void;
+ onSelect: (index: number) => void;
+ selected: boolean;
+ stop: GradientStop;
+}) => {
const { t } = useTranslation();
- const { angle, apply, kind, stops } = useGradientEditor(engine);
- const collection = useMemo(
- () =>
- createListCollection<{ label: string; value: GradientKind }>({
- items: [
- { label: t('widgets.canvas.toolOptions.gradientLinear'), value: 'linear' },
- { label: t('widgets.canvas.toolOptions.gradientRadial'), value: 'radial' },
- ],
- }),
- [t]
+ const onPointerDown = useCallback(
+ (event: ReactPointerEvent<HTMLButtonElement>) => {
+ event.preventDefault();
+ event.currentTarget.setPointerCapture(event.pointerId);
+ onDragStart(index);
+ onSelect(index);
+ },
+ [index, onDragStart, onSelect]
+ );
+ const onPointerMove = useCallback(
+ (event: ReactPointerEvent<HTMLButtonElement>) => onDragMove(event.clientX),
+ [onDragMove]
);
- const value = useMemo(() => [kind], [kind]);
- const onChange = useCallback(
- ({ value: next }: SelectValueChangeDetails<{ label: string; value: GradientKind }>) => {
- const kindNext = next[0] as GradientKind | undefined;
- if (kindNext && kindNext !== kind) {
- apply({ angle, kind: kindNext, stops: [...stops] }, true);
+ const onPointerUp = useCallback(
+ (event: ReactPointerEvent<HTMLButtonElement>) => onDragEnd(event.clientX),
+ [onDragEnd]
+ );
+ const onKeyDown = useCallback(
+ (event: KeyboardEvent<HTMLButtonElement>) => {
+ const direction = event.key === 'ArrowRight' ? 1 : event.key === 'ArrowLeft' ? -1 : 0;
+ if (direction === 0) {
+ return;
}
+ event.preventDefault();
+ onKeyMove(index, direction, event.shiftKey);
},
- [angle, apply, kind, stops]
+ [index, onKeyMove]
);
return (
- <Select
- aria-label={t('widgets.canvas.toolOptions.gradientKind')}
- collection={collection}
- positioning={SELECT_POSITIONING}
- size="xs"
- flexShrink={0}
- triggerProps={SELECT_TRIGGER_PROPS}
- w="6rem"
- value={value}
- valueText={t(
- kind === 'radial' ? 'widgets.canvas.toolOptions.gradientRadial' : 'widgets.canvas.toolOptions.gradientLinear'
- )}
- onValueChange={onChange}
+ <chakra.button
+ aria-label={t('widgets.canvas.toolOptions.gradientStopAt', { percent: Math.round(stop.offset * 100) })}
+ aria-pressed={selected}
+ bg={stop.color}
+ borderColor={selected ? 'fg' : 'border.emphasized'}
+ borderWidth="2px"
+ boxSize="3.5"
+ cursor="ew-resize"
+ left={`calc(${(stop.offset * 100).toFixed(2)}% - 7px)`}
+ position="absolute"
+ rounded="full"
+ top="50%"
+ transform="translateY(-50%)"
+ type="button"
+ data-stop-index={index}
+ onKeyDown={onKeyDown}
+ onPointerCancel={onDragCancel}
+ onPointerDown={onPointerDown}
+ onPointerMove={onPointerMove}
+ onPointerUp={onPointerUp}
/>
);
};
-const GradientStops = ({ engine }: ToolbarRegionProps) => {
+const GradientSettings = ({ engine }: ToolbarRegionProps) => {
const { t } = useTranslation();
- const { angle, apply, kind, preset, setCustomStops, setPreset, stops } = useGradientEditor(engine);
+ const editor = useGradientEditor(engine);
+ const kindOptions = useMemo(
+ () => [
+ { label: t('widgets.canvas.toolOptions.gradientLinear'), value: 'linear' as const },
+ { label: t('widgets.canvas.toolOptions.gradientRadial'), value: 'radial' as const },
+ ],
+ [t]
+ );
+ const setKind = useCallback(
+ (next: GradientKind) => editor.apply({ angle: editor.angle, kind: next, stops: [...editor.stops] }, true),
+ [editor]
+ );
+ // Ticks preview through the options store; ONE document commit lands on release.
+ const previewAngle = useCallback(
+ (value: number) => editor.apply({ angle: Math.round(value), kind: editor.kind, stops: [...editor.stops] }, false),
+ [editor]
+ );
+ const setAngle = useCallback(
+ (value: number) => editor.apply({ angle: Math.round(value), kind: editor.kind, stops: [...editor.stops] }, true),
+ [editor]
+ );
+ const angleGesture = useSliderGesture(Math.round(editor.angle), setAngle, previewAngle);
+ const onAngleCommit = useNumberCommit(setAngle);
+ return (
+ <>
+ <EditTargetChip layerName={editor.selectedName} />
+ <PropertySegmentedRow
+ label={t('widgets.properties.rows.kind')}
+ options={kindOptions}
+ value={editor.kind}
+ onValueChange={setKind}
+ />
+ <PropertyControlRow label={t('widgets.properties.rows.angle')}>
+ <ToolbarSlider
+ aria-label={t('widgets.canvas.toolOptions.gradientAngle')}
+ disabled={editor.kind === 'radial'}
+ max={360}
+ min={-360}
+ value={angleGesture.value}
+ onValueChange={angleGesture.onChange}
+ onValueChangeEnd={angleGesture.onChangeEnd}
+ />
+ <ToolbarNumberField
+ aria-label={t('widgets.canvas.toolOptions.gradientAngle')}
+ disabled={editor.kind === 'radial'}
+ max={360}
+ min={-360}
+ suffix="°"
+ value={String(Math.round(editor.angle))}
+ onValueCommit={onAngleCommit}
+ />
+ </PropertyControlRow>
+ </>
+ );
+};
+
+const GradientStopsSettings = ({ engine }: ToolbarRegionProps) => {
+ const { t } = useTranslation();
+ const editor = useGradientEditor(engine);
const sampleColor = useColorSampler(engine);
- const start = stops[0] ?? { color: '#000000ff', offset: 0 };
- const end = stops[stops.length - 1] ?? { color: '#ffffffff', offset: 1 };
- const setStop = useCallback(
- (index: number, color: string, commit: boolean) => {
- const nextStops = stops.map((stop, i) => (i === index ? { ...stop, color } : stop));
- if (preset === null) {
- // A selected gradient: explicit document stops, one entry on release.
- apply({ angle, kind, stops: nextStops }, commit);
- return;
+ const [selectedIndex, setSelectedIndex] = useState(0);
+ const stopCount = editor.stops.length;
+ const stop = editor.stops[Math.min(selectedIndex, stopCount - 1)] ?? null;
+ const stopIndex = Math.min(selectedIndex, stopCount - 1);
+
+ const onPresetToggle = useCallback((checked: boolean) => editor.setPreset(checked ? 'pair' : 'custom'), [editor]);
+ const onColorChange = useCallback(
+ (hex: string) => {
+ // Live color edits settle on release; the defaults' custom set is its own owner.
+ if (editor.preset !== null) {
+ editor.commitStops(recolorStop(editor.stops, stopIndex, hex));
}
- // No selection: stop edits make the custom set explicit.
- setCustomStops(nextStops);
},
- [angle, apply, kind, preset, setCustomStops, stops]
- );
- const onPresetToggle = useCallback((checked: boolean) => setPreset(checked ? 'pair' : 'custom'), [setPreset]);
- const last = stops.length - 1;
- const onStart = useCallback((color: string) => setStop(0, color, false), [setStop]);
- const onStartEnd = useCallback((color: string) => setStop(0, color, true), [setStop]);
- const onEnd = useCallback((color: string) => setStop(last, color, false), [last, setStop]);
- const onEndEnd = useCallback((color: string) => setStop(last, color, true), [last, setStop]);
+ [editor, stopIndex]
+ );
+ const onColorChangeEnd = useCallback(
+ (hex: string) => editor.commitStops(recolorStop(editor.stops, stopIndex, hex)),
+ [editor, stopIndex]
+ );
+ const setOffset = useCallback(
+ (value: number) => {
+ const moved = moveStop(editor.stops, stopIndex, value / 100);
+ editor.commitStops(moved.stops);
+ setSelectedIndex(moved.index);
+ },
+ [editor, stopIndex]
+ );
+ const onOffsetCommit = useNumberCommit(setOffset);
+ const onRemove = useCallback(() => {
+ editor.commitStops(removeStop(editor.stops, stopIndex));
+ setSelectedIndex(Math.max(0, stopIndex - 1));
+ }, [editor, stopIndex]);
+ // The keyboard path to what a ramp click does: a new stop halfway to the
+ // next one (or back toward the previous from the last stop).
+ const onAdd = useCallback(() => {
+ const current = editor.stops[stopIndex];
+ if (!current) {
+ return;
+ }
+ const neighbour = editor.stops[stopIndex + 1] ?? editor.stops[stopIndex - 1];
+ const at = neighbour ? (current.offset + neighbour.offset) / 2 : 0.5;
+ const inserted = insertStopAt(editor.stops, at);
+ editor.commitStops(inserted.stops);
+ setSelectedIndex(inserted.index);
+ }, [editor, stopIndex]);
+
return (
<>
- {/* Disabled, never removed, when a selected gradient owns the stops: the row keeps its geometry. */}
- <ToggleIconButton
- checked={preset === 'pair'}
- disabled={preset === null}
- icon={PaletteIcon}
- label={t('widgets.canvas.toolOptions.gradientPairPreset')}
- onCheckedChange={onPresetToggle}
- />
- <ColorPicker
- aria-label={t('widgets.canvas.toolOptions.gradientStart')}
- value={start.color}
- withAlpha
- onSampleColor={sampleColor}
- onValueChange={onStart}
- onValueChangeEnd={onStartEnd}
- />
- <ColorPicker
- aria-label={t('widgets.canvas.toolOptions.gradientEnd')}
- value={end.color}
- withAlpha
- onSampleColor={sampleColor}
- onValueChange={onEnd}
- onValueChangeEnd={onEndEnd}
+ {editor.preset !== null ? (
+ <PropertySwitchRow
+ checked={editor.preset === 'pair'}
+ label={t('widgets.canvas.toolOptions.gradientPairPreset')}
+ onCheckedChange={onPresetToggle}
+ />
+ ) : null}
+ <GradientStopStrip
+ selectedIndex={stopIndex}
+ stops={editor.stops}
+ onCommit={editor.commitStops}
+ onSelect={setSelectedIndex}
/>
+ {stop ? (
+ <PropertyControlRow label={t('widgets.properties.rows.stop')}>
+ <Flex align="center" gap="2" minW="0">
+ <ColorPicker
+ aria-label={t('widgets.canvas.toolOptions.gradientStopColor')}
+ value={stop.color}
+ withAlpha
+ onSampleColor={sampleColor}
+ onValueChange={onColorChange}
+ onValueChangeEnd={onColorChangeEnd}
+ />
+ <ToolbarNumberField
+ aria-label={t('widgets.properties.rows.offset')}
+ max={100}
+ min={0}
+ suffix="%"
+ value={String(Math.round(stop.offset * 100))}
+ onValueCommit={onOffsetCommit}
+ />
+ </Flex>
+ <Flex gap="0.5">
+ <ChakraIconButton
+ aria-label={t('widgets.canvas.toolOptions.gradientAddStop')}
+ size="2xs"
+ variant="ghost"
+ onClick={onAdd}
+ >
+ <Icon as={PlusIcon} boxSize="3.5" />
+ </ChakraIconButton>
+ <ChakraIconButton
+ aria-label={t('widgets.canvas.toolOptions.gradientRemoveStop')}
+ disabled={stopCount <= 2}
+ size="2xs"
+ variant="ghost"
+ onClick={onRemove}
+ >
+ <Icon as={Trash2Icon} boxSize="3.5" />
+ </ChakraIconButton>
+ </Flex>
+ </PropertyControlRow>
+ ) : null}
</>
);
};
-export const gradientAdapter: ToolPresentationAdapter = {
- rowLabels: {
- color: 'widgets.canvas.toolOptions.gradientStops',
- geometry: 'widgets.canvas.toolOptions.gradientAngle',
- modes: 'widgets.canvas.toolOptions.gradientKind',
- },
- color: GradientStops,
- geometry: GradientAngle,
+export const gradientForm: ToolPropertyForm = {
+ groups: [
+ { body: GradientSettings, id: 'gradient', labelKey: 'widgets.properties.groups.gradient' },
+ { body: GradientStopsSettings, id: 'gradient-stops', labelKey: 'widgets.properties.groups.stops' },
+ ],
id: 'gradient',
- modes: GradientKindSelect,
paintsLeaf: true,
};
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/ShapeOptions.tsx b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/ShapeOptions.tsx
index da6aa0fc03..73aec82041 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/ShapeOptions.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/ShapeOptions.tsx
@@ -1,21 +1,25 @@
-import type { SelectValueChangeDetails } from '@chakra-ui/react';
import type { CanvasLayerSourceContract, ShapeToolOptions } from '@workbench/canvas-engine/api';
import type {
ToolbarRegionProps,
- ToolPresentationAdapter,
+ ToolPropertyForm,
} from '@workbench/widgets/canvas/tool-presentation/toolbarContracts';
-import { createListCollection } from '@chakra-ui/react';
+import { Text } from '@chakra-ui/react';
import { ToggleIconButton } from '@platform/ui/Button';
import { ColorPicker } from '@platform/ui/ColorPicker';
-import { Select } from '@platform/ui/Select';
import { MAX_SHAPE_STROKE_WIDTH, getDocumentLayer } from '@workbench/canvas-engine/api';
import { useActiveColorCommands, useActiveColorPair } from '@workbench/widgets/canvas/color-system/useActiveColors';
import { useShapeOptions } from '@workbench/widgets/canvas/engineStoreHooks';
import {
- ToolbarHint,
+ EditTargetChip,
+ PropertyControlRow,
+ PropertySegmentedRow,
+} from '@workbench/widgets/canvas/tool-presentation/PropertyPrimitives';
+import {
ToolbarNumberField,
+ ToolbarSlider,
useNumberCommit,
+ useSliderGesture,
} from '@workbench/widgets/canvas/tool-presentation/ToolbarPrimitives';
import { useColorSampler } from '@workbench/widgets/canvas/useColorSampler';
import { usePreparedCommit } from '@workbench/widgets/canvas/useStructuralCommit';
@@ -29,12 +33,11 @@ type ShapeKind = ShapeToolOptions['kind'];
interface SelectedShape {
id: string;
+ name: string;
source: ShapeSource;
}
const FALLBACK_COLOR = '#000000';
-const SELECT_POSITIONING = { placement: 'bottom-start', sameWidth: false } as const;
-const SELECT_TRIGGER_PROPS = { minW: '6rem', w: '6rem' } as const;
/**
* Displayed values follow the selected shape layer, else the creation defaults
@@ -55,10 +58,10 @@ const useShapeEditor = (engine: ToolbarRegionProps['engine']) => {
const { document } = project.canvas;
const layer = document.selectedLayerId ? getDocumentLayer(document, document.selectedLayerId) : undefined;
return layer && layer.type === 'raster' && layer.source.type === 'shape'
- ? { id: layer.id, source: layer.source }
+ ? { id: layer.id, name: layer.name, source: layer.source }
: null;
},
- (a, b) => a?.id === b?.id && a?.source === b?.source
+ (a, b) => a?.id === b?.id && a?.name === b?.name && a?.source === b?.source
);
const kind: ShapeKind = selected ? (selected.source.kind === 'ellipse' ? 'ellipse' : 'rect') : options.kind;
const fill = selected ? selected.source.fill : options.fillEnabled ? pair.foreground : null;
@@ -90,6 +93,7 @@ const useShapeEditor = (engine: ToolbarRegionProps['engine']) => {
},
[commitSource, setOptions]
);
+ const previewStrokeWidth = useCallback((value: number) => setOptions({ strokeWidth: value }), [setOptions]);
const setStrokeWidth = useCallback(
(value: number) => {
setOptions({ strokeWidth: value });
@@ -138,9 +142,11 @@ const useShapeEditor = (engine: ToolbarRegionProps['engine']) => {
return {
fill,
kind,
+ selectedName: selected?.name ?? null,
setFillColor,
setFillEnabled,
setKind,
+ previewStrokeWidth,
setStrokeColor,
setStrokeEnabled,
setStrokeWidth,
@@ -149,123 +155,100 @@ const useShapeEditor = (engine: ToolbarRegionProps['engine']) => {
};
};
-const ShapeStrokeWidth = ({ engine }: ToolbarRegionProps) => {
+const ShapeSettings = ({ engine }: ToolbarRegionProps) => {
const { t } = useTranslation();
- const { setStrokeWidth, stroke, strokeWidth } = useShapeEditor(engine);
- const onCommit = useNumberCommit(
- useCallback((value: number) => setStrokeWidth(Math.max(0, Math.round(value))), [setStrokeWidth])
- );
- return (
- <ToolbarNumberField
- aria-label={t('widgets.canvas.toolOptions.shapeStrokeWidth')}
- disabled={stroke === null}
- max={MAX_SHAPE_STROKE_WIDTH}
- min={0}
- suffix="px"
- value={String(Math.round(strokeWidth))}
- onValueCommit={onCommit}
- />
- );
-};
-
-const ShapeModes = ({ engine }: ToolbarRegionProps) => {
- const { t } = useTranslation();
- const { fill, kind, setFillEnabled, setKind, setStrokeEnabled, stroke } = useShapeEditor(engine);
- const kindCollection = useMemo(
- () =>
- createListCollection<{ label: string; value: ShapeKind }>({
- items: [
- { label: t('widgets.canvas.toolOptions.shapeRect'), value: 'rect' },
- { label: t('widgets.canvas.toolOptions.shapeEllipse'), value: 'ellipse' },
- ],
- }),
+ const editor = useShapeEditor(engine);
+ const sampleColor = useColorSampler(engine);
+ const kindOptions = useMemo(
+ () => [
+ { label: t('widgets.canvas.toolOptions.shapeRect'), value: 'rect' as const },
+ { label: t('widgets.canvas.toolOptions.shapeEllipse'), value: 'ellipse' as const },
+ ],
[t]
);
- const kindValue = useMemo(() => [kind], [kind]);
- const onKindChange = useCallback(
- ({ value }: SelectValueChangeDetails<{ label: string; value: ShapeKind }>) => {
- const next = value[0] as ShapeKind | undefined;
- if (next && next !== kind) {
- setKind(next);
- }
- },
- [kind, setKind]
- );
- const onFillToggle = useCallback((checked: boolean) => setFillEnabled(checked), [setFillEnabled]);
- const onStrokeToggle = useCallback((checked: boolean) => setStrokeEnabled(checked), [setStrokeEnabled]);
- return (
- <>
- <Select
- aria-label={t('widgets.canvas.toolOptions.shapeKind')}
- collection={kindCollection}
- positioning={SELECT_POSITIONING}
- size="xs"
- flexShrink={0}
- triggerProps={SELECT_TRIGGER_PROPS}
- w="6rem"
- value={kindValue}
- valueText={t(
- kind === 'ellipse' ? 'widgets.canvas.toolOptions.shapeEllipse' : 'widgets.canvas.toolOptions.shapeRect'
- )}
- onValueChange={onKindChange}
- />
- <ToggleIconButton
- checked={fill !== null}
- icon={PaintBucketIcon}
- label={t('widgets.canvas.toolOptions.shapeFill')}
- onCheckedChange={onFillToggle}
- />
- <ToggleIconButton
- checked={stroke !== null}
- icon={SquareIcon}
- label={t('widgets.canvas.toolOptions.shapeStroke')}
- onCheckedChange={onStrokeToggle}
- />
- <ToolbarHint>{t('widgets.canvas.toolOptions.shapeHint')}</ToolbarHint>
- </>
+ const onFillChange = useCallback((hex: string) => editor.setFillColor(hex, false), [editor]);
+ const onFillChangeEnd = useCallback((hex: string) => editor.setFillColor(hex, true), [editor]);
+ const onStrokeChange = useCallback((hex: string) => editor.setStrokeColor(hex, false), [editor]);
+ const onStrokeChangeEnd = useCallback((hex: string) => editor.setStrokeColor(hex, true), [editor]);
+ // Slider ticks preview through the options store; ONE document commit lands on release.
+ const previewWidth = useCallback(
+ (value: number) => editor.previewStrokeWidth(Math.max(0, Math.round(value))),
+ [editor]
);
-};
-
-/** Fill and stroke chips; a `none` fill or stroke shows a disabled chip so the slots keep their place. */
-const ShapeColors = ({ engine }: ToolbarRegionProps) => {
- const { t } = useTranslation();
- const { fill, setFillColor, setStrokeColor, stroke } = useShapeEditor(engine);
- const sampleColor = useColorSampler(engine);
- const onFillChange = useCallback((hex: string) => setFillColor(hex, false), [setFillColor]);
- const onFillChangeEnd = useCallback((hex: string) => setFillColor(hex, true), [setFillColor]);
- const onStrokeChange = useCallback((hex: string) => setStrokeColor(hex, false), [setStrokeColor]);
- const onStrokeChangeEnd = useCallback((hex: string) => setStrokeColor(hex, true), [setStrokeColor]);
+ const setWidth = useCallback((value: number) => editor.setStrokeWidth(Math.max(0, Math.round(value))), [editor]);
+ const widthGesture = useSliderGesture(Math.round(editor.strokeWidth), setWidth, previewWidth);
+ const onWidthCommit = useNumberCommit(setWidth);
return (
<>
- <ColorPicker
- aria-label={t('widgets.canvas.toolOptions.shapeFill')}
- disabled={fill === null}
- value={fill ?? FALLBACK_COLOR}
- onSampleColor={sampleColor}
- onValueChange={onFillChange}
- onValueChangeEnd={onFillChangeEnd}
- />
- <ColorPicker
- aria-label={t('widgets.canvas.toolOptions.shapeStroke')}
- disabled={stroke === null}
- value={stroke ?? FALLBACK_COLOR}
- onSampleColor={sampleColor}
- onValueChange={onStrokeChange}
- onValueChangeEnd={onStrokeChangeEnd}
+ <EditTargetChip layerName={editor.selectedName} />
+ <PropertySegmentedRow
+ label={t('widgets.properties.rows.kind')}
+ options={kindOptions}
+ value={editor.kind}
+ onValueChange={editor.setKind}
/>
+ {/* The chip stays enabled-looking but inert when the slot is off; the toggle owns enablement. */}
+ <PropertyControlRow label={t('widgets.canvas.toolOptions.shapeFill')}>
+ <ColorPicker
+ aria-label={t('widgets.canvas.toolOptions.shapeFill')}
+ disabled={editor.fill === null}
+ value={editor.fill ?? FALLBACK_COLOR}
+ onSampleColor={sampleColor}
+ onValueChange={onFillChange}
+ onValueChangeEnd={onFillChangeEnd}
+ />
+ <ToggleIconButton
+ checked={editor.fill !== null}
+ icon={PaintBucketIcon}
+ label={t('widgets.canvas.toolOptions.shapeFill')}
+ onCheckedChange={editor.setFillEnabled}
+ />
+ </PropertyControlRow>
+ <PropertyControlRow label={t('widgets.canvas.toolOptions.shapeStroke')}>
+ <ColorPicker
+ aria-label={t('widgets.canvas.toolOptions.shapeStroke')}
+ disabled={editor.stroke === null}
+ value={editor.stroke ?? FALLBACK_COLOR}
+ onSampleColor={sampleColor}
+ onValueChange={onStrokeChange}
+ onValueChangeEnd={onStrokeChangeEnd}
+ />
+ <ToggleIconButton
+ checked={editor.stroke !== null}
+ icon={SquareIcon}
+ label={t('widgets.canvas.toolOptions.shapeStroke')}
+ onCheckedChange={editor.setStrokeEnabled}
+ />
+ </PropertyControlRow>
+ <PropertyControlRow label={t('widgets.properties.rows.width')}>
+ <ToolbarSlider
+ aria-label={t('widgets.canvas.toolOptions.shapeStrokeWidth')}
+ disabled={editor.stroke === null}
+ max={MAX_SHAPE_STROKE_WIDTH}
+ min={0}
+ value={widthGesture.value}
+ onValueChange={widthGesture.onChange}
+ onValueChangeEnd={widthGesture.onChangeEnd}
+ />
+ <ToolbarNumberField
+ aria-label={t('widgets.canvas.toolOptions.shapeStrokeWidth')}
+ disabled={editor.stroke === null}
+ max={MAX_SHAPE_STROKE_WIDTH}
+ min={0}
+ suffix="px"
+ value={String(Math.round(editor.strokeWidth))}
+ onValueCommit={onWidthCommit}
+ />
+ </PropertyControlRow>
+ <Text color="fg.muted" fontSize="2xs">
+ {t('widgets.canvas.toolOptions.shapeHint')}
+ </Text>
</>
);
};
-export const shapeAdapter: ToolPresentationAdapter = {
- rowLabels: {
- color: 'widgets.canvas.toolOptions.shapeColors',
- geometry: 'widgets.canvas.toolOptions.shapeStrokeWidth',
- modes: 'widgets.canvas.toolOptions.shapeKind',
- },
- color: ShapeColors,
- geometry: ShapeStrokeWidth,
+export const shapeForm: ToolPropertyForm = {
+ groups: [{ body: ShapeSettings, id: 'shape', labelKey: 'widgets.properties.groups.shape' }],
id: 'shape',
- modes: ShapeModes,
paintsLeaf: true,
};
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/TextOptions.tsx b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/TextOptions.tsx
index c8ca13317f..66c7994298 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/TextOptions.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/TextOptions.tsx
@@ -2,7 +2,7 @@ import type { SelectValueChangeDetails } from '@chakra-ui/react';
import type { CanvasLayerSourceContract, TextToolOptions } from '@workbench/canvas-engine/api';
import type {
ToolbarRegionProps,
- ToolPresentationAdapter,
+ ToolPropertyForm,
} from '@workbench/widgets/canvas/tool-presentation/toolbarContracts';
import { createListCollection, HStack } from '@chakra-ui/react';
@@ -18,7 +18,13 @@ import {
} from '@workbench/canvas-engine/api';
import { useActiveColorCommands, useActiveColorPair } from '@workbench/widgets/canvas/color-system/useActiveColors';
import { useTextEditSession, useTextOptions } from '@workbench/widgets/canvas/engineStoreHooks';
-import { ToolbarNumberField, useNumberCommit } from '@workbench/widgets/canvas/tool-presentation/ToolbarPrimitives';
+import { EditTargetChip, PropertyControlRow } from '@workbench/widgets/canvas/tool-presentation/PropertyPrimitives';
+import {
+ ToolbarNumberField,
+ ToolbarSlider,
+ useNumberCommit,
+ useSliderGesture,
+} from '@workbench/widgets/canvas/tool-presentation/ToolbarPrimitives';
import { useColorSampler } from '@workbench/widgets/canvas/useColorSampler';
import { usePreparedCommit } from '@workbench/widgets/canvas/useStructuralCommit';
import { useActiveProjectSelector } from '@workbench/WorkbenchContext';
@@ -31,11 +37,11 @@ type TextAlign = TextToolOptions['align'];
interface SelectedText {
id: string;
+ name: string;
source: TextSource;
}
const SELECT_POSITIONING = { placement: 'bottom-start', sameWidth: false } as const;
-const FAMILY_TRIGGER_PROPS = { minW: '7rem', w: '7rem' } as const;
const WEIGHT_TRIGGER_PROPS = { minW: '4.5rem', w: '4.5rem' } as const;
const ALIGN_ICONS: Record<TextAlign, typeof AlignLeftIcon> = {
@@ -97,10 +103,10 @@ const useTextEditor = (engine: ToolbarRegionProps['engine']) => {
const { document } = project.canvas;
const layer = document.selectedLayerId ? getDocumentLayer(document, document.selectedLayerId) : undefined;
return layer && layer.type === 'raster' && layer.source.type === 'text'
- ? { id: layer.id, source: layer.source }
+ ? { id: layer.id, name: layer.name, source: layer.source }
: null;
},
- (a, b) => a?.id === b?.id && a?.source === b?.source
+ (a, b) => a?.id === b?.id && a?.name === b?.name && a?.source === b?.source
);
const styleSource = session ? session.source : (selected?.source ?? null);
const align = styleSource?.align ?? options.align;
@@ -138,12 +144,22 @@ const useTextEditor = (engine: ToolbarRegionProps['engine']) => {
},
[align, colorCommands, commitPrepared, engine, fontFamily, fontSize, fontWeight, lineHeight, selected, session, t]
);
- return { active, applyEdit };
+ // The chip names what applyEdit actually writes: the SESSION when one is
+ // open (its layer's name, or the new-text placeholder in create mode), else
+ // the selected text layer, else the defaults.
+ const sessionLayerName = useActiveProjectSelector((project): string | null => {
+ if (!session?.layerId) {
+ return null;
+ }
+ return getDocumentLayer(project.canvas.document, session.layerId)?.name ?? null;
+ });
+ const targetName = session ? (sessionLayerName ?? t('widgets.properties.target.newText')) : (selected?.name ?? null);
+ return { active, applyEdit, targetName };
};
-const TextFamily = ({ engine }: ToolbarRegionProps) => {
+const TextFontSettings = ({ engine }: ToolbarRegionProps) => {
const { t } = useTranslation();
- const { active, applyEdit } = useTextEditor(engine);
+ const { active, applyEdit, targetName } = useTextEditor(engine);
const familyCollection = useMemo(
() => createListCollection<{ label: string; value: string }>({ items: [...TEXT_FONT_FAMILIES] }),
[]
@@ -162,25 +178,6 @@ const TextFamily = ({ engine }: ToolbarRegionProps) => {
},
[active.fontFamily, applyEdit]
);
- return (
- <Select
- aria-label={t('widgets.canvas.toolOptions.textFont')}
- collection={familyCollection}
- positioning={SELECT_POSITIONING}
- size="xs"
- flexShrink={0}
- triggerProps={FAMILY_TRIGGER_PROPS}
- w="7rem"
- value={familyValue}
- valueText={familyLabel}
- onValueChange={onFamily}
- />
- );
-};
-
-const TextStyle = ({ engine }: ToolbarRegionProps) => {
- const { t } = useTranslation();
- const { active, applyEdit } = useTextEditor(engine);
const weightCollection = useMemo(
() =>
createListCollection<{ label: string; value: string }>({
@@ -198,85 +195,140 @@ const TextStyle = ({ engine }: ToolbarRegionProps) => {
},
[active.fontWeight, applyEdit]
);
- const onSize = useNumberCommit(
- useCallback(
- (value: number) =>
- applyEdit({ fontSize: Math.min(MAX_TEXT_FONT_SIZE, Math.max(MIN_TEXT_FONT_SIZE, Math.round(value))) }, true),
- [applyEdit]
- )
+ // Ticks preview through the defaults/session; ONE document commit lands on release.
+ const previewSize = useCallback(
+ (value: number) =>
+ applyEdit({ fontSize: Math.min(MAX_TEXT_FONT_SIZE, Math.max(MIN_TEXT_FONT_SIZE, Math.round(value))) }, false),
+ [applyEdit]
);
- const onLineHeight = useNumberCommit(
- useCallback(
- (value: number) => applyEdit({ lineHeight: Math.max(0.5, Math.round(value * 10) / 10) }, true),
- [applyEdit]
- )
+ const setSize = useCallback(
+ (value: number) =>
+ applyEdit({ fontSize: Math.min(MAX_TEXT_FONT_SIZE, Math.max(MIN_TEXT_FONT_SIZE, Math.round(value))) }, true),
+ [applyEdit]
);
- const onAlign = useCallback((next: TextAlign) => applyEdit({ align: next }, true), [applyEdit]);
+ const sizeGesture = useSliderGesture(Math.round(active.fontSize), setSize, previewSize);
+ const onSize = useNumberCommit(setSize);
+ const previewLineHeight = useCallback(
+ (value: number) => applyEdit({ lineHeight: Math.max(0.5, Math.round(value * 10) / 10) }, false),
+ [applyEdit]
+ );
+ const setLineHeight = useCallback(
+ (value: number) => applyEdit({ lineHeight: Math.max(0.5, Math.round(value * 10) / 10) }, true),
+ [applyEdit]
+ );
+ const lineHeightGesture = useSliderGesture(active.lineHeight, setLineHeight, previewLineHeight);
+ const onLineHeight = useNumberCommit(setLineHeight);
return (
<>
- <ToolbarNumberField
- aria-label={t('widgets.canvas.toolOptions.textSize')}
- max={MAX_TEXT_FONT_SIZE}
- min={MIN_TEXT_FONT_SIZE}
- suffix="px"
- value={String(Math.round(active.fontSize))}
- onValueCommit={onSize}
- />
- <Select
- aria-label={t('widgets.canvas.toolOptions.textWeight')}
- collection={weightCollection}
- positioning={SELECT_POSITIONING}
- size="xs"
- flexShrink={0}
- triggerProps={WEIGHT_TRIGGER_PROPS}
- w="4.5rem"
- value={weightValue}
- valueText={String(active.fontWeight)}
- onValueChange={onWeight}
- />
- <ToolbarNumberField
- aria-label={t('widgets.canvas.toolOptions.textLineHeight')}
- max={4}
- min={0.5}
- step={0.1}
- value={active.lineHeight.toFixed(1)}
- onValueCommit={onLineHeight}
- />
+ <EditTargetChip layerName={targetName} />
+ <PropertyControlRow label={t('widgets.properties.rows.family')}>
+ <Select
+ aria-label={t('widgets.canvas.toolOptions.textFont')}
+ collection={familyCollection}
+ gridColumn="2 / -1"
+ positioning={SELECT_POSITIONING}
+ size="xs"
+ value={familyValue}
+ valueText={familyLabel}
+ w="full"
+ onValueChange={onFamily}
+ />
+ </PropertyControlRow>
+ <PropertyControlRow label={t('widgets.properties.rows.size')}>
+ <ToolbarSlider
+ aria-label={t('widgets.canvas.toolOptions.textSize')}
+ max={MAX_TEXT_FONT_SIZE}
+ min={MIN_TEXT_FONT_SIZE}
+ value={sizeGesture.value}
+ onValueChange={sizeGesture.onChange}
+ onValueChangeEnd={sizeGesture.onChangeEnd}
+ />
+ <ToolbarNumberField
+ aria-label={t('widgets.canvas.toolOptions.textSize')}
+ max={MAX_TEXT_FONT_SIZE}
+ min={MIN_TEXT_FONT_SIZE}
+ suffix="px"
+ value={String(Math.round(active.fontSize))}
+ onValueCommit={onSize}
+ />
+ </PropertyControlRow>
+ <PropertyControlRow label={t('widgets.properties.rows.weight')}>
+ <Select
+ aria-label={t('widgets.canvas.toolOptions.textWeight')}
+ collection={weightCollection}
+ flexShrink={0}
+ positioning={SELECT_POSITIONING}
+ size="xs"
+ triggerProps={WEIGHT_TRIGGER_PROPS}
+ value={weightValue}
+ valueText={String(active.fontWeight)}
+ w="4.5rem"
+ onValueChange={onWeight}
+ />
+ </PropertyControlRow>
+ <PropertyControlRow label={t('widgets.properties.rows.lineHeight')}>
+ <ToolbarSlider
+ aria-label={t('widgets.canvas.toolOptions.textLineHeight')}
+ max={4}
+ min={0.5}
+ step={0.1}
+ value={lineHeightGesture.value}
+ onValueChange={lineHeightGesture.onChange}
+ onValueChangeEnd={lineHeightGesture.onChangeEnd}
+ />
+ <ToolbarNumberField
+ aria-label={t('widgets.canvas.toolOptions.textLineHeight')}
+ max={4}
+ min={0.5}
+ step={0.1}
+ value={active.lineHeight.toFixed(1)}
+ onValueCommit={onLineHeight}
+ />
+ </PropertyControlRow>
+ </>
+ );
+};
+
+const TextParagraphSettings = ({ engine }: ToolbarRegionProps) => {
+ const { t } = useTranslation();
+ const { active, applyEdit } = useTextEditor(engine);
+ const onAlign = useCallback((next: TextAlign) => applyEdit({ align: next }, true), [applyEdit]);
+ return (
+ <PropertyControlRow label={t('widgets.properties.rows.align')}>
<HStack gap="0.5">
{ALIGN_VALUES.map((value) => (
<AlignButton key={value} active={active.align === value} value={value} onSelect={onAlign} />
))}
</HStack>
- </>
+ </PropertyControlRow>
);
};
-const TextColor = ({ engine }: ToolbarRegionProps) => {
+const TextColorSettings = ({ engine }: ToolbarRegionProps) => {
const { t } = useTranslation();
const { active, applyEdit } = useTextEditor(engine);
const sampleColor = useColorSampler(engine);
const onChange = useCallback((hex: string) => applyEdit({ color: hex }, false), [applyEdit]);
const onChangeEnd = useCallback((hex: string) => applyEdit({ color: hex }, true), [applyEdit]);
return (
- <ColorPicker
- aria-label={t('widgets.canvas.toolOptions.textColor')}
- value={active.color}
- onSampleColor={sampleColor}
- onValueChange={onChange}
- onValueChangeEnd={onChangeEnd}
- />
+ <PropertyControlRow label={t('widgets.properties.rows.color')}>
+ <ColorPicker
+ aria-label={t('widgets.canvas.toolOptions.textColor')}
+ value={active.color}
+ onSampleColor={sampleColor}
+ onValueChange={onChange}
+ onValueChangeEnd={onChangeEnd}
+ />
+ </PropertyControlRow>
);
};
-export const textAdapter: ToolPresentationAdapter = {
- rowLabels: {
- color: 'widgets.canvas.toolOptions.textColor',
- geometry: 'widgets.canvas.toolOptions.textFont',
- modes: 'widgets.canvas.toolOptions.textStyle',
- },
- color: TextColor,
- geometry: TextFamily,
+export const textForm: ToolPropertyForm = {
+ groups: [
+ { body: TextFontSettings, id: 'text-font', labelKey: 'widgets.properties.groups.font' },
+ { body: TextParagraphSettings, id: 'text-paragraph', labelKey: 'widgets.properties.groups.paragraph' },
+ { body: TextColorSettings, id: 'text-color', labelKey: 'widgets.properties.rows.color' },
+ ],
id: 'text',
- modes: TextStyle,
paintsLeaf: true,
};
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/gradientStops.test.ts b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/gradientStops.test.ts
new file mode 100644
index 0000000000..e87874c9fd
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/gradientStops.test.ts
@@ -0,0 +1,65 @@
+import type { GradientStop } from '@workbench/canvas-engine/api';
+
+import { describe, expect, it } from 'vitest';
+
+import {
+ insertStopAt,
+ moveStop,
+ recolorStop,
+ removeStop,
+ sampleGradientColor,
+ stopsToCssGradient,
+} from './gradientStops';
+
+const BW: GradientStop[] = [
+ { color: '#000000ff', offset: 0 },
+ { color: '#ffffffff', offset: 1 },
+];
+
+describe('gradient stop math', () => {
+ it('samples the interpolated color, clamped at the ends', () => {
+ expect(sampleGradientColor(BW, 0.5)).toBe('#808080ff');
+ expect(sampleGradientColor(BW, -1)).toBe('#000000ff');
+ expect(sampleGradientColor(BW, 2)).toBe('#ffffffff');
+ // Alpha interpolates too, and a #rrggbb stop counts as opaque.
+ const translucent: GradientStop[] = [
+ { color: '#ff000000', offset: 0 },
+ { color: '#ff0000', offset: 1 },
+ ];
+ expect(sampleGradientColor(translucent, 0.5)).toBe('#ff000080');
+ });
+
+ it('inserts a stop with the gradient color at that offset, sorted', () => {
+ const { index, stops } = insertStopAt(BW, 0.25);
+ expect(index).toBe(1);
+ expect(stops).toHaveLength(3);
+ expect(stops[1]).toEqual({ color: '#404040ff', offset: 0.25 });
+ expect(stops.map((stop) => stop.offset)).toEqual([0, 0.25, 1]);
+ });
+
+ it('moves a stop, keeping the list sorted and tracking its index across neighbours', () => {
+ const three = insertStopAt(BW, 0.25).stops;
+ const moved = moveStop(three, 1, 0.9);
+ expect(moved.stops.map((stop) => stop.offset)).toEqual([0, 0.9, 1]);
+ expect(moved.index).toBe(1);
+ const swapped = moveStop(three, 0, 0.95);
+ expect(swapped.stops.map((stop) => stop.offset)).toEqual([0.25, 0.95, 1]);
+ expect(swapped.index).toBe(1);
+ expect(moveStop(three, 1, 7).stops[2]!.offset).toBe(1);
+ });
+
+ it('recolors in place and refuses to remove below two stops', () => {
+ expect(recolorStop(BW, 0, '#112233ff')[0]!.color).toBe('#112233ff');
+ expect(removeStop(BW, 0)).toEqual(BW);
+ const three = insertStopAt(BW, 0.5).stops;
+ expect(removeStop(three, 1)).toEqual(BW);
+ });
+
+ it('renders the css preview in offset order', () => {
+ const unsorted: GradientStop[] = [
+ { color: '#ffffffff', offset: 1 },
+ { color: '#000000ff', offset: 0 },
+ ];
+ expect(stopsToCssGradient(unsorted)).toBe('linear-gradient(90deg, #000000ff 0.0%, #ffffffff 100.0%)');
+ });
+});
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/gradientStops.ts b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/gradientStops.ts
new file mode 100644
index 0000000000..790eab46ef
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/gradientStops.ts
@@ -0,0 +1,95 @@
+import type { GradientStop } from '@workbench/canvas-engine/api';
+
+/**
+ * Pure stop-list math for the gradient stop strip. Stops are `#rrggbb` or
+ * `#rrggbbaa` colors with offsets in [0, 1]; every operation returns a new
+ * sorted list and never drops below two stops.
+ */
+
+const clamp01 = (value: number): number => Math.min(1, Math.max(0, value));
+
+const parseChannel = (hex: string, index: number): number => {
+ const parsed = Number.parseInt(hex.slice(1 + index * 2, 3 + index * 2), 16);
+ return Number.isFinite(parsed) ? parsed : 0;
+};
+
+const parseRgba = (color: string): [number, number, number, number] => [
+ parseChannel(color, 0),
+ parseChannel(color, 1),
+ parseChannel(color, 2),
+ color.length >= 9 ? parseChannel(color, 3) : 255,
+];
+
+const toHexByte = (value: number): string =>
+ Math.round(Math.min(255, Math.max(0, value)))
+ .toString(16)
+ .padStart(2, '0');
+
+const sortStops = (stops: readonly GradientStop[]): GradientStop[] => [...stops].sort((a, b) => a.offset - b.offset);
+
+/** The gradient's color at `offset`: linear interpolation between the flanking stops. */
+export const sampleGradientColor = (stops: readonly GradientStop[], offset: number): string => {
+ const sorted = sortStops(stops);
+ const at = clamp01(offset);
+ const first = sorted[0];
+ const last = sorted[sorted.length - 1];
+ if (!first || !last) {
+ return '#000000ff';
+ }
+ if (at <= first.offset) {
+ return first.color;
+ }
+ if (at >= last.offset) {
+ return last.color;
+ }
+ const upperIndex = sorted.findIndex((stop) => stop.offset >= at);
+ const upper = sorted[upperIndex]!;
+ const lower = sorted[upperIndex - 1]!;
+ const span = upper.offset - lower.offset;
+ const mix = span <= 0 ? 0 : (at - lower.offset) / span;
+ const a = parseRgba(lower.color);
+ const b = parseRgba(upper.color);
+ const blended = a.map((channel, i) => channel + (b[i]! - channel) * mix);
+ return `#${blended.map(toHexByte).join('')}`;
+};
+
+/** Inserts a stop at `offset` with the gradient's own color there; returns the new list and the stop's index. */
+export const insertStopAt = (
+ stops: readonly GradientStop[],
+ offset: number
+): { stops: GradientStop[]; index: number } => {
+ const at = clamp01(offset);
+ const created: GradientStop = { color: sampleGradientColor(stops, at), offset: at };
+ const next = sortStops([...stops, created]);
+ return { index: next.indexOf(created), stops: next };
+};
+
+/** Moves one stop to `offset`; the list stays sorted, so the stop's index may change. */
+export const moveStop = (
+ stops: readonly GradientStop[],
+ index: number,
+ offset: number
+): { stops: GradientStop[]; index: number } => {
+ const target = stops[index];
+ if (!target) {
+ return { index, stops: [...stops] };
+ }
+ const moved: GradientStop = { ...target, offset: clamp01(offset) };
+ const rest = stops.filter((_, i) => i !== index);
+ const next = sortStops([...rest, moved]);
+ return { index: next.indexOf(moved), stops: next };
+};
+
+/** Recolors one stop in place. */
+export const recolorStop = (stops: readonly GradientStop[], index: number, color: string): GradientStop[] =>
+ stops.map((stop, i) => (i === index ? { ...stop, color } : stop));
+
+/** Removes one stop; refused (returns the input) when only two remain. */
+export const removeStop = (stops: readonly GradientStop[], index: number): GradientStop[] =>
+ stops.length <= 2 ? [...stops] : stops.filter((_, i) => i !== index);
+
+/** The strip's own preview: a horizontal CSS gradient of the stops. */
+export const stopsToCssGradient = (stops: readonly GradientStop[]): string => {
+ const parts = sortStops(stops).map((stop) => `${stop.color} ${(stop.offset * 100).toFixed(1)}%`);
+ return `linear-gradient(90deg, ${parts.join(', ')})`;
+};
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-presentation/PropertyPrimitives.tsx b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-presentation/PropertyPrimitives.tsx
index 7dfe1209f4..f87fc39f60 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-presentation/PropertyPrimitives.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-presentation/PropertyPrimitives.tsx
@@ -1,8 +1,9 @@
import type { ReactNode } from 'react';
-import { chakra, Grid, Icon, Stack, Switch, Text } from '@chakra-ui/react';
+import { Badge, chakra, Flex, Grid, Icon, SegmentGroup, Stack, Switch, Text } from '@chakra-ui/react';
import { ChevronDownIcon } from 'lucide-react';
import { useCallback } from 'react';
+import { useTranslation } from 'react-i18next';
import { setPropertyGroupCollapsed, usePropertyGroupCollapsed } from './propertyGroupStore';
@@ -115,3 +116,74 @@ export const PropertyGroup = ({
</Stack>
);
};
+
+/** A labelled choice row rendered as a full-width segmented control (≤5 options). */
+export const PropertySegmentedRow = <Value extends string>({
+ disabled,
+ label,
+ onValueChange,
+ options,
+ value,
+}: {
+ disabled?: boolean;
+ label: string;
+ onValueChange: (value: Value) => void;
+ options: readonly { value: Value; label: string }[];
+ value: Value;
+}) => {
+ const handleChange = useCallback(
+ ({ value: next }: SegmentGroup.ValueChangeDetails) => {
+ if (next !== null && next !== value) {
+ onValueChange(next as Value);
+ }
+ },
+ [onValueChange, value]
+ );
+ return (
+ <PropertyControlRow label={label}>
+ <SegmentGroup.Root
+ aria-label={label}
+ disabled={disabled}
+ gridColumn="2 / -1"
+ size="xs"
+ value={value}
+ w="full"
+ onValueChange={handleChange}
+ >
+ <SegmentGroup.Indicator />
+ {options.map((option) => (
+ <SegmentGroup.Item key={option.value} flex="1" justifyContent="center" value={option.value}>
+ <SegmentGroup.ItemText fontSize="2xs">{option.label}</SegmentGroup.ItemText>
+ <SegmentGroup.ItemHiddenInput />
+ </SegmentGroup.Item>
+ ))}
+ </SegmentGroup.Root>
+ </PropertyControlRow>
+ );
+};
+
+/**
+ * Names what a dual-role form is editing right now: the creation defaults, or
+ * the selected layer's own content. Shown once at the top of the affected
+ * form, per the C0 §4 target-chip decision.
+ */
+export const EditTargetChip = ({ layerName }: { layerName: string | null }) => {
+ const { t } = useTranslation();
+ return (
+ <Flex justify="flex-end">
+ <Badge
+ colorPalette={layerName === null ? 'gray' : 'blue'}
+ maxW="full"
+ size="sm"
+ title={layerName === null ? undefined : layerName}
+ variant="surface"
+ >
+ <Text minW="0" truncate>
+ {layerName === null
+ ? t('widgets.properties.target.defaults')
+ : t('widgets.properties.target.editing', { name: layerName })}
+ </Text>
+ </Badge>
+ </Flex>
+ );
+};
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-presentation/ToolbarPrimitives.tsx b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-presentation/ToolbarPrimitives.tsx
index 8186720abf..81f1ce517e 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-presentation/ToolbarPrimitives.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-presentation/ToolbarPrimitives.tsx
@@ -152,6 +152,8 @@ interface ToolbarSliderProps {
value: number;
onKeyDownCapture?: (event: KeyboardEvent<HTMLDivElement>) => void;
onValueChange: (value: number) => void;
+ /** Fires once when the drag or key gesture settles; document commits belong here, not in onValueChange. */
+ onValueChangeEnd?: (value: number) => void;
}
/** A slider that fills its region; pairs with a {@link ToolbarNumberField}. */
@@ -166,6 +168,7 @@ export const ToolbarSlider = ({
value,
onKeyDownCapture,
onValueChange,
+ onValueChangeEnd,
}: ToolbarSliderProps) => {
const labels = useMemo(() => [ariaLabel], [ariaLabel]);
const values = useMemo(() => [value], [value]);
@@ -182,6 +185,15 @@ export const ToolbarSlider = ({
},
[onValueChange]
);
+ const handleChangeEnd = useCallback(
+ ({ value: next }: SliderValueChangeDetails) => {
+ const first = next[0];
+ if (onValueChangeEnd && first !== undefined && Number.isFinite(first)) {
+ onValueChangeEnd(first);
+ }
+ },
+ [onValueChangeEnd]
+ );
return (
<Slider
aria-label={labels}
@@ -197,10 +209,48 @@ export const ToolbarSlider = ({
value={values}
onKeyDownCapture={onKeyDownCapture}
onValueChange={handleChange}
+ onValueChangeEnd={onValueChangeEnd ? handleChangeEnd : undefined}
/>
);
};
+/**
+ * Drag-gesture state for a slider whose settled value lives in the document: the
+ * draft follows the thumb, `settle` runs ONCE on release (one history entry per
+ * gesture), and optional `preview` mirrors ticks into a non-committing store.
+ */
+export const useSliderGesture = (
+ committed: number,
+ settle: (value: number) => void,
+ preview?: (value: number) => void
+) => {
+ const [draft, setDraft] = useState<number | null>(null);
+ // The end event also fires for gestures that changed nothing (a thumb click,
+ // an arrow key at the boundary); settling those would record empty history
+ // entries, so a gesture only settles a genuinely different value.
+ const committedRef = useRef(committed);
+ useEffect(() => {
+ committedRef.current = committed;
+ }, [committed]);
+ const onChange = useCallback(
+ (value: number) => {
+ setDraft(value);
+ preview?.(value);
+ },
+ [preview]
+ );
+ const onChangeEnd = useCallback(
+ (value: number) => {
+ setDraft(null);
+ if (value !== committedRef.current) {
+ settle(value);
+ }
+ },
+ [settle]
+ );
+ return { onChange, onChangeEnd, value: draft ?? committed };
+};
+
/** Apply and Cancel for a pending operation, session or float, after whatever the owner shows about it. */
export const ToolbarStatus = ({
applyDisabled = true,
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-presentation/toolAdapters.ts b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-presentation/toolAdapters.ts
index a54d7e9fd8..77af73587b 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-presentation/toolAdapters.ts
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-presentation/toolAdapters.ts
@@ -2,14 +2,14 @@ import type { ToolId } from '@workbench/canvas-engine/api';
import { bboxAdapter } from '@workbench/widgets/canvas/tool-options/BboxOptions';
import { filterOperationAdapter } from '@workbench/widgets/canvas/tool-options/FilterOptions';
-import { gradientAdapter } from '@workbench/widgets/canvas/tool-options/GradientOptions';
+import { gradientForm } from '@workbench/widgets/canvas/tool-options/GradientOptions';
import { lassoAdapter } from '@workbench/widgets/canvas/tool-options/LassoOptions';
import { marqueeAdapter } from '@workbench/widgets/canvas/tool-options/MarqueeOptions';
import { moveAdapter } from '@workbench/widgets/canvas/tool-options/MoveOptions';
import { brushForm, eraserForm } from '@workbench/widgets/canvas/tool-options/paintForm';
import { selectObjectOperationAdapter } from '@workbench/widgets/canvas/tool-options/SamOptions';
-import { shapeAdapter } from '@workbench/widgets/canvas/tool-options/ShapeOptions';
-import { textAdapter } from '@workbench/widgets/canvas/tool-options/TextOptions';
+import { shapeForm } from '@workbench/widgets/canvas/tool-options/ShapeOptions';
+import { textForm } from '@workbench/widgets/canvas/tool-options/TextOptions';
import { transformAdapter } from '@workbench/widgets/canvas/tool-options/TransformOptions';
import type {
@@ -29,13 +29,13 @@ export const TOOL_PRESENTATION_ADAPTERS: Readonly<Record<ToolId, ToolPanePresent
brush: brushForm,
colorPicker: hintOnly('colorPicker'),
eraser: eraserForm,
- gradient: gradientAdapter,
+ gradient: gradientForm,
lasso: lassoAdapter,
marquee: marqueeAdapter,
move: moveAdapter,
sam: hintOnly('sam'),
- shape: shapeAdapter,
- text: textAdapter,
+ shape: shapeForm,
+ text: textForm,
transform: transformAdapter,
view: hintOnly('view'),
};
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/panes/LayerEditorPanes.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/panes/LayerEditorPanes.browser.test.tsx
index c3d3b209d4..99592d1972 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/panes/LayerEditorPanes.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/panes/LayerEditorPanes.browser.test.tsx
@@ -1,4 +1,5 @@
/* oxlint-disable react-perf/jsx-no-new-function-as-prop */
+import type { CanvasLayerSourceContract } from '@workbench/canvas-engine/api';
import type { CanvasOperationState } from '@workbench/canvas-operations/api';
import type { CanvasEngine } from '@workbench/canvas-operations/createCanvasEngine';
import type { FilterOperationSessionState } from '@workbench/canvas-operations/filterOperationSession';
@@ -179,7 +180,28 @@ const settle = () =>
const IDENTITY = { rotation: 0, scaleX: 1, scaleY: 1, x: 0, y: 0 };
-type Selection = 'none' | 'layer' | 'group' | 'mask';
+type Selection = 'none' | 'layer' | 'group' | 'mask' | 'shape' | 'gradient';
+
+const SHAPE_SOURCE = {
+ fill: '#ff0000',
+ height: 10,
+ kind: 'rect',
+ stroke: null,
+ strokeWidth: 2,
+ type: 'shape',
+ width: 10,
+} satisfies Extract<CanvasLayerSourceContract, { type: 'shape' }>;
+const GRADIENT_SOURCE = {
+ angle: 0,
+ height: 10,
+ kind: 'linear',
+ stops: [
+ { color: '#000000ff', offset: 0 },
+ { color: '#ffffffff', offset: 1 },
+ ],
+ type: 'gradient',
+ width: 10,
+} satisfies Extract<CanvasLayerSourceContract, { type: 'gradient' }>;
const mount = async (View: typeof PropertiesPane, selection: Selection = 'none') => {
const base = { ...createInitialWorkbenchState().projects[0]!, id: 'p' };
@@ -188,13 +210,17 @@ const mount = async (View: typeof PropertiesPane, selection: Selection = 'none')
? []
: selection === 'layer'
? [layerContract('l0', 'raster', { name: 'Paint', transform: { ...IDENTITY, rotation: 0.5, x: 10.4 } })]
- : selection === 'mask'
- ? [layerContract('m0', 'inpaint_mask', { name: 'Mask' })]
- : [groupContract('g0', [layerContract('l0', 'raster', { name: 'Paint' })], { name: 'Folder' })];
+ : selection === 'shape'
+ ? [layerContract('l0', 'raster', { name: 'My Shape', source: SHAPE_SOURCE })]
+ : selection === 'gradient'
+ ? [layerContract('l0', 'raster', { name: 'My Gradient', source: GRADIENT_SOURCE })]
+ : selection === 'mask'
+ ? [layerContract('m0', 'inpaint_mask', { name: 'Mask' })]
+ : [groupContract('g0', [layerContract('l0', 'raster', { name: 'Paint' })], { name: 'Folder' })];
harness.project = applyCanvasProjectMutation(base, {
document: {
...createEmptyCanvasDocument(),
- selectedLayerId: selection === 'none' ? null : selection === 'layer' ? 'l0' : selection === 'mask' ? 'm0' : 'g0',
+ selectedLayerId: selection === 'none' ? null : selection === 'mask' ? 'm0' : selection === 'group' ? 'g0' : 'l0',
stacks: stacksFrom(nodes),
},
type: 'replaceCanvasDocument',
@@ -290,6 +316,48 @@ describe('Properties pane', () => {
expect(page.getByRole('button', { exact: true, name: 'Brush color' }).query()).toBeNull();
});
+ it('labels the shape form with its edit target and gates stroke width on the stroke slot', async () => {
+ await mount(PropertiesPane);
+ await act(() => engine!.tools.setTool('shape'));
+ await settle();
+ // Nothing selected: the chip says the form edits the creation defaults.
+ expect(host!.textContent).toContain('Defaults');
+ await expect.element(page.getByRole('radio', { exact: true, name: 'Rectangle' })).toBeInTheDocument();
+
+ await act(() => root?.unmount());
+ await mount(PropertiesPane, 'shape');
+ await act(() => engine!.tools.setTool('shape'));
+ await settle();
+ expect(host!.textContent).toContain('Editing: My Shape');
+ // The fixture shape has no stroke, so the width slider is disabled in place.
+ const width = page.getByRole('slider', { exact: true, name: 'Stroke width' });
+ await expect.element(width).toBeVisible();
+ expect(width.element().getAttribute('data-disabled')).not.toBeNull();
+ });
+
+ it('names a selected gradient in the chip and moves a default stop from the keyboard', async () => {
+ await mount(PropertiesPane, 'gradient');
+ await act(() => engine!.tools.setTool('gradient'));
+ await settle();
+ expect(host!.textContent).toContain('Editing: My Gradient');
+ await expect.element(page.getByRole('button', { exact: true, name: 'Gradient stop at 0%' })).toBeVisible();
+
+ // The harness's mutation port refuses document dispatches, so the
+ // keyboard-move half runs against the creation DEFAULTS (options store).
+ await act(() => root?.unmount());
+ await mount(PropertiesPane);
+ await act(() => engine!.tools.setTool('gradient'));
+ await settle();
+ expect(host!.textContent).toContain('Defaults');
+ const startStop = page.getByRole('button', { exact: true, name: 'Gradient stop at 0%' });
+ await expect.element(startStop).toBeVisible();
+ await expect.element(page.getByRole('button', { exact: true, name: 'Gradient stop at 100%' })).toBeVisible();
+ await act(() => (startStop.element() as HTMLElement).focus());
+ await act(() => userEvent.keyboard('{ArrowRight}'));
+ await settle();
+ await expect.element(page.getByRole('button', { exact: true, name: 'Gradient stop at 1%' })).toBeVisible();
+ });
+
it('remembers a group collapse per user across remounts', async () => {
await mount(PropertiesPane);
await act(() => engine!.tools.setTool('brush'));