@mgcrea/react-native-tailwind 0.12.0 → 0.12.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/babel/config-loader.d.ts +3 -0
- package/dist/babel/config-loader.test.ts +2 -2
- package/dist/babel/config-loader.ts +37 -2
- package/dist/babel/index.cjs +136 -22
- package/dist/babel/plugin.ts +11 -1
- package/dist/babel/utils/styleInjection.ts +57 -17
- package/dist/parser/index.d.ts +1 -0
- package/dist/parser/index.js +1 -1
- package/dist/parser/layout.js +1 -1
- package/dist/parser/layout.test.js +1 -1
- package/dist/parser/typography.d.ts +2 -1
- package/dist/parser/typography.js +1 -1
- package/dist/parser/typography.test.js +1 -1
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.cjs.map +3 -3
- package/dist/runtime.js +1 -1
- package/dist/runtime.js.map +3 -3
- package/package.json +1 -1
- package/src/babel/config-loader.test.ts +2 -2
- package/src/babel/config-loader.ts +37 -2
- package/src/babel/plugin.ts +11 -1
- package/src/babel/utils/styleInjection.ts +57 -17
- package/src/parser/index.ts +2 -1
- package/src/parser/layout.test.ts +61 -0
- package/src/parser/layout.ts +55 -1
- package/src/parser/typography.test.ts +102 -0
- package/src/parser/typography.ts +61 -15
|
@@ -7,9 +7,11 @@ export type TailwindConfig = {
|
|
|
7
7
|
extend?: {
|
|
8
8
|
colors?: Record<string, string | Record<string, string>>;
|
|
9
9
|
fontFamily?: Record<string, string | string[]>;
|
|
10
|
+
fontSize?: Record<string, string | number>;
|
|
10
11
|
};
|
|
11
12
|
colors?: Record<string, string | Record<string, string>>;
|
|
12
13
|
fontFamily?: Record<string, string | string[]>;
|
|
14
|
+
fontSize?: Record<string, string | number>;
|
|
13
15
|
};
|
|
14
16
|
};
|
|
15
17
|
/**
|
|
@@ -26,6 +28,7 @@ export declare function loadTailwindConfig(configPath: string): TailwindConfig |
|
|
|
26
28
|
export type CustomTheme = {
|
|
27
29
|
colors: Record<string, string>;
|
|
28
30
|
fontFamily: Record<string, string>;
|
|
31
|
+
fontSize: Record<string, number>;
|
|
29
32
|
};
|
|
30
33
|
/**
|
|
31
34
|
* Extract all custom theme extensions from tailwind config
|
|
@@ -120,7 +120,7 @@ describe("config-loader", () => {
|
|
|
120
120
|
vi.spyOn(fs, "existsSync").mockReturnValue(false);
|
|
121
121
|
|
|
122
122
|
const result = extractCustomTheme("/project/src/file.ts");
|
|
123
|
-
expect(result).toEqual({ colors: {}, fontFamily: {} });
|
|
123
|
+
expect(result).toEqual({ colors: {}, fontFamily: {}, fontSize: {} });
|
|
124
124
|
});
|
|
125
125
|
|
|
126
126
|
it("should return empty theme when config has no theme", () => {
|
|
@@ -134,7 +134,7 @@ describe("config-loader", () => {
|
|
|
134
134
|
const result = extractCustomTheme("/project/src/file.ts");
|
|
135
135
|
|
|
136
136
|
// Without actual config loading, this returns empty
|
|
137
|
-
expect(result).toEqual({ colors: {}, fontFamily: {} });
|
|
137
|
+
expect(result).toEqual({ colors: {}, fontFamily: {}, fontSize: {} });
|
|
138
138
|
});
|
|
139
139
|
|
|
140
140
|
it("should extract colors and fontFamily from theme.extend", () => {
|
|
@@ -14,9 +14,11 @@ export type TailwindConfig = {
|
|
|
14
14
|
extend?: {
|
|
15
15
|
colors?: Record<string, string | Record<string, string>>;
|
|
16
16
|
fontFamily?: Record<string, string | string[]>;
|
|
17
|
+
fontSize?: Record<string, string | number>;
|
|
17
18
|
};
|
|
18
19
|
colors?: Record<string, string | Record<string, string>>;
|
|
19
20
|
fontFamily?: Record<string, string | string[]>;
|
|
21
|
+
fontSize?: Record<string, string | number>;
|
|
20
22
|
};
|
|
21
23
|
};
|
|
22
24
|
|
|
@@ -89,6 +91,7 @@ export function loadTailwindConfig(configPath: string): TailwindConfig | null {
|
|
|
89
91
|
export type CustomTheme = {
|
|
90
92
|
colors: Record<string, string>;
|
|
91
93
|
fontFamily: Record<string, string>;
|
|
94
|
+
fontSize: Record<string, number>;
|
|
92
95
|
};
|
|
93
96
|
|
|
94
97
|
/**
|
|
@@ -100,12 +103,12 @@ export function extractCustomTheme(filename: string): CustomTheme {
|
|
|
100
103
|
const configPath = findTailwindConfig(projectDir);
|
|
101
104
|
|
|
102
105
|
if (!configPath) {
|
|
103
|
-
return { colors: {}, fontFamily: {} };
|
|
106
|
+
return { colors: {}, fontFamily: {}, fontSize: {} };
|
|
104
107
|
}
|
|
105
108
|
|
|
106
109
|
const config = loadTailwindConfig(configPath);
|
|
107
110
|
if (!config?.theme) {
|
|
108
|
-
return { colors: {}, fontFamily: {} };
|
|
111
|
+
return { colors: {}, fontFamily: {}, fontSize: {} };
|
|
109
112
|
}
|
|
110
113
|
|
|
111
114
|
// Extract colors
|
|
@@ -139,8 +142,40 @@ export function extractCustomTheme(filename: string): CustomTheme {
|
|
|
139
142
|
}
|
|
140
143
|
}
|
|
141
144
|
|
|
145
|
+
// Extract fontSize
|
|
146
|
+
/* v8 ignore next 5 */
|
|
147
|
+
if (config.theme.fontSize && !config.theme.extend?.fontSize && process.env.NODE_ENV !== "production") {
|
|
148
|
+
console.warn(
|
|
149
|
+
"[react-native-tailwind] Using theme.fontSize will override all default font sizes. " +
|
|
150
|
+
"Use theme.extend.fontSize to add custom font sizes while keeping defaults.",
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
const fontSize = config.theme.extend?.fontSize ?? config.theme.fontSize ?? {};
|
|
154
|
+
|
|
155
|
+
// Convert fontSize values to numbers (handle string or number values)
|
|
156
|
+
const fontSizeResult: Record<string, number> = {};
|
|
157
|
+
for (const [key, value] of Object.entries(fontSize)) {
|
|
158
|
+
if (typeof value === "number") {
|
|
159
|
+
fontSizeResult[key] = value;
|
|
160
|
+
} else if (typeof value === "string") {
|
|
161
|
+
// Parse string values like "18px" or "18" to number
|
|
162
|
+
const parsed = parseFloat(value.replace(/px$/, ""));
|
|
163
|
+
if (!isNaN(parsed)) {
|
|
164
|
+
fontSizeResult[key] = parsed;
|
|
165
|
+
} else {
|
|
166
|
+
/* v8 ignore next 5 */
|
|
167
|
+
if (process.env.NODE_ENV !== "production") {
|
|
168
|
+
console.warn(
|
|
169
|
+
`[react-native-tailwind] Invalid fontSize value for "${key}": ${value}. Expected number or string like "18px".`,
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
142
176
|
return {
|
|
143
177
|
colors: flattenColors(colors),
|
|
144
178
|
fontFamily: fontFamilyResult,
|
|
179
|
+
fontSize: fontSizeResult,
|
|
145
180
|
};
|
|
146
181
|
}
|
package/dist/babel/index.cjs
CHANGED
|
@@ -701,6 +701,21 @@ function parseArbitraryZIndex(value) {
|
|
|
701
701
|
}
|
|
702
702
|
return null;
|
|
703
703
|
}
|
|
704
|
+
function parseArbitraryGrowShrink(value) {
|
|
705
|
+
const match = value.match(/^\[(\d+(?:\.\d+)?|\.\d+)\]$/);
|
|
706
|
+
if (match) {
|
|
707
|
+
return parseFloat(match[1]);
|
|
708
|
+
}
|
|
709
|
+
if (value.startsWith("[") && value.endsWith("]")) {
|
|
710
|
+
if (process.env.NODE_ENV !== "production") {
|
|
711
|
+
console.warn(
|
|
712
|
+
`[react-native-tailwind] Invalid arbitrary grow/shrink value: ${value}. Only non-negative numbers are supported (e.g., [1.5], [2], [0.5], [.5]).`
|
|
713
|
+
);
|
|
714
|
+
}
|
|
715
|
+
return null;
|
|
716
|
+
}
|
|
717
|
+
return null;
|
|
718
|
+
}
|
|
704
719
|
var DISPLAY_MAP = {
|
|
705
720
|
flex: { display: "flex" },
|
|
706
721
|
hidden: { display: "none" }
|
|
@@ -725,7 +740,12 @@ var GROW_SHRINK_MAP = {
|
|
|
725
740
|
grow: { flexGrow: 1 },
|
|
726
741
|
"grow-0": { flexGrow: 0 },
|
|
727
742
|
shrink: { flexShrink: 1 },
|
|
728
|
-
"shrink-0": { flexShrink: 0 }
|
|
743
|
+
"shrink-0": { flexShrink: 0 },
|
|
744
|
+
// CSS-style aliases
|
|
745
|
+
"flex-grow": { flexGrow: 1 },
|
|
746
|
+
"flex-grow-0": { flexGrow: 0 },
|
|
747
|
+
"flex-shrink": { flexShrink: 1 },
|
|
748
|
+
"flex-shrink-0": { flexShrink: 0 }
|
|
729
749
|
};
|
|
730
750
|
var JUSTIFY_CONTENT_MAP = {
|
|
731
751
|
"justify-start": { justifyContent: "flex-start" },
|
|
@@ -920,6 +940,22 @@ function parseLayout(cls) {
|
|
|
920
940
|
return { top: insetValue, right: insetValue, bottom: insetValue, left: insetValue };
|
|
921
941
|
}
|
|
922
942
|
}
|
|
943
|
+
if (cls.startsWith("grow-") || cls.startsWith("flex-grow-")) {
|
|
944
|
+
const prefix = cls.startsWith("flex-grow-") ? "flex-grow-" : "grow-";
|
|
945
|
+
const growKey = cls.substring(prefix.length);
|
|
946
|
+
const arbitraryGrow = parseArbitraryGrowShrink(growKey);
|
|
947
|
+
if (arbitraryGrow !== null) {
|
|
948
|
+
return { flexGrow: arbitraryGrow };
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
if (cls.startsWith("shrink-") || cls.startsWith("flex-shrink-")) {
|
|
952
|
+
const prefix = cls.startsWith("flex-shrink-") ? "flex-shrink-" : "shrink-";
|
|
953
|
+
const shrinkKey = cls.substring(prefix.length);
|
|
954
|
+
const arbitraryShrink = parseArbitraryGrowShrink(shrinkKey);
|
|
955
|
+
if (arbitraryShrink !== null) {
|
|
956
|
+
return { flexShrink: arbitraryShrink };
|
|
957
|
+
}
|
|
958
|
+
}
|
|
923
959
|
return DISPLAY_MAP[cls] ?? FLEX_DIRECTION_MAP[cls] ?? FLEX_WRAP_MAP[cls] ?? FLEX_MAP[cls] ?? GROW_SHRINK_MAP[cls] ?? JUSTIFY_CONTENT_MAP[cls] ?? ALIGN_ITEMS_MAP[cls] ?? ALIGN_SELF_MAP[cls] ?? ALIGN_CONTENT_MAP[cls] ?? POSITION_MAP[cls] ?? OVERFLOW_MAP[cls] ?? OPACITY_MAP[cls] ?? null;
|
|
924
960
|
}
|
|
925
961
|
|
|
@@ -1649,14 +1685,14 @@ var TRACKING_MAP = {
|
|
|
1649
1685
|
"tracking-widest": { letterSpacing: 1.6 }
|
|
1650
1686
|
};
|
|
1651
1687
|
function parseArbitraryFontSize(value) {
|
|
1652
|
-
const pxMatch = value.match(/^\[(
|
|
1688
|
+
const pxMatch = value.match(/^\[(-?\d+(?:\.\d+)?|-?\.\d+)(?:px)?\]$/);
|
|
1653
1689
|
if (pxMatch) {
|
|
1654
|
-
return
|
|
1690
|
+
return parseFloat(pxMatch[1]);
|
|
1655
1691
|
}
|
|
1656
1692
|
if (value.startsWith("[") && value.endsWith("]")) {
|
|
1657
1693
|
if (process.env.NODE_ENV !== "production") {
|
|
1658
1694
|
console.warn(
|
|
1659
|
-
`[react-native-tailwind] Unsupported arbitrary font size value: ${value}. Only px values are supported (e.g., [18px]
|
|
1695
|
+
`[react-native-tailwind] Unsupported arbitrary font size value: ${value}. Only px values are supported (e.g., [18px], [13.5px], [.5]).`
|
|
1660
1696
|
);
|
|
1661
1697
|
}
|
|
1662
1698
|
return null;
|
|
@@ -1664,21 +1700,36 @@ function parseArbitraryFontSize(value) {
|
|
|
1664
1700
|
return null;
|
|
1665
1701
|
}
|
|
1666
1702
|
function parseArbitraryLineHeight(value) {
|
|
1667
|
-
const pxMatch = value.match(/^\[(
|
|
1703
|
+
const pxMatch = value.match(/^\[(-?\d+(?:\.\d+)?|-?\.\d+)(?:px)?\]$/);
|
|
1668
1704
|
if (pxMatch) {
|
|
1669
|
-
return
|
|
1705
|
+
return parseFloat(pxMatch[1]);
|
|
1670
1706
|
}
|
|
1671
1707
|
if (value.startsWith("[") && value.endsWith("]")) {
|
|
1672
1708
|
if (process.env.NODE_ENV !== "production") {
|
|
1673
1709
|
console.warn(
|
|
1674
|
-
`[react-native-tailwind] Unsupported arbitrary line height value: ${value}. Only px values are supported (e.g., [24px]
|
|
1710
|
+
`[react-native-tailwind] Unsupported arbitrary line height value: ${value}. Only px values are supported (e.g., [24px], [21.5px], [.5]).`
|
|
1675
1711
|
);
|
|
1676
1712
|
}
|
|
1677
1713
|
return null;
|
|
1678
1714
|
}
|
|
1679
1715
|
return null;
|
|
1680
1716
|
}
|
|
1681
|
-
function
|
|
1717
|
+
function parseArbitraryLetterSpacing(value) {
|
|
1718
|
+
const pxMatch = value.match(/^\[(-?\d+(?:\.\d+)?|-?\.\d+)(?:px)?\]$/);
|
|
1719
|
+
if (pxMatch) {
|
|
1720
|
+
return parseFloat(pxMatch[1]);
|
|
1721
|
+
}
|
|
1722
|
+
if (value.startsWith("[") && value.endsWith("]")) {
|
|
1723
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1724
|
+
console.warn(
|
|
1725
|
+
`[react-native-tailwind] Unsupported arbitrary letter spacing value: ${value}. Only px values are supported (e.g., [0.5px], [0.3], [.5], [-0.4]).`
|
|
1726
|
+
);
|
|
1727
|
+
}
|
|
1728
|
+
return null;
|
|
1729
|
+
}
|
|
1730
|
+
return null;
|
|
1731
|
+
}
|
|
1732
|
+
function parseTypography(cls, customFontFamily, customFontSize) {
|
|
1682
1733
|
const fontFamilyMap = customFontFamily ? {
|
|
1683
1734
|
...FONT_FAMILY_MAP,
|
|
1684
1735
|
...Object.fromEntries(
|
|
@@ -1691,6 +1742,9 @@ function parseTypography(cls, customFontFamily) {
|
|
|
1691
1742
|
if (arbitraryValue !== null) {
|
|
1692
1743
|
return { fontSize: arbitraryValue };
|
|
1693
1744
|
}
|
|
1745
|
+
if (customFontSize?.[sizeKey] !== void 0) {
|
|
1746
|
+
return { fontSize: customFontSize[sizeKey] };
|
|
1747
|
+
}
|
|
1694
1748
|
const fontSize = FONT_SIZES[sizeKey];
|
|
1695
1749
|
if (fontSize !== void 0) {
|
|
1696
1750
|
return { fontSize };
|
|
@@ -1707,6 +1761,13 @@ function parseTypography(cls, customFontFamily) {
|
|
|
1707
1761
|
return { lineHeight };
|
|
1708
1762
|
}
|
|
1709
1763
|
}
|
|
1764
|
+
if (cls.startsWith("tracking-")) {
|
|
1765
|
+
const trackingKey = cls.substring(9);
|
|
1766
|
+
const arbitraryValue = parseArbitraryLetterSpacing(trackingKey);
|
|
1767
|
+
if (arbitraryValue !== null) {
|
|
1768
|
+
return { letterSpacing: arbitraryValue };
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1710
1771
|
return fontFamilyMap[cls] ?? FONT_WEIGHT_MAP[cls] ?? FONT_STYLE_MAP[cls] ?? TEXT_ALIGN_MAP[cls] ?? TEXT_DECORATION_MAP[cls] ?? TEXT_TRANSFORM_MAP[cls] ?? LINE_HEIGHT_MAP[cls] ?? TRACKING_MAP[cls] ?? null;
|
|
1711
1772
|
}
|
|
1712
1773
|
|
|
@@ -1863,7 +1924,7 @@ function parseClass(cls, customTheme) {
|
|
|
1863
1924
|
parseBorder,
|
|
1864
1925
|
(cls2) => parseColor(cls2, customTheme?.colors),
|
|
1865
1926
|
parseLayout,
|
|
1866
|
-
(cls2) => parseTypography(cls2, customTheme?.fontFamily),
|
|
1927
|
+
(cls2) => parseTypography(cls2, customTheme?.fontFamily, customTheme?.fontSize),
|
|
1867
1928
|
parseSizing,
|
|
1868
1929
|
parseShadow,
|
|
1869
1930
|
parseAspectRatio,
|
|
@@ -1935,11 +1996,11 @@ function extractCustomTheme(filename) {
|
|
|
1935
1996
|
const projectDir = path.dirname(filename);
|
|
1936
1997
|
const configPath = findTailwindConfig(projectDir);
|
|
1937
1998
|
if (!configPath) {
|
|
1938
|
-
return { colors: {}, fontFamily: {} };
|
|
1999
|
+
return { colors: {}, fontFamily: {}, fontSize: {} };
|
|
1939
2000
|
}
|
|
1940
2001
|
const config = loadTailwindConfig(configPath);
|
|
1941
2002
|
if (!config?.theme) {
|
|
1942
|
-
return { colors: {}, fontFamily: {} };
|
|
2003
|
+
return { colors: {}, fontFamily: {}, fontSize: {} };
|
|
1943
2004
|
}
|
|
1944
2005
|
if (config.theme.colors && !config.theme.extend?.colors && process.env.NODE_ENV !== "production") {
|
|
1945
2006
|
console.warn(
|
|
@@ -1961,9 +2022,33 @@ function extractCustomTheme(filename) {
|
|
|
1961
2022
|
fontFamilyResult[key] = value;
|
|
1962
2023
|
}
|
|
1963
2024
|
}
|
|
2025
|
+
if (config.theme.fontSize && !config.theme.extend?.fontSize && process.env.NODE_ENV !== "production") {
|
|
2026
|
+
console.warn(
|
|
2027
|
+
"[react-native-tailwind] Using theme.fontSize will override all default font sizes. Use theme.extend.fontSize to add custom font sizes while keeping defaults."
|
|
2028
|
+
);
|
|
2029
|
+
}
|
|
2030
|
+
const fontSize = config.theme.extend?.fontSize ?? config.theme.fontSize ?? {};
|
|
2031
|
+
const fontSizeResult = {};
|
|
2032
|
+
for (const [key, value] of Object.entries(fontSize)) {
|
|
2033
|
+
if (typeof value === "number") {
|
|
2034
|
+
fontSizeResult[key] = value;
|
|
2035
|
+
} else if (typeof value === "string") {
|
|
2036
|
+
const parsed = parseFloat(value.replace(/px$/, ""));
|
|
2037
|
+
if (!isNaN(parsed)) {
|
|
2038
|
+
fontSizeResult[key] = parsed;
|
|
2039
|
+
} else {
|
|
2040
|
+
if (process.env.NODE_ENV !== "production") {
|
|
2041
|
+
console.warn(
|
|
2042
|
+
`[react-native-tailwind] Invalid fontSize value for "${key}": ${value}. Expected number or string like "18px".`
|
|
2043
|
+
);
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
2047
|
+
}
|
|
1964
2048
|
return {
|
|
1965
2049
|
colors: flattenColors(colors),
|
|
1966
|
-
fontFamily: fontFamilyResult
|
|
2050
|
+
fontFamily: fontFamilyResult,
|
|
2051
|
+
fontSize: fontSizeResult
|
|
1967
2052
|
};
|
|
1968
2053
|
}
|
|
1969
2054
|
|
|
@@ -2480,17 +2565,29 @@ function processPlatformModifiers(platformModifiers, state, parseClassName2, gen
|
|
|
2480
2565
|
// src/babel/utils/styleInjection.ts
|
|
2481
2566
|
function addStyleSheetImport(path2, t) {
|
|
2482
2567
|
const body = path2.node.body;
|
|
2483
|
-
let
|
|
2568
|
+
let existingValueImport = null;
|
|
2484
2569
|
for (const statement of body) {
|
|
2485
2570
|
if (t.isImportDeclaration(statement) && statement.source.value === "react-native") {
|
|
2486
|
-
|
|
2571
|
+
if (statement.importKind === "type") {
|
|
2572
|
+
continue;
|
|
2573
|
+
}
|
|
2574
|
+
const hasNamespaceImport = statement.specifiers.some((spec) => t.isImportNamespaceSpecifier(spec));
|
|
2575
|
+
if (hasNamespaceImport) {
|
|
2576
|
+
continue;
|
|
2577
|
+
}
|
|
2578
|
+
existingValueImport = statement;
|
|
2487
2579
|
break;
|
|
2488
2580
|
}
|
|
2489
2581
|
}
|
|
2490
|
-
if (
|
|
2491
|
-
|
|
2492
|
-
t.
|
|
2582
|
+
if (existingValueImport) {
|
|
2583
|
+
const hasStyleSheet = existingValueImport.specifiers.some(
|
|
2584
|
+
(spec) => t.isImportSpecifier(spec) && spec.imported.type === "Identifier" && spec.imported.name === "StyleSheet"
|
|
2493
2585
|
);
|
|
2586
|
+
if (!hasStyleSheet) {
|
|
2587
|
+
existingValueImport.specifiers.push(
|
|
2588
|
+
t.importSpecifier(t.identifier("StyleSheet"), t.identifier("StyleSheet"))
|
|
2589
|
+
);
|
|
2590
|
+
}
|
|
2494
2591
|
} else {
|
|
2495
2592
|
const importDeclaration = t.importDeclaration(
|
|
2496
2593
|
[t.importSpecifier(t.identifier("StyleSheet"), t.identifier("StyleSheet"))],
|
|
@@ -2501,15 +2598,29 @@ function addStyleSheetImport(path2, t) {
|
|
|
2501
2598
|
}
|
|
2502
2599
|
function addPlatformImport(path2, t) {
|
|
2503
2600
|
const body = path2.node.body;
|
|
2504
|
-
let
|
|
2601
|
+
let existingValueImport = null;
|
|
2505
2602
|
for (const statement of body) {
|
|
2506
2603
|
if (t.isImportDeclaration(statement) && statement.source.value === "react-native") {
|
|
2507
|
-
|
|
2604
|
+
if (statement.importKind === "type") {
|
|
2605
|
+
continue;
|
|
2606
|
+
}
|
|
2607
|
+
const hasNamespaceImport = statement.specifiers.some((spec) => t.isImportNamespaceSpecifier(spec));
|
|
2608
|
+
if (hasNamespaceImport) {
|
|
2609
|
+
continue;
|
|
2610
|
+
}
|
|
2611
|
+
existingValueImport = statement;
|
|
2508
2612
|
break;
|
|
2509
2613
|
}
|
|
2510
2614
|
}
|
|
2511
|
-
if (
|
|
2512
|
-
|
|
2615
|
+
if (existingValueImport) {
|
|
2616
|
+
const hasPlatform = existingValueImport.specifiers.some(
|
|
2617
|
+
(spec) => t.isImportSpecifier(spec) && spec.imported.type === "Identifier" && spec.imported.name === "Platform"
|
|
2618
|
+
);
|
|
2619
|
+
if (!hasPlatform) {
|
|
2620
|
+
existingValueImport.specifiers.push(
|
|
2621
|
+
t.importSpecifier(t.identifier("Platform"), t.identifier("Platform"))
|
|
2622
|
+
);
|
|
2623
|
+
}
|
|
2513
2624
|
} else {
|
|
2514
2625
|
const importDeclaration = t.importDeclaration(
|
|
2515
2626
|
[t.importSpecifier(t.identifier("Platform"), t.identifier("Platform"))],
|
|
@@ -3095,7 +3206,6 @@ function reactNativeTailwindBabelPlugin({ types: t }, options) {
|
|
|
3095
3206
|
if (importedName === "tw" || importedName === "twStyle") {
|
|
3096
3207
|
const localName = spec.local.name;
|
|
3097
3208
|
state.twImportNames.add(localName);
|
|
3098
|
-
state.hasTwImport = true;
|
|
3099
3209
|
}
|
|
3100
3210
|
}
|
|
3101
3211
|
});
|
|
@@ -3128,6 +3238,7 @@ function reactNativeTailwindBabelPlugin({ types: t }, options) {
|
|
|
3128
3238
|
path2.replaceWith(
|
|
3129
3239
|
t.objectExpression([t.objectProperty(t.identifier("style"), t.objectExpression([]))])
|
|
3130
3240
|
);
|
|
3241
|
+
state.hasTwImport = true;
|
|
3131
3242
|
return;
|
|
3132
3243
|
}
|
|
3133
3244
|
state.hasClassNames = true;
|
|
@@ -3141,6 +3252,7 @@ function reactNativeTailwindBabelPlugin({ types: t }, options) {
|
|
|
3141
3252
|
findComponentScope,
|
|
3142
3253
|
t
|
|
3143
3254
|
);
|
|
3255
|
+
state.hasTwImport = true;
|
|
3144
3256
|
},
|
|
3145
3257
|
// Handle twStyle('...') call expressions
|
|
3146
3258
|
CallExpression(path2, state) {
|
|
@@ -3172,6 +3284,7 @@ function reactNativeTailwindBabelPlugin({ types: t }, options) {
|
|
|
3172
3284
|
const className = arg.value.trim();
|
|
3173
3285
|
if (!className) {
|
|
3174
3286
|
path2.replaceWith(t.identifier("undefined"));
|
|
3287
|
+
state.hasTwImport = true;
|
|
3175
3288
|
return;
|
|
3176
3289
|
}
|
|
3177
3290
|
state.hasClassNames = true;
|
|
@@ -3185,6 +3298,7 @@ function reactNativeTailwindBabelPlugin({ types: t }, options) {
|
|
|
3185
3298
|
findComponentScope,
|
|
3186
3299
|
t
|
|
3187
3300
|
);
|
|
3301
|
+
state.hasTwImport = true;
|
|
3188
3302
|
},
|
|
3189
3303
|
JSXAttribute(path2, state) {
|
|
3190
3304
|
const node = path2.node;
|
package/dist/babel/plugin.ts
CHANGED
|
@@ -398,7 +398,7 @@ export default function reactNativeTailwindBabelPlugin(
|
|
|
398
398
|
// Track the local name (could be renamed: import { tw as customTw })
|
|
399
399
|
const localName = spec.local.name;
|
|
400
400
|
state.twImportNames.add(localName);
|
|
401
|
-
|
|
401
|
+
// Don't set hasTwImport yet - only set it when we successfully transform a call
|
|
402
402
|
}
|
|
403
403
|
}
|
|
404
404
|
});
|
|
@@ -443,6 +443,8 @@ export default function reactNativeTailwindBabelPlugin(
|
|
|
443
443
|
path.replaceWith(
|
|
444
444
|
t.objectExpression([t.objectProperty(t.identifier("style"), t.objectExpression([]))]),
|
|
445
445
|
);
|
|
446
|
+
// Mark as successfully transformed (even if empty)
|
|
447
|
+
state.hasTwImport = true;
|
|
446
448
|
return;
|
|
447
449
|
}
|
|
448
450
|
|
|
@@ -459,6 +461,9 @@ export default function reactNativeTailwindBabelPlugin(
|
|
|
459
461
|
findComponentScope,
|
|
460
462
|
t,
|
|
461
463
|
);
|
|
464
|
+
|
|
465
|
+
// Mark as successfully transformed
|
|
466
|
+
state.hasTwImport = true;
|
|
462
467
|
},
|
|
463
468
|
|
|
464
469
|
// Handle twStyle('...') call expressions
|
|
@@ -502,6 +507,8 @@ export default function reactNativeTailwindBabelPlugin(
|
|
|
502
507
|
if (!className) {
|
|
503
508
|
// Replace with undefined
|
|
504
509
|
path.replaceWith(t.identifier("undefined"));
|
|
510
|
+
// Mark as successfully transformed (even if empty)
|
|
511
|
+
state.hasTwImport = true;
|
|
505
512
|
return;
|
|
506
513
|
}
|
|
507
514
|
|
|
@@ -518,6 +525,9 @@ export default function reactNativeTailwindBabelPlugin(
|
|
|
518
525
|
findComponentScope,
|
|
519
526
|
t,
|
|
520
527
|
);
|
|
528
|
+
|
|
529
|
+
// Mark as successfully transformed
|
|
530
|
+
state.hasTwImport = true;
|
|
521
531
|
},
|
|
522
532
|
|
|
523
533
|
JSXAttribute(path, state) {
|
|
@@ -10,24 +10,44 @@ import type { StyleObject } from "../../types/core.js";
|
|
|
10
10
|
* Add StyleSheet import to the file or merge with existing react-native import
|
|
11
11
|
*/
|
|
12
12
|
export function addStyleSheetImport(path: NodePath<BabelTypes.Program>, t: typeof BabelTypes): void {
|
|
13
|
-
// Check if there's already a react-native
|
|
13
|
+
// Check if there's already a value import from react-native
|
|
14
14
|
const body = path.node.body;
|
|
15
|
-
let
|
|
15
|
+
let existingValueImport: BabelTypes.ImportDeclaration | null = null;
|
|
16
16
|
|
|
17
17
|
for (const statement of body) {
|
|
18
18
|
if (t.isImportDeclaration(statement) && statement.source.value === "react-native") {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
// Skip type-only imports (they get erased at runtime)
|
|
20
|
+
if (statement.importKind === "type") {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
// Skip namespace imports (import * as RN) - can't add named specifiers to them
|
|
24
|
+
const hasNamespaceImport = statement.specifiers.some((spec) => t.isImportNamespaceSpecifier(spec));
|
|
25
|
+
if (hasNamespaceImport) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
existingValueImport = statement;
|
|
29
|
+
break; // Found a value import, we can stop
|
|
21
30
|
}
|
|
22
31
|
}
|
|
23
32
|
|
|
24
|
-
if (
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
|
|
33
|
+
if (existingValueImport) {
|
|
34
|
+
// Check if StyleSheet is already imported
|
|
35
|
+
const hasStyleSheet = existingValueImport.specifiers.some(
|
|
36
|
+
(spec) =>
|
|
37
|
+
t.isImportSpecifier(spec) &&
|
|
38
|
+
spec.imported.type === "Identifier" &&
|
|
39
|
+
spec.imported.name === "StyleSheet",
|
|
28
40
|
);
|
|
41
|
+
|
|
42
|
+
if (!hasStyleSheet) {
|
|
43
|
+
// Add StyleSheet to existing value import
|
|
44
|
+
existingValueImport.specifiers.push(
|
|
45
|
+
t.importSpecifier(t.identifier("StyleSheet"), t.identifier("StyleSheet")),
|
|
46
|
+
);
|
|
47
|
+
}
|
|
29
48
|
} else {
|
|
30
|
-
//
|
|
49
|
+
// No value import exists - create a new one
|
|
50
|
+
// (Don't merge with type-only or namespace imports)
|
|
31
51
|
const importDeclaration = t.importDeclaration(
|
|
32
52
|
[t.importSpecifier(t.identifier("StyleSheet"), t.identifier("StyleSheet"))],
|
|
33
53
|
t.stringLiteral("react-native"),
|
|
@@ -40,22 +60,42 @@ export function addStyleSheetImport(path: NodePath<BabelTypes.Program>, t: typeo
|
|
|
40
60
|
* Add Platform import to the file or merge with existing react-native import
|
|
41
61
|
*/
|
|
42
62
|
export function addPlatformImport(path: NodePath<BabelTypes.Program>, t: typeof BabelTypes): void {
|
|
43
|
-
// Check if there's already a react-native
|
|
63
|
+
// Check if there's already a value import from react-native
|
|
44
64
|
const body = path.node.body;
|
|
45
|
-
let
|
|
65
|
+
let existingValueImport: BabelTypes.ImportDeclaration | null = null;
|
|
46
66
|
|
|
47
67
|
for (const statement of body) {
|
|
48
68
|
if (t.isImportDeclaration(statement) && statement.source.value === "react-native") {
|
|
49
|
-
|
|
50
|
-
|
|
69
|
+
// Skip type-only imports (they get erased at runtime)
|
|
70
|
+
if (statement.importKind === "type") {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
// Skip namespace imports (import * as RN) - can't add named specifiers to them
|
|
74
|
+
const hasNamespaceImport = statement.specifiers.some((spec) => t.isImportNamespaceSpecifier(spec));
|
|
75
|
+
if (hasNamespaceImport) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
existingValueImport = statement;
|
|
79
|
+
break; // Found a value import, we can stop
|
|
51
80
|
}
|
|
52
81
|
}
|
|
53
82
|
|
|
54
|
-
if (
|
|
55
|
-
//
|
|
56
|
-
|
|
83
|
+
if (existingValueImport) {
|
|
84
|
+
// Check if Platform is already imported
|
|
85
|
+
const hasPlatform = existingValueImport.specifiers.some(
|
|
86
|
+
(spec) =>
|
|
87
|
+
t.isImportSpecifier(spec) && spec.imported.type === "Identifier" && spec.imported.name === "Platform",
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
if (!hasPlatform) {
|
|
91
|
+
// Add Platform to existing value import
|
|
92
|
+
existingValueImport.specifiers.push(
|
|
93
|
+
t.importSpecifier(t.identifier("Platform"), t.identifier("Platform")),
|
|
94
|
+
);
|
|
95
|
+
}
|
|
57
96
|
} else {
|
|
58
|
-
//
|
|
97
|
+
// No value import exists - create a new one
|
|
98
|
+
// (Don't merge with type-only or namespace imports)
|
|
59
99
|
const importDeclaration = t.importDeclaration(
|
|
60
100
|
[t.importSpecifier(t.identifier("Platform"), t.identifier("Platform"))],
|
|
61
101
|
t.stringLiteral("react-native"),
|
package/dist/parser/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type { StyleObject } from "../types";
|
|
|
9
9
|
export type CustomTheme = {
|
|
10
10
|
colors?: Record<string, string>;
|
|
11
11
|
fontFamily?: Record<string, string>;
|
|
12
|
+
fontSize?: Record<string, number>;
|
|
12
13
|
};
|
|
13
14
|
/**
|
|
14
15
|
* Parse a className string and return a React Native style object
|
package/dist/parser/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"expandSchemeModifier",{enumerable:true,get:function get(){return _modifiers.expandSchemeModifier;}});Object.defineProperty(exports,"hasModifier",{enumerable:true,get:function get(){return _modifiers.hasModifier;}});Object.defineProperty(exports,"isColorClass",{enumerable:true,get:function get(){return _modifiers.isColorClass;}});Object.defineProperty(exports,"isColorSchemeModifier",{enumerable:true,get:function get(){return _modifiers.isColorSchemeModifier;}});Object.defineProperty(exports,"isPlatformModifier",{enumerable:true,get:function get(){return _modifiers.isPlatformModifier;}});Object.defineProperty(exports,"isSchemeModifier",{enumerable:true,get:function get(){return _modifiers.isSchemeModifier;}});Object.defineProperty(exports,"isStateModifier",{enumerable:true,get:function get(){return _modifiers.isStateModifier;}});Object.defineProperty(exports,"parseAspectRatio",{enumerable:true,get:function get(){return _aspectRatio.parseAspectRatio;}});Object.defineProperty(exports,"parseBorder",{enumerable:true,get:function get(){return _borders.parseBorder;}});exports.parseClass=parseClass;exports.parseClassName=parseClassName;Object.defineProperty(exports,"parseColor",{enumerable:true,get:function get(){return _colors.parseColor;}});Object.defineProperty(exports,"parseLayout",{enumerable:true,get:function get(){return _layout.parseLayout;}});Object.defineProperty(exports,"parseModifier",{enumerable:true,get:function get(){return _modifiers.parseModifier;}});Object.defineProperty(exports,"parsePlaceholderClass",{enumerable:true,get:function get(){return _placeholder.parsePlaceholderClass;}});Object.defineProperty(exports,"parsePlaceholderClasses",{enumerable:true,get:function get(){return _placeholder.parsePlaceholderClasses;}});Object.defineProperty(exports,"parseShadow",{enumerable:true,get:function get(){return _shadows.parseShadow;}});Object.defineProperty(exports,"parseSizing",{enumerable:true,get:function get(){return _sizing.parseSizing;}});Object.defineProperty(exports,"parseSpacing",{enumerable:true,get:function get(){return _spacing.parseSpacing;}});Object.defineProperty(exports,"parseTransform",{enumerable:true,get:function get(){return _transforms.parseTransform;}});Object.defineProperty(exports,"parseTypography",{enumerable:true,get:function get(){return _typography.parseTypography;}});Object.defineProperty(exports,"splitModifierClasses",{enumerable:true,get:function get(){return _modifiers.splitModifierClasses;}});var _aspectRatio=require("./aspectRatio");var _borders=require("./borders");var _colors=require("./colors");var _layout=require("./layout");var _shadows=require("./shadows");var _sizing=require("./sizing");var _spacing=require("./spacing");var _transforms=require("./transforms");var _typography=require("./typography");var _placeholder=require("./placeholder");var _modifiers=require("./modifiers");function parseClassName(className,customTheme){var classes=className.split(/\s+/).filter(Boolean);var style={};for(var cls of classes){var parsedStyle=parseClass(cls,customTheme);Object.assign(style,parsedStyle);}return style;}function parseClass(cls,customTheme){var parsers=[_spacing.parseSpacing,_borders.parseBorder,function(cls){return(0,_colors.parseColor)(cls,customTheme==null?void 0:customTheme.colors);},_layout.parseLayout,function(cls){return(0,_typography.parseTypography)(cls,customTheme==null?void 0:customTheme.fontFamily);},_sizing.parseSizing,_shadows.parseShadow,_aspectRatio.parseAspectRatio,_transforms.parseTransform];for(var parser of parsers){var result=parser(cls);if(result!==null){return result;}}if(process.env.NODE_ENV!=="production"){console.warn(`[react-native-tailwind] Unknown class: "${cls}"`);}return{};}
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"expandSchemeModifier",{enumerable:true,get:function get(){return _modifiers.expandSchemeModifier;}});Object.defineProperty(exports,"hasModifier",{enumerable:true,get:function get(){return _modifiers.hasModifier;}});Object.defineProperty(exports,"isColorClass",{enumerable:true,get:function get(){return _modifiers.isColorClass;}});Object.defineProperty(exports,"isColorSchemeModifier",{enumerable:true,get:function get(){return _modifiers.isColorSchemeModifier;}});Object.defineProperty(exports,"isPlatformModifier",{enumerable:true,get:function get(){return _modifiers.isPlatformModifier;}});Object.defineProperty(exports,"isSchemeModifier",{enumerable:true,get:function get(){return _modifiers.isSchemeModifier;}});Object.defineProperty(exports,"isStateModifier",{enumerable:true,get:function get(){return _modifiers.isStateModifier;}});Object.defineProperty(exports,"parseAspectRatio",{enumerable:true,get:function get(){return _aspectRatio.parseAspectRatio;}});Object.defineProperty(exports,"parseBorder",{enumerable:true,get:function get(){return _borders.parseBorder;}});exports.parseClass=parseClass;exports.parseClassName=parseClassName;Object.defineProperty(exports,"parseColor",{enumerable:true,get:function get(){return _colors.parseColor;}});Object.defineProperty(exports,"parseLayout",{enumerable:true,get:function get(){return _layout.parseLayout;}});Object.defineProperty(exports,"parseModifier",{enumerable:true,get:function get(){return _modifiers.parseModifier;}});Object.defineProperty(exports,"parsePlaceholderClass",{enumerable:true,get:function get(){return _placeholder.parsePlaceholderClass;}});Object.defineProperty(exports,"parsePlaceholderClasses",{enumerable:true,get:function get(){return _placeholder.parsePlaceholderClasses;}});Object.defineProperty(exports,"parseShadow",{enumerable:true,get:function get(){return _shadows.parseShadow;}});Object.defineProperty(exports,"parseSizing",{enumerable:true,get:function get(){return _sizing.parseSizing;}});Object.defineProperty(exports,"parseSpacing",{enumerable:true,get:function get(){return _spacing.parseSpacing;}});Object.defineProperty(exports,"parseTransform",{enumerable:true,get:function get(){return _transforms.parseTransform;}});Object.defineProperty(exports,"parseTypography",{enumerable:true,get:function get(){return _typography.parseTypography;}});Object.defineProperty(exports,"splitModifierClasses",{enumerable:true,get:function get(){return _modifiers.splitModifierClasses;}});var _aspectRatio=require("./aspectRatio");var _borders=require("./borders");var _colors=require("./colors");var _layout=require("./layout");var _shadows=require("./shadows");var _sizing=require("./sizing");var _spacing=require("./spacing");var _transforms=require("./transforms");var _typography=require("./typography");var _placeholder=require("./placeholder");var _modifiers=require("./modifiers");function parseClassName(className,customTheme){var classes=className.split(/\s+/).filter(Boolean);var style={};for(var cls of classes){var parsedStyle=parseClass(cls,customTheme);Object.assign(style,parsedStyle);}return style;}function parseClass(cls,customTheme){var parsers=[_spacing.parseSpacing,_borders.parseBorder,function(cls){return(0,_colors.parseColor)(cls,customTheme==null?void 0:customTheme.colors);},_layout.parseLayout,function(cls){return(0,_typography.parseTypography)(cls,customTheme==null?void 0:customTheme.fontFamily,customTheme==null?void 0:customTheme.fontSize);},_sizing.parseSizing,_shadows.parseShadow,_aspectRatio.parseAspectRatio,_transforms.parseTransform];for(var parser of parsers){var result=parser(cls);if(result!==null){return result;}}if(process.env.NODE_ENV!=="production"){console.warn(`[react-native-tailwind] Unknown class: "${cls}"`);}return{};}
|
package/dist/parser/layout.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,"__esModule",{value:true});exports.Z_INDEX_SCALE=exports.INSET_SCALE=void 0;exports.parseLayout=parseLayout;function parseArbitraryInset(value){var pxMatch=value.match(/^\[(-?\d+)(?:px)?\]$/);if(pxMatch){return parseInt(pxMatch[1],10);}var percentMatch=value.match(/^\[(-?\d+(?:\.\d+)?)%\]$/);if(percentMatch){return`${percentMatch[1]}%`;}if(value.startsWith("[")&&value.endsWith("]")){if(process.env.NODE_ENV!=="production"){console.warn(`[react-native-tailwind] Unsupported arbitrary inset unit: ${value}. Only px and % are supported.`);}return null;}return null;}function parseArbitraryZIndex(value){var zMatch=value.match(/^\[(-?\d+)\]$/);if(zMatch){return parseInt(zMatch[1],10);}if(value.startsWith("[")&&value.endsWith("]")){if(process.env.NODE_ENV!=="production"){console.warn(`[react-native-tailwind] Invalid arbitrary z-index: ${value}. Only integers are supported.`);}return null;}return null;}var DISPLAY_MAP={flex:{display:"flex"},hidden:{display:"none"}};var FLEX_DIRECTION_MAP={"flex-row":{flexDirection:"row"},"flex-row-reverse":{flexDirection:"row-reverse"},"flex-col":{flexDirection:"column"},"flex-col-reverse":{flexDirection:"column-reverse"}};var FLEX_WRAP_MAP={"flex-wrap":{flexWrap:"wrap"},"flex-wrap-reverse":{flexWrap:"wrap-reverse"},"flex-nowrap":{flexWrap:"nowrap"}};var FLEX_MAP={"flex-1":{flex:1},"flex-auto":{flex:1},"flex-none":{flex:0}};var GROW_SHRINK_MAP={grow:{flexGrow:1},"grow-0":{flexGrow:0},shrink:{flexShrink:1},"shrink-0":{flexShrink:0}};var JUSTIFY_CONTENT_MAP={"justify-start":{justifyContent:"flex-start"},"justify-end":{justifyContent:"flex-end"},"justify-center":{justifyContent:"center"},"justify-between":{justifyContent:"space-between"},"justify-around":{justifyContent:"space-around"},"justify-evenly":{justifyContent:"space-evenly"}};var ALIGN_ITEMS_MAP={"items-start":{alignItems:"flex-start"},"items-end":{alignItems:"flex-end"},"items-center":{alignItems:"center"},"items-baseline":{alignItems:"baseline"},"items-stretch":{alignItems:"stretch"}};var ALIGN_SELF_MAP={"self-auto":{alignSelf:"auto"},"self-start":{alignSelf:"flex-start"},"self-end":{alignSelf:"flex-end"},"self-center":{alignSelf:"center"},"self-stretch":{alignSelf:"stretch"},"self-baseline":{alignSelf:"baseline"}};var ALIGN_CONTENT_MAP={"content-start":{alignContent:"flex-start"},"content-end":{alignContent:"flex-end"},"content-center":{alignContent:"center"},"content-between":{alignContent:"space-between"},"content-around":{alignContent:"space-around"},"content-stretch":{alignContent:"stretch"}};var POSITION_MAP={absolute:{position:"absolute"},relative:{position:"relative"}};var OVERFLOW_MAP={"overflow-hidden":{overflow:"hidden"},"overflow-visible":{overflow:"visible"},"overflow-scroll":{overflow:"scroll"}};var OPACITY_MAP={"opacity-0":{opacity:0},"opacity-5":{opacity:0.05},"opacity-10":{opacity:0.1},"opacity-15":{opacity:0.15},"opacity-20":{opacity:0.2},"opacity-25":{opacity:0.25},"opacity-30":{opacity:0.3},"opacity-35":{opacity:0.35},"opacity-40":{opacity:0.4},"opacity-45":{opacity:0.45},"opacity-50":{opacity:0.5},"opacity-55":{opacity:0.55},"opacity-60":{opacity:0.6},"opacity-65":{opacity:0.65},"opacity-70":{opacity:0.7},"opacity-75":{opacity:0.75},"opacity-80":{opacity:0.8},"opacity-85":{opacity:0.85},"opacity-90":{opacity:0.9},"opacity-95":{opacity:0.95},"opacity-100":{opacity:1}};var Z_INDEX_SCALE=exports.Z_INDEX_SCALE={0:0,10:10,20:20,30:30,40:40,50:50,auto:0};var INSET_SCALE=exports.INSET_SCALE={0:0,0.5:2,1:4,1.5:6,2:8,2.5:10,3:12,3.5:14,4:16,5:20,6:24,8:32,10:40,12:48,16:64,20:80,24:96};function parseLayout(cls){var _ref,_ref2,_ref3,_ref4,_ref5,_ref6,_ref7,_ref8,_ref9,_ref0,_ref1,_DISPLAY_MAP$cls;if(cls.startsWith("z-")){var zKey=cls.substring(2);var arbitraryZ=parseArbitraryZIndex(zKey);if(arbitraryZ!==null){return{zIndex:arbitraryZ};}var zValue=Z_INDEX_SCALE[zKey];if(zValue!==undefined){return{zIndex:zValue};}}if(cls.startsWith("top-")){var topKey=cls.substring(4);if(topKey==="auto"){return{};}var arbitraryTop=parseArbitraryInset(topKey);if(arbitraryTop!==null){return{top:arbitraryTop};}var topValue=INSET_SCALE[topKey];if(topValue!==undefined){return{top:topValue};}}if(cls.startsWith("right-")){var rightKey=cls.substring(6);if(rightKey==="auto"){return{};}var arbitraryRight=parseArbitraryInset(rightKey);if(arbitraryRight!==null){return{right:arbitraryRight};}var rightValue=INSET_SCALE[rightKey];if(rightValue!==undefined){return{right:rightValue};}}if(cls.startsWith("bottom-")){var bottomKey=cls.substring(7);if(bottomKey==="auto"){return{};}var arbitraryBottom=parseArbitraryInset(bottomKey);if(arbitraryBottom!==null){return{bottom:arbitraryBottom};}var bottomValue=INSET_SCALE[bottomKey];if(bottomValue!==undefined){return{bottom:bottomValue};}}if(cls.startsWith("left-")){var leftKey=cls.substring(5);if(leftKey==="auto"){return{};}var arbitraryLeft=parseArbitraryInset(leftKey);if(arbitraryLeft!==null){return{left:arbitraryLeft};}var leftValue=INSET_SCALE[leftKey];if(leftValue!==undefined){return{left:leftValue};}}if(cls.startsWith("inset-x-")){var insetKey=cls.substring(8);var arbitraryInset=parseArbitraryInset(insetKey);if(arbitraryInset!==null){return{left:arbitraryInset,right:arbitraryInset};}var insetValue=INSET_SCALE[insetKey];if(insetValue!==undefined){return{left:insetValue,right:insetValue};}}if(cls.startsWith("inset-y-")){var _insetKey=cls.substring(8);var _arbitraryInset=parseArbitraryInset(_insetKey);if(_arbitraryInset!==null){return{top:_arbitraryInset,bottom:_arbitraryInset};}var _insetValue=INSET_SCALE[_insetKey];if(_insetValue!==undefined){return{top:_insetValue,bottom:_insetValue};}}if(cls.startsWith("inset-")){var _insetKey2=cls.substring(6);var _arbitraryInset2=parseArbitraryInset(_insetKey2);if(_arbitraryInset2!==null){return{top:_arbitraryInset2,right:_arbitraryInset2,bottom:_arbitraryInset2,left:_arbitraryInset2};}var _insetValue2=INSET_SCALE[_insetKey2];if(_insetValue2!==undefined){return{top:_insetValue2,right:_insetValue2,bottom:_insetValue2,left:_insetValue2};}}return(_ref=(_ref2=(_ref3=(_ref4=(_ref5=(_ref6=(_ref7=(_ref8=(_ref9=(_ref0=(_ref1=(_DISPLAY_MAP$cls=DISPLAY_MAP[cls])!=null?_DISPLAY_MAP$cls:FLEX_DIRECTION_MAP[cls])!=null?_ref1:FLEX_WRAP_MAP[cls])!=null?_ref0:FLEX_MAP[cls])!=null?_ref9:GROW_SHRINK_MAP[cls])!=null?_ref8:JUSTIFY_CONTENT_MAP[cls])!=null?_ref7:ALIGN_ITEMS_MAP[cls])!=null?_ref6:ALIGN_SELF_MAP[cls])!=null?_ref5:ALIGN_CONTENT_MAP[cls])!=null?_ref4:POSITION_MAP[cls])!=null?_ref3:OVERFLOW_MAP[cls])!=null?_ref2:OPACITY_MAP[cls])!=null?_ref:null;}
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:true});exports.Z_INDEX_SCALE=exports.INSET_SCALE=void 0;exports.parseLayout=parseLayout;function parseArbitraryInset(value){var pxMatch=value.match(/^\[(-?\d+)(?:px)?\]$/);if(pxMatch){return parseInt(pxMatch[1],10);}var percentMatch=value.match(/^\[(-?\d+(?:\.\d+)?)%\]$/);if(percentMatch){return`${percentMatch[1]}%`;}if(value.startsWith("[")&&value.endsWith("]")){if(process.env.NODE_ENV!=="production"){console.warn(`[react-native-tailwind] Unsupported arbitrary inset unit: ${value}. Only px and % are supported.`);}return null;}return null;}function parseArbitraryZIndex(value){var zMatch=value.match(/^\[(-?\d+)\]$/);if(zMatch){return parseInt(zMatch[1],10);}if(value.startsWith("[")&&value.endsWith("]")){if(process.env.NODE_ENV!=="production"){console.warn(`[react-native-tailwind] Invalid arbitrary z-index: ${value}. Only integers are supported.`);}return null;}return null;}function parseArbitraryGrowShrink(value){var match=value.match(/^\[(\d+(?:\.\d+)?|\.\d+)\]$/);if(match){return parseFloat(match[1]);}if(value.startsWith("[")&&value.endsWith("]")){if(process.env.NODE_ENV!=="production"){console.warn(`[react-native-tailwind] Invalid arbitrary grow/shrink value: ${value}. Only non-negative numbers are supported (e.g., [1.5], [2], [0.5], [.5]).`);}return null;}return null;}var DISPLAY_MAP={flex:{display:"flex"},hidden:{display:"none"}};var FLEX_DIRECTION_MAP={"flex-row":{flexDirection:"row"},"flex-row-reverse":{flexDirection:"row-reverse"},"flex-col":{flexDirection:"column"},"flex-col-reverse":{flexDirection:"column-reverse"}};var FLEX_WRAP_MAP={"flex-wrap":{flexWrap:"wrap"},"flex-wrap-reverse":{flexWrap:"wrap-reverse"},"flex-nowrap":{flexWrap:"nowrap"}};var FLEX_MAP={"flex-1":{flex:1},"flex-auto":{flex:1},"flex-none":{flex:0}};var GROW_SHRINK_MAP={grow:{flexGrow:1},"grow-0":{flexGrow:0},shrink:{flexShrink:1},"shrink-0":{flexShrink:0},"flex-grow":{flexGrow:1},"flex-grow-0":{flexGrow:0},"flex-shrink":{flexShrink:1},"flex-shrink-0":{flexShrink:0}};var JUSTIFY_CONTENT_MAP={"justify-start":{justifyContent:"flex-start"},"justify-end":{justifyContent:"flex-end"},"justify-center":{justifyContent:"center"},"justify-between":{justifyContent:"space-between"},"justify-around":{justifyContent:"space-around"},"justify-evenly":{justifyContent:"space-evenly"}};var ALIGN_ITEMS_MAP={"items-start":{alignItems:"flex-start"},"items-end":{alignItems:"flex-end"},"items-center":{alignItems:"center"},"items-baseline":{alignItems:"baseline"},"items-stretch":{alignItems:"stretch"}};var ALIGN_SELF_MAP={"self-auto":{alignSelf:"auto"},"self-start":{alignSelf:"flex-start"},"self-end":{alignSelf:"flex-end"},"self-center":{alignSelf:"center"},"self-stretch":{alignSelf:"stretch"},"self-baseline":{alignSelf:"baseline"}};var ALIGN_CONTENT_MAP={"content-start":{alignContent:"flex-start"},"content-end":{alignContent:"flex-end"},"content-center":{alignContent:"center"},"content-between":{alignContent:"space-between"},"content-around":{alignContent:"space-around"},"content-stretch":{alignContent:"stretch"}};var POSITION_MAP={absolute:{position:"absolute"},relative:{position:"relative"}};var OVERFLOW_MAP={"overflow-hidden":{overflow:"hidden"},"overflow-visible":{overflow:"visible"},"overflow-scroll":{overflow:"scroll"}};var OPACITY_MAP={"opacity-0":{opacity:0},"opacity-5":{opacity:0.05},"opacity-10":{opacity:0.1},"opacity-15":{opacity:0.15},"opacity-20":{opacity:0.2},"opacity-25":{opacity:0.25},"opacity-30":{opacity:0.3},"opacity-35":{opacity:0.35},"opacity-40":{opacity:0.4},"opacity-45":{opacity:0.45},"opacity-50":{opacity:0.5},"opacity-55":{opacity:0.55},"opacity-60":{opacity:0.6},"opacity-65":{opacity:0.65},"opacity-70":{opacity:0.7},"opacity-75":{opacity:0.75},"opacity-80":{opacity:0.8},"opacity-85":{opacity:0.85},"opacity-90":{opacity:0.9},"opacity-95":{opacity:0.95},"opacity-100":{opacity:1}};var Z_INDEX_SCALE=exports.Z_INDEX_SCALE={0:0,10:10,20:20,30:30,40:40,50:50,auto:0};var INSET_SCALE=exports.INSET_SCALE={0:0,0.5:2,1:4,1.5:6,2:8,2.5:10,3:12,3.5:14,4:16,5:20,6:24,8:32,10:40,12:48,16:64,20:80,24:96};function parseLayout(cls){var _ref,_ref2,_ref3,_ref4,_ref5,_ref6,_ref7,_ref8,_ref9,_ref0,_ref1,_DISPLAY_MAP$cls;if(cls.startsWith("z-")){var zKey=cls.substring(2);var arbitraryZ=parseArbitraryZIndex(zKey);if(arbitraryZ!==null){return{zIndex:arbitraryZ};}var zValue=Z_INDEX_SCALE[zKey];if(zValue!==undefined){return{zIndex:zValue};}}if(cls.startsWith("top-")){var topKey=cls.substring(4);if(topKey==="auto"){return{};}var arbitraryTop=parseArbitraryInset(topKey);if(arbitraryTop!==null){return{top:arbitraryTop};}var topValue=INSET_SCALE[topKey];if(topValue!==undefined){return{top:topValue};}}if(cls.startsWith("right-")){var rightKey=cls.substring(6);if(rightKey==="auto"){return{};}var arbitraryRight=parseArbitraryInset(rightKey);if(arbitraryRight!==null){return{right:arbitraryRight};}var rightValue=INSET_SCALE[rightKey];if(rightValue!==undefined){return{right:rightValue};}}if(cls.startsWith("bottom-")){var bottomKey=cls.substring(7);if(bottomKey==="auto"){return{};}var arbitraryBottom=parseArbitraryInset(bottomKey);if(arbitraryBottom!==null){return{bottom:arbitraryBottom};}var bottomValue=INSET_SCALE[bottomKey];if(bottomValue!==undefined){return{bottom:bottomValue};}}if(cls.startsWith("left-")){var leftKey=cls.substring(5);if(leftKey==="auto"){return{};}var arbitraryLeft=parseArbitraryInset(leftKey);if(arbitraryLeft!==null){return{left:arbitraryLeft};}var leftValue=INSET_SCALE[leftKey];if(leftValue!==undefined){return{left:leftValue};}}if(cls.startsWith("inset-x-")){var insetKey=cls.substring(8);var arbitraryInset=parseArbitraryInset(insetKey);if(arbitraryInset!==null){return{left:arbitraryInset,right:arbitraryInset};}var insetValue=INSET_SCALE[insetKey];if(insetValue!==undefined){return{left:insetValue,right:insetValue};}}if(cls.startsWith("inset-y-")){var _insetKey=cls.substring(8);var _arbitraryInset=parseArbitraryInset(_insetKey);if(_arbitraryInset!==null){return{top:_arbitraryInset,bottom:_arbitraryInset};}var _insetValue=INSET_SCALE[_insetKey];if(_insetValue!==undefined){return{top:_insetValue,bottom:_insetValue};}}if(cls.startsWith("inset-")){var _insetKey2=cls.substring(6);var _arbitraryInset2=parseArbitraryInset(_insetKey2);if(_arbitraryInset2!==null){return{top:_arbitraryInset2,right:_arbitraryInset2,bottom:_arbitraryInset2,left:_arbitraryInset2};}var _insetValue2=INSET_SCALE[_insetKey2];if(_insetValue2!==undefined){return{top:_insetValue2,right:_insetValue2,bottom:_insetValue2,left:_insetValue2};}}if(cls.startsWith("grow-")||cls.startsWith("flex-grow-")){var prefix=cls.startsWith("flex-grow-")?"flex-grow-":"grow-";var growKey=cls.substring(prefix.length);var arbitraryGrow=parseArbitraryGrowShrink(growKey);if(arbitraryGrow!==null){return{flexGrow:arbitraryGrow};}}if(cls.startsWith("shrink-")||cls.startsWith("flex-shrink-")){var _prefix=cls.startsWith("flex-shrink-")?"flex-shrink-":"shrink-";var shrinkKey=cls.substring(_prefix.length);var arbitraryShrink=parseArbitraryGrowShrink(shrinkKey);if(arbitraryShrink!==null){return{flexShrink:arbitraryShrink};}}return(_ref=(_ref2=(_ref3=(_ref4=(_ref5=(_ref6=(_ref7=(_ref8=(_ref9=(_ref0=(_ref1=(_DISPLAY_MAP$cls=DISPLAY_MAP[cls])!=null?_DISPLAY_MAP$cls:FLEX_DIRECTION_MAP[cls])!=null?_ref1:FLEX_WRAP_MAP[cls])!=null?_ref0:FLEX_MAP[cls])!=null?_ref9:GROW_SHRINK_MAP[cls])!=null?_ref8:JUSTIFY_CONTENT_MAP[cls])!=null?_ref7:ALIGN_ITEMS_MAP[cls])!=null?_ref6:ALIGN_SELF_MAP[cls])!=null?_ref5:ALIGN_CONTENT_MAP[cls])!=null?_ref4:POSITION_MAP[cls])!=null?_ref3:OVERFLOW_MAP[cls])!=null?_ref2:OPACITY_MAP[cls])!=null?_ref:null;}
|