UNPKG

@tokens-studio/graph-engine

Version:

An execution engine to handle Token Studios generators and resolvers

37 lines 1.13 kB
import valueParser from 'postcss-value-parser-esm'; import { Node } from '../../programmatic/node.js'; import { StringSchema } from '../../schemas/index.js'; export default class NodeDefinition extends Node { static title = 'Pass unit'; static type = 'studio.tokens.typing.passUnit'; static description = "Adds a unit to a value if it doesn't already have one"; constructor(props) { super(props); this.addInput('value', { type: StringSchema }); this.addInput('fallback', { type: { ...StringSchema, default: 'px' } }); this.addOutput('value', { type: StringSchema }); } execute() { const { value, fallback } = this.getAllInputs(); const x = valueParser.unit(value); if (!x) { throw Error('Could not parse unit'); } if (x.unit) { this.outputs.value.set(value); } else { this.outputs.value.set(`${value}${fallback || ''}`); } } } //# sourceMappingURL=passUnit.js.map