weapp-tailwindcss 5.1.4 → 5.1.6
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/bundlers/shared/generator-css/generation-helpers.d.ts +8 -2
- package/dist/bundlers/shared/generator-css/source-resolver/metadata.d.ts +5 -1
- package/dist/bundlers/shared/generator-css/types.d.ts +1 -0
- package/dist/bundlers/shared/generator-css/user-css.d.ts +4 -1
- package/dist/bundlers/vite/generate-bundle/finalize.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/remembered-css-replay.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/tailwind-v4-css-source.d.ts +6 -3
- package/dist/bundlers/vite/hot-css-modules.d.ts +1 -0
- package/dist/bundlers/vite/processed-css-assets.d.ts +7 -0
- package/dist/bundlers/vite/source-scan/css-entries.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.d.ts +2 -1
- package/dist/cli.js +18 -3
- package/dist/cli.mjs +16 -1
- package/dist/{context-Bkpmt3ja.mjs → context-3GGqW9vw.mjs} +20 -5
- package/dist/{context-DCVMkTRj.js → context-BCSk_YnL.js} +23 -8
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/css-macro/index.d.ts +2 -1
- package/dist/{defaults-BhE26nSw.mjs → defaults-9B6aMyZb.mjs} +2 -2
- package/dist/{defaults-DQhgnnn-.js → defaults-nsf4VNMX.js} +2 -2
- package/dist/defaults.d.ts +1 -1
- package/dist/defaults.js +1 -1
- package/dist/defaults.mjs +1 -1
- package/dist/{generator-24-HgU9F.mjs → generator-CoT5vu9w.mjs} +2 -2
- package/dist/{generator-CilgHtxb.js → generator-CqWzj2Z1.js} +2 -2
- package/dist/generator.js +2 -2
- package/dist/generator.mjs +2 -2
- package/dist/{gulp-0RsqkF_d.mjs → gulp-Bss4wJ8t.mjs} +4 -4
- package/dist/{gulp-Bogfnoki.js → gulp-hXE1U4Cu.js} +4 -4
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{hmr-timing-BRNaz8Od.mjs → hmr-timing-Cfu-4Bnf.mjs} +229 -576
- package/dist/{hmr-timing-BV6nFPoT.js → hmr-timing-Df4203aI.js} +253 -630
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/js/js-string-escape.d.ts +1 -0
- package/dist/postcss.js +2 -2
- package/dist/postcss.mjs +2 -2
- package/dist/presets.js +6 -3
- package/dist/presets.mjs +6 -3
- package/dist/rspack.js +1 -1
- package/dist/rspack.mjs +1 -1
- package/dist/runtime-branch/generator-target-env.d.ts +1 -0
- package/dist/{source-candidate-scan-signature-CaDT0gkj.js → source-candidate-scan-signature-5Uk6U72B.js} +168 -5
- package/dist/{source-candidate-scan-signature-BB1hvW68.mjs → source-candidate-scan-signature-BbCmW975.mjs} +157 -6
- package/dist/style-injector/internal.d.ts +7 -0
- package/dist/style-injector/options.d.ts +25 -0
- package/dist/tailwindcss/v4/preflight.d.ts +4 -0
- package/dist/{tailwindcss-D0JF0fuZ.mjs → tailwindcss-Bjr3aphG.mjs} +62 -15
- package/dist/{tailwindcss-D2xs4OEu.js → tailwindcss-DYJ3HZD2.js} +67 -14
- package/dist/{transform-BP86eSZp.mjs → transform--155BmeJ.mjs} +1 -1
- package/dist/{transform-CXCQ28Tc.js → transform-B6_y_yCB.js} +1 -1
- package/dist/typedoc.export.d.ts +1 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/user-defined-options/general.d.ts +2 -0
- package/dist/{v4-engine-CKtsdKxK.js → v4-engine-C9cmNlP8.js} +610 -3
- package/dist/{v4-engine-BuuYDXt1.mjs → v4-engine-DRQaCFMm.mjs} +529 -6
- package/dist/{vite-BYgT1ir9.js → vite-Baw9qNrc.js} +652 -140
- package/dist/{vite-B1SlBmqO.mjs → vite-PdxjaqhO.mjs} +653 -141
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +2981 -2752
- package/dist/{webpack-Bg6pefpb.mjs → webpack-BffTDmod.mjs} +69 -26
- package/dist/{webpack-khSwkXP5.js → webpack-C9u7mfGE.js} +74 -31
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +16 -5
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as resolveGeneratorRuntimeBranch, i as normalizeWeappTailwindcssGeneratorOptions, s as shouldUseMiniProgramCssBranch, t as createWeappTailwindcssGenerator } from "./generator-
|
|
3
|
-
import { S as createDebug, g as traverse, h as babelParse, m as replaceWxml, r as resolveStyleOptionsFromContext, w as md5Hash } from "./context-
|
|
4
|
-
import { h as resolveTailwindV4EntriesFromCss, l as getRuntimeClassSetSignature, r as isUniAppXEnabled } from "./tailwindcss-
|
|
1
|
+
import { $ as hasTailwindGeneratedCssMarkers, A as stripTailwindSourceMediaFragments, C as isCommentOnlyCss, D as removeTailwindV4GeneratorAtRules, E as removeTailwindV4GeneratedUserCssArtifacts, Et as omitUndefined, H as hasTailwindSourceDirectives, I as removeUnsupportedMiniProgramAtRules, J as resolveCssEntrySource, K as parseImportRequest, M as transformGeneratorUserCss, N as finalizeMiniProgramCss, O as shouldFilterApplyOnlyGeneratedCss, Q as hasTailwindGeneratedCss, S as hasUserCssLayerBlocks, St as toPosixPath$1, Tt as filterUnsupportedMiniProgramTailwindV4Candidates, V as hasTailwindRootDirectives, W as normalizeTailwindSourceDirectives, X as VITE_MARKER_RE, Y as GENERATOR_PLACEHOLDER_MARKER_RE, Z as createCssAppend, at as stripTailwindBanners, b as extractGeneratedCssForUserLayerSelectors, bt as resolveSourceScanPath, et as splitGeneratorPlaceholderCssBySourceOrder, ft as FULL_SOURCE_SCAN_EXTENSION_RE, gt as isFileMatchedByTailwindSourceEntries, i as resolveTailwindV4SourceOptionsFromRuntime, it as stripTailwindBanner, j as stripUnmatchedTailwindSourceMediaCloseFragments, k as splitUserCssLayerBlocks, kt as loadTailwindV4DesignSystem, n as resolveTailwindV4SourceFromRuntime, nt as splitTailwindV4GeneratedCssBySourceOrder, ot as normalizeConfigDirective, q as removeTailwindSourceDirectives, rt as stripGeneratorPlaceholderMarkers, st as prependConfigDirective, t as resolveTailwindV4Source$1, tt as splitTailwindGeneratedCssByBanner, w as normalizeEmptyTailwindCustomVariants, x as filterApplyOnlyGeneratedCss, xt as resolveTailwindV4CssSourceBase, z as hasTailwindApplyDirective } from "./v4-engine-DRQaCFMm.mjs";
|
|
2
|
+
import { a as resolveGeneratorRuntimeBranch, i as normalizeWeappTailwindcssGeneratorOptions, s as shouldUseMiniProgramCssBranch, t as createWeappTailwindcssGenerator } from "./generator-CoT5vu9w.mjs";
|
|
3
|
+
import { S as createDebug, g as traverse, h as babelParse, m as replaceWxml, r as resolveStyleOptionsFromContext, w as md5Hash } from "./context-3GGqW9vw.mjs";
|
|
4
|
+
import { h as resolveTailwindV4EntriesFromCss, l as getRuntimeClassSetSignature, r as isUniAppXEnabled, v as includesTailwindV4PreflightDirective } from "./tailwindcss-Bjr3aphG.mjs";
|
|
5
5
|
import { existsSync, readFileSync } from "node:fs";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import process from "node:process";
|
|
8
8
|
import { extractRawCandidatesWithPositions, extractSourceCandidates, extractValidCandidates, resolveProjectSourceFiles, resolveValidTailwindV4Candidates, splitCandidateTokens } from "@tailwindcss-mangle/engine";
|
|
9
|
-
import { cleanLocalCssImportWrapperTailwindDirectives, cleanLocalCssImportWrapperTailwindDirectivesRoot, filterExistingCssRules,
|
|
9
|
+
import { cleanLocalCssImportWrapperTailwindDirectives, cleanLocalCssImportWrapperTailwindDirectivesRoot, filterExistingCssRules, isPureLocalCssImportWrapper, isPureLocalCssImportWrapperRoot, postcss, restoreLocalCssImports, rewriteLocalCssImportRequestsForOutput, splitLocalCssImports, splitLocalCssImportsRoot, transformWebCssCompat } from "@weapp-tailwindcss/postcss";
|
|
10
10
|
import { LRUCache } from "lru-cache";
|
|
11
11
|
import { readFile } from "node:fs/promises";
|
|
12
12
|
import { MappingChars2String, unescape } from "@weapp-core/escape";
|
|
@@ -152,24 +152,94 @@ function collectGeneratedRawSourceCandidates(candidates, rawSource, escapeMap) {
|
|
|
152
152
|
return matched;
|
|
153
153
|
}
|
|
154
154
|
//#endregion
|
|
155
|
+
//#region src/bundlers/shared/generator-css/source-resolver/postcss-source.ts
|
|
156
|
+
function resolvePostcssFromOption(cssHandlerOptions) {
|
|
157
|
+
const from = cssHandlerOptions.postcssOptions?.options?.from;
|
|
158
|
+
return typeof from === "string" && from.length > 0 ? from : void 0;
|
|
159
|
+
}
|
|
160
|
+
function resolvePostcssSourceFile(cssHandlerOptions) {
|
|
161
|
+
const from = resolvePostcssFromOption(cssHandlerOptions);
|
|
162
|
+
if (!from || !path.isAbsolute(from)) return;
|
|
163
|
+
return from.replace(/[?#].*$/, "");
|
|
164
|
+
}
|
|
165
|
+
function resolveCssHandlerSourceOptions(cssHandlerOptions) {
|
|
166
|
+
return cssHandlerOptions.sourceOptions;
|
|
167
|
+
}
|
|
168
|
+
function resolveCssSourceBase(file, cssHandlerOptions) {
|
|
169
|
+
const normalized = (resolvePostcssFromOption(cssHandlerOptions) ?? file).replace(/[?#].*$/, "");
|
|
170
|
+
return path.dirname(path.resolve(normalized));
|
|
171
|
+
}
|
|
172
|
+
//#endregion
|
|
155
173
|
//#region src/bundlers/shared/generator-css/generation-helpers.ts
|
|
174
|
+
function isVueScopedStyleSource(from) {
|
|
175
|
+
if (typeof from !== "string" || from.length === 0) return false;
|
|
176
|
+
const queryIndex = from.indexOf("?");
|
|
177
|
+
if (queryIndex === -1) return false;
|
|
178
|
+
const query = from.slice(queryIndex + 1);
|
|
179
|
+
return /(?:^|&)type=style(?:&|$)/.test(query) && /(?:^|&)scoped(?:=(?:true|1))?(?:&|$)/.test(query);
|
|
180
|
+
}
|
|
156
181
|
function hasMiniProgramTailwindV4PreflightReset(css) {
|
|
157
182
|
return /(?:^|[},])\s*view\s*,\s*text\s*,\s*::after\s*,\s*::before\s*\{[^}]*\bborder\s*:\s*0\s+solid\b/.test(css);
|
|
158
183
|
}
|
|
184
|
+
function isMiniProgramGeneratorTarget(target) {
|
|
185
|
+
return target !== "web";
|
|
186
|
+
}
|
|
159
187
|
function finalizeMiniProgramGeneratorCss(css, target, _majorVersion, cssPreflight, options = {}) {
|
|
160
|
-
if (target
|
|
161
|
-
|
|
188
|
+
if (!isMiniProgramGeneratorTarget(target)) return css;
|
|
189
|
+
if (isVueScopedStyleSource(options.styleOptions?.postcssOptions?.options?.from)) return finalizeMiniProgramCss(css, {
|
|
190
|
+
cssPreflight: false,
|
|
191
|
+
cssSelectorReplacement: options.styleOptions?.cssOptions?.cssSelectorReplacement ?? options.styleOptions?.cssSelectorReplacement,
|
|
192
|
+
isTailwindcssV4: true,
|
|
193
|
+
tailwindcssV4GradientFallback: options.styleOptions?.cssOptions?.tailwindcssV4GradientFallback ?? options.styleOptions?.tailwindcssV4GradientFallback
|
|
194
|
+
});
|
|
195
|
+
const hasPreflightReset = hasMiniProgramTailwindV4PreflightReset(css);
|
|
196
|
+
const injectPreflight = options.injectPreflight !== false && !hasPreflightReset;
|
|
197
|
+
const preservePreflight = options.preservePreflight !== false;
|
|
162
198
|
return finalizeMiniProgramCss(css, {
|
|
163
|
-
cssPreflight: cssPreflight === false ? false : injectPreflight ? cssPreflight : void 0,
|
|
199
|
+
cssPreflight: cssPreflight === false || options.injectPreflight === false && (!hasPreflightReset || !preservePreflight) ? false : injectPreflight ? cssPreflight : hasPreflightReset && preservePreflight ? cssPreflight : void 0,
|
|
164
200
|
cssSelectorReplacement: options.styleOptions?.cssOptions?.cssSelectorReplacement ?? options.styleOptions?.cssSelectorReplacement,
|
|
165
201
|
isTailwindcssV4: true,
|
|
166
202
|
tailwindcssV4GradientFallback: options.styleOptions?.cssOptions?.tailwindcssV4GradientFallback ?? options.styleOptions?.tailwindcssV4GradientFallback
|
|
167
203
|
});
|
|
168
204
|
}
|
|
169
|
-
function
|
|
170
|
-
if (options.cssHandlerOptions
|
|
171
|
-
|
|
172
|
-
|
|
205
|
+
function resolveMiniProgramPreflightModeForGeneratorCss(opts, options) {
|
|
206
|
+
if (isVueScopedStyleSource(resolvePostcssFromOption(options.cssHandlerOptions))) return {
|
|
207
|
+
inject: false,
|
|
208
|
+
preserve: false
|
|
209
|
+
};
|
|
210
|
+
if (options.cssHandlerOptions.uniAppX === true && options.cssHandlerOptions.uniAppXCssTarget === "uvue") return {
|
|
211
|
+
inject: false,
|
|
212
|
+
preserve: false
|
|
213
|
+
};
|
|
214
|
+
const shouldInjectUniAppXLocalImportPreflight = isUniAppXEnabled(opts.uniAppX) && Boolean(options.localImports?.trim());
|
|
215
|
+
if (opts.cssPreflight === false) return {
|
|
216
|
+
inject: false,
|
|
217
|
+
preserve: false
|
|
218
|
+
};
|
|
219
|
+
if (options.primaryCssSource) return {
|
|
220
|
+
inject: true,
|
|
221
|
+
preserve: true
|
|
222
|
+
};
|
|
223
|
+
if (options.explicitCssSource) return {
|
|
224
|
+
inject: false,
|
|
225
|
+
preserve: true
|
|
226
|
+
};
|
|
227
|
+
if (options.cssHandlerOptions.isMainChunk) return {
|
|
228
|
+
inject: true,
|
|
229
|
+
preserve: true
|
|
230
|
+
};
|
|
231
|
+
if (!options.cssHandlerOptions.isMainChunk && !options.primaryCssSource && !options.explicitCssSource) return {
|
|
232
|
+
inject: shouldInjectUniAppXLocalImportPreflight,
|
|
233
|
+
preserve: shouldInjectUniAppXLocalImportPreflight
|
|
234
|
+
};
|
|
235
|
+
if (!options.isolateCurrentCssCandidates) return {
|
|
236
|
+
inject: true,
|
|
237
|
+
preserve: true
|
|
238
|
+
};
|
|
239
|
+
return {
|
|
240
|
+
inject: shouldInjectUniAppXLocalImportPreflight,
|
|
241
|
+
preserve: shouldInjectUniAppXLocalImportPreflight
|
|
242
|
+
};
|
|
173
243
|
}
|
|
174
244
|
function mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtime, options) {
|
|
175
245
|
if (options.isolateCssSource) {
|
|
@@ -203,9 +273,10 @@ function isEmptyCssSourceOrderParts(parts) {
|
|
|
203
273
|
}
|
|
204
274
|
function resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorStyleOptions) {
|
|
205
275
|
const resolvedStyleOptions = resolveStyleOptionsFromContext(opts);
|
|
276
|
+
const scopedVueStyleSource = isVueScopedStyleSource(resolvePostcssFromOption(cssHandlerOptions));
|
|
206
277
|
const preflightStyleOptions = {
|
|
207
|
-
cssPreflight: resolvedStyleOptions.cssPreflight,
|
|
208
|
-
cssPreflightRange: resolvedStyleOptions.cssPreflightRange
|
|
278
|
+
cssPreflight: scopedVueStyleSource ? false : resolvedStyleOptions.cssPreflight,
|
|
279
|
+
cssPreflightRange: scopedVueStyleSource ? void 0 : resolvedStyleOptions.cssPreflightRange
|
|
209
280
|
};
|
|
210
281
|
return {
|
|
211
282
|
...resolvedStyleOptions,
|
|
@@ -826,8 +897,9 @@ function withGeneratorSourceMetadata(source, metadata) {
|
|
|
826
897
|
__weappTailwindcssMeta: metadata
|
|
827
898
|
};
|
|
828
899
|
}
|
|
829
|
-
function withMatchedSourceSideMetadata(source, resolvedEntrySource) {
|
|
900
|
+
function withMatchedSourceSideMetadata(source, resolvedEntrySource, metadata = {}) {
|
|
830
901
|
return resolvedEntrySource.file ? withGeneratorSourceMetadata(source, {
|
|
902
|
+
...metadata,
|
|
831
903
|
isolateCssSource: true,
|
|
832
904
|
matchedCssSourceFile: resolvedEntrySource.file,
|
|
833
905
|
sourceBase: resolvedEntrySource.base,
|
|
@@ -835,24 +907,6 @@ function withMatchedSourceSideMetadata(source, resolvedEntrySource) {
|
|
|
835
907
|
}) : source;
|
|
836
908
|
}
|
|
837
909
|
//#endregion
|
|
838
|
-
//#region src/bundlers/shared/generator-css/source-resolver/postcss-source.ts
|
|
839
|
-
function resolvePostcssFromOption(cssHandlerOptions) {
|
|
840
|
-
const from = cssHandlerOptions.postcssOptions?.options?.from;
|
|
841
|
-
return typeof from === "string" && from.length > 0 ? from : void 0;
|
|
842
|
-
}
|
|
843
|
-
function resolvePostcssSourceFile(cssHandlerOptions) {
|
|
844
|
-
const from = resolvePostcssFromOption(cssHandlerOptions);
|
|
845
|
-
if (!from || !path.isAbsolute(from)) return;
|
|
846
|
-
return from.replace(/[?#].*$/, "");
|
|
847
|
-
}
|
|
848
|
-
function resolveCssHandlerSourceOptions(cssHandlerOptions) {
|
|
849
|
-
return cssHandlerOptions.sourceOptions;
|
|
850
|
-
}
|
|
851
|
-
function resolveCssSourceBase(file, cssHandlerOptions) {
|
|
852
|
-
const normalized = (resolvePostcssFromOption(cssHandlerOptions) ?? file).replace(/[?#].*$/, "");
|
|
853
|
-
return path.dirname(path.resolve(normalized));
|
|
854
|
-
}
|
|
855
|
-
//#endregion
|
|
856
910
|
//#region src/bundlers/shared/generator-css/source-resolver.ts
|
|
857
911
|
function createCssEntrySources(cssEntries) {
|
|
858
912
|
return cssEntries?.filter((entry) => typeof entry === "string" && entry.length > 0 && path.isAbsolute(entry)).map((entry) => ({ file: path.resolve(entry) }));
|
|
@@ -886,11 +940,15 @@ function createSingleTailwindV4SourceOptions(sourceOptions, options) {
|
|
|
886
940
|
cssEntries: options.cssEntries
|
|
887
941
|
});
|
|
888
942
|
}
|
|
889
|
-
async function resolveTailwindV4CssEntrySource(cssEntry, sourceOptions) {
|
|
943
|
+
async function resolveTailwindV4CssEntrySource(cssEntry, sourceOptions, options = {}) {
|
|
890
944
|
const { cssEntries: _cssEntries, cssSources: _cssSources, ...singleEntrySourceOptions } = sourceOptions;
|
|
891
|
-
if (!existsSync(cssEntry)) return resolveTailwindV4Source$1({
|
|
945
|
+
if (!existsSync(cssEntry)) return withGeneratorSourceMetadata(await resolveTailwindV4Source$1({
|
|
892
946
|
...omitUndefined(singleEntrySourceOptions),
|
|
893
947
|
cssEntries: [cssEntry]
|
|
948
|
+
}), {
|
|
949
|
+
cssEntryIndex: options.index,
|
|
950
|
+
includesPreflight: options.includesPreflight,
|
|
951
|
+
primaryCssSource: options.index === 0
|
|
894
952
|
});
|
|
895
953
|
const css = readFileSync(cssEntry, "utf8");
|
|
896
954
|
const base = path.dirname(path.resolve(cssEntry));
|
|
@@ -905,7 +963,10 @@ async function resolveTailwindV4CssEntrySource(cssEntry, sourceOptions) {
|
|
|
905
963
|
css: normalizeConfigDirective(css, config),
|
|
906
964
|
cssEntries: [cssEntry]
|
|
907
965
|
}), {
|
|
966
|
+
cssEntryIndex: options.index,
|
|
967
|
+
includesPreflight: options.includesPreflight,
|
|
908
968
|
matchedCssSourceFile: cssEntry,
|
|
969
|
+
primaryCssSource: options.index === 0,
|
|
909
970
|
sourceBase: base,
|
|
910
971
|
sourceCss: css
|
|
911
972
|
});
|
|
@@ -918,12 +979,15 @@ function canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) {
|
|
|
918
979
|
function shouldResolveSourceSideCssEntry(rawSource) {
|
|
919
980
|
return rawSource.includes("@apply") || hasTailwindRootDirectives(rawSource, { importFallback: true }) || hasTailwindSourceDirectives(rawSource, { importFallback: true }) || hasTailwindGeneratedCss(rawSource) || hasTailwindGeneratedCssMarkers(rawSource);
|
|
920
981
|
}
|
|
921
|
-
function resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) {
|
|
982
|
+
async function resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) {
|
|
922
983
|
const cssEntries = sourceOptions.cssEntries;
|
|
923
984
|
if (!cssEntries?.length) return;
|
|
924
985
|
const normalizedFile = path.resolve(file.replace(/[?#].*$/, ""));
|
|
925
986
|
const pathMatchedEntries = cssEntries.filter((cssEntry) => path.resolve(cssEntry.replace(/[?#].*$/, "")) === normalizedFile);
|
|
926
|
-
if (pathMatchedEntries.length === 1) return resolveTailwindV4CssEntrySource(pathMatchedEntries[0], sourceOptions
|
|
987
|
+
if (pathMatchedEntries.length === 1) return resolveTailwindV4CssEntrySource(pathMatchedEntries[0], sourceOptions, {
|
|
988
|
+
includesPreflight: await resolveTailwindV4CssEntryIncludesPreflight(pathMatchedEntries[0]),
|
|
989
|
+
index: cssEntries.indexOf(pathMatchedEntries[0])
|
|
990
|
+
});
|
|
927
991
|
const normalizedRawSource = normalizeCssSourceForCompare(rawSource);
|
|
928
992
|
const matches = cssEntries.map((cssEntry) => {
|
|
929
993
|
if (!existsSync(cssEntry)) return;
|
|
@@ -942,7 +1006,10 @@ function resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) {
|
|
|
942
1006
|
const bestScore = matches[0]?.score;
|
|
943
1007
|
const matchingEntry = bestScore && matches.filter((match) => match.score === bestScore).length === 1 ? matches[0]?.cssEntry : void 0;
|
|
944
1008
|
if (!matchingEntry) return;
|
|
945
|
-
return resolveTailwindV4CssEntrySource(matchingEntry, sourceOptions
|
|
1009
|
+
return resolveTailwindV4CssEntrySource(matchingEntry, sourceOptions, {
|
|
1010
|
+
includesPreflight: await resolveTailwindV4CssEntryIncludesPreflight(matchingEntry),
|
|
1011
|
+
index: cssEntries.indexOf(matchingEntry)
|
|
1012
|
+
});
|
|
946
1013
|
}
|
|
947
1014
|
function normalizeTailwindV4CssSourceConfig(cssSource, sourceBase) {
|
|
948
1015
|
if (typeof cssSource.css !== "string" || cssSource.css.length === 0 || !cssSource.css.includes("@config")) return cssSource;
|
|
@@ -992,7 +1059,7 @@ function normalizeTailwindV4CssSourceConfigs(sourceOptions) {
|
|
|
992
1059
|
cssSources
|
|
993
1060
|
} : sourceOptions;
|
|
994
1061
|
}
|
|
995
|
-
async function resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions) {
|
|
1062
|
+
async function resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions, selectionOptions) {
|
|
996
1063
|
const cssSources = sourceOptions.cssSources;
|
|
997
1064
|
if (!cssSources?.length) return;
|
|
998
1065
|
const normalizedRawSource = normalizeCssSourceForCompare(rawSource);
|
|
@@ -1013,7 +1080,12 @@ async function resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOpt
|
|
|
1013
1080
|
const bestScore = matches[0]?.score;
|
|
1014
1081
|
const matchingSource = bestScore && matches.filter((match) => match.score === bestScore).length === 1 ? matches[0]?.cssSource : void 0;
|
|
1015
1082
|
if (!matchingSource) return;
|
|
1016
|
-
return resolveSingleTailwindV4CssSource(matchingSource, sourceOptions, {
|
|
1083
|
+
return resolveSingleTailwindV4CssSource(matchingSource, sourceOptions, {
|
|
1084
|
+
includesPreflight: await resolveTailwindV4CssSourceEntries(matchingSource, sourceOptions).then((resolved) => resolved?.includesPreflight),
|
|
1085
|
+
index: matches[0]?.index,
|
|
1086
|
+
matched: true,
|
|
1087
|
+
primary: isSameTailwindV4CssSource(matchingSource, selectionOptions?.cssSources?.[0])
|
|
1088
|
+
});
|
|
1017
1089
|
}
|
|
1018
1090
|
function tryResolveTailwindV4SourceOptions(runtimeState) {
|
|
1019
1091
|
try {
|
|
@@ -1025,14 +1097,24 @@ function tryResolveTailwindV4SourceOptions(runtimeState) {
|
|
|
1025
1097
|
function hasConfiguredTailwindV4CssSource(sourceOptions) {
|
|
1026
1098
|
return Boolean(sourceOptions?.css) || Boolean(sourceOptions?.cssSources?.length);
|
|
1027
1099
|
}
|
|
1100
|
+
function isSameTailwindV4CssSource(a, b) {
|
|
1101
|
+
if (!a || !b) return false;
|
|
1102
|
+
if (typeof a.file === "string" && typeof b.file === "string") return path.resolve(a.file) === path.resolve(b.file);
|
|
1103
|
+
return typeof a.css === "string" && typeof b.css === "string" && normalizeCssSourceForCompare(a.css) === normalizeCssSourceForCompare(b.css);
|
|
1104
|
+
}
|
|
1028
1105
|
async function resolveSingleTailwindV4CssSource(cssSource, sourceOptions, options = {}) {
|
|
1029
1106
|
const sourceBase = resolveTailwindV4CssSourceBase(cssSource, sourceOptions.base ?? sourceOptions.projectRoot ?? process.cwd());
|
|
1030
1107
|
const normalizedCssSource = normalizeTailwindV4CssSourceConfig(cssSource, sourceBase);
|
|
1031
|
-
|
|
1108
|
+
const source = await resolveTailwindV4Source$1(createSingleTailwindV4SourceOptions(sourceOptions, {
|
|
1032
1109
|
base: sourceBase,
|
|
1033
1110
|
css: normalizedCssSource.css
|
|
1034
|
-
}))
|
|
1111
|
+
}));
|
|
1112
|
+
const resolvedEntries = options.includesPreflight === void 0 ? await resolveTailwindV4CssSourceEntries(normalizedCssSource, sourceOptions) : void 0;
|
|
1113
|
+
return withGeneratorSourceMetadata(source, {
|
|
1114
|
+
cssSourceIndex: options.index,
|
|
1115
|
+
includesPreflight: options.includesPreflight ?? resolvedEntries?.includesPreflight,
|
|
1035
1116
|
matchedCssSourceFile: options.matched && typeof normalizedCssSource.file === "string" ? normalizedCssSource.file : void 0,
|
|
1117
|
+
primaryCssSource: options.primary === true || !sourceOptions.cssEntries?.length && options.index === 0 || void 0,
|
|
1036
1118
|
sourceBase,
|
|
1037
1119
|
sourceCss: normalizedCssSource.css
|
|
1038
1120
|
});
|
|
@@ -1061,6 +1143,47 @@ async function resolveCandidateMatchedTailwindV4CssSource(_rawSource, _cssHandle
|
|
|
1061
1143
|
if (runtimeHits === 0) return;
|
|
1062
1144
|
matches.push({
|
|
1063
1145
|
cssSource,
|
|
1146
|
+
includesPreflight: resolved.includesPreflight,
|
|
1147
|
+
index,
|
|
1148
|
+
runtimeHits,
|
|
1149
|
+
totalCandidates: scopedCandidates.size
|
|
1150
|
+
});
|
|
1151
|
+
}));
|
|
1152
|
+
if (matches.length === 0) return;
|
|
1153
|
+
matches.sort((a, b) => b.runtimeHits - a.runtimeHits || b.totalCandidates - a.totalCandidates || a.index - b.index);
|
|
1154
|
+
const best = matches[0];
|
|
1155
|
+
const second = matches[1];
|
|
1156
|
+
if (!best) return;
|
|
1157
|
+
if (second && second.runtimeHits === best.runtimeHits && second.totalCandidates === best.totalCandidates) return;
|
|
1158
|
+
return resolveSingleTailwindV4CssSource(best.cssSource, sourceOptions, {
|
|
1159
|
+
includesPreflight: best.includesPreflight,
|
|
1160
|
+
index: best.index,
|
|
1161
|
+
matched: true,
|
|
1162
|
+
primary: isSameTailwindV4CssSource(best.cssSource, selectionOptions?.cssSources?.[0])
|
|
1163
|
+
});
|
|
1164
|
+
}
|
|
1165
|
+
async function resolveTailwindV4CssEntryEntries(cssEntry) {
|
|
1166
|
+
if (!existsSync(cssEntry)) return;
|
|
1167
|
+
const file = path.resolve(cssEntry);
|
|
1168
|
+
return resolveTailwindV4EntriesFromCss(readFileSync(file, "utf8"), path.dirname(file));
|
|
1169
|
+
}
|
|
1170
|
+
async function resolveTailwindV4CssEntryIncludesPreflight(cssEntry) {
|
|
1171
|
+
return resolveTailwindV4CssEntryEntries(cssEntry).then((resolved) => resolved?.includesPreflight);
|
|
1172
|
+
}
|
|
1173
|
+
async function resolveCandidateMatchedTailwindV4CssEntry(sourceOptions, selectionOptions) {
|
|
1174
|
+
const cssEntries = sourceOptions.cssEntries;
|
|
1175
|
+
const getSourceCandidatesForEntries = selectionOptions?.getSourceCandidatesForEntries;
|
|
1176
|
+
if (!cssEntries?.length || !getSourceCandidatesForEntries) return;
|
|
1177
|
+
const matches = [];
|
|
1178
|
+
await Promise.all(cssEntries.map(async (cssEntry, index) => {
|
|
1179
|
+
const resolved = await resolveTailwindV4CssEntryEntries(cssEntry);
|
|
1180
|
+
if (resolved?.entries === void 0) return;
|
|
1181
|
+
const scopedCandidates = getSourceCandidatesForEntries(resolved.entries);
|
|
1182
|
+
const runtimeHits = countRuntimeCandidateHits(scopedCandidates, selectionOptions?.runtime);
|
|
1183
|
+
if (runtimeHits === 0) return;
|
|
1184
|
+
matches.push({
|
|
1185
|
+
cssEntry,
|
|
1186
|
+
includesPreflight: resolved.includesPreflight,
|
|
1064
1187
|
index,
|
|
1065
1188
|
runtimeHits,
|
|
1066
1189
|
totalCandidates: scopedCandidates.size
|
|
@@ -1072,10 +1195,13 @@ async function resolveCandidateMatchedTailwindV4CssSource(_rawSource, _cssHandle
|
|
|
1072
1195
|
const second = matches[1];
|
|
1073
1196
|
if (!best) return;
|
|
1074
1197
|
if (second && second.runtimeHits === best.runtimeHits && second.totalCandidates === best.totalCandidates) return;
|
|
1075
|
-
return
|
|
1198
|
+
return resolveTailwindV4CssEntrySource(best.cssEntry, sourceOptions, {
|
|
1199
|
+
includesPreflight: best.includesPreflight,
|
|
1200
|
+
index: best.index
|
|
1201
|
+
});
|
|
1076
1202
|
}
|
|
1077
1203
|
function createTailwindV4CssSourceResolver(sourceOptions, generatorOptions) {
|
|
1078
|
-
return (cssSource) => resolveSingleTailwindV4CssSource(cssSource, sourceOptions).then((source) => generatorOptions?.config ? {
|
|
1204
|
+
return (cssSource, index) => resolveSingleTailwindV4CssSource(cssSource, sourceOptions, { index }).then((source) => generatorOptions?.config ? {
|
|
1079
1205
|
...source,
|
|
1080
1206
|
css: prependConfigDirective(source.css, generatorOptions.config)
|
|
1081
1207
|
} : source);
|
|
@@ -1088,11 +1214,19 @@ async function resolveTailwindV4SourceSideEntrySource(resolvedEntrySource, sourc
|
|
|
1088
1214
|
sourceFile: resolvedEntrySource.file
|
|
1089
1215
|
});
|
|
1090
1216
|
const css = createTailwindV4SourceReferenceSource(normalizeConfigDirective(prependConfigDirective(resolvedEntrySource.css, generatorOptions?.config), config), resolvedSourceOptions);
|
|
1091
|
-
|
|
1217
|
+
const source = await resolveTailwindV4Source$1(createSingleTailwindV4SourceOptions(resolvedSourceOptions, {
|
|
1092
1218
|
base: resolvedEntrySource.base,
|
|
1093
1219
|
css,
|
|
1094
1220
|
cssEntries: [resolvedEntrySource.file]
|
|
1095
|
-
}))
|
|
1221
|
+
}));
|
|
1222
|
+
const cssEntryIndex = sourceOptions.cssEntries?.findIndex((cssEntry) => typeof resolvedEntrySource.file === "string" && path.resolve(cssEntry.replace(/[?#].*$/, "")) === path.resolve(resolvedEntrySource.file));
|
|
1223
|
+
const cssSourceIndex = sourceOptions.cssSources?.findIndex((cssSource) => typeof cssSource.file === "string" && typeof resolvedEntrySource.file === "string" && path.resolve(cssSource.file.replace(/[?#].*$/, "")) === path.resolve(resolvedEntrySource.file));
|
|
1224
|
+
return withMatchedSourceSideMetadata(source, resolvedEntrySource, {
|
|
1225
|
+
cssEntryIndex,
|
|
1226
|
+
cssSourceIndex,
|
|
1227
|
+
includesPreflight: (await resolveTailwindV4EntriesFromCss(resolvedEntrySource.css, resolvedEntrySource.base))?.includesPreflight,
|
|
1228
|
+
primaryCssSource: cssEntryIndex === 0 || !sourceOptions.cssEntries?.length && cssSourceIndex === 0
|
|
1229
|
+
});
|
|
1096
1230
|
}
|
|
1097
1231
|
async function resolveGeneratorSource(_majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions) {
|
|
1098
1232
|
const base = resolveCssSourceBase(file, cssHandlerOptions);
|
|
@@ -1110,7 +1244,7 @@ async function resolveGeneratorSource(_majorVersion, runtimeState, rawSource, fi
|
|
|
1110
1244
|
sourceFile: sourceOptions.sourceFile ?? resolvePostcssSourceFile(cssHandlerOptions),
|
|
1111
1245
|
...resolveCssHandlerSourceOptions(cssHandlerOptions),
|
|
1112
1246
|
cssEntries: selectionOptions?.cssEntries ?? sourceOptions.cssEntries,
|
|
1113
|
-
cssSources: mergeCssSources(sourceOptions.cssSources, sourceOptions.cssSources?.length ? void 0 : createCssEntrySources(selectionOptions?.cssEntries ?? sourceOptions.cssEntries))
|
|
1247
|
+
cssSources: mergeCssSources(mergeCssSources(sourceOptions.cssSources, selectionOptions?.cssSources), sourceOptions.cssSources?.length || selectionOptions?.cssSources?.length ? void 0 : createCssEntrySources(selectionOptions?.cssEntries ?? sourceOptions.cssEntries))
|
|
1114
1248
|
}) : void 0;
|
|
1115
1249
|
const normalizedSourceOptions = resolvedSourceOptions ? normalizeTailwindV4CssSourceConfigs(resolvedSourceOptions) : void 0;
|
|
1116
1250
|
if (applyEntrySource && !cssHandlerOptions.isMainChunk && !hasTailwindRootDirectives(rawSource, { importFallback: generatorOptions?.importFallback ?? false })) {
|
|
@@ -1125,16 +1259,20 @@ async function resolveGeneratorSource(_majorVersion, runtimeState, rawSource, fi
|
|
|
1125
1259
|
const sourceSideCssSource = sourceSideEntrySource?.file && normalizedSourceOptions.cssEntries?.some((cssEntry) => path.resolve(cssEntry.replace(/[?#].*$/, "")) === path.resolve(sourceSideEntrySource.file)) ? await resolveTailwindV4SourceSideEntrySource(sourceSideEntrySource, normalizedSourceOptions, generatorOptions, file) : void 0;
|
|
1126
1260
|
if (sourceSideCssSource) return sourceSideCssSource;
|
|
1127
1261
|
const matchedCssEntrySource = normalizedSourceOptions ? await resolveMatchingTailwindV4CssEntry(rawSource, file, normalizedSourceOptions) : void 0;
|
|
1128
|
-
const matchedCssSource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, normalizedSourceOptions) : void 0;
|
|
1262
|
+
const matchedCssSource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, normalizedSourceOptions, selectionOptions) : void 0;
|
|
1263
|
+
const candidateMatchedCssEntrySource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveCandidateMatchedTailwindV4CssEntry(normalizedSourceOptions, selectionOptions) : void 0;
|
|
1129
1264
|
const candidateMatchedCssSource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, normalizedSourceOptions, selectionOptions) : void 0;
|
|
1130
|
-
const singleConfiguredCssSource = normalizedSourceOptions?.cssSources?.length === 1 ? await resolveSingleTailwindV4CssSource(normalizedSourceOptions.cssSources[0], normalizedSourceOptions, {
|
|
1265
|
+
const singleConfiguredCssSource = normalizedSourceOptions?.cssSources?.length === 1 ? await resolveSingleTailwindV4CssSource(normalizedSourceOptions.cssSources[0], normalizedSourceOptions, {
|
|
1266
|
+
index: 0,
|
|
1267
|
+
matched: true
|
|
1268
|
+
}) : void 0;
|
|
1131
1269
|
const configuredCssSource = normalizedSourceOptions && hasConfiguredTailwindV4CssSource(normalizedSourceOptions) && hasTailwindGeneratedCssMarkers(rawSource) ? matchedCssSource ?? candidateMatchedCssSource ?? singleConfiguredCssSource ?? await resolveTailwindV4Source$1(normalizedSourceOptions) : void 0;
|
|
1132
1270
|
if (configuredCssSource) return generatorOptions?.config ? {
|
|
1133
1271
|
...configuredCssSource,
|
|
1134
1272
|
css: prependConfigDirective(configuredCssSource.css, generatorOptions.config)
|
|
1135
1273
|
} : configuredCssSource;
|
|
1136
1274
|
const mainCssEntrySource = normalizedSourceOptions && cssHandlerOptions.isMainChunk && normalizedSourceOptions.cssEntries?.length === 1 ? await resolveTailwindV4CssEntrySource(normalizedSourceOptions.cssEntries[0], normalizedSourceOptions) : void 0;
|
|
1137
|
-
const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource ?? mainCssEntrySource ?? singleConfiguredCssSource;
|
|
1275
|
+
const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssEntrySource ?? candidateMatchedCssSource ?? mainCssEntrySource ?? singleConfiguredCssSource;
|
|
1138
1276
|
if (preferredCssEntrySource) return generatorOptions?.config ? {
|
|
1139
1277
|
...preferredCssEntrySource,
|
|
1140
1278
|
css: prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
|
|
@@ -1190,19 +1328,20 @@ async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, fi
|
|
|
1190
1328
|
} : matchedCssEntrySource, matchedCssEntrySource.__weappTailwindcssMeta?.matchedCssSourceFile, sourceOptions)];
|
|
1191
1329
|
const sourceSideCssSource = await resolveTailwindV4SourceSideEntrySource(canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) ? resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: false }) : void 0, sourceOptions, generatorOptions, file);
|
|
1192
1330
|
if (sourceSideCssSource) return [sourceSideCssSource];
|
|
1193
|
-
const matchedCssSource = await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions);
|
|
1331
|
+
const matchedCssSource = await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions, selectionOptions);
|
|
1332
|
+
const candidateMatchedCssEntrySource = await resolveCandidateMatchedTailwindV4CssEntry(sourceOptions, selectionOptions);
|
|
1194
1333
|
const candidateMatchedCssSource = await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, sourceOptions, selectionOptions);
|
|
1195
|
-
const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource;
|
|
1334
|
+
const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssEntrySource ?? candidateMatchedCssSource;
|
|
1196
1335
|
if (preferredCssEntrySource) return [normalizeResolvedTailwindV4SourceConfig(generatorOptions?.config ? {
|
|
1197
1336
|
...preferredCssEntrySource,
|
|
1198
1337
|
css: prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
|
|
1199
1338
|
} : preferredCssEntrySource, preferredCssEntrySource.__weappTailwindcssMeta?.matchedCssSourceFile, sourceOptions)];
|
|
1200
1339
|
if (!sourceOptions.cssEntries || sourceOptions.cssEntries.length <= 1) {
|
|
1201
|
-
if (cssHandlerOptions.isMainChunk && sourceOptions.cssEntries?.length === 1) return [await resolveTailwindV4CssEntrySource(sourceOptions.cssEntries[0], normalizeTailwindV4CssSourceConfigs(sourceOptions)).then((source) => generatorOptions?.config ? {
|
|
1340
|
+
if (cssHandlerOptions.isMainChunk && sourceOptions.cssEntries?.length === 1) return [await resolveTailwindV4CssEntrySource(sourceOptions.cssEntries[0], normalizeTailwindV4CssSourceConfigs(sourceOptions), { index: 0 }).then((source) => generatorOptions?.config ? {
|
|
1202
1341
|
...source,
|
|
1203
1342
|
css: prependConfigDirective(source.css, generatorOptions.config)
|
|
1204
1343
|
} : source)];
|
|
1205
|
-
if (sourceOptions.cssSources?.length === 1) return [normalizeResolvedTailwindV4SourceConfig(await createTailwindV4CssSourceResolver(sourceOptions, generatorOptions)(sourceOptions.cssSources[0]), sourceOptions.cssSources[0]?.file, sourceOptions)];
|
|
1344
|
+
if (sourceOptions.cssSources?.length === 1) return [normalizeResolvedTailwindV4SourceConfig(await createTailwindV4CssSourceResolver(sourceOptions, generatorOptions)(sourceOptions.cssSources[0], 0), sourceOptions.cssSources[0]?.file, sourceOptions)];
|
|
1206
1345
|
const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
|
|
1207
1346
|
return resolved ? [resolved] : [];
|
|
1208
1347
|
}
|
|
@@ -1211,7 +1350,7 @@ async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, fi
|
|
|
1211
1350
|
return resolved ? [resolved] : [];
|
|
1212
1351
|
}
|
|
1213
1352
|
const normalizedCssSourceOptions = normalizeTailwindV4CssSourceConfigs(sourceOptions);
|
|
1214
|
-
const cssEntrySources = await Promise.all(sourceOptions.cssEntries.map((cssEntry) => resolveTailwindV4CssEntrySource(cssEntry, normalizedCssSourceOptions).then((source) => generatorOptions?.config ? {
|
|
1353
|
+
const cssEntrySources = await Promise.all(sourceOptions.cssEntries.map((cssEntry, index) => resolveTailwindV4CssEntrySource(cssEntry, normalizedCssSourceOptions, { index }).then((source) => generatorOptions?.config ? {
|
|
1215
1354
|
...source,
|
|
1216
1355
|
css: prependConfigDirective(source.css, generatorOptions.config)
|
|
1217
1356
|
} : source)));
|
|
@@ -1245,501 +1384,6 @@ async function resolveGeneratorSourceEntries(source, runtimeState) {
|
|
|
1245
1384
|
return resolved?.entries;
|
|
1246
1385
|
}
|
|
1247
1386
|
//#endregion
|
|
1248
|
-
//#region src/bundlers/shared/generator-css/user-css.ts
|
|
1249
|
-
const TAILWIND_V4_GENERATOR_AT_RULES = /* @__PURE__ */ new Set([
|
|
1250
|
-
"config",
|
|
1251
|
-
"custom-variant",
|
|
1252
|
-
"plugin",
|
|
1253
|
-
"source",
|
|
1254
|
-
"theme",
|
|
1255
|
-
"utility",
|
|
1256
|
-
"variant"
|
|
1257
|
-
]);
|
|
1258
|
-
function removeBalancedAtRuleBlock(source, atRuleStart) {
|
|
1259
|
-
const blockStart = source.indexOf("{", atRuleStart);
|
|
1260
|
-
if (blockStart === -1) {
|
|
1261
|
-
const semicolon = source.indexOf(";", atRuleStart);
|
|
1262
|
-
return semicolon === -1 ? source.slice(0, atRuleStart) : `${source.slice(0, atRuleStart)}${source.slice(semicolon + 1)}`;
|
|
1263
|
-
}
|
|
1264
|
-
let depth = 0;
|
|
1265
|
-
for (let index = blockStart; index < source.length; index++) {
|
|
1266
|
-
const char = source[index];
|
|
1267
|
-
if (char === "{") {
|
|
1268
|
-
depth++;
|
|
1269
|
-
continue;
|
|
1270
|
-
}
|
|
1271
|
-
if (char !== "}") continue;
|
|
1272
|
-
depth--;
|
|
1273
|
-
if (depth === 0) return `${source.slice(0, atRuleStart)}${source.slice(index + 1)}`;
|
|
1274
|
-
}
|
|
1275
|
-
return source.slice(0, atRuleStart);
|
|
1276
|
-
}
|
|
1277
|
-
function removeTailwindV4GeneratorAtRulesFallback(source) {
|
|
1278
|
-
let next = source;
|
|
1279
|
-
let changed = false;
|
|
1280
|
-
const sourceMediaRE = /@media\s+source\([^)]*\)\s*\{/g;
|
|
1281
|
-
for (;;) {
|
|
1282
|
-
sourceMediaRE.lastIndex = 0;
|
|
1283
|
-
const match = sourceMediaRE.exec(next);
|
|
1284
|
-
if (!match) break;
|
|
1285
|
-
next = removeBalancedAtRuleBlock(next, match.index);
|
|
1286
|
-
changed = true;
|
|
1287
|
-
}
|
|
1288
|
-
const atRuleRE = /@(?:config|custom-variant|plugin|source|theme|utility|variant)\b/g;
|
|
1289
|
-
for (;;) {
|
|
1290
|
-
atRuleRE.lastIndex = 0;
|
|
1291
|
-
const match = atRuleRE.exec(next);
|
|
1292
|
-
if (!match) break;
|
|
1293
|
-
next = removeBalancedAtRuleBlock(next, match.index);
|
|
1294
|
-
changed = true;
|
|
1295
|
-
}
|
|
1296
|
-
return changed ? next : source;
|
|
1297
|
-
}
|
|
1298
|
-
function isTailwindGeneratedPreflightComment(text) {
|
|
1299
|
-
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");
|
|
1300
|
-
}
|
|
1301
|
-
function isTailwindGeneratedThemeRule(selector, node) {
|
|
1302
|
-
if (!/(?:^|,)\s*(?::host|page|\.tw-root|wx-root-portal-content)\b/.test(selector)) return false;
|
|
1303
|
-
return node.nodes?.some((child) => child.type === "decl" && /^--(?:color|spacing|text|font|default|radius|tw-)/.test(child.prop)) ?? false;
|
|
1304
|
-
}
|
|
1305
|
-
function isTailwindGeneratedPreflightRule(selector, node) {
|
|
1306
|
-
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;
|
|
1307
|
-
if (selector === "abbr[title]") return node.nodes?.some((child) => child.type === "decl" && child.prop === "text-decoration") ?? false;
|
|
1308
|
-
if (selector === ":host") return node.nodes?.some((child) => child.type === "decl" && child.value?.includes("--theme(")) ?? false;
|
|
1309
|
-
return false;
|
|
1310
|
-
}
|
|
1311
|
-
function removeTailwindV4GeneratedUserCssArtifacts(source) {
|
|
1312
|
-
try {
|
|
1313
|
-
const root = postcss.parse(source);
|
|
1314
|
-
let changed = false;
|
|
1315
|
-
root.walkComments((comment) => {
|
|
1316
|
-
if (!isTailwindGeneratedPreflightComment(comment.text)) return;
|
|
1317
|
-
comment.remove();
|
|
1318
|
-
changed = true;
|
|
1319
|
-
});
|
|
1320
|
-
root.walkRules((rule) => {
|
|
1321
|
-
const selector = rule.selector.replace(/\s+/g, " ").trim();
|
|
1322
|
-
if (isTailwindGeneratedThemeRule(selector, rule) || isTailwindGeneratedPreflightRule(selector, rule)) {
|
|
1323
|
-
rule.remove();
|
|
1324
|
-
changed = true;
|
|
1325
|
-
}
|
|
1326
|
-
});
|
|
1327
|
-
root.walkAtRules((rule) => {
|
|
1328
|
-
if (rule.nodes !== void 0 && rule.nodes.length === 0) {
|
|
1329
|
-
rule.remove();
|
|
1330
|
-
changed = true;
|
|
1331
|
-
}
|
|
1332
|
-
});
|
|
1333
|
-
return changed ? root.toString() : source;
|
|
1334
|
-
} catch {
|
|
1335
|
-
return source;
|
|
1336
|
-
}
|
|
1337
|
-
}
|
|
1338
|
-
function removeTailwindSourceMediaBlocks(source) {
|
|
1339
|
-
let next = source;
|
|
1340
|
-
let changed = false;
|
|
1341
|
-
const sourceMediaRE = /@media\s+source\([^)]*\)\s*\{/g;
|
|
1342
|
-
for (;;) {
|
|
1343
|
-
sourceMediaRE.lastIndex = 0;
|
|
1344
|
-
const match = sourceMediaRE.exec(next);
|
|
1345
|
-
if (!match) break;
|
|
1346
|
-
const blockStart = next.indexOf("{", match.index);
|
|
1347
|
-
if (blockStart === -1) break;
|
|
1348
|
-
let depth = 0;
|
|
1349
|
-
let blockEnd = -1;
|
|
1350
|
-
for (let index = blockStart; index < next.length; index++) {
|
|
1351
|
-
const char = next[index];
|
|
1352
|
-
if (char === "{") {
|
|
1353
|
-
depth++;
|
|
1354
|
-
continue;
|
|
1355
|
-
}
|
|
1356
|
-
if (char !== "}") continue;
|
|
1357
|
-
depth--;
|
|
1358
|
-
if (depth === 0) {
|
|
1359
|
-
blockEnd = index;
|
|
1360
|
-
break;
|
|
1361
|
-
}
|
|
1362
|
-
}
|
|
1363
|
-
if (blockEnd === -1) break;
|
|
1364
|
-
next = `${next.slice(0, match.index)}${next.slice(blockEnd + 1)}`;
|
|
1365
|
-
changed = true;
|
|
1366
|
-
}
|
|
1367
|
-
for (;;) {
|
|
1368
|
-
const atRuleStart = findTailwindSourceWrapperBlockStart(next);
|
|
1369
|
-
if (atRuleStart === -1) break;
|
|
1370
|
-
next = removeBalancedAtRuleBlock(next, atRuleStart);
|
|
1371
|
-
changed = true;
|
|
1372
|
-
}
|
|
1373
|
-
return changed ? next : source;
|
|
1374
|
-
}
|
|
1375
|
-
function terminateTailwindSourceAtRulesBeforeNextDirective(source) {
|
|
1376
|
-
if (!source.includes("@source")) return source;
|
|
1377
|
-
let next = "";
|
|
1378
|
-
let searchIndex = 0;
|
|
1379
|
-
for (;;) {
|
|
1380
|
-
const atRuleStart = source.indexOf("@source", searchIndex);
|
|
1381
|
-
if (atRuleStart === -1) {
|
|
1382
|
-
next += source.slice(searchIndex);
|
|
1383
|
-
break;
|
|
1384
|
-
}
|
|
1385
|
-
const nextChar = source[atRuleStart + 7];
|
|
1386
|
-
if (nextChar && /[\w-]/.test(nextChar)) {
|
|
1387
|
-
next += source.slice(searchIndex, atRuleStart + 7);
|
|
1388
|
-
searchIndex = atRuleStart + 7;
|
|
1389
|
-
continue;
|
|
1390
|
-
}
|
|
1391
|
-
next += source.slice(searchIndex, atRuleStart);
|
|
1392
|
-
let quote;
|
|
1393
|
-
let parenDepth = 0;
|
|
1394
|
-
let terminated = false;
|
|
1395
|
-
let index = atRuleStart + 7;
|
|
1396
|
-
for (; index < source.length; index++) {
|
|
1397
|
-
const char = source[index];
|
|
1398
|
-
if (quote) {
|
|
1399
|
-
if (char === "\\") {
|
|
1400
|
-
index++;
|
|
1401
|
-
continue;
|
|
1402
|
-
}
|
|
1403
|
-
if (char === quote) quote = void 0;
|
|
1404
|
-
continue;
|
|
1405
|
-
}
|
|
1406
|
-
if (char === "\"" || char === "'") {
|
|
1407
|
-
quote = char;
|
|
1408
|
-
continue;
|
|
1409
|
-
}
|
|
1410
|
-
if (char === "(") {
|
|
1411
|
-
parenDepth++;
|
|
1412
|
-
continue;
|
|
1413
|
-
}
|
|
1414
|
-
if (char === ")" && parenDepth > 0) {
|
|
1415
|
-
parenDepth--;
|
|
1416
|
-
continue;
|
|
1417
|
-
}
|
|
1418
|
-
if (parenDepth > 0) continue;
|
|
1419
|
-
if (char === ";" || char === "{") {
|
|
1420
|
-
terminated = true;
|
|
1421
|
-
index++;
|
|
1422
|
-
break;
|
|
1423
|
-
}
|
|
1424
|
-
if (char === "@" && /^(?:config|custom-variant|plugin|source|theme|utility|variant)\b/.test(source.slice(index + 1))) break;
|
|
1425
|
-
}
|
|
1426
|
-
const segment = source.slice(atRuleStart, index);
|
|
1427
|
-
const trimmedSegment = segment.trimEnd();
|
|
1428
|
-
next += terminated || trimmedSegment.endsWith(";") || trimmedSegment.endsWith("{") ? segment : `${trimmedSegment};${segment.slice(trimmedSegment.length)}`;
|
|
1429
|
-
searchIndex = index;
|
|
1430
|
-
}
|
|
1431
|
-
return next;
|
|
1432
|
-
}
|
|
1433
|
-
function findTailwindSourceWrapperBlockStart(source) {
|
|
1434
|
-
let searchIndex = 0;
|
|
1435
|
-
for (;;) {
|
|
1436
|
-
const atRuleStart = source.indexOf("@source", searchIndex);
|
|
1437
|
-
if (atRuleStart === -1) return -1;
|
|
1438
|
-
const nextChar = source[atRuleStart + 7];
|
|
1439
|
-
if (nextChar && /[\w-]/.test(nextChar)) {
|
|
1440
|
-
searchIndex = atRuleStart + 7;
|
|
1441
|
-
continue;
|
|
1442
|
-
}
|
|
1443
|
-
let quote;
|
|
1444
|
-
let parenDepth = 0;
|
|
1445
|
-
for (let index = atRuleStart + 7; index < source.length; index++) {
|
|
1446
|
-
const char = source[index];
|
|
1447
|
-
if (quote) {
|
|
1448
|
-
if (char === "\\") {
|
|
1449
|
-
index++;
|
|
1450
|
-
continue;
|
|
1451
|
-
}
|
|
1452
|
-
if (char === quote) quote = void 0;
|
|
1453
|
-
continue;
|
|
1454
|
-
}
|
|
1455
|
-
if (char === "\"" || char === "'") {
|
|
1456
|
-
quote = char;
|
|
1457
|
-
continue;
|
|
1458
|
-
}
|
|
1459
|
-
if (char === "(") {
|
|
1460
|
-
parenDepth++;
|
|
1461
|
-
continue;
|
|
1462
|
-
}
|
|
1463
|
-
if (char === ")" && parenDepth > 0) {
|
|
1464
|
-
parenDepth--;
|
|
1465
|
-
continue;
|
|
1466
|
-
}
|
|
1467
|
-
if (parenDepth > 0) continue;
|
|
1468
|
-
if (char === ";") {
|
|
1469
|
-
searchIndex = index + 1;
|
|
1470
|
-
break;
|
|
1471
|
-
}
|
|
1472
|
-
if (char === "{") return atRuleStart;
|
|
1473
|
-
}
|
|
1474
|
-
if (searchIndex <= atRuleStart) return -1;
|
|
1475
|
-
}
|
|
1476
|
-
}
|
|
1477
|
-
function removeTailwindApplyAtRules(source) {
|
|
1478
|
-
if (!source.includes("@apply")) return source;
|
|
1479
|
-
try {
|
|
1480
|
-
const root = postcss.parse(source);
|
|
1481
|
-
let changed = false;
|
|
1482
|
-
root.walkAtRules("apply", (rule) => {
|
|
1483
|
-
rule.remove();
|
|
1484
|
-
changed = true;
|
|
1485
|
-
});
|
|
1486
|
-
root.walk((node) => {
|
|
1487
|
-
if ("nodes" in node && node.nodes?.length === 0) node.remove();
|
|
1488
|
-
});
|
|
1489
|
-
return changed ? root.toString() : source;
|
|
1490
|
-
} catch {
|
|
1491
|
-
return source;
|
|
1492
|
-
}
|
|
1493
|
-
}
|
|
1494
|
-
function removeTailwindV4GeneratorAtRules(source) {
|
|
1495
|
-
try {
|
|
1496
|
-
const root = postcss.parse(source);
|
|
1497
|
-
let changed = false;
|
|
1498
|
-
root.walkAtRules((rule) => {
|
|
1499
|
-
if (rule.name === "media" && /^source\(/.test(rule.params.trim())) {
|
|
1500
|
-
rule.remove();
|
|
1501
|
-
changed = true;
|
|
1502
|
-
return;
|
|
1503
|
-
}
|
|
1504
|
-
if (!TAILWIND_V4_GENERATOR_AT_RULES.has(rule.name)) return;
|
|
1505
|
-
rule.remove();
|
|
1506
|
-
changed = true;
|
|
1507
|
-
});
|
|
1508
|
-
return changed ? root.toString() : source;
|
|
1509
|
-
} catch {
|
|
1510
|
-
return removeTailwindV4GeneratorAtRulesFallback(source);
|
|
1511
|
-
}
|
|
1512
|
-
}
|
|
1513
|
-
function isCommentOnlyCss(source) {
|
|
1514
|
-
try {
|
|
1515
|
-
const root = postcss.parse(source);
|
|
1516
|
-
return root.nodes.length > 0 && root.nodes.every((node) => node.type === "comment");
|
|
1517
|
-
} catch {
|
|
1518
|
-
return false;
|
|
1519
|
-
}
|
|
1520
|
-
}
|
|
1521
|
-
function removeMiniProgramHoverSelectors(source, enabled = true) {
|
|
1522
|
-
if (!enabled || !source.includes(":hover")) return source;
|
|
1523
|
-
try {
|
|
1524
|
-
const root = postcss.parse(source);
|
|
1525
|
-
let changed = false;
|
|
1526
|
-
root.walkRules((rule) => {
|
|
1527
|
-
const selectors = rule.selectors ?? [rule.selector];
|
|
1528
|
-
const keptSelectors = selectors.filter((selector) => !selector.includes(":hover"));
|
|
1529
|
-
if (keptSelectors.length === selectors.length) return;
|
|
1530
|
-
changed = true;
|
|
1531
|
-
if (keptSelectors.length === 0) {
|
|
1532
|
-
rule.remove();
|
|
1533
|
-
return;
|
|
1534
|
-
}
|
|
1535
|
-
rule.selectors = keptSelectors;
|
|
1536
|
-
});
|
|
1537
|
-
root.walk((node) => {
|
|
1538
|
-
if ("nodes" in node && node.nodes?.length === 0) {
|
|
1539
|
-
node.remove();
|
|
1540
|
-
changed = true;
|
|
1541
|
-
}
|
|
1542
|
-
});
|
|
1543
|
-
return changed ? root.toString() : source;
|
|
1544
|
-
} catch {
|
|
1545
|
-
return source;
|
|
1546
|
-
}
|
|
1547
|
-
}
|
|
1548
|
-
function removeProcessedMiniProgramUnsupportedCss(source, options) {
|
|
1549
|
-
return removeMiniProgramHoverSelectors(removeUnsupportedMiniProgramAtRules(source), options.cssRemoveHoverPseudoClass);
|
|
1550
|
-
}
|
|
1551
|
-
function unwrapMiniProgramCascadeLayers(source) {
|
|
1552
|
-
if (!source.includes("@layer")) return source;
|
|
1553
|
-
try {
|
|
1554
|
-
const root = postcss.parse(source);
|
|
1555
|
-
removeUnsupportedCascadeLayers(root);
|
|
1556
|
-
return root.toString();
|
|
1557
|
-
} catch {
|
|
1558
|
-
return source;
|
|
1559
|
-
}
|
|
1560
|
-
}
|
|
1561
|
-
function stripTailwindSourceMediaFragments(source) {
|
|
1562
|
-
let removedSourceMediaStart = false;
|
|
1563
|
-
return terminateTailwindSourceAtRulesBeforeNextDirective(removeTailwindSourceMediaBlocks(source)).split(/\r?\n/).filter((line) => {
|
|
1564
|
-
if (/^\s*@media\s+source\([^)]*\)\s*\{\s*$/.test(line)) {
|
|
1565
|
-
removedSourceMediaStart = true;
|
|
1566
|
-
return false;
|
|
1567
|
-
}
|
|
1568
|
-
if (/^\s*\}\s*\/\*\s*source\([^)]*\)\s*\*\/\s*$/.test(line)) return false;
|
|
1569
|
-
if (removedSourceMediaStart && /^\s*\}\s*$/.test(line)) {
|
|
1570
|
-
removedSourceMediaStart = false;
|
|
1571
|
-
return false;
|
|
1572
|
-
}
|
|
1573
|
-
return true;
|
|
1574
|
-
}).join("\n");
|
|
1575
|
-
}
|
|
1576
|
-
function stripLeadingTailwindSourceMediaCloseFragment(source) {
|
|
1577
|
-
return source.replace(/^\s*\}\s*(?:\n|$)/, "");
|
|
1578
|
-
}
|
|
1579
|
-
function stripUnmatchedTailwindSourceMediaCloseFragments(source) {
|
|
1580
|
-
try {
|
|
1581
|
-
postcss.parse(source);
|
|
1582
|
-
return source;
|
|
1583
|
-
} catch {
|
|
1584
|
-
return stripLeadingTailwindSourceMediaCloseFragment(source).replace(/\s*\}\s*$/, "");
|
|
1585
|
-
}
|
|
1586
|
-
}
|
|
1587
|
-
function splitUserCssLayerBlocks(source) {
|
|
1588
|
-
if (!source.includes("@layer")) return {
|
|
1589
|
-
layer: "",
|
|
1590
|
-
rest: source
|
|
1591
|
-
};
|
|
1592
|
-
try {
|
|
1593
|
-
const root = postcss.parse(source);
|
|
1594
|
-
const layerRoot = postcss.root();
|
|
1595
|
-
const restRoot = postcss.root();
|
|
1596
|
-
for (const node of root.nodes) (node.type === "atrule" && node.name === "layer" && node.nodes?.length ? layerRoot : restRoot).append(node.clone());
|
|
1597
|
-
return {
|
|
1598
|
-
layer: layerRoot.toString(),
|
|
1599
|
-
rest: restRoot.toString()
|
|
1600
|
-
};
|
|
1601
|
-
} catch {
|
|
1602
|
-
return {
|
|
1603
|
-
layer: source,
|
|
1604
|
-
rest: ""
|
|
1605
|
-
};
|
|
1606
|
-
}
|
|
1607
|
-
}
|
|
1608
|
-
function hasUserCssLayerBlocks(source) {
|
|
1609
|
-
if (!source.includes("@layer")) return false;
|
|
1610
|
-
try {
|
|
1611
|
-
let hasLayerBlock = false;
|
|
1612
|
-
postcss.parse(source).walkAtRules("layer", (node) => {
|
|
1613
|
-
if (node.nodes?.length) hasLayerBlock = true;
|
|
1614
|
-
});
|
|
1615
|
-
return hasLayerBlock;
|
|
1616
|
-
} catch {
|
|
1617
|
-
return true;
|
|
1618
|
-
}
|
|
1619
|
-
}
|
|
1620
|
-
function collectUserLayerSelectors(source) {
|
|
1621
|
-
const selectors = /* @__PURE__ */ new Set();
|
|
1622
|
-
try {
|
|
1623
|
-
postcss.parse(source).walkRules((rule) => {
|
|
1624
|
-
for (const selector of rule.selectors ?? [rule.selector]) {
|
|
1625
|
-
const normalized = selector.trim();
|
|
1626
|
-
if (normalized) selectors.add(normalized);
|
|
1627
|
-
}
|
|
1628
|
-
});
|
|
1629
|
-
} catch {}
|
|
1630
|
-
return selectors;
|
|
1631
|
-
}
|
|
1632
|
-
function matchesUserLayerSelector(selector, userLayerSelector) {
|
|
1633
|
-
if (selector === userLayerSelector) return true;
|
|
1634
|
-
if (!selector.startsWith(userLayerSelector)) return false;
|
|
1635
|
-
const next = selector[userLayerSelector.length];
|
|
1636
|
-
return next === ":" || next === "[";
|
|
1637
|
-
}
|
|
1638
|
-
function extractGeneratedCssForUserLayerSelectors(css, userLayerSource) {
|
|
1639
|
-
const selectors = collectUserLayerSelectors(userLayerSource);
|
|
1640
|
-
if (selectors.size === 0) return {
|
|
1641
|
-
layer: "",
|
|
1642
|
-
rest: css
|
|
1643
|
-
};
|
|
1644
|
-
try {
|
|
1645
|
-
const root = postcss.parse(css);
|
|
1646
|
-
const layerRoot = postcss.root();
|
|
1647
|
-
const selectorList = [...selectors];
|
|
1648
|
-
root.walkRules((rule) => {
|
|
1649
|
-
if ((rule.selectors ?? [rule.selector]).some((selector) => selectorList.some((userSelector) => matchesUserLayerSelector(selector.trim(), userSelector)))) {
|
|
1650
|
-
layerRoot.append(rule.clone());
|
|
1651
|
-
rule.remove();
|
|
1652
|
-
}
|
|
1653
|
-
});
|
|
1654
|
-
return {
|
|
1655
|
-
layer: layerRoot.toString(),
|
|
1656
|
-
rest: root.toString()
|
|
1657
|
-
};
|
|
1658
|
-
} catch {
|
|
1659
|
-
return {
|
|
1660
|
-
layer: "",
|
|
1661
|
-
rest: css
|
|
1662
|
-
};
|
|
1663
|
-
}
|
|
1664
|
-
}
|
|
1665
|
-
function normalizeGeneratedSelector(selector) {
|
|
1666
|
-
return selector.replace(/:not\(#\\#\)/g, "").trim();
|
|
1667
|
-
}
|
|
1668
|
-
function collectApplyOnlySourceSelectors(source) {
|
|
1669
|
-
const selectors = /* @__PURE__ */ new Set();
|
|
1670
|
-
try {
|
|
1671
|
-
postcss.parse(source).walkRules((rule) => {
|
|
1672
|
-
if (!rule.nodes?.some((node) => node.type === "atrule" && node.name === "apply")) return;
|
|
1673
|
-
for (const selector of rule.selectors ?? [rule.selector]) {
|
|
1674
|
-
const normalized = normalizeGeneratedSelector(selector);
|
|
1675
|
-
if (normalized) selectors.add(normalized);
|
|
1676
|
-
}
|
|
1677
|
-
});
|
|
1678
|
-
} catch {}
|
|
1679
|
-
return selectors;
|
|
1680
|
-
}
|
|
1681
|
-
function hasOnlyApplyBackedSourceRules(source) {
|
|
1682
|
-
let hasApplyRule = false;
|
|
1683
|
-
let hasNonApplyRule = false;
|
|
1684
|
-
try {
|
|
1685
|
-
postcss.parse(source).walkRules((rule) => {
|
|
1686
|
-
if (rule.nodes?.some((node) => node.type === "atrule" && node.name === "apply")) hasApplyRule = true;
|
|
1687
|
-
else hasNonApplyRule = true;
|
|
1688
|
-
});
|
|
1689
|
-
} catch {
|
|
1690
|
-
return false;
|
|
1691
|
-
}
|
|
1692
|
-
return hasApplyRule && !hasNonApplyRule;
|
|
1693
|
-
}
|
|
1694
|
-
function filterApplyOnlyGeneratedCss(css, source) {
|
|
1695
|
-
const selectors = collectApplyOnlySourceSelectors(source);
|
|
1696
|
-
if (selectors.size === 0) return css;
|
|
1697
|
-
const selectorList = [...selectors];
|
|
1698
|
-
try {
|
|
1699
|
-
const root = postcss.parse(css);
|
|
1700
|
-
root.walkRules((rule) => {
|
|
1701
|
-
const isApplySelector = (rule.selectors ?? [rule.selector]).some((selector) => {
|
|
1702
|
-
const normalized = normalizeGeneratedSelector(selector);
|
|
1703
|
-
return selectorList.some((sourceSelector) => {
|
|
1704
|
-
if (normalized === sourceSelector) return true;
|
|
1705
|
-
if (!normalized.startsWith(sourceSelector)) return false;
|
|
1706
|
-
const next = normalized[sourceSelector.length];
|
|
1707
|
-
return next === ":" || next === "[" || next === ".";
|
|
1708
|
-
});
|
|
1709
|
-
});
|
|
1710
|
-
const isVariableRule = rule.nodes?.some((node) => node.type === "decl" && node.prop.startsWith("--"));
|
|
1711
|
-
if (!isApplySelector && !isVariableRule) rule.remove();
|
|
1712
|
-
});
|
|
1713
|
-
root.walkAtRules((rule) => {
|
|
1714
|
-
if (rule.nodes !== void 0 && rule.nodes.length === 0) rule.remove();
|
|
1715
|
-
});
|
|
1716
|
-
return root.toString();
|
|
1717
|
-
} catch {
|
|
1718
|
-
return css;
|
|
1719
|
-
}
|
|
1720
|
-
}
|
|
1721
|
-
function shouldFilterApplyOnlyGeneratedCss(_majorVersion, target, source, options) {
|
|
1722
|
-
return target === "weapp" && hasTailwindApplyDirective(source) && !hasTailwindRootDirectives(source) && !options.hasGeneratedCss && !options.hasGeneratedMarkers && collectApplyOnlySourceSelectors(source).size > 0 && hasOnlyApplyBackedSourceRules(source);
|
|
1723
|
-
}
|
|
1724
|
-
async function transformGeneratorUserCss(source, options) {
|
|
1725
|
-
if (source.trim().length === 0) return "";
|
|
1726
|
-
if (options.processed) return stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(removeTailwindV4GeneratorAtRules(options.generatorTarget === "weapp" ? removeTailwindV4GeneratedUserCssArtifacts(removeProcessedMiniProgramUnsupportedCss(source, {
|
|
1727
|
-
...options.generatorStyleOptions,
|
|
1728
|
-
...options.cssUserHandlerOptions
|
|
1729
|
-
})) : source)));
|
|
1730
|
-
const cleanedSource = removeTailwindSourceDirectives(removeTailwindV4GeneratorAtRules(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(source))), { importFallback: options.importFallback });
|
|
1731
|
-
if (cleanedSource.trim().length === 0) return "";
|
|
1732
|
-
const userSource = stripUnmatchedTailwindSourceMediaCloseFragments(removeTailwindApplyAtRules(removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(options.generatorTarget === "weapp" ? removeTailwindV4GeneratedUserCssArtifacts(removeUnsupportedMiniProgramAtRules(unwrapMiniProgramCascadeLayers(cleanedSource))) : cleanedSource)), { importFallback: options.importFallback })));
|
|
1733
|
-
if (userSource.trim().length === 0) return "";
|
|
1734
|
-
if (isCommentOnlyCss(userSource)) return userSource;
|
|
1735
|
-
if (options.generatorTarget !== "weapp") return userSource;
|
|
1736
|
-
const { css } = await options.styleHandler(userSource, {
|
|
1737
|
-
...options.generatorStyleOptions,
|
|
1738
|
-
...options.cssUserHandlerOptions
|
|
1739
|
-
});
|
|
1740
|
-
return removeTailwindV4GeneratedUserCssArtifacts(removeUnsupportedMiniProgramAtRules(css));
|
|
1741
|
-
}
|
|
1742
|
-
//#endregion
|
|
1743
1387
|
//#region src/bundlers/shared/generator-css/legacy-compat.ts
|
|
1744
1388
|
const LEGACY_CONTAINER_COMPAT_CSS = [
|
|
1745
1389
|
".container {",
|
|
@@ -2244,11 +1888,12 @@ function finalizeWebGeneratorCss(css, target, webCompat) {
|
|
|
2244
1888
|
return target === "web" ? transformWebCssCompat(css, webCompat) : css;
|
|
2245
1889
|
}
|
|
2246
1890
|
async function generateCssByGenerator(options) {
|
|
2247
|
-
const { opts, runtimeState, runtime, rawSource, file, cssHandlerOptions, cssUserHandlerOptions, getSourceCandidatesForEntries, styleHandler, userRawSource, userRawSourceProcessed, debug } = options;
|
|
1891
|
+
const { opts, runtimeState, runtime, rawSource, file, cssHandlerOptions, cssUserHandlerOptions, getSourceCandidatesForEntries, styleHandler, generatorPlatform, userRawSource, userRawSourceProcessed, debug } = options;
|
|
1892
|
+
const platform = generatorPlatform ?? opts.cssOptions?.platform ?? opts.platform;
|
|
2248
1893
|
const generatorOptions = {
|
|
2249
1894
|
...normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
2250
1895
|
appType: opts.appType,
|
|
2251
|
-
platform
|
|
1896
|
+
platform,
|
|
2252
1897
|
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
2253
1898
|
uniAppX: opts.uniAppX
|
|
2254
1899
|
}),
|
|
@@ -2256,13 +1901,13 @@ async function generateCssByGenerator(options) {
|
|
|
2256
1901
|
};
|
|
2257
1902
|
const generatorBranch = resolveGeneratorRuntimeBranch(generatorOptions, {
|
|
2258
1903
|
appType: opts.appType,
|
|
2259
|
-
platform
|
|
1904
|
+
platform,
|
|
2260
1905
|
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
2261
1906
|
uniAppX: opts.uniAppX
|
|
2262
1907
|
});
|
|
2263
1908
|
const majorVersion = runtimeState.tailwindRuntime.majorVersion;
|
|
2264
1909
|
if (majorVersion !== 4) throw new Error("weapp-tailwindcss 生成管线仅支持 Tailwind CSS v4。");
|
|
2265
|
-
const effectiveRawSource = stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(normalizeTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })));
|
|
1910
|
+
const effectiveRawSource = stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(normalizeEmptyTailwindCustomVariants(normalizeTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback }))));
|
|
2266
1911
|
const effectiveRawSourceRoot = parseCssSourceRoot(effectiveRawSource);
|
|
2267
1912
|
const cleanedLocalImportWrapper = cleanLocalCssImportWrapperFromParsedRoot(effectiveRawSource, effectiveRawSourceRoot);
|
|
2268
1913
|
if (cleanedLocalImportWrapper !== void 0) return {
|
|
@@ -2280,10 +1925,10 @@ async function generateCssByGenerator(options) {
|
|
|
2280
1925
|
const localImportParts = splitLocalCssImportsFromParsedRoot(effectiveRawSource, effectiveRawSourceRoot);
|
|
2281
1926
|
const localImports = options.restoreLocalCssImports === false ? void 0 : localImportParts?.imports;
|
|
2282
1927
|
const finalizeGeneratorCss = (css, target, finalizeOptions = {}) => {
|
|
2283
|
-
return finalizeWebGeneratorCss(restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, target, majorVersion, opts.cssPreflight, finalizeOptions), localImports), target, generatorOptions.webCompat);
|
|
1928
|
+
return finalizeWebGeneratorCss(restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, target, majorVersion, opts.cssPreflight, finalizeOptions), localImports, { outputFile: file }), target, generatorOptions.webCompat);
|
|
2284
1929
|
};
|
|
2285
1930
|
const generatorRawSource = localImportParts?.source ?? effectiveRawSource;
|
|
2286
|
-
const rawUserSource = userRawSource === void 0 ? generatorRawSource : userRawSourceProcessed ? userRawSource : stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(normalizeTailwindSourceDirectives(userRawSource, { importFallback: generatorOptions.importFallback })));
|
|
1931
|
+
const rawUserSource = userRawSource === void 0 ? generatorRawSource : userRawSourceProcessed ? userRawSource : stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(normalizeEmptyTailwindCustomVariants(normalizeTailwindSourceDirectives(userRawSource, { importFallback: generatorOptions.importFallback }))));
|
|
2287
1932
|
const userSource = (rawUserSource === generatorRawSource ? void 0 : splitLocalCssImports(rawUserSource))?.source ?? rawUserSource;
|
|
2288
1933
|
const userCssRawSource = removeTailwindV4GeneratorAtRules(userSource);
|
|
2289
1934
|
const generatedUserCssOrderSource = hasTailwindGeneratedCss(userSource) ? splitTailwindV4GeneratedCssBySourceOrder(userSource, generatorRawSource) : void 0;
|
|
@@ -2293,6 +1938,10 @@ async function generateCssByGenerator(options) {
|
|
|
2293
1938
|
const hasGeneratedCss = hasTailwindGeneratedCss(generatorRawSource);
|
|
2294
1939
|
const hasSourceDirectives = hasTailwindSourceDirectives(generatorRawSource, { importFallback: generatorOptions.importFallback });
|
|
2295
1940
|
const hasGeneratedMarkers = hasTailwindGeneratedCssMarkers(generatorRawSource);
|
|
1941
|
+
const normalizedCssSources = options.cssSources?.map((source) => ({
|
|
1942
|
+
...source,
|
|
1943
|
+
css: normalizeEmptyTailwindCustomVariants(source.css)
|
|
1944
|
+
}));
|
|
2296
1945
|
if (!shouldUseGeneratorForCurrentCss(majorVersion, cssHandlerOptions, {
|
|
2297
1946
|
forceGenerator: options.forceGenerator,
|
|
2298
1947
|
hasGeneratedCss,
|
|
@@ -2313,8 +1962,8 @@ async function generateCssByGenerator(options) {
|
|
|
2313
1962
|
});
|
|
2314
1963
|
const runtimeWithCurrentCss = createRuntimeWithCurrentCssCandidates(runtime, currentCssCandidates, isolateCurrentCssCandidates);
|
|
2315
1964
|
const sources = await resolveGeneratorSources(majorVersion, runtimeState, generatorRawSource, file, cssHandlerOptions, generatorOptions, {
|
|
2316
|
-
cssEntries: opts.cssEntries,
|
|
2317
|
-
cssSources:
|
|
1965
|
+
cssEntries: cssHandlerOptions.sourceOptions?.cssEntries ?? opts.cssEntries,
|
|
1966
|
+
cssSources: normalizedCssSources,
|
|
2318
1967
|
getSourceCandidatesForEntries,
|
|
2319
1968
|
runtime: runtimeWithCurrentCss
|
|
2320
1969
|
});
|
|
@@ -2360,7 +2009,7 @@ async function generateCssByGenerator(options) {
|
|
|
2360
2009
|
const finalCss = finalizeWebGeneratorCss(restoreLocalCssImports(incrementalCss.trim().length > 0 ? createCssAppend(options.previousCss, finalizeMiniProgramGeneratorCss(incrementalCss, generated.target, majorVersion, opts.cssPreflight, {
|
|
2361
2010
|
injectPreflight: false,
|
|
2362
2011
|
styleOptions: generatorStyleOptions
|
|
2363
|
-
})) : options.previousCss, localImports), generated.target, generatorOptions.webCompat);
|
|
2012
|
+
})) : options.previousCss, localImports, { outputFile: file }), generated.target, generatorOptions.webCompat);
|
|
2364
2013
|
return {
|
|
2365
2014
|
css: finalCss,
|
|
2366
2015
|
classSet: mergeGeneratedCssClassSet(generated.classSet, runtimeWithCurrentCss, finalCss, opts.escapeMap),
|
|
@@ -2380,8 +2029,21 @@ async function generateCssByGenerator(options) {
|
|
|
2380
2029
|
hasGeneratedMarkers
|
|
2381
2030
|
});
|
|
2382
2031
|
const generatedCssSource = generated.target === "web" ? generated.css : stripTailwindBanner(generated.css);
|
|
2383
|
-
const generatedCss = shouldFilterApplyOnlyCss ? filterApplyOnlyGeneratedCss(generatedCssSource, generatorRawSource) : generatedCssSource;
|
|
2032
|
+
const generatedCss = shouldFilterApplyOnlyCss ? filterApplyOnlyGeneratedCss(generatedCssSource, generatorRawSource, { preserveVariables: generated.target !== "web" }) : generatedCssSource;
|
|
2384
2033
|
const hasMatchedCssSourceFile = sources.some((source) => source.__weappTailwindcssMeta?.matchedCssSourceFile);
|
|
2034
|
+
const hasExplicitCssSource = sources.some((source) => {
|
|
2035
|
+
const metadata = source.__weappTailwindcssMeta;
|
|
2036
|
+
return metadata?.cssEntryIndex !== void 0 || metadata?.cssSourceIndex !== void 0;
|
|
2037
|
+
});
|
|
2038
|
+
const hasPreflightCssSource = sources.some((source) => source.__weappTailwindcssMeta?.includesPreflight === true);
|
|
2039
|
+
const hasPreflightRawSource = includesTailwindV4PreflightDirective(generatorRawSource);
|
|
2040
|
+
const preflightMode = resolveMiniProgramPreflightModeForGeneratorCss(opts, {
|
|
2041
|
+
cssHandlerOptions,
|
|
2042
|
+
isolateCurrentCssCandidates,
|
|
2043
|
+
localImports,
|
|
2044
|
+
explicitCssSource: hasExplicitCssSource,
|
|
2045
|
+
primaryCssSource: sources.length > 0 && sources.every((source) => source.__weappTailwindcssMeta?.primaryCssSource === true) || hasPreflightCssSource || hasPreflightRawSource
|
|
2046
|
+
});
|
|
2385
2047
|
const orderedExtraCss = splitGeneratorPlaceholderCssBySourceOrder(userCssOrderSource, generated.rawCss) ?? (hasMatchedCssSourceFile ? splitTailwindV4GeneratedCssBySourceOrder(userCssOrderSource, generated.rawCss) : splitRawSourceByGeneratedCssOrder(userCssOrderSource, generated.rawCss));
|
|
2386
2048
|
const shouldAppendMatchedCssSourceCompat = !hasMatchedCssSourceFile || orderedExtraCss !== void 0;
|
|
2387
2049
|
if (orderedExtraCss) {
|
|
@@ -2429,11 +2091,8 @@ async function generateCssByGenerator(options) {
|
|
|
2429
2091
|
}
|
|
2430
2092
|
} else if (generated.target === "weapp" && shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
|
|
2431
2093
|
const finalCss = finalizeGeneratorCss(css, generated.target, {
|
|
2432
|
-
injectPreflight:
|
|
2433
|
-
|
|
2434
|
-
isolateCurrentCssCandidates,
|
|
2435
|
-
localImports
|
|
2436
|
-
}),
|
|
2094
|
+
injectPreflight: preflightMode.inject,
|
|
2095
|
+
preservePreflight: preflightMode.preserve,
|
|
2437
2096
|
styleOptions: generatorStyleOptions
|
|
2438
2097
|
});
|
|
2439
2098
|
return {
|
|
@@ -2537,11 +2196,8 @@ async function generateCssByGenerator(options) {
|
|
|
2537
2196
|
css = createCssSourceOrderAppend$1(css, missingUserCss);
|
|
2538
2197
|
}
|
|
2539
2198
|
const finalCss = finalizeGeneratorCss(css, generated.target, {
|
|
2540
|
-
injectPreflight:
|
|
2541
|
-
|
|
2542
|
-
isolateCurrentCssCandidates,
|
|
2543
|
-
localImports
|
|
2544
|
-
}),
|
|
2199
|
+
injectPreflight: preflightMode.inject,
|
|
2200
|
+
preservePreflight: preflightMode.preserve,
|
|
2545
2201
|
styleOptions: generatorStyleOptions
|
|
2546
2202
|
});
|
|
2547
2203
|
return {
|
|
@@ -2574,11 +2230,8 @@ async function generateCssByGenerator(options) {
|
|
|
2574
2230
|
css = createCssSourceOrderAppend$1(css, missingUserCss);
|
|
2575
2231
|
}
|
|
2576
2232
|
const finalCss = finalizeGeneratorCss(css, generated.target, {
|
|
2577
|
-
injectPreflight:
|
|
2578
|
-
|
|
2579
|
-
isolateCurrentCssCandidates,
|
|
2580
|
-
localImports
|
|
2581
|
-
}),
|
|
2233
|
+
injectPreflight: preflightMode.inject,
|
|
2234
|
+
preservePreflight: preflightMode.preserve,
|
|
2582
2235
|
styleOptions: generatorStyleOptions
|
|
2583
2236
|
});
|
|
2584
2237
|
return {
|
|
@@ -3417,4 +3070,4 @@ function createHmrTimingRecorder(bundler) {
|
|
|
3417
3070
|
};
|
|
3418
3071
|
}
|
|
3419
3072
|
//#endregion
|
|
3420
|
-
export {
|
|
3073
|
+
export { hasMiniProgramTailwindV4PreflightReset as C, isCssSourceTraceEnabled as D, createCssTokenSourceMap as E, processCachedTask as O, createCssSourceOrderAppend$1 as S, createCssSourceTraceCacheSignature as T, isPureLocalCssImportWrapper as _, isSourceCandidateRequest as a, scoreTailwindV4CssSourceFileMatch as b, collectStrictEscapedRuntimeCandidates as c, validateCandidatesByGenerator as d, pushConcurrentTaskFactories as f, mergeMarkedUserLayerComponentsCss as g, extractMarkedUserLayerComponentsCss as h, createSourceCandidateStore as i, 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, annotateCssSourceTrace as w, removeGeneratedSelectorCompatCss as x, splitLocalCssImports as y };
|