weapp-tailwindcss 5.0.11 → 5.0.13
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/{bundle-state-BwtEqxvU.js → bundle-state-CKWeTEhv.js} +2 -40
- package/dist/{bundle-state-CXzPknlT.mjs → bundle-state-zQ2MrDdi.mjs} +2 -34
- package/dist/bundlers/gulp/vinyl-transform.d.ts +1 -1
- package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +7 -2
- package/dist/bundlers/shared/generator-css/source-files.d.ts +1 -0
- package/dist/bundlers/shared/generator-css/source-resolver/apply-reference.d.ts +3 -0
- package/dist/bundlers/shared/generator-css/source-resolver/config.d.ts +7 -0
- package/dist/bundlers/shared/generator-css/source-resolver/matching.d.ts +4 -0
- package/dist/bundlers/shared/generator-css/source-resolver/metadata.d.ts +15 -0
- package/dist/bundlers/shared/generator-css/source-resolver/postcss-source.d.ts +12 -0
- package/dist/bundlers/shared/generator-css/source-resolver/types.d.ts +22 -0
- package/dist/bundlers/shared/generator-css/source-resolver.d.ts +5 -22
- package/dist/bundlers/shared/generator-css/types.d.ts +2 -0
- package/dist/bundlers/shared/generator-css/validate.d.ts +1 -0
- package/dist/bundlers/shared/hmr-timing.d.ts +1 -0
- package/dist/bundlers/vite/css-memory.d.ts +27 -0
- package/dist/bundlers/vite/generate-bundle/bundle-file-names.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/configured-css-sources.d.ts +8 -0
- package/dist/bundlers/vite/generate-bundle/css-assets.d.ts +4 -0
- package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +5 -0
- package/dist/bundlers/vite/generate-bundle/css-output.d.ts +9 -7
- package/dist/bundlers/vite/generate-bundle/env-flags.d.ts +7 -0
- package/dist/bundlers/vite/generate-bundle/finalize.d.ts +58 -0
- package/dist/bundlers/vite/generate-bundle/js-processing.d.ts +31 -0
- package/dist/bundlers/vite/generate-bundle/memory-debug.d.ts +77 -0
- package/dist/bundlers/vite/generate-bundle/remembered-css-replay.d.ts +53 -0
- package/dist/bundlers/vite/generate-bundle/remembered-css.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/runtime-linked-css.d.ts +4 -0
- package/dist/bundlers/vite/generate-bundle/scoped-generator.d.ts +21 -0
- package/dist/bundlers/vite/generate-bundle/sfc-style-source.d.ts +2 -1
- package/dist/bundlers/vite/generate-bundle/source-candidate-scope.d.ts +29 -0
- package/dist/bundlers/vite/generate-bundle/timing.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/types.d.ts +7 -0
- package/dist/bundlers/vite/generate-bundle/uni-app-x-postprocess.d.ts +20 -0
- package/dist/bundlers/vite/generate-bundle/vite-css-cache.d.ts +6 -0
- package/dist/bundlers/vite/generate-bundle.d.ts +2 -1
- package/dist/bundlers/vite/hot-css-modules.d.ts +5 -0
- package/dist/bundlers/vite/map-cache.d.ts +2 -0
- package/dist/bundlers/vite/processed-css-assets.d.ts +16 -0
- package/dist/bundlers/vite/resolve-app-type.d.ts +1 -2
- package/dist/bundlers/vite/source-candidate-scan-signature.d.ts +13 -0
- package/dist/bundlers/vite/source-candidates.d.ts +9 -0
- package/dist/bundlers/vite/source-scan/css-entries.d.ts +1 -0
- package/dist/bundlers/vite/source-scan.d.ts +1 -1
- package/dist/bundlers/vite/weapp-vite-config.d.ts +3 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.d.ts +11 -8
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +2 -0
- package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +5 -0
- package/dist/cache/index.d.ts +4 -0
- package/dist/cli.js +9 -2
- package/dist/cli.mjs +8 -1
- package/dist/core.d.ts +7 -0
- package/dist/core.js +8 -5
- package/dist/core.mjs +8 -5
- package/dist/css-macro.js +1 -1
- package/dist/css-macro.mjs +1 -1
- package/dist/{defaults-DH0ZQRhy.mjs → defaults-Bqx18S1f.mjs} +2 -35
- package/dist/{defaults-Boc26eel.js → defaults-C_J_kBpw.js} +2 -35
- package/dist/defaults.js +1 -1
- package/dist/defaults.mjs +1 -1
- package/dist/framework/index.d.ts +59 -0
- package/dist/framework.d.ts +1 -0
- package/dist/framework.js +198 -0
- package/dist/framework.mjs +180 -0
- package/dist/{generator-ChgOWNOj.js → generator-CzpArpCL.js} +1 -1
- package/dist/{generator-h2XRiJ9-.mjs → generator-ITLd7PTl.mjs} +1 -1
- package/dist/generator.js +2 -2
- package/dist/generator.mjs +2 -2
- package/dist/{gulp-Be88jhoY.mjs → gulp-DfOQERcV.mjs} +137 -23
- package/dist/{gulp-CHtZF-oT.js → gulp-XT8Jc7lH.js} +137 -23
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{hmr-timing-BkivBZvN.js → hmr-timing-BMftW7Us.js} +354 -225
- package/dist/{hmr-timing-Ct5w4hdM.mjs → hmr-timing-DQIP_8qP.mjs} +341 -225
- package/dist/index.d.ts +1 -0
- package/dist/index.js +20 -4
- package/dist/index.mjs +6 -5
- package/dist/postcss.js +9 -10
- package/dist/postcss.mjs +7 -5
- package/dist/{precheck-CY9oaH49.js → precheck-B0Z8yW7E.js} +108 -27
- package/dist/{precheck-BpHxsWRd.mjs → precheck-CRI90iL1.mjs} +109 -28
- package/dist/presets.js +3 -3
- package/dist/presets.mjs +3 -3
- package/dist/tailwindcss/source-scan.d.ts +1 -0
- package/dist/tailwindcss/v3-engine/generator.d.ts +17 -0
- package/dist/tailwindcss/v3-engine/index.d.ts +1 -1
- package/dist/tailwindcss/v3-engine/types.d.ts +1 -0
- package/dist/tailwindcss/v4-engine/generator.d.ts +19 -0
- package/dist/tailwindcss/v4-engine/index.d.ts +1 -1
- package/dist/{tailwindcss-Bfy2egdX.mjs → tailwindcss-DTq3uYBK.mjs} +2 -2
- package/dist/{tailwindcss-DbbAKAZP.js → tailwindcss-DZEwT3C_.js} +3 -3
- package/dist/{transform-r5evL6Hn.mjs → transform-DfcEjsZF.mjs} +29 -21
- package/dist/{transform-Cd634UZV.js → transform-YmrmxuF3.js} +29 -21
- package/dist/types/user-defined-options/general.d.ts +3 -1
- package/dist/{utils-Dolmt8EO.js → utils-BCa37Wqj.js} +2 -17
- package/dist/{utils-DsaS975I.mjs → utils-DodxWHGz.mjs} +2 -17
- package/dist/{v3-engine-D0yA9ZkF.js → v3-engine-2rrgylhn.js} +194 -34
- package/dist/{v3-engine-CFkP6dWF.mjs → v3-engine-C6eJ0YzK.mjs} +176 -34
- package/dist/{vite-j9cB2Ff1.js → vite-CXHVsHmX.js} +2071 -1160
- package/dist/{vite-Bd8qf9dK.mjs → vite-DjI09vVN.mjs} +2071 -1160
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +476 -217
- package/dist/weapp-tw-runtime-classset-loader.js +25 -0
- package/dist/{webpack-DPdrcC2X.mjs → webpack-BcPpnT90.mjs} +251 -40
- package/dist/{webpack-CJAOcYEO.js → webpack-CfkUkMXG.js} +254 -43
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +10 -5
|
@@ -4,18 +4,19 @@ Object.defineProperties(exports, {
|
|
|
4
4
|
});
|
|
5
5
|
const require_watch_dependencies = require("./watch-dependencies-bpG6kmAf.js");
|
|
6
6
|
let node_buffer = require("node:buffer");
|
|
7
|
-
let node_process = require("node:process");
|
|
8
|
-
node_process = require_watch_dependencies.__toESM(node_process);
|
|
9
|
-
let _weapp_tailwindcss_postcss = require("@weapp-tailwindcss/postcss");
|
|
10
7
|
let node_fs = require("node:fs");
|
|
11
8
|
node_fs = require_watch_dependencies.__toESM(node_fs);
|
|
12
9
|
let node_path = require("node:path");
|
|
13
10
|
node_path = require_watch_dependencies.__toESM(node_path);
|
|
11
|
+
let node_process = require("node:process");
|
|
12
|
+
node_process = require_watch_dependencies.__toESM(node_process);
|
|
13
|
+
let _weapp_tailwindcss_postcss = require("@weapp-tailwindcss/postcss");
|
|
14
14
|
let node_util = require("node:util");
|
|
15
15
|
let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared");
|
|
16
16
|
let tailwindcss_patch = require("tailwindcss-patch");
|
|
17
17
|
tailwindcss_patch = require_watch_dependencies.__toESM(tailwindcss_patch);
|
|
18
18
|
let node_module = require("node:module");
|
|
19
|
+
let lru_cache = require("lru-cache");
|
|
19
20
|
let _weapp_tailwindcss_logger = require("@weapp-tailwindcss/logger");
|
|
20
21
|
let node_url = require("node:url");
|
|
21
22
|
let debug = require("debug");
|
|
@@ -1783,8 +1784,12 @@ async function transformTailwindV4CssByTarget(css, target, options) {
|
|
|
1783
1784
|
}
|
|
1784
1785
|
//#endregion
|
|
1785
1786
|
//#region src/tailwindcss/v4-engine/generator.ts
|
|
1786
|
-
const
|
|
1787
|
-
const
|
|
1787
|
+
const INCREMENTAL_GENERATE_CACHE_MAX$1 = 8;
|
|
1788
|
+
const INCREMENTAL_GENERATE_TASK_CACHE_MAX = 32;
|
|
1789
|
+
const INCREMENTAL_GENERATE_ENTRY_CANDIDATES_MAX$1 = 128;
|
|
1790
|
+
const INCREMENTAL_GENERATE_ENTRY_CSS_BYTES_MAX$1 = 256 * 1024;
|
|
1791
|
+
const incrementalGenerateCache$1 = new lru_cache.LRUCache({ max: INCREMENTAL_GENERATE_CACHE_MAX$1 });
|
|
1792
|
+
const incrementalGenerateTaskCache = new lru_cache.LRUCache({ max: INCREMENTAL_GENERATE_TASK_CACHE_MAX });
|
|
1788
1793
|
function collectCandidates(candidates) {
|
|
1789
1794
|
return new Set(candidates ?? []);
|
|
1790
1795
|
}
|
|
@@ -1880,6 +1885,9 @@ function collectCustomPropertyValues(css) {
|
|
|
1880
1885
|
function mergeCustomPropertyValues(target, css) {
|
|
1881
1886
|
for (const [prop, value] of collectCustomPropertyValues(css)) target.set(prop, value);
|
|
1882
1887
|
}
|
|
1888
|
+
function shouldRebuildIncrementalEntry$1(cached, requestedCandidates, missingCandidates) {
|
|
1889
|
+
return cached.seenCandidates.size + missingCandidates.length > INCREMENTAL_GENERATE_ENTRY_CANDIDATES_MAX$1 || cached.css.length > INCREMENTAL_GENERATE_ENTRY_CSS_BYTES_MAX$1 || cached.rawCss.length > INCREMENTAL_GENERATE_ENTRY_CSS_BYTES_MAX$1 || requestedCandidates.size > INCREMENTAL_GENERATE_ENTRY_CANDIDATES_MAX$1;
|
|
1890
|
+
}
|
|
1883
1891
|
function seedIncrementalGenerateCache(options) {
|
|
1884
1892
|
const cacheKey = createIncrementalGenerateCacheKey(options.compatibleSource, options.target, options.styleOptions, options.tailwindcssV3Compatibility);
|
|
1885
1893
|
const customPropertyValues = collectCustomPropertyValues(options.compatibleSource.css);
|
|
@@ -1967,6 +1975,18 @@ function createTailwindV4Engine(source) {
|
|
|
1967
1975
|
root: cached.root,
|
|
1968
1976
|
target: cached.target
|
|
1969
1977
|
};
|
|
1978
|
+
if (shouldRebuildIncrementalEntry$1(cached, requestedCandidates, missingCandidates)) return runIncrementalGenerateTask(cacheKey, requestedCandidates, options.scanSources, async () => {
|
|
1979
|
+
const generated = await generateOnce(source, options);
|
|
1980
|
+
seedIncrementalGenerateCache({
|
|
1981
|
+
compatibleSource,
|
|
1982
|
+
generated,
|
|
1983
|
+
requestedCandidates,
|
|
1984
|
+
styleOptions,
|
|
1985
|
+
tailwindcssV3Compatibility: options.tailwindcssV3Compatibility,
|
|
1986
|
+
target
|
|
1987
|
+
});
|
|
1988
|
+
return generated;
|
|
1989
|
+
});
|
|
1970
1990
|
return runIncrementalGenerateTask(cacheKey, requestedCandidates, options.scanSources, async () => {
|
|
1971
1991
|
const designSystem = await cached.designSystemPromise;
|
|
1972
1992
|
const normalizedMissing = normalizeRpxTextCandidates(missingCandidates);
|
|
@@ -2923,6 +2943,7 @@ function readStaticConfigContent(configPath) {
|
|
|
2923
2943
|
//#endregion
|
|
2924
2944
|
//#region src/bundlers/vite/source-scan/css-entries.ts
|
|
2925
2945
|
const VITE_SOURCE_CANDIDATE_PATTERN = FULL_SOURCE_SCAN_PATTERN;
|
|
2946
|
+
const tailwindConfigCssEntriesCache = /* @__PURE__ */ new Map();
|
|
2926
2947
|
function parseImportSourceParam(params) {
|
|
2927
2948
|
const match = /\bsource\(\s*(none|(['"])(.*?)\2)\s*\)/.exec(params);
|
|
2928
2949
|
if (!match) return;
|
|
@@ -2949,6 +2970,44 @@ function resolveConfigPath(base, configPath) {
|
|
|
2949
2970
|
if (node_path.default.isAbsolute(configPath)) return node_path.default.resolve(configPath);
|
|
2950
2971
|
return node_path.default.resolve(base, configPath);
|
|
2951
2972
|
}
|
|
2973
|
+
function createCssEntriesCacheKey(css, base, dependencies) {
|
|
2974
|
+
return JSON.stringify({
|
|
2975
|
+
base: node_path.default.resolve(base),
|
|
2976
|
+
css,
|
|
2977
|
+
dependencies
|
|
2978
|
+
});
|
|
2979
|
+
}
|
|
2980
|
+
function createDependencyExcludeEntries(files) {
|
|
2981
|
+
return [...files].map((file) => ({
|
|
2982
|
+
base: node_path.default.dirname(file),
|
|
2983
|
+
negated: true,
|
|
2984
|
+
pattern: node_path.default.basename(file)
|
|
2985
|
+
}));
|
|
2986
|
+
}
|
|
2987
|
+
async function statConfigDependency(file) {
|
|
2988
|
+
try {
|
|
2989
|
+
const stats = await (0, node_fs_promises.stat)(file);
|
|
2990
|
+
return {
|
|
2991
|
+
file,
|
|
2992
|
+
mtimeMs: stats.mtimeMs,
|
|
2993
|
+
size: stats.size
|
|
2994
|
+
};
|
|
2995
|
+
} catch {
|
|
2996
|
+
return {
|
|
2997
|
+
file,
|
|
2998
|
+
mtimeMs: -1,
|
|
2999
|
+
size: -1
|
|
3000
|
+
};
|
|
3001
|
+
}
|
|
3002
|
+
}
|
|
3003
|
+
async function collectConfigDependencySignatures(root, base) {
|
|
3004
|
+
const configPaths = /* @__PURE__ */ new Set();
|
|
3005
|
+
root.walkAtRules("config", (rule) => {
|
|
3006
|
+
const configPath = parseConfigParam$1(rule.params);
|
|
3007
|
+
if (configPath) configPaths.add(resolveConfigPath(base, configPath));
|
|
3008
|
+
});
|
|
3009
|
+
return Promise.all([...configPaths].sort().map(statConfigDependency));
|
|
3010
|
+
}
|
|
2952
3011
|
async function resolveConfigContentEntries(root, base) {
|
|
2953
3012
|
const configPaths = /* @__PURE__ */ new Set();
|
|
2954
3013
|
root.walkAtRules("config", (rule) => {
|
|
@@ -3031,6 +3090,32 @@ async function resolveTailwindV4EntriesFromCss(css, base) {
|
|
|
3031
3090
|
dependencies: configEntries.dependencies
|
|
3032
3091
|
} : void 0;
|
|
3033
3092
|
}
|
|
3093
|
+
async function resolveTailwindConfigEntriesFromCssCached(css, base) {
|
|
3094
|
+
let root;
|
|
3095
|
+
try {
|
|
3096
|
+
root = _weapp_tailwindcss_postcss.postcss.parse(css);
|
|
3097
|
+
} catch {
|
|
3098
|
+
return;
|
|
3099
|
+
}
|
|
3100
|
+
const dependencies = await collectConfigDependencySignatures(root, base);
|
|
3101
|
+
if (dependencies.length === 0) return;
|
|
3102
|
+
const cacheKey = createCssEntriesCacheKey(css, base, dependencies);
|
|
3103
|
+
const cached = tailwindConfigCssEntriesCache.get(cacheKey);
|
|
3104
|
+
if (cached) return cached;
|
|
3105
|
+
const task = resolveConfigContentEntries(root, base).then((resolved) => {
|
|
3106
|
+
return {
|
|
3107
|
+
entries: [...resolved.entries, ...createDependencyExcludeEntries(resolved.dependencies)],
|
|
3108
|
+
explicit: true,
|
|
3109
|
+
inlineCandidates: {
|
|
3110
|
+
excluded: /* @__PURE__ */ new Set(),
|
|
3111
|
+
included: /* @__PURE__ */ new Set()
|
|
3112
|
+
},
|
|
3113
|
+
dependencies: resolved.dependencies
|
|
3114
|
+
};
|
|
3115
|
+
});
|
|
3116
|
+
tailwindConfigCssEntriesCache.set(cacheKey, task);
|
|
3117
|
+
return task;
|
|
3118
|
+
}
|
|
3034
3119
|
//#endregion
|
|
3035
3120
|
//#region src/tailwindcss/runtime/cache.ts
|
|
3036
3121
|
const runtimeSignaturePatchersSymbol = Symbol.for("weapp-tailwindcss.runtimeSignaturePatchers");
|
|
@@ -3200,7 +3285,10 @@ async function transformTailwindV3CssByTarget(css, target, options) {
|
|
|
3200
3285
|
}
|
|
3201
3286
|
//#endregion
|
|
3202
3287
|
//#region src/tailwindcss/v3-engine/generator.ts
|
|
3203
|
-
const
|
|
3288
|
+
const INCREMENTAL_GENERATE_CACHE_MAX = 8;
|
|
3289
|
+
const INCREMENTAL_GENERATE_ENTRY_CANDIDATES_MAX = 128;
|
|
3290
|
+
const INCREMENTAL_GENERATE_ENTRY_CSS_BYTES_MAX = 256 * 1024;
|
|
3291
|
+
const incrementalGenerateCache = new lru_cache.LRUCache({ max: INCREMENTAL_GENERATE_CACHE_MAX });
|
|
3204
3292
|
const patchRawStyleGenerator = typeof tailwindcss_patch.generateTailwindV3RawStyle === "function" ? tailwindcss_patch.generateTailwindV3RawStyle : void 0;
|
|
3205
3293
|
function isTailwindV3PatchResolutionError(error, packageName) {
|
|
3206
3294
|
if (!error || typeof error !== "object") return false;
|
|
@@ -3324,6 +3412,48 @@ function sortCandidates(candidates) {
|
|
|
3324
3412
|
return a < z ? -1 : 1;
|
|
3325
3413
|
});
|
|
3326
3414
|
}
|
|
3415
|
+
function createRequestedCandidatesCacheKey(candidates) {
|
|
3416
|
+
return sortCandidates(candidates).join("\n");
|
|
3417
|
+
}
|
|
3418
|
+
function createIncrementalResultsCache() {
|
|
3419
|
+
return new lru_cache.LRUCache({ max: 16 });
|
|
3420
|
+
}
|
|
3421
|
+
function replaceIncrementalEntry(entry, candidates, generated) {
|
|
3422
|
+
if (!generated.context) return;
|
|
3423
|
+
entry.context = generated.context;
|
|
3424
|
+
entry.seenCandidates = new Set(candidates);
|
|
3425
|
+
entry.classSet = new Set(generated.classSet);
|
|
3426
|
+
entry.css = generated.css;
|
|
3427
|
+
entry.rawCss = generated.rawCss;
|
|
3428
|
+
entry.dependencies = generated.dependencies;
|
|
3429
|
+
entry.resultsByCandidates.clear();
|
|
3430
|
+
}
|
|
3431
|
+
function seedIncrementalResult(entry, candidates, result) {
|
|
3432
|
+
entry.resultsByCandidates.set(createRequestedCandidatesCacheKey(candidates), {
|
|
3433
|
+
classSet: new Set(result.classSet),
|
|
3434
|
+
css: result.css,
|
|
3435
|
+
rawCss: result.rawCss,
|
|
3436
|
+
dependencies: result.dependencies
|
|
3437
|
+
});
|
|
3438
|
+
}
|
|
3439
|
+
function createGenerateResultFromCache(cached, result, candidates) {
|
|
3440
|
+
return {
|
|
3441
|
+
css: result.css,
|
|
3442
|
+
rawCss: result.rawCss,
|
|
3443
|
+
incrementalCss: "",
|
|
3444
|
+
incrementalRawCss: "",
|
|
3445
|
+
classSet: new Set(result.classSet),
|
|
3446
|
+
rawCandidates: new Set(candidates),
|
|
3447
|
+
dependencies: result.dependencies,
|
|
3448
|
+
sources: [],
|
|
3449
|
+
root: null,
|
|
3450
|
+
target: cached.target,
|
|
3451
|
+
version: 3
|
|
3452
|
+
};
|
|
3453
|
+
}
|
|
3454
|
+
function shouldRebuildIncrementalEntry(cached, requestedCandidates, missingCandidates) {
|
|
3455
|
+
return cached.seenCandidates.size + missingCandidates.length > INCREMENTAL_GENERATE_ENTRY_CANDIDATES_MAX || cached.css.length > INCREMENTAL_GENERATE_ENTRY_CSS_BYTES_MAX || cached.rawCss.length > INCREMENTAL_GENERATE_ENTRY_CSS_BYTES_MAX || requestedCandidates.size > INCREMENTAL_GENERATE_ENTRY_CANDIDATES_MAX;
|
|
3456
|
+
}
|
|
3327
3457
|
function appendUtilityRules(root, context, rules) {
|
|
3328
3458
|
const sortedRules = context.offsets.sort(rules);
|
|
3329
3459
|
for (const [sort, rule] of sortedRules) {
|
|
@@ -3453,38 +3583,31 @@ function createTailwindV3Engine(source) {
|
|
|
3453
3583
|
if (cached) {
|
|
3454
3584
|
if (hasRemovedCandidates(cached.seenCandidates, requestedCandidates)) {
|
|
3455
3585
|
const generated = await generateOnce(source, options);
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
seenCandidates: new Set(requestedCandidates),
|
|
3459
|
-
classSet: new Set(generated.classSet),
|
|
3460
|
-
css: generated.css,
|
|
3461
|
-
rawCss: generated.rawCss,
|
|
3462
|
-
dependencies: generated.dependencies,
|
|
3463
|
-
target: generated.target
|
|
3464
|
-
});
|
|
3586
|
+
replaceIncrementalEntry(cached, requestedCandidates, generated);
|
|
3587
|
+
seedIncrementalResult(cached, requestedCandidates, generated);
|
|
3465
3588
|
return generated;
|
|
3466
3589
|
}
|
|
3590
|
+
const requestedCacheKey = createRequestedCandidatesCacheKey(requestedCandidates);
|
|
3591
|
+
const cachedResult = cached.resultsByCandidates.get(requestedCacheKey);
|
|
3592
|
+
if (cachedResult) return createGenerateResultFromCache(cached, cachedResult, requestedCandidates);
|
|
3467
3593
|
const missingCandidates = [...requestedCandidates].filter((candidate) => !cached.seenCandidates.has(candidate));
|
|
3468
|
-
if (missingCandidates.length === 0)
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
target: cached.target,
|
|
3479
|
-
version: 3
|
|
3480
|
-
};
|
|
3594
|
+
if (missingCandidates.length === 0) {
|
|
3595
|
+
seedIncrementalResult(cached, requestedCandidates, cached);
|
|
3596
|
+
return createGenerateResultFromCache(cached, cached, requestedCandidates);
|
|
3597
|
+
}
|
|
3598
|
+
if (shouldRebuildIncrementalEntry(cached, requestedCandidates, missingCandidates)) {
|
|
3599
|
+
const generated = await generateOnce(source, options);
|
|
3600
|
+
replaceIncrementalEntry(cached, requestedCandidates, generated);
|
|
3601
|
+
seedIncrementalResult(cached, requestedCandidates, generated);
|
|
3602
|
+
return generated;
|
|
3603
|
+
}
|
|
3481
3604
|
const generated = await generateIncrementalMissingUtilities(cached.context, missingCandidates, target, styleOptions, options.bareArbitraryValues);
|
|
3482
3605
|
for (const candidate of missingCandidates) cached.seenCandidates.add(candidate);
|
|
3483
3606
|
for (const className of generated.classSet) cached.classSet.add(className);
|
|
3484
3607
|
cached.css = [cached.css, generated.css].filter(Boolean).join("\n");
|
|
3485
3608
|
cached.rawCss = [cached.rawCss, generated.rawCss].filter(Boolean).join("\n");
|
|
3486
3609
|
cached.dependencies = [...new Set([...cached.dependencies, ...generated.dependencies])];
|
|
3487
|
-
|
|
3610
|
+
const result = {
|
|
3488
3611
|
css: cached.css,
|
|
3489
3612
|
rawCss: cached.rawCss,
|
|
3490
3613
|
incrementalCss: generated.css,
|
|
@@ -3497,17 +3620,23 @@ function createTailwindV3Engine(source) {
|
|
|
3497
3620
|
target: cached.target,
|
|
3498
3621
|
version: 3
|
|
3499
3622
|
};
|
|
3623
|
+
seedIncrementalResult(cached, requestedCandidates, result);
|
|
3624
|
+
return result;
|
|
3500
3625
|
}
|
|
3501
3626
|
const generated = await generateOnce(source, options);
|
|
3502
|
-
|
|
3627
|
+
const resultsByCandidates = createIncrementalResultsCache();
|
|
3628
|
+
const entry = {
|
|
3503
3629
|
context: generated.context,
|
|
3504
3630
|
seenCandidates: new Set(requestedCandidates),
|
|
3505
3631
|
classSet: new Set(generated.classSet),
|
|
3506
3632
|
css: generated.css,
|
|
3507
3633
|
rawCss: generated.rawCss,
|
|
3508
3634
|
dependencies: generated.dependencies,
|
|
3635
|
+
resultsByCandidates,
|
|
3509
3636
|
target: generated.target
|
|
3510
|
-
}
|
|
3637
|
+
};
|
|
3638
|
+
seedIncrementalResult(entry, requestedCandidates, generated);
|
|
3639
|
+
incrementalGenerateCache.set(cacheKey, entry);
|
|
3511
3640
|
return generated;
|
|
3512
3641
|
}
|
|
3513
3642
|
async function generate(options = {}) {
|
|
@@ -3576,6 +3705,7 @@ async function resolveTailwindV3Source(options = {}) {
|
|
|
3576
3705
|
const cssConfig = resolveCssConfig(options.css, base);
|
|
3577
3706
|
const config = resolveOptionalPath(options.config, base) ?? cssConfig.config;
|
|
3578
3707
|
const cwd = options.cwd ?? (config ? node_path.default.dirname(config) : projectRoot);
|
|
3708
|
+
const explicitConfigObject = normalizeLoadedConfig(options.configObject);
|
|
3579
3709
|
const loaded = await (0, tailwindcss_config.loadConfig)(omitUndefined({
|
|
3580
3710
|
config,
|
|
3581
3711
|
cwd
|
|
@@ -3587,7 +3717,7 @@ async function resolveTailwindV3Source(options = {}) {
|
|
|
3587
3717
|
base,
|
|
3588
3718
|
css: cssConfig.css ?? options.css ?? DEFAULT_TAILWIND_V3_CSS,
|
|
3589
3719
|
config: loaded?.filepath ?? config,
|
|
3590
|
-
configObject: normalizeLoadedConfig(loaded?.config),
|
|
3720
|
+
configObject: explicitConfigObject ?? normalizeLoadedConfig(loaded?.config),
|
|
3591
3721
|
dependencies: loaded?.filepath ? [loaded.filepath] : [],
|
|
3592
3722
|
packageName: options.packageName ?? "tailwindcss",
|
|
3593
3723
|
postcssPlugin: options.postcssPlugin ?? options.packageName ?? "tailwindcss"
|
|
@@ -3707,22 +3837,45 @@ function isUniAppXEnabled(option) {
|
|
|
3707
3837
|
//#region src/context/style-options.ts
|
|
3708
3838
|
function resolveStyleOptionsFromContext(ctx) {
|
|
3709
3839
|
const resolvedUniAppXOptions = resolveUniAppXOptions(ctx.uniAppX);
|
|
3840
|
+
const hasCssOptions = ctx.cssOptions !== void 0;
|
|
3841
|
+
const cssOptions = {
|
|
3842
|
+
cssPreflight: ctx.cssOptions?.cssPreflight ?? ctx.cssPreflight,
|
|
3843
|
+
cssPreflightRange: ctx.cssOptions?.cssPreflightRange ?? ctx.cssPreflightRange,
|
|
3844
|
+
cssChildCombinatorReplaceValue: ctx.cssOptions?.cssChildCombinatorReplaceValue ?? ctx.cssChildCombinatorReplaceValue,
|
|
3845
|
+
cssSelectorReplacement: ctx.cssOptions?.cssSelectorReplacement ?? ctx.cssSelectorReplacement,
|
|
3846
|
+
rem2rpx: ctx.cssOptions?.rem2rpx ?? ctx.rem2rpx,
|
|
3847
|
+
cssRemoveProperty: ctx.cssOptions?.cssRemoveProperty ?? ctx.cssRemoveProperty,
|
|
3848
|
+
cssRemoveHoverPseudoClass: ctx.cssOptions?.cssRemoveHoverPseudoClass ?? ctx.cssRemoveHoverPseudoClass,
|
|
3849
|
+
tailwindcssV4GradientFallback: ctx.cssOptions?.tailwindcssV4GradientFallback ?? ctx.tailwindcssV4GradientFallback,
|
|
3850
|
+
cssPresetEnv: ctx.cssOptions?.cssPresetEnv ?? ctx.cssPresetEnv,
|
|
3851
|
+
atRules: ctx.cssOptions?.atRules ?? ctx.atRules,
|
|
3852
|
+
autoprefixer: ctx.cssOptions?.autoprefixer ?? ctx.autoprefixer,
|
|
3853
|
+
cssCalc: ctx.cssOptions?.cssCalc ?? ctx.cssCalc,
|
|
3854
|
+
platform: ctx.cssOptions?.platform ?? ctx.platform,
|
|
3855
|
+
px2rpx: ctx.cssOptions?.px2rpx ?? ctx.px2rpx,
|
|
3856
|
+
unitsToPx: ctx.cssOptions?.unitsToPx ?? ctx.unitsToPx,
|
|
3857
|
+
unitConversion: ctx.cssOptions?.unitConversion ?? ctx.unitConversion,
|
|
3858
|
+
injectAdditionalCssVarScope: ctx.cssOptions?.injectAdditionalCssVarScope ?? ctx.injectAdditionalCssVarScope
|
|
3859
|
+
};
|
|
3710
3860
|
return {
|
|
3711
|
-
cssPreflight:
|
|
3712
|
-
cssPreflightRange:
|
|
3713
|
-
cssChildCombinatorReplaceValue:
|
|
3714
|
-
cssSelectorReplacement:
|
|
3715
|
-
rem2rpx:
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3861
|
+
cssPreflight: cssOptions.cssPreflight,
|
|
3862
|
+
cssPreflightRange: cssOptions.cssPreflightRange,
|
|
3863
|
+
cssChildCombinatorReplaceValue: cssOptions.cssChildCombinatorReplaceValue,
|
|
3864
|
+
cssSelectorReplacement: cssOptions.cssSelectorReplacement,
|
|
3865
|
+
rem2rpx: cssOptions.rem2rpx,
|
|
3866
|
+
...hasCssOptions ? { cssOptions } : {},
|
|
3867
|
+
cssRemoveProperty: cssOptions.cssRemoveProperty,
|
|
3868
|
+
cssRemoveHoverPseudoClass: cssOptions.cssRemoveHoverPseudoClass,
|
|
3869
|
+
tailwindcssV4GradientFallback: cssOptions.tailwindcssV4GradientFallback,
|
|
3870
|
+
cssPresetEnv: cssOptions.cssPresetEnv,
|
|
3871
|
+
atRules: cssOptions.atRules,
|
|
3872
|
+
autoprefixer: cssOptions.autoprefixer,
|
|
3873
|
+
cssCalc: cssOptions.cssCalc,
|
|
3721
3874
|
uniAppX: resolvedUniAppXOptions.enabled,
|
|
3722
|
-
platform:
|
|
3723
|
-
px2rpx:
|
|
3724
|
-
unitsToPx:
|
|
3725
|
-
unitConversion:
|
|
3875
|
+
platform: cssOptions.platform,
|
|
3876
|
+
px2rpx: cssOptions.px2rpx,
|
|
3877
|
+
unitsToPx: cssOptions.unitsToPx,
|
|
3878
|
+
unitConversion: cssOptions.unitConversion
|
|
3726
3879
|
};
|
|
3727
3880
|
}
|
|
3728
3881
|
//#endregion
|
|
@@ -3732,7 +3885,8 @@ function finalizeMiniProgramGeneratorCss(css, target, majorVersion, cssPreflight
|
|
|
3732
3885
|
return (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(css, {
|
|
3733
3886
|
cssPreflight: majorVersion === 4 && options.injectPreflight !== false ? cssPreflight : void 0,
|
|
3734
3887
|
isTailwindcssV4: majorVersion === 4,
|
|
3735
|
-
preservePseudoContentInit: majorVersion === 3
|
|
3888
|
+
preservePseudoContentInit: majorVersion === 3,
|
|
3889
|
+
tailwindcssV4GradientFallback: options.styleOptions?.cssOptions?.tailwindcssV4GradientFallback ?? options.styleOptions?.tailwindcssV4GradientFallback
|
|
3736
3890
|
});
|
|
3737
3891
|
}
|
|
3738
3892
|
function shouldInjectMiniProgramPreflightForGeneratorCss(opts, options) {
|
|
@@ -3741,12 +3895,24 @@ function shouldInjectMiniProgramPreflightForGeneratorCss(opts, options) {
|
|
|
3741
3895
|
return isUniAppXEnabled(opts.uniAppX) && Boolean(options.localImports?.trim());
|
|
3742
3896
|
}
|
|
3743
3897
|
function mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtime, options) {
|
|
3744
|
-
if (options.
|
|
3745
|
-
|
|
3898
|
+
if (options.majorVersion === 3 && !options.isolateCssSource) return new Set([
|
|
3899
|
+
...scopedRuntime,
|
|
3900
|
+
...runtime,
|
|
3901
|
+
...options.currentCssCandidates ?? []
|
|
3902
|
+
]);
|
|
3903
|
+
if (options.isolateCssSource) {
|
|
3904
|
+
if (options.matchedCssSourceFile) return new Set([...scopedRuntime, ...options.currentCssCandidates ?? []]);
|
|
3905
|
+
return new Set([...scopedRuntime, ...options.currentCssCandidates ?? []]);
|
|
3906
|
+
}
|
|
3907
|
+
if (runtime.size === 0 || !options.cssHandlerOptions.isMainChunk) return scopedRuntime;
|
|
3746
3908
|
return new Set([...scopedRuntime, ...runtime]);
|
|
3747
3909
|
}
|
|
3748
|
-
function shouldIsolateScopedCssSource(source, sourceEntries) {
|
|
3749
|
-
|
|
3910
|
+
function shouldIsolateScopedCssSource(majorVersion, source, sourceEntries, options) {
|
|
3911
|
+
if (options.target !== "weapp") return false;
|
|
3912
|
+
if (source.__weappTailwindcssMeta?.isolateCssSource) return true;
|
|
3913
|
+
if (source.__weappTailwindcssMeta?.matchedCssSourceFile && (sourceEntries?.length ?? 0) > 0) return true;
|
|
3914
|
+
if (sourceEntries?.length === 0) return false;
|
|
3915
|
+
return (majorVersion === 3 || majorVersion === 4) && sourceEntries !== void 0 && options.cssHandlerOptions?.isMainChunk !== true;
|
|
3750
3916
|
}
|
|
3751
3917
|
function shouldIsolateCurrentTailwindV4CssCandidates(majorVersion, cssHandlerOptions, options) {
|
|
3752
3918
|
return majorVersion === 4 && !cssHandlerOptions.isMainChunk && hasTailwindApplyDirective(options.rawSource) && !hasTailwindRootDirectives(options.rawSource) && !options.hasGeneratedCss && !options.hasGeneratedMarkers;
|
|
@@ -3764,13 +3930,13 @@ function isEmptyCssSourceOrderParts(parts) {
|
|
|
3764
3930
|
return parts.before.trim().length === 0 && parts.after.trim().length === 0;
|
|
3765
3931
|
}
|
|
3766
3932
|
function resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorStyleOptions) {
|
|
3933
|
+
const resolvedStyleOptions = resolveStyleOptionsFromContext(opts);
|
|
3767
3934
|
const preflightStyleOptions = {
|
|
3768
|
-
cssPreflight:
|
|
3769
|
-
cssPreflightRange:
|
|
3935
|
+
cssPreflight: resolvedStyleOptions.cssPreflight,
|
|
3936
|
+
cssPreflightRange: resolvedStyleOptions.cssPreflightRange
|
|
3770
3937
|
};
|
|
3771
3938
|
return {
|
|
3772
|
-
...
|
|
3773
|
-
atRules: opts.atRules,
|
|
3939
|
+
...resolvedStyleOptions,
|
|
3774
3940
|
uniAppXCssTarget: opts.uniAppXCssTarget,
|
|
3775
3941
|
uniAppXUnsupported: opts.uniAppXUnsupported,
|
|
3776
3942
|
...cssHandlerOptions,
|
|
@@ -3794,9 +3960,9 @@ function splitRawSourceByGeneratedCssOrder(rawSource, rawTailwindCss) {
|
|
|
3794
3960
|
if (exactParts) return exactParts;
|
|
3795
3961
|
return splitTailwindGeneratedCssByBanner(rawSource);
|
|
3796
3962
|
}
|
|
3797
|
-
function shouldUseGeneratorForCurrentCss(
|
|
3963
|
+
function shouldUseGeneratorForCurrentCss(_majorVersion, cssHandlerOptions, options) {
|
|
3798
3964
|
const hasApplyDirectives = hasTailwindApplyDirective(options.rawSource);
|
|
3799
|
-
return options.hasGeneratedCss || options.hasGeneratedMarkers || options.hasSourceDirectives ||
|
|
3965
|
+
return options.hasGeneratedCss || options.hasGeneratedMarkers || options.hasSourceDirectives || hasApplyDirectives || cssHandlerOptions.isMainChunk;
|
|
3800
3966
|
}
|
|
3801
3967
|
function createRuntimeWithCurrentCssCandidates(runtime, currentCssCandidates, isolateCurrentCssCandidates) {
|
|
3802
3968
|
return isolateCurrentCssCandidates ? new Set(currentCssCandidates) : currentCssCandidates.length > 0 ? new Set([...runtime, ...currentCssCandidates]) : runtime;
|
|
@@ -4313,98 +4479,53 @@ function extractStyleDirectiveSources(source) {
|
|
|
4313
4479
|
let match = SFC_STYLE_BLOCK_RE.exec(source);
|
|
4314
4480
|
while (match !== null) {
|
|
4315
4481
|
const styleSource = match[1] ?? "";
|
|
4316
|
-
if (hasTailwindSourceDirectives(styleSource)) styleSources.push(styleSource);
|
|
4482
|
+
if (hasTailwindSourceDirectives(styleSource, { importFallback: true })) styleSources.push(styleSource);
|
|
4317
4483
|
match = SFC_STYLE_BLOCK_RE.exec(source);
|
|
4318
4484
|
}
|
|
4319
4485
|
if (styleSources.length > 0) return styleSources;
|
|
4320
|
-
return hasTailwindSourceDirectives(source) ? [source] : [];
|
|
4486
|
+
return hasTailwindSourceDirectives(source, { importFallback: true }) ? [source] : [];
|
|
4321
4487
|
}
|
|
4322
4488
|
function resolveSourceSideCssEntrySource(file, sourceOptions, resolveOptions = {}) {
|
|
4323
|
-
for (const sourceFile of createSourceStylePathCandidates(file, sourceOptions)) {
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
};
|
|
4333
|
-
}
|
|
4334
|
-
} catch {
|
|
4335
|
-
continue;
|
|
4489
|
+
for (const sourceFile of createSourceStylePathCandidates(file, sourceOptions)) try {
|
|
4490
|
+
const source = sourceOptions.sourceFile && node_path.default.resolve(sourceOptions.sourceFile) === node_path.default.resolve(sourceFile) && typeof sourceOptions.sourceCss === "string" ? sourceOptions.sourceCss : (0, node_fs.existsSync)(sourceFile) ? (0, node_fs.readFileSync)(sourceFile, "utf8") : void 0;
|
|
4491
|
+
if (source === void 0) continue;
|
|
4492
|
+
for (const styleSource of extractStyleDirectiveSources(source)) {
|
|
4493
|
+
const cssEntrySource = resolveCssEntrySource(styleSource, node_path.default.dirname(sourceFile), resolveOptions);
|
|
4494
|
+
if (cssEntrySource) return {
|
|
4495
|
+
...cssEntrySource,
|
|
4496
|
+
file: sourceFile
|
|
4497
|
+
};
|
|
4336
4498
|
}
|
|
4499
|
+
} catch {
|
|
4500
|
+
continue;
|
|
4337
4501
|
}
|
|
4338
4502
|
}
|
|
4339
4503
|
//#endregion
|
|
4340
|
-
//#region src/bundlers/shared/generator-css/source-resolver.ts
|
|
4341
|
-
function
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
}
|
|
4350
|
-
function resolveCssHandlerSourceOptions(cssHandlerOptions) {
|
|
4351
|
-
return cssHandlerOptions.sourceOptions;
|
|
4352
|
-
}
|
|
4353
|
-
function createCssEntrySources(cssEntries) {
|
|
4354
|
-
return cssEntries?.filter((entry) => typeof entry === "string" && entry.length > 0 && node_path.default.isAbsolute(entry)).map((entry) => ({ file: node_path.default.resolve(entry) }));
|
|
4355
|
-
}
|
|
4356
|
-
function mergeCssSources(cssSources, cssEntrySources) {
|
|
4357
|
-
const merged = [];
|
|
4358
|
-
const seenFiles = /* @__PURE__ */ new Set();
|
|
4359
|
-
const addSource = (cssSource) => {
|
|
4360
|
-
const file = typeof cssSource.file === "string" && cssSource.file.length > 0 ? node_path.default.resolve(cssSource.file) : void 0;
|
|
4361
|
-
if (file) {
|
|
4362
|
-
if (seenFiles.has(file)) return;
|
|
4363
|
-
seenFiles.add(file);
|
|
4364
|
-
}
|
|
4365
|
-
merged.push(cssSource);
|
|
4366
|
-
};
|
|
4367
|
-
for (const cssSource of cssSources ?? []) addSource(cssSource);
|
|
4368
|
-
for (const cssSource of cssEntrySources ?? []) addSource(cssSource);
|
|
4369
|
-
return merged.length > 0 ? merged : void 0;
|
|
4370
|
-
}
|
|
4371
|
-
function createSingleTailwindV4SourceOptions(sourceOptions, options) {
|
|
4372
|
-
return omitUndefined({
|
|
4373
|
-
projectRoot: sourceOptions.projectRoot,
|
|
4374
|
-
baseFallbacks: sourceOptions.baseFallbacks,
|
|
4375
|
-
packageName: sourceOptions.packageName,
|
|
4376
|
-
base: options.base,
|
|
4377
|
-
css: options.css
|
|
4378
|
-
});
|
|
4504
|
+
//#region src/bundlers/shared/generator-css/source-resolver/apply-reference.ts
|
|
4505
|
+
function createTailwindV4ApplyReferenceSource(css, sourceOptions) {
|
|
4506
|
+
if (!hasTailwindApplyDirective(css) || hasTailwindRootDirectives(css)) return css;
|
|
4507
|
+
const utilities = collectTailwindApplyUtilities(css);
|
|
4508
|
+
return [
|
|
4509
|
+
`@import "${sourceOptions.packageName ?? "tailwindcss"}" source(none);`,
|
|
4510
|
+
utilities.length > 0 ? `@source inline(${JSON.stringify(utilities.join(" "))});` : void 0,
|
|
4511
|
+
css
|
|
4512
|
+
].filter(Boolean).join("\n");
|
|
4379
4513
|
}
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
const
|
|
4388
|
-
|
|
4389
|
-
|
|
4390
|
-
...sourceOptions,
|
|
4391
|
-
sourceFile: sourceOptions.sourceFile ?? cssEntry
|
|
4392
|
-
});
|
|
4393
|
-
return withGeneratorSourceMetadata(await resolveTailwindV4Source({
|
|
4394
|
-
...omitUndefined(singleEntrySourceOptions),
|
|
4395
|
-
base,
|
|
4396
|
-
css: normalizeConfigDirective(css, config),
|
|
4397
|
-
cssEntries: [cssEntry]
|
|
4398
|
-
}), {
|
|
4399
|
-
matchedCssSourceFile: cssEntry,
|
|
4400
|
-
sourceBase: base,
|
|
4401
|
-
sourceCss: css
|
|
4514
|
+
function collectTailwindApplyUtilities(css) {
|
|
4515
|
+
let root;
|
|
4516
|
+
try {
|
|
4517
|
+
root = _weapp_tailwindcss_postcss.postcss.parse(css);
|
|
4518
|
+
} catch {
|
|
4519
|
+
return [];
|
|
4520
|
+
}
|
|
4521
|
+
const utilities = /* @__PURE__ */ new Set();
|
|
4522
|
+
root.walkAtRules("apply", (rule) => {
|
|
4523
|
+
for (const utility of (0, tailwindcss_patch.splitCandidateTokens)(rule.params)) utilities.add(utility);
|
|
4402
4524
|
});
|
|
4525
|
+
return [...utilities].sort();
|
|
4403
4526
|
}
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
return node_path.default.dirname(node_path.default.resolve(normalized));
|
|
4407
|
-
}
|
|
4527
|
+
//#endregion
|
|
4528
|
+
//#region src/bundlers/shared/generator-css/source-resolver/config.ts
|
|
4408
4529
|
function resolveExistingConfigPath(config, configRequest, file, sourceOptions) {
|
|
4409
4530
|
if (config && (0, node_fs.existsSync)(config)) return config;
|
|
4410
4531
|
if (!configRequest || node_path.default.isAbsolute(configRequest)) return sourceOptions.config;
|
|
@@ -4431,20 +4552,8 @@ function resolveExistingConfigPath(config, configRequest, file, sourceOptions) {
|
|
|
4431
4552
|
for (const candidate of configCandidates) if ((0, node_fs.existsSync)(candidate)) return candidate;
|
|
4432
4553
|
return sourceOptions.config;
|
|
4433
4554
|
}
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
if (!from || !node_path.default.isAbsolute(from)) return node_path.default.isAbsolute(file) || Boolean(sourceOptions?.sourceFile) || Boolean(sourceOptions?.cssSources?.length);
|
|
4437
|
-
return true;
|
|
4438
|
-
}
|
|
4439
|
-
function shouldResolveSourceSideCssEntry(rawSource) {
|
|
4440
|
-
return rawSource.includes("@apply") || hasTailwindRootDirectives(rawSource, { importFallback: true }) || hasTailwindSourceDirectives(rawSource, { importFallback: true }) || hasTailwindGeneratedCss(rawSource) || hasTailwindGeneratedCssMarkers(rawSource);
|
|
4441
|
-
}
|
|
4442
|
-
function shouldPreferTailwindV3SourceSideEntry(rawSource, sourceSideEntrySource) {
|
|
4443
|
-
return Boolean(sourceSideEntrySource) && !hasTailwindSourceDirectives(rawSource, { importFallback: true });
|
|
4444
|
-
}
|
|
4445
|
-
function shouldPreferResolvedSourceSideEntry(cssEntrySource, sourceSideEntrySource) {
|
|
4446
|
-
return Boolean(sourceSideEntrySource?.config) && Boolean(cssEntrySource?.configRequest) && (!cssEntrySource?.config || !(0, node_fs.existsSync)(cssEntrySource.config));
|
|
4447
|
-
}
|
|
4555
|
+
//#endregion
|
|
4556
|
+
//#region src/bundlers/shared/generator-css/source-resolver/matching.ts
|
|
4448
4557
|
function normalizeCssSourceForCompare(css) {
|
|
4449
4558
|
return stripGeneratorPlaceholderMarkers(stripTailwindBanners(css)).trim();
|
|
4450
4559
|
}
|
|
@@ -4495,6 +4604,107 @@ function scoreTailwindV4CssSourceFileMatch(file, cssSourceFile, sourceOptions) {
|
|
|
4495
4604
|
else if (sourceBase.endsWith(`/${outputBase}`)) bestScore = Math.max(bestScore, 1e3 + outputBase.length);
|
|
4496
4605
|
return bestScore;
|
|
4497
4606
|
}
|
|
4607
|
+
//#endregion
|
|
4608
|
+
//#region src/bundlers/shared/generator-css/source-resolver/metadata.ts
|
|
4609
|
+
function withGeneratorSourceMetadata(source, metadata) {
|
|
4610
|
+
return {
|
|
4611
|
+
...source,
|
|
4612
|
+
__weappTailwindcssMeta: metadata
|
|
4613
|
+
};
|
|
4614
|
+
}
|
|
4615
|
+
function withMatchedSourceSideMetadata(source, resolvedEntrySource) {
|
|
4616
|
+
return resolvedEntrySource.file ? withGeneratorSourceMetadata(source, {
|
|
4617
|
+
isolateCssSource: true,
|
|
4618
|
+
matchedCssSourceFile: resolvedEntrySource.file,
|
|
4619
|
+
sourceBase: resolvedEntrySource.base,
|
|
4620
|
+
sourceCss: resolvedEntrySource.css
|
|
4621
|
+
}) : source;
|
|
4622
|
+
}
|
|
4623
|
+
//#endregion
|
|
4624
|
+
//#region src/bundlers/shared/generator-css/source-resolver/postcss-source.ts
|
|
4625
|
+
function resolvePostcssFromOption(cssHandlerOptions) {
|
|
4626
|
+
const from = cssHandlerOptions.postcssOptions?.options?.from;
|
|
4627
|
+
return typeof from === "string" && from.length > 0 ? from : void 0;
|
|
4628
|
+
}
|
|
4629
|
+
function resolvePostcssSourceFile(cssHandlerOptions) {
|
|
4630
|
+
const from = resolvePostcssFromOption(cssHandlerOptions);
|
|
4631
|
+
if (!from || !node_path.default.isAbsolute(from)) return;
|
|
4632
|
+
return from.replace(/[?#].*$/, "");
|
|
4633
|
+
}
|
|
4634
|
+
function resolveCssHandlerSourceOptions(cssHandlerOptions) {
|
|
4635
|
+
return cssHandlerOptions.sourceOptions;
|
|
4636
|
+
}
|
|
4637
|
+
function resolveCssSourceBase(file, cssHandlerOptions) {
|
|
4638
|
+
const normalized = (resolvePostcssFromOption(cssHandlerOptions) ?? file).replace(/[?#].*$/, "");
|
|
4639
|
+
return node_path.default.dirname(node_path.default.resolve(normalized));
|
|
4640
|
+
}
|
|
4641
|
+
//#endregion
|
|
4642
|
+
//#region src/bundlers/shared/generator-css/source-resolver.ts
|
|
4643
|
+
function createCssEntrySources(cssEntries) {
|
|
4644
|
+
return cssEntries?.filter((entry) => typeof entry === "string" && entry.length > 0 && node_path.default.isAbsolute(entry)).map((entry) => ({ file: node_path.default.resolve(entry) }));
|
|
4645
|
+
}
|
|
4646
|
+
function mergeCssSources(cssSources, cssEntrySources) {
|
|
4647
|
+
const merged = [];
|
|
4648
|
+
const seenFiles = /* @__PURE__ */ new Set();
|
|
4649
|
+
const addSource = (cssSource) => {
|
|
4650
|
+
const file = typeof cssSource.file === "string" && cssSource.file.length > 0 ? node_path.default.resolve(cssSource.file) : void 0;
|
|
4651
|
+
if (file) {
|
|
4652
|
+
if (seenFiles.has(file)) return;
|
|
4653
|
+
seenFiles.add(file);
|
|
4654
|
+
}
|
|
4655
|
+
merged.push(cssSource);
|
|
4656
|
+
};
|
|
4657
|
+
for (const cssSource of cssSources ?? []) addSource(cssSource);
|
|
4658
|
+
for (const cssSource of cssEntrySources ?? []) addSource(cssSource);
|
|
4659
|
+
return merged.length > 0 ? merged : void 0;
|
|
4660
|
+
}
|
|
4661
|
+
function createSingleTailwindV4SourceOptions(sourceOptions, options) {
|
|
4662
|
+
return omitUndefined({
|
|
4663
|
+
projectRoot: sourceOptions.projectRoot,
|
|
4664
|
+
baseFallbacks: sourceOptions.baseFallbacks,
|
|
4665
|
+
packageName: sourceOptions.packageName,
|
|
4666
|
+
base: options.base,
|
|
4667
|
+
css: options.css
|
|
4668
|
+
});
|
|
4669
|
+
}
|
|
4670
|
+
async function resolveTailwindV4CssEntrySource(cssEntry, sourceOptions) {
|
|
4671
|
+
const { cssEntries: _cssEntries, cssSources: _cssSources, ...singleEntrySourceOptions } = sourceOptions;
|
|
4672
|
+
if (!(0, node_fs.existsSync)(cssEntry)) return resolveTailwindV4Source({
|
|
4673
|
+
...omitUndefined(singleEntrySourceOptions),
|
|
4674
|
+
cssEntries: [cssEntry]
|
|
4675
|
+
});
|
|
4676
|
+
const css = (0, node_fs.readFileSync)(cssEntry, "utf8");
|
|
4677
|
+
const base = node_path.default.dirname(node_path.default.resolve(cssEntry));
|
|
4678
|
+
const entrySource = resolveCssEntrySource(css, base, { removeConfig: false });
|
|
4679
|
+
const config = resolveExistingConfigPath(entrySource?.config, entrySource?.configRequest, cssEntry, {
|
|
4680
|
+
...sourceOptions,
|
|
4681
|
+
sourceFile: sourceOptions.sourceFile ?? cssEntry
|
|
4682
|
+
});
|
|
4683
|
+
return withGeneratorSourceMetadata(await resolveTailwindV4Source({
|
|
4684
|
+
...omitUndefined(singleEntrySourceOptions),
|
|
4685
|
+
base,
|
|
4686
|
+
css: normalizeConfigDirective(css, config),
|
|
4687
|
+
cssEntries: [cssEntry]
|
|
4688
|
+
}), {
|
|
4689
|
+
matchedCssSourceFile: cssEntry,
|
|
4690
|
+
sourceBase: base,
|
|
4691
|
+
sourceCss: css
|
|
4692
|
+
});
|
|
4693
|
+
}
|
|
4694
|
+
function canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) {
|
|
4695
|
+
const from = resolvePostcssFromOption(cssHandlerOptions);
|
|
4696
|
+
if (!from || !node_path.default.isAbsolute(from)) return node_path.default.isAbsolute(file) || Boolean(sourceOptions?.sourceFile) || Boolean(sourceOptions?.cssSources?.length);
|
|
4697
|
+
return true;
|
|
4698
|
+
}
|
|
4699
|
+
function shouldResolveSourceSideCssEntry(rawSource) {
|
|
4700
|
+
return rawSource.includes("@apply") || hasTailwindRootDirectives(rawSource, { importFallback: true }) || hasTailwindSourceDirectives(rawSource, { importFallback: true }) || hasTailwindGeneratedCss(rawSource) || hasTailwindGeneratedCssMarkers(rawSource);
|
|
4701
|
+
}
|
|
4702
|
+
function shouldPreferTailwindV3SourceSideEntry(rawSource, sourceSideEntrySource) {
|
|
4703
|
+
return Boolean(sourceSideEntrySource) && !hasTailwindSourceDirectives(rawSource, { importFallback: true });
|
|
4704
|
+
}
|
|
4705
|
+
function shouldPreferResolvedSourceSideEntry(cssEntrySource, sourceSideEntrySource) {
|
|
4706
|
+
return Boolean(sourceSideEntrySource?.config) && (Boolean(cssEntrySource?.configRequest) || !cssEntrySource?.config) && (!cssEntrySource?.config || !(0, node_fs.existsSync)(cssEntrySource.config));
|
|
4707
|
+
}
|
|
4498
4708
|
function resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) {
|
|
4499
4709
|
const cssEntries = sourceOptions.cssEntries;
|
|
4500
4710
|
if (!cssEntries?.length) return;
|
|
@@ -4672,12 +4882,6 @@ async function resolveTailwindV4SourceSideEntrySource(resolvedEntrySource, sourc
|
|
|
4672
4882
|
css
|
|
4673
4883
|
})), resolvedEntrySource);
|
|
4674
4884
|
}
|
|
4675
|
-
function withGeneratorSourceMetadata(source, metadata) {
|
|
4676
|
-
return {
|
|
4677
|
-
...source,
|
|
4678
|
-
__weappTailwindcssMeta: metadata
|
|
4679
|
-
};
|
|
4680
|
-
}
|
|
4681
4885
|
function resolveTailwindV3SourceEntries(source) {
|
|
4682
4886
|
if (!("version" in source) || source.version !== 3) return;
|
|
4683
4887
|
const entries = normalizeLegacyContentEntries(source.configObject?.content, source.cwd, { relativeBase: source.config ? node_path.default.dirname(source.config) : source.cwd });
|
|
@@ -4687,35 +4891,6 @@ function withTailwindV3SourceMetadata(source) {
|
|
|
4687
4891
|
const sourceEntries = resolveTailwindV3SourceEntries(source);
|
|
4688
4892
|
return sourceEntries ? withGeneratorSourceMetadata(source, { sourceEntries }) : source;
|
|
4689
4893
|
}
|
|
4690
|
-
function withMatchedSourceSideMetadata(source, resolvedEntrySource) {
|
|
4691
|
-
return resolvedEntrySource.file ? withGeneratorSourceMetadata(source, {
|
|
4692
|
-
matchedCssSourceFile: resolvedEntrySource.file,
|
|
4693
|
-
sourceBase: resolvedEntrySource.base,
|
|
4694
|
-
sourceCss: resolvedEntrySource.css
|
|
4695
|
-
}) : source;
|
|
4696
|
-
}
|
|
4697
|
-
function createTailwindV4ApplyReferenceSource(css, sourceOptions) {
|
|
4698
|
-
if (!hasTailwindApplyDirective(css) || hasTailwindRootDirectives(css)) return css;
|
|
4699
|
-
const utilities = collectTailwindApplyUtilities(css);
|
|
4700
|
-
return [
|
|
4701
|
-
`@import "${sourceOptions.packageName ?? "tailwindcss"}" source(none);`,
|
|
4702
|
-
utilities.length > 0 ? `@source inline(${JSON.stringify(utilities.join(" "))});` : void 0,
|
|
4703
|
-
css
|
|
4704
|
-
].filter(Boolean).join("\n");
|
|
4705
|
-
}
|
|
4706
|
-
function collectTailwindApplyUtilities(css) {
|
|
4707
|
-
let root;
|
|
4708
|
-
try {
|
|
4709
|
-
root = _weapp_tailwindcss_postcss.postcss.parse(css);
|
|
4710
|
-
} catch {
|
|
4711
|
-
return [];
|
|
4712
|
-
}
|
|
4713
|
-
const utilities = /* @__PURE__ */ new Set();
|
|
4714
|
-
root.walkAtRules("apply", (rule) => {
|
|
4715
|
-
for (const utility of (0, tailwindcss_patch.splitCandidateTokens)(rule.params)) utilities.add(utility);
|
|
4716
|
-
});
|
|
4717
|
-
return [...utilities].sort();
|
|
4718
|
-
}
|
|
4719
4894
|
async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions) {
|
|
4720
4895
|
const base = resolveCssSourceBase(file, cssHandlerOptions);
|
|
4721
4896
|
const cssEntrySource = resolveCssEntrySource(rawSource, base, {
|
|
@@ -4748,15 +4923,19 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
|
|
|
4748
4923
|
css: normalizeTailwindV3CssEntrySource(resolvedEntrySource.css),
|
|
4749
4924
|
...config ? { config } : {}
|
|
4750
4925
|
}));
|
|
4926
|
+
const cssEntrySourceEntries = await resolveTailwindConfigEntriesFromCssCached(rawSource, resolvedEntrySource.base);
|
|
4927
|
+
const sourceMetadata = sourceWithMetadata.__weappTailwindcssMeta;
|
|
4928
|
+
const matchedSourceFile = resolvedEntrySource.file ?? sourceSideEntrySource?.file;
|
|
4751
4929
|
return withGeneratorSourceMetadata(sourceWithMetadata, {
|
|
4752
|
-
...
|
|
4753
|
-
matchedCssSourceFile:
|
|
4930
|
+
...sourceMetadata,
|
|
4931
|
+
matchedCssSourceFile: matchedSourceFile,
|
|
4932
|
+
sourceEntries: cssEntrySourceEntries?.entries ?? sourceMetadata?.sourceEntries
|
|
4754
4933
|
});
|
|
4755
4934
|
}
|
|
4756
4935
|
const sourceOptions = tryResolveTailwindV4SourceOptions(runtimeState);
|
|
4757
4936
|
const resolvedSourceOptions = sourceOptions ? omitUndefined({
|
|
4758
4937
|
...sourceOptions,
|
|
4759
|
-
sourceFile: resolvePostcssSourceFile(cssHandlerOptions),
|
|
4938
|
+
sourceFile: sourceOptions.sourceFile ?? resolvePostcssSourceFile(cssHandlerOptions),
|
|
4760
4939
|
...resolveCssHandlerSourceOptions(cssHandlerOptions),
|
|
4761
4940
|
cssEntries: selectionOptions?.cssEntries ?? sourceOptions.cssEntries,
|
|
4762
4941
|
cssSources: mergeCssSources(sourceOptions.cssSources, sourceOptions.cssSources?.length ? void 0 : createCssEntrySources(selectionOptions?.cssEntries ?? sourceOptions.cssEntries))
|
|
@@ -4770,17 +4949,18 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
|
|
|
4770
4949
|
}));
|
|
4771
4950
|
}
|
|
4772
4951
|
const shouldPreferSourceSideEntry = shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder")) && (sourceOptions?.cssEntries?.length ?? 0) <= 1;
|
|
4773
|
-
const sourceSideEntrySource = normalizedSourceOptions && shouldPreferSourceSideEntry && canResolveSourceSideCssEntry(file, cssHandlerOptions, normalizedSourceOptions) ? resolveSourceSideCssEntrySource(file, normalizedSourceOptions, { removeConfig: false }) : void 0;
|
|
4952
|
+
const sourceSideEntrySource = normalizedSourceOptions && (shouldPreferSourceSideEntry || normalizedSourceOptions.sourceFile !== void 0) && canResolveSourceSideCssEntry(file, cssHandlerOptions, normalizedSourceOptions) ? resolveSourceSideCssEntrySource(file, normalizedSourceOptions, { removeConfig: false }) : void 0;
|
|
4774
4953
|
const matchedCssEntrySource = normalizedSourceOptions ? await resolveMatchingTailwindV4CssEntry(rawSource, file, normalizedSourceOptions) : void 0;
|
|
4775
4954
|
const matchedCssSource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, normalizedSourceOptions) : void 0;
|
|
4776
4955
|
const candidateMatchedCssSource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, normalizedSourceOptions, selectionOptions) : void 0;
|
|
4777
|
-
const
|
|
4956
|
+
const singleConfiguredCssSource = normalizedSourceOptions?.cssSources?.length === 1 ? await resolveSingleTailwindV4CssSource(normalizedSourceOptions.cssSources[0], normalizedSourceOptions, { matched: true }) : void 0;
|
|
4957
|
+
const configuredCssSource = normalizedSourceOptions && hasConfiguredTailwindV4CssSource(normalizedSourceOptions) && hasTailwindGeneratedCssMarkers(rawSource) ? matchedCssSource ?? candidateMatchedCssSource ?? singleConfiguredCssSource ?? await resolveTailwindV4Source(normalizedSourceOptions) : void 0;
|
|
4778
4958
|
if (configuredCssSource) return generatorOptions?.config ? {
|
|
4779
4959
|
...configuredCssSource,
|
|
4780
4960
|
css: prependConfigDirective(configuredCssSource.css, generatorOptions.config)
|
|
4781
4961
|
} : configuredCssSource;
|
|
4782
4962
|
const mainCssEntrySource = normalizedSourceOptions && cssHandlerOptions.isMainChunk && normalizedSourceOptions.cssEntries?.length === 1 ? await resolveTailwindV4CssEntrySource(normalizedSourceOptions.cssEntries[0], normalizedSourceOptions) : void 0;
|
|
4783
|
-
const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource ?? mainCssEntrySource;
|
|
4963
|
+
const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource ?? mainCssEntrySource ?? singleConfiguredCssSource;
|
|
4784
4964
|
if (preferredCssEntrySource) return generatorOptions?.config ? {
|
|
4785
4965
|
...preferredCssEntrySource,
|
|
4786
4966
|
css: prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
|
|
@@ -4820,7 +5000,7 @@ async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, fi
|
|
|
4820
5000
|
sourceFile: resolvePostcssSourceFile(cssHandlerOptions),
|
|
4821
5001
|
...resolveCssHandlerSourceOptions(cssHandlerOptions),
|
|
4822
5002
|
cssEntries,
|
|
4823
|
-
cssSources: mergeCssSources(sourceOptionsFromPatcher.cssSources, sourceOptionsFromPatcher.cssSources?.length ? void 0 : createCssEntrySources(cssEntries))
|
|
5003
|
+
cssSources: mergeCssSources(mergeCssSources(sourceOptionsFromPatcher.cssSources, selectionOptions?.cssSources), sourceOptionsFromPatcher.cssSources?.length || selectionOptions?.cssSources?.length ? void 0 : createCssEntrySources(cssEntries))
|
|
4824
5004
|
});
|
|
4825
5005
|
} catch {
|
|
4826
5006
|
const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
|
|
@@ -4831,7 +5011,7 @@ async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, fi
|
|
|
4831
5011
|
...matchedCssEntrySource,
|
|
4832
5012
|
css: prependConfigDirective(matchedCssEntrySource.css, generatorOptions.config)
|
|
4833
5013
|
} : matchedCssEntrySource];
|
|
4834
|
-
const sourceSideCssSource = await resolveTailwindV4SourceSideEntrySource(
|
|
5014
|
+
const sourceSideCssSource = await resolveTailwindV4SourceSideEntrySource(canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) ? resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: false }) : void 0, sourceOptions, generatorOptions, file);
|
|
4835
5015
|
if (sourceSideCssSource) return [sourceSideCssSource];
|
|
4836
5016
|
const matchedCssSource = await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions);
|
|
4837
5017
|
const candidateMatchedCssSource = await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, sourceOptions, selectionOptions);
|
|
@@ -4866,6 +5046,10 @@ async function resolveGeneratorSourceEntries(source, runtimeState) {
|
|
|
4866
5046
|
if (sourceMetadata?.sourceEntries) return sourceMetadata.sourceEntries;
|
|
4867
5047
|
if (!("css" in source) || !("base" in source) || !("baseFallbacks" in source)) return;
|
|
4868
5048
|
const resolved = await resolveTailwindV4EntriesFromCss(sourceMetadata?.sourceCss ?? source.css, sourceMetadata?.sourceBase ?? source.base);
|
|
5049
|
+
if (resolved?.entries.length === 0 && !resolved.inlineCandidates.included.size && !resolved.inlineCandidates.excluded.size && !resolved.dependencies.length) {
|
|
5050
|
+
if (sourceMetadata?.matchedCssSourceFile) return [];
|
|
5051
|
+
return;
|
|
5052
|
+
}
|
|
4869
5053
|
if (resolved?.entries.length || !resolved?.explicit && !sourceMetadata?.matchedCssSourceFile || !runtimeState) return resolved?.entries;
|
|
4870
5054
|
const matchingCssSource = tryResolveTailwindV4SourceOptions(runtimeState)?.cssSources?.find((cssSource) => {
|
|
4871
5055
|
if (sourceMetadata?.matchedCssSourceFile && typeof cssSource.file === "string" && node_path.default.resolve(cssSource.file) === node_path.default.resolve(sourceMetadata.matchedCssSourceFile)) return true;
|
|
@@ -5289,6 +5473,16 @@ function isCommentOnlyCss(source) {
|
|
|
5289
5473
|
return false;
|
|
5290
5474
|
}
|
|
5291
5475
|
}
|
|
5476
|
+
function unwrapMiniProgramCascadeLayers(source) {
|
|
5477
|
+
if (!source.includes("@layer")) return source;
|
|
5478
|
+
try {
|
|
5479
|
+
const root = _weapp_tailwindcss_postcss.postcss.parse(source);
|
|
5480
|
+
(0, _weapp_tailwindcss_postcss.removeUnsupportedCascadeLayers)(root);
|
|
5481
|
+
return root.toString();
|
|
5482
|
+
} catch {
|
|
5483
|
+
return source;
|
|
5484
|
+
}
|
|
5485
|
+
}
|
|
5292
5486
|
function stripTailwindSourceMediaFragments(source) {
|
|
5293
5487
|
let removedSourceMediaStart = false;
|
|
5294
5488
|
return source.split(/\r?\n/).filter((line) => {
|
|
@@ -5456,7 +5650,7 @@ async function transformGeneratorUserCss(source, options) {
|
|
|
5456
5650
|
if (source.trim().length === 0) return "";
|
|
5457
5651
|
const cleanedSource = removeTailwindSourceDirectives(removeTailwindV4GeneratorAtRules(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(source))), { importFallback: options.importFallback });
|
|
5458
5652
|
if (cleanedSource.trim().length === 0) return "";
|
|
5459
|
-
const userSource = stripUnmatchedTailwindSourceMediaCloseFragments(removeTailwindApplyAtRules(removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(options.generatorTarget === "weapp" ? (0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(cleanedSource) : cleanedSource)), { importFallback: options.importFallback })));
|
|
5653
|
+
const userSource = stripUnmatchedTailwindSourceMediaCloseFragments(removeTailwindApplyAtRules(removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(options.generatorTarget === "weapp" ? (0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(unwrapMiniProgramCascadeLayers(cleanedSource)) : cleanedSource)), { importFallback: options.importFallback })));
|
|
5460
5654
|
if (userSource.trim().length === 0) return "";
|
|
5461
5655
|
if (isCommentOnlyCss(userSource)) return userSource;
|
|
5462
5656
|
if (options.generatorTarget !== "weapp") return userSource;
|
|
@@ -5532,7 +5726,40 @@ function reorderMarkedUserLayerComponentsCss(css) {
|
|
|
5532
5726
|
return appendCss(appendCss(rest.slice(0, insertionIndex), layerCss), rest.slice(insertionIndex));
|
|
5533
5727
|
}
|
|
5534
5728
|
//#endregion
|
|
5729
|
+
//#region src/bundlers/shared/run-tasks.ts
|
|
5730
|
+
async function runWithConcurrency(factories, limit = Math.min(4, Math.max(1, factories.length))) {
|
|
5731
|
+
if (factories.length === 0) return [];
|
|
5732
|
+
const results = Array.from({ length: factories.length });
|
|
5733
|
+
const executing = /* @__PURE__ */ new Set();
|
|
5734
|
+
let cursor = 0;
|
|
5735
|
+
const effectiveLimit = Math.max(1, limit);
|
|
5736
|
+
const scheduleNext = () => {
|
|
5737
|
+
if (cursor >= factories.length) return;
|
|
5738
|
+
const currentIndex = cursor++;
|
|
5739
|
+
const factory = factories[currentIndex];
|
|
5740
|
+
if (!factory) return;
|
|
5741
|
+
const wrapped = Promise.resolve(factory()).then((value) => {
|
|
5742
|
+
results[currentIndex] = value;
|
|
5743
|
+
}).finally(() => {
|
|
5744
|
+
executing.delete(wrapped);
|
|
5745
|
+
});
|
|
5746
|
+
executing.add(wrapped);
|
|
5747
|
+
};
|
|
5748
|
+
while (cursor < factories.length && executing.size < effectiveLimit) scheduleNext();
|
|
5749
|
+
while (cursor < factories.length) {
|
|
5750
|
+
await Promise.race(executing);
|
|
5751
|
+
scheduleNext();
|
|
5752
|
+
}
|
|
5753
|
+
await Promise.all(executing);
|
|
5754
|
+
return results;
|
|
5755
|
+
}
|
|
5756
|
+
//#endregion
|
|
5535
5757
|
//#region src/bundlers/shared/generator-css.ts
|
|
5758
|
+
function resolveGeneratorSourceConcurrency() {
|
|
5759
|
+
const configured = Number.parseInt(node_process.default.env["WEAPP_TW_GENERATOR_SOURCE_CONCURRENCY"] ?? "", 10);
|
|
5760
|
+
if (Number.isFinite(configured) && configured > 0) return configured;
|
|
5761
|
+
return 1;
|
|
5762
|
+
}
|
|
5536
5763
|
async function generateCssByGenerator(options) {
|
|
5537
5764
|
const { opts, runtimeState, runtime, rawSource, file, cssHandlerOptions, cssUserHandlerOptions, getSourceCandidatesForEntries, styleHandler, debug } = options;
|
|
5538
5765
|
const generatorOptions = {
|
|
@@ -5573,26 +5800,32 @@ async function generateCssByGenerator(options) {
|
|
|
5573
5800
|
const runtimeWithCurrentCss = createRuntimeWithCurrentCssCandidates(runtime, currentCssCandidates, isolateCurrentCssCandidates);
|
|
5574
5801
|
const sources = await resolveGeneratorSources(majorVersion, runtimeState, generatorRawSource, file, cssHandlerOptions, generatorOptions, {
|
|
5575
5802
|
cssEntries: opts.cssEntries,
|
|
5803
|
+
cssSources: options.cssSources,
|
|
5576
5804
|
getSourceCandidatesForEntries,
|
|
5577
5805
|
runtime: runtimeWithCurrentCss
|
|
5578
5806
|
});
|
|
5579
5807
|
const generatorStyleOptions = resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorOptions.styleOptions);
|
|
5580
5808
|
const configuredContainerCompat = hasConfiguredContainerCompatSources(sources);
|
|
5581
|
-
const
|
|
5809
|
+
const sourceConcurrency = resolveGeneratorSourceConcurrency();
|
|
5810
|
+
const generated = mergeGeneratorResults((await runWithConcurrency(sources.map((source) => async () => {
|
|
5582
5811
|
const generator = createWeappTailwindcssGenerator(source);
|
|
5583
5812
|
const sourceEntries = getSourceCandidatesForEntries && (majorVersion === 3 || majorVersion === 4) ? await resolveGeneratorSourceEntries(source, runtimeState) : void 0;
|
|
5584
|
-
const scopedRuntime = sourceEntries ? getSourceCandidatesForEntries?.(sourceEntries) : void 0;
|
|
5585
|
-
const isolateCssSource = shouldIsolateScopedCssSource(source, sourceEntries
|
|
5813
|
+
const scopedRuntime = sourceEntries && sourceEntries.length > 0 ? getSourceCandidatesForEntries?.(sourceEntries) : void 0;
|
|
5814
|
+
const isolateCssSource = shouldIsolateScopedCssSource(majorVersion, source, sourceEntries, {
|
|
5815
|
+
cssHandlerOptions,
|
|
5816
|
+
target: generatorOptions.target
|
|
5817
|
+
});
|
|
5586
5818
|
const sourceMetadata = source.__weappTailwindcssMeta;
|
|
5587
5819
|
const matchedCssSourceFile = Boolean(sourceMetadata?.matchedCssSourceFile);
|
|
5588
5820
|
if (options.deferEmptyScopedCssSource && isolateCssSource && scopedRuntime?.size === 0 && currentCssCandidates.length === 0 && !cssHandlerOptions.isMainChunk) {
|
|
5589
5821
|
debug("defer empty scoped css source generation: %s", file);
|
|
5590
5822
|
return;
|
|
5591
5823
|
}
|
|
5592
|
-
const sourceRuntime = scopedRuntime && (scopedRuntime.size > 0 || isolateCssSource) ? isolateCurrentCssCandidates ? runtimeWithCurrentCss : mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtimeWithCurrentCss, {
|
|
5824
|
+
const sourceRuntime = scopedRuntime && (scopedRuntime.size > 0 || isolateCssSource) || isolateCssSource ? isolateCurrentCssCandidates ? runtimeWithCurrentCss : mergeScopedRuntimeWithCurrentRuntime(scopedRuntime ?? /* @__PURE__ */ new Set(), runtimeWithCurrentCss, {
|
|
5593
5825
|
currentCssCandidates,
|
|
5594
5826
|
cssHandlerOptions,
|
|
5595
5827
|
isolateCssSource,
|
|
5828
|
+
majorVersion,
|
|
5596
5829
|
matchedCssSourceFile
|
|
5597
5830
|
}) : runtimeWithCurrentCss;
|
|
5598
5831
|
const generatorRuntime = majorVersion === 4 && generatorOptions.target === "weapp" ? filterUnsupportedMiniProgramTailwindV4Candidates(sourceRuntime) : sourceRuntime;
|
|
@@ -5606,13 +5839,16 @@ async function generateCssByGenerator(options) {
|
|
|
5606
5839
|
tailwindcssV3Compatibility: generatorOptions.tailwindcssV3Compatibility,
|
|
5607
5840
|
target: generatorOptions.target
|
|
5608
5841
|
});
|
|
5609
|
-
}))).filter((item) => Boolean(item)));
|
|
5842
|
+
}), sourceConcurrency)).filter((item) => Boolean(item)));
|
|
5610
5843
|
if (!generated) return;
|
|
5611
5844
|
debug("tailwind generator result: %s rawBytes=%d cssBytes=%d candidates=%d", file, generated.rawCss.length, generated.css.length, generated.classSet.size);
|
|
5612
5845
|
if ((generated.target !== "weapp" || !hasUserCssLayerBlocks(generatorRawSource)) && typeof options.previousCss === "string" && typeof generated.incrementalCss === "string") {
|
|
5613
5846
|
const incrementalCss = stripTailwindBanner(generated.incrementalCss);
|
|
5614
5847
|
return {
|
|
5615
|
-
css: restoreLocalCssImports(incrementalCss.trim().length > 0 ? createCssAppend(options.previousCss, finalizeMiniProgramGeneratorCss(incrementalCss, generated.target, majorVersion, opts.cssPreflight, {
|
|
5848
|
+
css: restoreLocalCssImports(incrementalCss.trim().length > 0 ? createCssAppend(options.previousCss, finalizeMiniProgramGeneratorCss(incrementalCss, generated.target, majorVersion, opts.cssPreflight, {
|
|
5849
|
+
injectPreflight: false,
|
|
5850
|
+
styleOptions: generatorStyleOptions
|
|
5851
|
+
})) : options.previousCss, localImportParts?.imports),
|
|
5616
5852
|
target: generated.target,
|
|
5617
5853
|
source: "generator",
|
|
5618
5854
|
dependencies: generated.dependencies,
|
|
@@ -5644,7 +5880,8 @@ async function generateCssByGenerator(options) {
|
|
|
5644
5880
|
const beforeUserCss = await transformGeneratorUserCss(orderedExtraCss.before, userCssOptions);
|
|
5645
5881
|
const afterLayerUserCss = await transformGeneratorUserCss(afterLayerParts.layer, userCssOptions);
|
|
5646
5882
|
const afterUserCss = await transformGeneratorUserCss(afterLayerParts.rest, userCssOptions);
|
|
5647
|
-
|
|
5883
|
+
const fallbackLayerUserCss = generated.target === "weapp" && afterLayerParts.layer.trim().length === 0 && hasUserCssLayerBlocks(userCssRawSource) ? await transformGeneratorUserCss(splitUserCssLayerBlocks(userCssRawSource).layer, userCssOptions) : "";
|
|
5884
|
+
css = createCssSourceOrderAppend$1(createCssSourceOrderAppend$1(createCssSourceOrderAppend$1(beforeUserCss, generated.target === "weapp" ? wrapUserLayerComponentsCss(createCssSourceOrderAppend$1(afterLayerUserCss, fallbackLayerUserCss)) : afterLayerUserCss), css), afterUserCss);
|
|
5648
5885
|
if (isEmptyCssSourceOrderParts(orderedExtraCss) && shouldAppendWebBundleCssFallback(generated.target, {
|
|
5649
5886
|
hasSourceDirectives,
|
|
5650
5887
|
hasMatchedCssSourceFile
|
|
@@ -5660,11 +5897,14 @@ async function generateCssByGenerator(options) {
|
|
|
5660
5897
|
}
|
|
5661
5898
|
} else if (generated.target === "weapp" && shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
|
|
5662
5899
|
return {
|
|
5663
|
-
css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, {
|
|
5664
|
-
|
|
5665
|
-
|
|
5666
|
-
|
|
5667
|
-
|
|
5900
|
+
css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, {
|
|
5901
|
+
injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
|
|
5902
|
+
cssHandlerOptions,
|
|
5903
|
+
isolateCurrentCssCandidates,
|
|
5904
|
+
localImports: localImportParts?.imports
|
|
5905
|
+
}),
|
|
5906
|
+
styleOptions: generatorStyleOptions
|
|
5907
|
+
}), localImportParts?.imports),
|
|
5668
5908
|
target: generated.target,
|
|
5669
5909
|
source: "generator",
|
|
5670
5910
|
dependencies: generated.dependencies
|
|
@@ -5703,6 +5943,18 @@ async function generateCssByGenerator(options) {
|
|
|
5703
5943
|
importFallback: generatorOptions.importFallback
|
|
5704
5944
|
});
|
|
5705
5945
|
css = createCssSourceOrderAppend$1(css, userCss);
|
|
5946
|
+
} else if (hasMatchedCssSourceFile && generated.target === "weapp" && hasUserCssLayerBlocks(userCssRawSource)) {
|
|
5947
|
+
const layerUserCss = await transformGeneratorUserCss(splitUserCssLayerBlocks(userCssRawSource).layer, {
|
|
5948
|
+
generatorTarget: generated.target,
|
|
5949
|
+
generatorStyleOptions,
|
|
5950
|
+
cssUserHandlerOptions,
|
|
5951
|
+
styleHandler,
|
|
5952
|
+
importFallback: generatorOptions.importFallback
|
|
5953
|
+
});
|
|
5954
|
+
if (layerUserCss.trim().length > 0) {
|
|
5955
|
+
css = createCssSourceOrderAppend$1(css, wrapUserLayerComponentsCss(layerUserCss));
|
|
5956
|
+
if (shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
|
|
5957
|
+
}
|
|
5706
5958
|
}
|
|
5707
5959
|
if (hasMatchedCssSourceFile && generated.target === "weapp") {
|
|
5708
5960
|
if (!isolateCurrentCssCandidates && !shouldFilterApplyOnlyCss) css = await appendLegacyContainerCompatCss(css, userCssRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
@@ -5721,11 +5973,14 @@ async function generateCssByGenerator(options) {
|
|
|
5721
5973
|
css = createCssSourceOrderAppend$1(css, userCss);
|
|
5722
5974
|
}
|
|
5723
5975
|
return {
|
|
5724
|
-
css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, {
|
|
5725
|
-
|
|
5726
|
-
|
|
5727
|
-
|
|
5728
|
-
|
|
5976
|
+
css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, {
|
|
5977
|
+
injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
|
|
5978
|
+
cssHandlerOptions,
|
|
5979
|
+
isolateCurrentCssCandidates,
|
|
5980
|
+
localImports: localImportParts?.imports
|
|
5981
|
+
}),
|
|
5982
|
+
styleOptions: generatorStyleOptions
|
|
5983
|
+
}), localImportParts?.imports),
|
|
5729
5984
|
target: generated.target,
|
|
5730
5985
|
source: "generator",
|
|
5731
5986
|
dependencies: generated.dependencies
|
|
@@ -5736,11 +5991,14 @@ async function generateCssByGenerator(options) {
|
|
|
5736
5991
|
css = await appendLegacyContainerCompatCss(css, userCssRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
5737
5992
|
}
|
|
5738
5993
|
return {
|
|
5739
|
-
css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, {
|
|
5740
|
-
|
|
5741
|
-
|
|
5742
|
-
|
|
5743
|
-
|
|
5994
|
+
css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, {
|
|
5995
|
+
injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
|
|
5996
|
+
cssHandlerOptions,
|
|
5997
|
+
isolateCurrentCssCandidates,
|
|
5998
|
+
localImports: localImportParts?.imports
|
|
5999
|
+
}),
|
|
6000
|
+
styleOptions: generatorStyleOptions
|
|
6001
|
+
}), localImportParts?.imports),
|
|
5744
6002
|
target: generated.target,
|
|
5745
6003
|
source: "generator",
|
|
5746
6004
|
dependencies: generated.dependencies
|
|
@@ -5798,6 +6056,7 @@ async function generateCssForWebpackPipeline(source, loaderContext, options) {
|
|
|
5798
6056
|
if (!compilerOptions || !runtimeState || !getRuntimeSet) return;
|
|
5799
6057
|
await runtimeState.readyPromise;
|
|
5800
6058
|
const runtime = await getRuntimeSet();
|
|
6059
|
+
if (compilerOptions.generator?.target !== "web") return;
|
|
5801
6060
|
const file = loaderContext.resourcePath;
|
|
5802
6061
|
const normalizedSource = normalizeCssConfigDirectives(source, file);
|
|
5803
6062
|
const cssHandlerOptions = createCssHandlerOptions(compilerOptions, runtimeState.twPatcher.majorVersion, file, rewriteOptions.appType);
|