@codefast/cli 0.3.7-canary.0 → 0.3.12

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.
Files changed (120) hide show
  1. package/README.md +60 -299
  2. package/dist/bin.d.ts +3 -0
  3. package/dist/bin.d.ts.map +1 -0
  4. package/dist/bin.js +5 -0
  5. package/dist/commands/arrange.d.ts +3 -0
  6. package/dist/commands/arrange.d.ts.map +1 -0
  7. package/dist/commands/arrange.js +114 -0
  8. package/dist/commands/mirror.d.ts +4 -0
  9. package/dist/commands/mirror.d.ts.map +1 -0
  10. package/dist/commands/mirror.js +63 -0
  11. package/dist/lib/arrange/analyze.d.ts +4 -0
  12. package/dist/lib/arrange/analyze.d.ts.map +1 -0
  13. package/dist/lib/arrange/analyze.js +105 -0
  14. package/dist/lib/arrange/ast/collectors-cn.d.ts +10 -0
  15. package/dist/lib/arrange/ast/collectors-cn.d.ts.map +1 -0
  16. package/dist/lib/arrange/ast/collectors-cn.js +84 -0
  17. package/dist/lib/arrange/ast/collectors-jsx.d.ts +4 -0
  18. package/dist/lib/arrange/ast/collectors-jsx.d.ts.map +1 -0
  19. package/dist/lib/arrange/ast/collectors-jsx.js +18 -0
  20. package/dist/lib/arrange/ast/collectors-tv.d.ts +13 -0
  21. package/dist/lib/arrange/ast/collectors-tv.d.ts.map +1 -0
  22. package/dist/lib/arrange/ast/collectors-tv.js +273 -0
  23. package/dist/lib/arrange/ast/targets.d.ts +8 -0
  24. package/dist/lib/arrange/ast/targets.d.ts.map +1 -0
  25. package/dist/lib/arrange/ast/targets.js +143 -0
  26. package/dist/lib/arrange/ast/utils.d.ts +36 -0
  27. package/dist/lib/arrange/ast/utils.d.ts.map +1 -0
  28. package/dist/lib/arrange/ast/utils.js +138 -0
  29. package/dist/lib/arrange/constants.d.ts +68 -0
  30. package/dist/lib/arrange/constants.d.ts.map +1 -0
  31. package/dist/lib/arrange/constants.js +179 -0
  32. package/dist/lib/arrange/errors.d.ts +14 -0
  33. package/dist/lib/arrange/errors.d.ts.map +1 -0
  34. package/dist/lib/arrange/errors.js +16 -0
  35. package/dist/lib/arrange/formatters.d.ts +16 -0
  36. package/dist/lib/arrange/formatters.d.ts.map +1 -0
  37. package/dist/lib/arrange/formatters.js +57 -0
  38. package/dist/lib/arrange/group-file.d.ts +4 -0
  39. package/dist/lib/arrange/group-file.d.ts.map +1 -0
  40. package/dist/lib/arrange/group-file.js +115 -0
  41. package/dist/lib/arrange/grouping.d.ts +41 -0
  42. package/dist/lib/arrange/grouping.d.ts.map +1 -0
  43. package/dist/lib/arrange/grouping.js +280 -0
  44. package/dist/lib/arrange/imports.d.ts +6 -0
  45. package/dist/lib/arrange/imports.d.ts.map +1 -0
  46. package/dist/lib/arrange/imports.js +74 -0
  47. package/dist/lib/arrange/report.d.ts +4 -0
  48. package/dist/lib/arrange/report.d.ts.map +1 -0
  49. package/dist/lib/arrange/report.js +37 -0
  50. package/dist/lib/arrange/run-target.d.ts +4 -0
  51. package/dist/lib/arrange/run-target.d.ts.map +1 -0
  52. package/dist/lib/arrange/run-target.js +28 -0
  53. package/dist/lib/arrange/tokenizer.d.ts +37 -0
  54. package/dist/lib/arrange/tokenizer.d.ts.map +1 -0
  55. package/dist/lib/arrange/tokenizer.js +390 -0
  56. package/dist/lib/arrange/types.d.ts +104 -0
  57. package/dist/lib/arrange/types.d.ts.map +1 -0
  58. package/dist/lib/arrange/types.js +7 -0
  59. package/dist/lib/arrange/walk.d.ts +4 -0
  60. package/dist/lib/arrange/walk.d.ts.map +1 -0
  61. package/dist/lib/arrange/walk.js +34 -0
  62. package/dist/lib/arrange.d.ts +41 -0
  63. package/dist/lib/arrange.d.ts.map +1 -0
  64. package/dist/lib/arrange.js +38 -0
  65. package/dist/lib/infra/fs-contract.d.ts +28 -0
  66. package/dist/lib/infra/fs-contract.d.ts.map +1 -0
  67. package/dist/lib/infra/fs-contract.js +1 -0
  68. package/dist/lib/infra/node-io.d.ts +4 -0
  69. package/dist/lib/infra/node-io.d.ts.map +1 -0
  70. package/dist/lib/infra/node-io.js +27 -0
  71. package/dist/lib/mirror/config.d.ts +7 -0
  72. package/dist/lib/mirror/config.d.ts.map +1 -0
  73. package/dist/lib/mirror/config.js +146 -0
  74. package/dist/lib/mirror/constants.d.ts +10 -0
  75. package/dist/lib/mirror/constants.d.ts.map +1 -0
  76. package/dist/lib/mirror/constants.js +13 -0
  77. package/dist/lib/mirror/engine.d.ts +12 -0
  78. package/dist/lib/mirror/engine.d.ts.map +1 -0
  79. package/dist/lib/mirror/engine.js +248 -0
  80. package/dist/lib/mirror/errors.d.ts +10 -0
  81. package/dist/lib/mirror/errors.d.ts.map +1 -0
  82. package/dist/lib/mirror/errors.js +12 -0
  83. package/dist/lib/mirror/package-filter.d.ts +8 -0
  84. package/dist/lib/mirror/package-filter.d.ts.map +1 -0
  85. package/dist/lib/mirror/package-filter.js +33 -0
  86. package/dist/lib/mirror/reporter.d.ts +24 -0
  87. package/dist/lib/mirror/reporter.d.ts.map +1 -0
  88. package/dist/lib/mirror/reporter.js +126 -0
  89. package/dist/lib/mirror/sync.d.ts +4 -0
  90. package/dist/lib/mirror/sync.d.ts.map +1 -0
  91. package/dist/lib/mirror/sync.js +135 -0
  92. package/dist/lib/mirror/types.d.ts +81 -0
  93. package/dist/lib/mirror/types.d.ts.map +1 -0
  94. package/dist/lib/mirror/types.js +1 -0
  95. package/dist/lib/mirror/update-pkg.d.ts +13 -0
  96. package/dist/lib/mirror/update-pkg.d.ts.map +1 -0
  97. package/dist/lib/mirror/update-pkg.js +39 -0
  98. package/dist/lib/mirror/workspace-packages.d.ts +26 -0
  99. package/dist/lib/mirror/workspace-packages.d.ts.map +1 -0
  100. package/dist/lib/mirror/workspace-packages.js +160 -0
  101. package/dist/lib/mirror.d.ts +7 -0
  102. package/dist/lib/mirror.d.ts.map +1 -0
  103. package/dist/lib/mirror.js +5 -0
  104. package/dist/lib/repo-root.d.ts +7 -0
  105. package/dist/lib/repo-root.d.ts.map +1 -0
  106. package/dist/lib/repo-root.js +23 -0
  107. package/dist/lib/shared/utils.d.ts +9 -0
  108. package/dist/lib/shared/utils.d.ts.map +1 -0
  109. package/dist/lib/shared/utils.js +12 -0
  110. package/dist/program.d.ts +4 -0
  111. package/dist/program.d.ts.map +1 -0
  112. package/dist/program.js +38 -0
  113. package/package.json +42 -53
  114. package/CHANGELOG.md +0 -15
  115. package/dist/cjs/index.cjs +0 -2
  116. package/dist/cjs/src/index.d.ts +0 -3
  117. package/dist/cjs/src/index.d.ts.map +0 -1
  118. package/dist/esm/index.js +0 -2
  119. package/dist/esm/src/index.d.ts +0 -3
  120. package/dist/esm/src/index.d.ts.map +0 -1
