@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.
@@ -0,0 +1,902 @@
1
+ import { parse } from "@babel/parser";
2
+ import _traverse from "@babel/traverse";
3
+ import _generate from "@babel/generator";
4
+ import * as t from "@babel/types";
5
+ import { createModifierRegistry, defaultMediaKeys, fontWeightNames, formatCandidate, getTokenCategory, parseValue, propToTailwindPrefix, standaloneValueProps, v6RemovedThemeNames, v6ThemeNameReplacements } from "@tamagui/style-grammar/tooling";
6
+ import { componentToTag } from "./maps/componentToTag.native.js";
7
+ import { shorthands } from "@tamagui/shorthands/v4";
8
+
9
+ function _instanceof(left, right) {
10
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
11
+ return !!right[Symbol.hasInstance](left);
12
+ } else {
13
+ return left instanceof right;
14
+ }
15
+ }
16
+ var _traverse_default;
17
+ var traverse = (_traverse_default = _traverse.default) !== null && _traverse_default !== void 0 ? _traverse_default : _traverse;
18
+ var _generate_default;
19
+ var generate = (_generate_default = _generate.default) !== null && _generate_default !== void 0 ? _generate_default : _generate;
20
+ var defaultShorthands = shorthands;
21
+ var removedV6ThemeNames = new Set(v6RemovedThemeNames);
22
+ function getV6ThemeName(name) {
23
+ var opacityIndex = name.indexOf("/");
24
+ var baseName = opacityIndex === -1 ? name : name.slice(0, opacityIndex);
25
+ if (removedV6ThemeNames.has(baseName)) return null;
26
+ var _v6ThemeNameReplacements_baseName;
27
+ var mapped = (_v6ThemeNameReplacements_baseName = v6ThemeNameReplacements[baseName]) !== null && _v6ThemeNameReplacements_baseName !== void 0 ? _v6ThemeNameReplacements_baseName : baseName;
28
+ return opacityIndex === -1 ? mapped : `${mapped}${name.slice(opacityIndex)}`;
29
+ }
30
+ function namesToSet(names) {
31
+ if (!names) return /* @__PURE__ */ new Set();
32
+ if (Array.isArray(names)) return new Set(names);
33
+ if (_instanceof(names, Set)) return new Set(names);
34
+ return new Set(Object.keys(names));
35
+ }
36
+ function addConfigNames(target, source) {
37
+ if (!source) return;
38
+ for (var key in source) target.add(key);
39
+ }
40
+ function createTransformGrammarConfig(options, mediaKeys, shorthands) {
41
+ if (options.grammarConfig) {
42
+ return {
43
+ ...options.grammarConfig,
44
+ shorthands,
45
+ mediaNames: mediaKeys
46
+ };
47
+ }
48
+ var tokenNames = {};
49
+ var tokenCategories = [
50
+ "space",
51
+ "size",
52
+ "radius",
53
+ "zIndex",
54
+ "color"
55
+ ];
56
+ var fontCategories = [
57
+ "fontFamily",
58
+ "fontSize",
59
+ "fontWeight",
60
+ "lineHeight",
61
+ "letterSpacing"
62
+ ];
63
+ var authoritative = [
64
+ "tokens",
65
+ "fonts",
66
+ "themes",
67
+ "media",
68
+ "shorthands"
69
+ ].some(function(key) {
70
+ return Object.prototype.hasOwnProperty.call(options, key);
71
+ });
72
+ if (authoritative) {
73
+ for (var _i = 0, _iter = [...tokenCategories, ...fontCategories]; _i < _iter.length; _i++) {
74
+ var category = _iter[_i];
75
+ tokenNames[category] = /* @__PURE__ */ new Set();
76
+ }
77
+ }
78
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
79
+ try {
80
+ for (var _iterator = tokenCategories[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
81
+ var category1 = _step.value;
82
+ var _options_tokens;
83
+ if ((_options_tokens = options.tokens) === null || _options_tokens === void 0 ? void 0 : _options_tokens[category1]) {
84
+ var names = tokenNames[category1] || /* @__PURE__ */ new Set();
85
+ addConfigNames(names, options.tokens[category1]);
86
+ tokenNames[category1] = names;
87
+ }
88
+ }
89
+ } catch (err) {
90
+ _didIteratorError = true;
91
+ _iteratorError = err;
92
+ } finally {
93
+ try {
94
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
95
+ _iterator.return();
96
+ }
97
+ } finally {
98
+ if (_didIteratorError) {
99
+ throw _iteratorError;
100
+ }
101
+ }
102
+ }
103
+ if (options.fonts) {
104
+ var _tokenNames, _tokenNames1, _tokenNames2, _tokenNames3, _tokenNames4;
105
+ (_tokenNames = tokenNames).fontFamily || (_tokenNames.fontFamily = /* @__PURE__ */ new Set());
106
+ (_tokenNames1 = tokenNames).fontSize || (_tokenNames1.fontSize = /* @__PURE__ */ new Set());
107
+ (_tokenNames2 = tokenNames).fontWeight || (_tokenNames2.fontWeight = /* @__PURE__ */ new Set());
108
+ (_tokenNames3 = tokenNames).lineHeight || (_tokenNames3.lineHeight = /* @__PURE__ */ new Set());
109
+ (_tokenNames4 = tokenNames).letterSpacing || (_tokenNames4.letterSpacing = /* @__PURE__ */ new Set());
110
+ for (var familyName in options.fonts) {
111
+ tokenNames.fontFamily.add(familyName);
112
+ var font = options.fonts[familyName];
113
+ addConfigNames(tokenNames.fontSize, font === null || font === void 0 ? void 0 : font.size);
114
+ addConfigNames(tokenNames.fontWeight, font === null || font === void 0 ? void 0 : font.weight);
115
+ addConfigNames(tokenNames.lineHeight, font === null || font === void 0 ? void 0 : font.lineHeight);
116
+ addConfigNames(tokenNames.letterSpacing, font === null || font === void 0 ? void 0 : font.letterSpacing);
117
+ }
118
+ }
119
+ var themeNames = /* @__PURE__ */ new Set();
120
+ if (options.themes) {
121
+ var _tokenNames5;
122
+ (_tokenNames5 = tokenNames).color || (_tokenNames5.color = /* @__PURE__ */ new Set());
123
+ for (var themeName in options.themes) {
124
+ themeNames.add(themeName);
125
+ for (var name in options.themes[themeName]) {
126
+ var mapped = getV6ThemeName(name);
127
+ if (mapped) tokenNames.color.add(mapped);
128
+ }
129
+ }
130
+ }
131
+ return {
132
+ shorthands,
133
+ mediaNames: mediaKeys,
134
+ themeNames,
135
+ tokenNames
136
+ };
137
+ }
138
+ function findParseError(source) {
139
+ try {
140
+ var ast = parse(source, {
141
+ sourceType: "module",
142
+ plugins: ["jsx", "typescript"],
143
+ errorRecovery: true
144
+ });
145
+ var errs = ast.errors;
146
+ if (errs && errs.length > 0) {
147
+ var _$e = errs[0];
148
+ var loc = (_$e === null || _$e === void 0 ? void 0 : _$e.loc) ? `${_$e.loc.line}:${_$e.loc.column}` : "?";
149
+ return `${(_$e === null || _$e === void 0 ? void 0 : _$e.reasonCode) || (_$e === null || _$e === void 0 ? void 0 : _$e.message) || "parse error"} at ${loc}`;
150
+ }
151
+ return null;
152
+ } catch (e) {
153
+ return e.message || "parse error";
154
+ }
155
+ }
156
+ function tamaguiToTailwind(source) {
157
+ var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
158
+ var _options_grammarConfig, _options_grammarConfig1;
159
+ var { renameComponents = true } = options;
160
+ var mediaKeys = ((_options_grammarConfig = options.grammarConfig) === null || _options_grammarConfig === void 0 ? void 0 : _options_grammarConfig.mediaNames) ? namesToSet(options.grammarConfig.mediaNames) : options.media ? new Set(Array.isArray(options.media) ? options.media : Object.keys(options.media)) : new Set(defaultMediaKeys);
161
+ var _options_grammarConfig_shorthands, _ref;
162
+ var shorthands = (_ref = (_options_grammarConfig_shorthands = (_options_grammarConfig1 = options.grammarConfig) === null || _options_grammarConfig1 === void 0 ? void 0 : _options_grammarConfig1.shorthands) !== null && _options_grammarConfig_shorthands !== void 0 ? _options_grammarConfig_shorthands : options.shorthands) !== null && _ref !== void 0 ? _ref : defaultShorthands;
163
+ var grammarConfig = createTransformGrammarConfig(options, mediaKeys, shorthands);
164
+ var _options_components;
165
+ var ctx = {
166
+ mediaKeys,
167
+ componentAllow: new Set((_options_components = options.components) !== null && _options_components !== void 0 ? _options_components : []),
168
+ shorthands,
169
+ grammarConfig,
170
+ modifierRegistry: createModifierRegistry(grammarConfig).registry
171
+ };
172
+ var ast;
173
+ try {
174
+ ast = parse(source, {
175
+ sourceType: "module",
176
+ plugins: ["jsx", "typescript"],
177
+ errorRecovery: true
178
+ });
179
+ } catch (e) {
180
+ return source;
181
+ }
182
+ if (ast.errors && ast.errors.length > 0) {
183
+ return source;
184
+ }
185
+ var didTransform = false;
186
+ traverse(ast, { JSXOpeningElement(path) {
187
+ var node = path.node;
188
+ var resolved = resolveTamaguiComponent(path, ctx);
189
+ if (resolved === null) return;
190
+ var { name: componentName, isSimpleKnown, isPlainIdentifier } = resolved;
191
+ if (node.attributes.some(function(a2) {
192
+ return t.isJSXSpreadAttribute(a2);
193
+ })) return;
194
+ var hasDynamicClassName = node.attributes.some(function(attr2) {
195
+ return t.isJSXAttribute(attr2) && attr2.name.name === "className" && getStringValue(attr2.value) === null;
196
+ });
197
+ if (hasDynamicClassName) return;
198
+ var hasClassName = node.attributes.some(function(attr2) {
199
+ return t.isJSXAttribute(attr2) && attr2.name.name === "className";
200
+ });
201
+ var hasNeighboringStyleProp = node.attributes.some(function(attr2) {
202
+ if (!t.isJSXAttribute(attr2) || attr2.name.name === "className") return false;
203
+ var name2 = attr2.name.name;
204
+ return isConvertibleStyleProp(resolveShorthand(ctx, name2));
205
+ });
206
+ if (hasClassName && hasNeighboringStyleProp) return;
207
+ var classes = [];
208
+ var keptAttrs = [];
209
+ var existingClassName = null;
210
+ var blockedLeafKeys = /* @__PURE__ */ new Set();
211
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
212
+ try {
213
+ for (var _iterator = node.attributes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
214
+ var a = _step.value;
215
+ if (t.isJSXAttribute(a) && a.name.name === "className") {
216
+ var v = getStringValue(a.value);
217
+ if (v) {
218
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
219
+ try {
220
+ for (var _iterator1 = v.split(/\s+/)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
221
+ var tok = _step1.value;
222
+ var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0;
223
+ if (tok) try {
224
+ for (var _iterator2 = leafKeysOfClassToken(tok)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
225
+ var k = _step2.value;
226
+ blockedLeafKeys.add(k);
227
+ }
228
+ } catch (err) {
229
+ _didIteratorError2 = true;
230
+ _iteratorError2 = err;
231
+ } finally {
232
+ try {
233
+ if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
234
+ _iterator2.return();
235
+ }
236
+ } finally {
237
+ if (_didIteratorError2) {
238
+ throw _iteratorError2;
239
+ }
240
+ }
241
+ }
242
+ }
243
+ } catch (err) {
244
+ _didIteratorError1 = true;
245
+ _iteratorError1 = err;
246
+ } finally {
247
+ try {
248
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
249
+ _iterator1.return();
250
+ }
251
+ } finally {
252
+ if (_didIteratorError1) {
253
+ throw _iteratorError1;
254
+ }
255
+ }
256
+ }
257
+ }
258
+ }
259
+ }
260
+ } catch (err) {
261
+ _didIteratorError = true;
262
+ _iteratorError = err;
263
+ } finally {
264
+ try {
265
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
266
+ _iterator.return();
267
+ }
268
+ } finally {
269
+ if (_didIteratorError) {
270
+ throw _iteratorError;
271
+ }
272
+ }
273
+ }
274
+ var implicitClasses = [];
275
+ if (componentName === "XStack") implicitClasses.push("flex", "flex-row");
276
+ else if (componentName === "YStack") implicitClasses.push("flex", "flex-col");
277
+ else if (componentName === "ZStack") implicitClasses.push("relative");
278
+ var styleEntries = [];
279
+ var _iteratorNormalCompletion3 = true, _didIteratorError3 = false, _iteratorError3 = void 0;
280
+ try {
281
+ for (var _iterator3 = node.attributes[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
282
+ var attr = _step3.value;
283
+ if (!t.isJSXAttribute(attr)) {
284
+ keptAttrs.push(attr);
285
+ continue;
286
+ }
287
+ var name = attr.name.name;
288
+ if (name === "className") {
289
+ existingClassName = attr;
290
+ continue;
291
+ }
292
+ styleEntries.push({
293
+ attr,
294
+ fullProp: resolveShorthand(ctx, name),
295
+ cls: propValueToClass(ctx, name, attr.value)
296
+ });
297
+ }
298
+ } catch (err) {
299
+ _didIteratorError3 = true;
300
+ _iteratorError3 = err;
301
+ } finally {
302
+ try {
303
+ if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
304
+ _iterator3.return();
305
+ }
306
+ } finally {
307
+ if (_didIteratorError3) {
308
+ throw _iteratorError3;
309
+ }
310
+ }
311
+ }
312
+ var retainedLeafKeys = new Set(blockedLeafKeys);
313
+ var _iteratorNormalCompletion4 = true, _didIteratorError4 = false, _iteratorError4 = void 0;
314
+ try {
315
+ for (var _iterator4 = styleEntries[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
316
+ var e = _step4.value;
317
+ if (e.cls === null && isConvertibleStyleProp(e.fullProp)) {
318
+ var _iteratorNormalCompletion5 = true, _didIteratorError5 = false, _iteratorError5 = void 0;
319
+ try {
320
+ for (var _iterator5 = leafKeysOfProp(e.fullProp)[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
321
+ var k1 = _step5.value;
322
+ retainedLeafKeys.add(k1);
323
+ }
324
+ } catch (err) {
325
+ _didIteratorError5 = true;
326
+ _iteratorError5 = err;
327
+ } finally {
328
+ try {
329
+ if (!_iteratorNormalCompletion5 && _iterator5.return != null) {
330
+ _iterator5.return();
331
+ }
332
+ } finally {
333
+ if (_didIteratorError5) {
334
+ throw _iteratorError5;
335
+ }
336
+ }
337
+ }
338
+ }
339
+ }
340
+ } catch (err) {
341
+ _didIteratorError4 = true;
342
+ _iteratorError4 = err;
343
+ } finally {
344
+ try {
345
+ if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
346
+ _iterator4.return();
347
+ }
348
+ } finally {
349
+ if (_didIteratorError4) {
350
+ throw _iteratorError4;
351
+ }
352
+ }
353
+ }
354
+ var _iteratorNormalCompletion6 = true, _didIteratorError6 = false, _iteratorError6 = void 0;
355
+ try {
356
+ for (var _iterator6 = implicitClasses[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
357
+ var c = _step6.value;
358
+ if (!overlapsSet(leafKeysOfClassToken(c), retainedLeafKeys)) classes.push(c);
359
+ }
360
+ } catch (err) {
361
+ _didIteratorError6 = true;
362
+ _iteratorError6 = err;
363
+ } finally {
364
+ try {
365
+ if (!_iteratorNormalCompletion6 && _iterator6.return != null) {
366
+ _iterator6.return();
367
+ }
368
+ } finally {
369
+ if (_didIteratorError6) {
370
+ throw _iteratorError6;
371
+ }
372
+ }
373
+ }
374
+ var _iteratorNormalCompletion7 = true, _didIteratorError7 = false, _iteratorError7 = void 0;
375
+ try {
376
+ for (var _iterator7 = styleEntries[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) {
377
+ var e1 = _step7.value;
378
+ if (e1.cls !== null && !overlapsSet(leafKeysOfProp(e1.fullProp), retainedLeafKeys)) {
379
+ classes.push(e1.cls);
380
+ } else {
381
+ keptAttrs.push(e1.attr);
382
+ }
383
+ }
384
+ } catch (err) {
385
+ _didIteratorError7 = true;
386
+ _iteratorError7 = err;
387
+ } finally {
388
+ try {
389
+ if (!_iteratorNormalCompletion7 && _iterator7.return != null) {
390
+ _iterator7.return();
391
+ }
392
+ } finally {
393
+ if (_didIteratorError7) {
394
+ throw _iteratorError7;
395
+ }
396
+ }
397
+ }
398
+ if (classes.length > 0) {
399
+ var classStr = classes.join(" ");
400
+ if (existingClassName) {
401
+ var existingVal = getStringValue(existingClassName.value);
402
+ if (existingVal !== null) {
403
+ existingClassName.value = t.stringLiteral(existingVal ? `${classStr} ${existingVal}` : classStr);
404
+ keptAttrs.unshift(existingClassName);
405
+ } else if (t.isJSXExpressionContainer(existingClassName.value) && !t.isJSXEmptyExpression(existingClassName.value.expression)) {
406
+ var expr = existingClassName.value.expression;
407
+ existingClassName.value = t.jsxExpressionContainer(t.templateLiteral([t.templateElement({
408
+ raw: `${classStr} `,
409
+ cooked: `${classStr} `
410
+ }, false), t.templateElement({
411
+ raw: "",
412
+ cooked: ""
413
+ }, true)], [expr]));
414
+ keptAttrs.unshift(existingClassName);
415
+ } else {
416
+ keptAttrs.unshift(t.jsxAttribute(t.jsxIdentifier("className"), t.stringLiteral(classStr)));
417
+ }
418
+ } else {
419
+ keptAttrs.unshift(t.jsxAttribute(t.jsxIdentifier("className"), t.stringLiteral(classStr)));
420
+ }
421
+ } else if (existingClassName) {
422
+ keptAttrs.unshift(existingClassName);
423
+ }
424
+ node.attributes = keptAttrs;
425
+ if (classes.length > 0) didTransform = true;
426
+ if (renameComponents && isSimpleKnown && isPlainIdentifier) {
427
+ var tag = componentToTag[componentName];
428
+ node.name = t.jsxIdentifier(tag);
429
+ var parent = path.parent;
430
+ if (t.isJSXElement(parent) && parent.closingElement) {
431
+ parent.closingElement.name = t.jsxIdentifier(tag);
432
+ }
433
+ didTransform = true;
434
+ }
435
+ } });
436
+ if (!didTransform) return source;
437
+ var output = generate(ast, {
438
+ retainLines: true,
439
+ concise: false
440
+ });
441
+ return output.code;
442
+ }
443
+ var knownCompoundComponents = /* @__PURE__ */ new Set([
444
+ "Sheet.Frame",
445
+ "Sheet.Overlay",
446
+ "Sheet.Handle",
447
+ "Sheet.ScrollView",
448
+ "Sheet.Container",
449
+ "Dialog.Content",
450
+ "Dialog.Overlay",
451
+ "Popover.Content",
452
+ "Tabs.Tab"
453
+ ]);
454
+ function isTamaguiSource(source) {
455
+ return source === "tamagui" || source.startsWith("@tamagui/");
456
+ }
457
+ function resolveTamaguiComponent(path, ctx) {
458
+ var _path_scope_getBinding, _path_scope;
459
+ var nameNode = path.node.name;
460
+ var baseName;
461
+ var memberChain = [];
462
+ var isPlainIdentifier = t.isJSXIdentifier(nameNode);
463
+ if (t.isJSXIdentifier(nameNode)) {
464
+ baseName = nameNode.name;
465
+ } else if (t.isJSXMemberExpression(nameNode)) {
466
+ var parts = [];
467
+ var cur = nameNode;
468
+ while (t.isJSXMemberExpression(cur)) {
469
+ parts.unshift(cur.property.name);
470
+ cur = cur.object;
471
+ }
472
+ if (!t.isJSXIdentifier(cur)) return null;
473
+ baseName = cur.name;
474
+ memberChain = parts;
475
+ } else {
476
+ return null;
477
+ }
478
+ var binding = (_path_scope = path.scope) === null || _path_scope === void 0 ? void 0 : (_path_scope_getBinding = _path_scope.getBinding) === null || _path_scope_getBinding === void 0 ? void 0 : _path_scope_getBinding.call(_path_scope, baseName);
479
+ var tamaguiBase;
480
+ if (binding) {
481
+ var bnode = binding.path.node;
482
+ if (t.isImportSpecifier(bnode) || t.isImportDefaultSpecifier(bnode) || t.isImportNamespaceSpecifier(bnode)) {
483
+ var decl = binding.path.parent;
484
+ var source = t.isImportDeclaration(decl) ? String(decl.source.value) : "";
485
+ if (!isTamaguiSource(source)) return null;
486
+ if (t.isImportNamespaceSpecifier(bnode)) {
487
+ if (memberChain.length === 0) return null;
488
+ tamaguiBase = memberChain[0];
489
+ memberChain = memberChain.slice(1);
490
+ } else if (t.isImportSpecifier(bnode)) {
491
+ var imported = bnode.imported;
492
+ tamaguiBase = t.isIdentifier(imported) ? imported.name : String(imported.value);
493
+ } else {
494
+ return null;
495
+ }
496
+ } else {
497
+ return null;
498
+ }
499
+ } else {
500
+ tamaguiBase = baseName;
501
+ }
502
+ var name = memberChain.length ? [tamaguiBase, ...memberChain].join(".") : tamaguiBase;
503
+ var isSimpleKnown = memberChain.length === 0 && name in componentToTag;
504
+ if (!isSimpleKnown && !knownCompoundComponents.has(name) && !ctx.componentAllow.has(name)) {
505
+ return null;
506
+ }
507
+ return {
508
+ name,
509
+ isSimpleKnown,
510
+ isPlainIdentifier
511
+ };
512
+ }
513
+ function classPrefixOf(token) {
514
+ var noMod = token.slice(token.lastIndexOf(":") + 1);
515
+ var core = noMod[0] === "-" ? noMod.slice(1) : noMod;
516
+ var dash = core.indexOf("-");
517
+ return dash === -1 ? core : core.slice(0, dash);
518
+ }
519
+ var leafExpansion = {
520
+ padding: [
521
+ "paddingTop",
522
+ "paddingRight",
523
+ "paddingBottom",
524
+ "paddingLeft"
525
+ ],
526
+ paddingHorizontal: ["paddingLeft", "paddingRight"],
527
+ paddingVertical: ["paddingTop", "paddingBottom"],
528
+ margin: [
529
+ "marginTop",
530
+ "marginRight",
531
+ "marginBottom",
532
+ "marginLeft"
533
+ ],
534
+ marginHorizontal: ["marginLeft", "marginRight"],
535
+ marginVertical: ["marginTop", "marginBottom"],
536
+ inset: [
537
+ "top",
538
+ "right",
539
+ "bottom",
540
+ "left"
541
+ ],
542
+ gap: [
543
+ "gap",
544
+ "rowGap",
545
+ "columnGap"
546
+ ],
547
+ borderWidth: [
548
+ "borderTopWidth",
549
+ "borderRightWidth",
550
+ "borderBottomWidth",
551
+ "borderLeftWidth"
552
+ ],
553
+ borderColor: [
554
+ "borderTopColor",
555
+ "borderRightColor",
556
+ "borderBottomColor",
557
+ "borderLeftColor"
558
+ ],
559
+ borderRadius: [
560
+ "borderTopLeftRadius",
561
+ "borderTopRightRadius",
562
+ "borderBottomLeftRadius",
563
+ "borderBottomRightRadius"
564
+ ]
565
+ };
566
+ function leafKeysOfProp(fullProp) {
567
+ var _leafExpansion_fullProp;
568
+ return (_leafExpansion_fullProp = leafExpansion[fullProp]) !== null && _leafExpansion_fullProp !== void 0 ? _leafExpansion_fullProp : [fullProp];
569
+ }
570
+ var prefixToProp = (function() {
571
+ var m = {};
572
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
573
+ try {
574
+ for (var _iterator = Object.entries(propToTailwindPrefix)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
575
+ var [prop, prefix] = _step.value;
576
+ if (prefix && !(prefix in m)) m[prefix] = prop;
577
+ }
578
+ } catch (err) {
579
+ _didIteratorError = true;
580
+ _iteratorError = err;
581
+ } finally {
582
+ try {
583
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
584
+ _iterator.return();
585
+ }
586
+ } finally {
587
+ if (_didIteratorError) {
588
+ throw _iteratorError;
589
+ }
590
+ }
591
+ }
592
+ return m;
593
+ })();
594
+ function leafKeysOfClassToken(token) {
595
+ var prefix = classPrefixOf(token);
596
+ var _prefixToProp_prefix;
597
+ return leafKeysOfProp((_prefixToProp_prefix = prefixToProp[prefix]) !== null && _prefixToProp_prefix !== void 0 ? _prefixToProp_prefix : prefix);
598
+ }
599
+ function overlapsSet(keys, set) {
600
+ return keys.some(function(k) {
601
+ return set.has(k);
602
+ });
603
+ }
604
+ function isConvertibleStyleProp(fullProp) {
605
+ return propToTailwindPrefix[fullProp] !== void 0 || fullProp in standaloneValueProps;
606
+ }
607
+ function propValueToClass(ctx, propName, value) {
608
+ var fullProp = resolveShorthand(ctx, propName);
609
+ if (propToTailwindPrefix[fullProp] === void 0) return null;
610
+ var strVal = getStringValue(value);
611
+ var numVal = getNumericValue(value);
612
+ if (strVal !== null) {
613
+ var parsed = parseValue(strVal, ctx.modifierRegistry);
614
+ if (!parsed.ok) return null;
615
+ var classes = [];
616
+ if (parsed.value.base !== null) {
617
+ var base = payloadToClass(ctx, fullProp, parsed.value.base, []);
618
+ if (base === null) return null;
619
+ classes.push(base);
620
+ }
621
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
622
+ try {
623
+ for (var _iterator = parsed.value.clauses[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
624
+ var clause = _step.value;
625
+ var conditional = payloadToClass(ctx, fullProp, clause.payload, clause.modifiers);
626
+ if (conditional === null) return null;
627
+ classes.push(conditional);
628
+ }
629
+ } catch (err) {
630
+ _didIteratorError = true;
631
+ _iteratorError = err;
632
+ } finally {
633
+ try {
634
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
635
+ _iterator.return();
636
+ }
637
+ } finally {
638
+ if (_didIteratorError) {
639
+ throw _iteratorError;
640
+ }
641
+ }
642
+ }
643
+ return classes.length ? classes.join(" ") : null;
644
+ }
645
+ if (numVal === null) return null;
646
+ var formatted = formatNumericValue(fullProp, numVal);
647
+ if (formatted === null) return null;
648
+ return formatCandidate({
649
+ prop: fullProp,
650
+ value: formatted.value,
651
+ valueKind: formatted.valueKind,
652
+ modifiers: void 0
653
+ }, ctx.grammarConfig);
654
+ }
655
+ function payloadToClass(ctx, fullProp, payload, modifiers) {
656
+ var _standaloneValueProps_fullProp;
657
+ var formatted;
658
+ if ((_standaloneValueProps_fullProp = standaloneValueProps[fullProp]) === null || _standaloneValueProps_fullProp === void 0 ? void 0 : _standaloneValueProps_fullProp[payload]) {
659
+ formatted = {
660
+ value: payload,
661
+ valueKind: "enum"
662
+ };
663
+ } else {
664
+ formatted = formatStringValue(ctx, fullProp, payload);
665
+ if (formatted === null && /^-?\d+(?:\.\d+)?$/.test(payload)) {
666
+ var _ctx_grammarConfig_tokenNames;
667
+ var category = getTokenCategory(fullProp);
668
+ if (!category || ((_ctx_grammarConfig_tokenNames = ctx.grammarConfig.tokenNames) === null || _ctx_grammarConfig_tokenNames === void 0 ? void 0 : _ctx_grammarConfig_tokenNames[category]) !== void 0) {
669
+ formatted = formatNumericValue(fullProp, Number(payload));
670
+ }
671
+ }
672
+ }
673
+ if (formatted === null) return null;
674
+ return formatCandidate({
675
+ prop: fullProp,
676
+ value: formatted.value,
677
+ valueKind: formatted.valueKind,
678
+ modifiers: modifiers.length ? modifiers : void 0
679
+ }, ctx.grammarConfig);
680
+ }
681
+ function getStringValue(value) {
682
+ if (!value) return null;
683
+ if (t.isStringLiteral(value)) return value.value;
684
+ if (t.isJSXExpressionContainer(value) && t.isStringLiteral(value.expression)) {
685
+ return value.expression.value;
686
+ }
687
+ if (t.isJSXExpressionContainer(value) && t.isTemplateLiteral(value.expression)) {
688
+ if (value.expression.expressions.length === 0 && value.expression.quasis.length === 1) {
689
+ return value.expression.quasis[0].value.raw;
690
+ }
691
+ }
692
+ return null;
693
+ }
694
+ function getNumericValue(value) {
695
+ if (!value) return null;
696
+ if (t.isJSXExpressionContainer(value)) {
697
+ if (t.isNumericLiteral(value.expression)) return value.expression.value;
698
+ if (t.isUnaryExpression(value.expression) && value.expression.operator === "-" && t.isNumericLiteral(value.expression.argument)) {
699
+ return -value.expression.argument.value;
700
+ }
701
+ }
702
+ return null;
703
+ }
704
+ function resolveShorthand(ctx, name) {
705
+ return ctx.shorthands[name] || name;
706
+ }
707
+ function hasConfiguredName(names, value) {
708
+ if (!names) return false;
709
+ if (Array.isArray(names)) return names.includes(value);
710
+ if (_instanceof(names, Set)) return names.has(value);
711
+ return Object.prototype.hasOwnProperty.call(names, value);
712
+ }
713
+ function formatStringValue(ctx, prop, value) {
714
+ var _ctx_grammarConfig_tokenNames;
715
+ var category = getTokenCategory(prop);
716
+ if (prop !== "fontWeight" && category && hasConfiguredName((_ctx_grammarConfig_tokenNames = ctx.grammarConfig.tokenNames) === null || _ctx_grammarConfig_tokenNames === void 0 ? void 0 : _ctx_grammarConfig_tokenNames[category], value)) {
717
+ if (category === "color") {
718
+ var mapped = getV6ThemeName(value);
719
+ return mapped ? {
720
+ value: mapped,
721
+ valueKind: "token"
722
+ } : null;
723
+ }
724
+ return {
725
+ value,
726
+ valueKind: "token"
727
+ };
728
+ }
729
+ if (prop === "fontWeight") {
730
+ return fontWeightNames[value] ? {
731
+ value,
732
+ valueKind: "enum"
733
+ } : null;
734
+ }
735
+ if (prop === "zIndex" && /^\d+$/.test(value)) {
736
+ return {
737
+ value,
738
+ valueKind: "convenience"
739
+ };
740
+ }
741
+ if (/^-?\d+(\.\d+)?$/.test(value)) return null;
742
+ if (value.endsWith("%")) {
743
+ var exact = {
744
+ "100%": "full",
745
+ "50%": "1/2",
746
+ "25%": "1/4",
747
+ "75%": "3/4"
748
+ };
749
+ if (getTokenCategory(prop) === "size" && exact[value]) {
750
+ return {
751
+ value: exact[value],
752
+ valueKind: "convenience"
753
+ };
754
+ }
755
+ return {
756
+ value,
757
+ valueKind: "arbitrary"
758
+ };
759
+ }
760
+ if (value === "auto" && getTokenCategory(prop) === "size") {
761
+ return {
762
+ value,
763
+ valueKind: "convenience"
764
+ };
765
+ }
766
+ if (prop === "fontFamily") return {
767
+ value,
768
+ valueKind: "arbitrary"
769
+ };
770
+ if (value.includes("(") || value.includes(" ") || value.includes("_") || value.startsWith("#") || value.startsWith("-") || /^[\d.]+[a-z%]/i.test(value)) {
771
+ return {
772
+ value,
773
+ valueKind: "arbitrary"
774
+ };
775
+ }
776
+ return {
777
+ value,
778
+ valueKind: "arbitrary"
779
+ };
780
+ }
781
+ var pxLengthProps = /* @__PURE__ */ new Set([
782
+ "width",
783
+ "height",
784
+ "minWidth",
785
+ "maxWidth",
786
+ "minHeight",
787
+ "maxHeight",
788
+ "flexBasis",
789
+ "padding",
790
+ "paddingTop",
791
+ "paddingRight",
792
+ "paddingBottom",
793
+ "paddingLeft",
794
+ "paddingHorizontal",
795
+ "paddingVertical",
796
+ "margin",
797
+ "marginTop",
798
+ "marginRight",
799
+ "marginBottom",
800
+ "marginLeft",
801
+ "marginHorizontal",
802
+ "marginVertical",
803
+ "gap",
804
+ "rowGap",
805
+ "columnGap",
806
+ "top",
807
+ "right",
808
+ "bottom",
809
+ "left",
810
+ "inset",
811
+ "borderRadius",
812
+ "borderTopLeftRadius",
813
+ "borderTopRightRadius",
814
+ "borderBottomLeftRadius",
815
+ "borderBottomRightRadius",
816
+ "fontSize",
817
+ "letterSpacing",
818
+ "lineHeight"
819
+ ]);
820
+ function formatNumericValue(prop, value) {
821
+ if (prop === "opacity") {
822
+ var pct = value * 100;
823
+ return Number.isInteger(pct) ? {
824
+ value: String(pct),
825
+ valueKind: "convenience"
826
+ } : {
827
+ value: String(value),
828
+ valueKind: "arbitrary"
829
+ };
830
+ }
831
+ if (prop === "aspectRatio") return {
832
+ value: String(value),
833
+ valueKind: "arbitrary"
834
+ };
835
+ if (prop === "scale" || prop === "scaleX" || prop === "scaleY") {
836
+ if (value === 0) return {
837
+ value: "0",
838
+ valueKind: "convenience"
839
+ };
840
+ if (value === 1) return {
841
+ value: "100",
842
+ valueKind: "convenience"
843
+ };
844
+ return {
845
+ value: String(value),
846
+ valueKind: "arbitrary"
847
+ };
848
+ }
849
+ if (prop === "flex") {
850
+ return value === 1 ? {
851
+ value: "1",
852
+ valueKind: "convenience"
853
+ } : {
854
+ value: String(value),
855
+ valueKind: "arbitrary"
856
+ };
857
+ }
858
+ if (prop === "flexGrow" || prop === "flexShrink") {
859
+ return {
860
+ value: String(value),
861
+ valueKind: "arbitrary"
862
+ };
863
+ }
864
+ if (prop === "zIndex") {
865
+ return Number.isInteger(value) && value >= 0 ? {
866
+ value: String(value),
867
+ valueKind: "convenience"
868
+ } : {
869
+ value: String(value),
870
+ valueKind: "arbitrary"
871
+ };
872
+ }
873
+ if (prop === "fontWeight") {
874
+ return fontWeightNames[String(value)] ? {
875
+ value: String(value),
876
+ valueKind: "enum"
877
+ } : null;
878
+ }
879
+ if (prop === "rotate") return null;
880
+ if (prop === "x" || prop === "y") {
881
+ return {
882
+ value: `${value}px`,
883
+ valueKind: "arbitrary"
884
+ };
885
+ }
886
+ if (prop.includes("Width") && prop.startsWith("border")) {
887
+ return {
888
+ value: `${value}px`,
889
+ valueKind: "arbitrary"
890
+ };
891
+ }
892
+ if (pxLengthProps.has(prop)) {
893
+ return {
894
+ value: `${value}px`,
895
+ valueKind: "arbitrary"
896
+ };
897
+ }
898
+ return null;
899
+ }
900
+
901
+ export { findParseError, tamaguiToTailwind };
902
+ //# sourceMappingURL=transform.native.js.map