weapp-tailwindcss 5.0.12 → 5.1.0
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/README.en.md +1 -1
- package/README.md +1 -1
- package/dist/auto-Ba6hDrse.mjs +13 -0
- package/dist/auto-DtU6f3X6.js +18 -0
- package/dist/bundlers/shared/css-cleanup.d.ts +1 -1
- package/dist/bundlers/shared/generator-css/directives.d.ts +2 -1
- package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +27 -10
- package/dist/bundlers/shared/generator-css/local-imports.d.ts +3 -0
- package/dist/bundlers/shared/generator-css/source-files.d.ts +1 -0
- package/dist/bundlers/shared/generator-css/source-resolver/apply-reference.d.ts +6 -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 +3 -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 +6 -23
- package/dist/bundlers/shared/generator-css/types.d.ts +15 -1
- package/dist/bundlers/shared/generator-css/user-css.d.ts +5 -1
- package/dist/bundlers/shared/generator-css/validate.d.ts +1 -0
- package/dist/bundlers/shared/run-tasks.d.ts +1 -0
- package/dist/bundlers/shared/v4-generation-core.d.ts +11 -0
- package/dist/bundlers/vite/css-finalizer.d.ts +1 -1
- package/dist/bundlers/vite/css-memory.d.ts +37 -0
- package/dist/bundlers/vite/generate-bundle/bundle-file-names.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/candidates.d.ts +0 -1
- 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 +6 -0
- package/dist/bundlers/vite/generate-bundle/final-css-assets.d.ts +12 -0
- package/dist/bundlers/vite/generate-bundle/finalize.d.ts +63 -0
- package/dist/bundlers/vite/generate-bundle/js-processing.d.ts +31 -0
- package/dist/bundlers/vite/generate-bundle/memory-debug.d.ts +80 -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 +5 -2
- package/dist/bundlers/vite/generate-bundle/source-candidate-scope.d.ts +30 -0
- package/dist/bundlers/vite/generate-bundle/timing.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/types.d.ts +3 -1
- 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 +4 -1
- package/dist/bundlers/vite/hot-css-modules.d.ts +5 -0
- package/dist/bundlers/vite/incremental-runtime-class-set/escaped-candidates.d.ts +1 -0
- package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +3 -3
- 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/rewrite-css-imports.d.ts +1 -0
- package/dist/bundlers/vite/runtime-class-set.d.ts +5 -5
- package/dist/bundlers/vite/source-candidate-scan-signature.d.ts +13 -0
- package/dist/bundlers/vite/source-candidates/script.d.ts +1 -7
- package/dist/bundlers/vite/source-candidates.d.ts +12 -2
- package/dist/bundlers/vite/source-scan/css-entries.d.ts +3 -6
- package/dist/bundlers/vite/source-scan.d.ts +3 -3
- package/dist/bundlers/vite/uni-app-x-css-options.d.ts +1 -1
- package/dist/bundlers/vite/utils.d.ts +1 -0
- package/dist/bundlers/vite/weapp-vite-config.d.ts +3 -1
- package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +24 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.d.ts +48 -10
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/source-candidate-cache.d.ts +28 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +5 -1
- package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +15 -1
- package/dist/bundlers/webpack/shared/css-loader-runtime.d.ts +1 -0
- package/dist/cache/index.d.ts +1 -0
- package/dist/cli/mount-options.d.ts +2 -2
- package/dist/cli.js +126 -439
- package/dist/cli.mjs +121 -434
- package/dist/context/index.d.ts +3 -3
- package/dist/context/style-options.d.ts +4 -1
- package/dist/context/tailwindcss.d.ts +1 -1
- package/dist/{precheck-30zNPRlI.js → context-BHxLe743.js} +484 -175
- package/dist/{precheck-CsFr1q2l.mjs → context-Mbzkek1q.mjs} +461 -159
- package/dist/core.js +15 -12
- package/dist/core.mjs +10 -7
- package/dist/css-macro.js +2 -2
- package/dist/css-macro.mjs +2 -2
- package/dist/{defaults-Boc26eel.js → defaults-CVcKbXBG.js} +6 -50
- package/dist/{defaults-DH0ZQRhy.mjs → defaults-ZElj1zKc.mjs} +7 -45
- package/dist/defaults.d.ts +1 -7
- package/dist/defaults.js +1 -2
- package/dist/defaults.mjs +2 -2
- 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/index.d.ts +6 -7
- package/dist/generator/options.d.ts +3 -3
- package/dist/generator/types.d.ts +9 -10
- package/dist/generator-9rUz4Hcb.js +170 -0
- package/dist/generator-Dc4qaPmT.mjs +123 -0
- package/dist/generator.js +10 -16
- package/dist/generator.mjs +3 -3
- package/dist/{gulp-CxGZU0-v.js → gulp-B_sdP6dx.js} +80 -92
- package/dist/{gulp-BfZpaYSQ.mjs → gulp-uM36oIJs.mjs} +73 -85
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{hmr-timing-DNjF8bWA.mjs → hmr-timing-BXMLsF4b.mjs} +1289 -909
- package/dist/{hmr-timing-DFR51wgo.js → hmr-timing-CogqkFaF.js} +1397 -939
- package/dist/index.d.ts +1 -0
- package/dist/index.js +20 -4
- package/dist/index.mjs +6 -5
- package/dist/js/fast-path/oxc.d.ts +4 -0
- package/dist/js/precheck.d.ts +1 -0
- package/dist/postcss.js +3 -4
- package/dist/postcss.mjs +2 -3
- package/dist/presets.js +10 -20
- package/dist/presets.mjs +9 -19
- package/dist/runtime-branch/create-branch.d.ts +2 -0
- package/dist/runtime-branch/generator-target-env.d.ts +4 -0
- package/dist/runtime-branch/index.d.ts +6 -0
- package/dist/runtime-branch/mini-program.d.ts +2 -0
- package/dist/runtime-branch/native-app.d.ts +2 -0
- package/dist/runtime-branch/platform.d.ts +6 -0
- package/dist/runtime-branch/tailwind-version.d.ts +2 -0
- package/dist/runtime-branch/types.d.ts +37 -0
- package/dist/runtime-branch/web.d.ts +2 -0
- package/dist/runtime-branch.d.ts +1 -0
- package/dist/{bundle-state-DU2ATDhw.js → source-candidate-scan-signature-2ybpptAK.js} +262 -20
- package/dist/{bundle-state-BxMNKjBV.mjs → source-candidate-scan-signature-Cvb5z1ha.mjs} +187 -17
- package/dist/tailwindcss/candidates.d.ts +7 -0
- package/dist/tailwindcss/index.d.ts +2 -2
- package/dist/tailwindcss/runtime/cache.d.ts +6 -6
- package/dist/tailwindcss/runtime-factory.d.ts +12 -0
- package/dist/tailwindcss/runtime-options.d.ts +8 -0
- package/dist/tailwindcss/runtime-types.d.ts +86 -0
- package/dist/tailwindcss/runtime.d.ts +6 -6
- package/dist/tailwindcss/source-scan.d.ts +1 -1
- package/dist/tailwindcss/targets.d.ts +2 -2
- package/dist/tailwindcss/v4/config.d.ts +3 -3
- package/dist/tailwindcss/v4/css-entries.d.ts +1 -0
- package/dist/tailwindcss/v4/css-sources.d.ts +4 -2
- package/dist/tailwindcss/v4/index.d.ts +1 -1
- package/dist/tailwindcss/v4/multi-runtime.d.ts +2 -0
- package/dist/tailwindcss/v4/runtime-factory.d.ts +15 -0
- package/dist/tailwindcss/v4/runtime-options.d.ts +2 -0
- package/dist/tailwindcss/v4-engine/design-system.d.ts +1 -1
- package/dist/tailwindcss/v4-engine/generator/css-compat.d.ts +1 -1
- package/dist/tailwindcss/v4-engine/generator/rpx-candidates.d.ts +3 -3
- package/dist/tailwindcss/v4-engine/generator/scan-sources.d.ts +1 -1
- package/dist/tailwindcss/v4-engine/generator.d.ts +10 -3
- package/dist/tailwindcss/v4-engine/index.d.ts +1 -1
- package/dist/tailwindcss/v4-engine/miniprogram.d.ts +7 -1
- package/dist/tailwindcss/v4-engine/source.d.ts +23 -6
- package/dist/tailwindcss/v4-engine/types.d.ts +8 -9
- package/dist/tailwindcss/version.d.ts +1 -1
- package/dist/tailwindcss-DHIYcqXT.js +1523 -0
- package/dist/tailwindcss-wyUHrfil.mjs +1418 -0
- package/dist/{transform-CaVEBOuR.js → transform-CQVOgmzM.js} +45 -37
- package/dist/{transform-Cju08-aJ.mjs → transform-tExdt40m.mjs} +30 -22
- package/dist/typedoc.export.d.ts +1 -1
- package/dist/types/index.d.ts +16 -17
- package/dist/types/shared.d.ts +1 -1
- package/dist/types/{typedoc-tailwindcss-patch.d.ts → typedoc-tailwindcss-runtime.d.ts} +4 -10
- package/dist/types/user-defined-options/general.d.ts +8 -4
- package/dist/types/user-defined-options/important.d.ts +2 -2
- package/dist/uni-app-x/style-asset.d.ts +1 -0
- package/dist/{utils-Dolmt8EO.js → utils-BCa37Wqj.js} +2 -17
- package/dist/{utils-DsaS975I.mjs → utils-DodxWHGz.mjs} +2 -17
- package/dist/v4-engine-CF9zt4Cw.mjs +2396 -0
- package/dist/v4-engine-D4ubP7N5.js +2778 -0
- package/dist/{vite-BBGOjh9e.js → vite-CP0ylSxZ.js} +2887 -1683
- package/dist/{vite-CS5DE-HD.mjs → vite-CPO83EhA.mjs} +2753 -1548
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +5741 -4396
- package/dist/weapp-tw-runtime-classset-loader.js +36 -0
- package/dist/webpack-Bsek8VhR.js +2094 -0
- package/dist/webpack-BzqhJ8yK.mjs +2082 -0
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +11 -7
- package/dist/auto-CTp6wE5a.js +0 -33
- package/dist/auto-Cl8_hsG6.mjs +0 -22
- package/dist/bundlers/vite/incremental-runtime-class-set/v3-candidates.d.ts +0 -13
- package/dist/bundlers/vite/source-candidates/tailwind-v3-default-extractor.d.ts +0 -1
- package/dist/context/tailwindcss/rax.d.ts +0 -2
- package/dist/generator-Cb1Zp3Al.js +0 -92
- package/dist/generator-mvNFUvns.mjs +0 -67
- package/dist/tailwindcss/patcher-options.d.ts +0 -8
- package/dist/tailwindcss/patcher.d.ts +0 -12
- package/dist/tailwindcss/runtime-patch.d.ts +0 -5
- package/dist/tailwindcss/v3-engine/generator/cache-key.d.ts +0 -3
- package/dist/tailwindcss/v3-engine/generator/content.d.ts +0 -10
- package/dist/tailwindcss/v3-engine/generator/runtime-ready.d.ts +0 -2
- package/dist/tailwindcss/v3-engine/generator.d.ts +0 -19
- package/dist/tailwindcss/v3-engine/index.d.ts +0 -4
- package/dist/tailwindcss/v3-engine/miniprogram.d.ts +0 -4
- package/dist/tailwindcss/v3-engine/source.d.ts +0 -5
- package/dist/tailwindcss/v3-engine/types.d.ts +0 -61
- package/dist/tailwindcss/v4/multi-patcher.d.ts +0 -2
- package/dist/tailwindcss/v4/patcher-options.d.ts +0 -2
- package/dist/tailwindcss/v4/patcher.d.ts +0 -15
- package/dist/tailwindcss/v4-engine/tailwind-v3-compatibility.d.ts +0 -1
- package/dist/tailwindcss/v4-engine/tailwind-v3-default-colors.d.ts +0 -1
- package/dist/tailwindcss-CK84uGBp.mjs +0 -556
- package/dist/tailwindcss-Clpkz1oR.js +0 -613
- package/dist/v3-engine-CQE5JJNZ.js +0 -4639
- package/dist/v3-engine-DKBaKWGL.mjs +0 -4231
- package/dist/webpack-DIWrcpRo.js +0 -1066
- package/dist/webpack-SPcri_D8.mjs +0 -1054
- /package/dist/tailwindcss/{patcher-resolve.d.ts → runtime-resolve.d.ts} +0 -0
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import { i as normalizeWeappTailwindcssGeneratorOptions, t as createWeappTailwindcssGenerator } from "./generator-
|
|
3
|
-
import { h as traverse, m as babelParse,
|
|
4
|
-
import { r as isUniAppXEnabled } from "./tailwindcss-
|
|
5
|
-
import { createRequire } from "node:module";
|
|
6
|
-
import { finalizeMiniProgramCss, postcss, pruneMiniProgramGeneratedCss, removeUnsupportedMiniProgramAtRules } from "@weapp-tailwindcss/postcss";
|
|
7
|
-
import { LRUCache } from "lru-cache";
|
|
8
|
-
import { extractRawCandidatesWithPositions, extractSourceCandidates, extractValidCandidates, resolveProjectSourceFiles, resolveValidTailwindV4Candidates, splitCandidateTokens } from "tailwindcss-patch";
|
|
1
|
+
import { $ as isFileMatchedByTailwindSourceEntries, A as removeTailwindSourceDirectives, B as stripGeneratorPlaceholderMarkers, C as hasTailwindRootDirectives, D as normalizeTailwindSourceDirectives, F as hasTailwindGeneratedCss, H as stripTailwindBanners, I as hasTailwindGeneratedCssMarkers, L as splitGeneratorPlaceholderCssBySourceOrder, M as GENERATOR_PLACEHOLDER_MARKER_RE, N as VITE_MARKER_RE, P as createCssAppend, R as splitTailwindGeneratedCssByBanner, T as hasTailwindSourceDirectives, U as normalizeConfigDirective, V as stripTailwindBanner, W as prependConfigDirective, Y as FULL_SOURCE_SCAN_EXTENSION_RE, at as toPosixPath$1, ct as omitUndefined, i as resolveTailwindV4SourceOptionsFromRuntime, it as resolveTailwindV4CssSourceBase, j as resolveCssEntrySource, k as parseImportRequest, n as resolveTailwindV4SourceFromRuntime, rt as resolveSourceScanPath, st as filterUnsupportedMiniProgramTailwindV4Candidates, t as resolveTailwindV4Source$1, ut as loadTailwindV4DesignSystem, x as hasTailwindApplyDirective, z as splitTailwindV4GeneratedCssBySourceOrder } from "./v4-engine-CF9zt4Cw.mjs";
|
|
2
|
+
import { a as resolveGeneratorRuntimeBranch, i as normalizeWeappTailwindcssGeneratorOptions, s as shouldUseMiniProgramCssBranch, t as createWeappTailwindcssGenerator } from "./generator-Dc4qaPmT.mjs";
|
|
3
|
+
import { S as md5Hash, h as traverse, m as babelParse, n as resolveStyleOptionsFromContext, p as replaceWxml, x as createDebug } from "./context-Mbzkek1q.mjs";
|
|
4
|
+
import { h as resolveTailwindV4EntriesFromCss, l as getRuntimeClassSetSignature, r as isUniAppXEnabled } from "./tailwindcss-wyUHrfil.mjs";
|
|
9
5
|
import { existsSync, readFileSync } from "node:fs";
|
|
10
6
|
import path from "node:path";
|
|
11
7
|
import process from "node:process";
|
|
8
|
+
import { extractRawCandidatesWithPositions, extractSourceCandidates, extractValidCandidates, resolveProjectSourceFiles, resolveValidTailwindV4Candidates, splitCandidateTokens } from "@tailwindcss-mangle/engine";
|
|
9
|
+
import { filterExistingCssRules, finalizeMiniProgramCss, hasMiniProgramCssSpecificityPlaceholders, postcss, pruneMiniProgramGeneratedCss, removeUnsupportedCascadeLayers, removeUnsupportedMiniProgramAtRules, stripMiniProgramCssSpecificityPlaceholders } from "@weapp-tailwindcss/postcss";
|
|
10
|
+
import { LRUCache } from "lru-cache";
|
|
12
11
|
import { readFile } from "node:fs/promises";
|
|
13
12
|
import { MappingChars2String, unescape } from "@weapp-core/escape";
|
|
14
13
|
//#region src/bundlers/shared/cache.ts
|
|
@@ -101,6 +100,9 @@ function removeTracedTailwindGeneratedContainerRules(root) {
|
|
|
101
100
|
rule.remove();
|
|
102
101
|
});
|
|
103
102
|
}
|
|
103
|
+
function normalizeTraceCommentBefore(value) {
|
|
104
|
+
return value?.includes("\n") ? value : "\n";
|
|
105
|
+
}
|
|
104
106
|
function annotateCssSourceTrace(css, options) {
|
|
105
107
|
if (!isCssSourceTraceEnabled(options.opts) || !options.tokenSources?.size) return css;
|
|
106
108
|
try {
|
|
@@ -115,7 +117,7 @@ function annotateCssSourceTrace(css, options) {
|
|
|
115
117
|
return `${token} <= ${sources.length > 0 ? sources.join(", ") : "<tailwind generated>"}`;
|
|
116
118
|
});
|
|
117
119
|
const comment = postcss.comment({ text: `tokens: ${lines.join(" | ")}` });
|
|
118
|
-
|
|
120
|
+
comment.raws.before = normalizeTraceCommentBefore(rule.raws.before);
|
|
119
121
|
rule.raws.before = "\n";
|
|
120
122
|
rule.parent.insertBefore(rule, comment);
|
|
121
123
|
});
|
|
@@ -127,12 +129,15 @@ function annotateCssSourceTrace(css, options) {
|
|
|
127
129
|
}
|
|
128
130
|
//#endregion
|
|
129
131
|
//#region src/bundlers/shared/generator-css/generation-helpers.ts
|
|
130
|
-
function
|
|
132
|
+
function hasMiniProgramTailwindV4PreflightReset(css) {
|
|
133
|
+
return /(?:^|[},])\s*view\s*,\s*text\s*,\s*::after\s*,\s*::before\s*\{[^}]*\bborder\s*:\s*0\s+solid\b/.test(css);
|
|
134
|
+
}
|
|
135
|
+
function finalizeMiniProgramGeneratorCss(css, target, _majorVersion, cssPreflight, options = {}) {
|
|
131
136
|
if (target !== "weapp") return css;
|
|
132
137
|
return finalizeMiniProgramCss(css, {
|
|
133
|
-
cssPreflight:
|
|
134
|
-
isTailwindcssV4:
|
|
135
|
-
|
|
138
|
+
cssPreflight: options.injectPreflight !== false && !hasMiniProgramTailwindV4PreflightReset(css) ? cssPreflight : void 0,
|
|
139
|
+
isTailwindcssV4: true,
|
|
140
|
+
tailwindcssV4GradientFallback: options.styleOptions?.cssOptions?.tailwindcssV4GradientFallback ?? options.styleOptions?.tailwindcssV4GradientFallback
|
|
136
141
|
});
|
|
137
142
|
}
|
|
138
143
|
function shouldInjectMiniProgramPreflightForGeneratorCss(opts, options) {
|
|
@@ -141,36 +146,43 @@ function shouldInjectMiniProgramPreflightForGeneratorCss(opts, options) {
|
|
|
141
146
|
return isUniAppXEnabled(opts.uniAppX) && Boolean(options.localImports?.trim());
|
|
142
147
|
}
|
|
143
148
|
function mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtime, options) {
|
|
144
|
-
if (options.isolateCssSource
|
|
145
|
-
|
|
149
|
+
if (options.isolateCssSource) {
|
|
150
|
+
if (options.matchedCssSourceFile) return new Set([...scopedRuntime, ...options.currentCssCandidates ?? []]);
|
|
151
|
+
return new Set([...scopedRuntime, ...options.currentCssCandidates ?? []]);
|
|
152
|
+
}
|
|
153
|
+
if (runtime.size === 0 || !options.cssHandlerOptions.isMainChunk) return scopedRuntime;
|
|
146
154
|
return new Set([...scopedRuntime, ...runtime]);
|
|
147
155
|
}
|
|
148
|
-
function shouldIsolateScopedCssSource(source, sourceEntries) {
|
|
149
|
-
|
|
156
|
+
function shouldIsolateScopedCssSource(_majorVersion, source, sourceEntries, options) {
|
|
157
|
+
if (options.target !== "weapp") return false;
|
|
158
|
+
if (source.__weappTailwindcssMeta?.isolateCssSource) return true;
|
|
159
|
+
if (source.__weappTailwindcssMeta?.matchedCssSourceFile && (sourceEntries?.length ?? 0) > 0) return true;
|
|
160
|
+
if (sourceEntries?.length === 0) return false;
|
|
161
|
+
return sourceEntries !== void 0 && options.cssHandlerOptions?.isMainChunk !== true;
|
|
150
162
|
}
|
|
151
|
-
function shouldIsolateCurrentTailwindV4CssCandidates(
|
|
152
|
-
return
|
|
163
|
+
function shouldIsolateCurrentTailwindV4CssCandidates(_majorVersion, cssHandlerOptions, options) {
|
|
164
|
+
return !cssHandlerOptions.isMainChunk && hasTailwindApplyDirective(options.rawSource) && !hasTailwindRootDirectives(options.rawSource) && !options.hasGeneratedCss && !options.hasGeneratedMarkers;
|
|
153
165
|
}
|
|
154
166
|
function shouldScanTailwindV4Sources(majorVersion, target, generatorRuntime, isolateCssSource) {
|
|
155
|
-
if (majorVersion !== 4)
|
|
167
|
+
if (majorVersion !== 4) throw new Error("weapp-tailwindcss 生成管线仅支持 Tailwind CSS v4。");
|
|
156
168
|
if (target === "web") return true;
|
|
157
169
|
if (isolateCssSource) return false;
|
|
158
170
|
return generatorRuntime.size === 0;
|
|
159
171
|
}
|
|
160
|
-
function shouldAppendWebBundleCssFallback(target,
|
|
161
|
-
return target === "web"
|
|
172
|
+
function shouldAppendWebBundleCssFallback(target, _options) {
|
|
173
|
+
return target === "web";
|
|
162
174
|
}
|
|
163
175
|
function isEmptyCssSourceOrderParts(parts) {
|
|
164
176
|
return parts.before.trim().length === 0 && parts.after.trim().length === 0;
|
|
165
177
|
}
|
|
166
178
|
function resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorStyleOptions) {
|
|
179
|
+
const resolvedStyleOptions = resolveStyleOptionsFromContext(opts);
|
|
167
180
|
const preflightStyleOptions = {
|
|
168
|
-
cssPreflight:
|
|
169
|
-
cssPreflightRange:
|
|
181
|
+
cssPreflight: resolvedStyleOptions.cssPreflight,
|
|
182
|
+
cssPreflightRange: resolvedStyleOptions.cssPreflightRange
|
|
170
183
|
};
|
|
171
184
|
return {
|
|
172
|
-
...
|
|
173
|
-
atRules: opts.atRules,
|
|
185
|
+
...resolvedStyleOptions,
|
|
174
186
|
uniAppXCssTarget: opts.uniAppXCssTarget,
|
|
175
187
|
uniAppXUnsupported: opts.uniAppXUnsupported,
|
|
176
188
|
...cssHandlerOptions,
|
|
@@ -194,9 +206,11 @@ function splitRawSourceByGeneratedCssOrder(rawSource, rawTailwindCss) {
|
|
|
194
206
|
if (exactParts) return exactParts;
|
|
195
207
|
return splitTailwindGeneratedCssByBanner(rawSource);
|
|
196
208
|
}
|
|
197
|
-
function shouldUseGeneratorForCurrentCss(
|
|
209
|
+
function shouldUseGeneratorForCurrentCss(_majorVersion, cssHandlerOptions, options) {
|
|
198
210
|
const hasApplyDirectives = hasTailwindApplyDirective(options.rawSource);
|
|
199
|
-
|
|
211
|
+
const sourceCss = cssHandlerOptions.sourceOptions?.sourceCss;
|
|
212
|
+
const hasSourceCssDirectives = typeof sourceCss === "string" && (hasTailwindRootDirectives(sourceCss, { importFallback: true }) || hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || hasTailwindApplyDirective(sourceCss));
|
|
213
|
+
return options.forceGenerator === true || options.hasGeneratedCss || options.hasGeneratedMarkers || options.hasSourceDirectives || hasApplyDirectives || hasSourceCssDirectives;
|
|
200
214
|
}
|
|
201
215
|
function createRuntimeWithCurrentCssCandidates(runtime, currentCssCandidates, isolateCurrentCssCandidates) {
|
|
202
216
|
return isolateCurrentCssCandidates ? new Set(currentCssCandidates) : currentCssCandidates.length > 0 ? new Set([...runtime, ...currentCssCandidates]) : runtime;
|
|
@@ -218,10 +232,6 @@ function mergeGeneratorResults(generatedResults) {
|
|
|
218
232
|
sources: generatedResults.flatMap((item) => item.sources)
|
|
219
233
|
};
|
|
220
234
|
}
|
|
221
|
-
const SUPPORTED_GENERATOR_MAJOR_VERSIONS$1 = new Set([3, 4]);
|
|
222
|
-
function isSupportedGeneratorMajorVersion(majorVersion) {
|
|
223
|
-
return SUPPORTED_GENERATOR_MAJOR_VERSIONS$1.has(majorVersion ?? 0);
|
|
224
|
-
}
|
|
225
235
|
//#endregion
|
|
226
236
|
//#region src/bundlers/shared/generator-css/legacy-selectors.ts
|
|
227
237
|
const CLASS_SELECTOR_RE = /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i;
|
|
@@ -371,6 +381,21 @@ function collectGeneratedDeclarationPropsBySelector(generatedCss, selectors) {
|
|
|
371
381
|
}
|
|
372
382
|
return propsBySelector;
|
|
373
383
|
}
|
|
384
|
+
function isRuleCoveredByGeneratedProps(rule, generatedDeclarationPropsBySelector) {
|
|
385
|
+
const nodeSelectors = getRuleCompatSelectorKeys(rule);
|
|
386
|
+
if (nodeSelectors.length === 0) return false;
|
|
387
|
+
const props = /* @__PURE__ */ new Set();
|
|
388
|
+
rule.walkDecls((decl) => {
|
|
389
|
+
props.add(decl.prop);
|
|
390
|
+
});
|
|
391
|
+
if (props.size === 0) return false;
|
|
392
|
+
for (const selector of nodeSelectors) {
|
|
393
|
+
const generatedProps = generatedDeclarationPropsBySelector.get(selector);
|
|
394
|
+
if (!generatedProps) continue;
|
|
395
|
+
if ([...props].every((prop) => generatedProps.has(prop))) return true;
|
|
396
|
+
}
|
|
397
|
+
return false;
|
|
398
|
+
}
|
|
374
399
|
function removeGeneratedSelectorCompatCss(css, generatedCss) {
|
|
375
400
|
const generatedSelectors = collectGeneratedSelectors(generatedCss);
|
|
376
401
|
if (generatedSelectors.size === 0) return css;
|
|
@@ -411,6 +436,7 @@ function collectDedupedPostTransformCompatCss(css, generatedCss) {
|
|
|
411
436
|
preservedNodes.push(node.clone());
|
|
412
437
|
return;
|
|
413
438
|
}
|
|
439
|
+
if (isRuleCoveredByGeneratedProps(node, generatedDeclarationPropsBySelector)) return;
|
|
414
440
|
if (isCustomPropertyOnlyRule(node) && !isPseudoContentInitRule(node) && !hasUtilityClassSelector(node.selector)) {
|
|
415
441
|
const declarationProps = /* @__PURE__ */ new Set();
|
|
416
442
|
node.walkDecls((decl) => {
|
|
@@ -447,6 +473,16 @@ function removeDuplicatedViteMarkers(css, baseCss) {
|
|
|
447
473
|
//#endregion
|
|
448
474
|
//#region src/bundlers/shared/generator-css/source-files.ts
|
|
449
475
|
const SFC_STYLE_BLOCK_RE = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
|
|
476
|
+
const STYLE_IMPORT_EXTENSIONS = [
|
|
477
|
+
".css",
|
|
478
|
+
".scss",
|
|
479
|
+
".sass",
|
|
480
|
+
".less",
|
|
481
|
+
".styl",
|
|
482
|
+
".stylus",
|
|
483
|
+
".pcss",
|
|
484
|
+
".postcss"
|
|
485
|
+
];
|
|
450
486
|
function stripStyleExtension(file) {
|
|
451
487
|
const normalized = file.replace(/[?#].*$/, "");
|
|
452
488
|
const ext = path.extname(normalized);
|
|
@@ -548,98 +584,135 @@ function extractStyleDirectiveSources(source) {
|
|
|
548
584
|
let match = SFC_STYLE_BLOCK_RE.exec(source);
|
|
549
585
|
while (match !== null) {
|
|
550
586
|
const styleSource = match[1] ?? "";
|
|
551
|
-
if (hasTailwindSourceDirectives(styleSource)) styleSources.push(styleSource);
|
|
587
|
+
if (hasTailwindSourceDirectives(styleSource, { importFallback: true })) styleSources.push(styleSource);
|
|
552
588
|
match = SFC_STYLE_BLOCK_RE.exec(source);
|
|
553
589
|
}
|
|
554
590
|
if (styleSources.length > 0) return styleSources;
|
|
555
|
-
return hasTailwindSourceDirectives(source) ? [source] : [];
|
|
591
|
+
return hasTailwindSourceDirectives(source, { importFallback: true }) ? [source] : [];
|
|
556
592
|
}
|
|
557
|
-
function
|
|
558
|
-
|
|
559
|
-
|
|
593
|
+
function extractSfcStyleSources(source) {
|
|
594
|
+
const styleSources = [];
|
|
595
|
+
SFC_STYLE_BLOCK_RE.lastIndex = 0;
|
|
596
|
+
let match = SFC_STYLE_BLOCK_RE.exec(source);
|
|
597
|
+
while (match !== null) {
|
|
598
|
+
styleSources.push(match[1] ?? "");
|
|
599
|
+
match = SFC_STYLE_BLOCK_RE.exec(source);
|
|
600
|
+
}
|
|
601
|
+
return styleSources;
|
|
602
|
+
}
|
|
603
|
+
function isLocalStyleImportRequest(request) {
|
|
604
|
+
return typeof request === "string" && request.length > 0 && (request.startsWith(".") || request.startsWith("/"));
|
|
605
|
+
}
|
|
606
|
+
function resolveLocalStyleImportFile(request, base) {
|
|
607
|
+
const normalized = (path.isAbsolute(request) ? request : path.resolve(base, request)).replace(/[?#].*$/, "");
|
|
608
|
+
if (existsSync(normalized)) return normalized;
|
|
609
|
+
if (path.extname(normalized)) return;
|
|
610
|
+
for (const extension of STYLE_IMPORT_EXTENSIONS) {
|
|
611
|
+
const candidate = `${normalized}${extension}`;
|
|
612
|
+
if (existsSync(candidate)) return candidate;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
function collectLocalStyleImportFiles(source, base) {
|
|
616
|
+
const files = [];
|
|
617
|
+
const sources = extractSfcStyleSources(source);
|
|
618
|
+
if (sources.length === 0) sources.push(source);
|
|
619
|
+
for (const styleSource of sources) try {
|
|
620
|
+
postcss.parse(styleSource).walkAtRules("import", (rule) => {
|
|
621
|
+
const request = parseImportRequest(rule.params);
|
|
622
|
+
if (!isLocalStyleImportRequest(request)) return;
|
|
623
|
+
const file = resolveLocalStyleImportFile(request, base);
|
|
624
|
+
if (file) files.push(file);
|
|
625
|
+
});
|
|
626
|
+
} catch {}
|
|
627
|
+
return files;
|
|
628
|
+
}
|
|
629
|
+
function extractStyleDirectiveSourcesDeep(source, sourceFile, seen) {
|
|
630
|
+
const ownSources = extractStyleDirectiveSources(source);
|
|
631
|
+
if (ownSources.length > 0) return ownSources.map((styleSource) => ({
|
|
632
|
+
source: styleSource,
|
|
633
|
+
file: sourceFile
|
|
634
|
+
}));
|
|
635
|
+
const sources = [];
|
|
636
|
+
const base = path.dirname(sourceFile);
|
|
637
|
+
for (const importedFile of collectLocalStyleImportFiles(source, base)) {
|
|
638
|
+
const normalizedImportedFile = path.resolve(importedFile);
|
|
639
|
+
if (seen.has(normalizedImportedFile)) continue;
|
|
640
|
+
seen.add(normalizedImportedFile);
|
|
560
641
|
try {
|
|
561
|
-
const
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
642
|
+
const importedSource = readFileSync(normalizedImportedFile, "utf8");
|
|
643
|
+
sources.push(...extractStyleDirectiveSourcesDeep(importedSource, normalizedImportedFile, seen));
|
|
644
|
+
} catch {}
|
|
645
|
+
}
|
|
646
|
+
return sources;
|
|
647
|
+
}
|
|
648
|
+
function resolveSourceSideCssEntrySource(file, sourceOptions, resolveOptions = {}) {
|
|
649
|
+
for (const sourceFile of createSourceStylePathCandidates(file, sourceOptions)) try {
|
|
650
|
+
const source = sourceOptions.sourceFile && path.resolve(sourceOptions.sourceFile) === path.resolve(sourceFile) && typeof sourceOptions.sourceCss === "string" ? sourceOptions.sourceCss : existsSync(sourceFile) ? readFileSync(sourceFile, "utf8") : void 0;
|
|
651
|
+
if (source === void 0) continue;
|
|
652
|
+
const directiveSources = extractStyleDirectiveSourcesDeep(source, sourceFile, new Set([path.resolve(sourceFile)]));
|
|
653
|
+
for (const styleSource of directiveSources) {
|
|
654
|
+
const cssEntrySource = resolveCssEntrySource(styleSource.source, path.dirname(styleSource.file), resolveOptions);
|
|
655
|
+
if (cssEntrySource) return {
|
|
656
|
+
...cssEntrySource,
|
|
657
|
+
file: styleSource.file
|
|
658
|
+
};
|
|
571
659
|
}
|
|
660
|
+
} catch {
|
|
661
|
+
continue;
|
|
572
662
|
}
|
|
573
663
|
}
|
|
574
664
|
//#endregion
|
|
575
|
-
//#region src/bundlers/shared/generator-css/source-resolver.ts
|
|
576
|
-
function
|
|
577
|
-
|
|
578
|
-
return typeof from === "string" && from.length > 0 ? from : void 0;
|
|
579
|
-
}
|
|
580
|
-
function resolvePostcssSourceFile(cssHandlerOptions) {
|
|
581
|
-
const from = resolvePostcssFromOption(cssHandlerOptions);
|
|
582
|
-
if (!from || !path.isAbsolute(from)) return;
|
|
583
|
-
return from.replace(/[?#].*$/, "");
|
|
584
|
-
}
|
|
585
|
-
function resolveCssHandlerSourceOptions(cssHandlerOptions) {
|
|
586
|
-
return cssHandlerOptions.sourceOptions;
|
|
587
|
-
}
|
|
588
|
-
function createCssEntrySources(cssEntries) {
|
|
589
|
-
return cssEntries?.filter((entry) => typeof entry === "string" && entry.length > 0 && path.isAbsolute(entry)).map((entry) => ({ file: path.resolve(entry) }));
|
|
665
|
+
//#region src/bundlers/shared/generator-css/source-resolver/apply-reference.ts
|
|
666
|
+
function createTailwindV4ApplyReferenceSource(css, sourceOptions) {
|
|
667
|
+
return createTailwindV4SourceReferenceSource(css, sourceOptions);
|
|
590
668
|
}
|
|
591
|
-
function
|
|
592
|
-
|
|
593
|
-
const
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
};
|
|
602
|
-
for (const cssSource of cssSources ?? []) addSource(cssSource);
|
|
603
|
-
for (const cssSource of cssEntrySources ?? []) addSource(cssSource);
|
|
604
|
-
return merged.length > 0 ? merged : void 0;
|
|
669
|
+
function createTailwindV4SourceReferenceSource(css, sourceOptions) {
|
|
670
|
+
if (hasTailwindV4RootImport(css, sourceOptions)) return css;
|
|
671
|
+
const hasApplyDirective = hasTailwindApplyDirective(css);
|
|
672
|
+
if (!hasApplyDirective && !hasTailwindSourceDirectives(css, { importFallback: true })) return css;
|
|
673
|
+
const utilities = hasApplyDirective ? collectTailwindApplyUtilities(css) : [];
|
|
674
|
+
return [
|
|
675
|
+
`@import "${sourceOptions.packageName ?? "tailwindcss"}" source(none);`,
|
|
676
|
+
utilities.length > 0 ? `@source inline(${JSON.stringify(utilities.join(" "))});` : void 0,
|
|
677
|
+
css
|
|
678
|
+
].filter(Boolean).join("\n");
|
|
605
679
|
}
|
|
606
|
-
function
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
680
|
+
function hasTailwindV4RootImport(css, sourceOptions) {
|
|
681
|
+
try {
|
|
682
|
+
const root = postcss.parse(css);
|
|
683
|
+
let found = false;
|
|
684
|
+
root.walkAtRules((rule) => {
|
|
685
|
+
if (rule.name === "tailwind") {
|
|
686
|
+
found = true;
|
|
687
|
+
return false;
|
|
688
|
+
}
|
|
689
|
+
if (rule.name !== "import" && rule.name !== "use" && rule.name !== "forward") return;
|
|
690
|
+
const request = parseImportRequest(rule.params);
|
|
691
|
+
if (request === (sourceOptions.packageName ?? "tailwindcss") || request === "tailwindcss" || request === "tailwindcss4" || request?.startsWith("tailwindcss/") || request?.startsWith("tailwindcss4/")) {
|
|
692
|
+
found = true;
|
|
693
|
+
return false;
|
|
694
|
+
}
|
|
695
|
+
});
|
|
696
|
+
return found;
|
|
697
|
+
} catch {
|
|
698
|
+
return /@(?:import|use|forward|tailwind)(?:[\s"'(;]|$)/.test(css) && (css.includes("tailwindcss") || css.includes("tailwindcss4") || css.includes("weapp-tailwindcss"));
|
|
699
|
+
}
|
|
614
700
|
}
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
const
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
...sourceOptions,
|
|
626
|
-
sourceFile: sourceOptions.sourceFile ?? cssEntry
|
|
627
|
-
});
|
|
628
|
-
return withGeneratorSourceMetadata(await resolveTailwindV4Source$1({
|
|
629
|
-
...omitUndefined(singleEntrySourceOptions),
|
|
630
|
-
base,
|
|
631
|
-
css: normalizeConfigDirective(css, config),
|
|
632
|
-
cssEntries: [cssEntry]
|
|
633
|
-
}), {
|
|
634
|
-
matchedCssSourceFile: cssEntry,
|
|
635
|
-
sourceBase: base,
|
|
636
|
-
sourceCss: css
|
|
701
|
+
function collectTailwindApplyUtilities(css) {
|
|
702
|
+
let root;
|
|
703
|
+
try {
|
|
704
|
+
root = postcss.parse(css);
|
|
705
|
+
} catch {
|
|
706
|
+
return [];
|
|
707
|
+
}
|
|
708
|
+
const utilities = /* @__PURE__ */ new Set();
|
|
709
|
+
root.walkAtRules("apply", (rule) => {
|
|
710
|
+
for (const utility of splitCandidateTokens(rule.params)) utilities.add(utility);
|
|
637
711
|
});
|
|
712
|
+
return [...utilities].sort();
|
|
638
713
|
}
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
return path.dirname(path.resolve(normalized));
|
|
642
|
-
}
|
|
714
|
+
//#endregion
|
|
715
|
+
//#region src/bundlers/shared/generator-css/source-resolver/config.ts
|
|
643
716
|
function resolveExistingConfigPath(config, configRequest, file, sourceOptions) {
|
|
644
717
|
if (config && existsSync(config)) return config;
|
|
645
718
|
if (!configRequest || path.isAbsolute(configRequest)) return sourceOptions.config;
|
|
@@ -666,27 +739,11 @@ function resolveExistingConfigPath(config, configRequest, file, sourceOptions) {
|
|
|
666
739
|
for (const candidate of configCandidates) if (existsSync(candidate)) return candidate;
|
|
667
740
|
return sourceOptions.config;
|
|
668
741
|
}
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
if (!from || !path.isAbsolute(from)) return path.isAbsolute(file) || Boolean(sourceOptions?.sourceFile) || Boolean(sourceOptions?.cssSources?.length);
|
|
672
|
-
return true;
|
|
673
|
-
}
|
|
674
|
-
function shouldResolveSourceSideCssEntry(rawSource) {
|
|
675
|
-
return rawSource.includes("@apply") || hasTailwindRootDirectives(rawSource, { importFallback: true }) || hasTailwindSourceDirectives(rawSource, { importFallback: true }) || hasTailwindGeneratedCss(rawSource) || hasTailwindGeneratedCssMarkers(rawSource);
|
|
676
|
-
}
|
|
677
|
-
function shouldPreferTailwindV3SourceSideEntry(rawSource, sourceSideEntrySource) {
|
|
678
|
-
return Boolean(sourceSideEntrySource) && !hasTailwindSourceDirectives(rawSource, { importFallback: true });
|
|
679
|
-
}
|
|
680
|
-
function shouldPreferResolvedSourceSideEntry(cssEntrySource, sourceSideEntrySource) {
|
|
681
|
-
return Boolean(sourceSideEntrySource?.config) && Boolean(cssEntrySource?.configRequest) && (!cssEntrySource?.config || !existsSync(cssEntrySource.config));
|
|
682
|
-
}
|
|
742
|
+
//#endregion
|
|
743
|
+
//#region src/bundlers/shared/generator-css/source-resolver/matching.ts
|
|
683
744
|
function normalizeCssSourceForCompare(css) {
|
|
684
745
|
return stripGeneratorPlaceholderMarkers(stripTailwindBanners(css)).trim();
|
|
685
746
|
}
|
|
686
|
-
function getOutputFileStem(file) {
|
|
687
|
-
const normalized = file.replace(/[?#].*$/, "");
|
|
688
|
-
return path.basename(normalized, path.extname(normalized));
|
|
689
|
-
}
|
|
690
747
|
function getOutputFileWithoutExtension(file) {
|
|
691
748
|
const normalized = file.replace(/[?#].*$/, "");
|
|
692
749
|
const ext = path.extname(normalized);
|
|
@@ -695,6 +752,12 @@ function getOutputFileWithoutExtension(file) {
|
|
|
695
752
|
function normalizeMatchPath(file) {
|
|
696
753
|
return file.split(path.sep).join("/");
|
|
697
754
|
}
|
|
755
|
+
function stripBundlerContentHash(name) {
|
|
756
|
+
return name.replace(/[._-]?[a-f0-9]{6,32}$/i, "");
|
|
757
|
+
}
|
|
758
|
+
function getMatchBasename(file) {
|
|
759
|
+
return stripBundlerContentHash(path.basename(getOutputFileWithoutExtension(file.replace(/[?#].*$/, ""))));
|
|
760
|
+
}
|
|
698
761
|
function isPathWithinRoot(file, root) {
|
|
699
762
|
const relative = path.relative(root, file);
|
|
700
763
|
return Boolean(relative) && !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
@@ -704,11 +767,7 @@ function collectCssSourceMatchBases(file, roots) {
|
|
|
704
767
|
const bases = /* @__PURE__ */ new Set();
|
|
705
768
|
const addBase = (candidate) => {
|
|
706
769
|
const base = normalizeMatchPath(getOutputFileWithoutExtension(candidate));
|
|
707
|
-
if (base.length > 0)
|
|
708
|
-
bases.add(base);
|
|
709
|
-
const withoutWorkspaceSegment = base.replace(/^(?:src|dist)\//, "");
|
|
710
|
-
if (withoutWorkspaceSegment !== base && withoutWorkspaceSegment.length > 0) bases.add(withoutWorkspaceSegment);
|
|
711
|
-
}
|
|
770
|
+
if (base.length > 0) bases.add(base);
|
|
712
771
|
};
|
|
713
772
|
addBase(normalizedFile);
|
|
714
773
|
const resolvedRoots = roots.filter((root) => typeof root === "string" && root.length > 0).map((root) => path.resolve(root));
|
|
@@ -724,17 +783,121 @@ function scoreTailwindV4CssSourceFileMatch(file, cssSourceFile, sourceOptions) {
|
|
|
724
783
|
sourceOptions.cwd
|
|
725
784
|
]);
|
|
726
785
|
const sourceBases = collectCssSourceMatchBases(cssSourceFile, [sourceOptions.projectRoot, sourceOptions.cwd]);
|
|
786
|
+
const outputBasename = getMatchBasename(file);
|
|
787
|
+
const sourceBasename = getMatchBasename(cssSourceFile);
|
|
727
788
|
let bestScore = 0;
|
|
728
789
|
for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase) bestScore = Math.max(bestScore, 1e5 + outputBase.length);
|
|
729
790
|
else if (outputBase.endsWith(`/${sourceBase}`)) bestScore = Math.max(bestScore, 5e4 + sourceBase.length);
|
|
730
791
|
else if (sourceBase.endsWith(`/${outputBase}`)) bestScore = Math.max(bestScore, 1e3 + outputBase.length);
|
|
792
|
+
if (outputBasename && outputBasename === sourceBasename) bestScore = Math.max(bestScore, 100 + outputBasename.length);
|
|
731
793
|
return bestScore;
|
|
732
794
|
}
|
|
795
|
+
//#endregion
|
|
796
|
+
//#region src/bundlers/shared/generator-css/source-resolver/metadata.ts
|
|
797
|
+
function withGeneratorSourceMetadata(source, metadata) {
|
|
798
|
+
return {
|
|
799
|
+
...source,
|
|
800
|
+
__weappTailwindcssMeta: metadata
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
function withMatchedSourceSideMetadata(source, resolvedEntrySource) {
|
|
804
|
+
return resolvedEntrySource.file ? withGeneratorSourceMetadata(source, {
|
|
805
|
+
isolateCssSource: true,
|
|
806
|
+
matchedCssSourceFile: resolvedEntrySource.file,
|
|
807
|
+
sourceBase: resolvedEntrySource.base,
|
|
808
|
+
sourceCss: resolvedEntrySource.css
|
|
809
|
+
}) : source;
|
|
810
|
+
}
|
|
811
|
+
//#endregion
|
|
812
|
+
//#region src/bundlers/shared/generator-css/source-resolver/postcss-source.ts
|
|
813
|
+
function resolvePostcssFromOption(cssHandlerOptions) {
|
|
814
|
+
const from = cssHandlerOptions.postcssOptions?.options?.from;
|
|
815
|
+
return typeof from === "string" && from.length > 0 ? from : void 0;
|
|
816
|
+
}
|
|
817
|
+
function resolvePostcssSourceFile(cssHandlerOptions) {
|
|
818
|
+
const from = resolvePostcssFromOption(cssHandlerOptions);
|
|
819
|
+
if (!from || !path.isAbsolute(from)) return;
|
|
820
|
+
return from.replace(/[?#].*$/, "");
|
|
821
|
+
}
|
|
822
|
+
function resolveCssHandlerSourceOptions(cssHandlerOptions) {
|
|
823
|
+
return cssHandlerOptions.sourceOptions;
|
|
824
|
+
}
|
|
825
|
+
function resolveCssSourceBase(file, cssHandlerOptions) {
|
|
826
|
+
const normalized = (resolvePostcssFromOption(cssHandlerOptions) ?? file).replace(/[?#].*$/, "");
|
|
827
|
+
return path.dirname(path.resolve(normalized));
|
|
828
|
+
}
|
|
829
|
+
//#endregion
|
|
830
|
+
//#region src/bundlers/shared/generator-css/source-resolver.ts
|
|
831
|
+
function createCssEntrySources(cssEntries) {
|
|
832
|
+
return cssEntries?.filter((entry) => typeof entry === "string" && entry.length > 0 && path.isAbsolute(entry)).map((entry) => ({ file: path.resolve(entry) }));
|
|
833
|
+
}
|
|
834
|
+
function mergeCssSources(cssSources, cssEntrySources) {
|
|
835
|
+
const merged = [];
|
|
836
|
+
const fileIndex = /* @__PURE__ */ new Map();
|
|
837
|
+
const addSource = (cssSource) => {
|
|
838
|
+
const file = typeof cssSource.file === "string" && cssSource.file.length > 0 ? path.resolve(cssSource.file) : void 0;
|
|
839
|
+
if (file) {
|
|
840
|
+
const previousIndex = fileIndex.get(file);
|
|
841
|
+
if (previousIndex !== void 0) {
|
|
842
|
+
if (typeof merged[previousIndex]?.css !== "string" && typeof cssSource.css === "string") merged[previousIndex] = cssSource;
|
|
843
|
+
return;
|
|
844
|
+
}
|
|
845
|
+
fileIndex.set(file, merged.length);
|
|
846
|
+
}
|
|
847
|
+
merged.push(cssSource);
|
|
848
|
+
};
|
|
849
|
+
for (const cssSource of cssSources ?? []) addSource(cssSource);
|
|
850
|
+
for (const cssSource of cssEntrySources ?? []) addSource(cssSource);
|
|
851
|
+
return merged.length > 0 ? merged : void 0;
|
|
852
|
+
}
|
|
853
|
+
function createSingleTailwindV4SourceOptions(sourceOptions, options) {
|
|
854
|
+
return omitUndefined({
|
|
855
|
+
projectRoot: sourceOptions.projectRoot,
|
|
856
|
+
baseFallbacks: sourceOptions.baseFallbacks,
|
|
857
|
+
packageName: sourceOptions.packageName,
|
|
858
|
+
base: options.base,
|
|
859
|
+
css: options.css
|
|
860
|
+
});
|
|
861
|
+
}
|
|
862
|
+
async function resolveTailwindV4CssEntrySource(cssEntry, sourceOptions) {
|
|
863
|
+
const { cssEntries: _cssEntries, cssSources: _cssSources, ...singleEntrySourceOptions } = sourceOptions;
|
|
864
|
+
if (!existsSync(cssEntry)) return resolveTailwindV4Source$1({
|
|
865
|
+
...omitUndefined(singleEntrySourceOptions),
|
|
866
|
+
cssEntries: [cssEntry]
|
|
867
|
+
});
|
|
868
|
+
const css = readFileSync(cssEntry, "utf8");
|
|
869
|
+
const base = path.dirname(path.resolve(cssEntry));
|
|
870
|
+
const entrySource = resolveCssEntrySource(css, base, { removeConfig: false });
|
|
871
|
+
const config = resolveExistingConfigPath(entrySource?.config, entrySource?.configRequest, cssEntry, {
|
|
872
|
+
...sourceOptions,
|
|
873
|
+
sourceFile: sourceOptions.sourceFile ?? cssEntry
|
|
874
|
+
});
|
|
875
|
+
return withGeneratorSourceMetadata(await resolveTailwindV4Source$1({
|
|
876
|
+
...omitUndefined(singleEntrySourceOptions),
|
|
877
|
+
base,
|
|
878
|
+
css: normalizeConfigDirective(css, config),
|
|
879
|
+
cssEntries: [cssEntry]
|
|
880
|
+
}), {
|
|
881
|
+
matchedCssSourceFile: cssEntry,
|
|
882
|
+
sourceBase: base,
|
|
883
|
+
sourceCss: css
|
|
884
|
+
});
|
|
885
|
+
}
|
|
886
|
+
function canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) {
|
|
887
|
+
const from = resolvePostcssFromOption(cssHandlerOptions);
|
|
888
|
+
if (!from || !path.isAbsolute(from)) return path.isAbsolute(file) || Boolean(sourceOptions?.sourceFile) || Boolean(sourceOptions?.cssSources?.length);
|
|
889
|
+
return true;
|
|
890
|
+
}
|
|
891
|
+
function shouldResolveSourceSideCssEntry(rawSource) {
|
|
892
|
+
return rawSource.includes("@apply") || hasTailwindRootDirectives(rawSource, { importFallback: true }) || hasTailwindSourceDirectives(rawSource, { importFallback: true }) || hasTailwindGeneratedCss(rawSource) || hasTailwindGeneratedCssMarkers(rawSource);
|
|
893
|
+
}
|
|
733
894
|
function resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) {
|
|
734
895
|
const cssEntries = sourceOptions.cssEntries;
|
|
735
896
|
if (!cssEntries?.length) return;
|
|
897
|
+
const normalizedFile = path.resolve(file.replace(/[?#].*$/, ""));
|
|
898
|
+
const pathMatchedEntries = cssEntries.filter((cssEntry) => path.resolve(cssEntry.replace(/[?#].*$/, "")) === normalizedFile);
|
|
899
|
+
if (pathMatchedEntries.length === 1) return resolveTailwindV4CssEntrySource(pathMatchedEntries[0], sourceOptions);
|
|
736
900
|
const normalizedRawSource = normalizeCssSourceForCompare(rawSource);
|
|
737
|
-
const outputStem = getOutputFileStem(file);
|
|
738
901
|
const matches = cssEntries.map((cssEntry) => {
|
|
739
902
|
if (!existsSync(cssEntry)) return;
|
|
740
903
|
try {
|
|
@@ -744,14 +907,6 @@ function resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) {
|
|
|
744
907
|
cssEntry,
|
|
745
908
|
score: 1e6 + pathScore
|
|
746
909
|
};
|
|
747
|
-
if (pathScore > 0) return {
|
|
748
|
-
cssEntry,
|
|
749
|
-
score: pathScore
|
|
750
|
-
};
|
|
751
|
-
if (cssEntries.length === 1 && outputStem.length > 0 && getOutputFileStem(cssEntry) === outputStem) return {
|
|
752
|
-
cssEntry,
|
|
753
|
-
score: 1
|
|
754
|
-
};
|
|
755
910
|
return;
|
|
756
911
|
} catch {
|
|
757
912
|
return;
|
|
@@ -771,6 +926,18 @@ function normalizeTailwindV4CssSourceConfig(cssSource, sourceBase) {
|
|
|
771
926
|
css: normalizeConfigDirective(cssSource.css, entrySource.config)
|
|
772
927
|
};
|
|
773
928
|
}
|
|
929
|
+
function normalizeResolvedTailwindV4SourceConfig(source, file, sourceOptions) {
|
|
930
|
+
if (!("css" in source) || typeof source.css !== "string" || !source.css.includes("@config")) return source;
|
|
931
|
+
const sourceFile = typeof file === "string" && file.length > 0 ? file : source.__weappTailwindcssMeta?.matchedCssSourceFile;
|
|
932
|
+
if (!sourceFile) return source;
|
|
933
|
+
const entrySource = resolveCssEntrySource(source.css, path.dirname(path.resolve(sourceFile)), { removeConfig: false });
|
|
934
|
+
const config = resolveExistingConfigPath(entrySource?.config, entrySource?.configRequest, sourceFile, sourceOptions ?? {});
|
|
935
|
+
const normalizedCss = normalizeConfigDirective(source.css, config);
|
|
936
|
+
return normalizedCss === source.css ? source : {
|
|
937
|
+
...source,
|
|
938
|
+
css: normalizedCss
|
|
939
|
+
};
|
|
940
|
+
}
|
|
774
941
|
function hydrateTailwindV4CssSource(cssSource) {
|
|
775
942
|
if (typeof cssSource.css === "string" && cssSource.css.length > 0) return cssSource;
|
|
776
943
|
if (typeof cssSource.file !== "string" || !existsSync(cssSource.file)) return cssSource;
|
|
@@ -810,18 +977,10 @@ async function resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOpt
|
|
|
810
977
|
index,
|
|
811
978
|
score: 1e6
|
|
812
979
|
};
|
|
813
|
-
if (typeof cssSource.file === "string") {
|
|
814
|
-
const pathScore = scoreTailwindV4CssSourceFileMatch(file, cssSource.file, sourceOptions);
|
|
815
|
-
if (pathScore > 0) return {
|
|
816
|
-
cssSource,
|
|
817
|
-
index,
|
|
818
|
-
score: pathScore
|
|
819
|
-
};
|
|
820
|
-
}
|
|
821
980
|
if (normalizeCssSourceForCompare(cssSource.css) === normalizedRawSource) return {
|
|
822
981
|
cssSource,
|
|
823
982
|
index,
|
|
824
|
-
score: 1
|
|
983
|
+
score: 1 + (typeof cssSource.file === "string" ? scoreTailwindV4CssSourceFileMatch(file, cssSource.file, sourceOptions) : 0)
|
|
825
984
|
};
|
|
826
985
|
}).filter((match) => Boolean(match)).sort((a, b) => b.score - a.score || a.index - b.index);
|
|
827
986
|
const bestScore = matches[0]?.score;
|
|
@@ -831,7 +990,7 @@ async function resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOpt
|
|
|
831
990
|
}
|
|
832
991
|
function tryResolveTailwindV4SourceOptions(runtimeState) {
|
|
833
992
|
try {
|
|
834
|
-
return
|
|
993
|
+
return resolveTailwindV4SourceOptionsFromRuntime(runtimeState.tailwindRuntime);
|
|
835
994
|
} catch {
|
|
836
995
|
return;
|
|
837
996
|
}
|
|
@@ -842,10 +1001,10 @@ function hasConfiguredTailwindV4CssSource(sourceOptions) {
|
|
|
842
1001
|
async function resolveSingleTailwindV4CssSource(cssSource, sourceOptions, options = {}) {
|
|
843
1002
|
const sourceBase = resolveTailwindV4CssSourceBase(cssSource, sourceOptions.base ?? sourceOptions.projectRoot ?? process.cwd());
|
|
844
1003
|
const normalizedCssSource = normalizeTailwindV4CssSourceConfig(cssSource, sourceBase);
|
|
845
|
-
return withGeneratorSourceMetadata(await resolveTailwindV4Source$1({
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
}), {
|
|
1004
|
+
return withGeneratorSourceMetadata(await resolveTailwindV4Source$1(createSingleTailwindV4SourceOptions(sourceOptions, {
|
|
1005
|
+
base: sourceBase,
|
|
1006
|
+
css: normalizedCssSource.css
|
|
1007
|
+
})), {
|
|
849
1008
|
matchedCssSourceFile: options.matched && typeof normalizedCssSource.file === "string" ? normalizedCssSource.file : void 0,
|
|
850
1009
|
sourceBase,
|
|
851
1010
|
sourceCss: normalizedCssSource.css
|
|
@@ -901,97 +1060,26 @@ async function resolveTailwindV4SourceSideEntrySource(resolvedEntrySource, sourc
|
|
|
901
1060
|
...resolvedSourceOptions,
|
|
902
1061
|
sourceFile: resolvedEntrySource.file
|
|
903
1062
|
});
|
|
904
|
-
const css =
|
|
1063
|
+
const css = createTailwindV4SourceReferenceSource(normalizeConfigDirective(prependConfigDirective(resolvedEntrySource.css, generatorOptions?.config), config), resolvedSourceOptions);
|
|
905
1064
|
return withMatchedSourceSideMetadata(await resolveTailwindV4Source$1(createSingleTailwindV4SourceOptions(resolvedSourceOptions, {
|
|
906
1065
|
base: resolvedEntrySource.base,
|
|
907
1066
|
css
|
|
908
1067
|
})), resolvedEntrySource);
|
|
909
1068
|
}
|
|
910
|
-
function
|
|
911
|
-
return {
|
|
912
|
-
...source,
|
|
913
|
-
__weappTailwindcssMeta: metadata
|
|
914
|
-
};
|
|
915
|
-
}
|
|
916
|
-
function resolveTailwindV3SourceEntries(source) {
|
|
917
|
-
if (!("version" in source) || source.version !== 3) return;
|
|
918
|
-
const entries = normalizeLegacyContentEntries(source.configObject?.content, source.cwd, { relativeBase: source.config ? path.dirname(source.config) : source.cwd });
|
|
919
|
-
return entries.length > 0 ? entries : void 0;
|
|
920
|
-
}
|
|
921
|
-
function withTailwindV3SourceMetadata(source) {
|
|
922
|
-
const sourceEntries = resolveTailwindV3SourceEntries(source);
|
|
923
|
-
return sourceEntries ? withGeneratorSourceMetadata(source, { sourceEntries }) : source;
|
|
924
|
-
}
|
|
925
|
-
function withMatchedSourceSideMetadata(source, resolvedEntrySource) {
|
|
926
|
-
return resolvedEntrySource.file ? withGeneratorSourceMetadata(source, {
|
|
927
|
-
matchedCssSourceFile: resolvedEntrySource.file,
|
|
928
|
-
sourceBase: resolvedEntrySource.base,
|
|
929
|
-
sourceCss: resolvedEntrySource.css
|
|
930
|
-
}) : source;
|
|
931
|
-
}
|
|
932
|
-
function createTailwindV4ApplyReferenceSource(css, sourceOptions) {
|
|
933
|
-
if (!hasTailwindApplyDirective(css) || hasTailwindRootDirectives(css)) return css;
|
|
934
|
-
const utilities = collectTailwindApplyUtilities(css);
|
|
935
|
-
return [
|
|
936
|
-
`@import "${sourceOptions.packageName ?? "tailwindcss"}" source(none);`,
|
|
937
|
-
utilities.length > 0 ? `@source inline(${JSON.stringify(utilities.join(" "))});` : void 0,
|
|
938
|
-
css
|
|
939
|
-
].filter(Boolean).join("\n");
|
|
940
|
-
}
|
|
941
|
-
function collectTailwindApplyUtilities(css) {
|
|
942
|
-
let root;
|
|
943
|
-
try {
|
|
944
|
-
root = postcss.parse(css);
|
|
945
|
-
} catch {
|
|
946
|
-
return [];
|
|
947
|
-
}
|
|
948
|
-
const utilities = /* @__PURE__ */ new Set();
|
|
949
|
-
root.walkAtRules("apply", (rule) => {
|
|
950
|
-
for (const utility of splitCandidateTokens(rule.params)) utilities.add(utility);
|
|
951
|
-
});
|
|
952
|
-
return [...utilities].sort();
|
|
953
|
-
}
|
|
954
|
-
async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions) {
|
|
1069
|
+
async function resolveGeneratorSource(_majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions) {
|
|
955
1070
|
const base = resolveCssSourceBase(file, cssHandlerOptions);
|
|
956
1071
|
const cssEntrySource = resolveCssEntrySource(rawSource, base, {
|
|
957
1072
|
importFallback: generatorOptions?.importFallback ?? false,
|
|
958
|
-
removeConfig:
|
|
1073
|
+
removeConfig: false
|
|
959
1074
|
});
|
|
960
1075
|
const applyEntrySource = hasTailwindApplyDirective(rawSource) ? {
|
|
961
1076
|
base,
|
|
962
1077
|
css: rawSource
|
|
963
1078
|
} : void 0;
|
|
964
|
-
if (majorVersion === 3) {
|
|
965
|
-
const sourceOptions = resolveTailwindV3SourceOptionsFromPatcher(runtimeState.twPatcher);
|
|
966
|
-
const mergedSourceOptions = omitUndefined({
|
|
967
|
-
...sourceOptions,
|
|
968
|
-
config: generatorOptions?.config ?? sourceOptions.config,
|
|
969
|
-
sourceFile: resolvePostcssSourceFile(cssHandlerOptions),
|
|
970
|
-
...resolveCssHandlerSourceOptions(cssHandlerOptions),
|
|
971
|
-
cssEntries: selectionOptions?.cssEntries,
|
|
972
|
-
cssSources: createCssEntrySources(selectionOptions?.cssEntries)
|
|
973
|
-
});
|
|
974
|
-
const sourceSideEntrySource = canResolveSourceSideCssEntry(file, cssHandlerOptions, mergedSourceOptions) ? resolveSourceSideCssEntrySource(file, mergedSourceOptions, { removeConfig: true }) : void 0;
|
|
975
|
-
const shouldPreferSourceSideEntry = shouldPreferResolvedSourceSideEntry(cssEntrySource, sourceSideEntrySource);
|
|
976
|
-
const resolvedEntrySource = shouldResolveSourceSideCssEntry(rawSource) ? shouldPreferSourceSideEntry ? sourceSideEntrySource ?? cssEntrySource ?? applyEntrySource : cssEntrySource ?? applyEntrySource ?? sourceSideEntrySource : shouldPreferTailwindV3SourceSideEntry(rawSource, sourceSideEntrySource) || shouldPreferSourceSideEntry ? sourceSideEntrySource ?? cssEntrySource ?? applyEntrySource : cssEntrySource ?? applyEntrySource ?? sourceSideEntrySource;
|
|
977
|
-
if (!resolvedEntrySource) return withTailwindV3SourceMetadata(await (generatorOptions?.config ? resolveTailwindV3Source(mergedSourceOptions) : resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher)));
|
|
978
|
-
if (cssEntrySource && !sourceSideEntrySource && !applyEntrySource && !hasTailwindRootDirectives(rawSource, { importFallback: true })) return withTailwindV3SourceMetadata(await (generatorOptions?.config ? resolveTailwindV3Source(mergedSourceOptions) : resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher)));
|
|
979
|
-
const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, omitUndefined(mergedSourceOptions));
|
|
980
|
-
const sourceWithMetadata = withTailwindV3SourceMetadata(await resolveTailwindV3Source({
|
|
981
|
-
...mergedSourceOptions,
|
|
982
|
-
base: resolvedEntrySource.base,
|
|
983
|
-
css: normalizeTailwindV3CssEntrySource(resolvedEntrySource.css),
|
|
984
|
-
...config ? { config } : {}
|
|
985
|
-
}));
|
|
986
|
-
return withGeneratorSourceMetadata(sourceWithMetadata, {
|
|
987
|
-
...sourceWithMetadata.__weappTailwindcssMeta,
|
|
988
|
-
matchedCssSourceFile: resolvedEntrySource.file
|
|
989
|
-
});
|
|
990
|
-
}
|
|
991
1079
|
const sourceOptions = tryResolveTailwindV4SourceOptions(runtimeState);
|
|
992
1080
|
const resolvedSourceOptions = sourceOptions ? omitUndefined({
|
|
993
1081
|
...sourceOptions,
|
|
994
|
-
sourceFile: resolvePostcssSourceFile(cssHandlerOptions),
|
|
1082
|
+
sourceFile: sourceOptions.sourceFile ?? resolvePostcssSourceFile(cssHandlerOptions),
|
|
995
1083
|
...resolveCssHandlerSourceOptions(cssHandlerOptions),
|
|
996
1084
|
cssEntries: selectionOptions?.cssEntries ?? sourceOptions.cssEntries,
|
|
997
1085
|
cssSources: mergeCssSources(sourceOptions.cssSources, sourceOptions.cssSources?.length ? void 0 : createCssEntrySources(selectionOptions?.cssEntries ?? sourceOptions.cssEntries))
|
|
@@ -1005,33 +1093,37 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
|
|
|
1005
1093
|
}));
|
|
1006
1094
|
}
|
|
1007
1095
|
const shouldPreferSourceSideEntry = shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder")) && (sourceOptions?.cssEntries?.length ?? 0) <= 1;
|
|
1008
|
-
const sourceSideEntrySource = normalizedSourceOptions && shouldPreferSourceSideEntry && canResolveSourceSideCssEntry(file, cssHandlerOptions, normalizedSourceOptions) ? resolveSourceSideCssEntrySource(file, normalizedSourceOptions, { removeConfig: false }) : void 0;
|
|
1096
|
+
const sourceSideEntrySource = normalizedSourceOptions && (shouldPreferSourceSideEntry || normalizedSourceOptions.sourceFile !== void 0) && canResolveSourceSideCssEntry(file, cssHandlerOptions, normalizedSourceOptions) ? resolveSourceSideCssEntrySource(file, normalizedSourceOptions, { removeConfig: false }) : void 0;
|
|
1009
1097
|
const matchedCssEntrySource = normalizedSourceOptions ? await resolveMatchingTailwindV4CssEntry(rawSource, file, normalizedSourceOptions) : void 0;
|
|
1010
1098
|
const matchedCssSource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, normalizedSourceOptions) : void 0;
|
|
1011
1099
|
const candidateMatchedCssSource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, normalizedSourceOptions, selectionOptions) : void 0;
|
|
1012
|
-
const
|
|
1100
|
+
const singleConfiguredCssSource = normalizedSourceOptions?.cssSources?.length === 1 ? await resolveSingleTailwindV4CssSource(normalizedSourceOptions.cssSources[0], normalizedSourceOptions, { matched: true }) : void 0;
|
|
1101
|
+
const configuredCssSource = normalizedSourceOptions && hasConfiguredTailwindV4CssSource(normalizedSourceOptions) && hasTailwindGeneratedCssMarkers(rawSource) ? matchedCssSource ?? candidateMatchedCssSource ?? singleConfiguredCssSource ?? await resolveTailwindV4Source$1(normalizedSourceOptions) : void 0;
|
|
1013
1102
|
if (configuredCssSource) return generatorOptions?.config ? {
|
|
1014
1103
|
...configuredCssSource,
|
|
1015
1104
|
css: prependConfigDirective(configuredCssSource.css, generatorOptions.config)
|
|
1016
1105
|
} : configuredCssSource;
|
|
1017
1106
|
const mainCssEntrySource = normalizedSourceOptions && cssHandlerOptions.isMainChunk && normalizedSourceOptions.cssEntries?.length === 1 ? await resolveTailwindV4CssEntrySource(normalizedSourceOptions.cssEntries[0], normalizedSourceOptions) : void 0;
|
|
1018
|
-
const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource ?? mainCssEntrySource;
|
|
1107
|
+
const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource ?? mainCssEntrySource ?? singleConfiguredCssSource;
|
|
1019
1108
|
if (preferredCssEntrySource) return generatorOptions?.config ? {
|
|
1020
1109
|
...preferredCssEntrySource,
|
|
1021
1110
|
css: prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
|
|
1022
1111
|
} : preferredCssEntrySource;
|
|
1023
1112
|
const resolvedEntrySource = sourceSideEntrySource ?? cssEntrySource ?? applyEntrySource;
|
|
1024
1113
|
if (!resolvedEntrySource) {
|
|
1025
|
-
const source = await
|
|
1114
|
+
const source = await resolveTailwindV4SourceFromRuntime(runtimeState.tailwindRuntime);
|
|
1026
1115
|
return generatorOptions?.config ? {
|
|
1027
1116
|
...source,
|
|
1028
1117
|
css: prependConfigDirective(source.css, generatorOptions.config)
|
|
1029
1118
|
} : source;
|
|
1030
1119
|
}
|
|
1031
1120
|
if (sourceSideEntrySource && normalizedSourceOptions) return resolveTailwindV4SourceSideEntrySource(sourceSideEntrySource, normalizedSourceOptions, generatorOptions, file);
|
|
1032
|
-
const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file,
|
|
1121
|
+
const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, omitUndefined({
|
|
1122
|
+
...resolvedSourceOptions ?? {},
|
|
1123
|
+
sourceFile: resolvedEntrySource.file ?? resolvedSourceOptions?.sourceFile ?? resolvePostcssSourceFile(cssHandlerOptions)
|
|
1124
|
+
}));
|
|
1033
1125
|
const sourceBase = resolvedEntrySource === cssEntrySource && config ? path.dirname(config) : resolvedEntrySource.base;
|
|
1034
|
-
const css =
|
|
1126
|
+
const css = createTailwindV4SourceReferenceSource(normalizeConfigDirective(prependConfigDirective(resolvedEntrySource.css, generatorOptions?.config), config), normalizedSourceOptions ?? {});
|
|
1035
1127
|
return resolveTailwindV4Source$1(createSingleTailwindV4SourceOptions(normalizedSourceOptions ?? {}, {
|
|
1036
1128
|
base: sourceBase,
|
|
1037
1129
|
css
|
|
@@ -1040,83 +1132,583 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
|
|
|
1040
1132
|
async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions) {
|
|
1041
1133
|
const cssEntrySource = resolveCssEntrySource(rawSource, resolveCssSourceBase(file, cssHandlerOptions), {
|
|
1042
1134
|
importFallback: generatorOptions?.importFallback ?? false,
|
|
1043
|
-
removeConfig:
|
|
1135
|
+
removeConfig: false
|
|
1044
1136
|
});
|
|
1045
|
-
if (
|
|
1137
|
+
if (cssEntrySource && !cssHandlerOptions.isMainChunk || !cssHandlerOptions.isMainChunk && hasTailwindApplyDirective(rawSource) && !hasTailwindRootDirectives(rawSource, { importFallback: generatorOptions?.importFallback ?? false })) {
|
|
1046
1138
|
const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
|
|
1047
1139
|
return resolved ? [resolved] : [];
|
|
1048
1140
|
}
|
|
1049
1141
|
let sourceOptions;
|
|
1050
1142
|
try {
|
|
1051
|
-
const
|
|
1052
|
-
const cssEntries = selectionOptions?.cssEntries ??
|
|
1143
|
+
const sourceOptionsFromRuntime = resolveTailwindV4SourceOptionsFromRuntime(runtimeState.tailwindRuntime);
|
|
1144
|
+
const cssEntries = selectionOptions?.cssEntries ?? sourceOptionsFromRuntime.cssEntries;
|
|
1145
|
+
const runtimeCssSources = selectionOptions?.cssEntries ? void 0 : sourceOptionsFromRuntime.cssSources;
|
|
1053
1146
|
sourceOptions = omitUndefined({
|
|
1054
|
-
...
|
|
1147
|
+
...sourceOptionsFromRuntime,
|
|
1055
1148
|
sourceFile: resolvePostcssSourceFile(cssHandlerOptions),
|
|
1056
1149
|
...resolveCssHandlerSourceOptions(cssHandlerOptions),
|
|
1057
1150
|
cssEntries,
|
|
1058
|
-
cssSources: mergeCssSources(
|
|
1151
|
+
cssSources: mergeCssSources(mergeCssSources(runtimeCssSources, selectionOptions?.cssSources), void 0)
|
|
1152
|
+
});
|
|
1153
|
+
} catch {
|
|
1154
|
+
const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
|
|
1155
|
+
return resolved ? [resolved] : [];
|
|
1156
|
+
}
|
|
1157
|
+
const matchedCssEntrySource = sourceOptions ? await resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) : void 0;
|
|
1158
|
+
if (matchedCssEntrySource) return [normalizeResolvedTailwindV4SourceConfig(generatorOptions?.config ? {
|
|
1159
|
+
...matchedCssEntrySource,
|
|
1160
|
+
css: prependConfigDirective(matchedCssEntrySource.css, generatorOptions.config)
|
|
1161
|
+
} : matchedCssEntrySource, matchedCssEntrySource.__weappTailwindcssMeta?.matchedCssSourceFile, sourceOptions)];
|
|
1162
|
+
const sourceSideCssSource = await resolveTailwindV4SourceSideEntrySource(canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) ? resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: false }) : void 0, sourceOptions, generatorOptions, file);
|
|
1163
|
+
if (sourceSideCssSource) return [sourceSideCssSource];
|
|
1164
|
+
const matchedCssSource = await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions);
|
|
1165
|
+
const candidateMatchedCssSource = await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, sourceOptions, selectionOptions);
|
|
1166
|
+
const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource;
|
|
1167
|
+
if (preferredCssEntrySource) return [normalizeResolvedTailwindV4SourceConfig(generatorOptions?.config ? {
|
|
1168
|
+
...preferredCssEntrySource,
|
|
1169
|
+
css: prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
|
|
1170
|
+
} : preferredCssEntrySource, preferredCssEntrySource.__weappTailwindcssMeta?.matchedCssSourceFile, sourceOptions)];
|
|
1171
|
+
if (!sourceOptions.cssEntries || sourceOptions.cssEntries.length <= 1) {
|
|
1172
|
+
if (cssHandlerOptions.isMainChunk && sourceOptions.cssEntries?.length === 1) return [await resolveTailwindV4CssEntrySource(sourceOptions.cssEntries[0], normalizeTailwindV4CssSourceConfigs(sourceOptions)).then((source) => generatorOptions?.config ? {
|
|
1173
|
+
...source,
|
|
1174
|
+
css: prependConfigDirective(source.css, generatorOptions.config)
|
|
1175
|
+
} : source)];
|
|
1176
|
+
if (sourceOptions.cssSources?.length === 1) return [normalizeResolvedTailwindV4SourceConfig(await createTailwindV4CssSourceResolver(sourceOptions, generatorOptions)(sourceOptions.cssSources[0]), sourceOptions.cssSources[0]?.file, sourceOptions)];
|
|
1177
|
+
const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
|
|
1178
|
+
return resolved ? [resolved] : [];
|
|
1179
|
+
}
|
|
1180
|
+
if (cssHandlerOptions.isMainChunk && !cssEntrySource && !hasTailwindGeneratedCss(rawSource) && !hasTailwindGeneratedCssMarkers(rawSource) && !hasTailwindSourceDirectives(rawSource, { importFallback: generatorOptions?.importFallback ?? false }) && !rawSource.includes("weapp-tailwindcss generator-placeholder") && !hasConfiguredTailwindV4CssSource(sourceOptions)) {
|
|
1181
|
+
const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
|
|
1182
|
+
return resolved ? [resolved] : [];
|
|
1183
|
+
}
|
|
1184
|
+
const normalizedCssSourceOptions = normalizeTailwindV4CssSourceConfigs(sourceOptions);
|
|
1185
|
+
const cssEntrySources = await Promise.all(sourceOptions.cssEntries.map((cssEntry) => resolveTailwindV4CssEntrySource(cssEntry, normalizedCssSourceOptions).then((source) => generatorOptions?.config ? {
|
|
1186
|
+
...source,
|
|
1187
|
+
css: prependConfigDirective(source.css, generatorOptions.config)
|
|
1188
|
+
} : source)));
|
|
1189
|
+
const cssSources = sourceOptions.cssSources?.length ? await Promise.all(sourceOptions.cssSources.map(createTailwindV4CssSourceResolver(sourceOptions, generatorOptions))) : [];
|
|
1190
|
+
return [...cssEntrySources, ...cssSources];
|
|
1191
|
+
}
|
|
1192
|
+
async function resolveGeneratorSourceEntries(source, runtimeState) {
|
|
1193
|
+
const sourceMetadata = source.__weappTailwindcssMeta;
|
|
1194
|
+
if (sourceMetadata?.sourceEntries) return sourceMetadata.sourceEntries;
|
|
1195
|
+
if (!("css" in source) || !("base" in source) || !("baseFallbacks" in source)) return;
|
|
1196
|
+
const resolved = await resolveTailwindV4EntriesFromCss(sourceMetadata?.sourceCss ?? source.css, sourceMetadata?.sourceBase ?? source.base);
|
|
1197
|
+
if (resolved?.entries.length === 0 && !resolved.inlineCandidates.included.size && !resolved.inlineCandidates.excluded.size && !resolved.dependencies.length) {
|
|
1198
|
+
if (sourceMetadata?.matchedCssSourceFile) return [];
|
|
1199
|
+
return;
|
|
1200
|
+
}
|
|
1201
|
+
if (resolved?.entries.length || !resolved?.explicit && !sourceMetadata?.matchedCssSourceFile || !runtimeState) return resolved?.entries;
|
|
1202
|
+
const matchingCssSource = tryResolveTailwindV4SourceOptions(runtimeState)?.cssSources?.find((cssSource) => {
|
|
1203
|
+
if (sourceMetadata?.matchedCssSourceFile && typeof cssSource.file === "string" && path.resolve(cssSource.file) === path.resolve(sourceMetadata.matchedCssSourceFile)) return true;
|
|
1204
|
+
return cssSource.css === source.css;
|
|
1205
|
+
});
|
|
1206
|
+
if (!matchingCssSource) return resolved?.entries;
|
|
1207
|
+
const sourceResolved = await resolveTailwindV4EntriesFromCss(matchingCssSource.css, typeof matchingCssSource.base === "string" && matchingCssSource.base.length > 0 ? matchingCssSource.base : typeof matchingCssSource.file === "string" && matchingCssSource.file.length > 0 ? path.dirname(matchingCssSource.file) : source.base);
|
|
1208
|
+
if (sourceResolved?.entries.length) return sourceResolved.entries;
|
|
1209
|
+
for (const dependency of matchingCssSource.dependencies ?? []) {
|
|
1210
|
+
if (!existsSync(dependency)) continue;
|
|
1211
|
+
try {
|
|
1212
|
+
const dependencyResolved = await resolveTailwindV4EntriesFromCss(readFileSync(dependency, "utf8"), path.dirname(dependency));
|
|
1213
|
+
if (dependencyResolved?.entries.length) return dependencyResolved.entries;
|
|
1214
|
+
} catch {}
|
|
1215
|
+
}
|
|
1216
|
+
return resolved?.entries;
|
|
1217
|
+
}
|
|
1218
|
+
//#endregion
|
|
1219
|
+
//#region src/bundlers/shared/generator-css/user-css.ts
|
|
1220
|
+
const TAILWIND_V4_GENERATOR_AT_RULES = new Set([
|
|
1221
|
+
"config",
|
|
1222
|
+
"custom-variant",
|
|
1223
|
+
"plugin",
|
|
1224
|
+
"source",
|
|
1225
|
+
"theme",
|
|
1226
|
+
"utility",
|
|
1227
|
+
"variant"
|
|
1228
|
+
]);
|
|
1229
|
+
function removeBalancedAtRuleBlock(source, atRuleStart) {
|
|
1230
|
+
const blockStart = source.indexOf("{", atRuleStart);
|
|
1231
|
+
if (blockStart === -1) {
|
|
1232
|
+
const semicolon = source.indexOf(";", atRuleStart);
|
|
1233
|
+
return semicolon === -1 ? source.slice(0, atRuleStart) : `${source.slice(0, atRuleStart)}${source.slice(semicolon + 1)}`;
|
|
1234
|
+
}
|
|
1235
|
+
let depth = 0;
|
|
1236
|
+
for (let index = blockStart; index < source.length; index++) {
|
|
1237
|
+
const char = source[index];
|
|
1238
|
+
if (char === "{") {
|
|
1239
|
+
depth++;
|
|
1240
|
+
continue;
|
|
1241
|
+
}
|
|
1242
|
+
if (char !== "}") continue;
|
|
1243
|
+
depth--;
|
|
1244
|
+
if (depth === 0) return `${source.slice(0, atRuleStart)}${source.slice(index + 1)}`;
|
|
1245
|
+
}
|
|
1246
|
+
return source.slice(0, atRuleStart);
|
|
1247
|
+
}
|
|
1248
|
+
function removeTailwindV4GeneratorAtRulesFallback(source) {
|
|
1249
|
+
let next = source;
|
|
1250
|
+
let changed = false;
|
|
1251
|
+
const sourceMediaRE = /@media\s+source\([^)]*\)\s*\{/g;
|
|
1252
|
+
for (;;) {
|
|
1253
|
+
sourceMediaRE.lastIndex = 0;
|
|
1254
|
+
const match = sourceMediaRE.exec(next);
|
|
1255
|
+
if (!match) break;
|
|
1256
|
+
next = removeBalancedAtRuleBlock(next, match.index);
|
|
1257
|
+
changed = true;
|
|
1258
|
+
}
|
|
1259
|
+
const atRuleRE = /@(?:config|custom-variant|plugin|source|theme|utility|variant)\b/g;
|
|
1260
|
+
for (;;) {
|
|
1261
|
+
atRuleRE.lastIndex = 0;
|
|
1262
|
+
const match = atRuleRE.exec(next);
|
|
1263
|
+
if (!match) break;
|
|
1264
|
+
next = removeBalancedAtRuleBlock(next, match.index);
|
|
1265
|
+
changed = true;
|
|
1266
|
+
}
|
|
1267
|
+
return changed ? next : source;
|
|
1268
|
+
}
|
|
1269
|
+
function isTailwindGeneratedPreflightComment(text) {
|
|
1270
|
+
return text.includes("cssremedy") || text.includes("Use the user's configured") || text.includes("tailwindlabs/tailwindcss") || text.includes("Prevent padding and border from affecting element width") || text.includes("Remove default margins and padding") || text.includes("Deprecated") || text.includes("Reset all borders") || text.includes("Add the correct text decoration") || text.includes("Make elements with the HTML hidden attribute stay hidden") || text.includes("Inherit font styles in all browsers") || text.includes("Add the correct height in Firefox") || text.includes("Remove the default font size and weight for headings") || text.includes("Reset links to optimize for opt-in styling") || text.includes("Add the correct font weight in Edge and Safari") || text.includes("Use the user's configured `mono` font-family") || text.includes("Add the correct font size in all browsers") || text.includes("Prevent `sub` and `sup` elements from affecting the line height") || text.includes("Remove text indentation from table contents") || text.includes("Use the modern Firefox focus style") || text.includes("Add the correct vertical alignment") || text.includes("Add the correct display") || text.includes("Make lists unstyled by default") || text.includes("Make replaced elements `display: block` by default") || text.includes("Constrain images and videos to the parent width") || text.includes("Restore default font weight") || text.includes("Restore indentation") || text.includes("Restore space after button") || text.includes("Prevent resizing textareas horizontally") || text.includes("Remove the inner padding in Chrome and Safari") || text.includes("Ensure date/time inputs have the same height") || text.includes("Prevent height from changing on date/time inputs") || text.includes("Remove excess padding from pseudo-elements") || text.includes("Center dropdown marker shown on inputs") || text.includes("Remove the additional `:invalid` styles") || text.includes("Correct the inability to style the border radius") || text.includes("Correct the cursor style of increment and decrement buttons");
|
|
1271
|
+
}
|
|
1272
|
+
function isTailwindGeneratedThemeRule(selector, node) {
|
|
1273
|
+
if (!/(?:^|,)\s*(?::host|page|\.tw-root|wx-root-portal-content)\b/.test(selector)) return false;
|
|
1274
|
+
return node.nodes?.some((child) => child.type === "decl" && /^--(?:color|spacing|text|font|default|radius|tw-)/.test(child.prop)) ?? false;
|
|
1275
|
+
}
|
|
1276
|
+
function isTailwindGeneratedPreflightRule(selector, node) {
|
|
1277
|
+
if (selector === "view,text,::after,::before" || selector === "view, text, ::after, ::before" || selector === "*" || selector === "::after" || selector === "::before" || selector === "::backdrop" || selector === ":host" || selector === "[hidden]:not([hidden=\"until-found\"])" || selector === "[hidden]:not([hidden='until-found'])" || selector === "button,input[type=\"button\"],input[type=\"reset\"],input[type=\"submit\"]" || selector === "button, input[type=\"button\"], input[type=\"reset\"], input[type=\"submit\"]" || selector === "button,input[type='button'],input[type='reset'],input[type='submit']" || selector === "button, input[type='button'], input[type='reset'], input[type='submit']") return true;
|
|
1278
|
+
if (selector === "abbr[title]") return node.nodes?.some((child) => child.type === "decl" && child.prop === "text-decoration") ?? false;
|
|
1279
|
+
if (selector === ":host") return node.nodes?.some((child) => child.type === "decl" && child.value?.includes("--theme(")) ?? false;
|
|
1280
|
+
return false;
|
|
1281
|
+
}
|
|
1282
|
+
function removeTailwindV4GeneratedUserCssArtifacts(source) {
|
|
1283
|
+
try {
|
|
1284
|
+
const root = postcss.parse(source);
|
|
1285
|
+
let changed = false;
|
|
1286
|
+
root.walkComments((comment) => {
|
|
1287
|
+
if (!isTailwindGeneratedPreflightComment(comment.text)) return;
|
|
1288
|
+
comment.remove();
|
|
1289
|
+
changed = true;
|
|
1290
|
+
});
|
|
1291
|
+
root.walkRules((rule) => {
|
|
1292
|
+
const selector = rule.selector.replace(/\s+/g, " ").trim();
|
|
1293
|
+
if (isTailwindGeneratedThemeRule(selector, rule) || isTailwindGeneratedPreflightRule(selector, rule)) {
|
|
1294
|
+
rule.remove();
|
|
1295
|
+
changed = true;
|
|
1296
|
+
}
|
|
1297
|
+
});
|
|
1298
|
+
root.walkAtRules((rule) => {
|
|
1299
|
+
if (rule.nodes !== void 0 && rule.nodes.length === 0) {
|
|
1300
|
+
rule.remove();
|
|
1301
|
+
changed = true;
|
|
1302
|
+
}
|
|
1303
|
+
});
|
|
1304
|
+
return changed ? root.toString() : source;
|
|
1305
|
+
} catch {
|
|
1306
|
+
return source;
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
function removeTailwindSourceMediaBlocks(source) {
|
|
1310
|
+
let next = source;
|
|
1311
|
+
let changed = false;
|
|
1312
|
+
const sourceMediaRE = /@media\s+source\([^)]*\)\s*\{/g;
|
|
1313
|
+
for (;;) {
|
|
1314
|
+
sourceMediaRE.lastIndex = 0;
|
|
1315
|
+
const match = sourceMediaRE.exec(next);
|
|
1316
|
+
if (!match) break;
|
|
1317
|
+
const blockStart = next.indexOf("{", match.index);
|
|
1318
|
+
if (blockStart === -1) break;
|
|
1319
|
+
let depth = 0;
|
|
1320
|
+
let blockEnd = -1;
|
|
1321
|
+
for (let index = blockStart; index < next.length; index++) {
|
|
1322
|
+
const char = next[index];
|
|
1323
|
+
if (char === "{") {
|
|
1324
|
+
depth++;
|
|
1325
|
+
continue;
|
|
1326
|
+
}
|
|
1327
|
+
if (char !== "}") continue;
|
|
1328
|
+
depth--;
|
|
1329
|
+
if (depth === 0) {
|
|
1330
|
+
blockEnd = index;
|
|
1331
|
+
break;
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
if (blockEnd === -1) break;
|
|
1335
|
+
next = `${next.slice(0, match.index)}${next.slice(blockEnd + 1)}`;
|
|
1336
|
+
changed = true;
|
|
1337
|
+
}
|
|
1338
|
+
for (;;) {
|
|
1339
|
+
const atRuleStart = findTailwindSourceWrapperBlockStart(next);
|
|
1340
|
+
if (atRuleStart === -1) break;
|
|
1341
|
+
next = removeBalancedAtRuleBlock(next, atRuleStart);
|
|
1342
|
+
changed = true;
|
|
1343
|
+
}
|
|
1344
|
+
return changed ? next : source;
|
|
1345
|
+
}
|
|
1346
|
+
function terminateTailwindSourceAtRulesBeforeNextDirective(source) {
|
|
1347
|
+
if (!source.includes("@source")) return source;
|
|
1348
|
+
let next = "";
|
|
1349
|
+
let searchIndex = 0;
|
|
1350
|
+
for (;;) {
|
|
1351
|
+
const atRuleStart = source.indexOf("@source", searchIndex);
|
|
1352
|
+
if (atRuleStart === -1) {
|
|
1353
|
+
next += source.slice(searchIndex);
|
|
1354
|
+
break;
|
|
1355
|
+
}
|
|
1356
|
+
const nextChar = source[atRuleStart + 7];
|
|
1357
|
+
if (nextChar && /[\w-]/.test(nextChar)) {
|
|
1358
|
+
next += source.slice(searchIndex, atRuleStart + 7);
|
|
1359
|
+
searchIndex = atRuleStart + 7;
|
|
1360
|
+
continue;
|
|
1361
|
+
}
|
|
1362
|
+
next += source.slice(searchIndex, atRuleStart);
|
|
1363
|
+
let quote;
|
|
1364
|
+
let parenDepth = 0;
|
|
1365
|
+
let terminated = false;
|
|
1366
|
+
let index = atRuleStart + 7;
|
|
1367
|
+
for (; index < source.length; index++) {
|
|
1368
|
+
const char = source[index];
|
|
1369
|
+
if (quote) {
|
|
1370
|
+
if (char === "\\") {
|
|
1371
|
+
index++;
|
|
1372
|
+
continue;
|
|
1373
|
+
}
|
|
1374
|
+
if (char === quote) quote = void 0;
|
|
1375
|
+
continue;
|
|
1376
|
+
}
|
|
1377
|
+
if (char === "\"" || char === "'") {
|
|
1378
|
+
quote = char;
|
|
1379
|
+
continue;
|
|
1380
|
+
}
|
|
1381
|
+
if (char === "(") {
|
|
1382
|
+
parenDepth++;
|
|
1383
|
+
continue;
|
|
1384
|
+
}
|
|
1385
|
+
if (char === ")" && parenDepth > 0) {
|
|
1386
|
+
parenDepth--;
|
|
1387
|
+
continue;
|
|
1388
|
+
}
|
|
1389
|
+
if (parenDepth > 0) continue;
|
|
1390
|
+
if (char === ";" || char === "{") {
|
|
1391
|
+
terminated = true;
|
|
1392
|
+
index++;
|
|
1393
|
+
break;
|
|
1394
|
+
}
|
|
1395
|
+
if (char === "@" && /^(?:config|custom-variant|plugin|source|theme|utility|variant)\b/.test(source.slice(index + 1))) break;
|
|
1396
|
+
}
|
|
1397
|
+
const segment = source.slice(atRuleStart, index);
|
|
1398
|
+
const trimmedSegment = segment.trimEnd();
|
|
1399
|
+
next += terminated || trimmedSegment.endsWith(";") || trimmedSegment.endsWith("{") ? segment : `${trimmedSegment};${segment.slice(trimmedSegment.length)}`;
|
|
1400
|
+
searchIndex = index;
|
|
1401
|
+
}
|
|
1402
|
+
return next;
|
|
1403
|
+
}
|
|
1404
|
+
function findTailwindSourceWrapperBlockStart(source) {
|
|
1405
|
+
let searchIndex = 0;
|
|
1406
|
+
for (;;) {
|
|
1407
|
+
const atRuleStart = source.indexOf("@source", searchIndex);
|
|
1408
|
+
if (atRuleStart === -1) return -1;
|
|
1409
|
+
const nextChar = source[atRuleStart + 7];
|
|
1410
|
+
if (nextChar && /[\w-]/.test(nextChar)) {
|
|
1411
|
+
searchIndex = atRuleStart + 7;
|
|
1412
|
+
continue;
|
|
1413
|
+
}
|
|
1414
|
+
let quote;
|
|
1415
|
+
let parenDepth = 0;
|
|
1416
|
+
for (let index = atRuleStart + 7; index < source.length; index++) {
|
|
1417
|
+
const char = source[index];
|
|
1418
|
+
if (quote) {
|
|
1419
|
+
if (char === "\\") {
|
|
1420
|
+
index++;
|
|
1421
|
+
continue;
|
|
1422
|
+
}
|
|
1423
|
+
if (char === quote) quote = void 0;
|
|
1424
|
+
continue;
|
|
1425
|
+
}
|
|
1426
|
+
if (char === "\"" || char === "'") {
|
|
1427
|
+
quote = char;
|
|
1428
|
+
continue;
|
|
1429
|
+
}
|
|
1430
|
+
if (char === "(") {
|
|
1431
|
+
parenDepth++;
|
|
1432
|
+
continue;
|
|
1433
|
+
}
|
|
1434
|
+
if (char === ")" && parenDepth > 0) {
|
|
1435
|
+
parenDepth--;
|
|
1436
|
+
continue;
|
|
1437
|
+
}
|
|
1438
|
+
if (parenDepth > 0) continue;
|
|
1439
|
+
if (char === ";") {
|
|
1440
|
+
searchIndex = index + 1;
|
|
1441
|
+
break;
|
|
1442
|
+
}
|
|
1443
|
+
if (char === "{") return atRuleStart;
|
|
1444
|
+
}
|
|
1445
|
+
if (searchIndex <= atRuleStart) return -1;
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
function removeTailwindApplyAtRules(source) {
|
|
1449
|
+
if (!source.includes("@apply")) return source;
|
|
1450
|
+
try {
|
|
1451
|
+
const root = postcss.parse(source);
|
|
1452
|
+
let changed = false;
|
|
1453
|
+
root.walkAtRules("apply", (rule) => {
|
|
1454
|
+
rule.remove();
|
|
1455
|
+
changed = true;
|
|
1059
1456
|
});
|
|
1457
|
+
root.walk((node) => {
|
|
1458
|
+
if ("nodes" in node && node.nodes?.length === 0) node.remove();
|
|
1459
|
+
});
|
|
1460
|
+
return changed ? root.toString() : source;
|
|
1461
|
+
} catch {
|
|
1462
|
+
return source;
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
function removeTailwindV4GeneratorAtRules(source) {
|
|
1466
|
+
try {
|
|
1467
|
+
const root = postcss.parse(source);
|
|
1468
|
+
let changed = false;
|
|
1469
|
+
root.walkAtRules((rule) => {
|
|
1470
|
+
if (rule.name === "media" && /^source\(/.test(rule.params.trim())) {
|
|
1471
|
+
rule.remove();
|
|
1472
|
+
changed = true;
|
|
1473
|
+
return;
|
|
1474
|
+
}
|
|
1475
|
+
if (!TAILWIND_V4_GENERATOR_AT_RULES.has(rule.name)) return;
|
|
1476
|
+
rule.remove();
|
|
1477
|
+
changed = true;
|
|
1478
|
+
});
|
|
1479
|
+
return changed ? root.toString() : source;
|
|
1480
|
+
} catch {
|
|
1481
|
+
return removeTailwindV4GeneratorAtRulesFallback(source);
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
function isCommentOnlyCss(source) {
|
|
1485
|
+
try {
|
|
1486
|
+
const root = postcss.parse(source);
|
|
1487
|
+
return root.nodes.length > 0 && root.nodes.every((node) => node.type === "comment");
|
|
1488
|
+
} catch {
|
|
1489
|
+
return false;
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
function removeMiniProgramHoverSelectors(source, enabled = true) {
|
|
1493
|
+
if (!enabled || !source.includes(":hover")) return source;
|
|
1494
|
+
try {
|
|
1495
|
+
const root = postcss.parse(source);
|
|
1496
|
+
let changed = false;
|
|
1497
|
+
root.walkRules((rule) => {
|
|
1498
|
+
const selectors = rule.selectors ?? [rule.selector];
|
|
1499
|
+
const keptSelectors = selectors.filter((selector) => !selector.includes(":hover"));
|
|
1500
|
+
if (keptSelectors.length === selectors.length) return;
|
|
1501
|
+
changed = true;
|
|
1502
|
+
if (keptSelectors.length === 0) {
|
|
1503
|
+
rule.remove();
|
|
1504
|
+
return;
|
|
1505
|
+
}
|
|
1506
|
+
rule.selectors = keptSelectors;
|
|
1507
|
+
});
|
|
1508
|
+
root.walk((node) => {
|
|
1509
|
+
if ("nodes" in node && node.nodes?.length === 0) {
|
|
1510
|
+
node.remove();
|
|
1511
|
+
changed = true;
|
|
1512
|
+
}
|
|
1513
|
+
});
|
|
1514
|
+
return changed ? root.toString() : source;
|
|
1515
|
+
} catch {
|
|
1516
|
+
return source;
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
function removeProcessedMiniProgramUnsupportedCss(source, options) {
|
|
1520
|
+
return removeMiniProgramHoverSelectors(removeUnsupportedMiniProgramAtRules(source), options.cssRemoveHoverPseudoClass);
|
|
1521
|
+
}
|
|
1522
|
+
function unwrapMiniProgramCascadeLayers(source) {
|
|
1523
|
+
if (!source.includes("@layer")) return source;
|
|
1524
|
+
try {
|
|
1525
|
+
const root = postcss.parse(source);
|
|
1526
|
+
removeUnsupportedCascadeLayers(root);
|
|
1527
|
+
return root.toString();
|
|
1528
|
+
} catch {
|
|
1529
|
+
return source;
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
function stripTailwindSourceMediaFragments(source) {
|
|
1533
|
+
let removedSourceMediaStart = false;
|
|
1534
|
+
return terminateTailwindSourceAtRulesBeforeNextDirective(removeTailwindSourceMediaBlocks(source)).split(/\r?\n/).filter((line) => {
|
|
1535
|
+
if (/^\s*@media\s+source\([^)]*\)\s*\{\s*$/.test(line)) {
|
|
1536
|
+
removedSourceMediaStart = true;
|
|
1537
|
+
return false;
|
|
1538
|
+
}
|
|
1539
|
+
if (/^\s*\}\s*\/\*\s*source\([^)]*\)\s*\*\/\s*$/.test(line)) return false;
|
|
1540
|
+
if (removedSourceMediaStart && /^\s*\}\s*$/.test(line)) {
|
|
1541
|
+
removedSourceMediaStart = false;
|
|
1542
|
+
return false;
|
|
1543
|
+
}
|
|
1544
|
+
return true;
|
|
1545
|
+
}).join("\n");
|
|
1546
|
+
}
|
|
1547
|
+
function stripLeadingTailwindSourceMediaCloseFragment(source) {
|
|
1548
|
+
return source.replace(/^\s*\}\s*(?:\n|$)/, "");
|
|
1549
|
+
}
|
|
1550
|
+
function stripUnmatchedTailwindSourceMediaCloseFragments(source) {
|
|
1551
|
+
try {
|
|
1552
|
+
postcss.parse(source);
|
|
1553
|
+
return source;
|
|
1554
|
+
} catch {
|
|
1555
|
+
return stripLeadingTailwindSourceMediaCloseFragment(source).replace(/\s*\}\s*$/, "");
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
function splitUserCssLayerBlocks(source) {
|
|
1559
|
+
if (!source.includes("@layer")) return {
|
|
1560
|
+
layer: "",
|
|
1561
|
+
rest: source
|
|
1562
|
+
};
|
|
1563
|
+
try {
|
|
1564
|
+
const root = postcss.parse(source);
|
|
1565
|
+
const layerRoot = postcss.root();
|
|
1566
|
+
const restRoot = postcss.root();
|
|
1567
|
+
for (const node of root.nodes) (node.type === "atrule" && node.name === "layer" && node.nodes?.length ? layerRoot : restRoot).append(node.clone());
|
|
1568
|
+
return {
|
|
1569
|
+
layer: layerRoot.toString(),
|
|
1570
|
+
rest: restRoot.toString()
|
|
1571
|
+
};
|
|
1572
|
+
} catch {
|
|
1573
|
+
return {
|
|
1574
|
+
layer: source,
|
|
1575
|
+
rest: ""
|
|
1576
|
+
};
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
function hasUserCssLayerBlocks(source) {
|
|
1580
|
+
if (!source.includes("@layer")) return false;
|
|
1581
|
+
try {
|
|
1582
|
+
let hasLayerBlock = false;
|
|
1583
|
+
postcss.parse(source).walkAtRules("layer", (node) => {
|
|
1584
|
+
if (node.nodes?.length) hasLayerBlock = true;
|
|
1585
|
+
});
|
|
1586
|
+
return hasLayerBlock;
|
|
1587
|
+
} catch {
|
|
1588
|
+
return true;
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
function collectUserLayerSelectors(source) {
|
|
1592
|
+
const selectors = /* @__PURE__ */ new Set();
|
|
1593
|
+
try {
|
|
1594
|
+
postcss.parse(source).walkRules((rule) => {
|
|
1595
|
+
for (const selector of rule.selectors ?? [rule.selector]) {
|
|
1596
|
+
const normalized = selector.trim();
|
|
1597
|
+
if (normalized) selectors.add(normalized);
|
|
1598
|
+
}
|
|
1599
|
+
});
|
|
1600
|
+
} catch {}
|
|
1601
|
+
return selectors;
|
|
1602
|
+
}
|
|
1603
|
+
function matchesUserLayerSelector(selector, userLayerSelector) {
|
|
1604
|
+
if (selector === userLayerSelector) return true;
|
|
1605
|
+
if (!selector.startsWith(userLayerSelector)) return false;
|
|
1606
|
+
const next = selector[userLayerSelector.length];
|
|
1607
|
+
return next === ":" || next === "[";
|
|
1608
|
+
}
|
|
1609
|
+
function extractGeneratedCssForUserLayerSelectors(css, userLayerSource) {
|
|
1610
|
+
const selectors = collectUserLayerSelectors(userLayerSource);
|
|
1611
|
+
if (selectors.size === 0) return {
|
|
1612
|
+
layer: "",
|
|
1613
|
+
rest: css
|
|
1614
|
+
};
|
|
1615
|
+
try {
|
|
1616
|
+
const root = postcss.parse(css);
|
|
1617
|
+
const layerRoot = postcss.root();
|
|
1618
|
+
const selectorList = [...selectors];
|
|
1619
|
+
root.walkRules((rule) => {
|
|
1620
|
+
if ((rule.selectors ?? [rule.selector]).some((selector) => selectorList.some((userSelector) => matchesUserLayerSelector(selector.trim(), userSelector)))) {
|
|
1621
|
+
layerRoot.append(rule.clone());
|
|
1622
|
+
rule.remove();
|
|
1623
|
+
}
|
|
1624
|
+
});
|
|
1625
|
+
return {
|
|
1626
|
+
layer: layerRoot.toString(),
|
|
1627
|
+
rest: root.toString()
|
|
1628
|
+
};
|
|
1629
|
+
} catch {
|
|
1630
|
+
return {
|
|
1631
|
+
layer: "",
|
|
1632
|
+
rest: css
|
|
1633
|
+
};
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1636
|
+
function normalizeGeneratedSelector(selector) {
|
|
1637
|
+
return selector.replace(/:not\(#\\#\)/g, "").trim();
|
|
1638
|
+
}
|
|
1639
|
+
function collectApplyOnlySourceSelectors(source) {
|
|
1640
|
+
const selectors = /* @__PURE__ */ new Set();
|
|
1641
|
+
try {
|
|
1642
|
+
postcss.parse(source).walkRules((rule) => {
|
|
1643
|
+
if (!rule.nodes?.some((node) => node.type === "atrule" && node.name === "apply")) return;
|
|
1644
|
+
for (const selector of rule.selectors ?? [rule.selector]) {
|
|
1645
|
+
const normalized = normalizeGeneratedSelector(selector);
|
|
1646
|
+
if (normalized) selectors.add(normalized);
|
|
1647
|
+
}
|
|
1648
|
+
});
|
|
1649
|
+
} catch {}
|
|
1650
|
+
return selectors;
|
|
1651
|
+
}
|
|
1652
|
+
function hasOnlyApplyBackedSourceRules(source) {
|
|
1653
|
+
let hasApplyRule = false;
|
|
1654
|
+
let hasNonApplyRule = false;
|
|
1655
|
+
try {
|
|
1656
|
+
postcss.parse(source).walkRules((rule) => {
|
|
1657
|
+
if (rule.nodes?.some((node) => node.type === "atrule" && node.name === "apply")) hasApplyRule = true;
|
|
1658
|
+
else hasNonApplyRule = true;
|
|
1659
|
+
});
|
|
1660
|
+
} catch {
|
|
1661
|
+
return false;
|
|
1662
|
+
}
|
|
1663
|
+
return hasApplyRule && !hasNonApplyRule;
|
|
1664
|
+
}
|
|
1665
|
+
function filterApplyOnlyGeneratedCss(css, source) {
|
|
1666
|
+
const selectors = collectApplyOnlySourceSelectors(source);
|
|
1667
|
+
if (selectors.size === 0) return css;
|
|
1668
|
+
const selectorList = [...selectors];
|
|
1669
|
+
try {
|
|
1670
|
+
const root = postcss.parse(css);
|
|
1671
|
+
root.walkRules((rule) => {
|
|
1672
|
+
const isApplySelector = (rule.selectors ?? [rule.selector]).some((selector) => {
|
|
1673
|
+
const normalized = normalizeGeneratedSelector(selector);
|
|
1674
|
+
return selectorList.some((sourceSelector) => {
|
|
1675
|
+
if (normalized === sourceSelector) return true;
|
|
1676
|
+
if (!normalized.startsWith(sourceSelector)) return false;
|
|
1677
|
+
const next = normalized[sourceSelector.length];
|
|
1678
|
+
return next === ":" || next === "[" || next === ".";
|
|
1679
|
+
});
|
|
1680
|
+
});
|
|
1681
|
+
const isVariableRule = rule.nodes?.some((node) => node.type === "decl" && node.prop.startsWith("--"));
|
|
1682
|
+
if (!isApplySelector && !isVariableRule) rule.remove();
|
|
1683
|
+
});
|
|
1684
|
+
root.walkAtRules((rule) => {
|
|
1685
|
+
if (rule.nodes !== void 0 && rule.nodes.length === 0) rule.remove();
|
|
1686
|
+
});
|
|
1687
|
+
return root.toString();
|
|
1060
1688
|
} catch {
|
|
1061
|
-
|
|
1062
|
-
return resolved ? [resolved] : [];
|
|
1063
|
-
}
|
|
1064
|
-
const matchedCssEntrySource = sourceOptions ? await resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) : void 0;
|
|
1065
|
-
if (matchedCssEntrySource) return [generatorOptions?.config ? {
|
|
1066
|
-
...matchedCssEntrySource,
|
|
1067
|
-
css: prependConfigDirective(matchedCssEntrySource.css, generatorOptions.config)
|
|
1068
|
-
} : matchedCssEntrySource];
|
|
1069
|
-
const sourceSideCssSource = await resolveTailwindV4SourceSideEntrySource((shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder")) && (sourceOptions.cssEntries?.length ?? 0) <= 1) && canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) ? resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: false }) : void 0, sourceOptions, generatorOptions, file);
|
|
1070
|
-
if (sourceSideCssSource) return [sourceSideCssSource];
|
|
1071
|
-
const matchedCssSource = await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions);
|
|
1072
|
-
const candidateMatchedCssSource = await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, sourceOptions, selectionOptions);
|
|
1073
|
-
const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource;
|
|
1074
|
-
if (preferredCssEntrySource) return [generatorOptions?.config ? {
|
|
1075
|
-
...preferredCssEntrySource,
|
|
1076
|
-
css: prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
|
|
1077
|
-
} : preferredCssEntrySource];
|
|
1078
|
-
if (!sourceOptions.cssEntries || sourceOptions.cssEntries.length <= 1) {
|
|
1079
|
-
if (cssHandlerOptions.isMainChunk && sourceOptions.cssEntries?.length === 1) return [await resolveTailwindV4CssEntrySource(sourceOptions.cssEntries[0], normalizeTailwindV4CssSourceConfigs(sourceOptions)).then((source) => generatorOptions?.config ? {
|
|
1080
|
-
...source,
|
|
1081
|
-
css: prependConfigDirective(source.css, generatorOptions.config)
|
|
1082
|
-
} : source)];
|
|
1083
|
-
if (sourceOptions.cssSources?.length === 1) return [await createTailwindV4CssSourceResolver(sourceOptions, generatorOptions)(sourceOptions.cssSources[0])];
|
|
1084
|
-
const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
|
|
1085
|
-
return resolved ? [resolved] : [];
|
|
1086
|
-
}
|
|
1087
|
-
if (cssHandlerOptions.isMainChunk && !cssEntrySource && !hasTailwindGeneratedCss(rawSource) && !hasTailwindGeneratedCssMarkers(rawSource) && !hasTailwindSourceDirectives(rawSource, { importFallback: generatorOptions?.importFallback ?? false }) && !rawSource.includes("weapp-tailwindcss generator-placeholder") && !hasConfiguredTailwindV4CssSource(sourceOptions)) {
|
|
1088
|
-
const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
|
|
1089
|
-
return resolved ? [resolved] : [];
|
|
1689
|
+
return css;
|
|
1090
1690
|
}
|
|
1091
|
-
const normalizedCssSourceOptions = normalizeTailwindV4CssSourceConfigs(sourceOptions);
|
|
1092
|
-
const cssEntrySources = await Promise.all(sourceOptions.cssEntries.map((cssEntry) => resolveTailwindV4CssEntrySource(cssEntry, normalizedCssSourceOptions).then((source) => generatorOptions?.config ? {
|
|
1093
|
-
...source,
|
|
1094
|
-
css: prependConfigDirective(source.css, generatorOptions.config)
|
|
1095
|
-
} : source)));
|
|
1096
|
-
const cssSources = sourceOptions.cssSources?.length ? await Promise.all(sourceOptions.cssSources.map(createTailwindV4CssSourceResolver(sourceOptions, generatorOptions))) : [];
|
|
1097
|
-
return [...cssEntrySources, ...cssSources];
|
|
1098
1691
|
}
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
if (
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1692
|
+
function shouldFilterApplyOnlyGeneratedCss(_majorVersion, target, source, options) {
|
|
1693
|
+
return target === "weapp" && hasTailwindApplyDirective(source) && !hasTailwindRootDirectives(source) && !options.hasGeneratedCss && !options.hasGeneratedMarkers && collectApplyOnlySourceSelectors(source).size > 0 && hasOnlyApplyBackedSourceRules(source);
|
|
1694
|
+
}
|
|
1695
|
+
async function transformGeneratorUserCss(source, options) {
|
|
1696
|
+
if (source.trim().length === 0) return "";
|
|
1697
|
+
if (options.processed) return stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(removeTailwindV4GeneratorAtRules(options.generatorTarget === "weapp" ? removeTailwindV4GeneratedUserCssArtifacts(removeProcessedMiniProgramUnsupportedCss(source, {
|
|
1698
|
+
...options.generatorStyleOptions,
|
|
1699
|
+
...options.cssUserHandlerOptions
|
|
1700
|
+
})) : source)));
|
|
1701
|
+
const cleanedSource = removeTailwindSourceDirectives(removeTailwindV4GeneratorAtRules(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(source))), { importFallback: options.importFallback });
|
|
1702
|
+
if (cleanedSource.trim().length === 0) return "";
|
|
1703
|
+
const userSource = stripUnmatchedTailwindSourceMediaCloseFragments(removeTailwindApplyAtRules(removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(options.generatorTarget === "weapp" ? removeTailwindV4GeneratedUserCssArtifacts(removeUnsupportedMiniProgramAtRules(unwrapMiniProgramCascadeLayers(cleanedSource))) : cleanedSource)), { importFallback: options.importFallback })));
|
|
1704
|
+
if (userSource.trim().length === 0) return "";
|
|
1705
|
+
if (isCommentOnlyCss(userSource)) return userSource;
|
|
1706
|
+
if (options.generatorTarget !== "weapp") return userSource;
|
|
1707
|
+
const { css } = await options.styleHandler(userSource, {
|
|
1708
|
+
...options.generatorStyleOptions,
|
|
1709
|
+
...options.cssUserHandlerOptions
|
|
1108
1710
|
});
|
|
1109
|
-
|
|
1110
|
-
const sourceResolved = await resolveTailwindV4EntriesFromCss(matchingCssSource.css, typeof matchingCssSource.base === "string" && matchingCssSource.base.length > 0 ? matchingCssSource.base : typeof matchingCssSource.file === "string" && matchingCssSource.file.length > 0 ? path.dirname(matchingCssSource.file) : source.base);
|
|
1111
|
-
if (sourceResolved?.entries.length) return sourceResolved.entries;
|
|
1112
|
-
for (const dependency of matchingCssSource.dependencies ?? []) {
|
|
1113
|
-
if (!existsSync(dependency)) continue;
|
|
1114
|
-
try {
|
|
1115
|
-
const dependencyResolved = await resolveTailwindV4EntriesFromCss(readFileSync(dependency, "utf8"), path.dirname(dependency));
|
|
1116
|
-
if (dependencyResolved?.entries.length) return dependencyResolved.entries;
|
|
1117
|
-
} catch {}
|
|
1118
|
-
}
|
|
1119
|
-
return resolved?.entries;
|
|
1711
|
+
return removeTailwindV4GeneratedUserCssArtifacts(removeUnsupportedMiniProgramAtRules(css));
|
|
1120
1712
|
}
|
|
1121
1713
|
//#endregion
|
|
1122
1714
|
//#region src/bundlers/shared/generator-css/legacy-compat.ts
|
|
@@ -1244,7 +1836,7 @@ function removeTailwindApplyRules(rawSource) {
|
|
|
1244
1836
|
function resolveLegacyCompatCssSource(rawSource) {
|
|
1245
1837
|
const cached = legacyCompatSourceCache.get(rawSource);
|
|
1246
1838
|
if (cached !== void 0) return cached;
|
|
1247
|
-
const resolved = closeTrailingUnclosedBlocks(removeUnsupportedMiniProgramAtRules(removeTailwindApplyRules(removeTailwindSourceDirectives(closeTrailingUnclosedBlocks(stripTailwindBanners(rawSource))))));
|
|
1839
|
+
const resolved = closeTrailingUnclosedBlocks(removeTailwindV4GeneratedUserCssArtifacts(removeUnsupportedMiniProgramAtRules(removeTailwindApplyRules(removeTailwindSourceDirectives(closeTrailingUnclosedBlocks(stripTailwindBanners(rawSource)))))));
|
|
1248
1840
|
setLimitedCacheValue(legacyCompatSourceCache, rawSource, resolved);
|
|
1249
1841
|
return resolved;
|
|
1250
1842
|
}
|
|
@@ -1283,6 +1875,7 @@ function hasConfiguredContainerCompat(rawSource, file, cssHandlerOptions) {
|
|
|
1283
1875
|
}
|
|
1284
1876
|
}
|
|
1285
1877
|
function hasConfiguredContainerCompatSource(source) {
|
|
1878
|
+
if (typeof source.css !== "string") return false;
|
|
1286
1879
|
if (hasContainerConfigToken(source.css)) return true;
|
|
1287
1880
|
const cssEntrySource = resolveCssEntrySource(source.css, source.base);
|
|
1288
1881
|
if (cssEntrySource?.config) try {
|
|
@@ -1311,7 +1904,7 @@ async function appendLegacyCompatCss(css, rawSource, generatorTarget, styleHandl
|
|
|
1311
1904
|
compatCss = (await styleHandler(compatSource, styleOptions)).css;
|
|
1312
1905
|
setLimitedCacheValue(legacyCompatTransformCache, compatCssCacheKey, compatCss);
|
|
1313
1906
|
}
|
|
1314
|
-
const cleanedCompatCss = collectDedupedPostTransformCompatCss(removeDuplicatedViteMarkers(removeUnsupportedMiniProgramAtRules(compatCss), css), css);
|
|
1907
|
+
const cleanedCompatCss = collectDedupedPostTransformCompatCss(removeTailwindV4GeneratedUserCssArtifacts(removeDuplicatedViteMarkers(removeUnsupportedMiniProgramAtRules(compatCss), css)), css);
|
|
1315
1908
|
if (cleanedCompatCss.trim().length === 0) return css;
|
|
1316
1909
|
return createCssAppend(css, cleanedCompatCss);
|
|
1317
1910
|
}
|
|
@@ -1381,6 +1974,8 @@ function inheritLegacyUnitConvertedDeclarations(css, legacyCss) {
|
|
|
1381
1974
|
//#endregion
|
|
1382
1975
|
//#region src/bundlers/shared/generator-css/local-imports.ts
|
|
1383
1976
|
const REMOTE_IMPORT_RE = /^(?:https?:)?\/\//i;
|
|
1977
|
+
const CSS_STYLE_EXTENSION_RE = /\.(?:css|wxss|acss|ttss|qss|jxss|tyss|scss|sass|less|styl|stylus|pcss|postcss)(?:$|[?#])/i;
|
|
1978
|
+
const SOURCE_STYLE_EXTENSION_RE = /\.(?:css|scss|sass|less|styl|stylus|pcss|postcss)(?:$|[?#])/i;
|
|
1384
1979
|
function createCssSourceOrderAppend(base, extra) {
|
|
1385
1980
|
if (!base) return extra;
|
|
1386
1981
|
if (!extra) return base;
|
|
@@ -1458,249 +2053,51 @@ function splitLocalCssImports(source) {
|
|
|
1458
2053
|
const imports = importRoot.nodes.filter((node) => node.type === "atrule" && node.name === "import").map((node) => `@import ${node.params};`).join("\n");
|
|
1459
2054
|
return changed ? {
|
|
1460
2055
|
imports,
|
|
1461
|
-
source: root.toString()
|
|
1462
|
-
} : void 0;
|
|
1463
|
-
} catch {
|
|
1464
|
-
return;
|
|
1465
|
-
}
|
|
1466
|
-
}
|
|
1467
|
-
function restoreLocalCssImports(css, imports) {
|
|
1468
|
-
if (!imports?.trim()) return css;
|
|
1469
|
-
return createCssSourceOrderAppend(imports, css);
|
|
1470
|
-
}
|
|
1471
|
-
//#endregion
|
|
1472
|
-
//#region src/bundlers/shared/generator-css/user-css.ts
|
|
1473
|
-
const TAILWIND_V4_GENERATOR_AT_RULES = new Set([
|
|
1474
|
-
"config",
|
|
1475
|
-
"custom-variant",
|
|
1476
|
-
"plugin",
|
|
1477
|
-
"source",
|
|
1478
|
-
"theme",
|
|
1479
|
-
"utility",
|
|
1480
|
-
"variant"
|
|
1481
|
-
]);
|
|
1482
|
-
function removeTailwindApplyAtRules(source) {
|
|
1483
|
-
if (!source.includes("@apply")) return source;
|
|
1484
|
-
try {
|
|
1485
|
-
const root = postcss.parse(source);
|
|
1486
|
-
let changed = false;
|
|
1487
|
-
root.walkAtRules("apply", (rule) => {
|
|
1488
|
-
rule.remove();
|
|
1489
|
-
changed = true;
|
|
1490
|
-
});
|
|
1491
|
-
root.walk((node) => {
|
|
1492
|
-
if ("nodes" in node && node.nodes?.length === 0) node.remove();
|
|
1493
|
-
});
|
|
1494
|
-
return changed ? root.toString() : source;
|
|
1495
|
-
} catch {
|
|
1496
|
-
return source;
|
|
1497
|
-
}
|
|
1498
|
-
}
|
|
1499
|
-
function removeTailwindV4GeneratorAtRules(source) {
|
|
1500
|
-
try {
|
|
1501
|
-
const root = postcss.parse(source);
|
|
1502
|
-
let changed = false;
|
|
1503
|
-
root.walkAtRules((rule) => {
|
|
1504
|
-
if (!TAILWIND_V4_GENERATOR_AT_RULES.has(rule.name)) return;
|
|
1505
|
-
rule.remove();
|
|
1506
|
-
changed = true;
|
|
1507
|
-
});
|
|
1508
|
-
root.walk((node) => {
|
|
1509
|
-
if ("nodes" in node && node.nodes?.length === 0) {
|
|
1510
|
-
node.remove();
|
|
1511
|
-
changed = true;
|
|
1512
|
-
}
|
|
1513
|
-
});
|
|
1514
|
-
return changed ? root.toString() : source;
|
|
1515
|
-
} catch {
|
|
1516
|
-
return source;
|
|
1517
|
-
}
|
|
1518
|
-
}
|
|
1519
|
-
function isCommentOnlyCss(source) {
|
|
1520
|
-
try {
|
|
1521
|
-
const root = postcss.parse(source);
|
|
1522
|
-
return root.nodes.length > 0 && root.nodes.every((node) => node.type === "comment");
|
|
1523
|
-
} catch {
|
|
1524
|
-
return false;
|
|
1525
|
-
}
|
|
1526
|
-
}
|
|
1527
|
-
function stripTailwindSourceMediaFragments(source) {
|
|
1528
|
-
let removedSourceMediaStart = false;
|
|
1529
|
-
return source.split(/\r?\n/).filter((line) => {
|
|
1530
|
-
if (/^\s*@media\s+source\([^)]*\)\s*\{\s*$/.test(line)) {
|
|
1531
|
-
removedSourceMediaStart = true;
|
|
1532
|
-
return false;
|
|
1533
|
-
}
|
|
1534
|
-
if (/^\s*\}\s*\/\*\s*source\([^)]*\)\s*\*\/\s*$/.test(line)) return false;
|
|
1535
|
-
if (removedSourceMediaStart && /^\s*\}\s*$/.test(line)) {
|
|
1536
|
-
removedSourceMediaStart = false;
|
|
1537
|
-
return false;
|
|
1538
|
-
}
|
|
1539
|
-
return true;
|
|
1540
|
-
}).join("\n").replace(/\}[^\S\r\n]*(?=@(?:config|source)\b)/g, "");
|
|
1541
|
-
}
|
|
1542
|
-
function stripLeadingTailwindSourceMediaCloseFragment(source) {
|
|
1543
|
-
return source.replace(/^\s*\}\s*(?:\n|$)/, "");
|
|
1544
|
-
}
|
|
1545
|
-
function stripUnmatchedTailwindSourceMediaCloseFragments(source) {
|
|
1546
|
-
try {
|
|
1547
|
-
postcss.parse(source);
|
|
1548
|
-
return source;
|
|
1549
|
-
} catch {
|
|
1550
|
-
return stripLeadingTailwindSourceMediaCloseFragment(source).replace(/\s*\}\s*$/, "");
|
|
1551
|
-
}
|
|
1552
|
-
}
|
|
1553
|
-
function splitUserCssLayerBlocks(source) {
|
|
1554
|
-
if (!source.includes("@layer")) return {
|
|
1555
|
-
layer: "",
|
|
1556
|
-
rest: source
|
|
1557
|
-
};
|
|
1558
|
-
try {
|
|
1559
|
-
const root = postcss.parse(source);
|
|
1560
|
-
const layerRoot = postcss.root();
|
|
1561
|
-
const restRoot = postcss.root();
|
|
1562
|
-
for (const node of root.nodes) (node.type === "atrule" && node.name === "layer" && node.nodes?.length ? layerRoot : restRoot).append(node.clone());
|
|
1563
|
-
return {
|
|
1564
|
-
layer: layerRoot.toString(),
|
|
1565
|
-
rest: restRoot.toString()
|
|
1566
|
-
};
|
|
1567
|
-
} catch {
|
|
1568
|
-
return {
|
|
1569
|
-
layer: source,
|
|
1570
|
-
rest: ""
|
|
1571
|
-
};
|
|
1572
|
-
}
|
|
1573
|
-
}
|
|
1574
|
-
function hasUserCssLayerBlocks(source) {
|
|
1575
|
-
if (!source.includes("@layer")) return false;
|
|
1576
|
-
try {
|
|
1577
|
-
let hasLayerBlock = false;
|
|
1578
|
-
postcss.parse(source).walkAtRules("layer", (node) => {
|
|
1579
|
-
if (node.nodes?.length) hasLayerBlock = true;
|
|
1580
|
-
});
|
|
1581
|
-
return hasLayerBlock;
|
|
1582
|
-
} catch {
|
|
1583
|
-
return true;
|
|
1584
|
-
}
|
|
1585
|
-
}
|
|
1586
|
-
function collectUserLayerSelectors(source) {
|
|
1587
|
-
const selectors = /* @__PURE__ */ new Set();
|
|
1588
|
-
try {
|
|
1589
|
-
postcss.parse(source).walkRules((rule) => {
|
|
1590
|
-
for (const selector of rule.selectors ?? [rule.selector]) {
|
|
1591
|
-
const normalized = selector.trim();
|
|
1592
|
-
if (normalized) selectors.add(normalized);
|
|
1593
|
-
}
|
|
1594
|
-
});
|
|
1595
|
-
} catch {}
|
|
1596
|
-
return selectors;
|
|
1597
|
-
}
|
|
1598
|
-
function matchesUserLayerSelector(selector, userLayerSelector) {
|
|
1599
|
-
if (selector === userLayerSelector) return true;
|
|
1600
|
-
if (!selector.startsWith(userLayerSelector)) return false;
|
|
1601
|
-
const next = selector[userLayerSelector.length];
|
|
1602
|
-
return next === ":" || next === "[";
|
|
1603
|
-
}
|
|
1604
|
-
function extractGeneratedCssForUserLayerSelectors(css, userLayerSource) {
|
|
1605
|
-
const selectors = collectUserLayerSelectors(userLayerSource);
|
|
1606
|
-
if (selectors.size === 0) return {
|
|
1607
|
-
layer: "",
|
|
1608
|
-
rest: css
|
|
1609
|
-
};
|
|
1610
|
-
try {
|
|
1611
|
-
const root = postcss.parse(css);
|
|
1612
|
-
const layerRoot = postcss.root();
|
|
1613
|
-
const selectorList = [...selectors];
|
|
1614
|
-
root.walkRules((rule) => {
|
|
1615
|
-
if ((rule.selectors ?? [rule.selector]).some((selector) => selectorList.some((userSelector) => matchesUserLayerSelector(selector.trim(), userSelector)))) {
|
|
1616
|
-
layerRoot.append(rule.clone());
|
|
1617
|
-
rule.remove();
|
|
1618
|
-
}
|
|
1619
|
-
});
|
|
1620
|
-
return {
|
|
1621
|
-
layer: layerRoot.toString(),
|
|
1622
|
-
rest: root.toString()
|
|
1623
|
-
};
|
|
1624
|
-
} catch {
|
|
1625
|
-
return {
|
|
1626
|
-
layer: "",
|
|
1627
|
-
rest: css
|
|
1628
|
-
};
|
|
1629
|
-
}
|
|
1630
|
-
}
|
|
1631
|
-
function normalizeGeneratedSelector(selector) {
|
|
1632
|
-
return selector.replace(/:not\(#\\#\)/g, "").trim();
|
|
1633
|
-
}
|
|
1634
|
-
function collectApplyOnlySourceSelectors(source) {
|
|
1635
|
-
const selectors = /* @__PURE__ */ new Set();
|
|
1636
|
-
try {
|
|
1637
|
-
postcss.parse(source).walkRules((rule) => {
|
|
1638
|
-
if (!rule.nodes?.some((node) => node.type === "atrule" && node.name === "apply")) return;
|
|
1639
|
-
for (const selector of rule.selectors ?? [rule.selector]) {
|
|
1640
|
-
const normalized = normalizeGeneratedSelector(selector);
|
|
1641
|
-
if (normalized) selectors.add(normalized);
|
|
1642
|
-
}
|
|
1643
|
-
});
|
|
1644
|
-
} catch {}
|
|
1645
|
-
return selectors;
|
|
1646
|
-
}
|
|
1647
|
-
function hasOnlyApplyBackedSourceRules(source) {
|
|
1648
|
-
let hasApplyRule = false;
|
|
1649
|
-
let hasNonApplyRule = false;
|
|
1650
|
-
try {
|
|
1651
|
-
postcss.parse(source).walkRules((rule) => {
|
|
1652
|
-
if (rule.nodes?.some((node) => node.type === "atrule" && node.name === "apply")) hasApplyRule = true;
|
|
1653
|
-
else hasNonApplyRule = true;
|
|
1654
|
-
});
|
|
2056
|
+
source: root.toString()
|
|
2057
|
+
} : void 0;
|
|
1655
2058
|
} catch {
|
|
1656
|
-
return
|
|
2059
|
+
return;
|
|
1657
2060
|
}
|
|
1658
|
-
return hasApplyRule && !hasNonApplyRule;
|
|
1659
2061
|
}
|
|
1660
|
-
function
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
2062
|
+
function restoreLocalCssImports(css, imports) {
|
|
2063
|
+
if (!imports?.trim()) return css;
|
|
2064
|
+
return createCssSourceOrderAppend(imports, css);
|
|
2065
|
+
}
|
|
2066
|
+
function splitRequestSuffix(request) {
|
|
2067
|
+
const suffixIndexCandidates = [request.indexOf("?"), request.indexOf("#")].filter((index) => index >= 0);
|
|
2068
|
+
const suffixIndex = suffixIndexCandidates.length > 0 ? Math.min(...suffixIndexCandidates) : -1;
|
|
2069
|
+
if (suffixIndex < 0) return {
|
|
2070
|
+
clean: request,
|
|
2071
|
+
suffix: ""
|
|
2072
|
+
};
|
|
2073
|
+
return {
|
|
2074
|
+
clean: request.slice(0, suffixIndex),
|
|
2075
|
+
suffix: request.slice(suffixIndex)
|
|
2076
|
+
};
|
|
2077
|
+
}
|
|
2078
|
+
function normalizeOutputImportRequest(request, styleOutputExtension) {
|
|
2079
|
+
const normalizedStyleOutputExtension = styleOutputExtension?.startsWith(".") ? styleOutputExtension : styleOutputExtension ? `.${styleOutputExtension}` : void 0;
|
|
2080
|
+
const { clean, suffix } = splitRequestSuffix(request.replace(/\\/g, "/"));
|
|
2081
|
+
return `${clean.replace(/^(?:\.\/)?src\//, "./").replace(SOURCE_STYLE_EXTENSION_RE, normalizedStyleOutputExtension ?? ".css")}${suffix}`;
|
|
2082
|
+
}
|
|
2083
|
+
function rewriteLocalCssImportRequestsForOutput(css, options = {}) {
|
|
2084
|
+
if (!css.includes("@import")) return css;
|
|
1664
2085
|
try {
|
|
1665
2086
|
const root = postcss.parse(css);
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
});
|
|
1675
|
-
});
|
|
1676
|
-
const isVariableRule = rule.nodes?.some((node) => node.type === "decl" && node.prop.startsWith("--"));
|
|
1677
|
-
if (!isApplySelector && !isVariableRule) rule.remove();
|
|
1678
|
-
});
|
|
1679
|
-
root.walkAtRules((rule) => {
|
|
1680
|
-
if (rule.nodes !== void 0 && rule.nodes.length === 0) rule.remove();
|
|
2087
|
+
let changed = false;
|
|
2088
|
+
root.walkAtRules("import", (atRule) => {
|
|
2089
|
+
const request = parseImportRequest(atRule.params);
|
|
2090
|
+
if (!request || !isLocalImportRequest(request) || !CSS_STYLE_EXTENSION_RE.test(request)) return;
|
|
2091
|
+
const rewritten = normalizeOutputImportRequest(request, options.styleOutputExtension);
|
|
2092
|
+
if (rewritten === request) return;
|
|
2093
|
+
atRule.params = atRule.params.replace(request, rewritten);
|
|
2094
|
+
changed = true;
|
|
1681
2095
|
});
|
|
1682
|
-
return root.toString();
|
|
2096
|
+
return changed ? root.toString() : css;
|
|
1683
2097
|
} catch {
|
|
1684
2098
|
return css;
|
|
1685
2099
|
}
|
|
1686
2100
|
}
|
|
1687
|
-
function shouldFilterApplyOnlyGeneratedCss(majorVersion, target, source, options) {
|
|
1688
|
-
return majorVersion === 4 && target === "weapp" && hasTailwindApplyDirective(source) && !hasTailwindRootDirectives(source) && !options.hasGeneratedCss && !options.hasGeneratedMarkers && collectApplyOnlySourceSelectors(source).size > 0 && hasOnlyApplyBackedSourceRules(source);
|
|
1689
|
-
}
|
|
1690
|
-
async function transformGeneratorUserCss(source, options) {
|
|
1691
|
-
if (source.trim().length === 0) return "";
|
|
1692
|
-
const cleanedSource = removeTailwindSourceDirectives(removeTailwindV4GeneratorAtRules(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(source))), { importFallback: options.importFallback });
|
|
1693
|
-
if (cleanedSource.trim().length === 0) return "";
|
|
1694
|
-
const userSource = stripUnmatchedTailwindSourceMediaCloseFragments(removeTailwindApplyAtRules(removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(options.generatorTarget === "weapp" ? removeUnsupportedMiniProgramAtRules(cleanedSource) : cleanedSource)), { importFallback: options.importFallback })));
|
|
1695
|
-
if (userSource.trim().length === 0) return "";
|
|
1696
|
-
if (isCommentOnlyCss(userSource)) return userSource;
|
|
1697
|
-
if (options.generatorTarget !== "weapp") return userSource;
|
|
1698
|
-
const { css } = await options.styleHandler(userSource, {
|
|
1699
|
-
...options.generatorStyleOptions,
|
|
1700
|
-
...options.cssUserHandlerOptions
|
|
1701
|
-
});
|
|
1702
|
-
return removeUnsupportedMiniProgramAtRules(css);
|
|
1703
|
-
}
|
|
1704
2101
|
//#endregion
|
|
1705
2102
|
//#region src/bundlers/shared/generator-css/user-layer-order.ts
|
|
1706
2103
|
const USER_LAYER_COMPONENTS_START = "/*! weapp-tailwindcss layer components start */";
|
|
@@ -1848,17 +2245,21 @@ async function runWithConcurrency(factories, limit = Math.min(4, Math.max(1, fac
|
|
|
1848
2245
|
await Promise.all(executing);
|
|
1849
2246
|
return results;
|
|
1850
2247
|
}
|
|
2248
|
+
function resolveTaskConcurrency(defaultLimit = 1) {
|
|
2249
|
+
const configured = Number.parseInt(process.env["WEAPP_TW_TASK_CONCURRENCY"] ?? "", 10);
|
|
2250
|
+
if (Number.isFinite(configured) && configured > 0) return configured;
|
|
2251
|
+
return defaultLimit;
|
|
2252
|
+
}
|
|
1851
2253
|
function pushConcurrentTaskFactories(queue, factories, limit) {
|
|
1852
2254
|
if (factories.length === 0) return;
|
|
1853
2255
|
queue.push(runWithConcurrency(factories, limit).then(() => void 0));
|
|
1854
2256
|
}
|
|
1855
2257
|
//#endregion
|
|
1856
2258
|
//#region src/bundlers/shared/generator-css/validate.ts
|
|
1857
|
-
const SUPPORTED_GENERATOR_MAJOR_VERSIONS = new Set([3, 4]);
|
|
1858
2259
|
async function validateCandidatesByGenerator(options) {
|
|
1859
|
-
const { candidates, cssHandlerOptions, debug, file, opts, rawSource, runtimeState } = options;
|
|
1860
|
-
const majorVersion = runtimeState.
|
|
1861
|
-
if (
|
|
2260
|
+
const { candidates, cssHandlerOptions, debug, file, opts, rawSource, runtimeState, skipGenerateFallback } = options;
|
|
2261
|
+
const majorVersion = runtimeState.tailwindRuntime.majorVersion;
|
|
2262
|
+
if (majorVersion !== 4 || candidates.size === 0) return /* @__PURE__ */ new Set();
|
|
1862
2263
|
const generatorOptions = {
|
|
1863
2264
|
...normalizeWeappTailwindcssGeneratorOptions(opts.generator),
|
|
1864
2265
|
bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues
|
|
@@ -1872,10 +2273,11 @@ async function validateCandidatesByGenerator(options) {
|
|
|
1872
2273
|
if (generatorOptions.bareArbitraryValues === void 0 || generatorOptions.bareArbitraryValues === false) {
|
|
1873
2274
|
if (typeof generator.validateCandidates === "function") return generator.validateCandidates(candidates);
|
|
1874
2275
|
}
|
|
2276
|
+
if (skipGenerateFallback) return /* @__PURE__ */ new Set();
|
|
1875
2277
|
return (await generator.generate({
|
|
1876
2278
|
bareArbitraryValues: generatorOptions.bareArbitraryValues,
|
|
1877
2279
|
candidates,
|
|
1878
|
-
target: "
|
|
2280
|
+
target: "web"
|
|
1879
2281
|
})).classSet;
|
|
1880
2282
|
}));
|
|
1881
2283
|
const classSet = new Set(classSets.flatMap((item) => [...item]));
|
|
@@ -1889,38 +2291,87 @@ function resolveGeneratorSourceConcurrency() {
|
|
|
1889
2291
|
if (Number.isFinite(configured) && configured > 0) return configured;
|
|
1890
2292
|
return 1;
|
|
1891
2293
|
}
|
|
2294
|
+
function intersectCandidateSets(left, right) {
|
|
2295
|
+
if (left.size === 0 || right.size === 0) return /* @__PURE__ */ new Set();
|
|
2296
|
+
const [small, large] = left.size <= right.size ? [left, right] : [right, left];
|
|
2297
|
+
const matched = /* @__PURE__ */ new Set();
|
|
2298
|
+
for (const candidate of small) if (large.has(candidate)) matched.add(candidate);
|
|
2299
|
+
return matched;
|
|
2300
|
+
}
|
|
2301
|
+
function collectCssRuleIdentityMarkers(source) {
|
|
2302
|
+
const markers = /* @__PURE__ */ new Set();
|
|
2303
|
+
try {
|
|
2304
|
+
const root = postcss.parse(source);
|
|
2305
|
+
root.walkRules((rule) => {
|
|
2306
|
+
for (const selector of rule.selectors ?? [rule.selector]) for (const match of selector.matchAll(/\.((?:\\.|[_a-z\u00A0-\uFFFF-])(?:\\.|[\w\u00A0-\uFFFF-])*)/gi)) markers.add(`class:${match[1]}`);
|
|
2307
|
+
});
|
|
2308
|
+
root.walkAtRules("keyframes", (rule) => {
|
|
2309
|
+
if (rule.params) markers.add(`keyframes:${rule.params}`);
|
|
2310
|
+
});
|
|
2311
|
+
} catch {}
|
|
2312
|
+
return markers;
|
|
2313
|
+
}
|
|
2314
|
+
function isCssAlreadyRepresentedByMarkers(css, source) {
|
|
2315
|
+
const sourceMarkers = collectCssRuleIdentityMarkers(source);
|
|
2316
|
+
if (sourceMarkers.size === 0) return false;
|
|
2317
|
+
const cssMarkers = collectCssRuleIdentityMarkers(css);
|
|
2318
|
+
for (const marker of sourceMarkers) if (!cssMarkers.has(marker)) return false;
|
|
2319
|
+
return true;
|
|
2320
|
+
}
|
|
1892
2321
|
async function generateCssByGenerator(options) {
|
|
1893
|
-
const { opts, runtimeState, runtime, rawSource, file, cssHandlerOptions, cssUserHandlerOptions, getSourceCandidatesForEntries, styleHandler, debug } = options;
|
|
2322
|
+
const { opts, runtimeState, runtime, rawSource, file, cssHandlerOptions, cssUserHandlerOptions, getSourceCandidatesForEntries, styleHandler, userRawSource, userRawSourceProcessed, debug } = options;
|
|
1894
2323
|
const generatorOptions = {
|
|
1895
|
-
...normalizeWeappTailwindcssGeneratorOptions(opts.generator
|
|
2324
|
+
...normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
2325
|
+
appType: opts.appType,
|
|
2326
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
2327
|
+
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
2328
|
+
uniAppX: opts.uniAppX
|
|
2329
|
+
}),
|
|
1896
2330
|
bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues
|
|
1897
2331
|
};
|
|
1898
|
-
const
|
|
2332
|
+
const generatorBranch = resolveGeneratorRuntimeBranch(generatorOptions, {
|
|
2333
|
+
appType: opts.appType,
|
|
2334
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
2335
|
+
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
2336
|
+
uniAppX: opts.uniAppX
|
|
2337
|
+
});
|
|
2338
|
+
const majorVersion = runtimeState.tailwindRuntime.majorVersion;
|
|
2339
|
+
if (majorVersion !== 4) throw new Error("weapp-tailwindcss 生成管线仅支持 Tailwind CSS v4。");
|
|
1899
2340
|
const effectiveRawSource = stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(normalizeTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })));
|
|
1900
2341
|
const localImportParts = splitLocalCssImports(effectiveRawSource);
|
|
2342
|
+
const localImports = options.restoreLocalCssImports === false ? void 0 : localImportParts?.imports;
|
|
1901
2343
|
const generatorRawSource = localImportParts?.source ?? effectiveRawSource;
|
|
1902
|
-
const
|
|
2344
|
+
const rawUserSource = userRawSource === void 0 ? generatorRawSource : userRawSourceProcessed ? userRawSource : stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(normalizeTailwindSourceDirectives(userRawSource, { importFallback: generatorOptions.importFallback })));
|
|
2345
|
+
const userSource = splitLocalCssImports(rawUserSource)?.source ?? rawUserSource;
|
|
2346
|
+
const userCssRawSource = removeTailwindV4GeneratorAtRules(userSource);
|
|
2347
|
+
const userCssOrderSource = GENERATOR_PLACEHOLDER_MARKER_RE.test(userSource) ? userSource : userCssRawSource;
|
|
2348
|
+
const hasDistinctUserRawSource = typeof userRawSource === "string" && normalizeCssSourceForCompare(userCssRawSource) !== normalizeCssSourceForCompare(generatorRawSource);
|
|
1903
2349
|
const cleanedLocalImportWrapper = cleanLocalCssImportWrapperTailwindDirectives(effectiveRawSource);
|
|
1904
2350
|
if (cleanedLocalImportWrapper !== void 0) return {
|
|
1905
|
-
css:
|
|
2351
|
+
css: shouldUseMiniProgramCssBranch(generatorBranch) ? removeUnsupportedMiniProgramAtRules(cleanedLocalImportWrapper) : cleanedLocalImportWrapper,
|
|
2352
|
+
classSet: /* @__PURE__ */ new Set(),
|
|
1906
2353
|
target: generatorOptions.target,
|
|
1907
2354
|
source: "generator",
|
|
1908
|
-
dependencies: []
|
|
2355
|
+
dependencies: [],
|
|
2356
|
+
metadata: {
|
|
2357
|
+
file,
|
|
2358
|
+
majorVersion
|
|
2359
|
+
}
|
|
1909
2360
|
};
|
|
1910
2361
|
if (isPureLocalCssImportWrapper(effectiveRawSource)) return;
|
|
1911
2362
|
const hasGeneratedCss = hasTailwindGeneratedCss(generatorRawSource);
|
|
1912
2363
|
const hasSourceDirectives = hasTailwindSourceDirectives(generatorRawSource, { importFallback: generatorOptions.importFallback });
|
|
1913
2364
|
const hasGeneratedMarkers = hasTailwindGeneratedCssMarkers(generatorRawSource);
|
|
1914
|
-
|
|
2365
|
+
if (!shouldUseGeneratorForCurrentCss(majorVersion, cssHandlerOptions, {
|
|
2366
|
+
forceGenerator: options.forceGenerator,
|
|
1915
2367
|
hasGeneratedCss,
|
|
1916
2368
|
hasGeneratedMarkers,
|
|
1917
2369
|
hasSourceDirectives,
|
|
1918
2370
|
rawSource: generatorRawSource
|
|
1919
|
-
});
|
|
1920
|
-
if (!isSupportedGeneratorMajorVersion(majorVersion) || !shouldGenerateCurrentCss || majorVersion === 3 && !hasSourceDirectives && !hasGeneratedCss && !hasGeneratedMarkers) return;
|
|
2371
|
+
})) return;
|
|
1921
2372
|
try {
|
|
1922
2373
|
await runtimeState.readyPromise;
|
|
1923
|
-
const currentCssCandidates =
|
|
2374
|
+
const currentCssCandidates = await extractSourceCandidates(generatorRawSource, "css", { ...generatorOptions.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: generatorOptions.bareArbitraryValues } });
|
|
1924
2375
|
const isolateCurrentCssCandidates = shouldIsolateCurrentTailwindV4CssCandidates(majorVersion, cssHandlerOptions, {
|
|
1925
2376
|
hasGeneratedCss,
|
|
1926
2377
|
hasGeneratedMarkers,
|
|
@@ -1929,6 +2380,7 @@ async function generateCssByGenerator(options) {
|
|
|
1929
2380
|
const runtimeWithCurrentCss = createRuntimeWithCurrentCssCandidates(runtime, currentCssCandidates, isolateCurrentCssCandidates);
|
|
1930
2381
|
const sources = await resolveGeneratorSources(majorVersion, runtimeState, generatorRawSource, file, cssHandlerOptions, generatorOptions, {
|
|
1931
2382
|
cssEntries: opts.cssEntries,
|
|
2383
|
+
cssSources: options.cssSources,
|
|
1932
2384
|
getSourceCandidatesForEntries,
|
|
1933
2385
|
runtime: runtimeWithCurrentCss
|
|
1934
2386
|
});
|
|
@@ -1937,30 +2389,33 @@ async function generateCssByGenerator(options) {
|
|
|
1937
2389
|
const sourceConcurrency = resolveGeneratorSourceConcurrency();
|
|
1938
2390
|
const generated = mergeGeneratorResults((await runWithConcurrency(sources.map((source) => async () => {
|
|
1939
2391
|
const generator = createWeappTailwindcssGenerator(source);
|
|
1940
|
-
const sourceEntries = getSourceCandidatesForEntries
|
|
1941
|
-
const
|
|
1942
|
-
const
|
|
2392
|
+
const sourceEntries = getSourceCandidatesForEntries ? await resolveGeneratorSourceEntries(source, runtimeState) : void 0;
|
|
2393
|
+
const sourceScopedRuntime = sourceEntries && sourceEntries.length > 0 ? getSourceCandidatesForEntries?.(sourceEntries) : void 0;
|
|
2394
|
+
const scopedRuntime = options.sourceCandidates && sourceScopedRuntime ? intersectCandidateSets(options.sourceCandidates, sourceScopedRuntime) : options.sourceCandidates ?? sourceScopedRuntime;
|
|
2395
|
+
const isolateCssSource = shouldIsolateScopedCssSource(majorVersion, source, sourceEntries, {
|
|
2396
|
+
cssHandlerOptions,
|
|
2397
|
+
target: generatorOptions.target
|
|
2398
|
+
});
|
|
1943
2399
|
const sourceMetadata = source.__weappTailwindcssMeta;
|
|
1944
2400
|
const matchedCssSourceFile = Boolean(sourceMetadata?.matchedCssSourceFile);
|
|
1945
2401
|
if (options.deferEmptyScopedCssSource && isolateCssSource && scopedRuntime?.size === 0 && currentCssCandidates.length === 0 && !cssHandlerOptions.isMainChunk) {
|
|
1946
2402
|
debug("defer empty scoped css source generation: %s", file);
|
|
1947
2403
|
return;
|
|
1948
2404
|
}
|
|
1949
|
-
const sourceRuntime = scopedRuntime && (scopedRuntime.size > 0 || isolateCssSource) ? isolateCurrentCssCandidates ? runtimeWithCurrentCss : mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtimeWithCurrentCss, {
|
|
2405
|
+
const sourceRuntime = scopedRuntime && (scopedRuntime.size > 0 || isolateCssSource) || isolateCssSource ? isolateCurrentCssCandidates ? runtimeWithCurrentCss : mergeScopedRuntimeWithCurrentRuntime(scopedRuntime ?? /* @__PURE__ */ new Set(), runtimeWithCurrentCss, {
|
|
1950
2406
|
currentCssCandidates,
|
|
1951
2407
|
cssHandlerOptions,
|
|
1952
2408
|
isolateCssSource,
|
|
2409
|
+
majorVersion,
|
|
1953
2410
|
matchedCssSourceFile
|
|
1954
2411
|
}) : runtimeWithCurrentCss;
|
|
1955
|
-
const generatorRuntime =
|
|
1956
|
-
const useIncrementalCache = (majorVersion === 3 || majorVersion === 4) && !(majorVersion === 3 && isolateCssSource);
|
|
2412
|
+
const generatorRuntime = shouldUseMiniProgramCssBranch(generatorBranch) ? filterUnsupportedMiniProgramTailwindV4Candidates(sourceRuntime) : sourceRuntime;
|
|
1957
2413
|
return generator.generate({
|
|
1958
2414
|
bareArbitraryValues: generatorOptions.bareArbitraryValues,
|
|
1959
2415
|
candidates: generatorRuntime,
|
|
1960
|
-
incrementalCache:
|
|
2416
|
+
incrementalCache: true,
|
|
1961
2417
|
scanSources: shouldScanTailwindV4Sources(majorVersion, generatorOptions.target, generatorRuntime, isolateCssSource),
|
|
1962
2418
|
styleOptions: generatorStyleOptions,
|
|
1963
|
-
tailwindcssV3Compatibility: generatorOptions.tailwindcssV3Compatibility,
|
|
1964
2419
|
target: generatorOptions.target
|
|
1965
2420
|
});
|
|
1966
2421
|
}), sourceConcurrency)).filter((item) => Boolean(item)));
|
|
@@ -1969,20 +2424,30 @@ async function generateCssByGenerator(options) {
|
|
|
1969
2424
|
if ((generated.target !== "weapp" || !hasUserCssLayerBlocks(generatorRawSource)) && typeof options.previousCss === "string" && typeof generated.incrementalCss === "string") {
|
|
1970
2425
|
const incrementalCss = stripTailwindBanner(generated.incrementalCss);
|
|
1971
2426
|
return {
|
|
1972
|
-
css: restoreLocalCssImports(incrementalCss.trim().length > 0 ? createCssAppend(options.previousCss, finalizeMiniProgramGeneratorCss(incrementalCss, generated.target, majorVersion, opts.cssPreflight, {
|
|
2427
|
+
css: restoreLocalCssImports(incrementalCss.trim().length > 0 ? createCssAppend(options.previousCss, finalizeMiniProgramGeneratorCss(incrementalCss, generated.target, majorVersion, opts.cssPreflight, {
|
|
2428
|
+
injectPreflight: false,
|
|
2429
|
+
styleOptions: generatorStyleOptions
|
|
2430
|
+
})) : options.previousCss, localImports),
|
|
2431
|
+
classSet: generated.classSet,
|
|
1973
2432
|
target: generated.target,
|
|
1974
2433
|
source: "generator",
|
|
1975
2434
|
dependencies: generated.dependencies,
|
|
1976
|
-
incremental: true
|
|
2435
|
+
incremental: true,
|
|
2436
|
+
metadata: {
|
|
2437
|
+
file,
|
|
2438
|
+
majorVersion,
|
|
2439
|
+
rawCss: generated.rawCss
|
|
2440
|
+
}
|
|
1977
2441
|
};
|
|
1978
2442
|
}
|
|
1979
2443
|
const shouldFilterApplyOnlyCss = shouldFilterApplyOnlyGeneratedCss(majorVersion, generated.target, generatorRawSource, {
|
|
1980
2444
|
hasGeneratedCss,
|
|
1981
2445
|
hasGeneratedMarkers
|
|
1982
2446
|
});
|
|
1983
|
-
const
|
|
2447
|
+
const generatedCssSource = generated.target === "web" ? generated.css : stripTailwindBanner(generated.css);
|
|
2448
|
+
const generatedCss = shouldFilterApplyOnlyCss ? filterApplyOnlyGeneratedCss(generatedCssSource, generatorRawSource) : generatedCssSource;
|
|
1984
2449
|
const hasMatchedCssSourceFile = sources.some((source) => source.__weappTailwindcssMeta?.matchedCssSourceFile);
|
|
1985
|
-
const orderedExtraCss = hasMatchedCssSourceFile ? splitTailwindV4GeneratedCssBySourceOrder(
|
|
2450
|
+
const orderedExtraCss = splitGeneratorPlaceholderCssBySourceOrder(userCssOrderSource, generated.rawCss) ?? (hasMatchedCssSourceFile ? splitTailwindV4GeneratedCssBySourceOrder(userCssOrderSource, generated.rawCss) : splitRawSourceByGeneratedCssOrder(userCssOrderSource, generated.rawCss));
|
|
1986
2451
|
const shouldAppendMatchedCssSourceCompat = !hasMatchedCssSourceFile || orderedExtraCss !== void 0;
|
|
1987
2452
|
if (orderedExtraCss) {
|
|
1988
2453
|
let css = generatedCss;
|
|
@@ -1992,7 +2457,8 @@ async function generateCssByGenerator(options) {
|
|
|
1992
2457
|
generatorStyleOptions,
|
|
1993
2458
|
cssUserHandlerOptions,
|
|
1994
2459
|
styleHandler,
|
|
1995
|
-
importFallback: generatorOptions.importFallback
|
|
2460
|
+
importFallback: generatorOptions.importFallback,
|
|
2461
|
+
processed: userRawSourceProcessed
|
|
1996
2462
|
};
|
|
1997
2463
|
const afterLayerParts = generated.target === "weapp" ? splitUserCssLayerBlocks(orderedExtraCss.after) : {
|
|
1998
2464
|
layer: "",
|
|
@@ -2001,7 +2467,8 @@ async function generateCssByGenerator(options) {
|
|
|
2001
2467
|
const beforeUserCss = await transformGeneratorUserCss(orderedExtraCss.before, userCssOptions);
|
|
2002
2468
|
const afterLayerUserCss = await transformGeneratorUserCss(afterLayerParts.layer, userCssOptions);
|
|
2003
2469
|
const afterUserCss = await transformGeneratorUserCss(afterLayerParts.rest, userCssOptions);
|
|
2004
|
-
|
|
2470
|
+
const fallbackLayerUserCss = generated.target === "weapp" && afterLayerParts.layer.trim().length === 0 && hasUserCssLayerBlocks(userCssRawSource) ? await transformGeneratorUserCss(splitUserCssLayerBlocks(userCssRawSource).layer, userCssOptions) : "";
|
|
2471
|
+
css = createCssSourceOrderAppend$1(createCssSourceOrderAppend$1(createCssSourceOrderAppend$1(beforeUserCss, generated.target === "weapp" ? wrapUserLayerComponentsCss(createCssSourceOrderAppend$1(afterLayerUserCss, fallbackLayerUserCss)) : afterLayerUserCss), css), afterUserCss);
|
|
2005
2472
|
if (isEmptyCssSourceOrderParts(orderedExtraCss) && shouldAppendWebBundleCssFallback(generated.target, {
|
|
2006
2473
|
hasSourceDirectives,
|
|
2007
2474
|
hasMatchedCssSourceFile
|
|
@@ -2009,26 +2476,53 @@ async function generateCssByGenerator(options) {
|
|
|
2009
2476
|
const userCss = await transformGeneratorUserCss(userCssRawSource, userCssOptions);
|
|
2010
2477
|
css = createCssSourceOrderAppend$1(css, userCss);
|
|
2011
2478
|
}
|
|
2479
|
+
if (generated.target === "web") {
|
|
2480
|
+
const userCss = await transformGeneratorUserCss(userCssRawSource, userCssOptions);
|
|
2481
|
+
const missingUserCss = isCommentOnlyCss(userCss) ? "" : filterExistingCssRules(css, userCss);
|
|
2482
|
+
css = createCssSourceOrderAppend$1(css, missingUserCss);
|
|
2483
|
+
}
|
|
2484
|
+
if (generated.target === "weapp" && isEmptyCssSourceOrderParts(orderedExtraCss) && hasDistinctUserRawSource && !hasGeneratedCss && !hasGeneratedMarkers && !hasTailwindApplyDirective(userCssRawSource)) {
|
|
2485
|
+
const userCss = await transformGeneratorUserCss(userCssRawSource, userCssOptions);
|
|
2486
|
+
const missingUserCss = isCssAlreadyRepresentedByMarkers(css, userCssRawSource) ? filterExistingCssRules(css, userCss) : userCss;
|
|
2487
|
+
css = createCssSourceOrderAppend$1(css, missingUserCss);
|
|
2488
|
+
}
|
|
2012
2489
|
if (generated.target === "weapp" && shouldAppendMatchedCssSourceCompat) {
|
|
2013
2490
|
if (shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
|
|
2014
|
-
if (!shouldFilterApplyOnlyCss) {
|
|
2491
|
+
if (!shouldFilterApplyOnlyCss && !userRawSourceProcessed) {
|
|
2015
2492
|
css = await appendLegacyCompatCss(css, userCssRawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
2016
2493
|
if (!isolateCurrentCssCandidates) css = await appendLegacyContainerCompatCss(css, userCssRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
2017
2494
|
}
|
|
2018
2495
|
} else if (generated.target === "weapp" && shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
|
|
2019
2496
|
return {
|
|
2020
|
-
css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, {
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2497
|
+
css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, {
|
|
2498
|
+
injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
|
|
2499
|
+
cssHandlerOptions,
|
|
2500
|
+
isolateCurrentCssCandidates,
|
|
2501
|
+
localImports
|
|
2502
|
+
}),
|
|
2503
|
+
styleOptions: generatorStyleOptions
|
|
2504
|
+
}), localImports),
|
|
2505
|
+
classSet: generated.classSet,
|
|
2025
2506
|
target: generated.target,
|
|
2026
2507
|
source: "generator",
|
|
2027
|
-
dependencies: generated.dependencies
|
|
2508
|
+
dependencies: generated.dependencies,
|
|
2509
|
+
metadata: {
|
|
2510
|
+
file,
|
|
2511
|
+
majorVersion,
|
|
2512
|
+
rawCss: generated.rawCss
|
|
2513
|
+
}
|
|
2028
2514
|
};
|
|
2029
2515
|
}
|
|
2030
2516
|
debug("tailwind direct css generation prefix mismatch, append transformed bundle css %s", file);
|
|
2031
2517
|
let css = generatedCss;
|
|
2518
|
+
if (generated.target === "weapp" && generatorRawSource.includes("weapp-tailwindcss generator-placeholder") && !hasUserCssLayerBlocks(generatorRawSource)) css = createCssSourceOrderAppend$1(await transformGeneratorUserCss(userCssRawSource, {
|
|
2519
|
+
generatorTarget: generated.target,
|
|
2520
|
+
generatorStyleOptions,
|
|
2521
|
+
cssUserHandlerOptions,
|
|
2522
|
+
styleHandler,
|
|
2523
|
+
importFallback: generatorOptions.importFallback,
|
|
2524
|
+
processed: userRawSourceProcessed
|
|
2525
|
+
}), css);
|
|
2032
2526
|
if (generated.target === "weapp") {
|
|
2033
2527
|
css = inheritLegacyUnitConvertedDeclarations(css, generatorRawSource);
|
|
2034
2528
|
if (hasUserCssLayerBlocks(generatorRawSource)) {
|
|
@@ -2038,7 +2532,8 @@ async function generateCssByGenerator(options) {
|
|
|
2038
2532
|
generatorStyleOptions,
|
|
2039
2533
|
cssUserHandlerOptions,
|
|
2040
2534
|
styleHandler,
|
|
2041
|
-
importFallback: generatorOptions.importFallback
|
|
2535
|
+
importFallback: generatorOptions.importFallback,
|
|
2536
|
+
processed: userRawSourceProcessed
|
|
2042
2537
|
});
|
|
2043
2538
|
const layerCss = layerUserCss.trim().length > 0 && !hasTailwindApplyDirective(layerUserCss) ? {
|
|
2044
2539
|
layer: layerUserCss,
|
|
@@ -2051,18 +2546,44 @@ async function generateCssByGenerator(options) {
|
|
|
2051
2546
|
}
|
|
2052
2547
|
}
|
|
2053
2548
|
if (hasMatchedCssSourceFile || generated.target === "web") {
|
|
2054
|
-
if (
|
|
2549
|
+
if (generated.target === "weapp" && !hasGeneratedCss && !hasGeneratedMarkers) {
|
|
2055
2550
|
const userCss = await transformGeneratorUserCss(userCssRawSource, {
|
|
2056
2551
|
generatorTarget: generated.target,
|
|
2057
2552
|
generatorStyleOptions,
|
|
2058
2553
|
cssUserHandlerOptions,
|
|
2059
2554
|
styleHandler,
|
|
2060
|
-
importFallback: generatorOptions.importFallback
|
|
2555
|
+
importFallback: generatorOptions.importFallback,
|
|
2556
|
+
processed: userRawSourceProcessed
|
|
2061
2557
|
});
|
|
2062
|
-
|
|
2558
|
+
const missingUserCss = isCssAlreadyRepresentedByMarkers(css, userCssRawSource) ? filterExistingCssRules(css, userCss) : userCss;
|
|
2559
|
+
css = createCssSourceOrderAppend$1(css, missingUserCss);
|
|
2560
|
+
} else if (hasMatchedCssSourceFile && generated.target === "weapp" && hasGeneratedMarkers) {
|
|
2561
|
+
const userCss = await transformGeneratorUserCss(removeTailwindV4GeneratedUserCssArtifacts(userCssRawSource), {
|
|
2562
|
+
generatorTarget: generated.target,
|
|
2563
|
+
generatorStyleOptions,
|
|
2564
|
+
cssUserHandlerOptions,
|
|
2565
|
+
styleHandler,
|
|
2566
|
+
importFallback: generatorOptions.importFallback,
|
|
2567
|
+
processed: userRawSourceProcessed
|
|
2568
|
+
});
|
|
2569
|
+
const missingUserCss = filterExistingCssRules(css, userCss);
|
|
2570
|
+
css = createCssSourceOrderAppend$1(css, missingUserCss);
|
|
2571
|
+
} else if (hasMatchedCssSourceFile && generated.target === "weapp" && hasUserCssLayerBlocks(userCssRawSource)) {
|
|
2572
|
+
const layerUserCss = await transformGeneratorUserCss(splitUserCssLayerBlocks(userCssRawSource).layer, {
|
|
2573
|
+
generatorTarget: generated.target,
|
|
2574
|
+
generatorStyleOptions,
|
|
2575
|
+
cssUserHandlerOptions,
|
|
2576
|
+
styleHandler,
|
|
2577
|
+
importFallback: generatorOptions.importFallback,
|
|
2578
|
+
processed: userRawSourceProcessed
|
|
2579
|
+
});
|
|
2580
|
+
if (layerUserCss.trim().length > 0) {
|
|
2581
|
+
css = createCssSourceOrderAppend$1(css, wrapUserLayerComponentsCss(layerUserCss));
|
|
2582
|
+
if (shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
|
|
2583
|
+
}
|
|
2063
2584
|
}
|
|
2064
2585
|
if (hasMatchedCssSourceFile && generated.target === "weapp") {
|
|
2065
|
-
if (!isolateCurrentCssCandidates && !shouldFilterApplyOnlyCss) css = await appendLegacyContainerCompatCss(css, userCssRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
2586
|
+
if (!isolateCurrentCssCandidates && !shouldFilterApplyOnlyCss && !userRawSourceProcessed) css = await appendLegacyContainerCompatCss(css, userCssRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
2066
2587
|
}
|
|
2067
2588
|
if (shouldAppendWebBundleCssFallback(generated.target, {
|
|
2068
2589
|
hasSourceDirectives,
|
|
@@ -2073,34 +2594,66 @@ async function generateCssByGenerator(options) {
|
|
|
2073
2594
|
generatorStyleOptions,
|
|
2074
2595
|
cssUserHandlerOptions,
|
|
2075
2596
|
styleHandler,
|
|
2076
|
-
importFallback: generatorOptions.importFallback
|
|
2597
|
+
importFallback: generatorOptions.importFallback,
|
|
2598
|
+
processed: userRawSourceProcessed
|
|
2077
2599
|
});
|
|
2078
|
-
|
|
2600
|
+
const missingUserCss = isCommentOnlyCss(userCss) ? "" : filterExistingCssRules(css, userCss);
|
|
2601
|
+
css = createCssSourceOrderAppend$1(css, missingUserCss);
|
|
2079
2602
|
}
|
|
2080
2603
|
return {
|
|
2081
|
-
css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, {
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2604
|
+
css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, {
|
|
2605
|
+
injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
|
|
2606
|
+
cssHandlerOptions,
|
|
2607
|
+
isolateCurrentCssCandidates,
|
|
2608
|
+
localImports
|
|
2609
|
+
}),
|
|
2610
|
+
styleOptions: generatorStyleOptions
|
|
2611
|
+
}), localImports),
|
|
2612
|
+
classSet: generated.classSet,
|
|
2086
2613
|
target: generated.target,
|
|
2087
2614
|
source: "generator",
|
|
2088
|
-
dependencies: generated.dependencies
|
|
2615
|
+
dependencies: generated.dependencies,
|
|
2616
|
+
metadata: {
|
|
2617
|
+
file,
|
|
2618
|
+
majorVersion,
|
|
2619
|
+
rawCss: generated.rawCss
|
|
2620
|
+
}
|
|
2089
2621
|
};
|
|
2090
2622
|
}
|
|
2091
|
-
if (!shouldFilterApplyOnlyCss) {
|
|
2623
|
+
if (!shouldFilterApplyOnlyCss && !userRawSourceProcessed) {
|
|
2092
2624
|
css = await appendLegacyCompatCss(css, userCssRawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
2093
2625
|
css = await appendLegacyContainerCompatCss(css, userCssRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
2094
2626
|
}
|
|
2627
|
+
if (generated.target === "weapp" && hasDistinctUserRawSource && !hasGeneratedCss && !hasGeneratedMarkers && !hasTailwindApplyDirective(userCssRawSource)) {
|
|
2628
|
+
const userCss = await transformGeneratorUserCss(userCssRawSource, {
|
|
2629
|
+
generatorTarget: generated.target,
|
|
2630
|
+
generatorStyleOptions,
|
|
2631
|
+
cssUserHandlerOptions,
|
|
2632
|
+
styleHandler,
|
|
2633
|
+
importFallback: generatorOptions.importFallback,
|
|
2634
|
+
processed: userRawSourceProcessed
|
|
2635
|
+
});
|
|
2636
|
+
const missingUserCss = isCssAlreadyRepresentedByMarkers(css, userCssRawSource) ? filterExistingCssRules(css, userCss) : userCss;
|
|
2637
|
+
css = createCssSourceOrderAppend$1(css, missingUserCss);
|
|
2638
|
+
}
|
|
2095
2639
|
return {
|
|
2096
|
-
css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, {
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2640
|
+
css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, {
|
|
2641
|
+
injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
|
|
2642
|
+
cssHandlerOptions,
|
|
2643
|
+
isolateCurrentCssCandidates,
|
|
2644
|
+
localImports
|
|
2645
|
+
}),
|
|
2646
|
+
styleOptions: generatorStyleOptions
|
|
2647
|
+
}), localImports),
|
|
2648
|
+
classSet: generated.classSet,
|
|
2101
2649
|
target: generated.target,
|
|
2102
2650
|
source: "generator",
|
|
2103
|
-
dependencies: generated.dependencies
|
|
2651
|
+
dependencies: generated.dependencies,
|
|
2652
|
+
metadata: {
|
|
2653
|
+
file,
|
|
2654
|
+
majorVersion,
|
|
2655
|
+
rawCss: generated.rawCss
|
|
2656
|
+
}
|
|
2104
2657
|
};
|
|
2105
2658
|
} catch (error) {
|
|
2106
2659
|
debug("tailwind direct css generation failed: %s %O", file, error);
|
|
@@ -2201,182 +2754,19 @@ function collectEscapedRuntimeCandidates(source, escapeMap, escapeFragments) {
|
|
|
2201
2754
|
}
|
|
2202
2755
|
return candidates;
|
|
2203
2756
|
}
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
"bottom",
|
|
2214
|
-
"brightness",
|
|
2215
|
-
"caret",
|
|
2216
|
-
"col",
|
|
2217
|
-
"columns",
|
|
2218
|
-
"content",
|
|
2219
|
-
"contrast",
|
|
2220
|
-
"decoration",
|
|
2221
|
-
"delay",
|
|
2222
|
-
"divide",
|
|
2223
|
-
"drop-shadow",
|
|
2224
|
-
"duration",
|
|
2225
|
-
"ease",
|
|
2226
|
-
"fill",
|
|
2227
|
-
"font",
|
|
2228
|
-
"gap",
|
|
2229
|
-
"gradient",
|
|
2230
|
-
"grid",
|
|
2231
|
-
"grayscale",
|
|
2232
|
-
"grow",
|
|
2233
|
-
"h",
|
|
2234
|
-
"hue-rotate",
|
|
2235
|
-
"indent",
|
|
2236
|
-
"inset",
|
|
2237
|
-
"invert",
|
|
2238
|
-
"leading",
|
|
2239
|
-
"left",
|
|
2240
|
-
"list",
|
|
2241
|
-
"m",
|
|
2242
|
-
"max",
|
|
2243
|
-
"mb",
|
|
2244
|
-
"min",
|
|
2245
|
-
"ml",
|
|
2246
|
-
"mr",
|
|
2247
|
-
"mt",
|
|
2248
|
-
"mx",
|
|
2249
|
-
"my",
|
|
2250
|
-
"object",
|
|
2251
|
-
"opacity",
|
|
2252
|
-
"order",
|
|
2253
|
-
"outline",
|
|
2254
|
-
"overflow",
|
|
2255
|
-
"p",
|
|
2256
|
-
"pb",
|
|
2257
|
-
"pl",
|
|
2258
|
-
"pr",
|
|
2259
|
-
"pt",
|
|
2260
|
-
"px",
|
|
2261
|
-
"py",
|
|
2262
|
-
"right",
|
|
2263
|
-
"ring",
|
|
2264
|
-
"rotate",
|
|
2265
|
-
"rounded",
|
|
2266
|
-
"row",
|
|
2267
|
-
"saturate",
|
|
2268
|
-
"scale",
|
|
2269
|
-
"scroll",
|
|
2270
|
-
"sepia",
|
|
2271
|
-
"shadow",
|
|
2272
|
-
"shrink",
|
|
2273
|
-
"skew",
|
|
2274
|
-
"space",
|
|
2275
|
-
"stroke",
|
|
2276
|
-
"text",
|
|
2277
|
-
"top",
|
|
2278
|
-
"tracking",
|
|
2279
|
-
"translate",
|
|
2280
|
-
"underline",
|
|
2281
|
-
"w",
|
|
2282
|
-
"z"
|
|
2283
|
-
]);
|
|
2284
|
-
function isUrlLikeCandidate(candidate) {
|
|
2285
|
-
return candidate.startsWith("//") || candidate.startsWith("http://") || candidate.startsWith("https://");
|
|
2286
|
-
}
|
|
2287
|
-
function getBaseUtilityCandidate(candidate) {
|
|
2288
|
-
let bracketDepth = 0;
|
|
2289
|
-
let lastVariantSeparator = -1;
|
|
2290
|
-
for (let index = 0; index < candidate.length; index++) {
|
|
2291
|
-
const char = candidate[index];
|
|
2292
|
-
if (char === "[") bracketDepth += 1;
|
|
2293
|
-
else if (char === "]") bracketDepth = Math.max(0, bracketDepth - 1);
|
|
2294
|
-
else if (char === ":" && bracketDepth === 0) lastVariantSeparator = index;
|
|
2295
|
-
}
|
|
2296
|
-
let utility = lastVariantSeparator >= 0 ? candidate.slice(lastVariantSeparator + 1) : candidate;
|
|
2297
|
-
if (utility.startsWith("!")) utility = utility.slice(1);
|
|
2298
|
-
if (utility.startsWith("-")) utility = utility.slice(1);
|
|
2299
|
-
return utility;
|
|
2300
|
-
}
|
|
2301
|
-
function getArbitraryUtilityPrefix(utility) {
|
|
2302
|
-
const bracketIndex = utility.indexOf("[");
|
|
2303
|
-
if (bracketIndex <= 0 || !utility.endsWith("]")) return;
|
|
2304
|
-
const prefix = utility.slice(0, bracketIndex).replace(/-$/, "");
|
|
2305
|
-
const firstDash = prefix.indexOf("-");
|
|
2306
|
-
return firstDash >= 0 ? prefix.slice(0, firstDash) : prefix;
|
|
2307
|
-
}
|
|
2308
|
-
function isLikelyTailwindV3ArbitraryUtility(candidate) {
|
|
2309
|
-
const utility = getBaseUtilityCandidate(candidate);
|
|
2310
|
-
if (utility.startsWith("[") && utility.endsWith("]") && utility.includes(":")) return true;
|
|
2311
|
-
const prefix = getArbitraryUtilityPrefix(utility);
|
|
2312
|
-
return Boolean(prefix && TAILWIND_V3_ARBITRARY_UTILITY_PREFIXES.has(prefix));
|
|
2313
|
-
}
|
|
2314
|
-
function isLikelyTailwindV3VariantUtility(candidate) {
|
|
2315
|
-
if (!candidate.includes(":") || isUrlLikeCandidate(candidate)) return false;
|
|
2316
|
-
const utility = getBaseUtilityCandidate(candidate);
|
|
2317
|
-
return /^[!-]?[a-z@[]/.test(utility);
|
|
2318
|
-
}
|
|
2319
|
-
function isLikelyTailwindV3OpacityModifier(candidate) {
|
|
2320
|
-
if (!candidate.includes("/") || isUrlLikeCandidate(candidate)) return false;
|
|
2321
|
-
const utility = getBaseUtilityCandidate(candidate);
|
|
2322
|
-
return /^[!-]?[a-z][\w-]*-\w[\w-]*\/(?:\d+|\[[^\]]+\])$/.test(utility);
|
|
2323
|
-
}
|
|
2324
|
-
function isHighConfidenceV3Candidate(candidate) {
|
|
2325
|
-
return isLikelyTailwindV3ArbitraryUtility(candidate) || isLikelyTailwindV3VariantUtility(candidate) || isLikelyTailwindV3OpacityModifier(candidate);
|
|
2326
|
-
}
|
|
2327
|
-
function isRawCandidateInClassContext(source, start, extension) {
|
|
2328
|
-
if (typeof start !== "number" || start <= 0) return false;
|
|
2329
|
-
const before = source.slice(Math.max(0, start - 200), start);
|
|
2330
|
-
if (extension === "html") return /\bclass\s*=\s*["'][^"']*$/i.test(before);
|
|
2331
|
-
return /\bclass(?:Name)?\s*[:=]\s*["'][^"']*$/i.test(before) || /\.classList\.(?:add|remove|toggle|contains)\([^)]*$/i.test(before);
|
|
2332
|
-
}
|
|
2333
|
-
function resolveQuotedLiteralRange(source, start) {
|
|
2334
|
-
if (typeof start !== "number" || start <= 0) return;
|
|
2335
|
-
let quote;
|
|
2336
|
-
let literalStart = -1;
|
|
2337
|
-
for (let index = start - 1; index >= 0; index--) {
|
|
2338
|
-
const char = source[index];
|
|
2339
|
-
if (char !== "\"" && char !== "'" && char !== "`") continue;
|
|
2340
|
-
quote = char;
|
|
2341
|
-
literalStart = index;
|
|
2342
|
-
break;
|
|
2343
|
-
}
|
|
2344
|
-
if (!quote) return;
|
|
2345
|
-
let escaped = false;
|
|
2346
|
-
for (let index = literalStart + 1; index < source.length; index++) {
|
|
2347
|
-
const char = source[index];
|
|
2348
|
-
if (escaped) {
|
|
2349
|
-
escaped = false;
|
|
2350
|
-
continue;
|
|
2351
|
-
}
|
|
2352
|
-
if (char === "\\") {
|
|
2353
|
-
escaped = true;
|
|
2354
|
-
continue;
|
|
2355
|
-
}
|
|
2356
|
-
if (char === quote) {
|
|
2357
|
-
if (start < index) return {
|
|
2358
|
-
start: literalStart,
|
|
2359
|
-
end: index
|
|
2360
|
-
};
|
|
2361
|
-
return;
|
|
2757
|
+
function collectStrictEscapedRuntimeCandidates(source, escapeMap, escapeFragments) {
|
|
2758
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
2759
|
+
ESCAPED_CLASS_TOKEN_RE.lastIndex = 0;
|
|
2760
|
+
let match = ESCAPED_CLASS_TOKEN_RE.exec(source);
|
|
2761
|
+
while (match) {
|
|
2762
|
+
const token = match[0];
|
|
2763
|
+
if (hasEscapeFragment(token, escapeFragments)) {
|
|
2764
|
+
const restored = unescape(token, { map: escapeMap });
|
|
2765
|
+
if (restored !== token && TAILWIND_RESTORED_CANDIDATE_SIGNAL_RE.test(restored) && !/\s/.test(restored)) candidates.add(restored);
|
|
2362
2766
|
}
|
|
2767
|
+
match = ESCAPED_CLASS_TOKEN_RE.exec(source);
|
|
2363
2768
|
}
|
|
2364
|
-
|
|
2365
|
-
function createHighConfidenceLiteralRanges(source, matches) {
|
|
2366
|
-
const ranges = [];
|
|
2367
|
-
for (const match of matches) {
|
|
2368
|
-
const candidate = match?.rawCandidate;
|
|
2369
|
-
if (typeof candidate !== "string" || !isHighConfidenceV3Candidate(candidate)) continue;
|
|
2370
|
-
const range = resolveQuotedLiteralRange(source, match?.start ?? source.indexOf(candidate));
|
|
2371
|
-
if (range) ranges.push(range);
|
|
2372
|
-
}
|
|
2373
|
-
return ranges;
|
|
2374
|
-
}
|
|
2375
|
-
function isRawCandidateInRanges(start, ranges) {
|
|
2376
|
-
return typeof start === "number" && ranges.some((range) => start > range.start && start < range.end);
|
|
2377
|
-
}
|
|
2378
|
-
function isRawCandidateAllowedForV3(source, candidate, start, extension, knownSourceCandidates, highConfidenceLiteralRanges = []) {
|
|
2379
|
-
return isHighConfidenceV3Candidate(candidate) || knownSourceCandidates?.has(candidate) === true || isRawCandidateInClassContext(source, start, extension) || isRawCandidateInRanges(start, highConfidenceLiteralRanges);
|
|
2769
|
+
return candidates;
|
|
2380
2770
|
}
|
|
2381
2771
|
//#endregion
|
|
2382
2772
|
//#region src/bundlers/vite/incremental-runtime-class-set.ts
|
|
@@ -2442,8 +2832,8 @@ function createBundleRuntimeClassSetManager(options = {}) {
|
|
|
2442
2832
|
validationContext = void 0;
|
|
2443
2833
|
designSystemPromise = void 0;
|
|
2444
2834
|
}
|
|
2445
|
-
async function resolveValidationContextCached(
|
|
2446
|
-
if (!validationContext) validationContext = await
|
|
2835
|
+
async function resolveValidationContextCached(runtime) {
|
|
2836
|
+
if (!validationContext) validationContext = await resolveTailwindV4SourceFromRuntime(runtime);
|
|
2447
2837
|
return validationContext;
|
|
2448
2838
|
}
|
|
2449
2839
|
async function loadDesignSystem(context) {
|
|
@@ -2454,13 +2844,9 @@ function createBundleRuntimeClassSetManager(options = {}) {
|
|
|
2454
2844
|
const validCandidates = resolveValidTailwindV4Candidates(designSystem, unknownCandidates, { ...options.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: options.bareArbitraryValues } });
|
|
2455
2845
|
for (const candidate of unknownCandidates) candidateValidityCache.set(candidate, validCandidates.has(candidate));
|
|
2456
2846
|
}
|
|
2457
|
-
async function validateUnknownCandidates(
|
|
2847
|
+
async function validateUnknownCandidates(runtime, unknownCandidates) {
|
|
2458
2848
|
if (unknownCandidates.size === 0) return;
|
|
2459
|
-
|
|
2460
|
-
for (const candidate of unknownCandidates) candidateValidityCache.set(candidate, true);
|
|
2461
|
-
return;
|
|
2462
|
-
}
|
|
2463
|
-
const context = await resolveValidationContextCached(patcher);
|
|
2849
|
+
const context = await resolveValidationContextCached(runtime);
|
|
2464
2850
|
if (!customExtractCandidates) try {
|
|
2465
2851
|
populateCandidateValidityCacheFromDesignSystem(await loadDesignSystem(context), unknownCandidates);
|
|
2466
2852
|
return;
|
|
@@ -2473,23 +2859,19 @@ function createBundleRuntimeClassSetManager(options = {}) {
|
|
|
2473
2859
|
const validCandidates = new Set(await extractCandidates(createExtractOptions(context, source, options.bareArbitraryValues)));
|
|
2474
2860
|
for (const candidate of unknownCandidates) candidateValidityCache.set(candidate, validCandidates.has(candidate));
|
|
2475
2861
|
}
|
|
2476
|
-
async function extractEntryRawCandidates(entry,
|
|
2862
|
+
async function extractEntryRawCandidates(entry, _runtime, _knownSourceCandidates) {
|
|
2477
2863
|
const extension = resolveEntryExtension(entry);
|
|
2478
2864
|
const matches = options.bareArbitraryValues === void 0 || options.bareArbitraryValues === false ? await extractRawCandidates(entry.source, extension) : await extractRawCandidates(entry.source, extension, { bareArbitraryValues: options.bareArbitraryValues });
|
|
2479
|
-
const highConfidenceLiteralRanges = patcher.majorVersion === 3 && !customExtractCandidates ? createHighConfidenceLiteralRanges(entry.source, matches) : [];
|
|
2480
2865
|
const candidates = /* @__PURE__ */ new Set();
|
|
2481
2866
|
for (const match of matches) {
|
|
2482
2867
|
const candidate = match?.rawCandidate;
|
|
2483
|
-
if (typeof candidate === "string" && candidate.length > 0)
|
|
2484
|
-
if (patcher.majorVersion === 3 && !customExtractCandidates && !isRawCandidateAllowedForV3(entry.source, candidate, match.start, extension, knownSourceCandidates, highConfidenceLiteralRanges)) continue;
|
|
2485
|
-
candidates.add(candidate);
|
|
2486
|
-
}
|
|
2868
|
+
if (typeof candidate === "string" && candidate.length > 0) candidates.add(candidate);
|
|
2487
2869
|
}
|
|
2488
|
-
|
|
2870
|
+
for (const candidate of collectEscapedRuntimeCandidates(entry.source, escapeMap, escapeFragments)) candidates.add(candidate);
|
|
2489
2871
|
return candidates;
|
|
2490
2872
|
}
|
|
2491
|
-
async function sync(
|
|
2492
|
-
const nextSignature = getRuntimeClassSetSignature(
|
|
2873
|
+
async function sync(runtime, snapshot, options = {}) {
|
|
2874
|
+
const nextSignature = getRuntimeClassSetSignature(runtime) ?? "runtime:missing";
|
|
2493
2875
|
const runtimeEntries = createRuntimeEntries(snapshot);
|
|
2494
2876
|
const runtimeEntriesByFile = new Map(runtimeEntries.map((entry) => [entry.file, entry]));
|
|
2495
2877
|
const currentRuntimeFiles = new Set(runtimeEntriesByFile.keys());
|
|
@@ -2514,14 +2896,14 @@ function createBundleRuntimeClassSetManager(options = {}) {
|
|
|
2514
2896
|
}
|
|
2515
2897
|
const rawCandidatesByFile = /* @__PURE__ */ new Map();
|
|
2516
2898
|
const unknownCandidates = /* @__PURE__ */ new Set();
|
|
2517
|
-
|
|
2899
|
+
for (const file of changedRuntimeFiles) {
|
|
2518
2900
|
const entry = runtimeEntriesByFile.get(file);
|
|
2519
|
-
if (!entry)
|
|
2520
|
-
const candidates = await extractEntryRawCandidates(entry,
|
|
2901
|
+
if (!entry) continue;
|
|
2902
|
+
const candidates = await extractEntryRawCandidates(entry, runtime, nextBaseClassSet);
|
|
2521
2903
|
rawCandidatesByFile.set(file, candidates);
|
|
2522
2904
|
for (const candidate of candidates) if (!candidateValidityCache.has(candidate)) unknownCandidates.add(candidate);
|
|
2523
|
-
}
|
|
2524
|
-
await validateUnknownCandidates(
|
|
2905
|
+
}
|
|
2906
|
+
await validateUnknownCandidates(runtime, unknownCandidates);
|
|
2525
2907
|
let rawCandidateCount = 0;
|
|
2526
2908
|
for (const file of changedRuntimeFiles) {
|
|
2527
2909
|
const nextRawCandidates = rawCandidatesByFile.get(file);
|
|
@@ -2551,6 +2933,52 @@ function createBundleRuntimeClassSetManager(options = {}) {
|
|
|
2551
2933
|
};
|
|
2552
2934
|
}
|
|
2553
2935
|
//#endregion
|
|
2936
|
+
//#region src/tailwindcss/candidates.ts
|
|
2937
|
+
const SCRIPT_SOURCE_CANDIDATE_EXTENSIONS = new Set([
|
|
2938
|
+
"js",
|
|
2939
|
+
"jsx",
|
|
2940
|
+
"mjs",
|
|
2941
|
+
"cjs",
|
|
2942
|
+
"ts",
|
|
2943
|
+
"tsx",
|
|
2944
|
+
"mts",
|
|
2945
|
+
"cts"
|
|
2946
|
+
]);
|
|
2947
|
+
async function extractCandidatesFromSource(source, extension, options = {}) {
|
|
2948
|
+
const candidates = options.extractor ? new Set(await options.extractor(source, extension)) : new Set(await extractSourceCandidates(source, extension, { ...options.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: options.bareArbitraryValues } }));
|
|
2949
|
+
const scriptCandidates = await extractScriptStringCandidates(source, extension, options);
|
|
2950
|
+
for (const candidate of scriptCandidates) candidates.add(candidate);
|
|
2951
|
+
return candidates;
|
|
2952
|
+
}
|
|
2953
|
+
async function extractScriptStringCandidates(source, extension, options) {
|
|
2954
|
+
if (!SCRIPT_SOURCE_CANDIDATE_EXTENSIONS.has(extension)) return [];
|
|
2955
|
+
const values = /* @__PURE__ */ new Set();
|
|
2956
|
+
try {
|
|
2957
|
+
traverse(babelParse(source, {
|
|
2958
|
+
cache: true,
|
|
2959
|
+
cacheKey: `source-candidates:${extension}`,
|
|
2960
|
+
plugins: ["jsx", "typescript"],
|
|
2961
|
+
sourceType: "unambiguous"
|
|
2962
|
+
}), {
|
|
2963
|
+
noScope: true,
|
|
2964
|
+
StringLiteral(path) {
|
|
2965
|
+
values.add(path.node.value);
|
|
2966
|
+
},
|
|
2967
|
+
TemplateElement(path) {
|
|
2968
|
+
values.add(path.node.value.raw);
|
|
2969
|
+
}
|
|
2970
|
+
});
|
|
2971
|
+
} catch {
|
|
2972
|
+
return [];
|
|
2973
|
+
}
|
|
2974
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
2975
|
+
for (const value of values) {
|
|
2976
|
+
const extractedCandidates = options.extractor ? await options.extractor(value, "html") : await extractSourceCandidates(value, "html", { ...options.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: options.bareArbitraryValues } });
|
|
2977
|
+
for (const candidate of extractedCandidates) candidates.add(candidate);
|
|
2978
|
+
}
|
|
2979
|
+
return candidates;
|
|
2980
|
+
}
|
|
2981
|
+
//#endregion
|
|
2554
2982
|
//#region src/bundlers/vite/source-candidates/scan-root.ts
|
|
2555
2983
|
const TAILWIND_V4_IGNORED_CONTENT_DIRS = [
|
|
2556
2984
|
".git",
|
|
@@ -2658,109 +3086,6 @@ function resolveSourceCandidateScanFiles(options) {
|
|
|
2658
3086
|
});
|
|
2659
3087
|
}
|
|
2660
3088
|
//#endregion
|
|
2661
|
-
//#region src/bundlers/vite/source-candidates/script.ts
|
|
2662
|
-
const SCRIPT_SOURCE_CANDIDATE_EXTENSIONS = new Set([
|
|
2663
|
-
"js",
|
|
2664
|
-
"jsx",
|
|
2665
|
-
"mjs",
|
|
2666
|
-
"cjs",
|
|
2667
|
-
"ts",
|
|
2668
|
-
"tsx",
|
|
2669
|
-
"mts",
|
|
2670
|
-
"cts"
|
|
2671
|
-
]);
|
|
2672
|
-
const CLASS_LIKE_NAME_RE = /class/i;
|
|
2673
|
-
function getPropertyName(node) {
|
|
2674
|
-
if (!node) return;
|
|
2675
|
-
if (node.type === "Identifier") return node.name;
|
|
2676
|
-
if (node.type === "StringLiteral") return node.value;
|
|
2677
|
-
}
|
|
2678
|
-
function isClassLikeStringPath(path) {
|
|
2679
|
-
const parent = path.parentPath;
|
|
2680
|
-
if (!parent) return false;
|
|
2681
|
-
if (parent.isVariableDeclarator?.()) return CLASS_LIKE_NAME_RE.test(getPropertyName(parent.node.id) ?? "");
|
|
2682
|
-
if (parent.isObjectProperty?.() || parent.isObjectMethod?.()) return CLASS_LIKE_NAME_RE.test(getPropertyName(parent.node.key) ?? "");
|
|
2683
|
-
if (parent.isAssignmentExpression?.()) {
|
|
2684
|
-
const left = parent.node.left;
|
|
2685
|
-
if (left?.type === "Identifier") return CLASS_LIKE_NAME_RE.test(left.name);
|
|
2686
|
-
if (left?.type === "MemberExpression") return CLASS_LIKE_NAME_RE.test(getPropertyName(left.property) ?? "");
|
|
2687
|
-
}
|
|
2688
|
-
if (parent.isJSXAttribute?.()) return CLASS_LIKE_NAME_RE.test(getPropertyName(parent.node.name) ?? "");
|
|
2689
|
-
return false;
|
|
2690
|
-
}
|
|
2691
|
-
function isTemplateElementInClassLikePath(path) {
|
|
2692
|
-
const templateLiteralPath = path.parentPath;
|
|
2693
|
-
if (!templateLiteralPath?.isTemplateLiteral?.()) return false;
|
|
2694
|
-
const parent = templateLiteralPath.parentPath;
|
|
2695
|
-
if (!parent) return false;
|
|
2696
|
-
if (parent.isVariableDeclarator?.()) return CLASS_LIKE_NAME_RE.test(getPropertyName(parent.node.id) ?? "");
|
|
2697
|
-
if (parent.isObjectProperty?.() || parent.isObjectMethod?.()) return CLASS_LIKE_NAME_RE.test(getPropertyName(parent.node.key) ?? "");
|
|
2698
|
-
if (parent.isAssignmentExpression?.()) {
|
|
2699
|
-
const left = parent.node.left;
|
|
2700
|
-
if (left?.type === "Identifier") return CLASS_LIKE_NAME_RE.test(left.name);
|
|
2701
|
-
if (left?.type === "MemberExpression") return CLASS_LIKE_NAME_RE.test(getPropertyName(left.property) ?? "");
|
|
2702
|
-
}
|
|
2703
|
-
return false;
|
|
2704
|
-
}
|
|
2705
|
-
async function extractScriptStringCandidates(source, extension, options) {
|
|
2706
|
-
if (!SCRIPT_SOURCE_CANDIDATE_EXTENSIONS.has(extension)) return [];
|
|
2707
|
-
const values = /* @__PURE__ */ new Set();
|
|
2708
|
-
try {
|
|
2709
|
-
traverse(babelParse(source, {
|
|
2710
|
-
cache: true,
|
|
2711
|
-
cacheKey: `vite-source-candidates:${extension}`,
|
|
2712
|
-
plugins: ["jsx", "typescript"],
|
|
2713
|
-
sourceType: "unambiguous"
|
|
2714
|
-
}), {
|
|
2715
|
-
noScope: true,
|
|
2716
|
-
StringLiteral(path) {
|
|
2717
|
-
if (isClassLikeStringPath(path)) values.add(path.node.value);
|
|
2718
|
-
},
|
|
2719
|
-
TemplateElement(path) {
|
|
2720
|
-
if (isTemplateElementInClassLikePath(path)) values.add(path.node.value.raw);
|
|
2721
|
-
}
|
|
2722
|
-
});
|
|
2723
|
-
} catch {
|
|
2724
|
-
return [];
|
|
2725
|
-
}
|
|
2726
|
-
const candidates = /* @__PURE__ */ new Set();
|
|
2727
|
-
for (const value of values) {
|
|
2728
|
-
const extractedCandidates = options.extractor ? await options.extractor(value, "html") : await extractSourceCandidates(value, "html", { ...options.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: options.bareArbitraryValues } });
|
|
2729
|
-
for (const candidate of extractedCandidates) candidates.add(candidate);
|
|
2730
|
-
}
|
|
2731
|
-
return candidates;
|
|
2732
|
-
}
|
|
2733
|
-
//#endregion
|
|
2734
|
-
//#region src/bundlers/vite/source-candidates/tailwind-v3-default-extractor.ts
|
|
2735
|
-
const require = createRequire(import.meta.url);
|
|
2736
|
-
const TAILWIND_V3_HTML_TOKEN_CANDIDATES = new Set([
|
|
2737
|
-
"/block",
|
|
2738
|
-
"/div",
|
|
2739
|
-
"/span",
|
|
2740
|
-
"/template",
|
|
2741
|
-
"/text",
|
|
2742
|
-
"/view",
|
|
2743
|
-
"class",
|
|
2744
|
-
"className",
|
|
2745
|
-
"div",
|
|
2746
|
-
"hover-class",
|
|
2747
|
-
"span",
|
|
2748
|
-
"template",
|
|
2749
|
-
"text",
|
|
2750
|
-
"view"
|
|
2751
|
-
]);
|
|
2752
|
-
function createTailwindV3DefaultExtractor() {
|
|
2753
|
-
try {
|
|
2754
|
-
const defaultExtractorModule = require("tailwindcss/lib/lib/defaultExtractor");
|
|
2755
|
-
const resolveConfigModule = require("tailwindcss/resolveConfig");
|
|
2756
|
-
const resolveConfig = resolveConfigModule.default ?? resolveConfigModule;
|
|
2757
|
-
const extractor = (defaultExtractorModule.defaultExtractor ?? defaultExtractorModule.default ?? defaultExtractorModule)({ tailwindConfig: resolveConfig({ content: [] }) });
|
|
2758
|
-
return (source) => new Set(extractor(source).filter((candidate) => !TAILWIND_V3_HTML_TOKEN_CANDIDATES.has(candidate)));
|
|
2759
|
-
} catch {
|
|
2760
|
-
return;
|
|
2761
|
-
}
|
|
2762
|
-
}
|
|
2763
|
-
//#endregion
|
|
2764
3089
|
//#region src/bundlers/vite/source-candidates.ts
|
|
2765
3090
|
const CLEAN_URL_RE = /[?#].*$/;
|
|
2766
3091
|
const sourceCandidateContentCache = new LRUCache({ max: 128 });
|
|
@@ -2775,10 +3100,7 @@ function createSourceCandidateContentCacheKey(extension, source, bareArbitraryVa
|
|
|
2775
3100
|
return `${extension}\0${JSON.stringify(bareArbitraryValues ?? false)}\0${extractor ? "custom" : "default"}\0${md5Hash(source)}`;
|
|
2776
3101
|
}
|
|
2777
3102
|
async function extractCandidates(source, extension, options) {
|
|
2778
|
-
|
|
2779
|
-
const scriptCandidates = await extractScriptStringCandidates(source, extension, options);
|
|
2780
|
-
for (const candidate of scriptCandidates) candidates.add(candidate);
|
|
2781
|
-
return candidates;
|
|
3103
|
+
return extractCandidatesFromSource(source, extension, options);
|
|
2782
3104
|
}
|
|
2783
3105
|
function isSourceCandidateRequest(id) {
|
|
2784
3106
|
return FULL_SOURCE_SCAN_EXTENSION_RE.test(cleanUrl(id));
|
|
@@ -2797,18 +3119,20 @@ function removeCandidateSet(candidateCount, candidates) {
|
|
|
2797
3119
|
function addCandidateSet(candidateCount, candidates) {
|
|
2798
3120
|
for (const candidate of candidates) candidateCount.set(candidate, (candidateCount.get(candidate) ?? 0) + 1);
|
|
2799
3121
|
}
|
|
2800
|
-
function
|
|
3122
|
+
function createSourceCandidateStore(options = {}) {
|
|
2801
3123
|
const candidatesById = /* @__PURE__ */ new Map();
|
|
2802
3124
|
const scanCandidatesById = /* @__PURE__ */ new Map();
|
|
2803
3125
|
const transformCandidatesById = /* @__PURE__ */ new Map();
|
|
2804
3126
|
const cssCandidatesById = /* @__PURE__ */ new Map();
|
|
2805
|
-
const
|
|
3127
|
+
const scanSourceById = /* @__PURE__ */ new Map();
|
|
3128
|
+
const transformSourceById = /* @__PURE__ */ new Map();
|
|
3129
|
+
const cssSourceById = /* @__PURE__ */ new Map();
|
|
2806
3130
|
const candidateCount = /* @__PURE__ */ new Map();
|
|
2807
3131
|
let inlineIncludedCandidates = /* @__PURE__ */ new Set();
|
|
2808
3132
|
let inlineExcludedCandidates = /* @__PURE__ */ new Set();
|
|
2809
3133
|
async function sync(id, source) {
|
|
2810
3134
|
const normalizedId = cleanUrl(id);
|
|
2811
|
-
|
|
3135
|
+
scanSourceById.set(normalizedId, source);
|
|
2812
3136
|
const extension = resolveSourceCandidateExtension(normalizedId);
|
|
2813
3137
|
const contentCacheKey = createSourceCandidateContentCacheKey(extension, source, options.bareArbitraryValues, options.extractor);
|
|
2814
3138
|
const cachedCandidates = sourceCandidateContentCache.get(contentCacheKey);
|
|
@@ -2822,6 +3146,7 @@ function createSourceCandidateCollector(options = {}) {
|
|
|
2822
3146
|
}
|
|
2823
3147
|
async function syncCss(id, source) {
|
|
2824
3148
|
const normalizedId = cleanUrl(id);
|
|
3149
|
+
cssSourceById.set(normalizedId, source);
|
|
2825
3150
|
const contentCacheKey = createSourceCandidateContentCacheKey("css", source, options.bareArbitraryValues, options.extractor);
|
|
2826
3151
|
const cachedCandidates = sourceCandidateContentCache.get(contentCacheKey);
|
|
2827
3152
|
if (cachedCandidates) {
|
|
@@ -2834,6 +3159,7 @@ function createSourceCandidateCollector(options = {}) {
|
|
|
2834
3159
|
}
|
|
2835
3160
|
async function merge(id, source) {
|
|
2836
3161
|
const normalizedId = cleanUrl(id);
|
|
3162
|
+
transformSourceById.set(normalizedId, source);
|
|
2837
3163
|
const extension = resolveSourceCandidateExtension(normalizedId);
|
|
2838
3164
|
const contentCacheKey = createSourceCandidateContentCacheKey(extension, source, options.bareArbitraryValues, options.extractor);
|
|
2839
3165
|
const cachedCandidates = sourceCandidateContentCache.get(contentCacheKey);
|
|
@@ -2843,11 +3169,20 @@ function createSourceCandidateCollector(options = {}) {
|
|
|
2843
3169
|
}
|
|
2844
3170
|
async function syncFile(id) {
|
|
2845
3171
|
const normalizedId = cleanUrl(id);
|
|
2846
|
-
|
|
3172
|
+
try {
|
|
3173
|
+
await sync(normalizedId, await readFile(normalizedId, "utf8"));
|
|
3174
|
+
} catch (error) {
|
|
3175
|
+
if ((typeof error === "object" && error !== null && "code" in error ? error.code : void 0) === "ENOENT") {
|
|
3176
|
+
remove(normalizedId);
|
|
3177
|
+
return;
|
|
3178
|
+
}
|
|
3179
|
+
throw error;
|
|
3180
|
+
}
|
|
2847
3181
|
}
|
|
2848
3182
|
async function syncCurrentFile(id) {
|
|
2849
3183
|
const normalizedId = cleanUrl(id);
|
|
2850
3184
|
transformCandidatesById.delete(normalizedId);
|
|
3185
|
+
cssCandidatesById.delete(normalizedId);
|
|
2851
3186
|
await syncFile(normalizedId);
|
|
2852
3187
|
}
|
|
2853
3188
|
async function scanRoot({ entries, explicit, root, outDir }) {
|
|
@@ -2906,14 +3241,20 @@ function createSourceCandidateCollector(options = {}) {
|
|
|
2906
3241
|
scanCandidatesById.delete(normalizedId);
|
|
2907
3242
|
transformCandidatesById.delete(normalizedId);
|
|
2908
3243
|
cssCandidatesById.delete(normalizedId);
|
|
2909
|
-
|
|
3244
|
+
scanSourceById.delete(normalizedId);
|
|
3245
|
+
transformSourceById.delete(normalizedId);
|
|
3246
|
+
cssSourceById.delete(normalizedId);
|
|
2910
3247
|
const previousCandidates = candidatesById.get(normalizedId);
|
|
2911
3248
|
if (!previousCandidates) return;
|
|
2912
3249
|
removeCandidateSet(candidateCount, previousCandidates);
|
|
2913
3250
|
candidatesById.delete(normalizedId);
|
|
2914
3251
|
}
|
|
2915
3252
|
function source(id) {
|
|
2916
|
-
|
|
3253
|
+
const normalizedId = cleanUrl(id);
|
|
3254
|
+
return scanSourceById.get(normalizedId) ?? cssSourceById.get(normalizedId) ?? transformSourceById.get(normalizedId);
|
|
3255
|
+
}
|
|
3256
|
+
function sources() {
|
|
3257
|
+
return mergeSourcesByPriority().entries();
|
|
2917
3258
|
}
|
|
2918
3259
|
function values() {
|
|
2919
3260
|
const values = new Set([...candidateCount.keys(), ...inlineIncludedCandidates]);
|
|
@@ -2924,6 +3265,7 @@ function createSourceCandidateCollector(options = {}) {
|
|
|
2924
3265
|
if (entries === void 0) {
|
|
2925
3266
|
if (!options.excludeEntries?.length) return values();
|
|
2926
3267
|
}
|
|
3268
|
+
if (entries?.length === 0) return new Set(inlineIncludedCandidates);
|
|
2927
3269
|
const filtered = /* @__PURE__ */ new Set();
|
|
2928
3270
|
for (const [id, candidates] of candidatesById) {
|
|
2929
3271
|
if (entries !== void 0 && !isFileMatchedByTailwindSourceEntries(id, entries)) continue;
|
|
@@ -2944,6 +3286,11 @@ function createSourceCandidateCollector(options = {}) {
|
|
|
2944
3286
|
}
|
|
2945
3287
|
if (id) candidateSources.add(id);
|
|
2946
3288
|
};
|
|
3289
|
+
if (entries?.length === 0) {
|
|
3290
|
+
for (const candidate of inlineIncludedCandidates) addCandidateSource(candidate, void 0);
|
|
3291
|
+
for (const candidate of inlineExcludedCandidates) sources.delete(candidate);
|
|
3292
|
+
return sources;
|
|
3293
|
+
}
|
|
2947
3294
|
for (const [id, candidates] of candidatesById) {
|
|
2948
3295
|
if (entries !== void 0 && !isFileMatchedByTailwindSourceEntries(id, entries)) continue;
|
|
2949
3296
|
if (options.excludeEntries?.length && isFileMatchedByTailwindSourceEntries(id, options.excludeEntries)) continue;
|
|
@@ -2958,18 +3305,35 @@ function createSourceCandidateCollector(options = {}) {
|
|
|
2958
3305
|
scanCandidatesById.clear();
|
|
2959
3306
|
transformCandidatesById.clear();
|
|
2960
3307
|
cssCandidatesById.clear();
|
|
2961
|
-
|
|
3308
|
+
scanSourceById.clear();
|
|
3309
|
+
transformSourceById.clear();
|
|
3310
|
+
cssSourceById.clear();
|
|
2962
3311
|
candidateCount.clear();
|
|
2963
3312
|
inlineIncludedCandidates.clear();
|
|
2964
3313
|
inlineExcludedCandidates.clear();
|
|
2965
3314
|
}
|
|
3315
|
+
function clearScan() {
|
|
3316
|
+
for (const id of scanCandidatesById.keys()) {
|
|
3317
|
+
scanCandidatesById.delete(id);
|
|
3318
|
+
recompute(id);
|
|
3319
|
+
}
|
|
3320
|
+
inlineIncludedCandidates.clear();
|
|
3321
|
+
inlineExcludedCandidates.clear();
|
|
3322
|
+
}
|
|
3323
|
+
function resetScan() {
|
|
3324
|
+
inlineIncludedCandidates.clear();
|
|
3325
|
+
inlineExcludedCandidates.clear();
|
|
3326
|
+
}
|
|
2966
3327
|
function snapshot() {
|
|
2967
3328
|
return {
|
|
2968
3329
|
candidatesById: [...candidatesById.entries()].map(([id, candidates]) => [id, [...candidates]]),
|
|
2969
3330
|
cssCandidatesById: [...cssCandidatesById.entries()].map(([id, candidates]) => [id, [...candidates]]),
|
|
3331
|
+
cssSourceById: [...cssSourceById.entries()],
|
|
2970
3332
|
scanCandidatesById: [...scanCandidatesById.entries()].map(([id, candidates]) => [id, [...candidates]]),
|
|
2971
|
-
|
|
3333
|
+
scanSourceById: [...scanSourceById.entries()],
|
|
3334
|
+
sourceById: [...mergeSourcesByPriority().entries()],
|
|
2972
3335
|
transformCandidatesById: [...transformCandidatesById.entries()].map(([id, candidates]) => [id, [...candidates]]),
|
|
3336
|
+
transformSourceById: [...transformSourceById.entries()],
|
|
2973
3337
|
inlineExcludedCandidates: [...inlineExcludedCandidates],
|
|
2974
3338
|
inlineIncludedCandidates: [...inlineIncludedCandidates]
|
|
2975
3339
|
};
|
|
@@ -2994,15 +3358,18 @@ function createSourceCandidateCollector(options = {}) {
|
|
|
2994
3358
|
if (candidateSet.size === 0) continue;
|
|
2995
3359
|
cssCandidatesById.set(id, candidateSet);
|
|
2996
3360
|
}
|
|
2997
|
-
for (const [id,
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3361
|
+
for (const [id, source] of snapshot.scanSourceById ?? snapshot.sourceById ?? []) scanSourceById.set(id, source);
|
|
3362
|
+
for (const [id, source] of snapshot.transformSourceById ?? []) transformSourceById.set(id, source);
|
|
3363
|
+
for (const [id, source] of snapshot.cssSourceById ?? []) cssSourceById.set(id, source);
|
|
3364
|
+
const ids = new Set([
|
|
3365
|
+
...scanCandidatesById.keys(),
|
|
3366
|
+
...transformCandidatesById.keys(),
|
|
3367
|
+
...cssCandidatesById.keys()
|
|
3368
|
+
]);
|
|
3369
|
+
for (const id of ids) recompute(id);
|
|
3004
3370
|
}
|
|
3005
3371
|
return {
|
|
3372
|
+
syncSource: sync,
|
|
3006
3373
|
sync,
|
|
3007
3374
|
syncCss,
|
|
3008
3375
|
merge,
|
|
@@ -3012,13 +3379,26 @@ function createSourceCandidateCollector(options = {}) {
|
|
|
3012
3379
|
syncInline,
|
|
3013
3380
|
remove,
|
|
3014
3381
|
source,
|
|
3382
|
+
sources,
|
|
3015
3383
|
values,
|
|
3016
3384
|
valuesForEntries,
|
|
3017
3385
|
sourcesForEntries,
|
|
3018
3386
|
snapshot,
|
|
3019
3387
|
restore,
|
|
3388
|
+
clearScan,
|
|
3389
|
+
resetScan,
|
|
3020
3390
|
clear
|
|
3021
3391
|
};
|
|
3392
|
+
function mergeSourcesByPriority() {
|
|
3393
|
+
const sources = /* @__PURE__ */ new Map();
|
|
3394
|
+
for (const [id, source] of transformSourceById) sources.set(id, source);
|
|
3395
|
+
for (const [id, source] of cssSourceById) sources.set(id, source);
|
|
3396
|
+
for (const [id, source] of scanSourceById) sources.set(id, source);
|
|
3397
|
+
return sources;
|
|
3398
|
+
}
|
|
3399
|
+
}
|
|
3400
|
+
function createSourceCandidateCollector(options = {}) {
|
|
3401
|
+
return createSourceCandidateStore(options);
|
|
3022
3402
|
}
|
|
3023
3403
|
//#endregion
|
|
3024
3404
|
//#region src/bundlers/shared/hmr-timing.ts
|
|
@@ -3099,4 +3479,4 @@ function createHmrTimingRecorder(bundler) {
|
|
|
3099
3479
|
};
|
|
3100
3480
|
}
|
|
3101
3481
|
//#endregion
|
|
3102
|
-
export { createCssSourceTraceCacheSignature as _,
|
|
3482
|
+
export { stripMiniProgramCssSpecificityPlaceholders as A, stripUnmatchedTailwindSourceMediaCloseFragments as C, finalizeMiniProgramCss as D, hasMiniProgramTailwindV4PreflightReset as E, processCachedTask as F, createCssSourceTraceCacheSignature as M, createCssTokenSourceMap as N, hasMiniProgramCssSpecificityPlaceholders as O, isCssSourceTraceEnabled as P, stripTailwindSourceMediaFragments as S, createCssSourceOrderAppend$1 as T, isPureLocalCssImportWrapper as _, isSourceCandidateRequest as a, removeMiniProgramHoverSelectors as b, collectStrictEscapedRuntimeCandidates as c, validateCandidatesByGenerator as d, pushConcurrentTaskFactories as f, mergeMarkedUserLayerComponentsCss as g, extractMarkedUserLayerComponentsCss as h, createSourceCandidateStore as i, annotateCssSourceTrace as j, pruneMiniProgramGeneratedCss as k, createEscapeFragments as l, runWithConcurrency as m, emitHmrTiming as n, resolveSourceCandidateScanFiles as o, resolveTaskConcurrency as p, createSourceCandidateCollector as r, createBundleRuntimeClassSetManager as s, createHmrTimingRecorder as t, generateCssByGenerator as u, rewriteLocalCssImportRequestsForOutput as v, scoreTailwindV4CssSourceFileMatch as w, removeTailwindV4GeneratorAtRules as x, splitLocalCssImports as y };
|