@tokens-studio/graph-engine
Version:
An execution engine to handle Token Studios generators and resolvers
43 lines • 1.36 kB
JavaScript
import { Black, toColor } from './lib/utils.js';
import { ColorSchema, StringSchema } from '../../schemas/index.js';
import { ColorSpaces } from './lib/spaces.js';
import { Node } from '../../programmatic/node.js';
export default class NodeDefinition extends Node {
static title = 'Color to string';
static type = 'studio.tokens.color.colorToString';
static description = 'Converts a color to a string';
constructor(props) {
super(props);
this.addInput('color', {
type: {
...ColorSchema,
default: Black
}
});
this.addInput('space', {
type: {
...StringSchema,
enum: ['hex', ...ColorSpaces],
default: 'hex'
}
});
this.addOutput('value', {
type: StringSchema
});
}
execute() {
// eslint-disable-next-line prefer-const
const { color, space } = this.getAllInputs();
let adjustedSpace = space;
let format = undefined;
if (space == 'hex') {
adjustedSpace = 'srgb';
format = {
format: 'hex'
};
}
const col = toColor(color).to(adjustedSpace).toString(format);
this.outputs.value.set(col);
}
}
//# sourceMappingURL=colorToString.js.map