AI-native design editor. Open-source Figma alternative.
fix: flatten layers into regions with their own fills, as Figma does (#1663)
Danila Poyarkovdd15cea5eae3
diff --git a/changes/1663/fixed.md b/changes/1663/fixed.mdnew file mode 100644index 000000000..5e66f0cef--- /dev/null+++ b/changes/1663/fixed.md@@ -0,0 +1 @@+- Flatten keeps each layer's fill on its own part of the vector and gives it the topmost layer's stroke, as Figma does, instead of filling everything with the first layer's fill and turning strokes into shape.diff --git a/packages/core/src/canvas/boolean.ts b/packages/core/src/canvas/boolean.tsindex 4c7055712..e2f6e06fb 100644--- a/packages/core/src/canvas/boolean.ts+++ b/packages/core/src/canvas/boolean.ts@@ -18,7 +18,7 @@ import {normalizeDashPattern,withStrokeDash} from './strokes'-import { makeLineStrokeOutline } from './strokes/line'+import { makeLineSegmentPath, makeLineStrokeOutline } from './strokes/line'import { textNodeToOutlinePath } from './text/outlines'const BOOLEAN_PATH_OP: Record<@@ -361,6 +361,22 @@ export function makeBooleanSourcePath(return operandPath(r, node, pieces)}+/**+ * A layer's own geometry as Flatten keeps it, its stroke left a stroke (live-verified): a shape's+ * outline, a vector's paths open ones included, a line's segment, text's glyphs, or a boolean+ * operation's result.+ */+export function flattenSourcePath(+ r: SkiaRenderer,+ node: SceneNode,+ graph: SceneGraph+): Path | null {+ if (node.type === 'BOOLEAN_OPERATION') return makeBooleanOperationPath(r, node, graph)+ if (!canMakeBooleanSourcePath(node)) return null+ if (node.type === 'LINE') return makeLineSegmentPath(r, node)+ return strokeSourcePath(r, node)+}+function transformedShapePath(r: SkiaRenderer, child: SceneNode, graph: SceneGraph): Path | null {const path = makeBooleanSourcePath(r, child, graph)if (!path) return nulldiff --git a/packages/core/src/canvas/flatten.ts b/packages/core/src/canvas/flatten.tsindex 13a8f5f86..e8fe9c4e8 100644--- a/packages/core/src/canvas/flatten.ts+++ b/packages/core/src/canvas/flatten.ts@@ -1,54 +1,142 @@import type { Path } from 'canvaskit-wasm'+import { isEqual } from 'es-toolkit'import type { SceneGraph, SceneNode, VectorNetwork } from '@open-pencil/scene-graph'import { getNodeLocalMatrix } from '@open-pencil/scene-graph/coordinate'-import { copyFills } from '@open-pencil/scene-graph/copy'+import { copyFills, copyStrokes } from '@open-pencil/scene-graph/copy'+import Matrix from '@open-pencil/scene-graph/matrix'import { parseSVGPath } from '@open-pencil/scene-graph/parse-path'import type { Rect, Vector } from '@open-pencil/scene-graph/primitives'import { mergeVectorNetworks } from '@open-pencil/scene-graph/vector-network'-import { makeBooleanSourcePath, placedPath, windingRuleOf } from './boolean'+import {+ canContainFlattenableChildren,+ flattenSourcePath,+ placedPath,+ windingRuleOf+} from './boolean'import type { SkiaRenderer } from './renderer'+/** The stroke a flattened vector takes from its topmost shape. */+type StrokeFields =+ | 'strokes'+ | 'strokeWeight'+ | 'strokeAlign'+ | 'strokeCap'+ | 'strokeJoin'+ | 'strokeMiterLimit'+ | 'dashPattern'+export type VectorFlattenProps = Pick<SceneNode,- 'name' | 'x' | 'y' | 'width' | 'height' | 'fills' | 'vectorNetwork'+ 'name' | 'x' | 'y' | 'width' | 'height' | 'fills' | 'vectorNetwork' | StrokeFields>-type NodePathFactory = (- renderer: SkiaRenderer,- graph: SceneGraph,+/** A shape Flatten takes, and where it sits in the flattened layers' parent. */+interface FlattenLeaf {node: SceneNode-) => ReturnType<typeof makeBooleanSourcePath>+ matrix: number[]+}-function nodesToVectorProps(+/**+ * The shapes Flatten takes from `nodes`, bottom first: a frame, group, component or instance+ * gives its visible children, never its own paint (live-verified).+ */+function flattenLeaves(graph: SceneGraph, nodes: SceneNode[]): FlattenLeaf[] {+ const leaves: FlattenLeaf[] = []+ const visit = (node: SceneNode, parent: number[]) => {+ const matrix = Matrix.multiply(parent, getNodeLocalMatrix(node))+ if (!canContainFlattenableChildren(node)) {+ leaves.push({ node, matrix })+ return+ }+ for (const childId of node.childIds) {+ const child = graph.getNode(childId)+ if (child?.visible) visit(child, matrix)+ }+ }+ for (const node of nodes) visit(node, Matrix.identity())+ return leaves+}++/**+ * Layers in one parent in the order they are drawn: Flatten stacks their regions so, whatever the+ * selection's. Layers from several parents, which the Plugin API allows, keep the caller's order.+ */+function inDrawOrder(graph: SceneGraph, nodes: SceneNode[]): SceneNode[] {+ const parentId = nodes[0]?.parentId+ const parent = parentId ? graph.getNode(parentId) : undefined+ if (!parent || nodes.some((node) => node.parentId !== parentId)) return nodes+ return nodes.toSorted((a, b) => parent.childIds.indexOf(a.id) - parent.childIds.indexOf(b.id))+}++/**+ * The vector Flatten makes of `nodes`, as Figma's does (live-verified): each shape's own geometry,+ * its regions filled with its fills, and the topmost shape's stroke. Shapes that all fill alike+ * leave their regions to the layer's fills.+ */+export function flattenNodesToVectorProps(renderer: SkiaRenderer,graph: SceneGraph,- nodes: SceneNode[],- makeNodePath: NodePathFactory+ nodes: SceneNode[]): VectorFlattenProps | null {- const placed: Path[] = []+ const leaves = flattenLeaves(graph, inDrawOrder(graph, nodes))+ const placed: { node: SceneNode; path: Path }[] = []try {- for (const node of nodes) {- const nodePath = makeNodePath(renderer, graph, node)- if (!nodePath) return null- placed.push(placedPath(renderer, nodePath, getNodeLocalMatrix(node)))- nodePath.delete()+ for (const { node, matrix } of leaves) {+ const path = flattenSourcePath(renderer, node, graph)+ if (!path) return null+ placed.push({ node, path: placedPath(renderer, path, matrix) })+ path.delete()}- const drawn = placed.filter((path) => !path.isEmpty())- const box = boundsOf(drawn)- if (!box) return null+ const drawn = placed.filter(({ path }) => !path.isEmpty())+ const box = boundsOf(drawn.map(({ path }) => path))+ const top = leaves.at(-1)?.node+ if (!box || !top) return null+ const networks = drawn.map(({ node, path }) => ({+ node,+ network: networkIn(renderer, path, box)+ }))+ const filled = networks.filter(({ network }) => network.regions.length > 0)+ const alike = filled.every(({ node }) => isEqual(node.fills, filled[0].node.fills))return {name: 'Flatten',...box,- fills: copyFills(nodes[0].fills),- vectorNetwork: mergeVectorNetworks(drawn.map((path) => networkIn(renderer, path, box)))+ fills: copyFills((alike ? filled.at(0)?.node : undefined)?.fills ?? top.fills),+ vectorNetwork: mergeVectorNetworks(+ networks.map(({ node, network }) => (alike ? network : withRegionFills(network, node)))+ ),+ ...topStroke(top)}} finally {- for (const path of placed) path.delete()+ for (const { path } of placed) path.delete()}}+/** `network` with every region filled with `node`'s fills. */+function withRegionFills(network: VectorNetwork, node: SceneNode): VectorNetwork {+ return {+ ...network,+ regions: network.regions.map((region) => ({ ...region, fills: copyFills(node.fills) }))+ }+}++function topStroke(node: SceneNode): Pick<SceneNode, StrokeFields> {+ return {+ strokes: copyStrokes(node.strokes),+ strokeWeight: node.strokeWeight,+ strokeAlign: node.strokeAlign,+ strokeCap: node.strokeCap,+ strokeJoin: node.strokeJoin,+ strokeMiterLimit: node.strokeMiterLimit,+ dashPattern: [...node.dashPattern]+ }+}++/**+ * The box around `paths`; a straight line keeps a zero side, and a round-capped line no longer+ * than its weight, which its caps draw as a dot, a zero box.+ */function boundsOf(paths: Path[]): Rect | null {if (paths.length === 0) return nullconst all = paths.map((path) => path.getBounds())@@ -56,7 +144,6 @@ function boundsOf(paths: Path[]): Rect | null {const top = Math.min(...all.map((bounds) => bounds[1]))const right = Math.max(...all.map((bounds) => bounds[2]))const bottom = Math.max(...all.map((bounds) => bounds[3]))- if (right <= left || bottom <= top) return nullreturn { x: left, y: top, width: right - left, height: bottom - top }}@@ -66,13 +153,3 @@ function networkIn(renderer: SkiaRenderer, path: Path, box: Vector): VectorNetwomoved.delete()return network}--export function flattenNodesToVectorProps(- renderer: SkiaRenderer,- graph: SceneGraph,- nodes: SceneNode[]-): VectorFlattenProps | null {- return nodesToVectorProps(renderer, graph, nodes, (r, g, node) =>- makeBooleanSourcePath(r, node, g)- )-}diff --git a/packages/core/src/canvas/strokes/line.ts b/packages/core/src/canvas/strokes/line.tsindex 554a0ab67..a8f811017 100644--- a/packages/core/src/canvas/strokes/line.ts+++ b/packages/core/src/canvas/strokes/line.ts@@ -71,14 +71,32 @@ export function drawLineStroke(drawArrowHeads(r, canvas, heads, stroke.weight, color, stroke.opacity)}+/** The weight and cap a LINE is stroked with: its first visible stroke's. */+function lineStroke(node: SceneNode): { weight: number; cap: StrokeCap } {+ const stroke = node.strokes.find((item) => item.visible)+ return { weight: stroke?.weight ?? 1, cap: stroke?.cap ?? node.strokeCap }+}++/**+ * A LINE as Flatten keeps it: the segment its stroke is drawn along, to one side and inside its+ * caps by half a weight each, so the stroke it keeps lies where it did (live-measured). A line+ * shorter than its weight reverses, as in Figma.+ */+export function makeLineSegmentPath(r: SkiaRenderer, node: SceneNode): Path {+ const { weight, cap } = lineStroke(node)+ const { start, end } = lineStrokeEnds(node.width, node.height, weight, cap, true)+ const segment = new r.ck.PathBuilder()+ segment.moveTo(start.x, start.y)+ segment.lineTo(end.x, end.y)+ return segment.detachAndDelete()+}+/**- * The outline of a LINE's first visible stroke, as booleans and flattening take it: its shaft, its- * caps, and its heads, without dashes.+ * The outline of a LINE's first visible stroke, as booleans take it: its shaft, its caps, and+ * its heads, without dashes.*/export function makeLineStrokeOutline(r: SkiaRenderer, node: SceneNode): Path | null {- const stroke = node.strokes.find((item) => item.visible)- const weight = stroke?.weight ?? 1- const cap = stroke?.cap ?? node.strokeCap+ const { weight, cap } = lineStroke(node)const { network, from, to } = lineStrokePath(node, weight, cap)const shaft = new r.ck.PathBuilder()shaft.moveTo(from.x, from.y)diff --git a/packages/core/src/editor/structure/flatten.ts b/packages/core/src/editor/structure/flatten.tsindex dd08b00b5..1632c1f7c 100644--- a/packages/core/src/editor/structure/flatten.ts+++ b/packages/core/src/editor/structure/flatten.ts@@ -39,11 +39,7 @@ export function flattenSelected(const vectorProps = vectorPropsFactory(renderer, ctx.graph, topLevel)if (!vectorProps) return null- const vector = ctx.graph.createNode('VECTOR', parentId, {- ...vectorProps,- name: label,- strokes: []- })+ const vector = ctx.graph.createNode('VECTOR', parentId, { ...vectorProps, name: label })const vectorSnapshot = structuredClone(vector)ctx.graph.insertChildAt(vector.id, parentId, firstIndex)for (const id of childIds) ctx.graph.deleteNode(id)diff --git a/packages/core/tests/canvas/strokes/line.test.ts b/packages/core/tests/canvas/strokes/line.test.tsindex 3a04fd2ce..55f978fa7 100644--- a/packages/core/tests/canvas/strokes/line.test.ts+++ b/packages/core/tests/canvas/strokes/line.test.ts@@ -115,7 +115,7 @@ describe('a line stroke', () => {})})-// Booleans and flattening take a line as its stroke outline: Figma's stroke geometry for a 300 px+// Booleans take a line as its stroke outline (Flatten keeps its segment): Figma's stroke geometry for a 300 px// line with a 6 px stroke and triangle heads spans x 3 to 297 and y -20.32 to 14.32.describe('a line taken as a boolean operand', () => {test('keeps its heads and the shaft between them', () => {diff --git a/packages/core/tests/editor/structure/flatten.test.ts b/packages/core/tests/editor/structure/flatten.test.tsindex 8777b5a01..dee62f31b 100644--- a/packages/core/tests/editor/structure/flatten.test.ts+++ b/packages/core/tests/editor/structure/flatten.test.ts@@ -6,6 +6,7 @@ import { BLACK, TRANSPARENT } from '@open-pencil/core/constants'import { initCanvasKit } from '@open-pencil/core/io/formats/raster'import { fontManager } from '@open-pencil/core/text'import { vectorNetworkToPath } from '@open-pencil/core/vector'+import type { SceneGraph, SceneNode } from '@open-pencil/scene-graph'import { textNodeToOutlineLayout } from '#core/text/outlines'@@ -105,14 +106,17 @@ describe('flattenSelected', () => {expect([vector?.x, vector?.y, vector?.width, vector?.height]).toEqual([50, 22, 8, 8])})- test('keeps the shape an outside stroke surrounds empty', async () => {+ // Figma keeps a flattened layer's stroke a stroke: the shape is the ellipse alone.+ test('keeps an outside stroke a stroke, around the bare shape', async () => {const { editor } = await createEditorWithRenderer()const solid = { type: 'SOLID' as const, color: BLACK, opacity: 1, visible: true }const ellipse = editor.graph.createNode('ELLIPSE', editor.state.currentPageId, {width: 120,height: 70,fills: [{ ...solid, visible: false }],- strokes: [{ ...solid, weight: 4, align: 'OUTSIDE' as const }]+ strokes: [{ ...solid, weight: 4, align: 'OUTSIDE' as const }],+ strokeWeight: 4,+ strokeAlign: 'OUTSIDE'})editor.select([ellipse.id])@@ -121,9 +125,12 @@ describe('flattenSelected', () => {const vector = editor.graph.getNode([...editor.state.selectedIds][0])const network = vector?.vectorNetworkif (!vector || !network) throw new Error('Expected a flattened vector')+ expect([vector.x, vector.y, vector.width, vector.height]).toEqual([0, 0, 120, 70])+ expect([vector.strokeWeight, vector.strokeAlign, vector.strokes.length]).toEqual([4, 'OUTSIDE', 1])+ expect(vector.fills.map((fill) => fill.visible)).toEqual([false])const [path] = vectorNetworkToPath(await initCanvasKit(), network)- expect(path?.contains(60 - vector.x, 35 - vector.y)).toBe(false)- expect(path?.contains(60 - vector.x, -2 - vector.y)).toBe(true)+ expect(path?.contains(60, 35)).toBe(true)+ expect(path?.contains(60, -2)).toBe(false)path?.delete()})@@ -368,7 +375,7 @@ describe('flattenSelected', () => {expect(editor.graph.getNode(groupId)).toBeUndefined()})- test('includes stroke-only rectangles as flattenable outlines', async () => {+ test('flattens a stroke-only rectangle to its outline, its stroke kept a stroke', async () => {const { editor } = await createEditorWithRenderer()const pageId = editor.state.currentPageIdconst rect = editor.graph.createNode('RECTANGLE', pageId, {@@ -388,8 +395,146 @@ describe('flattenSelected', () => {const [vectorId] = [...editor.state.selectedIds]const vector = editor.graph.getNode(vectorId)expect(vector?.type).toBe('VECTOR')- expect(vector?.width).toBeGreaterThan(50)- expect(vector?.height).toBeGreaterThan(40)+ expect([vector?.width, vector?.height]).toEqual([50, 40])+ expect(vector?.strokes.map((stroke) => stroke.weight)).toEqual([8])+ })++ // Live-verified in Figma: each shape fills its own regions, stacked in layer order whatever+ // the selection's; the vector takes the topmost shape's stroke.+ describe("as Figma's Flatten", () => {+ const paint = (r: number, g: number, b: number) => ({+ type: 'SOLID' as const,+ color: { r, g, b, a: 1 },+ opacity: 1,+ visible: true+ })+ const RED = paint(1, 0, 0)+ const BLUE = paint(0, 0, 1)+ const regionColors = (vector: SceneNode | undefined) =>+ vector?.vectorNetwork?.regions.map((region) => region.fills?.map((fill) => fill.color))++ async function flattened(build: (graph: SceneGraph, pageId: string) => SceneNode[]) {+ const { editor } = await createEditorWithRenderer()+ editor.select(build(editor.graph, editor.state.currentPageId).map((node) => node.id))+ editor.flattenSelected()+ return editor.graph.getNode([...editor.state.selectedIds][0])+ }++ test("fills each shape's region with its fills and takes the top shape's stroke", async () => {+ const vector = await flattened((graph, pageId) => {+ const red = graph.createNode('RECTANGLE', pageId, {+ width: 20,+ height: 20,+ fills: [RED],+ strokes: [{ ...paint(1, 1, 0), weight: 2, align: 'CENTER' }],+ strokeWeight: 2+ })+ const blue = graph.createNode('RECTANGLE', pageId, {+ x: 40,+ width: 20,+ height: 20,+ fills: [BLUE],+ strokes: [{ ...paint(0, 1, 1), weight: 6, align: 'OUTSIDE' }],+ strokeWeight: 6,+ strokeAlign: 'OUTSIDE'+ })+ return [blue, red]+ })+ expect(regionColors(vector)).toEqual([[RED.color], [BLUE.color]])+ expect(vector?.strokes.map((stroke) => stroke.color)).toEqual([paint(0, 1, 1).color])+ expect([vector?.strokeWeight, vector?.strokeAlign]).toEqual([6, 'OUTSIDE'])+ })++ test('leaves the regions to the layer fill when every shape fills alike', async () => {+ const vector = await flattened((graph, pageId) => [+ graph.createNode('RECTANGLE', pageId, { width: 20, height: 20, fills: [RED] }),+ graph.createNode('RECTANGLE', pageId, { x: 40, width: 20, height: 20, fills: [RED] })+ ])+ expect(regionColors(vector)).toEqual([undefined, undefined])+ expect(vector?.fills.map((fill) => fill.color)).toEqual([RED.color])+ })++ test("takes a frame's shapes with their fills, never the frames' own", async () => {+ const vector = await flattened((graph, pageId) => {+ const frame = graph.createNode('FRAME', pageId, { width: 80, height: 60, fills: [paint(0, 1, 0)] })+ const inner = graph.createNode('FRAME', frame.id, { width: 40, height: 40, fills: [paint(1, 1, 0)] })+ graph.createNode('RECTANGLE', inner.id, { width: 20, height: 20, fills: [RED] })+ graph.createNode('RECTANGLE', frame.id, { x: 50, width: 20, height: 20, fills: [BLUE] })+ return [frame]+ })+ expect(regionColors(vector)).toEqual([[RED.color], [BLUE.color]])+ })++ // Figma: a 40 px line at (50, 20) with an 8 px stroke flattens to the segment its stroke is+ // drawn along, half a weight up, and inside a round cap: (54, 16), 32 long.+ test.each([+ ['NONE', 50, 40],+ ['ROUND', 54, 32]+ ] as const)('keeps a line where its %s-capped stroke lay', async (cap, x, width) => {+ const vector = await flattened((graph, pageId) => [+ graph.createNode('LINE', pageId, {+ x: 50,+ y: 20,+ width: 40,+ height: 0,+ strokes: [{ ...RED, weight: 8, align: 'CENTER', cap }],+ strokeWeight: 8,+ strokeCap: cap+ })+ ])+ expect([vector?.x, vector?.y, vector?.width, vector?.height]).toEqual([x, 16, width, 0])+ })++ test('keeps a line that runs down its height', async () => {+ const vector = await flattened((graph, pageId) => [+ graph.createNode('LINE', pageId, {+ width: 0,+ height: 40,+ strokes: [{ ...RED, weight: 2, align: 'CENTER' }]+ })+ ])+ expect(vector?.type).toBe('VECTOR')+ expect([vector?.width, vector?.height]).toEqual([0, 40])+ expect(vector?.vectorNetwork?.segments).toHaveLength(1)+ })++ // Figma insets each end by half the weight even past the middle: a 6 px line under an 8 px+ // round cap flattens to a 2 px segment from x 54 back to 52.+ test('reverses a round-capped line shorter than its weight, as Figma does', async () => {+ const vector = await flattened((graph, pageId) => [+ graph.createNode('LINE', pageId, {+ x: 50,+ y: 20,+ width: 6,+ height: 0,+ strokes: [{ ...RED, weight: 8, align: 'CENTER', cap: 'ROUND' }],+ strokeWeight: 8,+ strokeCap: 'ROUND'+ })+ ])+ expect([vector?.x, vector?.y, vector?.width, vector?.height]).toEqual([52, 16, 2, 0])+ expect(vector?.vectorNetwork?.vertices.map(({ x, y }) => [x, y])).toEqual([+ [2, 0],+ [0, 0]+ ])+ expect(vector?.strokeCap).toBe('ROUND')+ })++ test("keeps a line as an open segment, under the top shape's stroke", async () => {+ const vector = await flattened((graph, pageId) => [+ graph.createNode('LINE', pageId, {+ width: 40,+ height: 0,+ strokes: [{ ...RED, weight: 4, align: 'CENTER' }],+ strokeWeight: 4+ }),+ graph.createNode('RECTANGLE', pageId, { x: 60, width: 20, height: 20, fills: [BLUE] })+ ])+ expect(vector?.vectorNetwork?.regions).toHaveLength(1)+ expect(vector?.vectorNetwork?.segments).toHaveLength(5)+ expect(vector?.fills.map((fill) => fill.color)).toEqual([BLUE.color])+ expect(vector?.strokes).toEqual([])+ })})test('undo and redo restore flattened children and vector', async () => {diff --git a/packages/core/tests/figma-api/flatten.test.ts b/packages/core/tests/figma-api/flatten.test.tsindex a2475edc1..96a98fc13 100644--- a/packages/core/tests/figma-api/flatten.test.ts+++ b/packages/core/tests/figma-api/flatten.test.ts@@ -52,4 +52,27 @@ describe('FigmaAPI renderer-backed flatten', () => {expect(api.getNodeById(first.id)).toBeNull()surface.delete()})++ // The Plugin API takes layers from several parents; they stack in the order it is given them.+ test('stacks layers from several parents in the order given', async () => {+ const api = createAPI()+ const { renderer, surface } = await createRenderer()+ api.setRenderer(renderer)+ const solid = (r: number, b: number) => ({ type: 'SOLID' as const, color: { r, g: 0, b } })+ const frame = api.createFrame()+ const inFrame = api.createRectangle()+ frame.appendChild(inFrame)+ inFrame.fills = [solid(1, 0)]+ const onPage = api.createRectangle()+ onPage.x = 200+ onPage.fills = [solid(0, 1)]++ const vector = api.flatten([inFrame, onPage], api.currentPage)+ const regions = api.graph.getNode(vector.id)?.vectorNetwork?.regions+ expect(regions?.map((region) => region.fills?.[0]?.color)).toEqual([+ { r: 1, g: 0, b: 0, a: 1 },+ { r: 0, g: 0, b: 1, a: 1 }+ ])+ surface.delete()+ })})diff --git a/packages/docs/development/vector-conversion.md b/packages/docs/development/vector-conversion.mdindex c55b58255..c3fd595e5 100644--- a/packages/docs/development/vector-conversion.md+++ b/packages/docs/development/vector-conversion.md@@ -10,7 +10,7 @@ OpenPencil has a shared path-conversion pipeline for commands that turn scene no## Commands- **Boolean operations** keep a live `BOOLEAN_OPERATION` container and render it with CanvasKit path operations.-- **Flatten** replaces selected supported nodes with one persistent `VECTOR` node.+- **Flatten** replaces selected supported nodes with one persistent `VECTOR` node, as Figma's does: each shape keeps its own geometry (a line its segment, text its glyphs) and fills its own regions with its fills, stacked in layer order, and the vector takes the topmost shape's stroke. Strokes stay strokes rather than becoming shape.- **Outline text** replaces selected supported text nodes with vector outlines.- **Outline stroke** replaces selected supported stroked nodes with vector stroke outlines.@@ -18,7 +18,7 @@ The editor, renderer-backed Figma API, and menu command enablement all use the s## Supported sources-Supported sources include basic shapes, vectors, lines, nested boolean operations, and visual descendants inside groups, frames, components, and instances. Containers contribute their visible descendants, and their own fill/stroke if present.+Supported sources include basic shapes, vectors, lines, nested boolean operations, and visual descendants inside groups, frames, components, and instances. Containers contribute their visible descendants, never their own fill or stroke, as in Figma.Text can be converted when all required font data is loaded. The outline engine supports multiline text, horizontal and vertical alignment, letter spacing, style runs, and loaded fallback glyphs for mixed-font text such as Latin plus CJK.diff --git a/packages/scene-graph/src/arrow-caps.ts b/packages/scene-graph/src/arrow-caps.tsindex 538781d23..610d0bc88 100644--- a/packages/scene-graph/src/arrow-caps.ts+++ b/packages/scene-graph/src/arrow-caps.ts@@ -346,7 +346,9 @@ export function lineStrokeEnds(width: number,height: number,weight: number,- cap: StrokeCap | undefined+ cap: StrokeCap | undefined,+ // Flatten insets a full half weight even past the middle, reversing a short line (live-measured).+ insetPastMiddle = false): { start: Vector; end: Vector } {const length = Math.hypot(width, height)if (length === 0) return { start: { x: 0, y: 0 }, end: { x: 0, y: 0 } }@@ -355,7 +357,7 @@ export function lineStrokeEnds(const inset =cap === undefined || cap === 'NONE' || cap === 'ARROW_EQUILATERAL'? 0- : Math.min(weight, length) / 2+ : (insetPastMiddle ? weight : Math.min(weight, length)) / 2const offset = { x: (uy * weight) / 2, y: (-ux * weight) / 2 }return {start: { x: ux * inset + offset.x, y: uy * inset + offset.y },