@weapp-tailwindcss/react-native 0.1.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/LICENSE +21 -0
- package/README.md +28 -0
- package/dist/babel.cjs +112 -0
- package/dist/babel.d.ts +21 -0
- package/dist/babel.js +110 -0
- package/dist/compiler.cjs +383 -0
- package/dist/compiler.d.ts +8 -0
- package/dist/compiler.js +378 -0
- package/dist/env.cjs +1 -0
- package/dist/env.d.ts +14 -0
- package/dist/env.js +2 -0
- package/dist/index.cjs +22 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +6 -0
- package/dist/metro-transformer.cjs +52 -0
- package/dist/metro-transformer.d.ts +5 -0
- package/dist/metro-transformer.js +49 -0
- package/dist/metro.cjs +156 -0
- package/dist/metro.d.ts +39 -0
- package/dist/metro.js +145 -0
- package/dist/rolldown-runtime-D6vf50IK.cjs +28 -0
- package/dist/runtime.cjs +187 -0
- package/dist/runtime.d.ts +17 -0
- package/dist/runtime.js +179 -0
- package/dist/tailwind.cjs +50 -0
- package/dist/tailwind.d.ts +13 -0
- package/dist/tailwind.js +49 -0
- package/dist/types-BTxnqaRV.d.ts +48 -0
- package/package.json +109 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { o as NativeStyleManifest, t as CompileNativeStylesheetOptions } from "./types-BTxnqaRV.js";
|
|
2
|
+
//#region src/compiler.d.ts
|
|
3
|
+
declare function addNativeVariantRules(manifest: NativeStyleManifest, candidates: Iterable<string>): void;
|
|
4
|
+
/** 为 manifest 生成稳定的 StyleSheet ID 和 Babel 静态 lookup。 */
|
|
5
|
+
declare function finalizeNativeManifest(manifest: NativeStyleManifest): NativeStyleManifest;
|
|
6
|
+
declare function compileNativeStylesheet(css: string, options?: CompileNativeStylesheetOptions): NativeStyleManifest;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { addNativeVariantRules, compileNativeStylesheet, finalizeNativeManifest };
|
package/dist/compiler.js
ADDED
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
import postcss from "postcss";
|
|
2
|
+
//#region src/compiler.ts
|
|
3
|
+
const CLASS_SELECTOR_RE = /\.((?:\\.|[^\s.#:[>+~])+)/g;
|
|
4
|
+
const COLOR_PROPERTIES = /* @__PURE__ */ new Set([
|
|
5
|
+
"color",
|
|
6
|
+
"backgroundColor",
|
|
7
|
+
"borderColor",
|
|
8
|
+
"borderTopColor",
|
|
9
|
+
"borderRightColor",
|
|
10
|
+
"borderBottomColor",
|
|
11
|
+
"borderLeftColor",
|
|
12
|
+
"shadowColor",
|
|
13
|
+
"textDecorationColor"
|
|
14
|
+
]);
|
|
15
|
+
const NUMERIC_PROPERTIES = /* @__PURE__ */ new Set([
|
|
16
|
+
"aspectRatio",
|
|
17
|
+
"borderBottomWidth",
|
|
18
|
+
"borderLeftWidth",
|
|
19
|
+
"borderRadius",
|
|
20
|
+
"borderRightWidth",
|
|
21
|
+
"borderTopLeftRadius",
|
|
22
|
+
"borderTopRightRadius",
|
|
23
|
+
"borderTopWidth",
|
|
24
|
+
"borderWidth",
|
|
25
|
+
"bottom",
|
|
26
|
+
"elevation",
|
|
27
|
+
"flex",
|
|
28
|
+
"flexBasis",
|
|
29
|
+
"flexGrow",
|
|
30
|
+
"flexShrink",
|
|
31
|
+
"fontSize",
|
|
32
|
+
"gap",
|
|
33
|
+
"height",
|
|
34
|
+
"left",
|
|
35
|
+
"letterSpacing",
|
|
36
|
+
"lineHeight",
|
|
37
|
+
"margin",
|
|
38
|
+
"marginBottom",
|
|
39
|
+
"marginHorizontal",
|
|
40
|
+
"marginLeft",
|
|
41
|
+
"marginRight",
|
|
42
|
+
"marginTop",
|
|
43
|
+
"marginVertical",
|
|
44
|
+
"maxHeight",
|
|
45
|
+
"maxWidth",
|
|
46
|
+
"minHeight",
|
|
47
|
+
"minWidth",
|
|
48
|
+
"opacity",
|
|
49
|
+
"padding",
|
|
50
|
+
"paddingBottom",
|
|
51
|
+
"paddingHorizontal",
|
|
52
|
+
"paddingLeft",
|
|
53
|
+
"paddingRight",
|
|
54
|
+
"paddingTop",
|
|
55
|
+
"paddingVertical",
|
|
56
|
+
"right",
|
|
57
|
+
"top",
|
|
58
|
+
"width",
|
|
59
|
+
"zIndex"
|
|
60
|
+
]);
|
|
61
|
+
const SHORTHANDS = {
|
|
62
|
+
margin: [
|
|
63
|
+
"marginTop",
|
|
64
|
+
"marginRight",
|
|
65
|
+
"marginBottom",
|
|
66
|
+
"marginLeft"
|
|
67
|
+
],
|
|
68
|
+
padding: [
|
|
69
|
+
"paddingTop",
|
|
70
|
+
"paddingRight",
|
|
71
|
+
"paddingBottom",
|
|
72
|
+
"paddingLeft"
|
|
73
|
+
]
|
|
74
|
+
};
|
|
75
|
+
const UNSUPPORTED_PROPERTIES = /* @__PURE__ */ new Set([
|
|
76
|
+
"filter",
|
|
77
|
+
"backdropFilter",
|
|
78
|
+
"animation",
|
|
79
|
+
"transition",
|
|
80
|
+
"textShadow",
|
|
81
|
+
"backgroundImage",
|
|
82
|
+
"appearance",
|
|
83
|
+
"content",
|
|
84
|
+
"cursor",
|
|
85
|
+
"userSelect",
|
|
86
|
+
"whiteSpace",
|
|
87
|
+
"objectFit",
|
|
88
|
+
"listStyleType",
|
|
89
|
+
"outline"
|
|
90
|
+
]);
|
|
91
|
+
function decodeCssIdentifier(value) {
|
|
92
|
+
return value.replace(/\\([0-9a-f]{1,6})\s?/gi, (_, code) => String.fromCodePoint(Number.parseInt(code, 16))).replace(/\\(.)/g, "$1");
|
|
93
|
+
}
|
|
94
|
+
function propertyName(property) {
|
|
95
|
+
return {
|
|
96
|
+
"padding-inline": "paddingHorizontal",
|
|
97
|
+
"padding-inline-start": "paddingLeft",
|
|
98
|
+
"padding-inline-end": "paddingRight",
|
|
99
|
+
"padding-block": "paddingVertical",
|
|
100
|
+
"padding-block-start": "paddingTop",
|
|
101
|
+
"padding-block-end": "paddingBottom",
|
|
102
|
+
"margin-inline": "marginHorizontal",
|
|
103
|
+
"margin-inline-start": "marginLeft",
|
|
104
|
+
"margin-inline-end": "marginRight",
|
|
105
|
+
"margin-block": "marginVertical",
|
|
106
|
+
"margin-block-start": "marginTop",
|
|
107
|
+
"margin-block-end": "marginBottom"
|
|
108
|
+
}[property] ?? property.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
109
|
+
}
|
|
110
|
+
function splitValue(value) {
|
|
111
|
+
return value.trim().split(/\s+/).filter(Boolean);
|
|
112
|
+
}
|
|
113
|
+
function parseNumber(value, variables) {
|
|
114
|
+
const resolved = resolveVariables(value, variables);
|
|
115
|
+
const calculated = resolved.match(/^calc\(\s*(-?(?:\d+\.\d+|\d+|\.\d+))(px|rem|em|%)?\s*\*\s*(-?(?:\d+\.\d+|\d+|\.\d+))\s*\)$/);
|
|
116
|
+
if (calculated) {
|
|
117
|
+
const base = parseNumber(`${calculated[1]}${calculated[2] ?? ""}`, variables);
|
|
118
|
+
return typeof base === "number" ? base * Number(calculated[3]) : void 0;
|
|
119
|
+
}
|
|
120
|
+
const match = resolved.match(/^(-?(?:\d+\.\d+|\d+|\.\d+))(px|rem|em|%)?$/);
|
|
121
|
+
if (!match) return;
|
|
122
|
+
const number = Number(match[1]);
|
|
123
|
+
if (match[2] === "%") return `${number}%`;
|
|
124
|
+
if (match[2] === "rem" || match[2] === "em") return number * 16;
|
|
125
|
+
return number;
|
|
126
|
+
}
|
|
127
|
+
function resolveVariables(value, variables) {
|
|
128
|
+
return value.replace(/var\((--[\w-]+)(?:,\s*([^)]*))?\)/g, (_, key, fallback) => variables[key] ?? fallback ?? `var(${key})`);
|
|
129
|
+
}
|
|
130
|
+
function isColor(value) {
|
|
131
|
+
return /^(?:#[\da-f]{3,8}|(?:rgb|rgba|hsl|hsla|oklch|oklab)\([^)]*\)|[a-z]+)$/i.test(value);
|
|
132
|
+
}
|
|
133
|
+
function oklchToHex(value) {
|
|
134
|
+
const match = value.match(/^oklch\(\s*([\d.]+)%?\s+([\d.]+)\s+([\d.]+)(?:\s+\/\s*([\d.]+))?\s*\)$/i);
|
|
135
|
+
if (!match) return;
|
|
136
|
+
const lightness = Number(match[1]) > 1 ? Number(match[1]) / 100 : Number(match[1]);
|
|
137
|
+
const chroma = Number(match[2]);
|
|
138
|
+
const hue = Number(match[3]) * Math.PI / 180;
|
|
139
|
+
const alpha = match[4] === void 0 ? 1 : Number(match[4]);
|
|
140
|
+
const a = chroma * Math.cos(hue);
|
|
141
|
+
const b = chroma * Math.sin(hue);
|
|
142
|
+
const l = lightness + .3963377774 * a + .2158037573 * b;
|
|
143
|
+
const m = lightness - .1055613458 * a - .0638541728 * b;
|
|
144
|
+
const s = lightness - .0894841775 * a - 1.291485548 * b;
|
|
145
|
+
const linear = (channel) => channel ** 3;
|
|
146
|
+
const red = 4.0767416621 * linear(l) - 3.3077115913 * linear(m) + .2309699292 * linear(s);
|
|
147
|
+
const green = -1.2684380046 * linear(l) + 2.6097574011 * linear(m) - .3413193965 * linear(s);
|
|
148
|
+
const blue = -.0041960863 * linear(l) - .7034186147 * linear(m) + 1.707614701 * linear(s);
|
|
149
|
+
const toByte = (channel) => Math.round(Math.max(0, Math.min(1, channel <= .0031308 ? 12.92 * channel : 1.055 * channel ** (1 / 2.4) - .055)) * 255);
|
|
150
|
+
const hex = [
|
|
151
|
+
red,
|
|
152
|
+
green,
|
|
153
|
+
blue
|
|
154
|
+
].map((channel) => toByte(channel).toString(16).padStart(2, "0")).join("");
|
|
155
|
+
return alpha < 1 ? `#${hex}${Math.round(alpha * 255).toString(16).padStart(2, "0")}` : `#${hex}`;
|
|
156
|
+
}
|
|
157
|
+
function normalizeColor(value) {
|
|
158
|
+
return /^oklch\(/i.test(value) ? oklchToHex(value) : value;
|
|
159
|
+
}
|
|
160
|
+
function parseTransform(value, variables) {
|
|
161
|
+
const transform = [];
|
|
162
|
+
for (const match of value.matchAll(/(translateX|translateY|translate|scaleX|scaleY|scale|rotate|skewX|skewY)\(([^)]*)\)/g)) {
|
|
163
|
+
const name = match[1];
|
|
164
|
+
const values = splitValue(resolveVariables(match[2] ?? "", variables).replace(",", " "));
|
|
165
|
+
if (!name || !values.length) continue;
|
|
166
|
+
if (name.startsWith("scale")) {
|
|
167
|
+
const number = Number(values[0] ?? "");
|
|
168
|
+
if (Number.isFinite(number)) transform.push({ [name]: number });
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
if (name === "translate") {
|
|
172
|
+
const x = parseNumber(values[0] ?? "", variables);
|
|
173
|
+
const y = parseNumber(values[1] ?? "0", variables);
|
|
174
|
+
if (x !== void 0 && y !== void 0) transform.push({ translateX: x }, { translateY: y });
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
const property = name.replace(/^translate$/, "translateX");
|
|
178
|
+
const parsed = name.startsWith("rotate") || name.startsWith("skew") ? values[0] : parseNumber(values[0] ?? "", variables);
|
|
179
|
+
if (parsed !== void 0) transform.push({ [property]: parsed });
|
|
180
|
+
}
|
|
181
|
+
return transform.length ? transform : void 0;
|
|
182
|
+
}
|
|
183
|
+
function parseShadow(value, variables) {
|
|
184
|
+
const resolved = resolveVariables(value, variables);
|
|
185
|
+
const color = resolved.match(/(?:rgba?|hsla?)\([^)]*\)|#[\da-f]{3,8}/i)?.[0];
|
|
186
|
+
const parts = splitValue(color ? resolved.replace(color, "") : resolved);
|
|
187
|
+
const lengths = parts.filter((part) => parseNumber(part, variables) !== void 0).slice(0, 3);
|
|
188
|
+
if (lengths.length < 2) return;
|
|
189
|
+
const [x = "0", y = "0", blur = "0"] = lengths;
|
|
190
|
+
const shadowColor = normalizeColor(color ?? parts.find((part) => isColor(part)) ?? "#000000") ?? "#000000";
|
|
191
|
+
const opacity = /rgba\([^,]+,[^,]+,[^,]+,\s*([\d.]+)\)/i.exec(shadowColor)?.[1];
|
|
192
|
+
return {
|
|
193
|
+
shadowOffset: {
|
|
194
|
+
width: parseNumber(x, variables),
|
|
195
|
+
height: parseNumber(y, variables)
|
|
196
|
+
},
|
|
197
|
+
shadowRadius: parseNumber(blur, variables),
|
|
198
|
+
shadowColor,
|
|
199
|
+
...opacity ? { shadowOpacity: Number(opacity) } : {}
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
function parseValue(property, value, variables) {
|
|
203
|
+
const trimmed = value.trim();
|
|
204
|
+
if (UNSUPPORTED_PROPERTIES.has(property)) return;
|
|
205
|
+
if (trimmed.includes("linear-gradient(") || trimmed.includes("url(")) return;
|
|
206
|
+
if (COLOR_PROPERTIES.has(property)) {
|
|
207
|
+
const color = resolveVariables(trimmed, variables);
|
|
208
|
+
return isColor(color) ? normalizeColor(color) : void 0;
|
|
209
|
+
}
|
|
210
|
+
if (NUMERIC_PROPERTIES.has(property)) return parseNumber(trimmed, variables);
|
|
211
|
+
if (property === "transform") return parseTransform(trimmed, variables);
|
|
212
|
+
if (property === "boxShadow") return parseShadow(trimmed, variables);
|
|
213
|
+
if (property === "display" && !["flex", "none"].includes(trimmed)) return;
|
|
214
|
+
return trimmed;
|
|
215
|
+
}
|
|
216
|
+
function expandDeclaration(property, value, variables) {
|
|
217
|
+
if (property === "margin" || property === "padding") {
|
|
218
|
+
const parts = splitValue(value).map((item) => parseNumber(item, variables));
|
|
219
|
+
if (parts.includes(void 0)) return;
|
|
220
|
+
const [top, right = top, bottom = top, left = right] = parts;
|
|
221
|
+
return Object.fromEntries(SHORTHANDS[property].map((key, index) => [key, [
|
|
222
|
+
top,
|
|
223
|
+
right,
|
|
224
|
+
bottom,
|
|
225
|
+
left
|
|
226
|
+
][index]]));
|
|
227
|
+
}
|
|
228
|
+
if (property === "border") {
|
|
229
|
+
const width = splitValue(value).find((item) => /^\d/.test(item));
|
|
230
|
+
const color = splitValue(value).find((item) => isColor(item));
|
|
231
|
+
return {
|
|
232
|
+
...width ? { borderWidth: parseNumber(width, variables) } : {},
|
|
233
|
+
...color ? { borderColor: color } : {}
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
if (property === "boxShadow") return parseShadow(value, variables);
|
|
237
|
+
const parsed = parseValue(property, value, variables);
|
|
238
|
+
return parsed === void 0 ? void 0 : { [property]: parsed };
|
|
239
|
+
}
|
|
240
|
+
function walkClasses(selector) {
|
|
241
|
+
const classes = [];
|
|
242
|
+
for (const match of selector.matchAll(CLASS_SELECTOR_RE)) {
|
|
243
|
+
const token = decodeCssIdentifier(match[1]);
|
|
244
|
+
if (token && !classes.includes(token)) classes.push(token);
|
|
245
|
+
}
|
|
246
|
+
return classes;
|
|
247
|
+
}
|
|
248
|
+
function variantForClass(className) {
|
|
249
|
+
const result = {};
|
|
250
|
+
for (const variant of className.split(":").slice(0, -1)) {
|
|
251
|
+
if (variant === "dark") result.colorScheme = "dark";
|
|
252
|
+
if (variant === "ios" || variant === "android" || variant === "native") result.platform = variant;
|
|
253
|
+
}
|
|
254
|
+
return result;
|
|
255
|
+
}
|
|
256
|
+
function atRuleVariant(node) {
|
|
257
|
+
if (!node) return {};
|
|
258
|
+
const params = node.params.toLowerCase();
|
|
259
|
+
if (params.includes("prefers-color-scheme") && params.includes("dark")) return { colorScheme: "dark" };
|
|
260
|
+
if (params.includes("platform") && params.includes("ios")) return { platform: "ios" };
|
|
261
|
+
if (params.includes("platform") && params.includes("android")) return { platform: "android" };
|
|
262
|
+
return {};
|
|
263
|
+
}
|
|
264
|
+
function addNativeVariantRules(manifest, candidates) {
|
|
265
|
+
for (const candidate of candidates) {
|
|
266
|
+
const parts = candidate.split(":");
|
|
267
|
+
if (parts.length < 2) continue;
|
|
268
|
+
const base = parts.at(-1);
|
|
269
|
+
if (!base || manifest.rules[candidate] || !manifest.rules[base]) continue;
|
|
270
|
+
const variant = variantForClass(candidate);
|
|
271
|
+
if (!variant.colorScheme && !variant.platform) continue;
|
|
272
|
+
manifest.rules[candidate] = manifest.rules[base].map((rule) => ({
|
|
273
|
+
...rule,
|
|
274
|
+
...variant,
|
|
275
|
+
style: { ...rule.style }
|
|
276
|
+
}));
|
|
277
|
+
manifest.classSet.push(candidate);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
function ancestors(node) {
|
|
281
|
+
const result = [];
|
|
282
|
+
let current = node.parent;
|
|
283
|
+
while (current && current.type !== "root") {
|
|
284
|
+
if (current.type === "atrule") result.unshift(current);
|
|
285
|
+
current = current.parent;
|
|
286
|
+
}
|
|
287
|
+
return result;
|
|
288
|
+
}
|
|
289
|
+
function collectVariables(root) {
|
|
290
|
+
const variables = {};
|
|
291
|
+
root.walkDecls((decl) => {
|
|
292
|
+
if (decl.prop.startsWith("--")) variables[decl.prop] = decl.value.trim();
|
|
293
|
+
});
|
|
294
|
+
return variables;
|
|
295
|
+
}
|
|
296
|
+
function addWarning(warnings, warning) {
|
|
297
|
+
if (!warnings.some((item) => item.message === warning.message && item.property === warning.property && item.className === warning.className)) warnings.push(warning);
|
|
298
|
+
}
|
|
299
|
+
function compileRule(rule, className, variables, warnings, order) {
|
|
300
|
+
const styles = {
|
|
301
|
+
normal: {},
|
|
302
|
+
important: {}
|
|
303
|
+
};
|
|
304
|
+
rule.walkDecls((decl) => {
|
|
305
|
+
if (decl.prop.startsWith("--")) return;
|
|
306
|
+
const property = propertyName(decl.prop);
|
|
307
|
+
const important = decl.important || /!important\s*$/i.test(decl.value);
|
|
308
|
+
const value = decl.value.replace(/\s*!important\s*$/i, "");
|
|
309
|
+
const expanded = expandDeclaration(property, value, variables);
|
|
310
|
+
if (!expanded || Object.values(expanded).includes(void 0)) {
|
|
311
|
+
const variableReference = /var\((--[\w-]+)/.exec(value)?.[1];
|
|
312
|
+
if (!variableReference || !variables[variableReference]) addWarning(warnings, {
|
|
313
|
+
className,
|
|
314
|
+
property,
|
|
315
|
+
message: `不支持将 ${decl.prop}: ${value} 编译为 React Native style`
|
|
316
|
+
});
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
Object.assign(styles[important ? "important" : "normal"], expanded);
|
|
320
|
+
});
|
|
321
|
+
const variant = {
|
|
322
|
+
...variantForClass(className),
|
|
323
|
+
...ancestors(rule).reduce((result, node) => ({
|
|
324
|
+
...result,
|
|
325
|
+
...atRuleVariant(node)
|
|
326
|
+
}), {})
|
|
327
|
+
};
|
|
328
|
+
return ["normal", "important"].filter((kind) => Object.keys(styles[kind]).length > 0).map((kind) => ({
|
|
329
|
+
style: styles[kind],
|
|
330
|
+
...variant,
|
|
331
|
+
important: kind === "important" || void 0,
|
|
332
|
+
order
|
|
333
|
+
}));
|
|
334
|
+
}
|
|
335
|
+
/** 为 manifest 生成稳定的 StyleSheet ID 和 Babel 静态 lookup。 */
|
|
336
|
+
function finalizeNativeManifest(manifest) {
|
|
337
|
+
const styleSheet = {};
|
|
338
|
+
const styleEntries = {};
|
|
339
|
+
const staticLookup = {};
|
|
340
|
+
let nextId = 0;
|
|
341
|
+
for (const [className, rules] of Object.entries(manifest.rules)) for (const rule of rules) {
|
|
342
|
+
const id = rule.id ?? `s${nextId++}`;
|
|
343
|
+
rule.id = id;
|
|
344
|
+
styleSheet[id] = rule.style;
|
|
345
|
+
styleEntries[id] = rule;
|
|
346
|
+
(staticLookup[className] ??= []).push(id);
|
|
347
|
+
}
|
|
348
|
+
manifest.styleSheet = styleSheet;
|
|
349
|
+
manifest.styleEntries = styleEntries;
|
|
350
|
+
manifest.staticLookup = staticLookup;
|
|
351
|
+
manifest.classSet = Object.keys(manifest.rules);
|
|
352
|
+
return manifest;
|
|
353
|
+
}
|
|
354
|
+
function compileNativeStylesheet(css, options = {}) {
|
|
355
|
+
const root = postcss.parse(css);
|
|
356
|
+
const variables = collectVariables(root);
|
|
357
|
+
const allowed = options.classSet ? new Set(options.classSet) : void 0;
|
|
358
|
+
const rules = {};
|
|
359
|
+
const warnings = [];
|
|
360
|
+
let order = 0;
|
|
361
|
+
root.walkRules((rule) => {
|
|
362
|
+
if (options.ignorePreflight !== false && (rule.selector.includes(":root") || rule.selector.includes("*") || rule.selector.includes("::"))) return;
|
|
363
|
+
for (const selector of rule.selectors) for (const className of walkClasses(selector)) {
|
|
364
|
+
if (allowed && !allowed.has(className)) continue;
|
|
365
|
+
const compiled = compileRule(rule, className, variables, warnings, order++);
|
|
366
|
+
if (compiled.length) (rules[className] ??= []).push(...compiled);
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
return finalizeNativeManifest({
|
|
370
|
+
version: 1,
|
|
371
|
+
classSet: Object.keys(rules),
|
|
372
|
+
rules,
|
|
373
|
+
variables,
|
|
374
|
+
warnings
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
//#endregion
|
|
378
|
+
export { addNativeVariantRules, compileNativeStylesheet, finalizeNativeManifest };
|
package/dist/env.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require("react-native");
|
package/dist/env.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import "react-native";
|
|
2
|
+
//#region src/env.d.ts
|
|
3
|
+
/** 供业务组件复用的 React Native className 属性。 */
|
|
4
|
+
interface NativeClassNameProps {
|
|
5
|
+
className?: string | undefined;
|
|
6
|
+
}
|
|
7
|
+
declare module 'react-native' {
|
|
8
|
+
interface ViewProps extends NativeClassNameProps {}
|
|
9
|
+
interface TextProps extends NativeClassNameProps {}
|
|
10
|
+
interface ImageProps extends NativeClassNameProps {}
|
|
11
|
+
interface ScrollViewProps extends NativeClassNameProps {}
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { NativeClassNameProps };
|
package/dist/env.js
ADDED
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_babel = require("./babel.cjs");
|
|
3
|
+
const require_compiler = require("./compiler.cjs");
|
|
4
|
+
const require_metro = require("./metro.cjs");
|
|
5
|
+
const require_runtime = require("./runtime.cjs");
|
|
6
|
+
const require_tailwind = require("./tailwind.cjs");
|
|
7
|
+
exports.VIRTUAL_MANIFEST_MODULE = require_metro.VIRTUAL_MANIFEST_MODULE;
|
|
8
|
+
exports.babelPlugin = require_babel;
|
|
9
|
+
exports.compileNativeStylesheet = require_compiler.compileNativeStylesheet;
|
|
10
|
+
exports.composeStyle = require_runtime.composeStyle;
|
|
11
|
+
exports.createNativeStyleRuntime = require_runtime.createNativeStyleRuntime;
|
|
12
|
+
exports.generateNativeStylesheet = require_tailwind.generateNativeStylesheet;
|
|
13
|
+
exports.getManifest = require_runtime.getManifest;
|
|
14
|
+
exports.getRegisteredManifest = require_metro.getRegisteredManifest;
|
|
15
|
+
exports.getStaticStyle = require_runtime.getStaticStyle;
|
|
16
|
+
exports.getVirtualModuleCode = require_metro.getVirtualModuleCode;
|
|
17
|
+
exports.getVirtualModuleCodeAsync = require_metro.getVirtualModuleCodeAsync;
|
|
18
|
+
exports.setEnvironment = require_runtime.setEnvironment;
|
|
19
|
+
exports.setManifest = require_runtime.setManifest;
|
|
20
|
+
exports.setStyleSheetFactory = require_runtime.setStyleSheetFactory;
|
|
21
|
+
exports.tw = require_runtime.tw;
|
|
22
|
+
exports.withWeappTailwindcss = require_metro.withWeappTailwindcss;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import weappReactNativeBabel from "./babel.js";
|
|
2
|
+
import { a as NativeStyleEnvironment, c as NativeStyleRuntime, i as NativePlatform, l as NativeStyleValue, n as NativeClassValue, o as NativeStyleManifest, r as NativeCompilerWarning, s as NativeStyleRule, t as CompileNativeStylesheetOptions } from "./types-BTxnqaRV.js";
|
|
3
|
+
import { compileNativeStylesheet } from "./compiler.js";
|
|
4
|
+
import { VIRTUAL_MANIFEST_MODULE, getRegisteredManifest, getVirtualModuleCode, getVirtualModuleCodeAsync, withWeappTailwindcss } from "./metro.js";
|
|
5
|
+
import { composeStyle, createNativeStyleRuntime, getManifest, getStaticStyle, setEnvironment, setManifest, setStyleSheetFactory, tw } from "./runtime.js";
|
|
6
|
+
import { generateNativeStylesheet } from "./tailwind.js";
|
|
7
|
+
export { type CompileNativeStylesheetOptions, type NativeClassValue, type NativeCompilerWarning, type NativePlatform, type NativeStyleEnvironment, type NativeStyleManifest, type NativeStyleRule, type NativeStyleRuntime, type NativeStyleValue, VIRTUAL_MANIFEST_MODULE, weappReactNativeBabel as babelPlugin, compileNativeStylesheet, composeStyle, createNativeStyleRuntime, generateNativeStylesheet, getManifest, getRegisteredManifest, getStaticStyle, getVirtualModuleCode, getVirtualModuleCodeAsync, setEnvironment, setManifest, setStyleSheetFactory, tw, withWeappTailwindcss };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import weappReactNativeBabel from "./babel.js";
|
|
2
|
+
import { compileNativeStylesheet } from "./compiler.js";
|
|
3
|
+
import { VIRTUAL_MANIFEST_MODULE, getRegisteredManifest, getVirtualModuleCode, getVirtualModuleCodeAsync, withWeappTailwindcss } from "./metro.js";
|
|
4
|
+
import { composeStyle, createNativeStyleRuntime, getManifest, getStaticStyle, setEnvironment, setManifest, setStyleSheetFactory, tw } from "./runtime.js";
|
|
5
|
+
import { generateNativeStylesheet } from "./tailwind.js";
|
|
6
|
+
export { VIRTUAL_MANIFEST_MODULE, weappReactNativeBabel as babelPlugin, compileNativeStylesheet, composeStyle, createNativeStyleRuntime, generateNativeStylesheet, getManifest, getRegisteredManifest, getStaticStyle, getVirtualModuleCode, getVirtualModuleCodeAsync, setEnvironment, setManifest, setStyleSheetFactory, tw, withWeappTailwindcss };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_rolldown_runtime = require("./rolldown-runtime-D6vf50IK.cjs");
|
|
3
|
+
const require_babel = require("./babel.cjs");
|
|
4
|
+
const require_metro = require("./metro.cjs");
|
|
5
|
+
let node_fs = require("node:fs");
|
|
6
|
+
node_fs = require_rolldown_runtime.__toESM(node_fs, 1);
|
|
7
|
+
let node_module = require("node:module");
|
|
8
|
+
let _babel_core = require("@babel/core");
|
|
9
|
+
//#region src/metro-transformer.ts
|
|
10
|
+
const require$1 = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
11
|
+
async function transform(config, projectRoot, filename, data, options) {
|
|
12
|
+
const virtualCode = await require_metro.getVirtualModuleCodeAsync(filename);
|
|
13
|
+
if (virtualCode) return {
|
|
14
|
+
output: [{
|
|
15
|
+
type: "js/module",
|
|
16
|
+
data: {
|
|
17
|
+
code: virtualCode,
|
|
18
|
+
map: null
|
|
19
|
+
}
|
|
20
|
+
}],
|
|
21
|
+
dependencies: []
|
|
22
|
+
};
|
|
23
|
+
const metroId = config.weappTailwindcssMetroId;
|
|
24
|
+
const manifestPath = config.weappTailwindcssManifestPath;
|
|
25
|
+
const manifest = (metroId ? await require_metro.getRegisteredManifest(metroId) : void 0) ?? (manifestPath ? readManifest(manifestPath) : void 0);
|
|
26
|
+
let source = data;
|
|
27
|
+
if (manifest && /\.(?:[cm]?[jt]sx?|flow)$/i.test(filename) && !filename.replaceAll("\\", "/").includes("/node_modules/")) {
|
|
28
|
+
const transformed = (0, _babel_core.transformSync)(data.toString(), {
|
|
29
|
+
filename,
|
|
30
|
+
configFile: false,
|
|
31
|
+
babelrc: false,
|
|
32
|
+
sourceType: "unambiguous",
|
|
33
|
+
parserOpts: { plugins: ["jsx", "typescript"] },
|
|
34
|
+
plugins: [[require_babel, {
|
|
35
|
+
classNameSet: manifest.classSet,
|
|
36
|
+
staticStyleMap: manifest.staticLookup
|
|
37
|
+
}]]
|
|
38
|
+
});
|
|
39
|
+
if (transformed?.code) source = Buffer.from(transformed.code);
|
|
40
|
+
}
|
|
41
|
+
const originalPath = config.weappTailwindcssOriginalTransformerPath;
|
|
42
|
+
return (originalPath ? require$1(originalPath) : require$1("metro-react-native-babel-transformer")).transform(config, projectRoot, filename, source, options);
|
|
43
|
+
}
|
|
44
|
+
function readManifest(filename) {
|
|
45
|
+
try {
|
|
46
|
+
return JSON.parse(node_fs.default.readFileSync(filename, "utf8"));
|
|
47
|
+
} catch {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
exports.transform = transform;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
//#region src/metro-transformer.d.ts
|
|
3
|
+
declare function transform(config: Record<string, unknown>, projectRoot: string, filename: string, data: Buffer, options: Record<string, unknown>): Promise<any>;
|
|
4
|
+
//#endregion
|
|
5
|
+
export { transform };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import weappReactNativeBabel from "./babel.js";
|
|
2
|
+
import { getRegisteredManifest, getVirtualModuleCodeAsync } from "./metro.js";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import { transformSync } from "@babel/core";
|
|
6
|
+
//#region src/metro-transformer.ts
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
async function transform(config, projectRoot, filename, data, options) {
|
|
9
|
+
const virtualCode = await getVirtualModuleCodeAsync(filename);
|
|
10
|
+
if (virtualCode) return {
|
|
11
|
+
output: [{
|
|
12
|
+
type: "js/module",
|
|
13
|
+
data: {
|
|
14
|
+
code: virtualCode,
|
|
15
|
+
map: null
|
|
16
|
+
}
|
|
17
|
+
}],
|
|
18
|
+
dependencies: []
|
|
19
|
+
};
|
|
20
|
+
const metroId = config.weappTailwindcssMetroId;
|
|
21
|
+
const manifestPath = config.weappTailwindcssManifestPath;
|
|
22
|
+
const manifest = (metroId ? await getRegisteredManifest(metroId) : void 0) ?? (manifestPath ? readManifest(manifestPath) : void 0);
|
|
23
|
+
let source = data;
|
|
24
|
+
if (manifest && /\.(?:[cm]?[jt]sx?|flow)$/i.test(filename) && !filename.replaceAll("\\", "/").includes("/node_modules/")) {
|
|
25
|
+
const transformed = transformSync(data.toString(), {
|
|
26
|
+
filename,
|
|
27
|
+
configFile: false,
|
|
28
|
+
babelrc: false,
|
|
29
|
+
sourceType: "unambiguous",
|
|
30
|
+
parserOpts: { plugins: ["jsx", "typescript"] },
|
|
31
|
+
plugins: [[weappReactNativeBabel, {
|
|
32
|
+
classNameSet: manifest.classSet,
|
|
33
|
+
staticStyleMap: manifest.staticLookup
|
|
34
|
+
}]]
|
|
35
|
+
});
|
|
36
|
+
if (transformed?.code) source = Buffer.from(transformed.code);
|
|
37
|
+
}
|
|
38
|
+
const originalPath = config.weappTailwindcssOriginalTransformerPath;
|
|
39
|
+
return (originalPath ? require(originalPath) : require("metro-react-native-babel-transformer")).transform(config, projectRoot, filename, source, options);
|
|
40
|
+
}
|
|
41
|
+
function readManifest(filename) {
|
|
42
|
+
try {
|
|
43
|
+
return JSON.parse(fs.readFileSync(filename, "utf8"));
|
|
44
|
+
} catch {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { transform };
|