AI-native design editor. Open-source Figma alternative.
Apply SCALE constraint resizing to instance children + propagate through clone chains\n\nResult: {"status":"keep","total_diffs":70,"visibility":1,"text":0,"fills":11,"radius":0,"size":58,"unmatched":0}
Danila Poyarkov97ba6751e0b2
diff --git a/autoresearch.jsonl b/autoresearch.jsonlindex 97b2b3d0b..e9582d3fe 100644--- a/autoresearch.jsonl+++ b/autoresearch.jsonl@@ -3,3 +3,4 @@{"run":2,"commit":"3746d1a","metric":99,"metrics":{"visibility":1,"text":0,"fills":10,"radius":14,"size":74,"unmatched":99},"status":"keep","description":"Fix comparison: read individual corner radii when independentCorners=true","timestamp":1773483304162,"segment":0}{"run":3,"commit":"7fc3a64","metric":85,"metrics":{"visibility":1,"text":0,"fills":10,"radius":0,"size":74,"unmatched":99},"status":"keep","description":"Fix comparison: treat both-pill cornerRadius values as equal","timestamp":1773483389254,"segment":0}{"run":4,"commit":"2858d94","metric":84,"metrics":{"visibility":1,"text":0,"fills":9,"radius":0,"size":74,"unmatched":99},"status":"keep","description":"Skip self-referencing symbolOverrides on nodes with explicit kiwi properties (fixes bold toolbar button fill)","timestamp":1773484182748,"segment":0}+{"run":5,"commit":"fd5b0b5","metric":106,"metrics":{"visibility":1,"text":0,"fills":11,"radius":0,"size":94,"unmatched":0},"status":"keep","description":"Name-based tree path matching: 0 unmatched (was 99), reveals 106 total real diffs","timestamp":1773488934943,"segment":0}diff --git a/packages/core/src/kiwi/instance-overrides/constraints.ts b/packages/core/src/kiwi/instance-overrides/constraints.tsnew file mode 100644index 000000000..e59967811--- /dev/null+++ b/packages/core/src/kiwi/instance-overrides/constraints.ts@@ -0,0 +1,90 @@+import type { SceneGraph, SceneNode } from '../../scene-graph'+import type { OverrideContext } from './types'+import { buildClonesMap } from './sync'++/**+ * Apply SCALE constraint resizing to children of instances whose size+ * differs from their component's original size, then propagate the+ * changes through clone chains.+ */+export function applyConstraintScaling(ctx: OverrideContext): void {+ const { graph } = ctx+ const scaled = new Set<string>()++ for (const node of graph.getAllNodes()) {+ if (node.type !== 'INSTANCE' || !node.componentId) continue+ const comp = graph.getNode(node.componentId)+ if (!comp || comp.width <= 0 || comp.height <= 0) continue+ if (node.width === comp.width && node.height === comp.height) continue++ const sx = node.width / comp.width+ const sy = node.height / comp.height+ if (Math.abs(sx - 1) < 0.001 && Math.abs(sy - 1) < 0.001) continue++ scaleChildren(graph, node, comp, sx, sy, scaled)+ }++ if (scaled.size > 0) propagateScaling(graph, scaled)+}++function scaleChildren(+ graph: SceneGraph,+ instance: SceneNode,+ comp: SceneNode,+ sx: number,+ sy: number,+ scaled: Set<string>+): void {+ const len = Math.min(instance.childIds.length, comp.childIds.length)+ for (let i = 0; i < len; i++) {+ const child = graph.getNode(instance.childIds[i])+ const compChild = graph.getNode(comp.childIds[i])+ if (!child || !compChild) continue++ const hScale = child.horizontalConstraint === 'SCALE'+ const vScale = child.verticalConstraint === 'SCALE'+ if (!hScale && !vScale) continue++ const updates: Partial<SceneNode> = {}+ if (hScale) {+ updates.x = compChild.x * sx+ updates.width = compChild.width * sx+ }+ if (vScale) {+ updates.y = compChild.y * sy+ updates.height = compChild.height * sy+ }+ graph.updateNode(child.id, updates)+ scaled.add(child.id)++ if (child.childIds.length > 0 && compChild.childIds.length > 0) {+ scaleChildren(graph, child, compChild, hScale ? sx : 1, vScale ? sy : 1, scaled)+ }+ }+}++function propagateScaling(graph: SceneGraph, scaled: Set<string>): void {+ const clonesOf = buildClonesMap(graph)+ const queue = [...scaled]+ const visited = new Set<string>()++ for (let srcId = queue.shift(); srcId !== undefined; srcId = queue.shift()) {+ const source = graph.getNode(srcId)+ if (!source) continue+ const clones = clonesOf.get(srcId)+ if (!clones) continue+ for (const cloneId of clones) {+ if (visited.has(cloneId)) continue+ visited.add(cloneId)+ const clone = graph.getNode(cloneId)+ if (!clone) continue+ const cu: Partial<SceneNode> = {}+ if (clone.width !== source.width) cu.width = source.width+ if (clone.height !== source.height) cu.height = source.height+ if (clone.x !== source.x) cu.x = source.x+ if (clone.y !== source.y) cu.y = source.y+ if (Object.keys(cu).length > 0) graph.updateNode(cloneId, cu)+ queue.push(cloneId)+ }+ }+}diff --git a/packages/core/src/kiwi/instance-overrides/index.ts b/packages/core/src/kiwi/instance-overrides/index.tsindex 86058745b..ab3110bf3 100644--- a/packages/core/src/kiwi/instance-overrides/index.ts+++ b/packages/core/src/kiwi/instance-overrides/index.ts@@ -19,6 +19,7 @@ import { applySymbolOverrides } from './symbol-overrides'import { propagateOverridesTransitively } from './sync'import { applyComponentProperties } from './props'import { applyDerivedSymbolData } from './dsd'+import { applyConstraintScaling } from './constraints'function buildOverrideContext(graph: SceneGraph,@@ -114,4 +115,5 @@ export function populateAndApplyOverrides(}applyDerivedSymbolData(ctx)+ applyConstraintScaling(ctx)}