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
feat(canvas): triangle and star shape kinds (U6a)
Josh Corbett26587cdf4b0a
diff --git a/invokeai/frontend/webv2/performance/browser-baseline.json b/invokeai/frontend/webv2/performance/browser-baseline.jsonindex 46703d05af..38fc80756e 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": 117.6000000089407,+ "domContentLoadedMedianMs": 127.19999998807907,"id": "launchpad","layoutAckMedianMs": 0,"layoutReturnSwitchMedianMs": 0,"layoutSwitchMedianMs": 0,- "loadMedianMs": 117.70000000298023,- "longestTaskMaxMs": 70,+ "loadMedianMs": 127.3999999910593,+ "longestTaskMaxMs": 76,"owner": "app","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:launchpad",@@ -41,24 +41,24 @@"fontRawBytes": 23664,"imageRawBytes": 0,"largestAssetRawBytes": 746400,- "otherRawBytes": 162513,+ "otherRawBytes": 162626,"requestCount": 38,"scriptRawBytes": 1636642,"scriptRequestCount": 34,- "totalRawBytes": 1824978+ "totalRawBytes": 1825091},"resourceLimits": {"cssRawBytes": 2181,"fontRawBytes": 23901,"imageRawBytes": 0,"largestAssetRawBytes": 753864,- "otherRawBytes": 164139,+ "otherRawBytes": 164253,"requestCount": 38,"scriptRawBytes": 1653009,"scriptRequestCount": 34,- "totalRawBytes": 1843228+ "totalRawBytes": 1843342},- "routeReadyMedianMs": 265.09999999403954,+ "routeReadyMedianMs": 284.3999999910593,"scriptSourceOwnerSet": "launchpad-static","stateProfile": "empty"},@@ -85,13 +85,13 @@"scriptRequestCount": 0,"totalRawBytes": 0},- "domContentLoadedMedianMs": 117.3999999910593,+ "domContentLoadedMedianMs": 123.3999999910593,"id": "launchpad","layoutAckMedianMs": 0,"layoutReturnSwitchMedianMs": 0,"layoutSwitchMedianMs": 0,- "loadMedianMs": 117.5,- "longestTaskMaxMs": 74,+ "loadMedianMs": 123.59999999403954,+ "longestTaskMaxMs": 73,"owner": "app","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:launchpad",@@ -101,24 +101,24 @@"fontRawBytes": 23664,"imageRawBytes": 0,"largestAssetRawBytes": 746400,- "otherRawBytes": 162513,+ "otherRawBytes": 162626,"requestCount": 38,"scriptRawBytes": 1636642,"scriptRequestCount": 34,- "totalRawBytes": 1824978+ "totalRawBytes": 1825091},"resourceLimits": {"cssRawBytes": 2181,"fontRawBytes": 23901,"imageRawBytes": 0,"largestAssetRawBytes": 753864,- "otherRawBytes": 164139,+ "otherRawBytes": 164253,"requestCount": 38,"scriptRawBytes": 1653009,"scriptRequestCount": 34,- "totalRawBytes": 1843228+ "totalRawBytes": 1843342},- "routeReadyMedianMs": 278.40000000596046,+ "routeReadyMedianMs": 297.5,"scriptSourceOwnerSet": "launchpad-static","stateProfile": "representative"},@@ -145,15 +145,15 @@"scriptRequestCount": 0,"totalRawBytes": 0},- "domContentLoadedMedianMs": 119.3999999910593,+ "domContentLoadedMedianMs": 128.40000000596046,"id": "editor-minimal","layoutAckMedianMs": 0,"layoutReturnSwitchMedianMs": 0,"layoutSwitchMedianMs": 0,- "loadMedianMs": 119.5,- "longestTaskMaxMs": 129,+ "loadMedianMs": 128.5,+ "longestTaskMaxMs": 115,"owner": "workbench",- "projectSwitchMedianMs": 37.599999994039536,+ "projectSwitchMedianMs": 44.5,"readyMark": "invokeai:ready:widget:center:preview","remediationTicket": "deepen-widget-registry-loading","resourceBaseline": {@@ -161,24 +161,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 746400,- "otherRawBytes": 162513,+ "otherRawBytes": 162626,"requestCount": 115,- "scriptRawBytes": 3287526,+ "scriptRawBytes": 3287820,"scriptRequestCount": 110,- "totalRawBytes": 3632238+ "totalRawBytes": 3632645},"resourceLimits": {"cssRawBytes": 2181,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 753864,- "otherRawBytes": 164139,+ "otherRawBytes": 164253,"requestCount": 115,- "scriptRawBytes": 3320402,+ "scriptRawBytes": 3320699,"scriptRequestCount": 110,- "totalRawBytes": 3668561+ "totalRawBytes": 3668972},- "routeReadyMedianMs": 678.1000000089407,+ "routeReadyMedianMs": 709.7000000029802,"scriptSourceOwnerSet": "editor-minimal-static","stateProfile": "empty"},@@ -205,15 +205,15 @@"scriptRequestCount": 0,"totalRawBytes": 0},- "domContentLoadedMedianMs": 120.29999999701977,+ "domContentLoadedMedianMs": 123.79999999701977,"id": "editor-minimal","layoutAckMedianMs": 0,"layoutReturnSwitchMedianMs": 0,"layoutSwitchMedianMs": 0,- "loadMedianMs": 120.40000000596046,- "longestTaskMaxMs": 197,+ "loadMedianMs": 123.8999999910593,+ "longestTaskMaxMs": 210,"owner": "workbench",- "projectSwitchMedianMs": 71.5,+ "projectSwitchMedianMs": 78.79999999701977,"readyMark": "invokeai:ready:widget:center:preview","remediationTicket": "deepen-widget-registry-loading","resourceBaseline": {@@ -221,24 +221,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 746400,- "otherRawBytes": 162513,+ "otherRawBytes": 162626,"requestCount": 115,- "scriptRawBytes": 3287526,+ "scriptRawBytes": 3287820,"scriptRequestCount": 110,- "totalRawBytes": 3632238+ "totalRawBytes": 3632645},"resourceLimits": {"cssRawBytes": 2181,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 753864,- "otherRawBytes": 164139,+ "otherRawBytes": 164253,"requestCount": 115,- "scriptRawBytes": 3320402,+ "scriptRawBytes": 3320699,"scriptRequestCount": 110,- "totalRawBytes": 3668561+ "totalRawBytes": 3668972},- "routeReadyMedianMs": 453.20000000298023,+ "routeReadyMedianMs": 460.09999999403954,"scriptSourceOwnerSet": "editor-minimal-static","stateProfile": "representative"},@@ -247,31 +247,31 @@"cssRawBytes": 0,"fontRawBytes": 0,"imageRawBytes": 0,- "largestAssetRawBytes": 316058,+ "largestAssetRawBytes": 315016,"otherRawBytes": 0,"requestCount": 7,- "scriptRawBytes": 475692,+ "scriptRawBytes": 474650,"scriptRequestCount": 7,- "totalRawBytes": 475692+ "totalRawBytes": 474650},"activatedResourceLimits": {"cssRawBytes": 0,"fontRawBytes": 0,"imageRawBytes": 0,- "largestAssetRawBytes": 319219,+ "largestAssetRawBytes": 318167,"otherRawBytes": 0,"requestCount": 7,- "scriptRawBytes": 480449,+ "scriptRawBytes": 479397,"scriptRequestCount": 7,- "totalRawBytes": 480449+ "totalRawBytes": 479397},- "domContentLoadedMedianMs": 118.5,+ "domContentLoadedMedianMs": 119.40000000596046,"id": "editor-canvas",- "layoutAckMedianMs": 2.300000011920929,- "layoutReturnSwitchMedianMs": 55.29999999701977,- "layoutSwitchMedianMs": 95.29999999701977,- "loadMedianMs": 118.59999999403954,- "longestTaskMaxMs": 135,+ "layoutAckMedianMs": 2.7999999970197678,+ "layoutReturnSwitchMedianMs": 59.29999999701977,+ "layoutSwitchMedianMs": 93.59999999403954,+ "loadMedianMs": 119.5,+ "longestTaskMaxMs": 139,"owner": "canvas","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:widget:center:canvas",@@ -281,24 +281,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 746400,- "otherRawBytes": 162513,+ "otherRawBytes": 162626,"requestCount": 122,- "scriptRawBytes": 3763218,+ "scriptRawBytes": 3762470,"scriptRequestCount": 117,- "totalRawBytes": 4107930+ "totalRawBytes": 4107295},"resourceLimits": {"cssRawBytes": 2181,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 753864,- "otherRawBytes": 164139,+ "otherRawBytes": 164253,"requestCount": 122,- "scriptRawBytes": 3800851,+ "scriptRawBytes": 3800095,"scriptRequestCount": 117,- "totalRawBytes": 4149010+ "totalRawBytes": 4148368},- "routeReadyMedianMs": 1061.5,+ "routeReadyMedianMs": 1060.7000000029802,"scriptSourceOwnerSet": "editor-canvas-static","stateProfile": "empty"},@@ -307,31 +307,31 @@"cssRawBytes": 0,"fontRawBytes": 0,"imageRawBytes": 0,- "largestAssetRawBytes": 316058,+ "largestAssetRawBytes": 315016,"otherRawBytes": 0,"requestCount": 7,- "scriptRawBytes": 475692,+ "scriptRawBytes": 474650,"scriptRequestCount": 7,- "totalRawBytes": 475692+ "totalRawBytes": 474650},"activatedResourceLimits": {"cssRawBytes": 0,"fontRawBytes": 0,"imageRawBytes": 0,- "largestAssetRawBytes": 319219,+ "largestAssetRawBytes": 318167,"otherRawBytes": 0,"requestCount": 7,- "scriptRawBytes": 480449,+ "scriptRawBytes": 479397,"scriptRequestCount": 7,- "totalRawBytes": 480449+ "totalRawBytes": 479397},- "domContentLoadedMedianMs": 114.5,+ "domContentLoadedMedianMs": 130.09999999403954,"id": "editor-canvas",- "layoutAckMedianMs": 2.699999988079071,- "layoutReturnSwitchMedianMs": 44.900000005960464,- "layoutSwitchMedianMs": 94.69999998807907,- "loadMedianMs": 114.6000000089407,- "longestTaskMaxMs": 200,+ "layoutAckMedianMs": 3.2000000029802322,+ "layoutReturnSwitchMedianMs": 51.29999999701977,+ "layoutSwitchMedianMs": 98.40000000596046,+ "loadMedianMs": 130.19999998807907,+ "longestTaskMaxMs": 212,"owner": "canvas","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:widget:center:canvas",@@ -341,24 +341,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 746400,- "otherRawBytes": 162513,+ "otherRawBytes": 162626,"requestCount": 122,- "scriptRawBytes": 3763218,+ "scriptRawBytes": 3762470,"scriptRequestCount": 117,- "totalRawBytes": 4107930+ "totalRawBytes": 4107295},"resourceLimits": {"cssRawBytes": 2181,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 753864,- "otherRawBytes": 164139,+ "otherRawBytes": 164253,"requestCount": 122,- "scriptRawBytes": 3800851,+ "scriptRawBytes": 3800095,"scriptRequestCount": 117,- "totalRawBytes": 4149010+ "totalRawBytes": 4148368},- "routeReadyMedianMs": 1149.699999988079,+ "routeReadyMedianMs": 1260,"scriptSourceOwnerSet": "editor-canvas-static","stateProfile": "representative"},@@ -385,13 +385,13 @@"scriptRequestCount": 6,"totalRawBytes": 383431},- "domContentLoadedMedianMs": 118.79999999701977,+ "domContentLoadedMedianMs": 126.79999999701977,"id": "editor-workflow",- "layoutAckMedianMs": 2.2000000029802322,- "layoutReturnSwitchMedianMs": 34.20000000298023,- "layoutSwitchMedianMs": 90.09999999403954,- "loadMedianMs": 118.8999999910593,- "longestTaskMaxMs": 96,+ "layoutAckMedianMs": 3.2999999970197678,+ "layoutReturnSwitchMedianMs": 34.69999998807907,+ "layoutSwitchMedianMs": 91,+ "loadMedianMs": 127,+ "longestTaskMaxMs": 108,"owner": "workflow","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:widget:center:workflow",@@ -401,24 +401,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 746400,- "otherRawBytes": 162513,+ "otherRawBytes": 162626,"requestCount": 122,- "scriptRawBytes": 3651747,+ "scriptRawBytes": 3652041,"scriptRequestCount": 116,- "totalRawBytes": 4011872+ "totalRawBytes": 4012279},"resourceLimits": {"cssRawBytes": 17748,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 753864,- "otherRawBytes": 164139,+ "otherRawBytes": 164253,"requestCount": 122,- "scriptRawBytes": 3688265,+ "scriptRawBytes": 3688562,"scriptRequestCount": 116,- "totalRawBytes": 4051991+ "totalRawBytes": 4052402},- "routeReadyMedianMs": 1056.0999999940395,+ "routeReadyMedianMs": 1085.5999999940395,"scriptSourceOwnerSet": "editor-workflow-static","stateProfile": "empty"},@@ -445,13 +445,13 @@"scriptRequestCount": 6,"totalRawBytes": 383431},- "domContentLoadedMedianMs": 118.8999999910593,+ "domContentLoadedMedianMs": 121.29999999701977,"id": "editor-workflow",- "layoutAckMedianMs": 3.0999999940395355,- "layoutReturnSwitchMedianMs": 41.29999999701977,- "layoutSwitchMedianMs": 126.5,- "loadMedianMs": 119.09999999403954,- "longestTaskMaxMs": 342,+ "layoutAckMedianMs": 3.2999999970197678,+ "layoutReturnSwitchMedianMs": 46.5,+ "layoutSwitchMedianMs": 135.1000000089407,+ "loadMedianMs": 121.5,+ "longestTaskMaxMs": 400,"owner": "workflow","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:widget:center:workflow",@@ -461,24 +461,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 746400,- "otherRawBytes": 162513,+ "otherRawBytes": 162626,"requestCount": 122,- "scriptRawBytes": 3651747,+ "scriptRawBytes": 3652041,"scriptRequestCount": 116,- "totalRawBytes": 4011872+ "totalRawBytes": 4012279},"resourceLimits": {"cssRawBytes": 17748,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 753864,- "otherRawBytes": 164139,+ "otherRawBytes": 164253,"requestCount": 122,- "scriptRawBytes": 3688265,+ "scriptRawBytes": 3688562,"scriptRequestCount": 116,- "totalRawBytes": 4051991+ "totalRawBytes": 4052402},- "routeReadyMedianMs": 1188.4000000059605,+ "routeReadyMedianMs": 1246,"scriptSourceOwnerSet": "editor-workflow-static","stateProfile": "representative"},@@ -505,12 +505,12 @@"scriptRequestCount": 0,"totalRawBytes": 0},- "domContentLoadedMedianMs": 116.8999999910593,+ "domContentLoadedMedianMs": 120.5,"id": "editor-gallery","layoutAckMedianMs": 0,"layoutReturnSwitchMedianMs": 0,- "layoutSwitchMedianMs": 25.799999997019768,- "loadMedianMs": 117.09999999403954,+ "layoutSwitchMedianMs": 27.600000008940697,+ "loadMedianMs": 120.69999998807907,"longestTaskMaxMs": 103,"owner": "gallery","projectSwitchMedianMs": 0,@@ -521,24 +521,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 746400,- "otherRawBytes": 162513,+ "otherRawBytes": 162626,"requestCount": 115,- "scriptRawBytes": 3287526,+ "scriptRawBytes": 3287820,"scriptRequestCount": 110,- "totalRawBytes": 3632238+ "totalRawBytes": 3632645},"resourceLimits": {"cssRawBytes": 2181,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 753864,- "otherRawBytes": 164139,+ "otherRawBytes": 164253,"requestCount": 115,- "scriptRawBytes": 3320402,+ "scriptRawBytes": 3320699,"scriptRequestCount": 110,- "totalRawBytes": 3668561+ "totalRawBytes": 3668972},- "routeReadyMedianMs": 1264.1000000089407,+ "routeReadyMedianMs": 1277.3999999910593,"scriptSourceOwnerSet": "editor-minimal-static","stateProfile": "empty"},@@ -565,13 +565,13 @@"scriptRequestCount": 0,"totalRawBytes": 0},- "domContentLoadedMedianMs": 117.70000000298023,+ "domContentLoadedMedianMs": 120.79999999701977,"id": "editor-gallery","layoutAckMedianMs": 0,"layoutReturnSwitchMedianMs": 0,- "layoutSwitchMedianMs": 86.29999999701977,- "loadMedianMs": 117.79999999701977,- "longestTaskMaxMs": 183,+ "layoutSwitchMedianMs": 92.20000000298023,+ "loadMedianMs": 121,+ "longestTaskMaxMs": 189,"owner": "gallery","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:widget:center:gallery",@@ -581,24 +581,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 746400,- "otherRawBytes": 162513,+ "otherRawBytes": 162626,"requestCount": 115,- "scriptRawBytes": 3287526,+ "scriptRawBytes": 3287820,"scriptRequestCount": 110,- "totalRawBytes": 3632238+ "totalRawBytes": 3632645},"resourceLimits": {"cssRawBytes": 2181,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 753864,- "otherRawBytes": 164139,+ "otherRawBytes": 164253,"requestCount": 115,- "scriptRawBytes": 3320402,+ "scriptRawBytes": 3320699,"scriptRequestCount": 110,- "totalRawBytes": 3668561+ "totalRawBytes": 3668972},- "routeReadyMedianMs": 1435.1000000089407,+ "routeReadyMedianMs": 1473.7000000029802,"scriptSourceOwnerSet": "editor-minimal-static","stateProfile": "representative"}@@ -2840,11 +2840,10 @@"source:src/workbench/widgets/canvas/tool-options/paintForm.tsx","source:src/workbench/widgets/canvas/tool-options/selectionForm.tsx","source:src/workbench/widgets/canvas/tool-options/useBboxEditor.ts",+ "source:src/workbench/widgets/canvas/tool-presentation/FormControls.tsx","source:src/workbench/widgets/canvas/tool-presentation/PropertyPrimitives.tsx",- "source:src/workbench/widgets/canvas/tool-presentation/ToolbarPrimitives.tsx","source:src/workbench/widgets/canvas/tool-presentation/propertyGroupStore.ts","source:src/workbench/widgets/canvas/tool-presentation/toolAdapters.ts",- "source:src/workbench/widgets/canvas/tool-presentation/toolbarContracts.ts","source:src/workbench/widgets/canvas/useCanvasEngine.ts","source:src/workbench/widgets/canvas/useCanvasGallerySave.ts","source:src/workbench/widgets/canvas/useColorSampler.ts",diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.jsonindex 8bb03adafe..6624664aec 100644--- a/invokeai/frontend/webv2/public/locales/en.json+++ b/invokeai/frontend/webv2/public/locales/en.json@@ -2485,6 +2485,8 @@"shapeFill": "Fill","shapeHint": "Drag to draw a shape.","shapeRect": "Rectangle",+ "shapeStar": "Star",+ "shapeTriangle": "Triangle","shapeStroke": "Stroke","shapeStrokeWidth": "Stroke width","size": "Size",diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/browserRaster.browser.test.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/browserRaster.browser.test.tsindex 4983662699..bbe080e00b 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/browserRaster.browser.test.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/browserRaster.browser.test.ts@@ -13,6 +13,7 @@ import { sampleDocumentColor } from '@workbench/canvas-engine/render/colorSampleimport { compositeDocument } from '@workbench/canvas-engine/render/compositor';import { createLayerCacheStore } from '@workbench/canvas-engine/render/layerCache';import { createDomRasterBackend, type RasterSurface } from '@workbench/canvas-engine/render/raster';+import { rasterizeShapeSource } from '@workbench/canvas-engine/render/rasterizers/shapeRasterizer';import { rasterizeTextSource } from '@workbench/canvas-engine/render/rasterizers/textRasterizer';import { describe, expect, it, vi } from 'vitest';@@ -287,6 +288,45 @@ describe('real browser raster acceptance', () => {expect(parsed.children?.map((child) => child.name)).toEqual(['Base', 'Group']);});+ it('rasterizes triangle and star shapes with the documented geometry', async () => {+ const backend = createDomRasterBackend();+ const deps = {+ backend,+ documentSize: { height: 64, width: 64 },+ resolver: () => Promise.resolve(new Blob()),+ store: createLayerCacheStore(backend),+ };+ const alphaAt = (surface: { ctx: CanvasRenderingContext2D }, x: number, y: number) =>+ surface.ctx.getImageData(x, y, 1, 1).data[3]!;++ const triangle = await rasterizeShapeSource(+ { fill: '#ff0000', height: 64, kind: 'triangle', stroke: null, strokeWidth: 0, type: 'shape', width: 64 },+ deps+ );+ const tri = triangle.surface as { ctx: CanvasRenderingContext2D };+ expect(alphaAt(tri, 32, 32)).toBeGreaterThan(0);+ expect(alphaAt(tri, 32, 4)).toBeGreaterThan(0);+ expect(alphaAt(tri, 4, 62)).toBeGreaterThan(0);+ expect(alphaAt(tri, 4, 4)).toBe(0);+ expect(alphaAt(tri, 60, 4)).toBe(0);++ const star = await rasterizeShapeSource(+ { fill: '#00ff00', height: 64, kind: 'star', stroke: null, strokeWidth: 0, type: 'shape', width: 64 },+ deps+ );+ const st = star.surface as { ctx: CanvasRenderingContext2D };+ expect(alphaAt(st, 32, 32)).toBeGreaterThan(0);+ expect(alphaAt(st, 32, 4)).toBeGreaterThan(0);+ expect(alphaAt(st, 46, 32)).toBeGreaterThan(0);+ // The left spike reaches where a triangle would be empty, and the bottom+ // concave notch is empty where a triangle would be filled — these two pins+ // discriminate the star from every other kind.+ expect(alphaAt(st, 5, 22)).toBeGreaterThan(0);+ expect(alphaAt(st, 32, 60)).toBe(0);+ expect(alphaAt(st, 52, 32)).toBe(0);+ expect(alphaAt(st, 4, 4)).toBe(0);+ });+it('writes folder opacity/blend natively and isolates the folder in the merged preview', async () => {const backend = createDomRasterBackend();const fill = (color: string) => {diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/contracts.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/contracts.tsindex 76fcb8cdec..1600881230 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/contracts.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/contracts.ts@@ -100,6 +100,9 @@ export interface CanvasImageRef {contentHash?: string;}+/** The drag-drawable shape kinds; `polygon` (point lists) stays a non-tool source. */+export type ParametricShapeKind = 'rect' | 'ellipse' | 'triangle' | 'star';+export type CanvasLayerSourceContract =| {type: 'paint';@@ -127,7 +130,7 @@ export type CanvasLayerSourceContract =}| {type: 'shape';- kind: 'rect' | 'ellipse' | 'polygon';+ kind: ParametricShapeKind | 'polygon';points?: { x: number; y: number }[];width: number;height: number;diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/document/sources.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/document/sources.tsindex a33ff5a2f3..8c31d44d1f 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/document/sources.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/document/sources.ts@@ -67,7 +67,7 @@ export const renderableSourceOf = (layer: CanvasLayerContract): CanvasLayerSourc/*** True when a layer's source is one the engine can rasterize today: image,- * paint, gradient, text, or a rect/ellipse shape. A `polygon` shape has no+ * paint, gradient, text, or a parametric (non-polygon) shape. A `polygon` shape has no* rasterizer yet (deferred), so it is not renderable.*/export const isRenderableLayer = (layer: CanvasLayerContract): boolean => {diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/engineStores.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/engineStores.tsindex 671ae6e321..a7684849d5 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/engineStores.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/engineStores.ts@@ -11,7 +11,7 @@* Zero React, zero import-time side effects.*/-import type { CanvasLayerSourceContract } from '@workbench/canvas-engine/contracts';+import type { CanvasLayerSourceContract, ParametricShapeKind } from '@workbench/canvas-engine/contracts';import type { SamInteractionState } from '@workbench/canvas-engine/samInteraction';import type { LayerTransform } from '@workbench/canvas-engine/transform/transformMath';import type { Rect, SelectionOp, ToolId, Vec2 } from '@workbench/canvas-engine/types';@@ -98,7 +98,7 @@ export interface GradientStop {* shape color; a selected shape's explicit fill/stroke is document state.*/export interface ShapeToolOptions {- kind: 'rect' | 'ellipse';+ kind: ParametricShapeKind;fillEnabled: boolean;strokeEnabled: boolean;strokeWidth: number;@@ -474,7 +474,7 @@ export interface EngineStores {* when idle. The overlay renders the shape outline in place of a committed* layer so the drag tracks without dispatching; cleared on commit/cancel.*/- shapePreview: ScalarStore<{ rect: Rect; kind: 'rect' | 'ellipse' } | null>;+ shapePreview: ScalarStore<{ rect: Rect; kind: ParametricShapeKind } | null>;/*** The live gradient-tool drag preview: the drag vector's start/end points in* document space, drawn on the overlay as a direction indicator (a gradient@@ -628,8 +628,8 @@ const gradientOptionsEqual = (a: GradientToolOptions, b: GradientToolOptions): b/** Shared by the shape and marquee previews — both are a rect plus a shape kind. */const rectShapePreviewEqual = (- a: { rect: Rect; kind: 'rect' | 'ellipse' } | null,- b: { rect: Rect; kind: 'rect' | 'ellipse' } | null+ a: { rect: Rect; kind: ParametricShapeKind } | null,+ b: { rect: Rect; kind: ParametricShapeKind } | null): boolean => {if (a === null || b === null) {return a === b;@@ -735,7 +735,7 @@ export const createEngineStores = (initialTool: ToolId = 'view'): EngineStores =ruleOfThirds: createScalarStore<boolean>(false),samInteraction: createScalarStore(null),shapeOptions: createScalarStore<ShapeToolOptions>({ ...DEFAULT_SHAPE_OPTIONS }, shapeOptionsEqual),- shapePreview: createScalarStore<{ rect: Rect; kind: 'rect' | 'ellipse' } | null>(null, rectShapePreviewEqual),+ shapePreview: createScalarStore<{ rect: Rect; kind: ParametricShapeKind } | null>(null, rectShapePreviewEqual),showBbox: createScalarStore<boolean>(true),showGrid: createScalarStore<boolean>(false),snapToGrid: createScalarStore<boolean>(true),diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/render/overlayRenderer.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/render/overlayRenderer.tsindex c2451b8442..2d4a28b34f 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/render/overlayRenderer.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/render/overlayRenderer.ts@@ -12,10 +12,12 @@* side effects.*/+import type { ParametricShapeKind } from '@workbench/canvas-engine/contracts';import type { Mat2d, Rect, Vec2 } from '@workbench/canvas-engine/types';import { applyToPoint, getScale, invert } from '@workbench/canvas-engine/math/mat2d';import { transformBounds } from '@workbench/canvas-engine/math/rect';+import { buildParametricShapePath } from '@workbench/canvas-engine/render/rasterizers/shapeRasterizer';import { drawMarchingAnts, type MarchingAntsRender } from '@workbench/canvas-engine/selection/marchingAnts';import { BBOX_HANDLES, bboxHandlePoint } from '@workbench/canvas-engine/tools/bboxHitTest';import { TRANSFORM_ROTATE_NUB_PX } from '@workbench/canvas-engine/transform/transformMath';@@ -53,10 +55,10 @@ export interface OverlayCursor {radiusDoc: number;}-/** A live rect-or-ellipse drag outline in document space (shape and marquee tools). */+/** A live parametric-shape drag outline in document space (shape and marquee tools). */export interface RectShapePreview {rect: Rect;- kind: 'rect' | 'ellipse';+ kind: ParametricShapeKind;}/** Everything the overlay needs to draw a frame. */@@ -357,20 +359,8 @@ const drawRectShapePreview = (ctx: Ctx, state: OverlayState, preview: RectShapePctx.strokeStyle = LAYER_OUTLINE_COLOR;ctx.lineWidth = 1;ctx.setLineDash([...BBOX_DASH]);- ctx.beginPath();- if (preview.kind === 'ellipse') {- ctx.ellipse(- screen.x + screen.width / 2,- screen.y + screen.height / 2,- Math.abs(screen.width) / 2,- Math.abs(screen.height) / 2,- 0,- 0,- Math.PI * 2- );- } else {- ctx.rect(screen.x, screen.y, screen.width, screen.height);- }+ // The same path the rasterizer commits, so the outline is the shape it makes.+ buildParametricShapePath(ctx, preview.kind, screen.x, screen.y, Math.abs(screen.width), Math.abs(screen.height), 0);ctx.stroke();ctx.setLineDash([]);ctx.restore();diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/render/rasterizers/index.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/render/rasterizers/index.tsindex e63f940e12..fc446c6d0b 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/render/rasterizers/index.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/render/rasterizers/index.ts@@ -4,7 +4,7 @@* Given a layer `source`, produces a {@link RasterSurface} holding its* rasterized pixels. `image`, `paint`, `shape`, `gradient`, and `text` are* implemented. A `polygon` shape (no points-editing UX yet) throws — the- * dispatch only routes rect/ellipse.+ * dispatch only routes parametric (non-polygon).** Zero React, zero import-time side effects.*/diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/render/rasterizers/shapeRasterizer.test.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/render/rasterizers/shapeRasterizer.test.tsindex 7bb3f000f2..7e03e4103a 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/render/rasterizers/shapeRasterizer.test.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/render/rasterizers/shapeRasterizer.test.ts@@ -99,6 +99,31 @@ describe('rasterizeShapeSource — ellipse', () => {});});+describe('rasterizeShapeSource — triangle and star', () => {+ it('draws a closed three-vertex path for the triangle kind', async () => {+ const deps = makeDeps();+ const surface = (await rasterizeShapeSource(rect({ fill: '#abcdef', kind: 'triangle' }), deps))+ .surface as StubRasterSurface;+ const log = ops(surface);+ expect(log).toContain('moveTo');+ expect(log.filter((op) => op === 'lineTo')).toHaveLength(2);+ expect(log).toContain('closePath');+ expect(log).toContain('fill');+ });++ it('draws a closed ten-vertex path for the star kind and strokes with round joins', async () => {+ const deps = makeDeps();+ const surface = (+ await rasterizeShapeSource(rect({ fill: null, kind: 'star', stroke: '#123456', strokeWidth: 4 }), deps)+ ).surface as StubRasterSurface;+ const log = ops(surface);+ expect(log.filter((op) => op === 'lineTo')).toHaveLength(9);+ expect(log).toContain('closePath');+ expect(log).toContain('stroke');+ expect((surface.ctx as unknown as { lineJoin: string }).lineJoin).toBe('round');+ });+});+describe('rasterizeShapeSource — target reuse', () => {it('resizes and reuses a provided target surface', async () => {const deps = makeDeps();diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/render/rasterizers/shapeRasterizer.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/render/rasterizers/shapeRasterizer.tsindex 225aacbee5..a013a2e9dd 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/render/rasterizers/shapeRasterizer.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/render/rasterizers/shapeRasterizer.ts@@ -1,5 +1,6 @@/**- * Rasterizes a `shape` layer source (rect / ellipse). Shape layers are+ * Rasterizes a `shape` layer source (rect / ellipse / triangle / star). Shape+ * layers are* PARAMETRIC: their pixels are derived from the source params (`width`,* `height`, `fill`, `stroke`, `strokeWidth`, `kind`) rather than a persisted* bitmap, so they re-render for free whenever a param changes.@@ -18,7 +19,7 @@* Zero React, zero import-time side effects.*/-import type { CanvasLayerSourceContract } from '@workbench/canvas-engine/contracts';+import type { CanvasLayerSourceContract, ParametricShapeKind } from '@workbench/canvas-engine/contracts';import type { RasterSurface } from '@workbench/canvas-engine/render/raster';import type { RasterizeDeps, RasterizeResult } from './types';@@ -26,19 +27,69 @@ import type { RasterizeDeps, RasterizeResult } from './types';type ShapeSource = Extract<CanvasLayerSourceContract, { type: 'shape' }>;type Ctx = RasterSurface['ctx'];-/** Builds the rect/ellipse path for `kind` inset by `inset` on every side into the current path. */-const buildShapePath = (ctx: Ctx, kind: ShapeSource['kind'], width: number, height: number, inset: number): void => {+/** Pentagram inner/outer radius ratio: sin(18°) / sin(54°). */+const STAR_INNER_RATIO = 0.382;+const STAR_SPIKES = 5;++/**+ * Builds the parametric path for `kind` into an `x/y + width×height` box inset+ * by `inset` on every side. Shared by the rasterizer and the drag-preview+ * outline so a committed shape lands exactly where its preview drew. Sharp+ * kinds (triangle, star) are stroked with round joins, so a half-stroke-width+ * inset genuinely contains the outline. The inset path is a box RESCALE, not a+ * uniform offset: on slanted edges a thick stroke drifts slightly outside the+ * fill silhouette — accepted (the ellipse's radius-shrink has the same class+ * of error), revisit only if design objects.+ */+export const buildParametricShapePath = (+ ctx: Ctx,+ kind: ParametricShapeKind | 'polygon',+ x: number,+ y: number,+ width: number,+ height: number,+ inset: number+): void => {const w = Math.max(0, width - inset * 2);const h = Math.max(0, height - inset * 2);+ const cx = x + width / 2;+ const cy = y + height / 2;ctx.beginPath();if (kind === 'ellipse') {- ctx.ellipse(width / 2, height / 2, w / 2, h / 2, 0, 0, Math.PI * 2);+ ctx.ellipse(cx, cy, w / 2, h / 2, 0, 0, Math.PI * 2);+ return;+ }+ if (kind === 'triangle') {+ ctx.moveTo(cx, cy - h / 2);+ ctx.lineTo(cx + w / 2, cy + h / 2);+ ctx.lineTo(cx - w / 2, cy + h / 2);+ ctx.closePath();+ return;+ }+ if (kind === 'star') {+ const rx = w / 2;+ const ry = h / 2;+ for (let i = 0; i < STAR_SPIKES * 2; i += 1) {+ const radius = i % 2 === 0 ? 1 : STAR_INNER_RATIO;+ const angle = -Math.PI / 2 + (i * Math.PI) / STAR_SPIKES;+ const px = cx + Math.cos(angle) * rx * radius;+ const py = cy + Math.sin(angle) * ry * radius;+ if (i === 0) {+ ctx.moveTo(px, py);+ } else {+ ctx.lineTo(px, py);+ }+ }+ ctx.closePath();return;}// `rect` (and, defensively, `polygon` which the dispatch never sends here).- ctx.rect(inset, inset, w, h);+ ctx.rect(x + inset, y + inset, w, h);};+const buildShapePath = (ctx: Ctx, kind: ShapeSource['kind'], width: number, height: number, inset: number): void =>+ buildParametricShapePath(ctx, kind, 0, 0, width, height, inset);+/*** Draws a shape source onto a surface sized to the source extent. Reuses* `target` if provided (resizing it to the extent), matching the paint/image@@ -70,6 +121,10 @@ export const rasterizeShapeSource = (if (source.stroke && source.strokeWidth > 0) {ctx.strokeStyle = source.stroke;ctx.lineWidth = source.strokeWidth;+ // Round joins keep sharp vertices within the half-stroke inset (a miter+ // would spike past it); a rect keeps its miter — the 90° tip lands exactly+ // on the extent corner, and rounding it would re-render every stored rect.+ ctx.lineJoin = source.kind === 'triangle' || source.kind === 'star' ? 'round' : 'miter';// Inset by half the stroke width so the (centered) stroke stays inside the extent.buildShapePath(ctx, source.kind, width, height, source.strokeWidth / 2);ctx.stroke();diff --git a/invokeai/frontend/webv2/src/workbench/canvasMigration.test.ts b/invokeai/frontend/webv2/src/workbench/canvasMigration.test.tsindex 330a833550..50508fb25c 100644--- a/invokeai/frontend/webv2/src/workbench/canvasMigration.test.ts+++ b/invokeai/frontend/webv2/src/workbench/canvasMigration.test.ts@@ -119,6 +119,18 @@ describe('loadCanvasState', () => {expect(badLayer?.type === 'raster' ? badLayer.inpaint : null).toBeUndefined();});+ it('round-trips triangle and star shape sources', () => {+ const shape = (kind: string) => ({+ ...createEmptyPaintLayer(kind, kind),+ source: { fill: '#ff0000', height: 10, kind, stroke: null, strokeWidth: 0, type: 'shape', width: 10 },+ });+ const loaded = load(withNodes([shape('triangle'), shape('star')]));+ const kinds = loaded.document.stacks.raster.map((layer) =>+ layer.type === 'raster' && layer.source.type === 'shape' ? layer.source.kind : null+ );+ expect(kinds).toEqual(['triangle', 'star']);+ });+it('round-trips group adjustments in the raster stack, strips them from overlay groups, and drops a malformed group stack', () => {const stack = [{ brightness: 0.1, contrast: 0, id: 'ga1', isEnabled: true, type: 'brightness-contrast' }];const rasterGroup = {diff --git a/invokeai/frontend/webv2/src/workbench/canvasMigration.ts b/invokeai/frontend/webv2/src/workbench/canvasMigration.tsindex 13e4cdd0b1..018e2decc0 100644--- a/invokeai/frontend/webv2/src/workbench/canvasMigration.ts+++ b/invokeai/frontend/webv2/src/workbench/canvasMigration.ts@@ -59,7 +59,7 @@ const zLayerSource = z.discriminatedUnion('type', [z.object({fill: z.string().nullable(),height: zFiniteNumber,- kind: z.enum(['rect', 'ellipse', 'polygon']),+ kind: z.enum(['rect', 'ellipse', 'triangle', 'star', 'polygon']),points: z.array(zCoordinate).optional(),stroke: z.string().nullable(),strokeWidth: zFiniteNumber,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.tsxindex cff581e954..f7f85feb48 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@@ -60,7 +60,12 @@ const useShapeEditor = (engine: ToolFormProps['engine']) => {},(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;+ // Polygon shapes (no tool kind) display as rect; every parametric kind passes through.+ const kind: ShapeKind = selected+ ? selected.source.kind === 'polygon'+ ? 'rect'+ : selected.source.kind+ : options.kind;const fill = selected ? selected.source.fill : options.fillEnabled ? pair.foreground : null;const stroke = selected ? selected.source.stroke : options.strokeEnabled ? pair.background : null;const strokeWidth = selected ? selected.source.strokeWidth : options.strokeWidth;@@ -160,6 +165,8 @@ const ShapeSettings = ({ engine }: ToolFormProps) => {() => [{ label: t('widgets.canvas.toolOptions.shapeRect'), value: 'rect' as const },{ label: t('widgets.canvas.toolOptions.shapeEllipse'), value: 'ellipse' as const },+ { label: t('widgets.canvas.toolOptions.shapeTriangle'), value: 'triangle' as const },+ { label: t('widgets.canvas.toolOptions.shapeStar'), value: 'star' as const },],[t]);diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersTree.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersTree.browser.test.tsxindex 08a621d43a..4e20e34c05 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersTree.browser.test.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersTree.browser.test.tsx@@ -552,13 +552,26 @@ describe('LayersTree selection, surfaces and structure', () => {await new Promise<void>((resolve) => {setTimeout(resolve, 120);});- const scrolled = scroller.scrollTop;- expect(scrolled).toBeGreaterThan(0);+ expect(scroller.scrollTop).toBeGreaterThan(0);await act(() => pointer('pointermove', document, start.x, rect.top + rect.height / 2));+ // A queued edge-band tick may still land after the move, so the invariant+ // is that scrolling STOPS: wait for scrollTop to hold still, then assert+ // it stays put — not that it equals a value captured mid-flight.+ let settled = scroller.scrollTop;+ for (let attempt = 0; attempt < 20; attempt += 1) {+ await new Promise<void>((resolve) => {+ setTimeout(resolve, 30);+ });+ const next = scroller.scrollTop;+ if (next === settled) {+ break;+ }+ settled = next;+ }await new Promise<void>((resolve) => {setTimeout(resolve, 60);});- expect(scroller.scrollTop).toBe(scrolled);+ expect(scroller.scrollTop).toBe(settled);const checks = refusalChecks.mock.calls.length;await act(() => pointer('pointerup', document, start.x, rect.top + rect.height / 2));expect(checks).toBeLessThanOrEqual(6);diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerContextActions.ts b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerContextActions.tsindex 6b83728c28..6ca28a0a9f 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerContextActions.ts+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerContextActions.ts@@ -291,11 +291,7 @@ const hasFilterableLayerContent = (context: LayerContextActionState): boolean =>if (context.layer.type !== 'raster') {return false;}- return (- source.type === 'text' ||- source.type === 'gradient' ||- (source.type === 'shape' && (source.kind === 'rect' || source.kind === 'ellipse'))- );+ return source.type === 'text' || source.type === 'gradient' || (source.type === 'shape' && source.kind !== 'polygon');};/** Where the layer sits among its siblings (index 0 = top), or null when absent. */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.tsxindex 8a394f017c..ce78ad334c 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@@ -325,6 +325,8 @@ describe('Properties pane', () => {// 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 expect.element(page.getByRole('radio', { exact: true, name: 'Triangle' })).toBeInTheDocument();+ await expect.element(page.getByRole('radio', { exact: true, name: 'Star' })).toBeInTheDocument();await act(() => root?.unmount());await mount(PropertiesPane, 'shape');