medesign 1.4.0 → 1.6.1
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 +90 -72
- package/bin/mebolder.js +4 -0
- package/bin/medesign.js +370 -35
- package/bin/melint.js +4 -0
- package/bin/mepolish.js +4 -0
- package/bin/mequiet.js +4 -0
- package/bin/mesearch.js +4 -0
- package/bin/mesnapshot.js +4 -0
- package/examples/cadastral-qaqc-slide.html +577 -0
- package/examples/executive-summary-report.html +597 -0
- package/examples/executive-summary-report.pdf +0 -0
- package/examples/geospatial-banner-1200x630.html +370 -0
- package/examples/geospatial-banner-1200x630.svg +149 -0
- package/examples/linear-issue-board.html +1273 -0
- package/examples/snapshots/cadastral-qaqc-slide-desktop-1440x900.png +0 -0
- package/examples/snapshots/cadastral-qaqc-slide-mobile-390x844.png +0 -0
- package/examples/snapshots/cadastral-qaqc-slide-tablet-820x1180.png +0 -0
- package/examples/snapshots/executive-summary-report-desktop-1440x900.png +0 -0
- package/examples/snapshots/executive-summary-report-mobile-390x844.png +0 -0
- package/examples/snapshots/executive-summary-report-tablet-820x1180.png +0 -0
- package/examples/snapshots/geospatial-banner-1200x630-og-banner-1200x630.png +0 -0
- package/examples/snapshots/linear-issue-board-desktop-1440x900.png +0 -0
- package/examples/snapshots/linear-issue-board-mobile-390x844.png +0 -0
- package/examples/snapshots/linear-issue-board-tablet-820x1180.png +0 -0
- package/examples/snapshots/spotify-web-player-desktop-1440x900.png +0 -0
- package/examples/snapshots/spotify-web-player-mobile-390x844.png +0 -0
- package/examples/snapshots/spotify-web-player-tablet-820x1180.png +0 -0
- package/examples/spotify-web-player.html +1446 -0
- package/package.json +16 -4
- package/presets/metha/guidelines.md +26 -17
- package/presets/metha/preset.json +16 -16
- package/references/ai-tells.md +9 -2
- package/references/brand-design-tokens.md +27 -28
- package/references/brief-intake.md +90 -0
- package/references/catalog.json +1031 -1023
- package/references/cli-architecture.md +1 -1
- package/references/compositor-smoothness.md +161 -0
- package/references/design-core.md +11 -4
- package/references/executive-reports.md +234 -0
- package/references/image-mockup-direction.md +53 -53
- package/references/image-to-code.md +46 -46
- package/references/modern-craft-invariants.md +55 -9
- package/references/prompt-templates.md +49 -0
- package/references/quality-gate.md +42 -12
- package/references/typography-thai-latin.md +206 -0
- package/references/view-transitions-engine.md +89 -0
- package/references/web-retrofit-protocol.md +103 -0
- package/scripts/export-tokens.js +419 -403
- package/tests/browser-audit.js +463 -442
- package/tests/linter.js +49 -4
- package/tests/snapshot.js +266 -0
package/scripts/export-tokens.js
CHANGED
|
@@ -1,403 +1,419 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* ME-DESIGN Token Exporter
|
|
5
|
-
* Converts preset design tokens into industry standard formats:
|
|
6
|
-
* 1. Tailwind CSS v4 `@theme` block
|
|
7
|
-
* 2. W3C Design Tokens Community Group (DTCG) standard specification JSON
|
|
8
|
-
* 3. Standard CSS Custom Properties (:root { ... })
|
|
9
|
-
*
|
|
10
|
-
* Usage:
|
|
11
|
-
* node scripts/export-tokens.js [--preset <name|all>] [--format <tailwind|dtcg|css|all>] [--out <dir>]
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
const fs = require('fs');
|
|
15
|
-
const path = require('path');
|
|
16
|
-
|
|
17
|
-
const presetsDir = path.join(__dirname, '..', 'presets');
|
|
18
|
-
|
|
19
|
-
// Parse CLI Arguments
|
|
20
|
-
const args = process.argv.slice(2);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (preset.
|
|
74
|
-
if (preset.
|
|
75
|
-
if (preset.
|
|
76
|
-
if (preset.
|
|
77
|
-
if (preset.
|
|
78
|
-
if (preset.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (preset.
|
|
91
|
-
if (preset.
|
|
92
|
-
if (preset.
|
|
93
|
-
if (preset.
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
$
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
$
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
$
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
$
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
$
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
$
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
if (
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
console.log(
|
|
390
|
-
console.log(
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ME-DESIGN Token Exporter
|
|
5
|
+
* Converts preset design tokens into industry standard formats:
|
|
6
|
+
* 1. Tailwind CSS v4 `@theme` block
|
|
7
|
+
* 2. W3C Design Tokens Community Group (DTCG) standard specification JSON
|
|
8
|
+
* 3. Standard CSS Custom Properties (:root { ... })
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* node scripts/export-tokens.js [--preset <name|all>] [--format <tailwind|dtcg|css|all>] [--out <dir>]
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const fs = require('fs');
|
|
15
|
+
const path = require('path');
|
|
16
|
+
|
|
17
|
+
const presetsDir = path.join(__dirname, '..', 'presets');
|
|
18
|
+
|
|
19
|
+
// Parse CLI Arguments
|
|
20
|
+
const args = process.argv.slice(2);
|
|
21
|
+
|
|
22
|
+
if (process.argv.includes('--help') || process.argv.includes('-h')) {
|
|
23
|
+
console.log(`
|
|
24
|
+
\x1b[1mME-DESIGN Token Exporter\x1b[0m
|
|
25
|
+
\x1b[90mExport preset design tokens to Tailwind v4 @theme, W3C DTCG, or CSS\x1b[0m
|
|
26
|
+
|
|
27
|
+
\x1b[1mUsage:\x1b[0m
|
|
28
|
+
medesign tokens [export] [options]
|
|
29
|
+
|
|
30
|
+
\x1b[1mOptions:\x1b[0m
|
|
31
|
+
--preset <apple|tesla|metha|all> Target preset (default: all)
|
|
32
|
+
--format <tailwind|dtcg|css|all> Target format (default: all)
|
|
33
|
+
--out <directory> Output directory (default: stdout / dist/tokens)
|
|
34
|
+
`);
|
|
35
|
+
process.exit(0);
|
|
36
|
+
}
|
|
37
|
+
let targetPreset = 'all';
|
|
38
|
+
let targetFormat = 'all';
|
|
39
|
+
let outDir = null;
|
|
40
|
+
|
|
41
|
+
for (let i = 0; i < args.length; i++) {
|
|
42
|
+
if (args[i] === '--preset' && args[i + 1]) {
|
|
43
|
+
targetPreset = args[++i].toLowerCase();
|
|
44
|
+
} else if (args[i] === '--format' && args[i + 1]) {
|
|
45
|
+
targetFormat = args[++i].toLowerCase();
|
|
46
|
+
} else if (args[i] === '--out' && args[i + 1]) {
|
|
47
|
+
outDir = args[++i];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Discover available presets
|
|
52
|
+
const presetFolders = fs.readdirSync(presetsDir, { withFileTypes: true })
|
|
53
|
+
.filter(d => d.isDirectory())
|
|
54
|
+
.map(d => d.name)
|
|
55
|
+
.filter(name => fs.existsSync(path.join(presetsDir, name, 'preset.json')));
|
|
56
|
+
|
|
57
|
+
const selectedPresets = targetPreset === 'all'
|
|
58
|
+
? presetFolders
|
|
59
|
+
: presetFolders.filter(p => p.toLowerCase() === targetPreset);
|
|
60
|
+
|
|
61
|
+
if (selectedPresets.length === 0) {
|
|
62
|
+
console.error(`Error: Preset '${targetPreset}' not found. Available presets: ${presetFolders.join(', ')}`);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Format 1: Tailwind CSS v4 @theme Generator
|
|
67
|
+
function toTailwindV4Theme(preset) {
|
|
68
|
+
const lines = ['/* Tailwind CSS v4 @theme configuration */', '/* Generated by ME-DESIGN Token Engine */', '@theme {'];
|
|
69
|
+
|
|
70
|
+
// Colors
|
|
71
|
+
if (preset.color) {
|
|
72
|
+
if (preset.color.canvas) lines.push(` --color-canvas: ${preset.color.canvas};`);
|
|
73
|
+
if (preset.color.surfaceRaised) lines.push(` --color-surface-raised: ${preset.color.surfaceRaised};`);
|
|
74
|
+
if (preset.color.surfaceInset) lines.push(` --color-surface-inset: ${preset.color.surfaceInset};`);
|
|
75
|
+
if (preset.color.borderSubtle) lines.push(` --color-border-subtle: ${preset.color.borderSubtle};`);
|
|
76
|
+
if (preset.color.borderFocus) lines.push(` --color-border-focus: ${preset.color.borderFocus};`);
|
|
77
|
+
if (preset.color.accent) lines.push(` --color-accent: ${preset.color.accent};`);
|
|
78
|
+
if (preset.color.accentForeground) lines.push(` --color-accent-foreground: ${preset.color.accentForeground};`);
|
|
79
|
+
|
|
80
|
+
if (preset.color.status) {
|
|
81
|
+
Object.entries(preset.color.status).forEach(([k, v]) => {
|
|
82
|
+
lines.push(` --color-status-${k}: ${v};`);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Typography
|
|
88
|
+
if (preset.typography) {
|
|
89
|
+
if (preset.typography.display) lines.push(` --font-display: ${preset.typography.display};`);
|
|
90
|
+
if (preset.typography.sans) lines.push(` --font-sans: ${preset.typography.sans};`);
|
|
91
|
+
if (preset.typography.mono) lines.push(` --font-mono: ${preset.typography.mono};`);
|
|
92
|
+
if (preset.typography.headingTracking) lines.push(` --tracking-heading: ${preset.typography.headingTracking};`);
|
|
93
|
+
if (preset.typography.uiLineHeight) lines.push(` --leading-ui: ${preset.typography.uiLineHeight};`);
|
|
94
|
+
if (preset.typography.proseLineHeight) lines.push(` --leading-prose: ${preset.typography.proseLineHeight};`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Geometry
|
|
98
|
+
if (preset.geometry) {
|
|
99
|
+
if (preset.geometry.radiusBase) lines.push(` --radius-base: ${preset.geometry.radiusBase};`);
|
|
100
|
+
if (preset.geometry.radiusOuter) lines.push(` --radius-outer: ${preset.geometry.radiusOuter};`);
|
|
101
|
+
if (preset.geometry.hitTargetMinTouch) lines.push(` --hit-target-min: ${preset.geometry.hitTargetMinTouch};`);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Motion
|
|
105
|
+
if (preset.motion) {
|
|
106
|
+
if (preset.motion.easingEntry) lines.push(` --ease-entry: ${preset.motion.easingEntry};`);
|
|
107
|
+
if (preset.motion.easingExit) lines.push(` --ease-exit: ${preset.motion.easingExit};`);
|
|
108
|
+
if (preset.motion.durationEntry) lines.push(` --duration-entry: ${preset.motion.durationEntry};`);
|
|
109
|
+
if (preset.motion.durationExit) lines.push(` --duration-exit: ${preset.motion.durationExit};`);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
lines.push('}');
|
|
113
|
+
return lines.join('\n');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function oklchToLinearRgb(l, c, h) {
|
|
117
|
+
const rad = h * Math.PI / 180;
|
|
118
|
+
const a = c * Math.cos(rad);
|
|
119
|
+
const b = c * Math.sin(rad);
|
|
120
|
+
|
|
121
|
+
const l1 = l + 0.3963377774 * a + 0.2158037573 * b;
|
|
122
|
+
const m1 = l - 0.1055613458 * a - 0.0638541728 * b;
|
|
123
|
+
const s1 = l - 0.0894841775 * a - 1.2914855480 * b;
|
|
124
|
+
|
|
125
|
+
const l_c = l1 * l1 * l1;
|
|
126
|
+
const m_c = m1 * m1 * m1;
|
|
127
|
+
const s_c = s1 * s1 * s1;
|
|
128
|
+
|
|
129
|
+
const r_lin = +4.0767434721 * l_c - 3.3077115913 * m_c + 0.2309699292 * s_c;
|
|
130
|
+
const g_lin = -1.2684380046 * l_c + 2.6097574011 * m_c - 0.3413193965 * s_c;
|
|
131
|
+
const b_lin = -0.0041960863 * l_c - 0.7034186147 * m_c + 1.7076147010 * s_c;
|
|
132
|
+
|
|
133
|
+
return [r_lin, g_lin, b_lin];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function inGamut(r, g, b, eps = 0.0001) {
|
|
137
|
+
return r >= -eps && r <= 1 + eps &&
|
|
138
|
+
g >= -eps && g <= 1 + eps &&
|
|
139
|
+
b >= -eps && b <= 1 + eps;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Convert OKLCH to sRGB Hex using CSS Color 4 Gamut Mapping (binary search chroma reduction)
|
|
143
|
+
function oklchToHex(colorStr) {
|
|
144
|
+
if (!colorStr || !colorStr.startsWith('oklch(')) return null;
|
|
145
|
+
const match = colorStr.match(/oklch\(\s*([\d.]+)\s+([\d.]+)\s+([\d.]+)/i);
|
|
146
|
+
if (!match) return null;
|
|
147
|
+
const l = parseFloat(match[1]);
|
|
148
|
+
const c = parseFloat(match[2]);
|
|
149
|
+
const h = parseFloat(match[3]);
|
|
150
|
+
|
|
151
|
+
const [r0, g0, b0] = oklchToLinearRgb(l, c, h);
|
|
152
|
+
let bestRgb = [r0, g0, b0];
|
|
153
|
+
|
|
154
|
+
// If outside sRGB gamut, reduce chroma via binary search while preserving lightness and hue angle
|
|
155
|
+
if (!inGamut(r0, g0, b0)) {
|
|
156
|
+
let cLow = 0;
|
|
157
|
+
let cHigh = c;
|
|
158
|
+
for (let i = 0; i < 25; i++) {
|
|
159
|
+
const cMid = (cLow + cHigh) / 2;
|
|
160
|
+
const rgb = oklchToLinearRgb(l, cMid, h);
|
|
161
|
+
if (inGamut(rgb[0], rgb[1], rgb[2])) {
|
|
162
|
+
cLow = cMid;
|
|
163
|
+
bestRgb = rgb;
|
|
164
|
+
} else {
|
|
165
|
+
cHigh = cMid;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const gamma = (x) => x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(Math.max(0, x), 1 / 2.4) - 0.055;
|
|
171
|
+
const R = Math.min(255, Math.max(0, Math.round(gamma(bestRgb[0]) * 255)));
|
|
172
|
+
const G = Math.min(255, Math.max(0, Math.round(gamma(bestRgb[1]) * 255)));
|
|
173
|
+
const B = Math.min(255, Math.max(0, Math.round(gamma(bestRgb[2]) * 255)));
|
|
174
|
+
|
|
175
|
+
return '#' + [R, G, B].map(x => x.toString(16).padStart(2, '0')).join('');
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Format 2: W3C Design Tokens Community Group (DTCG) Generator
|
|
179
|
+
// Supports 'oklch' (modern CSS Color 4) or 'srgb' (hex tokens for Figma / legacy tools)
|
|
180
|
+
function toDtcgTokens(preset, colorSpace = 'oklch') {
|
|
181
|
+
const dtcg = {
|
|
182
|
+
$name: preset.name,
|
|
183
|
+
$description: preset.description,
|
|
184
|
+
$version: '2024.1.0',
|
|
185
|
+
color: {},
|
|
186
|
+
fontFamily: {},
|
|
187
|
+
dimension: {},
|
|
188
|
+
duration: {},
|
|
189
|
+
cubicBezier: {}
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
// Colors
|
|
193
|
+
if (preset.color) {
|
|
194
|
+
Object.entries(preset.color).forEach(([k, v]) => {
|
|
195
|
+
if (typeof v === 'string') {
|
|
196
|
+
const tokenVal = colorSpace === 'srgb' ? (oklchToHex(v) || v) : v;
|
|
197
|
+
dtcg.color[k] = {
|
|
198
|
+
$value: tokenVal,
|
|
199
|
+
$type: 'color',
|
|
200
|
+
$description: `${k} color token for ${preset.name}`
|
|
201
|
+
};
|
|
202
|
+
} else if (typeof v === 'object') {
|
|
203
|
+
dtcg.color[k] = {};
|
|
204
|
+
Object.entries(v).forEach(([subK, subV]) => {
|
|
205
|
+
const tokenVal = colorSpace === 'srgb' ? (oklchToHex(subV) || subV) : subV;
|
|
206
|
+
dtcg.color[k][subK] = {
|
|
207
|
+
$value: tokenVal,
|
|
208
|
+
$type: 'color',
|
|
209
|
+
$description: `${k}.${subK} color token for ${preset.name}`
|
|
210
|
+
};
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Typography
|
|
217
|
+
if (preset.typography) {
|
|
218
|
+
['display', 'sans', 'mono'].forEach(fontKey => {
|
|
219
|
+
if (preset.typography[fontKey]) {
|
|
220
|
+
dtcg.fontFamily[fontKey] = {
|
|
221
|
+
$value: preset.typography[fontKey],
|
|
222
|
+
$type: 'fontFamily',
|
|
223
|
+
$description: `${fontKey} font stack`
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
if (preset.typography.headingTracking) {
|
|
228
|
+
dtcg.dimension.headingTracking = {
|
|
229
|
+
$value: preset.typography.headingTracking,
|
|
230
|
+
$type: 'dimension',
|
|
231
|
+
$description: 'Optical negative tracking for headings'
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Geometry
|
|
237
|
+
if (preset.geometry) {
|
|
238
|
+
if (preset.geometry.radiusBase) {
|
|
239
|
+
dtcg.dimension.radiusBase = {
|
|
240
|
+
$value: preset.geometry.radiusBase,
|
|
241
|
+
$type: 'dimension',
|
|
242
|
+
$description: 'Base corner radius'
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
if (preset.geometry.radiusOuter) {
|
|
246
|
+
dtcg.dimension.radiusOuter = {
|
|
247
|
+
$value: preset.geometry.radiusOuter,
|
|
248
|
+
$type: 'dimension',
|
|
249
|
+
$description: 'Outer card corner radius'
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
if (preset.geometry.hitTargetMinTouch) {
|
|
253
|
+
dtcg.dimension.hitTargetMin = {
|
|
254
|
+
$value: preset.geometry.hitTargetMinTouch,
|
|
255
|
+
$type: 'dimension',
|
|
256
|
+
$description: 'WCAG 2.5.8 / HIG minimum touch target dimension (44px)'
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Motion
|
|
262
|
+
if (preset.motion) {
|
|
263
|
+
if (preset.motion.durationEntry) {
|
|
264
|
+
dtcg.duration.entry = {
|
|
265
|
+
$value: preset.motion.durationEntry,
|
|
266
|
+
$type: 'duration',
|
|
267
|
+
$description: 'Entry motion timing'
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
if (preset.motion.durationExit) {
|
|
271
|
+
dtcg.duration.exit = {
|
|
272
|
+
$value: preset.motion.durationExit,
|
|
273
|
+
$type: 'duration',
|
|
274
|
+
$description: 'Exit motion timing (asymmetric 0.65x)'
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
if (preset.motion.easingEntry) {
|
|
278
|
+
dtcg.cubicBezier.entry = {
|
|
279
|
+
$value: preset.motion.easingEntry,
|
|
280
|
+
$type: 'cubicBezier',
|
|
281
|
+
$description: 'Entry cubic-bezier timing function'
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
if (preset.motion.easingExit) {
|
|
285
|
+
dtcg.cubicBezier.exit = {
|
|
286
|
+
$value: preset.motion.easingExit,
|
|
287
|
+
$type: 'cubicBezier',
|
|
288
|
+
$description: 'Exit cubic-bezier timing function'
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return JSON.stringify(dtcg, null, 2);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// Format 3: CSS Custom Properties Generator (:root { ... })
|
|
297
|
+
function toCssVariables(preset) {
|
|
298
|
+
const lines = ['/* Standard CSS Custom Properties */', '/* Generated by ME-DESIGN Token Engine */', ':root {'];
|
|
299
|
+
|
|
300
|
+
if (preset.color) {
|
|
301
|
+
Object.entries(preset.color).forEach(([k, v]) => {
|
|
302
|
+
if (typeof v === 'string') {
|
|
303
|
+
const cssKey = k.replace(/([A-Z])/g, '-$1').toLowerCase();
|
|
304
|
+
lines.push(` --color-${cssKey}: ${v};`);
|
|
305
|
+
} else if (typeof v === 'object') {
|
|
306
|
+
Object.entries(v).forEach(([subK, subV]) => {
|
|
307
|
+
lines.push(` --color-${k}-${subK}: ${subV};`);
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
if (preset.typography) {
|
|
314
|
+
if (preset.typography.sans) lines.push(` --font-sans: ${preset.typography.sans};`);
|
|
315
|
+
if (preset.typography.mono) lines.push(` --font-mono: ${preset.typography.mono};`);
|
|
316
|
+
if (preset.typography.uiLineHeight) lines.push(` --line-height-ui: ${preset.typography.uiLineHeight};`);
|
|
317
|
+
if (preset.typography.proseLineHeight) lines.push(` --line-height-prose: ${preset.typography.proseLineHeight};`);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
if (preset.geometry) {
|
|
321
|
+
if (preset.geometry.radiusBase) lines.push(` --radius-base: ${preset.geometry.radiusBase};`);
|
|
322
|
+
if (preset.geometry.radiusOuter) lines.push(` --radius-outer: ${preset.geometry.radiusOuter};`);
|
|
323
|
+
if (preset.geometry.hitTargetMinTouch) lines.push(` --hit-target-min: ${preset.geometry.hitTargetMinTouch};`);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
lines.push('}');
|
|
327
|
+
return lines.join('\n');
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// Execution CLI Guard
|
|
331
|
+
if (require.main === module) {
|
|
332
|
+
const results = [];
|
|
333
|
+
|
|
334
|
+
selectedPresets.forEach(presetId => {
|
|
335
|
+
const jsonPath = path.join(presetsDir, presetId, 'preset.json');
|
|
336
|
+
const preset = JSON.parse(fs.readFileSync(jsonPath, 'utf8'));
|
|
337
|
+
|
|
338
|
+
const exportItem = {
|
|
339
|
+
preset: presetId,
|
|
340
|
+
name: preset.name,
|
|
341
|
+
outputs: {}
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
if (targetFormat === 'tailwind' || targetFormat === 'all') {
|
|
345
|
+
exportItem.outputs.tailwind = toTailwindV4Theme(preset);
|
|
346
|
+
}
|
|
347
|
+
if (targetFormat === 'dtcg' || targetFormat === 'all') {
|
|
348
|
+
exportItem.outputs.dtcgOklch = toDtcgTokens(preset, 'oklch');
|
|
349
|
+
exportItem.outputs.dtcgSrgb = toDtcgTokens(preset, 'srgb');
|
|
350
|
+
exportItem.outputs.dtcg = exportItem.outputs.dtcgOklch;
|
|
351
|
+
}
|
|
352
|
+
if (targetFormat === 'css' || targetFormat === 'all') {
|
|
353
|
+
exportItem.outputs.css = toCssVariables(preset);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
results.push(exportItem);
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
// Output Handling
|
|
360
|
+
if (outDir) {
|
|
361
|
+
if (!fs.existsSync(outDir)) {
|
|
362
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
results.forEach(res => {
|
|
366
|
+
if (res.outputs.tailwind) {
|
|
367
|
+
fs.writeFileSync(path.join(outDir, `${res.preset}-theme.css`), res.outputs.tailwind, 'utf8');
|
|
368
|
+
}
|
|
369
|
+
if (res.outputs.dtcgOklch) {
|
|
370
|
+
fs.writeFileSync(path.join(outDir, `${res.preset}-tokens.oklch.json`), res.outputs.dtcgOklch, 'utf8');
|
|
371
|
+
fs.writeFileSync(path.join(outDir, `${res.preset}-tokens.dtcg.json`), res.outputs.dtcgOklch, 'utf8');
|
|
372
|
+
}
|
|
373
|
+
if (res.outputs.dtcgSrgb) {
|
|
374
|
+
fs.writeFileSync(path.join(outDir, `${res.preset}-tokens.srgb.json`), res.outputs.dtcgSrgb, 'utf8');
|
|
375
|
+
}
|
|
376
|
+
if (res.outputs.css) {
|
|
377
|
+
fs.writeFileSync(path.join(outDir, `${res.preset}-tokens.css`), res.outputs.css, 'utf8');
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
console.log(`Successfully exported tokens for [${selectedPresets.join(', ')}] into '${outDir}'.`);
|
|
382
|
+
} else {
|
|
383
|
+
// Stdout
|
|
384
|
+
results.forEach(res => {
|
|
385
|
+
console.log(`\n========================================`);
|
|
386
|
+
console.log(`PRESET: ${res.name} (${res.preset})`);
|
|
387
|
+
console.log(`========================================\n`);
|
|
388
|
+
if (res.outputs.tailwind) {
|
|
389
|
+
console.log(`--- [Tailwind v4 @theme] ---`);
|
|
390
|
+
console.log(res.outputs.tailwind);
|
|
391
|
+
console.log('');
|
|
392
|
+
}
|
|
393
|
+
if (res.outputs.dtcgOklch) {
|
|
394
|
+
console.log(`--- [W3C DTCG Format JSON (OKLCH Native)] ---`);
|
|
395
|
+
console.log(res.outputs.dtcgOklch);
|
|
396
|
+
console.log('');
|
|
397
|
+
}
|
|
398
|
+
if (res.outputs.dtcgSrgb) {
|
|
399
|
+
console.log(`--- [W3C DTCG Format JSON (sRGB Gamut-Mapped Hex)] ---`);
|
|
400
|
+
console.log(res.outputs.dtcgSrgb);
|
|
401
|
+
console.log('');
|
|
402
|
+
}
|
|
403
|
+
if (res.outputs.css) {
|
|
404
|
+
console.log(`--- [CSS Custom Properties] ---`);
|
|
405
|
+
console.log(res.outputs.css);
|
|
406
|
+
console.log('');
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
module.exports = {
|
|
413
|
+
oklchToHex,
|
|
414
|
+
oklchToLinearRgb,
|
|
415
|
+
inGamut,
|
|
416
|
+
toTailwindV4Theme,
|
|
417
|
+
toDtcgTokens,
|
|
418
|
+
toCssVariables
|
|
419
|
+
};
|