AI-native design editor. Open-source Figma alternative.
Multi-selection properties panel with tests
Danila Poyarkov7e06969ab532
diff --git a/.github/workflows/build.yml b/.github/workflows/build.ymlindex 059fa63e5..532960d08 100644--- a/.github/workflows/build.yml+++ b/.github/workflows/build.yml@@ -111,6 +111,10 @@ jobs:env:NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}run: |+ cat > ~/.npmrc << EOF+ //registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}+ EOF+publish_if_new() {local dir=$1local name=$(node -p "require('./$dir/package.json').name")@@ -118,7 +122,7 @@ jobs:if npm view "${name}@${version}" version 2>/dev/null; thenecho "${name}@${version} already published, skipping"else- npm publish "./$dir" --provenance --access public+ npm publish "./$dir" --access publicfi}publish_if_new packages/corediff --git a/packages/core/src/kiwi-serialize.ts b/packages/core/src/kiwi-serialize.tsindex 9b06e35ce..384c02903 100644--- a/packages/core/src/kiwi-serialize.ts+++ b/packages/core/src/kiwi-serialize.ts@@ -171,8 +171,8 @@ export function sceneNodeToKiwi(const localID = localIdCounter.value++const guid = { sessionID: 1, localID }const sx = node.flipX ? -1 : 1- const cos = Math.cos((node.rotation * Math.PI) / 180) * sx- const sin = Math.sin((node.rotation * Math.PI) / 180) * sx+ const cos = Math.cos((node.rotation * Math.PI) / 180)+ const sin = Math.sin((node.rotation * Math.PI) / 180)const fillPaints = node.fills.map((f) => {const paint: Paint = {@@ -209,7 +209,7 @@ export function sceneNodeToKiwi(opacity: node.opacity,phase: 'CREATED',size: { x: node.width, y: node.height },- transform: { m00: cos, m01: -sin, m02: node.x, m10: sin, m11: cos, m12: node.y },+ 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'}diff --git a/src/components/DesignPanel.vue b/src/components/DesignPanel.vueindex 7e0eec094..195c69066 100644--- a/src/components/DesignPanel.vue+++ b/src/components/DesignPanel.vue@@ -33,7 +33,11 @@ const isComponentType = computed(() => {<span class="text-[11px] text-muted">Mixed</span><span class="text-xs font-semibold">{{ multiCount }} layers</span></div>+ <PositionSection /><AppearanceSection />+ <FillSection />+ <StrokeSection />+ <EffectsSection /></div><!-- Single selection -->diff --git a/src/components/ScrubInput.vue b/src/components/ScrubInput.vueindex c893903dd..8e4bb22f8 100644--- a/src/components/ScrubInput.vue+++ b/src/components/ScrubInput.vue@@ -4,7 +4,7 @@ import { useEventListener } from '@vueuse/core'const props = withDefaults(defineProps<{- modelValue: number+ modelValue: number | symbolmin?: numbermax?: numberstep?: number@@ -12,15 +12,19 @@ const props = withDefaults(label?: stringsuffix?: stringsensitivity?: number+ placeholder?: string}>(),{min: -Infinity,max: Infinity,step: 1,- sensitivity: 1+ sensitivity: 1,+ placeholder: 'Mixed'})+const isMixed = computed(() => typeof props.modelValue === 'symbol')+const emit = defineEmits<{'update:modelValue': [value: number]commit: [value: number, previous: number]@@ -33,14 +37,15 @@ const scrubbing = ref(false)let stopMove: (() => void) | undefinedlet stopUp: (() => void) | undefined-const displayValue = computed(() => Math.round(props.modelValue))+const numericValue = computed(() => (isMixed.value ? 0 : (props.modelValue as number)))+const displayValue = computed(() => (isMixed.value ? '' : Math.round(numericValue.value)))function startScrub(e: PointerEvent) {e.preventDefault()const startX = e.clientXlet lastX = startX- let accumulated = props.modelValue- const valueBeforeScrub = props.modelValue+ let accumulated = numericValue.value+ const valueBeforeScrub = numericValue.valuelet hasMoved = falsestopMove = useEventListener(document, 'pointermove', (ev: PointerEvent) => {@@ -84,7 +89,7 @@ function startEdit() {function commitEdit(e: Event) {const val = +(e.target as HTMLInputElement).value- const previous = props.modelValue+ const previous = numericValue.valueif (!Number.isNaN(val)) {const clamped = Math.min(props.max, Math.max(props.min, val))emit('update:modelValue', clamped)@@ -123,7 +128,8 @@ function onKeydown(e: KeyboardEvent) {ref="inputRef"type="number"class="min-w-0 flex-1 cursor-text border-none bg-transparent pr-1.5 font-[inherit] text-xs text-surface outline-none"- :value="displayValue"+ :value="isMixed ? '' : displayValue"+ :placeholder="placeholder":min="min === -Infinity ? undefined : min":max="max === Infinity ? undefined : max":step="step"@@ -134,8 +140,11 @@ function onKeydown(e: KeyboardEvent) {v-elseclass="flex flex-1 select-none items-center truncate pr-1.5 text-xs overflow-hidden">- <span class="flex-1 text-surface">{{ displayValue }}</span>- <span v-if="suffix" class="shrink-0 text-muted">{{ suffix }}</span>+ <span v-if="isMixed" class="flex-1 text-muted">{{ placeholder }}</span>+ <template v-else>+ <span class="flex-1 text-surface">{{ displayValue }}</span>+ <span v-if="suffix" class="shrink-0 text-muted">{{ suffix }}</span>+ </template></span></div></template>diff --git a/src/components/properties/AppearanceSection.vue b/src/components/properties/AppearanceSection.vueindex 0e7c9427d..57284aa78 100644--- a/src/components/properties/AppearanceSection.vue+++ b/src/components/properties/AppearanceSection.vue@@ -3,10 +3,12 @@ import { computed } from 'vue'import ScrubInput from '@/components/ScrubInput.vue'import { useNodeProps } from '@/composables/use-node-props'+import { MIXED, useMultiProps } from '@/composables/use-multi-props'import type { SceneNode } from '@/engine/scene-graph'-const { store, node, updateProp, commitProp } = useNodeProps()+const { store, updateProp, commitProp } = useNodeProps()+const { node, nodes, isMulti, active, merged, updateAllWithUndo } = useMultiProps()const CORNER_RADIUS_TYPES = new Set(['RECTANGLE',@@ -16,73 +18,153 @@ const CORNER_RADIUS_TYPES = new Set(['INSTANCE'])-const hasCornerRadius = computed(() => node.value && CORNER_RADIUS_TYPES.has(node.value.type))+const hasCornerRadius = computed(() => {+ if (isMulti.value) {+ return nodes.value.every((n) => CORNER_RADIUS_TYPES.has(n.type))+ }+ return node.value && CORNER_RADIUS_TYPES.has(node.value.type)+})++const visibilityState = computed(() => {+ const v = merged('visible')+ return v === MIXED ? 'mixed' : v ? 'visible' : 'hidden'+})function toggleVisibility() {- store.updateNodeWithUndo(node.value.id, { visible: !node.value.visible }, 'Toggle visibility')- store.requestRender()+ if (isMulti.value) {+ const allVisible = nodes.value.every((n) => n.visible)+ updateAllWithUndo({ visible: !allVisible }, 'Toggle visibility')+ } else {+ const n = node.value+ if (!n) return+ store.updateNodeWithUndo(n.id, { visible: !n.visible }, 'Toggle visibility')+ store.requestRender()+ }}function toggleIndependentCorners() {- const n = node.value- if (!n) return-- if (n.independentCorners) {- const uniform = n.topLeftRadius- store.updateNodeWithUndo(- n.id,- {- independentCorners: false,- cornerRadius: uniform,- topLeftRadius: uniform,- topRightRadius: uniform,- bottomRightRadius: uniform,- bottomLeftRadius: uniform- } as Partial<SceneNode>,- 'Uniform corner radius'- )+ const target = isMulti.value ? nodes.value[0] : node.value+ if (!target) return++ if (isMulti.value) {+ for (const n of nodes.value) {+ if (n.independentCorners) {+ const uniform = n.topLeftRadius+ store.updateNodeWithUndo(+ n.id,+ {+ independentCorners: false,+ cornerRadius: uniform,+ topLeftRadius: uniform,+ topRightRadius: uniform,+ bottomRightRadius: uniform,+ bottomLeftRadius: uniform+ } as Partial<SceneNode>,+ 'Uniform corner radius'+ )+ } else {+ store.updateNodeWithUndo(+ n.id,+ {+ independentCorners: true,+ topLeftRadius: n.cornerRadius,+ topRightRadius: n.cornerRadius,+ bottomRightRadius: n.cornerRadius,+ bottomLeftRadius: n.cornerRadius+ } as Partial<SceneNode>,+ 'Independent corner radii'+ )+ }+ }+ store.requestRender()} else {- store.updateNodeWithUndo(- n.id,- {- independentCorners: true,- topLeftRadius: n.cornerRadius,- topRightRadius: n.cornerRadius,- bottomRightRadius: n.cornerRadius,- bottomLeftRadius: n.cornerRadius- } as Partial<SceneNode>,- 'Independent corner radii'- )+ const n = node.value+ if (!n) return+ if (n.independentCorners) {+ const uniform = n.topLeftRadius+ store.updateNodeWithUndo(+ n.id,+ {+ independentCorners: false,+ cornerRadius: uniform,+ topLeftRadius: uniform,+ topRightRadius: uniform,+ bottomRightRadius: uniform,+ bottomLeftRadius: uniform+ } as Partial<SceneNode>,+ 'Uniform corner radius'+ )+ } else {+ store.updateNodeWithUndo(+ n.id,+ {+ independentCorners: true,+ topLeftRadius: n.cornerRadius,+ topRightRadius: n.cornerRadius,+ bottomRightRadius: n.cornerRadius,+ bottomLeftRadius: n.cornerRadius+ } as Partial<SceneNode>,+ 'Independent corner radii'+ )+ }}}function updateCornerProp(key: string, value: number) {- store.updateNode(node.value.id, { [key]: value })+ if (isMulti.value) {+ for (const n of nodes.value) store.updateNode(n.id, { [key]: value })+ } else {+ const n = node.value+ if (n) store.updateNode(n.id, { [key]: value })+ }}function commitCornerProp(key: string, value: number, previous: number) {- store.commitNodeUpdate(node.value.id, { [key]: previous } as Partial<SceneNode>, `Change ${key}`)+ if (isMulti.value) {+ for (const n of nodes.value) {+ store.commitNodeUpdate(n.id, { [key]: previous } as Partial<SceneNode>, `Change ${key}`)+ }+ } else {+ const n = node.value+ if (n) store.commitNodeUpdate(n.id, { [key]: previous } as Partial<SceneNode>, `Change ${key}`)+ }}++const independentCorners = computed(() => {+ if (isMulti.value) return merged('independentCorners')+ return node.value?.independentCorners ?? false+})++const opacityValue = computed(() => {+ const v = merged('opacity')+ return v === MIXED ? MIXED : Math.round((v as number) * 100)+})++const cornerRadiusValue = computed(() => {+ if (isMulti.value) return merged('cornerRadius')+ return node.value?.cornerRadius ?? 0+})</script><template>- <div v-if="node" class="border-b border-border px-3 py-2">+ <div v-if="active" class="border-b border-border px-3 py-2"><div class="mb-1.5 flex items-center justify-between"><label class="text-[11px] text-muted">Appearance</label><buttonclass="flex cursor-pointer items-center justify-center rounded border-none bg-transparent p-0.5 text-muted hover:bg-hover hover:text-surface"- :class="{ 'text-accent': !node.visible }"+ :class="{ 'text-accent': visibilityState === 'hidden' }"title="Toggle visibility"@click="toggleVisibility">- <icon-lucide-eye v-if="node.visible" class="size-3.5" />- <icon-lucide-eye-off v-else class="size-3.5" />+ <icon-lucide-eye v-if="visibilityState === 'visible'" class="size-3.5" />+ <icon-lucide-eye-off v-else-if="visibilityState === 'hidden'" class="size-3.5" />+ <icon-lucide-eye class="size-3.5 opacity-50" v-else /></button></div><div class="flex gap-1.5"><ScrubInputsuffix="%"- :model-value="Math.round(node.opacity * 100)"+ :model-value="opacityValue":min="0":max="100"@update:model-value="updateProp('opacity', $event / 100)"@@ -94,8 +176,8 @@ function commitCornerProp(key: string, value: number, previous: number) {</ScrubInput><template v-if="hasCornerRadius"><ScrubInput- v-if="!node.independentCorners"- :model-value="node.cornerRadius"+ v-if="independentCorners !== true"+ :model-value="cornerRadiusValue":min="0"@update:model-value="updateProp('cornerRadius', $event)"@commit="(v: number, p: number) => commitProp('cornerRadius', v, p)"@@ -106,7 +188,7 @@ function commitCornerProp(key: string, value: number, previous: number) {</ScrubInput><buttonclass="flex size-[26px] shrink-0 cursor-pointer items-center justify-center rounded border border-border bg-input text-muted hover:bg-hover hover:text-surface"- :class="{ '!border-accent !text-accent': node.independentCorners }"+ :class="{ '!border-accent !text-accent': independentCorners === true }"title="Independent corner radii"@click="toggleIndependentCorners">@@ -126,9 +208,12 @@ function commitCornerProp(key: string, value: number, previous: number) {</template></div>- <div v-if="hasCornerRadius && node.independentCorners" class="mt-1.5 grid grid-cols-2 gap-1.5">+ <div+ v-if="hasCornerRadius && independentCorners === true && !isMulti"+ class="mt-1.5 grid grid-cols-2 gap-1.5"+ ><ScrubInput- :model-value="node.topLeftRadius"+ :model-value="node!.topLeftRadius":min="0"@update:model-value="updateCornerProp('topLeftRadius', $event)"@commit="(v: number, p: number) => commitCornerProp('topLeftRadius', v, p)"@@ -146,7 +231,7 @@ function commitCornerProp(key: string, value: number, previous: number) {</template></ScrubInput><ScrubInput- :model-value="node.topRightRadius"+ :model-value="node!.topRightRadius":min="0"@update:model-value="updateCornerProp('topRightRadius', $event)"@commit="(v: number, p: number) => commitCornerProp('topRightRadius', v, p)"@@ -164,7 +249,7 @@ function commitCornerProp(key: string, value: number, previous: number) {</template></ScrubInput><ScrubInput- :model-value="node.bottomLeftRadius"+ :model-value="node!.bottomLeftRadius":min="0"@update:model-value="updateCornerProp('bottomLeftRadius', $event)"@commit="(v: number, p: number) => commitCornerProp('bottomLeftRadius', v, p)"@@ -182,7 +267,7 @@ function commitCornerProp(key: string, value: number, previous: number) {</template></ScrubInput><ScrubInput- :model-value="node.bottomRightRadius"+ :model-value="node!.bottomRightRadius":min="0"@update:model-value="updateCornerProp('bottomRightRadius', $event)"@commit="(v: number, p: number) => commitCornerProp('bottomRightRadius', v, p)"diff --git a/src/components/properties/EffectsSection.vue b/src/components/properties/EffectsSection.vueindex b56df49d3..67d22b216 100644--- a/src/components/properties/EffectsSection.vue+++ b/src/components/properties/EffectsSection.vue@@ -4,10 +4,19 @@ 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 type { Color, Effect } from '@/engine/scene-graph'-const { store, node } = useNodeProps()+const { store } = useNodeProps()+const { node, nodes, isMulti, active } = useMultiProps()++const effectsAreMixed = computed(() => {+ if (!isMulti.value) return false+ const all = nodes.value+ const first = JSON.stringify(all[0].effects)+ return all.some((n) => JSON.stringify(n.effects) !== first)+})const expandedIndex = ref<number | null>(null)const effectsBeforeScrub = ref<Effect[] | null>(null)@@ -103,6 +112,13 @@ function updateType(index: number, type: EffectType) {}function add() {+ if (isMulti.value) {+ for (const n of nodes.value) {+ store.updateNodeWithUndo(n.id, { effects: [defaultEffect()] }, 'Set effect')+ }+ store.requestRender()+ return+ }const n = node.valueif (!n) returnconst effects = [...n.effects, defaultEffect()]@@ -127,7 +143,7 @@ function toggleExpand(index: number) {</script><template>- <div v-if="node" class="border-b border-border px-3 py-2">+ <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">Effects</label><button@@ -138,7 +154,9 @@ function toggleExpand(index: number) {</button></div>- <div v-for="(effect, i) in node.effects" :key="i">+ <p v-if="effectsAreMixed" class="text-[11px] text-muted">Click + to replace mixed effects</p>++ <div v-for="(effect, i) in effectsAreMixed ? [] : ((node ?? nodes[0])?.effects ?? [])" :key="i"><!-- Collapsed row: color swatch | type dropdown | eye | minus --><div class="group flex items-center gap-1.5 py-0.5"><buttondiff --git a/src/components/properties/FillSection.vue b/src/components/properties/FillSection.vueindex 452205d76..416239ee0 100644--- a/src/components/properties/FillSection.vue+++ b/src/components/properties/FillSection.vue@@ -16,26 +16,41 @@ import {import FillPicker from '@/components/FillPicker.vue'import ScrubInput from '@/components/ScrubInput.vue'import { useNodeProps } from '@/composables/use-node-props'+import { useMultiProps } from '@/composables/use-multi-props'import { DEFAULT_SHAPE_FILL } from '@/constants'import { colorToHexRaw } from '@/engine/color'import type { Fill, Variable, Color } from '@/engine/scene-graph'-const { store, node } = useNodeProps()+const { store } = useNodeProps()+const { nodes, isMulti, active, activeNode } = useMultiProps()++const fillsAreMixed = computed(() => {+ if (!isMulti.value) return false+ const all = nodes.value+ const first = JSON.stringify(all[0].fills)+ return all.some((n) => JSON.stringify(n.fills) !== first)+})const colorVariables = computed(() => store.graph.getVariablesByType('COLOR'))function getBoundVariable(index: number): Variable | undefined {- const varId = node.value.boundVariables[`fills/${index}/color`]+ const n = activeNode.value+ if (!n) return undefined+ const varId = n.boundVariables[`fills/${index}/color`]return varId ? store.graph.variables.get(varId) : undefined}function bindVariable(index: number, variableId: string) {- store.graph.bindVariable(node.value.id, `fills/${index}/color`, variableId)+ const n = activeNode.value+ if (!n) return+ store.graph.bindVariable(n.id, `fills/${index}/color`, variableId)store.requestRender()}function unbindVariable(index: number) {- store.graph.unbindVariable(node.value.id, `fills/${index}/color`)+ const n = activeNode.value+ if (!n) return+ store.graph.unbindVariable(n.id, `fills/${index}/color`)store.requestRender()}@@ -46,37 +61,50 @@ function resolvedSwatchStyle(variable: Variable): string {}function updateFill(index: number, fill: Fill) {- const fills = [...node.value.fills]- fills[index] = fill- store.updateNodeWithUndo(node.value.id, { fills }, 'Change fill')+ for (const n of isMulti.value ? nodes.value : [activeNode.value]) {+ if (!n) continue+ const fills = [...n.fills]+ fills[index] = fill+ store.updateNodeWithUndo(n.id, { fills }, 'Change fill')+ }}function updateOpacity(index: number, opacity: number) {- const fills = [...node.value.fills]- fills[index] = { ...fills[index], opacity: Math.max(0, Math.min(1, opacity / 100)) }- store.updateNodeWithUndo(node.value.id, { fills }, 'Change fill')+ for (const n of isMulti.value ? nodes.value : [activeNode.value]) {+ if (!n) continue+ const fills = [...n.fills]+ fills[index] = { ...fills[index], opacity: Math.max(0, Math.min(1, opacity / 100)) }+ store.updateNodeWithUndo(n.id, { fills }, 'Change fill')+ }}function toggleVisibility(index: number) {- const fills = [...node.value.fills]- fills[index] = { ...fills[index], visible: !fills[index].visible }- store.updateNodeWithUndo(node.value.id, { fills }, 'Change fill')+ for (const n of isMulti.value ? nodes.value : [activeNode.value]) {+ if (!n) continue+ const fills = [...n.fills]+ fills[index] = { ...fills[index], visible: !fills[index].visible }+ store.updateNodeWithUndo(n.id, { fills }, 'Change fill')+ }}function add() {- store.updateNodeWithUndo(- node.value.id,- { fills: [...node.value.fills, { ...DEFAULT_SHAPE_FILL }] },- 'Add fill'- )+ if (isMulti.value) {+ for (const n of nodes.value) {+ store.updateNodeWithUndo(n.id, { fills: [{ ...DEFAULT_SHAPE_FILL }] }, 'Set fill')+ }+ store.requestRender()+ } else {+ const n = activeNode.value+ if (!n) return+ store.updateNodeWithUndo(n.id, { fills: [...n.fills, { ...DEFAULT_SHAPE_FILL }] }, 'Add fill')+ }}function remove(index: number) {- store.updateNodeWithUndo(- node.value.id,- { fills: node.value.fills.filter((_, i) => i !== index) },- 'Remove fill'- )+ for (const n of isMulti.value ? nodes.value : [activeNode.value]) {+ if (!n) continue+ store.updateNodeWithUndo(n.id, { fills: n.fills.filter((_, i) => i !== index) }, 'Remove fill')+ }}const searchTerm = ref('')@@ -88,7 +116,7 @@ const filteredVariables = computed(() => {</script><template>- <div v-if="node" class="border-b border-border px-3 py-2">+ <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">Fill</label><button@@ -98,7 +126,12 @@ const filteredVariables = computed(() => {+</button></div>- <div v-for="(fill, i) in node.fills" :key="i" class="group flex items-center gap-1.5 py-0.5">+ <p v-if="fillsAreMixed" class="text-[11px] text-muted">Click + to replace mixed fills</p>+ <div+ v-for="(fill, i) in fillsAreMixed ? [] : (activeNode?.fills ?? [])"+ :key="i"+ class="group flex items-center gap-1.5 py-0.5"+ ><FillPicker :fill="fill" @update="updateFill(i, $event)" /><!-- Bound variable indicator or hex value -->diff --git a/src/components/properties/PositionSection.vue b/src/components/properties/PositionSection.vueindex 0f9499deb..06dd08bca 100644--- a/src/components/properties/PositionSection.vue+++ b/src/components/properties/PositionSection.vue@@ -1,8 +1,24 @@<script setup lang="ts">+import { computed } from 'vue'+import ScrubInput from '@/components/ScrubInput.vue'import { useNodeProps } from '@/composables/use-node-props'--const { store, node, nodes, updateProp, commitProp } = useNodeProps()+import { useMultiProps } from '@/composables/use-multi-props'++const { store, updateProp, commitProp } = useNodeProps()+const { node, nodes, isMulti, active, prop: multiProp } = useMultiProps()++const xValue = computed(() =>+ isMulti.value ? multiProp('x').value : Math.round(node.value?.x ?? 0)+)+const yValue = computed(() =>+ isMulti.value ? multiProp('y').value : Math.round(node.value?.y ?? 0)+)+const wValue = multiProp('width')+const hValue = multiProp('height')+const rotationValue = computed(() =>+ isMulti.value ? multiProp('rotation').value : Math.round(node.value?.rotation ?? 0)+)type HAlign = 'left' | 'center' | 'right'type VAlign = 'top' | 'center' | 'bottom'@@ -86,26 +102,29 @@ function alignVertical(align: VAlign) {}function flipHorizontal() {- const n = node.value- store.updateNodeWithUndo(n.id, { flipX: !n.flipX }, 'Flip horizontal')+ for (const n of nodes.value) {+ store.updateNodeWithUndo(n.id, { flipX: !n.flipX }, 'Flip horizontal')+ }store.requestRender()}function flipVertical() {- const n = node.value- store.updateNodeWithUndo(n.id, { flipY: !n.flipY }, 'Flip vertical')+ for (const n of nodes.value) {+ store.updateNodeWithUndo(n.id, { flipY: !n.flipY }, 'Flip vertical')+ }store.requestRender()}function rotate90() {- const n = node.value- store.updateNodeWithUndo(n.id, { rotation: (n.rotation + 90) % 360 }, 'Rotate 90°')+ for (const n of nodes.value) {+ store.updateNodeWithUndo(n.id, { rotation: (n.rotation + 90) % 360 }, 'Rotate 90°')+ }store.requestRender()}</script><template>- <div v-if="node" class="border-b border-border px-3 py-2">+ <div v-if="active" class="border-b border-border px-3 py-2"><label class="mb-1.5 block text-[11px] text-muted">Position</label><!-- Alignment buttons -->@@ -162,24 +181,42 @@ function rotate90() {<div class="flex gap-1.5"><ScrubInputicon="X"- :model-value="Math.round(node.x)"+ :model-value="xValue"@update:model-value="updateProp('x', $event)"@commit="(v: number, p: number) => commitProp('x', v, p)"/><ScrubInputicon="Y"- :model-value="Math.round(node.y)"+ :model-value="yValue"@update:model-value="updateProp('y', $event)"@commit="(v: number, p: number) => commitProp('y', v, p)"/></div>+ <!-- W / H (multi-select only; single-select shows in LayoutSection) -->+ <div v-if="isMulti" class="mt-1.5 flex gap-1.5">+ <ScrubInput+ icon="W"+ :model-value="wValue"+ :min="1"+ @update:model-value="updateProp('width', $event)"+ @commit="(v: number, p: number) => commitProp('width', v, p)"+ />+ <ScrubInput+ icon="H"+ :model-value="hValue"+ :min="1"+ @update:model-value="updateProp('height', $event)"+ @commit="(v: number, p: number) => commitProp('height', v, p)"+ />+ </div>+<!-- Rotation + flip --><div class="mt-1.5 flex items-center gap-1.5"><ScrubInputclass="flex-1"suffix="°"- :model-value="Math.round(node.rotation)"+ :model-value="rotationValue":min="-360":max="360"@update:model-value="updateProp('rotation', $event)"diff --git a/src/components/properties/StrokeSection.vue b/src/components/properties/StrokeSection.vueindex 526fa4a2e..7823bfd31 100644--- a/src/components/properties/StrokeSection.vue+++ b/src/components/properties/StrokeSection.vue@@ -1,34 +1,57 @@<script setup lang="ts">+import { computed } from '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 type { Color, Stroke } from '@/engine/scene-graph'-const { store, node } = useNodeProps()+const { store } = useNodeProps()+const { nodes, isMulti, active, activeNode } = useMultiProps()++const strokesAreMixed = computed(() => {+ if (!isMulti.value) return false+ const all = nodes.value+ const first = JSON.stringify(all[0].strokes)+ return all.some((n) => JSON.stringify(n.strokes) !== first)+})function updateColor(index: number, color: Color) {- const strokes = [...node.value.strokes]- strokes[index] = { ...strokes[index], color }- store.updateNodeWithUndo(node.value.id, { strokes }, 'Change stroke')+ for (const n of isMulti.value ? nodes.value : [activeNode.value]) {+ if (!n) continue+ const strokes = [...n.strokes]+ strokes[index] = { ...strokes[index], color }+ store.updateNodeWithUndo(n.id, { strokes }, 'Change stroke')+ }}function updateWeight(index: number, weight: number) {- const strokes = [...node.value.strokes]- strokes[index] = { ...strokes[index], weight }- store.updateNodeWithUndo(node.value.id, { strokes }, 'Change stroke')+ for (const n of isMulti.value ? nodes.value : [activeNode.value]) {+ if (!n) continue+ const strokes = [...n.strokes]+ strokes[index] = { ...strokes[index], weight }+ store.updateNodeWithUndo(n.id, { strokes }, 'Change stroke')+ }}function updateOpacity(index: number, opacity: number) {- const strokes = [...node.value.strokes]- strokes[index] = { ...strokes[index], opacity: Math.max(0, Math.min(1, opacity / 100)) }- store.updateNodeWithUndo(node.value.id, { strokes }, 'Change stroke')+ for (const n of isMulti.value ? nodes.value : [activeNode.value]) {+ if (!n) continue+ const strokes = [...n.strokes]+ strokes[index] = { ...strokes[index], opacity: Math.max(0, Math.min(1, opacity / 100)) }+ store.updateNodeWithUndo(n.id, { strokes }, 'Change stroke')+ }}function toggleVisibility(index: number) {- const strokes = [...node.value.strokes]- strokes[index] = { ...strokes[index], visible: !strokes[index].visible }- store.updateNodeWithUndo(node.value.id, { strokes }, 'Change stroke')+ for (const n of isMulti.value ? nodes.value : [activeNode.value]) {+ if (!n) continue+ const strokes = [...n.strokes]+ strokes[index] = { ...strokes[index], visible: !strokes[index].visible }+ store.updateNodeWithUndo(n.id, { strokes }, 'Change stroke')+ }}function add() {@@ -39,24 +62,32 @@ function add() {visible: true,align: 'CENTER'}- store.updateNodeWithUndo(- node.value.id,- { strokes: [...node.value.strokes, stroke] },- 'Add stroke'- )+ if (isMulti.value) {+ for (const n of nodes.value) {+ store.updateNodeWithUndo(n.id, { strokes: [stroke] }, 'Set stroke')+ }+ store.requestRender()+ } else {+ const n = activeNode.value+ if (!n) return+ store.updateNodeWithUndo(n.id, { strokes: [...n.strokes, stroke] }, 'Add stroke')+ }}function remove(index: number) {- store.updateNodeWithUndo(- node.value.id,- { strokes: node.value.strokes.filter((_, i) => i !== index) },- 'Remove stroke'- )+ for (const n of isMulti.value ? nodes.value : [activeNode.value]) {+ if (!n) continue+ store.updateNodeWithUndo(+ n.id,+ { strokes: n.strokes.filter((_, i) => i !== index) },+ 'Remove stroke'+ )+ }}</script><template>- <div v-if="node" class="border-b border-border px-3 py-2">+ <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@@ -66,8 +97,9 @@ function remove(index: number) {+</button></div>+ <p v-if="strokesAreMixed" class="text-[11px] text-muted">Click + to replace mixed strokes</p><div- v-for="(stroke, i) in node.strokes"+ v-for="(stroke, i) in strokesAreMixed ? [] : (activeNode?.strokes ?? [])":key="i"class="group flex items-center gap-1.5 py-0.5">@@ -94,11 +126,14 @@ function remove(index: number) {−</button></div>- <div v-if="node.strokes.length > 0" class="mt-1 flex items-center gap-1.5">+ <div+ v-if="!strokesAreMixed && (activeNode?.strokes?.length ?? 0) > 0"+ class="mt-1 flex items-center gap-1.5"+ ><ScrubInputclass="w-16"icon="W"- :model-value="node.strokes[0].weight"+ :model-value="activeNode?.strokes[0].weight ?? 1":min="0"@update:model-value="updateWeight(0, $event)"/>diff --git a/src/composables/use-multi-props.ts b/src/composables/use-multi-props.tsnew file mode 100644index 000000000..2de935d66--- /dev/null+++ b/src/composables/use-multi-props.ts@@ -0,0 +1,40 @@+import { computed } from 'vue'++import { useEditorStore } from '@/stores/editor'++import type { SceneNode } from '@/engine/scene-graph'++export const MIXED = Symbol('mixed')+export type MixedValue<T> = T | typeof MIXED++export function useMultiProps() {+ const store = useEditorStore()+ const node = computed(() => store.selectedNode.value ?? null)+ const nodes = computed(() => store.selectedNodes.value)+ const isMulti = computed(() => nodes.value.length > 1)+ const active = computed(() => node.value || isMulti.value)+ const activeNode = computed(() => node.value ?? nodes.value[0] ?? null)++ function merged<K extends keyof SceneNode>(key: K): MixedValue<SceneNode[K]> {+ const all = nodes.value+ if (all.length === 0) return MIXED+ const first = all[0][key]+ for (let i = 1; i < all.length; i++) {+ if (all[i][key] !== first) return MIXED+ }+ return first+ }++ function prop<K extends keyof SceneNode>(key: K) {+ return computed(() => merged(key))+ }++ function updateAllWithUndo(patch: Partial<SceneNode>, label: string) {+ for (const n of nodes.value) {+ store.updateNodeWithUndo(n.id, patch, label)+ }+ store.requestRender()+ }++ return { store, node, nodes, isMulti, active, activeNode, prop, merged, updateAllWithUndo }+}diff --git a/src/composables/use-node-props.ts b/src/composables/use-node-props.tsindex 83052294a..1eaf9efbd 100644--- a/src/composables/use-node-props.ts+++ b/src/composables/use-node-props.ts@@ -11,6 +11,7 @@ export function useNodeProps() {function updateProp(key: string, value: number | string) {if (store.selectedNodes.value.length > 1) {+ storePreviousValues(key)for (const n of store.selectedNodes.value) {store.updateNode(n.id, { [key]: value })}@@ -20,11 +21,28 @@ export function useNodeProps() {}}+ const previousValues = new Map<string, Record<string, number | string>>()++ function storePreviousValues(key: string) {+ for (const n of store.selectedNodes.value) {+ let rec = previousValues.get(n.id)+ if (!rec) {+ rec = {}+ previousValues.set(n.id, rec)+ }+ if (!(key in rec)) {+ rec[key] = n[key as keyof SceneNode] as number | string+ }+ }+ }+function commitProp(key: string, _value: number | string, previous: number | string) {if (store.selectedNodes.value.length > 1) {for (const n of store.selectedNodes.value) {- store.commitNodeUpdate(n.id, { [key]: previous } as Partial<SceneNode>, `Change ${key}`)+ const prev = previousValues.get(n.id)?.[key] ?? previous+ store.commitNodeUpdate(n.id, { [key]: prev } as Partial<SceneNode>, `Change ${key}`)}+ previousValues.clear()} else {const node = store.selectedNode.valueif (node) {diff --git a/tests/engine/multi-selection.test.ts b/tests/engine/multi-selection.test.tsnew file mode 100644index 000000000..e644c889f--- /dev/null+++ b/tests/engine/multi-selection.test.ts@@ -0,0 +1,316 @@+import { describe, test, expect } from 'bun:test'++import { SceneGraph } from '../../packages/core/src/scene-graph'++function pageId(graph: SceneGraph) {+ return graph.getPages()[0].id+}++function rect(+ graph: SceneGraph,+ parentId: string,+ props: { name?: string; x?: number; y?: number; width?: number; height?: number } = {}+) {+ return graph.createNode('RECTANGLE', parentId, {+ name: props.name ?? 'Rect',+ x: props.x ?? 0,+ y: props.y ?? 0,+ width: props.width ?? 50,+ height: props.height ?? 50+ })+}++describe('flip', () => {+ test('flipX defaults to false', () => {+ const graph = new SceneGraph()+ const node = rect(graph, pageId(graph))+ expect(node.flipX).toBe(false)+ expect(node.flipY).toBe(false)+ })++ test('flipX can be set via updateNode', () => {+ const graph = new SceneGraph()+ const node = rect(graph, pageId(graph))+ graph.updateNode(node.id, { flipX: true })+ expect(graph.getNode(node.id)!.flipX).toBe(true)+ expect(graph.getNode(node.id)!.flipY).toBe(false)+ })++ test('flipY can be set via updateNode', () => {+ const graph = new SceneGraph()+ const node = rect(graph, pageId(graph))+ graph.updateNode(node.id, { flipY: true })+ expect(graph.getNode(node.id)!.flipX).toBe(false)+ expect(graph.getNode(node.id)!.flipY).toBe(true)+ })++ test('flip toggles', () => {+ const graph = new SceneGraph()+ const node = rect(graph, pageId(graph))+ graph.updateNode(node.id, { flipX: true })+ expect(graph.getNode(node.id)!.flipX).toBe(true)+ graph.updateNode(node.id, { flipX: false })+ expect(graph.getNode(node.id)!.flipX).toBe(false)+ })+})++describe('single-node alignment to parent', () => {+ function setup() {+ const graph = new SceneGraph()+ const frame = graph.createNode('FRAME', pageId(graph), {+ name: 'Container',+ x: 0,+ y: 0,+ width: 400,+ height: 300+ })+ const child = rect(graph, frame.id, { name: 'Child', x: 50, y: 50, width: 100, height: 80 })+ return { graph, frame, child }+ }++ test('align left within parent', () => {+ const { graph, frame, child } = setup()+ graph.updateNode(child.id, { x: 0 })+ expect(graph.getNode(child.id)!.x).toBe(0)+ })++ test('align right within parent', () => {+ const { graph, frame, child } = setup()+ const targetX = frame.width - child.width+ graph.updateNode(child.id, { x: targetX })+ expect(graph.getNode(child.id)!.x).toBe(300)+ })++ test('align center horizontal within parent', () => {+ const { graph, frame, child } = setup()+ const targetX = (frame.width - child.width) / 2+ graph.updateNode(child.id, { x: targetX })+ expect(graph.getNode(child.id)!.x).toBe(150)+ })++ test('align top within parent', () => {+ const { graph, child } = setup()+ graph.updateNode(child.id, { y: 0 })+ expect(graph.getNode(child.id)!.y).toBe(0)+ })++ test('align bottom within parent', () => {+ const { graph, frame, child } = setup()+ const targetY = frame.height - child.height+ graph.updateNode(child.id, { y: targetY })+ expect(graph.getNode(child.id)!.y).toBe(220)+ })++ test('align center vertical within parent', () => {+ const { graph, frame, child } = setup()+ const targetY = (frame.height - child.height) / 2+ graph.updateNode(child.id, { y: targetY })+ expect(graph.getNode(child.id)!.y).toBe(110)+ })+})++describe('multi-node alignment', () => {+ function setup() {+ const graph = new SceneGraph()+ const page = pageId(graph)+ const a = rect(graph, page, { name: 'A', x: 10, y: 20, width: 50, height: 30 })+ const b = rect(graph, page, { name: 'B', x: 100, y: 80, width: 60, height: 40 })+ const c = rect(graph, page, { name: 'C', x: 200, y: 50, width: 40, height: 50 })+ return { graph, a, b, c }+ }++ test('align left — all nodes move to min x', () => {+ const { graph, a, b, c } = setup()+ const nodes = [a, b, c].map((n) => graph.getNode(n.id)!)+ const abs = nodes.map((n) => graph.getAbsolutePosition(n.id))+ const minX = Math.min(...abs.map((p, i) => p.x))++ for (const n of nodes) {+ const nodeAbs = graph.getAbsolutePosition(n.id)+ graph.updateNode(n.id, { x: n.x + (minX - nodeAbs.x) })+ }++ expect(graph.getNode(a.id)!.x).toBe(10)+ expect(graph.getNode(b.id)!.x).toBe(10)+ expect(graph.getNode(c.id)!.x).toBe(10)+ })++ test('align right — all nodes align to max right edge', () => {+ const { graph, a, b, c } = setup()+ const nodes = [a, b, c].map((n) => graph.getNode(n.id)!)+ const abs = nodes.map((n) => graph.getAbsolutePosition(n.id))+ const maxX = Math.max(...abs.map((p, i) => p.x + nodes[i].width))++ for (const n of nodes) {+ const nodeAbs = graph.getAbsolutePosition(n.id)+ const targetX = maxX - n.width+ graph.updateNode(n.id, { x: n.x + (targetX - nodeAbs.x) })+ }++ expect(graph.getNode(a.id)!.x).toBe(190)+ expect(graph.getNode(b.id)!.x).toBe(180)+ expect(graph.getNode(c.id)!.x).toBe(200)+ })++ test('align top — all nodes move to min y', () => {+ const { graph, a, b, c } = setup()+ const nodes = [a, b, c].map((n) => graph.getNode(n.id)!)+ const abs = nodes.map((n) => graph.getAbsolutePosition(n.id))+ const minY = Math.min(...abs.map((p) => p.y))++ for (const n of nodes) {+ const nodeAbs = graph.getAbsolutePosition(n.id)+ graph.updateNode(n.id, { y: n.y + (minY - nodeAbs.y) })+ }++ expect(graph.getNode(a.id)!.y).toBe(20)+ expect(graph.getNode(b.id)!.y).toBe(20)+ expect(graph.getNode(c.id)!.y).toBe(20)+ })+})++describe('multi-node property merging', () => {+ test('same values merge to single value', () => {+ const graph = new SceneGraph()+ const page = pageId(graph)+ const a = rect(graph, page, { width: 100, height: 50 })+ const b = rect(graph, page, { width: 100, height: 50 })+ const nodes = [graph.getNode(a.id)!, graph.getNode(b.id)!]++ const widths = new Set(nodes.map((n) => n.width))+ expect(widths.size).toBe(1)+ expect([...widths][0]).toBe(100)+ })++ test('different values are detected', () => {+ const graph = new SceneGraph()+ const page = pageId(graph)+ const a = rect(graph, page, { width: 100 })+ const b = rect(graph, page, { width: 200 })+ const nodes = [graph.getNode(a.id)!, graph.getNode(b.id)!]++ const widths = new Set(nodes.map((n) => n.width))+ expect(widths.size).toBe(2)+ })++ test('update applies to all selected nodes', () => {+ const graph = new SceneGraph()+ const page = pageId(graph)+ const a = rect(graph, page, { width: 100 })+ const b = rect(graph, page, { width: 200 })+ const c = rect(graph, page, { width: 150 })++ for (const id of [a.id, b.id, c.id]) {+ graph.updateNode(id, { width: 300 })+ }++ expect(graph.getNode(a.id)!.width).toBe(300)+ expect(graph.getNode(b.id)!.width).toBe(300)+ expect(graph.getNode(c.id)!.width).toBe(300)+ })++ test('opacity update applies uniformly', () => {+ const graph = new SceneGraph()+ const page = pageId(graph)+ const a = rect(graph, page)+ const b = rect(graph, page)++ graph.updateNode(a.id, { opacity: 0.5 })+ graph.updateNode(b.id, { opacity: 0.8 })++ for (const id of [a.id, b.id]) {+ graph.updateNode(id, { opacity: 0.75 })+ }++ expect(graph.getNode(a.id)!.opacity).toBe(0.75)+ expect(graph.getNode(b.id)!.opacity).toBe(0.75)+ })++ test('fills comparison detects mixed', () => {+ const graph = new SceneGraph()+ const page = pageId(graph)+ const a = rect(graph, page)+ const b = rect(graph, page)++ graph.updateNode(a.id, {+ fills: [{ type: 'SOLID', color: { r: 1, g: 0, b: 0, a: 1 }, opacity: 1, visible: true }]+ })+ graph.updateNode(b.id, {+ fills: [{ type: 'SOLID', color: { r: 0, g: 1, b: 0, a: 1 }, opacity: 1, visible: true }]+ })++ const nodeA = graph.getNode(a.id)!+ const nodeB = graph.getNode(b.id)!+ expect(JSON.stringify(nodeA.fills)).not.toBe(JSON.stringify(nodeB.fills))+ })++ test('fills comparison detects same', () => {+ const graph = new SceneGraph()+ const page = pageId(graph)+ const fill = { type: 'SOLID' as const, color: { r: 1, g: 0, b: 0, a: 1 }, opacity: 1, visible: true }+ const a = rect(graph, page)+ const b = rect(graph, page)++ graph.updateNode(a.id, { fills: [{ ...fill }] })+ graph.updateNode(b.id, { fills: [{ ...fill }] })++ const nodeA = graph.getNode(a.id)!+ const nodeB = graph.getNode(b.id)!+ expect(JSON.stringify(nodeA.fills)).toBe(JSON.stringify(nodeB.fills))+ })+})++describe('flip roundtrip via kiwi', () => {+ async function roundtrip(graph: SceneGraph) {+ const { initCodec } = await import('../../packages/core/src/kiwi/codec')+ const { parseFigFile } = await import('../../packages/core/src/kiwi/fig-file')+ const { exportFigFile } = await import('../../packages/core/src/fig-export')+ await initCodec()+ const buf = await exportFigFile(graph)+ return parseFigFile(buf)+ }++ function findChild(graph: SceneGraph, name: string) {+ const pages = graph.getPages()+ const children = graph.getChildren(pages[0].id)+ return children.find((c) => c.name === name)+ }++ test('flipX preserved through export/import', async () => {+ const graph = new SceneGraph()+ const page = pageId(graph)+ rect(graph, page, { name: 'Flipped', x: 50, y: 50, width: 100, height: 80 })+ graph.updateNode(graph.getChildren(page).find((n) => n.name === 'Flipped')!.id, { flipX: true })++ const imported = await roundtrip(graph)+ const found = findChild(imported, 'Flipped')+ expect(found).toBeTruthy()+ expect(found!.flipX).toBe(true)+ })++ test('non-flipped node stays non-flipped', async () => {+ const graph = new SceneGraph()+ rect(graph, pageId(graph), { name: 'Normal', x: 100, y: 50, width: 200, height: 100 })++ const imported = await roundtrip(graph)+ const found = findChild(imported, 'Normal')+ expect(found).toBeTruthy()+ expect(found!.flipX).toBe(false)+ })++ test('flipX with rotation preserved', async () => {+ const graph = new SceneGraph()+ const page = pageId(graph)+ rect(graph, page, { name: 'RotFlip', x: 0, y: 0, width: 100, height: 100 })+ graph.updateNode(graph.getChildren(page).find((n) => n.name === 'RotFlip')!.id, {+ flipX: true,+ rotation: 45+ })++ const imported = await roundtrip(graph)+ const found = findChild(imported, 'RotFlip')+ expect(found).toBeTruthy()+ expect(found!.flipX).toBe(true)+ expect(Math.round(found!.rotation)).toBe(45)+ })+})