Skip to content

AI-native design editor. Open-source Figma alternative.

Fix flip and single-node alignment

Danila Poyarkov5a77f2c1cca2
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bc00cef4a..769f67819 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,17 @@
# Changelog
+## Unreleased
+
+### Features
+
+- Flip horizontal/vertical using scale transform instead of rotation
+- Single-node alignment aligns to parent frame bounds
+
+### Fixes
+
+- Fix flip buttons using rotation math instead of actual mirroring
+- Decode flip state from .fig transform matrix on import
+
## 0.5.1 — 2026-03-03
### Fixes
diff --git a/packages/core/src/kiwi-serialize.ts b/packages/core/src/kiwi-serialize.ts
index 6f70d705f..9b06e35ce 100644
--- a/packages/core/src/kiwi-serialize.ts
+++ b/packages/core/src/kiwi-serialize.ts
@@ -170,8 +170,9 @@ export function sceneNodeToKiwi(
): KiwiNodeChange[] {
const localID = localIdCounter.value++
const guid = { sessionID: 1, localID }
- const cos = Math.cos((node.rotation * Math.PI) / 180)
- const sin = Math.sin((node.rotation * Math.PI) / 180)
+ 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 fillPaints = node.fills.map((f) => {
const paint: Paint = {
diff --git a/packages/core/src/kiwi/fig-import.ts b/packages/core/src/kiwi/fig-import.ts
index ed26a5a53..9f79c4915 100644
--- a/packages/core/src/kiwi/fig-import.ts
+++ b/packages/core/src/kiwi/fig-import.ts
@@ -412,8 +412,13 @@ export function importNodeChanges(
const height = nc.size?.y ?? 100
let rotation = 0
+ let flipX = false
+ let flipY = false
if (nc.transform) {
- rotation = Math.atan2(nc.transform.m10, nc.transform.m00) * (180 / Math.PI)
+ const det = nc.transform.m00 * nc.transform.m11 - nc.transform.m01 * nc.transform.m10
+ if (det < 0) flipX = true
+ const sx = flipX ? -1 : 1
+ rotation = Math.atan2(nc.transform.m10 * sx, nc.transform.m00 * sx) * (180 / Math.PI)
}
const dashPattern = (ext(nc).dashPattern as number[]) ?? []
@@ -425,6 +430,8 @@ export function importNodeChanges(
width,
height,
rotation,
+ flipX,
+ flipY,
opacity: nc.opacity ?? 1,
visible: nc.visible ?? true,
locked: nc.locked ?? false,
diff --git a/packages/core/src/renderer.ts b/packages/core/src/renderer.ts
index 476760bb8..41ef58856 100644
--- a/packages/core/src/renderer.ts
+++ b/packages/core/src/renderer.ts
@@ -1021,6 +1021,14 @@ export class SkiaRenderer {
canvas.rotate(rotation, node.width / 2, node.height / 2)
}
+ if (node.flipX || node.flipY) {
+ canvas.translate(
+ node.flipX ? node.width : 0,
+ node.flipY ? node.height : 0
+ )
+ canvas.scale(node.flipX ? -1 : 1, node.flipY ? -1 : 1)
+ }
+
if (node.type === 'SECTION') {
this.renderSection(canvas, node, graph)
} else if (node.type === 'COMPONENT_SET') {
diff --git a/packages/core/src/scene-graph.ts b/packages/core/src/scene-graph.ts
index f8c78098e..186e7bf43 100644
--- a/packages/core/src/scene-graph.ts
+++ b/packages/core/src/scene-graph.ts
@@ -268,6 +268,9 @@ export interface SceneNode {
internalOnly: boolean
+ flipX: boolean
+ flipY: boolean
+
textPicture: Uint8Array | null
}
@@ -390,6 +393,8 @@ function createDefaultNode(type: NodeType, overrides: Partial<SceneNode> = {}):
overrides: {},
boundVariables: {},
internalOnly: false,
+ flipX: false,
+ flipY: false,
textPicture: null,
...overrides
}
diff --git a/src/components/properties/PositionSection.vue b/src/components/properties/PositionSection.vue
index 4ce4d5389..0f9499deb 100644
--- a/src/components/properties/PositionSection.vue
+++ b/src/components/properties/PositionSection.vue
@@ -9,63 +9,91 @@ type VAlign = 'top' | 'center' | 'bottom'
function alignHorizontal(align: HAlign) {
const selected = nodes.value
- if (selected.length < 2) return
+ if (selected.length === 0) return
- let minX = Infinity,
+ let minX: number, maxX: number
+
+ if (selected.length === 1) {
+ const parent = store.graph.getNode(selected[0].parentId ?? '')
+ if (!parent) return
+ minX = 0
+ maxX = parent.width
+ } else {
+ minX = Infinity
maxX = -Infinity
- for (const n of selected) {
- const abs = store.graph.getAbsolutePosition(n.id)
- minX = Math.min(minX, abs.x)
- maxX = Math.max(maxX, abs.x + n.width)
+ for (const n of selected) {
+ const abs = store.graph.getAbsolutePosition(n.id)
+ minX = Math.min(minX, abs.x)
+ maxX = Math.max(maxX, abs.x + n.width)
+ }
}
for (const n of selected) {
- const abs = store.graph.getAbsolutePosition(n.id)
let targetX: number
- if (align === 'left') targetX = minX
- else if (align === 'right') targetX = maxX - n.width
- else targetX = (minX + maxX) / 2 - n.width / 2
-
- const dx = targetX - abs.x
- store.updateNode(n.id, { x: n.x + dx })
+ if (selected.length === 1) {
+ if (align === 'left') targetX = minX
+ else if (align === 'right') targetX = maxX - n.width
+ else targetX = (minX + maxX) / 2 - n.width / 2
+ store.updateNode(n.id, { x: targetX })
+ } else {
+ const abs = store.graph.getAbsolutePosition(n.id)
+ if (align === 'left') targetX = minX
+ else if (align === 'right') targetX = maxX - n.width
+ else targetX = (minX + maxX) / 2 - n.width / 2
+ store.updateNode(n.id, { x: n.x + (targetX - abs.x) })
+ }
}
store.requestRender()
}
function alignVertical(align: VAlign) {
const selected = nodes.value
- if (selected.length < 2) return
+ if (selected.length === 0) return
- let minY = Infinity,
+ let minY: number, maxY: number
+
+ if (selected.length === 1) {
+ const parent = store.graph.getNode(selected[0].parentId ?? '')
+ if (!parent) return
+ minY = 0
+ maxY = parent.height
+ } else {
+ minY = Infinity
maxY = -Infinity
- for (const n of selected) {
- const abs = store.graph.getAbsolutePosition(n.id)
- minY = Math.min(minY, abs.y)
- maxY = Math.max(maxY, abs.y + n.height)
+ for (const n of selected) {
+ const abs = store.graph.getAbsolutePosition(n.id)
+ minY = Math.min(minY, abs.y)
+ maxY = Math.max(maxY, abs.y + n.height)
+ }
}
for (const n of selected) {
- const abs = store.graph.getAbsolutePosition(n.id)
let targetY: number
- if (align === 'top') targetY = minY
- else if (align === 'bottom') targetY = maxY - n.height
- else targetY = (minY + maxY) / 2 - n.height / 2
-
- const dy = targetY - abs.y
- store.updateNode(n.id, { y: n.y + dy })
+ if (selected.length === 1) {
+ if (align === 'top') targetY = minY
+ else if (align === 'bottom') targetY = maxY - n.height
+ else targetY = (minY + maxY) / 2 - n.height / 2
+ store.updateNode(n.id, { y: targetY })
+ } else {
+ const abs = store.graph.getAbsolutePosition(n.id)
+ if (align === 'top') targetY = minY
+ else if (align === 'bottom') targetY = maxY - n.height
+ else targetY = (minY + maxY) / 2 - n.height / 2
+ store.updateNode(n.id, { y: n.y + (targetY - abs.y) })
+ }
}
store.requestRender()
}
function flipHorizontal() {
const n = node.value
- store.updateNodeWithUndo(n.id, { rotation: -n.rotation || 0 }, 'Flip horizontal')
+ store.updateNodeWithUndo(n.id, { flipX: !n.flipX }, 'Flip horizontal')
store.requestRender()
}
function flipVertical() {
const n = node.value
- store.updateNodeWithUndo(n.id, { rotation: (180 - n.rotation) % 360 }, 'Flip vertical')
+ store.updateNodeWithUndo(n.id, { flipY: !n.flipY }, 'Flip vertical')
store.requestRender()
}