@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
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { Plugin, TokenNormalized } from '@terrazzo/parser';
|
|
5
|
-
import { transformCSSValue } from '@terrazzo/token-tools/css';
|
|
6
|
-
import {
|
|
7
|
-
parse,
|
|
8
|
-
to,
|
|
9
|
-
serialize,
|
|
10
|
-
sRGB,
|
|
11
|
-
type ColorConstructor,
|
|
12
|
-
} from 'colorjs.io/fn';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Internal dependencies
|
|
16
|
-
*/
|
|
17
|
-
import '../../src/color-ramps/lib/register-color-spaces';
|
|
18
|
-
import { FORMAT_JSON_ID } from './lib';
|
|
19
|
-
|
|
20
|
-
function titleCase( str: string ) {
|
|
21
|
-
return str[ 0 ].toUpperCase() + str.slice( 1 );
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function kebabToCamel( str: string ) {
|
|
25
|
-
return str.replace( /-([a-z])/g, ( _, letter ) => letter.toUpperCase() );
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function transformTokenName( { id }: { id: string } ) {
|
|
29
|
-
return (
|
|
30
|
-
id
|
|
31
|
-
// Capitalize first segment
|
|
32
|
-
.replace( /^(\w+)\./g, ( _, g1 ) => `${ titleCase( g1 ) }/` )
|
|
33
|
-
// Capitalize
|
|
34
|
-
.replace( /primitive\./g, '_Primitives/' )
|
|
35
|
-
.replace( /semantic\./g, 'Semantic/' )
|
|
36
|
-
.replace(
|
|
37
|
-
/(color\/_Primitives)\/(\w+)\.(.*)/gi,
|
|
38
|
-
( _, prefix, tone, rampStep ) => {
|
|
39
|
-
return `${ prefix }/${ titleCase( tone ) }/${ rampStep }`;
|
|
40
|
-
}
|
|
41
|
-
)
|
|
42
|
-
// Color-specific transformation for semantic tokens:
|
|
43
|
-
// - add extra folder (Background, Foreground, Stroke)
|
|
44
|
-
// - swap "tone" folder order, capitalize
|
|
45
|
-
// - limit bg-* to 6 characters
|
|
46
|
-
// - keep last part of the token name with dots (eg no folders)
|
|
47
|
-
.replace(
|
|
48
|
-
/(color\/Semantic)\/([\w,\-]+)\.(\w+)\.(.*)/gi,
|
|
49
|
-
( _, prefix, element, tone, emphasisAndState ) => {
|
|
50
|
-
let extraFolder = '';
|
|
51
|
-
let elementName = element;
|
|
52
|
-
if ( /bg/.test( element ) ) {
|
|
53
|
-
extraFolder = 'Background/';
|
|
54
|
-
elementName = element.slice( 0, 6 );
|
|
55
|
-
} else if ( /fg/.test( element ) ) {
|
|
56
|
-
extraFolder = 'Foreground/';
|
|
57
|
-
elementName = element.slice( 0, 6 );
|
|
58
|
-
} else if ( /stroke/.test( element ) ) {
|
|
59
|
-
extraFolder = 'Stroke/';
|
|
60
|
-
elementName = element.slice( 0, 10 );
|
|
61
|
-
}
|
|
62
|
-
return `${ prefix }/${ extraFolder }${ titleCase(
|
|
63
|
-
tone
|
|
64
|
-
) }/${ kebabToCamel(
|
|
65
|
-
elementName
|
|
66
|
-
) }.${ tone }.${ emphasisAndState }`;
|
|
67
|
-
}
|
|
68
|
-
)
|
|
69
|
-
// Remove default emphasis and state variants from variable name
|
|
70
|
-
.replace( /normal\./g, '' )
|
|
71
|
-
.replace( /resting/g, '' )
|
|
72
|
-
// Remove double dots
|
|
73
|
-
.replace( /\.{2,}/g, '.' )
|
|
74
|
-
// Remove trailing dot
|
|
75
|
-
.replace( /\.$/g, '' )
|
|
76
|
-
// Replace remaining dots with dashes
|
|
77
|
-
.replace( /\./g, '-' )
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function transformColorToken(
|
|
82
|
-
token: TokenNormalized,
|
|
83
|
-
mode: string,
|
|
84
|
-
tokens: Record< string, TokenNormalized >
|
|
85
|
-
) {
|
|
86
|
-
if (
|
|
87
|
-
token.mode[ mode ]?.aliasChain &&
|
|
88
|
-
token.mode[ mode ].aliasChain.length > 0
|
|
89
|
-
) {
|
|
90
|
-
// Keep aliases
|
|
91
|
-
return `{${ transformTokenName( {
|
|
92
|
-
id: token.mode[ mode ].aliasChain[ 0 ],
|
|
93
|
-
} ) }}`;
|
|
94
|
-
}
|
|
95
|
-
// Start by letting terrazzo do the heavy lifting.
|
|
96
|
-
const baselineCSSValue = transformCSSValue( token, {
|
|
97
|
-
mode,
|
|
98
|
-
tokensSet: tokens,
|
|
99
|
-
transformAlias: transformTokenName,
|
|
100
|
-
} );
|
|
101
|
-
|
|
102
|
-
if ( baselineCSSValue === undefined ) {
|
|
103
|
-
console.warn( 'Unexpected: could not tranform color token value' );
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
let cssColorValue: string;
|
|
108
|
-
|
|
109
|
-
if ( typeof baselineCSSValue === 'object' ) {
|
|
110
|
-
if ( 'srgb' in baselineCSSValue ) {
|
|
111
|
-
// Pick SRGB gamut (safer compared to p3 or rec2020)
|
|
112
|
-
cssColorValue = baselineCSSValue.srgb;
|
|
113
|
-
} else {
|
|
114
|
-
console.log( 'UNSUPPORTED USE CASE' );
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
} else {
|
|
118
|
-
cssColorValue = baselineCSSValue;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Always convert to hex
|
|
122
|
-
// (easier to convert to Figma RGB, and includes clamping)
|
|
123
|
-
let convertedColor: ColorConstructor;
|
|
124
|
-
try {
|
|
125
|
-
convertedColor = parse( cssColorValue );
|
|
126
|
-
} catch {
|
|
127
|
-
console.warn( 'Unexpected: could not convert token value to Color' );
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return serialize( to( convertedColor, sRGB ), { format: 'hex' } );
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export default function pluginFigmaDsTokenManager( {
|
|
135
|
-
filename = 'figma-ds-tokens.json',
|
|
136
|
-
} = {} ): Plugin {
|
|
137
|
-
return {
|
|
138
|
-
name: '@terrazzo/plugin-figma-ds-token-manager',
|
|
139
|
-
async transform( { tokens, getTransforms, setTransform } ) {
|
|
140
|
-
// skip work if another .json plugin has already run
|
|
141
|
-
const jsonTokens = getTransforms( {
|
|
142
|
-
format: FORMAT_JSON_ID,
|
|
143
|
-
id: '*',
|
|
144
|
-
mode: '.',
|
|
145
|
-
} );
|
|
146
|
-
if ( jsonTokens.length ) {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
for ( const [ id, token ] of Object.entries( tokens ) ) {
|
|
151
|
-
for ( const mode of Object.keys( token.mode ) ) {
|
|
152
|
-
const localID = transformTokenName( token );
|
|
153
|
-
|
|
154
|
-
let transformedValue;
|
|
155
|
-
|
|
156
|
-
if ( token.$type === 'color' ) {
|
|
157
|
-
transformedValue = transformColorToken(
|
|
158
|
-
token,
|
|
159
|
-
mode,
|
|
160
|
-
tokens
|
|
161
|
-
);
|
|
162
|
-
} else if (
|
|
163
|
-
token.mode[ mode ]?.aliasChain &&
|
|
164
|
-
token.mode[ mode ].aliasChain.length > 0
|
|
165
|
-
) {
|
|
166
|
-
// Keep aliases
|
|
167
|
-
transformedValue = `{${ transformTokenName( {
|
|
168
|
-
id: token.mode[ mode ].aliasChain[ 0 ],
|
|
169
|
-
} ) }}`;
|
|
170
|
-
} else {
|
|
171
|
-
// Fallback to terrazzo
|
|
172
|
-
transformedValue = transformCSSValue( token, {
|
|
173
|
-
mode,
|
|
174
|
-
tokensSet: tokens,
|
|
175
|
-
transformAlias: transformTokenName,
|
|
176
|
-
} );
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
if ( transformedValue !== undefined ) {
|
|
180
|
-
setTransform( id, {
|
|
181
|
-
format: FORMAT_JSON_ID,
|
|
182
|
-
localID,
|
|
183
|
-
value: transformedValue,
|
|
184
|
-
mode,
|
|
185
|
-
} );
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
},
|
|
190
|
-
async build( { getTransforms, outputFile } ) {
|
|
191
|
-
const tokenVals: Record<
|
|
192
|
-
string,
|
|
193
|
-
{
|
|
194
|
-
value: Record< string, string | Record< string, string > >;
|
|
195
|
-
description?: string;
|
|
196
|
-
}
|
|
197
|
-
> = {};
|
|
198
|
-
|
|
199
|
-
for ( const token of getTransforms( {
|
|
200
|
-
format: FORMAT_JSON_ID,
|
|
201
|
-
id: '*',
|
|
202
|
-
} ) ) {
|
|
203
|
-
if ( ! token.localID ) {
|
|
204
|
-
continue;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
tokenVals[ token.localID ] ??= { value: {}, description: '' };
|
|
208
|
-
|
|
209
|
-
tokenVals[ token.localID ].value[ token.mode ] = token.value;
|
|
210
|
-
tokenVals[ token.localID ].description =
|
|
211
|
-
token.token.$description;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
outputFile( filename, JSON.stringify( tokenVals, null, 2 ) );
|
|
215
|
-
},
|
|
216
|
-
};
|
|
217
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const FORMAT_JSON_ID = 'json';
|