@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
package/src/parser/typography.ts
CHANGED
|
@@ -113,14 +113,14 @@ const TRACKING_MAP: Record<string, StyleObject> = {
|
|
|
113
113
|
};
|
|
114
114
|
|
|
115
115
|
/**
|
|
116
|
-
* Parse arbitrary font size value: [18px], [20]
|
|
117
|
-
* Returns number for px values, null for unsupported formats
|
|
116
|
+
* Parse arbitrary font size value: [18px], [20], [13.5px], [.5]
|
|
117
|
+
* Returns number for px values (including decimals), null for unsupported formats
|
|
118
118
|
*/
|
|
119
119
|
function parseArbitraryFontSize(value: string): number | null {
|
|
120
|
-
// Match: [18px]
|
|
121
|
-
const pxMatch = value.match(/^\[(
|
|
120
|
+
// Match: [18px], [18], [13.5px], [13.5], [.5] (pixels, including decimals)
|
|
121
|
+
const pxMatch = value.match(/^\[(-?\d+(?:\.\d+)?|-?\.\d+)(?:px)?\]$/);
|
|
122
122
|
if (pxMatch) {
|
|
123
|
-
return
|
|
123
|
+
return parseFloat(pxMatch[1]);
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
// Warn about unsupported formats
|
|
@@ -128,7 +128,7 @@ function parseArbitraryFontSize(value: string): number | null {
|
|
|
128
128
|
/* v8 ignore next 5 */
|
|
129
129
|
if (process.env.NODE_ENV !== "production") {
|
|
130
130
|
console.warn(
|
|
131
|
-
`[react-native-tailwind] Unsupported arbitrary font size value: ${value}. Only px values are supported (e.g., [18px]
|
|
131
|
+
`[react-native-tailwind] Unsupported arbitrary font size value: ${value}. Only px values are supported (e.g., [18px], [13.5px], [.5]).`,
|
|
132
132
|
);
|
|
133
133
|
}
|
|
134
134
|
return null;
|
|
@@ -138,14 +138,14 @@ function parseArbitraryFontSize(value: string): number | null {
|
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
/**
|
|
141
|
-
* Parse arbitrary line height value: [24px], [28]
|
|
142
|
-
* Returns number for px values, null for unsupported formats
|
|
141
|
+
* Parse arbitrary line height value: [24px], [28], [21.5px], [.5]
|
|
142
|
+
* Returns number for px values (including decimals), null for unsupported formats
|
|
143
143
|
*/
|
|
144
144
|
function parseArbitraryLineHeight(value: string): number | null {
|
|
145
|
-
// Match: [24px]
|
|
146
|
-
const pxMatch = value.match(/^\[(
|
|
145
|
+
// Match: [24px], [24], [21.5px], [21.5], [.5] (pixels, including decimals)
|
|
146
|
+
const pxMatch = value.match(/^\[(-?\d+(?:\.\d+)?|-?\.\d+)(?:px)?\]$/);
|
|
147
147
|
if (pxMatch) {
|
|
148
|
-
return
|
|
148
|
+
return parseFloat(pxMatch[1]);
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
// Warn about unsupported formats
|
|
@@ -153,7 +153,32 @@ function parseArbitraryLineHeight(value: string): number | null {
|
|
|
153
153
|
/* v8 ignore next 5 */
|
|
154
154
|
if (process.env.NODE_ENV !== "production") {
|
|
155
155
|
console.warn(
|
|
156
|
-
`[react-native-tailwind] Unsupported arbitrary line height value: ${value}. Only px values are supported (e.g., [24px]
|
|
156
|
+
`[react-native-tailwind] Unsupported arbitrary line height value: ${value}. Only px values are supported (e.g., [24px], [21.5px], [.5]).`,
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Parse arbitrary letter spacing value: [0.5px], [0.3], [.5], [-0.4]
|
|
167
|
+
* Returns number for px values (including decimals), null for unsupported formats
|
|
168
|
+
*/
|
|
169
|
+
function parseArbitraryLetterSpacing(value: string): number | null {
|
|
170
|
+
// Match: [0.5px], [0.3], [.5], [-0.4px] (pixels, including decimals and negatives)
|
|
171
|
+
const pxMatch = value.match(/^\[(-?\d+(?:\.\d+)?|-?\.\d+)(?:px)?\]$/);
|
|
172
|
+
if (pxMatch) {
|
|
173
|
+
return parseFloat(pxMatch[1]);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Warn about unsupported formats
|
|
177
|
+
if (value.startsWith("[") && value.endsWith("]")) {
|
|
178
|
+
/* v8 ignore next 5 */
|
|
179
|
+
if (process.env.NODE_ENV !== "production") {
|
|
180
|
+
console.warn(
|
|
181
|
+
`[react-native-tailwind] Unsupported arbitrary letter spacing value: ${value}. Only px values are supported (e.g., [0.5px], [0.3], [.5], [-0.4]).`,
|
|
157
182
|
);
|
|
158
183
|
}
|
|
159
184
|
return null;
|
|
@@ -166,8 +191,13 @@ function parseArbitraryLineHeight(value: string): number | null {
|
|
|
166
191
|
* Parse typography classes
|
|
167
192
|
* @param cls - Class name to parse
|
|
168
193
|
* @param customFontFamily - Optional custom fontFamily from tailwind.config
|
|
194
|
+
* @param customFontSize - Optional custom fontSize from tailwind.config
|
|
169
195
|
*/
|
|
170
|
-
export function parseTypography(
|
|
196
|
+
export function parseTypography(
|
|
197
|
+
cls: string,
|
|
198
|
+
customFontFamily?: Record<string, string>,
|
|
199
|
+
customFontSize?: Record<string, number>,
|
|
200
|
+
): StyleObject | null {
|
|
171
201
|
// Merge custom fontFamily with defaults (custom takes precedence)
|
|
172
202
|
const fontFamilyMap = customFontFamily
|
|
173
203
|
? {
|
|
@@ -182,13 +212,18 @@ export function parseTypography(cls: string, customFontFamily?: Record<string, s
|
|
|
182
212
|
if (cls.startsWith("text-")) {
|
|
183
213
|
const sizeKey = cls.substring(5);
|
|
184
214
|
|
|
185
|
-
// Try arbitrary value first
|
|
215
|
+
// Try arbitrary value first (highest priority)
|
|
186
216
|
const arbitraryValue = parseArbitraryFontSize(sizeKey);
|
|
187
217
|
if (arbitraryValue !== null) {
|
|
188
218
|
return { fontSize: arbitraryValue };
|
|
189
219
|
}
|
|
190
220
|
|
|
191
|
-
// Try
|
|
221
|
+
// Try custom fontSize from config
|
|
222
|
+
if (customFontSize?.[sizeKey] !== undefined) {
|
|
223
|
+
return { fontSize: customFontSize[sizeKey] };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Try preset scale (fallback)
|
|
192
227
|
const fontSize = FONT_SIZES[sizeKey];
|
|
193
228
|
if (fontSize !== undefined) {
|
|
194
229
|
return { fontSize };
|
|
@@ -212,6 +247,17 @@ export function parseTypography(cls: string, customFontFamily?: Record<string, s
|
|
|
212
247
|
}
|
|
213
248
|
}
|
|
214
249
|
|
|
250
|
+
// Letter spacing: tracking-wide, tracking-[0.5px], tracking-[.3], etc.
|
|
251
|
+
if (cls.startsWith("tracking-")) {
|
|
252
|
+
const trackingKey = cls.substring(9);
|
|
253
|
+
|
|
254
|
+
// Try arbitrary value first
|
|
255
|
+
const arbitraryValue = parseArbitraryLetterSpacing(trackingKey);
|
|
256
|
+
if (arbitraryValue !== null) {
|
|
257
|
+
return { letterSpacing: arbitraryValue };
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
215
261
|
// Try each lookup table in order
|
|
216
262
|
return (
|
|
217
263
|
fontFamilyMap[cls] ??
|