@10up/block-renderer-theme-json 0.1.4
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 +518 -0
- package/dist/__benchmarks__/parser.bench.d.ts +5 -0
- package/dist/__benchmarks__/parser.bench.d.ts.map +1 -0
- package/dist/__benchmarks__/parser.bench.js +92 -0
- package/dist/__benchmarks__/parser.bench.js.map +1 -0
- package/dist/__tests__/fixtures/theme-json.d.ts +9 -0
- package/dist/__tests__/fixtures/theme-json.d.ts.map +1 -0
- package/dist/__tests__/fixtures/theme-json.js +212 -0
- package/dist/__tests__/fixtures/theme-json.js.map +1 -0
- package/dist/css-generator.d.ts +20 -0
- package/dist/css-generator.d.ts.map +1 -0
- package/dist/css-generator.js +262 -0
- package/dist/css-generator.js.map +1 -0
- package/dist/css-variables.d.ts +82 -0
- package/dist/css-variables.d.ts.map +1 -0
- package/dist/css-variables.js +143 -0
- package/dist/css-variables.js.map +1 -0
- package/dist/ignite-extractor.d.ts +46 -0
- package/dist/ignite-extractor.d.ts.map +1 -0
- package/dist/ignite-extractor.js +96 -0
- package/dist/ignite-extractor.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/parser.d.ts +45 -0
- package/dist/parser.d.ts.map +1 -0
- package/dist/parser.js +242 -0
- package/dist/parser.js.map +1 -0
- package/dist/types.d.ts +459 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +40 -0
- package/dist/types.js.map +1 -0
- package/package.json +51 -0
package/README.md
ADDED
|
@@ -0,0 +1,518 @@
|
|
|
1
|
+
# @10up/block-renderer-theme-json
|
|
2
|
+
|
|
3
|
+
Parse WordPress `theme.json` files and extract design tokens for colors, typography, spacing, and more.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @10up/block-renderer-theme-json
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @10up/block-renderer-theme-json
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
WordPress themes define their design system in `theme.json`. This package:
|
|
16
|
+
|
|
17
|
+
1. **Parses theme.json** - Supports v2 and v3 schema versions
|
|
18
|
+
2. **Extracts design tokens** - Colors, gradients, fonts, spacing, shadows
|
|
19
|
+
3. **Loads style variations** - From the `/styles` directory
|
|
20
|
+
4. **CSS variable utilities** - Convert between WordPress formats and actual CSS
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### Parse a Complete Theme
|
|
25
|
+
|
|
26
|
+
The main entry point - parses theme.json and loads style variations:
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { parseTheme } from '@10up/block-renderer-theme-json';
|
|
30
|
+
|
|
31
|
+
const theme = parseTheme('/path/to/theme');
|
|
32
|
+
|
|
33
|
+
// Access extracted tokens
|
|
34
|
+
console.log(theme.tokens.colors.palette);
|
|
35
|
+
// [{ slug: 'primary', color: '#0073aa', name: 'Primary' }, ...]
|
|
36
|
+
|
|
37
|
+
console.log(theme.tokens.typography.fontSizes);
|
|
38
|
+
// [{ slug: 'small', size: '13px', name: 'Small' }, ...]
|
|
39
|
+
|
|
40
|
+
console.log(theme.tokens.spacing.spacingSizes);
|
|
41
|
+
// [{ slug: '50', size: '1.5rem', name: 'Medium' }, ...]
|
|
42
|
+
|
|
43
|
+
// Access theme styles
|
|
44
|
+
console.log(theme.styles.global);
|
|
45
|
+
// { color: { background: 'var:preset|color|base' }, ... }
|
|
46
|
+
|
|
47
|
+
// Access style variations
|
|
48
|
+
console.log(theme.variations);
|
|
49
|
+
// { 'dark': { global: { color: { ... } } }, ... }
|
|
50
|
+
|
|
51
|
+
// Access raw theme.json
|
|
52
|
+
console.log(theme.raw);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Parse theme.json Directly
|
|
56
|
+
|
|
57
|
+
If you already have the theme.json content:
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import { parseThemeJson } from '@10up/block-renderer-theme-json';
|
|
61
|
+
|
|
62
|
+
const themeJson = {
|
|
63
|
+
version: 3,
|
|
64
|
+
settings: {
|
|
65
|
+
color: {
|
|
66
|
+
palette: [
|
|
67
|
+
{ slug: 'primary', color: '#0073aa', name: 'Primary' }
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const result = parseThemeJson(themeJson);
|
|
74
|
+
console.log(result.tokens);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Extract Tokens Only
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
import { extractTokens } from '@10up/block-renderer-theme-json';
|
|
81
|
+
|
|
82
|
+
const tokens = extractTokens(themeJson.settings);
|
|
83
|
+
console.log(tokens.colors.palette);
|
|
84
|
+
console.log(tokens.typography.fontFamilies);
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Extract Styles Only
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
import { extractStyles } from '@10up/block-renderer-theme-json';
|
|
91
|
+
|
|
92
|
+
const styles = extractStyles(themeJson.styles);
|
|
93
|
+
console.log(styles.global); // Global styles
|
|
94
|
+
console.log(styles.elements); // Element styles (h1, p, link, etc.)
|
|
95
|
+
console.log(styles.blocks); // Per-block styles
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Load Style Variations
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import { loadStyleVariations } from '@10up/block-renderer-theme-json';
|
|
102
|
+
|
|
103
|
+
const variations = loadStyleVariations('/path/to/theme');
|
|
104
|
+
// Reads all .json files from /path/to/theme/styles/
|
|
105
|
+
// { 'dark': { ... }, 'contrast': { ... } }
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Load Section Styles
|
|
109
|
+
|
|
110
|
+
For themes that define section-specific styles (like hero sections, testimonials, etc.):
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
import { loadSectionStyles } from '@10up/block-renderer-theme-json';
|
|
114
|
+
|
|
115
|
+
const sectionStyles = loadSectionStyles('/path/to/theme');
|
|
116
|
+
// Returns map of section name to styles
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Parse Theme Options
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
import { parseTheme } from '@10up/block-renderer-theme-json';
|
|
123
|
+
import type { ParseThemeOptions } from '@10up/block-renderer-theme-json';
|
|
124
|
+
|
|
125
|
+
const options: ParseThemeOptions = {
|
|
126
|
+
loadVariations: true, // Load style variations (default: true)
|
|
127
|
+
loadSectionStyles: true // Load section styles (default: true)
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const theme = parseTheme('/path/to/theme', options);
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## CSS Variable Utilities
|
|
134
|
+
|
|
135
|
+
WordPress uses two formats for design token references:
|
|
136
|
+
|
|
137
|
+
1. **WordPress format**: `var:preset|color|primary` (used in block attributes)
|
|
138
|
+
2. **CSS format**: `var(--wp--preset--color--primary)` (actual CSS output)
|
|
139
|
+
|
|
140
|
+
### Generate WordPress Reference
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
import { generateCssVarReference } from '@10up/block-renderer-theme-json';
|
|
144
|
+
|
|
145
|
+
generateCssVarReference('color', 'primary');
|
|
146
|
+
// 'var:preset|color|primary'
|
|
147
|
+
|
|
148
|
+
generateCssVarReference('spacing', '50');
|
|
149
|
+
// 'var:preset|spacing|50'
|
|
150
|
+
|
|
151
|
+
generateCssVarReference('font-family', 'heading');
|
|
152
|
+
// 'var:preset|font-family|heading'
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Generate CSS Custom Property
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
import { generateCssPropertyName, generateCssVarFunction } from '@10up/block-renderer-theme-json';
|
|
159
|
+
|
|
160
|
+
generateCssPropertyName('color', 'primary');
|
|
161
|
+
// '--wp--preset--color--primary'
|
|
162
|
+
|
|
163
|
+
generateCssVarFunction('color', 'primary');
|
|
164
|
+
// 'var(--wp--preset--color--primary)'
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Parse References
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
import { parseCssVarReference, isCssVarReference } from '@10up/block-renderer-theme-json';
|
|
171
|
+
|
|
172
|
+
isCssVarReference('var:preset|color|primary'); // true
|
|
173
|
+
isCssVarReference('#ff0000'); // false
|
|
174
|
+
|
|
175
|
+
parseCssVarReference('var:preset|color|primary');
|
|
176
|
+
// { type: 'color', slug: 'primary' }
|
|
177
|
+
|
|
178
|
+
parseCssVarReference('var:preset|spacing|50');
|
|
179
|
+
// { type: 'spacing', slug: '50' }
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Convert to CSS
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import { convertToActualCss } from '@10up/block-renderer-theme-json';
|
|
186
|
+
|
|
187
|
+
convertToActualCss('var:preset|color|primary');
|
|
188
|
+
// 'var(--wp--preset--color--primary)'
|
|
189
|
+
|
|
190
|
+
convertToActualCss('#ff0000'); // Returns unchanged if not a reference
|
|
191
|
+
// '#ff0000'
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Token Utilities
|
|
195
|
+
|
|
196
|
+
### Get Available Slugs
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
import {
|
|
200
|
+
getColorSlugs,
|
|
201
|
+
getGradientSlugs,
|
|
202
|
+
getFontFamilySlugs,
|
|
203
|
+
getFontSizeSlugs,
|
|
204
|
+
getSpacingSlugs,
|
|
205
|
+
getShadowSlugs,
|
|
206
|
+
} from '@10up/block-renderer-theme-json';
|
|
207
|
+
|
|
208
|
+
const theme = parseTheme('/path/to/theme');
|
|
209
|
+
|
|
210
|
+
getColorSlugs(theme.tokens); // ['primary', 'secondary', 'base', ...]
|
|
211
|
+
getGradientSlugs(theme.tokens); // ['vivid-cyan-blue', ...]
|
|
212
|
+
getFontFamilySlugs(theme.tokens); // ['system', 'heading', 'body', ...]
|
|
213
|
+
getFontSizeSlugs(theme.tokens); // ['small', 'medium', 'large', ...]
|
|
214
|
+
getSpacingSlugs(theme.tokens); // ['20', '30', '40', '50', ...]
|
|
215
|
+
getShadowSlugs(theme.tokens); // ['natural', 'deep', 'sharp', ...]
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Validate Slugs
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
import { validateSlug } from '@10up/block-renderer-theme-json';
|
|
222
|
+
|
|
223
|
+
validateSlug(theme.tokens, 'color', 'primary'); // true
|
|
224
|
+
validateSlug(theme.tokens, 'color', 'nonexistent'); // false
|
|
225
|
+
validateSlug(theme.tokens, 'font-size', 'large'); // true
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Get Token Values
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
import { getTokenValue } from '@10up/block-renderer-theme-json';
|
|
232
|
+
|
|
233
|
+
getTokenValue(theme.tokens, 'color', 'primary'); // '#0073aa'
|
|
234
|
+
getTokenValue(theme.tokens, 'font-size', 'large'); // '1.5rem'
|
|
235
|
+
getTokenValue(theme.tokens, 'spacing', '50'); // '1.5rem'
|
|
236
|
+
getTokenValue(theme.tokens, 'color', 'nonexistent'); // null
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## Ignite WP Support
|
|
240
|
+
|
|
241
|
+
Special support for [Ignite WP](https://developer.wordpress.org/) themes with fluid typography:
|
|
242
|
+
|
|
243
|
+
### Extract Ignite Tokens
|
|
244
|
+
|
|
245
|
+
```typescript
|
|
246
|
+
import {
|
|
247
|
+
extractIgniteTokens,
|
|
248
|
+
extractTypographyPresets,
|
|
249
|
+
extractFluidValues,
|
|
250
|
+
isFluidValue,
|
|
251
|
+
getTypographyPresetClassName,
|
|
252
|
+
} from '@10up/block-renderer-theme-json';
|
|
253
|
+
|
|
254
|
+
// Check if a value uses fluid typography
|
|
255
|
+
isFluidValue({ min: '1rem', max: '2rem' }); // true
|
|
256
|
+
isFluidValue('1.5rem'); // false
|
|
257
|
+
|
|
258
|
+
// Extract fluid values from theme settings
|
|
259
|
+
const fluidValues = extractFluidValues(themeJson.settings);
|
|
260
|
+
|
|
261
|
+
// Extract typography presets (display, heading, body, etc.)
|
|
262
|
+
const typographyPresets = extractTypographyPresets(themeJson.settings);
|
|
263
|
+
// { display: { fontFamily: '...', fontSize: '...' }, ... }
|
|
264
|
+
|
|
265
|
+
// Get the CSS class name for a typography preset
|
|
266
|
+
getTypographyPresetClassName('display'); // 'has-display-typography'
|
|
267
|
+
|
|
268
|
+
// Extract all Ignite-specific tokens
|
|
269
|
+
const igniteTokens = extractIgniteTokens(themeJson.settings);
|
|
270
|
+
// { typographyPresets: {...}, fluidValues: {...} }
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### Ignite Types
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
interface FluidValue {
|
|
277
|
+
min: string;
|
|
278
|
+
max: string;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
interface TypographyPreset {
|
|
282
|
+
fontFamily?: string;
|
|
283
|
+
fontSize?: string | FluidValue;
|
|
284
|
+
fontWeight?: string;
|
|
285
|
+
lineHeight?: string;
|
|
286
|
+
letterSpacing?: string;
|
|
287
|
+
textTransform?: string;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
interface IgniteTokens {
|
|
291
|
+
typographyPresets: Record<string, TypographyPreset>;
|
|
292
|
+
fluidValues: Record<string, FluidValue>;
|
|
293
|
+
}
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## CSS Generator
|
|
297
|
+
|
|
298
|
+
Generate CSS from theme.json section styles:
|
|
299
|
+
|
|
300
|
+
```typescript
|
|
301
|
+
import {
|
|
302
|
+
generateSectionStyleCss,
|
|
303
|
+
generateAllSectionStylesCss,
|
|
304
|
+
blockTypeToSelector,
|
|
305
|
+
flattenCustomToProperties,
|
|
306
|
+
} from '@10up/block-renderer-theme-json';
|
|
307
|
+
|
|
308
|
+
// Convert a block type to CSS selector
|
|
309
|
+
blockTypeToSelector('core/paragraph'); // '.wp-block-paragraph'
|
|
310
|
+
blockTypeToSelector('core/group'); // '.wp-block-group'
|
|
311
|
+
|
|
312
|
+
// Flatten custom properties for CSS
|
|
313
|
+
const properties = flattenCustomToProperties({
|
|
314
|
+
spacing: { gap: '1rem' }
|
|
315
|
+
});
|
|
316
|
+
// { '--wp--custom--spacing--gap': '1rem' }
|
|
317
|
+
|
|
318
|
+
// Generate CSS for a single section style
|
|
319
|
+
const css = generateSectionStyleCss('hero', sectionStyle);
|
|
320
|
+
|
|
321
|
+
// Generate CSS for all section styles
|
|
322
|
+
const allCss = generateAllSectionStylesCss(sectionStyles);
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
## Types
|
|
326
|
+
|
|
327
|
+
### ThemeTokens
|
|
328
|
+
|
|
329
|
+
```typescript
|
|
330
|
+
interface ThemeTokens {
|
|
331
|
+
colors: {
|
|
332
|
+
palette: ColorPreset[];
|
|
333
|
+
gradients: GradientPreset[];
|
|
334
|
+
duotone: DuotonePreset[];
|
|
335
|
+
};
|
|
336
|
+
typography: {
|
|
337
|
+
fontFamilies: FontFamilyPreset[];
|
|
338
|
+
fontSizes: FontSizePreset[];
|
|
339
|
+
};
|
|
340
|
+
spacing: {
|
|
341
|
+
spacingSizes: SpacingPreset[];
|
|
342
|
+
units: string[];
|
|
343
|
+
};
|
|
344
|
+
shadow: {
|
|
345
|
+
presets: ShadowPreset[];
|
|
346
|
+
};
|
|
347
|
+
layout: {
|
|
348
|
+
contentSize?: string;
|
|
349
|
+
wideSize?: string;
|
|
350
|
+
};
|
|
351
|
+
custom: Record<string, unknown>;
|
|
352
|
+
}
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
### Preset Types
|
|
356
|
+
|
|
357
|
+
```typescript
|
|
358
|
+
interface ColorPreset {
|
|
359
|
+
name: string;
|
|
360
|
+
slug: string;
|
|
361
|
+
color: string;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
interface GradientPreset {
|
|
365
|
+
name: string;
|
|
366
|
+
slug: string;
|
|
367
|
+
gradient: string;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
interface FontSizePreset {
|
|
371
|
+
name: string;
|
|
372
|
+
slug: string;
|
|
373
|
+
size: string;
|
|
374
|
+
fluid?: { min?: string; max?: string } | boolean;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
interface FontFamilyPreset {
|
|
378
|
+
name: string;
|
|
379
|
+
slug: string;
|
|
380
|
+
fontFamily: string;
|
|
381
|
+
fontFace?: FontFace[];
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
interface SpacingPreset {
|
|
385
|
+
name: string;
|
|
386
|
+
slug: string;
|
|
387
|
+
size: string;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
interface ShadowPreset {
|
|
391
|
+
name: string;
|
|
392
|
+
slug: string;
|
|
393
|
+
shadow: string;
|
|
394
|
+
}
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
### ParsedTheme
|
|
398
|
+
|
|
399
|
+
```typescript
|
|
400
|
+
interface ParsedTheme {
|
|
401
|
+
version: number;
|
|
402
|
+
tokens: ThemeTokens;
|
|
403
|
+
styles: ThemeStyles;
|
|
404
|
+
variations: Record<string, Partial<ThemeStyles>>;
|
|
405
|
+
raw: ThemeJson;
|
|
406
|
+
}
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
### TokenType
|
|
410
|
+
|
|
411
|
+
```typescript
|
|
412
|
+
type TokenType =
|
|
413
|
+
| 'color'
|
|
414
|
+
| 'gradient'
|
|
415
|
+
| 'font-family'
|
|
416
|
+
| 'font-size'
|
|
417
|
+
| 'spacing'
|
|
418
|
+
| 'shadow'
|
|
419
|
+
| 'duotone';
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
## Complete Exports
|
|
423
|
+
|
|
424
|
+
### Parser Functions
|
|
425
|
+
|
|
426
|
+
| Function | Description |
|
|
427
|
+
|----------|-------------|
|
|
428
|
+
| `parseTheme(themePath, options?)` | Parse theme directory, return tokens, styles, variations |
|
|
429
|
+
| `parseThemeJson(themeJson)` | Parse theme.json object directly |
|
|
430
|
+
| `extractTokens(settings)` | Extract tokens from settings object |
|
|
431
|
+
| `extractStyles(styles)` | Extract styles from styles object |
|
|
432
|
+
| `loadThemeJson(filePath)` | Load and parse a theme.json file |
|
|
433
|
+
| `loadStyleVariations(themePath)` | Load style variations from /styles |
|
|
434
|
+
| `loadSectionStyles(themePath)` | Load section styles from theme |
|
|
435
|
+
|
|
436
|
+
### CSS Variable Functions
|
|
437
|
+
|
|
438
|
+
| Function | Description |
|
|
439
|
+
|----------|-------------|
|
|
440
|
+
| `generateCssVarReference(type, slug)` | Generate WordPress var:preset format |
|
|
441
|
+
| `generateCssPropertyName(type, slug)` | Generate CSS custom property name |
|
|
442
|
+
| `generateCssVarFunction(type, slug)` | Generate var() CSS function |
|
|
443
|
+
| `parseCssVarReference(reference)` | Parse var:preset string to components |
|
|
444
|
+
| `isCssVarReference(value)` | Check if value is a var:preset reference |
|
|
445
|
+
| `convertToActualCss(reference)` | Convert var:preset to actual CSS |
|
|
446
|
+
|
|
447
|
+
### Token Utility Functions
|
|
448
|
+
|
|
449
|
+
| Function | Description |
|
|
450
|
+
|----------|-------------|
|
|
451
|
+
| `getColorSlugs(tokens)` | Get all color slugs |
|
|
452
|
+
| `getGradientSlugs(tokens)` | Get all gradient slugs |
|
|
453
|
+
| `getFontFamilySlugs(tokens)` | Get all font family slugs |
|
|
454
|
+
| `getFontSizeSlugs(tokens)` | Get all font size slugs |
|
|
455
|
+
| `getSpacingSlugs(tokens)` | Get all spacing slugs |
|
|
456
|
+
| `getShadowSlugs(tokens)` | Get all shadow slugs |
|
|
457
|
+
| `validateSlug(tokens, type, slug)` | Check if slug exists in tokens |
|
|
458
|
+
| `getTokenValue(tokens, type, slug)` | Get actual value for a token |
|
|
459
|
+
|
|
460
|
+
### Ignite WP Functions
|
|
461
|
+
|
|
462
|
+
| Function | Description |
|
|
463
|
+
|----------|-------------|
|
|
464
|
+
| `isFluidValue(value)` | Check if value is a fluid typography value |
|
|
465
|
+
| `extractFluidValues(settings)` | Extract fluid values from theme settings |
|
|
466
|
+
| `extractTypographyPresets(settings)` | Extract typography presets |
|
|
467
|
+
| `extractIgniteTokens(settings)` | Extract all Ignite-specific tokens |
|
|
468
|
+
| `getTypographyPresetClassName(preset)` | Get CSS class for typography preset |
|
|
469
|
+
|
|
470
|
+
### CSS Generator Functions
|
|
471
|
+
|
|
472
|
+
| Function | Description |
|
|
473
|
+
|----------|-------------|
|
|
474
|
+
| `blockTypeToSelector(blockType)` | Convert block type to CSS selector |
|
|
475
|
+
| `flattenCustomToProperties(custom)` | Flatten custom properties for CSS |
|
|
476
|
+
| `generateSectionStyleCss(name, style)` | Generate CSS for a section style |
|
|
477
|
+
| `generateAllSectionStylesCss(styles)` | Generate CSS for all section styles |
|
|
478
|
+
|
|
479
|
+
### Types
|
|
480
|
+
|
|
481
|
+
| Type | Description |
|
|
482
|
+
|------|-------------|
|
|
483
|
+
| `ThemeTokens` | Complete tokens structure |
|
|
484
|
+
| `ThemeStyles` | Theme styles structure |
|
|
485
|
+
| `SectionStyle` | Section-specific styles |
|
|
486
|
+
| `ParsedTheme` | Complete parsed theme data |
|
|
487
|
+
| `ParseThemeOptions` | Options for parseTheme function |
|
|
488
|
+
| `ThemeJson` | Raw theme.json structure |
|
|
489
|
+
| `ThemeJsonSettings` | Settings section type |
|
|
490
|
+
| `ColorPreset` | Color token definition |
|
|
491
|
+
| `GradientPreset` | Gradient token definition |
|
|
492
|
+
| `DuotonePreset` | Duotone filter definition |
|
|
493
|
+
| `FontFamilyPreset` | Font family definition |
|
|
494
|
+
| `FontFace` | Font face definition |
|
|
495
|
+
| `FontSizePreset` | Font size definition |
|
|
496
|
+
| `SpacingPreset` | Spacing token definition |
|
|
497
|
+
| `ShadowPreset` | Shadow token definition |
|
|
498
|
+
| `StyleObject` | Style object for elements/blocks |
|
|
499
|
+
| `SidesObject` | Margin/padding sides object |
|
|
500
|
+
| `TokenType` | Union of token type strings |
|
|
501
|
+
| `FluidValue` | Fluid typography min/max value |
|
|
502
|
+
| `TypographyPreset` | Typography preset definition |
|
|
503
|
+
| `IgniteTokens` | Ignite WP-specific tokens |
|
|
504
|
+
|
|
505
|
+
### Zod Schemas
|
|
506
|
+
|
|
507
|
+
| Schema | Description |
|
|
508
|
+
|--------|-------------|
|
|
509
|
+
| `colorPresetSchema` | Validate color preset objects |
|
|
510
|
+
| `gradientPresetSchema` | Validate gradient preset objects |
|
|
511
|
+
| `duotonePresetSchema` | Validate duotone preset objects |
|
|
512
|
+
| `fontSizePresetSchema` | Validate font size preset objects |
|
|
513
|
+
| `spacingPresetSchema` | Validate spacing preset objects |
|
|
514
|
+
| `shadowPresetSchema` | Validate shadow preset objects |
|
|
515
|
+
|
|
516
|
+
## License
|
|
517
|
+
|
|
518
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.bench.d.ts","sourceRoot":"","sources":["../../src/__benchmarks__/parser.bench.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Theme-json package benchmarks
|
|
3
|
+
*/
|
|
4
|
+
import { bench, describe } from 'vitest';
|
|
5
|
+
import { extractTokens, extractStyles, parseThemeJson, } from '../index.js';
|
|
6
|
+
// Import test fixtures
|
|
7
|
+
import { minimalThemeJson, fullThemeJson, partialThemeJson, } from '../__tests__/fixtures/theme-json.js';
|
|
8
|
+
// Create an even larger theme.json for stress testing
|
|
9
|
+
const largeThemeJson = {
|
|
10
|
+
...fullThemeJson,
|
|
11
|
+
settings: {
|
|
12
|
+
...fullThemeJson.settings,
|
|
13
|
+
color: {
|
|
14
|
+
palette: [
|
|
15
|
+
...Array.from({ length: 50 }, (_, i) => ({
|
|
16
|
+
slug: `color-${i}`,
|
|
17
|
+
color: `#${i.toString(16).padStart(6, '0')}`,
|
|
18
|
+
name: `Color ${i}`,
|
|
19
|
+
})),
|
|
20
|
+
],
|
|
21
|
+
gradients: [
|
|
22
|
+
...Array.from({ length: 20 }, (_, i) => ({
|
|
23
|
+
slug: `gradient-${i}`,
|
|
24
|
+
gradient: `linear-gradient(${i * 10}deg, #000 0%, #fff 100%)`,
|
|
25
|
+
name: `Gradient ${i}`,
|
|
26
|
+
})),
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
typography: {
|
|
30
|
+
fontFamilies: [
|
|
31
|
+
...Array.from({ length: 10 }, (_, i) => ({
|
|
32
|
+
slug: `font-${i}`,
|
|
33
|
+
fontFamily: `"Font ${i}", sans-serif`,
|
|
34
|
+
name: `Font ${i}`,
|
|
35
|
+
})),
|
|
36
|
+
],
|
|
37
|
+
fontSizes: [
|
|
38
|
+
...Array.from({ length: 20 }, (_, i) => ({
|
|
39
|
+
slug: `size-${i}`,
|
|
40
|
+
size: `${i + 10}px`,
|
|
41
|
+
name: `Size ${i}`,
|
|
42
|
+
})),
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
spacing: {
|
|
46
|
+
spacingSizes: [
|
|
47
|
+
...Array.from({ length: 20 }, (_, i) => ({
|
|
48
|
+
slug: `spacing-${i}`,
|
|
49
|
+
size: `${i * 0.25}rem`,
|
|
50
|
+
name: `Spacing ${i}`,
|
|
51
|
+
})),
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
describe('theme-json/extractTokens', () => {
|
|
57
|
+
bench('minimal theme (empty settings)', () => {
|
|
58
|
+
extractTokens(minimalThemeJson.settings);
|
|
59
|
+
});
|
|
60
|
+
bench('partial theme (few tokens)', () => {
|
|
61
|
+
extractTokens(partialThemeJson.settings);
|
|
62
|
+
});
|
|
63
|
+
bench('full theme (complete settings)', () => {
|
|
64
|
+
extractTokens(fullThemeJson.settings);
|
|
65
|
+
});
|
|
66
|
+
bench('large theme (many tokens)', () => {
|
|
67
|
+
extractTokens(largeThemeJson.settings);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
describe('theme-json/extractStyles', () => {
|
|
71
|
+
bench('minimal theme (empty styles)', () => {
|
|
72
|
+
extractStyles(minimalThemeJson.styles);
|
|
73
|
+
});
|
|
74
|
+
bench('full theme (complete styles)', () => {
|
|
75
|
+
extractStyles(fullThemeJson.styles);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
describe('theme-json/parseThemeJson', () => {
|
|
79
|
+
bench('minimal theme', () => {
|
|
80
|
+
parseThemeJson(minimalThemeJson);
|
|
81
|
+
});
|
|
82
|
+
bench('partial theme', () => {
|
|
83
|
+
parseThemeJson(partialThemeJson);
|
|
84
|
+
});
|
|
85
|
+
bench('full theme', () => {
|
|
86
|
+
parseThemeJson(fullThemeJson);
|
|
87
|
+
});
|
|
88
|
+
bench('large theme', () => {
|
|
89
|
+
parseThemeJson(largeThemeJson);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
//# sourceMappingURL=parser.bench.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.bench.js","sourceRoot":"","sources":["../../src/__benchmarks__/parser.bench.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EACL,aAAa,EACb,aAAa,EACb,cAAc,GACf,MAAM,aAAa,CAAC;AAErB,uBAAuB;AACvB,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,gBAAgB,GACjB,MAAM,qCAAqC,CAAC;AAE7C,sDAAsD;AACtD,MAAM,cAAc,GAAG;IACrB,GAAG,aAAa;IAChB,QAAQ,EAAE;QACR,GAAG,aAA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AAC,2BAA2B,EAAE,GAAG,EAAE;IACzC,KAAK,CAAC,eAAe,EAAE,GAAG,EAAE;QAC1B,cAAc,CAAC,gBAAgB,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,KAAK,CAAC,eAAe,EAAE,GAAG,EAAE;QAC1B,cAAc,CAAC,gBAAgB,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,KAAK,CAAC,YAAY,EAAE,GAAG,EAAE;QACvB,cAAc,CAAC,aAAa,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;IAEH,KAAK,CAAC,aAAa,EAAE,GAAG,EAAE;QACxB,cAAc,CAAC,cAAc,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test fixtures for theme.json
|
|
3
|
+
*/
|
|
4
|
+
import type { ThemeJson } from '../../types.js';
|
|
5
|
+
export declare const minimalThemeJson: ThemeJson;
|
|
6
|
+
export declare const fullThemeJson: ThemeJson;
|
|
7
|
+
export declare const emptySettingsThemeJson: ThemeJson;
|
|
8
|
+
export declare const partialThemeJson: ThemeJson;
|
|
9
|
+
//# sourceMappingURL=theme-json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme-json.d.ts","sourceRoot":"","sources":["../../../src/__tests__/fixtures/theme-json.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,eAAO,MAAM,gBAAgB,EAAE,SAI9B,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,SAqL3B,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,SAQpC,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,SAc9B,CAAC"}
|