@wordpress/theme 0.3.1-next.8b30e05b0.0 → 0.4.0
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/README.md +82 -18
- package/bin/generate-primitive-tokens/index.ts +26 -33
- package/bin/terrazzo-plugin-mode-overrides/index.ts +208 -0
- package/build/color-ramps/lib/default-ramps.js +65 -65
- package/build/color-ramps/lib/default-ramps.js.map +1 -1
- package/build/color-ramps/lib/find-color-with-constraints.js.map +2 -2
- package/build/color-ramps/lib/index.js.map +2 -2
- package/build/color-ramps/lib/taper-chroma.js +18 -44
- package/build/color-ramps/lib/taper-chroma.js.map +2 -2
- package/build/prebuilt/js/design-tokens.js +32 -6
- package/build/prebuilt/js/design-tokens.js.map +2 -2
- package/build/prebuilt/ts/color-tokens.js +35 -13
- package/build/prebuilt/ts/color-tokens.js.map +2 -2
- package/build-module/color-ramps/lib/default-ramps.js +65 -65
- package/build-module/color-ramps/lib/default-ramps.js.map +1 -1
- package/build-module/color-ramps/lib/find-color-with-constraints.js.map +2 -2
- package/build-module/color-ramps/lib/index.js.map +2 -2
- package/build-module/color-ramps/lib/taper-chroma.js +19 -46
- package/build-module/color-ramps/lib/taper-chroma.js.map +2 -2
- package/build-module/prebuilt/js/design-tokens.js +32 -6
- package/build-module/prebuilt/js/design-tokens.js.map +2 -2
- package/build-module/prebuilt/ts/color-tokens.js +35 -13
- package/build-module/prebuilt/ts/color-tokens.js.map +2 -2
- package/build-types/color-ramps/lib/find-color-with-constraints.d.ts +3 -4
- package/build-types/color-ramps/lib/find-color-with-constraints.d.ts.map +1 -1
- package/build-types/color-ramps/lib/taper-chroma.d.ts +4 -4
- package/build-types/color-ramps/lib/taper-chroma.d.ts.map +1 -1
- package/build-types/prebuilt/ts/color-tokens.d.ts.map +1 -1
- package/docs/ds-tokens.md +35 -9
- package/package.json +5 -5
- package/src/color-ramps/lib/default-ramps.ts +65 -65
- package/src/color-ramps/lib/find-color-with-constraints.ts +11 -7
- package/src/color-ramps/lib/index.ts +4 -4
- package/src/color-ramps/lib/taper-chroma.ts +32 -63
- package/src/prebuilt/css/design-tokens.css +72 -28
- package/src/prebuilt/js/design-tokens.js +32 -6
- package/src/prebuilt/ts/color-tokens.ts +31 -9
- package/terrazzo.config.ts +11 -14
- package/tokens/border.json +44 -22
- package/tokens/color.json +1160 -630
- package/tokens/dimension.json +112 -52
- package/tokens/elevation.json +1 -1
- package/tokens/modes/border.high-dpi.json +15 -0
- package/tokens/modes/dimension.comfortable.json +54 -0
- package/tokens/modes/dimension.compact.json +54 -0
- package/tokens/typography.json +1 -1
- package/tsconfig.bin.tsbuildinfo +1 -1
- package/tsconfig.src.json +1 -1
- package/tsconfig.src.tsbuildinfo +1 -1
- package/bin/terrazzo-plugin-figma-ds-token-manager/index.ts +0 -217
- package/bin/terrazzo-plugin-figma-ds-token-manager/lib.ts +0 -1
- package/build/prebuilt/json/figma.json +0 -715
- package/build/token-id.js +0 -30
- package/build/token-id.js.map +0 -7
- package/build/types/css-modules.d.js +0 -1
- package/build/types/css-modules.d.js.map +0 -7
- package/build-module/prebuilt/json/figma.json +0 -715
- package/build-module/token-id.js +0 -6
- package/build-module/token-id.js.map +0 -7
- package/build-module/types/css-modules.d.js +0 -1
- package/build-module/types/css-modules.d.js.map +0 -7
- package/build-types/token-id.d.ts +0 -9
- package/build-types/token-id.d.ts.map +0 -1
- package/src/prebuilt/json/figma.json +0 -715
- package/src/test/token-id.test.ts +0 -12
- package/src/token-id.ts +0 -9
- package/src/types/css-modules.d.ts +0 -4
package/README.md
CHANGED
|
@@ -13,27 +13,91 @@ A theming package that's part of the WordPress Design System. It has two parts:
|
|
|
13
13
|
|
|
14
14
|
In the **[Design Tokens Reference](docs/ds-tokens.md)** document there is a complete reference of all available design tokens including colors, spacing, typography, and more.
|
|
15
15
|
|
|
16
|
-
###
|
|
16
|
+
### Architecture
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
Internally, the design system uses a tiered token architecture:
|
|
19
|
+
|
|
20
|
+
- **Primitive tokens**: Raw values like hex colors or pixel dimensions which are what the browsers eventually interpret. These live in the `/tokens` directory as JSON source files and are an internal implementation detail.
|
|
21
|
+
- **Semantic tokens**: Purpose-driven tokens with meaningful names that reference primitives and describe their intended use. These are what get exported as CSS custom properties.
|
|
22
|
+
|
|
23
|
+
This separation allows the design system to maintain consistency while providing flexibility, since primitive values can be updated without changing the semantic token names that developers use in their code.
|
|
24
|
+
|
|
25
|
+
### Design Tokens
|
|
26
|
+
|
|
27
|
+
Design tokens are the visual design atoms of a design system. They are named entities that store visual design attributes like colors, spacing, typography, and shadows. They serve as a single source of truth that bridges design and development, ensuring consistency across platforms and making it easy to maintain and evolve the visual language of an application.
|
|
28
|
+
|
|
29
|
+
Rather than hardcoding values like `#3858e9` or `16px` throughout your code, tokens provide semantic names like `--wpds-color-bg-interactive-brand-strong` or `--wpds-dimension-padding-surface-md` that describe the purpose and context of the value. This makes code more maintainable and allows the design system to evolve. When a token's value changes, all components using that token automatically reflect the update.
|
|
30
|
+
|
|
31
|
+
#### Structure
|
|
32
|
+
|
|
33
|
+
The design system follows the [Design Tokens Community Group (DTCG)](https://design-tokens.github.io/community-group/format/) specification and organizes tokens into distinct types based on what kind of visual property they represent. Token definitions are stored as JSON files in the `/tokens` directory:
|
|
34
|
+
|
|
35
|
+
| File | Description |
|
|
36
|
+
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------- |
|
|
37
|
+
| `color.json` | Color palettes including primitive color ramps and semantic color tokens for backgrounds, foregrounds, strokes, and focus states |
|
|
38
|
+
| `dimension.json` | Spacing scale and semantic spacing tokens for padding, margins, and sizing |
|
|
39
|
+
| `typography.json` | Font family stacks, font sizes, and line heights |
|
|
40
|
+
| `border.json` | Border radius and width values |
|
|
41
|
+
| `elevation.json` | Shadow definitions for creating depth and layering |
|
|
42
|
+
|
|
43
|
+
Each JSON file contains both primitive and semantic token definitions in a hierarchical structure. These files are the source of truth for the design system and are processed during the build step to generate CSS custom properties and other output formats in `/src/prebuilt`.
|
|
44
|
+
|
|
45
|
+
#### Token Naming
|
|
46
|
+
|
|
47
|
+
Semantic tokens follow a consistent naming pattern:
|
|
19
48
|
|
|
20
49
|
```
|
|
21
|
-
--wpds-<
|
|
50
|
+
--wpds-<type>-<property>-<target>[-<modifier>]
|
|
22
51
|
```
|
|
23
52
|
|
|
24
|
-
**
|
|
53
|
+
**Type** indicates what kind of value it represents, usually mapping to a DTCG token type.
|
|
25
54
|
|
|
26
|
-
| Value
|
|
27
|
-
|
|
|
28
|
-
| `
|
|
29
|
-
| `
|
|
30
|
-
| `
|
|
31
|
-
| `
|
|
32
|
-
| `
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
|
55
|
+
| Value | Description |
|
|
56
|
+
| ----------- | ------------------------------------------------------------------------------ |
|
|
57
|
+
| `color` | Color values for backgrounds, foregrounds, and strokes |
|
|
58
|
+
| `dimension` | Spacing, sizing, and other measurable lengths (e.g., padding, margins, widths) |
|
|
59
|
+
| `border` | Border properties like radius and width |
|
|
60
|
+
| `elevation` | Shadow definitions for layering and depth |
|
|
61
|
+
| `font` | Typography properties like family, size, and line-height |
|
|
62
|
+
|
|
63
|
+
**Property** is the specific design property being defined.
|
|
64
|
+
|
|
65
|
+
| Value | Description |
|
|
66
|
+
| -------- | ---------------------------------- |
|
|
67
|
+
| `bg` | Background color |
|
|
68
|
+
| `fg` | Foreground color (text and icons) |
|
|
69
|
+
| `stroke` | Border and outline color |
|
|
70
|
+
| `padding`| Internal spacing within an element |
|
|
71
|
+
| `gap` | Spacing between elements |
|
|
72
|
+
| `radius` | Border radius for rounded corners |
|
|
73
|
+
| `width` | Border width |
|
|
74
|
+
| `size` | Font size |
|
|
75
|
+
| `family` | Font family |
|
|
76
|
+
|
|
77
|
+
**Target** is the component or element type the token applies to.
|
|
78
|
+
|
|
79
|
+
| Value | Description |
|
|
80
|
+
| ------------- | ------------------------------------------------------------ |
|
|
81
|
+
| `surface` | Container or layout backgrounds and borders |
|
|
82
|
+
| `interactive` | Interactive elements like buttons, inputs, and controls |
|
|
83
|
+
| `content` | Static content like text and icons |
|
|
84
|
+
| `track` | Track components like scrollbars and slider tracks |
|
|
85
|
+
| `thumb` | Thumb components like scrollbar thumbs and slider handles |
|
|
86
|
+
| `focus` | Focus indicators and rings |
|
|
87
|
+
|
|
88
|
+
**Modifier** is an optional size or intensity modifier.
|
|
89
|
+
|
|
90
|
+
| Value | Description |
|
|
91
|
+
| ----------------------------------- | -------------------- |
|
|
92
|
+
| `2xs`, `xs`, `sm`, `md`, `lg`, `xl` | Size scale modifiers |
|
|
93
|
+
|
|
94
|
+
#### Color Token Modifiers
|
|
95
|
+
|
|
96
|
+
Color tokens extend the base pattern with additional modifiers for tone, emphasis, and state:
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
--wpds-color-<property>-<target>-<tone>[-<emphasis>][-<state>]
|
|
100
|
+
```
|
|
37
101
|
|
|
38
102
|
**Tone** defines the semantic intent of the color.
|
|
39
103
|
|
|
@@ -53,9 +117,9 @@ The design system defines color tokens using the following naming scheme:
|
|
|
53
117
|
|
|
54
118
|
**Emphasis** adjusts color strength relative to the base tone, if specified. The default is a normal emphasis.
|
|
55
119
|
|
|
56
|
-
| Value | Description
|
|
57
|
-
| -------------------- |
|
|
58
|
-
| `strong` | Higher contrast and/or elevated emphasis.
|
|
120
|
+
| Value | Description |
|
|
121
|
+
| -------------------- | ----------------------------------------------- |
|
|
122
|
+
| `strong` | Higher contrast and/or elevated emphasis. |
|
|
59
123
|
| `weak` | Subtle variant for secondary or muted elements. |
|
|
60
124
|
|
|
61
125
|
**State** represents the interactive state of the element, if specified. The default is an idle state.
|
|
@@ -4,14 +4,7 @@
|
|
|
4
4
|
import fs from 'fs';
|
|
5
5
|
import path from 'path';
|
|
6
6
|
import { fileURLToPath } from 'url';
|
|
7
|
-
import {
|
|
8
|
-
parse,
|
|
9
|
-
to,
|
|
10
|
-
serialize,
|
|
11
|
-
OKLCH,
|
|
12
|
-
sRGB,
|
|
13
|
-
type PlainColorObject,
|
|
14
|
-
} from 'colorjs.io/fn';
|
|
7
|
+
import { parse, to, serialize, sRGB } from 'colorjs.io/fn';
|
|
15
8
|
|
|
16
9
|
/**
|
|
17
10
|
* Internal dependencies
|
|
@@ -29,29 +22,28 @@ const __dirname = path.dirname( __filename );
|
|
|
29
22
|
// Path to the color.json file
|
|
30
23
|
const colorJsonPath = path.join( __dirname, '../../tokens/color.json' );
|
|
31
24
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Rounds a given hex value (0-255) to 3 decimal places.
|
|
27
|
+
*
|
|
28
|
+
* 3 decimal places is the minimum precision for lossless hex serialization.
|
|
29
|
+
* With 3 decimal places rounding to the nearest 0.001, the maximum rounding
|
|
30
|
+
* error is 0.0005. With 256 possible hex values, 0.0005 × 256 = 0.128,
|
|
31
|
+
* guaranteeing the rounded value stays within 0.5 of the original value.
|
|
32
|
+
*
|
|
33
|
+
* @param n - The hex value to round.
|
|
34
|
+
* @return The rounded hex value.
|
|
35
|
+
*/
|
|
36
|
+
const roundHexComponent = ( n: number ) => Math.round( n * 1000 ) / 1000;
|
|
40
37
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
colorSpace: 'oklch',
|
|
44
|
-
components: [
|
|
45
|
-
Math.floor( 10000 * coords[ 0 ] ) / 10000, // l
|
|
46
|
-
coords[ 1 ], // c
|
|
47
|
-
isNaN( coords[ 2 ] ) ? 0 : coords[ 2 ], // h
|
|
48
|
-
],
|
|
49
|
-
...( parsed.alpha < 1 ? { alpha: parsed.alpha } : undefined ),
|
|
50
|
-
hex: serialize( to( parsed, sRGB ), { format: 'hex' } ),
|
|
51
|
-
};
|
|
52
|
-
}
|
|
38
|
+
const transformColorStringToDTCGValue = ( color: string ) => {
|
|
39
|
+
const parsed = to( parse( color ), sRGB );
|
|
53
40
|
|
|
54
|
-
return
|
|
41
|
+
return {
|
|
42
|
+
colorSpace: 'srgb',
|
|
43
|
+
components: parsed.coords.map( roundHexComponent ),
|
|
44
|
+
...( parsed.alpha < 1 ? { alpha: parsed.alpha } : undefined ),
|
|
45
|
+
hex: serialize( parsed, { format: 'hex' } ),
|
|
46
|
+
};
|
|
55
47
|
};
|
|
56
48
|
|
|
57
49
|
// Main function
|
|
@@ -82,13 +74,14 @@ function generatePrimitiveColorTokens() {
|
|
|
82
74
|
},
|
|
83
75
|
...accentRamps,
|
|
84
76
|
].forEach( ( { scaleName, ramp } ) => {
|
|
85
|
-
colorJson
|
|
77
|
+
colorJson[ 'wpds-color' ].primitive[ scaleName ] = {};
|
|
86
78
|
for ( const [ tokenName, tokenValue ] of Object.entries(
|
|
87
79
|
ramp.ramp
|
|
88
80
|
) ) {
|
|
89
|
-
colorJson
|
|
90
|
-
|
|
91
|
-
|
|
81
|
+
colorJson[ 'wpds-color' ].primitive[ scaleName ][ tokenName ] =
|
|
82
|
+
{
|
|
83
|
+
$value: transformColorStringToDTCGValue( tokenValue ),
|
|
84
|
+
};
|
|
92
85
|
}
|
|
93
86
|
} );
|
|
94
87
|
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { basename } from 'node:path';
|
|
5
|
+
import type { Plugin } from '@terrazzo/parser';
|
|
6
|
+
|
|
7
|
+
type DTCGPrimitiveValue =
|
|
8
|
+
| string
|
|
9
|
+
| number
|
|
10
|
+
| boolean
|
|
11
|
+
| { value: number; unit: string }
|
|
12
|
+
| { r: number; g: number; b: number; a?: number };
|
|
13
|
+
|
|
14
|
+
type DTCGValue = DTCGPrimitiveValue | Record< string, DTCGPrimitiveValue >;
|
|
15
|
+
|
|
16
|
+
interface DTCGExtensions {
|
|
17
|
+
[ key: string ]: unknown;
|
|
18
|
+
mode?: Record< string, DTCGValue >;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @see https://tr.designtokens.org/format/
|
|
23
|
+
*/
|
|
24
|
+
interface DTCGToken {
|
|
25
|
+
$value: DTCGValue;
|
|
26
|
+
$type?: string;
|
|
27
|
+
$description?: string;
|
|
28
|
+
$extensions?: DTCGExtensions;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface DTCGGroup {
|
|
32
|
+
$type?: string;
|
|
33
|
+
$description?: string;
|
|
34
|
+
$extensions?: DTCGExtensions;
|
|
35
|
+
[ key: string ]:
|
|
36
|
+
| DTCGToken
|
|
37
|
+
| DTCGGroup
|
|
38
|
+
| string
|
|
39
|
+
| DTCGExtensions
|
|
40
|
+
| undefined;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
type DTCGDocument = Record< string, DTCGGroup >;
|
|
44
|
+
|
|
45
|
+
interface ModeOverride {
|
|
46
|
+
path: string[];
|
|
47
|
+
$value: DTCGValue;
|
|
48
|
+
$type?: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Type guard to check if a value is a DTCG token (has $value).
|
|
53
|
+
*
|
|
54
|
+
* @param value - The value to check.
|
|
55
|
+
* @return True if the value is a DTCG token.
|
|
56
|
+
*/
|
|
57
|
+
function isDTCGToken( value: DTCGToken | DTCGGroup ): value is DTCGToken {
|
|
58
|
+
return '$value' in value;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Set a nested value in an object from a path array.
|
|
63
|
+
*
|
|
64
|
+
* @param object - The object to modify.
|
|
65
|
+
* @param pathParts - The path at which to set the value.
|
|
66
|
+
* @param value - The value to set.
|
|
67
|
+
*/
|
|
68
|
+
function setNestedValue(
|
|
69
|
+
object: Record< string, unknown >,
|
|
70
|
+
pathParts: string[],
|
|
71
|
+
value: any
|
|
72
|
+
): void {
|
|
73
|
+
let current = object;
|
|
74
|
+
|
|
75
|
+
for ( let i = 0; i < pathParts.length - 1; i++ ) {
|
|
76
|
+
const key = pathParts[ i ];
|
|
77
|
+
|
|
78
|
+
if ( ! ( key in current ) ) {
|
|
79
|
+
current[ key ] = {};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
current = current[ key ] as Record< string, unknown >;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
current[ pathParts[ pathParts.length - 1 ] ] = value;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Recursively extracts mode overrides from a DTCG token tree.
|
|
90
|
+
*
|
|
91
|
+
* @param object - The DTCG group to extract from.
|
|
92
|
+
* @param currentPath - The current path in the token tree.
|
|
93
|
+
* @param currentType - The $type inherited from parent groups.
|
|
94
|
+
* @return A map of mode names to their token overrides.
|
|
95
|
+
*/
|
|
96
|
+
function getModeOverrides(
|
|
97
|
+
object: DTCGGroup,
|
|
98
|
+
currentPath: string[] = [],
|
|
99
|
+
currentType?: string
|
|
100
|
+
): Map< string, ModeOverride[] > {
|
|
101
|
+
const modeOverrides = new Map< string, ModeOverride[] >();
|
|
102
|
+
|
|
103
|
+
// Check if this group defines a $type that should be inherited by children
|
|
104
|
+
const groupType = object.$type ?? currentType;
|
|
105
|
+
|
|
106
|
+
for ( const [ key, value ] of Object.entries( object ) ) {
|
|
107
|
+
// Skip DTCG metadata keys
|
|
108
|
+
if ( key.startsWith( '$' ) ) {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const node = value as DTCGToken | DTCGGroup;
|
|
113
|
+
|
|
114
|
+
if ( isDTCGToken( node ) ) {
|
|
115
|
+
// Extract mode-specific values from extensions
|
|
116
|
+
const modes = node.$extensions?.mode;
|
|
117
|
+
if ( modes ) {
|
|
118
|
+
for ( const [ mode, modeValue ] of Object.entries( modes ) ) {
|
|
119
|
+
modeOverrides.set( mode, [
|
|
120
|
+
...( modeOverrides.get( mode ) ?? [] ),
|
|
121
|
+
{
|
|
122
|
+
path: [ ...currentPath, key ],
|
|
123
|
+
$value: modeValue,
|
|
124
|
+
$type: node.$type ?? groupType,
|
|
125
|
+
},
|
|
126
|
+
] );
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
} else {
|
|
130
|
+
// Recurse into nested groups, passing down the type
|
|
131
|
+
const nextPath = [ ...currentPath, key ];
|
|
132
|
+
const childOverrides = getModeOverrides(
|
|
133
|
+
node,
|
|
134
|
+
nextPath,
|
|
135
|
+
groupType
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
// Merge child results
|
|
139
|
+
for ( const [ mode, overrides ] of childOverrides ) {
|
|
140
|
+
modeOverrides.set( mode, [
|
|
141
|
+
...( modeOverrides.get( mode ) ?? [] ),
|
|
142
|
+
...overrides,
|
|
143
|
+
] );
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return modeOverrides;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Terrazzo plugin that generates mode-specific DTCG override files.
|
|
153
|
+
*
|
|
154
|
+
* For each mode found in tokens (via $extensions.mode), generates a separate
|
|
155
|
+
* JSON file per source file containing tokens that have values for that mode.
|
|
156
|
+
*
|
|
157
|
+
* @return A Terrazzo plugin that generates mode-specific DTCG override files.
|
|
158
|
+
*/
|
|
159
|
+
export default function pluginModeOverrides(): Plugin {
|
|
160
|
+
return {
|
|
161
|
+
name: '@wordpress/terrazzo-plugin-mode-overrides',
|
|
162
|
+
async build( { outputFile, sources } ) {
|
|
163
|
+
for ( const { filename, src } of sources ) {
|
|
164
|
+
if ( ! filename ) {
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Parse the source JSON file
|
|
169
|
+
let document: DTCGDocument;
|
|
170
|
+
try {
|
|
171
|
+
document = JSON.parse( src ) as DTCGDocument;
|
|
172
|
+
} catch ( error ) {
|
|
173
|
+
throw new Error(
|
|
174
|
+
`Could not parse ${ filename }\n\n${ error }`
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Extract mode overrides from this file
|
|
179
|
+
const fileOverrides = getModeOverrides( document );
|
|
180
|
+
|
|
181
|
+
// Generate a DTCG file for each mode found in this source file
|
|
182
|
+
for ( const [ mode, overrides ] of fileOverrides ) {
|
|
183
|
+
const output: Record< string, unknown > = {};
|
|
184
|
+
|
|
185
|
+
for ( const override of overrides ) {
|
|
186
|
+
const { path, $value, $type } = override;
|
|
187
|
+
setNestedValue( output, path, { $type, $value } );
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Output as {basename}.{mode}.json (e.g., dimension.compact.json)
|
|
191
|
+
const sourceDir = new URL( './', filename );
|
|
192
|
+
const outFileName = `${ basename(
|
|
193
|
+
filename.pathname,
|
|
194
|
+
'.json'
|
|
195
|
+
) }.${ mode }.json`;
|
|
196
|
+
const outFileUrl = new URL(
|
|
197
|
+
`modes/${ outFileName }`,
|
|
198
|
+
sourceDir
|
|
199
|
+
);
|
|
200
|
+
outputFile(
|
|
201
|
+
outFileUrl.href,
|
|
202
|
+
JSON.stringify( output, null, '\t' )
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
}
|
|
@@ -55,10 +55,10 @@ var DEFAULT_RAMPS = {
|
|
|
55
55
|
bgFill1: "#3858e9",
|
|
56
56
|
fgFill: "#eff0f2",
|
|
57
57
|
bgFill2: "#2e49d9",
|
|
58
|
-
surface2: "#
|
|
59
|
-
surface6: "#
|
|
58
|
+
surface2: "#f6f8fd",
|
|
59
|
+
surface6: "#c7d2ed",
|
|
60
60
|
surface5: "#dbe2f4",
|
|
61
|
-
surface4: "#
|
|
61
|
+
surface4: "#e6eaf4",
|
|
62
62
|
surface3: "#fff",
|
|
63
63
|
fgSurface4: "#0b0070",
|
|
64
64
|
fgSurface3: "#3858e9",
|
|
@@ -66,11 +66,11 @@ var DEFAULT_RAMPS = {
|
|
|
66
66
|
fgSurface1: "#85a9ff",
|
|
67
67
|
stroke3: "#3858e9",
|
|
68
68
|
stroke4: "#2337c8",
|
|
69
|
-
stroke2: "#
|
|
70
|
-
stroke1: "#
|
|
71
|
-
bgFillDark: "#
|
|
69
|
+
stroke2: "#9caacc",
|
|
70
|
+
stroke1: "#a3b1d4",
|
|
71
|
+
bgFillDark: "#1a1e27",
|
|
72
72
|
fgFillDark: "#eff0f2",
|
|
73
|
-
bgFillInverted2: "#
|
|
73
|
+
bgFillInverted2: "#1a1e27",
|
|
74
74
|
bgFillInverted1: "#13009f",
|
|
75
75
|
fgFillInverted: "#eff0f2",
|
|
76
76
|
surface1: "#ecf0f9"
|
|
@@ -80,27 +80,27 @@ var DEFAULT_RAMPS = {
|
|
|
80
80
|
info: {
|
|
81
81
|
ramp: {
|
|
82
82
|
bgFill1: "#0090ff",
|
|
83
|
-
fgFill: "#
|
|
83
|
+
fgFill: "#1a1f24",
|
|
84
84
|
bgFill2: "#007fed",
|
|
85
|
-
surface2: "#
|
|
86
|
-
surface6: "#
|
|
87
|
-
surface5: "#
|
|
88
|
-
surface4: "#
|
|
85
|
+
surface2: "#f3f9ff",
|
|
86
|
+
surface6: "#bcd5f1",
|
|
87
|
+
surface5: "#d3e4f7",
|
|
88
|
+
surface4: "#deebfa",
|
|
89
89
|
surface3: "#fff",
|
|
90
90
|
fgSurface4: "#001b4f",
|
|
91
91
|
fgSurface3: "#006bd7",
|
|
92
92
|
fgSurface2: "#008bfa",
|
|
93
|
-
fgSurface1: "#
|
|
93
|
+
fgSurface1: "#58b0ff",
|
|
94
94
|
stroke3: "#006bd7",
|
|
95
95
|
stroke4: "#004fa9",
|
|
96
|
-
stroke2: "#
|
|
97
|
-
stroke1: "#
|
|
98
|
-
bgFillDark: "#
|
|
99
|
-
fgFillDark: "#
|
|
100
|
-
bgFillInverted2: "#
|
|
96
|
+
stroke2: "#95b5d9",
|
|
97
|
+
stroke1: "#9fbcdc",
|
|
98
|
+
bgFillDark: "#1a1f24",
|
|
99
|
+
fgFillDark: "#eef0f3",
|
|
100
|
+
bgFillInverted2: "#1a1f24",
|
|
101
101
|
bgFillInverted1: "#002a69",
|
|
102
|
-
fgFillInverted: "#
|
|
103
|
-
surface1: "#
|
|
102
|
+
fgFillInverted: "#eef0f3",
|
|
103
|
+
surface1: "#e4f1ff"
|
|
104
104
|
},
|
|
105
105
|
direction: "darker"
|
|
106
106
|
},
|
|
@@ -109,25 +109,25 @@ var DEFAULT_RAMPS = {
|
|
|
109
109
|
bgFill1: "#4ab866",
|
|
110
110
|
fgFill: "#1b1f1c",
|
|
111
111
|
bgFill2: "#37a756",
|
|
112
|
-
surface2: "#
|
|
113
|
-
surface6: "#
|
|
114
|
-
surface5: "#
|
|
115
|
-
surface4: "#
|
|
112
|
+
surface2: "#eaffed",
|
|
113
|
+
surface6: "#88e89b",
|
|
114
|
+
surface5: "#aff3bb",
|
|
115
|
+
surface4: "#c5f7cc",
|
|
116
116
|
surface3: "#fff",
|
|
117
117
|
fgSurface4: "#002900",
|
|
118
118
|
fgSurface3: "#007f30",
|
|
119
119
|
fgSurface2: "#2b9e4e",
|
|
120
|
-
fgSurface1: "#
|
|
120
|
+
fgSurface1: "#53c16e",
|
|
121
121
|
stroke3: "#007f30",
|
|
122
122
|
stroke4: "#006013",
|
|
123
|
-
stroke2: "#
|
|
124
|
-
stroke1: "#
|
|
123
|
+
stroke2: "#84c08e",
|
|
124
|
+
stroke1: "#8ac894",
|
|
125
125
|
bgFillDark: "#1b1f1c",
|
|
126
|
-
fgFillDark: "#
|
|
126
|
+
fgFillDark: "#eaf3eb",
|
|
127
127
|
bgFillInverted2: "#1b1f1c",
|
|
128
128
|
bgFillInverted1: "#003701",
|
|
129
|
-
fgFillInverted: "#
|
|
130
|
-
surface1: "#
|
|
129
|
+
fgFillInverted: "#eaf3eb",
|
|
130
|
+
surface1: "#cbfdd2"
|
|
131
131
|
},
|
|
132
132
|
direction: "darker"
|
|
133
133
|
},
|
|
@@ -136,25 +136,25 @@ var DEFAULT_RAMPS = {
|
|
|
136
136
|
bgFill1: "#f0d149",
|
|
137
137
|
fgFill: "#1f1e1b",
|
|
138
138
|
bgFill2: "#dcbe2f",
|
|
139
|
-
surface2: "#
|
|
140
|
-
surface6: "#
|
|
141
|
-
surface5: "#
|
|
142
|
-
surface4: "#
|
|
139
|
+
surface2: "#fff9c9",
|
|
140
|
+
surface6: "#e8d172",
|
|
141
|
+
surface5: "#f7e18a",
|
|
142
|
+
surface4: "#fee994",
|
|
143
143
|
surface3: "#fff",
|
|
144
144
|
fgSurface4: "#281d00",
|
|
145
|
-
fgSurface3: "#
|
|
146
|
-
fgSurface2: "#
|
|
147
|
-
fgSurface1: "#
|
|
148
|
-
stroke3: "#
|
|
149
|
-
stroke4: "#
|
|
150
|
-
stroke2: "#
|
|
151
|
-
stroke1: "#
|
|
145
|
+
fgSurface3: "#826a00",
|
|
146
|
+
fgSurface2: "#a48600",
|
|
147
|
+
fgSurface1: "#c6a800",
|
|
148
|
+
stroke3: "#826a00",
|
|
149
|
+
stroke4: "#624f00",
|
|
150
|
+
stroke2: "#bdb17e",
|
|
151
|
+
stroke1: "#c5b883",
|
|
152
152
|
bgFillDark: "#1f1e1b",
|
|
153
|
-
fgFillDark: "#
|
|
153
|
+
fgFillDark: "#fdf1bf",
|
|
154
154
|
bgFillInverted2: "#1f1e1b",
|
|
155
155
|
bgFillInverted1: "#392c00",
|
|
156
|
-
fgFillInverted: "#
|
|
157
|
-
surface1: "#
|
|
156
|
+
fgFillInverted: "#fdf1bf",
|
|
157
|
+
surface1: "#ffef9b"
|
|
158
158
|
},
|
|
159
159
|
direction: "darker"
|
|
160
160
|
},
|
|
@@ -163,25 +163,25 @@ var DEFAULT_RAMPS = {
|
|
|
163
163
|
bgFill1: "#f0b849",
|
|
164
164
|
fgFill: "#1f1e1b",
|
|
165
165
|
bgFill2: "#dda633",
|
|
166
|
-
surface2: "#
|
|
167
|
-
surface6: "#
|
|
168
|
-
surface5: "#
|
|
169
|
-
surface4: "#
|
|
166
|
+
surface2: "#fff7e0",
|
|
167
|
+
surface6: "#f4cc84",
|
|
168
|
+
surface5: "#faddac",
|
|
169
|
+
surface4: "#fde6bd",
|
|
170
170
|
surface3: "#fff",
|
|
171
171
|
fgSurface4: "#2e1900",
|
|
172
|
-
fgSurface3: "#
|
|
173
|
-
fgSurface2: "#
|
|
174
|
-
fgSurface1: "#
|
|
175
|
-
stroke3: "#
|
|
176
|
-
stroke4: "#
|
|
177
|
-
stroke2: "#
|
|
178
|
-
stroke1: "#
|
|
172
|
+
fgSurface3: "#926300",
|
|
173
|
+
fgSurface2: "#b47f00",
|
|
174
|
+
fgSurface1: "#d7a02a",
|
|
175
|
+
stroke3: "#926300",
|
|
176
|
+
stroke4: "#6f4900",
|
|
177
|
+
stroke2: "#c7ad7e",
|
|
178
|
+
stroke1: "#d0b381",
|
|
179
179
|
bgFillDark: "#1f1e1b",
|
|
180
|
-
fgFillDark: "#
|
|
180
|
+
fgFillDark: "#f7efe2",
|
|
181
181
|
bgFillInverted2: "#1f1e1b",
|
|
182
182
|
bgFillInverted1: "#422800",
|
|
183
|
-
fgFillInverted: "#
|
|
184
|
-
surface1: "#
|
|
183
|
+
fgFillInverted: "#f7efe2",
|
|
184
|
+
surface1: "#ffecc4"
|
|
185
185
|
},
|
|
186
186
|
direction: "darker"
|
|
187
187
|
},
|
|
@@ -190,10 +190,10 @@ var DEFAULT_RAMPS = {
|
|
|
190
190
|
bgFill1: "#cc1818",
|
|
191
191
|
fgFill: "#f2efef",
|
|
192
192
|
bgFill2: "#b90000",
|
|
193
|
-
surface2: "#
|
|
194
|
-
surface6: "#
|
|
195
|
-
surface5: "#
|
|
196
|
-
surface4: "#
|
|
193
|
+
surface2: "#fff6f4",
|
|
194
|
+
surface6: "#f3c8c2",
|
|
195
|
+
surface5: "#f8dcd7",
|
|
196
|
+
surface4: "#f6e6e3",
|
|
197
197
|
surface3: "#fff",
|
|
198
198
|
fgSurface4: "#470000",
|
|
199
199
|
fgSurface3: "#cc1818",
|
|
@@ -201,14 +201,14 @@ var DEFAULT_RAMPS = {
|
|
|
201
201
|
fgSurface1: "#ff8879",
|
|
202
202
|
stroke3: "#cc1818",
|
|
203
203
|
stroke4: "#9d0000",
|
|
204
|
-
stroke2: "#
|
|
205
|
-
stroke1: "#
|
|
204
|
+
stroke2: "#d39c95",
|
|
205
|
+
stroke1: "#daa39b",
|
|
206
206
|
bgFillDark: "#231c1b",
|
|
207
207
|
fgFillDark: "#f2efef",
|
|
208
208
|
bgFillInverted2: "#231c1b",
|
|
209
209
|
bgFillInverted1: "#640000",
|
|
210
210
|
fgFillInverted: "#f2efef",
|
|
211
|
-
surface1: "#
|
|
211
|
+
surface1: "#fcece9"
|
|
212
212
|
},
|
|
213
213
|
direction: "darker"
|
|
214
214
|
}
|