UNPKG

@tokens-studio/graph-engine

Version:

An execution engine to handle Token Studios generators and resolvers

47 lines 1.64 kB
import { ColorSchema, NumberSchema, StringSchema } from '../../schemas/index.js'; import { Node } from '../../programmatic/node.js'; export default class DestructColorNode extends Node { static title = 'Deconstruct Color'; static type = 'studio.tokens.color.deconstruct'; static description = 'Deconstructs a color object into its individual components'; constructor(props) { super(props); this.addInput('color', { type: ColorSchema }); this.addOutput('space', { type: StringSchema }); this.addOutput('a', { type: NumberSchema }); this.addOutput('b', { type: NumberSchema }); this.addOutput('c', { type: NumberSchema }); this.addOutput('alpha', { type: NumberSchema }); } execute() { const { color } = this.getAllInputs(); if (!color || !color.channels || !color.space) { throw new Error('Invalid color input'); } this.outputs.space.set(color.space); // Set channel values, defaulting to 0 if NaN this.outputs.a.set(isNaN(color.channels[0]) ? 0 : color.channels[0]); this.outputs.b.set(isNaN(color.channels[1]) ? 0 : color.channels[1]); this.outputs.c.set(isNaN(color.channels[2]) ? 0 : color.channels[2]); // Only set alpha if it exists if (color.alpha !== undefined) { this.outputs.alpha.set(color.alpha); } else { this.outputs.alpha.set(undefined); } } } //# sourceMappingURL=deconstruct.js.map