@primer/primitives 7.16.0 → 7.17.0-rc.132f02a7
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/css/functional/themes/dark-colorblind.css +14 -14
- package/dist/css/functional/themes/dark-tritanopia.css +14 -14
- package/dist/css/functional/themes/dark.css +14 -14
- package/dist/docs/functional/themes/dark-colorblind.json +7 -7
- package/dist/docs/functional/themes/dark-tritanopia.json +7 -7
- package/dist/docs/functional/themes/dark.json +7 -7
- package/dist/figma/scales/dark.json +5 -5
- package/dist/figma/themes/dark-colorblind.json +20 -20
- package/dist/figma/themes/dark-tritanopia.json +20 -20
- package/dist/figma/themes/dark.json +20 -20
- package/dist/internalCss/dark-colorblind.css +18 -18
- package/dist/internalCss/dark-tritanopia.css +18 -18
- package/dist/internalCss/dark.css +18 -18
- package/{tokens-next-private/docs → dist/styleLint}/base/size/size.json +17 -17
- package/{tokens-next-private/docs → dist/styleLint}/functional/size/border.json +6 -6
- package/{tokens-next-private/docs → dist/styleLint}/functional/size/breakpoints.json +6 -6
- package/{tokens-next-private/docs → dist/styleLint}/functional/size/size-coarse.json +3 -3
- package/{tokens-next-private/docs → dist/styleLint}/functional/size/size-fine.json +3 -3
- package/{tokens-next-private/docs → dist/styleLint}/functional/size/size.json +72 -72
- package/{tokens-next-private/docs → dist/styleLint}/functional/size/viewport.json +4 -4
- package/{tokens-next-private/docs → dist/styleLint}/functional/themes/dark-colorblind.json +7 -7
- package/{tokens-next-private/docs → dist/styleLint}/functional/themes/dark-tritanopia.json +7 -7
- package/{tokens-next-private/docs → dist/styleLint}/functional/themes/dark.json +7 -7
- package/{tokens-next-private/docs → dist/styleLint}/functional/typography/typography.json +23 -23
- package/package.json +12 -11
- package/src/PrimerStyleDictionary.ts +226 -0
- package/src/filters/index.ts +12 -0
- package/src/filters/isBorder.ts +10 -0
- package/src/filters/isColor.ts +10 -0
- package/src/filters/isColorWithAlpha.ts +11 -0
- package/src/filters/isColorWithMix.ts +33 -0
- package/src/filters/isDeprecated.ts +10 -0
- package/src/filters/isDimension.ts +10 -0
- package/src/filters/isDuration.ts +10 -0
- package/src/filters/isFontFamily.ts +10 -0
- package/src/filters/isFontWeight.ts +10 -0
- package/src/filters/isFromFile.ts +12 -0
- package/src/filters/isShadow.ts +10 -0
- package/src/filters/isSource.ts +10 -0
- package/src/filters/isTypography.ts +10 -0
- package/src/formats/cssCustomMedia.ts +24 -0
- package/src/formats/cssThemed.ts +35 -0
- package/src/formats/cssVariables.ts +25 -0
- package/src/formats/cssWrapMediaQuery.ts +29 -0
- package/src/formats/index.ts +11 -0
- package/src/formats/javascriptCommonJs.ts +21 -0
- package/src/formats/javascriptEsm.ts +21 -0
- package/src/formats/jsonFigma.ts +133 -0
- package/src/formats/jsonNestedPrefixed.ts +23 -0
- package/src/formats/jsonOneDimensional.ts +18 -0
- package/src/formats/jsonPostCssFallback.ts +16 -0
- package/src/formats/typescriptExportDefinition.ts +170 -0
- package/src/formats/utilities/jsonToFlat.ts +10 -0
- package/src/formats/utilities/jsonToNestedValue.ts +20 -0
- package/src/formats/utilities/prefixTokens.ts +17 -0
- package/src/parsers/index.ts +1 -0
- package/src/parsers/w3cJsonParser.ts +25 -0
- package/src/platforms/css.ts +93 -0
- package/src/platforms/deprecatedJson.ts +16 -0
- package/src/platforms/docJson.ts +34 -0
- package/src/platforms/fallbacks.ts +34 -0
- package/src/platforms/figma.ts +48 -0
- package/src/platforms/index.ts +10 -0
- package/src/platforms/javascript.ts +30 -0
- package/src/platforms/json.ts +32 -0
- package/src/platforms/styleLint.ts +34 -0
- package/src/platforms/typeDefinitions.ts +30 -0
- package/src/platforms/typescript.ts +30 -0
- package/src/schemas/alphaValue.ts +12 -0
- package/src/schemas/baseToken.ts +7 -0
- package/src/schemas/borderToken.ts +19 -0
- package/src/schemas/collections.ts +49 -0
- package/src/schemas/colorHexValue.ts +18 -0
- package/src/schemas/colorToken.ts +50 -0
- package/src/schemas/designToken.ts +38 -0
- package/src/schemas/dimensionToken.ts +22 -0
- package/src/schemas/dimensionValue.ts +16 -0
- package/src/schemas/durationToken.ts +12 -0
- package/src/schemas/durationValue.ts +9 -0
- package/src/schemas/fontFamilyToken.ts +21 -0
- package/src/schemas/fontWeightToken.ts +22 -0
- package/src/schemas/fontWeightValue.ts +14 -0
- package/src/schemas/numberToken.ts +11 -0
- package/src/schemas/referenceValue.ts +12 -0
- package/src/schemas/scopes.ts +16 -0
- package/src/schemas/shadowToken.ts +45 -0
- package/src/schemas/stringToken.ts +11 -0
- package/src/schemas/tokenName.ts +12 -0
- package/src/schemas/tokenType.ts +4 -0
- package/src/schemas/typographyToken.ts +20 -0
- package/src/schemas/validTokenType.ts +44 -0
- package/src/schemas/viewportRangeToken.ts +11 -0
- package/src/test-utilities/getMockDictionary.ts +22 -0
- package/src/test-utilities/getMockFormatterArguments.ts +21 -0
- package/src/test-utilities/getMockParserInput.ts +72 -0
- package/src/test-utilities/getMockToken.ts +25 -0
- package/src/test-utilities/index.ts +4 -0
- package/src/tokens/base/color/dark/dark.dimmed.json5 +1326 -0
- package/src/tokens/base/color/dark/dark.high-contrast.json5 +856 -0
- package/src/tokens/base/color/dark/dark.json5 +866 -0
- package/src/tokens/base/color/dark/display-dark.json5 +1774 -0
- package/src/tokens/base/color/light/display-light.json5 +1774 -0
- package/src/tokens/base/color/light/light.high-contrast.json5 +847 -0
- package/src/tokens/base/color/light/light.json5 +866 -0
- package/src/tokens/base/size/size.json +176 -0
- package/src/tokens/base/typography/typography.json +24 -0
- package/{tokens-next-private/fallbacks → src/tokens/fallback}/color-fallbacks.json +1 -1
- package/src/tokens/functional/border/dark.json5 +12 -0
- package/src/tokens/functional/border/light.json5 +12 -0
- package/src/tokens/functional/color/dark/app-dark.json5 +554 -0
- package/src/tokens/functional/color/dark/data-vis-dark.json5 +144 -0
- package/src/tokens/functional/color/dark/display-dark.json5 +1060 -0
- package/src/tokens/functional/color/dark/overrides/dark.dimmed.json5 +57 -0
- package/src/tokens/functional/color/dark/overrides/dark.high-contrast.json5 +390 -0
- package/src/tokens/functional/color/dark/overrides/dark.protanopia-deuteranopia.json5 +314 -0
- package/src/tokens/functional/color/dark/overrides/dark.tritanopia.json5 +229 -0
- package/src/tokens/functional/color/dark/patterns-dark.json5 +3073 -0
- package/src/tokens/functional/color/dark/primitives-dark.json5 +1206 -0
- package/src/tokens/functional/color/dark/syntax-dark.json5 +559 -0
- package/src/tokens/functional/color/light/app-light.json5 +551 -0
- package/src/tokens/functional/color/light/data-vis-light.json5 +144 -0
- package/src/tokens/functional/color/light/display-light.json5 +1060 -0
- package/src/tokens/functional/color/light/overrides/light.high-contrast.json5 +440 -0
- package/src/tokens/functional/color/light/overrides/light.protanopia-deuteranopia.json5 +340 -0
- package/src/tokens/functional/color/light/overrides/light.tritanopia.json5 +249 -0
- package/src/tokens/functional/color/light/patterns-light.json5 +3070 -0
- package/src/tokens/functional/color/light/primitives-light.json5 +1196 -0
- package/src/tokens/functional/color/light/syntax-light.json5 +559 -0
- package/src/tokens/functional/motion/loading.json5 +17 -0
- package/src/tokens/functional/motion/patterns.json5 +28 -0
- package/src/tokens/functional/shadow/dark.json5 +383 -0
- package/src/tokens/functional/shadow/light.json5 +376 -0
- package/src/tokens/functional/size/border.json +98 -0
- package/src/tokens/functional/size/breakpoints.json +64 -0
- package/src/tokens/functional/size/size-coarse.json +28 -0
- package/src/tokens/functional/size/size-fine.json +28 -0
- package/src/tokens/functional/size/size.json +802 -0
- package/src/tokens/functional/size/viewport.json +28 -0
- package/src/tokens/functional/typography/typography.json +279 -0
- package/src/transformers/borderToCss.ts +38 -0
- package/src/transformers/colorToHex.ts +16 -0
- package/src/transformers/colorToHexAlpha.ts +23 -0
- package/src/transformers/colorToHexMix.ts +19 -0
- package/src/transformers/colorToRgbAlpha.ts +19 -0
- package/src/transformers/colorToRgbaFloat.ts +45 -0
- package/src/transformers/dimensionToPixelUnitless.ts +60 -0
- package/src/transformers/dimensionToRem.ts +56 -0
- package/src/transformers/dimensionToRemPxArray.ts +60 -0
- package/src/transformers/durationToCss.ts +29 -0
- package/src/transformers/figmaAttributes.ts +55 -0
- package/src/transformers/fontFamilyToCss.ts +38 -0
- package/src/transformers/fontWeightToNumber.ts +53 -0
- package/src/transformers/index.ts +21 -0
- package/src/transformers/jsonDeprecated.ts +15 -0
- package/src/transformers/namePathToCamelCase.ts +14 -0
- package/src/transformers/namePathToDotNotation.ts +34 -0
- package/src/transformers/namePathToFigma.ts +28 -0
- package/src/transformers/namePathToKebabCase.ts +19 -0
- package/src/transformers/namePathToSlashNotation.ts +19 -0
- package/src/transformers/shadowToCss.ts +37 -0
- package/src/transformers/typographyToCss.ts +31 -0
- package/src/transformers/utilities/alpha.ts +23 -0
- package/src/transformers/utilities/checkRequiredTokenProperties.ts +16 -0
- package/src/transformers/utilities/getTokenValue.ts +18 -0
- package/src/transformers/utilities/hexToRgbaFloat.ts +31 -0
- package/src/transformers/utilities/invalidTokenError.ts +34 -0
- package/src/transformers/utilities/isRgbaFloat.ts +29 -0
- package/src/transformers/utilities/mix.ts +46 -0
- package/src/transformers/utilities/rgbaFloatToHex.ts +15 -0
- package/src/types/Border.d.ts +5 -0
- package/src/types/BorderTokenValue.d.ts +10 -0
- package/src/types/ColorHex.d.ts +4 -0
- package/src/types/PlatformInitializer.d.ts +11 -0
- package/src/types/Shadow.d.ts +5 -0
- package/src/types/ShadowTokenValue.d.ts +14 -0
- package/src/types/SizeEm.d.ts +4 -0
- package/src/types/SizePx.d.ts +4 -0
- package/src/types/SizeRem.d.ts +4 -0
- package/src/types/StyleDictionaryConfigGenerator.d.ts +15 -0
- package/src/types/TokenBuildInput.d.ts +8 -0
- package/src/types/TypographyTokenValue.d.ts +12 -0
- package/src/types/w3cTransformedToken.d.ts +8 -0
- package/src/utilities/copyFromDir.ts +21 -0
- package/src/utilities/getFlag.ts +12 -0
- package/src/utilities/index.ts +3 -0
- package/src/utilities/joinFriendly.ts +2 -0
- package/src/utilities/schemaErrorMessage.ts +2 -0
- package/src/utilities/toCamelCase.ts +29 -0
- package/src/utilities/treeWalker.ts +27 -0
- package/src/utilities/upperCaseFirstCharacter.ts +10 -0
- package/src/utils-v1.ts +36 -0
- package/tokens-v2-private/css/tokens/base/size/size.css +1 -1
- package/tokens-v2-private/css/tokens/base/typography/typography.css +1 -1
- package/tokens-v2-private/css/tokens/functional/size/border.css +1 -1
- package/tokens-v2-private/css/tokens/functional/size/breakpoints.css +1 -1
- package/tokens-v2-private/css/tokens/functional/size/size-coarse.css +1 -1
- package/tokens-v2-private/css/tokens/functional/size/size-fine.css +1 -1
- package/tokens-v2-private/css/tokens/functional/size/size.css +1 -1
- package/tokens-v2-private/css/tokens/functional/typography/typography.css +1 -1
- package/tokens-v2-private/js/module/tokens/base/size/size.js +1 -1
- package/tokens-v2-private/js/module/tokens/base/typography/typography.js +1 -1
- package/tokens-v2-private/js/module/tokens/functional/size/border.js +1 -1
- package/tokens-v2-private/js/module/tokens/functional/size/breakpoints.js +1 -1
- package/tokens-v2-private/js/module/tokens/functional/size/size-coarse.js +1 -1
- package/tokens-v2-private/js/module/tokens/functional/size/size-fine.js +1 -1
- package/tokens-v2-private/js/module/tokens/functional/size/size.js +1 -1
- package/tokens-v2-private/js/module/tokens/functional/size/viewport.js +1 -1
- package/tokens-v2-private/js/module/tokens/functional/typography/typography.js +1 -1
- package/tokens-v2-private/js/tokens/base/size/size.js +1 -1
- package/tokens-v2-private/js/tokens/base/typography/typography.js +1 -1
- package/tokens-v2-private/js/tokens/functional/size/border.js +1 -1
- package/tokens-v2-private/js/tokens/functional/size/breakpoints.js +1 -1
- package/tokens-v2-private/js/tokens/functional/size/size-coarse.js +1 -1
- package/tokens-v2-private/js/tokens/functional/size/size-fine.js +1 -1
- package/tokens-v2-private/js/tokens/functional/size/size.js +1 -1
- package/tokens-v2-private/js/tokens/functional/size/viewport.js +1 -1
- package/tokens-v2-private/js/tokens/functional/typography/typography.js +1 -1
- package/tokens-v2-private/scss/tokens/base/size/size.scss +1 -1
- package/tokens-v2-private/scss/tokens/base/typography/typography.scss +1 -1
- package/tokens-v2-private/scss/tokens/functional/size/border.scss +1 -1
- package/tokens-v2-private/scss/tokens/functional/size/breakpoints.scss +1 -1
- package/tokens-v2-private/scss/tokens/functional/size/size-coarse.scss +1 -1
- package/tokens-v2-private/scss/tokens/functional/size/size-fine.scss +1 -1
- package/tokens-v2-private/scss/tokens/functional/size/size.scss +1 -1
- package/tokens-v2-private/scss/tokens/functional/size/viewport.scss +1 -1
- package/tokens-v2-private/scss/tokens/functional/typography/typography.scss +1 -1
- package/tokens-v2-private/ts/tokens/base/size/size.d.ts +1 -1
- package/tokens-v2-private/ts/tokens/base/size/size.js +1 -1
- package/tokens-v2-private/ts/tokens/base/typography/typography.d.ts +1 -1
- package/tokens-v2-private/ts/tokens/base/typography/typography.js +1 -1
- package/tokens-v2-private/ts/tokens/functional/size/border.d.ts +1 -1
- package/tokens-v2-private/ts/tokens/functional/size/border.js +1 -1
- package/tokens-v2-private/ts/tokens/functional/size/breakpoints.d.ts +1 -1
- package/tokens-v2-private/ts/tokens/functional/size/breakpoints.js +1 -1
- package/tokens-v2-private/ts/tokens/functional/size/size-coarse.d.ts +1 -1
- package/tokens-v2-private/ts/tokens/functional/size/size-coarse.js +1 -1
- package/tokens-v2-private/ts/tokens/functional/size/size-fine.d.ts +1 -1
- package/tokens-v2-private/ts/tokens/functional/size/size-fine.js +1 -1
- package/tokens-v2-private/ts/tokens/functional/size/size.d.ts +1 -1
- package/tokens-v2-private/ts/tokens/functional/size/size.js +1 -1
- package/tokens-v2-private/ts/tokens/functional/size/viewport.d.ts +1 -1
- package/tokens-v2-private/ts/tokens/functional/size/viewport.js +1 -1
- package/tokens-v2-private/ts/tokens/functional/typography/typography.d.ts +1 -1
- package/tokens-v2-private/ts/tokens/functional/typography/typography.js +1 -1
- package/dist/deprecated/colors.json +0 -7
- package/dist/js/colors/dark.d.ts +0 -516
- package/dist/js/colors/dark.js +0 -616
- package/dist/js/colors/dark_colorblind.d.ts +0 -516
- package/dist/js/colors/dark_colorblind.js +0 -616
- package/dist/js/colors/dark_dimmed.d.ts +0 -516
- package/dist/js/colors/dark_dimmed.js +0 -616
- package/dist/js/colors/dark_high_contrast.d.ts +0 -516
- package/dist/js/colors/dark_high_contrast.js +0 -616
- package/dist/js/colors/dark_tritanopia.d.ts +0 -516
- package/dist/js/colors/dark_tritanopia.js +0 -616
- package/dist/js/colors/index.d.ts +0 -4638
- package/dist/js/colors/index.js +0 -15
- package/dist/js/colors/light.d.ts +0 -516
- package/dist/js/colors/light.js +0 -616
- package/dist/js/colors/light_colorblind.d.ts +0 -516
- package/dist/js/colors/light_colorblind.js +0 -616
- package/dist/js/colors/light_high_contrast.d.ts +0 -516
- package/dist/js/colors/light_high_contrast.js +0 -616
- package/dist/js/colors/light_tritanopia.d.ts +0 -516
- package/dist/js/colors/light_tritanopia.js +0 -616
- package/dist/js/index.d.ts +0 -4655
- package/dist/js/index.js +0 -9
- package/dist/js/spacing/index.d.ts +0 -6
- package/dist/js/spacing/index.js +0 -7
- package/dist/js/spacing/normal.d.ts +0 -4
- package/dist/js/spacing/normal.js +0 -13
- package/dist/js/typography/index.d.ts +0 -11
- package/dist/js/typography/index.js +0 -7
- package/dist/js/typography/normal.d.ts +0 -9
- package/dist/js/typography/normal.js +0 -19
- package/dist/json/colors/dark.json +0 -614
- package/dist/json/colors/dark_colorblind.json +0 -614
- package/dist/json/colors/dark_dimmed.json +0 -614
- package/dist/json/colors/dark_high_contrast.json +0 -614
- package/dist/json/colors/dark_tritanopia.json +0 -614
- package/dist/json/colors/light.json +0 -614
- package/dist/json/colors/light_colorblind.json +0 -614
- package/dist/json/colors/light_high_contrast.json +0 -614
- package/dist/json/colors/light_tritanopia.json +0 -614
- package/dist/json/spacing/normal.json +0 -11
- package/dist/json/typography/normal.json +0 -17
- package/dist/removed/colors.json +0 -432
- package/dist/scss/colors/_dark.scss +0 -452
- package/dist/scss/colors/_dark_colorblind.scss +0 -452
- package/dist/scss/colors/_dark_dimmed.scss +0 -452
- package/dist/scss/colors/_dark_high_contrast.scss +0 -452
- package/dist/scss/colors/_dark_tritanopia.scss +0 -452
- package/dist/scss/colors/_light.scss +0 -452
- package/dist/scss/colors/_light_colorblind.scss +0 -452
- package/dist/scss/colors/_light_high_contrast.scss +0 -452
- package/dist/scss/colors/_light_tritanopia.scss +0 -452
- package/dist/scss/spacing/_normal.scss +0 -11
- package/dist/scss/typography/_normal.scss +0 -15
- package/dist/ts/colors/dark.ts +0 -614
- package/dist/ts/colors/dark_colorblind.ts +0 -614
- package/dist/ts/colors/dark_dimmed.ts +0 -614
- package/dist/ts/colors/dark_high_contrast.ts +0 -614
- package/dist/ts/colors/dark_tritanopia.ts +0 -614
- package/dist/ts/colors/index.ts +0 -10
- package/dist/ts/colors/light.ts +0 -614
- package/dist/ts/colors/light_colorblind.ts +0 -614
- package/dist/ts/colors/light_high_contrast.ts +0 -614
- package/dist/ts/colors/light_tritanopia.ts +0 -614
- package/dist/ts/index.ts +0 -4
- package/dist/ts/spacing/index.ts +0 -2
- package/dist/ts/spacing/normal.ts +0 -11
- package/dist/ts/typography/index.ts +0 -2
- package/dist/ts/typography/normal.ts +0 -17
- package/tokens-next-private/css/base/size/size.css +0 -19
- package/tokens-next-private/css/base/typography/typography.css +0 -6
- package/tokens-next-private/css/functional/motion/motion.css +0 -5
- package/tokens-next-private/css/functional/size/border.css +0 -14
- package/tokens-next-private/css/functional/size/breakpoints.css +0 -8
- package/tokens-next-private/css/functional/size/size-coarse.css +0 -7
- package/tokens-next-private/css/functional/size/size-fine.css +0 -7
- package/tokens-next-private/css/functional/size/size.css +0 -74
- package/tokens-next-private/css/functional/size/viewport.css +0 -6
- package/tokens-next-private/css/functional/themes/dark-colorblind.css +0 -1078
- package/tokens-next-private/css/functional/themes/dark-dimmed.css +0 -1078
- package/tokens-next-private/css/functional/themes/dark-high-contrast.css +0 -1078
- package/tokens-next-private/css/functional/themes/dark-tritanopia.css +0 -1078
- package/tokens-next-private/css/functional/themes/dark.css +0 -1078
- package/tokens-next-private/css/functional/themes/light-colorblind.css +0 -1078
- package/tokens-next-private/css/functional/themes/light-high-contrast.css +0 -1078
- package/tokens-next-private/css/functional/themes/light-tritanopia.css +0 -1078
- package/tokens-next-private/css/functional/themes/light.css +0 -1078
- package/tokens-next-private/css/functional/typography/typography.css +0 -47
- package/tokens-next-private/fallbacks/base/size/size.json +0 -19
- package/tokens-next-private/fallbacks/base/typography/typography.json +0 -6
- package/tokens-next-private/fallbacks/functional/motion/motion.json +0 -5
- package/tokens-next-private/fallbacks/functional/size/border.json +0 -14
- package/tokens-next-private/fallbacks/functional/size/breakpoints.json +0 -8
- package/tokens-next-private/fallbacks/functional/size/size-coarse.json +0 -5
- package/tokens-next-private/fallbacks/functional/size/size-fine.json +0 -5
- package/tokens-next-private/fallbacks/functional/size/size.json +0 -74
- package/tokens-next-private/fallbacks/functional/size/viewport.json +0 -8
- package/tokens-next-private/fallbacks/functional/typography/typography.json +0 -47
- package/tokens-next-private/internalCss/dark-colorblind.css +0 -1648
- package/tokens-next-private/internalCss/dark-dimmed.css +0 -1648
- package/tokens-next-private/internalCss/dark-high-contrast.css +0 -1648
- package/tokens-next-private/internalCss/dark-tritanopia.css +0 -1648
- package/tokens-next-private/internalCss/dark.css +0 -1648
- package/tokens-next-private/internalCss/light-colorblind.css +0 -1648
- package/tokens-next-private/internalCss/light-high-contrast.css +0 -1648
- package/tokens-next-private/internalCss/light-tritanopia.css +0 -1648
- package/tokens-next-private/internalCss/light.css +0 -1648
- /package/{tokens-next-private/docs → dist/styleLint}/base/typography/typography.json +0 -0
- /package/{tokens-next-private/docs → dist/styleLint}/functional/motion/motion.json +0 -0
- /package/{tokens-next-private/docs → dist/styleLint}/functional/themes/dark-dimmed.json +0 -0
- /package/{tokens-next-private/docs → dist/styleLint}/functional/themes/dark-high-contrast.json +0 -0
- /package/{tokens-next-private/docs → dist/styleLint}/functional/themes/light-colorblind.json +0 -0
- /package/{tokens-next-private/docs → dist/styleLint}/functional/themes/light-high-contrast.json +0 -0
- /package/{tokens-next-private/docs → dist/styleLint}/functional/themes/light-tritanopia.json +0 -0
- /package/{tokens-next-private/docs → dist/styleLint}/functional/themes/light.json +0 -0
- /package/{tokens-next-private → src/tokens}/removed/color.json +0 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import StyleDictionary from 'style-dictionary'
|
|
2
|
+
import {format} from 'prettier'
|
|
3
|
+
import type {FormatterArguments} from 'style-dictionary/types/Format'
|
|
4
|
+
import {transformNamePathToFigma} from '../transformers/namePathToFigma'
|
|
5
|
+
import type {ShadowTokenValue} from '../types/ShadowTokenValue'
|
|
6
|
+
import {hexToRgbaFloat} from '../transformers/utilities/hexToRgbaFloat'
|
|
7
|
+
import type {RgbaFloat} from '../transformers/utilities/isRgbaFloat'
|
|
8
|
+
import {isRgbaFloat} from '../transformers/utilities/isRgbaFloat'
|
|
9
|
+
const {sortByReference} = StyleDictionary.formatHelpers
|
|
10
|
+
|
|
11
|
+
const isReference = (string: string): boolean => /^\{([^\\]*)\}$/g.test(string)
|
|
12
|
+
|
|
13
|
+
const getReference = (
|
|
14
|
+
dictionary: StyleDictionary.Dictionary,
|
|
15
|
+
refString: string,
|
|
16
|
+
platform: StyleDictionary.Platform,
|
|
17
|
+
) => {
|
|
18
|
+
if (isReference(refString)) {
|
|
19
|
+
// retrieve reference token
|
|
20
|
+
const refToken = dictionary.getReferences(refString)[0]
|
|
21
|
+
// return full reference
|
|
22
|
+
return [refToken.attributes?.collection, transformNamePathToFigma(refToken, platform)].filter(Boolean).join('/')
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const getFigmaType = (type: string): string => {
|
|
27
|
+
const validTypes = {
|
|
28
|
+
color: 'COLOR',
|
|
29
|
+
dimension: 'FLOAT',
|
|
30
|
+
fontWeight: 'FLOAT',
|
|
31
|
+
fontFamily: 'STRING',
|
|
32
|
+
}
|
|
33
|
+
if (type in validTypes) return validTypes[type as keyof typeof validTypes]
|
|
34
|
+
throw new Error(`Invalid type: ${type}`)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const shadowToVariables = (
|
|
38
|
+
name: string,
|
|
39
|
+
values: Omit<ShadowTokenValue, 'color'> & {color: string | RgbaFloat},
|
|
40
|
+
token: StyleDictionary.TransformedToken,
|
|
41
|
+
) => {
|
|
42
|
+
// floatValue
|
|
43
|
+
const floatValue = (property: 'offsetX' | 'offsetY' | 'blur' | 'spread') => ({
|
|
44
|
+
name: `${name}/${property}`,
|
|
45
|
+
value: parseInt(values[property].replace('px', '')),
|
|
46
|
+
type: 'FLOAT',
|
|
47
|
+
scopes: ['EFFECT_FLOAT'],
|
|
48
|
+
mode,
|
|
49
|
+
collection,
|
|
50
|
+
group,
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
const {attributes} = token
|
|
54
|
+
const {mode, collection, group} = attributes || {}
|
|
55
|
+
|
|
56
|
+
return [
|
|
57
|
+
floatValue('offsetX'),
|
|
58
|
+
floatValue('offsetY'),
|
|
59
|
+
floatValue('blur'),
|
|
60
|
+
floatValue('spread'),
|
|
61
|
+
{
|
|
62
|
+
name: `${name}/color`,
|
|
63
|
+
value: isRgbaFloat(values.color)
|
|
64
|
+
? {...values.color, ...(values.alpha ? {a: values.alpha} : {})}
|
|
65
|
+
: hexToRgbaFloat(values.color, values.alpha),
|
|
66
|
+
type: 'COLOR',
|
|
67
|
+
scopes: ['EFFECT_COLOR'],
|
|
68
|
+
mode,
|
|
69
|
+
collection,
|
|
70
|
+
group,
|
|
71
|
+
},
|
|
72
|
+
]
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @description Converts `StyleDictionary.dictionary.tokens` to javascript esm (javascript export statement)
|
|
77
|
+
* @param arguments [FormatterArguments](https://github.com/amzn/style-dictionary/blob/main/types/Format.d.ts)
|
|
78
|
+
* @returns formatted `string`
|
|
79
|
+
*/
|
|
80
|
+
export const jsonFigma: StyleDictionary.Formatter = ({dictionary, file: _file, platform}: FormatterArguments) => {
|
|
81
|
+
// array to store tokens in
|
|
82
|
+
const tokens: Record<string, unknown>[] = []
|
|
83
|
+
// loop through tokens sorted by reference
|
|
84
|
+
for (const token of dictionary.allTokens.sort(sortByReference(dictionary))) {
|
|
85
|
+
// deconstruct token
|
|
86
|
+
const {attributes, value, $type, comment: description, original, alpha, mix} = token
|
|
87
|
+
const {mode, collection, scopes, group, codeSyntax} = attributes || {}
|
|
88
|
+
// shadows need to be specifically dealt with
|
|
89
|
+
if ($type === 'shadow') {
|
|
90
|
+
const shadowValues = !Array.isArray(value) ? [value] : value
|
|
91
|
+
// if only one set of shadow values is present
|
|
92
|
+
if (shadowValues.length === 1) {
|
|
93
|
+
tokens.push(
|
|
94
|
+
...shadowToVariables(token.name, shadowValues[0], {
|
|
95
|
+
...token,
|
|
96
|
+
...(platform.mode ? {mode: platform.mode} : {}),
|
|
97
|
+
}),
|
|
98
|
+
)
|
|
99
|
+
} else {
|
|
100
|
+
// if multiple shadow sets values are present we need loop through them and add the index to the name
|
|
101
|
+
for (const [index, stepValue] of shadowValues.entries()) {
|
|
102
|
+
tokens.push(
|
|
103
|
+
...shadowToVariables(`${token.name}/${index + 1}`, stepValue, {
|
|
104
|
+
...token,
|
|
105
|
+
...(platform.mode ? {mode: platform.mode} : {}),
|
|
106
|
+
}),
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// other tokens just get added to tokens array
|
|
111
|
+
} else {
|
|
112
|
+
tokens.push({
|
|
113
|
+
name: token.name,
|
|
114
|
+
value,
|
|
115
|
+
type: getFigmaType($type),
|
|
116
|
+
alpha,
|
|
117
|
+
isMix: mix ? true : undefined,
|
|
118
|
+
description,
|
|
119
|
+
refId: [collection, token.name].filter(Boolean).join('/'),
|
|
120
|
+
reference: getReference(dictionary, original.value, platform),
|
|
121
|
+
collection,
|
|
122
|
+
mode,
|
|
123
|
+
group,
|
|
124
|
+
scopes,
|
|
125
|
+
codeSyntax,
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// add file header and convert output
|
|
130
|
+
const output = JSON.stringify(tokens, null, 2)
|
|
131
|
+
// return prettified
|
|
132
|
+
return format(output, {parser: 'json', printWidth: 500})
|
|
133
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type StyleDictionary from 'style-dictionary'
|
|
2
|
+
import {format} from 'prettier'
|
|
3
|
+
import {prefixTokens} from './utilities/prefixTokens'
|
|
4
|
+
import {jsonToNestedValue} from './utilities/jsonToNestedValue'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @description Takes a style dictionary token dictionary and converts it to a nested json string.
|
|
8
|
+
* In contrast to the `json/nested` this formatter does add a prefix if provided
|
|
9
|
+
* @param StyleDictionary.FormatterArguments
|
|
10
|
+
* @returns formatted json `string`
|
|
11
|
+
*/
|
|
12
|
+
export const jsonNestedPrefixed: StyleDictionary.Formatter = ({dictionary, file: _file, options, platform}) => {
|
|
13
|
+
const {outputVerbose} = options
|
|
14
|
+
// add prefix if defined
|
|
15
|
+
let tokens = prefixTokens(dictionary.tokens, platform)
|
|
16
|
+
if (!outputVerbose) {
|
|
17
|
+
tokens = jsonToNestedValue(tokens)
|
|
18
|
+
}
|
|
19
|
+
// add file header and convert output
|
|
20
|
+
const output = JSON.stringify(tokens, null, 2)
|
|
21
|
+
// return prettified
|
|
22
|
+
return format(output, {parser: 'json', printWidth: 500})
|
|
23
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type StyleDictionary from 'style-dictionary'
|
|
2
|
+
import {format} from 'prettier'
|
|
3
|
+
import {jsonToFlat} from './utilities/jsonToFlat'
|
|
4
|
+
/**
|
|
5
|
+
* @description Takes a style dictionary token dictionary and converts it to a one dimensional json object.
|
|
6
|
+
* @param StyleDictionary.FormatterArguments
|
|
7
|
+
* @param options.nameSeparator - separator to use for nested token name
|
|
8
|
+
* @returns formatted json `string`
|
|
9
|
+
*/
|
|
10
|
+
export const jsonOneDimensional: StyleDictionary.Formatter = ({dictionary, file: _file, options}) => {
|
|
11
|
+
// option to allow verbose output (object) or just the value
|
|
12
|
+
const {outputVerbose} = options
|
|
13
|
+
const tokens = jsonToFlat(dictionary.allTokens, outputVerbose)
|
|
14
|
+
// add file header and convert output
|
|
15
|
+
const output = JSON.stringify(tokens, null, 2)
|
|
16
|
+
// return prettified
|
|
17
|
+
return format(output, {parser: 'json', printWidth: 500})
|
|
18
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type StyleDictionary from 'style-dictionary'
|
|
2
|
+
import {format} from 'prettier'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @description Takes a style dictionary token dictionary and converts it to a one dimensional json object.
|
|
6
|
+
* @param StyleDictionary.FormatterArguments
|
|
7
|
+
* @param options.nameSeparator - separator to use for nested token name
|
|
8
|
+
* @returns formatted json `string`
|
|
9
|
+
*/
|
|
10
|
+
export const jsonPostCssFallback: StyleDictionary.Formatter = ({dictionary, file: _file}) => {
|
|
11
|
+
const tokens = Object.fromEntries(dictionary.allTokens.map(token => [`--${token.name}`, token.value]))
|
|
12
|
+
// add file header and convert output
|
|
13
|
+
const output = JSON.stringify(tokens, null, 2)
|
|
14
|
+
// return prettified
|
|
15
|
+
return format(output, {parser: 'json', printWidth: 500})
|
|
16
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import StyleDictionary from 'style-dictionary'
|
|
2
|
+
import {format} from 'prettier'
|
|
3
|
+
import fs = require('fs')
|
|
4
|
+
import path = require('path')
|
|
5
|
+
import {treeWalker} from '../utilities/treeWalker'
|
|
6
|
+
|
|
7
|
+
import type {FormatterArguments} from 'style-dictionary/types/Format'
|
|
8
|
+
import type {w3cTransformedToken} from '../types/w3cTransformedToken'
|
|
9
|
+
import {prefixTokens} from './utilities/prefixTokens'
|
|
10
|
+
|
|
11
|
+
const {fileHeader} = StyleDictionary.formatHelpers
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* unquoteTypes
|
|
15
|
+
* @description extract types from designTokenTypes (string with type definitions from file) and replace quoted types "Color" with unquoted Color
|
|
16
|
+
* @param output
|
|
17
|
+
* @param designTokenTypes
|
|
18
|
+
* @returns string with unquoted types
|
|
19
|
+
*/
|
|
20
|
+
const unquoteTypes = (output: string, designTokenTypes: string[]): string => {
|
|
21
|
+
// join types for replacement
|
|
22
|
+
const regex = `"(${['number', 'string', 'any', ...designTokenTypes].join('|')})"`
|
|
23
|
+
// remove strings
|
|
24
|
+
return output.replace(new RegExp(regex, 'g'), '$1')
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* getTokenType
|
|
29
|
+
* @description extract content from token files
|
|
30
|
+
* @param path string
|
|
31
|
+
*/
|
|
32
|
+
const getTokenType = (tokenTypesPath: string): string => {
|
|
33
|
+
try {
|
|
34
|
+
const designTokenType = fs.readFileSync(path.resolve(tokenTypesPath), {encoding: 'utf-8'})
|
|
35
|
+
return designTokenType
|
|
36
|
+
} catch (e) {
|
|
37
|
+
// eslint-disable-next-line no-console
|
|
38
|
+
throw new Error(`Error trying to load design token type from file "${tokenTypesPath}".`)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @description throws an error stating the token name, type and invalid value
|
|
44
|
+
* @param token w3cTransformedToken
|
|
45
|
+
*/
|
|
46
|
+
const invalidTokenValueError = (token: w3cTransformedToken) => {
|
|
47
|
+
throw new Error(`Invalid token: "${token.name}" with type "${token.$type}" can not have a value of "${token.value}"`)
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* convertPropToType
|
|
51
|
+
* @description return take type attribute and return correct typescript type as string
|
|
52
|
+
* @param type
|
|
53
|
+
* @returns
|
|
54
|
+
*/
|
|
55
|
+
const convertPropToType = (tree: w3cTransformedToken): string => {
|
|
56
|
+
if (!Object.prototype.hasOwnProperty.call(tree, 'value')) {
|
|
57
|
+
throw new Error(`Invalid token: ${tree}`)
|
|
58
|
+
}
|
|
59
|
+
switch (tree.$type) {
|
|
60
|
+
case 'color':
|
|
61
|
+
if (typeof tree.value === 'string' && tree.value[0] === '#') {
|
|
62
|
+
return 'ColorHex'
|
|
63
|
+
}
|
|
64
|
+
return invalidTokenValueError(tree)
|
|
65
|
+
case 'dimension':
|
|
66
|
+
if (typeof tree.value === 'string' && tree.value.substring(tree.value.length - 3) === 'rem') return 'SizeRem'
|
|
67
|
+
if (typeof tree.value === 'string' && tree.value.substring(tree.value.length - 2) === 'em') return 'SizeEm'
|
|
68
|
+
if (typeof tree.value === 'string' && tree.value.substring(tree.value.length - 2) === 'px') return 'SizePx'
|
|
69
|
+
return invalidTokenValueError(tree)
|
|
70
|
+
case 'shadow':
|
|
71
|
+
return 'Shadow'
|
|
72
|
+
case 'border':
|
|
73
|
+
return 'Border'
|
|
74
|
+
default:
|
|
75
|
+
if (typeof tree.value === 'number') return 'number'
|
|
76
|
+
if (typeof tree.value === 'string') return 'string'
|
|
77
|
+
if (typeof tree.value === 'boolean') return 'boolean'
|
|
78
|
+
return 'any'
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* a valid token node has a `value` property
|
|
83
|
+
* @param item object
|
|
84
|
+
* @returns boolean
|
|
85
|
+
*/
|
|
86
|
+
const validTokenNode = (item: w3cTransformedToken | unknown): item is w3cTransformedToken => {
|
|
87
|
+
return typeof item === 'object' && item !== null && 'value' in item
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* returns a set with every used token type
|
|
91
|
+
* @param item object
|
|
92
|
+
* @param validTypes array, all other types will be removed
|
|
93
|
+
* @returns set of all used token types
|
|
94
|
+
*/
|
|
95
|
+
const getUsedTokenTypes = (tokens: StyleDictionary.DesignTokens, validTypes: string[]): Set<string> => {
|
|
96
|
+
// using a set to assure every value only exists once
|
|
97
|
+
const usedTypes = new Set<string>()
|
|
98
|
+
// adds type to set
|
|
99
|
+
const callback = (tree: unknown) => usedTypes.add(convertPropToType(tree as w3cTransformedToken))
|
|
100
|
+
// tree walker adds to usedTypes
|
|
101
|
+
treeWalker(tokens, callback, validTokenNode)
|
|
102
|
+
// clean up types
|
|
103
|
+
for (const type of usedTypes) {
|
|
104
|
+
if (!validTypes.includes(type)) {
|
|
105
|
+
usedTypes.delete(type)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return usedTypes
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* returns the entire token object structure but instead of token values each token just has a typescript type
|
|
112
|
+
* @param item object
|
|
113
|
+
* @returns object
|
|
114
|
+
*/
|
|
115
|
+
const getTokenObjectWithTypes = (tokens: StyleDictionary.DesignTokens): Record<string, unknown> => {
|
|
116
|
+
// TODO: FIX typescript issues
|
|
117
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
118
|
+
// @ts-ignore
|
|
119
|
+
return treeWalker(tokens, convertPropToType, validTokenNode) as Record<string, unknown>
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* getTypeDefinition
|
|
123
|
+
* @description returns type definitions as string
|
|
124
|
+
* @param tokens
|
|
125
|
+
* @param moduleName
|
|
126
|
+
* @param tokenTypesPath
|
|
127
|
+
* @returns string
|
|
128
|
+
*/
|
|
129
|
+
const getTypeDefinition = (
|
|
130
|
+
tokens: StyleDictionary.DesignTokens,
|
|
131
|
+
moduleName: string,
|
|
132
|
+
tokenTypesPath: string,
|
|
133
|
+
): string => {
|
|
134
|
+
const usedTypes = getUsedTokenTypes(tokens, ['ColorHex', 'Shadow', 'Border', 'SizeEm', 'SizeRem', 'SizePx'])
|
|
135
|
+
const tokenObjectWithTypes = getTokenObjectWithTypes(tokens)
|
|
136
|
+
// get token type declaration from file
|
|
137
|
+
const designTokenTypes: string[] = []
|
|
138
|
+
for (const type of usedTypes) {
|
|
139
|
+
// path to type files without trailing slash
|
|
140
|
+
const typePath = tokenTypesPath.replace(new RegExp(/\/$/, 'g'), '')
|
|
141
|
+
|
|
142
|
+
designTokenTypes.push(getTokenType(`${typePath}/${type}.d.ts`))
|
|
143
|
+
}
|
|
144
|
+
// build output
|
|
145
|
+
const output = `${designTokenTypes.join('\n')}
|
|
146
|
+
export type ${moduleName} = ${JSON.stringify(tokenObjectWithTypes, null, 2)}`
|
|
147
|
+
|
|
148
|
+
// JSON stringify will quote strings, because this is a type we need it unquoted.
|
|
149
|
+
return unquoteTypes(output, [...usedTypes])
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* @description Converts `StyleDictionary.dictionary.tokens` to typescript definition
|
|
153
|
+
* @param arguments [FormatterArguments](https://github.com/amzn/style-dictionary/blob/main/types/Format.d.ts)
|
|
154
|
+
* @returns formatted `string`
|
|
155
|
+
*/
|
|
156
|
+
export const typescriptExportDefinition: StyleDictionary.Formatter = ({
|
|
157
|
+
dictionary,
|
|
158
|
+
file,
|
|
159
|
+
options = {},
|
|
160
|
+
platform,
|
|
161
|
+
}: FormatterArguments): string => {
|
|
162
|
+
// extract options
|
|
163
|
+
const {moduleName = `tokens`, tokenTypesPath = `./src/types/`} = options
|
|
164
|
+
// add prefix if defined
|
|
165
|
+
const tokens = prefixTokens(dictionary.tokens, platform)
|
|
166
|
+
// add file header and convert output
|
|
167
|
+
const output = `${fileHeader({file})}\n${getTypeDefinition(tokens, moduleName, tokenTypesPath)}\n`
|
|
168
|
+
// return prettified
|
|
169
|
+
return format(output, {parser: 'typescript', printWidth: 500})
|
|
170
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type StyleDictionary from 'style-dictionary'
|
|
2
|
+
/**
|
|
3
|
+
* jsonToFlat
|
|
4
|
+
* @description creates a one dimensional json structure with either a single value or an token object as the value
|
|
5
|
+
* @param token StyleDictionary.DesignToken
|
|
6
|
+
* @param returnObject - boolean
|
|
7
|
+
* @returns flat json three
|
|
8
|
+
*/
|
|
9
|
+
export const jsonToFlat = (tokens: StyleDictionary.TransformedToken[], returnObject = false) =>
|
|
10
|
+
Object.fromEntries(tokens.map(token => [token.name, returnObject ? token : token.value]))
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type StyleDictionary from 'style-dictionary'
|
|
2
|
+
/**
|
|
3
|
+
* jsonToNestedValue
|
|
4
|
+
* @description creates a nested json tree where every final value is the `.value` prop
|
|
5
|
+
* @param token StyleDictionary.DesignToken
|
|
6
|
+
* @returns nested json three
|
|
7
|
+
*/
|
|
8
|
+
export const jsonToNestedValue = (token: StyleDictionary.DesignToken | Record<string, unknown>) => {
|
|
9
|
+
// is non-object value
|
|
10
|
+
if (typeof token !== 'object') return token
|
|
11
|
+
// is design token
|
|
12
|
+
if ('value' in token) return token.value
|
|
13
|
+
// is obj
|
|
14
|
+
const nextObj = {}
|
|
15
|
+
for (const [prop, value] of Object.entries(token)) {
|
|
16
|
+
// @ts-expect-error: can't predict type
|
|
17
|
+
nextObj[prop] = jsonToNestedValue(value)
|
|
18
|
+
}
|
|
19
|
+
return nextObj
|
|
20
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type StyleDictionary from 'style-dictionary'
|
|
2
|
+
/**
|
|
3
|
+
* @description extract prefix from platform and add to tokens array if defined
|
|
4
|
+
* @param tokens StyleDictionary.TransformedTokens
|
|
5
|
+
* @param platform StyleDictionary.Platform
|
|
6
|
+
* @return StyleDictionary.TransformedTokens
|
|
7
|
+
*/
|
|
8
|
+
export const prefixTokens = (
|
|
9
|
+
tokens: StyleDictionary.TransformedTokens,
|
|
10
|
+
platform: StyleDictionary.Platform = {},
|
|
11
|
+
): StyleDictionary.TransformedTokens => {
|
|
12
|
+
const {prefix} = platform
|
|
13
|
+
if (typeof prefix === 'string') {
|
|
14
|
+
tokens = {[prefix]: tokens}
|
|
15
|
+
}
|
|
16
|
+
return tokens
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {w3cJsonParser} from './w3cJsonParser'
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {parse as json5Parse} from 'json5'
|
|
2
|
+
import type StyleDictionary from 'style-dictionary'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @description Parses a valid [json5](https://json5.org) file and replaces `$value` with `value` and `$description` with `comment` to make a w3c standard file compatible with style dictionary
|
|
6
|
+
* @pattern supported file extensions `.json` or `.json5`
|
|
7
|
+
*/
|
|
8
|
+
export const w3cJsonParser: StyleDictionary.Parser = {
|
|
9
|
+
pattern: /\.json5?$/,
|
|
10
|
+
parse: ({filePath, contents}: {filePath: string; contents: string}) => {
|
|
11
|
+
// replace $value with value so that style dictionary recognizes it
|
|
12
|
+
try {
|
|
13
|
+
contents = contents
|
|
14
|
+
.replace(/["|']?\$value["|']?:/g, '"value":')
|
|
15
|
+
// convert $description to comment
|
|
16
|
+
.replace(/["|']?\$?description["|']?:/g, '"comment":')
|
|
17
|
+
.replace(/["|']?\$?type["|']?:/g, '"$type":')
|
|
18
|
+
.replace(/["|']?\$?extensions["|']?:/g, '"$extensions":')
|
|
19
|
+
//
|
|
20
|
+
return json5Parse(contents)
|
|
21
|
+
} catch (e) {
|
|
22
|
+
throw new Error(`Invalid json5 file "${filePath}".`)
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import {isFromFile, isSource} from '../filters'
|
|
2
|
+
import type StyleDictionary from 'style-dictionary'
|
|
3
|
+
import type {PlatformInitializer} from '../types/PlatformInitializer'
|
|
4
|
+
|
|
5
|
+
const getCssSelectors = (outputFile: string): {selector: string; selectorLight: string; selectorDark: string} => {
|
|
6
|
+
// check for dark in the beginning of the output filename
|
|
7
|
+
const lastSlash = outputFile.lastIndexOf('/')
|
|
8
|
+
const outputBasename = outputFile.substring(lastSlash + 1, outputFile.indexOf('.'))
|
|
9
|
+
const themeName = outputBasename.replace(/-/g, '_')
|
|
10
|
+
const mode = outputBasename.substring(0, 4) === 'dark' ? 'dark' : 'light'
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
selector: `[data-color-mode="${mode}"][data-${mode}-theme="${themeName}"], [data-color-mode="${mode}"][data-${mode}-theme="${themeName}"] ::backdrop`,
|
|
14
|
+
selectorLight: `[data-color-mode="auto"][data-light-theme="${themeName}"], [data-color-mode="auto"][data-light-theme="${themeName}"] ::backdrop`,
|
|
15
|
+
selectorDark: `[data-color-mode="auto"][data-dark-theme="${themeName}"], [data-color-mode="auto"][data-dark-theme="${themeName}"] ::backdrop`,
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const css: PlatformInitializer = (outputFile, prefix, buildPath, options): StyleDictionary.Platform => {
|
|
20
|
+
const {selector, selectorLight, selectorDark} = getCssSelectors(outputFile)
|
|
21
|
+
return {
|
|
22
|
+
prefix,
|
|
23
|
+
buildPath,
|
|
24
|
+
transforms: [
|
|
25
|
+
'name/pathToKebabCase',
|
|
26
|
+
'color/hex',
|
|
27
|
+
'color/hexAlpha',
|
|
28
|
+
'color/hexMix',
|
|
29
|
+
'dimension/rem',
|
|
30
|
+
'duration/css',
|
|
31
|
+
'shadow/css',
|
|
32
|
+
'border/css',
|
|
33
|
+
'typography/css',
|
|
34
|
+
'fontFamily/css',
|
|
35
|
+
'fontWeight/number',
|
|
36
|
+
],
|
|
37
|
+
options: {
|
|
38
|
+
basePxFontSize: 16,
|
|
39
|
+
},
|
|
40
|
+
files: [
|
|
41
|
+
{
|
|
42
|
+
destination: `${outputFile}`,
|
|
43
|
+
format: `css/themed`,
|
|
44
|
+
filter: token => isSource(token) && options?.themed === true,
|
|
45
|
+
options: {
|
|
46
|
+
showFileHeader: false,
|
|
47
|
+
outputReferences: false,
|
|
48
|
+
descriptions: false,
|
|
49
|
+
selector,
|
|
50
|
+
selectorLight,
|
|
51
|
+
selectorDark,
|
|
52
|
+
...options?.options,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
destination: `${outputFile}`,
|
|
57
|
+
format: `css/variables`,
|
|
58
|
+
filter: token => isSource(token) && options?.themed !== true,
|
|
59
|
+
options: {
|
|
60
|
+
showFileHeader: false,
|
|
61
|
+
descriptions: false,
|
|
62
|
+
...options?.options,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
destination: `${outputFile}`,
|
|
67
|
+
format: `css/customMedia`,
|
|
68
|
+
filter: token => isSource(token) && options?.themed !== true && token.$type === 'custom-viewportRange',
|
|
69
|
+
options: {
|
|
70
|
+
showFileHeader: false,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
destination: `${outputFile}`,
|
|
75
|
+
format: `css/wrapMediaQuery`,
|
|
76
|
+
filter: token =>
|
|
77
|
+
isSource(token) &&
|
|
78
|
+
isFromFile(token, [
|
|
79
|
+
'src/tokens/functional/size/size-coarse.json',
|
|
80
|
+
'src/tokens/functional/size/size-fine.json',
|
|
81
|
+
]),
|
|
82
|
+
options: {
|
|
83
|
+
descriptions: false,
|
|
84
|
+
showFileHeader: false,
|
|
85
|
+
mediaQuery: {
|
|
86
|
+
'css/functional/size/size-fine.css': '(pointer: fine)',
|
|
87
|
+
'css/functional/size/size-coarse.css': '(pointer: coarse)',
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type StyleDictionary from 'style-dictionary'
|
|
2
|
+
import type {PlatformInitializer} from '../types/PlatformInitializer'
|
|
3
|
+
import {isDeprecated} from '../filters'
|
|
4
|
+
|
|
5
|
+
export const deprecatedJson: PlatformInitializer = (outputFile, prefix, buildPath): StyleDictionary.Platform => ({
|
|
6
|
+
prefix,
|
|
7
|
+
buildPath,
|
|
8
|
+
transforms: ['name/pathToDotNotation', 'json/deprecated'],
|
|
9
|
+
files: [
|
|
10
|
+
{
|
|
11
|
+
destination: outputFile,
|
|
12
|
+
format: `json/flat`,
|
|
13
|
+
filter: isDeprecated,
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
})
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type StyleDictionary from 'style-dictionary'
|
|
2
|
+
import type {PlatformInitializer} from '../types/PlatformInitializer'
|
|
3
|
+
import {isSource} from '../filters'
|
|
4
|
+
|
|
5
|
+
export const docJson: PlatformInitializer = (outputFile, prefix, buildPath): StyleDictionary.Platform => ({
|
|
6
|
+
prefix,
|
|
7
|
+
buildPath,
|
|
8
|
+
transforms: [
|
|
9
|
+
'name/pathToKebabCase',
|
|
10
|
+
'color/hex',
|
|
11
|
+
'color/hexMix',
|
|
12
|
+
'color/hexAlpha',
|
|
13
|
+
'dimension/rem',
|
|
14
|
+
'shadow/css',
|
|
15
|
+
'border/css',
|
|
16
|
+
'typography/css',
|
|
17
|
+
'fontFamily/css',
|
|
18
|
+
'fontWeight/number',
|
|
19
|
+
],
|
|
20
|
+
options: {
|
|
21
|
+
basePxFontSize: 16,
|
|
22
|
+
},
|
|
23
|
+
files: [
|
|
24
|
+
{
|
|
25
|
+
destination: outputFile,
|
|
26
|
+
format: `json/one-dimensional`,
|
|
27
|
+
filter: isSource,
|
|
28
|
+
options: {
|
|
29
|
+
outputReferences: false,
|
|
30
|
+
outputVerbose: true,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
})
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type StyleDictionary from 'style-dictionary'
|
|
2
|
+
import type {PlatformInitializer} from '../types/PlatformInitializer'
|
|
3
|
+
import {isSource} from '../filters'
|
|
4
|
+
|
|
5
|
+
export const fallbacks: PlatformInitializer = (outputFile, prefix, buildPath): StyleDictionary.Platform => ({
|
|
6
|
+
prefix,
|
|
7
|
+
buildPath,
|
|
8
|
+
transforms: [
|
|
9
|
+
'name/pathToKebabCase',
|
|
10
|
+
'color/hex',
|
|
11
|
+
'color/hexMix',
|
|
12
|
+
'color/hexAlpha',
|
|
13
|
+
'dimension/rem',
|
|
14
|
+
'shadow/css',
|
|
15
|
+
'border/css',
|
|
16
|
+
'typography/css',
|
|
17
|
+
'fontFamily/css',
|
|
18
|
+
'fontWeight/number',
|
|
19
|
+
],
|
|
20
|
+
options: {
|
|
21
|
+
basePxFontSize: 16,
|
|
22
|
+
},
|
|
23
|
+
files: [
|
|
24
|
+
{
|
|
25
|
+
destination: outputFile,
|
|
26
|
+
format: `json/postCss-fallback`,
|
|
27
|
+
filter: isSource,
|
|
28
|
+
options: {
|
|
29
|
+
outputReferences: false,
|
|
30
|
+
outputVerbose: true,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
})
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type StyleDictionary from 'style-dictionary'
|
|
2
|
+
import type {PlatformInitializer} from '../types/PlatformInitializer'
|
|
3
|
+
import {isSource} from '../filters'
|
|
4
|
+
|
|
5
|
+
const validFigmaToken = (token: StyleDictionary.TransformedToken) => {
|
|
6
|
+
const validTypes = ['color', 'dimension', 'shadow', 'fontWeight', 'fontFamily']
|
|
7
|
+
// is a siource token, not an included one
|
|
8
|
+
if (!isSource(token)) return false
|
|
9
|
+
// has a collection attribute
|
|
10
|
+
if (
|
|
11
|
+
!('$extensions' in token) ||
|
|
12
|
+
!('org.primer.figma' in token.$extensions) ||
|
|
13
|
+
!('collection' in token.$extensions['org.primer.figma'])
|
|
14
|
+
)
|
|
15
|
+
return false
|
|
16
|
+
// is a color or dimension type
|
|
17
|
+
return validTypes.includes(token.$type)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const figma: PlatformInitializer = (outputFile, prefix, buildPath, options): StyleDictionary.Platform => ({
|
|
21
|
+
prefix,
|
|
22
|
+
buildPath,
|
|
23
|
+
transforms: [
|
|
24
|
+
'color/rgbaFloat',
|
|
25
|
+
'name/pathToFigma',
|
|
26
|
+
// 'name/pathToSlashNotation',
|
|
27
|
+
'figma/attributes',
|
|
28
|
+
'dimension/pixelUnitless',
|
|
29
|
+
// 'border/figma',
|
|
30
|
+
// 'typography/figma',
|
|
31
|
+
'fontWeight/number',
|
|
32
|
+
],
|
|
33
|
+
options: {
|
|
34
|
+
basePxFontSize: 16,
|
|
35
|
+
...options,
|
|
36
|
+
},
|
|
37
|
+
files: [
|
|
38
|
+
{
|
|
39
|
+
destination: outputFile,
|
|
40
|
+
filter: validFigmaToken,
|
|
41
|
+
format: `json/figma`,
|
|
42
|
+
options: {
|
|
43
|
+
outputReferences: true,
|
|
44
|
+
mode: options?.mode,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
})
|