tokenami 0.0.77--canary.400.e4d091f.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/dist/cli.cjs ADDED
@@ -0,0 +1,1256 @@
1
+ 'use strict';
2
+
3
+ var Tokenami2 = require('@tokenami/config');
4
+ var browserslist = require('browserslist');
5
+ var lightning = require('lightningcss');
6
+ var cac = require('cac');
7
+ var glob = require('fast-glob');
8
+ var inquirer = require('inquirer');
9
+ var fs2 = require('fs');
10
+ var chokidar = require('chokidar');
11
+ var pathe = require('pathe');
12
+ var stringify = require('@stitches/stringify');
13
+ var createJiti = require('jiti');
14
+ var sucrase = require('sucrase');
15
+ var chalk = require('chalk');
16
+ var acorn = require('acorn');
17
+ var acornWalk = require('acorn-walk');
18
+
19
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
20
+
21
+ function _interopNamespace(e) {
22
+ if (e && e.__esModule) return e;
23
+ var n = Object.create(null);
24
+ if (e) {
25
+ Object.keys(e).forEach(function (k) {
26
+ if (k !== 'default') {
27
+ var d = Object.getOwnPropertyDescriptor(e, k);
28
+ Object.defineProperty(n, k, d.get ? d : {
29
+ enumerable: true,
30
+ get: function () { return e[k]; }
31
+ });
32
+ }
33
+ });
34
+ }
35
+ n.default = e;
36
+ return Object.freeze(n);
37
+ }
38
+
39
+ var Tokenami2__namespace = /*#__PURE__*/_interopNamespace(Tokenami2);
40
+ var browserslist__default = /*#__PURE__*/_interopDefault(browserslist);
41
+ var lightning__namespace = /*#__PURE__*/_interopNamespace(lightning);
42
+ var cac__default = /*#__PURE__*/_interopDefault(cac);
43
+ var glob__default = /*#__PURE__*/_interopDefault(glob);
44
+ var inquirer__default = /*#__PURE__*/_interopDefault(inquirer);
45
+ var fs2__namespace = /*#__PURE__*/_interopNamespace(fs2);
46
+ var chokidar__namespace = /*#__PURE__*/_interopNamespace(chokidar);
47
+ var pathe__namespace = /*#__PURE__*/_interopNamespace(pathe);
48
+ var createJiti__default = /*#__PURE__*/_interopDefault(createJiti);
49
+ var chalk__default = /*#__PURE__*/_interopDefault(chalk);
50
+ var acorn__namespace = /*#__PURE__*/_interopNamespace(acorn);
51
+ var acornWalk__namespace = /*#__PURE__*/_interopNamespace(acornWalk);
52
+
53
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
54
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
55
+ }) : x)(function(x) {
56
+ if (typeof require !== "undefined")
57
+ return require.apply(this, arguments);
58
+ throw Error('Dynamic require of "' + x + '" is not supported');
59
+ });
60
+
61
+ // src/supports.ts
62
+ var supportedLogical = {
63
+ "block-overflow": 1,
64
+ "block-size": 1,
65
+ "border-block": 1,
66
+ "border-block-end": 1,
67
+ "border-block-start": 1,
68
+ "border-block-color": 1,
69
+ "border-block-end-color": 1,
70
+ "border-block-end-style": 1,
71
+ "border-block-end-width": 1,
72
+ "border-block-start-color": 1,
73
+ "border-block-start-style": 1,
74
+ "border-block-start-width": 1,
75
+ "border-block-style": 1,
76
+ "border-block-width": 1,
77
+ "border-inline": 1,
78
+ "border-inline-end": 1,
79
+ "border-inline-start": 1,
80
+ "border-inline-color": 1,
81
+ "border-inline-end-color": 1,
82
+ "border-inline-end-style": 1,
83
+ "border-inline-end-width": 1,
84
+ "border-inline-start-color": 1,
85
+ "border-inline-start-style": 1,
86
+ "border-inline-start-width": 1,
87
+ "border-inline-style": 1,
88
+ "border-inline-width": 1,
89
+ "contain-intrinsic-block-size": 1,
90
+ "contain-intrinsic-inline-size": 1,
91
+ "inline-size": 1,
92
+ "inset-block": 1,
93
+ "inset-block-end": 1,
94
+ "inset-block-start": 1,
95
+ "inset-inline": 1,
96
+ "inset-inline-end": 1,
97
+ "inset-inline-start": 1,
98
+ "margin-block": 1,
99
+ "margin-block-end": 1,
100
+ "margin-block-start": 1,
101
+ "margin-inline": 1,
102
+ "margin-inline-end": 1,
103
+ "margin-inline-start": 1,
104
+ "max-block-size": 1,
105
+ "max-inline-size": 1,
106
+ "min-block-size": 1,
107
+ "min-inline-size": 1,
108
+ "overflow-block": 1,
109
+ "overflow-inline": 1,
110
+ "overscroll-behavior-block": 1,
111
+ "overscroll-behavior-inline": 1,
112
+ "padding-block": 1,
113
+ "padding-block-end": 1,
114
+ "padding-block-start": 1,
115
+ "padding-inline": 1,
116
+ "padding-inline-end": 1,
117
+ "padding-inline-start": 1,
118
+ "scroll-margin-block": 1,
119
+ "scroll-margin-block-end": 1,
120
+ "scroll-margin-block-start": 1,
121
+ "scroll-margin-inline": 1,
122
+ "scroll-margin-inline-end": 1,
123
+ "scroll-margin-inline-start": 1,
124
+ "scroll-padding-block": 1,
125
+ "scroll-padding-block-end": 1,
126
+ "scroll-padding-block-start": 1,
127
+ "scroll-padding-inline": 1,
128
+ "scroll-padding-inline-end": 1,
129
+ "scroll-padding-inline-start": 1
130
+ };
131
+ var supported = {
132
+ all: 1,
133
+ animation: 1,
134
+ "animation-range": 1,
135
+ background: 1,
136
+ "background-position": 1,
137
+ border: 1,
138
+ "border-bottom": 1,
139
+ "border-color": 1,
140
+ "border-image": 1,
141
+ "border-left": 1,
142
+ "border-radius": 1,
143
+ "border-right": 1,
144
+ "border-style": 1,
145
+ "border-top": 1,
146
+ "border-width": 1,
147
+ caret: 1,
148
+ "column-rule": 1,
149
+ columns: 1,
150
+ "contain-intrinsic-size": 1,
151
+ container: 1,
152
+ flex: 1,
153
+ "flex-flow": 1,
154
+ font: 1,
155
+ gap: 1,
156
+ grid: 1,
157
+ "grid-area": 1,
158
+ "grid-column": 1,
159
+ "grid-row": 1,
160
+ "grid-template": 1,
161
+ inset: 1,
162
+ "line-clamp": 1,
163
+ "list-style": 1,
164
+ margin: 1,
165
+ mask: 1,
166
+ "mask-border": 1,
167
+ motion: 1,
168
+ offset: 1,
169
+ outline: 1,
170
+ overflow: 1,
171
+ "overscroll-behavior": 1,
172
+ padding: 1,
173
+ "place-content": 1,
174
+ "place-items": 1,
175
+ "place-self": 1,
176
+ "scroll-margin": 1,
177
+ "scroll-padding": 1,
178
+ "scroll-snap-margin": 1,
179
+ "scroll-timeline": 1,
180
+ "text-decoration": 1,
181
+ "text-emphasis": 1,
182
+ transition: 1,
183
+ "view-timeline": 1,
184
+ "accent-color": 1,
185
+ "align-content": 1,
186
+ "align-items": 1,
187
+ "align-self": 1,
188
+ "align-tracks": 1,
189
+ "animation-composition": 1,
190
+ "animation-delay": 1,
191
+ "animation-direction": 1,
192
+ "animation-duration": 1,
193
+ "animation-fill-mode": 1,
194
+ "animation-iteration-count": 1,
195
+ "animation-name": 1,
196
+ "animation-play-state": 1,
197
+ "animation-range-end": 1,
198
+ "animation-range-start": 1,
199
+ "animation-timeline": 1,
200
+ "animation-timing-function": 1,
201
+ appearance: 1,
202
+ "aspect-ratio": 1,
203
+ "backdrop-filter": 1,
204
+ "backface-visibility": 1,
205
+ "background-attachment": 1,
206
+ "background-blend-mode": 1,
207
+ "background-clip": 1,
208
+ "background-color": 1,
209
+ "background-image": 1,
210
+ "background-origin": 1,
211
+ "background-position-x": 1,
212
+ "background-position-y": 1,
213
+ "background-repeat": 1,
214
+ "background-size": 1,
215
+ "border-bottom-color": 1,
216
+ "border-bottom-left-radius": 1,
217
+ "border-bottom-right-radius": 1,
218
+ "border-bottom-style": 1,
219
+ "border-bottom-width": 1,
220
+ "border-collapse": 1,
221
+ "border-end-end-radius": 1,
222
+ "border-end-start-radius": 1,
223
+ "border-image-outset": 1,
224
+ "border-image-repeat": 1,
225
+ "border-image-slice": 1,
226
+ "border-image-source": 1,
227
+ "border-image-width": 1,
228
+ "border-left-color": 1,
229
+ "border-left-style": 1,
230
+ "border-left-width": 1,
231
+ "border-right-color": 1,
232
+ "border-right-style": 1,
233
+ "border-right-width": 1,
234
+ "border-spacing": 1,
235
+ "border-start-end-radius": 1,
236
+ "border-start-start-radius": 1,
237
+ "border-top-color": 1,
238
+ "border-top-left-radius": 1,
239
+ "border-top-right-radius": 1,
240
+ "border-top-style": 1,
241
+ "border-top-width": 1,
242
+ bottom: 1,
243
+ "box-decoration-break": 1,
244
+ "box-shadow": 1,
245
+ "box-sizing": 1,
246
+ "break-after": 1,
247
+ "break-before": 1,
248
+ "break-inside": 1,
249
+ "caption-side": 1,
250
+ "caret-color": 1,
251
+ "caret-shape": 1,
252
+ clear: 1,
253
+ "clip-path": 1,
254
+ color: 1,
255
+ "color-adjust": 1,
256
+ "color-scheme": 1,
257
+ "column-count": 1,
258
+ "column-fill": 1,
259
+ "column-gap": 1,
260
+ "column-rule-color": 1,
261
+ "column-rule-style": 1,
262
+ "column-rule-width": 1,
263
+ "column-span": 1,
264
+ "column-width": 1,
265
+ contain: 1,
266
+ "contain-intrinsic-height": 1,
267
+ "contain-intrinsic-width": 1,
268
+ "container-name": 1,
269
+ "container-type": 1,
270
+ content: 1,
271
+ "content-visibility": 1,
272
+ "counter-increment": 1,
273
+ "counter-reset": 1,
274
+ "counter-set": 1,
275
+ cursor: 1,
276
+ direction: 1,
277
+ display: 1,
278
+ "empty-cells": 1,
279
+ filter: 1,
280
+ "flex-basis": 1,
281
+ "flex-direction": 1,
282
+ "flex-grow": 1,
283
+ "flex-shrink": 1,
284
+ "flex-wrap": 1,
285
+ float: 1,
286
+ "font-family": 1,
287
+ "font-feature-settings": 1,
288
+ "font-kerning": 1,
289
+ "font-language-override": 1,
290
+ "font-optical-sizing": 1,
291
+ "font-palette": 1,
292
+ "font-size": 1,
293
+ "font-size-adjust": 1,
294
+ "font-smooth": 1,
295
+ "font-stretch": 1,
296
+ "font-style": 1,
297
+ "font-synthesis": 1,
298
+ "font-synthesis-position": 1,
299
+ "font-synthesis-small-caps": 1,
300
+ "font-synthesis-style": 1,
301
+ "font-synthesis-weight": 1,
302
+ "font-variant": 1,
303
+ "font-variant-alternates": 1,
304
+ "font-variant-caps": 1,
305
+ "font-variant-east-asian": 1,
306
+ "font-variant-emoji": 1,
307
+ "font-variant-ligatures": 1,
308
+ "font-variant-numeric": 1,
309
+ "font-variant-position": 1,
310
+ "font-variation-settings": 1,
311
+ "font-weight": 1,
312
+ "forced-color-adjust": 1,
313
+ "grid-auto-columns": 1,
314
+ "grid-auto-flow": 1,
315
+ "grid-auto-rows": 1,
316
+ "grid-column-end": 1,
317
+ "grid-column-start": 1,
318
+ "grid-row-end": 1,
319
+ "grid-row-start": 1,
320
+ "grid-template-areas": 1,
321
+ "grid-template-columns": 1,
322
+ "grid-template-rows": 1,
323
+ "hanging-punctuation": 1,
324
+ height: 1,
325
+ "hyphenate-character": 1,
326
+ "hyphenate-limit-chars": 1,
327
+ hyphens: 1,
328
+ "image-orientation": 1,
329
+ "image-rendering": 1,
330
+ "image-resolution": 1,
331
+ "initial-letter": 1,
332
+ "input-security": 1,
333
+ isolation: 1,
334
+ "justify-content": 1,
335
+ "justify-items": 1,
336
+ "justify-self": 1,
337
+ "justify-tracks": 1,
338
+ left: 1,
339
+ "letter-spacing": 1,
340
+ "line-break": 1,
341
+ "line-height": 1,
342
+ "line-height-step": 1,
343
+ "list-style-image": 1,
344
+ "list-style-position": 1,
345
+ "list-style-type": 1,
346
+ "margin-bottom": 1,
347
+ "margin-left": 1,
348
+ "margin-right": 1,
349
+ "margin-top": 1,
350
+ "margin-trim": 1,
351
+ "mask-border-mode": 1,
352
+ "mask-border-outset": 1,
353
+ "mask-border-repeat": 1,
354
+ "mask-border-slice": 1,
355
+ "mask-border-source": 1,
356
+ "mask-border-width": 1,
357
+ "mask-clip": 1,
358
+ "mask-composite": 1,
359
+ "mask-image": 1,
360
+ "mask-mode": 1,
361
+ "mask-origin": 1,
362
+ "mask-position": 1,
363
+ "mask-repeat": 1,
364
+ "mask-size": 1,
365
+ "mask-type": 1,
366
+ "masonry-auto-flow": 1,
367
+ "math-depth": 1,
368
+ "math-shift": 1,
369
+ "math-style": 1,
370
+ "max-height": 1,
371
+ "max-lines": 1,
372
+ "max-width": 1,
373
+ "min-height": 1,
374
+ "min-width": 1,
375
+ "mix-blend-mode": 1,
376
+ "motion-distance": 1,
377
+ "motion-path": 1,
378
+ "motion-rotation": 1,
379
+ "object-fit": 1,
380
+ "object-position": 1,
381
+ "offset-anchor": 1,
382
+ "offset-distance": 1,
383
+ "offset-path": 1,
384
+ "offset-position": 1,
385
+ "offset-rotate": 1,
386
+ "offset-rotation": 1,
387
+ opacity: 1,
388
+ order: 1,
389
+ orphans: 1,
390
+ "outline-color": 1,
391
+ "outline-offset": 1,
392
+ "outline-style": 1,
393
+ "outline-width": 1,
394
+ "overflow-anchor": 1,
395
+ "overflow-clip-box": 1,
396
+ "overflow-clip-margin": 1,
397
+ "overflow-wrap": 1,
398
+ "overflow-x": 1,
399
+ "overflow-y": 1,
400
+ overlay: 1,
401
+ "overscroll-behavior-x": 1,
402
+ "overscroll-behavior-y": 1,
403
+ "padding-bottom": 1,
404
+ "padding-left": 1,
405
+ "padding-right": 1,
406
+ "padding-top": 1,
407
+ page: 1,
408
+ "page-break-after": 1,
409
+ "page-break-before": 1,
410
+ "page-break-inside": 1,
411
+ "paint-order": 1,
412
+ perspective: 1,
413
+ "perspective-origin": 1,
414
+ "pointer-events": 1,
415
+ position: 1,
416
+ "print-color-adjust": 1,
417
+ quotes: 1,
418
+ resize: 1,
419
+ right: 1,
420
+ rotate: 1,
421
+ "row-gap": 1,
422
+ "ruby-align": 1,
423
+ "ruby-merge": 1,
424
+ "ruby-position": 1,
425
+ scale: 1,
426
+ "scroll-behavior": 1,
427
+ "scroll-margin-bottom": 1,
428
+ "scroll-margin-left": 1,
429
+ "scroll-margin-right": 1,
430
+ "scroll-margin-top": 1,
431
+ "scroll-padding-bottom": 1,
432
+ "scroll-padding-left": 1,
433
+ "scroll-padding-right": 1,
434
+ "scroll-padding-top": 1,
435
+ "scroll-snap-align": 1,
436
+ "scroll-snap-margin-bottom": 1,
437
+ "scroll-snap-margin-left": 1,
438
+ "scroll-snap-margin-right": 1,
439
+ "scroll-snap-margin-top": 1,
440
+ "scroll-snap-stop": 1,
441
+ "scroll-snap-type": 1,
442
+ "scroll-timeline-axis": 1,
443
+ "scroll-timeline-name": 1,
444
+ "scrollbar-color": 1,
445
+ "scrollbar-gutter": 1,
446
+ "scrollbar-width": 1,
447
+ "shape-image-threshold": 1,
448
+ "shape-margin": 1,
449
+ "shape-outside": 1,
450
+ "tab-size": 1,
451
+ "table-layout": 1,
452
+ "text-align": 1,
453
+ "text-align-last": 1,
454
+ "text-combine-upright": 1,
455
+ "text-decoration-color": 1,
456
+ "text-decoration-line": 1,
457
+ "text-decoration-skip": 1,
458
+ "text-decoration-skip-ink": 1,
459
+ "text-decoration-style": 1,
460
+ "text-decoration-thickness": 1,
461
+ "text-emphasis-color": 1,
462
+ "text-emphasis-position": 1,
463
+ "text-emphasis-style": 1,
464
+ "text-indent": 1,
465
+ "text-justify": 1,
466
+ "text-orientation": 1,
467
+ "text-overflow": 1,
468
+ "text-rendering": 1,
469
+ "text-shadow": 1,
470
+ "text-size-adjust": 1,
471
+ "text-transform": 1,
472
+ "text-underline-offset": 1,
473
+ "text-underline-position": 1,
474
+ "text-wrap": 1,
475
+ "timeline-scope": 1,
476
+ top: 1,
477
+ "touch-action": 1,
478
+ transform: 1,
479
+ "transform-box": 1,
480
+ "transform-origin": 1,
481
+ "transform-style": 1,
482
+ "transition-behavior": 1,
483
+ "transition-delay": 1,
484
+ "transition-duration": 1,
485
+ "transition-property": 1,
486
+ "transition-timing-function": 1,
487
+ translate: 1,
488
+ "unicode-bidi": 1,
489
+ "user-select": 1,
490
+ "vertical-align": 1,
491
+ "view-timeline-axis": 1,
492
+ "view-timeline-inset": 1,
493
+ "view-timeline-name": 1,
494
+ "view-transition-name": 1,
495
+ visibility: 1,
496
+ "white-space": 1,
497
+ "white-space-collapse": 1,
498
+ "white-space-trim": 1,
499
+ widows: 1,
500
+ width: 1,
501
+ "will-change": 1,
502
+ "word-break": 1,
503
+ "word-spacing": 1,
504
+ "word-wrap": 1,
505
+ "writing-mode": 1,
506
+ "z-index": 1,
507
+ zoom: 1,
508
+ "alignment-baseline": 1,
509
+ "baseline-shift": 1,
510
+ clip: 1,
511
+ "clip-rule": 1,
512
+ "color-interpolation": 1,
513
+ "color-rendering": 1,
514
+ "dominant-baseline": 1,
515
+ fill: 1,
516
+ "fill-opacity": 1,
517
+ "fill-rule": 1,
518
+ "flood-color": 1,
519
+ "flood-opacity": 1,
520
+ "glyph-orientation-vertical": 1,
521
+ "lighting-color": 1,
522
+ marker: 1,
523
+ "marker-end": 1,
524
+ "marker-mid": 1,
525
+ "marker-start": 1,
526
+ "shape-rendering": 1,
527
+ "stop-color": 1,
528
+ "stop-opacity": 1,
529
+ stroke: 1,
530
+ "stroke-dasharray": 1,
531
+ "stroke-dashoffset": 1,
532
+ "stroke-linecap": 1,
533
+ "stroke-linejoin": 1,
534
+ "stroke-miterlimit": 1,
535
+ "stroke-opacity": 1,
536
+ "stroke-width": 1,
537
+ "text-anchor": 1,
538
+ "vector-effect": 1,
539
+ ...supportedLogical
540
+ };
541
+ var inheritedProperties = /* @__PURE__ */ new Set([
542
+ "azimuth",
543
+ "border-collapse",
544
+ "border-spacing",
545
+ "caption-side",
546
+ "color",
547
+ "cursor",
548
+ "direction",
549
+ "empty-cells",
550
+ "font-family",
551
+ "font-size",
552
+ "font-style",
553
+ "font-variant",
554
+ "font-weight",
555
+ "font-stretch",
556
+ "font",
557
+ "letter-spacing",
558
+ "line-height",
559
+ "list-style-image",
560
+ "list-style-position",
561
+ "list-style-type",
562
+ "list-style",
563
+ "orphans",
564
+ "quotes",
565
+ "text-align",
566
+ "text-indent",
567
+ "text-transform",
568
+ "visibility",
569
+ "white-space",
570
+ "widows",
571
+ "word-spacing"
572
+ ]);
573
+ var supportedProperties = new Set(Object.keys(supported));
574
+ var supportedLogicalProperties = new Set(Object.keys(supportedLogical));
575
+
576
+ // src/utils.ts
577
+ var DEFAULT_PATHS = {
578
+ js: "./.tokenami/tokenami.config.js",
579
+ ts: "./.tokenami/tokenami.config.ts",
580
+ cjs: "./.tokenami/tokenami.config.cjs",
581
+ mjs: "./.tokenami/tokenami.config.mjs"
582
+ };
583
+ function getConfigPath(cwd, path, type) {
584
+ path = path || getConfigDefaultPath(cwd, type);
585
+ return pathe__namespace.join(cwd, path);
586
+ }
587
+ function getConfigAtPath(path) {
588
+ const config = function() {
589
+ try {
590
+ return __require(path);
591
+ } catch {
592
+ return lazyJiti()(path);
593
+ }
594
+ }();
595
+ return mergedConfigs(config.default ?? config);
596
+ }
597
+ function getReloadedConfigAtPath(path) {
598
+ const config = function() {
599
+ try {
600
+ delete __require.cache[__require.resolve(path)];
601
+ return __require(path);
602
+ } catch {
603
+ return lazyJiti({ cache: false })(path);
604
+ }
605
+ }();
606
+ return mergedConfigs(config.default ?? config);
607
+ }
608
+ function getConfigDefaultPath(cwd, type) {
609
+ const existingConfig = Object.values(DEFAULT_PATHS).find((path) => {
610
+ return fs2__namespace.existsSync(pathe__namespace.join(cwd, path));
611
+ });
612
+ return existingConfig || DEFAULT_PATHS[type || "js"];
613
+ }
614
+ function getTypeDefsPath(configPath) {
615
+ const dirname3 = pathe__namespace.dirname(configPath);
616
+ return `${dirname3}/tokenami.env.d.ts`;
617
+ }
618
+ function getCiTypeDefsPath(configPath) {
619
+ const dirname3 = pathe__namespace.dirname(configPath);
620
+ return `${dirname3}/tokenami.env.ci.d.ts`;
621
+ }
622
+ function getThemeValuesByTokenValues(tokenValues, theme) {
623
+ const entries = getThemeValueByTokenValueEntries(tokenValues, theme);
624
+ return Object.fromEntries(entries);
625
+ }
626
+ function getThemeValueByTokenValueEntries(tokenValues, theme) {
627
+ const sorted = [...tokenValues].sort();
628
+ return sorted.flatMap((tokenValue) => {
629
+ const parts = Tokenami2__namespace.getTokenValueParts(tokenValue);
630
+ const value = theme[parts.themeKey]?.[parts.token];
631
+ if (value == null)
632
+ return [];
633
+ const valueString = String(value);
634
+ const tokenValues2 = findTokenValuesInThemeValue(valueString);
635
+ const themeValuesEntries = getThemeValueByTokenValueEntries(tokenValues2, theme);
636
+ return [[parts.property, valueString], ...themeValuesEntries];
637
+ });
638
+ }
639
+ function findTokenValuesInThemeValue(themeValue) {
640
+ const cssVariables = themeValue.match(/var\([\w-_]+\)/g) || [];
641
+ const tokenValues = cssVariables.filter((v) => Tokenami2__namespace.TokenValue.safeParse(v).success);
642
+ return tokenValues;
643
+ }
644
+ function getThemeFromConfig(themeConfig) {
645
+ const { modes = {}, root, ...base } = themeConfig;
646
+ if ("modes" in themeConfig) {
647
+ const config = themeConfig;
648
+ return { modes: config.modes, root: config.root };
649
+ }
650
+ return { modes: {}, root: base };
651
+ }
652
+ function getThemeValuesByThemeMode(tokenValue, themeConfig) {
653
+ const theme = getThemeFromConfig(themeConfig);
654
+ const parts = Tokenami2__namespace.getTokenValueParts(tokenValue);
655
+ const modeThemeEntries = Object.entries(theme.modes);
656
+ const modeValues = modeThemeEntries.concat([["root", theme.root]]).flatMap(([mode, theme2]) => {
657
+ const value = theme2[parts.themeKey]?.[parts.token];
658
+ return value == null ? [] : [[mode, String(value)]];
659
+ });
660
+ return Object.fromEntries(modeValues);
661
+ }
662
+ function generateConfig(include, configPath) {
663
+ const filename = pathe__namespace.basename(configPath);
664
+ const configStubPath = pathe__namespace.resolve(__dirname, `../stubs/${filename}`);
665
+ const configStub = fs2__namespace.readFileSync(configStubPath, "utf8");
666
+ return configStub.replace("include: []", `include: [${include}]`);
667
+ }
668
+ function mergedConfigs(theirs) {
669
+ return theirs;
670
+ }
671
+ function generateTypeDefs(configPath, stubPath = "../stubs/tokenami.env.d.ts") {
672
+ const parsed = pathe__namespace.parse(configPath);
673
+ const typeDefStubPath = pathe__namespace.resolve(__dirname, stubPath);
674
+ const typeDefStub = fs2__namespace.readFileSync(typeDefStubPath, "utf8");
675
+ return typeDefStub.replace("tokenami.config", parsed.name);
676
+ }
677
+ function generateCiTypeDefs(configPath) {
678
+ return generateTypeDefs(configPath, "../stubs/tokenami.env.ci.d.ts");
679
+ }
680
+ function getResponsivePropertyVariants(tokenProperty2, responsive) {
681
+ return Object.keys(responsive || {}).map((query) => {
682
+ const name = Tokenami2__namespace.getTokenPropertyName(tokenProperty2);
683
+ return Tokenami2__namespace.variantProperty(query, name);
684
+ });
685
+ }
686
+ function getValidProperties(config) {
687
+ return /* @__PURE__ */ new Set([
688
+ ...supportedProperties,
689
+ ...Object.keys(config.properties || {}),
690
+ ...Object.keys(config.customProperties || {}),
691
+ ...Object.keys(config.aliases || {})
692
+ ]);
693
+ }
694
+ function unique(items) {
695
+ return Array.from(new Set(items));
696
+ }
697
+ var jitiCache = {};
698
+ function lazyJiti(options = {}) {
699
+ const cacheId = JSON.stringify(options);
700
+ return jitiCache[cacheId] ??= createJiti__default.default(__filename, {
701
+ transform: (opts) => sucrase.transform(opts.source, { transforms: ["typescript", "imports"] }),
702
+ interopDefault: true,
703
+ requireCache: options.cache
704
+ });
705
+ }
706
+ function error(str) {
707
+ console.error(`${chalk__default.default.bgRed(" tokenami ")} ${chalk__default.default.red(str)}`);
708
+ process.exit(1);
709
+ }
710
+ function debug(str) {
711
+ console.debug(`${chalk__default.default.bgYellow(" tokenami ")} ${chalk__default.default.yellow(str)}`);
712
+ }
713
+
714
+ // src/sheet.ts
715
+ var UNUSED_LAYERS_REGEX = /[\n\s]*@layer[^;{]+;/g;
716
+ var DEFAULT_SELECTOR = "[style]";
717
+ var CUSTOM_PROP_PREFIX = "--_";
718
+ var LAYERS = {
719
+ BASE: "tk",
720
+ LOGICAL: "tkl",
721
+ SELECTORS: "tks",
722
+ SELECTORS_LOGICAL: "tksl"
723
+ };
724
+ function generate(params) {
725
+ try {
726
+ const sheet = createSheet(params);
727
+ const transformed = lightning__namespace.transform({
728
+ code: Buffer.from(sheet),
729
+ filename: params.output,
730
+ minify: params.minify,
731
+ targets: params.targets
732
+ });
733
+ return transformed.code.toString().replace(UNUSED_LAYERS_REGEX, "");
734
+ } catch (e) {
735
+ const message = e instanceof Error ? e.message : "Unknown error";
736
+ const escapedMessage = message.replace(/(['"])/g, "\\$1");
737
+ debug(`Error generating stylesheet: ${message}`);
738
+ return `body::after { content: 'Error generating stylesheet: ${escapedMessage}'; position: fixed; inset: 0; background: #ec6142; color: white; padding: 20px; font-family: sans-serif; z-index: 9999; }`;
739
+ }
740
+ }
741
+ function createSheet(params) {
742
+ if (!params.tokens.properties.length)
743
+ return "";
744
+ const tokenProperties = params.tokens.properties;
745
+ const tokenValues = params.tokens.values;
746
+ const propertyConfigsByCSSProperty = getPropertyConfigs(tokenProperties, params.config);
747
+ const allPropertyConfigs = Array.from(propertyConfigsByCSSProperty.values()).flat();
748
+ const elemSelectors = unique(
749
+ allPropertyConfigs.map((config) => {
750
+ const selectors = getSelectorsFromConfig(config.selector, params.config);
751
+ return selectors.find(isElementSelector) || DEFAULT_SELECTOR;
752
+ })
753
+ );
754
+ const styles = {
755
+ reset: /* @__PURE__ */ new Set(),
756
+ atomic: /* @__PURE__ */ new Set(),
757
+ selectors: /* @__PURE__ */ new Set(),
758
+ toggles: {}
759
+ };
760
+ propertyConfigsByCSSProperty.forEach((configs, cssProperty) => {
761
+ const isLogical = supportedLogicalProperties.has(cssProperty);
762
+ const isInheritable = inheritedProperties.has(cssProperty);
763
+ const sortedConfigs = [...configs].sort((a, b) => a.order - b.order);
764
+ const variants = sortedConfigs.flatMap((config) => config.variant ? [config.variant] : []);
765
+ const variantValue = unique(variants).reduce((fallback, variant) => {
766
+ const hashedProperty = hashVariantProperty(variant, cssProperty);
767
+ return `var(${hashedProperty}, ${fallback})`;
768
+ }, "revert-layer");
769
+ configs.forEach((config) => {
770
+ const layerIndex = getAtomicLayerIndex(cssProperty, params.config);
771
+ const toggleKey = config.responsive || config.selector;
772
+ const propertyPrefix = config.isCustom ? CUSTOM_PROP_PREFIX : "";
773
+ if (layerIndex === -1)
774
+ return;
775
+ if (config.variant && toggleKey) {
776
+ const responsive = getResponsiveSelectorFromConfig(config.responsive, params.config);
777
+ const selectors = getSelectorsFromConfig(config.selector, params.config);
778
+ const hasCombinator = selectors.some(isCombinatorSelector);
779
+ const responsiveSelectors = [responsive, ...selectors].filter(Boolean);
780
+ const hashedProperty = hashVariantProperty(config.variant, cssProperty);
781
+ const variantProperty2 = Tokenami2__namespace.parsedVariantProperty(config.variant, cssProperty);
782
+ const basePropertyValue = getBasePropertyValue(variantProperty2, config, false);
783
+ const toggleProperty = Tokenami2__namespace.parsedTokenProperty(config.variant);
784
+ const toggleDeclaration = `${hashedProperty}: var(${toggleProperty}) ${basePropertyValue};`;
785
+ const layer = `${isLogical ? LAYERS.SELECTORS_LOGICAL : LAYERS.SELECTORS}${layerIndex}`;
786
+ const customPropertyFallback = `var(${Tokenami2__namespace.tokenProperty(cssProperty)})`;
787
+ const customPropertyValue = variantValue.replace("revert-layer", customPropertyFallback);
788
+ const declaration = `${propertyPrefix}${cssProperty}: ${config.isCustom ? customPropertyValue : variantValue};`;
789
+ const toggle = responsiveSelectors.reduceRight(
790
+ (declaration2, selector) => `${selector} { ${declaration2} }`,
791
+ `${toggleProperty}: ;`
792
+ );
793
+ styles.reset.add(`${toggleProperty}: initial;`);
794
+ if (!isInheritable && !hasCombinator)
795
+ styles.reset.add(`${variantProperty2}: initial;`);
796
+ styles.selectors.add(`@layer ${layer} { ${elemSelectors} { ${declaration} } }`);
797
+ styles.selectors.add(`@layer ${layer} { ${elemSelectors} { ${toggleDeclaration} } }`);
798
+ styles.toggles[toggleKey] ??= /* @__PURE__ */ new Set();
799
+ styles.toggles[toggleKey].add(toggle);
800
+ if (config.isGrid) {
801
+ const gridToggle = getGridPropertyToggle(variantProperty2);
802
+ styles.selectors.add(`@layer ${layer} { ${elemSelectors} { ${gridToggle} } }`);
803
+ }
804
+ } else {
805
+ const propertyValue = getBasePropertyValue(config.tokenProperty, config);
806
+ const declaration = `${DEFAULT_SELECTOR} { ${propertyPrefix}${cssProperty}: ${propertyValue}; }`;
807
+ const layer = `${isLogical ? LAYERS.LOGICAL : LAYERS.BASE}${layerIndex}`;
808
+ if (!isInheritable)
809
+ styles.reset.add(`${config.tokenProperty}: initial;`);
810
+ styles.atomic.add(`@layer ${layer} { ${declaration} }`);
811
+ if (config.isGrid) {
812
+ const gridToggle = getGridPropertyToggle(config.tokenProperty);
813
+ styles.atomic.add(`@layer ${layer} { ${DEFAULT_SELECTOR} { ${gridToggle} } }`);
814
+ }
815
+ }
816
+ });
817
+ });
818
+ return `
819
+ @layer global {
820
+ ${params.config.globalStyles ? stringify.stringify(params.config.globalStyles) : ""}
821
+ }
822
+
823
+ @layer tokenami {
824
+ ${generateKeyframeRules(tokenValues, params.config)}
825
+ ${generateThemeTokens(tokenValues, params.config)}
826
+
827
+ * { ${Array.from(styles.reset).join(" ")} }
828
+
829
+ ${generatePlaceholderLayers(LAYERS.BASE)}
830
+ ${generatePlaceholderLayers(LAYERS.LOGICAL)}
831
+ ${generatePlaceholderLayers(LAYERS.SELECTORS)}
832
+ ${generatePlaceholderLayers(LAYERS.SELECTORS_LOGICAL)}
833
+
834
+ ${Array.from(styles.atomic).join(" ")}
835
+ ${Array.from(styles.selectors).join(" ")}
836
+
837
+ ${Object.values(styles.toggles).flatMap((set) => Array.from(set)).join(" ")}
838
+ }
839
+ `;
840
+ }
841
+ function getGridPropertyToggle(property) {
842
+ const hashGridProperty = hashVariantProperty("grid", property);
843
+ const gridProperty3 = Tokenami2__namespace.gridProperty();
844
+ return `${hashGridProperty}: var(${property}__calc) calc(var(${property}) * var(${gridProperty3}));`;
845
+ }
846
+ function getBasePropertyValue(property, config, revert = true) {
847
+ const hashGridProperty = hashVariantProperty("grid", property);
848
+ const baseProperty = `var(${property}${revert ? ", revert-layer" : ""})`;
849
+ return config.isGrid ? `var(${hashGridProperty}, ${baseProperty})` : baseProperty;
850
+ }
851
+ function generatePlaceholderLayers(prefix) {
852
+ return `@layer ${Array.from({ length: 20 }).map((_, layer) => `${prefix}${layer}`).join(", ")};`;
853
+ }
854
+ function getPropertyConfigs(tokenProperties, config) {
855
+ let propertyConfigs = /* @__PURE__ */ new Map();
856
+ const customProperties = Object.keys(config.customProperties || {});
857
+ tokenProperties.forEach((tokenProperty2) => {
858
+ const parts = Tokenami2__namespace.getTokenPropertyParts(tokenProperty2, config);
859
+ if (!parts)
860
+ return;
861
+ const properties = Tokenami2__namespace.getCSSPropertiesForAlias(parts.alias, config.aliases);
862
+ const responsiveOrder = parts.responsive ? 1 : 0;
863
+ const selectorOrder = parts.selector ? 2 : 0;
864
+ const order = responsiveOrder + selectorOrder;
865
+ properties.forEach((cssProperty) => {
866
+ const tokenProperty3 = Tokenami2__namespace.parsedTokenProperty(cssProperty);
867
+ const currentConfigs = propertyConfigs.get(cssProperty) || [];
868
+ const isCustom = customProperties.includes(cssProperty);
869
+ const isGrid = config.properties?.[cssProperty]?.includes("grid") ?? false;
870
+ const nextConfig = { ...parts, tokenProperty: tokenProperty3, order, isCustom, isGrid };
871
+ propertyConfigs.set(cssProperty, [...currentConfigs, nextConfig]);
872
+ });
873
+ });
874
+ return propertyConfigs;
875
+ }
876
+ var SHORTHAND_TO_LONGHAND_ENTRIES = [...Tokenami2__namespace.mapShorthandToLonghands.entries()];
877
+ function getAtomicLayerIndex(cssProperty, config) {
878
+ const validProperties = getValidProperties(config);
879
+ const isSupported = validProperties.has(cssProperty);
880
+ const initialDepth = isSupported ? 1 : -1;
881
+ if (cssProperty === "all")
882
+ return 0;
883
+ return SHORTHAND_TO_LONGHAND_ENTRIES.reduce((depth, [shorthand, longhands]) => {
884
+ const isLonghand = longhands.includes(cssProperty);
885
+ return isLonghand ? depth + getAtomicLayerIndex(shorthand, config) : depth;
886
+ }, initialDepth);
887
+ }
888
+ function generateKeyframeRules(tokenValues, config) {
889
+ const themeValues = tokenValues.flatMap((tokenValue) => {
890
+ return Object.values(getThemeValuesByThemeMode(tokenValue, config.theme));
891
+ });
892
+ const rules = Object.entries(config.keyframes || {}).flatMap(([name, styles]) => {
893
+ const nameRegex = new RegExp(`\\b${name}\\b`);
894
+ const isUsingKeyframeName = themeValues.some((value) => nameRegex.test(value));
895
+ if (!isUsingKeyframeName)
896
+ return [];
897
+ return [[`@keyframes ${name} { ${stringify.stringify(styles)} }`]];
898
+ });
899
+ return rules.join(" ");
900
+ }
901
+ function generateThemeTokens(tokenValues, config) {
902
+ const theme = getThemeFromConfig(config.theme);
903
+ const rootSelector = ":root";
904
+ const gridStyles = `${rootSelector} { ${Tokenami2__namespace.gridProperty()}: ${config.grid}; }`;
905
+ const rootStyles = getThemeStyles(rootSelector, tokenValues, theme.root, config);
906
+ const themeToModes = {};
907
+ const modeEntries = Object.entries(theme.modes || {});
908
+ for (const [mode, theme2] of modeEntries) {
909
+ const themeKey = JSON.stringify(theme2);
910
+ if (themeKey in themeToModes)
911
+ themeToModes[themeKey].push(mode);
912
+ else
913
+ themeToModes[themeKey] = [mode];
914
+ }
915
+ const modeStyles = Object.entries(themeToModes).map(([theme2, modes]) => {
916
+ const selector = modes.map(config.themeSelector).join(", ");
917
+ return getThemeStyles(selector, tokenValues, JSON.parse(theme2), config);
918
+ });
919
+ const themeTokens = [gridStyles, rootStyles, modeStyles.join(" ")];
920
+ return themeTokens.join(" ");
921
+ }
922
+ var getThemeStyles = (selector, tokenValues, theme, config) => {
923
+ const themeValues = getThemeValuesByTokenValues(tokenValues, theme);
924
+ const customPropertyThemeValues = getCustomPropertyThemeValues(themeValues, config);
925
+ const selectors = Array.isArray(selector) ? selector : [selector];
926
+ for (const customKey of Object.keys(customPropertyThemeValues)) {
927
+ delete themeValues[customKey];
928
+ }
929
+ const themeStyles = selectors.reduceRight(
930
+ (declaration, selector2) => `${selector2} { ${declaration} }`,
931
+ stringify.stringify(themeValues)
932
+ );
933
+ const elementSelector = selectors.at(-1);
934
+ const elementThemeStyles = getElementThemeStyles(elementSelector, customPropertyThemeValues);
935
+ const customPropertyThemeStyles = selectors.slice(0, -1).reduceRight((declaration, selector2) => {
936
+ return `${selector2} { ${declaration} }`;
937
+ }, elementThemeStyles);
938
+ return themeStyles + " " + customPropertyThemeStyles;
939
+ };
940
+ var getElementThemeStyles = (selector, themeValues) => {
941
+ const splitChained = selector.split(",");
942
+ return splitChained.map((selector2) => `${selector2}, ${selector2} ${DEFAULT_SELECTOR} { ${stringify.stringify(themeValues)} }`).join(" ");
943
+ };
944
+ function getCustomPropertyThemeValues(themeValues, config) {
945
+ const entries = Object.entries(themeValues).flatMap(([key, value]) => {
946
+ const valueWithCustomPrefixes = getPrefixedCustomPropertyValues(value, config.customProperties);
947
+ return valueWithCustomPrefixes ? [[key, valueWithCustomPrefixes]] : [];
948
+ });
949
+ return Object.fromEntries(entries);
950
+ }
951
+ var CUSTOM_PROP_REGEX = /\(--[^-][\w-]+/g;
952
+ var getPrefixedCustomPropertyValues = (themeValue, customProperties) => {
953
+ const variables = themeValue.match(CUSTOM_PROP_REGEX);
954
+ if (!variables)
955
+ return null;
956
+ return themeValue.replace(CUSTOM_PROP_REGEX, (m) => {
957
+ const match = m.replace("(", "");
958
+ const tokenProperty2 = Tokenami2__namespace.TokenProperty.safeParse(match);
959
+ if (!tokenProperty2.success)
960
+ return m;
961
+ const parts = Tokenami2__namespace.getTokenPropertySplit(tokenProperty2.output);
962
+ const isCustom = Boolean(customProperties?.[parts.alias]);
963
+ if (!isCustom)
964
+ return m;
965
+ const tokenPrefix = Tokenami2__namespace.tokenProperty("");
966
+ const customPrefixTokenValue = tokenProperty2.output.replace(tokenPrefix, CUSTOM_PROP_PREFIX);
967
+ return "(" + customPrefixTokenValue;
968
+ });
969
+ };
970
+ function hash(str) {
971
+ let hash2 = 0;
972
+ for (let i = 0, len = str.length; i < len; i++) {
973
+ let chr = str.charCodeAt(i);
974
+ hash2 = (hash2 << 5) - hash2 + chr;
975
+ hash2 |= 0;
976
+ }
977
+ return Math.abs(hash2).toString(32);
978
+ }
979
+ function hashVariantProperty(variant, property) {
980
+ return `--_${hash(variant + property)}`;
981
+ }
982
+ var PSEUDO_REGEX = /::/;
983
+ function isElementSelector(selector = "") {
984
+ return isCombinatorSelector(selector) || PSEUDO_REGEX.test(selector);
985
+ }
986
+ var COMBINATOR_REGEX = /(.+)\s\[style|style\]\s(.+)/;
987
+ function isCombinatorSelector(selector = "") {
988
+ return COMBINATOR_REGEX.test(selector);
989
+ }
990
+ function getResponsiveSelectorFromConfig(responsiveSelector, tokenamiConfig) {
991
+ return responsiveSelector && tokenamiConfig.responsive?.[responsiveSelector];
992
+ }
993
+ function getSelectorsFromConfig(propertySelector, tokenamiConfig) {
994
+ const arbitrarySelector = Tokenami2__namespace.getArbitrarySelector(propertySelector);
995
+ const configSelector = propertySelector && tokenamiConfig.selectors?.[propertySelector];
996
+ const selector = arbitrarySelector?.replace(/_/g, " ") || configSelector;
997
+ const selectors = selector ? Array.isArray(selector) ? selector : [selector] : ["&"];
998
+ const isSelectionVariant = selectors.includes("&::selection");
999
+ if (selectors.toString().indexOf("&") === -1) {
1000
+ throw new Error(`Selector '${selector}' must include '&'`);
1001
+ }
1002
+ return selectors.map((selector2) => {
1003
+ const tkSelector = isSelectionVariant ? `[style*="${propertySelector}_"]` : DEFAULT_SELECTOR;
1004
+ return selector2.replace(/&/g, tkSelector);
1005
+ });
1006
+ }
1007
+
1008
+ // package.json
1009
+ var package_default = {
1010
+ name: "tokenami",
1011
+ version: "0.0.76",
1012
+ license: "MIT",
1013
+ type: "module",
1014
+ main: "./dist/index.cjs",
1015
+ module: "./dist/index.js",
1016
+ types: "./dist/index.d.ts",
1017
+ repository: "https://github.com/tokenami/tokenami",
1018
+ publishConfig: {
1019
+ access: "public"
1020
+ },
1021
+ exports: {
1022
+ ".": {
1023
+ import: {
1024
+ types: "./dist/index.d.ts",
1025
+ default: "./dist/index.js"
1026
+ },
1027
+ require: {
1028
+ types: "./dist/index.d.cts",
1029
+ default: "./dist/index.cjs"
1030
+ }
1031
+ }
1032
+ },
1033
+ bin: {
1034
+ tokenami: "bin.js"
1035
+ },
1036
+ files: [
1037
+ "dist",
1038
+ "stubs",
1039
+ "bin.js"
1040
+ ],
1041
+ scripts: {
1042
+ build: "tsup",
1043
+ dev: "tsup --watch",
1044
+ typecheck: "tsc --noEmit"
1045
+ },
1046
+ devDependencies: {
1047
+ "@types/culori": "^2.1.0",
1048
+ "@types/inquirer": "^9.0.7",
1049
+ "@types/node": "^20.3.1",
1050
+ tsup: "^7.0.0",
1051
+ typescript: "^5.1.3"
1052
+ },
1053
+ dependencies: {
1054
+ "@stitches/stringify": "^1.2.8",
1055
+ "@tokenami/config": "workspace:*",
1056
+ "@tokenami/ds": "workspace:*",
1057
+ acorn: "^8.11.3",
1058
+ "acorn-walk": "^8.3.2",
1059
+ browserslist: "^4.22.2",
1060
+ cac: "^6.7.14",
1061
+ chalk: "^5.2.0",
1062
+ chokidar: "^3.5.3",
1063
+ csstype: "^3.1.2",
1064
+ culori: "^4.0.1",
1065
+ "fast-glob": "^3.2.12",
1066
+ inquirer: "^9.2.12",
1067
+ jiti: "^1.21.0",
1068
+ lightningcss: "1.23.0",
1069
+ pathe: "^1.1.1",
1070
+ sucrase: "^3.34.0",
1071
+ "trie-search": "^2.0.0"
1072
+ },
1073
+ peerDependencies: {
1074
+ typescript: ">= 5"
1075
+ }
1076
+ };
1077
+
1078
+ // src/cli.ts
1079
+ var questions = [
1080
+ {
1081
+ type: "list",
1082
+ name: "type",
1083
+ message: "TypeScript or JavaScript?",
1084
+ choices: [
1085
+ { name: "TypeScript", value: "ts" },
1086
+ { name: "JavaScript", value: "js" }
1087
+ ]
1088
+ },
1089
+ {
1090
+ type: "input",
1091
+ name: "folder",
1092
+ message: "What folder should Tokenami watch for token properties?",
1093
+ default: "./app"
1094
+ }
1095
+ ];
1096
+ var run = () => {
1097
+ const cli = cac__default.default("tokenami");
1098
+ const cwd = process.cwd();
1099
+ cli.command("init").option("-c, --config [path]", "Path to a custom config file").action(async (_, flags) => {
1100
+ const tsconfigPath = pathe__namespace.join(cwd, "tsconfig.json");
1101
+ const jsconfigPath = pathe__namespace.join(cwd, "jsconfig.json");
1102
+ const hasTsConfig = fs2__namespace.existsSync(tsconfigPath);
1103
+ const hasJsConfig = fs2__namespace.existsSync(jsconfigPath);
1104
+ const hasProjectConfig = hasTsConfig || hasJsConfig;
1105
+ if (hasProjectConfig)
1106
+ questions.shift();
1107
+ const answers = await inquirer__default.default.prompt(questions);
1108
+ const type = hasTsConfig ? "ts" : hasJsConfig ? "js" : answers.type;
1109
+ const extensions = type === "ts" ? "ts,tsx" : "js,jsx";
1110
+ const include = `'${answers.folder}/**/*.{${extensions}}'`;
1111
+ const configPath = getConfigPath(cwd, flags?.config, type);
1112
+ const outDir = pathe__namespace.dirname(configPath);
1113
+ const initialConfig = generateConfig(include, configPath);
1114
+ const ciTypeDefs = generateCiTypeDefs(configPath);
1115
+ const typeDefs = generateTypeDefs(configPath);
1116
+ fs2__namespace.mkdirSync(outDir, { recursive: true });
1117
+ fs2__namespace.writeFileSync(configPath, initialConfig, { flag: "w" });
1118
+ fs2__namespace.writeFileSync(getTypeDefsPath(configPath), typeDefs, { flag: "w" });
1119
+ fs2__namespace.writeFileSync(getCiTypeDefsPath(configPath), ciTypeDefs, { flag: "w" });
1120
+ debug(`Project successfully configured in './tokenami'`);
1121
+ });
1122
+ cli.command("[files]", "Include file glob").option("-c, --config [path]", "Path to a custom config file").option("-o, --output [path]", "Output file", { default: "public/tokenami.css" }).option("-w, --watch", "Watch for changes and rebuild as needed").option("--minify", "Minify CSS output").action(async (_, flags) => {
1123
+ const startTime = startTimer();
1124
+ const minify = flags.minify;
1125
+ const configPath = getConfigPath(cwd, flags.config);
1126
+ const browsers = browserslist__default.default(null, { env: process.env.NODE_ENV || "development" });
1127
+ const targets = lightning.browserslistToTargets(browsers);
1128
+ let config = getConfigAtPath(configPath);
1129
+ config.include = flags.files || config.include;
1130
+ if (!config.include.length)
1131
+ error("Provide a glob pattern to include files");
1132
+ async function regenerateStylesheet(file, config2) {
1133
+ const generateTime = startTimer();
1134
+ const tokens2 = await findUsedTokens(cwd, config2);
1135
+ generateStyles({ tokens: tokens2, cwd, out: flags.output, config: config2, minify, targets });
1136
+ debug(`Generated styles from ${file} in ${generateTime()}ms.`);
1137
+ }
1138
+ if (flags.watch) {
1139
+ const configWatcher = watch2(cwd, [configPath]);
1140
+ const tokenWatcher = watch2(cwd, config.include, config.exclude);
1141
+ debug(`Watching for changes to ${config.include}.`);
1142
+ tokenWatcher.on("all", (_2, file) => regenerateStylesheet(file, config));
1143
+ configWatcher.on("all", async (_2, file) => {
1144
+ try {
1145
+ config = getReloadedConfigAtPath(configPath);
1146
+ config.include = flags.files || config.include;
1147
+ regenerateStylesheet(file, config);
1148
+ } catch (e) {
1149
+ debug(`Skipped change to ${file} with ${e}`);
1150
+ }
1151
+ });
1152
+ process.once("SIGINT", async () => {
1153
+ await tokenWatcher.close();
1154
+ await configWatcher.close();
1155
+ });
1156
+ }
1157
+ const tokens = await findUsedTokens(cwd, config);
1158
+ generateStyles({ tokens, cwd, out: flags.output, config, minify, targets });
1159
+ debug(`Ready in ${startTime()}ms.`);
1160
+ });
1161
+ cli.help();
1162
+ cli.version(package_default.version);
1163
+ cli.parse();
1164
+ };
1165
+ function generateStyles(params) {
1166
+ const { cwd, out, ...generateParams } = params;
1167
+ const outDir = pathe__namespace.join(cwd, pathe__namespace.dirname(out));
1168
+ const outPath = pathe__namespace.join(cwd, out);
1169
+ const output = generate({ ...generateParams, output: outPath });
1170
+ fs2__namespace.mkdirSync(outDir, { recursive: true });
1171
+ fs2__namespace.writeFileSync(outPath, output, { flag: "w" });
1172
+ }
1173
+ function watch2(cwd, include, exclude) {
1174
+ return chokidar__namespace.watch(include, {
1175
+ cwd,
1176
+ persistent: true,
1177
+ ignoreInitial: true,
1178
+ ignorePermissionErrors: true,
1179
+ ignored: exclude
1180
+ });
1181
+ }
1182
+ async function findUsedTokens(cwd, config) {
1183
+ const include = config.include;
1184
+ const exclude = config.exclude;
1185
+ const entries = await glob__default.default(include, { cwd, onlyFiles: true, stats: false, ignore: exclude });
1186
+ let tokenProperties = [];
1187
+ let tokenValues = [];
1188
+ entries.forEach((entry) => {
1189
+ const fileContent = fs2__namespace.readFileSync(entry, "utf8");
1190
+ const tokens = matchTokens(fileContent, config.theme);
1191
+ const responsiveProperties = matchResponsiveComposeVariants(fileContent, config);
1192
+ tokenProperties = [...tokenProperties, ...tokens.properties, ...responsiveProperties];
1193
+ tokenValues = [...tokenValues, ...tokens.values];
1194
+ });
1195
+ return { properties: tokenProperties, values: tokenValues };
1196
+ }
1197
+ var CSS_VARIABLE_REGEX = /--(?:[\w-]+|\{[^\{\}]*\})+/g;
1198
+ function matchTokens(content, theme) {
1199
+ const matches = content.match(CSS_VARIABLE_REGEX) || [];
1200
+ const stringMatches = Array.from(matches).map(Tokenami2__namespace.stringifyProperty);
1201
+ const uniqueMatches = unique(stringMatches);
1202
+ const variableMatches = uniqueMatches.filter((match) => match !== Tokenami2__namespace.gridProperty());
1203
+ const values = variableMatches.flatMap((match) => {
1204
+ const valueProperty = Tokenami2__namespace.TokenValue.safeParse(`var(${match})`);
1205
+ if (!valueProperty.success)
1206
+ return [];
1207
+ const themeValues = getThemeValuesByThemeMode(valueProperty.output, theme);
1208
+ return Object.entries(themeValues).length ? [valueProperty.output] : [];
1209
+ });
1210
+ const properties = variableMatches.flatMap((match) => {
1211
+ const tokenProperty2 = Tokenami2__namespace.TokenProperty.safeParse(match);
1212
+ const isValue = values.includes(`var(${match})`);
1213
+ if (isValue || !tokenProperty2.success)
1214
+ return [];
1215
+ return tokenProperty2.output;
1216
+ });
1217
+ return { properties, values };
1218
+ }
1219
+ var COMPOSE_BLOCKS_REGEX = /^.*css\.compose\(\{[\s\S]*?\}\);/gm;
1220
+ function matchResponsiveComposeVariants(fileContent, config) {
1221
+ const composeBlocks = fileContent.match(COMPOSE_BLOCKS_REGEX);
1222
+ if (!composeBlocks)
1223
+ return [];
1224
+ const responsiveBlocks = composeBlocks.filter((block) => block.match("responsiveVariants"));
1225
+ return responsiveBlocks.flatMap((block) => {
1226
+ const ast = acorn__namespace.parse(block, { ecmaVersion: 2020 });
1227
+ const responsiveVariants = findResponsiveVariants(ast);
1228
+ const tokens = matchTokens(JSON.stringify(responsiveVariants), config.theme);
1229
+ return tokens.properties.flatMap((tokenProperty2) => {
1230
+ return getResponsivePropertyVariants(tokenProperty2, config.responsive);
1231
+ });
1232
+ });
1233
+ }
1234
+ function findResponsiveVariants(node) {
1235
+ let responsiveVariantsNode = null;
1236
+ acornWalk__namespace.simple(node, {
1237
+ Property(node2) {
1238
+ if (node2.key.type === "Identifier" && node2.key.name === "responsiveVariants") {
1239
+ responsiveVariantsNode = node2;
1240
+ }
1241
+ }
1242
+ });
1243
+ return responsiveVariantsNode;
1244
+ }
1245
+ function startTimer() {
1246
+ const start = performance.now();
1247
+ return () => {
1248
+ const stop = performance.now();
1249
+ return Math.round(stop - start);
1250
+ };
1251
+ }
1252
+ try {
1253
+ run();
1254
+ } catch (e) {
1255
+ error(e instanceof Error ? e.message : "Unknown error occurred.");
1256
+ }