@@ -0,0 +1,143 @@
1
+ import ts from "typescript";
2
+ import { APPLY_MIN_TOKENS } from "#lib/arrange/constants";
3
+ import { areCnTailwindPartitionsEquivalent, suggestCnGroups, summarizeGroupBucketLabels, } from "#lib/arrange/grouping";
4
+ import { escapeTsStringLiteralContent, formatArray, formatJsxCnAttributeValue, } from "#lib/arrange/formatters";
5
+ import { tokenizeClassString } from "#lib/arrange/tokenizer";
6
+ import { isUnsafeLiteralForCnStyleApplySplit } from "#lib/arrange/ast/collectors-cn";
7
+ import { jsxClassNameStaticLiteral } from "#lib/arrange/ast/collectors-jsx";
8
+ import { collectGroupableStringNodes, slotClassString } from "#lib/arrange/ast/collectors-tv";
9
+ import { indentOfLineContaining } from "#lib/arrange/ast/utils";
10
+ export function targetReplaceStart(target) {
11
+ if (target.kind === "cnArg") {
12
+ return target.item.cnCall
13
+ ? target.item.cnCall.getStart(target.item.sf)
14
+ : target.item.node.getStart(target.item.sf);
15
+ }
16
+ return target.valueNode.getStart(target.sf);
17
+ }
18
+ export function collectLongJsxClassNameTargets(sf) {
19
+ const results = [];
20
+ const visit = (node) => {
21
+ if (ts.isJsxAttribute(node)) {
22
+ const parsed = jsxClassNameStaticLiteral(node);
23
+ if (parsed && tokenizeClassString(parsed.lit.text).length >= APPLY_MIN_TOKENS) {
24
+ results.push({
25
+ kind: "jsxClassName",
26
+ sf,
27
+ lit: parsed.lit,
28
+ valueNode: parsed.valueNode,
29
+ });
30
+ }
31
+ }
32
+ ts.forEachChild(node, visit);
33
+ };
34
+ visit(sf);
35
+ return results;
36
+ }
37
+ export function collectGroupTargets(sf, filePath) {
38
+ const cnPart = collectGroupableStringNodes(sf).map((item) => ({ kind: "cnArg", item }));
39
+ if (!filePath.endsWith(".tsx"))
40
+ return cnPart;
41
+ return [...cnPart, ...collectLongJsxClassNameTargets(sf)];
42
+ }
43
+ export function formatCnCallReplacement(item, sourceText, withClassName) {
44
+ const call = item.cnCall;
45
+ const sf = item.sf;
46
+ const baseIndent = indentOfLineContaining(sourceText, call.getStart(sf));
47
+ const argIndent = `${baseIndent} `;
48
+ const dynamicArgTexts = [];
49
+ for (const arg of call.arguments) {
50
+ const isSimpleStatic = (ts.isStringLiteral(arg) || ts.isNoSubstitutionTemplateLiteral(arg)) &&
51
+ !isUnsafeLiteralForCnStyleApplySplit(arg);
52
+ if (!isSimpleStatic) {
53
+ dynamicArgTexts.push(sourceText.slice(arg.getStart(sf), arg.getEnd()));
54
+ }
55
+ }
56
+ const pool = slotClassString(item);
57
+ const groups = pool.trim() ? suggestCnGroups(pool) : [];
58
+ const allArgs = [];
59
+ if (groups.length > 1) {
60
+ for (const group of groups) {
61
+ allArgs.push(`${argIndent}"${escapeTsStringLiteralContent(group)}"`);
62
+ }
63
+ }
64
+ else if (groups.length === 1) {
65
+ allArgs.push(`${argIndent}"${escapeTsStringLiteralContent(groups[0])}"`);
66
+ }
67
+ for (const dyn of dynamicArgTexts) {
68
+ allArgs.push(`${argIndent}${dyn}`);
69
+ }
70
+ if (withClassName) {
71
+ allArgs.push(`${argIndent}className`);
72
+ }
73
+ // Keep formatter behavior explicit: multiline cn() calls with multiple args use trailing comma.
74
+ const commaAfterLastArg = allArgs.length > 1;
75
+ const argLines = allArgs.map((argLine, lineIndex) => lineIndex < allArgs.length - 1 || commaAfterLastArg ? `${argLine},` : `${argLine}`);
76
+ return `cn(\n${argLines.join("\n")}\n${baseIndent})`;
77
+ }
78
+ export function planGroupEditForTarget(target, textAfterUnwrap, withClassName) {
79
+ if (target.kind === "jsxClassName") {
80
+ const groups = suggestCnGroups(target.lit.text);
81
+ if (groups.length <= 1)
82
+ return undefined;
83
+ const start = target.valueNode.getStart(target.sf);
84
+ const end = target.valueNode.getEnd();
85
+ const replacement = formatJsxCnAttributeValue(groups, textAfterUnwrap, start);
86
+ return {
87
+ start,
88
+ end,
89
+ replacement,
90
+ bucketSummary: summarizeGroupBucketLabels(groups),
91
+ jsxCn: true,
92
+ lineSf: target.sf,
93
+ reportNode: target.lit,
94
+ label: "JSX className",
95
+ };
96
+ }
97
+ const pool = slotClassString(target.item);
98
+ const groups = suggestCnGroups(pool);
99
+ if (groups.length <= 1)
100
+ return undefined;
101
+ if (areCnTailwindPartitionsEquivalent(target.item.nodes.map((node) => node.text), groups)) {
102
+ return undefined;
103
+ }
104
+ if (!target.item.cnCall) {
105
+ const firstNode = target.item.node;
106
+ const parentArray = target.item.nodes.length > 1 && ts.isArrayLiteralExpression(firstNode.parent)
107
+ ? firstNode.parent
108
+ : null;
109
+ const start = parentArray
110
+ ? parentArray.getStart(target.item.sf)
111
+ : firstNode.getStart(target.item.sf);
112
+ const end = parentArray ? parentArray.getEnd() : firstNode.getEnd();
113
+ const baseIndent = indentOfLineContaining(textAfterUnwrap, start);
114
+ const replacement = formatArray(groups)
115
+ .split("\n")
116
+ .map((line, lineIndex) => (lineIndex === 0 ? line : `${baseIndent}${line}`))
117
+ .join("\n");
118
+ return {
119
+ start,
120
+ end,
121
+ replacement,
122
+ bucketSummary: summarizeGroupBucketLabels(groups),
123
+ jsxCn: false,
124
+ lineSf: target.item.sf,
125
+ reportNode: firstNode,
126
+ label: target.item.isTvContext ? "tv" : "cn",
127
+ };
128
+ }
129
+ const call = target.item.cnCall;
130
+ const start = call.getStart(target.item.sf);
131
+ const end = call.getEnd();
132
+ const replacement = formatCnCallReplacement(target.item, textAfterUnwrap, withClassName);
133
+ return {
134
+ start,
135
+ end,
136
+ replacement,
137
+ bucketSummary: summarizeGroupBucketLabels(groups),
138
+ jsxCn: false,
139
+ lineSf: target.item.sf,
140
+ reportNode: target.item.node,
141
+ label: target.item.isTvContext ? "tv" : "cn",
142
+ };
143
+ }
@@ -0,0 +1,36 @@
1
+ import ts from "typescript";
2
+ /** Known module specifiers that export `cn` / `tv`. */
3
+ export declare const KNOWN_CN_TV_MODULES: Set<string>;
4
+ /**
5
+ * True for typical shadcn-style re-exports: `./utils`, `@/lib/utils`, `…/utils/…`,
6
+ * or a dedicated `cn.ts` / `cn.tsx` module.
7
+ */
8
+ export declare function moduleLooksLikeCnTvReexport(mod: string): boolean;
9
+ /**
10
+ * Build a set of local binding names that are imported from a known cn/tv
11
+ * module in `sf`.
12
+ */
13
+ export declare function buildKnownCnTvBindings(sf: ts.SourceFile): Set<string>;
14
+ /**
15
+ * Returns true when `expr` is an identifier whose name matches `name` AND
16
+ * that name is listed in `knownBindings` from a recognized import.
17
+ */
18
+ export declare function isCnOrTvIdentifier(expr: ts.Expression, name: "cn" | "tv", knownBindings?: Set<string>): boolean;
19
+ export declare function propertyAssignmentNameText(prop: ts.PropertyAssignment): string | undefined;
20
+ export declare function lineOf(sf: ts.SourceFile, node: ts.Node): number;
21
+ /**
22
+ * Returns only the leading whitespace (tabs / spaces) of the line containing
23
+ * `pos`.
24
+ */
25
+ export declare function indentOfLineContaining(source: string, pos: number): string;
26
+ export declare function applyEditsDescending(sourceText: string, edits: ReadonlyArray<{
27
+ start: number;
28
+ end: number;
29
+ replacement: string;
30
+ }>): string;
31
+ /**
32
+ * Replace `cn(...)` nested in `tv({...})` with a plain string (one arg) or a string
33
+ * array (multiple args). Returns undefined when there are zero arguments.
34
+ */
35
+ export declare function unwrapCnInsideTvCallReplacement(call: ts.CallExpression, sourceText: string, sf: ts.SourceFile): string | undefined;
36
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/lib/arrange/ast/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAG5B,uDAAuD;AACvD,eAAO,MAAM,mBAAmB,aAU9B,CAAC;AAEH;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAMhE;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,EAAE,CAAC,UAAU,GAAG,GAAG,CAAC,MAAM,CAAC,CAqBrE;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,EAAE,CAAC,UAAU,EACnB,IAAI,EAAE,IAAI,GAAG,IAAI,EACjB,aAAa,GAAE,GAAG,CAAC,MAAM,CAAwB,GAChD,OAAO,CAOT;AAED,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,EAAE,CAAC,kBAAkB,GAAG,MAAM,GAAG,SAAS,CAI1F;AAED,wBAAgB,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,MAAM,CAE/D;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAoB1E;AAED,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,aAAa,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC,GACxE,MAAM,CAOR;AAED;;;GAGG;AACH,wBAAgB,+BAA+B,CAC7C,IAAI,EAAE,EAAE,CAAC,cAAc,EACvB,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,EAAE,CAAC,UAAU,GAChB,MAAM,GAAG,SAAS,CAoBpB"}
@@ -0,0 +1,138 @@
1
+ import ts from "typescript";
2
+ import { EMPTY_CN_TV_BINDINGS } from "#lib/arrange/constants";
3
+ /** Known module specifiers that export `cn` / `tv`. */
4
+ export const KNOWN_CN_TV_MODULES = new Set([
5
+ "@codefast/tailwind-variants",
6
+ "clsx",
7
+ "class-variance-authority",
8
+ // Backward compatibility only: keep detection for existing user code that still imports
9
+ // from "tailwind-variants"; new code should prefer "@codefast/tailwind-variants".
10
+ "tailwind-variants",
11
+ "#lib/utils",
12
+ "~/lib/utils",
13
+ "@/lib/utils",
14
+ ]);
15
+ /**
16
+ * True for typical shadcn-style re-exports: `./utils`, `@/lib/utils`, `…/utils/…`,
17
+ * or a dedicated `cn.ts` / `cn.tsx` module.
18
+ */
19
+ export function moduleLooksLikeCnTvReexport(mod) {
20
+ const norm = mod.replace(/\\/g, "/");
21
+ if (/(?:^|[./])utils(?:\/|$)/.test(norm))
22
+ return true;
23
+ if (/\/utils\//.test(norm) || /\/utils$/.test(norm))
24
+ return true;
25
+ if (/(?:^|\/)cn\.tsx?$/.test(norm))
26
+ return true;
27
+ return false;
28
+ }
29
+ /**
30
+ * Build a set of local binding names that are imported from a known cn/tv
31
+ * module in `sf`.
32
+ */
33
+ export function buildKnownCnTvBindings(sf) {
34
+ const bindings = new Set();
35
+ for (const stmt of sf.statements) {
36
+ if (!ts.isImportDeclaration(stmt) || !stmt.importClause)
37
+ continue;
38
+ if (stmt.importClause.isTypeOnly)
39
+ continue;
40
+ const spec = stmt.moduleSpecifier;
41
+ if (!ts.isStringLiteral(spec))
42
+ continue;
43
+ const mod = spec.text;
44
+ const isKnown = KNOWN_CN_TV_MODULES.has(mod);
45
+ if (!isKnown && !moduleLooksLikeCnTvReexport(mod))
46
+ continue;
47
+ const clause = stmt.importClause;
48
+ if (clause.name)
49
+ bindings.add(clause.name.text);
50
+ if (!clause.namedBindings)
51
+ continue;
52
+ if (ts.isNamedImports(clause.namedBindings)) {
53
+ for (const el of clause.namedBindings.elements)
54
+ bindings.add(el.name.text);
55
+ continue;
56
+ }
57
+ bindings.add(clause.namedBindings.name.text);
58
+ }
59
+ return bindings;
60
+ }
61
+ /**
62
+ * Returns true when `expr` is an identifier whose name matches `name` AND
63
+ * that name is listed in `knownBindings` from a recognized import.
64
+ */
65
+ export function isCnOrTvIdentifier(expr, name, knownBindings = EMPTY_CN_TV_BINDINGS) {
66
+ if (knownBindings.size === 0)
67
+ return false;
68
+ if (ts.isIdentifier(expr) && expr.text === name)
69
+ return knownBindings.has(expr.text);
70
+ if (ts.isPropertyAccessExpression(expr) && expr.name.text === name) {
71
+ return ts.isIdentifier(expr.expression) && knownBindings.has(expr.expression.text);
72
+ }
73
+ return false;
74
+ }
75
+ export function propertyAssignmentNameText(prop) {
76
+ if (ts.isIdentifier(prop.name))
77
+ return prop.name.text;
78
+ if (ts.isStringLiteral(prop.name))
79
+ return prop.name.text;
80
+ return undefined;
81
+ }
82
+ export function lineOf(sf, node) {
83
+ return sf.getLineAndCharacterOfPosition(node.getStart(sf)).line + 1;
84
+ }
85
+ /**
86
+ * Returns only the leading whitespace (tabs / spaces) of the line containing
87
+ * `pos`.
88
+ */
89
+ export function indentOfLineContaining(source, pos) {
90
+ const searchPos = Math.max(0, Math.min(pos, source.length));
91
+ const prevLineBreak = Math.max(source.lastIndexOf("\n", searchPos - 1), source.lastIndexOf("\r", searchPos - 1));
92
+ const lineStart = prevLineBreak === -1 ? 0 : prevLineBreak + 1;
93
+ let lineEnd = source.length;
94
+ for (let i = lineStart; i < source.length; i++) {
95
+ const ch = source[i];
96
+ if (ch === "\n" || ch === "\r") {
97
+ lineEnd = i;
98
+ break;
99
+ }
100
+ }
101
+ const line = source.slice(lineStart, lineEnd);
102
+ const indentMatch = /^[\t ]*/.exec(line);
103
+ return indentMatch?.[0] ?? "";
104
+ }
105
+ export function applyEditsDescending(sourceText, edits) {
106
+ const sorted = [...edits].sort((editA, editB) => editB.start - editA.start);
107
+ let out = sourceText;
108
+ for (const edit of sorted) {
109
+ out = out.slice(0, edit.start) + edit.replacement + out.slice(edit.end);
110
+ }
111
+ return out;
112
+ }
113
+ /**
114
+ * Replace `cn(...)` nested in `tv({...})` with a plain string (one arg) or a string
115
+ * array (multiple args). Returns undefined when there are zero arguments.
116
+ */
117
+ export function unwrapCnInsideTvCallReplacement(call, sourceText, sf) {
118
+ const args = call.arguments;
119
+ if (args.length === 0)
120
+ return undefined;
121
+ const baseIndent = indentOfLineContaining(sourceText, call.getStart(sf));
122
+ const innerIndent = `${baseIndent} `;
123
+ if (args.length === 1) {
124
+ const firstArg = args[0];
125
+ return sourceText.slice(firstArg.getStart(sf), firstArg.getEnd());
126
+ }
127
+ const lines = ["["];
128
+ for (let i = 0; i < args.length; i++) {
129
+ const arg = args[i];
130
+ const piece = sourceText.slice(arg.getStart(sf), arg.getEnd());
131
+ // Trailing comma on every element — intentional (Prettier-compatible style;
132
+ // keeps array diffs clean when arguments are later added or removed).
133
+ const comma = i < args.length - 1 || args.length > 1 ? "," : "";
134
+ lines.push(`${innerIndent}${piece}${comma}`);
135
+ }
136
+ lines.push(`${baseIndent}]`);
137
+ return lines.join("\n");
138
+ }
@@ -0,0 +1,68 @@
1
+ import type { Bucket } from "#lib/arrange/types";
2
+ /** Analyze report: long literal threshold (token count). */
3
+ export declare const LONG_STRING_TOKEN_THRESHOLD = 18;
4
+ /**
5
+ * Minimum token count for a string to be considered a candidate for grouping
6
+ * in the apply/preview pipeline. Intentionally much lower than
7
+ * {@link LONG_STRING_TOKEN_THRESHOLD} (analyze only).
8
+ */
9
+ export declare const APPLY_MIN_TOKENS = 2;
10
+ /**
11
+ * Minimum tokens a group must have to stand alone before singleton-merging.
12
+ * Set to 2 so single-token groups are not collapsed into unrelated buckets by the merger.
13
+ */
14
+ export declare const MIN_GROUP_TOKENS = 2;
15
+ /** Dynamic max groups clamp: base bound. */
16
+ export declare const MAX_GROUPS_BASE = 4;
17
+ /** Dynamic max groups clamp: upper cap. */
18
+ export declare const MAX_GROUPS_CAP = 24;
19
+ /**
20
+ * Extra slots so a few state / aria groups do not force `capGroups` to merge
21
+ * unrelated buckets (e.g. `bg-border` + `outline-hidden`).
22
+ */
23
+ export declare const MAX_GROUPS_HEADROOM = 2;
24
+ /** Maximum findings printed per category in the analyze report. */
25
+ export declare const MAX_REPORT_LINES = 40;
26
+ /** Maximum recursion depth when traversing `tv()` object literals. */
27
+ export declare const MAX_OBJECT_DEPTH = 12;
28
+ /** Maximum depth when peeling conditional / parens / arrays inside `cn(...)` args. */
29
+ export declare const MAX_CLASS_EXPR_DEPTH = 12;
30
+ /**
31
+ * Maximum variant-stripping passes in {@link stripVariants}.
32
+ * Real-world Tailwind stacks rarely exceed 4–5 segments (e.g. `@md/sidebar:group-hover:dark:focus-visible:`);
33
+ * 12 is a conservative safety cap that prevents runaway loops on malformed input.
34
+ */
35
+ export declare const MAX_STRIP_VARIANT_PASSES = 12;
36
+ /**
37
+ * Passed when optional `knownBindings` is missing — size 0 disables matching
38
+ * for `cn` / `tv` identifier resolution.
39
+ */
40
+ export declare const EMPTY_CN_TV_BINDINGS: Set<string>;
41
+ /**
42
+ * Bucket sort order — **render pipeline** (lower → earlier in output).
43
+ * Existence → Position → Layout → Sizing → Spacing → Shape → Background → Shadow
44
+ * → Typography → Composite → Motion → Starting → Behavior → Conditions (state).
45
+ */
46
+ export declare const BUCKET_ORDER: Record<Bucket, number>;
47
+ /**
48
+ * Compatible bucket **pairs** — two adjacent tokens whose buckets appear in the same
49
+ * `Set` may stay in one `cn()` string chunk. Compatibility is **not transitive**: there is
50
+ * no `{position, sizing}` pair, so `fixed inset-0` and `overflow-auto` become **separate**
51
+ * literals unless **layout** tokens sit between them in sorted order; then
52
+ * `position↔layout` and `layout↔sizing` each justify one hop and the whole “box in flow”
53
+ * (place + tracks + scrollport) stays in one chunk — co-located because they jointly define
54
+ * stacking and scroll behavior for the same surface.
55
+ */
56
+ export declare const COMPATIBLE_BUCKET_SETS: ReadonlyArray<ReadonlySet<Bucket>>;
57
+ /**
58
+ * Responsive / variant prefix — Tailwind v4 aware.
59
+ *
60
+ * v3: sm: md: … — v4: @sm:, @min-[600px]:, @[480px]:, named @md/sidebar:,
61
+ * viewport md/sidebar:, min-[100px]: / max-[100px]:, …
62
+ */
63
+ export declare const RESPONSIVE_PREFIX: RegExp;
64
+ /** State variant stems — hoisted to module scope (not recreated per call). */
65
+ export declare const STATE_PREFIXES: Set<string>;
66
+ /** Default directory for arrange analyze/preview/apply when no target is passed. */
67
+ export declare const DEFAULT_ARRANGE_TARGET = "packages/ui/src/components";
68
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/lib/arrange/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEjD,4DAA4D;AAC5D,eAAO,MAAM,2BAA2B,KAAK,CAAC;AAE9C;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAElC;;;GAGG;AACH,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAElC,4CAA4C;AAC5C,eAAO,MAAM,eAAe,IAAI,CAAC;AAEjC,2CAA2C;AAC3C,eAAO,MAAM,cAAc,KAAK,CAAC;AAEjC;;;GAGG;AACH,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC,mEAAmE;AACnE,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAEnC,sEAAsE;AACtE,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAEnC,sFAAsF;AACtF,eAAO,MAAM,oBAAoB,KAAK,CAAC;AAEvC;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,KAAK,CAAC;AAE3C;;;GAGG;AACH,eAAO,MAAM,oBAAoB,aAAoB,CAAC;AAEtD;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAiB/C,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,EAAE,aAAa,CAAC,WAAW,CAAC,MAAM,CAAC,CA6BrE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,QAC2J,CAAC;AAE1L,8EAA8E;AAC9E,eAAO,MAAM,cAAc,aAmEzB,CAAC;AAEH,oFAAoF;AACpF,eAAO,MAAM,sBAAsB,+BAA+B,CAAC"}
@@ -0,0 +1,179 @@
1
+ /** Analyze report: long literal threshold (token count). */
2
+ export const LONG_STRING_TOKEN_THRESHOLD = 18;
3
+ /**
4
+ * Minimum token count for a string to be considered a candidate for grouping
5
+ * in the apply/preview pipeline. Intentionally much lower than
6
+ * {@link LONG_STRING_TOKEN_THRESHOLD} (analyze only).
7
+ */
8
+ export const APPLY_MIN_TOKENS = 2;
9
+ /**
10
+ * Minimum tokens a group must have to stand alone before singleton-merging.
11
+ * Set to 2 so single-token groups are not collapsed into unrelated buckets by the merger.
12
+ */
13
+ export const MIN_GROUP_TOKENS = 2;
14
+ /** Dynamic max groups clamp: base bound. */
15
+ export const MAX_GROUPS_BASE = 4;
16
+ /** Dynamic max groups clamp: upper cap. */
17
+ export const MAX_GROUPS_CAP = 24;
18
+ /**
19
+ * Extra slots so a few state / aria groups do not force `capGroups` to merge
20
+ * unrelated buckets (e.g. `bg-border` + `outline-hidden`).
21
+ */
22
+ export const MAX_GROUPS_HEADROOM = 2;
23
+ /** Maximum findings printed per category in the analyze report. */
24
+ export const MAX_REPORT_LINES = 40;
25
+ /** Maximum recursion depth when traversing `tv()` object literals. */
26
+ export const MAX_OBJECT_DEPTH = 12;
27
+ /** Maximum depth when peeling conditional / parens / arrays inside `cn(...)` args. */
28
+ export const MAX_CLASS_EXPR_DEPTH = 12;
29
+ /**
30
+ * Maximum variant-stripping passes in {@link stripVariants}.
31
+ * Real-world Tailwind stacks rarely exceed 4–5 segments (e.g. `@md/sidebar:group-hover:dark:focus-visible:`);
32
+ * 12 is a conservative safety cap that prevents runaway loops on malformed input.
33
+ */
34
+ export const MAX_STRIP_VARIANT_PASSES = 12;
35
+ /**
36
+ * Passed when optional `knownBindings` is missing — size 0 disables matching
37
+ * for `cn` / `tv` identifier resolution.
38
+ */
39
+ export const EMPTY_CN_TV_BINDINGS = new Set();
40
+ /**
41
+ * Bucket sort order — **render pipeline** (lower → earlier in output).
42
+ * Existence → Position → Layout → Sizing → Spacing → Shape → Background → Shadow
43
+ * → Typography → Composite → Motion → Starting → Behavior → Conditions (state).
44
+ */
45
+ export const BUCKET_ORDER = {
46
+ existence: 0,
47
+ position: 1,
48
+ layout: 2,
49
+ sizing: 3,
50
+ spacing: 4,
51
+ shape: 5,
52
+ background: 6,
53
+ shadow: 7,
54
+ typography: 8,
55
+ composite: 9,
56
+ motion: 10,
57
+ starting: 11,
58
+ behavior: 12,
59
+ state: 13,
60
+ other: 14,
61
+ arbitrary: 15,
62
+ };
63
+ /**
64
+ * Compatible bucket **pairs** — two adjacent tokens whose buckets appear in the same
65
+ * `Set` may stay in one `cn()` string chunk. Compatibility is **not transitive**: there is
66
+ * no `{position, sizing}` pair, so `fixed inset-0` and `overflow-auto` become **separate**
67
+ * literals unless **layout** tokens sit between them in sorted order; then
68
+ * `position↔layout` and `layout↔sizing` each justify one hop and the whole “box in flow”
69
+ * (place + tracks + scrollport) stays in one chunk — co-located because they jointly define
70
+ * stacking and scroll behavior for the same surface.
71
+ */
72
+ export const COMPATIBLE_BUCKET_SETS = [
73
+ // existence + position: named container / group / peer context edited next to inset & z-index.
74
+ new Set(["existence", "position"]),
75
+ // existence + layout: `group/cmd` + `flex …` are one template row (context + grid/flex).
76
+ new Set(["existence", "layout"]),
77
+ // position + layout: `fixed inset-0` + `grid` describe the same stacking + track shell.
78
+ new Set(["position", "layout"]),
79
+ // layout + sizing: `grid` + `overflow-auto` / min size are one scrollport / track concern.
80
+ new Set(["layout", "sizing"]),
81
+ // shape + shadow: radius/border + shadow/outline overlay are one “chrome” literal in UIs.
82
+ new Set(["shape", "shadow"]),
83
+ // background + shadow: fill + depth (card surface) without splitting noise across args.
84
+ new Set(["background", "shadow"]),
85
+ // background + typography: destructive buttons etc. (`bg-*` + `text-*` on the same control).
86
+ new Set(["background", "typography"]),
87
+ // layout + typography: title rows (`flex` + `text-sm`) in one literal when adjacent in sort order.
88
+ new Set(["layout", "typography"]),
89
+ // sizing + typography: chart shell (`aspect-video` + `text-xs`) before scoped `[&_…]` state.
90
+ new Set(["sizing", "typography"]),
91
+ // motion + behavior: `transition-*` with `pointer-events-*` / `select-*` on the same surface.
92
+ new Set(["motion", "behavior"]),
93
+ // motion + starting: `transition` beside `starting:*` for coordinated enter/exit motion.
94
+ new Set(["motion", "starting"]),
95
+ // composite + motion: transforms then transitions (`-translate-*` + `transition-*` + `ease-*`).
96
+ new Set(["composite", "motion"]),
97
+ // sizing + composite: width/position utilities with transforms in one interaction block.
98
+ new Set(["sizing", "composite"]),
99
+ // sizing + spacing: width utilities with padding on the same slot (`w-auto` + `px-3`).
100
+ new Set(["sizing", "spacing"]),
101
+ ];
102
+ /**
103
+ * Responsive / variant prefix — Tailwind v4 aware.
104
+ *
105
+ * v3: sm: md: … — v4: @sm:, @min-[600px]:, @[480px]:, named @md/sidebar:,
106
+ * viewport md/sidebar:, min-[100px]: / max-[100px]:, …
107
+ */
108
+ export const RESPONSIVE_PREFIX = /^(?:@(?:min|max)-\[[^\]]+\]:|@\[[^\]]+\]:|@(?:[a-z0-9]+(?:-[a-z0-9]+)*)(?:\/[a-z][a-z0-9-]*)?:|(?:max-|min-)?(?:sm|md|lg|xl|2xl|3xl)(?:\/[a-z][a-z0-9-]*)?:|(?:max-|min-)\[[^\]]+\]:)/;
109
+ /** State variant stems — hoisted to module scope (not recreated per call). */
110
+ export const STATE_PREFIXES = new Set([
111
+ "hover",
112
+ "focus",
113
+ "focus-within",
114
+ "focus-visible",
115
+ "active",
116
+ "visited",
117
+ "link",
118
+ "any-link",
119
+ "disabled",
120
+ "enabled",
121
+ "checked",
122
+ "indeterminate",
123
+ "required",
124
+ "optional",
125
+ "valid",
126
+ "invalid",
127
+ "in-range",
128
+ "out-of-range",
129
+ "read-only",
130
+ "read-write",
131
+ "placeholder-shown",
132
+ "default",
133
+ "autofill",
134
+ "open",
135
+ "closed",
136
+ "first",
137
+ "last",
138
+ "only",
139
+ "odd",
140
+ "even",
141
+ "first-of-type",
142
+ "last-of-type",
143
+ "only-of-type",
144
+ "first-child",
145
+ "last-child",
146
+ "only-child",
147
+ "empty",
148
+ "target",
149
+ "group",
150
+ "peer",
151
+ "aria",
152
+ "data",
153
+ "dark",
154
+ "light",
155
+ "supports",
156
+ "motion-reduce",
157
+ "motion-safe",
158
+ "print",
159
+ "screen",
160
+ "ltr",
161
+ "rtl",
162
+ "not",
163
+ "has",
164
+ "in",
165
+ "nth",
166
+ "file",
167
+ "selection",
168
+ "marker",
169
+ "placeholder",
170
+ "before",
171
+ "after",
172
+ "first-line",
173
+ "first-letter",
174
+ "backdrop",
175
+ "details-content",
176
+ "popover-open",
177
+ ]);
178
+ /** Default directory for arrange analyze/preview/apply when no target is passed. */
179
+ export const DEFAULT_ARRANGE_TARGET = "packages/ui/src/components";
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Structured errors for the arrange CLI library (throw from lib; handle exit in commands).
3
+ */
4
+ export declare const ArrangeErrorCode: {
5
+ readonly TARGET_NOT_FOUND: "TARGET_NOT_FOUND";
6
+ readonly INVALID_INPUT: "INVALID_INPUT";
7
+ readonly INTERNAL: "INTERNAL";
8
+ };
9
+ export type ArrangeErrorCode = (typeof ArrangeErrorCode)[keyof typeof ArrangeErrorCode];
10
+ export declare class ArrangeError extends Error {
11
+ readonly code: ArrangeErrorCode;
12
+ constructor(code: ArrangeErrorCode, message: string, options?: ErrorOptions);
13
+ }
14
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/lib/arrange/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,eAAO,MAAM,gBAAgB;aAC3B,gBAAgB,EAAE,kBAAkB;aACpC,aAAa,EAAE,eAAe;aAC9B,QAAQ,EAAE,UAAU;CACZ,CAAC;AAGX,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,OAAO,gBAAgB,CAAC,CAAC;AAExF,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAEhC,YAAY,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,EAI1E;CACF"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Structured errors for the arrange CLI library (throw from lib; handle exit in commands).
3
+ */
4
+ export const ArrangeErrorCode = {
5
+ TARGET_NOT_FOUND: "TARGET_NOT_FOUND",
6
+ INVALID_INPUT: "INVALID_INPUT",
7
+ INTERNAL: "INTERNAL",
8
+ };
9
+ export class ArrangeError extends Error {
10
+ code;
11
+ constructor(code, message, options) {
12
+ super(message, options);
13
+ this.name = "ArrangeError";
14
+ this.code = code;
15
+ }
16
+ }
@@ -0,0 +1,16 @@
1
+ export declare function escapeTsStringLiteralContent(group: string): string;
2
+ /**
3
+ * Multiline fragment for use *inside* an existing `cn(...)` — replaces one
4
+ * string argument with several, without producing `cn(cn(...))`.
5
+ */
6
+ export declare function formatCnArguments(groups: string[], options?: {
7
+ indent?: string;
8
+ commaAfterLastGroup?: boolean;
9
+ trailingClassName?: boolean;
10
+ }): string;
11
+ export declare function formatCnCall(groups: string[], options?: {
12
+ trailingClassName?: boolean;
13
+ }): string;
14
+ export declare function formatArray(groups: string[]): string;
15
+ export declare function formatJsxCnAttributeValue(groups: string[], source: string, valueNodeStart: number): string;
16
+ //# sourceMappingURL=formatters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../../../src/lib/arrange/formatters.ts"],"names":[],"mappings":"AAEA,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAElE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,EAAE,EAChB,OAAO,CAAC,EAAE;IACR,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,GACA,MAAM,CAaR;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE;IAAE,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,MAAM,CAahG;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAWpD;AAED,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,MAAM,EAAE,EAChB,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,MAAM,GACrB,MAAM,CAQR"}