dispersa 0.4.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -39
- package/dist/android-CRDfSB3_.d.cts +126 -0
- package/dist/android-DANJjjPO.d.ts +126 -0
- package/dist/builders.cjs +220 -64
- package/dist/builders.cjs.map +1 -1
- package/dist/builders.d.cts +15 -13
- package/dist/builders.d.ts +15 -13
- package/dist/builders.js +220 -64
- package/dist/builders.js.map +1 -1
- package/dist/cli/cli.js +120 -7
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/config.d.ts +321 -0
- package/dist/cli/config.js.map +1 -1
- package/dist/cli/index.js +119 -7
- package/dist/cli/index.js.map +1 -1
- package/dist/dispersa-BC1kDF5u.d.ts +118 -0
- package/dist/dispersa-DL3J_Pmz.d.cts +118 -0
- package/dist/errors-qT4sJgSA.d.cts +104 -0
- package/dist/errors-qT4sJgSA.d.ts +104 -0
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts +1 -83
- package/dist/errors.d.ts +1 -83
- package/dist/errors.js.map +1 -1
- package/dist/filters.cjs.map +1 -1
- package/dist/filters.d.cts +2 -2
- package/dist/filters.d.ts +2 -2
- package/dist/filters.js.map +1 -1
- package/dist/{index-CNT2Meyf.d.cts → index-Dajm5rvM.d.ts} +311 -132
- package/dist/{index-CqdaN3X0.d.ts → index-De6SjZYH.d.cts} +311 -132
- package/dist/index.cjs +813 -355
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -329
- package/dist/index.d.ts +8 -329
- package/dist/index.js +807 -355
- package/dist/index.js.map +1 -1
- package/dist/lint.cjs +1017 -0
- package/dist/lint.cjs.map +1 -0
- package/dist/lint.d.cts +463 -0
- package/dist/lint.d.ts +463 -0
- package/dist/lint.js +997 -0
- package/dist/lint.js.map +1 -0
- package/dist/preprocessors.d.cts +2 -2
- package/dist/preprocessors.d.ts +2 -2
- package/dist/renderers.cjs.map +1 -1
- package/dist/renderers.d.cts +7 -6
- package/dist/renderers.d.ts +7 -6
- package/dist/renderers.js.map +1 -1
- package/dist/transforms.cjs +0 -12
- package/dist/transforms.cjs.map +1 -1
- package/dist/transforms.d.cts +3 -7
- package/dist/transforms.d.ts +3 -7
- package/dist/transforms.js +1 -12
- package/dist/transforms.js.map +1 -1
- package/dist/{types-CZb19kiq.d.ts → types-8MLtztK3.d.ts} +56 -1
- package/dist/{types-CussyWwe.d.cts → types-BHBHRm0a.d.cts} +56 -1
- package/dist/{types-BAv39mum.d.cts → types-BltzwVYK.d.cts} +1 -1
- package/dist/{types-DWKq-eJj.d.cts → types-CAdUV-fa.d.cts} +1 -1
- package/dist/{types-CzHa7YkW.d.ts → types-DztXKlka.d.ts} +1 -1
- package/dist/{types-Bc0kA7De.d.ts → types-TQHV1MrY.d.cts} +19 -1
- package/dist/{types-Bc0kA7De.d.cts → types-TQHV1MrY.d.ts} +19 -1
- package/dist/{types-BzNcG-rI.d.ts → types-ebxDimRz.d.ts} +1 -1
- package/package.json +11 -1
package/dist/builders.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var changeCase = require('change-case');
|
|
3
4
|
var culori = require('culori');
|
|
4
5
|
var prettier = require('prettier');
|
|
5
6
|
|
|
@@ -46,19 +47,6 @@ var init_errors = __esm({
|
|
|
46
47
|
});
|
|
47
48
|
|
|
48
49
|
// src/shared/utils/token-utils.ts
|
|
49
|
-
function formatDeprecationMessage(token, description = "", format = "bracket") {
|
|
50
|
-
if (token.$deprecated == null || token.$deprecated === false) {
|
|
51
|
-
return description;
|
|
52
|
-
}
|
|
53
|
-
const deprecationMsg = typeof token.$deprecated === "string" ? token.$deprecated : "";
|
|
54
|
-
if (format === "comment") {
|
|
55
|
-
const msg2 = deprecationMsg ? ` ${deprecationMsg}` : "";
|
|
56
|
-
return `DEPRECATED${msg2}`;
|
|
57
|
-
}
|
|
58
|
-
const msg = deprecationMsg ? `: ${deprecationMsg}` : "";
|
|
59
|
-
const prefix = `[DEPRECATED${msg}]`;
|
|
60
|
-
return description ? `${prefix} ${description}` : prefix;
|
|
61
|
-
}
|
|
62
50
|
function stripInternalTokenMetadata(tokens) {
|
|
63
51
|
const cleaned = {};
|
|
64
52
|
for (const [name, token] of Object.entries(tokens)) {
|
|
@@ -132,7 +120,7 @@ function indentStr(width, level) {
|
|
|
132
120
|
function buildGeneratedFileHeader() {
|
|
133
121
|
return [
|
|
134
122
|
"// Generated by Dispersa - do not edit manually",
|
|
135
|
-
"// https://github.com/
|
|
123
|
+
"// https://github.com/dispersa-core/dispersa"
|
|
136
124
|
].join("\n");
|
|
137
125
|
}
|
|
138
126
|
function toSafeIdentifier(name, keywords, capitalize) {
|
|
@@ -336,6 +324,94 @@ var init_utils = __esm({
|
|
|
336
324
|
}
|
|
337
325
|
});
|
|
338
326
|
|
|
327
|
+
// src/renderers/metadata.ts
|
|
328
|
+
function sanitizeText(text, format) {
|
|
329
|
+
switch (format) {
|
|
330
|
+
case "css":
|
|
331
|
+
case "tailwind":
|
|
332
|
+
return text.replace(/\*\//g, "*\\/").replace(/\r?\n/g, " ").trim();
|
|
333
|
+
case "kotlin":
|
|
334
|
+
return text.replace(/\*\//g, "* /").replace(/\r?\n/g, " ").trim();
|
|
335
|
+
case "js":
|
|
336
|
+
case "swift":
|
|
337
|
+
return text.replace(/\r?\n/g, " ").trim();
|
|
338
|
+
default:
|
|
339
|
+
return text.trim();
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
function buildDeprecationText(token) {
|
|
343
|
+
if (token.$deprecated == null || token.$deprecated === false) {
|
|
344
|
+
return "";
|
|
345
|
+
}
|
|
346
|
+
const msg = typeof token.$deprecated === "string" ? token.$deprecated : "";
|
|
347
|
+
return msg ? `DEPRECATED: ${msg}` : "DEPRECATED";
|
|
348
|
+
}
|
|
349
|
+
function buildTokenDescriptionComment(token, format) {
|
|
350
|
+
if (!token.$description || token.$description === "") {
|
|
351
|
+
return void 0;
|
|
352
|
+
}
|
|
353
|
+
const text = sanitizeText(token.$description, format);
|
|
354
|
+
switch (format) {
|
|
355
|
+
case "css":
|
|
356
|
+
case "tailwind":
|
|
357
|
+
return `/* ${text} */`;
|
|
358
|
+
case "js":
|
|
359
|
+
return `// ${text}`;
|
|
360
|
+
case "swift":
|
|
361
|
+
return `/// ${text}`;
|
|
362
|
+
case "kotlin":
|
|
363
|
+
return `/** ${text} */`;
|
|
364
|
+
default:
|
|
365
|
+
return void 0;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
function buildTokenDeprecationComment(token, format) {
|
|
369
|
+
const text = buildDeprecationText(token);
|
|
370
|
+
if (!text) {
|
|
371
|
+
return void 0;
|
|
372
|
+
}
|
|
373
|
+
switch (format) {
|
|
374
|
+
case "css":
|
|
375
|
+
case "tailwind":
|
|
376
|
+
return `/* ${text} */`;
|
|
377
|
+
case "js":
|
|
378
|
+
return `// ${text}`;
|
|
379
|
+
case "swift":
|
|
380
|
+
return `/// ${text}`;
|
|
381
|
+
case "kotlin":
|
|
382
|
+
return `/** ${text} */`;
|
|
383
|
+
default:
|
|
384
|
+
return void 0;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
function buildModifierComment(modifier, context) {
|
|
388
|
+
return `/* Modifier: ${modifier}=${context} */`;
|
|
389
|
+
}
|
|
390
|
+
function buildSwiftDeprecationAttribute(token) {
|
|
391
|
+
if (token.$deprecated == null || token.$deprecated === false) {
|
|
392
|
+
return void 0;
|
|
393
|
+
}
|
|
394
|
+
const msg = typeof token.$deprecated === "string" ? token.$deprecated : "";
|
|
395
|
+
if (msg) {
|
|
396
|
+
return `@available(*, deprecated, message: "${sanitizeText(msg, "swift")}")`;
|
|
397
|
+
}
|
|
398
|
+
return "@available(*, deprecated)";
|
|
399
|
+
}
|
|
400
|
+
function buildKotlinDeprecationAnnotation(token) {
|
|
401
|
+
if (token.$deprecated == null || token.$deprecated === false) {
|
|
402
|
+
return void 0;
|
|
403
|
+
}
|
|
404
|
+
const msg = typeof token.$deprecated === "string" ? token.$deprecated : "";
|
|
405
|
+
if (msg) {
|
|
406
|
+
return `@Deprecated(message = "${sanitizeText(msg, "kotlin")}")`;
|
|
407
|
+
}
|
|
408
|
+
return "@Deprecated";
|
|
409
|
+
}
|
|
410
|
+
var init_metadata = __esm({
|
|
411
|
+
"src/renderers/metadata.ts"() {
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
|
|
339
415
|
// src/renderers/bundlers/js.ts
|
|
340
416
|
var js_exports = {};
|
|
341
417
|
__export(js_exports, {
|
|
@@ -440,7 +516,7 @@ async function bundleAsJsModule(bundleData, resolver, options, formatTokens) {
|
|
|
440
516
|
}
|
|
441
517
|
const metadata = buildMetadata(resolver);
|
|
442
518
|
const jsBlocks = [];
|
|
443
|
-
for (const { tokens, modifierInputs } of bundleData) {
|
|
519
|
+
for (const { tokens, modifierInputs, isBase } of bundleData) {
|
|
444
520
|
const cleanTokens = stripInternalMetadata(tokens);
|
|
445
521
|
const key = buildStableDashKey({
|
|
446
522
|
modifierInputs,
|
|
@@ -448,10 +524,30 @@ async function bundleAsJsModule(bundleData, resolver, options, formatTokens) {
|
|
|
448
524
|
defaults: metadata.defaults
|
|
449
525
|
});
|
|
450
526
|
const camelKey = toCamelKey(key);
|
|
527
|
+
const normalizedInputs = normalizeModifierInputs(modifierInputs);
|
|
528
|
+
const modifierParts = [];
|
|
529
|
+
for (const dim of metadata.dimensions) {
|
|
530
|
+
const value = normalizedInputs[dim.toLowerCase()];
|
|
531
|
+
if (value) {
|
|
532
|
+
modifierParts.push(`${dim}=${value}`);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
451
535
|
const formattedJs = await formatTokens(cleanTokens);
|
|
452
536
|
const tokenObject = extractObjectFromJsModule(formattedJs);
|
|
453
537
|
const indentedObject = tokenObject.replace(/\n/g, "\n ");
|
|
454
|
-
|
|
538
|
+
let comment;
|
|
539
|
+
if (modifierParts.length > 0) {
|
|
540
|
+
const modifierPart = modifierParts[0];
|
|
541
|
+
const eqIndex = modifierPart.indexOf("=");
|
|
542
|
+
const modifier = modifierPart.slice(0, eqIndex);
|
|
543
|
+
const context = modifierPart.slice(eqIndex + 1);
|
|
544
|
+
comment = buildModifierComment(modifier, context);
|
|
545
|
+
} else if (isBase) {
|
|
546
|
+
comment = "// Base permutation";
|
|
547
|
+
} else {
|
|
548
|
+
comment = `// ${key}`;
|
|
549
|
+
}
|
|
550
|
+
jsBlocks.push(` ${comment}
|
|
455
551
|
${JSON.stringify(camelKey)}: ${indentedObject}`);
|
|
456
552
|
}
|
|
457
553
|
return assembleJsBundle(metadata, jsBlocks, options?.generateHelper ?? false);
|
|
@@ -459,6 +555,7 @@ async function bundleAsJsModule(bundleData, resolver, options, formatTokens) {
|
|
|
459
555
|
var init_js = __esm({
|
|
460
556
|
"src/renderers/bundlers/js.ts"() {
|
|
461
557
|
init_errors();
|
|
558
|
+
init_metadata();
|
|
462
559
|
init_utils();
|
|
463
560
|
}
|
|
464
561
|
});
|
|
@@ -490,6 +587,17 @@ var init_json = __esm({
|
|
|
490
587
|
init_utils();
|
|
491
588
|
}
|
|
492
589
|
});
|
|
590
|
+
function nameKebabCase() {
|
|
591
|
+
return {
|
|
592
|
+
transform: (token) => {
|
|
593
|
+
const name = changeCase.kebabCase(token.path.join(" "));
|
|
594
|
+
return {
|
|
595
|
+
...token,
|
|
596
|
+
name
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
}
|
|
493
601
|
function isColorObject(value) {
|
|
494
602
|
return typeof value === "object" && value !== null && "colorSpace" in value && "components" in value;
|
|
495
603
|
}
|
|
@@ -567,6 +675,7 @@ function durationObjectToString(duration) {
|
|
|
567
675
|
init_errors();
|
|
568
676
|
init_token_utils();
|
|
569
677
|
init_utils();
|
|
678
|
+
init_metadata();
|
|
570
679
|
|
|
571
680
|
// src/renderers/output-tree.ts
|
|
572
681
|
var outputTree = (files) => {
|
|
@@ -627,9 +736,6 @@ function resolveColorFormat(format) {
|
|
|
627
736
|
function escapeKotlinString(str) {
|
|
628
737
|
return str.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\$/g, "\\$");
|
|
629
738
|
}
|
|
630
|
-
function escapeKDoc(str) {
|
|
631
|
-
return str.replace(/\*\//g, "* /").replace(/\r?\n/g, " ").trim();
|
|
632
|
-
}
|
|
633
739
|
function formatKotlinNumber(value) {
|
|
634
740
|
return Number.isInteger(value) ? `${value}.0` : String(value);
|
|
635
741
|
}
|
|
@@ -761,8 +867,13 @@ var AndroidRenderer = class {
|
|
|
761
867
|
const kotlinName = this.buildFlatKotlinName(token);
|
|
762
868
|
const kotlinValue = this.formatKotlinValue(token, options, baseDepth + 1);
|
|
763
869
|
const annotation = this.typeAnnotationSuffix(token);
|
|
764
|
-
|
|
765
|
-
|
|
870
|
+
const descriptionComment = buildTokenDescriptionComment(token, "kotlin");
|
|
871
|
+
if (descriptionComment) {
|
|
872
|
+
lines.push(`${valIndent}${descriptionComment}`);
|
|
873
|
+
}
|
|
874
|
+
const deprecation = buildKotlinDeprecationAnnotation(token);
|
|
875
|
+
if (deprecation) {
|
|
876
|
+
lines.push(`${valIndent}${deprecation}`);
|
|
766
877
|
}
|
|
767
878
|
lines.push(
|
|
768
879
|
`${valIndent}${options.visPrefix}val ${kotlinName}${annotation} = ${kotlinValue}`
|
|
@@ -798,8 +909,13 @@ var AndroidRenderer = class {
|
|
|
798
909
|
const kotlinName = toSafeIdentifier(key, KOTLIN_KEYWORDS, false);
|
|
799
910
|
const kotlinValue = this.formatKotlinValue(token, options, depth);
|
|
800
911
|
const annotation = this.typeAnnotationSuffix(token);
|
|
801
|
-
|
|
802
|
-
|
|
912
|
+
const descriptionComment = buildTokenDescriptionComment(token, "kotlin");
|
|
913
|
+
if (descriptionComment) {
|
|
914
|
+
lines.push(`${pad}${descriptionComment}`);
|
|
915
|
+
}
|
|
916
|
+
const deprecation = buildKotlinDeprecationAnnotation(token);
|
|
917
|
+
if (deprecation) {
|
|
918
|
+
lines.push(`${pad}${deprecation}`);
|
|
803
919
|
}
|
|
804
920
|
lines.push(`${pad}${options.visPrefix}val ${kotlinName}${annotation} = ${kotlinValue}`);
|
|
805
921
|
}
|
|
@@ -1576,10 +1692,8 @@ function stableInputsKey(modifierInputs) {
|
|
|
1576
1692
|
|
|
1577
1693
|
// src/renderers/css.ts
|
|
1578
1694
|
init_utils();
|
|
1695
|
+
init_metadata();
|
|
1579
1696
|
var CssRenderer = class _CssRenderer {
|
|
1580
|
-
sanitizeCssCommentText(text) {
|
|
1581
|
-
return text.replace(/\*\//g, "*\\/").replace(/\r?\n/g, " ").trim();
|
|
1582
|
-
}
|
|
1583
1697
|
async format(context, options) {
|
|
1584
1698
|
const opts = {
|
|
1585
1699
|
preset: options?.preset ?? "bundle",
|
|
@@ -1659,12 +1773,13 @@ var CssRenderer = class _CssRenderer {
|
|
|
1659
1773
|
}
|
|
1660
1774
|
pushTokenLines(lines, token, tokens, referenceTokens, preserveReferences, indent, newline, space) {
|
|
1661
1775
|
const entries = this.buildCssEntries(token, tokens, referenceTokens, preserveReferences);
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
lines.push(`${indent}
|
|
1776
|
+
const deprecationComment = buildTokenDeprecationComment(token, "css");
|
|
1777
|
+
if (deprecationComment) {
|
|
1778
|
+
lines.push(`${indent}${deprecationComment}${newline}`);
|
|
1665
1779
|
}
|
|
1666
|
-
|
|
1667
|
-
|
|
1780
|
+
const descriptionComment = buildTokenDescriptionComment(token, "css");
|
|
1781
|
+
if (descriptionComment) {
|
|
1782
|
+
lines.push(`${indent}${descriptionComment}${newline}`);
|
|
1668
1783
|
}
|
|
1669
1784
|
for (const entry of entries) {
|
|
1670
1785
|
lines.push(`${indent}--${entry.name}:${space}${entry.value};${newline}`);
|
|
@@ -2315,6 +2430,7 @@ function isBorderToken(token) {
|
|
|
2315
2430
|
|
|
2316
2431
|
// src/renderers/ios.ts
|
|
2317
2432
|
init_utils();
|
|
2433
|
+
init_metadata();
|
|
2318
2434
|
var toSRGB2 = culori.converter("rgb");
|
|
2319
2435
|
var toP32 = culori.converter("p3");
|
|
2320
2436
|
var SWIFT_TYPE_GROUP_MAP = {
|
|
@@ -2458,9 +2574,13 @@ var IosRenderer = class {
|
|
|
2458
2574
|
const swiftValue = this.formatSwiftValue(token, options);
|
|
2459
2575
|
const typeAnnotation = this.getTypeAnnotation(token);
|
|
2460
2576
|
const annotation = typeAnnotation ? `: ${typeAnnotation}` : "";
|
|
2461
|
-
const docComment =
|
|
2577
|
+
const docComment = buildTokenDescriptionComment(token, "swift");
|
|
2462
2578
|
if (docComment) {
|
|
2463
|
-
lines.push(docComment);
|
|
2579
|
+
lines.push(`${indent}${docComment}`);
|
|
2580
|
+
}
|
|
2581
|
+
const deprecationAttr = buildSwiftDeprecationAttribute(token);
|
|
2582
|
+
if (deprecationAttr) {
|
|
2583
|
+
lines.push(`${indent}${deprecationAttr}`);
|
|
2464
2584
|
}
|
|
2465
2585
|
lines.push(`${indent}${access} ${staticPrefix}${swiftName}${annotation} = ${swiftValue}`);
|
|
2466
2586
|
}
|
|
@@ -2475,15 +2595,6 @@ var IosRenderer = class {
|
|
|
2475
2595
|
}
|
|
2476
2596
|
return Array.from(imports).sort();
|
|
2477
2597
|
}
|
|
2478
|
-
/**
|
|
2479
|
-
* Builds a `///` doc comment from a token's `$description`, if present.
|
|
2480
|
-
*/
|
|
2481
|
-
buildDocComment(token, indent) {
|
|
2482
|
-
if (!token.$description) {
|
|
2483
|
-
return void 0;
|
|
2484
|
-
}
|
|
2485
|
-
return `${indent}/// ${token.$description}`;
|
|
2486
|
-
}
|
|
2487
2598
|
/**
|
|
2488
2599
|
* Builds a qualified Swift name from a token's path, preserving parent
|
|
2489
2600
|
* hierarchy segments to avoid duplicate identifiers.
|
|
@@ -2874,6 +2985,7 @@ function iosRenderer() {
|
|
|
2874
2985
|
// src/renderers/js-module.ts
|
|
2875
2986
|
init_utils();
|
|
2876
2987
|
init_token_utils();
|
|
2988
|
+
init_metadata();
|
|
2877
2989
|
var JsModuleRenderer = class {
|
|
2878
2990
|
async format(context, options) {
|
|
2879
2991
|
const opts = {
|
|
@@ -2911,17 +3023,10 @@ var JsModuleRenderer = class {
|
|
|
2911
3023
|
return outputTree(files);
|
|
2912
3024
|
}
|
|
2913
3025
|
async formatTokens(tokens, options) {
|
|
2914
|
-
const opts = {
|
|
2915
|
-
preset: options.preset ?? "standalone",
|
|
2916
|
-
structure: options.structure ?? "nested",
|
|
2917
|
-
minify: options.minify ?? false,
|
|
2918
|
-
moduleName: options.moduleName ?? "tokens",
|
|
2919
|
-
generateHelper: options.generateHelper ?? false
|
|
2920
|
-
};
|
|
2921
3026
|
const lines = [];
|
|
2922
|
-
lines.push(...this.formatAsObject(tokens,
|
|
3027
|
+
lines.push(...this.formatAsObject(tokens, options));
|
|
2923
3028
|
const code = lines.join("\n");
|
|
2924
|
-
if (
|
|
3029
|
+
if (options.minify) {
|
|
2925
3030
|
return code;
|
|
2926
3031
|
}
|
|
2927
3032
|
return await prettier__default.default.format(code, {
|
|
@@ -2934,20 +3039,53 @@ var JsModuleRenderer = class {
|
|
|
2934
3039
|
trailingComma: "es5"
|
|
2935
3040
|
});
|
|
2936
3041
|
}
|
|
2937
|
-
/**
|
|
2938
|
-
* Format as default export object
|
|
2939
|
-
*/
|
|
2940
3042
|
formatAsObject(tokens, options) {
|
|
2941
3043
|
const lines = [];
|
|
2942
|
-
const
|
|
3044
|
+
const tokenMap = this.buildTokenMap(tokens);
|
|
2943
3045
|
const varName = options.moduleName !== "" ? options.moduleName : "tokens";
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
3046
|
+
if (options.structure === "flat") {
|
|
3047
|
+
lines.push(`const ${varName} = {`);
|
|
3048
|
+
this.addFlatProperties(lines, tokens, 1);
|
|
3049
|
+
lines.push("}");
|
|
3050
|
+
} else {
|
|
3051
|
+
lines.push(`const ${varName} = {`);
|
|
3052
|
+
const tokenObj = this.tokensToPlainObject(tokens, "nested");
|
|
3053
|
+
this.addNestedProperties(lines, tokenObj, tokenMap, 1);
|
|
3054
|
+
lines.push("}");
|
|
3055
|
+
}
|
|
2947
3056
|
lines.push("");
|
|
2948
3057
|
lines.push(`export default ${varName}`);
|
|
2949
3058
|
return lines;
|
|
2950
3059
|
}
|
|
3060
|
+
buildTokenMap(tokens) {
|
|
3061
|
+
const map = /* @__PURE__ */ new Map();
|
|
3062
|
+
for (const [name, token] of Object.entries(tokens)) {
|
|
3063
|
+
map.set(name, token);
|
|
3064
|
+
}
|
|
3065
|
+
return map;
|
|
3066
|
+
}
|
|
3067
|
+
addFlatProperties(lines, tokens, indent) {
|
|
3068
|
+
const indentStr2 = " ".repeat(indent);
|
|
3069
|
+
const sortedEntries = getSortedTokenEntries(tokens);
|
|
3070
|
+
for (let i = 0; i < sortedEntries.length; i++) {
|
|
3071
|
+
const [name, token] = sortedEntries[i];
|
|
3072
|
+
const isLast = i === sortedEntries.length - 1;
|
|
3073
|
+
this.pushTokenComments(lines, token, indentStr2);
|
|
3074
|
+
lines.push(
|
|
3075
|
+
`${indentStr2}${this.quoteKey(name)}: ${JSON.stringify(token.$value)}${isLast ? "" : ","}`
|
|
3076
|
+
);
|
|
3077
|
+
}
|
|
3078
|
+
}
|
|
3079
|
+
pushTokenComments(lines, token, indent) {
|
|
3080
|
+
const deprecationComment = buildTokenDeprecationComment(token, "js");
|
|
3081
|
+
if (deprecationComment) {
|
|
3082
|
+
lines.push(`${indent}${deprecationComment}`);
|
|
3083
|
+
}
|
|
3084
|
+
const descriptionComment = buildTokenDescriptionComment(token, "js");
|
|
3085
|
+
if (descriptionComment) {
|
|
3086
|
+
lines.push(`${indent}${descriptionComment}`);
|
|
3087
|
+
}
|
|
3088
|
+
}
|
|
2951
3089
|
tokensToPlainObject(tokens, structure) {
|
|
2952
3090
|
if (structure === "nested") {
|
|
2953
3091
|
return buildNestedTokenObject(tokens, (token) => token.$value);
|
|
@@ -2958,7 +3096,7 @@ var JsModuleRenderer = class {
|
|
|
2958
3096
|
}
|
|
2959
3097
|
return result;
|
|
2960
3098
|
}
|
|
2961
|
-
|
|
3099
|
+
addNestedProperties(lines, obj, tokenMap, indent) {
|
|
2962
3100
|
const indentStr2 = " ".repeat(indent);
|
|
2963
3101
|
const entries = Object.entries(obj).sort(([keyA], [keyB]) => keyA.localeCompare(keyB));
|
|
2964
3102
|
for (let i = 0; i < entries.length; i++) {
|
|
@@ -2970,19 +3108,20 @@ var JsModuleRenderer = class {
|
|
|
2970
3108
|
const isLast = i === entries.length - 1;
|
|
2971
3109
|
const isNestedObject = typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2972
3110
|
if (!isNestedObject) {
|
|
3111
|
+
const token = tokenMap.get(key);
|
|
3112
|
+
if (token) {
|
|
3113
|
+
this.pushTokenComments(lines, token, indentStr2);
|
|
3114
|
+
}
|
|
2973
3115
|
lines.push(
|
|
2974
3116
|
`${indentStr2}${this.quoteKey(key)}: ${JSON.stringify(value)}${isLast ? "" : ","}`
|
|
2975
3117
|
);
|
|
2976
3118
|
continue;
|
|
2977
3119
|
}
|
|
2978
3120
|
lines.push(`${indentStr2}${this.quoteKey(key)}: {`);
|
|
2979
|
-
this.
|
|
3121
|
+
this.addNestedProperties(lines, value, tokenMap, indent + 1);
|
|
2980
3122
|
lines.push(`${indentStr2}}${isLast ? "" : ","}`);
|
|
2981
3123
|
}
|
|
2982
3124
|
}
|
|
2983
|
-
/**
|
|
2984
|
-
* Quote key if necessary
|
|
2985
|
-
*/
|
|
2986
3125
|
quoteKey(key) {
|
|
2987
3126
|
if (/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key)) {
|
|
2988
3127
|
return key;
|
|
@@ -3218,6 +3357,7 @@ function resolveOptions(options) {
|
|
|
3218
3357
|
|
|
3219
3358
|
// src/renderers/tailwind.ts
|
|
3220
3359
|
init_utils();
|
|
3360
|
+
init_metadata();
|
|
3221
3361
|
var TAILWIND_NAMESPACE_MAP = {
|
|
3222
3362
|
color: "color",
|
|
3223
3363
|
dimension: "spacing",
|
|
@@ -3271,6 +3411,14 @@ var TailwindRenderer = class {
|
|
|
3271
3411
|
for (const [, token] of getSortedTokenEntries(tokens)) {
|
|
3272
3412
|
const varName = this.buildVariableName(token);
|
|
3273
3413
|
const varValue = this.formatValue(token);
|
|
3414
|
+
const deprecationComment = buildTokenDeprecationComment(token, "tailwind");
|
|
3415
|
+
if (deprecationComment) {
|
|
3416
|
+
lines.push(`${indent}${deprecationComment}${newline}`);
|
|
3417
|
+
}
|
|
3418
|
+
const descriptionComment = buildTokenDescriptionComment(token, "tailwind");
|
|
3419
|
+
if (descriptionComment) {
|
|
3420
|
+
lines.push(`${indent}${descriptionComment}${newline}`);
|
|
3421
|
+
}
|
|
3274
3422
|
lines.push(`${indent}--${varName}:${space}${varValue};${newline}`);
|
|
3275
3423
|
}
|
|
3276
3424
|
lines.push(`}${newline}`);
|
|
@@ -3297,6 +3445,14 @@ var TailwindRenderer = class {
|
|
|
3297
3445
|
for (const [, token] of getSortedTokenEntries(tokens)) {
|
|
3298
3446
|
const varName = this.buildVariableName(token);
|
|
3299
3447
|
const varValue = this.formatValue(token);
|
|
3448
|
+
const deprecationComment = buildTokenDeprecationComment(token, "tailwind");
|
|
3449
|
+
if (deprecationComment) {
|
|
3450
|
+
lines.push(`${tokenIndent}${deprecationComment}${newline}`);
|
|
3451
|
+
}
|
|
3452
|
+
const descriptionComment = buildTokenDescriptionComment(token, "tailwind");
|
|
3453
|
+
if (descriptionComment) {
|
|
3454
|
+
lines.push(`${tokenIndent}${descriptionComment}${newline}`);
|
|
3455
|
+
}
|
|
3300
3456
|
lines.push(`${tokenIndent}--${varName}:${space}${varValue};${newline}`);
|
|
3301
3457
|
}
|
|
3302
3458
|
if (hasMediaQuery) {
|
|
@@ -3457,7 +3613,7 @@ function css(config) {
|
|
|
3457
3613
|
file,
|
|
3458
3614
|
renderer: cssRenderer(),
|
|
3459
3615
|
options: { preset, ...rendererOptions },
|
|
3460
|
-
transforms,
|
|
3616
|
+
transforms: [nameKebabCase(), ...transforms ?? []],
|
|
3461
3617
|
filters,
|
|
3462
3618
|
hooks
|
|
3463
3619
|
};
|