@weapp-tailwindcss/postcss 3.3.5 → 3.3.7

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 (107) hide show
  1. package/README.md +10 -0
  2. package/README.zh-CN.md +6 -0
  3. package/dist/compat/index.d.ts +57 -0
  4. package/dist/compat/legacy-css/source-cleanup.d.ts +2 -0
  5. package/dist/compat/mini-program-css/output-import-shell.d.ts +8 -0
  6. package/dist/compat/native/compile.d.ts +2 -0
  7. package/dist/compat/native/properties.d.ts +15 -0
  8. package/dist/compat/native/selectors.d.ts +8 -0
  9. package/dist/compat/native/types.d.ts +23 -0
  10. package/dist/compat/processed-css/cleanup.d.ts +4 -0
  11. package/dist/compat/processed-css/composition.d.ts +6 -0
  12. package/dist/compat/processed-css/entry-directives.d.ts +1 -0
  13. package/dist/compat/processed-css/imports.d.ts +8 -0
  14. package/dist/compat/scoped-css/cleanup.d.ts +4 -0
  15. package/dist/compat/scoped-css/coverage.d.ts +10 -0
  16. package/dist/compat/scoped-css/covered-rules.d.ts +4 -0
  17. package/dist/compat/scoped-css/predicates.d.ts +13 -0
  18. package/dist/compat/tailwind-directive-injection.d.ts +8 -0
  19. package/dist/compat/tailwindcss-v4/generated-output.d.ts +5 -0
  20. package/dist/compat/tailwindcss-v4/package-import-statements.d.ts +1 -0
  21. package/dist/compat/tailwindcss-v4/preflight-imports.d.ts +3 -0
  22. package/dist/compat/tailwindcss-v4/rpx-candidates.d.ts +6 -0
  23. package/dist/compat/tailwindcss-v4/theme-injection.d.ts +1 -0
  24. package/dist/compat/tailwindcss-v4/theme-source.d.ts +5 -0
  25. package/dist/compat/tailwindcss-v4/user-css/apply-only.d.ts +6 -0
  26. package/dist/compat/tailwindcss-v4/user-css/apply-reference.d.ts +4 -0
  27. package/dist/compat/tailwindcss-v4/user-css/at-rules.d.ts +3 -0
  28. package/dist/compat/tailwindcss-v4/user-css/class-selectors.d.ts +2 -0
  29. package/dist/compat/tailwindcss-v4/user-css/directives/entry-source.d.ts +9 -0
  30. package/dist/compat/tailwindcss-v4/user-css/directives/fallback.d.ts +11 -0
  31. package/dist/compat/tailwindcss-v4/user-css/directives/index.d.ts +2 -0
  32. package/dist/compat/tailwindcss-v4/user-css/directives/shared.d.ts +26 -0
  33. package/dist/compat/tailwindcss-v4/user-css/framework-composition.d.ts +2 -0
  34. package/dist/compat/tailwindcss-v4/user-css/framework-source.d.ts +1 -0
  35. package/dist/compat/tailwindcss-v4/user-css/generated-cleanup.d.ts +7 -0
  36. package/dist/compat/tailwindcss-v4/user-css/identity.d.ts +1 -0
  37. package/dist/compat/tailwindcss-v4/user-css/markers.d.ts +32 -0
  38. package/dist/compat/tailwindcss-v4/user-css/rule-deduplication.d.ts +1 -0
  39. package/dist/compat/tailwindcss-v4/user-css/scoped-rules.d.ts +4 -0
  40. package/dist/compat/tailwindcss-v4/user-css/source-fragments.d.ts +15 -0
  41. package/dist/compat/tailwindcss-v4/user-css/transform.d.ts +14 -0
  42. package/dist/compat/tailwindcss-v4/user-css/user-layer-order.d.ts +10 -0
  43. package/dist/compat/tailwindcss-v4/user-css/user-layers.d.ts +15 -0
  44. package/dist/compat/uni-app-x/apply-source.d.ts +2 -0
  45. package/dist/compat/uni-app-x/harmony-apply.d.ts +2 -0
  46. package/dist/compat/uni-app-x/reference-paths.d.ts +2 -0
  47. package/dist/compat/uni-app-x-style-value.d.ts +2 -0
  48. package/dist/compat/webpack-css/bare-selectors.d.ts +1 -0
  49. package/dist/compat/webpack-css/generated-cleanup.d.ts +4 -0
  50. package/dist/compat/webpack-css/identity.d.ts +5 -0
  51. package/dist/compat/webpack-css/preflight.d.ts +5 -0
  52. package/dist/compat/webpack-css/user-source.d.ts +6 -0
  53. package/dist/diagnostics/rpx-theme.d.ts +9 -0
  54. package/dist/directives-C7XTve1w.js +8263 -0
  55. package/dist/experimental/lightningcss/index.cjs +256 -0
  56. package/dist/experimental/lightningcss/index.d.ts +3 -0
  57. package/dist/experimental/lightningcss/index.js +245 -0
  58. package/dist/experimental/lightningcss/options.d.ts +3 -0
  59. package/dist/experimental/lightningcss/selector-transform.d.ts +10 -0
  60. package/dist/experimental/lightningcss/selector-utils.d.ts +10 -0
  61. package/dist/generator-plugin/config-directive.d.ts +5 -0
  62. package/dist/generator-plugin/source-files.d.ts +5 -5
  63. package/dist/generator-plugin/types.d.ts +5 -0
  64. package/dist/index.cjs +383 -9089
  65. package/dist/index.d.ts +2 -43
  66. package/dist/index.js +10 -8935
  67. package/dist/native.cjs +425 -0
  68. package/dist/native.d.ts +3 -0
  69. package/dist/native.js +419 -0
  70. package/dist/plugin-CRzZbcEf.js +185 -0
  71. package/dist/plugin-DwoAGHyN.cjs +194 -0
  72. package/dist/plugin.cjs +3 -0
  73. package/dist/plugin.d.ts +2 -0
  74. package/dist/plugin.js +2 -0
  75. package/dist/postcss-runtime-i5rHe_mj.js +2 -0
  76. package/dist/preflight-BTZL2nvC.cjs +21 -0
  77. package/dist/preflight-DVg4eehD.js +16 -0
  78. package/dist/resolve-BFphwPip.cjs +9987 -0
  79. package/dist/resolve-D-FbFBpF.js +1139 -0
  80. package/dist/rewrite-imports-Dk9TKKSF.js +145 -0
  81. package/dist/shared-CELzerNo.cjs +34 -0
  82. package/dist/shared-CfQUwapA.js +23 -0
  83. package/dist/source-scan/candidates.d.ts +4 -0
  84. package/dist/source-scan/description.d.ts +15 -0
  85. package/dist/source-scan/params.d.ts +5 -0
  86. package/dist/source-scan/resolve.d.ts +30 -0
  87. package/dist/source-scan/tailwind-v4/entry-source.d.ts +16 -0
  88. package/dist/source-scan/tailwind-v4/fingerprint.d.ts +5 -0
  89. package/dist/source-scan.d.ts +3 -24
  90. package/dist/syntax/index.d.ts +1 -0
  91. package/dist/syntax/location-dependencies.d.ts +2 -0
  92. package/dist/syntax/rewrite-imports.d.ts +5 -0
  93. package/dist/syntax/runtime-signature.d.ts +2 -0
  94. package/dist/syntax/source-style.d.ts +1 -0
  95. package/dist/syntax.cjs +1167 -0
  96. package/dist/syntax.d.ts +6 -0
  97. package/dist/syntax.js +3 -0
  98. package/dist/transform-BGYgGeQj.js +9239 -0
  99. package/dist/transform-DpFypcaN.cjs +10956 -0
  100. package/dist/transform.cjs +421 -0
  101. package/dist/transform.d.ts +40 -0
  102. package/dist/transform.js +10 -0
  103. package/dist/utils/apply-source.d.ts +11 -0
  104. package/dist/utils/css-source-trace.d.ts +6 -0
  105. package/dist/utils/custom-property-values.d.ts +4 -0
  106. package/dist/utils/generated-css-marker.d.ts +12 -0
  107. package/package.json +49 -9
