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,284 +0,0 @@
1
- const require_chunk = require("./chunk-emK7D4bc.js");
2
- const require_v3_engine = require("./v3-engine-DdlvXpID.js");
3
- const require_generator = require("./generator-C--TrAod.js");
4
- let postcss = require("postcss");
5
- postcss = require_chunk.__toESM(postcss);
6
- let tailwindcss_patch = require("tailwindcss-patch");
7
- let node_process = require("node:process");
8
- node_process = require_chunk.__toESM(node_process);
9
- let node_path = require("node:path");
10
- node_path = require_chunk.__toESM(node_path);
11
- let node_fs_promises = require("node:fs/promises");
12
- let tailwindcss_config = require("tailwindcss-config");
13
- //#region src/postcss/config-directive.ts
14
- function quoteCssString(value) {
15
- return value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"");
16
- }
17
- function toCssPath(value) {
18
- return value.replaceAll("\\", "/");
19
- }
20
- function prependConfigDirective(css, config) {
21
- if (!config || /@config\s+/.test(css)) return css;
22
- return `@config "${quoteCssString(toCssPath(config))}";\n${css}`;
23
- }
24
- //#endregion
25
- //#region src/postcss/context.ts
26
- const PLUGIN_NAME$1 = "weapp-tailwindcss";
27
- function resolveInputFile(result) {
28
- const from = result.opts.from;
29
- if (typeof from !== "string" || from.length === 0) return;
30
- return node_path.default.isAbsolute(from) ? from : node_path.default.resolve(node_process.default.cwd(), from);
31
- }
32
- function resolvePostcssBase(result, options) {
33
- if (options.base) return options.base;
34
- const inputFile = resolveInputFile(result);
35
- return inputFile ? node_path.default.dirname(inputFile) : node_process.default.cwd();
36
- }
37
- function resolvePostcssProjectRoot(result, options) {
38
- if (options.projectRoot) return options.projectRoot;
39
- const inputFile = resolveInputFile(result);
40
- return inputFile ? node_path.default.dirname(inputFile) : node_process.default.cwd();
41
- }
42
- function replaceRootCss(root, css, result) {
43
- root.removeAll();
44
- try {
45
- const nextRoot = postcss.default.parse(css, { from: resolveInputFile(result) });
46
- root.append(nextRoot.nodes);
47
- } catch {
48
- root.raws = { after: css };
49
- }
50
- }
51
- function addDependencyMessages(result, generated) {
52
- for (const file of generated.dependencies) result.messages.push({
53
- type: "dependency",
54
- plugin: PLUGIN_NAME$1,
55
- file
56
- });
57
- }
58
- function addSourceDependencyMessages(result, files) {
59
- for (const file of files) result.messages.push({
60
- type: "dependency",
61
- plugin: PLUGIN_NAME$1,
62
- file
63
- });
64
- }
65
- //#endregion
66
- //#region src/postcss/source-files.ts
67
- const POSTCSS_SOURCE_PATTERN = require_v3_engine.createSourceScanPattern(require_v3_engine.DEFAULT_SOURCE_SCAN_EXTENSIONS);
68
- function isTailwindV4ApplyOnlyCss$1(root, options) {
69
- return options.version === 4 && require_v3_engine.hasTailwindApplyDirective(root.toString()) && !require_v3_engine.hasTailwindRootDirectives(root.toString(), { importFallback: true });
70
- }
71
- function getSourceExtension(file) {
72
- return node_path.default.extname(file).slice(1) || void 0;
73
- }
74
- function collectConfigPaths(root, base) {
75
- const configPaths = [];
76
- root.walkAtRules("config", (rule) => {
77
- const configPath = require_v3_engine.parseConfigParam(rule.params);
78
- if (configPath) configPaths.push(node_path.default.isAbsolute(configPath) ? configPath : node_path.default.resolve(base, configPath));
79
- });
80
- return [...new Set(configPaths)];
81
- }
82
- function resolveOptionConfigPath(config, base) {
83
- if (!config) return;
84
- return node_path.default.isAbsolute(config) ? config : node_path.default.resolve(base, config);
85
- }
86
- async function collectConfigContentFiles(root, base, options) {
87
- const configPaths = [...new Set([...resolveOptionConfigPath(options.config, base) ? [resolveOptionConfigPath(options.config, base)] : [], ...collectConfigPaths(root, base)])];
88
- const files = [];
89
- for (const configPath of configPaths) {
90
- const contentEntries = require_v3_engine.normalizeLegacyContentEntries((await (0, tailwindcss_config.loadConfig)({
91
- config: configPath,
92
- cwd: node_path.default.dirname(configPath)
93
- }))?.config.content, options.version === 3 ? options.projectRoot ?? base : node_path.default.dirname(configPath), { relativeBase: node_path.default.dirname(configPath) });
94
- files.push(...await require_v3_engine.expandTailwindSourceEntries(contentEntries));
95
- }
96
- return {
97
- configPaths,
98
- files: [...new Set(files)]
99
- };
100
- }
101
- async function collectConfiguredContentEntries(root, base, options) {
102
- const configPath = resolveOptionConfigPath(options.generator?.config ?? options.config, base) ?? collectConfigPaths(root, base)[0];
103
- if (!configPath) return [];
104
- const resolvedConfigPath = node_path.default.isAbsolute(configPath) ? configPath : node_path.default.resolve(base, configPath);
105
- return require_v3_engine.normalizeLegacyContentEntries((await (0, tailwindcss_config.loadConfig)({
106
- config: resolvedConfigPath,
107
- cwd: node_path.default.dirname(resolvedConfigPath)
108
- }))?.config.content, options.version === 3 ? options.projectRoot ?? base : node_path.default.dirname(resolvedConfigPath), { relativeBase: node_path.default.dirname(resolvedConfigPath) });
109
- }
110
- async function collectRawCandidatesFromSourceEntries(sourceEntries) {
111
- const candidates = /* @__PURE__ */ new Set();
112
- const files = await require_v3_engine.expandTailwindSourceEntries(sourceEntries);
113
- await Promise.all(files.map(async (file) => {
114
- const matches = await (0, tailwindcss_patch.extractRawCandidatesWithPositions)(await (0, node_fs_promises.readFile)(file, "utf8"), getSourceExtension(file));
115
- for (const match of matches) {
116
- const candidate = match?.rawCandidate;
117
- if (typeof candidate === "string" && candidate.length > 0) candidates.add(candidate);
118
- }
119
- }));
120
- return candidates;
121
- }
122
- async function collectAutoTailwindCandidates(root, result, options) {
123
- if (options.scanSources === false) return /* @__PURE__ */ new Set();
124
- const base = resolvePostcssBase(result, options);
125
- const projectRoot = resolvePostcssProjectRoot(result, options);
126
- const sourceEntries = [];
127
- const hasSourceNone = root.toString().includes("source(none)");
128
- const shouldSkipAutoScan = isTailwindV4ApplyOnlyCss$1(root, options);
129
- const inlineCandidates = require_v3_engine.collectCssInlineSourceCandidates(root);
130
- const configuredContentEntries = options.version === 3 ? await collectConfiguredContentEntries(root, base, options) : [];
131
- if (configuredContentEntries.length > 0) sourceEntries.push(...configuredContentEntries);
132
- else if (!hasSourceNone && !shouldSkipAutoScan) sourceEntries.push({
133
- base,
134
- negated: false,
135
- pattern: POSTCSS_SOURCE_PATTERN
136
- });
137
- sourceEntries.push(...await require_v3_engine.resolveCssSourceEntries(root, base, POSTCSS_SOURCE_PATTERN));
138
- const candidates = sourceEntries.length === 0 ? [] : options.version === 3 ? await collectRawCandidatesFromSourceEntries(sourceEntries) : await (0, tailwindcss_patch.extractValidCandidates)({
139
- base,
140
- css: root.toString(),
141
- cwd: projectRoot,
142
- sources: sourceEntries
143
- });
144
- return new Set([...[...candidates].filter((candidate) => !inlineCandidates.excluded.has(candidate)), ...inlineCandidates.included]);
145
- }
146
- async function collectPostcssLocalSources(root, result, options) {
147
- const base = resolvePostcssBase(result, options);
148
- const sourceEntries = await require_v3_engine.resolveCssSourceEntries(root, base, POSTCSS_SOURCE_PATTERN);
149
- const configContentFiles = await collectConfigContentFiles(root, base, options);
150
- const files = [...new Set([...await require_v3_engine.expandTailwindSourceEntries(sourceEntries), ...configContentFiles.files])];
151
- const sources = await Promise.all(files.map(async (file) => {
152
- const extension = getSourceExtension(file);
153
- return {
154
- content: await (0, node_fs_promises.readFile)(file, "utf8"),
155
- ...extension === void 0 ? {} : { extension }
156
- };
157
- }));
158
- return {
159
- files: [...files, ...configContentFiles.configPaths],
160
- sources
161
- };
162
- }
163
- //#endregion
164
- //#region src/postcss/tailwind-version.ts
165
- function hasTailwindV4CssSyntax(root) {
166
- let hasV4Syntax = false;
167
- root.walkAtRules((rule) => {
168
- if (rule.name === "theme" || rule.name === "source" || rule.name === "custom-variant") hasV4Syntax = true;
169
- if (rule.name === "import" && /(['"])tailwindcss\1/.test(rule.params)) hasV4Syntax = true;
170
- });
171
- return hasV4Syntax;
172
- }
173
- function resolvePostcssTailwindVersion(root, result, options) {
174
- const packageName = options.packageName ?? "tailwindcss";
175
- const installedVersion = require_v3_engine.readInstalledPackageMajorVersion(packageName, resolvePostcssProjectRoot(result, options));
176
- if (installedVersion) return installedVersion;
177
- if (options.version) return options.version;
178
- if (packageName === "@tailwindcss/postcss" || packageName.includes("tailwindcss4")) return 4;
179
- if (packageName.includes("tailwindcss3")) return 3;
180
- if (hasTailwindV4CssSyntax(root)) return 4;
181
- return 4;
182
- }
183
- //#endregion
184
- //#region src/postcss.ts
185
- const PLUGIN_NAME = "weapp-tailwindcss";
186
- function isTailwindV4ApplyOnlyCss(css) {
187
- return require_v3_engine.hasTailwindApplyDirective(css) && !require_v3_engine.hasTailwindRootDirectives(css, { importFallback: true });
188
- }
189
- function resolveTailwindV4PostcssSourceCss(css, sourceOptions) {
190
- return isTailwindV4ApplyOnlyCss(css) ? `@import "${sourceOptions.packageName ?? "tailwindcss"}" source(none);\n${css}` : css;
191
- }
192
- function normalizeSelector(selector) {
193
- return selector.replace(/:not\(#\\#\)/g, "").trim();
194
- }
195
- function collectApplyOnlyCssSelectors(css) {
196
- const selectors = /* @__PURE__ */ new Set();
197
- try {
198
- postcss.default.parse(css).walkRules((rule) => {
199
- if (!rule.nodes?.some((node) => node.type === "atrule" && node.name === "apply")) return;
200
- for (const selector of rule.selectors ?? [rule.selector]) {
201
- const normalized = normalizeSelector(selector);
202
- if (normalized) selectors.add(normalized);
203
- }
204
- });
205
- } catch {}
206
- return selectors;
207
- }
208
- function ruleMatchesApplyOnlySelector(rule, selectors) {
209
- return (rule.selectors ?? [rule.selector]).some((selector) => selectors.has(normalizeSelector(selector)));
210
- }
211
- function filterApplyOnlyGeneratedCss(css, rawCss) {
212
- const selectors = collectApplyOnlyCssSelectors(rawCss);
213
- if (selectors.size === 0) return css;
214
- try {
215
- const root = postcss.default.parse(css);
216
- root.walkRules((rule) => {
217
- if (!ruleMatchesApplyOnlySelector(rule, selectors) && !rule.nodes?.some((node) => node.type === "decl" && node.prop.startsWith("--"))) rule.remove();
218
- });
219
- root.walkAtRules((rule) => {
220
- if (rule.nodes !== void 0 && rule.nodes.length === 0) rule.remove();
221
- });
222
- return root.toString();
223
- } catch {
224
- return css;
225
- }
226
- }
227
- const weappTailwindcssPostcssPlugin = (options = {}) => {
228
- return {
229
- postcssPlugin: PLUGIN_NAME,
230
- async Once(root, { result }) {
231
- const { candidates, generator: userGeneratorOptions, scanSources, sources, styleOptions, ...sourceOptions } = options;
232
- const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(userGeneratorOptions);
233
- const tailwindVersion = resolvePostcssTailwindVersion(root, result, options);
234
- const [collectedSources, autoCandidates] = await Promise.all([collectPostcssLocalSources(root, result, options), collectAutoTailwindCandidates(root, result, options)]);
235
- const generatorConfig = generatorOptions.config ?? options.config;
236
- const rawCss = sourceOptions.css ?? root.toString();
237
- const isApplyOnlyTailwindV4Css = tailwindVersion === 4 && isTailwindV4ApplyOnlyCss(rawCss);
238
- const generator = require_generator.createWeappTailwindcssGenerator(tailwindVersion === 3 ? await require_v3_engine.resolveTailwindV3Source({
239
- config: generatorConfig,
240
- css: rawCss,
241
- base: resolvePostcssBase(result, options),
242
- cwd: resolvePostcssProjectRoot(result, options),
243
- projectRoot: resolvePostcssProjectRoot(result, options),
244
- packageName: options.packageName,
245
- postcssPlugin: options.postcssPlugin
246
- }) : await require_v3_engine.resolveTailwindV4Source({
247
- ...sourceOptions,
248
- css: prependConfigDirective(resolveTailwindV4PostcssSourceCss(rawCss, sourceOptions), generatorConfig),
249
- base: resolvePostcssBase(result, options),
250
- projectRoot: resolvePostcssProjectRoot(result, options)
251
- }));
252
- const generateOptions = {
253
- candidates: new Set([...autoCandidates, ...candidates ?? []]),
254
- scanSources: scanSources ?? false,
255
- sources: [...collectedSources.sources, ...sources ?? []],
256
- styleOptions: {
257
- ...generatorOptions.styleOptions,
258
- ...styleOptions
259
- },
260
- tailwindcssV3Compatibility: generatorOptions.tailwindcssV3Compatibility,
261
- target: generatorOptions.target
262
- };
263
- const generated = await generator.generate(generateOptions);
264
- replaceRootCss(root, isApplyOnlyTailwindV4Css ? filterApplyOnlyGeneratedCss(generated.css, rawCss) : generated.css, result);
265
- addDependencyMessages(result, generated);
266
- addSourceDependencyMessages(result, collectedSources.files);
267
- result.messages.push({
268
- type: "weapp-tailwindcss:generated",
269
- plugin: PLUGIN_NAME,
270
- target: generated.target,
271
- classSet: generated.classSet,
272
- rawCss: generated.rawCss
273
- });
274
- }
275
- };
276
- };
277
- weappTailwindcssPostcssPlugin.postcss = true;
278
- //#endregion
279
- Object.defineProperty(exports, "weappTailwindcssPostcssPlugin", {
280
- enumerable: true,
281
- get: function() {
282
- return weappTailwindcssPostcssPlugin;
283
- }
284
- });