UNPKG

@tokens-studio/graph-engine

Version:

An execution engine to handle Token Studios generators and resolvers

52 lines 1.76 kB
import { ColorSchema, NumberSchema } from '../../schemas/index.js'; import { Node } from '../../programmatic/node.js'; import { Red, toColor, toColorObject } from './lib/utils.js'; import { arrayOf } from '../../schemas/utils.js'; export default class NodeDefinition extends Node { static title = 'Scale colors'; static type = 'studio.tokens.color.scale'; static description = 'Create a scale/ramp of colors based on a given color by specifying the number of steps up and down'; constructor(props) { super(props); this.addInput('color', { type: { ...ColorSchema, default: Red } }); this.addInput('stepsUp', { type: { ...NumberSchema, default: 5 } }); this.addInput('stepsDown', { type: { ...NumberSchema, default: 5 } }); this.addOutput('value', { type: arrayOf(ColorSchema) }); } execute() { const { stepsUp, stepsDown, color } = this.getAllInputs(); const col = toColor(color); const sUp = Math.max(0, stepsUp) + 2; const sDown = Math.max(0, stepsDown) + 2; const lighter = col .steps('white', { space: 'hsl', steps: sUp }) .slice(0, -1) .map(x => toColorObject(x)) .reverse(); const darker = col .steps('black', { space: 'hsl', steps: sDown }) .slice(1, -1) .map(x => toColorObject(x)); //Not need to modify const final = [].concat(lighter, darker); this.outputs.value.set(final); } } //# sourceMappingURL=scale.js.map