weapp-tailwindcss 5.0.8 → 5.0.11

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 (67) hide show
  1. package/dist/auto-CTp6wE5a.js +33 -0
  2. package/dist/auto-Cl8_hsG6.mjs +22 -0
  3. package/dist/{bundle-state-cHwTyrOS.js → bundle-state-BwtEqxvU.js} +3 -3
  4. package/dist/{bundle-state-5FtFktJr.mjs → bundle-state-CXzPknlT.mjs} +2 -2
  5. package/dist/bundlers/vite/official-tailwind-plugins.d.ts +0 -2
  6. package/dist/cli.js +1 -159
  7. package/dist/cli.mjs +1 -159
  8. package/dist/core.js +1 -1
  9. package/dist/core.mjs +1 -1
  10. package/dist/css-macro/auto.d.ts +1 -7
  11. package/dist/css-macro/postcss.d.ts +1 -6
  12. package/dist/css-macro/postcss.js +15 -3
  13. package/dist/css-macro/postcss.mjs +2 -2
  14. package/dist/css-macro.js +19 -5
  15. package/dist/css-macro.mjs +16 -2
  16. package/dist/{generator-C--TrAod.js → generator-ChgOWNOj.js} +1 -1
  17. package/dist/{generator-DnwUQOXB.mjs → generator-h2XRiJ9-.mjs} +1 -1
  18. package/dist/generator.js +2 -2
  19. package/dist/generator.mjs +2 -2
  20. package/dist/{gulp-B22YSGU_.mjs → gulp-Be88jhoY.mjs} +5 -5
  21. package/dist/{gulp-5Tan5bHG.js → gulp-CHtZF-oT.js} +6 -6
  22. package/dist/gulp.js +1 -1
  23. package/dist/gulp.mjs +1 -1
  24. package/dist/{hmr-timing-CscCNKb9.js → hmr-timing-BkivBZvN.js} +41 -43
  25. package/dist/{hmr-timing-DK-mine6.mjs → hmr-timing-Ct5w4hdM.mjs} +6 -7
  26. package/dist/index.js +6 -6
  27. package/dist/index.mjs +5 -5
  28. package/dist/postcss.d.ts +2 -13
  29. package/dist/postcss.js +14 -3
  30. package/dist/postcss.mjs +10 -1
  31. package/dist/{precheck-CcxTR7E_.mjs → precheck-BpHxsWRd.mjs} +4 -4
  32. package/dist/{precheck-B8y6tDvG.js → precheck-CY9oaH49.js} +5 -5
  33. package/dist/presets.js +4 -4
  34. package/dist/presets.mjs +3 -3
  35. package/dist/tailwindcss/source-scan/inline-source.d.ts +1 -1
  36. package/dist/{tailwindcss-0DaftXcU.mjs → tailwindcss-Bfy2egdX.mjs} +2 -2
  37. package/dist/{tailwindcss-DbZ4o4m_.js → tailwindcss-DbbAKAZP.js} +3 -3
  38. package/dist/{transform-DiW_u3eD.js → transform-Cd634UZV.js} +1 -1
  39. package/dist/{transform-DRyWUN5X.mjs → transform-r5evL6Hn.mjs} +1 -1
  40. package/dist/types/index.d.ts +1 -2
  41. package/dist/{v3-engine-ArQVHEau.mjs → v3-engine-CFkP6dWF.mjs} +4 -5
  42. package/dist/{v3-engine-DdlvXpID.js → v3-engine-D0yA9ZkF.js} +35 -73
  43. package/dist/{vite-_iUhzc4t.mjs → vite-Bd8qf9dK.mjs} +21 -423
  44. package/dist/{vite-C_IUnDBy.js → vite-j9cB2Ff1.js} +38 -443
  45. package/dist/vite.js +1 -1
  46. package/dist/vite.mjs +1 -1
  47. package/dist/watch-dependencies-bpG6kmAf.js +80 -0
  48. package/dist/weapp-tw-css-import-rewrite-loader.js +60 -393
  49. package/dist/weapp-tw-runtime-classset-loader.js +2 -2
  50. package/dist/{webpack-KLoTb5Dr.js → webpack-CJAOcYEO.js} +8 -8
  51. package/dist/{webpack-CqnI4Ymw.mjs → webpack-DPdrcC2X.mjs} +7 -7
  52. package/dist/webpack.js +1 -1
  53. package/dist/webpack.mjs +1 -1
  54. package/package.json +3 -5
  55. package/dist/auto-Cvy0zWpS.js +0 -238
  56. package/dist/auto-DEHRmEAx.mjs +0 -200
  57. package/dist/bundlers/vite/postcss-config.d.ts +0 -6
  58. package/dist/bundlers/vite/processed-css-assets/css-rules.d.ts +0 -17
  59. package/dist/postcss/config-directive.d.ts +0 -1
  60. package/dist/postcss/context.d.ts +0 -9
  61. package/dist/postcss/source-files.d.ts +0 -8
  62. package/dist/postcss/tailwind-version.d.ts +0 -3
  63. package/dist/postcss-C7BMYpEF.mjs +0 -169
  64. package/dist/postcss-CiYLsqZn.js +0 -192
  65. package/dist/postcss-CjWuDZwL.mjs +0 -275
  66. package/dist/postcss-R5pDVHUy.js +0 -284
  67. package/dist/watch-dependencies-zwx4EhBn.js +0 -5535
