UNPKG

@tokens-studio/graph-engine

Version:

An execution engine to handle Token Studios generators and resolvers

39 lines 1.2 kB
import { Node } from '../../programmatic/node.js'; import { NumberSchema } from '../../schemas/index.js'; import { setToPrecision } from '../../utils/precision.js'; export default class NodeDefinition extends Node { static title = 'Difference'; static type = 'studio.tokens.math.difference'; static description = 'Calculates the absolute difference between two numbers'; constructor(props) { super(props); this.addInput('a', { type: { ...NumberSchema, default: 0 } }); this.addInput('b', { type: { ...NumberSchema, default: 0 } }); this.addInput('precision', { type: { ...NumberSchema, default: 2, minimum: 0 } }); this.addOutput('difference', { type: NumberSchema }); } execute() { const { a, b, precision } = this.getAllInputs(); const difference = Math.abs(a - b); this.outputs.difference.set(setToPrecision(difference, precision)); } } //# sourceMappingURL=difference.js.map