@primer/primitives 9.0.3 → 9.1.0-rc.56a8ee48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build/PrimerStyleDictionary.d.ts +9 -0
- package/dist/build/PrimerStyleDictionary.js +93 -0
- package/dist/build/filters/index.d.ts +13 -0
- package/dist/build/filters/index.js +29 -0
- package/{src/filters/isBorder.ts → dist/build/filters/isBorder.d.ts} +2 -5
- package/dist/build/filters/isBorder.js +12 -0
- package/{src/filters/isColor.ts → dist/build/filters/isColor.d.ts} +2 -5
- package/dist/build/filters/isColor.js +12 -0
- package/dist/build/filters/isColorWithAlpha.d.ts +7 -0
- package/dist/build/filters/isColorWithAlpha.js +13 -0
- package/dist/build/filters/isColorWithMix.d.ts +7 -0
- package/dist/build/filters/isColorWithMix.js +28 -0
- package/{src/filters/isDeprecated.ts → dist/build/filters/isDeprecated.d.ts} +2 -5
- package/dist/build/filters/isDeprecated.js +12 -0
- package/{src/filters/isDimension.ts → dist/build/filters/isDimension.d.ts} +2 -5
- package/dist/build/filters/isDimension.js +12 -0
- package/{src/filters/isDuration.ts → dist/build/filters/isDuration.d.ts} +2 -5
- package/dist/build/filters/isDuration.js +12 -0
- package/{src/filters/isFontFamily.ts → dist/build/filters/isFontFamily.d.ts} +2 -5
- package/dist/build/filters/isFontFamily.js +12 -0
- package/{src/filters/isFontWeight.ts → dist/build/filters/isFontWeight.d.ts} +2 -5
- package/dist/build/filters/isFontWeight.js +12 -0
- package/dist/build/filters/isFromFile.d.ts +8 -0
- package/dist/build/filters/isFromFile.js +14 -0
- package/{src/filters/isNumber.ts → dist/build/filters/isNumber.d.ts} +2 -3
- package/dist/build/filters/isNumber.js +10 -0
- package/{src/filters/isShadow.ts → dist/build/filters/isShadow.d.ts} +2 -5
- package/dist/build/filters/isShadow.js +12 -0
- package/{src/filters/isSource.ts → dist/build/filters/isSource.d.ts} +2 -5
- package/dist/build/filters/isSource.js +12 -0
- package/{src/filters/isTypography.ts → dist/build/filters/isTypography.d.ts} +2 -5
- package/dist/build/filters/isTypography.js +12 -0
- package/dist/build/formats/cssAdvanced.d.ts +2 -0
- package/dist/build/formats/cssAdvanced.js +84 -0
- package/dist/build/formats/cssCustomMedia.d.ts +7 -0
- package/dist/build/formats/cssCustomMedia.js +25 -0
- package/dist/build/formats/index.d.ts +9 -0
- package/dist/build/formats/index.js +21 -0
- package/dist/build/formats/javascriptCommonJs.d.ts +7 -0
- package/dist/build/formats/javascriptCommonJs.js +25 -0
- package/dist/build/formats/javascriptEsm.d.ts +7 -0
- package/dist/build/formats/javascriptEsm.js +25 -0
- package/dist/build/formats/jsonFigma.d.ts +7 -0
- package/dist/build/formats/jsonFigma.js +116 -0
- package/dist/build/formats/jsonNestedPrefixed.d.ts +8 -0
- package/dist/build/formats/jsonNestedPrefixed.js +28 -0
- package/dist/build/formats/jsonOneDimensional.d.ts +8 -0
- package/dist/build/formats/jsonOneDimensional.js +24 -0
- package/dist/build/formats/jsonPostCssFallback.d.ts +8 -0
- package/dist/build/formats/jsonPostCssFallback.js +21 -0
- package/dist/build/formats/typescriptExportDefinition.d.ts +7 -0
- package/dist/build/formats/typescriptExportDefinition.js +166 -0
- package/{src/formats/utilities/jsonToFlat.ts → dist/build/formats/utilities/jsonToFlat.d.ts} +4 -3
- package/dist/build/formats/utilities/jsonToFlat.js +12 -0
- package/dist/build/formats/utilities/jsonToNestedValue.d.ts +8 -0
- package/dist/build/formats/utilities/jsonToNestedValue.js +25 -0
- package/dist/build/formats/utilities/prefixTokens.d.ts +8 -0
- package/dist/build/formats/utilities/prefixTokens.js +17 -0
- package/dist/build/parsers/index.d.ts +1 -0
- package/dist/build/parsers/index.js +5 -0
- package/dist/build/parsers/w3cJsonParser.d.ts +6 -0
- package/dist/build/parsers/w3cJsonParser.js +27 -0
- package/dist/build/platforms/css.d.ts +2 -0
- package/dist/build/platforms/css.js +88 -0
- package/dist/build/platforms/deprecatedJson.d.ts +2 -0
- package/dist/build/platforms/deprecatedJson.js +17 -0
- package/dist/build/platforms/docJson.d.ts +2 -0
- package/dist/build/platforms/docJson.js +35 -0
- package/dist/build/platforms/fallbacks.d.ts +2 -0
- package/dist/build/platforms/fallbacks.js +35 -0
- package/dist/build/platforms/figma.d.ts +2 -0
- package/dist/build/platforms/figma.js +53 -0
- package/dist/build/platforms/index.d.ts +10 -0
- package/dist/build/platforms/index.js +23 -0
- package/dist/build/platforms/javascript.d.ts +2 -0
- package/dist/build/platforms/javascript.js +31 -0
- package/dist/build/platforms/json.d.ts +2 -0
- package/dist/build/platforms/json.js +33 -0
- package/dist/build/platforms/styleLint.d.ts +2 -0
- package/dist/build/platforms/styleLint.js +35 -0
- package/dist/build/platforms/typeDefinitions.d.ts +2 -0
- package/dist/build/platforms/typeDefinitions.js +31 -0
- package/dist/build/platforms/typescript.d.ts +2 -0
- package/dist/build/platforms/typescript.js +31 -0
- package/dist/build/schemas/alphaValue.d.ts +2 -0
- package/dist/build/schemas/alphaValue.js +8 -0
- package/dist/build/schemas/baseToken.d.ts +11 -0
- package/dist/build/schemas/baseToken.js +10 -0
- package/dist/build/schemas/borderToken.d.ts +51 -0
- package/dist/build/schemas/borderToken.js +20 -0
- package/dist/build/schemas/collections.d.ts +6 -0
- package/dist/build/schemas/collections.js +18 -0
- package/dist/build/schemas/colorHexValue.d.ts +2 -0
- package/dist/build/schemas/colorHexValue.js +12 -0
- package/dist/build/schemas/colorToken.d.ts +80 -0
- package/dist/build/schemas/colorToken.js +52 -0
- package/dist/build/schemas/designToken.d.ts +2 -0
- package/dist/build/schemas/designToken.js +37 -0
- package/dist/build/schemas/dimensionToken.d.ts +52 -0
- package/dist/build/schemas/dimensionToken.js +36 -0
- package/dist/build/schemas/dimensionValue.d.ts +2 -0
- package/dist/build/schemas/dimensionValue.js +12 -0
- package/dist/build/schemas/durationToken.d.ts +18 -0
- package/dist/build/schemas/durationToken.js +14 -0
- package/dist/build/schemas/durationValue.d.ts +2 -0
- package/dist/build/schemas/durationValue.js +8 -0
- package/dist/build/schemas/fontFamilyToken.d.ts +52 -0
- package/dist/build/schemas/fontFamilyToken.js +23 -0
- package/dist/build/schemas/fontWeightToken.d.ts +52 -0
- package/dist/build/schemas/fontWeightToken.js +24 -0
- package/dist/build/schemas/fontWeightValue.d.ts +2 -0
- package/dist/build/schemas/fontWeightValue.js +9 -0
- package/dist/build/schemas/numberToken.d.ts +71 -0
- package/dist/build/schemas/numberToken.js +30 -0
- package/dist/build/schemas/referenceValue.d.ts +2 -0
- package/dist/build/schemas/referenceValue.js +8 -0
- package/dist/build/schemas/scopes.d.ts +5 -0
- package/dist/build/schemas/scopes.js +34 -0
- package/dist/build/schemas/shadowToken.d.ts +157 -0
- package/dist/build/schemas/shadowToken.js +46 -0
- package/dist/build/schemas/stringToken.d.ts +18 -0
- package/dist/build/schemas/stringToken.js +13 -0
- package/dist/build/schemas/tokenName.d.ts +2 -0
- package/dist/build/schemas/tokenName.js +8 -0
- package/dist/build/schemas/tokenType.d.ts +3 -0
- package/dist/build/schemas/tokenType.js +6 -0
- package/dist/build/schemas/typographyToken.d.ts +59 -0
- package/dist/build/schemas/typographyToken.js +21 -0
- package/dist/build/schemas/validTokenType.d.ts +5 -0
- package/dist/build/schemas/validTokenType.js +34 -0
- package/dist/build/schemas/viewportRangeToken.d.ts +18 -0
- package/dist/build/schemas/viewportRangeToken.js +13 -0
- package/dist/build/transformers/borderToCss.d.ts +8 -0
- package/dist/build/transformers/borderToCss.js +38 -0
- package/dist/build/transformers/colorToHex.d.ts +8 -0
- package/dist/build/transformers/colorToHex.js +18 -0
- package/dist/build/transformers/colorToHexAlpha.d.ts +8 -0
- package/dist/build/transformers/colorToHexAlpha.js +25 -0
- package/dist/build/transformers/colorToHexMix.d.ts +8 -0
- package/dist/build/transformers/colorToHexMix.js +25 -0
- package/dist/build/transformers/colorToRgbAlpha.d.ts +8 -0
- package/dist/build/transformers/colorToRgbAlpha.js +22 -0
- package/dist/build/transformers/colorToRgbaFloat.d.ts +8 -0
- package/dist/build/transformers/colorToRgbaFloat.js +50 -0
- package/dist/build/transformers/dimensionToPixelUnitless.d.ts +8 -0
- package/dist/build/transformers/dimensionToPixelUnitless.js +50 -0
- package/dist/build/transformers/dimensionToRem.d.ts +8 -0
- package/dist/build/transformers/dimensionToRem.js +47 -0
- package/dist/build/transformers/dimensionToRemPxArray.d.ts +8 -0
- package/dist/build/transformers/dimensionToRemPxArray.js +47 -0
- package/dist/build/transformers/durationToCss.d.ts +8 -0
- package/dist/build/transformers/durationToCss.js +30 -0
- package/dist/build/transformers/figmaAttributes.d.ts +8 -0
- package/dist/build/transformers/figmaAttributes.js +57 -0
- package/dist/build/transformers/floatToPixel.d.ts +15 -0
- package/dist/build/transformers/floatToPixel.js +41 -0
- package/dist/build/transformers/fontFamilyToCss.d.ts +14 -0
- package/dist/build/transformers/fontFamilyToCss.js +40 -0
- package/dist/build/transformers/fontFamilyToFigma.d.ts +14 -0
- package/dist/build/transformers/fontFamilyToFigma.js +46 -0
- package/dist/build/transformers/fontWeightToNumber.d.ts +9 -0
- package/dist/build/transformers/fontWeightToNumber.js +53 -0
- package/dist/build/transformers/index.d.ts +25 -0
- package/dist/build/transformers/index.js +53 -0
- package/dist/build/transformers/jsonDeprecated.d.ts +8 -0
- package/dist/build/transformers/jsonDeprecated.js +16 -0
- package/{src/transformers/namePathToCamelCase.ts → dist/build/transformers/namePathToCamelCase.d.ts} +2 -8
- package/dist/build/transformers/namePathToCamelCase.js +14 -0
- package/dist/build/transformers/namePathToDotNotation.d.ts +8 -0
- package/dist/build/transformers/namePathToDotNotation.js +33 -0
- package/dist/build/transformers/namePathToFigma.d.ts +9 -0
- package/dist/build/transformers/namePathToFigma.js +24 -0
- package/dist/build/transformers/namePathToKebabCase.d.ts +8 -0
- package/dist/build/transformers/namePathToKebabCase.js +18 -0
- package/dist/build/transformers/namePathToPascalCase.d.ts +8 -0
- package/dist/build/transformers/namePathToPascalCase.js +14 -0
- package/dist/build/transformers/namePathToSlashNotation.d.ts +8 -0
- package/dist/build/transformers/namePathToSlashNotation.js +18 -0
- package/dist/build/transformers/shadowToCss.d.ts +8 -0
- package/dist/build/transformers/shadowToCss.js +35 -0
- package/dist/build/transformers/typographyToCss.d.ts +8 -0
- package/dist/build/transformers/typographyToCss.js +29 -0
- package/dist/build/transformers/utilities/alpha.d.ts +9 -0
- package/dist/build/transformers/utilities/alpha.js +20 -0
- package/dist/build/transformers/utilities/checkRequiredTokenProperties.d.ts +7 -0
- package/dist/build/transformers/utilities/checkRequiredTokenProperties.js +17 -0
- package/dist/build/transformers/utilities/getTokenValue.d.ts +2 -0
- package/dist/build/transformers/utilities/getTokenValue.js +18 -0
- package/dist/build/transformers/utilities/hasSpaceInString.d.ts +1 -0
- package/dist/build/transformers/utilities/hasSpaceInString.js +10 -0
- package/dist/build/transformers/utilities/hexToRgbaFloat.d.ts +2 -0
- package/dist/build/transformers/utilities/hexToRgbaFloat.js +33 -0
- package/dist/build/transformers/utilities/invalidTokenError.d.ts +7 -0
- package/dist/build/transformers/utilities/invalidTokenError.js +26 -0
- package/dist/build/transformers/utilities/isRgbaFloat.d.ts +7 -0
- package/dist/build/transformers/utilities/isRgbaFloat.js +24 -0
- package/dist/build/transformers/utilities/mix.d.ts +5 -0
- package/dist/build/transformers/utilities/mix.js +40 -0
- package/dist/build/transformers/utilities/rgbaFloatToHex.d.ts +6 -0
- package/dist/build/transformers/utilities/rgbaFloatToHex.js +15 -0
- package/dist/build/utilities/copyFromDir.d.ts +8 -0
- package/dist/build/utilities/copyFromDir.js +34 -0
- package/dist/build/utilities/filterStringArray.d.ts +1 -0
- package/dist/build/utilities/filterStringArray.js +17 -0
- package/{src/utilities/getFlag.ts → dist/build/utilities/getFlag.d.ts} +1 -5
- package/dist/build/utilities/getFlag.js +16 -0
- package/dist/build/utilities/index.d.ts +3 -0
- package/dist/build/utilities/index.js +9 -0
- package/dist/build/utilities/joinFriendly.d.ts +1 -0
- package/dist/build/utilities/joinFriendly.js +5 -0
- package/dist/build/utilities/schemaErrorMessage.d.ts +1 -0
- package/dist/build/utilities/schemaErrorMessage.js +5 -0
- package/dist/build/utilities/toCamelCase.d.ts +1 -0
- package/dist/build/utilities/toCamelCase.js +20 -0
- package/dist/build/utilities/toPascalCase.d.ts +1 -0
- package/dist/build/utilities/toPascalCase.js +17 -0
- package/dist/build/utilities/treeWalker.d.ts +8 -0
- package/dist/build/utilities/treeWalker.js +27 -0
- package/{src/utilities/upperCaseFirstCharacter.ts → dist/build/utilities/upperCaseFirstCharacter.d.ts} +1 -3
- package/dist/build/utilities/upperCaseFirstCharacter.js +14 -0
- package/dist/css/functional/motion/motion.css +3 -3
- package/dist/css/functional/size/border.css +2 -2
- package/dist/css/functional/typography/typography.css +11 -11
- package/dist/css/primitives.css +16 -16
- package/package.json +6 -8
- package/src/PrimerStyleDictionary.ts +0 -232
- package/src/filters/index.ts +0 -13
- package/src/filters/isColorWithAlpha.ts +0 -11
- package/src/filters/isColorWithMix.ts +0 -33
- package/src/filters/isFromFile.ts +0 -12
- package/src/formats/cssAdvanced.ts +0 -99
- package/src/formats/cssCustomMedia.ts +0 -24
- package/src/formats/index.ts +0 -9
- package/src/formats/javascriptCommonJs.ts +0 -21
- package/src/formats/javascriptEsm.ts +0 -21
- package/src/formats/jsonFigma.ts +0 -134
- package/src/formats/jsonNestedPrefixed.ts +0 -23
- package/src/formats/jsonOneDimensional.ts +0 -18
- package/src/formats/jsonPostCssFallback.ts +0 -16
- package/src/formats/typescriptExportDefinition.ts +0 -170
- package/src/formats/utilities/jsonToNestedValue.ts +0 -20
- package/src/formats/utilities/prefixTokens.ts +0 -17
- package/src/parsers/index.ts +0 -1
- package/src/parsers/w3cJsonParser.ts +0 -25
- package/src/platforms/css.ts +0 -101
- package/src/platforms/deprecatedJson.ts +0 -16
- package/src/platforms/docJson.ts +0 -34
- package/src/platforms/fallbacks.ts +0 -34
- package/src/platforms/figma.ts +0 -58
- package/src/platforms/index.ts +0 -10
- package/src/platforms/javascript.ts +0 -30
- package/src/platforms/json.ts +0 -32
- package/src/platforms/styleLint.ts +0 -34
- package/src/platforms/typeDefinitions.ts +0 -30
- package/src/platforms/typescript.ts +0 -30
- package/src/schemas/alphaValue.ts +0 -12
- package/src/schemas/baseToken.ts +0 -8
- package/src/schemas/borderToken.ts +0 -19
- package/src/schemas/collections.ts +0 -49
- package/src/schemas/colorHexValue.ts +0 -18
- package/src/schemas/colorToken.ts +0 -50
- package/src/schemas/designToken.ts +0 -38
- package/src/schemas/dimensionToken.ts +0 -34
- package/src/schemas/dimensionValue.ts +0 -16
- package/src/schemas/durationToken.ts +0 -12
- package/src/schemas/durationValue.ts +0 -9
- package/src/schemas/fontFamilyToken.ts +0 -21
- package/src/schemas/fontWeightToken.ts +0 -22
- package/src/schemas/fontWeightValue.ts +0 -14
- package/src/schemas/numberToken.ts +0 -28
- package/src/schemas/referenceValue.ts +0 -12
- package/src/schemas/scopes.ts +0 -40
- package/src/schemas/shadowToken.ts +0 -45
- package/src/schemas/stringToken.ts +0 -11
- package/src/schemas/tokenName.ts +0 -12
- package/src/schemas/tokenType.ts +0 -4
- package/src/schemas/typographyToken.ts +0 -20
- package/src/schemas/validTokenType.ts +0 -44
- package/src/schemas/viewportRangeToken.ts +0 -11
- package/src/test-utilities/getMockDictionary.ts +0 -22
- package/src/test-utilities/getMockFormatterArguments.ts +0 -21
- package/src/test-utilities/getMockParserInput.ts +0 -72
- package/src/test-utilities/getMockToken.ts +0 -25
- package/src/test-utilities/index.ts +0 -4
- package/src/transformers/borderToCss.ts +0 -38
- package/src/transformers/colorToHex.ts +0 -16
- package/src/transformers/colorToHexAlpha.ts +0 -23
- package/src/transformers/colorToHexMix.ts +0 -19
- package/src/transformers/colorToRgbAlpha.ts +0 -19
- package/src/transformers/colorToRgbaFloat.ts +0 -45
- package/src/transformers/dimensionToPixelUnitless.ts +0 -60
- package/src/transformers/dimensionToRem.ts +0 -56
- package/src/transformers/dimensionToRemPxArray.ts +0 -60
- package/src/transformers/durationToCss.ts +0 -29
- package/src/transformers/figmaAttributes.ts +0 -79
- package/src/transformers/floatToPixel.ts +0 -40
- package/src/transformers/fontFamilyToCss.ts +0 -37
- package/src/transformers/fontFamilyToFigma.ts +0 -47
- package/src/transformers/fontWeightToNumber.ts +0 -53
- package/src/transformers/index.ts +0 -24
- package/src/transformers/jsonDeprecated.ts +0 -15
- package/src/transformers/namePathToDotNotation.ts +0 -34
- package/src/transformers/namePathToFigma.ts +0 -28
- package/src/transformers/namePathToKebabCase.ts +0 -19
- package/src/transformers/namePathToSlashNotation.ts +0 -19
- package/src/transformers/shadowToCss.ts +0 -37
- package/src/transformers/typographyToCss.ts +0 -31
- package/src/transformers/utilities/alpha.ts +0 -23
- package/src/transformers/utilities/checkRequiredTokenProperties.ts +0 -16
- package/src/transformers/utilities/getTokenValue.ts +0 -18
- package/src/transformers/utilities/hasSpaceInString.ts +0 -6
- package/src/transformers/utilities/hexToRgbaFloat.ts +0 -31
- package/src/transformers/utilities/invalidTokenError.ts +0 -34
- package/src/transformers/utilities/isRgbaFloat.ts +0 -29
- package/src/transformers/utilities/mix.ts +0 -46
- package/src/transformers/utilities/rgbaFloatToHex.ts +0 -15
- package/src/types/Border.d.ts +0 -5
- package/src/types/BorderTokenValue.d.ts +0 -10
- package/src/types/ColorHex.d.ts +0 -4
- package/src/types/PlatformInitializer.d.ts +0 -11
- package/src/types/Shadow.d.ts +0 -5
- package/src/types/ShadowTokenValue.d.ts +0 -14
- package/src/types/SizeEm.d.ts +0 -4
- package/src/types/SizePx.d.ts +0 -4
- package/src/types/SizeRem.d.ts +0 -4
- package/src/types/StyleDictionaryConfigGenerator.d.ts +0 -15
- package/src/types/TokenBuildInput.d.ts +0 -8
- package/src/types/TypographyTokenValue.d.ts +0 -12
- package/src/types/w3cTransformedToken.d.ts +0 -8
- package/src/utilities/copyFromDir.ts +0 -21
- package/src/utilities/index.ts +0 -3
- package/src/utilities/joinFriendly.ts +0 -2
- package/src/utilities/schemaErrorMessage.ts +0 -2
- package/src/utilities/toCamelCase.ts +0 -29
- package/src/utilities/treeWalker.ts +0 -27
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import {toHex} from 'color2k'
|
|
2
|
-
import {isColor} from '../filters'
|
|
3
|
-
import type StyleDictionary from 'style-dictionary'
|
|
4
|
-
import {getTokenValue} from './utilities/getTokenValue'
|
|
5
|
-
import {rgbaFloatToHex} from './utilities/rgbaFloatToHex'
|
|
6
|
-
import mix from './utilities/mix'
|
|
7
|
-
import {hexToRgbaFloat} from './utilities/hexToRgbaFloat'
|
|
8
|
-
import {isRgbaFloat} from './utilities/isRgbaFloat'
|
|
9
|
-
|
|
10
|
-
const toRgbaFloat = (token: StyleDictionary.TransformedToken, alpha?: number) => {
|
|
11
|
-
let tokenValue = getTokenValue(token)
|
|
12
|
-
let tokenMixColor = token.mix?.color
|
|
13
|
-
// get hex value from color string
|
|
14
|
-
if (isRgbaFloat(tokenValue)) {
|
|
15
|
-
tokenValue = rgbaFloatToHex(tokenValue, false)
|
|
16
|
-
}
|
|
17
|
-
if (tokenMixColor && isRgbaFloat(tokenMixColor)) {
|
|
18
|
-
tokenMixColor = rgbaFloatToHex(tokenMixColor, false)
|
|
19
|
-
}
|
|
20
|
-
let hex = toHex(tokenValue)
|
|
21
|
-
// mix color with mix color and weight
|
|
22
|
-
if (token.mix && token.mix.color && token.mix.weight) {
|
|
23
|
-
hex = toHex(mix(tokenValue, tokenMixColor, token.mix.weight))
|
|
24
|
-
}
|
|
25
|
-
// return color as RgbaFloat
|
|
26
|
-
return hexToRgbaFloat(hex, alpha)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* @description converts color tokens rgba float with values from 0 - 1
|
|
31
|
-
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
32
|
-
* @matcher matches all tokens of $type `color`
|
|
33
|
-
* @transformer returns a `rgb` float object
|
|
34
|
-
*/
|
|
35
|
-
export const colorToRgbaFloat: StyleDictionary.Transform = {
|
|
36
|
-
type: `value`,
|
|
37
|
-
transitive: true,
|
|
38
|
-
matcher: isColor,
|
|
39
|
-
transformer: (token: StyleDictionary.TransformedToken) => {
|
|
40
|
-
// skip if value is already rgb float
|
|
41
|
-
if (isRgbaFloat(token.value) && !('mix' in token) && !('alpha' in token)) return token.value
|
|
42
|
-
// convert hex or rgb values to rgba float
|
|
43
|
-
return toRgbaFloat(token, token.alpha)
|
|
44
|
-
},
|
|
45
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import {isDimension} from '../filters'
|
|
2
|
-
import type StyleDictionary from 'style-dictionary'
|
|
3
|
-
import type {Platform} from 'style-dictionary'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @description base font size from options or 16
|
|
7
|
-
* @param options
|
|
8
|
-
* @returns number
|
|
9
|
-
*/
|
|
10
|
-
const getBasePxFontSize = (options?: Platform): number => (options && options.basePxFontSize) || 16
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @description checks if token value has a specific unit
|
|
14
|
-
* @param value token value
|
|
15
|
-
* @param unit unit string like px or value
|
|
16
|
-
* @returns boolean
|
|
17
|
-
*/
|
|
18
|
-
const hasUnit = (value: string | number, unit: string): boolean => {
|
|
19
|
-
if (typeof value === 'number') {
|
|
20
|
-
return false
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return value.indexOf(unit) > -1
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @description converts dimension tokens value to pixel value without unit, ignores `em` as they are relative to the font size of the parent element
|
|
28
|
-
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
29
|
-
* @matcher matches all tokens of $type `dimension`
|
|
30
|
-
* @transformer returns a float number
|
|
31
|
-
*/
|
|
32
|
-
export const dimensionToPixelUnitless: StyleDictionary.Transform = {
|
|
33
|
-
type: `value`,
|
|
34
|
-
transitive: true,
|
|
35
|
-
matcher: isDimension,
|
|
36
|
-
transformer: (token: StyleDictionary.TransformedToken, options?: Platform) => {
|
|
37
|
-
const baseFont = getBasePxFontSize(options)
|
|
38
|
-
const floatVal = parseFloat(token.value)
|
|
39
|
-
|
|
40
|
-
if (isNaN(floatVal)) {
|
|
41
|
-
throw new Error(
|
|
42
|
-
`Invalid dimension token: '${token.name}: ${token.value}' is not valid and cannot be transform to 'float' \n`,
|
|
43
|
-
)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (floatVal === 0) {
|
|
47
|
-
return 0
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (hasUnit(token.value, 'rem')) {
|
|
51
|
-
return floatVal * baseFont
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (hasUnit(token.value, 'px')) {
|
|
55
|
-
return floatVal
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return token.value
|
|
59
|
-
},
|
|
60
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import {isDimension} from '../filters'
|
|
2
|
-
import type StyleDictionary from 'style-dictionary'
|
|
3
|
-
import type {Platform} from 'style-dictionary'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @description base font size from options or 16
|
|
7
|
-
* @param options
|
|
8
|
-
* @returns number
|
|
9
|
-
*/
|
|
10
|
-
const getBasePxFontSize = (options?: Platform): number => (options && options.basePxFontSize) || 16
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @description checks if token value has a specific unit
|
|
14
|
-
* @param value token value
|
|
15
|
-
* @param unit unit string like px or value
|
|
16
|
-
* @returns boolean
|
|
17
|
-
*/
|
|
18
|
-
const hasUnit = (value: string | number, unit: string): boolean => {
|
|
19
|
-
if (typeof value === 'number') {
|
|
20
|
-
return false
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return value.indexOf(unit) > -1
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @description converts dimension tokens value to `rem`, ignores `em` as they are relative to the font size of the parent element
|
|
28
|
-
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
29
|
-
* @matcher matches all tokens of $type `dimension`
|
|
30
|
-
* @transformer returns a `rem` string
|
|
31
|
-
*/
|
|
32
|
-
export const dimensionToRem: StyleDictionary.Transform = {
|
|
33
|
-
type: `value`,
|
|
34
|
-
transitive: true,
|
|
35
|
-
matcher: isDimension,
|
|
36
|
-
transformer: (token: StyleDictionary.TransformedToken, options?: Platform) => {
|
|
37
|
-
const baseFont = getBasePxFontSize(options)
|
|
38
|
-
const floatVal = parseFloat(token.value)
|
|
39
|
-
|
|
40
|
-
if (isNaN(floatVal)) {
|
|
41
|
-
throw new Error(
|
|
42
|
-
`Invalid dimension token: '${token.name}: ${token.value}' is not valid and cannot be transform to 'rem' \n`,
|
|
43
|
-
)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (floatVal === 0) {
|
|
47
|
-
return '0'
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (hasUnit(token.value, 'rem') || hasUnit(token.value, 'em')) {
|
|
51
|
-
return token.value
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return `${floatVal / baseFont}rem`
|
|
55
|
-
},
|
|
56
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import {isDimension} from '../filters'
|
|
2
|
-
import type StyleDictionary from 'style-dictionary'
|
|
3
|
-
import type {Platform} from 'style-dictionary'
|
|
4
|
-
|
|
5
|
-
type SizePx = '0' | `${number}px`
|
|
6
|
-
type SizeRem = '0' | `${number}rem`
|
|
7
|
-
type SizeEm = '0' | `${number}em`
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @description base font size from options or 16
|
|
11
|
-
* @param options
|
|
12
|
-
* @returns number
|
|
13
|
-
*/
|
|
14
|
-
const getBasePxFontSize = (options?: Platform): number => (options && options.basePxFontSize) || 16
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @description checks if token value has a specific unit
|
|
18
|
-
* @param value token value
|
|
19
|
-
* @param unit unit string like px or value
|
|
20
|
-
* @returns boolean
|
|
21
|
-
*/
|
|
22
|
-
const hasUnit = (value: string | number, unit: string): boolean => {
|
|
23
|
-
if (typeof value === 'number') {
|
|
24
|
-
return false
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return value.indexOf(unit) > -1
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* @description converts dimension tokens value to `rem`, ignores `em` as they are relative to the font size of the parent element
|
|
32
|
-
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
33
|
-
* @matcher matches all tokens of $type `dimension`
|
|
34
|
-
* @transformer returns an array with the `rem` and `pixel` string
|
|
35
|
-
*/
|
|
36
|
-
export const dimensionToRemPxArray: StyleDictionary.Transform = {
|
|
37
|
-
type: `value`,
|
|
38
|
-
transitive: true,
|
|
39
|
-
matcher: isDimension,
|
|
40
|
-
transformer: (token: StyleDictionary.TransformedToken, options?: Platform): [SizeRem | SizeEm, SizePx] => {
|
|
41
|
-
const baseFont = getBasePxFontSize(options)
|
|
42
|
-
const floatVal = parseFloat(token.value)
|
|
43
|
-
|
|
44
|
-
if (isNaN(floatVal)) {
|
|
45
|
-
throw new Error(
|
|
46
|
-
`Invalid dimension token: '${token.name}: ${token.value}' is not valid and cannot be transform to 'rem' \n`,
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (floatVal === 0) {
|
|
51
|
-
return ['0', '0']
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (hasUnit(token.value, 'rem') || hasUnit(token.value, 'em')) {
|
|
55
|
-
return [token.value, `${floatVal * baseFont}px`]
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return [`${floatVal / baseFont}rem`, `${floatVal}px`]
|
|
59
|
-
},
|
|
60
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type StyleDictionary from 'style-dictionary'
|
|
2
|
-
import {isDuration} from '../filters/isDuration'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @description converts duration tokens string value to number with `ms` unit
|
|
6
|
-
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
7
|
-
* @matcher matches all tokens of $type `duration`
|
|
8
|
-
* @transformer returns a css duration
|
|
9
|
-
*/
|
|
10
|
-
export const durationToCss: StyleDictionary.Transform = {
|
|
11
|
-
type: `value`,
|
|
12
|
-
transitive: true,
|
|
13
|
-
matcher: isDuration,
|
|
14
|
-
transformer: (token: StyleDictionary.TransformedToken, _options?: StyleDictionary.Platform) => {
|
|
15
|
-
// throw an error if token value is not a string or does not end with `ms`
|
|
16
|
-
if (typeof token.value !== `string` || !token.value.endsWith(`ms`)) {
|
|
17
|
-
throw new Error(`duration token value must be a string with an "ms" unit`)
|
|
18
|
-
}
|
|
19
|
-
// get value
|
|
20
|
-
let value = parseInt(token.value.replace('ms', ''))
|
|
21
|
-
let unit = `ms`
|
|
22
|
-
if (value >= 1000) {
|
|
23
|
-
value = value / 1000
|
|
24
|
-
unit = `s`
|
|
25
|
-
}
|
|
26
|
-
// return value
|
|
27
|
-
return `${value}${unit}`
|
|
28
|
-
},
|
|
29
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import type StyleDictionary from 'style-dictionary'
|
|
2
|
-
|
|
3
|
-
type FigmaVariableScope =
|
|
4
|
-
| 'ALL_SCOPES'
|
|
5
|
-
| 'TEXT_CONTENT'
|
|
6
|
-
| 'CORNER_RADIUS'
|
|
7
|
-
| 'WIDTH_HEIGHT'
|
|
8
|
-
| 'GAP'
|
|
9
|
-
| 'ALL_FILLS'
|
|
10
|
-
| 'FRAME_FILL'
|
|
11
|
-
| 'SHAPE_FILL'
|
|
12
|
-
| 'TEXT_FILL'
|
|
13
|
-
| 'STROKE_COLOR'
|
|
14
|
-
| 'STROKE_FLOAT'
|
|
15
|
-
| 'EFFECT_COLOR'
|
|
16
|
-
| 'EFFECT_FLOAT'
|
|
17
|
-
| 'OPACITY'
|
|
18
|
-
| 'FONT_FAMILY'
|
|
19
|
-
| 'FONT_STYLE'
|
|
20
|
-
| 'FONT_WEIGHT'
|
|
21
|
-
| 'FONT_SIZE'
|
|
22
|
-
| 'LINE_HEIGHT'
|
|
23
|
-
| 'LETTER_SPACING'
|
|
24
|
-
| 'PARAGRAPH_SPACING'
|
|
25
|
-
| 'PARAGRAPH_INDENT'
|
|
26
|
-
|
|
27
|
-
const figmaScopes: Record<string, FigmaVariableScope[]> = {
|
|
28
|
-
all: ['ALL_SCOPES'],
|
|
29
|
-
radius: ['CORNER_RADIUS'],
|
|
30
|
-
size: ['WIDTH_HEIGHT'],
|
|
31
|
-
gap: ['GAP'],
|
|
32
|
-
bgColor: ['FRAME_FILL', 'SHAPE_FILL'],
|
|
33
|
-
fgColor: ['TEXT_FILL', 'SHAPE_FILL'],
|
|
34
|
-
effectColor: ['EFFECT_COLOR'],
|
|
35
|
-
effectFloat: ['EFFECT_FLOAT'],
|
|
36
|
-
borderColor: ['STROKE_COLOR'],
|
|
37
|
-
borderWidth: ['STROKE_FLOAT'],
|
|
38
|
-
opacity: ['OPACITY'],
|
|
39
|
-
fontFamily: ['FONT_FAMILY'],
|
|
40
|
-
fontStyle: ['FONT_STYLE'],
|
|
41
|
-
fontWeight: ['FONT_WEIGHT'],
|
|
42
|
-
fontSize: ['FONT_SIZE'],
|
|
43
|
-
lineHeight: ['LINE_HEIGHT'],
|
|
44
|
-
letterSpacing: ['LETTER_SPACING'],
|
|
45
|
-
paragraphSpacing: ['PARAGRAPH_SPACING'],
|
|
46
|
-
paragraphIndent: ['PARAGRAPH_INDENT'],
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const getScopes = (scopes: string[] | string | undefined): FigmaVariableScope[] => {
|
|
50
|
-
if (typeof scopes === 'string') scopes = [scopes]
|
|
51
|
-
if (Array.isArray(scopes))
|
|
52
|
-
return scopes
|
|
53
|
-
.map(scope => {
|
|
54
|
-
if (scope in figmaScopes) return figmaScopes[scope]
|
|
55
|
-
throw new Error(`Invalid scope: ${scope}`)
|
|
56
|
-
})
|
|
57
|
-
.flat() as FigmaVariableScope[]
|
|
58
|
-
|
|
59
|
-
return ['ALL_SCOPES']
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* @description retrieves figma attributes from token and adds them to attributes
|
|
63
|
-
* @type attribute transformer — [StyleDictionary.AttributeTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
64
|
-
* @matcher matches all tokens
|
|
65
|
-
* @transformer returns ab object of figma attributes
|
|
66
|
-
*/
|
|
67
|
-
export const figmaAttributes: StyleDictionary.Transform = {
|
|
68
|
-
type: `attribute`,
|
|
69
|
-
transformer: (token: StyleDictionary.TransformedToken, platform: StyleDictionary.Platform = {}) => {
|
|
70
|
-
const {mode, collection, scopes, group, codeSyntax} = token.$extensions?.['org.primer.figma'] || {}
|
|
71
|
-
return {
|
|
72
|
-
mode: platform.options?.mode || mode || 'default',
|
|
73
|
-
collection,
|
|
74
|
-
group: group || collection,
|
|
75
|
-
scopes: getScopes(scopes),
|
|
76
|
-
codeSyntax,
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type StyleDictionary from 'style-dictionary'
|
|
2
|
-
import {isNumber} from '../filters'
|
|
3
|
-
/**
|
|
4
|
-
* takes a value and returns it if its a px string if it is a float and the token has a fontSize value in extensions['org.primer.data']
|
|
5
|
-
* @param value
|
|
6
|
-
* @returns string
|
|
7
|
-
*/
|
|
8
|
-
export const convertFloatToPixel = (token: StyleDictionary.TransformedToken, unitless = false) => {
|
|
9
|
-
// short circut if value is not a number
|
|
10
|
-
if (
|
|
11
|
-
typeof token.value !== 'number' ||
|
|
12
|
-
!token.$extensions?.['org.primer.data']?.fontSize ||
|
|
13
|
-
typeof token.$extensions?.['org.primer.data']?.fontSize !== 'number'
|
|
14
|
-
) {
|
|
15
|
-
return token.value
|
|
16
|
-
}
|
|
17
|
-
// convert value
|
|
18
|
-
const convertedValue = token.$extensions?.['org.primer.data']?.fontSize * token.value
|
|
19
|
-
// return converted value
|
|
20
|
-
return convertedValue === 0 ? 0 : unitless ? Math.round(convertedValue) : `${Math.round(convertedValue)}px`
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* @description converts a float value to a pixel value based on the provided fontSize on the tokersn extension
|
|
24
|
-
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
25
|
-
* @matcher matches all tokens of $type `isNumber`
|
|
26
|
-
* @transformer returns a pixel string
|
|
27
|
-
*/
|
|
28
|
-
export const floatToPixel: StyleDictionary.Transform = {
|
|
29
|
-
type: `value`,
|
|
30
|
-
transitive: true,
|
|
31
|
-
matcher: isNumber,
|
|
32
|
-
transformer: (token: StyleDictionary.TransformedToken): string => convertFloatToPixel(token),
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export const floatToPixelUnitless: StyleDictionary.Transform = {
|
|
36
|
-
type: `value`,
|
|
37
|
-
transitive: true,
|
|
38
|
-
matcher: isNumber,
|
|
39
|
-
transformer: (token: StyleDictionary.TransformedToken): string => convertFloatToPixel(token, true),
|
|
40
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type StyleDictionary from 'style-dictionary'
|
|
2
|
-
import {isFontFamily} from '../filters'
|
|
3
|
-
import {getTokenValue} from './utilities/getTokenValue'
|
|
4
|
-
import {hasSpaceInString} from './utilities/hasSpaceInString'
|
|
5
|
-
/**
|
|
6
|
-
* takes a value and returns it if its a string or concats strings in an array quoting strings with spaces
|
|
7
|
-
* @param value
|
|
8
|
-
* @returns string
|
|
9
|
-
*/
|
|
10
|
-
export const parseFontFamily = (value: unknown): string => {
|
|
11
|
-
if (typeof value === 'string') {
|
|
12
|
-
return value
|
|
13
|
-
}
|
|
14
|
-
if (Array.isArray(value)) {
|
|
15
|
-
return value
|
|
16
|
-
.map((string: string) => {
|
|
17
|
-
if (typeof string !== 'string') {
|
|
18
|
-
throw new Error(`Invalid value in array ${string}, must be a string`)
|
|
19
|
-
}
|
|
20
|
-
return hasSpaceInString(string) ? `'${string}'` : string
|
|
21
|
-
})
|
|
22
|
-
.join(', ')
|
|
23
|
-
}
|
|
24
|
-
throw new Error(`Invalid value ${value}, should be a string or array of strings`)
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* @description converts fontFamily tokens value to string
|
|
28
|
-
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
29
|
-
* @matcher matches all tokens of $type `fontFamily`
|
|
30
|
-
* @transformer returns a string
|
|
31
|
-
*/
|
|
32
|
-
export const fontFamilyToCss: StyleDictionary.Transform = {
|
|
33
|
-
type: `value`,
|
|
34
|
-
transitive: true,
|
|
35
|
-
matcher: isFontFamily,
|
|
36
|
-
transformer: (token: StyleDictionary.TransformedToken): string => parseFontFamily(getTokenValue(token)),
|
|
37
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type StyleDictionary from 'style-dictionary'
|
|
2
|
-
import {isFontFamily} from '../filters'
|
|
3
|
-
import {hasSpaceInString} from './utilities/hasSpaceInString'
|
|
4
|
-
/**
|
|
5
|
-
* takes a value and returns it if its a string or concats strings in an array quoting strings with spaces
|
|
6
|
-
* @param value
|
|
7
|
-
* @returns string
|
|
8
|
-
*/
|
|
9
|
-
export const parseFontFamily = (
|
|
10
|
-
token: StyleDictionary.TransformedToken,
|
|
11
|
-
fontFamilies: Record<string, string> = {},
|
|
12
|
-
): string => {
|
|
13
|
-
// return value from fontFamilies
|
|
14
|
-
if (token.name in fontFamilies) {
|
|
15
|
-
return fontFamilies[token.name]
|
|
16
|
-
}
|
|
17
|
-
// return string
|
|
18
|
-
if (typeof token.value === 'string') {
|
|
19
|
-
return token.value
|
|
20
|
-
}
|
|
21
|
-
// return stringified array
|
|
22
|
-
if (Array.isArray(token.value)) {
|
|
23
|
-
return token.value
|
|
24
|
-
.map((string: string) => {
|
|
25
|
-
if (typeof string !== 'string') {
|
|
26
|
-
throw new Error(`Invalid value in array ${string}, must be a string`)
|
|
27
|
-
}
|
|
28
|
-
return hasSpaceInString(string) ? `'${string}'` : string
|
|
29
|
-
})
|
|
30
|
-
.join(', ')
|
|
31
|
-
}
|
|
32
|
-
// invalid value
|
|
33
|
-
throw new Error(`Invalid value ${token.value}, should be a string or array of strings`)
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* @description converts fontFamily tokens value to string
|
|
37
|
-
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
38
|
-
* @matcher matches all tokens of $type `fontFamily`
|
|
39
|
-
* @transformer returns a string
|
|
40
|
-
*/
|
|
41
|
-
export const fontFamilyToFigma: StyleDictionary.Transform = {
|
|
42
|
-
type: `value`,
|
|
43
|
-
transitive: true,
|
|
44
|
-
matcher: isFontFamily,
|
|
45
|
-
transformer: (token: StyleDictionary.TransformedToken, platform: StyleDictionary.Platform): string =>
|
|
46
|
-
parseFontFamily(token, platform.options?.fontFamilies),
|
|
47
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type StyleDictionary from 'style-dictionary'
|
|
2
|
-
import {isFontWeight} from '../filters'
|
|
3
|
-
import {getTokenValue} from './utilities/getTokenValue'
|
|
4
|
-
|
|
5
|
-
const fontWeightMatrix: Record<string, string[]> = {
|
|
6
|
-
'100': ['thin', 'hairline'],
|
|
7
|
-
'200': ['extra-light', 'ultra-light'],
|
|
8
|
-
'300': ['light'],
|
|
9
|
-
'400': ['normal', 'regular', 'book'],
|
|
10
|
-
'500': ['medium'],
|
|
11
|
-
'600': ['semi-bold', 'demi-bold'],
|
|
12
|
-
'700': ['bold'],
|
|
13
|
-
'800': ['extra-bold', 'ultra-bold'],
|
|
14
|
-
'900': ['black', 'heavy'],
|
|
15
|
-
'950': ['extra-black', 'ultra-black'],
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const parseFontWeight = (value: unknown): number => {
|
|
19
|
-
// throw on anything but string and number
|
|
20
|
-
if (typeof value !== 'string' && typeof value !== 'number') {
|
|
21
|
-
throw new Error(`Invalid value ${value}, should be a number or fontWeight string`)
|
|
22
|
-
}
|
|
23
|
-
// valid string
|
|
24
|
-
if (typeof value === 'string') {
|
|
25
|
-
const key = Object.keys(fontWeightMatrix).find((k: string) => fontWeightMatrix[k].includes(value as string))
|
|
26
|
-
if (key !== undefined) {
|
|
27
|
-
return parseInt(key)
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
// if number as string
|
|
31
|
-
if (typeof value === 'string' && typeof parseInt(value) === 'number' && !isNaN(parseInt(value))) {
|
|
32
|
-
value = parseInt(value)
|
|
33
|
-
}
|
|
34
|
-
// return if valid numver
|
|
35
|
-
if (typeof value === 'number' && value > 0 && value <= 1000) {
|
|
36
|
-
return value
|
|
37
|
-
}
|
|
38
|
-
// invalid value
|
|
39
|
-
throw new Error(`Invalid value ${value}, should be a number or fontWeight string`)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @description converts fontWeight tokens value to numeric value
|
|
44
|
-
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
45
|
-
* @matcher matches all tokens of $type `fontWeight`
|
|
46
|
-
* @transformer returns a number
|
|
47
|
-
*/
|
|
48
|
-
export const fontWeightToNumber: StyleDictionary.Transform = {
|
|
49
|
-
type: `value`,
|
|
50
|
-
transitive: true,
|
|
51
|
-
matcher: isFontWeight,
|
|
52
|
-
transformer: (token: StyleDictionary.TransformedToken): number => parseFontWeight(getTokenValue(token)),
|
|
53
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export {borderToCss} from './borderToCss'
|
|
2
|
-
export {colorToHex} from './colorToHex'
|
|
3
|
-
export {colorToHexAlpha} from './colorToHexAlpha'
|
|
4
|
-
export {colorToHexMix} from './colorToHexMix'
|
|
5
|
-
export {colorToRgbAlpha} from './colorToRgbAlpha'
|
|
6
|
-
export {colorToRgbaFloat} from './colorToRgbaFloat'
|
|
7
|
-
export {floatToPixel} from './floatToPixel'
|
|
8
|
-
export {floatToPixelUnitless} from './floatToPixel'
|
|
9
|
-
export {dimensionToRem} from './dimensionToRem'
|
|
10
|
-
export {dimensionToRemPxArray} from './dimensionToRemPxArray'
|
|
11
|
-
export {dimensionToPixelUnitless} from './dimensionToPixelUnitless'
|
|
12
|
-
export {durationToCss} from './durationToCss'
|
|
13
|
-
export {figmaAttributes} from './figmaAttributes'
|
|
14
|
-
export {fontFamilyToCss} from './fontFamilyToCss'
|
|
15
|
-
export {fontFamilyToFigma} from './fontFamilyToFigma'
|
|
16
|
-
export {fontWeightToNumber} from './fontWeightToNumber'
|
|
17
|
-
export {jsonDeprecated} from './jsonDeprecated'
|
|
18
|
-
export {namePathToCamelCase} from './namePathToCamelCase'
|
|
19
|
-
export {namePathToDotNotation} from './namePathToDotNotation'
|
|
20
|
-
export {namePathToFigma} from './namePathToFigma'
|
|
21
|
-
export {namePathToKebabCase} from './namePathToKebabCase'
|
|
22
|
-
export {namePathToSlashNotation} from './namePathToSlashNotation'
|
|
23
|
-
export {shadowToCss} from './shadowToCss'
|
|
24
|
-
export {typographyToCss} from './typographyToCss'
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import {isDeprecated} from '../filters'
|
|
2
|
-
import type StyleDictionary from 'style-dictionary'
|
|
3
|
-
/**
|
|
4
|
-
* @description replaces tokens value with content of tokens `deprecated` property
|
|
5
|
-
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
6
|
-
* @matcher matches all tokens with a `deprecated` property
|
|
7
|
-
* @transformer returns `string` specified in `token.deprecated` or `null`
|
|
8
|
-
*/
|
|
9
|
-
export const jsonDeprecated: StyleDictionary.Transform = {
|
|
10
|
-
type: `value`,
|
|
11
|
-
transitive: true,
|
|
12
|
-
matcher: isDeprecated,
|
|
13
|
-
transformer: (token: StyleDictionary.TransformedToken) =>
|
|
14
|
-
typeof token.deprecated === 'string' ? token.deprecated.replace(/[{}]/g, '') : null,
|
|
15
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import {upperCaseFirstCharacter} from '../utilities'
|
|
2
|
-
import type StyleDictionary from 'style-dictionary'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* camelCase
|
|
6
|
-
* @scope custom camelCase implementation should only be used within `name path to dot notation` transformer
|
|
7
|
-
* @description replaces space ` `, dash `-`, underscore `_` and plus `+` by camelCasing e.g. `camel-case` -> `camelCase`
|
|
8
|
-
* @param string
|
|
9
|
-
* @returns string
|
|
10
|
-
*/
|
|
11
|
-
const camelCase = (string: string): string => {
|
|
12
|
-
return string
|
|
13
|
-
.split(/[\s-_+]+/g)
|
|
14
|
-
.map((stringPart: string, index: number) => (index === 0 ? stringPart : upperCaseFirstCharacter(stringPart)))
|
|
15
|
-
.join('')
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* @description converts the [TransformedToken's](https://github.com/amzn/style-dictionary/blob/main/types/TransformedToken.d.ts) `.path` array to a dot.notation string
|
|
19
|
-
* @type name transformer — [StyleDictionary.NameTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
20
|
-
* @matcher omitted to match all tokens
|
|
21
|
-
* @transformer returns `string` in dot.notation
|
|
22
|
-
*/
|
|
23
|
-
export const namePathToDotNotation: StyleDictionary.Transform = {
|
|
24
|
-
type: `name`,
|
|
25
|
-
transformer: (token: StyleDictionary.TransformedToken, options?: StyleDictionary.Platform): string => {
|
|
26
|
-
return (
|
|
27
|
-
[options?.prefix, ...token.path]
|
|
28
|
-
// remove undefined if exists
|
|
29
|
-
.filter((part: unknown): part is string => typeof part === 'string' && part !== '@')
|
|
30
|
-
.map((part: string) => camelCase(part))
|
|
31
|
-
.join('.')
|
|
32
|
-
)
|
|
33
|
-
},
|
|
34
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type StyleDictionary from 'style-dictionary'
|
|
2
|
-
|
|
3
|
-
export const transformNamePathToFigma = (
|
|
4
|
-
token: StyleDictionary.TransformedToken,
|
|
5
|
-
options?: StyleDictionary.Platform,
|
|
6
|
-
): string => {
|
|
7
|
-
let pathArray = token.path.filter((part: unknown): part is string => part !== '@')
|
|
8
|
-
if (['fgColor', 'borderColor', 'bgColor'].includes(pathArray[0]) && pathArray.length === 3) {
|
|
9
|
-
pathArray = [pathArray[0], `${pathArray[1]}-${pathArray[2]}`]
|
|
10
|
-
}
|
|
11
|
-
return (
|
|
12
|
-
[options?.prefix, ...pathArray]
|
|
13
|
-
// remove undefined if exists
|
|
14
|
-
.filter((part: unknown): part is string => typeof part === 'string' && part !== '@')
|
|
15
|
-
.join('/')
|
|
16
|
-
)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @description converts the [TransformedToken's](https://github.com/amzn/style-dictionary/blob/main/types/TransformedToken.d.ts) `.path` array to a specific figma name
|
|
21
|
-
* @type name transformer — [StyleDictionary.NameTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
22
|
-
* @matcher omitted to match all tokens
|
|
23
|
-
* @transformer returns `string`
|
|
24
|
-
*/
|
|
25
|
-
export const namePathToFigma: StyleDictionary.Transform = {
|
|
26
|
-
type: `name`,
|
|
27
|
-
transformer: transformNamePathToFigma,
|
|
28
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type StyleDictionary from 'style-dictionary'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @description converts the [TransformedToken's](https://github.com/amzn/style-dictionary/blob/main/types/TransformedToken.d.ts) `.path` array to a kebab-case string, preserves casing of parts
|
|
5
|
-
* @type name transformer — [StyleDictionary.NameTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
6
|
-
* @matcher omitted to match all tokens
|
|
7
|
-
* @transformer returns `string` kebab-case
|
|
8
|
-
*/
|
|
9
|
-
export const namePathToKebabCase: StyleDictionary.Transform = {
|
|
10
|
-
type: `name`,
|
|
11
|
-
transformer: (token: StyleDictionary.TransformedToken, options?: StyleDictionary.Platform): string => {
|
|
12
|
-
return (
|
|
13
|
-
[options?.prefix, ...token.path]
|
|
14
|
-
// remove undefined if exists
|
|
15
|
-
.filter((part: unknown): part is string => typeof part === 'string' && part !== '@')
|
|
16
|
-
.join('-')
|
|
17
|
-
)
|
|
18
|
-
},
|
|
19
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type StyleDictionary from 'style-dictionary'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @description converts the [TransformedToken's](https://github.com/amzn/style-dictionary/blob/main/types/TransformedToken.d.ts) `.path` array to a slash/notation string
|
|
5
|
-
* @type name transformer — [StyleDictionary.NameTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
6
|
-
* @matcher omitted to match all tokens
|
|
7
|
-
* @transformer returns `string` on slash/notation
|
|
8
|
-
*/
|
|
9
|
-
export const namePathToSlashNotation: StyleDictionary.Transform = {
|
|
10
|
-
type: `name`,
|
|
11
|
-
transformer: (token: StyleDictionary.TransformedToken, options?: StyleDictionary.Platform): string => {
|
|
12
|
-
return (
|
|
13
|
-
[options?.prefix, ...token.path]
|
|
14
|
-
// remove undefined if exists
|
|
15
|
-
.filter((part: unknown): part is string => typeof part === 'string' && part !== '@')
|
|
16
|
-
.join('/')
|
|
17
|
-
)
|
|
18
|
-
},
|
|
19
|
-
}
|