@tamagui/to-tailwind 3.0.0-beta.924.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/transform.cjs +99 -10
- package/dist/cjs/transform.native.cjs +120 -19
- package/dist/cjs/transform.native.js +120 -19
- package/dist/cjs/transform.native.js.map +1 -1
- package/dist/esm/transform.mjs +100 -11
- package/dist/esm/transform.mjs.map +1 -1
- package/dist/esm/transform.native.js +121 -20
- package/dist/esm/transform.native.js.map +1 -1
- package/package.json +5 -4
- package/src/transform.ts +140 -8
package/dist/cjs/transform.cjs
CHANGED
|
@@ -100,6 +100,12 @@ function createTransformGrammarConfig(options, mediaKeys, shorthands) {
|
|
|
100
100
|
tokenNames[category] = names;
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
|
+
for (const group in import_tooling.propTokenGroupFallbacks) {
|
|
104
|
+
const own = options.tokens?.[group];
|
|
105
|
+
const names = own ? /* @__PURE__ */ new Set() : tokenNames[import_tooling.propTokenGroupFallbacks[group]];
|
|
106
|
+
if (own) addConfigNames(names, own);
|
|
107
|
+
if (names) tokenNames[group] = names;
|
|
108
|
+
}
|
|
103
109
|
if (options.fonts) {
|
|
104
110
|
tokenNames.fontFamily ||= /* @__PURE__ */ new Set();
|
|
105
111
|
tokenNames.fontSize ||= /* @__PURE__ */ new Set();
|
|
@@ -161,7 +167,8 @@ function tamaguiToTailwind(source, options = {}) {
|
|
|
161
167
|
componentAllow: new Set(options.components ?? []),
|
|
162
168
|
shorthands,
|
|
163
169
|
grammarConfig,
|
|
164
|
-
modifierRegistry: (0, import_tooling.createModifierRegistry)(grammarConfig).registry
|
|
170
|
+
modifierRegistry: (0, import_tooling.createModifierRegistry)(grammarConfig).registry,
|
|
171
|
+
rewriteImports: options.rewriteImports === true
|
|
165
172
|
};
|
|
166
173
|
let ast;
|
|
167
174
|
try {
|
|
@@ -281,9 +288,12 @@ function tamaguiToTailwind(source, options = {}) {
|
|
|
281
288
|
didTransform = true;
|
|
282
289
|
}
|
|
283
290
|
} });
|
|
291
|
+
if (options.rewriteImports && rewriteTailwindFrontendImports(ast)) {
|
|
292
|
+
didTransform = true;
|
|
293
|
+
}
|
|
284
294
|
if (!didTransform) return source;
|
|
285
295
|
const output = generate(ast, {
|
|
286
|
-
retainLines:
|
|
296
|
+
retainLines: options.retainLines !== false,
|
|
287
297
|
concise: false
|
|
288
298
|
});
|
|
289
299
|
return output.code;
|
|
@@ -299,6 +309,11 @@ const knownCompoundComponents = /* @__PURE__ */ new Set([
|
|
|
299
309
|
"Popover.Content",
|
|
300
310
|
"Tabs.Tab"
|
|
301
311
|
]);
|
|
312
|
+
const tailwindFrontendImports = /* @__PURE__ */ new Set([
|
|
313
|
+
"html",
|
|
314
|
+
"View",
|
|
315
|
+
"Text"
|
|
316
|
+
]);
|
|
302
317
|
function isTamaguiSource(source) {
|
|
303
318
|
return source === "tamagui" || source.startsWith("@tamagui/");
|
|
304
319
|
}
|
|
@@ -340,15 +355,20 @@ function resolveTamaguiComponent(path, ctx) {
|
|
|
340
355
|
} else {
|
|
341
356
|
return null;
|
|
342
357
|
}
|
|
358
|
+
if (ctx.rewriteImports && source !== "@tamagui/tailwind" && (source !== "tamagui" && source !== "@tamagui/core" || !tailwindFrontendImports.has(tamaguiBase) || !isTailwindFrontendOnlyBinding(binding, tamaguiBase))) {
|
|
359
|
+
return null;
|
|
360
|
+
}
|
|
343
361
|
} else {
|
|
344
362
|
return null;
|
|
345
363
|
}
|
|
346
364
|
} else {
|
|
347
365
|
tamaguiBase = baseName;
|
|
366
|
+
if (ctx.rewriteImports && !tailwindFrontendImports.has(tamaguiBase)) return null;
|
|
348
367
|
}
|
|
349
368
|
const name = memberChain.length ? [tamaguiBase, ...memberChain].join(".") : tamaguiBase;
|
|
350
369
|
const isSimpleKnown = memberChain.length === 0 && name in import_componentToTag.componentToTag;
|
|
351
|
-
|
|
370
|
+
const isHTMLPrimitive = tamaguiBase === "html" && memberChain.length === 1;
|
|
371
|
+
if (!isSimpleKnown && !isHTMLPrimitive && !knownCompoundComponents.has(name) && !ctx.componentAllow.has(name)) {
|
|
352
372
|
return null;
|
|
353
373
|
}
|
|
354
374
|
return {
|
|
@@ -357,6 +377,47 @@ function resolveTamaguiComponent(path, ctx) {
|
|
|
357
377
|
isPlainIdentifier
|
|
358
378
|
};
|
|
359
379
|
}
|
|
380
|
+
function isTailwindFrontendOnlyBinding(binding, importedName) {
|
|
381
|
+
return binding.referencePaths.every((referencePath) => {
|
|
382
|
+
const parent = referencePath.parent;
|
|
383
|
+
if (importedName === "html") {
|
|
384
|
+
return t.isJSXMemberExpression(parent) && parent.object === referencePath.node && (t.isJSXOpeningElement(referencePath.parentPath?.parent) || t.isJSXClosingElement(referencePath.parentPath?.parent));
|
|
385
|
+
}
|
|
386
|
+
return t.isJSXIdentifier(referencePath.node) && (t.isJSXOpeningElement(parent) || t.isJSXClosingElement(parent)) && parent.name === referencePath.node;
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
function rewriteTailwindFrontendImports(ast) {
|
|
390
|
+
let changed = false;
|
|
391
|
+
traverse(ast, { ImportDeclaration(path) {
|
|
392
|
+
const source = String(path.node.source.value);
|
|
393
|
+
if (source !== "tamagui" && source !== "@tamagui/core") return;
|
|
394
|
+
if (path.node.importKind === "type") return;
|
|
395
|
+
const moved = [];
|
|
396
|
+
const retained = [];
|
|
397
|
+
for (const specifier of path.node.specifiers) {
|
|
398
|
+
if (!t.isImportSpecifier(specifier) || specifier.importKind === "type") {
|
|
399
|
+
retained.push(specifier);
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
const importedName = t.isIdentifier(specifier.imported) ? specifier.imported.name : String(specifier.imported.value);
|
|
403
|
+
const binding = path.scope.getBinding(specifier.local.name);
|
|
404
|
+
if (!tailwindFrontendImports.has(importedName) || !binding || !isTailwindFrontendOnlyBinding(binding, importedName)) {
|
|
405
|
+
retained.push(specifier);
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
moved.push(specifier);
|
|
409
|
+
}
|
|
410
|
+
if (!moved.length) return;
|
|
411
|
+
changed = true;
|
|
412
|
+
if (!retained.length) {
|
|
413
|
+
path.node.source = t.stringLiteral("@tamagui/tailwind");
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
path.node.specifiers = retained;
|
|
417
|
+
path.insertAfter(t.importDeclaration(moved, t.stringLiteral("@tamagui/tailwind")));
|
|
418
|
+
} });
|
|
419
|
+
return changed;
|
|
420
|
+
}
|
|
360
421
|
function classPrefixOf(token) {
|
|
361
422
|
const noMod = token.slice(token.lastIndexOf(":") + 1);
|
|
362
423
|
const core = noMod[0] === "-" ? noMod.slice(1) : noMod;
|
|
@@ -544,7 +605,12 @@ function formatStringValue(ctx, prop, value) {
|
|
|
544
605
|
valueKind: "convenience"
|
|
545
606
|
};
|
|
546
607
|
}
|
|
547
|
-
if (/^-?\d+(\.\d+)?$/.test(value))
|
|
608
|
+
if (/^-?\d+(\.\d+)?$/.test(value)) {
|
|
609
|
+
return prop === "lineHeight" ? {
|
|
610
|
+
value,
|
|
611
|
+
valueKind: "arbitrary"
|
|
612
|
+
} : null;
|
|
613
|
+
}
|
|
548
614
|
if (value.endsWith("%")) {
|
|
549
615
|
const exact = {
|
|
550
616
|
"100%": "full",
|
|
@@ -597,6 +663,12 @@ const pxLengthProps = /* @__PURE__ */ new Set([
|
|
|
597
663
|
"paddingRight",
|
|
598
664
|
"paddingBottom",
|
|
599
665
|
"paddingLeft",
|
|
666
|
+
"paddingStart",
|
|
667
|
+
"paddingEnd",
|
|
668
|
+
"paddingInlineStart",
|
|
669
|
+
"paddingInlineEnd",
|
|
670
|
+
"paddingBlockStart",
|
|
671
|
+
"paddingBlockEnd",
|
|
600
672
|
"paddingHorizontal",
|
|
601
673
|
"paddingVertical",
|
|
602
674
|
"margin",
|
|
@@ -604,6 +676,12 @@ const pxLengthProps = /* @__PURE__ */ new Set([
|
|
|
604
676
|
"marginRight",
|
|
605
677
|
"marginBottom",
|
|
606
678
|
"marginLeft",
|
|
679
|
+
"marginStart",
|
|
680
|
+
"marginEnd",
|
|
681
|
+
"marginInlineStart",
|
|
682
|
+
"marginInlineEnd",
|
|
683
|
+
"marginBlockStart",
|
|
684
|
+
"marginBlockEnd",
|
|
607
685
|
"marginHorizontal",
|
|
608
686
|
"marginVertical",
|
|
609
687
|
"gap",
|
|
@@ -614,14 +692,23 @@ const pxLengthProps = /* @__PURE__ */ new Set([
|
|
|
614
692
|
"bottom",
|
|
615
693
|
"left",
|
|
616
694
|
"inset",
|
|
695
|
+
"insetInlineStart",
|
|
696
|
+
"insetInlineEnd",
|
|
617
697
|
"borderRadius",
|
|
618
698
|
"borderTopLeftRadius",
|
|
619
699
|
"borderTopRightRadius",
|
|
620
700
|
"borderBottomLeftRadius",
|
|
621
701
|
"borderBottomRightRadius",
|
|
702
|
+
"borderTopStartRadius",
|
|
703
|
+
"borderTopEndRadius",
|
|
704
|
+
"borderBottomStartRadius",
|
|
705
|
+
"borderBottomEndRadius",
|
|
706
|
+
"borderStartStartRadius",
|
|
707
|
+
"borderStartEndRadius",
|
|
708
|
+
"borderEndStartRadius",
|
|
709
|
+
"borderEndEndRadius",
|
|
622
710
|
"fontSize",
|
|
623
|
-
"letterSpacing"
|
|
624
|
-
"lineHeight"
|
|
711
|
+
"letterSpacing"
|
|
625
712
|
]);
|
|
626
713
|
function formatNumericValue(prop, value) {
|
|
627
714
|
if (prop === "opacity") {
|
|
@@ -634,10 +721,12 @@ function formatNumericValue(prop, value) {
|
|
|
634
721
|
valueKind: "arbitrary"
|
|
635
722
|
};
|
|
636
723
|
}
|
|
637
|
-
if (prop === "aspectRatio")
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
724
|
+
if (prop === "aspectRatio" || prop === "lineHeight") {
|
|
725
|
+
return {
|
|
726
|
+
value: String(value),
|
|
727
|
+
valueKind: "arbitrary"
|
|
728
|
+
};
|
|
729
|
+
}
|
|
641
730
|
if (prop === "scale" || prop === "scaleX" || prop === "scaleY") {
|
|
642
731
|
if (value === 0) return {
|
|
643
732
|
value: "0",
|
|
@@ -39,13 +39,6 @@ var t = __toESM(require("@babel/types"), 1);
|
|
|
39
39
|
var import_tooling = require("@tamagui/style-grammar/tooling");
|
|
40
40
|
var import_componentToTag = require("./maps/componentToTag.native.js");
|
|
41
41
|
var import_v4 = require("@tamagui/shorthands/v4");
|
|
42
|
-
function _instanceof(left, right) {
|
|
43
|
-
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
44
|
-
return !!right[Symbol.hasInstance](left);
|
|
45
|
-
} else {
|
|
46
|
-
return left instanceof right;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
42
|
var _traverse_default;
|
|
50
43
|
var traverse = (_traverse_default = import_traverse.default.default) !== null && _traverse_default !== void 0 ? _traverse_default : import_traverse.default;
|
|
51
44
|
var _generate_default;
|
|
@@ -63,7 +56,7 @@ function getV6ThemeName(name) {
|
|
|
63
56
|
function namesToSet(names) {
|
|
64
57
|
if (!names) return /* @__PURE__ */ new Set();
|
|
65
58
|
if (Array.isArray(names)) return new Set(names);
|
|
66
|
-
if (
|
|
59
|
+
if (names instanceof Set) return new Set(names);
|
|
67
60
|
return new Set(Object.keys(names));
|
|
68
61
|
}
|
|
69
62
|
function addConfigNames(target, source) {
|
|
@@ -133,6 +126,13 @@ function createTransformGrammarConfig(options, mediaKeys, shorthands) {
|
|
|
133
126
|
}
|
|
134
127
|
}
|
|
135
128
|
}
|
|
129
|
+
for (var group in import_tooling.propTokenGroupFallbacks) {
|
|
130
|
+
var _options_tokens1;
|
|
131
|
+
var own = (_options_tokens1 = options.tokens) === null || _options_tokens1 === void 0 ? void 0 : _options_tokens1[group];
|
|
132
|
+
var names1 = own ? /* @__PURE__ */ new Set() : tokenNames[import_tooling.propTokenGroupFallbacks[group]];
|
|
133
|
+
if (own) addConfigNames(names1, own);
|
|
134
|
+
if (names1) tokenNames[group] = names1;
|
|
135
|
+
}
|
|
136
136
|
if (options.fonts) {
|
|
137
137
|
var _tokenNames, _tokenNames1, _tokenNames2, _tokenNames3, _tokenNames4;
|
|
138
138
|
(_tokenNames = tokenNames).fontFamily || (_tokenNames.fontFamily = /* @__PURE__ */ new Set());
|
|
@@ -200,7 +200,8 @@ function tamaguiToTailwind(source) {
|
|
|
200
200
|
componentAllow: new Set((_options_components = options.components) !== null && _options_components !== void 0 ? _options_components : []),
|
|
201
201
|
shorthands,
|
|
202
202
|
grammarConfig,
|
|
203
|
-
modifierRegistry: (0, import_tooling.createModifierRegistry)(grammarConfig).registry
|
|
203
|
+
modifierRegistry: (0, import_tooling.createModifierRegistry)(grammarConfig).registry,
|
|
204
|
+
rewriteImports: options.rewriteImports === true
|
|
204
205
|
};
|
|
205
206
|
var ast;
|
|
206
207
|
try {
|
|
@@ -466,9 +467,12 @@ function tamaguiToTailwind(source) {
|
|
|
466
467
|
didTransform = true;
|
|
467
468
|
}
|
|
468
469
|
} });
|
|
470
|
+
if (options.rewriteImports && rewriteTailwindFrontendImports(ast)) {
|
|
471
|
+
didTransform = true;
|
|
472
|
+
}
|
|
469
473
|
if (!didTransform) return source;
|
|
470
474
|
var output = generate(ast, {
|
|
471
|
-
retainLines:
|
|
475
|
+
retainLines: options.retainLines !== false,
|
|
472
476
|
concise: false
|
|
473
477
|
});
|
|
474
478
|
return output.code;
|
|
@@ -484,6 +488,11 @@ var knownCompoundComponents = /* @__PURE__ */ new Set([
|
|
|
484
488
|
"Popover.Content",
|
|
485
489
|
"Tabs.Tab"
|
|
486
490
|
]);
|
|
491
|
+
var tailwindFrontendImports = /* @__PURE__ */ new Set([
|
|
492
|
+
"html",
|
|
493
|
+
"View",
|
|
494
|
+
"Text"
|
|
495
|
+
]);
|
|
487
496
|
function isTamaguiSource(source) {
|
|
488
497
|
return source === "tamagui" || source.startsWith("@tamagui/");
|
|
489
498
|
}
|
|
@@ -526,15 +535,20 @@ function resolveTamaguiComponent(path, ctx) {
|
|
|
526
535
|
} else {
|
|
527
536
|
return null;
|
|
528
537
|
}
|
|
538
|
+
if (ctx.rewriteImports && source !== "@tamagui/tailwind" && (source !== "tamagui" && source !== "@tamagui/core" || !tailwindFrontendImports.has(tamaguiBase) || !isTailwindFrontendOnlyBinding(binding, tamaguiBase))) {
|
|
539
|
+
return null;
|
|
540
|
+
}
|
|
529
541
|
} else {
|
|
530
542
|
return null;
|
|
531
543
|
}
|
|
532
544
|
} else {
|
|
533
545
|
tamaguiBase = baseName;
|
|
546
|
+
if (ctx.rewriteImports && !tailwindFrontendImports.has(tamaguiBase)) return null;
|
|
534
547
|
}
|
|
535
548
|
var name = memberChain.length ? [tamaguiBase, ...memberChain].join(".") : tamaguiBase;
|
|
536
549
|
var isSimpleKnown = memberChain.length === 0 && name in import_componentToTag.componentToTag;
|
|
537
|
-
|
|
550
|
+
var isHTMLPrimitive = tamaguiBase === "html" && memberChain.length === 1;
|
|
551
|
+
if (!isSimpleKnown && !isHTMLPrimitive && !knownCompoundComponents.has(name) && !ctx.componentAllow.has(name)) {
|
|
538
552
|
return null;
|
|
539
553
|
}
|
|
540
554
|
return {
|
|
@@ -543,6 +557,65 @@ function resolveTamaguiComponent(path, ctx) {
|
|
|
543
557
|
isPlainIdentifier
|
|
544
558
|
};
|
|
545
559
|
}
|
|
560
|
+
function isTailwindFrontendOnlyBinding(binding, importedName) {
|
|
561
|
+
return binding.referencePaths.every(function(referencePath) {
|
|
562
|
+
var parent = referencePath.parent;
|
|
563
|
+
if (importedName === "html") {
|
|
564
|
+
var _referencePath_parentPath, _referencePath_parentPath1;
|
|
565
|
+
return t.isJSXMemberExpression(parent) && parent.object === referencePath.node && (t.isJSXOpeningElement((_referencePath_parentPath = referencePath.parentPath) === null || _referencePath_parentPath === void 0 ? void 0 : _referencePath_parentPath.parent) || t.isJSXClosingElement((_referencePath_parentPath1 = referencePath.parentPath) === null || _referencePath_parentPath1 === void 0 ? void 0 : _referencePath_parentPath1.parent));
|
|
566
|
+
}
|
|
567
|
+
return t.isJSXIdentifier(referencePath.node) && (t.isJSXOpeningElement(parent) || t.isJSXClosingElement(parent)) && parent.name === referencePath.node;
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
function rewriteTailwindFrontendImports(ast) {
|
|
571
|
+
var changed = false;
|
|
572
|
+
traverse(ast, { ImportDeclaration(path) {
|
|
573
|
+
var source = String(path.node.source.value);
|
|
574
|
+
if (source !== "tamagui" && source !== "@tamagui/core") return;
|
|
575
|
+
if (path.node.importKind === "type") return;
|
|
576
|
+
var moved = [];
|
|
577
|
+
var retained = [];
|
|
578
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
579
|
+
try {
|
|
580
|
+
for (var _iterator = path.node.specifiers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
581
|
+
var specifier = _step.value;
|
|
582
|
+
if (!t.isImportSpecifier(specifier) || specifier.importKind === "type") {
|
|
583
|
+
retained.push(specifier);
|
|
584
|
+
continue;
|
|
585
|
+
}
|
|
586
|
+
var importedName = t.isIdentifier(specifier.imported) ? specifier.imported.name : String(specifier.imported.value);
|
|
587
|
+
var binding = path.scope.getBinding(specifier.local.name);
|
|
588
|
+
if (!tailwindFrontendImports.has(importedName) || !binding || !isTailwindFrontendOnlyBinding(binding, importedName)) {
|
|
589
|
+
retained.push(specifier);
|
|
590
|
+
continue;
|
|
591
|
+
}
|
|
592
|
+
moved.push(specifier);
|
|
593
|
+
}
|
|
594
|
+
} catch (err) {
|
|
595
|
+
_didIteratorError = true;
|
|
596
|
+
_iteratorError = err;
|
|
597
|
+
} finally {
|
|
598
|
+
try {
|
|
599
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
600
|
+
_iterator.return();
|
|
601
|
+
}
|
|
602
|
+
} finally {
|
|
603
|
+
if (_didIteratorError) {
|
|
604
|
+
throw _iteratorError;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
if (!moved.length) return;
|
|
609
|
+
changed = true;
|
|
610
|
+
if (!retained.length) {
|
|
611
|
+
path.node.source = t.stringLiteral("@tamagui/tailwind");
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
path.node.specifiers = retained;
|
|
615
|
+
path.insertAfter(t.importDeclaration(moved, t.stringLiteral("@tamagui/tailwind")));
|
|
616
|
+
} });
|
|
617
|
+
return changed;
|
|
618
|
+
}
|
|
546
619
|
function classPrefixOf(token) {
|
|
547
620
|
var noMod = token.slice(token.lastIndexOf(":") + 1);
|
|
548
621
|
var core = noMod[0] === "-" ? noMod.slice(1) : noMod;
|
|
@@ -740,7 +813,7 @@ function resolveShorthand(ctx, name) {
|
|
|
740
813
|
function hasConfiguredName(names, value) {
|
|
741
814
|
if (!names) return false;
|
|
742
815
|
if (Array.isArray(names)) return names.includes(value);
|
|
743
|
-
if (
|
|
816
|
+
if (names instanceof Set) return names.has(value);
|
|
744
817
|
return value in names;
|
|
745
818
|
}
|
|
746
819
|
function formatStringValue(ctx, prop, value) {
|
|
@@ -771,7 +844,12 @@ function formatStringValue(ctx, prop, value) {
|
|
|
771
844
|
valueKind: "convenience"
|
|
772
845
|
};
|
|
773
846
|
}
|
|
774
|
-
if (/^-?\d+(\.\d+)?$/.test(value))
|
|
847
|
+
if (/^-?\d+(\.\d+)?$/.test(value)) {
|
|
848
|
+
return prop === "lineHeight" ? {
|
|
849
|
+
value,
|
|
850
|
+
valueKind: "arbitrary"
|
|
851
|
+
} : null;
|
|
852
|
+
}
|
|
775
853
|
if (value.endsWith("%")) {
|
|
776
854
|
var exact = {
|
|
777
855
|
"100%": "full",
|
|
@@ -824,6 +902,12 @@ var pxLengthProps = /* @__PURE__ */ new Set([
|
|
|
824
902
|
"paddingRight",
|
|
825
903
|
"paddingBottom",
|
|
826
904
|
"paddingLeft",
|
|
905
|
+
"paddingStart",
|
|
906
|
+
"paddingEnd",
|
|
907
|
+
"paddingInlineStart",
|
|
908
|
+
"paddingInlineEnd",
|
|
909
|
+
"paddingBlockStart",
|
|
910
|
+
"paddingBlockEnd",
|
|
827
911
|
"paddingHorizontal",
|
|
828
912
|
"paddingVertical",
|
|
829
913
|
"margin",
|
|
@@ -831,6 +915,12 @@ var pxLengthProps = /* @__PURE__ */ new Set([
|
|
|
831
915
|
"marginRight",
|
|
832
916
|
"marginBottom",
|
|
833
917
|
"marginLeft",
|
|
918
|
+
"marginStart",
|
|
919
|
+
"marginEnd",
|
|
920
|
+
"marginInlineStart",
|
|
921
|
+
"marginInlineEnd",
|
|
922
|
+
"marginBlockStart",
|
|
923
|
+
"marginBlockEnd",
|
|
834
924
|
"marginHorizontal",
|
|
835
925
|
"marginVertical",
|
|
836
926
|
"gap",
|
|
@@ -841,14 +931,23 @@ var pxLengthProps = /* @__PURE__ */ new Set([
|
|
|
841
931
|
"bottom",
|
|
842
932
|
"left",
|
|
843
933
|
"inset",
|
|
934
|
+
"insetInlineStart",
|
|
935
|
+
"insetInlineEnd",
|
|
844
936
|
"borderRadius",
|
|
845
937
|
"borderTopLeftRadius",
|
|
846
938
|
"borderTopRightRadius",
|
|
847
939
|
"borderBottomLeftRadius",
|
|
848
940
|
"borderBottomRightRadius",
|
|
941
|
+
"borderTopStartRadius",
|
|
942
|
+
"borderTopEndRadius",
|
|
943
|
+
"borderBottomStartRadius",
|
|
944
|
+
"borderBottomEndRadius",
|
|
945
|
+
"borderStartStartRadius",
|
|
946
|
+
"borderStartEndRadius",
|
|
947
|
+
"borderEndStartRadius",
|
|
948
|
+
"borderEndEndRadius",
|
|
849
949
|
"fontSize",
|
|
850
|
-
"letterSpacing"
|
|
851
|
-
"lineHeight"
|
|
950
|
+
"letterSpacing"
|
|
852
951
|
]);
|
|
853
952
|
function formatNumericValue(prop, value) {
|
|
854
953
|
if (prop === "opacity") {
|
|
@@ -861,10 +960,12 @@ function formatNumericValue(prop, value) {
|
|
|
861
960
|
valueKind: "arbitrary"
|
|
862
961
|
};
|
|
863
962
|
}
|
|
864
|
-
if (prop === "aspectRatio")
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
963
|
+
if (prop === "aspectRatio" || prop === "lineHeight") {
|
|
964
|
+
return {
|
|
965
|
+
value: String(value),
|
|
966
|
+
valueKind: "arbitrary"
|
|
967
|
+
};
|
|
968
|
+
}
|
|
868
969
|
if (prop === "scale" || prop === "scaleX" || prop === "scaleY") {
|
|
869
970
|
if (value === 0) return {
|
|
870
971
|
value: "0",
|
|
@@ -39,13 +39,6 @@ var t = __toESM(require("@babel/types"), 1);
|
|
|
39
39
|
var import_tooling = require("@tamagui/style-grammar/tooling");
|
|
40
40
|
var import_componentToTag = require("./maps/componentToTag.native.js");
|
|
41
41
|
var import_v4 = require("@tamagui/shorthands/v4");
|
|
42
|
-
function _instanceof(left, right) {
|
|
43
|
-
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
44
|
-
return !!right[Symbol.hasInstance](left);
|
|
45
|
-
} else {
|
|
46
|
-
return left instanceof right;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
42
|
var _traverse_default;
|
|
50
43
|
var traverse = (_traverse_default = import_traverse.default.default) !== null && _traverse_default !== void 0 ? _traverse_default : import_traverse.default;
|
|
51
44
|
var _generate_default;
|
|
@@ -63,7 +56,7 @@ function getV6ThemeName(name) {
|
|
|
63
56
|
function namesToSet(names) {
|
|
64
57
|
if (!names) return /* @__PURE__ */ new Set();
|
|
65
58
|
if (Array.isArray(names)) return new Set(names);
|
|
66
|
-
if (
|
|
59
|
+
if (names instanceof Set) return new Set(names);
|
|
67
60
|
return new Set(Object.keys(names));
|
|
68
61
|
}
|
|
69
62
|
function addConfigNames(target, source) {
|
|
@@ -133,6 +126,13 @@ function createTransformGrammarConfig(options, mediaKeys, shorthands) {
|
|
|
133
126
|
}
|
|
134
127
|
}
|
|
135
128
|
}
|
|
129
|
+
for (var group in import_tooling.propTokenGroupFallbacks) {
|
|
130
|
+
var _options_tokens1;
|
|
131
|
+
var own = (_options_tokens1 = options.tokens) === null || _options_tokens1 === void 0 ? void 0 : _options_tokens1[group];
|
|
132
|
+
var names1 = own ? /* @__PURE__ */ new Set() : tokenNames[import_tooling.propTokenGroupFallbacks[group]];
|
|
133
|
+
if (own) addConfigNames(names1, own);
|
|
134
|
+
if (names1) tokenNames[group] = names1;
|
|
135
|
+
}
|
|
136
136
|
if (options.fonts) {
|
|
137
137
|
var _tokenNames, _tokenNames1, _tokenNames2, _tokenNames3, _tokenNames4;
|
|
138
138
|
(_tokenNames = tokenNames).fontFamily || (_tokenNames.fontFamily = /* @__PURE__ */ new Set());
|
|
@@ -200,7 +200,8 @@ function tamaguiToTailwind(source) {
|
|
|
200
200
|
componentAllow: new Set((_options_components = options.components) !== null && _options_components !== void 0 ? _options_components : []),
|
|
201
201
|
shorthands,
|
|
202
202
|
grammarConfig,
|
|
203
|
-
modifierRegistry: (0, import_tooling.createModifierRegistry)(grammarConfig).registry
|
|
203
|
+
modifierRegistry: (0, import_tooling.createModifierRegistry)(grammarConfig).registry,
|
|
204
|
+
rewriteImports: options.rewriteImports === true
|
|
204
205
|
};
|
|
205
206
|
var ast;
|
|
206
207
|
try {
|
|
@@ -466,9 +467,12 @@ function tamaguiToTailwind(source) {
|
|
|
466
467
|
didTransform = true;
|
|
467
468
|
}
|
|
468
469
|
} });
|
|
470
|
+
if (options.rewriteImports && rewriteTailwindFrontendImports(ast)) {
|
|
471
|
+
didTransform = true;
|
|
472
|
+
}
|
|
469
473
|
if (!didTransform) return source;
|
|
470
474
|
var output = generate(ast, {
|
|
471
|
-
retainLines:
|
|
475
|
+
retainLines: options.retainLines !== false,
|
|
472
476
|
concise: false
|
|
473
477
|
});
|
|
474
478
|
return output.code;
|
|
@@ -484,6 +488,11 @@ var knownCompoundComponents = /* @__PURE__ */ new Set([
|
|
|
484
488
|
"Popover.Content",
|
|
485
489
|
"Tabs.Tab"
|
|
486
490
|
]);
|
|
491
|
+
var tailwindFrontendImports = /* @__PURE__ */ new Set([
|
|
492
|
+
"html",
|
|
493
|
+
"View",
|
|
494
|
+
"Text"
|
|
495
|
+
]);
|
|
487
496
|
function isTamaguiSource(source) {
|
|
488
497
|
return source === "tamagui" || source.startsWith("@tamagui/");
|
|
489
498
|
}
|
|
@@ -526,15 +535,20 @@ function resolveTamaguiComponent(path, ctx) {
|
|
|
526
535
|
} else {
|
|
527
536
|
return null;
|
|
528
537
|
}
|
|
538
|
+
if (ctx.rewriteImports && source !== "@tamagui/tailwind" && (source !== "tamagui" && source !== "@tamagui/core" || !tailwindFrontendImports.has(tamaguiBase) || !isTailwindFrontendOnlyBinding(binding, tamaguiBase))) {
|
|
539
|
+
return null;
|
|
540
|
+
}
|
|
529
541
|
} else {
|
|
530
542
|
return null;
|
|
531
543
|
}
|
|
532
544
|
} else {
|
|
533
545
|
tamaguiBase = baseName;
|
|
546
|
+
if (ctx.rewriteImports && !tailwindFrontendImports.has(tamaguiBase)) return null;
|
|
534
547
|
}
|
|
535
548
|
var name = memberChain.length ? [tamaguiBase, ...memberChain].join(".") : tamaguiBase;
|
|
536
549
|
var isSimpleKnown = memberChain.length === 0 && name in import_componentToTag.componentToTag;
|
|
537
|
-
|
|
550
|
+
var isHTMLPrimitive = tamaguiBase === "html" && memberChain.length === 1;
|
|
551
|
+
if (!isSimpleKnown && !isHTMLPrimitive && !knownCompoundComponents.has(name) && !ctx.componentAllow.has(name)) {
|
|
538
552
|
return null;
|
|
539
553
|
}
|
|
540
554
|
return {
|
|
@@ -543,6 +557,65 @@ function resolveTamaguiComponent(path, ctx) {
|
|
|
543
557
|
isPlainIdentifier
|
|
544
558
|
};
|
|
545
559
|
}
|
|
560
|
+
function isTailwindFrontendOnlyBinding(binding, importedName) {
|
|
561
|
+
return binding.referencePaths.every(function(referencePath) {
|
|
562
|
+
var parent = referencePath.parent;
|
|
563
|
+
if (importedName === "html") {
|
|
564
|
+
var _referencePath_parentPath, _referencePath_parentPath1;
|
|
565
|
+
return t.isJSXMemberExpression(parent) && parent.object === referencePath.node && (t.isJSXOpeningElement((_referencePath_parentPath = referencePath.parentPath) === null || _referencePath_parentPath === void 0 ? void 0 : _referencePath_parentPath.parent) || t.isJSXClosingElement((_referencePath_parentPath1 = referencePath.parentPath) === null || _referencePath_parentPath1 === void 0 ? void 0 : _referencePath_parentPath1.parent));
|
|
566
|
+
}
|
|
567
|
+
return t.isJSXIdentifier(referencePath.node) && (t.isJSXOpeningElement(parent) || t.isJSXClosingElement(parent)) && parent.name === referencePath.node;
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
function rewriteTailwindFrontendImports(ast) {
|
|
571
|
+
var changed = false;
|
|
572
|
+
traverse(ast, { ImportDeclaration(path) {
|
|
573
|
+
var source = String(path.node.source.value);
|
|
574
|
+
if (source !== "tamagui" && source !== "@tamagui/core") return;
|
|
575
|
+
if (path.node.importKind === "type") return;
|
|
576
|
+
var moved = [];
|
|
577
|
+
var retained = [];
|
|
578
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
579
|
+
try {
|
|
580
|
+
for (var _iterator = path.node.specifiers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
581
|
+
var specifier = _step.value;
|
|
582
|
+
if (!t.isImportSpecifier(specifier) || specifier.importKind === "type") {
|
|
583
|
+
retained.push(specifier);
|
|
584
|
+
continue;
|
|
585
|
+
}
|
|
586
|
+
var importedName = t.isIdentifier(specifier.imported) ? specifier.imported.name : String(specifier.imported.value);
|
|
587
|
+
var binding = path.scope.getBinding(specifier.local.name);
|
|
588
|
+
if (!tailwindFrontendImports.has(importedName) || !binding || !isTailwindFrontendOnlyBinding(binding, importedName)) {
|
|
589
|
+
retained.push(specifier);
|
|
590
|
+
continue;
|
|
591
|
+
}
|
|
592
|
+
moved.push(specifier);
|
|
593
|
+
}
|
|
594
|
+
} catch (err) {
|
|
595
|
+
_didIteratorError = true;
|
|
596
|
+
_iteratorError = err;
|
|
597
|
+
} finally {
|
|
598
|
+
try {
|
|
599
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
600
|
+
_iterator.return();
|
|
601
|
+
}
|
|
602
|
+
} finally {
|
|
603
|
+
if (_didIteratorError) {
|
|
604
|
+
throw _iteratorError;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
if (!moved.length) return;
|
|
609
|
+
changed = true;
|
|
610
|
+
if (!retained.length) {
|
|
611
|
+
path.node.source = t.stringLiteral("@tamagui/tailwind");
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
path.node.specifiers = retained;
|
|
615
|
+
path.insertAfter(t.importDeclaration(moved, t.stringLiteral("@tamagui/tailwind")));
|
|
616
|
+
} });
|
|
617
|
+
return changed;
|
|
618
|
+
}
|
|
546
619
|
function classPrefixOf(token) {
|
|
547
620
|
var noMod = token.slice(token.lastIndexOf(":") + 1);
|
|
548
621
|
var core = noMod[0] === "-" ? noMod.slice(1) : noMod;
|
|
@@ -740,7 +813,7 @@ function resolveShorthand(ctx, name) {
|
|
|
740
813
|
function hasConfiguredName(names, value) {
|
|
741
814
|
if (!names) return false;
|
|
742
815
|
if (Array.isArray(names)) return names.includes(value);
|
|
743
|
-
if (
|
|
816
|
+
if (names instanceof Set) return names.has(value);
|
|
744
817
|
return value in names;
|
|
745
818
|
}
|
|
746
819
|
function formatStringValue(ctx, prop, value) {
|
|
@@ -771,7 +844,12 @@ function formatStringValue(ctx, prop, value) {
|
|
|
771
844
|
valueKind: "convenience"
|
|
772
845
|
};
|
|
773
846
|
}
|
|
774
|
-
if (/^-?\d+(\.\d+)?$/.test(value))
|
|
847
|
+
if (/^-?\d+(\.\d+)?$/.test(value)) {
|
|
848
|
+
return prop === "lineHeight" ? {
|
|
849
|
+
value,
|
|
850
|
+
valueKind: "arbitrary"
|
|
851
|
+
} : null;
|
|
852
|
+
}
|
|
775
853
|
if (value.endsWith("%")) {
|
|
776
854
|
var exact = {
|
|
777
855
|
"100%": "full",
|
|
@@ -824,6 +902,12 @@ var pxLengthProps = /* @__PURE__ */ new Set([
|
|
|
824
902
|
"paddingRight",
|
|
825
903
|
"paddingBottom",
|
|
826
904
|
"paddingLeft",
|
|
905
|
+
"paddingStart",
|
|
906
|
+
"paddingEnd",
|
|
907
|
+
"paddingInlineStart",
|
|
908
|
+
"paddingInlineEnd",
|
|
909
|
+
"paddingBlockStart",
|
|
910
|
+
"paddingBlockEnd",
|
|
827
911
|
"paddingHorizontal",
|
|
828
912
|
"paddingVertical",
|
|
829
913
|
"margin",
|
|
@@ -831,6 +915,12 @@ var pxLengthProps = /* @__PURE__ */ new Set([
|
|
|
831
915
|
"marginRight",
|
|
832
916
|
"marginBottom",
|
|
833
917
|
"marginLeft",
|
|
918
|
+
"marginStart",
|
|
919
|
+
"marginEnd",
|
|
920
|
+
"marginInlineStart",
|
|
921
|
+
"marginInlineEnd",
|
|
922
|
+
"marginBlockStart",
|
|
923
|
+
"marginBlockEnd",
|
|
834
924
|
"marginHorizontal",
|
|
835
925
|
"marginVertical",
|
|
836
926
|
"gap",
|
|
@@ -841,14 +931,23 @@ var pxLengthProps = /* @__PURE__ */ new Set([
|
|
|
841
931
|
"bottom",
|
|
842
932
|
"left",
|
|
843
933
|
"inset",
|
|
934
|
+
"insetInlineStart",
|
|
935
|
+
"insetInlineEnd",
|
|
844
936
|
"borderRadius",
|
|
845
937
|
"borderTopLeftRadius",
|
|
846
938
|
"borderTopRightRadius",
|
|
847
939
|
"borderBottomLeftRadius",
|
|
848
940
|
"borderBottomRightRadius",
|
|
941
|
+
"borderTopStartRadius",
|
|
942
|
+
"borderTopEndRadius",
|
|
943
|
+
"borderBottomStartRadius",
|
|
944
|
+
"borderBottomEndRadius",
|
|
945
|
+
"borderStartStartRadius",
|
|
946
|
+
"borderStartEndRadius",
|
|
947
|
+
"borderEndStartRadius",
|
|
948
|
+
"borderEndEndRadius",
|
|
849
949
|
"fontSize",
|
|
850
|
-
"letterSpacing"
|
|
851
|
-
"lineHeight"
|
|
950
|
+
"letterSpacing"
|
|
852
951
|
]);
|
|
853
952
|
function formatNumericValue(prop, value) {
|
|
854
953
|
if (prop === "opacity") {
|
|
@@ -861,10 +960,12 @@ function formatNumericValue(prop, value) {
|
|
|
861
960
|
valueKind: "arbitrary"
|
|
862
961
|
};
|
|
863
962
|
}
|
|
864
|
-
if (prop === "aspectRatio")
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
963
|
+
if (prop === "aspectRatio" || prop === "lineHeight") {
|
|
964
|
+
return {
|
|
965
|
+
value: String(value),
|
|
966
|
+
valueKind: "arbitrary"
|
|
967
|
+
};
|
|
968
|
+
}
|
|
868
969
|
if (prop === "scale" || prop === "scaleX" || prop === "scaleY") {
|
|
869
970
|
if (value === 0) return {
|
|
870
971
|
value: "0",
|