AI-native design editor. Open-source Figma alternative.
fix(vector): default missing tangents to {x:0, y:0} in create_vector
Danila Poyarkov66b2e7c487ed
diff --git a/packages/core/src/index.ts b/packages/core/src/index.tsindex 806e0e94e..8cbec4129 100644--- a/packages/core/src/index.ts+++ b/packages/core/src/index.ts@@ -26,6 +26,7 @@ export {SceneGraph,generateId,cloneVectorNetwork,+ normalizeVectorNetwork,type SceneNode,type NodeType,type Fill,diff --git a/packages/core/src/scene-graph/index.ts b/packages/core/src/scene-graph/index.tsindex 03e79301f..ab75fbcea 100644--- a/packages/core/src/scene-graph/index.ts+++ b/packages/core/src/scene-graph/index.ts@@ -78,6 +78,25 @@ export function cloneVectorNetwork(vn: VectorNetwork): VectorNetwork {}}+/**+ * Ensure every segment has tangentStart/tangentEnd.+ * Missing tangents default to {x:0, y:0} (straight line segments).+ * Use at system boundaries where input may come from JSON/MCP.+ */+export function normalizeVectorNetwork(vn: VectorNetwork): VectorNetwork {+ const ZERO: Vector = { x: 0, y: 0 }+ return {+ vertices: vn.vertices,+ segments: vn.segments.map((s) => ({+ start: s.start,+ end: s.end,+ tangentStart: (s as Partial<VectorSegment>).tangentStart ?? { ...ZERO },+ tangentEnd: (s as Partial<VectorSegment>).tangentEnd ?? { ...ZERO }+ })),+ regions: vn.regions+ }+}+export interface GeometryPath {windingRule: WindingRulecommandsBlob: Uint8Arraydiff --git a/packages/core/src/tools/create.ts b/packages/core/src/tools/create.tsindex 32e827b3a..aeddbc9f5 100644--- a/packages/core/src/tools/create.ts+++ b/packages/core/src/tools/create.ts@@ -1,6 +1,7 @@import { parseColor } from '../color'import { fetchIcons, searchIconsBatch } from '../icons'import { createIconFromPaths } from '../icons/render'+import { normalizeVectorNetwork } from '../scene-graph'import { defineTool, nodeSummary } from './schema'import type { FigmaNodeProxy } from '../figma-api'@@ -169,7 +170,8 @@ export const createVector = defineTool({node.y = args.yif (args.name) node.name = args.nameif (args.path) {- figma.graph.updateNode(node.id, { vectorNetwork: JSON.parse(args.path) as VectorNetwork })+ const network = normalizeVectorNetwork(JSON.parse(args.path) as VectorNetwork)+ figma.graph.updateNode(node.id, { vectorNetwork: network })}if (args.fill) {node.fills = [{ type: 'SOLID', color: parseColor(args.fill), opacity: 1, visible: true }]