@primer/primitives 7.16.0 → 7.17.0-rc.086cd658
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/styleLint/base/size/size.json +427 -0
- package/dist/styleLint/base/typography/typography.json +54 -0
- package/dist/styleLint/functional/motion/motion.json +47 -0
- package/dist/styleLint/functional/size/border.json +234 -0
- package/dist/styleLint/functional/size/breakpoints.json +152 -0
- package/dist/styleLint/functional/size/size-coarse.json +41 -0
- package/dist/styleLint/functional/size/size-fine.json +41 -0
- package/dist/styleLint/functional/size/size.json +1838 -0
- package/dist/styleLint/functional/size/viewport.json +80 -0
- package/dist/styleLint/functional/themes/dark-colorblind.json +16155 -0
- package/dist/styleLint/functional/themes/dark-dimmed.json +16159 -0
- package/dist/styleLint/functional/themes/dark-high-contrast.json +16175 -0
- package/dist/styleLint/functional/themes/dark-tritanopia.json +16161 -0
- package/dist/styleLint/functional/themes/dark.json +16159 -0
- package/dist/styleLint/functional/themes/light-colorblind.json +16123 -0
- package/dist/styleLint/functional/themes/light-high-contrast.json +16125 -0
- package/dist/styleLint/functional/themes/light-tritanopia.json +16115 -0
- package/dist/styleLint/functional/themes/light.json +16113 -0
- package/dist/styleLint/functional/typography/typography.json +663 -0
- package/package.json +11 -9
- 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 +131 -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 +47 -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 +11 -0
- package/src/schemas/fontWeightToken.ts +12 -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/src/tokens/fallback/color-fallbacks.json +260 -0
- 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/tokens/removed/color.json +421 -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-next-private/styleLint/base/size/size.json +427 -0
- package/tokens-next-private/styleLint/base/typography/typography.json +54 -0
- package/tokens-next-private/styleLint/functional/motion/motion.json +47 -0
- package/tokens-next-private/styleLint/functional/size/border.json +234 -0
- package/tokens-next-private/styleLint/functional/size/breakpoints.json +152 -0
- package/tokens-next-private/styleLint/functional/size/size-coarse.json +41 -0
- package/tokens-next-private/styleLint/functional/size/size-fine.json +41 -0
- package/tokens-next-private/styleLint/functional/size/size.json +1838 -0
- package/tokens-next-private/styleLint/functional/size/viewport.json +80 -0
- package/tokens-next-private/styleLint/functional/themes/dark-colorblind.json +16155 -0
- package/tokens-next-private/styleLint/functional/themes/dark-dimmed.json +16159 -0
- package/tokens-next-private/styleLint/functional/themes/dark-high-contrast.json +16175 -0
- package/tokens-next-private/styleLint/functional/themes/dark-tritanopia.json +16161 -0
- package/tokens-next-private/styleLint/functional/themes/dark.json +16159 -0
- package/tokens-next-private/styleLint/functional/themes/light-colorblind.json +16123 -0
- package/tokens-next-private/styleLint/functional/themes/light-high-contrast.json +16125 -0
- package/tokens-next-private/styleLint/functional/themes/light-tritanopia.json +16115 -0
- package/tokens-next-private/styleLint/functional/themes/light.json +16113 -0
- package/tokens-next-private/styleLint/functional/typography/typography.json +663 -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
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
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));
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the value of a flag from the command line
|
|
3
|
+
* @param flag name of the flag to get
|
|
4
|
+
* @param prefix default `--` but can be changed to `-` the part to the left of the flag name
|
|
5
|
+
* @returns null if flag is not found, otherwise the value of the flag or the flag name if the flag has no value
|
|
6
|
+
* @example `getFlag('--silent')` returns `null` if `--silent` is not found, `--silent` if `--silent` is found with no value, and `true` if `--silent=true` is found
|
|
7
|
+
*/
|
|
8
|
+
export const getFlag = (flag: string, prefix = '--') => {
|
|
9
|
+
flag = `${prefix}${flag.replace(prefix, '')}`
|
|
10
|
+
const index = process.argv.findIndex(arg => arg === flag || arg.startsWith(`${flag}=`))
|
|
11
|
+
return index === -1 ? null : process.argv[index].replace(`${flag}=`, '')
|
|
12
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* upperCaseFirstCharacter
|
|
3
|
+
* @scope custom implementation should only be used within `name path to ...` transformer
|
|
4
|
+
* @description changes first letter to uppercase but keeps the rest of the word as is
|
|
5
|
+
* @param string
|
|
6
|
+
* @returns string
|
|
7
|
+
*/
|
|
8
|
+
export const upperCaseFirstCharacter = ([firstLetter, ...restOfWord]: string): string => {
|
|
9
|
+
return firstLetter.toUpperCase() + restOfWord.join('')
|
|
10
|
+
}
|
package/src/utils-v1.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {lighten as _lighten, transparentize, darken as _darken} from 'color2k'
|
|
2
|
+
import deepmerge from 'deepmerge'
|
|
3
|
+
import _get from 'lodash/get'
|
|
4
|
+
import isFunction from 'lodash/isFunction'
|
|
5
|
+
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
+
type Value = string | ((obj: any) => string)
|
|
8
|
+
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
+
export function resolveValue(value: Value, obj: any): string {
|
|
11
|
+
return isFunction(value) ? resolveValue(value(obj), obj) : value
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function merge(...objects: object[]) {
|
|
15
|
+
return deepmerge.all(objects, {arrayMerge: (target, source) => source})
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function get(path: string) {
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
+
return (obj: any) => _get(obj, path)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function alpha(value: Value, amount: number) {
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
+
return (obj: any) => transparentize(resolveValue(value, obj), 1 - amount).replace(/ /g, '')
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function lighten(value: Value, amount: number) {
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
+
return (obj: any) => _lighten(resolveValue(value, obj), amount).replace(/ /g, '')
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function darken(value: Value, amount: number) {
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
|
+
return (obj: any) => _darken(resolveValue(value, obj), amount).replace(/ /g, '')
|
|
36
|
+
}
|