@mgcrea/react-native-tailwind 0.13.0 → 0.15.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/README.md +33 -30
- package/dist/babel/config-loader.d.ts +10 -0
- package/dist/babel/config-loader.test.ts +75 -21
- package/dist/babel/config-loader.ts +100 -2
- package/dist/babel/index.cjs +439 -46
- package/dist/babel/plugin/state.d.ts +4 -0
- package/dist/babel/plugin/state.ts +8 -0
- package/dist/babel/plugin/visitors/className.test.ts +313 -0
- package/dist/babel/plugin/visitors/className.ts +36 -8
- package/dist/babel/plugin/visitors/imports.ts +16 -1
- package/dist/babel/plugin/visitors/program.ts +19 -2
- package/dist/babel/plugin/visitors/tw.test.ts +151 -0
- package/dist/babel/utils/directionalModifierProcessing.d.ts +34 -0
- package/dist/babel/utils/directionalModifierProcessing.ts +99 -0
- package/dist/babel/utils/styleInjection.d.ts +16 -0
- package/dist/babel/utils/styleInjection.ts +138 -7
- package/dist/babel/utils/twProcessing.d.ts +2 -0
- package/dist/babel/utils/twProcessing.ts +92 -3
- package/dist/parser/borders.js +1 -1
- package/dist/parser/borders.test.js +1 -1
- package/dist/parser/index.d.ts +3 -2
- package/dist/parser/index.js +1 -1
- package/dist/parser/layout.d.ts +3 -1
- package/dist/parser/layout.js +1 -1
- package/dist/parser/layout.test.js +1 -1
- package/dist/parser/modifiers.d.ts +32 -2
- package/dist/parser/modifiers.js +1 -1
- package/dist/parser/modifiers.test.js +1 -1
- package/dist/parser/sizing.d.ts +3 -1
- package/dist/parser/sizing.js +1 -1
- package/dist/parser/sizing.test.js +1 -1
- package/dist/parser/spacing.d.ts +4 -2
- package/dist/parser/spacing.js +1 -1
- package/dist/parser/spacing.test.js +1 -1
- package/dist/parser/transforms.d.ts +3 -1
- package/dist/parser/transforms.js +1 -1
- package/dist/parser/transforms.test.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.d.ts +2 -0
- package/dist/runtime.js +1 -1
- package/dist/runtime.js.map +3 -3
- package/dist/runtime.test.js +1 -1
- package/package.json +6 -6
- package/src/babel/config-loader.test.ts +75 -21
- package/src/babel/config-loader.ts +100 -2
- package/src/babel/plugin/state.ts +8 -0
- package/src/babel/plugin/visitors/className.test.ts +313 -0
- package/src/babel/plugin/visitors/className.ts +36 -8
- package/src/babel/plugin/visitors/imports.ts +16 -1
- package/src/babel/plugin/visitors/program.ts +19 -2
- package/src/babel/plugin/visitors/tw.test.ts +151 -0
- package/src/babel/utils/directionalModifierProcessing.ts +99 -0
- package/src/babel/utils/styleInjection.ts +138 -7
- package/src/babel/utils/twProcessing.ts +92 -3
- package/src/parser/borders.test.ts +104 -0
- package/src/parser/borders.ts +50 -7
- package/src/parser/index.ts +8 -5
- package/src/parser/layout.test.ts +168 -0
- package/src/parser/layout.ts +107 -8
- package/src/parser/modifiers.test.ts +206 -0
- package/src/parser/modifiers.ts +62 -3
- package/src/parser/sizing.test.ts +56 -0
- package/src/parser/sizing.ts +20 -15
- package/src/parser/spacing.test.ts +123 -0
- package/src/parser/spacing.ts +30 -15
- package/src/parser/transforms.test.ts +57 -0
- package/src/parser/transforms.ts +7 -3
- package/src/parser/typography.test.ts +8 -0
- package/src/parser/typography.ts +4 -0
- package/src/runtime.test.ts +149 -0
- package/src/runtime.ts +53 -1
package/dist/babel/index.cjs
CHANGED
|
@@ -53,6 +53,40 @@ function flattenColors(colors, prefix = "") {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
// src/babel/config-loader.ts
|
|
56
|
+
var SUPPORTED_THEME_KEYS = /* @__PURE__ */ new Set(["colors", "fontFamily", "fontSize", "spacing", "extend"]);
|
|
57
|
+
var warnedConfigPaths = /* @__PURE__ */ new Set();
|
|
58
|
+
function warnUnsupportedThemeKeys(config, configPath) {
|
|
59
|
+
if (process.env.NODE_ENV === "production" || warnedConfigPaths.has(configPath)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const unsupportedKeys = [];
|
|
63
|
+
if (config.theme?.extend && typeof config.theme.extend === "object") {
|
|
64
|
+
for (const key of Object.keys(config.theme.extend)) {
|
|
65
|
+
if (!SUPPORTED_THEME_KEYS.has(key)) {
|
|
66
|
+
unsupportedKeys.push(`theme.extend.${key}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (config.theme && typeof config.theme === "object") {
|
|
71
|
+
for (const key of Object.keys(config.theme)) {
|
|
72
|
+
if (key !== "extend" && !SUPPORTED_THEME_KEYS.has(key)) {
|
|
73
|
+
unsupportedKeys.push(`theme.${key}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (unsupportedKeys.length > 0) {
|
|
78
|
+
warnedConfigPaths.add(configPath);
|
|
79
|
+
console.warn(
|
|
80
|
+
`[react-native-tailwind] Unsupported theme configuration detected:
|
|
81
|
+
${unsupportedKeys.join(", ")}
|
|
82
|
+
|
|
83
|
+
Currently supported: colors, fontFamily, fontSize, spacing
|
|
84
|
+
|
|
85
|
+
These extensions will be ignored. If you need support for these features,
|
|
86
|
+
please open an issue: https://github.com/mgcrea/react-native-tailwind/issues/new`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
56
90
|
var configCache = /* @__PURE__ */ new Map();
|
|
57
91
|
function findTailwindConfig(startDir) {
|
|
58
92
|
let currentDir = startDir;
|
|
@@ -97,12 +131,13 @@ function extractCustomTheme(filename) {
|
|
|
97
131
|
const projectDir = path.dirname(filename);
|
|
98
132
|
const configPath = findTailwindConfig(projectDir);
|
|
99
133
|
if (!configPath) {
|
|
100
|
-
return { colors: {}, fontFamily: {}, fontSize: {} };
|
|
134
|
+
return { colors: {}, fontFamily: {}, fontSize: {}, spacing: {} };
|
|
101
135
|
}
|
|
102
136
|
const config = loadTailwindConfig(configPath);
|
|
103
137
|
if (!config?.theme) {
|
|
104
|
-
return { colors: {}, fontFamily: {}, fontSize: {} };
|
|
138
|
+
return { colors: {}, fontFamily: {}, fontSize: {}, spacing: {} };
|
|
105
139
|
}
|
|
140
|
+
warnUnsupportedThemeKeys(config, configPath);
|
|
106
141
|
if (config.theme.colors && !config.theme.extend?.colors && process.env.NODE_ENV !== "production") {
|
|
107
142
|
console.warn(
|
|
108
143
|
"[react-native-tailwind] Using theme.colors will override all default colors. Use theme.extend.colors to add custom colors while keeping defaults."
|
|
@@ -146,10 +181,39 @@ function extractCustomTheme(filename) {
|
|
|
146
181
|
}
|
|
147
182
|
}
|
|
148
183
|
}
|
|
184
|
+
if (config.theme.spacing && !config.theme.extend?.spacing && process.env.NODE_ENV !== "production") {
|
|
185
|
+
console.warn(
|
|
186
|
+
"[react-native-tailwind] Using theme.spacing will override all default spacing. Use theme.extend.spacing to add custom spacing while keeping defaults."
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
const spacing = config.theme.extend?.spacing ?? config.theme.spacing ?? {};
|
|
190
|
+
const spacingResult = {};
|
|
191
|
+
for (const [key, value] of Object.entries(spacing)) {
|
|
192
|
+
if (typeof value === "number") {
|
|
193
|
+
spacingResult[key] = value;
|
|
194
|
+
} else if (typeof value === "string") {
|
|
195
|
+
let parsed;
|
|
196
|
+
if (value.endsWith("rem")) {
|
|
197
|
+
parsed = parseFloat(value.replace(/rem$/, "")) * 16;
|
|
198
|
+
} else {
|
|
199
|
+
parsed = parseFloat(value.replace(/px$/, ""));
|
|
200
|
+
}
|
|
201
|
+
if (!isNaN(parsed)) {
|
|
202
|
+
spacingResult[key] = parsed;
|
|
203
|
+
} else {
|
|
204
|
+
if (process.env.NODE_ENV !== "production") {
|
|
205
|
+
console.warn(
|
|
206
|
+
`[react-native-tailwind] Invalid spacing value for "${key}": ${value}. Expected number or string like "16px" or "1rem".`
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
149
212
|
return {
|
|
150
213
|
colors: flattenColors(colors),
|
|
151
214
|
fontFamily: fontFamilyResult,
|
|
152
|
-
fontSize: fontSizeResult
|
|
215
|
+
fontSize: fontSizeResult,
|
|
216
|
+
spacing: spacingResult
|
|
153
217
|
};
|
|
154
218
|
}
|
|
155
219
|
|
|
@@ -212,6 +276,10 @@ function createInitialState(options, filename, colorSchemeImportSource, colorSch
|
|
|
212
276
|
needsWindowDimensionsImport: false,
|
|
213
277
|
windowDimensionsVariableName: "_twDimensions",
|
|
214
278
|
windowDimensionsLocalIdentifier: void 0,
|
|
279
|
+
hasI18nManagerImport: false,
|
|
280
|
+
needsI18nManagerImport: false,
|
|
281
|
+
i18nManagerVariableName: "_twIsRTL",
|
|
282
|
+
i18nManagerLocalIdentifier: void 0,
|
|
215
283
|
customTheme,
|
|
216
284
|
schemeModifierConfig,
|
|
217
285
|
supportedAttributes: exactMatches,
|
|
@@ -715,7 +783,9 @@ var BORDER_WIDTH_PROP_MAP = {
|
|
|
715
783
|
t: "borderTopWidth",
|
|
716
784
|
r: "borderRightWidth",
|
|
717
785
|
b: "borderBottomWidth",
|
|
718
|
-
l: "borderLeftWidth"
|
|
786
|
+
l: "borderLeftWidth",
|
|
787
|
+
s: "borderStartWidth",
|
|
788
|
+
e: "borderEndWidth"
|
|
719
789
|
};
|
|
720
790
|
var BORDER_RADIUS_CORNER_MAP = {
|
|
721
791
|
tl: "borderTopLeftRadius",
|
|
@@ -723,11 +793,19 @@ var BORDER_RADIUS_CORNER_MAP = {
|
|
|
723
793
|
bl: "borderBottomLeftRadius",
|
|
724
794
|
br: "borderBottomRightRadius"
|
|
725
795
|
};
|
|
796
|
+
var BORDER_RADIUS_LOGICAL_CORNER_MAP = {
|
|
797
|
+
ss: "borderTopStartRadius",
|
|
798
|
+
se: "borderTopEndRadius",
|
|
799
|
+
es: "borderBottomStartRadius",
|
|
800
|
+
ee: "borderBottomEndRadius"
|
|
801
|
+
};
|
|
726
802
|
var BORDER_RADIUS_SIDE_MAP = {
|
|
727
803
|
t: ["borderTopLeftRadius", "borderTopRightRadius"],
|
|
728
804
|
r: ["borderTopRightRadius", "borderBottomRightRadius"],
|
|
729
805
|
b: ["borderBottomLeftRadius", "borderBottomRightRadius"],
|
|
730
|
-
l: ["borderTopLeftRadius", "borderBottomLeftRadius"]
|
|
806
|
+
l: ["borderTopLeftRadius", "borderBottomLeftRadius"],
|
|
807
|
+
s: ["borderTopStartRadius", "borderBottomStartRadius"],
|
|
808
|
+
e: ["borderTopEndRadius", "borderBottomEndRadius"]
|
|
731
809
|
};
|
|
732
810
|
function parseArbitraryBorderWidth(value) {
|
|
733
811
|
const pxMatch = value.match(/^\[(\d+)(?:px)?\]$/);
|
|
@@ -775,11 +853,11 @@ function parseBorder(cls, customColors) {
|
|
|
775
853
|
return null;
|
|
776
854
|
}
|
|
777
855
|
function parseBorderWidth(cls, customColors) {
|
|
778
|
-
const dirMatch = cls.match(/^border-([
|
|
856
|
+
const dirMatch = cls.match(/^border-([trblse])(?:-(.+))?$/);
|
|
779
857
|
if (dirMatch) {
|
|
780
858
|
const dir = dirMatch[1];
|
|
781
859
|
const valueStr = dirMatch[2] || "";
|
|
782
|
-
if (valueStr) {
|
|
860
|
+
if (valueStr && dir !== "s" && dir !== "e") {
|
|
783
861
|
const colorResult = parseColor(cls, customColors);
|
|
784
862
|
if (colorResult !== null) {
|
|
785
863
|
return null;
|
|
@@ -843,7 +921,24 @@ function parseBorderRadius(cls) {
|
|
|
843
921
|
}
|
|
844
922
|
return null;
|
|
845
923
|
}
|
|
846
|
-
const
|
|
924
|
+
const logicalCornerMatch = rest.match(/^(ss|se|es|ee)(?:-(.+))?$/);
|
|
925
|
+
if (logicalCornerMatch) {
|
|
926
|
+
const corner = logicalCornerMatch[1];
|
|
927
|
+
const valueStr = logicalCornerMatch[2] || "";
|
|
928
|
+
if (valueStr.startsWith("[")) {
|
|
929
|
+
const arbitraryValue = parseArbitraryBorderRadius(valueStr);
|
|
930
|
+
if (arbitraryValue !== null) {
|
|
931
|
+
return { [BORDER_RADIUS_LOGICAL_CORNER_MAP[corner]]: arbitraryValue };
|
|
932
|
+
}
|
|
933
|
+
return null;
|
|
934
|
+
}
|
|
935
|
+
const scaleValue2 = BORDER_RADIUS_SCALE[valueStr];
|
|
936
|
+
if (scaleValue2 !== void 0) {
|
|
937
|
+
return { [BORDER_RADIUS_LOGICAL_CORNER_MAP[corner]]: scaleValue2 };
|
|
938
|
+
}
|
|
939
|
+
return null;
|
|
940
|
+
}
|
|
941
|
+
const sideMatch = rest.match(/^([trblse])(?:-(.+))?$/);
|
|
847
942
|
if (sideMatch) {
|
|
848
943
|
const side = sideMatch[1];
|
|
849
944
|
const valueStr = sideMatch[2] || "";
|
|
@@ -1052,7 +1147,8 @@ var INSET_SCALE = {
|
|
|
1052
1147
|
20: 80,
|
|
1053
1148
|
24: 96
|
|
1054
1149
|
};
|
|
1055
|
-
function parseLayout(cls) {
|
|
1150
|
+
function parseLayout(cls, customSpacing) {
|
|
1151
|
+
const insetMap = customSpacing ? { ...INSET_SCALE, ...customSpacing } : INSET_SCALE;
|
|
1056
1152
|
if (cls.startsWith("z-")) {
|
|
1057
1153
|
const zKey = cls.substring(2);
|
|
1058
1154
|
const arbitraryZ = parseArbitraryZIndex(zKey);
|
|
@@ -1073,7 +1169,7 @@ function parseLayout(cls) {
|
|
|
1073
1169
|
if (arbitraryTop !== null) {
|
|
1074
1170
|
return { top: arbitraryTop };
|
|
1075
1171
|
}
|
|
1076
|
-
const topValue =
|
|
1172
|
+
const topValue = insetMap[topKey];
|
|
1077
1173
|
if (topValue !== void 0) {
|
|
1078
1174
|
return { top: topValue };
|
|
1079
1175
|
}
|
|
@@ -1087,7 +1183,7 @@ function parseLayout(cls) {
|
|
|
1087
1183
|
if (arbitraryRight !== null) {
|
|
1088
1184
|
return { right: arbitraryRight };
|
|
1089
1185
|
}
|
|
1090
|
-
const rightValue =
|
|
1186
|
+
const rightValue = insetMap[rightKey];
|
|
1091
1187
|
if (rightValue !== void 0) {
|
|
1092
1188
|
return { right: rightValue };
|
|
1093
1189
|
}
|
|
@@ -1101,7 +1197,7 @@ function parseLayout(cls) {
|
|
|
1101
1197
|
if (arbitraryBottom !== null) {
|
|
1102
1198
|
return { bottom: arbitraryBottom };
|
|
1103
1199
|
}
|
|
1104
|
-
const bottomValue =
|
|
1200
|
+
const bottomValue = insetMap[bottomKey];
|
|
1105
1201
|
if (bottomValue !== void 0) {
|
|
1106
1202
|
return { bottom: bottomValue };
|
|
1107
1203
|
}
|
|
@@ -1115,18 +1211,64 @@ function parseLayout(cls) {
|
|
|
1115
1211
|
if (arbitraryLeft !== null) {
|
|
1116
1212
|
return { left: arbitraryLeft };
|
|
1117
1213
|
}
|
|
1118
|
-
const leftValue =
|
|
1214
|
+
const leftValue = insetMap[leftKey];
|
|
1119
1215
|
if (leftValue !== void 0) {
|
|
1120
1216
|
return { left: leftValue };
|
|
1121
1217
|
}
|
|
1122
1218
|
}
|
|
1219
|
+
const startMatch = cls.match(/^(-?)start-(.+)$/);
|
|
1220
|
+
if (startMatch) {
|
|
1221
|
+
const [, negPrefix, startKey] = startMatch;
|
|
1222
|
+
const isNegative = negPrefix === "-";
|
|
1223
|
+
if (startKey === "auto") {
|
|
1224
|
+
return {};
|
|
1225
|
+
}
|
|
1226
|
+
const arbitraryStart = parseArbitraryInset(startKey);
|
|
1227
|
+
if (arbitraryStart !== null) {
|
|
1228
|
+
if (typeof arbitraryStart === "number") {
|
|
1229
|
+
return { start: isNegative ? -arbitraryStart : arbitraryStart };
|
|
1230
|
+
}
|
|
1231
|
+
if (isNegative && arbitraryStart.endsWith("%")) {
|
|
1232
|
+
const numValue = parseFloat(arbitraryStart);
|
|
1233
|
+
return { start: `${-numValue}%` };
|
|
1234
|
+
}
|
|
1235
|
+
return { start: arbitraryStart };
|
|
1236
|
+
}
|
|
1237
|
+
const startValue = insetMap[startKey];
|
|
1238
|
+
if (startValue !== void 0) {
|
|
1239
|
+
return { start: isNegative ? -startValue : startValue };
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
const endMatch = cls.match(/^(-?)end-(.+)$/);
|
|
1243
|
+
if (endMatch) {
|
|
1244
|
+
const [, negPrefix, endKey] = endMatch;
|
|
1245
|
+
const isNegative = negPrefix === "-";
|
|
1246
|
+
if (endKey === "auto") {
|
|
1247
|
+
return {};
|
|
1248
|
+
}
|
|
1249
|
+
const arbitraryEnd = parseArbitraryInset(endKey);
|
|
1250
|
+
if (arbitraryEnd !== null) {
|
|
1251
|
+
if (typeof arbitraryEnd === "number") {
|
|
1252
|
+
return { end: isNegative ? -arbitraryEnd : arbitraryEnd };
|
|
1253
|
+
}
|
|
1254
|
+
if (isNegative && arbitraryEnd.endsWith("%")) {
|
|
1255
|
+
const numValue = parseFloat(arbitraryEnd);
|
|
1256
|
+
return { end: `${-numValue}%` };
|
|
1257
|
+
}
|
|
1258
|
+
return { end: arbitraryEnd };
|
|
1259
|
+
}
|
|
1260
|
+
const endValue = insetMap[endKey];
|
|
1261
|
+
if (endValue !== void 0) {
|
|
1262
|
+
return { end: isNegative ? -endValue : endValue };
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1123
1265
|
if (cls.startsWith("inset-x-")) {
|
|
1124
1266
|
const insetKey = cls.substring(8);
|
|
1125
1267
|
const arbitraryInset = parseArbitraryInset(insetKey);
|
|
1126
1268
|
if (arbitraryInset !== null) {
|
|
1127
1269
|
return { left: arbitraryInset, right: arbitraryInset };
|
|
1128
1270
|
}
|
|
1129
|
-
const insetValue =
|
|
1271
|
+
const insetValue = insetMap[insetKey];
|
|
1130
1272
|
if (insetValue !== void 0) {
|
|
1131
1273
|
return { left: insetValue, right: insetValue };
|
|
1132
1274
|
}
|
|
@@ -1137,18 +1279,40 @@ function parseLayout(cls) {
|
|
|
1137
1279
|
if (arbitraryInset !== null) {
|
|
1138
1280
|
return { top: arbitraryInset, bottom: arbitraryInset };
|
|
1139
1281
|
}
|
|
1140
|
-
const insetValue =
|
|
1282
|
+
const insetValue = insetMap[insetKey];
|
|
1141
1283
|
if (insetValue !== void 0) {
|
|
1142
1284
|
return { top: insetValue, bottom: insetValue };
|
|
1143
1285
|
}
|
|
1144
1286
|
}
|
|
1287
|
+
if (cls.startsWith("inset-s-")) {
|
|
1288
|
+
const insetKey = cls.substring(8);
|
|
1289
|
+
const arbitraryInset = parseArbitraryInset(insetKey);
|
|
1290
|
+
if (arbitraryInset !== null) {
|
|
1291
|
+
return { start: arbitraryInset };
|
|
1292
|
+
}
|
|
1293
|
+
const insetValue = insetMap[insetKey];
|
|
1294
|
+
if (insetValue !== void 0) {
|
|
1295
|
+
return { start: insetValue };
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
if (cls.startsWith("inset-e-")) {
|
|
1299
|
+
const insetKey = cls.substring(8);
|
|
1300
|
+
const arbitraryInset = parseArbitraryInset(insetKey);
|
|
1301
|
+
if (arbitraryInset !== null) {
|
|
1302
|
+
return { end: arbitraryInset };
|
|
1303
|
+
}
|
|
1304
|
+
const insetValue = insetMap[insetKey];
|
|
1305
|
+
if (insetValue !== void 0) {
|
|
1306
|
+
return { end: insetValue };
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1145
1309
|
if (cls.startsWith("inset-")) {
|
|
1146
1310
|
const insetKey = cls.substring(6);
|
|
1147
1311
|
const arbitraryInset = parseArbitraryInset(insetKey);
|
|
1148
1312
|
if (arbitraryInset !== null) {
|
|
1149
1313
|
return { top: arbitraryInset, right: arbitraryInset, bottom: arbitraryInset, left: arbitraryInset };
|
|
1150
1314
|
}
|
|
1151
|
-
const insetValue =
|
|
1315
|
+
const insetValue = insetMap[insetKey];
|
|
1152
1316
|
if (insetValue !== void 0) {
|
|
1153
1317
|
return { top: insetValue, right: insetValue, bottom: insetValue, left: insetValue };
|
|
1154
1318
|
}
|
|
@@ -1308,7 +1472,8 @@ function parseArbitrarySize(value) {
|
|
|
1308
1472
|
}
|
|
1309
1473
|
return null;
|
|
1310
1474
|
}
|
|
1311
|
-
function parseSizing(cls) {
|
|
1475
|
+
function parseSizing(cls, customSpacing) {
|
|
1476
|
+
const sizeMap = customSpacing ? { ...SIZE_SCALE, ...customSpacing } : SIZE_SCALE;
|
|
1312
1477
|
if (cls.startsWith("w-")) {
|
|
1313
1478
|
const sizeKey = cls.substring(2);
|
|
1314
1479
|
if (sizeKey === "screen") {
|
|
@@ -1322,7 +1487,7 @@ function parseSizing(cls) {
|
|
|
1322
1487
|
if (percentage) {
|
|
1323
1488
|
return { width: percentage };
|
|
1324
1489
|
}
|
|
1325
|
-
const numericSize =
|
|
1490
|
+
const numericSize = sizeMap[sizeKey];
|
|
1326
1491
|
if (numericSize !== void 0) {
|
|
1327
1492
|
return { width: numericSize };
|
|
1328
1493
|
}
|
|
@@ -1343,7 +1508,7 @@ function parseSizing(cls) {
|
|
|
1343
1508
|
if (percentage) {
|
|
1344
1509
|
return { height: percentage };
|
|
1345
1510
|
}
|
|
1346
|
-
const numericSize =
|
|
1511
|
+
const numericSize = sizeMap[sizeKey];
|
|
1347
1512
|
if (numericSize !== void 0) {
|
|
1348
1513
|
return { height: numericSize };
|
|
1349
1514
|
}
|
|
@@ -1361,7 +1526,7 @@ function parseSizing(cls) {
|
|
|
1361
1526
|
if (percentage) {
|
|
1362
1527
|
return { minWidth: percentage };
|
|
1363
1528
|
}
|
|
1364
|
-
const numericSize =
|
|
1529
|
+
const numericSize = sizeMap[sizeKey];
|
|
1365
1530
|
if (numericSize !== void 0) {
|
|
1366
1531
|
return { minWidth: numericSize };
|
|
1367
1532
|
}
|
|
@@ -1376,7 +1541,7 @@ function parseSizing(cls) {
|
|
|
1376
1541
|
if (percentage) {
|
|
1377
1542
|
return { minHeight: percentage };
|
|
1378
1543
|
}
|
|
1379
|
-
const numericSize =
|
|
1544
|
+
const numericSize = sizeMap[sizeKey];
|
|
1380
1545
|
if (numericSize !== void 0) {
|
|
1381
1546
|
return { minHeight: numericSize };
|
|
1382
1547
|
}
|
|
@@ -1391,7 +1556,7 @@ function parseSizing(cls) {
|
|
|
1391
1556
|
if (percentage) {
|
|
1392
1557
|
return { maxWidth: percentage };
|
|
1393
1558
|
}
|
|
1394
|
-
const numericSize =
|
|
1559
|
+
const numericSize = sizeMap[sizeKey];
|
|
1395
1560
|
if (numericSize !== void 0) {
|
|
1396
1561
|
return { maxWidth: numericSize };
|
|
1397
1562
|
}
|
|
@@ -1406,7 +1571,7 @@ function parseSizing(cls) {
|
|
|
1406
1571
|
if (percentage) {
|
|
1407
1572
|
return { maxHeight: percentage };
|
|
1408
1573
|
}
|
|
1409
|
-
const numericSize =
|
|
1574
|
+
const numericSize = sizeMap[sizeKey];
|
|
1410
1575
|
if (numericSize !== void 0) {
|
|
1411
1576
|
return { maxHeight: numericSize };
|
|
1412
1577
|
}
|
|
@@ -1466,8 +1631,9 @@ function parseArbitrarySpacing(value) {
|
|
|
1466
1631
|
}
|
|
1467
1632
|
return null;
|
|
1468
1633
|
}
|
|
1469
|
-
function parseSpacing(cls) {
|
|
1470
|
-
const
|
|
1634
|
+
function parseSpacing(cls, customSpacing) {
|
|
1635
|
+
const spacingMap = customSpacing ? { ...SPACING_SCALE, ...customSpacing } : SPACING_SCALE;
|
|
1636
|
+
const marginMatch = cls.match(/^(-?)m([xytrblse]?)-(.+)$/);
|
|
1471
1637
|
if (marginMatch) {
|
|
1472
1638
|
const [, negativePrefix, dir, valueStr] = marginMatch;
|
|
1473
1639
|
const isNegative = negativePrefix === "-";
|
|
@@ -1476,20 +1642,20 @@ function parseSpacing(cls) {
|
|
|
1476
1642
|
const finalValue = isNegative ? -arbitraryValue : arbitraryValue;
|
|
1477
1643
|
return getMarginStyle(dir, finalValue);
|
|
1478
1644
|
}
|
|
1479
|
-
const scaleValue =
|
|
1645
|
+
const scaleValue = spacingMap[valueStr];
|
|
1480
1646
|
if (scaleValue !== void 0) {
|
|
1481
1647
|
const finalValue = isNegative ? -scaleValue : scaleValue;
|
|
1482
1648
|
return getMarginStyle(dir, finalValue);
|
|
1483
1649
|
}
|
|
1484
1650
|
}
|
|
1485
|
-
const paddingMatch = cls.match(/^p([
|
|
1651
|
+
const paddingMatch = cls.match(/^p([xytrblse]?)-(.+)$/);
|
|
1486
1652
|
if (paddingMatch) {
|
|
1487
1653
|
const [, dir, valueStr] = paddingMatch;
|
|
1488
1654
|
const arbitraryValue = parseArbitrarySpacing(valueStr);
|
|
1489
1655
|
if (arbitraryValue !== null) {
|
|
1490
1656
|
return getPaddingStyle(dir, arbitraryValue);
|
|
1491
1657
|
}
|
|
1492
|
-
const scaleValue =
|
|
1658
|
+
const scaleValue = spacingMap[valueStr];
|
|
1493
1659
|
if (scaleValue !== void 0) {
|
|
1494
1660
|
return getPaddingStyle(dir, scaleValue);
|
|
1495
1661
|
}
|
|
@@ -1501,7 +1667,7 @@ function parseSpacing(cls) {
|
|
|
1501
1667
|
if (arbitraryValue !== null) {
|
|
1502
1668
|
return { gap: arbitraryValue };
|
|
1503
1669
|
}
|
|
1504
|
-
const scaleValue =
|
|
1670
|
+
const scaleValue = spacingMap[valueStr];
|
|
1505
1671
|
if (scaleValue !== void 0) {
|
|
1506
1672
|
return { gap: scaleValue };
|
|
1507
1673
|
}
|
|
@@ -1524,6 +1690,10 @@ function getMarginStyle(dir, value) {
|
|
|
1524
1690
|
return { marginBottom: value };
|
|
1525
1691
|
case "l":
|
|
1526
1692
|
return { marginLeft: value };
|
|
1693
|
+
case "s":
|
|
1694
|
+
return { marginStart: value };
|
|
1695
|
+
case "e":
|
|
1696
|
+
return { marginEnd: value };
|
|
1527
1697
|
default:
|
|
1528
1698
|
return {};
|
|
1529
1699
|
}
|
|
@@ -1544,6 +1714,10 @@ function getPaddingStyle(dir, value) {
|
|
|
1544
1714
|
return { paddingBottom: value };
|
|
1545
1715
|
case "l":
|
|
1546
1716
|
return { paddingLeft: value };
|
|
1717
|
+
case "s":
|
|
1718
|
+
return { paddingStart: value };
|
|
1719
|
+
case "e":
|
|
1720
|
+
return { paddingEnd: value };
|
|
1547
1721
|
default:
|
|
1548
1722
|
return {};
|
|
1549
1723
|
}
|
|
@@ -1659,7 +1833,8 @@ function parseArbitraryPerspective(value) {
|
|
|
1659
1833
|
}
|
|
1660
1834
|
return null;
|
|
1661
1835
|
}
|
|
1662
|
-
function parseTransform(cls) {
|
|
1836
|
+
function parseTransform(cls, customSpacing) {
|
|
1837
|
+
const spacingMap = customSpacing ? { ...SPACING_SCALE, ...customSpacing } : SPACING_SCALE;
|
|
1663
1838
|
if (cls.startsWith("origin-")) {
|
|
1664
1839
|
if (process.env.NODE_ENV !== "production") {
|
|
1665
1840
|
console.warn(
|
|
@@ -1765,7 +1940,7 @@ function parseTransform(cls) {
|
|
|
1765
1940
|
const value = typeof arbitraryTranslate === "number" ? isNegative ? -arbitraryTranslate : arbitraryTranslate : isNegative ? `-${arbitraryTranslate}` : arbitraryTranslate;
|
|
1766
1941
|
return { transform: [{ translateX: value }] };
|
|
1767
1942
|
}
|
|
1768
|
-
const translateValue =
|
|
1943
|
+
const translateValue = spacingMap[translateKey];
|
|
1769
1944
|
if (translateValue !== void 0) {
|
|
1770
1945
|
const value = isNegative ? -translateValue : translateValue;
|
|
1771
1946
|
return { transform: [{ translateX: value }] };
|
|
@@ -1779,7 +1954,7 @@ function parseTransform(cls) {
|
|
|
1779
1954
|
const value = typeof arbitraryTranslate === "number" ? isNegative ? -arbitraryTranslate : arbitraryTranslate : isNegative ? `-${arbitraryTranslate}` : arbitraryTranslate;
|
|
1780
1955
|
return { transform: [{ translateY: value }] };
|
|
1781
1956
|
}
|
|
1782
|
-
const translateValue =
|
|
1957
|
+
const translateValue = spacingMap[translateKey];
|
|
1783
1958
|
if (translateValue !== void 0) {
|
|
1784
1959
|
const value = isNegative ? -translateValue : translateValue;
|
|
1785
1960
|
return { transform: [{ translateY: value }] };
|
|
@@ -2032,11 +2207,13 @@ var STATE_MODIFIERS = [
|
|
|
2032
2207
|
var PLATFORM_MODIFIERS = ["ios", "android", "web"];
|
|
2033
2208
|
var COLOR_SCHEME_MODIFIERS = ["dark", "light"];
|
|
2034
2209
|
var SCHEME_MODIFIERS = ["scheme"];
|
|
2210
|
+
var DIRECTIONAL_MODIFIERS = ["rtl", "ltr"];
|
|
2035
2211
|
var SUPPORTED_MODIFIERS = [
|
|
2036
2212
|
...STATE_MODIFIERS,
|
|
2037
2213
|
...PLATFORM_MODIFIERS,
|
|
2038
2214
|
...COLOR_SCHEME_MODIFIERS,
|
|
2039
|
-
...SCHEME_MODIFIERS
|
|
2215
|
+
...SCHEME_MODIFIERS,
|
|
2216
|
+
...DIRECTIONAL_MODIFIERS
|
|
2040
2217
|
];
|
|
2041
2218
|
function parseModifier(cls) {
|
|
2042
2219
|
const colonIndex = cls.indexOf(":");
|
|
@@ -2071,6 +2248,9 @@ function isColorSchemeModifier(modifier) {
|
|
|
2071
2248
|
function isSchemeModifier(modifier) {
|
|
2072
2249
|
return SCHEME_MODIFIERS.includes(modifier);
|
|
2073
2250
|
}
|
|
2251
|
+
function isDirectionalModifier(modifier) {
|
|
2252
|
+
return DIRECTIONAL_MODIFIERS.includes(modifier);
|
|
2253
|
+
}
|
|
2074
2254
|
function isColorClass(className) {
|
|
2075
2255
|
return className.startsWith("text-") || className.startsWith("bg-") || className.startsWith("border-");
|
|
2076
2256
|
}
|
|
@@ -2115,11 +2295,24 @@ function expandSchemeModifier(schemeModifier, customColors, darkSuffix = "-dark"
|
|
|
2115
2295
|
}
|
|
2116
2296
|
];
|
|
2117
2297
|
}
|
|
2298
|
+
var DIRECTIONAL_TEXT_ALIGN_EXPANSIONS = {
|
|
2299
|
+
"text-start": { ltr: "text-left", rtl: "text-right" },
|
|
2300
|
+
"text-end": { ltr: "text-right", rtl: "text-left" }
|
|
2301
|
+
};
|
|
2302
|
+
function getDirectionalExpansion(cls) {
|
|
2303
|
+
return DIRECTIONAL_TEXT_ALIGN_EXPANSIONS[cls];
|
|
2304
|
+
}
|
|
2118
2305
|
function splitModifierClasses(className) {
|
|
2119
2306
|
const classes = className.trim().split(/\s+/).filter(Boolean);
|
|
2120
2307
|
const baseClasses = [];
|
|
2121
2308
|
const modifierClasses = [];
|
|
2122
2309
|
for (const cls of classes) {
|
|
2310
|
+
const directionalExpansion = getDirectionalExpansion(cls);
|
|
2311
|
+
if (directionalExpansion) {
|
|
2312
|
+
modifierClasses.push({ modifier: "ltr", baseClass: directionalExpansion.ltr });
|
|
2313
|
+
modifierClasses.push({ modifier: "rtl", baseClass: directionalExpansion.rtl });
|
|
2314
|
+
continue;
|
|
2315
|
+
}
|
|
2123
2316
|
const parsed = parseModifier(cls);
|
|
2124
2317
|
if (parsed) {
|
|
2125
2318
|
modifierClasses.push(parsed);
|
|
@@ -2142,15 +2335,15 @@ function parseClassName(className, customTheme) {
|
|
|
2142
2335
|
}
|
|
2143
2336
|
function parseClass(cls, customTheme) {
|
|
2144
2337
|
const parsers = [
|
|
2145
|
-
parseSpacing,
|
|
2338
|
+
(cls2) => parseSpacing(cls2, customTheme?.spacing),
|
|
2146
2339
|
(cls2) => parseBorder(cls2, customTheme?.colors),
|
|
2147
2340
|
(cls2) => parseColor(cls2, customTheme?.colors),
|
|
2148
|
-
parseLayout,
|
|
2341
|
+
(cls2) => parseLayout(cls2, customTheme?.spacing),
|
|
2149
2342
|
(cls2) => parseTypography(cls2, customTheme?.fontFamily, customTheme?.fontSize),
|
|
2150
|
-
parseSizing,
|
|
2343
|
+
(cls2) => parseSizing(cls2, customTheme?.spacing),
|
|
2151
2344
|
parseShadow,
|
|
2152
2345
|
parseAspectRatio,
|
|
2153
|
-
parseTransform
|
|
2346
|
+
(cls2) => parseTransform(cls2, customTheme?.spacing)
|
|
2154
2347
|
];
|
|
2155
2348
|
for (const parser of parsers) {
|
|
2156
2349
|
const result = parser(cls);
|
|
@@ -2298,6 +2491,40 @@ function getStatePropertyForModifier(modifier) {
|
|
|
2298
2491
|
}
|
|
2299
2492
|
}
|
|
2300
2493
|
|
|
2494
|
+
// src/babel/utils/directionalModifierProcessing.ts
|
|
2495
|
+
function processDirectionalModifiers(directionalModifiers, state, parseClassName2, generateStyleKey2, t) {
|
|
2496
|
+
state.needsI18nManagerImport = true;
|
|
2497
|
+
const modifiersByDirection = /* @__PURE__ */ new Map();
|
|
2498
|
+
for (const mod of directionalModifiers) {
|
|
2499
|
+
const direction = mod.modifier;
|
|
2500
|
+
if (!modifiersByDirection.has(direction)) {
|
|
2501
|
+
modifiersByDirection.set(direction, []);
|
|
2502
|
+
}
|
|
2503
|
+
const directionGroup = modifiersByDirection.get(direction);
|
|
2504
|
+
if (directionGroup) {
|
|
2505
|
+
directionGroup.push(mod);
|
|
2506
|
+
}
|
|
2507
|
+
}
|
|
2508
|
+
const conditionalExpressions = [];
|
|
2509
|
+
for (const [direction, modifiers] of modifiersByDirection) {
|
|
2510
|
+
const classNames = modifiers.map((m) => m.baseClass).join(" ");
|
|
2511
|
+
const styleObject = parseClassName2(classNames, state.customTheme);
|
|
2512
|
+
if (hasRuntimeDimensions(styleObject)) {
|
|
2513
|
+
throw new Error(
|
|
2514
|
+
`w-screen and h-screen cannot be combined with directional modifiers (rtl:, ltr:). Found in: "${direction}:${classNames}". Use w-screen/h-screen without modifiers instead.`
|
|
2515
|
+
);
|
|
2516
|
+
}
|
|
2517
|
+
const styleKey = generateStyleKey2(`${direction}_${classNames}`);
|
|
2518
|
+
state.styleRegistry.set(styleKey, styleObject);
|
|
2519
|
+
const rtlVariable = t.identifier(state.i18nManagerVariableName);
|
|
2520
|
+
const directionCheck = direction === "rtl" ? rtlVariable : t.unaryExpression("!", rtlVariable);
|
|
2521
|
+
const styleReference = t.memberExpression(t.identifier(state.stylesIdentifier), t.identifier(styleKey));
|
|
2522
|
+
const conditionalExpression = t.logicalExpression("&&", directionCheck, styleReference);
|
|
2523
|
+
conditionalExpressions.push(conditionalExpression);
|
|
2524
|
+
}
|
|
2525
|
+
return conditionalExpressions;
|
|
2526
|
+
}
|
|
2527
|
+
|
|
2301
2528
|
// src/babel/utils/dynamicProcessing.ts
|
|
2302
2529
|
function processDynamicExpression(expression, state, parseClassName2, generateStyleKey2, splitModifierClasses2, processPlatformModifiers2, processColorSchemeModifiers2, componentScope, isPlatformModifier2, isColorSchemeModifier2, isSchemeModifier2, expandSchemeModifier2, t) {
|
|
2303
2530
|
if (t.isTemplateLiteral(expression)) {
|
|
@@ -2901,6 +3128,7 @@ function jsxAttributeVisitor(path2, state, t) {
|
|
|
2901
3128
|
const placeholderModifiers = modifierClasses.filter((m) => m.modifier === "placeholder");
|
|
2902
3129
|
const platformModifiers = modifierClasses.filter((m) => isPlatformModifier(m.modifier));
|
|
2903
3130
|
const colorSchemeModifiers = modifierClasses.filter((m) => isColorSchemeModifier(m.modifier));
|
|
3131
|
+
const directionalModifiers = modifierClasses.filter((m) => isDirectionalModifier(m.modifier));
|
|
2904
3132
|
const stateModifiers = modifierClasses.filter(
|
|
2905
3133
|
(m) => isStateModifier(m.modifier) && m.modifier !== "placeholder"
|
|
2906
3134
|
);
|
|
@@ -2923,6 +3151,7 @@ function jsxAttributeVisitor(path2, state, t) {
|
|
|
2923
3151
|
}
|
|
2924
3152
|
const hasPlatformModifiers = platformModifiers.length > 0;
|
|
2925
3153
|
const hasColorSchemeModifiers = colorSchemeModifiers.length > 0;
|
|
3154
|
+
const hasDirectionalModifiers = directionalModifiers.length > 0;
|
|
2926
3155
|
const hasStateModifiers = stateModifiers.length > 0;
|
|
2927
3156
|
const hasBaseClasses = baseClasses.length > 0;
|
|
2928
3157
|
let componentScope = null;
|
|
@@ -2938,7 +3167,7 @@ function jsxAttributeVisitor(path2, state, t) {
|
|
|
2938
3167
|
}
|
|
2939
3168
|
}
|
|
2940
3169
|
}
|
|
2941
|
-
if (hasStateModifiers && (hasPlatformModifiers || hasColorSchemeModifiers)) {
|
|
3170
|
+
if (hasStateModifiers && (hasPlatformModifiers || hasColorSchemeModifiers || hasDirectionalModifiers)) {
|
|
2942
3171
|
const jsxOpeningElement = path2.parent;
|
|
2943
3172
|
const componentSupport = getComponentModifierSupport(jsxOpeningElement, t);
|
|
2944
3173
|
if (componentSupport) {
|
|
@@ -2948,7 +3177,7 @@ function jsxAttributeVisitor(path2, state, t) {
|
|
|
2948
3177
|
const baseStyleObject = parseClassName(baseClassName, state.customTheme);
|
|
2949
3178
|
if (hasRuntimeDimensions(baseStyleObject)) {
|
|
2950
3179
|
throw path2.buildCodeFrameError(
|
|
2951
|
-
`w-screen and h-screen cannot be combined with modifiers. Found: "${baseClassName}" with state, platform,
|
|
3180
|
+
`w-screen and h-screen cannot be combined with modifiers. Found: "${baseClassName}" with state, platform, color scheme, or directional modifiers. Use w-screen/h-screen without modifiers instead.`
|
|
2952
3181
|
);
|
|
2953
3182
|
}
|
|
2954
3183
|
const baseStyleKey = generateStyleKey(baseClassName);
|
|
@@ -2977,6 +3206,16 @@ function jsxAttributeVisitor(path2, state, t) {
|
|
|
2977
3206
|
);
|
|
2978
3207
|
styleArrayElements.push(...colorSchemeConditionals);
|
|
2979
3208
|
}
|
|
3209
|
+
if (hasDirectionalModifiers) {
|
|
3210
|
+
const directionalConditionals = processDirectionalModifiers(
|
|
3211
|
+
directionalModifiers,
|
|
3212
|
+
state,
|
|
3213
|
+
parseClassName,
|
|
3214
|
+
generateStyleKey,
|
|
3215
|
+
t
|
|
3216
|
+
);
|
|
3217
|
+
styleArrayElements.push(...directionalConditionals);
|
|
3218
|
+
}
|
|
2980
3219
|
const modifiersByType = /* @__PURE__ */ new Map();
|
|
2981
3220
|
for (const mod of stateModifiers) {
|
|
2982
3221
|
const modType = mod.modifier;
|
|
@@ -3016,14 +3255,14 @@ function jsxAttributeVisitor(path2, state, t) {
|
|
|
3016
3255
|
} else {
|
|
3017
3256
|
}
|
|
3018
3257
|
}
|
|
3019
|
-
if ((hasPlatformModifiers || hasColorSchemeModifiers) && !hasStateModifiers) {
|
|
3258
|
+
if ((hasPlatformModifiers || hasColorSchemeModifiers || hasDirectionalModifiers) && !hasStateModifiers) {
|
|
3020
3259
|
const styleExpressions = [];
|
|
3021
3260
|
if (hasBaseClasses) {
|
|
3022
3261
|
const baseClassName = baseClasses.join(" ");
|
|
3023
3262
|
const baseStyleObject = parseClassName(baseClassName, state.customTheme);
|
|
3024
3263
|
if (hasRuntimeDimensions(baseStyleObject)) {
|
|
3025
3264
|
throw path2.buildCodeFrameError(
|
|
3026
|
-
`w-screen and h-screen cannot be combined with modifiers. Found: "${baseClassName}" with platform
|
|
3265
|
+
`w-screen and h-screen cannot be combined with modifiers. Found: "${baseClassName}" with platform, color scheme, or directional modifiers. Use w-screen/h-screen without modifiers instead.`
|
|
3027
3266
|
);
|
|
3028
3267
|
}
|
|
3029
3268
|
const baseStyleKey = generateStyleKey(baseClassName);
|
|
@@ -3052,6 +3291,16 @@ function jsxAttributeVisitor(path2, state, t) {
|
|
|
3052
3291
|
);
|
|
3053
3292
|
styleExpressions.push(...colorSchemeConditionals);
|
|
3054
3293
|
}
|
|
3294
|
+
if (hasDirectionalModifiers) {
|
|
3295
|
+
const directionalConditionals = processDirectionalModifiers(
|
|
3296
|
+
directionalModifiers,
|
|
3297
|
+
state,
|
|
3298
|
+
parseClassName,
|
|
3299
|
+
generateStyleKey,
|
|
3300
|
+
t
|
|
3301
|
+
);
|
|
3302
|
+
styleExpressions.push(...directionalConditionals);
|
|
3303
|
+
}
|
|
3055
3304
|
const styleExpression = styleExpressions.length === 1 ? styleExpressions[0] : t.arrayExpression(styleExpressions);
|
|
3056
3305
|
const styleAttribute2 = findStyleAttribute(path2, targetStyleProp, t);
|
|
3057
3306
|
if (styleAttribute2) {
|
|
@@ -3277,6 +3526,17 @@ function importDeclarationVisitor(path2, state, t) {
|
|
|
3277
3526
|
}
|
|
3278
3527
|
return false;
|
|
3279
3528
|
});
|
|
3529
|
+
if (node.importKind !== "type") {
|
|
3530
|
+
for (const spec of specifiers) {
|
|
3531
|
+
if (t.isImportSpecifier(spec) && t.isIdentifier(spec.imported)) {
|
|
3532
|
+
if (spec.imported.name === "I18nManager") {
|
|
3533
|
+
state.hasI18nManagerImport = true;
|
|
3534
|
+
state.i18nManagerLocalIdentifier = spec.local.name;
|
|
3535
|
+
break;
|
|
3536
|
+
}
|
|
3537
|
+
}
|
|
3538
|
+
}
|
|
3539
|
+
}
|
|
3280
3540
|
if (node.importKind !== "type") {
|
|
3281
3541
|
for (const spec of specifiers) {
|
|
3282
3542
|
if (t.isImportSpecifier(spec) && t.isIdentifier(spec.imported)) {
|
|
@@ -3447,6 +3707,71 @@ function injectColorSchemeHook(functionPath, colorSchemeVariableName, hookName,
|
|
|
3447
3707
|
body.body.unshift(hookCall);
|
|
3448
3708
|
return true;
|
|
3449
3709
|
}
|
|
3710
|
+
function addI18nManagerImport(path2, t) {
|
|
3711
|
+
const body = path2.node.body;
|
|
3712
|
+
let existingValueImport = null;
|
|
3713
|
+
for (const statement of body) {
|
|
3714
|
+
if (t.isImportDeclaration(statement) && statement.source.value === "react-native") {
|
|
3715
|
+
if (statement.importKind === "type") {
|
|
3716
|
+
continue;
|
|
3717
|
+
}
|
|
3718
|
+
const hasNamespaceImport = statement.specifiers.some((spec) => t.isImportNamespaceSpecifier(spec));
|
|
3719
|
+
if (hasNamespaceImport) {
|
|
3720
|
+
continue;
|
|
3721
|
+
}
|
|
3722
|
+
existingValueImport = statement;
|
|
3723
|
+
break;
|
|
3724
|
+
}
|
|
3725
|
+
}
|
|
3726
|
+
if (existingValueImport) {
|
|
3727
|
+
const hasI18nManager = existingValueImport.specifiers.some(
|
|
3728
|
+
(spec) => t.isImportSpecifier(spec) && spec.imported.type === "Identifier" && spec.imported.name === "I18nManager"
|
|
3729
|
+
);
|
|
3730
|
+
if (!hasI18nManager) {
|
|
3731
|
+
existingValueImport.specifiers.push(
|
|
3732
|
+
t.importSpecifier(t.identifier("I18nManager"), t.identifier("I18nManager"))
|
|
3733
|
+
);
|
|
3734
|
+
}
|
|
3735
|
+
} else {
|
|
3736
|
+
const importDeclaration = t.importDeclaration(
|
|
3737
|
+
[t.importSpecifier(t.identifier("I18nManager"), t.identifier("I18nManager"))],
|
|
3738
|
+
t.stringLiteral("react-native")
|
|
3739
|
+
);
|
|
3740
|
+
path2.unshiftContainer("body", importDeclaration);
|
|
3741
|
+
}
|
|
3742
|
+
}
|
|
3743
|
+
function injectI18nManagerVariable(path2, variableName, localIdentifier, t) {
|
|
3744
|
+
const body = path2.node.body;
|
|
3745
|
+
for (const statement of body) {
|
|
3746
|
+
if (t.isVariableDeclaration(statement) && statement.declarations.length > 0 && t.isVariableDeclarator(statement.declarations[0])) {
|
|
3747
|
+
const declarator = statement.declarations[0];
|
|
3748
|
+
if (t.isIdentifier(declarator.id) && declarator.id.name === variableName) {
|
|
3749
|
+
return;
|
|
3750
|
+
}
|
|
3751
|
+
}
|
|
3752
|
+
}
|
|
3753
|
+
const identifierToUse = localIdentifier ?? "I18nManager";
|
|
3754
|
+
const i18nVariable = t.variableDeclaration("const", [
|
|
3755
|
+
t.variableDeclarator(
|
|
3756
|
+
t.identifier(variableName),
|
|
3757
|
+
t.memberExpression(t.identifier(identifierToUse), t.identifier("isRTL"))
|
|
3758
|
+
)
|
|
3759
|
+
]);
|
|
3760
|
+
let insertIndex = 0;
|
|
3761
|
+
for (let i = 0; i < body.length; i++) {
|
|
3762
|
+
const statement = body[i];
|
|
3763
|
+
if (t.isExpressionStatement(statement) && t.isStringLiteral(statement.expression)) {
|
|
3764
|
+
insertIndex = i + 1;
|
|
3765
|
+
continue;
|
|
3766
|
+
}
|
|
3767
|
+
if (t.isImportDeclaration(statement)) {
|
|
3768
|
+
insertIndex = i + 1;
|
|
3769
|
+
continue;
|
|
3770
|
+
}
|
|
3771
|
+
break;
|
|
3772
|
+
}
|
|
3773
|
+
body.splice(insertIndex, 0, i18nVariable);
|
|
3774
|
+
}
|
|
3450
3775
|
function addWindowDimensionsImport(path2, t) {
|
|
3451
3776
|
const body = path2.node.body;
|
|
3452
3777
|
let existingValueImport = null;
|
|
@@ -3534,11 +3859,16 @@ function injectStylesAtTop(path2, styleRegistry, stylesIdentifier, t) {
|
|
|
3534
3859
|
const body = path2.node.body;
|
|
3535
3860
|
let insertIndex = 0;
|
|
3536
3861
|
for (let i = 0; i < body.length; i++) {
|
|
3537
|
-
|
|
3862
|
+
const statement = body[i];
|
|
3863
|
+
if (t.isExpressionStatement(statement) && t.isStringLiteral(statement.expression)) {
|
|
3538
3864
|
insertIndex = i + 1;
|
|
3539
|
-
|
|
3540
|
-
|
|
3865
|
+
continue;
|
|
3866
|
+
}
|
|
3867
|
+
if (t.isImportDeclaration(statement)) {
|
|
3868
|
+
insertIndex = i + 1;
|
|
3869
|
+
continue;
|
|
3541
3870
|
}
|
|
3871
|
+
break;
|
|
3542
3872
|
}
|
|
3543
3873
|
body.splice(insertIndex, 0, styleSheet);
|
|
3544
3874
|
}
|
|
@@ -3582,8 +3912,9 @@ function processTwCall(className, path2, state, parseClassName2, generateStyleKe
|
|
|
3582
3912
|
}
|
|
3583
3913
|
const colorSchemeModifiers = modifierClasses.filter((m) => isColorSchemeModifier(m.modifier));
|
|
3584
3914
|
const platformModifiers = modifierClasses.filter((m) => isPlatformModifier(m.modifier));
|
|
3915
|
+
const directionalModifiers = modifierClasses.filter((m) => isDirectionalModifier(m.modifier));
|
|
3585
3916
|
const otherModifiers = modifierClasses.filter(
|
|
3586
|
-
(m) => !isColorSchemeModifier(m.modifier) && !isPlatformModifier(m.modifier)
|
|
3917
|
+
(m) => !isColorSchemeModifier(m.modifier) && !isPlatformModifier(m.modifier) && !isDirectionalModifier(m.modifier)
|
|
3587
3918
|
);
|
|
3588
3919
|
const hasColorSchemeModifiers = colorSchemeModifiers.length > 0;
|
|
3589
3920
|
let componentScope = null;
|
|
@@ -3717,6 +4048,62 @@ function processTwCall(className, path2, state, parseClassName2, generateStyleKe
|
|
|
3717
4048
|
);
|
|
3718
4049
|
}
|
|
3719
4050
|
}
|
|
4051
|
+
const hasDirectionalModifiers = directionalModifiers.length > 0;
|
|
4052
|
+
if (hasDirectionalModifiers) {
|
|
4053
|
+
state.needsI18nManagerImport = true;
|
|
4054
|
+
const directionalConditionals = processDirectionalModifiers(
|
|
4055
|
+
directionalModifiers,
|
|
4056
|
+
state,
|
|
4057
|
+
parseClassName2,
|
|
4058
|
+
generateStyleKey2,
|
|
4059
|
+
t
|
|
4060
|
+
);
|
|
4061
|
+
const styleProperty = objectProperties.find(
|
|
4062
|
+
(prop) => t.isIdentifier(prop.key) && prop.key.name === "style"
|
|
4063
|
+
);
|
|
4064
|
+
if (styleProperty && t.isArrayExpression(styleProperty.value)) {
|
|
4065
|
+
styleProperty.value.elements.push(...directionalConditionals);
|
|
4066
|
+
} else {
|
|
4067
|
+
const styleArrayElements = [];
|
|
4068
|
+
if (baseClasses.length > 0) {
|
|
4069
|
+
const baseClassName = baseClasses.join(" ");
|
|
4070
|
+
const baseStyleObject = parseClassName2(baseClassName, state.customTheme);
|
|
4071
|
+
const baseStyleKey = generateStyleKey2(baseClassName);
|
|
4072
|
+
state.styleRegistry.set(baseStyleKey, baseStyleObject);
|
|
4073
|
+
styleArrayElements.push(
|
|
4074
|
+
t.memberExpression(t.identifier(state.stylesIdentifier), t.identifier(baseStyleKey))
|
|
4075
|
+
);
|
|
4076
|
+
}
|
|
4077
|
+
styleArrayElements.push(...directionalConditionals);
|
|
4078
|
+
objectProperties[0] = t.objectProperty(t.identifier("style"), t.arrayExpression(styleArrayElements));
|
|
4079
|
+
}
|
|
4080
|
+
const rtlModifiers = directionalModifiers.filter((m) => m.modifier === "rtl");
|
|
4081
|
+
const ltrModifiers = directionalModifiers.filter((m) => m.modifier === "ltr");
|
|
4082
|
+
if (rtlModifiers.length > 0) {
|
|
4083
|
+
const rtlClassNames = rtlModifiers.map((m) => m.baseClass).join(" ");
|
|
4084
|
+
const rtlStyleObject = parseClassName2(rtlClassNames, state.customTheme);
|
|
4085
|
+
const rtlStyleKey = generateStyleKey2(`rtl_${rtlClassNames}`);
|
|
4086
|
+
state.styleRegistry.set(rtlStyleKey, rtlStyleObject);
|
|
4087
|
+
objectProperties.push(
|
|
4088
|
+
t.objectProperty(
|
|
4089
|
+
t.identifier("rtlStyle"),
|
|
4090
|
+
t.memberExpression(t.identifier(state.stylesIdentifier), t.identifier(rtlStyleKey))
|
|
4091
|
+
)
|
|
4092
|
+
);
|
|
4093
|
+
}
|
|
4094
|
+
if (ltrModifiers.length > 0) {
|
|
4095
|
+
const ltrClassNames = ltrModifiers.map((m) => m.baseClass).join(" ");
|
|
4096
|
+
const ltrStyleObject = parseClassName2(ltrClassNames, state.customTheme);
|
|
4097
|
+
const ltrStyleKey = generateStyleKey2(`ltr_${ltrClassNames}`);
|
|
4098
|
+
state.styleRegistry.set(ltrStyleKey, ltrStyleObject);
|
|
4099
|
+
objectProperties.push(
|
|
4100
|
+
t.objectProperty(
|
|
4101
|
+
t.identifier("ltrStyle"),
|
|
4102
|
+
t.memberExpression(t.identifier(state.stylesIdentifier), t.identifier(ltrStyleKey))
|
|
4103
|
+
)
|
|
4104
|
+
);
|
|
4105
|
+
}
|
|
4106
|
+
}
|
|
3720
4107
|
const modifiersByType = /* @__PURE__ */ new Map();
|
|
3721
4108
|
for (const mod of otherModifiers) {
|
|
3722
4109
|
if (!modifiersByType.has(mod.modifier)) {
|
|
@@ -3773,7 +4160,7 @@ function programExit(path2, state, t) {
|
|
|
3773
4160
|
if (state.hasTwImport) {
|
|
3774
4161
|
removeTwImports(path2, t);
|
|
3775
4162
|
}
|
|
3776
|
-
if (!state.hasClassNames && !state.needsWindowDimensionsImport && !state.needsColorSchemeImport) {
|
|
4163
|
+
if (!state.hasClassNames && !state.needsWindowDimensionsImport && !state.needsColorSchemeImport && !state.needsI18nManagerImport) {
|
|
3777
4164
|
return;
|
|
3778
4165
|
}
|
|
3779
4166
|
if (!state.hasStyleSheetImport && state.styleRegistry.size > 0) {
|
|
@@ -3782,6 +4169,12 @@ function programExit(path2, state, t) {
|
|
|
3782
4169
|
if (state.needsPlatformImport && !state.hasPlatformImport) {
|
|
3783
4170
|
addPlatformImport(path2, t);
|
|
3784
4171
|
}
|
|
4172
|
+
if (state.needsI18nManagerImport && !state.hasI18nManagerImport) {
|
|
4173
|
+
addI18nManagerImport(path2, t);
|
|
4174
|
+
}
|
|
4175
|
+
if (state.needsI18nManagerImport) {
|
|
4176
|
+
injectI18nManagerVariable(path2, state.i18nManagerVariableName, state.i18nManagerLocalIdentifier, t);
|
|
4177
|
+
}
|
|
3785
4178
|
if (state.needsColorSchemeImport && !state.hasColorSchemeImport) {
|
|
3786
4179
|
addColorSchemeImport(path2, state.colorSchemeImportSource, state.colorSchemeHookName, t);
|
|
3787
4180
|
}
|