@tokens-studio/graph-engine
Version:
An execution engine to handle Token Studios generators and resolvers
49 lines • 1.61 kB
JavaScript
import { Black, White, toColor } from './lib/utils.js';
import { ColorSchema, NumberSchema, StringSchema } from '../../schemas/index.js';
import { Node } from '../../programmatic/node.js';
import { setToPrecision } from '../../utils/precision.js';
export const algorithms = ['76', 'CMC', '2000', 'Jz', 'ITP', 'OK'];
export default class NodeDefinition extends Node {
static title = 'Delta E (ΔE)';
static type = 'studio.tokens.color.deltaE';
static description = 'Delta E node allows you to calculate the distance between two colors.';
constructor(props) {
super(props);
this.addInput('colorA', {
type: {
...ColorSchema,
default: White
}
});
this.addInput('colorB', {
type: {
...ColorSchema,
default: Black
}
});
this.addInput('precision', {
type: {
...NumberSchema,
default: 4
}
});
this.addInput('algorithm', {
type: {
...StringSchema,
enum: algorithms,
default: '2000'
}
});
this.addOutput('value', {
type: NumberSchema
});
}
execute() {
const { colorA, colorB, algorithm, precision } = this.getAllInputs();
const a = toColor(colorA);
const b = toColor(colorB);
const distance = a.deltaE(b, algorithm);
this.outputs.value.set(setToPrecision(distance, precision));
}
}
//# sourceMappingURL=deltaE.js.map