convert-dimension
This parser helps you convert units of dimension tokens (spacing, sizing, breakpoint, blur...) and composite tokens sub values (font-size, letter-spacing, border-width...)
Interface
interface parser {
name: 'convert-dimension';
options: {
toFormat:
| '%'
| 'px'
| 'em'
| 'rem'
| 'pt'
| 'pc'
| 'in'
| 'cm'
| 'mm'
| 'ex'
| 'cap'
| 'ch'
| 'ic'
| 'lh'
| 'rlh'
| 'vw'
| 'svw'
| 'lvw'
| 'dvw'
| 'vh'
| 'svh'
| 'lvh'
| 'dvh'
| 'vi'
| 'svi'
| 'lvi'
| 'dvi'
| 'vb'
| 'svb'
| 'lvb'
| 'dvb'
| 'vmin'
| 'svmin'
| 'lvmin'
| 'dvmin'
| 'vmax'
| 'svmax'
| 'lvmax'
| 'dvmax'
| null;
baseValue?: {
rem?: number
};
applyTo?: SDTFQuery;
applyToKeys?: {
textStyle?: Array<'fontSize' | 'lineHeight' | 'letterSpacing' | 'paragraphSpacing'| 'textIndent'>,
shadow?: Array<'offsetX' | 'offsetY' | 'blurRadius' | 'spreadRadius'>,
border?: Array<'width' | 'rectangleCornerRadii'>,
};
excludeFormats?: array;
includeFormats?: array;
};
}Options
toFormat
required
The target dimension format to convert to.
baseValue
false
applyTo
false
The selection where to apply the transformation.
collection, group, token take a Regex string or true to select anything of the kind.
An SDTFQuery can be used for advance use cases.
applyToKeys
false
Select composite tokens sub-values to convert
excludeFormats
false
array
List of dimension formats you don't want to convert.
includeFormats
false
array
List of dimension formats you only want to convert.
Examples
Basic usage
We convert all dimensions from our SDTF graph in rem.
We then generate our transformed SDTF graph in a JSON file thanks to the to-sdtf parser.
Generate unitless dimension tokens
Convert text style's font-size from px to rem
Last updated
Was this helpful?