@primer/primitives 10.0.0-rc.fd912e08 → 10.1.0-rc.0146c170
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/README.md +2 -2
- package/dist/build/filters/index.d.ts +14 -0
- package/dist/build/filters/index.js +14 -0
- package/dist/build/filters/isBorder.d.ts +7 -0
- package/dist/build/filters/isBorder.js +8 -0
- package/dist/build/filters/isColor.d.ts +7 -0
- package/dist/build/filters/isColor.js +10 -0
- package/dist/build/filters/isColorWithAlpha.d.ts +7 -0
- package/dist/build/filters/isColorWithAlpha.js +9 -0
- package/dist/build/filters/isColorWithMix.d.ts +7 -0
- package/dist/build/filters/isColorWithMix.js +24 -0
- package/dist/build/filters/isCubicBezier.d.ts +7 -0
- package/dist/build/filters/isCubicBezier.js +10 -0
- package/dist/build/filters/isDeprecated.d.ts +7 -0
- package/dist/build/filters/isDeprecated.js +8 -0
- package/dist/build/filters/isDimension.d.ts +7 -0
- package/dist/build/filters/isDimension.js +8 -0
- package/dist/build/filters/isDuration.d.ts +7 -0
- package/dist/build/filters/isDuration.js +8 -0
- package/dist/build/filters/isFontFamily.d.ts +7 -0
- package/dist/build/filters/isFontFamily.js +8 -0
- package/dist/build/filters/isFontWeight.d.ts +7 -0
- package/dist/build/filters/isFontWeight.js +8 -0
- package/dist/build/filters/isFromFile.d.ts +8 -0
- package/dist/build/filters/isFromFile.js +10 -0
- package/dist/build/filters/isNumber.d.ts +7 -0
- package/dist/build/filters/isNumber.js +8 -0
- package/dist/build/filters/isShadow.d.ts +7 -0
- package/dist/build/filters/isShadow.js +8 -0
- package/dist/build/filters/isSource.d.ts +7 -0
- package/dist/build/filters/isSource.js +8 -0
- package/dist/build/filters/isTypography.d.ts +7 -0
- package/dist/build/filters/isTypography.js +8 -0
- package/dist/build/formats/cssAdvanced.d.ts +2 -0
- package/dist/build/formats/cssAdvanced.js +86 -0
- package/dist/build/formats/cssCustomMedia.d.ts +7 -0
- package/dist/build/formats/cssCustomMedia.js +26 -0
- package/dist/build/formats/index.d.ts +9 -0
- package/dist/build/formats/index.js +9 -0
- package/dist/build/formats/javascriptCommonJs.d.ts +7 -0
- package/dist/build/formats/javascriptCommonJs.js +26 -0
- package/dist/build/formats/javascriptEsm.d.ts +7 -0
- package/dist/build/formats/javascriptEsm.js +26 -0
- package/dist/build/formats/jsonFigma.d.ts +7 -0
- package/dist/build/formats/jsonFigma.js +121 -0
- package/dist/build/formats/jsonNestedPrefixed.d.ts +8 -0
- package/dist/build/formats/jsonNestedPrefixed.js +30 -0
- package/dist/build/formats/jsonOneDimensional.d.ts +8 -0
- package/dist/build/formats/jsonOneDimensional.js +32 -0
- package/dist/build/formats/jsonPostCssFallback.d.ts +8 -0
- package/dist/build/formats/jsonPostCssFallback.js +14 -0
- package/dist/build/formats/typescriptExportDefinition.d.ts +7 -0
- package/dist/build/formats/typescriptExportDefinition.js +170 -0
- package/dist/build/formats/utilities/getPropName.d.ts +1 -0
- package/dist/build/formats/utilities/getPropName.js +16 -0
- package/dist/build/formats/utilities/jsonToFlat.d.ts +11 -0
- package/dist/build/formats/utilities/jsonToFlat.js +8 -0
- package/dist/build/formats/utilities/jsonToNestedValue.d.ts +8 -0
- package/dist/build/formats/utilities/jsonToNestedValue.js +23 -0
- package/dist/build/formats/utilities/prefixTokens.d.ts +8 -0
- package/dist/build/formats/utilities/prefixTokens.js +13 -0
- package/dist/build/parsers/index.d.ts +1 -0
- package/dist/build/parsers/index.js +1 -0
- package/dist/build/parsers/w3cJsonParser.d.ts +6 -0
- package/dist/build/parsers/w3cJsonParser.js +25 -0
- package/dist/build/platforms/css.d.ts +2 -0
- package/dist/build/platforms/css.js +100 -0
- package/dist/build/platforms/deprecatedJson.d.ts +2 -0
- package/dist/build/platforms/deprecatedJson.js +13 -0
- package/dist/build/platforms/docJson.d.ts +2 -0
- package/dist/build/platforms/docJson.js +39 -0
- package/dist/build/platforms/fallbacks.d.ts +2 -0
- package/dist/build/platforms/fallbacks.js +30 -0
- package/dist/build/platforms/figma.d.ts +2 -0
- package/dist/build/platforms/figma.js +63 -0
- package/dist/build/platforms/index.d.ts +10 -0
- package/dist/build/platforms/index.js +10 -0
- package/dist/build/platforms/javascript.d.ts +2 -0
- package/dist/build/platforms/javascript.js +30 -0
- package/dist/build/platforms/json.d.ts +2 -0
- package/dist/build/platforms/json.js +32 -0
- package/dist/build/platforms/styleLint.d.ts +2 -0
- package/dist/build/platforms/styleLint.js +34 -0
- package/dist/build/platforms/typeDefinitions.d.ts +2 -0
- package/dist/build/platforms/typeDefinitions.js +30 -0
- package/dist/build/platforms/typescript.d.ts +2 -0
- package/dist/build/platforms/typescript.js +30 -0
- package/dist/build/preprocessors/themeOverrides.d.ts +2 -0
- package/dist/build/preprocessors/themeOverrides.js +22 -0
- package/dist/build/preprocessors/utilities/transformTokens.d.ts +8 -0
- package/dist/build/preprocessors/utilities/transformTokens.js +22 -0
- package/dist/build/primerStyleDictionary.d.ts +8 -0
- package/dist/build/primerStyleDictionary.js +82 -0
- package/dist/build/schemas/alphaValue.d.ts +2 -0
- package/dist/build/schemas/alphaValue.js +5 -0
- package/dist/build/schemas/baseToken.d.ts +11 -0
- package/dist/build/schemas/baseToken.js +7 -0
- package/dist/build/schemas/borderToken.d.ts +51 -0
- package/dist/build/schemas/borderToken.js +17 -0
- package/dist/build/schemas/collections.d.ts +6 -0
- package/dist/build/schemas/collections.js +12 -0
- package/dist/build/schemas/colorHexValue.d.ts +2 -0
- package/dist/build/schemas/colorHexValue.js +9 -0
- package/dist/build/schemas/colorToken.d.ts +167 -0
- package/dist/build/schemas/colorToken.js +76 -0
- package/dist/build/schemas/cubicBezierToken.d.ts +18 -0
- package/dist/build/schemas/cubicBezierToken.js +8 -0
- package/dist/build/schemas/designToken.d.ts +2 -0
- package/dist/build/schemas/designToken.js +35 -0
- package/dist/build/schemas/dimensionToken.d.ts +59 -0
- package/dist/build/schemas/dimensionToken.js +34 -0
- package/dist/build/schemas/dimensionValue.d.ts +2 -0
- package/dist/build/schemas/dimensionValue.js +9 -0
- package/dist/build/schemas/durationToken.d.ts +18 -0
- package/dist/build/schemas/durationToken.js +11 -0
- package/dist/build/schemas/durationValue.d.ts +2 -0
- package/dist/build/schemas/durationValue.js +5 -0
- package/dist/build/schemas/fontFamilyToken.d.ts +52 -0
- package/dist/build/schemas/fontFamilyToken.js +20 -0
- package/dist/build/schemas/fontWeightToken.d.ts +52 -0
- package/dist/build/schemas/fontWeightToken.js +21 -0
- package/dist/build/schemas/fontWeightValue.d.ts +2 -0
- package/dist/build/schemas/fontWeightValue.js +6 -0
- package/dist/build/schemas/numberToken.d.ts +71 -0
- package/dist/build/schemas/numberToken.js +27 -0
- package/dist/build/schemas/referenceValue.d.ts +2 -0
- package/dist/build/schemas/referenceValue.js +5 -0
- package/dist/build/schemas/scopes.d.ts +5 -0
- package/dist/build/schemas/scopes.js +29 -0
- package/dist/build/schemas/shadowToken.d.ts +164 -0
- package/dist/build/schemas/shadowToken.js +46 -0
- package/dist/build/schemas/stringToken.d.ts +18 -0
- package/dist/build/schemas/stringToken.js +10 -0
- package/dist/build/schemas/tokenName.d.ts +2 -0
- package/dist/build/schemas/tokenName.js +5 -0
- package/dist/build/schemas/tokenType.d.ts +3 -0
- package/dist/build/schemas/tokenType.js +2 -0
- package/dist/build/schemas/typographyToken.d.ts +59 -0
- package/dist/build/schemas/typographyToken.js +18 -0
- package/dist/build/schemas/validTokenType.d.ts +5 -0
- package/dist/build/schemas/validTokenType.js +31 -0
- package/dist/build/schemas/viewportRangeToken.d.ts +18 -0
- package/dist/build/schemas/viewportRangeToken.js +10 -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 +24 -0
- package/dist/build/transformers/colorToHexMix.d.ts +8 -0
- package/dist/build/transformers/colorToHexMix.js +20 -0
- package/dist/build/transformers/colorToRgbAlpha.d.ts +8 -0
- package/dist/build/transformers/colorToRgbAlpha.js +20 -0
- package/dist/build/transformers/colorToRgbaFloat.d.ts +8 -0
- package/dist/build/transformers/colorToRgbaFloat.js +46 -0
- package/dist/build/transformers/cubicBezierToCss.d.ts +8 -0
- package/dist/build/transformers/cubicBezierToCss.js +23 -0
- package/dist/build/transformers/dimensionToPixelUnitless.d.ts +8 -0
- package/dist/build/transformers/dimensionToPixelUnitless.js +49 -0
- package/dist/build/transformers/dimensionToRem.d.ts +8 -0
- package/dist/build/transformers/dimensionToRem.js +46 -0
- package/dist/build/transformers/dimensionToRemPxArray.d.ts +8 -0
- package/dist/build/transformers/dimensionToRemPxArray.js +46 -0
- package/dist/build/transformers/durationToCss.d.ts +8 -0
- package/dist/build/transformers/durationToCss.js +29 -0
- package/dist/build/transformers/figmaAttributes.d.ts +8 -0
- package/dist/build/transformers/figmaAttributes.js +55 -0
- package/dist/build/transformers/floatToPixel.d.ts +15 -0
- package/dist/build/transformers/floatToPixel.js +39 -0
- package/dist/build/transformers/fontFamilyToCss.d.ts +14 -0
- package/dist/build/transformers/fontFamilyToCss.js +37 -0
- package/dist/build/transformers/fontFamilyToFigma.d.ts +14 -0
- package/dist/build/transformers/fontFamilyToFigma.js +44 -0
- package/dist/build/transformers/fontWeightToNumber.d.ts +9 -0
- package/dist/build/transformers/fontWeightToNumber.js +50 -0
- package/dist/build/transformers/index.d.ts +25 -0
- package/dist/build/transformers/index.js +25 -0
- package/dist/build/transformers/jsonDeprecated.d.ts +8 -0
- package/dist/build/transformers/jsonDeprecated.js +14 -0
- package/dist/build/transformers/namePathToCamelCase.d.ts +8 -0
- package/dist/build/transformers/namePathToCamelCase.js +12 -0
- package/dist/build/transformers/namePathToDotNotation.d.ts +8 -0
- package/dist/build/transformers/namePathToDotNotation.js +31 -0
- package/dist/build/transformers/namePathToFigma.d.ts +9 -0
- package/dist/build/transformers/namePathToFigma.js +21 -0
- package/dist/build/transformers/namePathToKebabCase.d.ts +8 -0
- package/dist/build/transformers/namePathToKebabCase.js +16 -0
- package/dist/build/transformers/namePathToPascalCase.d.ts +8 -0
- package/dist/build/transformers/namePathToPascalCase.js +12 -0
- package/dist/build/transformers/namePathToSlashNotation.d.ts +8 -0
- package/dist/build/transformers/namePathToSlashNotation.js +16 -0
- package/dist/build/transformers/shadowToCss.d.ts +8 -0
- package/dist/build/transformers/shadowToCss.js +34 -0
- package/dist/build/transformers/typographyToCss.d.ts +8 -0
- package/dist/build/transformers/typographyToCss.js +27 -0
- package/dist/build/transformers/utilities/alpha.d.ts +9 -0
- package/dist/build/transformers/utilities/alpha.js +16 -0
- package/dist/build/transformers/utilities/checkRequiredTokenProperties.d.ts +7 -0
- package/dist/build/transformers/utilities/checkRequiredTokenProperties.js +13 -0
- package/dist/build/transformers/utilities/getTokenValue.d.ts +2 -0
- package/dist/build/transformers/utilities/getTokenValue.js +16 -0
- package/dist/build/transformers/utilities/hasSpaceInString.d.ts +1 -0
- package/dist/build/transformers/utilities/hasSpaceInString.js +6 -0
- package/dist/build/transformers/utilities/hexToRgbaFloat.d.ts +2 -0
- package/dist/build/transformers/utilities/hexToRgbaFloat.js +29 -0
- package/dist/build/transformers/utilities/invalidTokenError.d.ts +7 -0
- package/dist/build/transformers/utilities/invalidTokenError.js +25 -0
- package/dist/build/transformers/utilities/isRgbaFloat.d.ts +7 -0
- package/dist/build/transformers/utilities/isRgbaFloat.js +20 -0
- package/dist/build/transformers/utilities/mix.d.ts +5 -0
- package/dist/build/transformers/utilities/mix.js +38 -0
- package/dist/build/transformers/utilities/rgbaFloatToHex.d.ts +6 -0
- package/dist/build/transformers/utilities/rgbaFloatToHex.js +11 -0
- package/dist/build/types/border.d.ts +5 -0
- package/dist/build/types/borderTokenValue.d.ts +10 -0
- package/dist/build/types/colorHex.d.ts +4 -0
- package/dist/build/types/platformInitializer.d.ts +11 -0
- package/dist/build/types/shadow.d.ts +5 -0
- package/dist/build/types/shadowTokenValue.d.ts +14 -0
- package/dist/build/types/sizeEm.d.ts +4 -0
- package/dist/build/types/sizePx.d.ts +4 -0
- package/dist/build/types/sizeRem.d.ts +4 -0
- package/dist/build/types/styleDictionaryConfigGenerator.d.ts +16 -0
- package/dist/build/types/tokenBuildInput.d.ts +10 -0
- package/dist/build/types/typographyTokenValue.d.ts +12 -0
- package/dist/build/types/w3cTransformedToken.d.ts +8 -0
- package/dist/build/utilities/copyFromDir.d.ts +8 -0
- package/dist/build/utilities/copyFromDir.js +31 -0
- package/dist/build/utilities/filterStringArray.d.ts +1 -0
- package/dist/build/utilities/filterStringArray.js +13 -0
- package/dist/build/utilities/getFlag.d.ts +8 -0
- package/dist/build/utilities/getFlag.js +12 -0
- package/dist/build/utilities/index.d.ts +9 -0
- package/dist/build/utilities/index.js +9 -0
- package/dist/build/utilities/joinFriendly.d.ts +1 -0
- package/dist/build/utilities/joinFriendly.js +1 -0
- package/dist/build/utilities/lowerCaseFirstCharacter.d.ts +8 -0
- package/dist/build/utilities/lowerCaseFirstCharacter.js +10 -0
- package/dist/build/utilities/schemaErrorMessage.d.ts +1 -0
- package/dist/build/utilities/schemaErrorMessage.js +1 -0
- package/dist/build/utilities/toCamelCase.d.ts +1 -0
- package/dist/build/utilities/toCamelCase.js +16 -0
- package/dist/build/utilities/toPascalCase.d.ts +1 -0
- package/dist/build/utilities/toPascalCase.js +13 -0
- package/dist/build/utilities/treeWalker.d.ts +8 -0
- package/dist/build/utilities/treeWalker.js +23 -0
- package/dist/build/utilities/upperCaseFirstCharacter.d.ts +8 -0
- package/dist/build/utilities/upperCaseFirstCharacter.js +10 -0
- package/dist/css/base/motion/motion.css +17 -0
- package/dist/css/functional/motion/motion.css +4 -3
- package/dist/css/functional/themes/dark-colorblind.css +58 -38
- package/dist/css/functional/themes/dark-dimmed.css +44 -24
- package/dist/css/functional/themes/dark-high-contrast.css +42 -22
- package/dist/css/functional/themes/dark-tritanopia.css +44 -24
- package/dist/css/functional/themes/dark.css +42 -22
- package/dist/css/functional/themes/light-colorblind.css +60 -40
- package/dist/css/functional/themes/light-high-contrast.css +44 -24
- package/dist/css/functional/themes/light-tritanopia.css +42 -22
- package/dist/css/functional/themes/light.css +42 -22
- package/dist/css/functional/typography/typography.css +43 -43
- package/dist/css/primitives.css +64 -46
- package/dist/docs/base/motion/motion.json +205 -0
- package/dist/docs/functional/motion/motion.json +18 -3
- package/dist/docs/functional/themes/dark-colorblind.json +350 -1114
- package/dist/docs/functional/themes/dark-dimmed.json +364 -1152
- package/dist/docs/functional/themes/dark-high-contrast.json +312 -922
- package/dist/docs/functional/themes/dark-tritanopia.json +344 -1138
- package/dist/docs/functional/themes/dark.json +346 -1206
- package/dist/docs/functional/themes/light-colorblind.json +366 -1140
- package/dist/docs/functional/themes/light-high-contrast.json +335 -949
- package/dist/docs/functional/themes/light-tritanopia.json +311 -1135
- package/dist/docs/functional/themes/light.json +336 -1202
- package/dist/fallbacks/base/motion/motion.json +17 -0
- package/dist/fallbacks/functional/motion/motion.json +1 -0
- package/dist/figma/dimension/dimension.json +518 -518
- package/dist/figma/figma.json +15 -23
- package/dist/figma/scales/dark-dimmed.json +3536 -656
- package/dist/figma/scales/dark-high-constrast.json +3535 -655
- package/dist/figma/scales/dark.json +3371 -491
- package/dist/figma/scales/light-high-constrast.json +3533 -653
- package/dist/figma/scales/light.json +3370 -490
- package/dist/figma/shadows/dark-colorblind.json +285 -285
- package/dist/figma/shadows/dark-dimmed.json +285 -285
- package/dist/figma/shadows/dark-high-contrast.json +285 -285
- package/dist/figma/shadows/dark-tritanopia.json +285 -285
- package/dist/figma/shadows/dark.json +285 -285
- package/dist/figma/shadows/light-colorblind.json +254 -254
- package/dist/figma/shadows/light-high-contrast.json +254 -254
- package/dist/figma/shadows/light-tritanopia.json +254 -254
- package/dist/figma/shadows/light.json +254 -254
- package/dist/figma/themes/dark-colorblind.json +5197 -5068
- package/dist/figma/themes/dark-dimmed.json +5526 -5351
- package/dist/figma/themes/dark-high-contrast.json +4361 -4251
- package/dist/figma/themes/dark-tritanopia.json +5315 -5187
- package/dist/figma/themes/dark.json +5740 -5581
- package/dist/figma/themes/light-colorblind.json +5104 -4929
- package/dist/figma/themes/light-high-contrast.json +4462 -4319
- package/dist/figma/themes/light-tritanopia.json +5176 -5050
- package/dist/figma/themes/light.json +5657 -5500
- package/dist/figma/typography/typography.json +162 -162
- package/dist/internalCss/dark-colorblind.css +58 -38
- package/dist/internalCss/dark-dimmed.css +44 -24
- package/dist/internalCss/dark-high-contrast.css +42 -22
- package/dist/internalCss/dark-tritanopia.css +44 -24
- package/dist/internalCss/dark.css +42 -22
- package/dist/internalCss/light-colorblind.css +60 -40
- package/dist/internalCss/light-high-contrast.css +44 -24
- package/dist/internalCss/light-tritanopia.css +42 -22
- package/dist/internalCss/light.css +42 -22
- package/dist/styleLint/base/motion/motion.json +205 -0
- package/dist/styleLint/functional/motion/motion.json +18 -3
- package/dist/styleLint/functional/themes/dark-colorblind.json +350 -1114
- package/dist/styleLint/functional/themes/dark-dimmed.json +364 -1152
- package/dist/styleLint/functional/themes/dark-high-contrast.json +311 -921
- package/dist/styleLint/functional/themes/dark-tritanopia.json +344 -1138
- package/dist/styleLint/functional/themes/dark.json +346 -1206
- package/dist/styleLint/functional/themes/light-colorblind.json +366 -1140
- package/dist/styleLint/functional/themes/light-high-contrast.json +335 -949
- package/dist/styleLint/functional/themes/light-tritanopia.json +311 -1135
- package/dist/styleLint/functional/themes/light.json +336 -1202
- package/package.json +30 -36
- package/src/tokens/base/motion/easing.json5 +26 -0
- package/src/tokens/base/motion/timing.json5 +50 -0
- package/src/tokens/functional/color/dark/app-dark.json5 +236 -121
- package/src/tokens/functional/color/dark/data-vis-dark.json5 +40 -40
- package/src/tokens/functional/color/dark/display-dark.json5 +95 -95
- package/src/tokens/functional/color/dark/overrides/dark.dimmed.json5 +1 -9
- package/src/tokens/functional/color/dark/overrides/dark.high-contrast.json5 +40 -27
- package/src/tokens/functional/color/dark/overrides/dark.protanopia-deuteranopia.json5 +56 -30
- package/src/tokens/functional/color/dark/overrides/dark.tritanopia.json5 +37 -14
- package/src/tokens/functional/color/dark/patterns-dark.json +3963 -0
- package/src/tokens/functional/color/dark/patterns-dark.json5 +126 -277
- package/src/tokens/functional/color/dark/primitives-dark.json5 +78 -78
- package/src/tokens/functional/color/dark/syntax-dark.json5 +47 -47
- package/src/tokens/functional/color/light/app-light.json5 +179 -118
- package/src/tokens/functional/color/light/data-vis-light.json5 +40 -40
- package/src/tokens/functional/color/light/display-light.json5 +0 -95
- package/src/tokens/functional/color/light/overrides/light.high-contrast.json5 +25 -27
- package/src/tokens/functional/color/light/overrides/light.protanopia-deuteranopia.json5 +58 -33
- package/src/tokens/functional/color/light/overrides/light.tritanopia.json5 +59 -10
- package/src/tokens/functional/color/light/patterns-light.json5 +126 -276
- package/src/tokens/functional/color/light/primitives-light.json5 +0 -78
- package/src/tokens/functional/color/light/syntax-light.json5 +0 -47
- package/src/tokens/functional/motion/loading.json5 +1 -1
- package/src/tokens/functional/motion/patterns.json5 +9 -2
- package/src/tokens/functional/shadow/dark.json5 +0 -14
- package/src/tokens/functional/shadow/light.json5 +0 -13
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { isFontWeight } from '../filters/index.js';
|
|
2
|
+
import { getTokenValue } from './utilities/getTokenValue.js';
|
|
3
|
+
const fontWeightMatrix = {
|
|
4
|
+
'100': ['thin', 'hairline'],
|
|
5
|
+
'200': ['extra-light', 'ultra-light'],
|
|
6
|
+
'300': ['light'],
|
|
7
|
+
'400': ['normal', 'regular', 'book'],
|
|
8
|
+
'500': ['medium'],
|
|
9
|
+
'600': ['semi-bold', 'demi-bold'],
|
|
10
|
+
'700': ['bold'],
|
|
11
|
+
'800': ['extra-bold', 'ultra-bold'],
|
|
12
|
+
'900': ['black', 'heavy'],
|
|
13
|
+
'950': ['extra-black', 'ultra-black'],
|
|
14
|
+
};
|
|
15
|
+
export const parseFontWeight = (value) => {
|
|
16
|
+
// throw on anything but string and number
|
|
17
|
+
if (typeof value !== 'string' && typeof value !== 'number') {
|
|
18
|
+
throw new Error(`Invalid value ${value}, should be a number or fontWeight string`);
|
|
19
|
+
}
|
|
20
|
+
// valid string
|
|
21
|
+
if (typeof value === 'string') {
|
|
22
|
+
const key = Object.keys(fontWeightMatrix).find((k) => fontWeightMatrix[k].includes(value));
|
|
23
|
+
if (key !== undefined) {
|
|
24
|
+
return parseInt(key);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
// if number as string
|
|
28
|
+
if (typeof value === 'string' && typeof parseInt(value) === 'number' && !isNaN(parseInt(value))) {
|
|
29
|
+
value = parseInt(value);
|
|
30
|
+
}
|
|
31
|
+
// return if valid numver
|
|
32
|
+
if (typeof value === 'number' && value > 0 && value <= 1000) {
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
// invalid value
|
|
36
|
+
throw new Error(`Invalid value ${value}, should be a number or fontWeight string`);
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* @description converts fontWeight tokens value to numeric value
|
|
40
|
+
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
41
|
+
* @matcher matches all tokens of $type `fontWeight`
|
|
42
|
+
* @transformer returns a number
|
|
43
|
+
*/
|
|
44
|
+
export const fontWeightToNumber = {
|
|
45
|
+
name: 'fontWeight/number',
|
|
46
|
+
type: 'value',
|
|
47
|
+
transitive: true,
|
|
48
|
+
filter: isFontWeight,
|
|
49
|
+
transform: (token) => parseFontWeight(getTokenValue(token)),
|
|
50
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export { borderToCss } from './borderToCss.js';
|
|
2
|
+
export { colorToHex } from './colorToHex.js';
|
|
3
|
+
export { colorToHexMix } from './colorToHexMix.js';
|
|
4
|
+
export { colorToRgbAlpha } from './colorToRgbAlpha.js';
|
|
5
|
+
export { colorToRgbaFloat } from './colorToRgbaFloat.js';
|
|
6
|
+
export { cubicBezierToCss } from './cubicBezierToCss.js';
|
|
7
|
+
export { floatToPixel } from './floatToPixel.js';
|
|
8
|
+
export { floatToPixelUnitless } from './floatToPixel.js';
|
|
9
|
+
export { dimensionToRem } from './dimensionToRem.js';
|
|
10
|
+
export { dimensionToRemPxArray } from './dimensionToRemPxArray.js';
|
|
11
|
+
export { dimensionToPixelUnitless } from './dimensionToPixelUnitless.js';
|
|
12
|
+
export { durationToCss } from './durationToCss.js';
|
|
13
|
+
export { figmaAttributes } from './figmaAttributes.js';
|
|
14
|
+
export { fontFamilyToCss } from './fontFamilyToCss.js';
|
|
15
|
+
export { fontFamilyToFigma } from './fontFamilyToFigma.js';
|
|
16
|
+
export { fontWeightToNumber } from './fontWeightToNumber.js';
|
|
17
|
+
export { jsonDeprecated } from './jsonDeprecated.js';
|
|
18
|
+
export { namePathToCamelCase } from './namePathToCamelCase.js';
|
|
19
|
+
export { namePathToPascalCase } from './namePathToPascalCase.js';
|
|
20
|
+
export { namePathToDotNotation } from './namePathToDotNotation.js';
|
|
21
|
+
export { namePathToFigma } from './namePathToFigma.js';
|
|
22
|
+
export { namePathToKebabCase } from './namePathToKebabCase.js';
|
|
23
|
+
export { namePathToSlashNotation } from './namePathToSlashNotation.js';
|
|
24
|
+
export { shadowToCss } from './shadowToCss.js';
|
|
25
|
+
export { typographyToCss } from './typographyToCss.js';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export { borderToCss } from './borderToCss.js';
|
|
2
|
+
export { colorToHex } from './colorToHex.js';
|
|
3
|
+
export { colorToHexMix } from './colorToHexMix.js';
|
|
4
|
+
export { colorToRgbAlpha } from './colorToRgbAlpha.js';
|
|
5
|
+
export { colorToRgbaFloat } from './colorToRgbaFloat.js';
|
|
6
|
+
export { cubicBezierToCss } from './cubicBezierToCss.js';
|
|
7
|
+
export { floatToPixel } from './floatToPixel.js';
|
|
8
|
+
export { floatToPixelUnitless } from './floatToPixel.js';
|
|
9
|
+
export { dimensionToRem } from './dimensionToRem.js';
|
|
10
|
+
export { dimensionToRemPxArray } from './dimensionToRemPxArray.js';
|
|
11
|
+
export { dimensionToPixelUnitless } from './dimensionToPixelUnitless.js';
|
|
12
|
+
export { durationToCss } from './durationToCss.js';
|
|
13
|
+
export { figmaAttributes } from './figmaAttributes.js';
|
|
14
|
+
export { fontFamilyToCss } from './fontFamilyToCss.js';
|
|
15
|
+
export { fontFamilyToFigma } from './fontFamilyToFigma.js';
|
|
16
|
+
export { fontWeightToNumber } from './fontWeightToNumber.js';
|
|
17
|
+
export { jsonDeprecated } from './jsonDeprecated.js';
|
|
18
|
+
export { namePathToCamelCase } from './namePathToCamelCase.js';
|
|
19
|
+
export { namePathToPascalCase } from './namePathToPascalCase.js';
|
|
20
|
+
export { namePathToDotNotation } from './namePathToDotNotation.js';
|
|
21
|
+
export { namePathToFigma } from './namePathToFigma.js';
|
|
22
|
+
export { namePathToKebabCase } from './namePathToKebabCase.js';
|
|
23
|
+
export { namePathToSlashNotation } from './namePathToSlashNotation.js';
|
|
24
|
+
export { shadowToCss } from './shadowToCss.js';
|
|
25
|
+
export { typographyToCss } from './typographyToCss.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Transform } from 'style-dictionary/types';
|
|
2
|
+
/**
|
|
3
|
+
* @description replaces tokens value with content of tokens `deprecated` property
|
|
4
|
+
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
5
|
+
* @matcher matches all tokens with a `deprecated` property
|
|
6
|
+
* @transformer returns `string` specified in `token.deprecated` or `null`
|
|
7
|
+
*/
|
|
8
|
+
export declare const jsonDeprecated: Transform;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { isDeprecated } from '../filters/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* @description replaces tokens value with content of tokens `deprecated` property
|
|
4
|
+
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
5
|
+
* @matcher matches all tokens with a `deprecated` property
|
|
6
|
+
* @transformer returns `string` specified in `token.deprecated` or `null`
|
|
7
|
+
*/
|
|
8
|
+
export const jsonDeprecated = {
|
|
9
|
+
name: 'json/deprecated',
|
|
10
|
+
type: 'value',
|
|
11
|
+
transitive: true,
|
|
12
|
+
filter: isDeprecated,
|
|
13
|
+
transform: (token) => typeof token.$deprecated === 'string' ? token.$deprecated.replace(/[{}]/g, '') : null,
|
|
14
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Transform } from 'style-dictionary/types';
|
|
2
|
+
/**
|
|
3
|
+
* @description converts the [TransformedToken's](https://github.com/amzn/style-dictionary/blob/main/types/TransformedToken.d.ts) `.path` array to a camelCase string, preserves casing of parts
|
|
4
|
+
* @type name transformer — [StyleDictionary.NameTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
5
|
+
* @matcher omitted to match all tokens
|
|
6
|
+
* @transformer returns `string` camelCase
|
|
7
|
+
*/
|
|
8
|
+
export declare const namePathToCamelCase: Transform;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { toCamelCase } from '../utilities/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* @description converts the [TransformedToken's](https://github.com/amzn/style-dictionary/blob/main/types/TransformedToken.d.ts) `.path` array to a camelCase string, preserves casing of parts
|
|
4
|
+
* @type name transformer — [StyleDictionary.NameTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
5
|
+
* @matcher omitted to match all tokens
|
|
6
|
+
* @transformer returns `string` camelCase
|
|
7
|
+
*/
|
|
8
|
+
export const namePathToCamelCase = {
|
|
9
|
+
name: 'name/pathToCamelCase',
|
|
10
|
+
type: 'name',
|
|
11
|
+
transform: (token, options) => toCamelCase([(options === null || options === void 0 ? void 0 : options.prefix) || '', ...token.path]),
|
|
12
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Transform } from 'style-dictionary/types';
|
|
2
|
+
/**
|
|
3
|
+
* @description converts the [TransformedToken's](https://github.com/amzn/style-dictionary/blob/main/types/TransformedToken.d.ts) `.path` array to a dot.notation string
|
|
4
|
+
* @type name transformer — [StyleDictionary.NameTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
5
|
+
* @matcher omitted to match all tokens
|
|
6
|
+
* @transformer returns `string` in dot.notation
|
|
7
|
+
*/
|
|
8
|
+
export declare const namePathToDotNotation: Transform;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { upperCaseFirstCharacter } from '../utilities/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* camelCase
|
|
4
|
+
* @scope custom camelCase implementation should only be used within `name path to dot notation` transformer
|
|
5
|
+
* @description replaces space ` `, dash `-`, underscore `_` and plus `+` by camelCasing e.g. `camel-case` -> `camelCase`
|
|
6
|
+
* @param string
|
|
7
|
+
* @returns string
|
|
8
|
+
*/
|
|
9
|
+
const camelCase = (string) => {
|
|
10
|
+
return string
|
|
11
|
+
.split(/[\s-_+]+/g)
|
|
12
|
+
.map((stringPart, index) => (index === 0 ? stringPart : upperCaseFirstCharacter(stringPart)))
|
|
13
|
+
.join('');
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* @description converts the [TransformedToken's](https://github.com/amzn/style-dictionary/blob/main/types/TransformedToken.d.ts) `.path` array to a dot.notation string
|
|
17
|
+
* @type name transformer — [StyleDictionary.NameTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
18
|
+
* @matcher omitted to match all tokens
|
|
19
|
+
* @transformer returns `string` in dot.notation
|
|
20
|
+
*/
|
|
21
|
+
export const namePathToDotNotation = {
|
|
22
|
+
name: 'name/pathToDotNotation',
|
|
23
|
+
type: 'name',
|
|
24
|
+
transform: (token, options) => {
|
|
25
|
+
return ([options === null || options === void 0 ? void 0 : options.prefix, ...token.path]
|
|
26
|
+
// remove undefined if exists
|
|
27
|
+
.filter((part) => typeof part === 'string' && part !== '@')
|
|
28
|
+
.map((part) => camelCase(part))
|
|
29
|
+
.join('.'));
|
|
30
|
+
},
|
|
31
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PlatformConfig, Transform, TransformedToken } from 'style-dictionary/types';
|
|
2
|
+
export declare const transformNamePathToFigma: (token: TransformedToken, options?: PlatformConfig) => string;
|
|
3
|
+
/**
|
|
4
|
+
* @description converts the [TransformedToken's](https://github.com/amzn/style-dictionary/blob/main/types/TransformedToken.d.ts) `.path` array to a specific figma name
|
|
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`
|
|
8
|
+
*/
|
|
9
|
+
export declare const namePathToFigma: Transform;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const transformNamePathToFigma = (token, options) => {
|
|
2
|
+
let pathArray = token.path.filter((part) => part !== '@');
|
|
3
|
+
if (['fgColor', 'borderColor', 'bgColor'].includes(pathArray[0]) && pathArray.length === 3) {
|
|
4
|
+
pathArray = [pathArray[0], `${pathArray[1]}-${pathArray[2]}`];
|
|
5
|
+
}
|
|
6
|
+
return ([options === null || options === void 0 ? void 0 : options.prefix, ...pathArray]
|
|
7
|
+
// remove undefined if exists
|
|
8
|
+
.filter((part) => typeof part === 'string' && part !== '@')
|
|
9
|
+
.join('/'));
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* @description converts the [TransformedToken's](https://github.com/amzn/style-dictionary/blob/main/types/TransformedToken.d.ts) `.path` array to a specific figma name
|
|
13
|
+
* @type name transformer — [StyleDictionary.NameTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
14
|
+
* @matcher omitted to match all tokens
|
|
15
|
+
* @transformer returns `string`
|
|
16
|
+
*/
|
|
17
|
+
export const namePathToFigma = {
|
|
18
|
+
name: 'name/pathToFigma',
|
|
19
|
+
type: 'name',
|
|
20
|
+
transform: transformNamePathToFigma,
|
|
21
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Transform } from 'style-dictionary/types';
|
|
2
|
+
/**
|
|
3
|
+
* @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
|
|
4
|
+
* @type name transformer — [StyleDictionary.NameTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
5
|
+
* @matcher omitted to match all tokens
|
|
6
|
+
* @transformer returns `string` kebab-case
|
|
7
|
+
*/
|
|
8
|
+
export declare const namePathToKebabCase: Transform;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @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
|
|
3
|
+
* @type name transformer — [StyleDictionary.NameTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
4
|
+
* @matcher omitted to match all tokens
|
|
5
|
+
* @transformer returns `string` kebab-case
|
|
6
|
+
*/
|
|
7
|
+
export const namePathToKebabCase = {
|
|
8
|
+
name: 'name/pathToKebabCase',
|
|
9
|
+
type: 'name',
|
|
10
|
+
transform: (token, options) => {
|
|
11
|
+
return ([options === null || options === void 0 ? void 0 : options.prefix, ...token.path]
|
|
12
|
+
// remove undefined if exists
|
|
13
|
+
.filter((part) => typeof part === 'string' && part !== '@')
|
|
14
|
+
.join('-'));
|
|
15
|
+
},
|
|
16
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Transform } from 'style-dictionary/types';
|
|
2
|
+
/**
|
|
3
|
+
* @description converts the [TransformedToken's](https://github.com/amzn/style-dictionary/blob/main/types/TransformedToken.d.ts) `.path` array to a PascalCase string, preserves casing of parts
|
|
4
|
+
* @type name transformer — [StyleDictionary.NameTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
5
|
+
* @matcher omitted to match all tokens
|
|
6
|
+
* @transformer returns `string` PascalCase
|
|
7
|
+
*/
|
|
8
|
+
export declare const namePathToPascalCase: Transform;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { toPascalCase } from '../utilities/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* @description converts the [TransformedToken's](https://github.com/amzn/style-dictionary/blob/main/types/TransformedToken.d.ts) `.path` array to a PascalCase string, preserves casing of parts
|
|
4
|
+
* @type name transformer — [StyleDictionary.NameTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
5
|
+
* @matcher omitted to match all tokens
|
|
6
|
+
* @transformer returns `string` PascalCase
|
|
7
|
+
*/
|
|
8
|
+
export const namePathToPascalCase = {
|
|
9
|
+
name: 'name/pathToPascalCase',
|
|
10
|
+
type: 'name',
|
|
11
|
+
transform: (token, options) => toPascalCase([(options === null || options === void 0 ? void 0 : options.prefix) || '', ...token.path]),
|
|
12
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Transform } from 'style-dictionary/types';
|
|
2
|
+
/**
|
|
3
|
+
* @description converts the [TransformedToken's](https://github.com/amzn/style-dictionary/blob/main/types/TransformedToken.d.ts) `.path` array to a slash/notation string
|
|
4
|
+
* @type name transformer — [StyleDictionary.NameTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
5
|
+
* @matcher omitted to match all tokens
|
|
6
|
+
* @transformer returns `string` on slash/notation
|
|
7
|
+
*/
|
|
8
|
+
export declare const namePathToSlashNotation: Transform;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description converts the [TransformedToken's](https://github.com/amzn/style-dictionary/blob/main/types/TransformedToken.d.ts) `.path` array to a slash/notation string
|
|
3
|
+
* @type name transformer — [StyleDictionary.NameTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
4
|
+
* @matcher omitted to match all tokens
|
|
5
|
+
* @transformer returns `string` on slash/notation
|
|
6
|
+
*/
|
|
7
|
+
export const namePathToSlashNotation = {
|
|
8
|
+
name: 'name/pathToSlashNotation',
|
|
9
|
+
type: 'name',
|
|
10
|
+
transform: (token, options) => {
|
|
11
|
+
return ([options === null || options === void 0 ? void 0 : options.prefix, ...token.path]
|
|
12
|
+
// remove undefined if exists
|
|
13
|
+
.filter((part) => typeof part === 'string' && part !== '@')
|
|
14
|
+
.join('/'));
|
|
15
|
+
},
|
|
16
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Transform } from 'style-dictionary/types';
|
|
2
|
+
/**
|
|
3
|
+
* @description converts w3c shadow tokens in css shadow string
|
|
4
|
+
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
5
|
+
* @matcher matches all tokens of $type `shadow`
|
|
6
|
+
* @transformer returns css shadow `string`
|
|
7
|
+
*/
|
|
8
|
+
export declare const shadowToCss: Transform;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { toHex } from 'color2k';
|
|
2
|
+
import { isShadow } from '../filters/index.js';
|
|
3
|
+
import { alpha } from './utilities/alpha.js';
|
|
4
|
+
import { checkRequiredTokenProperties } from './utilities/checkRequiredTokenProperties.js';
|
|
5
|
+
import { getTokenValue } from './utilities/getTokenValue.js';
|
|
6
|
+
/**
|
|
7
|
+
* @description converts w3c shadow tokens in css shadow string
|
|
8
|
+
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
9
|
+
* @matcher matches all tokens of $type `shadow`
|
|
10
|
+
* @transformer returns css shadow `string`
|
|
11
|
+
*/
|
|
12
|
+
export const shadowToCss = {
|
|
13
|
+
name: 'shadow/css',
|
|
14
|
+
type: 'value',
|
|
15
|
+
transitive: true,
|
|
16
|
+
filter: isShadow,
|
|
17
|
+
transform: (token) => {
|
|
18
|
+
// extract value
|
|
19
|
+
const value = getTokenValue(token);
|
|
20
|
+
const valueProp = token.$value ? '$value' : 'value';
|
|
21
|
+
// turn value into array
|
|
22
|
+
const shadowValues = !Array.isArray(value) ? [value] : value;
|
|
23
|
+
return shadowValues
|
|
24
|
+
.map((shadow) => {
|
|
25
|
+
// if value === string it was probably already transformed
|
|
26
|
+
if (typeof shadow === 'string')
|
|
27
|
+
return shadow;
|
|
28
|
+
checkRequiredTokenProperties(shadow, ['color', 'offsetX', 'offsetY', 'blur', 'spread']);
|
|
29
|
+
/*css box shadow: inset? | offset-x | offset-y | blur-radius | spread-radius | color */
|
|
30
|
+
return `${shadow.inset === true ? 'inset ' : ''}${shadow.offsetX} ${shadow.offsetY} ${shadow.blur} ${shadow.spread} ${toHex(alpha(getTokenValue(Object.assign(Object.assign({}, token), { [valueProp]: shadow }), 'color'), shadow.alpha || 1, token))}`;
|
|
31
|
+
})
|
|
32
|
+
.join(', ');
|
|
33
|
+
},
|
|
34
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Transform } from 'style-dictionary/types';
|
|
2
|
+
/**
|
|
3
|
+
* @description converts typograhy token value to css font shorthand
|
|
4
|
+
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
5
|
+
* @matcher matches all tokens of $type `typography`
|
|
6
|
+
* @transformer returns a css font string
|
|
7
|
+
*/
|
|
8
|
+
export declare const typographyToCss: Transform;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { isTypography } from '../filters/index.js';
|
|
2
|
+
import { checkRequiredTokenProperties } from './utilities/checkRequiredTokenProperties.js';
|
|
3
|
+
import { parseFontFamily } from './fontFamilyToCss.js';
|
|
4
|
+
import { parseFontWeight } from './fontWeightToNumber.js';
|
|
5
|
+
import { getTokenValue } from './utilities/getTokenValue.js';
|
|
6
|
+
/**
|
|
7
|
+
* @description converts typograhy token value to css font shorthand
|
|
8
|
+
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
9
|
+
* @matcher matches all tokens of $type `typography`
|
|
10
|
+
* @transformer returns a css font string
|
|
11
|
+
*/
|
|
12
|
+
export const typographyToCss = {
|
|
13
|
+
name: 'typography/css',
|
|
14
|
+
type: 'value',
|
|
15
|
+
transitive: true,
|
|
16
|
+
filter: isTypography,
|
|
17
|
+
transform: (token) => {
|
|
18
|
+
// extract value
|
|
19
|
+
const value = getTokenValue(token);
|
|
20
|
+
// validate token properties
|
|
21
|
+
checkRequiredTokenProperties(value, ['fontWeight', 'fontSize', 'fontFamily']);
|
|
22
|
+
// format output
|
|
23
|
+
return `${value.fontStyle || ''} ${parseFontWeight(getTokenValue(token, 'fontWeight'))} ${value.fontSize}${value.lineHeight ? `/${value.lineHeight}` : ''} ${parseFontFamily(getTokenValue(token, 'fontFamily'))}`
|
|
24
|
+
.trim()
|
|
25
|
+
.replace(/\s\s+/g, ' ');
|
|
26
|
+
},
|
|
27
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TransformedToken } from 'style-dictionary/types';
|
|
2
|
+
/**
|
|
3
|
+
* alpha
|
|
4
|
+
* @description takes a colors string like hex or rgba and returns an rgba color with the specified alpha value
|
|
5
|
+
* @param color color string like a `#334455` or `rgb(255,200,100)`
|
|
6
|
+
* @param desiredAlpha number
|
|
7
|
+
* @returns rgba value
|
|
8
|
+
*/
|
|
9
|
+
export declare const alpha: (color: string, desiredAlpha: number, token?: TransformedToken) => string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { rgba, parseToRgba } from 'color2k';
|
|
2
|
+
/**
|
|
3
|
+
* alpha
|
|
4
|
+
* @description takes a colors string like hex or rgba and returns an rgba color with the specified alpha value
|
|
5
|
+
* @param color color string like a `#334455` or `rgb(255,200,100)`
|
|
6
|
+
* @param desiredAlpha number
|
|
7
|
+
* @returns rgba value
|
|
8
|
+
*/
|
|
9
|
+
export const alpha = (color, desiredAlpha, token) => {
|
|
10
|
+
const [r, g, b, a] = parseToRgba(color);
|
|
11
|
+
if (a < 1 && desiredAlpha < 1) {
|
|
12
|
+
// eslint-disable-next-line no-console
|
|
13
|
+
console.warn(`🚨 You are setting an alpha value of "${desiredAlpha}" for a color with an alpha value (${color}). The previous alpha value will be disregarded as if the color would have been 100% opaque.${token !== undefined ? `\n ↳ Token: "${token.name}" in file: "${token.filePath}"` : ''}`);
|
|
14
|
+
}
|
|
15
|
+
return rgba(r, g, b, desiredAlpha);
|
|
16
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* checks if all required properties exist on token
|
|
3
|
+
* @param object - tokenValue
|
|
4
|
+
* @param array - property names
|
|
5
|
+
* @returns void or throws error
|
|
6
|
+
*/
|
|
7
|
+
export declare const checkRequiredTokenProperties: (tokenValue: Record<string, unknown>, requiredProperties: readonly string[]) => void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* checks if all required properties exist on token
|
|
3
|
+
* @param object - tokenValue
|
|
4
|
+
* @param array - property names
|
|
5
|
+
* @returns void or throws error
|
|
6
|
+
*/
|
|
7
|
+
export const checkRequiredTokenProperties = (tokenValue, requiredProperties) => {
|
|
8
|
+
for (const prop of requiredProperties) {
|
|
9
|
+
if (prop in tokenValue === false) {
|
|
10
|
+
throw new Error(`Missing property: ${prop} on token with value ${JSON.stringify(tokenValue)}`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { invalidTokenValueError, invalidTokenValuePropertyError } from './invalidTokenError.js';
|
|
2
|
+
export const getTokenValue = (token, property) => {
|
|
3
|
+
var _a;
|
|
4
|
+
const value = (_a = token.$value) !== null && _a !== void 0 ? _a : token.value;
|
|
5
|
+
if (value === undefined) {
|
|
6
|
+
throw new invalidTokenValueError(token);
|
|
7
|
+
}
|
|
8
|
+
// for composite token if subproperty is needed
|
|
9
|
+
if (typeof property === 'string' && value[property] === undefined) {
|
|
10
|
+
throw new invalidTokenValuePropertyError(token, property);
|
|
11
|
+
}
|
|
12
|
+
if (typeof property === 'string') {
|
|
13
|
+
return value[property];
|
|
14
|
+
}
|
|
15
|
+
return value;
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const hasSpaceInString: (string: string) => boolean;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export const hexToRgbaFloat = (hex, alpha) => {
|
|
2
|
+
// retrieve spots from hex value (hex 3, hex 4, hex 6 or hex 8)
|
|
3
|
+
let result;
|
|
4
|
+
if (hex.length > 5) {
|
|
5
|
+
result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i.exec(hex);
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
result = /^#?([a-f\d]{1})([a-f\d]{1})([a-f\d]{1})([a-f\d]{1})?$/i.exec(hex);
|
|
9
|
+
}
|
|
10
|
+
if (result === null) {
|
|
11
|
+
throw new Error('Invalid hex value in "hexToRgbaFloat". Please provide a valid hex3, hex4, hex6 or hex8 value.');
|
|
12
|
+
}
|
|
13
|
+
// doule characters if hex 3 or hex 4
|
|
14
|
+
if (hex.length < 6) {
|
|
15
|
+
result[1] = `${result[1]}${result[1]}`; // double the character
|
|
16
|
+
result[2] = `${result[2]}${result[2]}`; // double the character
|
|
17
|
+
result[3] = `${result[3]}${result[3]}`; // double the character
|
|
18
|
+
if (result[4]) {
|
|
19
|
+
result[4] = `${result[4]}${result[4]}`; // double the character
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
// return parsed rgba float object using alpha value from token, from hex code or defaults to 1
|
|
23
|
+
return {
|
|
24
|
+
r: parseInt(result[1], 16) / 255,
|
|
25
|
+
g: parseInt(result[2], 16) / 255,
|
|
26
|
+
b: parseInt(result[3], 16) / 255,
|
|
27
|
+
a: alpha !== undefined ? alpha : result[4] ? parseInt(result[4], 16) / 255 : 1,
|
|
28
|
+
};
|
|
29
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { TransformedToken } from 'style-dictionary/types';
|
|
2
|
+
export declare class invalidTokenValueError extends Error {
|
|
3
|
+
constructor(token: TransformedToken);
|
|
4
|
+
}
|
|
5
|
+
export declare class invalidTokenValuePropertyError extends Error {
|
|
6
|
+
constructor(token: TransformedToken, property: string);
|
|
7
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { namePathToDotNotation } from '../namePathToDotNotation.js';
|
|
2
|
+
const composeValueErrorMessage = (token) => {
|
|
3
|
+
var _a, _b;
|
|
4
|
+
const originalValue = (_a = token.original.$value) !== null && _a !== void 0 ? _a : token.original.value;
|
|
5
|
+
const value = (_b = token.$value) !== null && _b !== void 0 ? _b : token.value;
|
|
6
|
+
return `Invalid token "${namePathToDotNotation.transform(token, {}, {})}" in file "${token.filePath}". Transformed value: "${JSON.stringify(value)}". ${originalValue ? `Original value: "${JSON.stringify(originalValue)}" ` : ''}This may be due to referencing a token that does not exists.`;
|
|
7
|
+
};
|
|
8
|
+
const composeValuePropertyErrorMessage = (token, property) => {
|
|
9
|
+
var _a, _b;
|
|
10
|
+
const originalValue = (_a = token.original.$value) !== null && _a !== void 0 ? _a : token.original.value;
|
|
11
|
+
const value = (_b = token.$value) !== null && _b !== void 0 ? _b : token.value;
|
|
12
|
+
return `Invalid property "${property}" of token "${namePathToDotNotation.transform(token, {}, {})}" in file "${token.filePath}". Transformed property value: "${value[property]}". ${originalValue ? `Original value: "${originalValue[property]}" ` : ''}This may be due to referencing a token that does not exists.`;
|
|
13
|
+
};
|
|
14
|
+
export class invalidTokenValueError extends Error {
|
|
15
|
+
constructor(token) {
|
|
16
|
+
super(composeValueErrorMessage(token));
|
|
17
|
+
Error.captureStackTrace(this, invalidTokenValueError);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export class invalidTokenValuePropertyError extends Error {
|
|
21
|
+
constructor(token, property) {
|
|
22
|
+
super(composeValuePropertyErrorMessage(token, property));
|
|
23
|
+
Error.captureStackTrace(this, invalidTokenValuePropertyError);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// check if a value is an rgba float object
|
|
2
|
+
export const isRgbaFloat = (value) => {
|
|
3
|
+
if (value &&
|
|
4
|
+
typeof value === `object` &&
|
|
5
|
+
'r' in value &&
|
|
6
|
+
typeof value.r === `number` &&
|
|
7
|
+
'g' in value &&
|
|
8
|
+
typeof value.g === `number` &&
|
|
9
|
+
'b' in value &&
|
|
10
|
+
typeof value.b === `number` &&
|
|
11
|
+
value.r >= 0 &&
|
|
12
|
+
value.r <= 1 &&
|
|
13
|
+
value.g >= 0 &&
|
|
14
|
+
value.g <= 1 &&
|
|
15
|
+
value.b >= 0 &&
|
|
16
|
+
value.b <= 1) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { rgba, parseToRgba } from 'color2k';
|
|
2
|
+
/**
|
|
3
|
+
* Mixes two colors together. Taken from sass's implementation.
|
|
4
|
+
*/
|
|
5
|
+
function mix(color1, color2, weight) {
|
|
6
|
+
const normalize = (n, index) =>
|
|
7
|
+
// 3rd index is alpha channel which is already normalized
|
|
8
|
+
index === 3 ? n : n / 255;
|
|
9
|
+
const [r1, g1, b1, a1] = parseToRgba(color1).map(normalize);
|
|
10
|
+
const [r2, g2, b2, a2] = parseToRgba(color2).map(normalize);
|
|
11
|
+
// The formula is copied from the original Sass implementation:
|
|
12
|
+
// http://sass-lang.com/documentation/Sass/Script/Functions.html#mix-instance_method
|
|
13
|
+
const normalizedWeight = 2 * weight - 1;
|
|
14
|
+
const alphaDelta = a1 - a2;
|
|
15
|
+
const combinedWeight = normalizedWeight * alphaDelta === -1
|
|
16
|
+
? normalizedWeight
|
|
17
|
+
: (normalizedWeight + alphaDelta) / (1 + normalizedWeight * alphaDelta);
|
|
18
|
+
const weight2 = (combinedWeight + 1) / 2;
|
|
19
|
+
const weight1 = 1 - weight2;
|
|
20
|
+
const r = Math.round((r1 * weight1 + r2 * weight2) * 255);
|
|
21
|
+
const g = Math.round((g1 * weight1 + g2 * weight2) * 255);
|
|
22
|
+
const b = Math.round((b1 * weight1 + b2 * weight2) * 255);
|
|
23
|
+
const a = a2 * weight + a1 * (1 - weight);
|
|
24
|
+
return rgba(r, g, b, a);
|
|
25
|
+
}
|
|
26
|
+
export default mix;
|
|
27
|
+
// Number* weight = ARGR("$weight", Number, 0, 100);
|
|
28
|
+
// double p = weight->value()/100;
|
|
29
|
+
// double w = 2*p - 1;
|
|
30
|
+
// double a = color1->a() - color2->a();
|
|
31
|
+
// double nW = ((w * a == -1) ? w : (w + a)/(1 + w*a))
|
|
32
|
+
// double w1 = (nW + 1)/2.0;
|
|
33
|
+
// double w2 = 1 - w1;
|
|
34
|
+
// return new (ctx.mem) Color(pstate,
|
|
35
|
+
// std::round(w1*color1->r() + w2*color2->r()),
|
|
36
|
+
// std::round(w1*color1->g() + w2*color2->g()),
|
|
37
|
+
// std::round(w1*color1->b() + w2*color2->b()),
|
|
38
|
+
// color1->a()*p + color2->a()*(1-p));
|