@primer/primitives 9.0.3 → 9.1.0-rc.73606a1a
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 +85 -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/package.json +4 -7
- 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,12 +0,0 @@
|
|
|
1
|
-
import {z} from 'zod'
|
|
2
|
-
import {baseToken} from './baseToken'
|
|
3
|
-
import {referenceValue} from './referenceValue'
|
|
4
|
-
import {durationValue} from './durationValue'
|
|
5
|
-
import {tokenType} from './tokenType'
|
|
6
|
-
|
|
7
|
-
export const durationToken = baseToken
|
|
8
|
-
.extend({
|
|
9
|
-
$value: z.union([durationValue, referenceValue]),
|
|
10
|
-
$type: tokenType('duration'),
|
|
11
|
-
})
|
|
12
|
-
.strict()
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {z} from 'zod'
|
|
2
|
-
import {schemaErrorMessage} from '../utilities/schemaErrorMessage'
|
|
3
|
-
|
|
4
|
-
export const durationValue = z.string().refine(
|
|
5
|
-
duration => /(^[0-9]+ms$)/.test(duration),
|
|
6
|
-
val => ({
|
|
7
|
-
message: schemaErrorMessage(`Invalid duration: "${val}"`, `A duration must be a string with an "ms"`),
|
|
8
|
-
}),
|
|
9
|
-
)
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import {z} from 'zod'
|
|
2
|
-
import {referenceValue} from './referenceValue'
|
|
3
|
-
import {baseToken} from './baseToken'
|
|
4
|
-
import {tokenType} from './tokenType'
|
|
5
|
-
import {collection} from './collections'
|
|
6
|
-
import {scopes} from './scopes'
|
|
7
|
-
|
|
8
|
-
export const fontFamilyToken = baseToken
|
|
9
|
-
.extend({
|
|
10
|
-
$value: z.union([z.string(), referenceValue]),
|
|
11
|
-
$type: tokenType('fontFamily'),
|
|
12
|
-
$extensions: z
|
|
13
|
-
.object({
|
|
14
|
-
'org.primer.figma': z.object({
|
|
15
|
-
collection: collection(['base/typography', 'typography']).optional(),
|
|
16
|
-
scopes: scopes(['fontFamily']).optional(),
|
|
17
|
-
}),
|
|
18
|
-
})
|
|
19
|
-
.optional(),
|
|
20
|
-
})
|
|
21
|
-
.strict()
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import {z} from 'zod'
|
|
2
|
-
import {fontWeightValue} from './fontWeightValue'
|
|
3
|
-
import {referenceValue} from './referenceValue'
|
|
4
|
-
import {baseToken} from './baseToken'
|
|
5
|
-
import {tokenType} from './tokenType'
|
|
6
|
-
import {collection} from './collections'
|
|
7
|
-
import {scopes} from './scopes'
|
|
8
|
-
|
|
9
|
-
export const fontWeightToken = baseToken
|
|
10
|
-
.extend({
|
|
11
|
-
$type: tokenType('fontWeight'),
|
|
12
|
-
$value: z.union([fontWeightValue, referenceValue]),
|
|
13
|
-
$extensions: z
|
|
14
|
-
.object({
|
|
15
|
-
'org.primer.figma': z.object({
|
|
16
|
-
collection: collection(['base/typography', 'typography']).optional(),
|
|
17
|
-
scopes: scopes(['fontWeight']).optional(),
|
|
18
|
-
}),
|
|
19
|
-
})
|
|
20
|
-
.optional(),
|
|
21
|
-
})
|
|
22
|
-
.strict()
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import {z} from 'zod'
|
|
2
|
-
import {schemaErrorMessage} from '../utilities/schemaErrorMessage'
|
|
3
|
-
|
|
4
|
-
const allowed = [100, 200, 300, 400, 500, 600, 700, 800, 900, 950]
|
|
5
|
-
|
|
6
|
-
export const fontWeightValue = z.number().refine(
|
|
7
|
-
value => allowed.includes(value),
|
|
8
|
-
value => ({
|
|
9
|
-
message: schemaErrorMessage(
|
|
10
|
-
`Invalid font weight value: "${value}"`,
|
|
11
|
-
`Font weight must be one of ${allowed.join(', ')}`,
|
|
12
|
-
),
|
|
13
|
-
}),
|
|
14
|
-
)
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import {z} from 'zod'
|
|
2
|
-
import {baseToken} from './baseToken'
|
|
3
|
-
import {referenceValue} from './referenceValue'
|
|
4
|
-
import {tokenType} from './tokenType'
|
|
5
|
-
import {scopes} from './scopes'
|
|
6
|
-
import {collection} from './collections'
|
|
7
|
-
|
|
8
|
-
export const numberToken = baseToken
|
|
9
|
-
.extend({
|
|
10
|
-
$value: z.union([z.number(), referenceValue]),
|
|
11
|
-
$type: tokenType('number'),
|
|
12
|
-
$extensions: z
|
|
13
|
-
.object({
|
|
14
|
-
'org.primer.data': z
|
|
15
|
-
.object({
|
|
16
|
-
fontSize: z.number().optional(),
|
|
17
|
-
})
|
|
18
|
-
.optional(),
|
|
19
|
-
'org.primer.figma': z
|
|
20
|
-
.object({
|
|
21
|
-
collection: collection(['typography']).optional(),
|
|
22
|
-
scopes: scopes(['fontWeight', 'lineHeight']).optional(),
|
|
23
|
-
})
|
|
24
|
-
.optional(),
|
|
25
|
-
})
|
|
26
|
-
.optional(),
|
|
27
|
-
})
|
|
28
|
-
.strict()
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import {z} from 'zod'
|
|
2
|
-
import {schemaErrorMessage} from '../utilities/schemaErrorMessage'
|
|
3
|
-
|
|
4
|
-
export const referenceValue = z.string().refine(
|
|
5
|
-
ref => /^{\w+(\.\w+)*(\.\w+|\.@)}$/.test(ref),
|
|
6
|
-
ref => ({
|
|
7
|
-
message: schemaErrorMessage(
|
|
8
|
-
`Invalid reference: "${ref}"`,
|
|
9
|
-
'Reference must be a string in the format "{path.to.token}".',
|
|
10
|
-
),
|
|
11
|
-
}),
|
|
12
|
-
)
|
package/src/schemas/scopes.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import {z} from 'zod'
|
|
2
|
-
import {joinFriendly} from '../utilities/joinFriendly'
|
|
3
|
-
import {schemaErrorMessage} from '../utilities/schemaErrorMessage'
|
|
4
|
-
|
|
5
|
-
const validScopes = [
|
|
6
|
-
'all',
|
|
7
|
-
'bgColor',
|
|
8
|
-
'fgColor',
|
|
9
|
-
'borderColor',
|
|
10
|
-
'borderWidth',
|
|
11
|
-
'size',
|
|
12
|
-
'gap',
|
|
13
|
-
'radius',
|
|
14
|
-
'effectColor',
|
|
15
|
-
'effectFloat',
|
|
16
|
-
'opacity',
|
|
17
|
-
'fontFamily',
|
|
18
|
-
'fontStyle',
|
|
19
|
-
'fontWeight',
|
|
20
|
-
'fontSize',
|
|
21
|
-
'lineHeight',
|
|
22
|
-
'letterSpacing',
|
|
23
|
-
'paragraphSpacing',
|
|
24
|
-
'paragraphIndent',
|
|
25
|
-
] as const
|
|
26
|
-
|
|
27
|
-
export type ValidScope = (typeof validScopes)[number]
|
|
28
|
-
|
|
29
|
-
export const scopes = (scopeSubset?: ValidScope[]) => {
|
|
30
|
-
const scopeArray = scopeSubset ?? validScopes
|
|
31
|
-
return z.array(z.string()).refine(
|
|
32
|
-
value => value.every(item => scopeArray.includes(item as ValidScope)),
|
|
33
|
-
value => ({
|
|
34
|
-
message: schemaErrorMessage(
|
|
35
|
-
`Invalid scope: "${value}"`,
|
|
36
|
-
`Valid scopes are: ${joinFriendly(scopeArray as string[])}`,
|
|
37
|
-
),
|
|
38
|
-
}),
|
|
39
|
-
)
|
|
40
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import {z} from 'zod'
|
|
2
|
-
import {baseToken} from './baseToken'
|
|
3
|
-
import {referenceValue} from './referenceValue'
|
|
4
|
-
import {colorHexValue} from './colorHexValue'
|
|
5
|
-
import {alphaValue} from './alphaValue'
|
|
6
|
-
import {dimensionValue} from './dimensionValue'
|
|
7
|
-
import {tokenType} from './tokenType'
|
|
8
|
-
import {collection, mode} from './collections'
|
|
9
|
-
|
|
10
|
-
export const shadowValue = z
|
|
11
|
-
.object({
|
|
12
|
-
color: z.union([colorHexValue, referenceValue]),
|
|
13
|
-
alpha: z.union([alphaValue, referenceValue]),
|
|
14
|
-
offsetX: z.union([dimensionValue, referenceValue]),
|
|
15
|
-
offsetY: z.union([dimensionValue, referenceValue]),
|
|
16
|
-
blur: z.union([dimensionValue, referenceValue]),
|
|
17
|
-
spread: z.union([dimensionValue, referenceValue]),
|
|
18
|
-
inset: z.boolean().optional(),
|
|
19
|
-
})
|
|
20
|
-
.strict()
|
|
21
|
-
|
|
22
|
-
export const shadowToken = baseToken
|
|
23
|
-
.extend({
|
|
24
|
-
$value: z.union([shadowValue, z.array(shadowValue), referenceValue]),
|
|
25
|
-
$type: tokenType('shadow'),
|
|
26
|
-
$extensions: z
|
|
27
|
-
.object({
|
|
28
|
-
'org.primer.figma': z.object({
|
|
29
|
-
collection: collection(['mode']).optional(),
|
|
30
|
-
mode: mode([
|
|
31
|
-
'light',
|
|
32
|
-
'dark',
|
|
33
|
-
'dark dimmed',
|
|
34
|
-
'light high contrast',
|
|
35
|
-
'dark high contrast',
|
|
36
|
-
'light colorblind',
|
|
37
|
-
'dark colorblind',
|
|
38
|
-
'light tritanopia',
|
|
39
|
-
'dark tritanopia',
|
|
40
|
-
]).optional(),
|
|
41
|
-
}),
|
|
42
|
-
})
|
|
43
|
-
.optional(),
|
|
44
|
-
})
|
|
45
|
-
.strict()
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import {z} from 'zod'
|
|
2
|
-
import {baseToken} from './baseToken'
|
|
3
|
-
import {referenceValue} from './referenceValue'
|
|
4
|
-
import {tokenType} from './tokenType'
|
|
5
|
-
|
|
6
|
-
export const stringToken = baseToken
|
|
7
|
-
.extend({
|
|
8
|
-
$value: z.union([z.string(), referenceValue]),
|
|
9
|
-
$type: tokenType('string'),
|
|
10
|
-
})
|
|
11
|
-
.strict()
|
package/src/schemas/tokenName.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import {z} from 'zod'
|
|
2
|
-
import {schemaErrorMessage} from '../utilities/schemaErrorMessage'
|
|
3
|
-
|
|
4
|
-
export const tokenName = z.string().refine(
|
|
5
|
-
name => /(^[a-z0-9][A-Za-z0-9-]*$|^@$)/.test(name),
|
|
6
|
-
name => ({
|
|
7
|
-
message: schemaErrorMessage(
|
|
8
|
-
`Invalid token name: "${name}"`,
|
|
9
|
-
'Token name must be kebab-case or camelCase, and start with a lowercase letter or number and consist only of letters, numbers, and hyphens.',
|
|
10
|
-
),
|
|
11
|
-
}),
|
|
12
|
-
)
|
package/src/schemas/tokenType.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import {z} from 'zod'
|
|
2
|
-
import {referenceValue} from './referenceValue'
|
|
3
|
-
import {dimensionValue} from './dimensionValue'
|
|
4
|
-
import {baseToken} from './baseToken'
|
|
5
|
-
import {fontWeightValue} from './fontWeightValue'
|
|
6
|
-
import {tokenType} from './tokenType'
|
|
7
|
-
|
|
8
|
-
export const typographyValue = z.object({
|
|
9
|
-
fontSize: z.union([dimensionValue, referenceValue]),
|
|
10
|
-
lineHeight: z.union([dimensionValue, referenceValue]).optional(),
|
|
11
|
-
fontWeight: z.union([fontWeightValue, referenceValue]),
|
|
12
|
-
fontFamily: z.union([z.string().min(1), referenceValue]),
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
export const typographyToken = baseToken
|
|
16
|
-
.extend({
|
|
17
|
-
$value: z.union([typographyValue, referenceValue]),
|
|
18
|
-
$type: tokenType('typography'),
|
|
19
|
-
})
|
|
20
|
-
.strict()
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import {z} from 'zod'
|
|
2
|
-
import {joinFriendly} from '../utilities/joinFriendly'
|
|
3
|
-
import {schemaErrorMessage} from '../utilities/schemaErrorMessage'
|
|
4
|
-
|
|
5
|
-
const validTypes = [
|
|
6
|
-
'color',
|
|
7
|
-
'typography',
|
|
8
|
-
'dimension',
|
|
9
|
-
'duration',
|
|
10
|
-
'border',
|
|
11
|
-
'shadow',
|
|
12
|
-
'fontFamily',
|
|
13
|
-
'fontWeight',
|
|
14
|
-
'number',
|
|
15
|
-
'string',
|
|
16
|
-
'custom-viewportRange',
|
|
17
|
-
] as const
|
|
18
|
-
|
|
19
|
-
export type TokenType = (typeof validTypes)[number]
|
|
20
|
-
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
22
|
-
// @ts-ignore: TODO: fix this
|
|
23
|
-
export const validateType = z.record(
|
|
24
|
-
z.string(),
|
|
25
|
-
z.lazy((): z.ZodTypeAny => {
|
|
26
|
-
return z.union([
|
|
27
|
-
z
|
|
28
|
-
.object({
|
|
29
|
-
$value: z.any(),
|
|
30
|
-
$type: z.string().refine(
|
|
31
|
-
type => validTypes.includes(type as TokenType),
|
|
32
|
-
val => ({
|
|
33
|
-
message: schemaErrorMessage(
|
|
34
|
-
`Invalid token $type: "${val}"`,
|
|
35
|
-
`Must be one of the following: ${joinFriendly([...validTypes], 'or')}`,
|
|
36
|
-
),
|
|
37
|
-
}),
|
|
38
|
-
),
|
|
39
|
-
})
|
|
40
|
-
.required(),
|
|
41
|
-
validateType,
|
|
42
|
-
])
|
|
43
|
-
}),
|
|
44
|
-
)
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import {z} from 'zod'
|
|
2
|
-
import {baseToken} from './baseToken'
|
|
3
|
-
import {referenceValue} from './referenceValue'
|
|
4
|
-
import {tokenType} from './tokenType'
|
|
5
|
-
|
|
6
|
-
export const viewportRangeToken = baseToken
|
|
7
|
-
.extend({
|
|
8
|
-
$value: z.union([z.string(), referenceValue]),
|
|
9
|
-
$type: tokenType('custom-viewportRange'),
|
|
10
|
-
})
|
|
11
|
-
.strict()
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type StyleDictionary from 'style-dictionary'
|
|
2
|
-
import {getMockToken} from './getMockToken'
|
|
3
|
-
|
|
4
|
-
const mockDictionaryDefault = {
|
|
5
|
-
tokens: {
|
|
6
|
-
subgroup: {
|
|
7
|
-
red: getMockToken({
|
|
8
|
-
name: 'red',
|
|
9
|
-
path: ['tokens', 'subgroup', 'red'],
|
|
10
|
-
}),
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const getMockDictionary = (tokens?: StyleDictionary.TransformedTokens): StyleDictionary.Dictionary => ({
|
|
16
|
-
allTokens: Object.values((tokens || mockDictionaryDefault).tokens.subgroup),
|
|
17
|
-
tokens: tokens || mockDictionaryDefault,
|
|
18
|
-
allProperties: Object.values((tokens || mockDictionaryDefault).tokens.subgroup),
|
|
19
|
-
properties: tokens || mockDictionaryDefault,
|
|
20
|
-
usesReference: _value => false,
|
|
21
|
-
getReferences: _value => [],
|
|
22
|
-
})
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type {FormatterArguments} from 'style-dictionary/types/Format'
|
|
2
|
-
import {getMockDictionary} from './'
|
|
3
|
-
|
|
4
|
-
const defaultFormatterArguments: FormatterArguments = {
|
|
5
|
-
dictionary: getMockDictionary(),
|
|
6
|
-
file: {
|
|
7
|
-
destination: 'tokens.ts',
|
|
8
|
-
options: {
|
|
9
|
-
showFileHeader: false,
|
|
10
|
-
},
|
|
11
|
-
},
|
|
12
|
-
options: {},
|
|
13
|
-
platform: {},
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const getMockFormatterArguments = (overrides?: Partial<FormatterArguments>): FormatterArguments => {
|
|
17
|
-
return {
|
|
18
|
-
...defaultFormatterArguments,
|
|
19
|
-
...(overrides || {}),
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
export const parserOutput = {
|
|
2
|
-
color: {
|
|
3
|
-
value: 'red',
|
|
4
|
-
comment: 'a red color',
|
|
5
|
-
$type: 'color',
|
|
6
|
-
$extensions: {},
|
|
7
|
-
alpha: 0.5,
|
|
8
|
-
},
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const parserInput: {[Property in jsonFormats]: string} = {
|
|
12
|
-
'json.w3c': `{
|
|
13
|
-
"color": {
|
|
14
|
-
"$value": 'red',
|
|
15
|
-
"$description": "a red color",
|
|
16
|
-
"$type": "color",
|
|
17
|
-
"$extensions": {},
|
|
18
|
-
"alpha": 0.5
|
|
19
|
-
}
|
|
20
|
-
}`,
|
|
21
|
-
'json.default': `{
|
|
22
|
-
"color": {
|
|
23
|
-
"value": 'red',
|
|
24
|
-
"description": "a red color",
|
|
25
|
-
"type": "color",
|
|
26
|
-
"extensions": {},
|
|
27
|
-
"alpha": 0.5
|
|
28
|
-
}
|
|
29
|
-
}`,
|
|
30
|
-
'json5.w3c': `{
|
|
31
|
-
"color": {
|
|
32
|
-
// comment
|
|
33
|
-
$value: 'red',
|
|
34
|
-
"$description": "a red color",
|
|
35
|
-
'$type': "color",
|
|
36
|
-
"$extensions": {},
|
|
37
|
-
alpha: 0.5,
|
|
38
|
-
}
|
|
39
|
-
}`,
|
|
40
|
-
'json5.default': `{
|
|
41
|
-
"color": {
|
|
42
|
-
// comment
|
|
43
|
-
value: 'red',
|
|
44
|
-
"description": "a red color",
|
|
45
|
-
'type': "color",
|
|
46
|
-
"extensions": {},
|
|
47
|
-
alpha: 0.5,
|
|
48
|
-
}
|
|
49
|
-
}`,
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
type jsonFormats = 'json5.default' | 'json5.w3c' | 'json.default' | 'json.w3c'
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
*
|
|
56
|
-
* @param contents jsonFormats or string taht replaces content in return
|
|
57
|
-
* @returns predefined json string or override
|
|
58
|
-
*/
|
|
59
|
-
export const getMockParserInput = (
|
|
60
|
-
contents: jsonFormats | string,
|
|
61
|
-
filePath?: string,
|
|
62
|
-
): {filePath: string; contents: string} => {
|
|
63
|
-
// use predefined if no override
|
|
64
|
-
if (['json5.default', 'json5.w3c', 'json.default', 'json.w3c'].includes(contents)) {
|
|
65
|
-
contents = parserInput[contents as jsonFormats]
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return {
|
|
69
|
-
filePath: filePath || `path/to/file/token.json`,
|
|
70
|
-
contents,
|
|
71
|
-
}
|
|
72
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type StyleDictionary from 'style-dictionary'
|
|
2
|
-
|
|
3
|
-
const mockTokenDefaults = {
|
|
4
|
-
name: 'tokenName',
|
|
5
|
-
path: ['path'],
|
|
6
|
-
original: {
|
|
7
|
-
value: 'originalValue',
|
|
8
|
-
attributes: {},
|
|
9
|
-
},
|
|
10
|
-
filePath: 'file.json',
|
|
11
|
-
isSource: true,
|
|
12
|
-
value: 'transformedValue',
|
|
13
|
-
attributes: {},
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
*
|
|
17
|
-
* @param valueOverrides partial StyleDictionary.TransformedToken
|
|
18
|
-
* @returns StyleDictionary.TransformedToken - a merge of {@link mockTokenDefaults} and any valid properties provided in the valueOverrides param
|
|
19
|
-
*/
|
|
20
|
-
export const getMockToken = (valueOverrides: {
|
|
21
|
-
[key: keyof StyleDictionary.TransformedToken]: unknown
|
|
22
|
-
}): StyleDictionary.TransformedToken => ({
|
|
23
|
-
...mockTokenDefaults,
|
|
24
|
-
...valueOverrides,
|
|
25
|
-
})
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import {isBorder} from '../filters/isBorder'
|
|
2
|
-
import type StyleDictionary from 'style-dictionary'
|
|
3
|
-
import type {BorderTokenValue} from '../types/BorderTokenValue'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* checks if all required properties exist on shadow token
|
|
7
|
-
* @param object - BorderTokenValue
|
|
8
|
-
* @returns void or throws error
|
|
9
|
-
*/
|
|
10
|
-
const checkForBorderTokenProperties = (border: BorderTokenValue) => {
|
|
11
|
-
const requiredProperties = ['color', 'width', 'style']
|
|
12
|
-
for (const prop of requiredProperties) {
|
|
13
|
-
if (prop in border === false) {
|
|
14
|
-
throw new Error(`Missing propery: ${prop} on border token ${JSON.stringify(border)}`)
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* @description converts w3c border tokens in css border string
|
|
20
|
-
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
21
|
-
* @matcher matches all tokens of $type `border`
|
|
22
|
-
* @transformer returns css border `string`
|
|
23
|
-
*/
|
|
24
|
-
export const borderToCss: StyleDictionary.Transform = {
|
|
25
|
-
type: `value`,
|
|
26
|
-
transitive: true,
|
|
27
|
-
matcher: isBorder,
|
|
28
|
-
transformer: ({value}: {value: BorderTokenValue}) => {
|
|
29
|
-
//
|
|
30
|
-
checkForBorderTokenProperties(value)
|
|
31
|
-
// if value === string it was probably already transformed
|
|
32
|
-
if (typeof value === 'string') {
|
|
33
|
-
return value
|
|
34
|
-
}
|
|
35
|
-
/* color | style | width */
|
|
36
|
-
return `${value.color} ${value.style} ${value.width}`
|
|
37
|
-
},
|
|
38
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import {toHex} from 'color2k'
|
|
2
|
-
import {isColor} from '../filters'
|
|
3
|
-
import type StyleDictionary from 'style-dictionary'
|
|
4
|
-
import {getTokenValue} from './utilities/getTokenValue'
|
|
5
|
-
/**
|
|
6
|
-
* @description converts color tokens value to `hex6` or `hex8`
|
|
7
|
-
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
8
|
-
* @matcher matches all tokens of $type `color`
|
|
9
|
-
* @transformer returns a `hex` string
|
|
10
|
-
*/
|
|
11
|
-
export const colorToHex: StyleDictionary.Transform = {
|
|
12
|
-
type: `value`,
|
|
13
|
-
transitive: true,
|
|
14
|
-
matcher: isColor,
|
|
15
|
-
transformer: (token: StyleDictionary.TransformedToken) => toHex(getTokenValue(token)),
|
|
16
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import {toHex} from 'color2k'
|
|
2
|
-
import {alpha} from './utilities/alpha'
|
|
3
|
-
import {isColorWithAlpha} from '../filters'
|
|
4
|
-
import type StyleDictionary from 'style-dictionary'
|
|
5
|
-
import {getTokenValue} from './utilities/getTokenValue'
|
|
6
|
-
/**
|
|
7
|
-
* @description replaces tokens value with `hex8` color using the tokens `alpha` property to specify the value used for alpha
|
|
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 `color` with an `alpha` property
|
|
10
|
-
* @transformer returns `hex8` string
|
|
11
|
-
*/
|
|
12
|
-
export const colorToHexAlpha: StyleDictionary.Transform = {
|
|
13
|
-
type: `value`,
|
|
14
|
-
transitive: true,
|
|
15
|
-
matcher: isColorWithAlpha,
|
|
16
|
-
transformer: (token: StyleDictionary.TransformedToken) => {
|
|
17
|
-
// don't change if alpha is null
|
|
18
|
-
if (token.alpha === null) {
|
|
19
|
-
return toHex(getTokenValue(token))
|
|
20
|
-
}
|
|
21
|
-
return toHex(alpha(getTokenValue(token), token.alpha, token))
|
|
22
|
-
},
|
|
23
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import {toHex} from 'color2k'
|
|
2
|
-
import {isColorWithMix} from '../filters'
|
|
3
|
-
import type StyleDictionary from 'style-dictionary'
|
|
4
|
-
import {getTokenValue} from './utilities/getTokenValue'
|
|
5
|
-
import mix from './utilities/mix'
|
|
6
|
-
/**
|
|
7
|
-
* @description replaces tokens value with `hex8` color using the tokens `alpha` property to specify the value used for alpha
|
|
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 `color` with an `alpha` property
|
|
10
|
-
* @transformer returns `hex8` string
|
|
11
|
-
*/
|
|
12
|
-
export const colorToHexMix: StyleDictionary.Transform = {
|
|
13
|
-
type: `value`,
|
|
14
|
-
transitive: true,
|
|
15
|
-
matcher: isColorWithMix,
|
|
16
|
-
transformer: (token: StyleDictionary.TransformedToken) => {
|
|
17
|
-
return toHex(mix(getTokenValue(token), token.mix?.color || getTokenValue(token), token.mix?.weight || 0))
|
|
18
|
-
},
|
|
19
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import {isColorWithAlpha} from '../filters'
|
|
2
|
-
import {alpha} from './utilities/alpha'
|
|
3
|
-
import type StyleDictionary from 'style-dictionary'
|
|
4
|
-
import {getTokenValue} from './utilities/getTokenValue'
|
|
5
|
-
/**
|
|
6
|
-
* @description replaces tokens value with `rgba` color using the tokens `alpha` property to specify the value used for alpha
|
|
7
|
-
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
8
|
-
* @matcher matches all tokens of $type `color` with an `alpha` property
|
|
9
|
-
* @transformer returns `rgba` string
|
|
10
|
-
*/
|
|
11
|
-
export const colorToRgbAlpha: StyleDictionary.Transform = {
|
|
12
|
-
type: `value`,
|
|
13
|
-
transitive: true,
|
|
14
|
-
matcher: isColorWithAlpha,
|
|
15
|
-
transformer: (token: StyleDictionary.TransformedToken) => {
|
|
16
|
-
if (token.alpha === null) return getTokenValue(token)
|
|
17
|
-
return alpha(getTokenValue(token), token.alpha, token)
|
|
18
|
-
},
|
|
19
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import {toHex} from 'color2k'
|
|
2
|
-
import {isColor} from '../filters'
|
|
3
|
-
import type StyleDictionary from 'style-dictionary'
|
|
4
|
-
import {getTokenValue} from './utilities/getTokenValue'
|
|
5
|
-
import {rgbaFloatToHex} from './utilities/rgbaFloatToHex'
|
|
6
|
-
import mix from './utilities/mix'
|
|
7
|
-
import {hexToRgbaFloat} from './utilities/hexToRgbaFloat'
|
|
8
|
-
import {isRgbaFloat} from './utilities/isRgbaFloat'
|
|
9
|
-
|
|
10
|
-
const toRgbaFloat = (token: StyleDictionary.TransformedToken, alpha?: number) => {
|
|
11
|
-
let tokenValue = getTokenValue(token)
|
|
12
|
-
let tokenMixColor = token.mix?.color
|
|
13
|
-
// get hex value from color string
|
|
14
|
-
if (isRgbaFloat(tokenValue)) {
|
|
15
|
-
tokenValue = rgbaFloatToHex(tokenValue, false)
|
|
16
|
-
}
|
|
17
|
-
if (tokenMixColor && isRgbaFloat(tokenMixColor)) {
|
|
18
|
-
tokenMixColor = rgbaFloatToHex(tokenMixColor, false)
|
|
19
|
-
}
|
|
20
|
-
let hex = toHex(tokenValue)
|
|
21
|
-
// mix color with mix color and weight
|
|
22
|
-
if (token.mix && token.mix.color && token.mix.weight) {
|
|
23
|
-
hex = toHex(mix(tokenValue, tokenMixColor, token.mix.weight))
|
|
24
|
-
}
|
|
25
|
-
// return color as RgbaFloat
|
|
26
|
-
return hexToRgbaFloat(hex, alpha)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* @description converts color tokens rgba float with values from 0 - 1
|
|
31
|
-
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
32
|
-
* @matcher matches all tokens of $type `color`
|
|
33
|
-
* @transformer returns a `rgb` float object
|
|
34
|
-
*/
|
|
35
|
-
export const colorToRgbaFloat: StyleDictionary.Transform = {
|
|
36
|
-
type: `value`,
|
|
37
|
-
transitive: true,
|
|
38
|
-
matcher: isColor,
|
|
39
|
-
transformer: (token: StyleDictionary.TransformedToken) => {
|
|
40
|
-
// skip if value is already rgb float
|
|
41
|
-
if (isRgbaFloat(token.value) && !('mix' in token) && !('alpha' in token)) return token.value
|
|
42
|
-
// convert hex or rgb values to rgba float
|
|
43
|
-
return toRgbaFloat(token, token.alpha)
|
|
44
|
-
},
|
|
45
|
-
}
|