-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add base font size node * move correction factor to inputs * add changeset --------- Co-authored-by: SorsOps <[email protected]>
- Loading branch information
Showing
7 changed files
with
135 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@tokens-studio/graph-editor": minor | ||
"@tokens-studio/graph-engine": minor | ||
--- | ||
|
||
Adds a base font node based on german DIN 1450 and calculates the min required font size for readability |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
packages/graph-editor/src/components/flow/nodes/accessibility/baseFontSizeNode.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// ui | ||
import { Stack, Text } from '@tokens-studio/ui'; | ||
import { Handle, HandleContainer } from '../../../../components/flow/handles.tsx'; | ||
import { WrapNode, useNode } from '../../wrapper/nodeV2.tsx'; | ||
import { node } from '@tokens-studio/graph-engine/nodes/accessibility/baseFontSize.js'; | ||
import PreviewNumber from '../../preview/number.tsx'; | ||
import React from 'react'; | ||
|
||
const BaseFontSizeNode = (props) => { | ||
const { input, output, state, setState } = useNode(); | ||
|
||
return ( | ||
<Stack direction="row" gap={4}> | ||
<HandleContainer type="target"> | ||
<Handle id="visualAcuity"> | ||
<Text>Visual Acuity</Text> | ||
<PreviewNumber value={input.visualAcuity} /> | ||
</Handle> | ||
<Handle id="lightingCondition"> | ||
<Text>Lighting Condition</Text> | ||
<PreviewNumber value={input.lightingCondition} /> | ||
</Handle> | ||
<Handle id="distance"> | ||
<Text>Distance</Text> | ||
<PreviewNumber value={input.distance} /> | ||
</Handle> | ||
<Handle id="xHeightRatio"> | ||
<Text>X-Height Ratio</Text> | ||
<PreviewNumber value={input.xHeightRatio} /> | ||
</Handle> | ||
<Handle id="ppi"> | ||
<Text>PPI</Text> | ||
<PreviewNumber value={input.ppi} /> | ||
</Handle> | ||
<Handle id="pixelDensity"> | ||
<Text>Pixel Density</Text> | ||
<PreviewNumber value={input.pixelDensity} /> | ||
</Handle> | ||
<Handle id="correctionFactor"> | ||
<Text>Correction Factor</Text> | ||
<PreviewNumber value={input.correctionFactor} /> | ||
</Handle> | ||
</HandleContainer> | ||
|
||
<HandleContainer type="source"> | ||
<Handle id="output"> | ||
<Text>Font Size:</Text> | ||
<PreviewNumber value={output?.fontSizePX} /> | ||
</Handle> | ||
</HandleContainer> | ||
</Stack> | ||
); | ||
}; | ||
|
||
export default WrapNode(BaseFontSizeNode, { | ||
...node, | ||
title: 'Base Font Size', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
packages/graph-engine/src/nodes/accessibility/baseFontSize.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// node | ||
/** | ||
* Calculates the base font size | ||
* | ||
* @packageDocumentation | ||
*/ | ||
|
||
import { NodeDefinition, NodeTypes } from "../../types.js"; | ||
|
||
const type = NodeTypes.BASE_FONT_SIZE; | ||
|
||
type Inputs = { | ||
visualAcuity: number; | ||
lightingCondition: number; | ||
distance: number; | ||
xHeightRatio: number; | ||
ppi: number; | ||
pixelDensity: number; | ||
correctionFactor: number; | ||
}; | ||
|
||
const defaults = { | ||
correctionFactor: 13, | ||
visualAcuity: 0.7, | ||
lightingCondition: 0.85, | ||
distance: 30, | ||
xHeightRatio: 0.53, | ||
ppi: 458, | ||
pixelDensity: 3 | ||
}; | ||
|
||
const process = (input: Inputs, state) => { | ||
const { | ||
visualAcuity, | ||
lightingCondition, | ||
distance, | ||
xHeightRatio, | ||
ppi, | ||
pixelDensity, | ||
correctionFactor | ||
} = input; | ||
|
||
const visualCorrection = correctionFactor * (lightingCondition / visualAcuity); | ||
const xHeightMM = Math.tan(visualCorrection * Math.PI / 21600) * (distance * 10) * 2; | ||
const xHeightPX = (xHeightMM / 25.4) * (ppi / pixelDensity); | ||
const fontSizePT = 2.83465 * xHeightMM * 1 / xHeightRatio; | ||
const fontSizePX = 1 * xHeightPX / xHeightRatio; | ||
|
||
return { fontSizePX }; | ||
}; | ||
|
||
export const mapOutput = (input, state, processed) => { | ||
return processed; | ||
}; | ||
|
||
export const node: NodeDefinition<Inputs> = { | ||
type, | ||
defaults, | ||
process, | ||
mapOutput | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { node as colorBlindness } from "./colorBlindness.js"; | ||
import { node as contrast } from "./contrast.js"; | ||
import { node as baseFontSize } from "./baseFontSize.js"; | ||
|
||
export const nodes = [contrast, colorBlindness]; | ||
export const nodes = [contrast, colorBlindness, baseFontSize]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters