@primer/primitives 9.0.3 → 9.1.0-rc.56a8ee48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build/PrimerStyleDictionary.d.ts +9 -0
- package/dist/build/PrimerStyleDictionary.js +93 -0
- package/dist/build/filters/index.d.ts +13 -0
- package/dist/build/filters/index.js +29 -0
- package/{src/filters/isBorder.ts → dist/build/filters/isBorder.d.ts} +2 -5
- package/dist/build/filters/isBorder.js +12 -0
- package/{src/filters/isColor.ts → dist/build/filters/isColor.d.ts} +2 -5
- package/dist/build/filters/isColor.js +12 -0
- package/dist/build/filters/isColorWithAlpha.d.ts +7 -0
- package/dist/build/filters/isColorWithAlpha.js +13 -0
- package/dist/build/filters/isColorWithMix.d.ts +7 -0
- package/dist/build/filters/isColorWithMix.js +28 -0
- package/{src/filters/isDeprecated.ts → dist/build/filters/isDeprecated.d.ts} +2 -5
- package/dist/build/filters/isDeprecated.js +12 -0
- package/{src/filters/isDimension.ts → dist/build/filters/isDimension.d.ts} +2 -5
- package/dist/build/filters/isDimension.js +12 -0
- package/{src/filters/isDuration.ts → dist/build/filters/isDuration.d.ts} +2 -5
- package/dist/build/filters/isDuration.js +12 -0
- package/{src/filters/isFontFamily.ts → dist/build/filters/isFontFamily.d.ts} +2 -5
- package/dist/build/filters/isFontFamily.js +12 -0
- package/{src/filters/isFontWeight.ts → dist/build/filters/isFontWeight.d.ts} +2 -5
- package/dist/build/filters/isFontWeight.js +12 -0
- package/dist/build/filters/isFromFile.d.ts +8 -0
- package/dist/build/filters/isFromFile.js +14 -0
- package/{src/filters/isNumber.ts → dist/build/filters/isNumber.d.ts} +2 -3
- package/dist/build/filters/isNumber.js +10 -0
- package/{src/filters/isShadow.ts → dist/build/filters/isShadow.d.ts} +2 -5
- package/dist/build/filters/isShadow.js +12 -0
- package/{src/filters/isSource.ts → dist/build/filters/isSource.d.ts} +2 -5
- package/dist/build/filters/isSource.js +12 -0
- package/{src/filters/isTypography.ts → dist/build/filters/isTypography.d.ts} +2 -5
- package/dist/build/filters/isTypography.js +12 -0
- package/dist/build/formats/cssAdvanced.d.ts +2 -0
- package/dist/build/formats/cssAdvanced.js +84 -0
- package/dist/build/formats/cssCustomMedia.d.ts +7 -0
- package/dist/build/formats/cssCustomMedia.js +25 -0
- package/dist/build/formats/index.d.ts +9 -0
- package/dist/build/formats/index.js +21 -0
- package/dist/build/formats/javascriptCommonJs.d.ts +7 -0
- package/dist/build/formats/javascriptCommonJs.js +25 -0
- package/dist/build/formats/javascriptEsm.d.ts +7 -0
- package/dist/build/formats/javascriptEsm.js +25 -0
- package/dist/build/formats/jsonFigma.d.ts +7 -0
- package/dist/build/formats/jsonFigma.js +116 -0
- package/dist/build/formats/jsonNestedPrefixed.d.ts +8 -0
- package/dist/build/formats/jsonNestedPrefixed.js +28 -0
- package/dist/build/formats/jsonOneDimensional.d.ts +8 -0
- package/dist/build/formats/jsonOneDimensional.js +24 -0
- package/dist/build/formats/jsonPostCssFallback.d.ts +8 -0
- package/dist/build/formats/jsonPostCssFallback.js +21 -0
- package/dist/build/formats/typescriptExportDefinition.d.ts +7 -0
- package/dist/build/formats/typescriptExportDefinition.js +166 -0
- package/{src/formats/utilities/jsonToFlat.ts → dist/build/formats/utilities/jsonToFlat.d.ts} +4 -3
- package/dist/build/formats/utilities/jsonToFlat.js +12 -0
- package/dist/build/formats/utilities/jsonToNestedValue.d.ts +8 -0
- package/dist/build/formats/utilities/jsonToNestedValue.js +25 -0
- package/dist/build/formats/utilities/prefixTokens.d.ts +8 -0
- package/dist/build/formats/utilities/prefixTokens.js +17 -0
- package/dist/build/parsers/index.d.ts +1 -0
- package/dist/build/parsers/index.js +5 -0
- package/dist/build/parsers/w3cJsonParser.d.ts +6 -0
- package/dist/build/parsers/w3cJsonParser.js +27 -0
- package/dist/build/platforms/css.d.ts +2 -0
- package/dist/build/platforms/css.js +88 -0
- package/dist/build/platforms/deprecatedJson.d.ts +2 -0
- package/dist/build/platforms/deprecatedJson.js +17 -0
- package/dist/build/platforms/docJson.d.ts +2 -0
- package/dist/build/platforms/docJson.js +35 -0
- package/dist/build/platforms/fallbacks.d.ts +2 -0
- package/dist/build/platforms/fallbacks.js +35 -0
- package/dist/build/platforms/figma.d.ts +2 -0
- package/dist/build/platforms/figma.js +53 -0
- package/dist/build/platforms/index.d.ts +10 -0
- package/dist/build/platforms/index.js +23 -0
- package/dist/build/platforms/javascript.d.ts +2 -0
- package/dist/build/platforms/javascript.js +31 -0
- package/dist/build/platforms/json.d.ts +2 -0
- package/dist/build/platforms/json.js +33 -0
- package/dist/build/platforms/styleLint.d.ts +2 -0
- package/dist/build/platforms/styleLint.js +35 -0
- package/dist/build/platforms/typeDefinitions.d.ts +2 -0
- package/dist/build/platforms/typeDefinitions.js +31 -0
- package/dist/build/platforms/typescript.d.ts +2 -0
- package/dist/build/platforms/typescript.js +31 -0
- package/dist/build/schemas/alphaValue.d.ts +2 -0
- package/dist/build/schemas/alphaValue.js +8 -0
- package/dist/build/schemas/baseToken.d.ts +11 -0
- package/dist/build/schemas/baseToken.js +10 -0
- package/dist/build/schemas/borderToken.d.ts +51 -0
- package/dist/build/schemas/borderToken.js +20 -0
- package/dist/build/schemas/collections.d.ts +6 -0
- package/dist/build/schemas/collections.js +18 -0
- package/dist/build/schemas/colorHexValue.d.ts +2 -0
- package/dist/build/schemas/colorHexValue.js +12 -0
- package/dist/build/schemas/colorToken.d.ts +80 -0
- package/dist/build/schemas/colorToken.js +52 -0
- package/dist/build/schemas/designToken.d.ts +2 -0
- package/dist/build/schemas/designToken.js +37 -0
- package/dist/build/schemas/dimensionToken.d.ts +52 -0
- package/dist/build/schemas/dimensionToken.js +36 -0
- package/dist/build/schemas/dimensionValue.d.ts +2 -0
- package/dist/build/schemas/dimensionValue.js +12 -0
- package/dist/build/schemas/durationToken.d.ts +18 -0
- package/dist/build/schemas/durationToken.js +14 -0
- package/dist/build/schemas/durationValue.d.ts +2 -0
- package/dist/build/schemas/durationValue.js +8 -0
- package/dist/build/schemas/fontFamilyToken.d.ts +52 -0
- package/dist/build/schemas/fontFamilyToken.js +23 -0
- package/dist/build/schemas/fontWeightToken.d.ts +52 -0
- package/dist/build/schemas/fontWeightToken.js +24 -0
- package/dist/build/schemas/fontWeightValue.d.ts +2 -0
- package/dist/build/schemas/fontWeightValue.js +9 -0
- package/dist/build/schemas/numberToken.d.ts +71 -0
- package/dist/build/schemas/numberToken.js +30 -0
- package/dist/build/schemas/referenceValue.d.ts +2 -0
- package/dist/build/schemas/referenceValue.js +8 -0
- package/dist/build/schemas/scopes.d.ts +5 -0
- package/dist/build/schemas/scopes.js +34 -0
- package/dist/build/schemas/shadowToken.d.ts +157 -0
- package/dist/build/schemas/shadowToken.js +46 -0
- package/dist/build/schemas/stringToken.d.ts +18 -0
- package/dist/build/schemas/stringToken.js +13 -0
- package/dist/build/schemas/tokenName.d.ts +2 -0
- package/dist/build/schemas/tokenName.js +8 -0
- package/dist/build/schemas/tokenType.d.ts +3 -0
- package/dist/build/schemas/tokenType.js +6 -0
- package/dist/build/schemas/typographyToken.d.ts +59 -0
- package/dist/build/schemas/typographyToken.js +21 -0
- package/dist/build/schemas/validTokenType.d.ts +5 -0
- package/dist/build/schemas/validTokenType.js +34 -0
- package/dist/build/schemas/viewportRangeToken.d.ts +18 -0
- package/dist/build/schemas/viewportRangeToken.js +13 -0
- package/dist/build/transformers/borderToCss.d.ts +8 -0
- package/dist/build/transformers/borderToCss.js +38 -0
- package/dist/build/transformers/colorToHex.d.ts +8 -0
- package/dist/build/transformers/colorToHex.js +18 -0
- package/dist/build/transformers/colorToHexAlpha.d.ts +8 -0
- package/dist/build/transformers/colorToHexAlpha.js +25 -0
- package/dist/build/transformers/colorToHexMix.d.ts +8 -0
- package/dist/build/transformers/colorToHexMix.js +25 -0
- package/dist/build/transformers/colorToRgbAlpha.d.ts +8 -0
- package/dist/build/transformers/colorToRgbAlpha.js +22 -0
- package/dist/build/transformers/colorToRgbaFloat.d.ts +8 -0
- package/dist/build/transformers/colorToRgbaFloat.js +50 -0
- package/dist/build/transformers/dimensionToPixelUnitless.d.ts +8 -0
- package/dist/build/transformers/dimensionToPixelUnitless.js +50 -0
- package/dist/build/transformers/dimensionToRem.d.ts +8 -0
- package/dist/build/transformers/dimensionToRem.js +47 -0
- package/dist/build/transformers/dimensionToRemPxArray.d.ts +8 -0
- package/dist/build/transformers/dimensionToRemPxArray.js +47 -0
- package/dist/build/transformers/durationToCss.d.ts +8 -0
- package/dist/build/transformers/durationToCss.js +30 -0
- package/dist/build/transformers/figmaAttributes.d.ts +8 -0
- package/dist/build/transformers/figmaAttributes.js +57 -0
- package/dist/build/transformers/floatToPixel.d.ts +15 -0
- package/dist/build/transformers/floatToPixel.js +41 -0
- package/dist/build/transformers/fontFamilyToCss.d.ts +14 -0
- package/dist/build/transformers/fontFamilyToCss.js +40 -0
- package/dist/build/transformers/fontFamilyToFigma.d.ts +14 -0
- package/dist/build/transformers/fontFamilyToFigma.js +46 -0
- package/dist/build/transformers/fontWeightToNumber.d.ts +9 -0
- package/dist/build/transformers/fontWeightToNumber.js +53 -0
- package/dist/build/transformers/index.d.ts +25 -0
- package/dist/build/transformers/index.js +53 -0
- package/dist/build/transformers/jsonDeprecated.d.ts +8 -0
- package/dist/build/transformers/jsonDeprecated.js +16 -0
- package/{src/transformers/namePathToCamelCase.ts → dist/build/transformers/namePathToCamelCase.d.ts} +2 -8
- package/dist/build/transformers/namePathToCamelCase.js +14 -0
- package/dist/build/transformers/namePathToDotNotation.d.ts +8 -0
- package/dist/build/transformers/namePathToDotNotation.js +33 -0
- package/dist/build/transformers/namePathToFigma.d.ts +9 -0
- package/dist/build/transformers/namePathToFigma.js +24 -0
- package/dist/build/transformers/namePathToKebabCase.d.ts +8 -0
- package/dist/build/transformers/namePathToKebabCase.js +18 -0
- package/dist/build/transformers/namePathToPascalCase.d.ts +8 -0
- package/dist/build/transformers/namePathToPascalCase.js +14 -0
- package/dist/build/transformers/namePathToSlashNotation.d.ts +8 -0
- package/dist/build/transformers/namePathToSlashNotation.js +18 -0
- package/dist/build/transformers/shadowToCss.d.ts +8 -0
- package/dist/build/transformers/shadowToCss.js +35 -0
- package/dist/build/transformers/typographyToCss.d.ts +8 -0
- package/dist/build/transformers/typographyToCss.js +29 -0
- package/dist/build/transformers/utilities/alpha.d.ts +9 -0
- package/dist/build/transformers/utilities/alpha.js +20 -0
- package/dist/build/transformers/utilities/checkRequiredTokenProperties.d.ts +7 -0
- package/dist/build/transformers/utilities/checkRequiredTokenProperties.js +17 -0
- package/dist/build/transformers/utilities/getTokenValue.d.ts +2 -0
- package/dist/build/transformers/utilities/getTokenValue.js +18 -0
- package/dist/build/transformers/utilities/hasSpaceInString.d.ts +1 -0
- package/dist/build/transformers/utilities/hasSpaceInString.js +10 -0
- package/dist/build/transformers/utilities/hexToRgbaFloat.d.ts +2 -0
- package/dist/build/transformers/utilities/hexToRgbaFloat.js +33 -0
- package/dist/build/transformers/utilities/invalidTokenError.d.ts +7 -0
- package/dist/build/transformers/utilities/invalidTokenError.js +26 -0
- package/dist/build/transformers/utilities/isRgbaFloat.d.ts +7 -0
- package/dist/build/transformers/utilities/isRgbaFloat.js +24 -0
- package/dist/build/transformers/utilities/mix.d.ts +5 -0
- package/dist/build/transformers/utilities/mix.js +40 -0
- package/dist/build/transformers/utilities/rgbaFloatToHex.d.ts +6 -0
- package/dist/build/transformers/utilities/rgbaFloatToHex.js +15 -0
- package/dist/build/utilities/copyFromDir.d.ts +8 -0
- package/dist/build/utilities/copyFromDir.js +34 -0
- package/dist/build/utilities/filterStringArray.d.ts +1 -0
- package/dist/build/utilities/filterStringArray.js +17 -0
- package/{src/utilities/getFlag.ts → dist/build/utilities/getFlag.d.ts} +1 -5
- package/dist/build/utilities/getFlag.js +16 -0
- package/dist/build/utilities/index.d.ts +3 -0
- package/dist/build/utilities/index.js +9 -0
- package/dist/build/utilities/joinFriendly.d.ts +1 -0
- package/dist/build/utilities/joinFriendly.js +5 -0
- package/dist/build/utilities/schemaErrorMessage.d.ts +1 -0
- package/dist/build/utilities/schemaErrorMessage.js +5 -0
- package/dist/build/utilities/toCamelCase.d.ts +1 -0
- package/dist/build/utilities/toCamelCase.js +20 -0
- package/dist/build/utilities/toPascalCase.d.ts +1 -0
- package/dist/build/utilities/toPascalCase.js +17 -0
- package/dist/build/utilities/treeWalker.d.ts +8 -0
- package/dist/build/utilities/treeWalker.js +27 -0
- package/{src/utilities/upperCaseFirstCharacter.ts → dist/build/utilities/upperCaseFirstCharacter.d.ts} +1 -3
- package/dist/build/utilities/upperCaseFirstCharacter.js +14 -0
- package/dist/css/functional/motion/motion.css +3 -3
- package/dist/css/functional/size/border.css +2 -2
- package/dist/css/functional/typography/typography.css +11 -11
- package/dist/css/primitives.css +16 -16
- package/package.json +6 -8
- package/src/PrimerStyleDictionary.ts +0 -232
- package/src/filters/index.ts +0 -13
- package/src/filters/isColorWithAlpha.ts +0 -11
- package/src/filters/isColorWithMix.ts +0 -33
- package/src/filters/isFromFile.ts +0 -12
- package/src/formats/cssAdvanced.ts +0 -99
- package/src/formats/cssCustomMedia.ts +0 -24
- package/src/formats/index.ts +0 -9
- package/src/formats/javascriptCommonJs.ts +0 -21
- package/src/formats/javascriptEsm.ts +0 -21
- package/src/formats/jsonFigma.ts +0 -134
- package/src/formats/jsonNestedPrefixed.ts +0 -23
- package/src/formats/jsonOneDimensional.ts +0 -18
- package/src/formats/jsonPostCssFallback.ts +0 -16
- package/src/formats/typescriptExportDefinition.ts +0 -170
- package/src/formats/utilities/jsonToNestedValue.ts +0 -20
- package/src/formats/utilities/prefixTokens.ts +0 -17
- package/src/parsers/index.ts +0 -1
- package/src/parsers/w3cJsonParser.ts +0 -25
- package/src/platforms/css.ts +0 -101
- package/src/platforms/deprecatedJson.ts +0 -16
- package/src/platforms/docJson.ts +0 -34
- package/src/platforms/fallbacks.ts +0 -34
- package/src/platforms/figma.ts +0 -58
- package/src/platforms/index.ts +0 -10
- package/src/platforms/javascript.ts +0 -30
- package/src/platforms/json.ts +0 -32
- package/src/platforms/styleLint.ts +0 -34
- package/src/platforms/typeDefinitions.ts +0 -30
- package/src/platforms/typescript.ts +0 -30
- package/src/schemas/alphaValue.ts +0 -12
- package/src/schemas/baseToken.ts +0 -8
- package/src/schemas/borderToken.ts +0 -19
- package/src/schemas/collections.ts +0 -49
- package/src/schemas/colorHexValue.ts +0 -18
- package/src/schemas/colorToken.ts +0 -50
- package/src/schemas/designToken.ts +0 -38
- package/src/schemas/dimensionToken.ts +0 -34
- package/src/schemas/dimensionValue.ts +0 -16
- package/src/schemas/durationToken.ts +0 -12
- package/src/schemas/durationValue.ts +0 -9
- package/src/schemas/fontFamilyToken.ts +0 -21
- package/src/schemas/fontWeightToken.ts +0 -22
- package/src/schemas/fontWeightValue.ts +0 -14
- package/src/schemas/numberToken.ts +0 -28
- package/src/schemas/referenceValue.ts +0 -12
- package/src/schemas/scopes.ts +0 -40
- package/src/schemas/shadowToken.ts +0 -45
- package/src/schemas/stringToken.ts +0 -11
- package/src/schemas/tokenName.ts +0 -12
- package/src/schemas/tokenType.ts +0 -4
- package/src/schemas/typographyToken.ts +0 -20
- package/src/schemas/validTokenType.ts +0 -44
- package/src/schemas/viewportRangeToken.ts +0 -11
- package/src/test-utilities/getMockDictionary.ts +0 -22
- package/src/test-utilities/getMockFormatterArguments.ts +0 -21
- package/src/test-utilities/getMockParserInput.ts +0 -72
- package/src/test-utilities/getMockToken.ts +0 -25
- package/src/test-utilities/index.ts +0 -4
- package/src/transformers/borderToCss.ts +0 -38
- package/src/transformers/colorToHex.ts +0 -16
- package/src/transformers/colorToHexAlpha.ts +0 -23
- package/src/transformers/colorToHexMix.ts +0 -19
- package/src/transformers/colorToRgbAlpha.ts +0 -19
- package/src/transformers/colorToRgbaFloat.ts +0 -45
- package/src/transformers/dimensionToPixelUnitless.ts +0 -60
- package/src/transformers/dimensionToRem.ts +0 -56
- package/src/transformers/dimensionToRemPxArray.ts +0 -60
- package/src/transformers/durationToCss.ts +0 -29
- package/src/transformers/figmaAttributes.ts +0 -79
- package/src/transformers/floatToPixel.ts +0 -40
- package/src/transformers/fontFamilyToCss.ts +0 -37
- package/src/transformers/fontFamilyToFigma.ts +0 -47
- package/src/transformers/fontWeightToNumber.ts +0 -53
- package/src/transformers/index.ts +0 -24
- package/src/transformers/jsonDeprecated.ts +0 -15
- package/src/transformers/namePathToDotNotation.ts +0 -34
- package/src/transformers/namePathToFigma.ts +0 -28
- package/src/transformers/namePathToKebabCase.ts +0 -19
- package/src/transformers/namePathToSlashNotation.ts +0 -19
- package/src/transformers/shadowToCss.ts +0 -37
- package/src/transformers/typographyToCss.ts +0 -31
- package/src/transformers/utilities/alpha.ts +0 -23
- package/src/transformers/utilities/checkRequiredTokenProperties.ts +0 -16
- package/src/transformers/utilities/getTokenValue.ts +0 -18
- package/src/transformers/utilities/hasSpaceInString.ts +0 -6
- package/src/transformers/utilities/hexToRgbaFloat.ts +0 -31
- package/src/transformers/utilities/invalidTokenError.ts +0 -34
- package/src/transformers/utilities/isRgbaFloat.ts +0 -29
- package/src/transformers/utilities/mix.ts +0 -46
- package/src/transformers/utilities/rgbaFloatToHex.ts +0 -15
- package/src/types/Border.d.ts +0 -5
- package/src/types/BorderTokenValue.d.ts +0 -10
- package/src/types/ColorHex.d.ts +0 -4
- package/src/types/PlatformInitializer.d.ts +0 -11
- package/src/types/Shadow.d.ts +0 -5
- package/src/types/ShadowTokenValue.d.ts +0 -14
- package/src/types/SizeEm.d.ts +0 -4
- package/src/types/SizePx.d.ts +0 -4
- package/src/types/SizeRem.d.ts +0 -4
- package/src/types/StyleDictionaryConfigGenerator.d.ts +0 -15
- package/src/types/TokenBuildInput.d.ts +0 -8
- package/src/types/TypographyTokenValue.d.ts +0 -12
- package/src/types/w3cTransformedToken.d.ts +0 -8
- package/src/utilities/copyFromDir.ts +0 -21
- package/src/utilities/index.ts +0 -3
- package/src/utilities/joinFriendly.ts +0 -2
- package/src/utilities/schemaErrorMessage.ts +0 -2
- package/src/utilities/toCamelCase.ts +0 -29
- package/src/utilities/treeWalker.ts +0 -27
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import {toHex} from 'color2k'
|
|
2
|
-
import {isShadow} from '../filters'
|
|
3
|
-
import {alpha} from './utilities/alpha'
|
|
4
|
-
import {checkRequiredTokenProperties} from './utilities/checkRequiredTokenProperties'
|
|
5
|
-
import type {ShadowTokenValue} from '../types/ShadowTokenValue'
|
|
6
|
-
import type StyleDictionary from 'style-dictionary'
|
|
7
|
-
import {getTokenValue} from './utilities/getTokenValue'
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @description converts w3c shadow tokens in css shadow string
|
|
11
|
-
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
12
|
-
* @matcher matches all tokens of $type `shadow`
|
|
13
|
-
* @transformer returns css shadow `string`
|
|
14
|
-
*/
|
|
15
|
-
export const shadowToCss: StyleDictionary.Transform = {
|
|
16
|
-
type: `value`,
|
|
17
|
-
transitive: true,
|
|
18
|
-
matcher: isShadow,
|
|
19
|
-
transformer: (token: StyleDictionary.TransformedToken) => {
|
|
20
|
-
// extract value
|
|
21
|
-
const {value}: {value: ShadowTokenValue | ShadowTokenValue[]} = token
|
|
22
|
-
// turn value into array
|
|
23
|
-
const shadowValues = !Array.isArray(value) ? [value] : value
|
|
24
|
-
|
|
25
|
-
return shadowValues
|
|
26
|
-
.map((shadow: ShadowTokenValue) => {
|
|
27
|
-
// if value === string it was probably already transformed
|
|
28
|
-
if (typeof shadow === 'string') return shadow
|
|
29
|
-
checkRequiredTokenProperties(shadow, ['color', 'offsetX', 'offsetY', 'blur', 'spread'])
|
|
30
|
-
/*css box shadow: inset? | offset-x | offset-y | blur-radius | spread-radius | color */
|
|
31
|
-
return `${shadow.inset === true ? 'inset ' : ''}${shadow.offsetX} ${shadow.offsetY} ${shadow.blur} ${
|
|
32
|
-
shadow.spread
|
|
33
|
-
} ${toHex(alpha(getTokenValue({...token, ...{value: shadow}}, 'color'), shadow.alpha || 1, token))}`
|
|
34
|
-
})
|
|
35
|
-
.join(', ')
|
|
36
|
-
},
|
|
37
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type StyleDictionary from 'style-dictionary'
|
|
2
|
-
import {isTypography} from '../filters'
|
|
3
|
-
import type {TypographyTokenValue} from '../types/TypographyTokenValue'
|
|
4
|
-
import {checkRequiredTokenProperties} from './utilities/checkRequiredTokenProperties'
|
|
5
|
-
import {parseFontFamily} from './fontFamilyToCss'
|
|
6
|
-
import {parseFontWeight} from './fontWeightToNumber'
|
|
7
|
-
import {getTokenValue} from './utilities/getTokenValue'
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @description converts typograhy token value to css font shorthand
|
|
11
|
-
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
12
|
-
* @matcher matches all tokens of $type `typography`
|
|
13
|
-
* @transformer returns a css font string
|
|
14
|
-
*/
|
|
15
|
-
export const typographyToCss: StyleDictionary.Transform = {
|
|
16
|
-
type: `value`,
|
|
17
|
-
transitive: true,
|
|
18
|
-
matcher: isTypography,
|
|
19
|
-
transformer: (token: StyleDictionary.TransformedToken) => {
|
|
20
|
-
// extract value
|
|
21
|
-
const value: TypographyTokenValue = getTokenValue(token)
|
|
22
|
-
// validate token properties
|
|
23
|
-
checkRequiredTokenProperties(value, ['fontWeight', 'fontSize', 'fontFamily'])
|
|
24
|
-
// format output
|
|
25
|
-
return `${value.fontStyle || ''} ${parseFontWeight(getTokenValue(token, 'fontWeight'))} ${value.fontSize}${
|
|
26
|
-
value.lineHeight ? `/${value.lineHeight}` : ''
|
|
27
|
-
} ${parseFontFamily(getTokenValue(token, 'fontFamily'))}`
|
|
28
|
-
.trim()
|
|
29
|
-
.replace(/\s\s+/g, ' ')
|
|
30
|
-
},
|
|
31
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import {rgba, parseToRgba} from 'color2k'
|
|
2
|
-
import type {TransformedToken} from 'style-dictionary'
|
|
3
|
-
/**
|
|
4
|
-
* alpha
|
|
5
|
-
* @description takes a colors string like hex or rgba and returns an rgba color with the specified alpha value
|
|
6
|
-
* @param color color string like a `#334455` or `rgb(255,200,100)`
|
|
7
|
-
* @param desiredAlpha number
|
|
8
|
-
* @returns rgba value
|
|
9
|
-
*/
|
|
10
|
-
export const alpha = (color: string, desiredAlpha: number, token?: TransformedToken): string => {
|
|
11
|
-
const [r, g, b, a] = parseToRgba(color)
|
|
12
|
-
|
|
13
|
-
if (a < 1 && desiredAlpha < 1) {
|
|
14
|
-
// eslint-disable-next-line no-console
|
|
15
|
-
console.warn(
|
|
16
|
-
`🚨 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.${
|
|
17
|
-
token !== undefined ? `\n ↳ Token: "${token.name}" in file: "${token.filePath}"` : ''
|
|
18
|
-
}`,
|
|
19
|
-
)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return rgba(r, g, b, desiredAlpha)
|
|
23
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
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 = (
|
|
8
|
-
tokenValue: Record<string, unknown>,
|
|
9
|
-
requiredProperties: readonly string[],
|
|
10
|
-
) => {
|
|
11
|
-
for (const prop of requiredProperties) {
|
|
12
|
-
if (prop in tokenValue === false) {
|
|
13
|
-
throw new Error(`Missing property: ${prop} on token with value ${JSON.stringify(tokenValue)}`)
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type StyleDictionary from 'style-dictionary'
|
|
2
|
-
import {invalidTokenValueError, invalidTokenValuePropertyError} from './invalidTokenError'
|
|
3
|
-
|
|
4
|
-
export const getTokenValue = (token: StyleDictionary.TransformedToken, property?: string) => {
|
|
5
|
-
if (token.value === undefined) {
|
|
6
|
-
throw new invalidTokenValueError(token)
|
|
7
|
-
}
|
|
8
|
-
// for composite token if subproperty is needed
|
|
9
|
-
if (typeof property === 'string' && token.value[property] === undefined) {
|
|
10
|
-
throw new invalidTokenValuePropertyError(token, property)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
if (typeof property === 'string') {
|
|
14
|
-
return token.value[property]
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return token.value
|
|
18
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type {RgbaFloat} from './isRgbaFloat'
|
|
2
|
-
|
|
3
|
-
export const hexToRgbaFloat = (hex: string, alpha?: number): RgbaFloat => {
|
|
4
|
-
// retrieve spots from hex value (hex 3, hex 4, hex 6 or hex 8)
|
|
5
|
-
let result
|
|
6
|
-
if (hex.length > 5) {
|
|
7
|
-
result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i.exec(hex)
|
|
8
|
-
} else {
|
|
9
|
-
result = /^#?([a-f\d]{1})([a-f\d]{1})([a-f\d]{1})([a-f\d]{1})?$/i.exec(hex)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (result === null) {
|
|
13
|
-
throw new Error('Invalid hex value in "hexToRgbaFloat". Please provide a valid hex3, hex4, hex6 or hex8 value.')
|
|
14
|
-
}
|
|
15
|
-
// doule characters if hex 3 or hex 4
|
|
16
|
-
if (hex.length < 6) {
|
|
17
|
-
result[1] = `${result[1]}${result[1]}` // double the character
|
|
18
|
-
result[2] = `${result[2]}${result[2]}` // double the character
|
|
19
|
-
result[3] = `${result[3]}${result[3]}` // double the character
|
|
20
|
-
if (result[4]) {
|
|
21
|
-
result[4] = `${result[4]}${result[4]}` // double the character
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
// return parsed rgba float object using alpha value from token, from hex code or defaults to 1
|
|
25
|
-
return {
|
|
26
|
-
r: parseInt(result[1], 16) / 255,
|
|
27
|
-
g: parseInt(result[2], 16) / 255,
|
|
28
|
-
b: parseInt(result[3], 16) / 255,
|
|
29
|
-
a: alpha !== undefined ? alpha : result[4] ? parseInt(result[4], 16) / 255 : 1,
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type {TransformedToken} from 'style-dictionary'
|
|
2
|
-
import {namePathToDotNotation} from '../namePathToDotNotation'
|
|
3
|
-
|
|
4
|
-
const composeValueErrorMessage = (token: TransformedToken) => {
|
|
5
|
-
// eslint-disable-next-line i18n-text/no-en
|
|
6
|
-
return `Invalid token "${namePathToDotNotation.transformer(token, {})}" in file "${
|
|
7
|
-
token.filePath
|
|
8
|
-
}". Transformed value: "${JSON.stringify(token.value)}". ${
|
|
9
|
-
token.original.value ? `Original value: "${JSON.stringify(token.original.value)}" ` : ''
|
|
10
|
-
}This may be due to referencing a token that does not exists.`
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const composeValuePropertyErrorMessage = (token: TransformedToken, property: string) => {
|
|
14
|
-
// eslint-disable-next-line i18n-text/no-en
|
|
15
|
-
return `Invalid property "${property}" of token "${namePathToDotNotation.transformer(token, {})}" in file "${
|
|
16
|
-
token.filePath
|
|
17
|
-
}". Transformed property value: "${token.value[property]}". ${
|
|
18
|
-
token.original.value ? `Original value: "${token.original.value[property]}" ` : ''
|
|
19
|
-
}This may be due to referencing a token that does not exists.`
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class invalidTokenValueError extends Error {
|
|
23
|
-
constructor(token: TransformedToken) {
|
|
24
|
-
super(composeValueErrorMessage(token))
|
|
25
|
-
Error.captureStackTrace(this, invalidTokenValueError)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export class invalidTokenValuePropertyError extends Error {
|
|
30
|
-
constructor(token: TransformedToken, property: string) {
|
|
31
|
-
super(composeValuePropertyErrorMessage(token, property))
|
|
32
|
-
Error.captureStackTrace(this, invalidTokenValuePropertyError)
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export type RgbaFloat = {
|
|
2
|
-
r: number
|
|
3
|
-
g: number
|
|
4
|
-
b: number
|
|
5
|
-
a?: number
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
// check if a value is an rgba float object
|
|
9
|
-
export const isRgbaFloat = (value: unknown): value is RgbaFloat => {
|
|
10
|
-
if (
|
|
11
|
-
value &&
|
|
12
|
-
typeof value === `object` &&
|
|
13
|
-
'r' in value &&
|
|
14
|
-
typeof value.r === `number` &&
|
|
15
|
-
'g' in value &&
|
|
16
|
-
typeof value.g === `number` &&
|
|
17
|
-
'b' in value &&
|
|
18
|
-
typeof value.b === `number` &&
|
|
19
|
-
value.r >= 0 &&
|
|
20
|
-
value.r <= 1 &&
|
|
21
|
-
value.g >= 0 &&
|
|
22
|
-
value.g <= 1 &&
|
|
23
|
-
value.b >= 0 &&
|
|
24
|
-
value.b <= 1
|
|
25
|
-
) {
|
|
26
|
-
return true
|
|
27
|
-
}
|
|
28
|
-
return false
|
|
29
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import {rgba, parseToRgba} from 'color2k'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Mixes two colors together. Taken from sass's implementation.
|
|
5
|
-
*/
|
|
6
|
-
function mix(color1: string, color2: string, weight: number): string {
|
|
7
|
-
const normalize = (n: number, index: number) =>
|
|
8
|
-
// 3rd index is alpha channel which is already normalized
|
|
9
|
-
index === 3 ? n : n / 255
|
|
10
|
-
|
|
11
|
-
const [r1, g1, b1, a1] = parseToRgba(color1).map(normalize)
|
|
12
|
-
const [r2, g2, b2, a2] = parseToRgba(color2).map(normalize)
|
|
13
|
-
|
|
14
|
-
// The formula is copied from the original Sass implementation:
|
|
15
|
-
// http://sass-lang.com/documentation/Sass/Script/Functions.html#mix-instance_method
|
|
16
|
-
const normalizedWeight = 2 * weight - 1
|
|
17
|
-
const alphaDelta = a1 - a2
|
|
18
|
-
|
|
19
|
-
const combinedWeight =
|
|
20
|
-
normalizedWeight * alphaDelta === -1
|
|
21
|
-
? normalizedWeight
|
|
22
|
-
: (normalizedWeight + alphaDelta) / (1 + normalizedWeight * alphaDelta)
|
|
23
|
-
|
|
24
|
-
const weight2 = (combinedWeight + 1) / 2
|
|
25
|
-
const weight1 = 1 - weight2
|
|
26
|
-
const r = Math.round((r1 * weight1 + r2 * weight2) * 255)
|
|
27
|
-
const g = Math.round((g1 * weight1 + g2 * weight2) * 255)
|
|
28
|
-
const b = Math.round((b1 * weight1 + b2 * weight2) * 255)
|
|
29
|
-
const a = a2 * weight + a1 * (1 - weight)
|
|
30
|
-
return rgba(r, g, b, a)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export default mix
|
|
34
|
-
// Number* weight = ARGR("$weight", Number, 0, 100);
|
|
35
|
-
// double p = weight->value()/100;
|
|
36
|
-
// double w = 2*p - 1;
|
|
37
|
-
// double a = color1->a() - color2->a();
|
|
38
|
-
// double nW = ((w * a == -1) ? w : (w + a)/(1 + w*a))
|
|
39
|
-
// double w1 = (nW + 1)/2.0;
|
|
40
|
-
// double w2 = 1 - w1;
|
|
41
|
-
|
|
42
|
-
// return new (ctx.mem) Color(pstate,
|
|
43
|
-
// std::round(w1*color1->r() + w2*color2->r()),
|
|
44
|
-
// std::round(w1*color1->g() + w2*color2->g()),
|
|
45
|
-
// std::round(w1*color1->b() + w2*color2->b()),
|
|
46
|
-
// color1->a()*p + color2->a()*(1-p));
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export const rgbaFloatToHex = ({r, g, b, a}: {r: number; g: number; b: number; a?: number}, alpha = true): string => {
|
|
2
|
-
const values = [r, g, b, alpha === true && a && a < 1 ? a : undefined].filter(item => item !== undefined) as number[]
|
|
3
|
-
|
|
4
|
-
if (r > 1 || r < 0 || g > 1 || g < 0 || b > 1 || b < 0) {
|
|
5
|
-
throw new Error('Invalid RgbaFloat value. R, G and B values must be between 0 and 1.')
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return `#${values
|
|
9
|
-
.map(v =>
|
|
10
|
-
Number(parseInt(`${v * 255}`, 10))
|
|
11
|
-
.toString(16)
|
|
12
|
-
.padStart(2, '0'),
|
|
13
|
-
)
|
|
14
|
-
.join('')}`
|
|
15
|
-
}
|
package/src/types/Border.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type definition for w3c border composite token value
|
|
3
|
-
* @link https://design-tokens.github.io/community-group/format/#border
|
|
4
|
-
*/
|
|
5
|
-
export type StrokeStyleString = 'solid' | 'dashed' | 'dotted' | 'double' | 'groove' | 'ridge' | 'outset' | 'inset'
|
|
6
|
-
export type BorderTokenValue = {
|
|
7
|
-
color: string
|
|
8
|
-
width: string
|
|
9
|
-
style: StrokeStyleString
|
|
10
|
-
}
|
package/src/types/ColorHex.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type StyleDictionary from 'style-dictionary'
|
|
2
|
-
|
|
3
|
-
export type PlatformInitializer = (
|
|
4
|
-
// the filename including the extension (e.g. `.css`) and any subfolders after the buildPath (e.g. `functional`)
|
|
5
|
-
outputFile: string,
|
|
6
|
-
// the prefix is prepended to all tokens
|
|
7
|
-
prefix: string | undefined,
|
|
8
|
-
// the build path in which the `outputFile` is placed
|
|
9
|
-
buildPath: string,
|
|
10
|
-
options?: StyleDictionary.Options,
|
|
11
|
-
) => StyleDictionary.Platform
|
package/src/types/Shadow.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type definition for w3c shadow composite token value
|
|
3
|
-
* @link https://design-tokens.github.io/community-group/format/#shadow
|
|
4
|
-
*/
|
|
5
|
-
export type ShadowTokenValue = {
|
|
6
|
-
color: string
|
|
7
|
-
offsetX: string
|
|
8
|
-
offsetY: string
|
|
9
|
-
blur: string
|
|
10
|
-
spread: string
|
|
11
|
-
// custom non w3c values
|
|
12
|
-
inset?: boolean
|
|
13
|
-
alpha?: number
|
|
14
|
-
}
|
package/src/types/SizeEm.d.ts
DELETED
package/src/types/SizePx.d.ts
DELETED
package/src/types/SizeRem.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type StyleDictionary from 'style-dictionary'
|
|
2
|
-
|
|
3
|
-
export type ConfigGeneratorOptions = {
|
|
4
|
-
buildPath: string
|
|
5
|
-
prefix?: string
|
|
6
|
-
themed?: boolean
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export type StyleDictionaryConfigGenerator = (
|
|
10
|
-
outputName: string,
|
|
11
|
-
source: string[],
|
|
12
|
-
include: string[],
|
|
13
|
-
options: ConfigGeneratorOptions,
|
|
14
|
-
platforms?: Record<string, StyleDictionary.Platform | undefined>,
|
|
15
|
-
) => StyleDictionary.Config
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export type TokenBuildInput = {
|
|
2
|
-
// The output filename WITHOUT the extension
|
|
3
|
-
filename: string
|
|
4
|
-
// Array of `filepaths` to token files that should be converted and included in the output. Accepts relative or glob paths.
|
|
5
|
-
source: string[]
|
|
6
|
-
// Array of `filepaths` to token fils that should NOT be included in the output, but should be available to reference during compilation e.g. base color scales
|
|
7
|
-
include: string[]
|
|
8
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type definition for w3c typography composite token value
|
|
3
|
-
* @link https://design-tokens.github.io/community-group/format/#typography
|
|
4
|
-
*/
|
|
5
|
-
export type TypographyTokenValue = {
|
|
6
|
-
fontFamily: string
|
|
7
|
-
fontSize: number
|
|
8
|
-
fontWeight: number
|
|
9
|
-
lineHeight: number
|
|
10
|
-
fontStyle?: string
|
|
11
|
-
letterSpacing?: number
|
|
12
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type StyleDictionary from 'style-dictionary'
|
|
2
|
-
|
|
3
|
-
export type w3cTokenType = 'color' | 'dimension' | 'fontFamily' | 'fontWeight' | 'duration' | 'cubicBezier'
|
|
4
|
-
export type w3cCompositeTokenType = 'shadow' | 'border' | 'gradient' | 'transition' | 'strokeStyle' | 'typography'
|
|
5
|
-
|
|
6
|
-
export interface w3cTransformedToken extends StyleDictionary.TransformedToken {
|
|
7
|
-
$type?: w3cTokenType | w3cCompositeTokenType
|
|
8
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/* istanbul ignore file */
|
|
2
|
-
import {copyFile, readdir, mkdir} from 'fs/promises'
|
|
3
|
-
/**
|
|
4
|
-
* copyFromDir
|
|
5
|
-
* @description Copies all files from source folder to destination
|
|
6
|
-
* @param source path
|
|
7
|
-
* @param destination path
|
|
8
|
-
* @returns promise
|
|
9
|
-
*/
|
|
10
|
-
export const copyFromDir = async (source: string, destination: string) => {
|
|
11
|
-
// adjust trailing slash
|
|
12
|
-
const src = `${source.replace(/\/$/, '')}`
|
|
13
|
-
const dest = `${destination.replace(/\/$/, '')}`
|
|
14
|
-
// create dest if it does not exists
|
|
15
|
-
await mkdir(dest, {recursive: true})
|
|
16
|
-
// read files from source
|
|
17
|
-
const files = await readdir(src)
|
|
18
|
-
for (const file of files) {
|
|
19
|
-
copyFile(`${src}/${file}`, `${dest}/${file}`)
|
|
20
|
-
}
|
|
21
|
-
}
|
package/src/utilities/index.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import {upperCaseFirstCharacter} from './upperCaseFirstCharacter'
|
|
2
|
-
|
|
3
|
-
export const toCamelCase = (string: string | string[]) => {
|
|
4
|
-
if (!Array.isArray(string)) {
|
|
5
|
-
string = [string]
|
|
6
|
-
}
|
|
7
|
-
// match unsupported characters
|
|
8
|
-
const regex = /[^a-zA-Z0-9]+/g
|
|
9
|
-
// replace any non-letter and non-number character and split into word array
|
|
10
|
-
const stringArray = string
|
|
11
|
-
.filter(part => part !== '@')
|
|
12
|
-
.filter(Boolean)
|
|
13
|
-
.join(' ')
|
|
14
|
-
.replace(regex, ' ')
|
|
15
|
-
.split(' ')
|
|
16
|
-
return (
|
|
17
|
-
stringArray
|
|
18
|
-
// remove undefined if exists
|
|
19
|
-
.filter((part: unknown): part is string => typeof part === 'string')
|
|
20
|
-
// ucFirst all but first part
|
|
21
|
-
.map((part: string, index: number) => {
|
|
22
|
-
if (index > 0) {
|
|
23
|
-
return upperCaseFirstCharacter(part)
|
|
24
|
-
}
|
|
25
|
-
return part
|
|
26
|
-
})
|
|
27
|
-
.join('')
|
|
28
|
-
)
|
|
29
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description converts tokens to type and returns array with used type
|
|
3
|
-
* @param tree object
|
|
4
|
-
* @param callback function to be run on valid items
|
|
5
|
-
* @param validItem function to test if a node is a validItem to be transformed
|
|
6
|
-
* @returns object
|
|
7
|
-
*/
|
|
8
|
-
export const treeWalker = (
|
|
9
|
-
tree: unknown,
|
|
10
|
-
callback: <T>(argument: T) => unknown,
|
|
11
|
-
isValidItem: (argument: unknown) => boolean,
|
|
12
|
-
): unknown => {
|
|
13
|
-
// is a valid item -> pass through callback
|
|
14
|
-
if (isValidItem(tree)) {
|
|
15
|
-
return callback(tree)
|
|
16
|
-
}
|
|
17
|
-
// is non-object value -> ignore
|
|
18
|
-
if (typeof tree !== 'object' || tree === null) {
|
|
19
|
-
return
|
|
20
|
-
}
|
|
21
|
-
// is obj -> continue
|
|
22
|
-
const nextObj: Record<string, unknown> = {}
|
|
23
|
-
for (const [prop, value] of Object.entries(tree) as [prop: string, value: unknown][]) {
|
|
24
|
-
nextObj[prop] = treeWalker(value, callback, isValidItem)
|
|
25
|
-
}
|
|
26
|
-
return nextObj
|
|
27
|
-
}
|