@mgcrea/react-native-tailwind 0.11.1 → 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.
Files changed (41) hide show
  1. package/dist/babel/config-loader.d.ts +3 -0
  2. package/dist/babel/config-loader.test.ts +2 -2
  3. package/dist/babel/config-loader.ts +37 -2
  4. package/dist/babel/index.cjs +325 -42
  5. package/dist/babel/plugin.test.ts +498 -0
  6. package/dist/babel/plugin.ts +66 -17
  7. package/dist/babel/utils/styleInjection.ts +57 -17
  8. package/dist/babel/utils/twProcessing.d.ts +8 -1
  9. package/dist/babel/utils/twProcessing.ts +212 -4
  10. package/dist/parser/index.d.ts +1 -0
  11. package/dist/parser/index.js +1 -1
  12. package/dist/parser/layout.js +1 -1
  13. package/dist/parser/layout.test.js +1 -1
  14. package/dist/parser/spacing.d.ts +1 -1
  15. package/dist/parser/spacing.js +1 -1
  16. package/dist/parser/spacing.test.js +1 -1
  17. package/dist/parser/typography.d.ts +2 -1
  18. package/dist/parser/typography.js +1 -1
  19. package/dist/parser/typography.test.js +1 -1
  20. package/dist/runtime.cjs +1 -1
  21. package/dist/runtime.cjs.map +3 -3
  22. package/dist/runtime.js +1 -1
  23. package/dist/runtime.js.map +3 -3
  24. package/dist/runtime.test.js +1 -1
  25. package/dist/types/runtime.d.ts +8 -1
  26. package/package.json +1 -1
  27. package/src/babel/config-loader.test.ts +2 -2
  28. package/src/babel/config-loader.ts +37 -2
  29. package/src/babel/plugin.test.ts +498 -0
  30. package/src/babel/plugin.ts +66 -17
  31. package/src/babel/utils/styleInjection.ts +57 -17
  32. package/src/babel/utils/twProcessing.ts +212 -4
  33. package/src/parser/index.ts +2 -1
  34. package/src/parser/layout.test.ts +61 -0
  35. package/src/parser/layout.ts +55 -1
  36. package/src/parser/spacing.test.ts +62 -0
  37. package/src/parser/spacing.ts +7 -7
  38. package/src/parser/typography.test.ts +102 -0
  39. package/src/parser/typography.ts +61 -15
  40. package/src/runtime.test.ts +4 -1
  41. package/src/types/runtime.ts +8 -1
@@ -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
  }