package/dist/native.js ADDED
@@ -0,0 +1,419 @@
1
+ import { postcss } from "./postcss-runtime-i5rHe_mj.js";
2
+ //#region src/compat/native/properties.ts
3
+ const COLOR_PROPERTIES = /* @__PURE__ */ new Set([
4
+ "color",
5
+ "backgroundColor",
6
+ "borderColor",
7
+ "borderTopColor",
8
+ "borderRightColor",
9
+ "borderBottomColor",
10
+ "borderLeftColor",
11
+ "shadowColor",
12
+ "textDecorationColor"
13
+ ]);
14
+ const NUMERIC_PROPERTIES = /* @__PURE__ */ new Set([
15
+ "aspectRatio",
16
+ "borderBottomWidth",
17
+ "borderLeftWidth",
18
+ "borderRadius",
19
+ "borderRightWidth",
20
+ "borderTopLeftRadius",
21
+ "borderTopRightRadius",
22
+ "borderTopWidth",
23
+ "borderWidth",
24
+ "bottom",
25
+ "elevation",
26
+ "flex",
27
+ "flexBasis",
28
+ "flexGrow",
29
+ "flexShrink",
30
+ "fontSize",
31
+ "gap",
32
+ "height",
33
+ "left",
34
+ "letterSpacing",
35
+ "lineHeight",
36
+ "margin",
37
+ "marginBottom",
38
+ "marginHorizontal",
39
+ "marginLeft",
40
+ "marginRight",
41
+ "marginTop",
42
+ "marginVertical",
43
+ "maxHeight",
44
+ "maxWidth",
45
+ "minHeight",
46
+ "minWidth",
47
+ "opacity",
48
+ "padding",
49
+ "paddingBottom",
50
+ "paddingHorizontal",
51
+ "paddingLeft",
52
+ "paddingRight",
53
+ "paddingTop",
54
+ "paddingVertical",
55
+ "right",
56
+ "top",
57
+ "width",
58
+ "zIndex"
59
+ ]);
60
+ const STRING_PROPERTIES = /* @__PURE__ */ new Set([
61
+ "alignContent",
62
+ "alignItems",
63
+ "alignSelf",
64
+ "borderStyle",
65
+ "direction",
66
+ "display",
67
+ "flexDirection",
68
+ "flexWrap",
69
+ "fontFamily",
70
+ "fontStyle",
71
+ "fontWeight",
72
+ "justifyContent",
73
+ "overflow",
74
+ "position",
75
+ "textAlign",
76
+ "textDecorationLine",
77
+ "textDecorationStyle",
78
+ "textTransform",
79
+ "writingDirection"
80
+ ]);
81
+ const SHORTHANDS = {
82
+ margin: [
83
+ "marginTop",
84
+ "marginRight",
85
+ "marginBottom",
86
+ "marginLeft"
87
+ ],
88
+ padding: [
89
+ "paddingTop",
90
+ "paddingRight",
91
+ "paddingBottom",
92
+ "paddingLeft"
93
+ ]
94
+ };
95
+ const UNSUPPORTED_PROPERTIES = /* @__PURE__ */ new Set([
96
+ "filter",
97
+ "backdropFilter",
98
+ "animation",
99
+ "transition",
100
+ "textShadow",
101
+ "backgroundImage",
102
+ "appearance",
103
+ "content",
104
+ "cursor",
105
+ "userSelect",
106
+ "whiteSpace",
107
+ "objectFit",
108
+ "listStyleType",
109
+ "outline"
110
+ ]);
111
+ function propertyName(property) {
112
+ return {
113
+ "padding-inline": "paddingHorizontal",
114
+ "padding-inline-start": "paddingLeft",
115
+ "padding-inline-end": "paddingRight",
116
+ "padding-block": "paddingVertical",
117
+ "padding-block-start": "paddingTop",
118
+ "padding-block-end": "paddingBottom",
119
+ "margin-inline": "marginHorizontal",
120
+ "margin-inline-start": "marginLeft",
121
+ "margin-inline-end": "marginRight",
122
+ "margin-block": "marginVertical",
123
+ "margin-block-start": "marginTop",
124
+ "margin-block-end": "marginBottom"
125
+ }[property] ?? property.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
126
+ }
127
+ function splitValue(value) {
128
+ return value.trim().split(/\s+/).filter(Boolean);
129
+ }
130
+ function parseNumber(value, variables) {
131
+ const resolved = resolveVariables(value, variables);
132
+ const fraction = resolved.match(/^(-?(?:\d+\.\d+|\d+|\.\d+))\s*\/\s*(-?(?:\d+\.\d+|\d+|\.\d+))$/);
133
+ if (fraction && Number(fraction[2]) !== 0) return Number(fraction[1]) / Number(fraction[2]);
134
+ const calculated = resolved.match(/^calc\(\s*(-?(?:\d+\.\d+|\d+|\.\d+))(px|rem|em|%)?\s*\*\s*(-?(?:\d+\.\d+|\d+|\.\d+))\s*\)$/);
135
+ if (calculated) {
136
+ const base = parseNumber(`${calculated[1]}${calculated[2] ?? ""}`, variables);
137
+ return typeof base === "number" ? base * Number(calculated[3]) : void 0;
138
+ }
139
+ const match = resolved.match(/^(-?(?:\d+\.\d+|\d+|\.\d+))(px|rem|em|%)?$/);
140
+ if (!match) return;
141
+ const number = Number(match[1]);
142
+ if (match[2] === "%") return `${number}%`;
143
+ if (match[2] === "rem" || match[2] === "em") return number * 16;
144
+ return number;
145
+ }
146
+ function resolveVariables(value, variables) {
147
+ return value.replace(/var\((--[\w-]+)(?:,\s*([^)]*))?\)/g, (_, key, fallback) => variables[key] ?? fallback ?? `var(${key})`);
148
+ }
149
+ function isColor(value) {
150
+ return /^(?:#[\da-f]{3,8}|(?:rgb|rgba|hsl|hsla|oklch|oklab)\([^)]*\)|[a-z]+)$/i.test(value);
151
+ }
152
+ function oklchToHex(value) {
153
+ const match = value.match(/^oklch\(\s*([\d.]+)%?\s+([\d.]+)\s+([\d.]+)(?:\s+\/\s*([\d.]+))?\s*\)$/i);
154
+ if (!match) return;
155
+ const lightness = Number(match[1]) > 1 ? Number(match[1]) / 100 : Number(match[1]);
156
+ const chroma = Number(match[2]);
157
+ const hue = Number(match[3]) * Math.PI / 180;
158
+ const alpha = match[4] === void 0 ? 1 : Number(match[4]);
159
+ const a = chroma * Math.cos(hue);
160
+ const b = chroma * Math.sin(hue);
161
+ const l = lightness + .3963377774 * a + .2158037573 * b;
162
+ const m = lightness - .1055613458 * a - .0638541728 * b;
163
+ const s = lightness - .0894841775 * a - 1.291485548 * b;
164
+ const linear = (channel) => channel ** 3;
165
+ const red = 4.0767416621 * linear(l) - 3.3077115913 * linear(m) + .2309699292 * linear(s);
166
+ const green = -1.2684380046 * linear(l) + 2.6097574011 * linear(m) - .3413193965 * linear(s);
167
+ const blue = -.0041960863 * linear(l) - .7034186147 * linear(m) + 1.707614701 * linear(s);
168
+ const toByte = (channel) => Math.round(Math.max(0, Math.min(1, channel <= .0031308 ? 12.92 * channel : 1.055 * channel ** (1 / 2.4) - .055)) * 255);
169
+ const hex = [
170
+ red,
171
+ green,
172
+ blue
173
+ ].map((channel) => toByte(channel).toString(16).padStart(2, "0")).join("");
174
+ return alpha < 1 ? `#${hex}${Math.round(alpha * 255).toString(16).padStart(2, "0")}` : `#${hex}`;
175
+ }
176
+ function normalizeColor(value) {
177
+ return /^oklch\(/i.test(value) ? oklchToHex(value) : value;
178
+ }
179
+ function parseTransform(value, variables) {
180
+ const transform = [];
181
+ for (const match of value.matchAll(/(translateX|translateY|translate|scaleX|scaleY|scale|rotate|skewX|skewY)\(([^)]*)\)/g)) {
182
+ const name = match[1];
183
+ const values = splitValue(resolveVariables(match[2] ?? "", variables).replace(",", " "));
184
+ if (!name || !values.length) continue;
185
+ if (name.startsWith("scale")) {
186
+ const number = Number(values[0] ?? "");
187
+ if (Number.isFinite(number)) transform.push({ [name]: number });
188
+ continue;
189
+ }
190
+ if (name === "translate") {
191
+ const x = parseNumber(values[0] ?? "", variables);
192
+ const y = parseNumber(values[1] ?? "0", variables);
193
+ if (x !== void 0 && y !== void 0) transform.push({ translateX: x }, { translateY: y });
194
+ continue;
195
+ }
196
+ const property = name.replace(/^translate$/, "translateX");
197
+ const parsed = name.startsWith("rotate") || name.startsWith("skew") ? values[0] : parseNumber(values[0] ?? "", variables);
198
+ if (parsed !== void 0) transform.push({ [property]: parsed });
199
+ }
200
+ return transform.length ? transform : void 0;
201
+ }
202
+ function parseShadow(value, variables) {
203
+ const resolved = resolveVariables(value, variables);
204
+ const color = resolved.match(/(?:rgba?|hsla?)\([^)]*\)|#[\da-f]{3,8}/i)?.[0];
205
+ const parts = splitValue(color ? resolved.replace(color, "") : resolved);
206
+ const lengths = parts.filter((part) => parseNumber(part, variables) !== void 0).slice(0, 3);
207
+ if (lengths.length < 2) return;
208
+ const [x = "0", y = "0", blur = "0"] = lengths;
209
+ const shadowColor = normalizeColor(color ?? parts.find((part) => isColor(part)) ?? "#000000") ?? "#000000";
210
+ const opacity = /rgba\([^,]+,[^,]+,[^,]+,\s*([\d.]+)\)/i.exec(shadowColor)?.[1];
211
+ return {
212
+ shadowOffset: {
213
+ width: parseNumber(x, variables),
214
+ height: parseNumber(y, variables)
215
+ },
216
+ shadowRadius: parseNumber(blur, variables),
217
+ shadowColor,
218
+ ...opacity ? { shadowOpacity: Number(opacity) } : {}
219
+ };
220
+ }
221
+ function parseValue(property, value, variables) {
222
+ const trimmed = value.trim();
223
+ if (UNSUPPORTED_PROPERTIES.has(property)) return;
224
+ if (trimmed.includes("linear-gradient(") || trimmed.includes("url(")) return;
225
+ if (COLOR_PROPERTIES.has(property)) {
226
+ const color = resolveVariables(trimmed, variables);
227
+ return isColor(color) ? normalizeColor(color) : void 0;
228
+ }
229
+ if (NUMERIC_PROPERTIES.has(property)) {
230
+ const number = parseNumber(trimmed, variables);
231
+ if (property === "opacity" && typeof number === "string" && number.endsWith("%")) return Number.parseFloat(number) / 100;
232
+ return number;
233
+ }
234
+ if (property === "transform") return parseTransform(trimmed, variables);
235
+ if (property === "boxShadow") return parseShadow(trimmed, variables);
236
+ if (property === "display" && !["flex", "none"].includes(trimmed)) return;
237
+ return STRING_PROPERTIES.has(property) ? trimmed : void 0;
238
+ }
239
+ function expandDeclaration(property, value, variables) {
240
+ if (property === "margin" || property === "padding") {
241
+ const parts = splitValue(value).map((item) => parseNumber(item, variables));
242
+ if (parts.includes(void 0)) return;
243
+ const [top, right = top, bottom = top, left = right] = parts;
244
+ return Object.fromEntries(SHORTHANDS[property].map((key, index) => [key, [
245
+ top,
246
+ right,
247
+ bottom,
248
+ left
249
+ ][index]]));
250
+ }
251
+ if (property === "border") {
252
+ const width = splitValue(value).find((item) => /^\d/.test(item));
253
+ const color = splitValue(value).find((item) => isColor(item));
254
+ return {
255
+ ...width ? { borderWidth: parseNumber(width, variables) } : {},
256
+ ...color ? { borderColor: color } : {}
257
+ };
258
+ }
259
+ if (property === "boxShadow") return parseShadow(value, variables);
260
+ const parsed = parseValue(property, value, variables);
261
+ return parsed === void 0 ? void 0 : { [property]: parsed };
262
+ }
263
+ //#endregion
264
+ //#region src/compat/native/selectors.ts
265
+ const CLASS_SELECTOR_RE = /\.((?:\\.|[^\s.#:[>+~])+)/g;
266
+ function decodeCssIdentifier(value) {
267
+ return value.replace(/\\([0-9a-f]{1,6})\s?/gi, (_, code) => String.fromCodePoint(Number.parseInt(code, 16))).replace(/\\(.)/g, "$1");
268
+ }
269
+ function splitClassName(className) {
270
+ const parts = [];
271
+ let current = "";
272
+ let bracketDepth = 0;
273
+ let escaped = false;
274
+ for (const character of className) {
275
+ if (escaped) {
276
+ current += character;
277
+ escaped = false;
278
+ continue;
279
+ }
280
+ if (character === "\\") {
281
+ current += character;
282
+ escaped = true;
283
+ continue;
284
+ }
285
+ if (character === "[") bracketDepth += 1;
286
+ if (character === "]") bracketDepth = Math.max(0, bracketDepth - 1);
287
+ if (character === ":" && bracketDepth === 0) {
288
+ parts.push(current);
289
+ current = "";
290
+ continue;
291
+ }
292
+ current += character;
293
+ }
294
+ parts.push(current);
295
+ return parts;
296
+ }
297
+ function baseClassName(className) {
298
+ return splitClassName(className).at(-1);
299
+ }
300
+ function unsupportedVariant(className) {
301
+ return splitClassName(className).slice(0, -1).find((variant) => ![
302
+ "dark",
303
+ "ios",
304
+ "android",
305
+ "native"
306
+ ].includes(variant));
307
+ }
308
+ function walkClasses(selector) {
309
+ const classes = [];
310
+ for (const match of selector.matchAll(CLASS_SELECTOR_RE)) {
311
+ const token = decodeCssIdentifier(match[1]);
312
+ if (token && !classes.includes(token)) classes.push(token);
313
+ }
314
+ return classes;
315
+ }
316
+ function variantForClass(className) {
317
+ const result = {};
318
+ for (const variant of splitClassName(className).slice(0, -1)) {
319
+ if (variant === "dark") result.colorScheme = "dark";
320
+ if (variant === "ios" || variant === "android" || variant === "native") result.platform = variant;
321
+ }
322
+ return result;
323
+ }
324
+ function atRuleVariant(node) {
325
+ if (!node) return {};
326
+ const params = node.params.toLowerCase();
327
+ if (params.includes("prefers-color-scheme") && params.includes("dark")) return { colorScheme: "dark" };
328
+ if (params.includes("platform") && params.includes("ios")) return { platform: "ios" };
329
+ if (params.includes("platform") && params.includes("android")) return { platform: "android" };
330
+ return {};
331
+ }
332
+ //#endregion
333
+ //#region src/compat/native/compile.ts
334
+ function ancestors(node) {
335
+ const result = [];
336
+ let current = node.parent;
337
+ while (current && current.type !== "root") {
338
+ if (current.type === "atrule") result.unshift(current);
339
+ current = current.parent;
340
+ }
341
+ return result;
342
+ }
343
+ function collectVariables(root) {
344
+ const variables = {};
345
+ root.walkDecls((decl) => {
346
+ if (decl.prop.startsWith("--")) variables[decl.prop] = decl.value.trim();
347
+ });
348
+ return variables;
349
+ }
350
+ function addWarning(warnings, warning) {
351
+ if (!warnings.some((item) => item.message === warning.message && item.property === warning.property && item.className === warning.className)) warnings.push(warning);
352
+ }
353
+ function compileRule(rule, className, variables, warnings, order) {
354
+ const unsupported = unsupportedVariant(className);
355
+ if (unsupported) {
356
+ addWarning(warnings, {
357
+ className,
358
+ property: "variant",
359
+ message: `不支持将 ${unsupported}: 变体编译为 React Native 条件样式`
360
+ });
361
+ return [];
362
+ }
363
+ const styles = {
364
+ normal: {},
365
+ important: {}
366
+ };
367
+ rule.walkDecls((decl) => {
368
+ if (decl.prop.startsWith("--")) return;
369
+ const property = propertyName(decl.prop);
370
+ const important = decl.important || /!important\s*$/i.test(decl.value);
371
+ const value = decl.value.replace(/\s*!important\s*$/i, "");
372
+ const expanded = expandDeclaration(property, value, variables);
373
+ if (!expanded || Object.values(expanded).includes(void 0)) {
374
+ addWarning(warnings, {
375
+ className,
376
+ property,
377
+ message: `不支持将 ${decl.prop}: ${value} 编译为 React Native style`
378
+ });
379
+ return;
380
+ }
381
+ Object.assign(styles[important ? "important" : "normal"], expanded);
382
+ });
383
+ const variant = {
384
+ ...variantForClass(className),
385
+ ...ancestors(rule).reduce((result, node) => ({
386
+ ...result,
387
+ ...atRuleVariant(node)
388
+ }), {})
389
+ };
390
+ return ["normal", "important"].filter((kind) => Object.keys(styles[kind]).length > 0).map((kind) => ({
391
+ style: styles[kind],
392
+ ...variant,
393
+ important: kind === "important" || void 0,
394
+ order
395
+ }));
396
+ }
397
+ function compileNativeCss(css, options = {}) {
398
+ const root = postcss.parse(css);
399
+ const variables = collectVariables(root);
400
+ const allowed = options.classSet ? new Set(options.classSet) : void 0;
401
+ const rules = {};
402
+ const warnings = [];
403
+ let order = 0;
404
+ root.walkRules((rule) => {
405
+ if (options.ignorePreflight !== false && (rule.selector.includes(":root") || rule.selector.includes("*") || rule.selector.includes("::"))) return;
406
+ for (const selector of rule.selectors) for (const className of walkClasses(selector)) {
407
+ if (allowed && !allowed.has(className)) continue;
408
+ const compiled = compileRule(rule, className, variables, warnings, order++);
409
+ if (compiled.length) (rules[className] ??= []).push(...compiled);
410
+ }
411
+ });
412
+ return {
413
+ rules,
414
+ variables,
415
+ warnings
416
+ };
417
+ }
418
+ //#endregion
419
+ export { baseClassName, compileNativeCss, splitClassName, variantForClass };
@@ -0,0 +1,185 @@
1
+ import { collectApplyOnlyCssSelectorsRoot, filterApplyOnlyGeneratedCss, finalizeMiniProgramCss, hasTailwindApplyDirective, hasTailwindRootDirectives, prependConfigDirective, transformLynxCssCompat, transformWebCssCompat } from "./directives-C7XTve1w.js";
2
+ import { DEFAULT_SOURCE_SCAN_EXTENSIONS, createSourceScanPattern, expandTailwindSourceEntries, resolveCssScanSources, resolveCssSourceEntries } from "./resolve-D-FbFBpF.js";
3
+ import postcss from "postcss";
4
+ import path from "node:path";
5
+ import { extractValidCandidates } from "@weapp-tailwindcss/engine";
6
+ import process from "node:process";
7
+ import { readFile } from "node:fs/promises";
8
+ //#region src/generator-plugin/context.ts
9
+ const PLUGIN_NAME$1 = "weapp-tailwindcss";
10
+ function resolveInputFile(result) {
11
+ const from = result.opts.from;
12
+ if (typeof from !== "string" || from.length === 0) return;
13
+ return path.isAbsolute(from) ? from : path.resolve(process.cwd(), from);
14
+ }
15
+ function resolvePostcssBase(result, options) {
16
+ if (options.base) return options.base;
17
+ const inputFile = resolveInputFile(result);
18
+ return inputFile ? path.dirname(inputFile) : process.cwd();
19
+ }
20
+ function resolvePostcssProjectRoot(result, options) {
21
+ if (options.projectRoot) return options.projectRoot;
22
+ const inputFile = resolveInputFile(result);
23
+ return inputFile ? path.dirname(inputFile) : process.cwd();
24
+ }
25
+ function replaceRootCss(root, css, result) {
26
+ root.removeAll();
27
+ try {
28
+ const nextRoot = postcss.parse(css, { from: resolveInputFile(result) });
29
+ root.append(nextRoot.nodes);
30
+ } catch {
31
+ root.raws = { after: css };
32
+ }
33
+ }
34
+ function addDependencyMessages(result, generated) {
35
+ for (const file of generated.dependencies) result.messages.push({
36
+ type: "dependency",
37
+ plugin: PLUGIN_NAME$1,
38
+ file
39
+ });
40
+ }
41
+ function addSourceDependencyMessages(result, files) {
42
+ for (const file of files) result.messages.push({
43
+ type: "dependency",
44
+ plugin: PLUGIN_NAME$1,
45
+ file
46
+ });
47
+ }
48
+ //#endregion
49
+ //#region src/generator-plugin/source-files.ts
50
+ const POSTCSS_SOURCE_PATTERN$1 = createSourceScanPattern(DEFAULT_SOURCE_SCAN_EXTENSIONS);
51
+ function resolveCompatibilityScan(root, result, options, context, local) {
52
+ const css = context.css ?? root.toString();
53
+ const applyOnly = hasTailwindApplyDirective(css) && !hasTailwindRootDirectives(root, { importFallback: true });
54
+ const base = resolvePostcssBase(result, options);
55
+ return resolveCssScanSources([{
56
+ root,
57
+ base
58
+ }], {
59
+ base,
60
+ automatic: local || applyOnly || options.scanSources === false ? "disabled" : "auto",
61
+ pattern: POSTCSS_SOURCE_PATTERN$1,
62
+ config: options.config,
63
+ configResolution: "path",
64
+ sourceEntries: context.sourceEntries,
65
+ loadConfigContent: local
66
+ });
67
+ }
68
+ async function collectAutoTailwindCandidates(root, result, options, context = {}) {
69
+ if (options.scanSources === false) return /* @__PURE__ */ new Set();
70
+ const scan = await resolveCompatibilityScan(root, result, options, context, false);
71
+ const candidates = !scan.entries.some((entry) => !entry.negated) ? [] : await extractValidCandidates({
72
+ base: resolvePostcssBase(result, options),
73
+ css: context.css ?? root.toString(),
74
+ cwd: resolvePostcssProjectRoot(result, options),
75
+ sources: scan.entries
76
+ });
77
+ return /* @__PURE__ */ new Set([...[...candidates].filter((candidate) => !scan.inlineCandidates.excluded.has(candidate)), ...scan.inlineCandidates.included]);
78
+ }
79
+ async function collectPostcssLocalSources(root, result, options, context = {}) {
80
+ const scan = await resolveCompatibilityScan(root, result, options, context, true);
81
+ const files = [.../* @__PURE__ */ new Set([...await expandTailwindSourceEntries(scan.explicitEntries), ...(await Promise.all(scan.configGroups.map((entries) => expandTailwindSourceEntries(entries)))).flat()])];
82
+ const sources = await Promise.all(files.map(async (file) => {
83
+ const extension = path.extname(file).slice(1);
84
+ return {
85
+ content: await readFile(file, "utf8"),
86
+ ...extension ? { extension } : {}
87
+ };
88
+ }));
89
+ return {
90
+ files: [...files, ...scan.configPaths],
91
+ sources
92
+ };
93
+ }
94
+ //#endregion
95
+ //#region src/generator-plugin/index.ts
96
+ const PLUGIN_NAME = "weapp-tailwindcss";
97
+ const POSTCSS_SOURCE_PATTERN = createSourceScanPattern(DEFAULT_SOURCE_SCAN_EXTENSIONS);
98
+ function isTailwindV4ApplyOnlyCss(css, root) {
99
+ return hasTailwindApplyDirective(css) && !hasTailwindRootDirectives(root, { importFallback: true });
100
+ }
101
+ function resolveTailwindV4PostcssSourceCss(css, sourceOptions, root) {
102
+ const packageName = sourceOptions.packageName ?? "tailwindcss";
103
+ return isTailwindV4ApplyOnlyCss(css, root) ? `@import "${packageName}" source(none);\n@reference "${packageName}";\n${css}` : css;
104
+ }
105
+ function isMiniProgramGeneratorTarget(target) {
106
+ return target !== "web";
107
+ }
108
+ function finalizeGeneratedCss(css, target, styleOptions, webCompat) {
109
+ if (target === "web") {
110
+ const webCss = transformWebCssCompat(css, webCompat);
111
+ return (styleOptions?.cssOptions?.platform ?? styleOptions?.platform) === "lynx" ? transformLynxCssCompat(webCss) : webCss;
112
+ }
113
+ if (!isMiniProgramGeneratorTarget(target)) return css;
114
+ return finalizeMiniProgramCss(css, {
115
+ cssSelectorReplacement: styleOptions?.cssOptions?.cssSelectorReplacement ?? styleOptions?.cssSelectorReplacement,
116
+ isTailwindcssV4: true,
117
+ tailwindcssV4GradientFallback: styleOptions?.cssOptions?.tailwindcssV4GradientFallback ?? styleOptions?.tailwindcssV4GradientFallback
118
+ });
119
+ }
120
+ function createWeappTailwindcssPostcssPlugin(adapters) {
121
+ const plugin = (options = {}) => {
122
+ return {
123
+ postcssPlugin: PLUGIN_NAME,
124
+ async Once(root, { result }) {
125
+ const { candidates, generator: userGeneratorOptions, scanSources, sources, styleOptions, ...sourceOptions } = options;
126
+ const generatorOptions = adapters.normalizeGeneratorOptions(userGeneratorOptions);
127
+ const rawCss = sourceOptions.css ?? root.toString();
128
+ const base = resolvePostcssBase(result, options);
129
+ const projectRoot = resolvePostcssProjectRoot(result, options);
130
+ const compiledScan = adapters.compiledSourceScan && scanSources !== false;
131
+ const sourceEntries = compiledScan ? [] : await resolveCssSourceEntries(root, base, POSTCSS_SOURCE_PATTERN);
132
+ const [collectedSources, autoCandidates] = await Promise.all([compiledScan ? {
133
+ files: [],
134
+ sources: []
135
+ } : collectPostcssLocalSources(root, result, options, { sourceEntries }), compiledScan ? /* @__PURE__ */ new Set() : collectAutoTailwindCandidates(root, result, options, {
136
+ css: rawCss,
137
+ sourceEntries
138
+ })]);
139
+ const generatorConfig = generatorOptions.config ?? options.config;
140
+ const isApplyOnlyTailwindV4Css = isTailwindV4ApplyOnlyCss(rawCss, root);
141
+ const applyOnlyCssSelectors = isApplyOnlyTailwindV4Css ? collectApplyOnlyCssSelectorsRoot(root) : void 0;
142
+ const source = await adapters.resolveTailwindV4Source({
143
+ ...sourceOptions,
144
+ css: prependConfigDirective(resolveTailwindV4PostcssSourceCss(rawCss, sourceOptions, root), generatorConfig),
145
+ base,
146
+ projectRoot
147
+ });
148
+ const generator = adapters.createGenerator(source);
149
+ const generatorStyleOptions = {
150
+ ...generatorOptions.styleOptions,
151
+ ...styleOptions
152
+ };
153
+ try {
154
+ const generated = await generator.generate({
155
+ candidates: /* @__PURE__ */ new Set([...autoCandidates, ...candidates ?? []]),
156
+ scanSources: compiledScan ? true : scanSources ?? false,
157
+ ...compiledScan ? {
158
+ scanMode: "compiled",
159
+ excludeFiles: result.opts.to ? [result.opts.to] : []
160
+ } : {},
161
+ sources: [...collectedSources.sources, ...sources ?? []],
162
+ styleOptions: generatorStyleOptions,
163
+ target: generatorOptions.target
164
+ });
165
+ replaceRootCss(root, finalizeGeneratedCss(isApplyOnlyTailwindV4Css ? filterApplyOnlyGeneratedCss(generated.css, applyOnlyCssSelectors ?? /* @__PURE__ */ new Set()) : generated.css, generated.target, generatorStyleOptions, generatorOptions.webCompat), result);
166
+ addDependencyMessages(result, generated);
167
+ addSourceDependencyMessages(result, collectedSources.files);
168
+ result.messages.push({
169
+ type: "weapp-tailwindcss:generated",
170
+ plugin: PLUGIN_NAME,
171
+ target: generated.target,
172
+ classSet: generated.classSet,
173
+ rawCss: generated.rawCss
174
+ });
175
+ } finally {
176
+ generator.dispose?.();
177
+ }
178
+ }
179
+ };
180
+ };
181
+ plugin.postcss = true;
182
+ return plugin;
183
+ }
184
+ //#endregion
185
+ export { createWeappTailwindcssPostcssPlugin };