@tokens-studio/graph-engine
Version:
An execution engine to handle Token Studios generators and resolvers
50 lines • 1.6 kB
JavaScript
import { Node } from '../../programmatic/node.js';
import { NumberSchema } from '../../schemas/index.js';
import { arrayOf } from '../../schemas/utils.js';
import { setToPrecision } from '../../utils/precision.js';
export default class NodeDefinition extends Node {
static title = 'Linear Space';
static type = 'studio.tokens.series.linear';
static description = 'Creates evenly spaced numbers over a specified interval';
constructor(props) {
super(props);
this.addInput('start', {
type: {
...NumberSchema,
default: 0
}
});
this.addInput('stop', {
type: {
...NumberSchema,
default: 1
}
});
this.addInput('length', {
type: {
...NumberSchema,
default: 5
}
});
this.addInput('precision', {
type: {
...NumberSchema,
default: 2
}
});
this.addOutput('array', {
type: arrayOf(NumberSchema)
});
}
execute() {
const { start, stop, length, precision } = this.getAllInputs();
if (length <= 1) {
this.outputs.array.set([setToPrecision(start, precision)]);
return;
}
const step = (stop - start) / (length - 1);
const values = Array.from({ length: length }).map((_, i) => setToPrecision(start + step * i, precision));
this.outputs.array.set(values);
}
}
//# sourceMappingURL=linear.js.map