@weapp-tailwindcss/postcss 3.3.5 → 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 (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-DTKFO5Hv.js +2630 -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-BWDgxMn5.cjs +194 -0
  71. package/dist/plugin-CpkRzMhp.js +185 -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-DQiOQfoY.js +354 -0
  79. package/dist/resolve-EBh65bS8.cjs +3556 -0
  80. package/dist/rewrite-imports-CdZQE6CI.js +146 -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 +547 -0
  96. package/dist/syntax.d.ts +6 -0
  97. package/dist/syntax.js +3 -0
  98. package/dist/transform-Djx5HILQ.js +9239 -0
  99. package/dist/transform-Xb48e-Wk.cjs +10957 -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 +45 -5
@@ -0,0 +1,256 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_shared = require("../../shared-CELzerNo.cjs");
3
+ const require_preflight = require("../../preflight-BTZL2nvC.cjs");
4
+ let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared");
5
+ //#region src/experimental/lightningcss/options.ts
6
+ const FALLBACK_PLACEHOLDER_SUFFIXES = [":not(#n)", ":not(#\\#)"];
7
+ function normalizeSelectorList(value) {
8
+ if (value === void 0 || value === false) return [];
9
+ return Array.isArray(value) ? value.filter(Boolean) : [value];
10
+ }
11
+ function getSpecificityMatchingName(options) {
12
+ const feature = options.cssPresetEnv?.features?.["is-pseudo-class"];
13
+ if (feature && typeof feature === "object" && "specificityMatchingName" in feature) {
14
+ const specificityName = feature.specificityMatchingName;
15
+ return typeof specificityName === "string" && specificityName.length > 0 ? specificityName : void 0;
16
+ }
17
+ }
18
+ function createRootSpecificityReplacer(options) {
19
+ const specificityMatchingName = getSpecificityMatchingName(options);
20
+ const selectors = normalizeSelectorList(options.cssSelectorReplacement?.root);
21
+ const replaceFallbackPlaceholder = (code) => {
22
+ let output = code;
23
+ for (const suffix of FALLBACK_PLACEHOLDER_SUFFIXES) if (output.includes(suffix)) output = output.split(suffix).join("");
24
+ return output;
25
+ };
26
+ if (!specificityMatchingName || selectors.length === 0) return replaceFallbackPlaceholder;
27
+ const suffix = `:not(.${specificityMatchingName})`;
28
+ const targets = selectors.map((selector) => selector?.trim()).filter((selector) => Boolean(selector?.length)).map((selector) => ({
29
+ match: `${selector}${suffix}`,
30
+ spacedMatch: `${selector} ${suffix}`,
31
+ replacement: selector
32
+ }));
33
+ if (!targets.length) return;
34
+ return (code) => {
35
+ let output = replaceFallbackPlaceholder(code);
36
+ for (const target of targets) {
37
+ if (output.includes(target.match)) output = output.split(target.match).join(target.replacement);
38
+ if (output.includes(target.spacedMatch)) output = output.split(target.spacedMatch).join(target.replacement);
39
+ }
40
+ return output;
41
+ };
42
+ }
43
+ function getLightningDefaultOptions(options) {
44
+ const customPropertiesFeature = options?.cssPresetEnv?.features?.["custom-properties"];
45
+ return {
46
+ cssPresetEnv: {
47
+ features: {
48
+ "cascade-layers": true,
49
+ "is-pseudo-class": { specificityMatchingName: "weapp-tw-ig" },
50
+ "oklab-function": true,
51
+ "color-mix": true,
52
+ "custom-properties": customPropertiesFeature !== void 0 ? customPropertiesFeature : options?.cssCalc ? { preserve: true } : false
53
+ },
54
+ autoprefixer: { add: false }
55
+ },
56
+ cssRemoveProperty: true,
57
+ cssRemoveHoverPseudoClass: true,
58
+ cssChildCombinatorReplaceValue: ["view", "text"],
59
+ cssSelectorReplacement: {
60
+ root: [
61
+ "page",
62
+ ".tw-root",
63
+ "wx-root-portal-content"
64
+ ],
65
+ universal: ["view", "text"]
66
+ }
67
+ };
68
+ }
69
+ function prepareStyleOptions(options) {
70
+ const merged = (0, _weapp_tailwindcss_shared.defuOverrideArray)(options, getLightningDefaultOptions(options));
71
+ merged.cssInjectPreflight = require_preflight.createInjectPreflight(merged.cssPreflight);
72
+ return merged;
73
+ }
74
+ //#endregion
75
+ //#region src/experimental/lightningcss/selector-utils.ts
76
+ function createTypeSelector(name) {
77
+ return {
78
+ type: "type",
79
+ name
80
+ };
81
+ }
82
+ function cloneComponent(value) {
83
+ const structured = globalThis.structuredClone;
84
+ if (typeof structured === "function") return structured(value);
85
+ return JSON.parse(JSON.stringify(value));
86
+ }
87
+ function cloneComponents(list) {
88
+ return list.map(cloneComponent);
89
+ }
90
+ function normalizeNestedSelectors(selectors) {
91
+ if (!selectors) return;
92
+ if (Array.isArray(selectors)) {
93
+ if (selectors.length === 0) return [];
94
+ const first = selectors[0];
95
+ if (Array.isArray(first)) return selectors;
96
+ return [selectors];
97
+ }
98
+ return [selectors];
99
+ }
100
+ function assignNestedSelectors(target, value) {
101
+ if (!("selectors" in target)) return;
102
+ if (Array.isArray(target.selectors)) target.selectors = value ?? [];
103
+ else if (target.selectors && !Array.isArray(target.selectors)) target.selectors = value?.[0] ?? target.selectors;
104
+ }
105
+ function trimCombinators(components) {
106
+ let start = 0;
107
+ let end = components.length;
108
+ while (start < end && components[start]?.type === "combinator") start++;
109
+ while (end > start && components[end - 1]?.type === "combinator") end--;
110
+ return components.slice(start, end);
111
+ }
112
+ function matchesHiddenNot(component) {
113
+ if (!component || component.type !== "pseudo-class" || component.kind !== "not") return false;
114
+ const selectors = normalizeNestedSelectors(component.selectors);
115
+ if (!selectors || selectors.length !== 1) return false;
116
+ const [nestedSelector] = selectors;
117
+ if (!nestedSelector || nestedSelector.length !== 1) return false;
118
+ const [node] = nestedSelector;
119
+ if (!node) return false;
120
+ return node.type === "attribute" && node.name === "hidden" || node.type === "type" && node.name === "template";
121
+ }
122
+ //#endregion
123
+ //#region src/experimental/lightningcss/selector-transform.ts
124
+ function buildSelectorReplacement(value) {
125
+ if (!value) return null;
126
+ const targets = Array.isArray(value) ? value : [value];
127
+ if (!targets.length) return null;
128
+ if (targets.length === 1) return [createTypeSelector(targets[0])];
129
+ return [{
130
+ type: "pseudo-class",
131
+ kind: "is",
132
+ selectors: targets.map((name) => [createTypeSelector(name)])
133
+ }];
134
+ }
135
+ function buildChildCombinatorReplacement(options) {
136
+ const { cssChildCombinatorReplaceValue } = options;
137
+ if (!cssChildCombinatorReplaceValue) return;
138
+ const normalized = Array.isArray(cssChildCombinatorReplaceValue) ? cssChildCombinatorReplaceValue : [cssChildCombinatorReplaceValue];
139
+ if (!normalized.length) return;
140
+ const baseComponents = buildSelectorReplacement(normalized) ?? [createTypeSelector("view")];
141
+ const left = cloneComponents(baseComponents);
142
+ const right = cloneComponents(baseComponents);
143
+ return [
144
+ ...left,
145
+ {
146
+ type: "combinator",
147
+ value: "next-sibling"
148
+ },
149
+ ...right
150
+ ];
151
+ }
152
+ function transformSelectorComponent(component, ctx, transformList) {
153
+ const { options } = ctx;
154
+ if (component.type === "class") {
155
+ const cloned = cloneComponent(component);
156
+ cloned.name = require_shared.internalCssSelectorReplacer(component.name, { escapeMap: options.escapeMap });
157
+ return [cloned];
158
+ }
159
+ if (component.type === "universal") {
160
+ const replacement = buildSelectorReplacement(options.cssSelectorReplacement?.universal);
161
+ if (replacement) return cloneComponents(replacement);
162
+ return [cloneComponent(component)];
163
+ }
164
+ if (component.type === "type") {
165
+ if (options.uniAppX) return [];
166
+ return [cloneComponent(component)];
167
+ }
168
+ if (component.type === "attribute") {
169
+ if (options.uniAppX) return [];
170
+ return [cloneComponent(component)];
171
+ }
172
+ if (component.type === "combinator") return [cloneComponent(component)];
173
+ if (component.type === "pseudo-element") return [cloneComponent(component)];
174
+ if (component.type === "pseudo-class") {
175
+ if (component.kind === "hover" && options.cssRemoveHoverPseudoClass) return null;
176
+ if (component.kind === "root") {
177
+ const replacement = buildSelectorReplacement(options.cssSelectorReplacement?.root);
178
+ if (replacement) return cloneComponents(replacement);
179
+ return [cloneComponent(component)];
180
+ }
181
+ const cloned = cloneComponent(component);
182
+ if ("selectors" in cloned) {
183
+ const nestedSelectors = normalizeNestedSelectors(cloned.selectors);
184
+ if (nestedSelectors) assignNestedSelectors(cloned, transformList(nestedSelectors, ctx));
185
+ }
186
+ if (cloned.kind === "where" && options.uniAppX) cloned.kind = "is";
187
+ return [cloned];
188
+ }
189
+ return [cloneComponent(component)];
190
+ }
191
+ function transformSelector(selector, ctx, transformList) {
192
+ const { childCombinatorReplacement } = ctx;
193
+ const output = [];
194
+ for (let index = 0; index < selector.length; index++) {
195
+ const component = selector[index];
196
+ if (!component) continue;
197
+ if (component.type === "combinator" && component.value === "child" && childCombinatorReplacement) {
198
+ const next = selector[index + 1];
199
+ const combinator = selector[index + 2];
200
+ const third = selector[index + 3];
201
+ if (matchesHiddenNot(next) && combinator?.type === "combinator" && (combinator.value === "next-sibling" || combinator.value === "later-sibling") && matchesHiddenNot(third)) {
202
+ output.push(cloneComponent(component));
203
+ output.push(...cloneComponents(childCombinatorReplacement));
204
+ index += 3;
205
+ continue;
206
+ }
207
+ }
208
+ const replaced = transformSelectorComponent(component, ctx, transformList);
209
+ if (replaced === null) return null;
210
+ output.push(...replaced);
211
+ }
212
+ const trimmed = trimCombinators(output);
213
+ return trimmed.length > 0 ? trimmed : null;
214
+ }
215
+ function transformSelectorList(selectors, ctx) {
216
+ const result = [];
217
+ for (const selector of selectors) {
218
+ const transformed = transformSelector(selector, ctx, transformSelectorList);
219
+ if (transformed && transformed.length > 0) result.push(transformed);
220
+ }
221
+ return result;
222
+ }
223
+ function createVisitor(ctx) {
224
+ return {
225
+ Rule(rule) {
226
+ if (rule.type === "property" && ctx.options.cssRemoveProperty) return [];
227
+ if (rule.type !== "style") return rule;
228
+ const styleRule = rule.value;
229
+ if (!styleRule.selectors) return rule;
230
+ const selectors = transformSelectorList(styleRule.selectors, ctx);
231
+ if (!selectors.length) return [];
232
+ styleRule.selectors = selectors;
233
+ return rule;
234
+ },
235
+ RuleExit(rule) {
236
+ if (rule.type !== "style") return rule;
237
+ const styleRule = rule.value;
238
+ const hasValidSelectors = (styleRule.selectors ?? []).some((selector) => selector.length > 0);
239
+ const declarationCount = styleRule.declarations?.declarations?.length ?? 0;
240
+ if (!hasValidSelectors || ctx.options.uniAppX && declarationCount === 0) return [];
241
+ return rule;
242
+ }
243
+ };
244
+ }
245
+ //#endregion
246
+ exports.assignNestedSelectors = assignNestedSelectors;
247
+ exports.buildChildCombinatorReplacement = buildChildCombinatorReplacement;
248
+ exports.cloneComponent = cloneComponent;
249
+ exports.cloneComponents = cloneComponents;
250
+ exports.createRootSpecificityReplacer = createRootSpecificityReplacer;
251
+ exports.createTypeSelector = createTypeSelector;
252
+ exports.createVisitor = createVisitor;
253
+ exports.matchesHiddenNot = matchesHiddenNot;
254
+ exports.normalizeNestedSelectors = normalizeNestedSelectors;
255
+ exports.prepareStyleOptions = prepareStyleOptions;
256
+ exports.trimCombinators = trimCombinators;
@@ -0,0 +1,3 @@
1
+ export { createRootSpecificityReplacer, prepareStyleOptions } from './options.js';
2
+ export { buildChildCombinatorReplacement, createVisitor, type SelectorTransformContext } from './selector-transform.js';
3
+ export { assignNestedSelectors, cloneComponent, cloneComponents, createTypeSelector, matchesHiddenNot, normalizeNestedSelectors, trimCombinators } from './selector-utils.js';
@@ -0,0 +1,245 @@
1
+ import { internalCssSelectorReplacer } from "../../shared-CfQUwapA.js";
2
+ import { createInjectPreflight } from "../../preflight-DVg4eehD.js";
3
+ import { defuOverrideArray } from "@weapp-tailwindcss/shared";
4
+ //#region src/experimental/lightningcss/options.ts
5
+ const FALLBACK_PLACEHOLDER_SUFFIXES = [":not(#n)", ":not(#\\#)"];
6
+ function normalizeSelectorList(value) {
7
+ if (value === void 0 || value === false) return [];
8
+ return Array.isArray(value) ? value.filter(Boolean) : [value];
9
+ }
10
+ function getSpecificityMatchingName(options) {
11
+ const feature = options.cssPresetEnv?.features?.["is-pseudo-class"];
12
+ if (feature && typeof feature === "object" && "specificityMatchingName" in feature) {
13
+ const specificityName = feature.specificityMatchingName;
14
+ return typeof specificityName === "string" && specificityName.length > 0 ? specificityName : void 0;
15
+ }
16
+ }
17
+ function createRootSpecificityReplacer(options) {
18
+ const specificityMatchingName = getSpecificityMatchingName(options);
19
+ const selectors = normalizeSelectorList(options.cssSelectorReplacement?.root);
20
+ const replaceFallbackPlaceholder = (code) => {
21
+ let output = code;
22
+ for (const suffix of FALLBACK_PLACEHOLDER_SUFFIXES) if (output.includes(suffix)) output = output.split(suffix).join("");
23
+ return output;
24
+ };
25
+ if (!specificityMatchingName || selectors.length === 0) return replaceFallbackPlaceholder;
26
+ const suffix = `:not(.${specificityMatchingName})`;
27
+ const targets = selectors.map((selector) => selector?.trim()).filter((selector) => Boolean(selector?.length)).map((selector) => ({
28
+ match: `${selector}${suffix}`,
29
+ spacedMatch: `${selector} ${suffix}`,
30
+ replacement: selector
31
+ }));
32
+ if (!targets.length) return;
33
+ return (code) => {
34
+ let output = replaceFallbackPlaceholder(code);
35
+ for (const target of targets) {
36
+ if (output.includes(target.match)) output = output.split(target.match).join(target.replacement);
37
+ if (output.includes(target.spacedMatch)) output = output.split(target.spacedMatch).join(target.replacement);
38
+ }
39
+ return output;
40
+ };
41
+ }
42
+ function getLightningDefaultOptions(options) {
43
+ const customPropertiesFeature = options?.cssPresetEnv?.features?.["custom-properties"];
44
+ return {
45
+ cssPresetEnv: {
46
+ features: {
47
+ "cascade-layers": true,
48
+ "is-pseudo-class": { specificityMatchingName: "weapp-tw-ig" },
49
+ "oklab-function": true,
50
+ "color-mix": true,
51
+ "custom-properties": customPropertiesFeature !== void 0 ? customPropertiesFeature : options?.cssCalc ? { preserve: true } : false
52
+ },
53
+ autoprefixer: { add: false }
54
+ },
55
+ cssRemoveProperty: true,
56
+ cssRemoveHoverPseudoClass: true,
57
+ cssChildCombinatorReplaceValue: ["view", "text"],
58
+ cssSelectorReplacement: {
59
+ root: [
60
+ "page",
61
+ ".tw-root",
62
+ "wx-root-portal-content"
63
+ ],
64
+ universal: ["view", "text"]
65
+ }
66
+ };
67
+ }
68
+ function prepareStyleOptions(options) {
69
+ const merged = defuOverrideArray(options, getLightningDefaultOptions(options));
70
+ merged.cssInjectPreflight = createInjectPreflight(merged.cssPreflight);
71
+ return merged;
72
+ }
73
+ //#endregion
74
+ //#region src/experimental/lightningcss/selector-utils.ts
75
+ function createTypeSelector(name) {
76
+ return {
77
+ type: "type",
78
+ name
79
+ };
80
+ }
81
+ function cloneComponent(value) {
82
+ const structured = globalThis.structuredClone;
83
+ if (typeof structured === "function") return structured(value);
84
+ return JSON.parse(JSON.stringify(value));
85
+ }
86
+ function cloneComponents(list) {
87
+ return list.map(cloneComponent);
88
+ }
89
+ function normalizeNestedSelectors(selectors) {
90
+ if (!selectors) return;
91
+ if (Array.isArray(selectors)) {
92
+ if (selectors.length === 0) return [];
93
+ const first = selectors[0];
94
+ if (Array.isArray(first)) return selectors;
95
+ return [selectors];
96
+ }
97
+ return [selectors];
98
+ }
99
+ function assignNestedSelectors(target, value) {
100
+ if (!("selectors" in target)) return;
101
+ if (Array.isArray(target.selectors)) target.selectors = value ?? [];
102
+ else if (target.selectors && !Array.isArray(target.selectors)) target.selectors = value?.[0] ?? target.selectors;
103
+ }
104
+ function trimCombinators(components) {
105
+ let start = 0;
106
+ let end = components.length;
107
+ while (start < end && components[start]?.type === "combinator") start++;
108
+ while (end > start && components[end - 1]?.type === "combinator") end--;
109
+ return components.slice(start, end);
110
+ }
111
+ function matchesHiddenNot(component) {
112
+ if (!component || component.type !== "pseudo-class" || component.kind !== "not") return false;
113
+ const selectors = normalizeNestedSelectors(component.selectors);
114
+ if (!selectors || selectors.length !== 1) return false;
115
+ const [nestedSelector] = selectors;
116
+ if (!nestedSelector || nestedSelector.length !== 1) return false;
117
+ const [node] = nestedSelector;
118
+ if (!node) return false;
119
+ return node.type === "attribute" && node.name === "hidden" || node.type === "type" && node.name === "template";
120
+ }
121
+ //#endregion
122
+ //#region src/experimental/lightningcss/selector-transform.ts
123
+ function buildSelectorReplacement(value) {
124
+ if (!value) return null;
125
+ const targets = Array.isArray(value) ? value : [value];
126
+ if (!targets.length) return null;
127
+ if (targets.length === 1) return [createTypeSelector(targets[0])];
128
+ return [{
129
+ type: "pseudo-class",
130
+ kind: "is",
131
+ selectors: targets.map((name) => [createTypeSelector(name)])
132
+ }];
133
+ }
134
+ function buildChildCombinatorReplacement(options) {
135
+ const { cssChildCombinatorReplaceValue } = options;
136
+ if (!cssChildCombinatorReplaceValue) return;
137
+ const normalized = Array.isArray(cssChildCombinatorReplaceValue) ? cssChildCombinatorReplaceValue : [cssChildCombinatorReplaceValue];
138
+ if (!normalized.length) return;
139
+ const baseComponents = buildSelectorReplacement(normalized) ?? [createTypeSelector("view")];
140
+ const left = cloneComponents(baseComponents);
141
+ const right = cloneComponents(baseComponents);
142
+ return [
143
+ ...left,
144
+ {
145
+ type: "combinator",
146
+ value: "next-sibling"
147
+ },
148
+ ...right
149
+ ];
150
+ }
151
+ function transformSelectorComponent(component, ctx, transformList) {
152
+ const { options } = ctx;
153
+ if (component.type === "class") {
154
+ const cloned = cloneComponent(component);
155
+ cloned.name = internalCssSelectorReplacer(component.name, { escapeMap: options.escapeMap });
156
+ return [cloned];
157
+ }
158
+ if (component.type === "universal") {
159
+ const replacement = buildSelectorReplacement(options.cssSelectorReplacement?.universal);
160
+ if (replacement) return cloneComponents(replacement);
161
+ return [cloneComponent(component)];
162
+ }
163
+ if (component.type === "type") {
164
+ if (options.uniAppX) return [];
165
+ return [cloneComponent(component)];
166
+ }
167
+ if (component.type === "attribute") {
168
+ if (options.uniAppX) return [];
169
+ return [cloneComponent(component)];
170
+ }
171
+ if (component.type === "combinator") return [cloneComponent(component)];
172
+ if (component.type === "pseudo-element") return [cloneComponent(component)];
173
+ if (component.type === "pseudo-class") {
174
+ if (component.kind === "hover" && options.cssRemoveHoverPseudoClass) return null;
175
+ if (component.kind === "root") {
176
+ const replacement = buildSelectorReplacement(options.cssSelectorReplacement?.root);
177
+ if (replacement) return cloneComponents(replacement);
178
+ return [cloneComponent(component)];
179
+ }
180
+ const cloned = cloneComponent(component);
181
+ if ("selectors" in cloned) {
182
+ const nestedSelectors = normalizeNestedSelectors(cloned.selectors);
183
+ if (nestedSelectors) assignNestedSelectors(cloned, transformList(nestedSelectors, ctx));
184
+ }
185
+ if (cloned.kind === "where" && options.uniAppX) cloned.kind = "is";
186
+ return [cloned];
187
+ }
188
+ return [cloneComponent(component)];
189
+ }
190
+ function transformSelector(selector, ctx, transformList) {
191
+ const { childCombinatorReplacement } = ctx;
192
+ const output = [];
193
+ for (let index = 0; index < selector.length; index++) {
194
+ const component = selector[index];
195
+ if (!component) continue;
196
+ if (component.type === "combinator" && component.value === "child" && childCombinatorReplacement) {
197
+ const next = selector[index + 1];
198
+ const combinator = selector[index + 2];
199
+ const third = selector[index + 3];
200
+ if (matchesHiddenNot(next) && combinator?.type === "combinator" && (combinator.value === "next-sibling" || combinator.value === "later-sibling") && matchesHiddenNot(third)) {
201
+ output.push(cloneComponent(component));
202
+ output.push(...cloneComponents(childCombinatorReplacement));
203
+ index += 3;
204
+ continue;
205
+ }
206
+ }
207
+ const replaced = transformSelectorComponent(component, ctx, transformList);
208
+ if (replaced === null) return null;
209
+ output.push(...replaced);
210
+ }
211
+ const trimmed = trimCombinators(output);
212
+ return trimmed.length > 0 ? trimmed : null;
213
+ }
214
+ function transformSelectorList(selectors, ctx) {
215
+ const result = [];
216
+ for (const selector of selectors) {
217
+ const transformed = transformSelector(selector, ctx, transformSelectorList);
218
+ if (transformed && transformed.length > 0) result.push(transformed);
219
+ }
220
+ return result;
221
+ }
222
+ function createVisitor(ctx) {
223
+ return {
224
+ Rule(rule) {
225
+ if (rule.type === "property" && ctx.options.cssRemoveProperty) return [];
226
+ if (rule.type !== "style") return rule;
227
+ const styleRule = rule.value;
228
+ if (!styleRule.selectors) return rule;
229
+ const selectors = transformSelectorList(styleRule.selectors, ctx);
230
+ if (!selectors.length) return [];
231
+ styleRule.selectors = selectors;
232
+ return rule;
233
+ },
234
+ RuleExit(rule) {
235
+ if (rule.type !== "style") return rule;
236
+ const styleRule = rule.value;
237
+ const hasValidSelectors = (styleRule.selectors ?? []).some((selector) => selector.length > 0);
238
+ const declarationCount = styleRule.declarations?.declarations?.length ?? 0;
239
+ if (!hasValidSelectors || ctx.options.uniAppX && declarationCount === 0) return [];
240
+ return rule;
241
+ }
242
+ };
243
+ }
244
+ //#endregion
245
+ export { assignNestedSelectors, buildChildCombinatorReplacement, cloneComponent, cloneComponents, createRootSpecificityReplacer, createTypeSelector, createVisitor, matchesHiddenNot, normalizeNestedSelectors, prepareStyleOptions, trimCombinators };
@@ -0,0 +1,3 @@
1
+ import type { IStyleHandlerOptions } from '../../types.js';
2
+ export declare function createRootSpecificityReplacer(options: IStyleHandlerOptions): ((code: string) => string) | undefined;
3
+ export declare function prepareStyleOptions(options?: Partial<IStyleHandlerOptions>): IStyleHandlerOptions;
@@ -0,0 +1,10 @@
1
+ import type { SelectorComponent } from 'lightningcss';
2
+ import type { IStyleHandlerOptions } from '../../types.js';
3
+ type CustomAtRules = Record<string, never>;
4
+ export interface SelectorTransformContext {
5
+ options: IStyleHandlerOptions;
6
+ childCombinatorReplacement?: SelectorComponent[] | undefined;
7
+ }
8
+ export declare function buildChildCombinatorReplacement(options: IStyleHandlerOptions): SelectorComponent[] | undefined;
9
+ export declare function createVisitor(ctx: SelectorTransformContext): import("lightningcss").Visitor<CustomAtRules>;
10
+ export {};
@@ -0,0 +1,10 @@
1
+ import type { Selector, SelectorComponent } from 'lightningcss';
2
+ export declare function createTypeSelector(name: string): SelectorComponent;
3
+ export declare function cloneComponent<T>(value: T): T;
4
+ export declare function cloneComponents(list: SelectorComponent[]): SelectorComponent[];
5
+ export declare function normalizeNestedSelectors(selectors: Selector[] | Selector | null | undefined): Selector[] | undefined;
6
+ export declare function assignNestedSelectors(target: SelectorComponent & {
7
+ selectors?: Selector[] | Selector | null;
8
+ }, value: Selector[] | undefined): void;
9
+ export declare function trimCombinators(components: SelectorComponent[]): SelectorComponent[];
10
+ export declare function matchesHiddenNot(component: SelectorComponent | undefined): boolean;
@@ -1 +1,6 @@
1
+ export declare function normalizeConfigDirective(css: string, config: string | undefined): string;
2
+ /** 保留预处理器文本兼容;请求解析与文件定位由调用方提供。 */
3
+ export declare function rewriteCssConfigRequests(source: string, resolve: (request: string) => string | undefined): string;
4
+ /** 保留 Vite 预处理前的行级清理语义,允许尚未编译的 Sass 等源码。 */
5
+ export declare function stripTailwindConfigDirectives(code: string): string;
1
6
  export declare function prependConfigDirective(css: string, config: string | undefined): string;
@@ -1,13 +1,13 @@
1
1
  import type { Result, Root } from 'postcss';
2
2
  import type { TailwindSourceEntry } from '../source-scan.js';
3
3
  import type { TailwindCandidateSource, WeappTailwindcssPostcssPluginOptions } from './types.js';
4
- export declare function collectAutoTailwindCandidates(root: Root, result: Result, options: WeappTailwindcssPostcssPluginOptions, context?: {
4
+ interface ScanContext {
5
5
  css?: string | undefined;
6
6
  sourceEntries?: TailwindSourceEntry[] | undefined;
7
- }): Promise<Set<string>>;
8
- export declare function collectPostcssLocalSources(root: Root, result: Result, options: WeappTailwindcssPostcssPluginOptions, context?: {
9
- sourceEntries?: TailwindSourceEntry[] | undefined;
10
- }): Promise<{
7
+ }
8
+ export declare function collectAutoTailwindCandidates(root: Root, result: Result, options: WeappTailwindcssPostcssPluginOptions, context?: ScanContext): Promise<Set<string>>;
9
+ export declare function collectPostcssLocalSources(root: Root, result: Result, options: WeappTailwindcssPostcssPluginOptions, context?: ScanContext): Promise<{
11
10
  files: string[];
12
11
  sources: TailwindCandidateSource[];
13
12
  }>;
13
+ export {};
@@ -5,6 +5,8 @@ export interface TailwindCandidateSource {
5
5
  extension?: string | undefined;
6
6
  }
7
7
  export interface WeappTailwindcssPostcssGenerateOptions {
8
+ scanMode?: 'compiled' | undefined;
9
+ excludeFiles?: string[] | undefined;
8
10
  candidates?: Iterable<string> | undefined;
9
11
  scanSources?: boolean | undefined;
10
12
  sources?: TailwindCandidateSource[] | undefined;
@@ -19,6 +21,7 @@ export interface WeappTailwindcssPostcssGenerateResult {
19
21
  dependencies: string[];
20
22
  }
21
23
  export interface WeappTailwindcssPostcssGenerator {
24
+ dispose?: (() => void) | undefined;
22
25
  generate: (options?: WeappTailwindcssPostcssGenerateOptions) => Promise<WeappTailwindcssPostcssGenerateResult>;
23
26
  }
24
27
  export interface TailwindV4SourceOptions {
@@ -45,6 +48,8 @@ export interface NormalizedWeappTailwindcssPostcssGeneratorOptions {
45
48
  bareArbitraryValues?: unknown;
46
49
  }
47
50
  export interface WeappTailwindcssPostcssPluginAdapters {
51
+ /** 生成器支持在编译会话内复用来源扫描;省略时保留旧适配协议。 */
52
+ compiledSourceScan?: boolean | undefined;
48
53
  createGenerator: (source: TailwindResolvedSource) => WeappTailwindcssPostcssGenerator;
49
54
  normalizeGeneratorOptions: (options: WeappTailwindcssPostcssGeneratorUserOptions | undefined) => NormalizedWeappTailwindcssPostcssGeneratorOptions;
50
55
  resolveTailwindV4Source: (options: TailwindV4SourceOptions) => Promise<TailwindResolvedSource>;