@@ -1,169 +0,0 @@
1
- //#region src/css-macro/constants.ts
2
- const queryKey = "weapp-tw-platform";
3
- const ifdefAtRule = "weapp-tw-ifdef";
4
- const ifndefAtRule = "weapp-tw-ifndef";
5
- function quoteAtRuleParam(value) {
6
- return `"${value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"")}"`;
7
- }
8
- function createConditionalAtRule(value) {
9
- return `@${ifdefAtRule} ${quoteAtRuleParam(value)}{&}`;
10
- }
11
- function createNegativeConditionalAtRule(value) {
12
- return `@${ifndefAtRule} ${quoteAtRuleParam(value)}{&}`;
13
- }
14
- const UNESCAPED_UNDERSCORE_RE = /(?<!\\)_/g;
15
- const WHITESPACE_RE = /\s+/g;
16
- const LOGICAL_OPERATOR_RE = /\s*(\|\||&&)\s*/g;
17
- function normalComment(text) {
18
- if (typeof text === "string") {
19
- const normalized = text.replaceAll(UNESCAPED_UNDERSCORE_RE, " ").replaceAll(WHITESPACE_RE, " ").trim();
20
- if (normalized.includes("\\")) return normalized;
21
- return normalized.replaceAll(LOGICAL_OPERATOR_RE, " $1 ").replaceAll(WHITESPACE_RE, " ").trim();
22
- }
23
- return text;
24
- }
25
- function ifdef(text) {
26
- return {
27
- start: `#ifdef ${normalComment(text)}`,
28
- end: `#endif`
29
- };
30
- }
31
- function ifndef(text) {
32
- return {
33
- start: `#ifndef ${normalComment(text)}`,
34
- end: `#endif`
35
- };
36
- }
37
- const QUERY_KEY_REGEX = new RegExp(`\\(\\s*${queryKey}\\s*:\\s*"([^)]*)"\\)`, "g");
38
- function matchCustomPropertyFromValue(str, cb) {
39
- let index = 0;
40
- QUERY_KEY_REGEX.lastIndex = 0;
41
- let arr = QUERY_KEY_REGEX.exec(str);
42
- while (arr !== null) {
43
- cb(arr, index);
44
- index++;
45
- arr = QUERY_KEY_REGEX.exec(str);
46
- }
47
- }
48
- function parseConditionalAtRuleParam(params) {
49
- const value = params.trim();
50
- const quoted = /^(['"])((?:\\.|(?!\1).)*)\1/.exec(value);
51
- if (!quoted) return value;
52
- return quoted[2]?.replaceAll(/\\(["'\\])/g, "$1") ?? "";
53
- }
54
- //#endregion
55
- //#region src/css-macro/postcss.ts
56
- const IFDEF_ENDIF_RE = /#(?:ifn?def|endif)/;
57
- const CONDITIONAL_COMMENT_SPACING = " ";
58
- const CSS_MACRO_POSTCSS_PLUGIN_NAME = "postcss-weapp-tw-css-macro-plugin";
59
- const creator = () => {
60
- return {
61
- postcssPlugin: CSS_MACRO_POSTCSS_PLUGIN_NAME,
62
- prepare() {
63
- function replaceAtRuleWithConditionalComments(atRule, helper, comment) {
64
- const hasPreviousNode = Boolean(atRule.prev());
65
- const clonedNodes = (atRule.nodes ?? []).map((node) => node.clone());
66
- const startComment = helper.comment({
67
- raws: {
68
- left: CONDITIONAL_COMMENT_SPACING,
69
- right: CONDITIONAL_COMMENT_SPACING
70
- },
71
- text: comment.start
72
- });
73
- const endComment = helper.comment({
74
- raws: {
75
- left: CONDITIONAL_COMMENT_SPACING,
76
- right: CONDITIONAL_COMMENT_SPACING
77
- },
78
- text: comment.end
79
- });
80
- const nextNodes = [
81
- startComment,
82
- ...clonedNodes,
83
- endComment
84
- ];
85
- atRule.replaceWith(nextNodes);
86
- startComment.raws.before = hasPreviousNode ? "\n" : "";
87
- startComment.raws["after"] = "\n";
88
- if (clonedNodes[0]) clonedNodes[0].raws.before = "\n";
89
- endComment.raws.before = "\n";
90
- endComment.raws["after"] = "\n";
91
- const nextNode = endComment?.next();
92
- if (nextNode) nextNode.raws.before = "\n";
93
- }
94
- function replaceNestedAtRuleWithConditionalRule(atRule, helper, comment) {
95
- if (atRule.parent?.type !== "rule") return false;
96
- const parentRule = atRule.parent;
97
- const clonedNodes = (atRule.nodes ?? []).map((node) => node.clone());
98
- const conditionalRule = parentRule.clone();
99
- conditionalRule.removeAll();
100
- conditionalRule.append(...clonedNodes);
101
- const startComment = helper.comment({
102
- raws: {
103
- left: CONDITIONAL_COMMENT_SPACING,
104
- right: CONDITIONAL_COMMENT_SPACING
105
- },
106
- text: comment.start
107
- });
108
- const endComment = helper.comment({
109
- raws: {
110
- left: CONDITIONAL_COMMENT_SPACING,
111
- right: CONDITIONAL_COMMENT_SPACING
112
- },
113
- text: comment.end
114
- });
115
- const nextNodes = [
116
- startComment,
117
- conditionalRule,
118
- endComment
119
- ];
120
- const hasPreviousNode = Boolean(parentRule.prev());
121
- atRule.remove();
122
- if ((parentRule.nodes?.length ?? 0) === 0) parentRule.replaceWith(nextNodes);
123
- else parentRule.after(nextNodes);
124
- startComment.raws.before = hasPreviousNode ? "\n" : "";
125
- startComment.raws["after"] = "\n";
126
- conditionalRule.raws.before = "\n";
127
- endComment.raws.before = "\n";
128
- endComment.raws["after"] = "\n";
129
- const nextNode = endComment.next();
130
- if (nextNode) nextNode.raws.before = "\n";
131
- return true;
132
- }
133
- return {
134
- AtRule(atRule, helper) {
135
- if (atRule.name === "weapp-tw-ifdef" || atRule.name === "weapp-tw-ifndef") {
136
- const text = parseConditionalAtRuleParam(atRule.params);
137
- const comment = atRule.name === "weapp-tw-ifndef" ? ifndef(text) : ifdef(text);
138
- if (replaceNestedAtRuleWithConditionalRule(atRule, helper, comment)) return;
139
- replaceAtRuleWithConditionalComments(atRule, helper, comment);
140
- return;
141
- }
142
- if (atRule.name === "media") {
143
- const values = [];
144
- matchCustomPropertyFromValue(atRule.params, (arr) => {
145
- const value = arr[1];
146
- if (value) values.push(value);
147
- });
148
- if (values.length > 0) {
149
- const isNegative = atRule.params.includes("not");
150
- const text = values.join(" ");
151
- const comment = isNegative ? ifndef(text) : ifdef(text);
152
- if (replaceNestedAtRuleWithConditionalRule(atRule, helper, comment)) return;
153
- replaceAtRuleWithConditionalComments(atRule, helper, comment);
154
- }
155
- }
156
- },
157
- CommentExit(comment) {
158
- if (IFDEF_ENDIF_RE.test(comment.text)) {
159
- comment.raws.left = CONDITIONAL_COMMENT_SPACING;
160
- comment.raws.right = CONDITIONAL_COMMENT_SPACING;
161
- }
162
- }
163
- };
164
- }
165
- };
166
- };
167
- creator.postcss = true;
168
- //#endregion
169
- export { createNegativeConditionalAtRule as i, creator as n, createConditionalAtRule as r, CSS_MACRO_POSTCSS_PLUGIN_NAME as t };
@@ -1,192 +0,0 @@
1
- //#region src/css-macro/constants.ts
2
- const queryKey = "weapp-tw-platform";
3
- const ifdefAtRule = "weapp-tw-ifdef";
4
- const ifndefAtRule = "weapp-tw-ifndef";
5
- function quoteAtRuleParam(value) {
6
- return `"${value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"")}"`;
7
- }
8
- function createConditionalAtRule(value) {
9
- return `@${ifdefAtRule} ${quoteAtRuleParam(value)}{&}`;
10
- }
11
- function createNegativeConditionalAtRule(value) {
12
- return `@${ifndefAtRule} ${quoteAtRuleParam(value)}{&}`;
13
- }
14
- const UNESCAPED_UNDERSCORE_RE = /(?<!\\)_/g;
15
- const WHITESPACE_RE = /\s+/g;
16
- const LOGICAL_OPERATOR_RE = /\s*(\|\||&&)\s*/g;
17
- function normalComment(text) {
18
- if (typeof text === "string") {
19
- const normalized = text.replaceAll(UNESCAPED_UNDERSCORE_RE, " ").replaceAll(WHITESPACE_RE, " ").trim();
20
- if (normalized.includes("\\")) return normalized;
21
- return normalized.replaceAll(LOGICAL_OPERATOR_RE, " $1 ").replaceAll(WHITESPACE_RE, " ").trim();
22
- }
23
- return text;
24
- }
25
- function ifdef(text) {
26
- return {
27
- start: `#ifdef ${normalComment(text)}`,
28
- end: `#endif`
29
- };
30
- }
31
- function ifndef(text) {
32
- return {
33
- start: `#ifndef ${normalComment(text)}`,
34
- end: `#endif`
35
- };
36
- }
37
- const QUERY_KEY_REGEX = new RegExp(`\\(\\s*${queryKey}\\s*:\\s*"([^)]*)"\\)`, "g");
38
- function matchCustomPropertyFromValue(str, cb) {
39
- let index = 0;
40
- QUERY_KEY_REGEX.lastIndex = 0;
41
- let arr = QUERY_KEY_REGEX.exec(str);
42
- while (arr !== null) {
43
- cb(arr, index);
44
- index++;
45
- arr = QUERY_KEY_REGEX.exec(str);
46
- }
47
- }
48
- function parseConditionalAtRuleParam(params) {
49
- const value = params.trim();
50
- const quoted = /^(['"])((?:\\.|(?!\1).)*)\1/.exec(value);
51
- if (!quoted) return value;
52
- return quoted[2]?.replaceAll(/\\(["'\\])/g, "$1") ?? "";
53
- }
54
- //#endregion
55
- //#region src/css-macro/postcss.ts
56
- const IFDEF_ENDIF_RE = /#(?:ifn?def|endif)/;
57
- const CONDITIONAL_COMMENT_SPACING = " ";
58
- const CSS_MACRO_POSTCSS_PLUGIN_NAME = "postcss-weapp-tw-css-macro-plugin";
59
- const creator = () => {
60
- return {
61
- postcssPlugin: CSS_MACRO_POSTCSS_PLUGIN_NAME,
62
- prepare() {
63
- function replaceAtRuleWithConditionalComments(atRule, helper, comment) {
64
- const hasPreviousNode = Boolean(atRule.prev());
65
- const clonedNodes = (atRule.nodes ?? []).map((node) => node.clone());
66
- const startComment = helper.comment({
67
- raws: {
68
- left: CONDITIONAL_COMMENT_SPACING,
69
- right: CONDITIONAL_COMMENT_SPACING
70
- },
71
- text: comment.start
72
- });
73
- const endComment = helper.comment({
74
- raws: {
75
- left: CONDITIONAL_COMMENT_SPACING,
76
- right: CONDITIONAL_COMMENT_SPACING
77
- },
78
- text: comment.end
79
- });
80
- const nextNodes = [
81
- startComment,
82
- ...clonedNodes,
83
- endComment
84
- ];
85
- atRule.replaceWith(nextNodes);
86
- startComment.raws.before = hasPreviousNode ? "\n" : "";
87
- startComment.raws["after"] = "\n";
88
- if (clonedNodes[0]) clonedNodes[0].raws.before = "\n";
89
- endComment.raws.before = "\n";
90
- endComment.raws["after"] = "\n";
91
- const nextNode = endComment?.next();
92
- if (nextNode) nextNode.raws.before = "\n";
93
- }
94
- function replaceNestedAtRuleWithConditionalRule(atRule, helper, comment) {
95
- if (atRule.parent?.type !== "rule") return false;
96
- const parentRule = atRule.parent;
97
- const clonedNodes = (atRule.nodes ?? []).map((node) => node.clone());
98
- const conditionalRule = parentRule.clone();
99
- conditionalRule.removeAll();
100
- conditionalRule.append(...clonedNodes);
101
- const startComment = helper.comment({
102
- raws: {
103
- left: CONDITIONAL_COMMENT_SPACING,
104
- right: CONDITIONAL_COMMENT_SPACING
105
- },
106
- text: comment.start
107
- });
108
- const endComment = helper.comment({
109
- raws: {
110
- left: CONDITIONAL_COMMENT_SPACING,
111
- right: CONDITIONAL_COMMENT_SPACING
112
- },
113
- text: comment.end
114
- });
115
- const nextNodes = [
116
- startComment,
117
- conditionalRule,
118
- endComment
119
- ];
120
- const hasPreviousNode = Boolean(parentRule.prev());
121
- atRule.remove();
122
- if ((parentRule.nodes?.length ?? 0) === 0) parentRule.replaceWith(nextNodes);
123
- else parentRule.after(nextNodes);
124
- startComment.raws.before = hasPreviousNode ? "\n" : "";
125
- startComment.raws["after"] = "\n";
126
- conditionalRule.raws.before = "\n";
127
- endComment.raws.before = "\n";
128
- endComment.raws["after"] = "\n";
129
- const nextNode = endComment.next();
130
- if (nextNode) nextNode.raws.before = "\n";
131
- return true;
132
- }
133
- return {
134
- AtRule(atRule, helper) {
135
- if (atRule.name === "weapp-tw-ifdef" || atRule.name === "weapp-tw-ifndef") {
136
- const text = parseConditionalAtRuleParam(atRule.params);
137
- const comment = atRule.name === "weapp-tw-ifndef" ? ifndef(text) : ifdef(text);
138
- if (replaceNestedAtRuleWithConditionalRule(atRule, helper, comment)) return;
139
- replaceAtRuleWithConditionalComments(atRule, helper, comment);
140
- return;
141
- }
142
- if (atRule.name === "media") {
143
- const values = [];
144
- matchCustomPropertyFromValue(atRule.params, (arr) => {
145
- const value = arr[1];
146
- if (value) values.push(value);
147
- });
148
- if (values.length > 0) {
149
- const isNegative = atRule.params.includes("not");
150
- const text = values.join(" ");
151
- const comment = isNegative ? ifndef(text) : ifdef(text);
152
- if (replaceNestedAtRuleWithConditionalRule(atRule, helper, comment)) return;
153
- replaceAtRuleWithConditionalComments(atRule, helper, comment);
154
- }
155
- }
156
- },
157
- CommentExit(comment) {
158
- if (IFDEF_ENDIF_RE.test(comment.text)) {
159
- comment.raws.left = CONDITIONAL_COMMENT_SPACING;
160
- comment.raws.right = CONDITIONAL_COMMENT_SPACING;
161
- }
162
- }
163
- };
164
- }
165
- };
166
- };
167
- creator.postcss = true;
168
- //#endregion
169
- Object.defineProperty(exports, "CSS_MACRO_POSTCSS_PLUGIN_NAME", {
170
- enumerable: true,
171
- get: function() {
172
- return CSS_MACRO_POSTCSS_PLUGIN_NAME;
173
- }
174
- });
175
- Object.defineProperty(exports, "createConditionalAtRule", {
176
- enumerable: true,
177
- get: function() {
178
- return createConditionalAtRule;
179
- }
180
- });
181
- Object.defineProperty(exports, "createNegativeConditionalAtRule", {
182
- enumerable: true,
183
- get: function() {
184
- return createNegativeConditionalAtRule;
185
- }
186
- });
187
- Object.defineProperty(exports, "creator", {
188
- enumerable: true,
189
- get: function() {
190
- return creator;
191
- }
192
- });
@@ -1,275 +0,0 @@
1
- import { $ as createSourceScanPattern, T as hasTailwindRootDirectives, Z as DEFAULT_SOURCE_SCAN_EXTENSIONS, ct as collectCssInlineSourceCandidates, dt as readInstalledPackageMajorVersion, et as expandTailwindSourceEntries, it as resolveCssSourceEntries, nt as normalizeLegacyContentEntries, rt as parseConfigParam, t as resolveTailwindV3Source, w as hasTailwindApplyDirective, y as resolveTailwindV4Source$1 } from "./v3-engine-ArQVHEau.mjs";
2
- import { i as normalizeWeappTailwindcssGeneratorOptions, t as createWeappTailwindcssGenerator } from "./generator-DnwUQOXB.mjs";
3
- import postcss from "postcss";
4
- import { extractRawCandidatesWithPositions, extractValidCandidates } from "tailwindcss-patch";
5
- import process from "node:process";
6
- import path from "node:path";
7
- import { readFile } from "node:fs/promises";
8
- import { loadConfig } from "tailwindcss-config";
9
- //#region src/postcss/config-directive.ts
10
- function quoteCssString(value) {
11
- return value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"");
12
- }
13
- function toCssPath(value) {
14
- return value.replaceAll("\\", "/");
15
- }
16
- function prependConfigDirective(css, config) {
17
- if (!config || /@config\s+/.test(css)) return css;
18
- return `@config "${quoteCssString(toCssPath(config))}";\n${css}`;
19
- }
20
- //#endregion
21
- //#region src/postcss/context.ts
22
- const PLUGIN_NAME$1 = "weapp-tailwindcss";
23
- function resolveInputFile(result) {
24
- const from = result.opts.from;
25
- if (typeof from !== "string" || from.length === 0) return;
26
- return path.isAbsolute(from) ? from : path.resolve(process.cwd(), from);
27
- }
28
- function resolvePostcssBase(result, options) {
29
- if (options.base) return options.base;
30
- const inputFile = resolveInputFile(result);
31
- return inputFile ? path.dirname(inputFile) : process.cwd();
32
- }
33
- function resolvePostcssProjectRoot(result, options) {
34
- if (options.projectRoot) return options.projectRoot;
35
- const inputFile = resolveInputFile(result);
36
- return inputFile ? path.dirname(inputFile) : process.cwd();
37
- }
38
- function replaceRootCss(root, css, result) {
39
- root.removeAll();
40
- try {
41
- const nextRoot = postcss.parse(css, { from: resolveInputFile(result) });
42
- root.append(nextRoot.nodes);
43
- } catch {
44
- root.raws = { after: css };
45
- }
46
- }
47
- function addDependencyMessages(result, generated) {
48
- for (const file of generated.dependencies) result.messages.push({
49
- type: "dependency",
50
- plugin: PLUGIN_NAME$1,
51
- file
52
- });
53
- }
54
- function addSourceDependencyMessages(result, files) {
55
- for (const file of files) result.messages.push({
56
- type: "dependency",
57
- plugin: PLUGIN_NAME$1,
58
- file
59
- });
60
- }
61
- //#endregion
62
- //#region src/postcss/source-files.ts
63
- const POSTCSS_SOURCE_PATTERN = createSourceScanPattern(DEFAULT_SOURCE_SCAN_EXTENSIONS);
64
- function isTailwindV4ApplyOnlyCss$1(root, options) {
65
- return options.version === 4 && hasTailwindApplyDirective(root.toString()) && !hasTailwindRootDirectives(root.toString(), { importFallback: true });
66
- }
67
- function getSourceExtension(file) {
68
- return path.extname(file).slice(1) || void 0;
69
- }
70
- function collectConfigPaths(root, base) {
71
- const configPaths = [];
72
- root.walkAtRules("config", (rule) => {
73
- const configPath = parseConfigParam(rule.params);
74
- if (configPath) configPaths.push(path.isAbsolute(configPath) ? configPath : path.resolve(base, configPath));
75
- });
76
- return [...new Set(configPaths)];
77
- }
78
- function resolveOptionConfigPath(config, base) {
79
- if (!config) return;
80
- return path.isAbsolute(config) ? config : path.resolve(base, config);
81
- }
82
- async function collectConfigContentFiles(root, base, options) {
83
- const configPaths = [...new Set([...resolveOptionConfigPath(options.config, base) ? [resolveOptionConfigPath(options.config, base)] : [], ...collectConfigPaths(root, base)])];
84
- const files = [];
85
- for (const configPath of configPaths) {
86
- const contentEntries = normalizeLegacyContentEntries((await loadConfig({
87
- config: configPath,
88
- cwd: path.dirname(configPath)
89
- }))?.config.content, options.version === 3 ? options.projectRoot ?? base : path.dirname(configPath), { relativeBase: path.dirname(configPath) });
90
- files.push(...await expandTailwindSourceEntries(contentEntries));
91
- }
92
- return {
93
- configPaths,
94
- files: [...new Set(files)]
95
- };
96
- }
97
- async function collectConfiguredContentEntries(root, base, options) {
98
- const configPath = resolveOptionConfigPath(options.generator?.config ?? options.config, base) ?? collectConfigPaths(root, base)[0];
99
- if (!configPath) return [];
100
- const resolvedConfigPath = path.isAbsolute(configPath) ? configPath : path.resolve(base, configPath);
101
- return normalizeLegacyContentEntries((await loadConfig({
102
- config: resolvedConfigPath,
103
- cwd: path.dirname(resolvedConfigPath)
104
- }))?.config.content, options.version === 3 ? options.projectRoot ?? base : path.dirname(resolvedConfigPath), { relativeBase: path.dirname(resolvedConfigPath) });
105
- }
106
- async function collectRawCandidatesFromSourceEntries(sourceEntries) {
107
- const candidates = /* @__PURE__ */ new Set();
108
- const files = await expandTailwindSourceEntries(sourceEntries);
109
- await Promise.all(files.map(async (file) => {
110
- const matches = await extractRawCandidatesWithPositions(await readFile(file, "utf8"), getSourceExtension(file));
111
- for (const match of matches) {
112
- const candidate = match?.rawCandidate;
113
- if (typeof candidate === "string" && candidate.length > 0) candidates.add(candidate);
114
- }
115
- }));
116
- return candidates;
117
- }
118
- async function collectAutoTailwindCandidates(root, result, options) {
119
- if (options.scanSources === false) return /* @__PURE__ */ new Set();
120
- const base = resolvePostcssBase(result, options);
121
- const projectRoot = resolvePostcssProjectRoot(result, options);
122
- const sourceEntries = [];
123
- const hasSourceNone = root.toString().includes("source(none)");
124
- const shouldSkipAutoScan = isTailwindV4ApplyOnlyCss$1(root, options);
125
- const inlineCandidates = collectCssInlineSourceCandidates(root);
126
- const configuredContentEntries = options.version === 3 ? await collectConfiguredContentEntries(root, base, options) : [];
127
- if (configuredContentEntries.length > 0) sourceEntries.push(...configuredContentEntries);
128
- else if (!hasSourceNone && !shouldSkipAutoScan) sourceEntries.push({
129
- base,
130
- negated: false,
131
- pattern: POSTCSS_SOURCE_PATTERN
132
- });
133
- sourceEntries.push(...await resolveCssSourceEntries(root, base, POSTCSS_SOURCE_PATTERN));
134
- const candidates = sourceEntries.length === 0 ? [] : options.version === 3 ? await collectRawCandidatesFromSourceEntries(sourceEntries) : await extractValidCandidates({
135
- base,
136
- css: root.toString(),
137
- cwd: projectRoot,
138
- sources: sourceEntries
139
- });
140
- return new Set([...[...candidates].filter((candidate) => !inlineCandidates.excluded.has(candidate)), ...inlineCandidates.included]);
141
- }
142
- async function collectPostcssLocalSources(root, result, options) {
143
- const base = resolvePostcssBase(result, options);
144
- const sourceEntries = await resolveCssSourceEntries(root, base, POSTCSS_SOURCE_PATTERN);
145
- const configContentFiles = await collectConfigContentFiles(root, base, options);
146
- const files = [...new Set([...await expandTailwindSourceEntries(sourceEntries), ...configContentFiles.files])];
147
- const sources = await Promise.all(files.map(async (file) => {
148
- const extension = getSourceExtension(file);
149
- return {
150
- content: await readFile(file, "utf8"),
151
- ...extension === void 0 ? {} : { extension }
152
- };
153
- }));
154
- return {
155
- files: [...files, ...configContentFiles.configPaths],
156
- sources
157
- };
158
- }
159
- //#endregion
160
- //#region src/postcss/tailwind-version.ts
161
- function hasTailwindV4CssSyntax(root) {
162
- let hasV4Syntax = false;
163
- root.walkAtRules((rule) => {
164
- if (rule.name === "theme" || rule.name === "source" || rule.name === "custom-variant") hasV4Syntax = true;
165
- if (rule.name === "import" && /(['"])tailwindcss\1/.test(rule.params)) hasV4Syntax = true;
166
- });
167
- return hasV4Syntax;
168
- }
169
- function resolvePostcssTailwindVersion(root, result, options) {
170
- const packageName = options.packageName ?? "tailwindcss";
171
- const installedVersion = readInstalledPackageMajorVersion(packageName, resolvePostcssProjectRoot(result, options));
172
- if (installedVersion) return installedVersion;
173
- if (options.version) return options.version;
174
- if (packageName === "@tailwindcss/postcss" || packageName.includes("tailwindcss4")) return 4;
175
- if (packageName.includes("tailwindcss3")) return 3;
176
- if (hasTailwindV4CssSyntax(root)) return 4;
177
- return 4;
178
- }
179
- //#endregion
180
- //#region src/postcss.ts
181
- const PLUGIN_NAME = "weapp-tailwindcss";
182
- function isTailwindV4ApplyOnlyCss(css) {
183
- return hasTailwindApplyDirective(css) && !hasTailwindRootDirectives(css, { importFallback: true });
184
- }
185
- function resolveTailwindV4PostcssSourceCss(css, sourceOptions) {
186
- return isTailwindV4ApplyOnlyCss(css) ? `@import "${sourceOptions.packageName ?? "tailwindcss"}" source(none);\n${css}` : css;
187
- }
188
- function normalizeSelector(selector) {
189
- return selector.replace(/:not\(#\\#\)/g, "").trim();
190
- }
191
- function collectApplyOnlyCssSelectors(css) {
192
- const selectors = /* @__PURE__ */ new Set();
193
- try {
194
- postcss.parse(css).walkRules((rule) => {
195
- if (!rule.nodes?.some((node) => node.type === "atrule" && node.name === "apply")) return;
196
- for (const selector of rule.selectors ?? [rule.selector]) {
197
- const normalized = normalizeSelector(selector);
198
- if (normalized) selectors.add(normalized);
199
- }
200
- });
201
- } catch {}
202
- return selectors;
203
- }
204
- function ruleMatchesApplyOnlySelector(rule, selectors) {
205
- return (rule.selectors ?? [rule.selector]).some((selector) => selectors.has(normalizeSelector(selector)));
206
- }
207
- function filterApplyOnlyGeneratedCss(css, rawCss) {
208
- const selectors = collectApplyOnlyCssSelectors(rawCss);
209
- if (selectors.size === 0) return css;
210
- try {
211
- const root = postcss.parse(css);
212
- root.walkRules((rule) => {
213
- if (!ruleMatchesApplyOnlySelector(rule, selectors) && !rule.nodes?.some((node) => node.type === "decl" && node.prop.startsWith("--"))) rule.remove();
214
- });
215
- root.walkAtRules((rule) => {
216
- if (rule.nodes !== void 0 && rule.nodes.length === 0) rule.remove();
217
- });
218
- return root.toString();
219
- } catch {
220
- return css;
221
- }
222
- }
223
- const weappTailwindcssPostcssPlugin = (options = {}) => {
224
- return {
225
- postcssPlugin: PLUGIN_NAME,
226
- async Once(root, { result }) {
227
- const { candidates, generator: userGeneratorOptions, scanSources, sources, styleOptions, ...sourceOptions } = options;
228
- const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(userGeneratorOptions);
229
- const tailwindVersion = resolvePostcssTailwindVersion(root, result, options);
230
- const [collectedSources, autoCandidates] = await Promise.all([collectPostcssLocalSources(root, result, options), collectAutoTailwindCandidates(root, result, options)]);
231
- const generatorConfig = generatorOptions.config ?? options.config;
232
- const rawCss = sourceOptions.css ?? root.toString();
233
- const isApplyOnlyTailwindV4Css = tailwindVersion === 4 && isTailwindV4ApplyOnlyCss(rawCss);
234
- const generator = createWeappTailwindcssGenerator(tailwindVersion === 3 ? await resolveTailwindV3Source({
235
- config: generatorConfig,
236
- css: rawCss,
237
- base: resolvePostcssBase(result, options),
238
- cwd: resolvePostcssProjectRoot(result, options),
239
- projectRoot: resolvePostcssProjectRoot(result, options),
240
- packageName: options.packageName,
241
- postcssPlugin: options.postcssPlugin
242
- }) : await resolveTailwindV4Source$1({
243
- ...sourceOptions,
244
- css: prependConfigDirective(resolveTailwindV4PostcssSourceCss(rawCss, sourceOptions), generatorConfig),
245
- base: resolvePostcssBase(result, options),
246
- projectRoot: resolvePostcssProjectRoot(result, options)
247
- }));
248
- const generateOptions = {
249
- candidates: new Set([...autoCandidates, ...candidates ?? []]),
250
- scanSources: scanSources ?? false,
251
- sources: [...collectedSources.sources, ...sources ?? []],
252
- styleOptions: {
253
- ...generatorOptions.styleOptions,
254
- ...styleOptions
255
- },
256
- tailwindcssV3Compatibility: generatorOptions.tailwindcssV3Compatibility,
257
- target: generatorOptions.target
258
- };
259
- const generated = await generator.generate(generateOptions);
260
- replaceRootCss(root, isApplyOnlyTailwindV4Css ? filterApplyOnlyGeneratedCss(generated.css, rawCss) : generated.css, result);
261
- addDependencyMessages(result, generated);
262
- addSourceDependencyMessages(result, collectedSources.files);
263
- result.messages.push({
264
- type: "weapp-tailwindcss:generated",
265
- plugin: PLUGIN_NAME,
266
- target: generated.target,
267
- classSet: generated.classSet,
268
- rawCss: generated.rawCss
269
- });
270
- }
271
- };
272
- };
273
- weappTailwindcssPostcssPlugin.postcss = true;
274
- //#endregion
275
- export { weappTailwindcssPostcssPlugin as t };