weapp-tailwindcss 5.0.7 → 5.0.10
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.
- package/dist/auto-CTp6wE5a.js +33 -0
- package/dist/auto-Cl8_hsG6.mjs +22 -0
- package/dist/{bundle-state-BzwPS-UI.js → bundle-state-BwtEqxvU.js} +3 -3
- package/dist/{bundle-state-ChcOKb9w.mjs → bundle-state-CXzPknlT.mjs} +2 -2
- package/dist/bundlers/vite/official-tailwind-plugins.d.ts +0 -2
- package/dist/cli.js +3 -159
- package/dist/cli.mjs +3 -159
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/css-macro/auto.d.ts +1 -7
- package/dist/css-macro/postcss.d.ts +1 -6
- package/dist/css-macro/postcss.js +15 -3
- package/dist/css-macro/postcss.mjs +2 -2
- package/dist/css-macro.js +19 -5
- package/dist/css-macro.mjs +16 -2
- package/dist/{generator-6yF8wjxR.js → generator-ChgOWNOj.js} +1 -1
- package/dist/{generator-BON6M1bL.mjs → generator-h2XRiJ9-.mjs} +1 -1
- package/dist/generator.js +2 -2
- package/dist/generator.mjs +2 -2
- package/dist/{gulp-oE-Byqk6.mjs → gulp-Be88jhoY.mjs} +5 -5
- package/dist/{gulp-_7p1Z2vc.js → gulp-CHtZF-oT.js} +6 -6
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{hmr-timing-BKQNRxHr.js → hmr-timing-BkivBZvN.js} +41 -43
- package/dist/{hmr-timing-BVTGf5ch.mjs → hmr-timing-Ct5w4hdM.mjs} +6 -7
- package/dist/index.js +6 -6
- package/dist/index.mjs +5 -5
- package/dist/postcss.d.ts +2 -13
- package/dist/postcss.js +14 -3
- package/dist/postcss.mjs +10 -1
- package/dist/{precheck-CZjr87m_.mjs → precheck-BpHxsWRd.mjs} +4 -4
- package/dist/{precheck-fhIkzCSU.js → precheck-CY9oaH49.js} +5 -5
- package/dist/presets.js +4 -4
- package/dist/presets.mjs +3 -3
- package/dist/tailwindcss/source-scan/inline-source.d.ts +1 -1
- package/dist/{tailwindcss-bbQUg25J.mjs → tailwindcss-Bfy2egdX.mjs} +2 -2
- package/dist/{tailwindcss-vswd1gc3.js → tailwindcss-DbbAKAZP.js} +3 -3
- package/dist/{transform-CReJxxh_.js → transform-Cd634UZV.js} +1 -1
- package/dist/{transform-DEsFlG9k.mjs → transform-r5evL6Hn.mjs} +1 -1
- package/dist/types/index.d.ts +1 -2
- package/dist/{v3-engine-CdIwmHuc.mjs → v3-engine-CFkP6dWF.mjs} +55 -19
- package/dist/{v3-engine-CEMXFegG.js → v3-engine-D0yA9ZkF.js} +86 -87
- package/dist/{vite-C7BGAlCE.mjs → vite-BM_iIFmS.mjs} +10 -411
- package/dist/{vite-0jFbh9hx.js → vite-Bh-BNp5g.js} +27 -431
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/watch-dependencies-bpG6kmAf.js +80 -0
- package/dist/weapp-tw-css-import-rewrite-loader.js +111 -407
- package/dist/weapp-tw-runtime-classset-loader.js +2 -2
- package/dist/{webpack-aEuDoYfQ.js → webpack-CJAOcYEO.js} +16 -9
- package/dist/{webpack-Dx6_eg5k.mjs → webpack-DPdrcC2X.mjs} +15 -8
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +5 -7
- package/dist/auto-Cvy0zWpS.js +0 -238
- package/dist/auto-DEHRmEAx.mjs +0 -200
- package/dist/bundlers/vite/postcss-config.d.ts +0 -6
- package/dist/bundlers/vite/processed-css-assets/css-rules.d.ts +0 -17
- package/dist/postcss/config-directive.d.ts +0 -1
- package/dist/postcss/context.d.ts +0 -9
- package/dist/postcss/source-files.d.ts +0 -8
- package/dist/postcss/tailwind-version.d.ts +0 -3
- package/dist/postcss-BTIunhWl.js +0 -284
- package/dist/postcss-BtmrrZ31.mjs +0 -275
- package/dist/postcss-C7BMYpEF.mjs +0 -169
- package/dist/postcss-CiYLsqZn.js +0 -192
- package/dist/watch-dependencies-zwx4EhBn.js +0 -5535
package/dist/postcss-BTIunhWl.js
DELETED
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
const require_chunk = require("./chunk-emK7D4bc.js");
|
|
2
|
-
const require_v3_engine = require("./v3-engine-CEMXFegG.js");
|
|
3
|
-
const require_generator = require("./generator-6yF8wjxR.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
|
-
});
|
|
@@ -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-CdIwmHuc.mjs";
|
|
2
|
-
import { i as normalizeWeappTailwindcssGeneratorOptions, t as createWeappTailwindcssGenerator } from "./generator-BON6M1bL.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 };
|