weapp-tailwindcss 5.1.9 → 5.1.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/bundlers/shared/generator-css/generation-helpers.d.ts +1 -0
- package/dist/bundlers/shared/generator-css/output-import-shell.d.ts +4 -0
- package/dist/bundlers/shared/generator-css/source-resolver/metadata.d.ts +1 -0
- package/dist/bundlers/shared/generator-css/types.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/css-assets.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/remembered-css-replay.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/scoped-generator.d.ts +1 -0
- package/dist/bundlers/vite/hot-css-modules.d.ts +1 -1
- package/dist/bundlers/vite/source-candidates.d.ts +7 -2
- package/dist/bundlers/vite/web-css-compat.d.ts +3 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/css-source-resolvers.d.ts +9 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.d.ts +3 -0
- package/dist/cli.js +3 -2
- package/dist/cli.mjs +2 -1
- package/dist/{context-CfXr3hWz.mjs → context-DzkSFEVL.mjs} +4 -4
- package/dist/{context-CRhUs_5e.js → context-y2BGCok4.js} +10 -10
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/generator/options.d.ts +8 -1
- package/dist/{v4-engine-BZP2462H.js → generator-Bz94KTkH.js} +229 -17
- package/dist/{v4-engine-CjjWONB0.mjs → generator-ROzBodj6.mjs} +185 -9
- package/dist/generator.js +7 -8
- package/dist/generator.mjs +1 -2
- package/dist/{gulp-CRjkPsbX.mjs → gulp-BKqMb_Ds.mjs} +4 -4
- package/dist/{gulp-JUfnhOOo.js → gulp-DfOLvYLs.js} +10 -10
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{hmr-timing-DcIEXnf8.js → hmr-timing-DOTdH18A.js} +556 -170
- package/dist/{hmr-timing-BecOXMd8.mjs → hmr-timing-DwtYJdwb.mjs} +430 -56
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/postcss.js +2 -3
- package/dist/postcss.mjs +1 -2
- package/dist/presets.js +7 -6
- package/dist/presets.mjs +5 -4
- package/dist/rspack.js +1 -1
- package/dist/rspack.mjs +1 -1
- package/dist/{source-candidate-scan-signature-10tvdJVC.js → source-candidate-scan-signature-BrWuBTjY.js} +34 -6
- package/dist/{source-candidate-scan-signature-DAg8QSgh.mjs → source-candidate-scan-signature-CQ04hiox.mjs} +29 -7
- package/dist/{tailwindcss-BZjZZi60.js → tailwindcss-Dn5DVlkI.js} +55 -47
- package/dist/{tailwindcss-PA2jHHpx.mjs → tailwindcss-hzy_WaC9.mjs} +14 -6
- package/dist/{transform-wNEbcZeQ.mjs → transform-BgnNYkIG.mjs} +1 -1
- package/dist/{transform-B0BxX3XB.js → transform-DZQETx51.js} +1 -1
- package/dist/{vite-ClpyoD9e.mjs → vite-BimHmlSp.mjs} +824 -207
- package/dist/{vite-CHk7V9EA.js → vite-bztpcI8_.js} +871 -254
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +613 -63
- package/dist/{webpack-2s-TFhgm.mjs → webpack-CCapGlNg.mjs} +235 -38
- package/dist/{webpack-BhM4Hqla.js → webpack-XxBCIrBp.js} +276 -79
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +6 -6
- package/dist/generator-DaaFxR5V.js +0 -174
- package/dist/generator-DugIHBgl.mjs +0 -127
|
@@ -15,10 +15,10 @@ let node_util = require("node:util");
|
|
|
15
15
|
let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared");
|
|
16
16
|
let _tailwindcss_mangle_engine = require("@tailwindcss-mangle/engine");
|
|
17
17
|
let lru_cache = require("lru-cache");
|
|
18
|
+
let node_module = require("node:module");
|
|
18
19
|
let node_fs_promises = require("node:fs/promises");
|
|
19
20
|
let micromatch = require("micromatch");
|
|
20
21
|
micromatch = require_watch_dependencies.__toESM(micromatch);
|
|
21
|
-
let node_module = require("node:module");
|
|
22
22
|
let _weapp_core_escape = require("@weapp-core/escape");
|
|
23
23
|
let magic_string = require("magic-string");
|
|
24
24
|
magic_string = require_watch_dependencies.__toESM(magic_string);
|
|
@@ -61,11 +61,12 @@ function rewriteTailwindcssImportsInCode(code, pkgDir, options) {
|
|
|
61
61
|
//#endregion
|
|
62
62
|
//#region src/bundlers/shared/generated-css-marker.ts
|
|
63
63
|
const BUNDLER_GENERATED_CSS_MARKER_GLOBAL_RE = /\/\*!?\s*weapp-tailwindcss (?:vite|webpack)-generated-css(?:\s*:\s*[^\s*]+)?\s*\*\/\s*/gi;
|
|
64
|
+
const VITE_INTERNAL_CSS_MARKER_GLOBAL_RE = /\/\*\$vite\$:\d+\*\/\s*/g;
|
|
64
65
|
function createBundlerGeneratedCssMarker(bundler, file) {
|
|
65
66
|
return `/*! weapp-tailwindcss ${bundler}-generated-css:${encodeURIComponent(file)} */`;
|
|
66
67
|
}
|
|
67
68
|
function stripBundlerGeneratedCssMarkers(source) {
|
|
68
|
-
return source.replace(BUNDLER_GENERATED_CSS_MARKER_GLOBAL_RE, "");
|
|
69
|
+
return source.replace(BUNDLER_GENERATED_CSS_MARKER_GLOBAL_RE, "").replace(VITE_INTERNAL_CSS_MARKER_GLOBAL_RE, "");
|
|
69
70
|
}
|
|
70
71
|
//#endregion
|
|
71
72
|
//#region src/bundlers/shared/generator-css/markers.ts
|
|
@@ -934,6 +935,8 @@ function createTailwindV4DefaultColorThemeCss() {
|
|
|
934
935
|
}
|
|
935
936
|
//#endregion
|
|
936
937
|
//#region src/tailwindcss/v4-engine/generator/css-compat.ts
|
|
938
|
+
const require$2 = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
939
|
+
const tailwindThemeCssCache = /* @__PURE__ */ new Map();
|
|
937
940
|
function findLeadingImportInsertionIndex(css) {
|
|
938
941
|
const importPattern = /(?:^|\n)\s*@import\b[^;]*;/g;
|
|
939
942
|
let insertionIndex = 0;
|
|
@@ -944,8 +947,46 @@ function findLeadingImportInsertionIndex(css) {
|
|
|
944
947
|
}
|
|
945
948
|
return insertionIndex;
|
|
946
949
|
}
|
|
947
|
-
function
|
|
948
|
-
const
|
|
950
|
+
function readCachedCss(file) {
|
|
951
|
+
const cached = tailwindThemeCssCache.get(file);
|
|
952
|
+
if (cached !== void 0) return cached;
|
|
953
|
+
const css = (0, node_fs.readFileSync)(file, "utf8");
|
|
954
|
+
tailwindThemeCssCache.set(file, css);
|
|
955
|
+
return css;
|
|
956
|
+
}
|
|
957
|
+
function resolveTailwindV4ThemeCssFromImport(css) {
|
|
958
|
+
const root = _weapp_tailwindcss_postcss.postcss.parse(css);
|
|
959
|
+
let resolved;
|
|
960
|
+
root.walkAtRules("import", (rule) => {
|
|
961
|
+
if (resolved) return;
|
|
962
|
+
const specifier = parseCssImportSpecifier$3(rule.params);
|
|
963
|
+
if (!specifier || !node_path.default.isAbsolute(specifier) || node_path.default.basename(specifier) !== "index.css") return;
|
|
964
|
+
const themeCss = node_path.default.join(node_path.default.dirname(specifier), "theme.css");
|
|
965
|
+
if ((0, node_fs.existsSync)(themeCss)) resolved = themeCss;
|
|
966
|
+
});
|
|
967
|
+
return resolved;
|
|
968
|
+
}
|
|
969
|
+
function resolveTailwindV4ThemeCssFromBase(base) {
|
|
970
|
+
try {
|
|
971
|
+
return (0, node_module.createRequire)(node_path.default.join(base, "package.json")).resolve("tailwindcss/theme.css");
|
|
972
|
+
} catch {
|
|
973
|
+
try {
|
|
974
|
+
return require$2.resolve("tailwindcss/theme.css");
|
|
975
|
+
} catch {
|
|
976
|
+
return;
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
function resolveTailwindV4DefaultThemeCss(source) {
|
|
981
|
+
try {
|
|
982
|
+
const themeCss = resolveTailwindV4ThemeCssFromImport(source.css) ?? resolveTailwindV4ThemeCssFromBase(source.base);
|
|
983
|
+
return themeCss ? readCachedCss(themeCss) : createTailwindV4DefaultColorThemeCss();
|
|
984
|
+
} catch {
|
|
985
|
+
return createTailwindV4DefaultColorThemeCss();
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
function applyMiniProgramTailwindV4DefaultColorCss(css, source) {
|
|
989
|
+
const themeCss = resolveTailwindV4DefaultThemeCss(source);
|
|
949
990
|
const insertionIndex = findLeadingImportInsertionIndex(css);
|
|
950
991
|
if (insertionIndex === 0) return `${themeCss}\n${css}`;
|
|
951
992
|
return `${css.slice(0, insertionIndex)}\n${themeCss}\n${css.slice(insertionIndex)}`;
|
|
@@ -1008,7 +1049,7 @@ function removeUnsupportedThemeVendorKeyframes(css) {
|
|
|
1008
1049
|
}
|
|
1009
1050
|
function createCompatibleSource(source, target) {
|
|
1010
1051
|
const filteredSourceCss = target === "weapp" ? removeTailwindV4PreflightImports(source.css) : source.css;
|
|
1011
|
-
const compatibleSourceCss = removeUnsupportedThemeVendorKeyframes(target === "weapp" ? applyMiniProgramTailwindV4DefaultColorCss(filteredSourceCss) : filteredSourceCss);
|
|
1052
|
+
const compatibleSourceCss = removeUnsupportedThemeVendorKeyframes(target === "weapp" ? applyMiniProgramTailwindV4DefaultColorCss(filteredSourceCss, source) : filteredSourceCss);
|
|
1012
1053
|
return compatibleSourceCss === source.css ? source : {
|
|
1013
1054
|
...source,
|
|
1014
1055
|
css: compatibleSourceCss
|
|
@@ -1562,8 +1603,8 @@ async function transformTailwindV4CssByTarget(css, target, options) {
|
|
|
1562
1603
|
//#region src/tailwindcss/v4-engine/generator.ts
|
|
1563
1604
|
const INCREMENTAL_GENERATE_CACHE_MAX = 8;
|
|
1564
1605
|
const INCREMENTAL_GENERATE_TASK_CACHE_MAX = 32;
|
|
1565
|
-
const INCREMENTAL_GENERATE_ENTRY_CANDIDATES_MAX =
|
|
1566
|
-
const INCREMENTAL_GENERATE_ENTRY_CSS_BYTES_MAX =
|
|
1606
|
+
const INCREMENTAL_GENERATE_ENTRY_CANDIDATES_MAX = 12e3;
|
|
1607
|
+
const INCREMENTAL_GENERATE_ENTRY_CSS_BYTES_MAX = 2 * 1024 * 1024;
|
|
1567
1608
|
const incrementalGenerateCache = new lru_cache.LRUCache({ max: INCREMENTAL_GENERATE_CACHE_MAX });
|
|
1568
1609
|
const incrementalGenerateTaskCache = new lru_cache.LRUCache({ max: INCREMENTAL_GENERATE_TASK_CACHE_MAX });
|
|
1569
1610
|
function collectCandidates(candidates) {
|
|
@@ -1694,6 +1735,9 @@ function normalizeTargetRpxLengthCandidates(candidates, target, styleOptions) {
|
|
|
1694
1735
|
restoreCandidates: /* @__PURE__ */ new Map()
|
|
1695
1736
|
};
|
|
1696
1737
|
}
|
|
1738
|
+
function resolveGeneratedSourcePatterns(generatedSources, scanSources) {
|
|
1739
|
+
return Array.isArray(scanSources) ? scanSources : generatedSources;
|
|
1740
|
+
}
|
|
1697
1741
|
function createTailwindV4Engine(source) {
|
|
1698
1742
|
async function generateOnce(generateSource, options = {}) {
|
|
1699
1743
|
const { scanSources = true, styleOptions, target = "weapp", ...patchOptions } = options;
|
|
@@ -1708,10 +1752,12 @@ function createTailwindV4Engine(source) {
|
|
|
1708
1752
|
...patchOptions,
|
|
1709
1753
|
candidates: normalizedCandidates.candidates
|
|
1710
1754
|
}));
|
|
1755
|
+
const sources = resolveGeneratedSourcePatterns(result.sources, resolvedScanSources);
|
|
1711
1756
|
const rawCss = restoreRpxLengthCssSelectors(result.css, normalizedCandidates.restoreCandidates);
|
|
1712
1757
|
const css = await transformTailwindV4CssByTarget(rawCss, target, resolvedStyleOptions);
|
|
1713
1758
|
return {
|
|
1714
1759
|
...result,
|
|
1760
|
+
sources,
|
|
1715
1761
|
classSet: restoreRpxLengthCandidates(result.classSet, normalizedCandidates.restoreCandidates),
|
|
1716
1762
|
rawCandidates: restoreRpxLengthCandidates(result.rawCandidates, normalizedCandidates.restoreCandidates),
|
|
1717
1763
|
css,
|
|
@@ -1733,7 +1779,7 @@ function createTailwindV4Engine(source) {
|
|
|
1733
1779
|
compatibleSource,
|
|
1734
1780
|
generated,
|
|
1735
1781
|
requestedCandidates,
|
|
1736
|
-
styleOptions
|
|
1782
|
+
styleOptions,
|
|
1737
1783
|
target
|
|
1738
1784
|
})) incrementalGenerateCache.delete(cacheKey);
|
|
1739
1785
|
return generated;
|
|
@@ -2384,10 +2430,10 @@ function shouldFilterApplyOnlyGeneratedCss(_majorVersion, target, source, option
|
|
|
2384
2430
|
}
|
|
2385
2431
|
async function transformGeneratorUserCss(source, options) {
|
|
2386
2432
|
if (source.trim().length === 0) return "";
|
|
2387
|
-
if (options.processed) return stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(removeTailwindV4GeneratorAtRules(options.generatorTarget === "weapp" ? removeTailwindV4GeneratedUserCssArtifacts(removeProcessedMiniProgramUnsupportedCss(source, {
|
|
2433
|
+
if (options.processed) return stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(removeTailwindV4GeneratorAtRules(options.generatorTarget === "weapp" ? removeTailwindV4GeneratedUserCssArtifacts(unwrapMiniProgramCascadeLayers(removeProcessedMiniProgramUnsupportedCss(source, {
|
|
2388
2434
|
...options.generatorStyleOptions,
|
|
2389
2435
|
...options.cssUserHandlerOptions
|
|
2390
|
-
})) : source)));
|
|
2436
|
+
}))) : source)));
|
|
2391
2437
|
const cleanedSource = removeTailwindSourceDirectives(removeTailwindV4GeneratorAtRules(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(source))), { importFallback: options.importFallback });
|
|
2392
2438
|
if (cleanedSource.trim().length === 0) return "";
|
|
2393
2439
|
const userSource = stripUnmatchedTailwindSourceMediaCloseFragments(removeTailwindApplyAtRules(removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(options.generatorTarget === "weapp" ? removeTailwindV4GeneratedUserCssArtifacts((0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(unwrapMiniProgramCascadeLayers(cleanedSource))) : cleanedSource)), { importFallback: options.importFallback })));
|
|
@@ -2792,28 +2838,34 @@ function shouldUseMiniProgramCssBranch(branch) {
|
|
|
2792
2838
|
//#endregion
|
|
2793
2839
|
//#region src/generator/options.ts
|
|
2794
2840
|
function normalizeWeappTailwindcssGeneratorOptions(options, context = {}) {
|
|
2795
|
-
const
|
|
2841
|
+
const enabled = options !== false;
|
|
2842
|
+
const objectOptions = enabled ? options : void 0;
|
|
2843
|
+
const target = objectOptions?.target ?? (shouldUseUniAppViteWebViewGeneratorTarget(context.appType, context.platform) ? "web" : inferGeneratorTargetFromEnv());
|
|
2796
2844
|
const branch = resolveRuntimeBranch({
|
|
2797
2845
|
...context,
|
|
2798
2846
|
generatorTarget: target
|
|
2799
2847
|
});
|
|
2800
|
-
const hasExplicitTarget =
|
|
2801
|
-
const webCompat =
|
|
2802
|
-
if (
|
|
2848
|
+
const hasExplicitTarget = objectOptions !== void 0 && Object.hasOwn(objectOptions, "target");
|
|
2849
|
+
const webCompat = objectOptions?.webCompat ?? (!hasExplicitTarget && branch.isWeb ? true : void 0);
|
|
2850
|
+
if (objectOptions == null) return {
|
|
2851
|
+
enabled,
|
|
2803
2852
|
target,
|
|
2804
2853
|
branch,
|
|
2805
2854
|
webCompat,
|
|
2855
|
+
hmr: { preserveDeletedCss: true },
|
|
2806
2856
|
importFallback: false,
|
|
2807
2857
|
bareArbitraryValues: void 0
|
|
2808
2858
|
};
|
|
2809
2859
|
return {
|
|
2860
|
+
enabled,
|
|
2810
2861
|
target,
|
|
2811
2862
|
branch,
|
|
2812
|
-
config:
|
|
2813
|
-
styleOptions:
|
|
2863
|
+
config: objectOptions.config,
|
|
2864
|
+
styleOptions: objectOptions.styleOptions,
|
|
2814
2865
|
webCompat,
|
|
2815
|
-
|
|
2816
|
-
|
|
2866
|
+
hmr: { preserveDeletedCss: objectOptions.hmr?.preserveDeletedCss ?? true },
|
|
2867
|
+
importFallback: objectOptions.importFallback ?? false,
|
|
2868
|
+
bareArbitraryValues: objectOptions.bareArbitraryValues
|
|
2817
2869
|
};
|
|
2818
2870
|
}
|
|
2819
2871
|
//#endregion
|
|
@@ -2974,6 +3026,7 @@ function resolveStyleOptionsFromContext(ctx, tailwindcssMajorVersion) {
|
|
|
2974
3026
|
};
|
|
2975
3027
|
return {
|
|
2976
3028
|
appType: ctx.appType,
|
|
3029
|
+
postcssOptions: ctx.postcssOptions,
|
|
2977
3030
|
cssPreflight: cssOptions.cssPreflight,
|
|
2978
3031
|
cssPreflightRange: cssOptions.cssPreflightRange,
|
|
2979
3032
|
cssChildCombinatorReplaceValue: cssOptions.cssChildCombinatorReplaceValue,
|
|
@@ -3136,6 +3189,119 @@ function createCssSourceOrderAppend$1(base, extra) {
|
|
|
3136
3189
|
if (/\s$/.test(base) || /^\s/.test(extra)) return `${base}${extra}`;
|
|
3137
3190
|
return `${base}\n${extra}`;
|
|
3138
3191
|
}
|
|
3192
|
+
const LEGACY_PSEUDO_ELEMENTS$1 = [
|
|
3193
|
+
"before",
|
|
3194
|
+
"after",
|
|
3195
|
+
"first-letter",
|
|
3196
|
+
"first-line"
|
|
3197
|
+
];
|
|
3198
|
+
const CSS_STRING_LITERAL_RE = /(["'])((?:\\[\s\S]|(?!\1)[\s\S])*)\1/g;
|
|
3199
|
+
function isLegacyPseudoElementAt$1(selector, index) {
|
|
3200
|
+
for (const name of LEGACY_PSEUDO_ELEMENTS$1) {
|
|
3201
|
+
if (!selector.startsWith(name, index)) continue;
|
|
3202
|
+
const next = selector[index + name.length];
|
|
3203
|
+
if (next === void 0 || !/[\w-]/.test(next)) return name;
|
|
3204
|
+
}
|
|
3205
|
+
}
|
|
3206
|
+
function normalizeLegacyPseudoElements$1(selector) {
|
|
3207
|
+
let result = "";
|
|
3208
|
+
let quote;
|
|
3209
|
+
let bracketDepth = 0;
|
|
3210
|
+
let index = 0;
|
|
3211
|
+
while (index < selector.length) {
|
|
3212
|
+
const char = selector[index];
|
|
3213
|
+
if (char === "\\") {
|
|
3214
|
+
result += selector.slice(index, index + 2);
|
|
3215
|
+
index += 2;
|
|
3216
|
+
continue;
|
|
3217
|
+
}
|
|
3218
|
+
if (quote !== void 0) {
|
|
3219
|
+
result += char;
|
|
3220
|
+
if (char === quote) quote = void 0;
|
|
3221
|
+
index += 1;
|
|
3222
|
+
continue;
|
|
3223
|
+
}
|
|
3224
|
+
if (char === "\"" || char === "'") {
|
|
3225
|
+
quote = char;
|
|
3226
|
+
result += char;
|
|
3227
|
+
index += 1;
|
|
3228
|
+
continue;
|
|
3229
|
+
}
|
|
3230
|
+
if (char === "[") {
|
|
3231
|
+
bracketDepth++;
|
|
3232
|
+
result += char;
|
|
3233
|
+
index += 1;
|
|
3234
|
+
continue;
|
|
3235
|
+
}
|
|
3236
|
+
if (char === "]") {
|
|
3237
|
+
bracketDepth = Math.max(0, bracketDepth - 1);
|
|
3238
|
+
result += char;
|
|
3239
|
+
index += 1;
|
|
3240
|
+
continue;
|
|
3241
|
+
}
|
|
3242
|
+
if (bracketDepth === 0 && char === ":" && selector[index + 1] === ":") {
|
|
3243
|
+
result += "::";
|
|
3244
|
+
index += 2;
|
|
3245
|
+
continue;
|
|
3246
|
+
}
|
|
3247
|
+
if (bracketDepth === 0 && char === ":") {
|
|
3248
|
+
const name = isLegacyPseudoElementAt$1(selector, index + 1);
|
|
3249
|
+
if (name) {
|
|
3250
|
+
result += `::${name}`;
|
|
3251
|
+
index += name.length + 1;
|
|
3252
|
+
continue;
|
|
3253
|
+
}
|
|
3254
|
+
}
|
|
3255
|
+
result += char;
|
|
3256
|
+
index += 1;
|
|
3257
|
+
}
|
|
3258
|
+
return result;
|
|
3259
|
+
}
|
|
3260
|
+
function normalizeCssRuleDeduplicationSelector(selector) {
|
|
3261
|
+
return normalizeLegacyPseudoElements$1(selector).replace(/\s+/g, " ").replace(/\s*([>+~])\s*/g, "$1").replace(/\(\s+/g, "(").replace(/\s+\)/g, ")").trim();
|
|
3262
|
+
}
|
|
3263
|
+
function normalizeCssRuleDeduplicationValue(value) {
|
|
3264
|
+
return value.replace(/\s+/g, " ").replace(CSS_STRING_LITERAL_RE, (_match, _quote, content) => {
|
|
3265
|
+
return `'${content.replace(/\\(["'])/g, "$1").replace(/'/g, "\\'")}'`;
|
|
3266
|
+
}).trim();
|
|
3267
|
+
}
|
|
3268
|
+
function createRuleDeduplicationKey(rule) {
|
|
3269
|
+
const parents = [];
|
|
3270
|
+
let parent = rule.parent;
|
|
3271
|
+
while (parent && parent.type !== "root") {
|
|
3272
|
+
if (parent.type === "atrule") parents.push(`${parent.name}:${parent.params}`);
|
|
3273
|
+
parent = parent.parent;
|
|
3274
|
+
}
|
|
3275
|
+
const declarations = (rule.nodes ?? []).map((node) => {
|
|
3276
|
+
if (node.type === "decl") return `${node.prop}:${normalizeCssRuleDeduplicationValue(node.value)}:${node.important ? "1" : "0"}`;
|
|
3277
|
+
if (node.type === "comment") return "";
|
|
3278
|
+
return normalizeCssRuleDeduplicationValue(node.toString());
|
|
3279
|
+
}).filter(Boolean);
|
|
3280
|
+
const selectors = (rule.selectors?.length ? rule.selectors : [rule.selector]).map(normalizeCssRuleDeduplicationSelector);
|
|
3281
|
+
return [
|
|
3282
|
+
parents.reverse().join("|"),
|
|
3283
|
+
selectors.join(","),
|
|
3284
|
+
declarations.join(";")
|
|
3285
|
+
].join("\n");
|
|
3286
|
+
}
|
|
3287
|
+
function deduplicateGeneratedCssRules(css) {
|
|
3288
|
+
if (!css) return css;
|
|
3289
|
+
try {
|
|
3290
|
+
const root = _weapp_tailwindcss_postcss.postcss.parse(css);
|
|
3291
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3292
|
+
root.walkRules((rule) => {
|
|
3293
|
+
const key = createRuleDeduplicationKey(rule);
|
|
3294
|
+
if (seen.has(key)) {
|
|
3295
|
+
rule.remove();
|
|
3296
|
+
return;
|
|
3297
|
+
}
|
|
3298
|
+
seen.add(key);
|
|
3299
|
+
});
|
|
3300
|
+
return root.toString();
|
|
3301
|
+
} catch {
|
|
3302
|
+
return css;
|
|
3303
|
+
}
|
|
3304
|
+
}
|
|
3139
3305
|
function shouldFinalizeMarkedUserLayerComponentsCss(file) {
|
|
3140
3306
|
return !/\.(?:vue|svelte|astro|scss|sass|less|styl)(?:[?#].*)?$/i.test(file);
|
|
3141
3307
|
}
|
|
@@ -3163,8 +3329,8 @@ function mergeGeneratorResults(generatedResults) {
|
|
|
3163
3329
|
const incrementalRawCssResults = generatedResults.map((item) => item.incrementalRawCss).filter((css) => typeof css === "string");
|
|
3164
3330
|
return {
|
|
3165
3331
|
...firstGenerated,
|
|
3166
|
-
css: generatedResults.map((item) => item.css).join("\n"),
|
|
3167
|
-
rawCss: generatedResults.map((item) => item.rawCss).join("\n"),
|
|
3332
|
+
css: deduplicateGeneratedCssRules(generatedResults.map((item) => item.css).join("\n")),
|
|
3333
|
+
rawCss: deduplicateGeneratedCssRules(generatedResults.map((item) => item.rawCss).join("\n")),
|
|
3168
3334
|
incrementalCss: incrementalCssResults.length === generatedResults.length ? incrementalCssResults.filter(Boolean).join("\n") : void 0,
|
|
3169
3335
|
incrementalRawCss: incrementalRawCssResults.length === generatedResults.length ? incrementalRawCssResults.filter(Boolean).join("\n") : void 0,
|
|
3170
3336
|
classSet: new Set(generatedResults.flatMap((item) => [...item.classSet])),
|
|
@@ -3301,8 +3467,8 @@ function getEscapedCandidate(candidate, escapeMap, store = getEscapedCandidateCa
|
|
|
3301
3467
|
* 返回结构化结果,附带已计算的 escapedValue 以避免下游重复 escape。
|
|
3302
3468
|
*/
|
|
3303
3469
|
function resolveClassNameTransformWithResult(candidate, { alwaysEscape, classNameSet, escapeMap, jsArbitraryValueFallback, jsPreserveClass, tailwindcssMajorVersion, classContext }) {
|
|
3304
|
-
if (alwaysEscape) return DIRECT_RESULT;
|
|
3305
3470
|
if (jsPreserveClass?.(candidate)) return SKIP_RESULT;
|
|
3471
|
+
if (alwaysEscape) return DIRECT_RESULT;
|
|
3306
3472
|
if (!classContext && isPlainSlashPathCandidate(candidate)) return SKIP_RESULT;
|
|
3307
3473
|
if (classNameSet?.has(candidate)) return DIRECT_RESULT;
|
|
3308
3474
|
if (classNameSet && classNameSet.size > 0) {
|
|
@@ -3765,6 +3931,12 @@ const MINI_PROGRAM_THEME_SCOPE_SELECTORS = /* @__PURE__ */ new Set([
|
|
|
3765
3931
|
]);
|
|
3766
3932
|
const SPECIFICITY_PLACEHOLDER_RE = /:not\(#(?:\\#|n)\)/g;
|
|
3767
3933
|
const SELECTOR_CACHE_LIMIT = 64;
|
|
3934
|
+
const LEGACY_PSEUDO_ELEMENTS = [
|
|
3935
|
+
"before",
|
|
3936
|
+
"after",
|
|
3937
|
+
"first-letter",
|
|
3938
|
+
"first-line"
|
|
3939
|
+
];
|
|
3768
3940
|
const generatedSelectorCache = /* @__PURE__ */ new Map();
|
|
3769
3941
|
function setGeneratedSelectorCache(css, selectors) {
|
|
3770
3942
|
if (generatedSelectorCache.size >= SELECTOR_CACHE_LIMIT) {
|
|
@@ -3776,6 +3948,67 @@ function setGeneratedSelectorCache(css, selectors) {
|
|
|
3776
3948
|
function normalizeCompatSelector(selector) {
|
|
3777
3949
|
return selector.replace(SPECIFICITY_PLACEHOLDER_RE, "").replace(/\s+/g, " ").trim();
|
|
3778
3950
|
}
|
|
3951
|
+
function isLegacyPseudoElementAt(selector, index) {
|
|
3952
|
+
for (const name of LEGACY_PSEUDO_ELEMENTS) {
|
|
3953
|
+
if (!selector.startsWith(name, index)) continue;
|
|
3954
|
+
const next = selector[index + name.length];
|
|
3955
|
+
if (next === void 0 || !/[\w-]/.test(next)) return name;
|
|
3956
|
+
}
|
|
3957
|
+
}
|
|
3958
|
+
function normalizeLegacyPseudoElements(selector) {
|
|
3959
|
+
let result = "";
|
|
3960
|
+
let quote;
|
|
3961
|
+
let bracketDepth = 0;
|
|
3962
|
+
let index = 0;
|
|
3963
|
+
while (index < selector.length) {
|
|
3964
|
+
const char = selector[index];
|
|
3965
|
+
if (char === "\\") {
|
|
3966
|
+
result += selector.slice(index, index + 2);
|
|
3967
|
+
index += 2;
|
|
3968
|
+
continue;
|
|
3969
|
+
}
|
|
3970
|
+
if (quote !== void 0) {
|
|
3971
|
+
result += char;
|
|
3972
|
+
if (char === quote) quote = void 0;
|
|
3973
|
+
index += 1;
|
|
3974
|
+
continue;
|
|
3975
|
+
}
|
|
3976
|
+
if (char === "\"" || char === "'") {
|
|
3977
|
+
quote = char;
|
|
3978
|
+
result += char;
|
|
3979
|
+
index += 1;
|
|
3980
|
+
continue;
|
|
3981
|
+
}
|
|
3982
|
+
if (char === "[") {
|
|
3983
|
+
bracketDepth++;
|
|
3984
|
+
result += char;
|
|
3985
|
+
index += 1;
|
|
3986
|
+
continue;
|
|
3987
|
+
}
|
|
3988
|
+
if (char === "]") {
|
|
3989
|
+
bracketDepth = Math.max(0, bracketDepth - 1);
|
|
3990
|
+
result += char;
|
|
3991
|
+
index += 1;
|
|
3992
|
+
continue;
|
|
3993
|
+
}
|
|
3994
|
+
if (bracketDepth === 0 && char === ":" && selector[index + 1] === ":") {
|
|
3995
|
+
result += "::";
|
|
3996
|
+
index += 2;
|
|
3997
|
+
continue;
|
|
3998
|
+
}
|
|
3999
|
+
if (bracketDepth === 0 && char === ":") {
|
|
4000
|
+
const name = isLegacyPseudoElementAt(selector, index + 1);
|
|
4001
|
+
if (name) {
|
|
4002
|
+
result += `::${name}`;
|
|
4003
|
+
index += name.length + 1;
|
|
4004
|
+
continue;
|
|
4005
|
+
}
|
|
4006
|
+
}
|
|
4007
|
+
result += char;
|
|
4008
|
+
index += 1;
|
|
4009
|
+
}
|
|
4010
|
+
return result;
|
|
4011
|
+
}
|
|
3779
4012
|
function isClassSelectorTerminator(char) {
|
|
3780
4013
|
return /[\s>+~#,.:()[\]]/.test(char);
|
|
3781
4014
|
}
|
|
@@ -3826,7 +4059,7 @@ function normalizeCompatSelectors(selector) {
|
|
|
3826
4059
|
return [...selectors];
|
|
3827
4060
|
}
|
|
3828
4061
|
function normalizeCssSelector(selector) {
|
|
3829
|
-
return selector.trim().replace(/\s+/g, "");
|
|
4062
|
+
return normalizeLegacyPseudoElements(selector).trim().replace(/\s+/g, "");
|
|
3830
4063
|
}
|
|
3831
4064
|
function getCompatSelectorKeys(selector) {
|
|
3832
4065
|
return normalizeCompatSelectors(selector).map(normalizeCssSelector);
|
|
@@ -4609,10 +4842,26 @@ function stripBundlerContentHash(name) {
|
|
|
4609
4842
|
function getMatchBasename(file) {
|
|
4610
4843
|
return stripBundlerContentHash(node_path.default.basename(getOutputFileWithoutExtension(file.replace(/[?#].*$/, ""))));
|
|
4611
4844
|
}
|
|
4845
|
+
function getMatchDirname(file) {
|
|
4846
|
+
const normalized = normalizeMatchPath(file);
|
|
4847
|
+
const dirname = node_path.default.posix.dirname(normalized);
|
|
4848
|
+
return dirname === "." ? "" : dirname;
|
|
4849
|
+
}
|
|
4612
4850
|
function isPathWithinRoot(file, root) {
|
|
4613
4851
|
const relative = node_path.default.relative(root, file);
|
|
4614
4852
|
return Boolean(relative) && !relative.startsWith("..") && !node_path.default.isAbsolute(relative);
|
|
4615
4853
|
}
|
|
4854
|
+
function collectParentDirectories(file) {
|
|
4855
|
+
const directories = [];
|
|
4856
|
+
let current = node_path.default.dirname(node_path.default.resolve(file.replace(/[?#].*$/, "")));
|
|
4857
|
+
while (true) {
|
|
4858
|
+
directories.push(current);
|
|
4859
|
+
const parent = node_path.default.dirname(current);
|
|
4860
|
+
if (parent === current) break;
|
|
4861
|
+
current = parent;
|
|
4862
|
+
}
|
|
4863
|
+
return directories;
|
|
4864
|
+
}
|
|
4616
4865
|
function collectCssSourceMatchBases(file, roots) {
|
|
4617
4866
|
const normalizedFile = file.replace(/[?#].*$/, "");
|
|
4618
4867
|
const bases = /* @__PURE__ */ new Set();
|
|
@@ -4634,13 +4883,18 @@ function scoreTailwindV4CssSourceFileMatch(file, cssSourceFile, sourceOptions) {
|
|
|
4634
4883
|
sourceOptions.cwd
|
|
4635
4884
|
]);
|
|
4636
4885
|
const sourceBases = collectCssSourceMatchBases(cssSourceFile, [sourceOptions.projectRoot, sourceOptions.cwd]);
|
|
4886
|
+
const sourceDirectoryIndexBases = collectCssSourceMatchBases(cssSourceFile, collectParentDirectories(cssSourceFile));
|
|
4637
4887
|
const outputBasename = getMatchBasename(file);
|
|
4638
4888
|
const sourceBasename = getMatchBasename(cssSourceFile);
|
|
4639
4889
|
let bestScore = 0;
|
|
4640
|
-
for (const outputBase of outputBases)
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
|
|
4890
|
+
for (const outputBase of outputBases) {
|
|
4891
|
+
for (const sourceBase of sourceBases) if (outputBase === sourceBase) bestScore = Math.max(bestScore, 1e5 + outputBase.length);
|
|
4892
|
+
else if (outputBase.endsWith(`/${sourceBase}`)) bestScore = Math.max(bestScore, 5e4 + sourceBase.length);
|
|
4893
|
+
else if (sourceBase.endsWith(`/${outputBase}`)) bestScore = Math.max(bestScore, 1e3 + outputBase.length);
|
|
4894
|
+
else if (getMatchBasename(sourceBase) === "index" && getMatchDirname(sourceBase).length > 0 && outputBase.startsWith(`${getMatchDirname(sourceBase)}/`)) bestScore = Math.max(bestScore, 25e3 + getMatchDirname(sourceBase).length);
|
|
4895
|
+
for (const sourceBase of sourceDirectoryIndexBases) if (getMatchBasename(sourceBase) === "index" && getMatchDirname(sourceBase).length > 0 && outputBase.startsWith(`${getMatchDirname(sourceBase)}/`)) bestScore = Math.max(bestScore, 25e3 + getMatchDirname(sourceBase).length);
|
|
4896
|
+
}
|
|
4897
|
+
if (outputBasename && outputBasename === sourceBasename && outputBasename !== "index") bestScore = Math.max(bestScore, 100 + outputBasename.length);
|
|
4644
4898
|
return bestScore;
|
|
4645
4899
|
}
|
|
4646
4900
|
//#endregion
|
|
@@ -4700,6 +4954,7 @@ async function resolveTailwindV4CssEntrySource(cssEntry, sourceOptions, options
|
|
|
4700
4954
|
...omitUndefined(singleEntrySourceOptions),
|
|
4701
4955
|
cssEntries: [cssEntry]
|
|
4702
4956
|
}), {
|
|
4957
|
+
candidateMatchedCssSource: options.candidateMatched,
|
|
4703
4958
|
cssEntryIndex: options.index,
|
|
4704
4959
|
includesPreflight: options.includesPreflight,
|
|
4705
4960
|
primaryCssSource: options.index === 0
|
|
@@ -4717,6 +4972,7 @@ async function resolveTailwindV4CssEntrySource(cssEntry, sourceOptions, options
|
|
|
4717
4972
|
css: normalizeConfigDirective(css, config),
|
|
4718
4973
|
cssEntries: [cssEntry]
|
|
4719
4974
|
}), {
|
|
4975
|
+
candidateMatchedCssSource: options.candidateMatched,
|
|
4720
4976
|
cssEntryIndex: options.index,
|
|
4721
4977
|
includesPreflight: options.includesPreflight,
|
|
4722
4978
|
matchedCssSourceFile: cssEntry,
|
|
@@ -4950,6 +5206,7 @@ async function resolveCandidateMatchedTailwindV4CssEntry(sourceOptions, selectio
|
|
|
4950
5206
|
if (!best) return;
|
|
4951
5207
|
if (second && second.runtimeHits === best.runtimeHits && second.totalCandidates === best.totalCandidates) return;
|
|
4952
5208
|
return resolveTailwindV4CssEntrySource(best.cssEntry, sourceOptions, {
|
|
5209
|
+
candidateMatched: true,
|
|
4953
5210
|
includesPreflight: best.includesPreflight,
|
|
4954
5211
|
index: best.index
|
|
4955
5212
|
});
|
|
@@ -4973,13 +5230,14 @@ async function resolveTailwindV4SourceSideEntrySource(resolvedEntrySource, sourc
|
|
|
4973
5230
|
css,
|
|
4974
5231
|
cssEntries: [resolvedEntrySource.file]
|
|
4975
5232
|
}));
|
|
4976
|
-
const
|
|
4977
|
-
const
|
|
5233
|
+
const matchedCssEntryIndex = sourceOptions.cssEntries?.findIndex((cssEntry) => typeof resolvedEntrySource.file === "string" && node_path.default.resolve(cssEntry.replace(/[?#].*$/, "")) === node_path.default.resolve(resolvedEntrySource.file));
|
|
5234
|
+
const matchedCssSourceIndex = sourceOptions.cssSources?.findIndex((cssSource) => typeof cssSource.file === "string" && typeof resolvedEntrySource.file === "string" && node_path.default.resolve(cssSource.file.replace(/[?#].*$/, "")) === node_path.default.resolve(resolvedEntrySource.file));
|
|
5235
|
+
const resolvedEntries = await resolveTailwindV4EntriesFromCss(resolvedEntrySource.css, resolvedEntrySource.base);
|
|
4978
5236
|
return withMatchedSourceSideMetadata(source, resolvedEntrySource, {
|
|
4979
|
-
cssEntryIndex,
|
|
4980
|
-
cssSourceIndex,
|
|
4981
|
-
includesPreflight:
|
|
4982
|
-
primaryCssSource:
|
|
5237
|
+
cssEntryIndex: matchedCssEntryIndex !== void 0 && matchedCssEntryIndex >= 0 ? matchedCssEntryIndex : void 0,
|
|
5238
|
+
cssSourceIndex: matchedCssSourceIndex !== void 0 && matchedCssSourceIndex >= 0 ? matchedCssSourceIndex : void 0,
|
|
5239
|
+
includesPreflight: resolvedEntries?.includesPreflight,
|
|
5240
|
+
primaryCssSource: matchedCssEntryIndex === 0 || !sourceOptions.cssEntries?.length && matchedCssSourceIndex === 0
|
|
4983
5241
|
});
|
|
4984
5242
|
}
|
|
4985
5243
|
async function resolveGeneratorSource(_majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions) {
|
|
@@ -5399,6 +5657,81 @@ function inheritLegacyUnitConvertedDeclarations(css, legacyCss) {
|
|
|
5399
5657
|
}
|
|
5400
5658
|
}
|
|
5401
5659
|
//#endregion
|
|
5660
|
+
//#region src/bundlers/shared/generator-css/output-import-shell.ts
|
|
5661
|
+
const MINI_PROGRAM_OUTPUT_IMPORT_RE = /(@import\s+(?:url\(\s*)?)(["'])([^"']+\.(?:wxss|acss|ttss|qss|jxss|tyss)(?:[?#][^"']*)?)\2([^;]*;)/gi;
|
|
5662
|
+
const MINI_PROGRAM_OUTPUT_STYLE_RE = /\.(?:wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i;
|
|
5663
|
+
function normalizeMiniProgramOutputImportRequest(request) {
|
|
5664
|
+
if (request.startsWith(".") || request.startsWith("/") || /^(?:[a-z][a-z\d+.-]*:|#)/i.test(request)) return request;
|
|
5665
|
+
return `./${request}`;
|
|
5666
|
+
}
|
|
5667
|
+
function normalizeMiniProgramImportShell(css) {
|
|
5668
|
+
return css.replace(MINI_PROGRAM_OUTPUT_IMPORT_RE, (_match, prefix, quote, request, suffix) => {
|
|
5669
|
+
return `${prefix}${quote}${normalizeMiniProgramOutputImportRequest(request)}${quote}${suffix}`;
|
|
5670
|
+
});
|
|
5671
|
+
}
|
|
5672
|
+
function normalizeOutputPath(file) {
|
|
5673
|
+
const segments = [];
|
|
5674
|
+
for (const segment of file.replace(/\\/g, "/").replace(/^\/+/, "").split("/")) {
|
|
5675
|
+
if (!segment || segment === ".") continue;
|
|
5676
|
+
if (segment === "..") {
|
|
5677
|
+
if (segments.length > 0 && segments[segments.length - 1] !== "..") segments.pop();
|
|
5678
|
+
else segments.push(segment);
|
|
5679
|
+
continue;
|
|
5680
|
+
}
|
|
5681
|
+
segments.push(segment);
|
|
5682
|
+
}
|
|
5683
|
+
return segments.join("/");
|
|
5684
|
+
}
|
|
5685
|
+
function splitRequestSuffix(request) {
|
|
5686
|
+
const suffixIndexCandidates = [request.indexOf("?"), request.indexOf("#")].filter((index) => index >= 0);
|
|
5687
|
+
const suffixIndex = suffixIndexCandidates.length > 0 ? Math.min(...suffixIndexCandidates) : -1;
|
|
5688
|
+
return suffixIndex < 0 ? request : request.slice(0, suffixIndex);
|
|
5689
|
+
}
|
|
5690
|
+
function resolveOutputImportRequest(file, request) {
|
|
5691
|
+
const cleanRequest = splitRequestSuffix(request.replace(/\\/g, "/"));
|
|
5692
|
+
if (cleanRequest.startsWith("/")) return normalizeOutputPath(cleanRequest);
|
|
5693
|
+
const normalizedFile = normalizeOutputPath(file);
|
|
5694
|
+
const baseDir = normalizedFile.includes("/") ? normalizedFile.slice(0, normalizedFile.lastIndexOf("/")) : "";
|
|
5695
|
+
return normalizeOutputPath(baseDir ? `${baseDir}/${cleanRequest}` : cleanRequest);
|
|
5696
|
+
}
|
|
5697
|
+
function isMiniProgramOutputImport(node) {
|
|
5698
|
+
if (node.type !== "atrule" || node.name !== "import") return false;
|
|
5699
|
+
const request = parseImportRequest(node.params);
|
|
5700
|
+
return request !== void 0 && MINI_PROGRAM_OUTPUT_STYLE_RE.test(request);
|
|
5701
|
+
}
|
|
5702
|
+
function isSelfMiniProgramOutputImport(outputFile, node) {
|
|
5703
|
+
if (!isMiniProgramOutputImport(node) || node.type !== "atrule") return false;
|
|
5704
|
+
const request = parseImportRequest(node.params);
|
|
5705
|
+
return request !== void 0 && resolveOutputImportRequest(outputFile, request) === normalizeOutputPath(outputFile);
|
|
5706
|
+
}
|
|
5707
|
+
function removeMiniProgramOutputImportsBy(css, predicate) {
|
|
5708
|
+
if (!css.includes("@import")) return css;
|
|
5709
|
+
try {
|
|
5710
|
+
const root = _weapp_tailwindcss_postcss.postcss.parse(css);
|
|
5711
|
+
let changed = false;
|
|
5712
|
+
root.walk((node) => {
|
|
5713
|
+
if (predicate(node)) {
|
|
5714
|
+
node.remove();
|
|
5715
|
+
changed = true;
|
|
5716
|
+
}
|
|
5717
|
+
});
|
|
5718
|
+
return changed ? root.toString() : css;
|
|
5719
|
+
} catch {
|
|
5720
|
+
return css;
|
|
5721
|
+
}
|
|
5722
|
+
}
|
|
5723
|
+
function removeSelfMiniProgramOutputImports(css, outputFile) {
|
|
5724
|
+
return removeMiniProgramOutputImportsBy(css, (node) => isSelfMiniProgramOutputImport(outputFile, node));
|
|
5725
|
+
}
|
|
5726
|
+
function removeMiniProgramOutputImports(css) {
|
|
5727
|
+
return removeMiniProgramOutputImportsBy(css, isMiniProgramOutputImport);
|
|
5728
|
+
}
|
|
5729
|
+
function normalizeMiniProgramGeneratorCssSource(css, outputFile) {
|
|
5730
|
+
const normalized = normalizeMiniProgramImportShell(css);
|
|
5731
|
+
if (outputFile) return removeSelfMiniProgramOutputImports(normalized, outputFile);
|
|
5732
|
+
return (0, _weapp_tailwindcss_postcss.isPureLocalCssImportWrapper)(normalized) ? normalized : removeMiniProgramOutputImports(normalized);
|
|
5733
|
+
}
|
|
5734
|
+
//#endregion
|
|
5402
5735
|
//#region src/bundlers/shared/generator-css/user-layer-order.ts
|
|
5403
5736
|
const USER_LAYER_COMPONENTS_START = "/*! weapp-tailwindcss layer components start */";
|
|
5404
5737
|
const USER_LAYER_COMPONENTS_END = "/*! weapp-tailwindcss layer components end */";
|
|
@@ -5498,6 +5831,15 @@ function resolveGeneratorSourceConcurrency() {
|
|
|
5498
5831
|
if (Number.isFinite(configured) && configured > 0) return configured;
|
|
5499
5832
|
return 1;
|
|
5500
5833
|
}
|
|
5834
|
+
function hasPostcssUserPlugins(options) {
|
|
5835
|
+
const plugins = options.postcssOptions?.plugins;
|
|
5836
|
+
if (Array.isArray(plugins)) return plugins.length > 0;
|
|
5837
|
+
return typeof plugins === "object" && plugins !== null && Object.keys(plugins).length > 0;
|
|
5838
|
+
}
|
|
5839
|
+
function shouldProcessDisabledGeneratorCss(rawSource, options) {
|
|
5840
|
+
if (!hasPostcssUserPlugins(options)) return false;
|
|
5841
|
+
return /@import\s+(?:url\(\s*)?["']tailwindcss(?:\/[^"')\s]*)?["']/.test(rawSource) || hasTailwindApplyDirective(rawSource);
|
|
5842
|
+
}
|
|
5501
5843
|
function intersectCandidateSets(left, right) {
|
|
5502
5844
|
if (left.size === 0 || right.size === 0) return /* @__PURE__ */ new Set();
|
|
5503
5845
|
const [small, large] = left.size <= right.size ? [left, right] : [right, left];
|
|
@@ -5553,9 +5895,18 @@ function mergeGeneratedCssClassSet(classSet, candidates, css, escapeMap) {
|
|
|
5553
5895
|
for (const candidate of collectGeneratedRawSourceCandidates(candidates, css, escapeMap)) merged.add(candidate);
|
|
5554
5896
|
return merged;
|
|
5555
5897
|
}
|
|
5898
|
+
function resolveGeneratedCssClassSet(target, classSet, candidates, css, escapeMap, previousClassSet) {
|
|
5899
|
+
if (target === "web") return /* @__PURE__ */ new Set([...previousClassSet ?? [], ...classSet]);
|
|
5900
|
+
return mergeGeneratedCssClassSet(classSet, candidates, css, escapeMap);
|
|
5901
|
+
}
|
|
5556
5902
|
function finalizeWebGeneratorCss(css, target, webCompat) {
|
|
5557
5903
|
return target === "web" ? (0, _weapp_tailwindcss_postcss.transformWebCssCompat)(css, webCompat) : css;
|
|
5558
5904
|
}
|
|
5905
|
+
function finalizeIncrementalGeneratorCss(previousCss, incrementalCss, target, majorVersion, cssPreflight, options, webCompat) {
|
|
5906
|
+
const finalizedIncrementalCss = finalizeMiniProgramGeneratorCss(incrementalCss, target, majorVersion, cssPreflight, options);
|
|
5907
|
+
if (target === "web") return createCssAppend(previousCss, finalizeWebGeneratorCss(finalizedIncrementalCss, target, webCompat));
|
|
5908
|
+
return createCssAppend(previousCss, finalizedIncrementalCss);
|
|
5909
|
+
}
|
|
5559
5910
|
async function generateCssByGenerator(options) {
|
|
5560
5911
|
const { opts, runtimeState, runtime, rawSource, file, cssHandlerOptions, cssUserHandlerOptions, getSourceCandidatesForEntries, styleHandler, generatorPlatform, userRawSource, userRawSourceProcessed, debug } = options;
|
|
5561
5912
|
const platform = generatorPlatform ?? opts.cssOptions?.platform ?? opts.platform;
|
|
@@ -5576,7 +5927,37 @@ async function generateCssByGenerator(options) {
|
|
|
5576
5927
|
});
|
|
5577
5928
|
const majorVersion = runtimeState.tailwindRuntime.majorVersion;
|
|
5578
5929
|
if (majorVersion !== 4) throw new Error("weapp-tailwindcss 生成管线仅支持 Tailwind CSS v4。");
|
|
5579
|
-
const
|
|
5930
|
+
const useMiniProgramCssBranch = shouldUseMiniProgramCssBranch(generatorBranch);
|
|
5931
|
+
const normalizeGeneratorCssSource = (css) => {
|
|
5932
|
+
return useMiniProgramCssBranch ? normalizeMiniProgramGeneratorCssSource(css, file) : css;
|
|
5933
|
+
};
|
|
5934
|
+
const normalizeGeneratorSource = (source) => {
|
|
5935
|
+
const css = normalizeGeneratorCssSource(source.css);
|
|
5936
|
+
return css === source.css ? source : {
|
|
5937
|
+
...source,
|
|
5938
|
+
css
|
|
5939
|
+
};
|
|
5940
|
+
};
|
|
5941
|
+
if (!generatorOptions.enabled) {
|
|
5942
|
+
debug("tailwind direct css generation disabled: %s", file);
|
|
5943
|
+
if (shouldProcessDisabledGeneratorCss(rawSource, cssHandlerOptions)) {
|
|
5944
|
+
const handled = await styleHandler(rawSource, cssHandlerOptions);
|
|
5945
|
+
return {
|
|
5946
|
+
css: finalizeWebGeneratorCss(handled.css, generatorOptions.target, generatorOptions.webCompat),
|
|
5947
|
+
classSet: resolveGeneratedCssClassSet(generatorOptions.target, /* @__PURE__ */ new Set(), runtime, handled.css, opts.escapeMap, options.previousClassSet),
|
|
5948
|
+
target: generatorOptions.target,
|
|
5949
|
+
source: "generator",
|
|
5950
|
+
dependencies: [],
|
|
5951
|
+
metadata: {
|
|
5952
|
+
file,
|
|
5953
|
+
majorVersion,
|
|
5954
|
+
rawCss: rawSource
|
|
5955
|
+
}
|
|
5956
|
+
};
|
|
5957
|
+
}
|
|
5958
|
+
return;
|
|
5959
|
+
}
|
|
5960
|
+
const effectiveRawSource = stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(normalizeEmptyTailwindCustomVariants(normalizeGeneratorCssSource(normalizeTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })))));
|
|
5580
5961
|
const effectiveRawSourceRoot = parseCssSourceRoot(effectiveRawSource);
|
|
5581
5962
|
const cleanedLocalImportWrapper = cleanLocalCssImportWrapperFromParsedRoot(effectiveRawSource, effectiveRawSourceRoot);
|
|
5582
5963
|
if (cleanedLocalImportWrapper !== void 0) return {
|
|
@@ -5597,9 +5978,10 @@ async function generateCssByGenerator(options) {
|
|
|
5597
5978
|
return finalizeWebGeneratorCss((0, _weapp_tailwindcss_postcss.restoreLocalCssImports)(finalizeMiniProgramGeneratorCss(css, target, majorVersion, opts.cssPreflight, finalizeOptions), localImports, { outputFile: file }), target, generatorOptions.webCompat);
|
|
5598
5979
|
};
|
|
5599
5980
|
const generatorRawSource = localImportParts?.source ?? effectiveRawSource;
|
|
5600
|
-
const rawUserSource = userRawSource === void 0 ? generatorRawSource : userRawSourceProcessed ? userRawSource : stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(normalizeEmptyTailwindCustomVariants(normalizeTailwindSourceDirectives(userRawSource, { importFallback: generatorOptions.importFallback }))));
|
|
5981
|
+
const rawUserSource = userRawSource === void 0 ? generatorRawSource : userRawSourceProcessed ? userRawSource : stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(normalizeEmptyTailwindCustomVariants(normalizeGeneratorCssSource(normalizeTailwindSourceDirectives(userRawSource, { importFallback: generatorOptions.importFallback })))));
|
|
5601
5982
|
const userSource = (rawUserSource === generatorRawSource ? void 0 : (0, _weapp_tailwindcss_postcss.splitLocalCssImports)(rawUserSource))?.source ?? rawUserSource;
|
|
5602
5983
|
const userCssRawSource = removeTailwindV4GeneratorAtRules(userSource);
|
|
5984
|
+
const hasWebUserCssFallbackSource = userCssRawSource.trim().length > 0 && !isCommentOnlyCss(userCssRawSource);
|
|
5603
5985
|
const generatedUserCssOrderSource = hasTailwindGeneratedCss(userSource) ? splitTailwindV4GeneratedCssBySourceOrder(userSource, generatorRawSource) : void 0;
|
|
5604
5986
|
const generatedUserCssRawSource = generatedUserCssOrderSource ? createCssAppend(generatedUserCssOrderSource.before, generatedUserCssOrderSource.after) : hasTailwindGeneratedCss(userSource) ? "" : userCssRawSource;
|
|
5605
5987
|
const userCssOrderSource = GENERATOR_PLACEHOLDER_MARKER_RE.test(userSource) ? userSource : hasTailwindGeneratedCss(userSource) ? userSource : generatedUserCssRawSource;
|
|
@@ -5607,10 +5989,13 @@ async function generateCssByGenerator(options) {
|
|
|
5607
5989
|
const hasGeneratedCss = hasTailwindGeneratedCss(generatorRawSource);
|
|
5608
5990
|
const hasSourceDirectives = hasTailwindSourceDirectives(generatorRawSource, { importFallback: generatorOptions.importFallback });
|
|
5609
5991
|
const hasGeneratedMarkers = hasTailwindGeneratedCssMarkers(generatorRawSource);
|
|
5610
|
-
const normalizedCssSources = options.cssSources?.map((source) =>
|
|
5611
|
-
|
|
5612
|
-
css
|
|
5613
|
-
|
|
5992
|
+
const normalizedCssSources = options.cssSources?.map((source) => {
|
|
5993
|
+
const css = normalizeGeneratorCssSource(normalizeEmptyTailwindCustomVariants(source.css));
|
|
5994
|
+
return css === source.css ? source : {
|
|
5995
|
+
...source,
|
|
5996
|
+
css
|
|
5997
|
+
};
|
|
5998
|
+
});
|
|
5614
5999
|
if (!shouldUseGeneratorForCurrentCss(majorVersion, cssHandlerOptions, {
|
|
5615
6000
|
forceGenerator: options.forceGenerator,
|
|
5616
6001
|
hasGeneratedCss,
|
|
@@ -5636,11 +6021,15 @@ async function generateCssByGenerator(options) {
|
|
|
5636
6021
|
getSourceCandidatesForEntries,
|
|
5637
6022
|
runtime: runtimeWithCurrentCss
|
|
5638
6023
|
});
|
|
6024
|
+
const generatorSources = useMiniProgramCssBranch ? sources.map(normalizeGeneratorSource) : sources;
|
|
5639
6025
|
const generatorStyleOptions = resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorOptions.styleOptions);
|
|
5640
|
-
const configuredContainerCompat = hasConfiguredContainerCompatSources(
|
|
6026
|
+
const configuredContainerCompat = hasConfiguredContainerCompatSources(generatorSources);
|
|
5641
6027
|
const sourceConcurrency = resolveGeneratorSourceConcurrency();
|
|
5642
|
-
const generated = mergeGeneratorResults((await runWithConcurrency(
|
|
5643
|
-
const generator = createWeappTailwindcssGenerator(
|
|
6028
|
+
const generated = mergeGeneratorResults((await runWithConcurrency(generatorSources.map((source) => async () => {
|
|
6029
|
+
const generator = createWeappTailwindcssGenerator(options.disableSourceScan === true ? {
|
|
6030
|
+
...source,
|
|
6031
|
+
css: removeTailwindSourceDirectives(source.css, { importFallback: generatorOptions.importFallback })
|
|
6032
|
+
} : source);
|
|
5644
6033
|
const sourceEntries = getSourceCandidatesForEntries ? await resolveGeneratorSourceEntries(source, runtimeState) : void 0;
|
|
5645
6034
|
const sourceScopedRuntime = sourceEntries && sourceEntries.length > 0 ? getSourceCandidatesForEntries?.(sourceEntries) : void 0;
|
|
5646
6035
|
const scopedRuntime = resolveScopedRuntimeCandidates(options.sourceCandidates, sourceScopedRuntime);
|
|
@@ -5666,7 +6055,7 @@ async function generateCssByGenerator(options) {
|
|
|
5666
6055
|
bareArbitraryValues: generatorOptions.bareArbitraryValues,
|
|
5667
6056
|
candidates: generatorRuntime,
|
|
5668
6057
|
incrementalCache: true,
|
|
5669
|
-
scanSources: shouldScanTailwindV4Sources(majorVersion, generatorOptions.target, generatorRuntime, isolateCssSource),
|
|
6058
|
+
scanSources: options.disableSourceScan === true ? false : shouldScanTailwindV4Sources(majorVersion, generatorOptions.target, generatorRuntime, isolateCssSource),
|
|
5670
6059
|
styleOptions: generatorStyleOptions,
|
|
5671
6060
|
target: generatorOptions.target
|
|
5672
6061
|
});
|
|
@@ -5675,13 +6064,14 @@ async function generateCssByGenerator(options) {
|
|
|
5675
6064
|
debug("tailwind generator result: %s rawBytes=%d cssBytes=%d candidates=%d", file, generated.rawCss.length, generated.css.length, generated.classSet.size);
|
|
5676
6065
|
if ((generated.target !== "weapp" || !hasUserCssLayerBlocks(generatorRawSource)) && typeof options.previousCss === "string" && typeof generated.incrementalCss === "string") {
|
|
5677
6066
|
const incrementalCss = stripTailwindBanner(generated.incrementalCss);
|
|
5678
|
-
const
|
|
6067
|
+
const css = incrementalCss.trim().length > 0 ? finalizeIncrementalGeneratorCss(options.previousCss, incrementalCss, generated.target, majorVersion, opts.cssPreflight, {
|
|
5679
6068
|
injectPreflight: false,
|
|
5680
6069
|
styleOptions: generatorStyleOptions
|
|
5681
|
-
})
|
|
6070
|
+
}, generatorOptions.webCompat) : options.previousCss;
|
|
6071
|
+
const finalCss = generated.target === "web" ? (0, _weapp_tailwindcss_postcss.restoreLocalCssImports)(css, localImports, { outputFile: file }) : finalizeWebGeneratorCss((0, _weapp_tailwindcss_postcss.restoreLocalCssImports)(css, localImports, { outputFile: file }), generated.target, generatorOptions.webCompat);
|
|
5682
6072
|
return {
|
|
5683
6073
|
css: finalCss,
|
|
5684
|
-
classSet:
|
|
6074
|
+
classSet: resolveGeneratedCssClassSet(generated.target, generated.classSet, runtimeWithCurrentCss, finalCss, opts.escapeMap, options.previousClassSet),
|
|
5685
6075
|
target: generated.target,
|
|
5686
6076
|
source: "generator",
|
|
5687
6077
|
dependencies: generated.dependencies,
|
|
@@ -5699,19 +6089,26 @@ async function generateCssByGenerator(options) {
|
|
|
5699
6089
|
});
|
|
5700
6090
|
const generatedCssSource = generated.target === "web" ? generated.css : stripTailwindBanner(generated.css);
|
|
5701
6091
|
const generatedCss = shouldFilterApplyOnlyCss ? filterApplyOnlyGeneratedCss(generatedCssSource, generatorRawSource, { preserveVariables: generated.target !== "web" }) : generatedCssSource;
|
|
5702
|
-
const hasMatchedCssSourceFile =
|
|
5703
|
-
const hasExplicitCssSource =
|
|
6092
|
+
const hasMatchedCssSourceFile = generatorSources.some((source) => source.__weappTailwindcssMeta?.matchedCssSourceFile);
|
|
6093
|
+
const hasExplicitCssSource = generatorSources.some((source) => {
|
|
5704
6094
|
const metadata = source.__weappTailwindcssMeta;
|
|
5705
|
-
return metadata?.cssEntryIndex !== void 0 || metadata?.cssSourceIndex !== void 0;
|
|
6095
|
+
return metadata?.candidateMatchedCssSource !== true && (metadata?.cssEntryIndex !== void 0 || metadata?.cssSourceIndex !== void 0);
|
|
6096
|
+
});
|
|
6097
|
+
const hasPreflightCssSource = generatorSources.some((source) => {
|
|
6098
|
+
const metadata = source.__weappTailwindcssMeta;
|
|
6099
|
+
const appEntryMatchedByCandidates = metadata?.candidateMatchedCssSource === true && metadata.cssEntryIndex === 0 && metadata.cssSourceIndex === void 0;
|
|
6100
|
+
return metadata?.includesPreflight === true && !appEntryMatchedByCandidates;
|
|
5706
6101
|
});
|
|
5707
|
-
const hasPreflightCssSource = sources.some((source) => source.__weappTailwindcssMeta?.includesPreflight === true);
|
|
5708
6102
|
const hasPreflightRawSource = includesTailwindV4PreflightDirective(generatorRawSource);
|
|
5709
6103
|
const preflightMode = resolveMiniProgramPreflightModeForGeneratorCss(opts, {
|
|
5710
6104
|
cssHandlerOptions,
|
|
5711
6105
|
isolateCurrentCssCandidates,
|
|
5712
6106
|
localImports,
|
|
5713
6107
|
explicitCssSource: hasExplicitCssSource,
|
|
5714
|
-
primaryCssSource:
|
|
6108
|
+
primaryCssSource: generatorSources.length > 0 && generatorSources.every((source) => {
|
|
6109
|
+
const metadata = source.__weappTailwindcssMeta;
|
|
6110
|
+
return metadata?.candidateMatchedCssSource !== true && metadata?.primaryCssSource === true;
|
|
6111
|
+
}) || hasPreflightCssSource || hasPreflightRawSource
|
|
5715
6112
|
});
|
|
5716
6113
|
const orderedExtraCss = splitGeneratorPlaceholderCssBySourceOrder(userCssOrderSource, generated.rawCss) ?? (hasMatchedCssSourceFile ? splitTailwindV4GeneratedCssBySourceOrder(userCssOrderSource, generated.rawCss) : splitRawSourceByGeneratedCssOrder(userCssOrderSource, generated.rawCss));
|
|
5717
6114
|
const shouldAppendMatchedCssSourceCompat = !hasMatchedCssSourceFile || orderedExtraCss !== void 0;
|
|
@@ -5735,14 +6132,14 @@ async function generateCssByGenerator(options) {
|
|
|
5735
6132
|
const afterUserCss = await transformGeneratorUserCss(afterLayerParts.rest, userCssOptions);
|
|
5736
6133
|
const fallbackLayerUserCss = generated.target === "weapp" && hasUserCssLayerBlocks(userCssRawSource) ? (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(afterLayerUserCss, await transformGeneratorUserCss(splitUserCssLayerBlocks(userCssRawSource).layer, userCssOptions)) : "";
|
|
5737
6134
|
css = createCssSourceOrderAppend$1(createCssSourceOrderAppend$1(createCssSourceOrderAppend$1(beforeUserCss, generated.target === "weapp" ? wrapUserLayerComponentsCss(createCssSourceOrderAppend$1(afterLayerUserCss, fallbackLayerUserCss)) : afterLayerUserCss), css), afterUserCss);
|
|
5738
|
-
if (isEmptyCssSourceOrderParts(orderedExtraCss) && shouldAppendWebBundleCssFallback(generated.target, {
|
|
6135
|
+
if (hasWebUserCssFallbackSource && isEmptyCssSourceOrderParts(orderedExtraCss) && shouldAppendWebBundleCssFallback(generated.target, {
|
|
5739
6136
|
hasSourceDirectives,
|
|
5740
6137
|
hasMatchedCssSourceFile
|
|
5741
6138
|
})) {
|
|
5742
6139
|
const userCss = await transformGeneratorUserCss(userCssRawSource, userCssOptions);
|
|
5743
6140
|
css = createCssSourceOrderAppend$1(css, userCss);
|
|
5744
6141
|
}
|
|
5745
|
-
if (generated.target === "web") {
|
|
6142
|
+
if (generated.target === "web" && hasWebUserCssFallbackSource) {
|
|
5746
6143
|
const userCss = await transformGeneratorUserCss(userCssRawSource, userCssOptions);
|
|
5747
6144
|
const missingUserCss = isCommentOnlyCss(userCss) ? "" : (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(css, userCss);
|
|
5748
6145
|
css = createCssSourceOrderAppend$1(css, missingUserCss);
|
|
@@ -5766,7 +6163,7 @@ async function generateCssByGenerator(options) {
|
|
|
5766
6163
|
});
|
|
5767
6164
|
return {
|
|
5768
6165
|
css: finalCss,
|
|
5769
|
-
classSet:
|
|
6166
|
+
classSet: resolveGeneratedCssClassSet(generated.target, generated.classSet, runtimeWithCurrentCss, finalCss, opts.escapeMap, options.previousClassSet),
|
|
5770
6167
|
target: generated.target,
|
|
5771
6168
|
source: "generator",
|
|
5772
6169
|
dependencies: generated.dependencies,
|
|
@@ -5849,7 +6246,7 @@ async function generateCssByGenerator(options) {
|
|
|
5849
6246
|
if (hasMatchedCssSourceFile && generated.target === "weapp") {
|
|
5850
6247
|
if (!isolateCurrentCssCandidates && !shouldFilterApplyOnlyCss && !userRawSourceProcessed && !hasGeneratedCss && !hasGeneratedMarkers) css = await appendLegacyContainerCompatCss(css, generatedUserCssRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
5851
6248
|
}
|
|
5852
|
-
if (shouldAppendWebBundleCssFallback(generated.target, {
|
|
6249
|
+
if (hasWebUserCssFallbackSource && shouldAppendWebBundleCssFallback(generated.target, {
|
|
5853
6250
|
hasSourceDirectives,
|
|
5854
6251
|
hasMatchedCssSourceFile
|
|
5855
6252
|
})) {
|
|
@@ -5871,7 +6268,7 @@ async function generateCssByGenerator(options) {
|
|
|
5871
6268
|
});
|
|
5872
6269
|
return {
|
|
5873
6270
|
css: finalCss,
|
|
5874
|
-
classSet:
|
|
6271
|
+
classSet: resolveGeneratedCssClassSet(generated.target, generated.classSet, runtimeWithCurrentCss, finalCss, opts.escapeMap, options.previousClassSet),
|
|
5875
6272
|
target: generated.target,
|
|
5876
6273
|
source: "generator",
|
|
5877
6274
|
dependencies: generated.dependencies,
|
|
@@ -5905,7 +6302,7 @@ async function generateCssByGenerator(options) {
|
|
|
5905
6302
|
});
|
|
5906
6303
|
return {
|
|
5907
6304
|
css: finalCss,
|
|
5908
|
-
classSet:
|
|
6305
|
+
classSet: resolveGeneratedCssClassSet(generated.target, generated.classSet, runtimeWithCurrentCss, finalCss, opts.escapeMap, options.previousClassSet),
|
|
5909
6306
|
target: generated.target,
|
|
5910
6307
|
source: "generator",
|
|
5911
6308
|
dependencies: generated.dependencies,
|
|
@@ -7080,6 +7477,7 @@ function createDefaultIgnoredSources(root, outDirIgnore, entries, explicit) {
|
|
|
7080
7477
|
}
|
|
7081
7478
|
function resolveSourceCandidateScanFiles(options) {
|
|
7082
7479
|
const resolvedRoot = node_path.default.resolve(options.root);
|
|
7480
|
+
if (options.explicit && options.entries?.length && options.entries.every((entry) => entry.negated)) return Promise.resolve([]);
|
|
7083
7481
|
const outDirIgnore = resolveOutDirIgnorePattern(resolvedRoot, options.outDir);
|
|
7084
7482
|
const scanEntries = normalizeScanEntries(resolvedRoot, options.entries, outDirIgnore);
|
|
7085
7483
|
const ignoredSources = createDefaultIgnoredSources(resolvedRoot, outDirIgnore, options.entries, options.explicit);
|
|
@@ -7124,6 +7522,16 @@ function removeCandidateSet(candidateCount, candidates) {
|
|
|
7124
7522
|
function addCandidateSet(candidateCount, candidates) {
|
|
7125
7523
|
for (const candidate of candidates) candidateCount.set(candidate, (candidateCount.get(candidate) ?? 0) + 1);
|
|
7126
7524
|
}
|
|
7525
|
+
function diffCandidateSets(previous, next) {
|
|
7526
|
+
const addedCandidates = /* @__PURE__ */ new Set();
|
|
7527
|
+
const removedCandidates = /* @__PURE__ */ new Set();
|
|
7528
|
+
for (const candidate of next) if (!previous.has(candidate)) addedCandidates.add(candidate);
|
|
7529
|
+
for (const candidate of previous) if (!next.has(candidate)) removedCandidates.add(candidate);
|
|
7530
|
+
return {
|
|
7531
|
+
addedCandidates,
|
|
7532
|
+
removedCandidates
|
|
7533
|
+
};
|
|
7534
|
+
}
|
|
7127
7535
|
function createSourceCandidateStore(options = {}) {
|
|
7128
7536
|
const candidatesById = /* @__PURE__ */ new Map();
|
|
7129
7537
|
const scanCandidatesById = /* @__PURE__ */ new Map();
|
|
@@ -7184,11 +7592,25 @@ function createSourceCandidateStore(options = {}) {
|
|
|
7184
7592
|
throw error;
|
|
7185
7593
|
}
|
|
7186
7594
|
}
|
|
7187
|
-
async function
|
|
7595
|
+
async function syncCurrentSource(id, source) {
|
|
7188
7596
|
const normalizedId = cleanUrl(id);
|
|
7189
7597
|
transformCandidatesById.delete(normalizedId);
|
|
7190
7598
|
cssCandidatesById.delete(normalizedId);
|
|
7191
|
-
|
|
7599
|
+
transformSourceById.delete(normalizedId);
|
|
7600
|
+
cssSourceById.delete(normalizedId);
|
|
7601
|
+
recompute(normalizedId);
|
|
7602
|
+
const previousCandidates = values();
|
|
7603
|
+
await sync(normalizedId, source);
|
|
7604
|
+
return diffCandidateSets(previousCandidates, values());
|
|
7605
|
+
}
|
|
7606
|
+
async function syncCurrentFile(id) {
|
|
7607
|
+
const normalizedId = cleanUrl(id);
|
|
7608
|
+
try {
|
|
7609
|
+
return await syncCurrentSource(normalizedId, await (0, node_fs_promises.readFile)(normalizedId, "utf8"));
|
|
7610
|
+
} catch (error) {
|
|
7611
|
+
if ((typeof error === "object" && error !== null && "code" in error ? error.code : void 0) === "ENOENT") return remove(normalizedId);
|
|
7612
|
+
throw error;
|
|
7613
|
+
}
|
|
7192
7614
|
}
|
|
7193
7615
|
async function scanRoot({ entries, explicit, root, outDir }) {
|
|
7194
7616
|
const files = await resolveSourceCandidateScanFiles({
|
|
@@ -7243,6 +7665,7 @@ function createSourceCandidateStore(options = {}) {
|
|
|
7243
7665
|
}
|
|
7244
7666
|
function remove(id) {
|
|
7245
7667
|
const normalizedId = cleanUrl(id);
|
|
7668
|
+
const previousValues = values();
|
|
7246
7669
|
scanCandidatesById.delete(normalizedId);
|
|
7247
7670
|
transformCandidatesById.delete(normalizedId);
|
|
7248
7671
|
cssCandidatesById.delete(normalizedId);
|
|
@@ -7250,9 +7673,10 @@ function createSourceCandidateStore(options = {}) {
|
|
|
7250
7673
|
transformSourceById.delete(normalizedId);
|
|
7251
7674
|
cssSourceById.delete(normalizedId);
|
|
7252
7675
|
const previousCandidates = candidatesById.get(normalizedId);
|
|
7253
|
-
if (!previousCandidates) return;
|
|
7676
|
+
if (!previousCandidates) return diffCandidateSets(previousValues, values());
|
|
7254
7677
|
removeCandidateSet(candidateCount, previousCandidates);
|
|
7255
7678
|
candidatesById.delete(normalizedId);
|
|
7679
|
+
return diffCandidateSets(previousValues, values());
|
|
7256
7680
|
}
|
|
7257
7681
|
function source(id) {
|
|
7258
7682
|
const normalizedId = cleanUrl(id);
|
|
@@ -7379,6 +7803,7 @@ function createSourceCandidateStore(options = {}) {
|
|
|
7379
7803
|
syncCss,
|
|
7380
7804
|
merge,
|
|
7381
7805
|
syncFile,
|
|
7806
|
+
syncCurrentSource,
|
|
7382
7807
|
syncCurrentFile,
|
|
7383
7808
|
scanRoot,
|
|
7384
7809
|
syncInline,
|
|
@@ -7403,7 +7828,111 @@ function createSourceCandidateStore(options = {}) {
|
|
|
7403
7828
|
}
|
|
7404
7829
|
}
|
|
7405
7830
|
//#endregion
|
|
7831
|
+
//#region src/defaults.ts
|
|
7832
|
+
const TAILWIND_V4_CSS_PREFLIGHT = {
|
|
7833
|
+
"border": "0 solid",
|
|
7834
|
+
"box-sizing": "border-box",
|
|
7835
|
+
"margin": "0",
|
|
7836
|
+
"padding": "0"
|
|
7837
|
+
};
|
|
7838
|
+
function getDefaultCssPreflight() {
|
|
7839
|
+
return { ...TAILWIND_V4_CSS_PREFLIGHT };
|
|
7840
|
+
}
|
|
7841
|
+
//#endregion
|
|
7406
7842
|
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.ts
|
|
7843
|
+
function resolveConfiguredWebpackCssPreflight(compilerOptions, styleOptions) {
|
|
7844
|
+
return styleOptions.cssPreflight ?? compilerOptions.cssPreflight ?? getDefaultCssPreflight();
|
|
7845
|
+
}
|
|
7846
|
+
function resolveExistingWebpackCssPreflight(compilerOptions, styleOptions, source) {
|
|
7847
|
+
return hasMiniProgramPreflightSelector(source) ? resolveConfiguredWebpackCssPreflight(compilerOptions, styleOptions) : void 0;
|
|
7848
|
+
}
|
|
7849
|
+
function removeMiniProgramPreflightSelectorRule(source) {
|
|
7850
|
+
try {
|
|
7851
|
+
const root = _weapp_tailwindcss_postcss.postcss.parse(source);
|
|
7852
|
+
let changed = false;
|
|
7853
|
+
root.walkRules((rule) => {
|
|
7854
|
+
const selectors = new Set((rule.selectors ?? [rule.selector]).map((selector) => selector.trim().replace(/^:before$/, "::before").replace(/^:after$/, "::after")));
|
|
7855
|
+
if (selectors.has("view") && selectors.has("text") && selectors.has("::before") && selectors.has("::after")) {
|
|
7856
|
+
rule.remove();
|
|
7857
|
+
changed = true;
|
|
7858
|
+
}
|
|
7859
|
+
});
|
|
7860
|
+
return changed ? root.toString() : source;
|
|
7861
|
+
} catch {
|
|
7862
|
+
return source.replace(/(?:^|[}\s])\s*view\s*,\s*text\s*,\s*::after\s*,\s*::before\s*\{[^}]*\}/g, "");
|
|
7863
|
+
}
|
|
7864
|
+
}
|
|
7865
|
+
function dedupeMiniProgramPreflightSelectorRules(source) {
|
|
7866
|
+
try {
|
|
7867
|
+
const root = _weapp_tailwindcss_postcss.postcss.parse(source);
|
|
7868
|
+
let firstRule;
|
|
7869
|
+
let changed = false;
|
|
7870
|
+
root.walkRules((rule) => {
|
|
7871
|
+
const selectors = new Set((rule.selectors ?? [rule.selector]).map((selector) => selector.trim().replace(/^:before$/, "::before").replace(/^:after$/, "::after")));
|
|
7872
|
+
if (!selectors.has("view") || !selectors.has("text") || !selectors.has("::before") || !selectors.has("::after")) return;
|
|
7873
|
+
if (!firstRule) {
|
|
7874
|
+
firstRule = rule;
|
|
7875
|
+
return;
|
|
7876
|
+
}
|
|
7877
|
+
const existingProps = /* @__PURE__ */ new Set();
|
|
7878
|
+
firstRule.walkDecls((decl) => {
|
|
7879
|
+
existingProps.add(decl.prop);
|
|
7880
|
+
});
|
|
7881
|
+
rule.walkDecls((decl) => {
|
|
7882
|
+
if (!existingProps.has(decl.prop)) {
|
|
7883
|
+
firstRule?.append(decl.clone());
|
|
7884
|
+
existingProps.add(decl.prop);
|
|
7885
|
+
}
|
|
7886
|
+
});
|
|
7887
|
+
rule.remove();
|
|
7888
|
+
changed = true;
|
|
7889
|
+
});
|
|
7890
|
+
return changed ? root.toString() : source;
|
|
7891
|
+
} catch {
|
|
7892
|
+
return source;
|
|
7893
|
+
}
|
|
7894
|
+
}
|
|
7895
|
+
function hasMiniProgramPreflightSelector(source) {
|
|
7896
|
+
try {
|
|
7897
|
+
let found = false;
|
|
7898
|
+
_weapp_tailwindcss_postcss.postcss.parse(source).walkRules((rule) => {
|
|
7899
|
+
const selectors = new Set((rule.selectors ?? [rule.selector]).map((selector) => selector.trim().replace(/^:before$/, "::before").replace(/^:after$/, "::after")));
|
|
7900
|
+
if (selectors.has("view") && selectors.has("text") && selectors.has("::before") && selectors.has("::after")) {
|
|
7901
|
+
found = true;
|
|
7902
|
+
return false;
|
|
7903
|
+
}
|
|
7904
|
+
});
|
|
7905
|
+
return found;
|
|
7906
|
+
} catch {
|
|
7907
|
+
return /(?:^|[},])\s*view\s*,\s*text\s*,\s*::after\s*,\s*::before\s*\{/.test(source);
|
|
7908
|
+
}
|
|
7909
|
+
}
|
|
7910
|
+
function ensureWebpackMiniProgramTwContentInit(source) {
|
|
7911
|
+
if (!source.includes("var(--tw-content)")) return source;
|
|
7912
|
+
try {
|
|
7913
|
+
const root = _weapp_tailwindcss_postcss.postcss.parse(source);
|
|
7914
|
+
let changed = false;
|
|
7915
|
+
root.walkRules((rule) => {
|
|
7916
|
+
const selectors = new Set((rule.selectors ?? [rule.selector]).map((selector) => selector.trim().replace(/^:before$/, "::before").replace(/^:after$/, "::after")));
|
|
7917
|
+
if (!selectors.has("view") || !selectors.has("text") || !selectors.has("::before") || !selectors.has("::after")) return;
|
|
7918
|
+
let hasContentInit = false;
|
|
7919
|
+
rule.walkDecls("--tw-content", () => {
|
|
7920
|
+
hasContentInit = true;
|
|
7921
|
+
});
|
|
7922
|
+
if (!hasContentInit) {
|
|
7923
|
+
rule.append(_weapp_tailwindcss_postcss.postcss.decl({
|
|
7924
|
+
prop: "--tw-content",
|
|
7925
|
+
value: "''"
|
|
7926
|
+
}));
|
|
7927
|
+
changed = true;
|
|
7928
|
+
}
|
|
7929
|
+
return false;
|
|
7930
|
+
});
|
|
7931
|
+
return changed ? root.toString() : source;
|
|
7932
|
+
} catch {
|
|
7933
|
+
return source;
|
|
7934
|
+
}
|
|
7935
|
+
}
|
|
7407
7936
|
function removeTailwindV4StandaloneHostPreflightRule(source) {
|
|
7408
7937
|
if (!source.includes("--theme(")) return source;
|
|
7409
7938
|
try {
|
|
@@ -7465,7 +7994,7 @@ function finalizeMiniProgramUserCssAssetSource(source, compilerOptions, isWebGen
|
|
|
7465
7994
|
const styleOptions = resolveStyleOptionsFromContext(compilerOptions);
|
|
7466
7995
|
if (isWebGeneratorTarget) return source;
|
|
7467
7996
|
return (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(removeTailwindV4StandaloneHostPreflightRule((0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(removeMiniProgramHoverSelectors(source, styleOptions.cssRemoveHoverPseudoClass), {
|
|
7468
|
-
cssPreflight: options.cssPreflight === false ? false : !hasMiniProgramTailwindV4PreflightReset(source) ? compilerOptions
|
|
7997
|
+
cssPreflight: options.cssPreflight === false ? false : !hasMiniProgramTailwindV4PreflightReset(source) ? resolveConfiguredWebpackCssPreflight(compilerOptions, styleOptions) : void 0,
|
|
7469
7998
|
isTailwindcssV4: true,
|
|
7470
7999
|
tailwindcssV4GradientFallback: styleOptions.tailwindcssV4GradientFallback
|
|
7471
8000
|
})));
|
|
@@ -7477,15 +8006,29 @@ function finalizeWebpackCssAssetSource(source, compilerOptions, isWebGeneratorTa
|
|
|
7477
8006
|
return stripTrailingLineWhitespace(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(removeTailwindV4GeneratorAtRules(removeTailwindSourceDirectives(stripBundlerGeneratedCssMarkers(source), { importFallback: true })))));
|
|
7478
8007
|
}
|
|
7479
8008
|
let finalized = removeTailwindSourceDirectives(stripBundlerGeneratedCssMarkers(source), { importFallback: true });
|
|
7480
|
-
if (options.generatedCss !== true)
|
|
8009
|
+
if (options.generatedCss !== true) {
|
|
8010
|
+
finalized = (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(finalized, {
|
|
8011
|
+
cssPreflight: false,
|
|
8012
|
+
isTailwindcssV4: true,
|
|
8013
|
+
tailwindcssV4GradientFallback: styleOptions.tailwindcssV4GradientFallback
|
|
8014
|
+
});
|
|
8015
|
+
finalized = dedupeMiniProgramPreflightSelectorRules(finalized);
|
|
8016
|
+
return (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(removeMiniProgramHoverSelectors(finalized, styleOptions.cssRemoveHoverPseudoClass));
|
|
8017
|
+
}
|
|
7481
8018
|
try {
|
|
7482
8019
|
finalized = (0, _weapp_tailwindcss_postcss.pruneMiniProgramGeneratedCss)(finalized, { preservePreflight: options.cssPreflight !== false });
|
|
7483
8020
|
} catch {}
|
|
8021
|
+
const shouldRemoveExistingPreflight = options.cssPreflight === false && options.preserveExistingPreflight === false;
|
|
8022
|
+
if (shouldRemoveExistingPreflight) finalized = removeMiniProgramPreflightSelectorRule(finalized);
|
|
8023
|
+
const hasExistingMiniProgramPreflight = options.preserveExistingPreflight !== false && hasMiniProgramPreflightSelector(source);
|
|
7484
8024
|
finalized = (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(finalized, {
|
|
7485
|
-
cssPreflight: options.cssPreflight === false ? false : !hasMiniProgramTailwindV4PreflightReset(finalized) ? compilerOptions
|
|
8025
|
+
cssPreflight: options.cssPreflight === false && !hasExistingMiniProgramPreflight ? false : !hasMiniProgramTailwindV4PreflightReset(finalized) ? resolveExistingWebpackCssPreflight(compilerOptions, styleOptions, source) : void 0,
|
|
7486
8026
|
isTailwindcssV4: true,
|
|
7487
8027
|
tailwindcssV4GradientFallback: styleOptions.tailwindcssV4GradientFallback
|
|
7488
8028
|
});
|
|
8029
|
+
finalized = ensureWebpackMiniProgramTwContentInit(finalized);
|
|
8030
|
+
if (shouldRemoveExistingPreflight) finalized = removeMiniProgramPreflightSelectorRule(finalized);
|
|
8031
|
+
else finalized = dedupeMiniProgramPreflightSelectorRules(finalized);
|
|
7489
8032
|
return (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(removeMiniProgramHoverSelectors(finalized, styleOptions.cssRemoveHoverPseudoClass));
|
|
7490
8033
|
}
|
|
7491
8034
|
//#endregion
|
|
@@ -7569,7 +8112,14 @@ async function generateCssForWebpackPipeline(source, loaderContext, options) {
|
|
|
7569
8112
|
if (!compilerOptions || !runtimeState || !getRuntimeSet) return;
|
|
7570
8113
|
await runtimeState.readyPromise;
|
|
7571
8114
|
const runtime = await getRuntimeSet();
|
|
7572
|
-
const
|
|
8115
|
+
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(compilerOptions.generator, {
|
|
8116
|
+
appType: compilerOptions.appType,
|
|
8117
|
+
platform: compilerOptions.cssOptions?.platform ?? compilerOptions.platform,
|
|
8118
|
+
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
8119
|
+
uniAppX: compilerOptions.uniAppX
|
|
8120
|
+
});
|
|
8121
|
+
if (!generatorOptions.enabled) return;
|
|
8122
|
+
const generatorTarget = generatorOptions.target;
|
|
7573
8123
|
if (generatorTarget !== "web" && generatorTarget !== "weapp") return;
|
|
7574
8124
|
const file = loaderContext.resourcePath;
|
|
7575
8125
|
const normalizedSource = normalizeCssConfigDirectives(source, file);
|