AI-native design editor. Open-source Figma alternative.
import type { Fill, Stroke } from '@open-pencil/scene-graph'
import { parseCSSColor, parseCSSNumber } from '@open-pencil/scene-graph/css'
import type { DesignStyleDeclaration } from '../types'
export function colorToFillFromCSS(value: string | undefined): Fill[] {
const color = parseCSSColor(value)
if (!color) return []
return [{ type: 'SOLID', color, opacity: color.a, visible: true }]
}
export function colorToStrokeFromCSS(
colorValue: string | undefined,
weightValue: string | undefined
): Stroke[] {
const color = parseCSSColor(colorValue)
const weight = parseCSSNumber(weightValue)
if (!color || weight === null || weight <= 0) return []
return [{ type: 'SOLID', color, weight, opacity: color.a, visible: true, align: 'INSIDE' }]
}
export function pickStyle(elementStyle: DesignStyleDeclaration | undefined, property: string) {
return elementStyle?.[property]
}
export function mergedStyle(node: {
inlineStyle?: DesignStyleDeclaration
computedStyle?: DesignStyleDeclaration
}) {
return { ...node.inlineStyle, ...node.computedStyle }
}