@weapp-tailwindcss/postcss 3.3.4 → 3.3.6

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 (129) hide show
  1. package/README.md +10 -0
  2. package/README.zh-CN.md +6 -0
  3. package/dist/compat/author-selector.d.ts +2 -0
  4. package/dist/compat/index.d.ts +57 -0
  5. package/dist/compat/legacy-css/apply.d.ts +2 -0
  6. package/dist/compat/legacy-css/dedupe.d.ts +2 -0
  7. package/dist/compat/legacy-css/index.d.ts +4 -0
  8. package/dist/compat/legacy-css/selectors.d.ts +7 -0
  9. package/dist/compat/legacy-css/source-cleanup.d.ts +2 -0
  10. package/dist/compat/legacy-css/units.d.ts +1 -0
  11. package/dist/compat/mini-program-css/class-presence.d.ts +3 -0
  12. package/dist/compat/mini-program-css/content-init.d.ts +3 -0
  13. package/dist/compat/mini-program-css/empty-blocks.d.ts +3 -0
  14. package/dist/compat/mini-program-css/index.d.ts +2 -0
  15. package/dist/compat/mini-program-css/output-import-shell.d.ts +8 -0
  16. package/dist/compat/native/compile.d.ts +2 -0
  17. package/dist/compat/native/properties.d.ts +15 -0
  18. package/dist/compat/native/selectors.d.ts +8 -0
  19. package/dist/compat/native/types.d.ts +23 -0
  20. package/dist/compat/processed-css/cleanup.d.ts +4 -0
  21. package/dist/compat/processed-css/composition.d.ts +6 -0
  22. package/dist/compat/processed-css/entry-directives.d.ts +1 -0
  23. package/dist/compat/processed-css/imports.d.ts +8 -0
  24. package/dist/compat/scoped-css/cleanup.d.ts +4 -0
  25. package/dist/compat/scoped-css/coverage.d.ts +10 -0
  26. package/dist/compat/scoped-css/covered-rules.d.ts +4 -0
  27. package/dist/compat/scoped-css/predicates.d.ts +13 -0
  28. package/dist/compat/tailwind-directive-injection.d.ts +8 -0
  29. package/dist/compat/tailwindcss-v4/author-functions.d.ts +7 -0
  30. package/dist/compat/tailwindcss-v4/generated-output.d.ts +5 -0
  31. package/dist/compat/tailwindcss-v4/package-import-statements.d.ts +1 -0
  32. package/dist/compat/tailwindcss-v4/preflight-imports.d.ts +3 -0
  33. package/dist/compat/tailwindcss-v4/rpx-candidates.d.ts +6 -0
  34. package/dist/compat/tailwindcss-v4/theme-injection.d.ts +1 -0
  35. package/dist/compat/tailwindcss-v4/theme-source.d.ts +9 -0
  36. package/dist/compat/tailwindcss-v4/user-css/apply-only.d.ts +6 -0
  37. package/dist/compat/tailwindcss-v4/user-css/apply-reference.d.ts +4 -0
  38. package/dist/compat/tailwindcss-v4/user-css/at-rules.d.ts +3 -0
  39. package/dist/compat/tailwindcss-v4/user-css/class-selectors.d.ts +2 -0
  40. package/dist/compat/tailwindcss-v4/user-css/directives/entry-source.d.ts +9 -0
  41. package/dist/compat/tailwindcss-v4/user-css/directives/fallback.d.ts +11 -0
  42. package/dist/compat/tailwindcss-v4/user-css/directives/index.d.ts +2 -0
  43. package/dist/compat/tailwindcss-v4/user-css/directives/shared.d.ts +26 -0
  44. package/dist/compat/tailwindcss-v4/user-css/framework-composition.d.ts +2 -0
  45. package/dist/compat/tailwindcss-v4/user-css/framework-source.d.ts +1 -0
  46. package/dist/compat/tailwindcss-v4/user-css/generated-cleanup.d.ts +7 -0
  47. package/dist/compat/tailwindcss-v4/user-css/identity.d.ts +1 -0
  48. package/dist/compat/tailwindcss-v4/user-css/markers.d.ts +32 -0
  49. package/dist/compat/tailwindcss-v4/user-css/rule-deduplication.d.ts +1 -0
  50. package/dist/compat/tailwindcss-v4/user-css/scoped-rules.d.ts +4 -0
  51. package/dist/compat/tailwindcss-v4/user-css/source-fragments.d.ts +15 -0
  52. package/dist/compat/tailwindcss-v4/user-css/transform.d.ts +14 -0
  53. package/dist/compat/tailwindcss-v4/user-css/user-layer-order.d.ts +10 -0
  54. package/dist/compat/tailwindcss-v4/user-css/user-layers.d.ts +15 -0
  55. package/dist/compat/tailwindcss-v4.d.ts +1 -0
  56. package/dist/compat/uni-app-x/apply-source.d.ts +2 -0
  57. package/dist/compat/uni-app-x/harmony-apply.d.ts +2 -0
  58. package/dist/compat/uni-app-x/reference-paths.d.ts +2 -0
  59. package/dist/compat/uni-app-x-author-apply.d.ts +10 -0
  60. package/dist/compat/uni-app-x-border.d.ts +6 -0
  61. package/dist/compat/uni-app-x-style-value.d.ts +11 -0
  62. package/dist/compat/webpack-css/bare-selectors.d.ts +1 -0
  63. package/dist/compat/webpack-css/generated-cleanup.d.ts +4 -0
  64. package/dist/compat/webpack-css/identity.d.ts +5 -0
  65. package/dist/compat/webpack-css/preflight.d.ts +5 -0
  66. package/dist/compat/webpack-css/user-source.d.ts +6 -0
  67. package/dist/diagnostics/rpx-theme.d.ts +9 -0
  68. package/dist/directives-DTKFO5Hv.js +2630 -0
  69. package/dist/experimental/lightningcss/index.cjs +256 -0
  70. package/dist/experimental/lightningcss/index.d.ts +3 -0
  71. package/dist/experimental/lightningcss/index.js +245 -0
  72. package/dist/experimental/lightningcss/options.d.ts +3 -0
  73. package/dist/experimental/lightningcss/selector-transform.d.ts +10 -0
  74. package/dist/experimental/lightningcss/selector-utils.d.ts +10 -0
  75. package/dist/framework-pipeline.d.ts +4 -0
  76. package/dist/generator-plugin/config-directive.d.ts +5 -0
  77. package/dist/generator-plugin/local-imports.d.ts +6 -1
  78. package/dist/generator-plugin/source-files.d.ts +5 -5
  79. package/dist/generator-plugin/types.d.ts +5 -0
  80. package/dist/index.cjs +388 -7960
  81. package/dist/index.d.ts +2 -33
  82. package/dist/index.js +10 -7840
  83. package/dist/native.cjs +425 -0
  84. package/dist/native.d.ts +3 -0
  85. package/dist/native.js +419 -0
  86. package/dist/plugin-BWDgxMn5.cjs +194 -0
  87. package/dist/plugin-CpkRzMhp.js +185 -0
  88. package/dist/plugin.cjs +3 -0
  89. package/dist/plugin.d.ts +2 -0
  90. package/dist/plugin.js +2 -0
  91. package/dist/plugins/applyConfiguredCssCalc.d.ts +9 -0
  92. package/dist/postcss-runtime-i5rHe_mj.js +2 -0
  93. package/dist/postcss-runtime.d.ts +1 -1
  94. package/dist/preflight-BTZL2nvC.cjs +21 -0
  95. package/dist/preflight-DVg4eehD.js +16 -0
  96. package/dist/resolve-DQiOQfoY.js +354 -0
  97. package/dist/resolve-EBh65bS8.cjs +3556 -0
  98. package/dist/rewrite-imports-CdZQE6CI.js +146 -0
  99. package/dist/selectorParser/utils.d.ts +1 -1
  100. package/dist/shared-CELzerNo.cjs +34 -0
  101. package/dist/shared-CfQUwapA.js +23 -0
  102. package/dist/source-scan/candidates.d.ts +4 -0
  103. package/dist/source-scan/description.d.ts +15 -0
  104. package/dist/source-scan/params.d.ts +5 -0
  105. package/dist/source-scan/resolve.d.ts +30 -0
  106. package/dist/source-scan/tailwind-v4/entry-source.d.ts +16 -0
  107. package/dist/source-scan/tailwind-v4/fingerprint.d.ts +5 -0
  108. package/dist/source-scan.d.ts +3 -24
  109. package/dist/syntax/css-import.d.ts +20 -0
  110. package/dist/syntax/index.d.ts +3 -0
  111. package/dist/syntax/location-dependencies.d.ts +2 -0
  112. package/dist/syntax/parse.d.ts +13 -0
  113. package/dist/syntax/rewrite-imports.d.ts +5 -0
  114. package/dist/syntax/runtime-signature.d.ts +2 -0
  115. package/dist/syntax/source-style.d.ts +1 -0
  116. package/dist/syntax.cjs +547 -0
  117. package/dist/syntax.d.ts +6 -0
  118. package/dist/syntax.js +3 -0
  119. package/dist/transform-Djx5HILQ.js +9239 -0
  120. package/dist/transform-Xb48e-Wk.cjs +10957 -0
  121. package/dist/transform.cjs +421 -0
  122. package/dist/transform.d.ts +40 -0
  123. package/dist/transform.js +10 -0
  124. package/dist/types.d.ts +1 -1
  125. package/dist/utils/apply-source.d.ts +11 -0
  126. package/dist/utils/css-source-trace.d.ts +6 -0
  127. package/dist/utils/custom-property-values.d.ts +4 -0
  128. package/dist/utils/generated-css-marker.d.ts +12 -0
  129. package/package.json +48 -8
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,194 @@
1
+ const require_rolldown_runtime = require("./rolldown-runtime-VH7oDXx4.cjs");
2
+ const require_resolve = require("./resolve-EBh65bS8.cjs");
3
+ let postcss = require("postcss");
4
+ postcss = require_rolldown_runtime.__toESM(postcss, 1);
5
+ let node_path = require("node:path");
6
+ node_path = require_rolldown_runtime.__toESM(node_path, 1);
7
+ let _weapp_tailwindcss_engine = require("@weapp-tailwindcss/engine");
8
+ let node_process = require("node:process");
9
+ node_process = require_rolldown_runtime.__toESM(node_process, 1);
10
+ let node_fs_promises = require("node:fs/promises");
11
+ let _weapp_tailwindcss_source_scan = require("@weapp-tailwindcss/source-scan");
12
+ //#region src/generator-plugin/context.ts
13
+ const PLUGIN_NAME$1 = "weapp-tailwindcss";
14
+ function resolveInputFile(result) {
15
+ const from = result.opts.from;
16
+ if (typeof from !== "string" || from.length === 0) return;
17
+ return node_path.default.isAbsolute(from) ? from : node_path.default.resolve(node_process.default.cwd(), from);
18
+ }
19
+ function resolvePostcssBase(result, options) {
20
+ if (options.base) return options.base;
21
+ const inputFile = resolveInputFile(result);
22
+ return inputFile ? node_path.default.dirname(inputFile) : node_process.default.cwd();
23
+ }
24
+ function resolvePostcssProjectRoot(result, options) {
25
+ if (options.projectRoot) return options.projectRoot;
26
+ const inputFile = resolveInputFile(result);
27
+ return inputFile ? node_path.default.dirname(inputFile) : node_process.default.cwd();
28
+ }
29
+ function replaceRootCss(root, css, result) {
30
+ root.removeAll();
31
+ try {
32
+ const nextRoot = postcss.default.parse(css, { from: resolveInputFile(result) });
33
+ root.append(nextRoot.nodes);
34
+ } catch {
35
+ root.raws = { after: css };
36
+ }
37
+ }
38
+ function addDependencyMessages(result, generated) {
39
+ for (const file of generated.dependencies) result.messages.push({
40
+ type: "dependency",
41
+ plugin: PLUGIN_NAME$1,
42
+ file
43
+ });
44
+ }
45
+ function addSourceDependencyMessages(result, files) {
46
+ for (const file of files) result.messages.push({
47
+ type: "dependency",
48
+ plugin: PLUGIN_NAME$1,
49
+ file
50
+ });
51
+ }
52
+ //#endregion
53
+ //#region src/generator-plugin/source-files.ts
54
+ const POSTCSS_SOURCE_PATTERN$1 = (0, _weapp_tailwindcss_source_scan.createSourceScanPattern)(_weapp_tailwindcss_source_scan.DEFAULT_SOURCE_SCAN_EXTENSIONS);
55
+ function resolveCompatibilityScan(root, result, options, context, local) {
56
+ const css = context.css ?? root.toString();
57
+ const applyOnly = require_resolve.hasTailwindApplyDirective(css) && !require_resolve.hasTailwindRootDirectives(root, { importFallback: true });
58
+ const base = resolvePostcssBase(result, options);
59
+ return require_resolve.resolveCssScanSources([{
60
+ root,
61
+ base
62
+ }], {
63
+ base,
64
+ automatic: local || applyOnly || options.scanSources === false ? "disabled" : "auto",
65
+ pattern: POSTCSS_SOURCE_PATTERN$1,
66
+ config: options.config,
67
+ configResolution: "path",
68
+ sourceEntries: context.sourceEntries,
69
+ loadConfigContent: local
70
+ });
71
+ }
72
+ async function collectAutoTailwindCandidates(root, result, options, context = {}) {
73
+ if (options.scanSources === false) return /* @__PURE__ */ new Set();
74
+ const scan = await resolveCompatibilityScan(root, result, options, context, false);
75
+ const candidates = !scan.entries.some((entry) => !entry.negated) ? [] : await (0, _weapp_tailwindcss_engine.extractValidCandidates)({
76
+ base: resolvePostcssBase(result, options),
77
+ css: context.css ?? root.toString(),
78
+ cwd: resolvePostcssProjectRoot(result, options),
79
+ sources: scan.entries
80
+ });
81
+ return /* @__PURE__ */ new Set([...[...candidates].filter((candidate) => !scan.inlineCandidates.excluded.has(candidate)), ...scan.inlineCandidates.included]);
82
+ }
83
+ async function collectPostcssLocalSources(root, result, options, context = {}) {
84
+ const scan = await resolveCompatibilityScan(root, result, options, context, true);
85
+ const files = [.../* @__PURE__ */ new Set([...await require_resolve.expandTailwindSourceEntries(scan.explicitEntries), ...(await Promise.all(scan.configGroups.map((entries) => require_resolve.expandTailwindSourceEntries(entries)))).flat()])];
86
+ const sources = await Promise.all(files.map(async (file) => {
87
+ const extension = node_path.default.extname(file).slice(1);
88
+ return {
89
+ content: await (0, node_fs_promises.readFile)(file, "utf8"),
90
+ ...extension ? { extension } : {}
91
+ };
92
+ }));
93
+ return {
94
+ files: [...files, ...scan.configPaths],
95
+ sources
96
+ };
97
+ }
98
+ //#endregion
99
+ //#region src/generator-plugin/index.ts
100
+ const PLUGIN_NAME = "weapp-tailwindcss";
101
+ const POSTCSS_SOURCE_PATTERN = (0, _weapp_tailwindcss_source_scan.createSourceScanPattern)(_weapp_tailwindcss_source_scan.DEFAULT_SOURCE_SCAN_EXTENSIONS);
102
+ function isTailwindV4ApplyOnlyCss(css, root) {
103
+ return require_resolve.hasTailwindApplyDirective(css) && !require_resolve.hasTailwindRootDirectives(root, { importFallback: true });
104
+ }
105
+ function resolveTailwindV4PostcssSourceCss(css, sourceOptions, root) {
106
+ const packageName = sourceOptions.packageName ?? "tailwindcss";
107
+ return isTailwindV4ApplyOnlyCss(css, root) ? `@import "${packageName}" source(none);\n@reference "${packageName}";\n${css}` : css;
108
+ }
109
+ function isMiniProgramGeneratorTarget(target) {
110
+ return target !== "web";
111
+ }
112
+ function finalizeGeneratedCss(css, target, styleOptions, webCompat) {
113
+ if (target === "web") {
114
+ const webCss = require_resolve.transformWebCssCompat(css, webCompat);
115
+ return (styleOptions?.cssOptions?.platform ?? styleOptions?.platform) === "lynx" ? require_resolve.transformLynxCssCompat(webCss) : webCss;
116
+ }
117
+ if (!isMiniProgramGeneratorTarget(target)) return css;
118
+ return require_resolve.finalizeMiniProgramCss(css, {
119
+ cssSelectorReplacement: styleOptions?.cssOptions?.cssSelectorReplacement ?? styleOptions?.cssSelectorReplacement,
120
+ isTailwindcssV4: true,
121
+ tailwindcssV4GradientFallback: styleOptions?.cssOptions?.tailwindcssV4GradientFallback ?? styleOptions?.tailwindcssV4GradientFallback
122
+ });
123
+ }
124
+ function createWeappTailwindcssPostcssPlugin(adapters) {
125
+ const plugin = (options = {}) => {
126
+ return {
127
+ postcssPlugin: PLUGIN_NAME,
128
+ async Once(root, { result }) {
129
+ const { candidates, generator: userGeneratorOptions, scanSources, sources, styleOptions, ...sourceOptions } = options;
130
+ const generatorOptions = adapters.normalizeGeneratorOptions(userGeneratorOptions);
131
+ const rawCss = sourceOptions.css ?? root.toString();
132
+ const base = resolvePostcssBase(result, options);
133
+ const projectRoot = resolvePostcssProjectRoot(result, options);
134
+ const compiledScan = adapters.compiledSourceScan && scanSources !== false;
135
+ const sourceEntries = compiledScan ? [] : await require_resolve.resolveCssSourceEntries(root, base, POSTCSS_SOURCE_PATTERN);
136
+ const [collectedSources, autoCandidates] = await Promise.all([compiledScan ? {
137
+ files: [],
138
+ sources: []
139
+ } : collectPostcssLocalSources(root, result, options, { sourceEntries }), compiledScan ? /* @__PURE__ */ new Set() : collectAutoTailwindCandidates(root, result, options, {
140
+ css: rawCss,
141
+ sourceEntries
142
+ })]);
143
+ const generatorConfig = generatorOptions.config ?? options.config;
144
+ const isApplyOnlyTailwindV4Css = isTailwindV4ApplyOnlyCss(rawCss, root);
145
+ const applyOnlyCssSelectors = isApplyOnlyTailwindV4Css ? require_resolve.collectApplyOnlyCssSelectorsRoot(root) : void 0;
146
+ const source = await adapters.resolveTailwindV4Source({
147
+ ...sourceOptions,
148
+ css: require_resolve.prependConfigDirective(resolveTailwindV4PostcssSourceCss(rawCss, sourceOptions, root), generatorConfig),
149
+ base,
150
+ projectRoot
151
+ });
152
+ const generator = adapters.createGenerator(source);
153
+ const generatorStyleOptions = {
154
+ ...generatorOptions.styleOptions,
155
+ ...styleOptions
156
+ };
157
+ try {
158
+ const generated = await generator.generate({
159
+ candidates: /* @__PURE__ */ new Set([...autoCandidates, ...candidates ?? []]),
160
+ scanSources: compiledScan ? true : scanSources ?? false,
161
+ ...compiledScan ? {
162
+ scanMode: "compiled",
163
+ excludeFiles: result.opts.to ? [result.opts.to] : []
164
+ } : {},
165
+ sources: [...collectedSources.sources, ...sources ?? []],
166
+ styleOptions: generatorStyleOptions,
167
+ target: generatorOptions.target
168
+ });
169
+ replaceRootCss(root, finalizeGeneratedCss(isApplyOnlyTailwindV4Css ? require_resolve.filterApplyOnlyGeneratedCss(generated.css, applyOnlyCssSelectors ?? /* @__PURE__ */ new Set()) : generated.css, generated.target, generatorStyleOptions, generatorOptions.webCompat), result);
170
+ addDependencyMessages(result, generated);
171
+ addSourceDependencyMessages(result, collectedSources.files);
172
+ result.messages.push({
173
+ type: "weapp-tailwindcss:generated",
174
+ plugin: PLUGIN_NAME,
175
+ target: generated.target,
176
+ classSet: generated.classSet,
177
+ rawCss: generated.rawCss
178
+ });
179
+ } finally {
180
+ generator.dispose?.();
181
+ }
182
+ }
183
+ };
184
+ };
185
+ plugin.postcss = true;
186
+ return plugin;
187
+ }
188
+ //#endregion
189
+ Object.defineProperty(exports, "createWeappTailwindcssPostcssPlugin", {
190
+ enumerable: true,
191
+ get: function() {
192
+ return createWeappTailwindcssPostcssPlugin;
193
+ }
194
+ });