@primer/primitives 11.4.0 → 11.4.1-rc.24c79953
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/DESIGN_TOKENS_GUIDE.md +185 -0
- package/DESIGN_TOKENS_SPEC.md +565 -0
- package/dist/build/formats/jsonFigma.js +8 -1
- package/dist/build/formats/markdownLlmGuidelines.d.ts +7 -6
- package/dist/build/formats/markdownLlmGuidelines.js +1034 -60
- package/dist/build/schemas/borderToken.d.ts +17 -3
- package/dist/build/schemas/colorToken.d.ts +1 -1
- package/dist/build/schemas/cubicBezierToken.d.ts +1 -1
- package/dist/build/schemas/dimensionToken.d.ts +9 -2
- package/dist/build/schemas/dimensionValue.d.ts +12 -1
- package/dist/build/schemas/dimensionValue.js +10 -13
- package/dist/build/schemas/durationToken.d.ts +8 -2
- package/dist/build/schemas/durationValue.d.ts +11 -1
- package/dist/build/schemas/durationValue.js +13 -3
- package/dist/build/schemas/fontFamilyToken.d.ts +1 -1
- package/dist/build/schemas/fontWeightToken.d.ts +1 -1
- package/dist/build/schemas/gradientToken.d.ts +1 -1
- package/dist/build/schemas/numberToken.d.ts +1 -1
- package/dist/build/schemas/shadowToken.d.ts +673 -85
- package/dist/build/schemas/stringToken.d.ts +1 -1
- package/dist/build/schemas/stringToken.js +1 -1
- package/dist/build/schemas/tokenType.d.ts +1 -1
- package/dist/build/schemas/transitionToken.d.ts +15 -3
- package/dist/build/schemas/typographyToken.d.ts +19 -5
- package/dist/build/schemas/typographyToken.js +1 -1
- package/dist/build/schemas/validTokenType.d.ts +1 -1
- package/dist/build/schemas/validTokenType.js +1 -1
- package/dist/build/schemas/viewportRangeToken.d.ts +1 -1
- package/dist/build/transformers/borderToCss.js +17 -1
- package/dist/build/transformers/dimensionToPixelUnitless.d.ts +3 -2
- package/dist/build/transformers/dimensionToPixelUnitless.js +22 -26
- package/dist/build/transformers/dimensionToRem.d.ts +2 -1
- package/dist/build/transformers/dimensionToRem.js +21 -22
- package/dist/build/transformers/dimensionToRemPxArray.d.ts +2 -1
- package/dist/build/transformers/dimensionToRemPxArray.js +21 -22
- package/dist/build/transformers/durationToCss.d.ts +2 -1
- package/dist/build/transformers/durationToCss.js +18 -11
- package/dist/build/transformers/shadowToCss.js +12 -1
- package/dist/build/transformers/utilities/parseDimension.d.ts +12 -0
- package/dist/build/transformers/utilities/parseDimension.js +31 -0
- package/dist/build/types/borderTokenValue.d.ts +3 -1
- package/dist/build/types/dimensionTokenValue.d.ts +9 -0
- package/dist/build/types/shadowTokenValue.d.ts +6 -4
- package/dist/css/functional/themes/dark-colorblind-high-contrast.css +32 -28
- package/dist/css/functional/themes/dark-colorblind.css +32 -28
- package/dist/css/functional/themes/dark-dimmed-high-contrast.css +32 -28
- package/dist/css/functional/themes/dark-dimmed.css +32 -28
- package/dist/css/functional/themes/dark-high-contrast.css +32 -28
- package/dist/css/functional/themes/dark-tritanopia-high-contrast.css +32 -28
- package/dist/css/functional/themes/dark-tritanopia.css +32 -28
- package/dist/css/functional/themes/dark.css +32 -28
- package/dist/css/functional/themes/light-colorblind-high-contrast.css +32 -28
- package/dist/css/functional/themes/light-colorblind.css +32 -28
- package/dist/css/functional/themes/light-high-contrast.css +32 -28
- package/dist/css/functional/themes/light-tritanopia-high-contrast.css +32 -28
- package/dist/css/functional/themes/light-tritanopia.css +32 -28
- package/dist/css/functional/themes/light.css +32 -28
- package/dist/css/primitives.css +4 -0
- package/dist/docs/base/motion/motion.json +96 -24
- package/dist/docs/base/size/size.json +76 -19
- package/dist/docs/base/typography/typography.json +24 -6
- package/dist/docs/functional/size/border.json +26 -11
- package/dist/docs/functional/size/breakpoints.json +24 -6
- package/dist/docs/functional/size/radius.json +16 -4
- package/dist/docs/functional/size/size.json +60 -15
- package/dist/docs/functional/themes/dark-colorblind-high-contrast.json +1423 -346
- package/dist/docs/functional/themes/dark-colorblind.json +1423 -346
- package/dist/docs/functional/themes/dark-dimmed-high-contrast.json +1423 -346
- package/dist/docs/functional/themes/dark-dimmed.json +1423 -346
- package/dist/docs/functional/themes/dark-high-contrast.json +1423 -346
- package/dist/docs/functional/themes/dark-tritanopia-high-contrast.json +1423 -346
- package/dist/docs/functional/themes/dark-tritanopia.json +1423 -346
- package/dist/docs/functional/themes/dark.json +1423 -346
- package/dist/docs/functional/themes/light-colorblind-high-contrast.json +1426 -349
- package/dist/docs/functional/themes/light-colorblind.json +1426 -349
- package/dist/docs/functional/themes/light-high-contrast.json +1426 -349
- package/dist/docs/functional/themes/light-tritanopia-high-contrast.json +1426 -349
- package/dist/docs/functional/themes/light-tritanopia.json +1426 -349
- package/dist/docs/functional/themes/light.json +1426 -349
- package/dist/docs/functional/typography/typography.json +8 -2
- package/dist/fallbacks/base/motion/motion.json +48 -12
- package/dist/figma/themes/light-colorblind.json +4 -4
- package/dist/figma/themes/light-high-contrast.json +4 -4
- package/dist/figma/themes/light-tritanopia.json +4 -4
- package/dist/figma/themes/light.json +4 -4
- package/dist/internalCss/dark-colorblind-high-contrast.css +28 -28
- package/dist/internalCss/dark-colorblind.css +28 -28
- package/dist/internalCss/dark-dimmed-high-contrast.css +28 -28
- package/dist/internalCss/dark-dimmed.css +28 -28
- package/dist/internalCss/dark-high-contrast.css +28 -28
- package/dist/internalCss/dark-tritanopia-high-contrast.css +28 -28
- package/dist/internalCss/dark-tritanopia.css +28 -28
- package/dist/internalCss/dark.css +28 -28
- package/dist/internalCss/light-colorblind-high-contrast.css +28 -28
- package/dist/internalCss/light-colorblind.css +28 -28
- package/dist/internalCss/light-high-contrast.css +28 -28
- package/dist/internalCss/light-tritanopia-high-contrast.css +28 -28
- package/dist/internalCss/light-tritanopia.css +28 -28
- package/dist/internalCss/light.css +28 -28
- package/dist/styleLint/base/motion/motion.json +96 -24
- package/dist/styleLint/base/size/size.json +76 -19
- package/dist/styleLint/base/typography/typography.json +30 -12
- package/dist/styleLint/functional/size/border.json +27 -12
- package/dist/styleLint/functional/size/breakpoints.json +24 -6
- package/dist/styleLint/functional/size/radius.json +17 -5
- package/dist/styleLint/functional/size/size-coarse.json +3 -3
- package/dist/styleLint/functional/size/size-fine.json +3 -3
- package/dist/styleLint/functional/size/size.json +111 -66
- package/dist/styleLint/functional/themes/dark-colorblind-high-contrast.json +1551 -366
- package/dist/styleLint/functional/themes/dark-colorblind.json +1551 -366
- package/dist/styleLint/functional/themes/dark-dimmed-high-contrast.json +1551 -366
- package/dist/styleLint/functional/themes/dark-dimmed.json +1551 -366
- package/dist/styleLint/functional/themes/dark-high-contrast.json +1551 -366
- package/dist/styleLint/functional/themes/dark-tritanopia-high-contrast.json +1551 -366
- package/dist/styleLint/functional/themes/dark-tritanopia.json +1551 -366
- package/dist/styleLint/functional/themes/dark.json +1551 -366
- package/dist/styleLint/functional/themes/light-colorblind-high-contrast.json +1554 -369
- package/dist/styleLint/functional/themes/light-colorblind.json +1554 -369
- package/dist/styleLint/functional/themes/light-high-contrast.json +1554 -369
- package/dist/styleLint/functional/themes/light-tritanopia-high-contrast.json +1554 -369
- package/dist/styleLint/functional/themes/light-tritanopia.json +1554 -369
- package/dist/styleLint/functional/themes/light.json +1554 -369
- package/dist/styleLint/functional/typography/typography.json +28 -22
- package/package.json +6 -5
- package/src/tokens/base/motion/timing.json5 +12 -12
- package/src/tokens/base/size/size.json5 +19 -19
- package/src/tokens/base/typography/typography.json5 +6 -6
- package/src/tokens/component/avatar.json5 +72 -44
- package/src/tokens/component/button.json5 +1545 -1193
- package/src/tokens/functional/border/border.json5 +4 -1
- package/src/tokens/functional/color/bgColor.json5 +8 -0
- package/src/tokens/functional/color/display.json5 +7 -0
- package/src/tokens/functional/color/fgColor.json5 +8 -0
- package/src/tokens/functional/color/syntax.json5 +14 -0
- package/src/tokens/functional/shadow/shadow.json5 +678 -163
- package/src/tokens/functional/size/border.json5 +8 -8
- package/src/tokens/functional/size/breakpoints.json5 +6 -6
- package/src/tokens/functional/size/radius.json5 +4 -4
- package/src/tokens/functional/size/size.json5 +15 -15
- package/src/tokens/functional/typography/typography.json5 +8 -4
- package/dist/build/parsers/index.d.ts +0 -1
- package/dist/build/parsers/index.js +0 -1
- package/dist/build/parsers/w3cJsonParser.d.ts +0 -6
- package/dist/build/parsers/w3cJsonParser.js +0 -25
- package/dist/removed/testing.json5 +0 -4
- package/guidelines/color.llm.md +0 -16
- package/guidelines/guidelines.llm.md +0 -34
- package/guidelines/motion.llm.md +0 -41
- package/guidelines/spacing.llm.md +0 -20
- package/guidelines/typography.llm.md +0 -14
- package/src/tokens/removed/testing.json5 +0 -4
- package/token-guidelines.llm.md +0 -695
|
@@ -3,7 +3,7 @@ export declare const stringToken: z.ZodObject<{
|
|
|
3
3
|
$description: z.ZodOptional<z.ZodString>;
|
|
4
4
|
$deprecated: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodBoolean]>>;
|
|
5
5
|
$value: z.ZodUnion<readonly [z.ZodString, z.ZodString]>;
|
|
6
|
-
$type: z.ZodLiteral<"
|
|
6
|
+
$type: z.ZodLiteral<"number" | "border" | "color" | "fontFamily" | "fontWeight" | "transition" | "dimension" | "duration" | "gradient" | "shadow" | "typography" | "cubicBezier" | "custom-viewportRange" | "custom-string">;
|
|
7
7
|
$extensions: z.ZodOptional<z.ZodObject<{
|
|
8
8
|
'org.primer.llm': z.ZodOptional<z.ZodObject<{
|
|
9
9
|
usage: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
@@ -6,7 +6,7 @@ import { llmExtension } from './llmExtension.js';
|
|
|
6
6
|
export const stringToken = baseToken
|
|
7
7
|
.extend({
|
|
8
8
|
$value: z.union([z.string(), referenceValue]),
|
|
9
|
-
$type: tokenType('string'),
|
|
9
|
+
$type: tokenType('custom-string'),
|
|
10
10
|
$extensions: z
|
|
11
11
|
.object({
|
|
12
12
|
'org.primer.llm': llmExtension,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import type { TokenType } from './validTokenType.js';
|
|
3
|
-
export declare const tokenType: ($type: TokenType) => z.ZodLiteral<"
|
|
3
|
+
export declare const tokenType: ($type: TokenType) => z.ZodLiteral<"number" | "border" | "color" | "fontFamily" | "fontWeight" | "transition" | "dimension" | "duration" | "gradient" | "shadow" | "typography" | "cubicBezier" | "custom-viewportRange" | "custom-string">;
|
|
@@ -3,11 +3,23 @@ export declare const transitionToken: z.ZodObject<{
|
|
|
3
3
|
$description: z.ZodOptional<z.ZodString>;
|
|
4
4
|
$deprecated: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodBoolean]>>;
|
|
5
5
|
$value: z.ZodUnion<readonly [z.ZodObject<{
|
|
6
|
-
duration: z.ZodUnion<readonly [z.ZodUnion<readonly [z.
|
|
6
|
+
duration: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodObject<{
|
|
7
|
+
value: z.ZodNumber;
|
|
8
|
+
unit: z.ZodEnum<{
|
|
9
|
+
s: "s";
|
|
10
|
+
ms: "ms";
|
|
11
|
+
}>;
|
|
12
|
+
}, z.core.$strict>, z.ZodString]>, z.ZodString]>;
|
|
7
13
|
timingFunction: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodArray<z.ZodNumber>, z.ZodString]>, z.ZodString]>;
|
|
8
|
-
delay: z.ZodOptional<z.ZodUnion<readonly [z.ZodUnion<readonly [z.
|
|
14
|
+
delay: z.ZodOptional<z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodObject<{
|
|
15
|
+
value: z.ZodNumber;
|
|
16
|
+
unit: z.ZodEnum<{
|
|
17
|
+
s: "s";
|
|
18
|
+
ms: "ms";
|
|
19
|
+
}>;
|
|
20
|
+
}, z.core.$strict>, z.ZodString]>, z.ZodString]>>;
|
|
9
21
|
}, z.core.$strip>, z.ZodString]>;
|
|
10
|
-
$type: z.ZodLiteral<"
|
|
22
|
+
$type: z.ZodLiteral<"number" | "border" | "color" | "fontFamily" | "fontWeight" | "transition" | "dimension" | "duration" | "gradient" | "shadow" | "typography" | "cubicBezier" | "custom-viewportRange" | "custom-string">;
|
|
11
23
|
$extensions: z.ZodOptional<z.ZodObject<{
|
|
12
24
|
'org.primer.llm': z.ZodOptional<z.ZodObject<{
|
|
13
25
|
usage: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
export declare const typographyValue: z.ZodObject<{
|
|
3
|
-
fontSize: z.ZodUnion<readonly [z.
|
|
4
|
-
|
|
3
|
+
fontSize: z.ZodUnion<readonly [z.ZodObject<{
|
|
4
|
+
value: z.ZodNumber;
|
|
5
|
+
unit: z.ZodEnum<{
|
|
6
|
+
em: "em";
|
|
7
|
+
px: "px";
|
|
8
|
+
rem: "rem";
|
|
9
|
+
}>;
|
|
10
|
+
}, z.core.$strict>, z.ZodString]>;
|
|
11
|
+
lineHeight: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
|
|
5
12
|
fontWeight: z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>;
|
|
6
13
|
fontFamily: z.ZodUnion<readonly [z.ZodString, z.ZodString]>;
|
|
7
14
|
}, z.core.$strip>;
|
|
@@ -9,12 +16,19 @@ export declare const typographyToken: z.ZodObject<{
|
|
|
9
16
|
$description: z.ZodOptional<z.ZodString>;
|
|
10
17
|
$deprecated: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodBoolean]>>;
|
|
11
18
|
$value: z.ZodUnion<readonly [z.ZodObject<{
|
|
12
|
-
fontSize: z.ZodUnion<readonly [z.
|
|
13
|
-
|
|
19
|
+
fontSize: z.ZodUnion<readonly [z.ZodObject<{
|
|
20
|
+
value: z.ZodNumber;
|
|
21
|
+
unit: z.ZodEnum<{
|
|
22
|
+
em: "em";
|
|
23
|
+
px: "px";
|
|
24
|
+
rem: "rem";
|
|
25
|
+
}>;
|
|
26
|
+
}, z.core.$strict>, z.ZodString]>;
|
|
27
|
+
lineHeight: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
|
|
14
28
|
fontWeight: z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>;
|
|
15
29
|
fontFamily: z.ZodUnion<readonly [z.ZodString, z.ZodString]>;
|
|
16
30
|
}, z.core.$strip>, z.ZodString]>;
|
|
17
|
-
$type: z.ZodLiteral<"
|
|
31
|
+
$type: z.ZodLiteral<"number" | "border" | "color" | "fontFamily" | "fontWeight" | "transition" | "dimension" | "duration" | "gradient" | "shadow" | "typography" | "cubicBezier" | "custom-viewportRange" | "custom-string">;
|
|
18
32
|
$extensions: z.ZodOptional<z.ZodObject<{
|
|
19
33
|
'org.primer.llm': z.ZodOptional<z.ZodObject<{
|
|
20
34
|
usage: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
@@ -7,7 +7,7 @@ import { tokenType } from './tokenType.js';
|
|
|
7
7
|
import { llmExtension } from './llmExtension.js';
|
|
8
8
|
export const typographyValue = z.object({
|
|
9
9
|
fontSize: z.union([dimensionValue, referenceValue]),
|
|
10
|
-
lineHeight: z.union([
|
|
10
|
+
lineHeight: z.union([z.number(), referenceValue]).optional(),
|
|
11
11
|
fontWeight: z.union([fontWeightValue, referenceValue]),
|
|
12
12
|
fontFamily: z.union([z.string().min(1), referenceValue]),
|
|
13
13
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
declare const validTypes: readonly ["color", "cubicBezier", "typography", "dimension", "duration", "border", "shadow", "fontFamily", "fontWeight", "gradient", "number", "string", "transition", "custom-viewportRange"];
|
|
2
|
+
declare const validTypes: readonly ["color", "cubicBezier", "typography", "dimension", "duration", "border", "shadow", "fontFamily", "fontWeight", "gradient", "number", "custom-string", "transition", "custom-viewportRange"];
|
|
3
3
|
export type TokenType = (typeof validTypes)[number];
|
|
4
4
|
/**
|
|
5
5
|
* Recursively validates $type properties in token structure
|
|
@@ -3,7 +3,7 @@ export declare const viewportRangeToken: z.ZodObject<{
|
|
|
3
3
|
$description: z.ZodOptional<z.ZodString>;
|
|
4
4
|
$deprecated: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodBoolean]>>;
|
|
5
5
|
$value: z.ZodUnion<readonly [z.ZodString, z.ZodString]>;
|
|
6
|
-
$type: z.ZodLiteral<"
|
|
6
|
+
$type: z.ZodLiteral<"number" | "border" | "color" | "fontFamily" | "fontWeight" | "transition" | "dimension" | "duration" | "gradient" | "shadow" | "typography" | "cubicBezier" | "custom-viewportRange" | "custom-string">;
|
|
7
7
|
$extensions: z.ZodOptional<z.ZodObject<{
|
|
8
8
|
'org.primer.llm': z.ZodOptional<z.ZodObject<{
|
|
9
9
|
usage: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
import { isBorder } from '../filters/isBorder.js';
|
|
2
|
+
import { parseDimension } from './utilities/parseDimension.js';
|
|
3
|
+
/**
|
|
4
|
+
* @description Converts a W3C dimension object to CSS string, preserving the original unit
|
|
5
|
+
* @param dim - The dimension value in W3C object format or a string
|
|
6
|
+
* @returns CSS dimension string (e.g., "2px", "0.125rem", "1em", "0")
|
|
7
|
+
*/
|
|
8
|
+
const dimensionToCss = (dim) => {
|
|
9
|
+
if (typeof dim === 'string') {
|
|
10
|
+
return dim;
|
|
11
|
+
}
|
|
12
|
+
const { value, unit } = parseDimension(dim);
|
|
13
|
+
if (value === 0) {
|
|
14
|
+
return '0';
|
|
15
|
+
}
|
|
16
|
+
return `${value}${unit}`;
|
|
17
|
+
};
|
|
2
18
|
/**
|
|
3
19
|
* checks if all required properties exist on shadow token
|
|
4
20
|
* @param object - BorderTokenValue
|
|
@@ -33,6 +49,6 @@ export const borderToCss = {
|
|
|
33
49
|
throw new Error(`Invalid border token property ${JSON.stringify(value)}. Must be an object with color, width and style properties.`);
|
|
34
50
|
}
|
|
35
51
|
/* width | style | color */
|
|
36
|
-
return `${value.width} ${value.style} ${value.color}`;
|
|
52
|
+
return `${dimensionToCss(value.width)} ${value.style} ${value.color}`;
|
|
37
53
|
},
|
|
38
54
|
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { Transform } from 'style-dictionary/types';
|
|
2
2
|
/**
|
|
3
|
-
* @description converts dimension tokens value to pixel value without unit
|
|
3
|
+
* @description converts dimension tokens value to pixel value without unit
|
|
4
4
|
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
5
5
|
* @matcher matches all tokens of $type `dimension`
|
|
6
|
-
* @transformer returns a
|
|
6
|
+
* @transformer returns a number for px/rem values, or a string with unit for em values (cannot convert to unitless)
|
|
7
|
+
* @note Expects W3C DTCG format { value: number, unit: "px" | "rem" | "em" }
|
|
7
8
|
*/
|
|
8
9
|
export declare const dimensionToPixelUnitless: Transform;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isDimension } from '../filters/index.js';
|
|
2
|
+
import { parseDimension } from './utilities/parseDimension.js';
|
|
2
3
|
/**
|
|
3
4
|
* @description base font size from options or 16
|
|
4
5
|
* @param options
|
|
@@ -6,22 +7,11 @@ import { isDimension } from '../filters/index.js';
|
|
|
6
7
|
*/
|
|
7
8
|
const getBasePxFontSize = (options) => (options && options.basePxFontSize) || 16;
|
|
8
9
|
/**
|
|
9
|
-
* @description
|
|
10
|
-
* @param value token value
|
|
11
|
-
* @param unit unit string like px or value
|
|
12
|
-
* @returns boolean
|
|
13
|
-
*/
|
|
14
|
-
const hasUnit = (value, unit) => {
|
|
15
|
-
if (typeof value === 'number') {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
return value.indexOf(unit) > -1;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* @description converts dimension tokens value to pixel value without unit, ignores `em` as they are relative to the font size of the parent element
|
|
10
|
+
* @description converts dimension tokens value to pixel value without unit
|
|
22
11
|
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
23
12
|
* @matcher matches all tokens of $type `dimension`
|
|
24
|
-
* @transformer returns a
|
|
13
|
+
* @transformer returns a number for px/rem values, or a string with unit for em values (cannot convert to unitless)
|
|
14
|
+
* @note Expects W3C DTCG format { value: number, unit: "px" | "rem" | "em" }
|
|
25
15
|
*/
|
|
26
16
|
export const dimensionToPixelUnitless = {
|
|
27
17
|
name: 'dimension/pixelUnitless',
|
|
@@ -31,19 +21,25 @@ export const dimensionToPixelUnitless = {
|
|
|
31
21
|
transform: (token, config, options) => {
|
|
32
22
|
const valueProp = options.usesDtcg ? '$value' : 'value';
|
|
33
23
|
const baseFont = getBasePxFontSize(config);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
24
|
+
try {
|
|
25
|
+
const { value, unit } = parseDimension(token[valueProp]);
|
|
26
|
+
if (value === 0) {
|
|
27
|
+
return 0;
|
|
28
|
+
}
|
|
29
|
+
// rem values convert to px
|
|
30
|
+
if (unit === 'rem') {
|
|
31
|
+
return value * baseFont;
|
|
32
|
+
}
|
|
33
|
+
// em values pass through as string (relative to parent, cannot convert to unitless px)
|
|
34
|
+
if (unit === 'em') {
|
|
35
|
+
return `${value}em`;
|
|
36
|
+
}
|
|
37
|
+
// px values return the number directly
|
|
38
|
+
return value;
|
|
43
39
|
}
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
catch (error) {
|
|
41
|
+
const originalMessage = error instanceof Error ? error.message : String(error);
|
|
42
|
+
throw new Error(`Invalid dimension token: '${token.path.join('.')}: ${JSON.stringify(token[valueProp])}' - ${originalMessage}\n`);
|
|
46
43
|
}
|
|
47
|
-
return token[valueProp];
|
|
48
44
|
},
|
|
49
45
|
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { Transform } from 'style-dictionary/types';
|
|
2
2
|
/**
|
|
3
|
-
* @description converts dimension tokens value to `rem
|
|
3
|
+
* @description converts dimension tokens value to `rem`
|
|
4
4
|
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
5
5
|
* @matcher matches all tokens of $type `dimension`
|
|
6
6
|
* @transformer returns a `rem` string
|
|
7
|
+
* @note Expects W3C DTCG format { value: number, unit: "px" | "rem" | "em" }
|
|
7
8
|
*/
|
|
8
9
|
export declare const dimensionToRem: Transform;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isDimension } from '../filters/index.js';
|
|
2
|
+
import { parseDimension } from './utilities/parseDimension.js';
|
|
2
3
|
/**
|
|
3
4
|
* @description base font size from options or 16
|
|
4
5
|
* @param options
|
|
@@ -6,22 +7,11 @@ import { isDimension } from '../filters/index.js';
|
|
|
6
7
|
*/
|
|
7
8
|
const getBasePxFontSize = (options) => (options && options.basePxFontSize) || 16;
|
|
8
9
|
/**
|
|
9
|
-
* @description
|
|
10
|
-
* @param value token value
|
|
11
|
-
* @param unit unit string like px or value
|
|
12
|
-
* @returns boolean
|
|
13
|
-
*/
|
|
14
|
-
const hasUnit = (value, unit) => {
|
|
15
|
-
if (typeof value === 'number') {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
return value.indexOf(unit) > -1;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* @description converts dimension tokens value to `rem`, ignores `em` as they are relative to the font size of the parent element
|
|
10
|
+
* @description converts dimension tokens value to `rem`
|
|
22
11
|
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
23
12
|
* @matcher matches all tokens of $type `dimension`
|
|
24
13
|
* @transformer returns a `rem` string
|
|
14
|
+
* @note Expects W3C DTCG format { value: number, unit: "px" | "rem" | "em" }
|
|
25
15
|
*/
|
|
26
16
|
export const dimensionToRem = {
|
|
27
17
|
name: 'dimension/rem',
|
|
@@ -31,16 +21,25 @@ export const dimensionToRem = {
|
|
|
31
21
|
transform: (token, config, options) => {
|
|
32
22
|
const valueProp = options.usesDtcg ? '$value' : 'value';
|
|
33
23
|
const baseFont = getBasePxFontSize(config);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
24
|
+
try {
|
|
25
|
+
const { value, unit } = parseDimension(token[valueProp]);
|
|
26
|
+
if (value === 0) {
|
|
27
|
+
return '0';
|
|
28
|
+
}
|
|
29
|
+
// rem values pass through unchanged
|
|
30
|
+
if (unit === 'rem') {
|
|
31
|
+
return `${value}rem`;
|
|
32
|
+
}
|
|
33
|
+
// em values pass through unchanged (relative to parent, cannot convert)
|
|
34
|
+
if (unit === 'em') {
|
|
35
|
+
return `${value}em`;
|
|
36
|
+
}
|
|
37
|
+
// px values convert to rem
|
|
38
|
+
return `${value / baseFont}rem`;
|
|
40
39
|
}
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
catch (error) {
|
|
41
|
+
const details = error instanceof Error && error.message ? ` - ${error.message}` : error ? ` - ${String(error)}` : '';
|
|
42
|
+
throw new Error(`Invalid dimension token: '${token.name}: ${JSON.stringify(token[valueProp])}' is not valid and cannot be transformed to 'rem'${details}\n`);
|
|
43
43
|
}
|
|
44
|
-
return `${floatVal / baseFont}rem`;
|
|
45
44
|
},
|
|
46
45
|
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { Transform } from 'style-dictionary/types';
|
|
2
2
|
/**
|
|
3
|
-
* @description converts dimension tokens value to `rem
|
|
3
|
+
* @description converts dimension tokens value to an array with both `rem` and `px` values
|
|
4
4
|
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
5
5
|
* @matcher matches all tokens of $type `dimension`
|
|
6
6
|
* @transformer returns an array with the `rem` and `pixel` string
|
|
7
|
+
* @note Expects W3C DTCG format { value: number, unit: "px" | "rem" | "em" }
|
|
7
8
|
*/
|
|
8
9
|
export declare const dimensionToRemPxArray: Transform;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isDimension } from '../filters/index.js';
|
|
2
|
+
import { parseDimension } from './utilities/parseDimension.js';
|
|
2
3
|
/**
|
|
3
4
|
* @description base font size from options or 16
|
|
4
5
|
* @param options
|
|
@@ -6,22 +7,11 @@ import { isDimension } from '../filters/index.js';
|
|
|
6
7
|
*/
|
|
7
8
|
const getBasePxFontSize = (options) => (options && options.basePxFontSize) || 16;
|
|
8
9
|
/**
|
|
9
|
-
* @description
|
|
10
|
-
* @param value token value
|
|
11
|
-
* @param unit unit string like px or value
|
|
12
|
-
* @returns boolean
|
|
13
|
-
*/
|
|
14
|
-
const hasUnit = (value, unit) => {
|
|
15
|
-
if (typeof value === 'number') {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
return value.indexOf(unit) > -1;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* @description converts dimension tokens value to `rem`, ignores `em` as they are relative to the font size of the parent element
|
|
10
|
+
* @description converts dimension tokens value to an array with both `rem` and `px` values
|
|
22
11
|
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
23
12
|
* @matcher matches all tokens of $type `dimension`
|
|
24
13
|
* @transformer returns an array with the `rem` and `pixel` string
|
|
14
|
+
* @note Expects W3C DTCG format { value: number, unit: "px" | "rem" | "em" }
|
|
25
15
|
*/
|
|
26
16
|
export const dimensionToRemPxArray = {
|
|
27
17
|
name: 'dimension/remPxArray',
|
|
@@ -31,16 +21,25 @@ export const dimensionToRemPxArray = {
|
|
|
31
21
|
transform: (token, config, options) => {
|
|
32
22
|
const valueProp = options.usesDtcg ? '$value' : 'value';
|
|
33
23
|
const baseFont = getBasePxFontSize(config);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
24
|
+
try {
|
|
25
|
+
const { value, unit } = parseDimension(token[valueProp]);
|
|
26
|
+
if (value === 0) {
|
|
27
|
+
return ['0', '0'];
|
|
28
|
+
}
|
|
29
|
+
// em values pass through unchanged (relative to parent, cannot convert)
|
|
30
|
+
if (unit === 'em') {
|
|
31
|
+
return [`${value}em`, `${value}em`];
|
|
32
|
+
}
|
|
33
|
+
// rem values pass through, convert to px for second value
|
|
34
|
+
if (unit === 'rem') {
|
|
35
|
+
return [`${value}rem`, `${value * baseFont}px`];
|
|
36
|
+
}
|
|
37
|
+
// px values convert to rem for first value
|
|
38
|
+
return [`${value / baseFont}rem`, `${value}px`];
|
|
40
39
|
}
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
catch (error) {
|
|
41
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
42
|
+
throw new Error(`Invalid dimension token: '${token.name}: ${JSON.stringify(token[valueProp])}' is not valid and cannot be transformed to 'rem' - ${errorMessage}\n`);
|
|
43
43
|
}
|
|
44
|
-
return [`${floatVal / baseFont}rem`, `${floatVal}px`];
|
|
45
44
|
},
|
|
46
45
|
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { Transform } from 'style-dictionary/types';
|
|
2
2
|
/**
|
|
3
|
-
* @description converts duration tokens
|
|
3
|
+
* @description converts duration tokens to css duration string
|
|
4
4
|
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
5
5
|
* @matcher matches all tokens of $type `duration`
|
|
6
6
|
* @transformer returns a css duration
|
|
7
|
+
* @note W3C DTCG format: { value: number, unit: "ms" | "s" }
|
|
7
8
|
*/
|
|
8
9
|
export declare const durationToCss: Transform;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { isDuration } from '../filters/index.js';
|
|
2
2
|
/**
|
|
3
|
-
* @description converts duration tokens
|
|
3
|
+
* @description converts duration tokens to css duration string
|
|
4
4
|
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
5
5
|
* @matcher matches all tokens of $type `duration`
|
|
6
6
|
* @transformer returns a css duration
|
|
7
|
+
* @note W3C DTCG format: { value: number, unit: "ms" | "s" }
|
|
7
8
|
*/
|
|
8
9
|
export const durationToCss = {
|
|
9
10
|
name: 'duration/css',
|
|
@@ -12,18 +13,24 @@ export const durationToCss = {
|
|
|
12
13
|
filter: isDuration,
|
|
13
14
|
transform: (token, _config, options) => {
|
|
14
15
|
const valueProp = options.usesDtcg ? '$value' : 'value';
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const tokenValue = token[valueProp];
|
|
17
|
+
// Validate W3C DTCG object format: { value: number, unit: "ms" | "s" }
|
|
18
|
+
if (typeof tokenValue !== 'object' || tokenValue === null || !('value' in tokenValue) || !('unit' in tokenValue)) {
|
|
19
|
+
throw new Error(`duration token value must be an object with "value" and "unit" properties (W3C DTCG format). Invalid token: ${token.name} with value: ${JSON.stringify(tokenValue)}`);
|
|
18
20
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
const { value, unit } = tokenValue;
|
|
22
|
+
// Validate unit
|
|
23
|
+
if (unit !== 'ms' && unit !== 's') {
|
|
24
|
+
throw new Error(`duration token unit must be "ms" or "s", invalid token: ${token.name} with unit: ${unit}`);
|
|
25
|
+
}
|
|
26
|
+
// Validate value is a finite, non-negative number
|
|
27
|
+
if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) {
|
|
28
|
+
throw new Error(`duration token value must be a finite, non-negative number, invalid token: ${token.name} with value: ${value}`);
|
|
29
|
+
}
|
|
30
|
+
// Convert ms >= 1000 to seconds for cleaner output
|
|
31
|
+
if (unit === 'ms' && value >= 1000) {
|
|
32
|
+
return `${value / 1000}s`;
|
|
25
33
|
}
|
|
26
|
-
// return value
|
|
27
34
|
return `${value}${unit}`;
|
|
28
35
|
},
|
|
29
36
|
};
|
|
@@ -3,6 +3,17 @@ import { isShadow } from '../filters/index.js';
|
|
|
3
3
|
import { alpha } from './utilities/alpha.js';
|
|
4
4
|
import { checkRequiredTokenProperties } from './utilities/checkRequiredTokenProperties.js';
|
|
5
5
|
import { getTokenValue } from './utilities/getTokenValue.js';
|
|
6
|
+
/**
|
|
7
|
+
* @description Converts a W3C dimension object to CSS string
|
|
8
|
+
* @param dim - The dimension value in W3C object format
|
|
9
|
+
* @returns CSS dimension string (e.g., "16px", "1rem", "0")
|
|
10
|
+
*/
|
|
11
|
+
const dimensionToCss = (dim) => {
|
|
12
|
+
if (dim.value === 0) {
|
|
13
|
+
return '0';
|
|
14
|
+
}
|
|
15
|
+
return `${dim.value}${dim.unit}`;
|
|
16
|
+
};
|
|
6
17
|
/**
|
|
7
18
|
* @description converts w3c shadow tokens in css shadow string
|
|
8
19
|
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
@@ -27,7 +38,7 @@ export const shadowToCss = {
|
|
|
27
38
|
return shadow;
|
|
28
39
|
checkRequiredTokenProperties(shadow, ['color', 'offsetX', 'offsetY', 'blur', 'spread']);
|
|
29
40
|
/*css box shadow: inset? | offset-x | offset-y | blur-radius | spread-radius | color */
|
|
30
|
-
return `${shadow.inset === true ? 'inset ' : ''}${shadow.offsetX} ${shadow.offsetY} ${shadow.blur} ${shadow.spread} ${toHex(alpha(getTokenValue(Object.assign(Object.assign({}, token), { [valueProp]: shadow }), 'color'), shadow.alpha || 1, token, config))}`;
|
|
41
|
+
return `${shadow.inset === true ? 'inset ' : ''}${dimensionToCss(shadow.offsetX)} ${dimensionToCss(shadow.offsetY)} ${dimensionToCss(shadow.blur)} ${dimensionToCss(shadow.spread)} ${toHex(alpha(getTokenValue(Object.assign(Object.assign({}, token), { [valueProp]: shadow }), 'color'), shadow.alpha || 1, token, config))}`;
|
|
31
42
|
})
|
|
32
43
|
.join(', ');
|
|
33
44
|
},
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { DimensionTokenValue } from '../../types/dimensionTokenValue.js';
|
|
2
|
+
/**
|
|
3
|
+
* @description Parses and validates a dimension value in W3C DTCG object format
|
|
4
|
+
* @param input - The dimension value in W3C object format { value: number, unit: "px" | "rem" | "em" }
|
|
5
|
+
* @returns Validated DimensionTokenValue
|
|
6
|
+
* @throws Error if the input is not a valid W3C dimension object
|
|
7
|
+
*
|
|
8
|
+
* W3C DTCG format: { value: 16, unit: "px" }
|
|
9
|
+
* @note `em` is not in the W3C spec but is supported for practical use
|
|
10
|
+
* @link https://www.designtokens.org/tr/drafts/format/#dimension
|
|
11
|
+
*/
|
|
12
|
+
export declare const parseDimension: (input: DimensionTokenValue) => DimensionTokenValue;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Parses and validates a dimension value in W3C DTCG object format
|
|
3
|
+
* @param input - The dimension value in W3C object format { value: number, unit: "px" | "rem" | "em" }
|
|
4
|
+
* @returns Validated DimensionTokenValue
|
|
5
|
+
* @throws Error if the input is not a valid W3C dimension object
|
|
6
|
+
*
|
|
7
|
+
* W3C DTCG format: { value: 16, unit: "px" }
|
|
8
|
+
* @note `em` is not in the W3C spec but is supported for practical use
|
|
9
|
+
* @link https://www.designtokens.org/tr/drafts/format/#dimension
|
|
10
|
+
*/
|
|
11
|
+
export const parseDimension = (input) => {
|
|
12
|
+
// Runtime validation for W3C DTCG object format
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
14
|
+
if (typeof input !== 'object' || input === null) {
|
|
15
|
+
throw new Error(`Invalid dimension value: ${JSON.stringify(input)} - must be a W3C DTCG dimension object with "value" and "unit" properties`);
|
|
16
|
+
}
|
|
17
|
+
const inputObj = input;
|
|
18
|
+
if (!('value' in inputObj) || !('unit' in inputObj)) {
|
|
19
|
+
throw new Error(`Invalid dimension value: ${JSON.stringify(input)} - must be a W3C DTCG dimension object with "value" and "unit" properties`);
|
|
20
|
+
}
|
|
21
|
+
const { value, unit } = input;
|
|
22
|
+
if (typeof value !== 'number' || !Number.isFinite(value)) {
|
|
23
|
+
throw new Error(`Invalid dimension value: ${JSON.stringify(input)} - value must be a finite number`);
|
|
24
|
+
}
|
|
25
|
+
// Runtime check - unit could be invalid at runtime even if types say otherwise
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
27
|
+
if (unit !== 'px' && unit !== 'rem' && unit !== 'em') {
|
|
28
|
+
throw new Error(`Invalid dimension unit: ${String(unit)} - must be "px", "rem", or "em"`);
|
|
29
|
+
}
|
|
30
|
+
return { value, unit };
|
|
31
|
+
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type {DimensionTokenValue} from './dimensionTokenValue.js'
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Type definition for w3c border composite token value
|
|
3
5
|
* @link https://design-tokens.github.io/community-group/format/#border
|
|
@@ -5,6 +7,6 @@
|
|
|
5
7
|
export type StrokeStyleString = 'solid' | 'dashed' | 'dotted' | 'double' | 'groove' | 'ridge' | 'outset' | 'inset'
|
|
6
8
|
export type BorderTokenValue = {
|
|
7
9
|
color: string
|
|
8
|
-
width: string
|
|
10
|
+
width: string | DimensionTokenValue
|
|
9
11
|
style: StrokeStyleString
|
|
10
12
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* W3C DTCG dimension token value format
|
|
3
|
+
* @link https://www.designtokens.org/tr/drafts/format/#dimension
|
|
4
|
+
* @note `em` is not in the W3C spec but is supported for practical use
|
|
5
|
+
*/
|
|
6
|
+
export type DimensionTokenValue = {
|
|
7
|
+
value: number
|
|
8
|
+
unit: 'px' | 'rem' | 'em'
|
|
9
|
+
}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
import type {DimensionTokenValue} from './dimensionTokenValue.js'
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Type definition for w3c shadow composite token value
|
|
3
5
|
* @link https://design-tokens.github.io/community-group/format/#shadow
|
|
4
6
|
*/
|
|
5
7
|
export type ShadowTokenValue = {
|
|
6
8
|
color: string
|
|
7
|
-
offsetX:
|
|
8
|
-
offsetY:
|
|
9
|
-
blur:
|
|
10
|
-
spread:
|
|
9
|
+
offsetX: DimensionTokenValue
|
|
10
|
+
offsetY: DimensionTokenValue
|
|
11
|
+
blur: DimensionTokenValue
|
|
12
|
+
spread: DimensionTokenValue
|
|
11
13
|
// custom non w3c values
|
|
12
14
|
inset?: boolean
|
|
13
15
|
alpha?: number
|