AI-native design editor. Open-source Figma alternative.
Add stroke align, individual side strokes, and side selector UI
Danila Poyarkovc412b78ed8d6
diff --git a/packages/core/src/kiwi-serialize.ts b/packages/core/src/kiwi-serialize.tsindex 384c02903..506ddf0d5 100644--- a/packages/core/src/kiwi-serialize.ts+++ b/packages/core/src/kiwi-serialize.ts@@ -211,7 +211,15 @@ export function sceneNodeToKiwi(size: { x: node.width, y: node.height },transform: { m00: cos * sx, m01: -sin, m02: node.x, m10: sin * sx, m11: cos, m12: node.y },strokeWeight: node.strokes.length > 0 ? node.strokes[0].weight : 1,- strokeAlign: 'INSIDE'+ strokeAlign: node.strokes.length > 0 ? node.strokes[0].align : 'INSIDE'+ }++ if (node.independentStrokeWeights) {+ nc.borderStrokeWeightsIndependent = true+ nc.borderTopWeight = node.borderTopWeight+ nc.borderRightWeight = node.borderRightWeight+ nc.borderBottomWeight = node.borderBottomWeight+ nc.borderLeftWeight = node.borderLeftWeight}if (fillPaints.length > 0) nc.fillPaints = fillPaintsdiff --git a/packages/core/src/renderer.ts b/packages/core/src/renderer.tsindex 7cf4898c5..017c4d72f 100644--- a/packages/core/src/renderer.ts+++ b/packages/core/src/renderer.ts@@ -1174,7 +1174,7 @@ export class SkiaRenderer {this.fillPaint.setShader(null)}- // Stroke+ // Stroke — sections use a fixed corner radius, not node.cornerRadiusfor (let si = 0; si < node.strokes.length; si++) {const stroke = node.strokes[si]!if (!stroke.visible) continue@@ -1182,7 +1182,12 @@ export class SkiaRenderer {this.strokePaint.setColor(this.ck.Color4f(sc.r, sc.g, sc.b, sc.a))this.strokePaint.setStrokeWidth(stroke.weight)this.strokePaint.setAlphaf(stroke.opacity)- canvas.drawRRect(rrect, this.strokePaint)++ if (node.independentStrokeWeights) {+ this.drawIndividualSideStrokes(canvas, node, stroke.align)+ } else {+ this.drawRRectStrokeWithAlign(canvas, rrect, node, stroke)+ }}}@@ -1506,7 +1511,11 @@ export class SkiaRenderer {this.strokePaint.setPathEffect(null)}- this.drawNodeStroke(canvas, node, rect, hasRadius)+ if (node.independentStrokeWeights && this.isRectangularType(node.type)) {+ this.drawIndividualSideStrokes(canvas, node, stroke.align)+ } else {+ this.drawStrokeWithAlign(canvas, node, rect, hasRadius, stroke.align)+ }}// Effects (front: inner shadow, blur)@@ -1589,6 +1598,163 @@ export class SkiaRenderer {}}+ private drawRRectStrokeWithAlign(+ canvas: Canvas,+ rrect: Float32Array,+ node: SceneNode,+ stroke: Stroke+ ): void {+ if (stroke.align === 'INSIDE') {+ canvas.save()+ canvas.clipRRect(rrect, this.ck.ClipOp.Intersect, true)+ this.strokePaint.setStrokeWidth(stroke.weight * 2)+ canvas.drawRRect(rrect, this.strokePaint)+ this.strokePaint.setStrokeWidth(stroke.weight)+ canvas.restore()+ } else if (stroke.align === 'OUTSIDE') {+ canvas.save()+ const outerPath = new this.ck.Path()+ outerPath.addRect(+ this.ck.LTRBRect(-node.width, -node.height, node.width * 2, node.height * 2)+ )+ const innerPath = new this.ck.Path()+ innerPath.addRRect(rrect)+ outerPath.op(innerPath, this.ck.PathOp.Difference)+ innerPath.delete()+ canvas.clipPath(outerPath, this.ck.ClipOp.Intersect, true)+ outerPath.delete()+ this.strokePaint.setStrokeWidth(stroke.weight * 2)+ canvas.drawRRect(rrect, this.strokePaint)+ this.strokePaint.setStrokeWidth(stroke.weight)+ canvas.restore()+ } else {+ canvas.drawRRect(rrect, this.strokePaint)+ }+ }++ private isRectangularType(type: string): boolean {+ return (+ type === 'FRAME' ||+ type === 'RECTANGLE' ||+ type === 'ROUNDED_RECTANGLE' ||+ type === 'COMPONENT' ||+ type === 'INSTANCE' ||+ type === 'SECTION' ||+ type === 'GROUP'+ )+ }++ private drawStrokeWithAlign(+ canvas: Canvas,+ node: SceneNode,+ rect: Float32Array,+ hasRadius: boolean,+ align: 'INSIDE' | 'CENTER' | 'OUTSIDE'+ ): void {+ if (align === 'INSIDE') {+ canvas.save()+ this.clipNodeShape(canvas, node, rect, hasRadius)+ const origWidth = this.strokePaint.getStrokeWidth()+ this.strokePaint.setStrokeWidth(origWidth * 2)+ this.drawNodeStroke(canvas, node, rect, hasRadius)+ this.strokePaint.setStrokeWidth(origWidth)+ canvas.restore()+ } else if (align === 'OUTSIDE') {+ canvas.save()+ const bigRect = this.ck.LTRBRect(+ -node.width,+ -node.height,+ node.width * 2,+ node.height * 2+ )+ const outerPath = new this.ck.Path()+ outerPath.addRect(bigRect)+ const innerPath = this.makeNodeShapePath(node, rect, hasRadius)+ outerPath.op(innerPath, this.ck.PathOp.Difference)+ innerPath.delete()+ canvas.clipPath(outerPath, this.ck.ClipOp.Intersect, true)+ outerPath.delete()+ const origWidth = this.strokePaint.getStrokeWidth()+ this.strokePaint.setStrokeWidth(origWidth * 2)+ this.drawNodeStroke(canvas, node, rect, hasRadius)+ this.strokePaint.setStrokeWidth(origWidth)+ canvas.restore()+ } else {+ this.drawNodeStroke(canvas, node, rect, hasRadius)+ }+ }++ private makeNodeShapePath(+ node: SceneNode,+ rect: Float32Array,+ hasRadius: boolean+ ): Path {+ const path = new this.ck.Path()+ switch (node.type) {+ case 'ELLIPSE':+ path.addOval(rect)+ break+ case 'VECTOR': {+ const vp = this.getVectorPath(node)+ if (vp) path.addPath(vp)+ break+ }+ case 'POLYGON':+ case 'STAR': {+ const polyPath = this.makePolygonPath(node)+ path.addPath(polyPath)+ polyPath.delete()+ break+ }+ default:+ if (hasRadius) {+ path.addRRect(this.makeRRect(node))+ } else {+ path.addRect(rect)+ }+ }+ return path+ }++ private drawIndividualSideStrokes(+ canvas: Canvas,+ node: SceneNode,+ align: 'INSIDE' | 'CENTER' | 'OUTSIDE'+ ): void {+ const w = node.width+ const h = node.height+ const inside = align === 'INSIDE'+ const outside = align === 'OUTSIDE'++ const tw = node.borderTopWeight+ if (tw > 0) {+ const y = inside ? tw / 2 : outside ? -tw / 2 : 0+ this.strokePaint.setStrokeWidth(tw)+ canvas.drawLine(0, y, w, y, this.strokePaint)+ }++ const rw = node.borderRightWeight+ if (rw > 0) {+ const x = inside ? w - rw / 2 : outside ? w + rw / 2 : w+ this.strokePaint.setStrokeWidth(rw)+ canvas.drawLine(x, 0, x, h, this.strokePaint)+ }++ const bw = node.borderBottomWeight+ if (bw > 0) {+ const y = inside ? h - bw / 2 : outside ? h + bw / 2 : h+ this.strokePaint.setStrokeWidth(bw)+ canvas.drawLine(0, y, w, y, this.strokePaint)+ }++ const lw = node.borderLeftWeight+ if (lw > 0) {+ const x = inside ? lw / 2 : outside ? -lw / 2 : 0+ this.strokePaint.setStrokeWidth(lw)+ canvas.drawLine(x, 0, x, h, this.strokePaint)+ }+ }+private makePolygonPath(node: SceneNode): Path {const path = new this.ck.Path()const cx = node.width / 2diff --git a/packages/core/src/scene-graph.ts b/packages/core/src/scene-graph.tsindex 2f21edbad..86c65538e 100644--- a/packages/core/src/scene-graph.ts+++ b/packages/core/src/scene-graph.ts@@ -890,7 +890,12 @@ export class SceneGraph {'paddingRight','paddingBottom','paddingLeft',- 'clipsContent'+ 'clipsContent',+ 'independentStrokeWeights',+ 'borderTopWeight',+ 'borderRightWeight',+ 'borderBottomWeight',+ 'borderLeftWeight']private static copyProp<K extends keyof SceneNode>(diff --git a/src/components/properties/StrokeSection.vue b/src/components/properties/StrokeSection.vueindex 7823bfd31..3ff3ec062 100644--- a/src/components/properties/StrokeSection.vue+++ b/src/components/properties/StrokeSection.vue@@ -1,12 +1,23 @@<script setup lang="ts">-import { computed } from 'vue'+import { computed, ref } from 'vue'+import AppSelect from '@/components/AppSelect.vue'import ColorInput from '@/components/ColorInput.vue'import ScrubInput from '@/components/ScrubInput.vue'import { useNodeProps } from '@/composables/use-node-props'import { useMultiProps } from '@/composables/use-multi-props'+import {+ DropdownMenuRoot,+ DropdownMenuTrigger,+ DropdownMenuContent,+ DropdownMenuItem,+ DropdownMenuPortal+} from 'reka-ui'import type { Color, Stroke } from '@/engine/scene-graph'+import type { SceneNode } from '@/engine/scene-graph'++type StrokeSides = 'ALL' | 'TOP' | 'BOTTOM' | 'LEFT' | 'RIGHT' | 'CUSTOM'const { store } = useNodeProps()const { nodes, isMulti, active, activeNode } = useMultiProps()@@ -18,6 +29,40 @@ const strokesAreMixed = computed(() => {return all.some((n) => JSON.stringify(n.strokes) !== first)})+const ALIGN_OPTIONS: { value: Stroke['align']; label: string }[] = [+ { value: 'INSIDE', label: 'Inside' },+ { value: 'CENTER', label: 'Center' },+ { value: 'OUTSIDE', label: 'Outside' }+]++const currentAlign = computed<Stroke['align']>(() => {+ const n = activeNode.value+ if (!n || n.strokes.length === 0) return 'CENTER'+ return n.strokes[0].align+})++const currentSides = computed<StrokeSides>(() => {+ const n = activeNode.value+ if (!n || !n.independentStrokeWeights) return 'ALL'+ const { borderTopWeight: t, borderRightWeight: r, borderBottomWeight: b, borderLeftWeight: l } = n+ const active = [t > 0, r > 0, b > 0, l > 0]+ const count = active.filter(Boolean).length+ if (count === 4 && t === r && r === b && b === l) return 'ALL'+ if (count === 1) {+ if (t > 0) return 'TOP'+ if (b > 0) return 'BOTTOM'+ if (l > 0) return 'LEFT'+ if (r > 0) return 'RIGHT'+ }+ return 'CUSTOM'+})++const hasStrokes = computed(+ () => !strokesAreMixed.value && (activeNode.value?.strokes?.length ?? 0) > 0+)++const sideMenuOpen = ref(false)+function updateColor(index: number, color: Color) {for (const n of isMulti.value ? nodes.value : [activeNode.value]) {if (!n) continue@@ -45,6 +90,14 @@ function updateOpacity(index: number, opacity: number) {}}+function updateAlign(align: Stroke['align']) {+ for (const n of isMulti.value ? nodes.value : [activeNode.value]) {+ if (!n) continue+ const strokes = n.strokes.map((s) => ({ ...s, align }))+ store.updateNodeWithUndo(n.id, { strokes }, 'Change stroke align')+ }+}+function toggleVisibility(index: number) {for (const n of isMulti.value ? nodes.value : [activeNode.value]) {if (!n) continue@@ -84,18 +137,183 @@ function remove(index: number) {)}}++function selectSide(side: StrokeSides) {+ for (const n of isMulti.value ? nodes.value : [activeNode.value]) {+ if (!n) continue+ const weight = n.strokes.length > 0 ? n.strokes[0].weight : 1+ if (side === 'ALL') {+ store.updateNodeWithUndo(+ n.id,+ {+ independentStrokeWeights: false,+ borderTopWeight: 0,+ borderRightWeight: 0,+ borderBottomWeight: 0,+ borderLeftWeight: 0+ } as Partial<SceneNode>,+ 'Stroke all sides'+ )+ } else if (side === 'CUSTOM') {+ const current = n.independentStrokeWeights+ ? {+ top: n.borderTopWeight,+ right: n.borderRightWeight,+ bottom: n.borderBottomWeight,+ left: n.borderLeftWeight+ }+ : { top: weight, right: weight, bottom: weight, left: weight }+ store.updateNodeWithUndo(+ n.id,+ {+ independentStrokeWeights: true,+ borderTopWeight: current.top,+ borderRightWeight: current.right,+ borderBottomWeight: current.bottom,+ borderLeftWeight: current.left+ } as Partial<SceneNode>,+ 'Custom stroke sides'+ )+ } else {+ store.updateNodeWithUndo(+ n.id,+ {+ independentStrokeWeights: true,+ borderTopWeight: side === 'TOP' ? weight : 0,+ borderRightWeight: side === 'RIGHT' ? weight : 0,+ borderBottomWeight: side === 'BOTTOM' ? weight : 0,+ borderLeftWeight: side === 'LEFT' ? weight : 0+ } as Partial<SceneNode>,+ `Stroke ${side.toLowerCase()} only`+ )+ }+ }+ sideMenuOpen.value = false+}++function updateBorderWeight(side: 'top' | 'right' | 'bottom' | 'left', value: number) {+ const fieldMap = {+ top: 'borderTopWeight',+ right: 'borderRightWeight',+ bottom: 'borderBottomWeight',+ left: 'borderLeftWeight'+ } as const+ for (const n of isMulti.value ? nodes.value : [activeNode.value]) {+ if (!n) continue+ store.updateNodeWithUndo(+ n.id,+ { [fieldMap[side]]: value } as Partial<SceneNode>,+ 'Change stroke weight'+ )+ }+}++const SIDE_OPTIONS: { value: StrokeSides; label: string }[] = [+ { value: 'ALL', label: 'All' },+ { value: 'TOP', label: 'Top' },+ { value: 'BOTTOM', label: 'Bottom' },+ { value: 'LEFT', label: 'Left' },+ { value: 'RIGHT', label: 'Right' },+ { value: 'CUSTOM', label: 'Custom' }+]++const BORDER_SIDES = ['top', 'right', 'bottom', 'left'] as const++const borderWeights = computed(() => {+ const n = activeNode.value+ return {+ top: n?.borderTopWeight ?? 0,+ right: n?.borderRightWeight ?? 0,+ bottom: n?.borderBottomWeight ?? 0,+ left: n?.borderLeftWeight ?? 0+ }+})</script><template><div v-if="active" class="border-b border-border px-3 py-2"><div class="flex items-center justify-between"><label class="mb-1 block text-[11px] text-muted">Stroke</label>- <button- class="flex size-5 cursor-pointer items-center justify-center rounded border-none bg-transparent text-sm leading-none text-muted hover:bg-hover hover:text-surface"- @click="add"- >- +- </button>+ <div class="flex items-center gap-0.5">+ <DropdownMenuRoot v-model:open="sideMenuOpen">+ <DropdownMenuTrigger as-child>+ <button+ v-if="hasStrokes"+ class="flex size-5 cursor-pointer items-center justify-center rounded border-none bg-transparent text-muted hover:bg-hover hover:text-surface"+ title="Stroke sides"+ >+ <svg+ class="size-3.5"+ viewBox="0 0 14 14"+ fill="none"+ stroke="currentColor"+ stroke-width="1.5"+ >+ <rect x="1" y="1" width="12" height="12" rx="1" />+ </svg>+ </button>+ </DropdownMenuTrigger>+ <DropdownMenuPortal>+ <DropdownMenuContent+ :side-offset="4"+ align="end"+ class="z-50 min-w-[140px] rounded-md border border-border bg-panel p-0.5 shadow-lg"+ >+ <DropdownMenuItem+ v-for="opt in SIDE_OPTIONS"+ :key="opt.value"+ class="relative flex cursor-pointer items-center gap-2 rounded px-2 py-1.5 text-xs text-surface outline-none data-[highlighted]:bg-hover"+ @click="selectSide(opt.value)"+ >+ <icon-lucide-check+ v-if="currentSides === opt.value"+ class="absolute left-2 size-3 text-accent"+ />+ <span class="flex items-center gap-2 pl-5">+ <!-- Side indicator icons -->+ <svg+ class="size-3.5"+ viewBox="0 0 14 14"+ fill="none"+ stroke="currentColor"+ stroke-width="1.5"+ >+ <template v-if="opt.value === 'ALL'">+ <rect x="1" y="1" width="12" height="12" rx="1" />+ </template>+ <template v-else-if="opt.value === 'CUSTOM'">+ <line x1="4" y1="7" x2="10" y2="7" />+ <line x1="7" y1="4" x2="7" y2="10" />+ </template>+ <template v-else>+ <rect+ x="1"+ y="1"+ width="12"+ height="12"+ rx="1"+ stroke-opacity="0.3"+ stroke-dasharray="2 2"+ />+ <line v-if="opt.value === 'TOP'" x1="1" y1="1" x2="13" y2="1" />+ <line v-else-if="opt.value === 'BOTTOM'" x1="1" y1="13" x2="13" y2="13" />+ <line v-else-if="opt.value === 'LEFT'" x1="1" y1="1" x2="1" y2="13" />+ <line v-else-if="opt.value === 'RIGHT'" x1="13" y1="1" x2="13" y2="13" />+ </template>+ </svg>+ <span>{{ opt.label }}</span>+ </span>+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenuPortal>+ </DropdownMenuRoot>+ <button+ class="flex size-5 cursor-pointer items-center justify-center rounded border-none bg-transparent text-sm leading-none text-muted hover:bg-hover hover:text-surface"+ @click="add"+ >+ ++ </button>+ </div></div><p v-if="strokesAreMixed" class="text-[11px] text-muted">Click + to replace mixed strokes</p><div@@ -126,17 +344,81 @@ function remove(index: number) {−</button></div>++ <!-- Stroke details row -->+ <div v-if="hasStrokes" class="mt-1 flex items-center gap-1.5">+ <AppSelect+ class="w-[72px]"+ :model-value="currentAlign"+ :options="ALIGN_OPTIONS"+ @update:model-value="updateAlign($event as Stroke['align'])"+ />+ <ScrubInput+ v-if="!activeNode?.independentStrokeWeights"+ class="flex-1"+ :model-value="activeNode?.strokes[0]?.weight ?? 1"+ :min="0"+ @update:model-value="updateWeight(0, $event)"+ >+ <template #icon>+ <svg+ class="size-3"+ viewBox="0 0 12 12"+ fill="none"+ stroke="currentColor"+ stroke-width="1.5"+ >+ <rect x="1" y="4" width="10" height="4" rx="0.5" />+ </svg>+ </template>+ </ScrubInput>+ </div>++ <!-- Individual side weights --><div- v-if="!strokesAreMixed && (activeNode?.strokes?.length ?? 0) > 0"- class="mt-1 flex items-center gap-1.5"+ v-if="hasStrokes && activeNode?.independentStrokeWeights"+ class="mt-1.5 grid grid-cols-2 gap-1.5"><ScrubInput- class="w-16"- icon="W"- :model-value="activeNode?.strokes[0].weight ?? 1"+ v-for="side in BORDER_SIDES"+ :key="side"+ :model-value="borderWeights[side]":min="0"- @update:model-value="updateWeight(0, $event)"- />+ @update:model-value="updateBorderWeight(side, $event)"+ >+ <template #icon>+ <svg class="size-3" viewBox="0 0 12 12" fill="none" stroke-width="1.5">+ <rect+ x="1"+ y="1"+ width="10"+ height="10"+ rx="1"+ stroke="currentColor"+ stroke-opacity="0.3"+ stroke-dasharray="2 2"+ />+ <line v-if="side === 'top'" x1="1" y1="1" x2="11" y2="1" stroke="currentColor" />+ <line+ v-else-if="side === 'right'"+ x1="11"+ y1="1"+ x2="11"+ y2="11"+ stroke="currentColor"+ />+ <line+ v-else-if="side === 'bottom'"+ x1="1"+ y1="11"+ x2="11"+ y2="11"+ stroke="currentColor"+ />+ <line v-else x1="1" y1="1" x2="1" y2="11" stroke="currentColor" />+ </svg>+ </template>+ </ScrubInput></div></div></template>diff --git a/tests/engine/individual-strokes.test.ts b/tests/engine/individual-strokes.test.tsnew file mode 100644index 000000000..32d668b0f--- /dev/null+++ b/tests/engine/individual-strokes.test.ts@@ -0,0 +1,352 @@+import { describe, test, expect } from 'bun:test'++import { SceneGraph } from '../../packages/core/src/scene-graph'+import { FigmaAPI } from '../../packages/core/src/figma-api'+import { sceneNodeToKiwi } from '../../packages/core/src/kiwi-serialize'++import type { Stroke } from '../../packages/core/src/scene-graph'++function pageId(graph: SceneGraph) {+ return graph.getPages()[0].id+}++function rectWithStroke(+ graph: SceneGraph,+ name: string,+ strokeOverrides: Partial<Stroke> = {}+) {+ const stroke: Stroke = {+ color: { r: 0, g: 0, b: 0, a: 1 },+ weight: 2,+ opacity: 1,+ visible: true,+ align: 'CENTER',+ ...strokeOverrides+ }+ return graph.createNode('RECTANGLE', pageId(graph), {+ name,+ x: 0,+ y: 0,+ width: 100,+ height: 100,+ strokes: [stroke]+ })+}++describe('Stroke align', () => {+ test('default stroke align is stored per stroke', () => {+ const graph = new SceneGraph()+ const node = rectWithStroke(graph, 'R')+ expect(node.strokes[0].align).toBe('CENTER')+ })++ test('stroke align can be set to INSIDE', () => {+ const graph = new SceneGraph()+ const node = rectWithStroke(graph, 'R', { align: 'INSIDE' })+ expect(node.strokes[0].align).toBe('INSIDE')+ })++ test('stroke align can be set to OUTSIDE', () => {+ const graph = new SceneGraph()+ const node = rectWithStroke(graph, 'R', { align: 'OUTSIDE' })+ expect(node.strokes[0].align).toBe('OUTSIDE')+ })++ test('updating stroke align preserves other stroke properties', () => {+ const graph = new SceneGraph()+ const node = rectWithStroke(graph, 'R', { weight: 5, align: 'CENTER' })+ const strokes = [...node.strokes]+ strokes[0] = { ...strokes[0], align: 'INSIDE' }+ graph.updateNode(node.id, { strokes })++ const updated = graph.getNode(node.id)!+ expect(updated.strokes[0].align).toBe('INSIDE')+ expect(updated.strokes[0].weight).toBe(5)+ expect(updated.strokes[0].color).toEqual({ r: 0, g: 0, b: 0, a: 1 })+ })+})++describe('Individual stroke weights', () => {+ test('default independentStrokeWeights is false', () => {+ const graph = new SceneGraph()+ const node = graph.createNode('RECTANGLE', pageId(graph), { name: 'R' })+ expect(node.independentStrokeWeights).toBe(false)+ expect(node.borderTopWeight).toBe(0)+ expect(node.borderRightWeight).toBe(0)+ expect(node.borderBottomWeight).toBe(0)+ expect(node.borderLeftWeight).toBe(0)+ })++ test('enable independent stroke weights', () => {+ const graph = new SceneGraph()+ const node = rectWithStroke(graph, 'R')+ graph.updateNode(node.id, {+ independentStrokeWeights: true,+ borderTopWeight: 2,+ borderRightWeight: 0,+ borderBottomWeight: 4,+ borderLeftWeight: 0+ })++ const updated = graph.getNode(node.id)!+ expect(updated.independentStrokeWeights).toBe(true)+ expect(updated.borderTopWeight).toBe(2)+ expect(updated.borderRightWeight).toBe(0)+ expect(updated.borderBottomWeight).toBe(4)+ expect(updated.borderLeftWeight).toBe(0)+ })++ test('disable independent stroke weights', () => {+ const graph = new SceneGraph()+ const node = rectWithStroke(graph, 'R')+ graph.updateNode(node.id, {+ independentStrokeWeights: true,+ borderTopWeight: 2,+ borderRightWeight: 3,+ borderBottomWeight: 4,+ borderLeftWeight: 5+ })+ graph.updateNode(node.id, {+ independentStrokeWeights: false,+ borderTopWeight: 0,+ borderRightWeight: 0,+ borderBottomWeight: 0,+ borderLeftWeight: 0+ })++ const updated = graph.getNode(node.id)!+ expect(updated.independentStrokeWeights).toBe(false)+ })++ test('single side: top only', () => {+ const graph = new SceneGraph()+ const node = rectWithStroke(graph, 'R')+ graph.updateNode(node.id, {+ independentStrokeWeights: true,+ borderTopWeight: 3,+ borderRightWeight: 0,+ borderBottomWeight: 0,+ borderLeftWeight: 0+ })++ const updated = graph.getNode(node.id)!+ expect(updated.borderTopWeight).toBe(3)+ expect(updated.borderRightWeight).toBe(0)+ expect(updated.borderBottomWeight).toBe(0)+ expect(updated.borderLeftWeight).toBe(0)+ })++ test('individual weights are independent from stroke weight', () => {+ const graph = new SceneGraph()+ const node = rectWithStroke(graph, 'R', { weight: 10 })+ graph.updateNode(node.id, {+ independentStrokeWeights: true,+ borderTopWeight: 1,+ borderRightWeight: 2,+ borderBottomWeight: 3,+ borderLeftWeight: 4+ })++ const updated = graph.getNode(node.id)!+ expect(updated.strokes[0].weight).toBe(10)+ expect(updated.borderTopWeight).toBe(1)+ expect(updated.borderRightWeight).toBe(2)+ expect(updated.borderBottomWeight).toBe(3)+ expect(updated.borderLeftWeight).toBe(4)+ })+})++describe('Instance sync with stroke weights', () => {+ test('syncInstances propagates independentStrokeWeights', () => {+ const graph = new SceneGraph()+ const comp = graph.createNode('COMPONENT', pageId(graph), {+ name: 'Comp',+ strokes: [+ {+ color: { r: 1, g: 0, b: 0, a: 1 },+ weight: 2,+ opacity: 1,+ visible: true,+ align: 'INSIDE'+ }+ ],+ independentStrokeWeights: true,+ borderTopWeight: 3,+ borderRightWeight: 0,+ borderBottomWeight: 3,+ borderLeftWeight: 0+ })++ const instance = graph.createInstance(comp.id, pageId(graph))!+ expect(instance.independentStrokeWeights).toBe(true)+ expect(instance.borderTopWeight).toBe(3)+ expect(instance.borderBottomWeight).toBe(3)++ graph.updateNode(comp.id, { borderTopWeight: 5 })+ graph.syncInstances(comp.id)++ const synced = graph.getNode(instance.id)!+ expect(synced.borderTopWeight).toBe(5)+ })+})++describe('Kiwi serialization', () => {+ test('exports stroke align from first stroke', () => {+ const graph = new SceneGraph()+ const node = rectWithStroke(graph, 'R', { align: 'OUTSIDE' })++ const blobs: Uint8Array[] = []+ const changes = sceneNodeToKiwi(+ node,+ { sessionID: 1, localID: 0 },+ 0,+ { value: 100 },+ graph,+ blobs+ )++ expect(changes[0].strokeAlign).toBe('OUTSIDE')+ })++ test('exports default CENTER align', () => {+ const graph = new SceneGraph()+ const node = rectWithStroke(graph, 'R')++ const blobs: Uint8Array[] = []+ const changes = sceneNodeToKiwi(+ node,+ { sessionID: 1, localID: 0 },+ 0,+ { value: 100 },+ graph,+ blobs+ )++ expect(changes[0].strokeAlign).toBe('CENTER')+ })++ test('exports individual stroke weights', () => {+ const graph = new SceneGraph()+ const node = rectWithStroke(graph, 'R')+ graph.updateNode(node.id, {+ independentStrokeWeights: true,+ borderTopWeight: 1,+ borderRightWeight: 2,+ borderBottomWeight: 3,+ borderLeftWeight: 4+ })++ const updated = graph.getNode(node.id)!+ const blobs: Uint8Array[] = []+ const changes = sceneNodeToKiwi(+ updated,+ { sessionID: 1, localID: 0 },+ 0,+ { value: 100 },+ graph,+ blobs+ ) as Record<string, unknown>[]++ expect(changes[0].borderStrokeWeightsIndependent).toBe(true)+ expect(changes[0].borderTopWeight).toBe(1)+ expect(changes[0].borderRightWeight).toBe(2)+ expect(changes[0].borderBottomWeight).toBe(3)+ expect(changes[0].borderLeftWeight).toBe(4)+ })++ test('does not export individual weights when disabled', () => {+ const graph = new SceneGraph()+ const node = rectWithStroke(graph, 'R')++ const blobs: Uint8Array[] = []+ const changes = sceneNodeToKiwi(+ node,+ { sessionID: 1, localID: 0 },+ 0,+ { value: 100 },+ graph,+ blobs+ ) as Record<string, unknown>[]++ expect(changes[0].borderStrokeWeightsIndependent).toBeUndefined()+ expect(changes[0].borderTopWeight).toBeUndefined()+ })+})++describe('FigmaAPI stroke properties', () => {+ test('strokeTopWeight sets independentStrokeWeights', () => {+ const api = new FigmaAPI(new SceneGraph())+ const rect = api.createRectangle()+ rect.strokes = [+ {+ color: { r: 0, g: 0, b: 0, a: 1 },+ weight: 2,+ opacity: 1,+ visible: true,+ align: 'CENTER'+ }+ ]+ rect.strokeTopWeight = 5++ const raw = api.graph.getNode(rect.id)!+ expect(raw.independentStrokeWeights).toBe(true)+ expect(raw.borderTopWeight).toBe(5)+ })++ test('strokeBottomWeight getter returns borderBottomWeight', () => {+ const api = new FigmaAPI(new SceneGraph())+ const frame = api.createFrame()+ api.graph.updateNode(frame.id, { borderBottomWeight: 7 })+ expect(frame.strokeBottomWeight).toBe(7)+ })++ test('strokeAlign getter returns first stroke align', () => {+ const api = new FigmaAPI(new SceneGraph())+ const rect = api.createRectangle()+ rect.strokes = [+ {+ color: { r: 0, g: 0, b: 0, a: 1 },+ weight: 2,+ opacity: 1,+ visible: true,+ align: 'INSIDE'+ }+ ]+ expect(rect.strokeAlign).toBe('INSIDE')+ })++ test('strokeAlign setter updates stroke', () => {+ const api = new FigmaAPI(new SceneGraph())+ const rect = api.createRectangle()+ rect.strokes = [+ {+ color: { r: 0, g: 0, b: 0, a: 1 },+ weight: 2,+ opacity: 1,+ visible: true,+ align: 'CENTER'+ }+ ]+ rect.strokeAlign = 'OUTSIDE'++ const raw = api.graph.getNode(rect.id)!+ expect(raw.strokes[0].align).toBe('OUTSIDE')+ })++ test('all four individual stroke weight setters', () => {+ const api = new FigmaAPI(new SceneGraph())+ const frame = api.createFrame()+ frame.strokeTopWeight = 1+ frame.strokeRightWeight = 2+ frame.strokeBottomWeight = 3+ frame.strokeLeftWeight = 4++ expect(frame.strokeTopWeight).toBe(1)+ expect(frame.strokeRightWeight).toBe(2)+ expect(frame.strokeBottomWeight).toBe(3)+ expect(frame.strokeLeftWeight).toBe(4)++ const raw = api.graph.getNode(frame.id)!+ expect(raw.independentStrokeWeights).toBe(true)+ })+})