UNPKG

@tokens-studio/graph-engine

Version:

An execution engine to handle Token Studios generators and resolvers

74 lines 2.43 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 = 'Base Font Size'; static type = 'studio.tokens.typography.baseFontSize'; static description = 'calculate the base font size with DIN 1450. The output is a number representing the font size in pixels.'; constructor(props) { super(props); this.addInput('visualAcuity', { type: { ...NumberSchema, default: 0.7 } }); this.addInput('correctionFactor', { type: { ...NumberSchema, default: 13 } }); this.addInput('lightingCondition', { type: { ...NumberSchema, default: 0.83 } }); this.addInput('distance', { type: { ...NumberSchema, default: 30 } }); this.addInput('xHeightRatio', { type: { ...NumberSchema, default: 0.53 } }); this.addInput('ppi', { type: { ...NumberSchema, default: 458 } }); this.addInput('pixelDensity', { type: { ...NumberSchema, default: 3 } }); this.addInput('precision', { type: { ...NumberSchema, default: 0 } }); this.addOutput('value', { type: { ...NumberSchema, description: 'The generated font size' } }); } execute() { const { visualAcuity, lightingCondition, distance, xHeightRatio, ppi, pixelDensity, correctionFactor, precision } = this.getAllInputs(); const visualCorrection = correctionFactor * (lightingCondition / visualAcuity); const xHeightMM = Math.tan((visualCorrection * Math.PI) / 21600) * (distance * 10) * 2; const xHeightPX = (xHeightMM / 25.4) * (ppi / pixelDensity); const fontSizePX = (1 * xHeightPX) / xHeightRatio; this.outputs.value.set(setToPrecision(fontSizePX, precision)); } } //# sourceMappingURL=baseFontSize.js.map