@tamagui/to-tailwind 0.0.0-bootstrap.0 → 3.0.0-beta.643.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +30 -0
- package/dist/cjs/index.native.cjs +32 -0
- package/dist/cjs/index.native.js +34 -0
- package/dist/cjs/index.native.js.map +1 -0
- package/dist/cjs/maps/componentToTag.cjs +42 -0
- package/dist/cjs/maps/componentToTag.native.cjs +44 -0
- package/dist/cjs/maps/componentToTag.native.js +46 -0
- package/dist/cjs/maps/componentToTag.native.js.map +1 -0
- package/dist/cjs/transform.cjs +706 -0
- package/dist/cjs/transform.native.cjs +933 -0
- package/dist/cjs/transform.native.js +935 -0
- package/dist/cjs/transform.native.js.map +1 -0
- package/dist/esm/index.mjs +4 -0
- package/dist/esm/index.native.js +4 -0
- package/dist/esm/maps/componentToTag.mjs +21 -0
- package/dist/esm/maps/componentToTag.mjs.map +1 -0
- package/dist/esm/maps/componentToTag.native.js +21 -0
- package/dist/esm/maps/componentToTag.native.js.map +1 -0
- package/dist/esm/transform.mjs +677 -0
- package/dist/esm/transform.mjs.map +1 -0
- package/dist/esm/transform.native.js +902 -0
- package/dist/esm/transform.native.js.map +1 -0
- package/package.json +44 -7
- package/src/index.ts +2 -0
- package/src/maps/componentToTag.ts +18 -0
- package/src/transform.ts +889 -0
- package/README.md +0 -1
|
@@ -0,0 +1,706 @@
|
|
|
1
|
+
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all) __defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: () => from[key],
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var transform_exports = {};
|
|
29
|
+
__export(transform_exports, {
|
|
30
|
+
findParseError: () => findParseError,
|
|
31
|
+
tamaguiToTailwind: () => tamaguiToTailwind
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(transform_exports);
|
|
34
|
+
var import_parser = require("@babel/parser");
|
|
35
|
+
var import_traverse = __toESM(require("@babel/traverse"), 1);
|
|
36
|
+
var import_generator = __toESM(require("@babel/generator"), 1);
|
|
37
|
+
var t = __toESM(require("@babel/types"), 1);
|
|
38
|
+
var import_tooling = require("@tamagui/style-grammar/tooling");
|
|
39
|
+
var import_componentToTag = require("./maps/componentToTag.cjs");
|
|
40
|
+
var import_v4 = require("@tamagui/shorthands/v4");
|
|
41
|
+
const traverse = import_traverse.default.default ?? import_traverse.default;
|
|
42
|
+
const generate = import_generator.default.default ?? import_generator.default;
|
|
43
|
+
const defaultShorthands = import_v4.shorthands;
|
|
44
|
+
const removedV6ThemeNames = new Set(import_tooling.v6RemovedThemeNames);
|
|
45
|
+
function getV6ThemeName(name) {
|
|
46
|
+
const opacityIndex = name.indexOf("/");
|
|
47
|
+
const baseName = opacityIndex === -1 ? name : name.slice(0, opacityIndex);
|
|
48
|
+
if (removedV6ThemeNames.has(baseName)) return null;
|
|
49
|
+
const mapped = import_tooling.v6ThemeNameReplacements[baseName] ?? baseName;
|
|
50
|
+
return opacityIndex === -1 ? mapped : `${mapped}${name.slice(opacityIndex)}`;
|
|
51
|
+
}
|
|
52
|
+
function namesToSet(names) {
|
|
53
|
+
if (!names) return /* @__PURE__ */ new Set();
|
|
54
|
+
if (Array.isArray(names)) return new Set(names);
|
|
55
|
+
if (names instanceof Set) return new Set(names);
|
|
56
|
+
return new Set(Object.keys(names));
|
|
57
|
+
}
|
|
58
|
+
function addConfigNames(target, source) {
|
|
59
|
+
if (!source) return;
|
|
60
|
+
for (const key in source) target.add(key);
|
|
61
|
+
}
|
|
62
|
+
function createTransformGrammarConfig(options, mediaKeys, shorthands) {
|
|
63
|
+
if (options.grammarConfig) {
|
|
64
|
+
return {
|
|
65
|
+
...options.grammarConfig,
|
|
66
|
+
shorthands,
|
|
67
|
+
mediaNames: mediaKeys
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const tokenNames = {};
|
|
71
|
+
const tokenCategories = [
|
|
72
|
+
"space",
|
|
73
|
+
"size",
|
|
74
|
+
"radius",
|
|
75
|
+
"zIndex",
|
|
76
|
+
"color"
|
|
77
|
+
];
|
|
78
|
+
const fontCategories = [
|
|
79
|
+
"fontFamily",
|
|
80
|
+
"fontSize",
|
|
81
|
+
"fontWeight",
|
|
82
|
+
"lineHeight",
|
|
83
|
+
"letterSpacing"
|
|
84
|
+
];
|
|
85
|
+
const authoritative = [
|
|
86
|
+
"tokens",
|
|
87
|
+
"fonts",
|
|
88
|
+
"themes",
|
|
89
|
+
"media",
|
|
90
|
+
"shorthands"
|
|
91
|
+
].some((key) => Object.prototype.hasOwnProperty.call(options, key));
|
|
92
|
+
if (authoritative) {
|
|
93
|
+
for (const category of [...tokenCategories, ...fontCategories]) {
|
|
94
|
+
tokenNames[category] = /* @__PURE__ */ new Set();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
for (const category of tokenCategories) {
|
|
98
|
+
if (options.tokens?.[category]) {
|
|
99
|
+
const names = tokenNames[category] || /* @__PURE__ */ new Set();
|
|
100
|
+
addConfigNames(names, options.tokens[category]);
|
|
101
|
+
tokenNames[category] = names;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (options.fonts) {
|
|
105
|
+
tokenNames.fontFamily ||= /* @__PURE__ */ new Set();
|
|
106
|
+
tokenNames.fontSize ||= /* @__PURE__ */ new Set();
|
|
107
|
+
tokenNames.fontWeight ||= /* @__PURE__ */ new Set();
|
|
108
|
+
tokenNames.lineHeight ||= /* @__PURE__ */ new Set();
|
|
109
|
+
tokenNames.letterSpacing ||= /* @__PURE__ */ new Set();
|
|
110
|
+
for (const familyName in options.fonts) {
|
|
111
|
+
tokenNames.fontFamily.add(familyName);
|
|
112
|
+
const font = options.fonts[familyName];
|
|
113
|
+
addConfigNames(tokenNames.fontSize, font?.size);
|
|
114
|
+
addConfigNames(tokenNames.fontWeight, font?.weight);
|
|
115
|
+
addConfigNames(tokenNames.lineHeight, font?.lineHeight);
|
|
116
|
+
addConfigNames(tokenNames.letterSpacing, font?.letterSpacing);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const themeNames = /* @__PURE__ */ new Set();
|
|
120
|
+
if (options.themes) {
|
|
121
|
+
tokenNames.color ||= /* @__PURE__ */ new Set();
|
|
122
|
+
for (const themeName in options.themes) {
|
|
123
|
+
themeNames.add(themeName);
|
|
124
|
+
for (const name in options.themes[themeName]) {
|
|
125
|
+
const mapped = getV6ThemeName(name);
|
|
126
|
+
if (mapped) tokenNames.color.add(mapped);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
shorthands,
|
|
132
|
+
mediaNames: mediaKeys,
|
|
133
|
+
themeNames,
|
|
134
|
+
tokenNames
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function findParseError(source) {
|
|
138
|
+
try {
|
|
139
|
+
const ast = (0, import_parser.parse)(source, {
|
|
140
|
+
sourceType: "module",
|
|
141
|
+
plugins: ["jsx", "typescript"],
|
|
142
|
+
errorRecovery: true
|
|
143
|
+
});
|
|
144
|
+
const errs = ast.errors;
|
|
145
|
+
if (errs && errs.length > 0) {
|
|
146
|
+
const e = errs[0];
|
|
147
|
+
const loc = e?.loc ? `${e.loc.line}:${e.loc.column}` : "?";
|
|
148
|
+
return `${e?.reasonCode || e?.message || "parse error"} at ${loc}`;
|
|
149
|
+
}
|
|
150
|
+
return null;
|
|
151
|
+
} catch (e) {
|
|
152
|
+
return e.message || "parse error";
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function tamaguiToTailwind(source, options = {}) {
|
|
156
|
+
const { renameComponents = true } = options;
|
|
157
|
+
const mediaKeys = options.grammarConfig?.mediaNames ? namesToSet(options.grammarConfig.mediaNames) : options.media ? new Set(Array.isArray(options.media) ? options.media : Object.keys(options.media)) : new Set(import_tooling.defaultMediaKeys);
|
|
158
|
+
const shorthands = options.grammarConfig?.shorthands ?? options.shorthands ?? defaultShorthands;
|
|
159
|
+
const grammarConfig = createTransformGrammarConfig(options, mediaKeys, shorthands);
|
|
160
|
+
const ctx = {
|
|
161
|
+
mediaKeys,
|
|
162
|
+
componentAllow: new Set(options.components ?? []),
|
|
163
|
+
shorthands,
|
|
164
|
+
grammarConfig,
|
|
165
|
+
modifierRegistry: (0, import_tooling.createModifierRegistry)(grammarConfig).registry
|
|
166
|
+
};
|
|
167
|
+
let ast;
|
|
168
|
+
try {
|
|
169
|
+
ast = (0, import_parser.parse)(source, {
|
|
170
|
+
sourceType: "module",
|
|
171
|
+
plugins: ["jsx", "typescript"],
|
|
172
|
+
errorRecovery: true
|
|
173
|
+
});
|
|
174
|
+
} catch {
|
|
175
|
+
return source;
|
|
176
|
+
}
|
|
177
|
+
if (ast.errors && ast.errors.length > 0) {
|
|
178
|
+
return source;
|
|
179
|
+
}
|
|
180
|
+
let didTransform = false;
|
|
181
|
+
traverse(ast, { JSXOpeningElement(path) {
|
|
182
|
+
const node = path.node;
|
|
183
|
+
const resolved = resolveTamaguiComponent(path, ctx);
|
|
184
|
+
if (resolved === null) return;
|
|
185
|
+
const { name: componentName, isSimpleKnown, isPlainIdentifier } = resolved;
|
|
186
|
+
if (node.attributes.some((a) => t.isJSXSpreadAttribute(a))) return;
|
|
187
|
+
const hasDynamicClassName = node.attributes.some((attr) => t.isJSXAttribute(attr) && attr.name.name === "className" && getStringValue(attr.value) === null);
|
|
188
|
+
if (hasDynamicClassName) return;
|
|
189
|
+
const hasClassName = node.attributes.some((attr) => t.isJSXAttribute(attr) && attr.name.name === "className");
|
|
190
|
+
const hasNeighboringStyleProp = node.attributes.some((attr) => {
|
|
191
|
+
if (!t.isJSXAttribute(attr) || attr.name.name === "className") return false;
|
|
192
|
+
const name = attr.name.name;
|
|
193
|
+
return isConvertibleStyleProp(resolveShorthand(ctx, name));
|
|
194
|
+
});
|
|
195
|
+
if (hasClassName && hasNeighboringStyleProp) return;
|
|
196
|
+
const classes = [];
|
|
197
|
+
const keptAttrs = [];
|
|
198
|
+
let existingClassName = null;
|
|
199
|
+
const blockedLeafKeys = /* @__PURE__ */ new Set();
|
|
200
|
+
for (const a of node.attributes) {
|
|
201
|
+
if (t.isJSXAttribute(a) && a.name.name === "className") {
|
|
202
|
+
const v = getStringValue(a.value);
|
|
203
|
+
if (v) {
|
|
204
|
+
for (const tok of v.split(/\s+/)) {
|
|
205
|
+
if (tok) for (const k of leafKeysOfClassToken(tok)) blockedLeafKeys.add(k);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
const implicitClasses = [];
|
|
211
|
+
if (componentName === "XStack") implicitClasses.push("flex", "flex-row");
|
|
212
|
+
else if (componentName === "YStack") implicitClasses.push("flex", "flex-col");
|
|
213
|
+
else if (componentName === "ZStack") implicitClasses.push("relative");
|
|
214
|
+
const styleEntries = [];
|
|
215
|
+
for (const attr of node.attributes) {
|
|
216
|
+
if (!t.isJSXAttribute(attr)) {
|
|
217
|
+
keptAttrs.push(attr);
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
const name = attr.name.name;
|
|
221
|
+
if (name === "className") {
|
|
222
|
+
existingClassName = attr;
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
styleEntries.push({
|
|
226
|
+
attr,
|
|
227
|
+
fullProp: resolveShorthand(ctx, name),
|
|
228
|
+
cls: propValueToClass(ctx, name, attr.value)
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
const retainedLeafKeys = new Set(blockedLeafKeys);
|
|
232
|
+
for (const e of styleEntries) {
|
|
233
|
+
if (e.cls === null && isConvertibleStyleProp(e.fullProp)) {
|
|
234
|
+
for (const k of leafKeysOfProp(e.fullProp)) retainedLeafKeys.add(k);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
for (const c of implicitClasses) {
|
|
238
|
+
if (!overlapsSet(leafKeysOfClassToken(c), retainedLeafKeys)) classes.push(c);
|
|
239
|
+
}
|
|
240
|
+
for (const e of styleEntries) {
|
|
241
|
+
if (e.cls !== null && !overlapsSet(leafKeysOfProp(e.fullProp), retainedLeafKeys)) {
|
|
242
|
+
classes.push(e.cls);
|
|
243
|
+
} else {
|
|
244
|
+
keptAttrs.push(e.attr);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if (classes.length > 0) {
|
|
248
|
+
const classStr = classes.join(" ");
|
|
249
|
+
if (existingClassName) {
|
|
250
|
+
const existingVal = getStringValue(existingClassName.value);
|
|
251
|
+
if (existingVal !== null) {
|
|
252
|
+
existingClassName.value = t.stringLiteral(existingVal ? `${classStr} ${existingVal}` : classStr);
|
|
253
|
+
keptAttrs.unshift(existingClassName);
|
|
254
|
+
} else if (t.isJSXExpressionContainer(existingClassName.value) && !t.isJSXEmptyExpression(existingClassName.value.expression)) {
|
|
255
|
+
const expr = existingClassName.value.expression;
|
|
256
|
+
existingClassName.value = t.jsxExpressionContainer(t.templateLiteral([t.templateElement({
|
|
257
|
+
raw: `${classStr} `,
|
|
258
|
+
cooked: `${classStr} `
|
|
259
|
+
}, false), t.templateElement({
|
|
260
|
+
raw: "",
|
|
261
|
+
cooked: ""
|
|
262
|
+
}, true)], [expr]));
|
|
263
|
+
keptAttrs.unshift(existingClassName);
|
|
264
|
+
} else {
|
|
265
|
+
keptAttrs.unshift(t.jsxAttribute(t.jsxIdentifier("className"), t.stringLiteral(classStr)));
|
|
266
|
+
}
|
|
267
|
+
} else {
|
|
268
|
+
keptAttrs.unshift(t.jsxAttribute(t.jsxIdentifier("className"), t.stringLiteral(classStr)));
|
|
269
|
+
}
|
|
270
|
+
} else if (existingClassName) {
|
|
271
|
+
keptAttrs.unshift(existingClassName);
|
|
272
|
+
}
|
|
273
|
+
node.attributes = keptAttrs;
|
|
274
|
+
if (classes.length > 0) didTransform = true;
|
|
275
|
+
if (renameComponents && isSimpleKnown && isPlainIdentifier) {
|
|
276
|
+
const tag = import_componentToTag.componentToTag[componentName];
|
|
277
|
+
node.name = t.jsxIdentifier(tag);
|
|
278
|
+
const parent = path.parent;
|
|
279
|
+
if (t.isJSXElement(parent) && parent.closingElement) {
|
|
280
|
+
parent.closingElement.name = t.jsxIdentifier(tag);
|
|
281
|
+
}
|
|
282
|
+
didTransform = true;
|
|
283
|
+
}
|
|
284
|
+
} });
|
|
285
|
+
if (!didTransform) return source;
|
|
286
|
+
const output = generate(ast, {
|
|
287
|
+
retainLines: true,
|
|
288
|
+
concise: false
|
|
289
|
+
});
|
|
290
|
+
return output.code;
|
|
291
|
+
}
|
|
292
|
+
const knownCompoundComponents = /* @__PURE__ */ new Set([
|
|
293
|
+
"Sheet.Frame",
|
|
294
|
+
"Sheet.Overlay",
|
|
295
|
+
"Sheet.Handle",
|
|
296
|
+
"Sheet.ScrollView",
|
|
297
|
+
"Sheet.Container",
|
|
298
|
+
"Dialog.Content",
|
|
299
|
+
"Dialog.Overlay",
|
|
300
|
+
"Popover.Content",
|
|
301
|
+
"Tabs.Tab"
|
|
302
|
+
]);
|
|
303
|
+
function isTamaguiSource(source) {
|
|
304
|
+
return source === "tamagui" || source.startsWith("@tamagui/");
|
|
305
|
+
}
|
|
306
|
+
function resolveTamaguiComponent(path, ctx) {
|
|
307
|
+
const nameNode = path.node.name;
|
|
308
|
+
let baseName;
|
|
309
|
+
let memberChain = [];
|
|
310
|
+
const isPlainIdentifier = t.isJSXIdentifier(nameNode);
|
|
311
|
+
if (t.isJSXIdentifier(nameNode)) {
|
|
312
|
+
baseName = nameNode.name;
|
|
313
|
+
} else if (t.isJSXMemberExpression(nameNode)) {
|
|
314
|
+
const parts = [];
|
|
315
|
+
let cur = nameNode;
|
|
316
|
+
while (t.isJSXMemberExpression(cur)) {
|
|
317
|
+
parts.unshift(cur.property.name);
|
|
318
|
+
cur = cur.object;
|
|
319
|
+
}
|
|
320
|
+
if (!t.isJSXIdentifier(cur)) return null;
|
|
321
|
+
baseName = cur.name;
|
|
322
|
+
memberChain = parts;
|
|
323
|
+
} else {
|
|
324
|
+
return null;
|
|
325
|
+
}
|
|
326
|
+
const binding = path.scope?.getBinding?.(baseName);
|
|
327
|
+
let tamaguiBase;
|
|
328
|
+
if (binding) {
|
|
329
|
+
const bnode = binding.path.node;
|
|
330
|
+
if (t.isImportSpecifier(bnode) || t.isImportDefaultSpecifier(bnode) || t.isImportNamespaceSpecifier(bnode)) {
|
|
331
|
+
const decl = binding.path.parent;
|
|
332
|
+
const source = t.isImportDeclaration(decl) ? String(decl.source.value) : "";
|
|
333
|
+
if (!isTamaguiSource(source)) return null;
|
|
334
|
+
if (t.isImportNamespaceSpecifier(bnode)) {
|
|
335
|
+
if (memberChain.length === 0) return null;
|
|
336
|
+
tamaguiBase = memberChain[0];
|
|
337
|
+
memberChain = memberChain.slice(1);
|
|
338
|
+
} else if (t.isImportSpecifier(bnode)) {
|
|
339
|
+
const imported = bnode.imported;
|
|
340
|
+
tamaguiBase = t.isIdentifier(imported) ? imported.name : String(imported.value);
|
|
341
|
+
} else {
|
|
342
|
+
return null;
|
|
343
|
+
}
|
|
344
|
+
} else {
|
|
345
|
+
return null;
|
|
346
|
+
}
|
|
347
|
+
} else {
|
|
348
|
+
tamaguiBase = baseName;
|
|
349
|
+
}
|
|
350
|
+
const name = memberChain.length ? [tamaguiBase, ...memberChain].join(".") : tamaguiBase;
|
|
351
|
+
const isSimpleKnown = memberChain.length === 0 && name in import_componentToTag.componentToTag;
|
|
352
|
+
if (!isSimpleKnown && !knownCompoundComponents.has(name) && !ctx.componentAllow.has(name)) {
|
|
353
|
+
return null;
|
|
354
|
+
}
|
|
355
|
+
return {
|
|
356
|
+
name,
|
|
357
|
+
isSimpleKnown,
|
|
358
|
+
isPlainIdentifier
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
function classPrefixOf(token) {
|
|
362
|
+
const noMod = token.slice(token.lastIndexOf(":") + 1);
|
|
363
|
+
const core = noMod[0] === "-" ? noMod.slice(1) : noMod;
|
|
364
|
+
const dash = core.indexOf("-");
|
|
365
|
+
return dash === -1 ? core : core.slice(0, dash);
|
|
366
|
+
}
|
|
367
|
+
const leafExpansion = {
|
|
368
|
+
padding: [
|
|
369
|
+
"paddingTop",
|
|
370
|
+
"paddingRight",
|
|
371
|
+
"paddingBottom",
|
|
372
|
+
"paddingLeft"
|
|
373
|
+
],
|
|
374
|
+
paddingHorizontal: ["paddingLeft", "paddingRight"],
|
|
375
|
+
paddingVertical: ["paddingTop", "paddingBottom"],
|
|
376
|
+
margin: [
|
|
377
|
+
"marginTop",
|
|
378
|
+
"marginRight",
|
|
379
|
+
"marginBottom",
|
|
380
|
+
"marginLeft"
|
|
381
|
+
],
|
|
382
|
+
marginHorizontal: ["marginLeft", "marginRight"],
|
|
383
|
+
marginVertical: ["marginTop", "marginBottom"],
|
|
384
|
+
inset: [
|
|
385
|
+
"top",
|
|
386
|
+
"right",
|
|
387
|
+
"bottom",
|
|
388
|
+
"left"
|
|
389
|
+
],
|
|
390
|
+
gap: [
|
|
391
|
+
"gap",
|
|
392
|
+
"rowGap",
|
|
393
|
+
"columnGap"
|
|
394
|
+
],
|
|
395
|
+
borderWidth: [
|
|
396
|
+
"borderTopWidth",
|
|
397
|
+
"borderRightWidth",
|
|
398
|
+
"borderBottomWidth",
|
|
399
|
+
"borderLeftWidth"
|
|
400
|
+
],
|
|
401
|
+
borderColor: [
|
|
402
|
+
"borderTopColor",
|
|
403
|
+
"borderRightColor",
|
|
404
|
+
"borderBottomColor",
|
|
405
|
+
"borderLeftColor"
|
|
406
|
+
],
|
|
407
|
+
borderRadius: [
|
|
408
|
+
"borderTopLeftRadius",
|
|
409
|
+
"borderTopRightRadius",
|
|
410
|
+
"borderBottomLeftRadius",
|
|
411
|
+
"borderBottomRightRadius"
|
|
412
|
+
]
|
|
413
|
+
};
|
|
414
|
+
function leafKeysOfProp(fullProp) {
|
|
415
|
+
return leafExpansion[fullProp] ?? [fullProp];
|
|
416
|
+
}
|
|
417
|
+
const prefixToProp = (() => {
|
|
418
|
+
const m = {};
|
|
419
|
+
for (const [prop, prefix] of Object.entries(import_tooling.propToTailwindPrefix)) {
|
|
420
|
+
if (prefix && !(prefix in m)) m[prefix] = prop;
|
|
421
|
+
}
|
|
422
|
+
return m;
|
|
423
|
+
})();
|
|
424
|
+
function leafKeysOfClassToken(token) {
|
|
425
|
+
const prefix = classPrefixOf(token);
|
|
426
|
+
return leafKeysOfProp(prefixToProp[prefix] ?? prefix);
|
|
427
|
+
}
|
|
428
|
+
function overlapsSet(keys, set) {
|
|
429
|
+
return keys.some((k) => set.has(k));
|
|
430
|
+
}
|
|
431
|
+
function isConvertibleStyleProp(fullProp) {
|
|
432
|
+
return import_tooling.propToTailwindPrefix[fullProp] !== void 0 || fullProp in import_tooling.standaloneValueProps;
|
|
433
|
+
}
|
|
434
|
+
function propValueToClass(ctx, propName, value) {
|
|
435
|
+
const fullProp = resolveShorthand(ctx, propName);
|
|
436
|
+
if (import_tooling.propToTailwindPrefix[fullProp] === void 0) return null;
|
|
437
|
+
const strVal = getStringValue(value);
|
|
438
|
+
const numVal = getNumericValue(value);
|
|
439
|
+
if (strVal !== null) {
|
|
440
|
+
const parsed = (0, import_tooling.parseValue)(strVal, ctx.modifierRegistry);
|
|
441
|
+
if (!parsed.ok) return null;
|
|
442
|
+
const classes = [];
|
|
443
|
+
if (parsed.value.base !== null) {
|
|
444
|
+
const base = payloadToClass(ctx, fullProp, parsed.value.base, []);
|
|
445
|
+
if (base === null) return null;
|
|
446
|
+
classes.push(base);
|
|
447
|
+
}
|
|
448
|
+
for (const clause of parsed.value.clauses) {
|
|
449
|
+
const conditional = payloadToClass(ctx, fullProp, clause.payload, clause.modifiers);
|
|
450
|
+
if (conditional === null) return null;
|
|
451
|
+
classes.push(conditional);
|
|
452
|
+
}
|
|
453
|
+
return classes.length ? classes.join(" ") : null;
|
|
454
|
+
}
|
|
455
|
+
if (numVal === null) return null;
|
|
456
|
+
const formatted = formatNumericValue(fullProp, numVal);
|
|
457
|
+
if (formatted === null) return null;
|
|
458
|
+
return (0, import_tooling.formatCandidate)({
|
|
459
|
+
prop: fullProp,
|
|
460
|
+
value: formatted.value,
|
|
461
|
+
valueKind: formatted.valueKind,
|
|
462
|
+
modifiers: void 0
|
|
463
|
+
}, ctx.grammarConfig);
|
|
464
|
+
}
|
|
465
|
+
function payloadToClass(ctx, fullProp, payload, modifiers) {
|
|
466
|
+
let formatted;
|
|
467
|
+
if (import_tooling.standaloneValueProps[fullProp]?.[payload]) {
|
|
468
|
+
formatted = {
|
|
469
|
+
value: payload,
|
|
470
|
+
valueKind: "enum"
|
|
471
|
+
};
|
|
472
|
+
} else {
|
|
473
|
+
formatted = formatStringValue(ctx, fullProp, payload);
|
|
474
|
+
if (formatted === null && /^-?\d+(?:\.\d+)?$/.test(payload)) {
|
|
475
|
+
const category = (0, import_tooling.getTokenCategory)(fullProp);
|
|
476
|
+
if (!category || ctx.grammarConfig.tokenNames?.[category] !== void 0) {
|
|
477
|
+
formatted = formatNumericValue(fullProp, Number(payload));
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
if (formatted === null) return null;
|
|
482
|
+
return (0, import_tooling.formatCandidate)({
|
|
483
|
+
prop: fullProp,
|
|
484
|
+
value: formatted.value,
|
|
485
|
+
valueKind: formatted.valueKind,
|
|
486
|
+
modifiers: modifiers.length ? modifiers : void 0
|
|
487
|
+
}, ctx.grammarConfig);
|
|
488
|
+
}
|
|
489
|
+
function getStringValue(value) {
|
|
490
|
+
if (!value) return null;
|
|
491
|
+
if (t.isStringLiteral(value)) return value.value;
|
|
492
|
+
if (t.isJSXExpressionContainer(value) && t.isStringLiteral(value.expression)) {
|
|
493
|
+
return value.expression.value;
|
|
494
|
+
}
|
|
495
|
+
if (t.isJSXExpressionContainer(value) && t.isTemplateLiteral(value.expression)) {
|
|
496
|
+
if (value.expression.expressions.length === 0 && value.expression.quasis.length === 1) {
|
|
497
|
+
return value.expression.quasis[0].value.raw;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
return null;
|
|
501
|
+
}
|
|
502
|
+
function getNumericValue(value) {
|
|
503
|
+
if (!value) return null;
|
|
504
|
+
if (t.isJSXExpressionContainer(value)) {
|
|
505
|
+
if (t.isNumericLiteral(value.expression)) return value.expression.value;
|
|
506
|
+
if (t.isUnaryExpression(value.expression) && value.expression.operator === "-" && t.isNumericLiteral(value.expression.argument)) {
|
|
507
|
+
return -value.expression.argument.value;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
return null;
|
|
511
|
+
}
|
|
512
|
+
function resolveShorthand(ctx, name) {
|
|
513
|
+
return ctx.shorthands[name] || name;
|
|
514
|
+
}
|
|
515
|
+
function hasConfiguredName(names, value) {
|
|
516
|
+
if (!names) return false;
|
|
517
|
+
if (Array.isArray(names)) return names.includes(value);
|
|
518
|
+
if (names instanceof Set) return names.has(value);
|
|
519
|
+
return Object.prototype.hasOwnProperty.call(names, value);
|
|
520
|
+
}
|
|
521
|
+
function formatStringValue(ctx, prop, value) {
|
|
522
|
+
const category = (0, import_tooling.getTokenCategory)(prop);
|
|
523
|
+
if (prop !== "fontWeight" && category && hasConfiguredName(ctx.grammarConfig.tokenNames?.[category], value)) {
|
|
524
|
+
if (category === "color") {
|
|
525
|
+
const mapped = getV6ThemeName(value);
|
|
526
|
+
return mapped ? {
|
|
527
|
+
value: mapped,
|
|
528
|
+
valueKind: "token"
|
|
529
|
+
} : null;
|
|
530
|
+
}
|
|
531
|
+
return {
|
|
532
|
+
value,
|
|
533
|
+
valueKind: "token"
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
if (prop === "fontWeight") {
|
|
537
|
+
return import_tooling.fontWeightNames[value] ? {
|
|
538
|
+
value,
|
|
539
|
+
valueKind: "enum"
|
|
540
|
+
} : null;
|
|
541
|
+
}
|
|
542
|
+
if (prop === "zIndex" && /^\d+$/.test(value)) {
|
|
543
|
+
return {
|
|
544
|
+
value,
|
|
545
|
+
valueKind: "convenience"
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
if (/^-?\d+(\.\d+)?$/.test(value)) return null;
|
|
549
|
+
if (value.endsWith("%")) {
|
|
550
|
+
const exact = {
|
|
551
|
+
"100%": "full",
|
|
552
|
+
"50%": "1/2",
|
|
553
|
+
"25%": "1/4",
|
|
554
|
+
"75%": "3/4"
|
|
555
|
+
};
|
|
556
|
+
if ((0, import_tooling.getTokenCategory)(prop) === "size" && exact[value]) {
|
|
557
|
+
return {
|
|
558
|
+
value: exact[value],
|
|
559
|
+
valueKind: "convenience"
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
return {
|
|
563
|
+
value,
|
|
564
|
+
valueKind: "arbitrary"
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
if (value === "auto" && (0, import_tooling.getTokenCategory)(prop) === "size") {
|
|
568
|
+
return {
|
|
569
|
+
value,
|
|
570
|
+
valueKind: "convenience"
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
if (prop === "fontFamily") return {
|
|
574
|
+
value,
|
|
575
|
+
valueKind: "arbitrary"
|
|
576
|
+
};
|
|
577
|
+
if (value.includes("(") || value.includes(" ") || value.includes("_") || value.startsWith("#") || value.startsWith("-") || /^[\d.]+[a-z%]/i.test(value)) {
|
|
578
|
+
return {
|
|
579
|
+
value,
|
|
580
|
+
valueKind: "arbitrary"
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
return {
|
|
584
|
+
value,
|
|
585
|
+
valueKind: "arbitrary"
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
const pxLengthProps = /* @__PURE__ */ new Set([
|
|
589
|
+
"width",
|
|
590
|
+
"height",
|
|
591
|
+
"minWidth",
|
|
592
|
+
"maxWidth",
|
|
593
|
+
"minHeight",
|
|
594
|
+
"maxHeight",
|
|
595
|
+
"flexBasis",
|
|
596
|
+
"padding",
|
|
597
|
+
"paddingTop",
|
|
598
|
+
"paddingRight",
|
|
599
|
+
"paddingBottom",
|
|
600
|
+
"paddingLeft",
|
|
601
|
+
"paddingHorizontal",
|
|
602
|
+
"paddingVertical",
|
|
603
|
+
"margin",
|
|
604
|
+
"marginTop",
|
|
605
|
+
"marginRight",
|
|
606
|
+
"marginBottom",
|
|
607
|
+
"marginLeft",
|
|
608
|
+
"marginHorizontal",
|
|
609
|
+
"marginVertical",
|
|
610
|
+
"gap",
|
|
611
|
+
"rowGap",
|
|
612
|
+
"columnGap",
|
|
613
|
+
"top",
|
|
614
|
+
"right",
|
|
615
|
+
"bottom",
|
|
616
|
+
"left",
|
|
617
|
+
"inset",
|
|
618
|
+
"borderRadius",
|
|
619
|
+
"borderTopLeftRadius",
|
|
620
|
+
"borderTopRightRadius",
|
|
621
|
+
"borderBottomLeftRadius",
|
|
622
|
+
"borderBottomRightRadius",
|
|
623
|
+
"fontSize",
|
|
624
|
+
"letterSpacing",
|
|
625
|
+
"lineHeight"
|
|
626
|
+
]);
|
|
627
|
+
function formatNumericValue(prop, value) {
|
|
628
|
+
if (prop === "opacity") {
|
|
629
|
+
const pct = value * 100;
|
|
630
|
+
return Number.isInteger(pct) ? {
|
|
631
|
+
value: String(pct),
|
|
632
|
+
valueKind: "convenience"
|
|
633
|
+
} : {
|
|
634
|
+
value: String(value),
|
|
635
|
+
valueKind: "arbitrary"
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
if (prop === "aspectRatio") return {
|
|
639
|
+
value: String(value),
|
|
640
|
+
valueKind: "arbitrary"
|
|
641
|
+
};
|
|
642
|
+
if (prop === "scale" || prop === "scaleX" || prop === "scaleY") {
|
|
643
|
+
if (value === 0) return {
|
|
644
|
+
value: "0",
|
|
645
|
+
valueKind: "convenience"
|
|
646
|
+
};
|
|
647
|
+
if (value === 1) return {
|
|
648
|
+
value: "100",
|
|
649
|
+
valueKind: "convenience"
|
|
650
|
+
};
|
|
651
|
+
return {
|
|
652
|
+
value: String(value),
|
|
653
|
+
valueKind: "arbitrary"
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
if (prop === "flex") {
|
|
657
|
+
return value === 1 ? {
|
|
658
|
+
value: "1",
|
|
659
|
+
valueKind: "convenience"
|
|
660
|
+
} : {
|
|
661
|
+
value: String(value),
|
|
662
|
+
valueKind: "arbitrary"
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
if (prop === "flexGrow" || prop === "flexShrink") {
|
|
666
|
+
return {
|
|
667
|
+
value: String(value),
|
|
668
|
+
valueKind: "arbitrary"
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
if (prop === "zIndex") {
|
|
672
|
+
return Number.isInteger(value) && value >= 0 ? {
|
|
673
|
+
value: String(value),
|
|
674
|
+
valueKind: "convenience"
|
|
675
|
+
} : {
|
|
676
|
+
value: String(value),
|
|
677
|
+
valueKind: "arbitrary"
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
if (prop === "fontWeight") {
|
|
681
|
+
return import_tooling.fontWeightNames[String(value)] ? {
|
|
682
|
+
value: String(value),
|
|
683
|
+
valueKind: "enum"
|
|
684
|
+
} : null;
|
|
685
|
+
}
|
|
686
|
+
if (prop === "rotate") return null;
|
|
687
|
+
if (prop === "x" || prop === "y") {
|
|
688
|
+
return {
|
|
689
|
+
value: `${value}px`,
|
|
690
|
+
valueKind: "arbitrary"
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
if (prop.includes("Width") && prop.startsWith("border")) {
|
|
694
|
+
return {
|
|
695
|
+
value: `${value}px`,
|
|
696
|
+
valueKind: "arbitrary"
|
|
697
|
+
};
|
|
698
|
+
}
|
|
699
|
+
if (pxLengthProps.has(prop)) {
|
|
700
|
+
return {
|
|
701
|
+
value: `${value}px`,
|
|
702
|
+
valueKind: "arbitrary"
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
return null;
|
|
706
|
+
}
|