weapp-tailwindcss 5.1.3 → 5.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auto-CrJJc5rK.mjs +13 -0
- package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +8 -2
- package/dist/bundlers/shared/generator-css/local-imports.d.ts +1 -10
- package/dist/bundlers/shared/generator-css/source-resolver/metadata.d.ts +5 -1
- package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/tailwind-v4-css-source.d.ts +6 -3
- package/dist/bundlers/vite/generate-bundle/temporary-css-assets.d.ts +1 -1
- package/dist/bundlers/vite/hot-css-modules.d.ts +1 -0
- package/dist/bundlers/vite/processed-css-assets.d.ts +1 -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-D75pwtBW.js → context-BziwyWy1.js} +56 -9
- package/dist/{context-B07Vf584.mjs → context-rrYZuUBU.mjs} +48 -7
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/css-macro/auto.d.ts +1 -1
- package/dist/css-macro/index.d.ts +2 -1
- package/dist/css-macro.mjs +1 -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/framework/platform.d.ts +2 -0
- package/dist/{generator-DNs6ekoC.mjs → generator-24-HgU9F.mjs} +5 -3
- package/dist/{generator-CV_0irKO.js → generator-CilgHtxb.js} +5 -3
- package/dist/generator.js +2 -2
- package/dist/generator.mjs +2 -2
- package/dist/{gulp-B_u8NjQL.js → gulp-CuVsZdO9.js} +7 -6
- package/dist/{gulp-aQMZ0M7c.mjs → gulp-ygWfmOqh.mjs} +4 -4
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{hmr-timing-DOoHun3i.js → hmr-timing-BKdCeIrn.js} +244 -229
- package/dist/{hmr-timing-DLYQTCDb.mjs → hmr-timing-Dh_nn3w5.mjs} +244 -211
- 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 +2 -2
- package/dist/presets.mjs +2 -2
- package/dist/rspack.js +1 -1
- package/dist/rspack.mjs +1 -1
- package/dist/{source-candidate-scan-signature-pS87mdHZ.mjs → source-candidate-scan-signature-DATRnS1X.mjs} +165 -8
- package/dist/{source-candidate-scan-signature-DzwebZrf.js → source-candidate-scan-signature-DIj9m4wB.js} +177 -7
- 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/v4-engine/css-macro-source.d.ts +2 -0
- package/dist/{tailwindcss-BSCvrs1p.js → tailwindcss-BwoNQ3t8.js} +56 -16
- package/dist/{tailwindcss-BwV3_Ryc.mjs → tailwindcss-C-uM4rB8.mjs} +51 -17
- package/dist/{transform-Clj7R818.mjs → transform-DHLemtaX.mjs} +1 -1
- package/dist/{transform-fin-OTVD.js → transform-KLD1tJdb.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-BklH3CpJ.mjs → v4-engine-BuuYDXt1.mjs} +54 -114
- package/dist/{v4-engine-CKbS27-o.js → v4-engine-CKtsdKxK.js} +57 -111
- package/dist/{vite-CkVMSDDp.js → vite-Yp14HNyS.js} +310 -78
- package/dist/{vite-5Wn0PIzJ.mjs → vite-cH0tTMHc.mjs} +308 -76
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +363 -272
- package/dist/{webpack-DEag6ueE.mjs → webpack-DBhmJ-_P.mjs} +107 -20
- package/dist/{webpack-hvSFaicc.js → webpack-DN3tgLbF.js} +107 -20
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +16 -5
- package/dist/auto-Ba6hDrse.mjs +0 -13
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const require_rolldown_runtime = require("./rolldown-runtime-emK7D4bc.js");
|
|
2
|
-
const require_v4_engine = require("./v4-engine-
|
|
3
|
-
const require_generator = require("./generator-
|
|
4
|
-
const require_context = require("./context-
|
|
5
|
-
const require_tailwindcss = require("./tailwindcss-
|
|
2
|
+
const require_v4_engine = require("./v4-engine-CKtsdKxK.js");
|
|
3
|
+
const require_generator = require("./generator-CilgHtxb.js");
|
|
4
|
+
const require_context = require("./context-BziwyWy1.js");
|
|
5
|
+
const require_tailwindcss = require("./tailwindcss-BwoNQ3t8.js");
|
|
6
6
|
let node_fs = require("node:fs");
|
|
7
7
|
let node_path = require("node:path");
|
|
8
8
|
node_path = require_rolldown_runtime.__toESM(node_path);
|
|
@@ -156,22 +156,91 @@ function collectGeneratedRawSourceCandidates(candidates, rawSource, escapeMap) {
|
|
|
156
156
|
return matched;
|
|
157
157
|
}
|
|
158
158
|
//#endregion
|
|
159
|
+
//#region src/bundlers/shared/generator-css/source-resolver/postcss-source.ts
|
|
160
|
+
function resolvePostcssFromOption(cssHandlerOptions) {
|
|
161
|
+
const from = cssHandlerOptions.postcssOptions?.options?.from;
|
|
162
|
+
return typeof from === "string" && from.length > 0 ? from : void 0;
|
|
163
|
+
}
|
|
164
|
+
function resolvePostcssSourceFile(cssHandlerOptions) {
|
|
165
|
+
const from = resolvePostcssFromOption(cssHandlerOptions);
|
|
166
|
+
if (!from || !node_path.default.isAbsolute(from)) return;
|
|
167
|
+
return from.replace(/[?#].*$/, "");
|
|
168
|
+
}
|
|
169
|
+
function resolveCssHandlerSourceOptions(cssHandlerOptions) {
|
|
170
|
+
return cssHandlerOptions.sourceOptions;
|
|
171
|
+
}
|
|
172
|
+
function resolveCssSourceBase(file, cssHandlerOptions) {
|
|
173
|
+
const normalized = (resolvePostcssFromOption(cssHandlerOptions) ?? file).replace(/[?#].*$/, "");
|
|
174
|
+
return node_path.default.dirname(node_path.default.resolve(normalized));
|
|
175
|
+
}
|
|
176
|
+
//#endregion
|
|
159
177
|
//#region src/bundlers/shared/generator-css/generation-helpers.ts
|
|
178
|
+
function isVueScopedStyleSource(from) {
|
|
179
|
+
if (typeof from !== "string" || from.length === 0) return false;
|
|
180
|
+
const queryIndex = from.indexOf("?");
|
|
181
|
+
if (queryIndex === -1) return false;
|
|
182
|
+
const query = from.slice(queryIndex + 1);
|
|
183
|
+
return /(?:^|&)type=style(?:&|$)/.test(query) && /(?:^|&)scoped(?:=(?:true|1))?(?:&|$)/.test(query);
|
|
184
|
+
}
|
|
160
185
|
function hasMiniProgramTailwindV4PreflightReset(css) {
|
|
161
186
|
return /(?:^|[},])\s*view\s*,\s*text\s*,\s*::after\s*,\s*::before\s*\{[^}]*\bborder\s*:\s*0\s+solid\b/.test(css);
|
|
162
187
|
}
|
|
163
188
|
function finalizeMiniProgramGeneratorCss(css, target, _majorVersion, cssPreflight, options = {}) {
|
|
164
189
|
if (target !== "weapp") return css;
|
|
190
|
+
if (isVueScopedStyleSource(options.styleOptions?.postcssOptions?.options?.from)) return (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(css, {
|
|
191
|
+
cssPreflight: false,
|
|
192
|
+
cssSelectorReplacement: options.styleOptions?.cssOptions?.cssSelectorReplacement ?? options.styleOptions?.cssSelectorReplacement,
|
|
193
|
+
isTailwindcssV4: true,
|
|
194
|
+
tailwindcssV4GradientFallback: options.styleOptions?.cssOptions?.tailwindcssV4GradientFallback ?? options.styleOptions?.tailwindcssV4GradientFallback
|
|
195
|
+
});
|
|
196
|
+
const hasPreflightReset = hasMiniProgramTailwindV4PreflightReset(css);
|
|
197
|
+
const injectPreflight = options.injectPreflight !== false && !hasPreflightReset;
|
|
198
|
+
const preservePreflight = options.preservePreflight !== false;
|
|
165
199
|
return (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(css, {
|
|
166
|
-
cssPreflight: options.injectPreflight
|
|
200
|
+
cssPreflight: cssPreflight === false || options.injectPreflight === false && (!hasPreflightReset || !preservePreflight) ? false : injectPreflight ? cssPreflight : hasPreflightReset && preservePreflight ? cssPreflight : void 0,
|
|
201
|
+
cssSelectorReplacement: options.styleOptions?.cssOptions?.cssSelectorReplacement ?? options.styleOptions?.cssSelectorReplacement,
|
|
167
202
|
isTailwindcssV4: true,
|
|
168
203
|
tailwindcssV4GradientFallback: options.styleOptions?.cssOptions?.tailwindcssV4GradientFallback ?? options.styleOptions?.tailwindcssV4GradientFallback
|
|
169
204
|
});
|
|
170
205
|
}
|
|
171
|
-
function
|
|
172
|
-
if (options.cssHandlerOptions
|
|
173
|
-
|
|
174
|
-
|
|
206
|
+
function resolveMiniProgramPreflightModeForGeneratorCss(opts, options) {
|
|
207
|
+
if (isVueScopedStyleSource(resolvePostcssFromOption(options.cssHandlerOptions))) return {
|
|
208
|
+
inject: false,
|
|
209
|
+
preserve: false
|
|
210
|
+
};
|
|
211
|
+
if (options.cssHandlerOptions.uniAppX === true && options.cssHandlerOptions.uniAppXCssTarget === "uvue") return {
|
|
212
|
+
inject: false,
|
|
213
|
+
preserve: false
|
|
214
|
+
};
|
|
215
|
+
const shouldInjectUniAppXLocalImportPreflight = require_tailwindcss.isUniAppXEnabled(opts.uniAppX) && Boolean(options.localImports?.trim());
|
|
216
|
+
if (opts.cssPreflight === false) return {
|
|
217
|
+
inject: false,
|
|
218
|
+
preserve: false
|
|
219
|
+
};
|
|
220
|
+
if (options.primaryCssSource) return {
|
|
221
|
+
inject: true,
|
|
222
|
+
preserve: true
|
|
223
|
+
};
|
|
224
|
+
if (options.explicitCssSource) return {
|
|
225
|
+
inject: false,
|
|
226
|
+
preserve: true
|
|
227
|
+
};
|
|
228
|
+
if (options.cssHandlerOptions.isMainChunk) return {
|
|
229
|
+
inject: true,
|
|
230
|
+
preserve: true
|
|
231
|
+
};
|
|
232
|
+
if (!options.cssHandlerOptions.isMainChunk && !options.primaryCssSource && !options.explicitCssSource) return {
|
|
233
|
+
inject: shouldInjectUniAppXLocalImportPreflight,
|
|
234
|
+
preserve: shouldInjectUniAppXLocalImportPreflight
|
|
235
|
+
};
|
|
236
|
+
if (!options.isolateCurrentCssCandidates) return {
|
|
237
|
+
inject: true,
|
|
238
|
+
preserve: true
|
|
239
|
+
};
|
|
240
|
+
return {
|
|
241
|
+
inject: shouldInjectUniAppXLocalImportPreflight,
|
|
242
|
+
preserve: shouldInjectUniAppXLocalImportPreflight
|
|
243
|
+
};
|
|
175
244
|
}
|
|
176
245
|
function mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtime, options) {
|
|
177
246
|
if (options.isolateCssSource) {
|
|
@@ -205,9 +274,10 @@ function isEmptyCssSourceOrderParts(parts) {
|
|
|
205
274
|
}
|
|
206
275
|
function resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorStyleOptions) {
|
|
207
276
|
const resolvedStyleOptions = require_context.resolveStyleOptionsFromContext(opts);
|
|
277
|
+
const scopedVueStyleSource = isVueScopedStyleSource(resolvePostcssFromOption(cssHandlerOptions));
|
|
208
278
|
const preflightStyleOptions = {
|
|
209
|
-
cssPreflight: resolvedStyleOptions.cssPreflight,
|
|
210
|
-
cssPreflightRange: resolvedStyleOptions.cssPreflightRange
|
|
279
|
+
cssPreflight: scopedVueStyleSource ? false : resolvedStyleOptions.cssPreflight,
|
|
280
|
+
cssPreflightRange: scopedVueStyleSource ? void 0 : resolvedStyleOptions.cssPreflightRange
|
|
211
281
|
};
|
|
212
282
|
return {
|
|
213
283
|
...resolvedStyleOptions,
|
|
@@ -828,8 +898,9 @@ function withGeneratorSourceMetadata(source, metadata) {
|
|
|
828
898
|
__weappTailwindcssMeta: metadata
|
|
829
899
|
};
|
|
830
900
|
}
|
|
831
|
-
function withMatchedSourceSideMetadata(source, resolvedEntrySource) {
|
|
901
|
+
function withMatchedSourceSideMetadata(source, resolvedEntrySource, metadata = {}) {
|
|
832
902
|
return resolvedEntrySource.file ? withGeneratorSourceMetadata(source, {
|
|
903
|
+
...metadata,
|
|
833
904
|
isolateCssSource: true,
|
|
834
905
|
matchedCssSourceFile: resolvedEntrySource.file,
|
|
835
906
|
sourceBase: resolvedEntrySource.base,
|
|
@@ -837,24 +908,6 @@ function withMatchedSourceSideMetadata(source, resolvedEntrySource) {
|
|
|
837
908
|
}) : source;
|
|
838
909
|
}
|
|
839
910
|
//#endregion
|
|
840
|
-
//#region src/bundlers/shared/generator-css/source-resolver/postcss-source.ts
|
|
841
|
-
function resolvePostcssFromOption(cssHandlerOptions) {
|
|
842
|
-
const from = cssHandlerOptions.postcssOptions?.options?.from;
|
|
843
|
-
return typeof from === "string" && from.length > 0 ? from : void 0;
|
|
844
|
-
}
|
|
845
|
-
function resolvePostcssSourceFile(cssHandlerOptions) {
|
|
846
|
-
const from = resolvePostcssFromOption(cssHandlerOptions);
|
|
847
|
-
if (!from || !node_path.default.isAbsolute(from)) return;
|
|
848
|
-
return from.replace(/[?#].*$/, "");
|
|
849
|
-
}
|
|
850
|
-
function resolveCssHandlerSourceOptions(cssHandlerOptions) {
|
|
851
|
-
return cssHandlerOptions.sourceOptions;
|
|
852
|
-
}
|
|
853
|
-
function resolveCssSourceBase(file, cssHandlerOptions) {
|
|
854
|
-
const normalized = (resolvePostcssFromOption(cssHandlerOptions) ?? file).replace(/[?#].*$/, "");
|
|
855
|
-
return node_path.default.dirname(node_path.default.resolve(normalized));
|
|
856
|
-
}
|
|
857
|
-
//#endregion
|
|
858
911
|
//#region src/bundlers/shared/generator-css/source-resolver.ts
|
|
859
912
|
function createCssEntrySources(cssEntries) {
|
|
860
913
|
return cssEntries?.filter((entry) => typeof entry === "string" && entry.length > 0 && node_path.default.isAbsolute(entry)).map((entry) => ({ file: node_path.default.resolve(entry) }));
|
|
@@ -888,11 +941,15 @@ function createSingleTailwindV4SourceOptions(sourceOptions, options) {
|
|
|
888
941
|
cssEntries: options.cssEntries
|
|
889
942
|
});
|
|
890
943
|
}
|
|
891
|
-
async function resolveTailwindV4CssEntrySource(cssEntry, sourceOptions) {
|
|
944
|
+
async function resolveTailwindV4CssEntrySource(cssEntry, sourceOptions, options = {}) {
|
|
892
945
|
const { cssEntries: _cssEntries, cssSources: _cssSources, ...singleEntrySourceOptions } = sourceOptions;
|
|
893
|
-
if (!(0, node_fs.existsSync)(cssEntry)) return require_v4_engine.resolveTailwindV4Source({
|
|
946
|
+
if (!(0, node_fs.existsSync)(cssEntry)) return withGeneratorSourceMetadata(await require_v4_engine.resolveTailwindV4Source({
|
|
894
947
|
...require_v4_engine.omitUndefined(singleEntrySourceOptions),
|
|
895
948
|
cssEntries: [cssEntry]
|
|
949
|
+
}), {
|
|
950
|
+
cssEntryIndex: options.index,
|
|
951
|
+
includesPreflight: options.includesPreflight,
|
|
952
|
+
primaryCssSource: options.index === 0
|
|
896
953
|
});
|
|
897
954
|
const css = (0, node_fs.readFileSync)(cssEntry, "utf8");
|
|
898
955
|
const base = node_path.default.dirname(node_path.default.resolve(cssEntry));
|
|
@@ -907,7 +964,10 @@ async function resolveTailwindV4CssEntrySource(cssEntry, sourceOptions) {
|
|
|
907
964
|
css: require_v4_engine.normalizeConfigDirective(css, config),
|
|
908
965
|
cssEntries: [cssEntry]
|
|
909
966
|
}), {
|
|
967
|
+
cssEntryIndex: options.index,
|
|
968
|
+
includesPreflight: options.includesPreflight,
|
|
910
969
|
matchedCssSourceFile: cssEntry,
|
|
970
|
+
primaryCssSource: options.index === 0,
|
|
911
971
|
sourceBase: base,
|
|
912
972
|
sourceCss: css
|
|
913
973
|
});
|
|
@@ -920,12 +980,15 @@ function canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) {
|
|
|
920
980
|
function shouldResolveSourceSideCssEntry(rawSource) {
|
|
921
981
|
return rawSource.includes("@apply") || require_v4_engine.hasTailwindRootDirectives(rawSource, { importFallback: true }) || require_v4_engine.hasTailwindSourceDirectives(rawSource, { importFallback: true }) || require_v4_engine.hasTailwindGeneratedCss(rawSource) || require_v4_engine.hasTailwindGeneratedCssMarkers(rawSource);
|
|
922
982
|
}
|
|
923
|
-
function resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) {
|
|
983
|
+
async function resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) {
|
|
924
984
|
const cssEntries = sourceOptions.cssEntries;
|
|
925
985
|
if (!cssEntries?.length) return;
|
|
926
986
|
const normalizedFile = node_path.default.resolve(file.replace(/[?#].*$/, ""));
|
|
927
987
|
const pathMatchedEntries = cssEntries.filter((cssEntry) => node_path.default.resolve(cssEntry.replace(/[?#].*$/, "")) === normalizedFile);
|
|
928
|
-
if (pathMatchedEntries.length === 1) return resolveTailwindV4CssEntrySource(pathMatchedEntries[0], sourceOptions
|
|
988
|
+
if (pathMatchedEntries.length === 1) return resolveTailwindV4CssEntrySource(pathMatchedEntries[0], sourceOptions, {
|
|
989
|
+
includesPreflight: await resolveTailwindV4CssEntryIncludesPreflight(pathMatchedEntries[0]),
|
|
990
|
+
index: cssEntries.indexOf(pathMatchedEntries[0])
|
|
991
|
+
});
|
|
929
992
|
const normalizedRawSource = normalizeCssSourceForCompare(rawSource);
|
|
930
993
|
const matches = cssEntries.map((cssEntry) => {
|
|
931
994
|
if (!(0, node_fs.existsSync)(cssEntry)) return;
|
|
@@ -944,7 +1007,10 @@ function resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) {
|
|
|
944
1007
|
const bestScore = matches[0]?.score;
|
|
945
1008
|
const matchingEntry = bestScore && matches.filter((match) => match.score === bestScore).length === 1 ? matches[0]?.cssEntry : void 0;
|
|
946
1009
|
if (!matchingEntry) return;
|
|
947
|
-
return resolveTailwindV4CssEntrySource(matchingEntry, sourceOptions
|
|
1010
|
+
return resolveTailwindV4CssEntrySource(matchingEntry, sourceOptions, {
|
|
1011
|
+
includesPreflight: await resolveTailwindV4CssEntryIncludesPreflight(matchingEntry),
|
|
1012
|
+
index: cssEntries.indexOf(matchingEntry)
|
|
1013
|
+
});
|
|
948
1014
|
}
|
|
949
1015
|
function normalizeTailwindV4CssSourceConfig(cssSource, sourceBase) {
|
|
950
1016
|
if (typeof cssSource.css !== "string" || cssSource.css.length === 0 || !cssSource.css.includes("@config")) return cssSource;
|
|
@@ -994,7 +1060,7 @@ function normalizeTailwindV4CssSourceConfigs(sourceOptions) {
|
|
|
994
1060
|
cssSources
|
|
995
1061
|
} : sourceOptions;
|
|
996
1062
|
}
|
|
997
|
-
async function resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions) {
|
|
1063
|
+
async function resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions, selectionOptions) {
|
|
998
1064
|
const cssSources = sourceOptions.cssSources;
|
|
999
1065
|
if (!cssSources?.length) return;
|
|
1000
1066
|
const normalizedRawSource = normalizeCssSourceForCompare(rawSource);
|
|
@@ -1015,7 +1081,12 @@ async function resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOpt
|
|
|
1015
1081
|
const bestScore = matches[0]?.score;
|
|
1016
1082
|
const matchingSource = bestScore && matches.filter((match) => match.score === bestScore).length === 1 ? matches[0]?.cssSource : void 0;
|
|
1017
1083
|
if (!matchingSource) return;
|
|
1018
|
-
return resolveSingleTailwindV4CssSource(matchingSource, sourceOptions, {
|
|
1084
|
+
return resolveSingleTailwindV4CssSource(matchingSource, sourceOptions, {
|
|
1085
|
+
includesPreflight: await resolveTailwindV4CssSourceEntries(matchingSource, sourceOptions).then((resolved) => resolved?.includesPreflight),
|
|
1086
|
+
index: matches[0]?.index,
|
|
1087
|
+
matched: true,
|
|
1088
|
+
primary: isSameTailwindV4CssSource(matchingSource, selectionOptions?.cssSources?.[0])
|
|
1089
|
+
});
|
|
1019
1090
|
}
|
|
1020
1091
|
function tryResolveTailwindV4SourceOptions(runtimeState) {
|
|
1021
1092
|
try {
|
|
@@ -1027,14 +1098,24 @@ function tryResolveTailwindV4SourceOptions(runtimeState) {
|
|
|
1027
1098
|
function hasConfiguredTailwindV4CssSource(sourceOptions) {
|
|
1028
1099
|
return Boolean(sourceOptions?.css) || Boolean(sourceOptions?.cssSources?.length);
|
|
1029
1100
|
}
|
|
1101
|
+
function isSameTailwindV4CssSource(a, b) {
|
|
1102
|
+
if (!a || !b) return false;
|
|
1103
|
+
if (typeof a.file === "string" && typeof b.file === "string") return node_path.default.resolve(a.file) === node_path.default.resolve(b.file);
|
|
1104
|
+
return typeof a.css === "string" && typeof b.css === "string" && normalizeCssSourceForCompare(a.css) === normalizeCssSourceForCompare(b.css);
|
|
1105
|
+
}
|
|
1030
1106
|
async function resolveSingleTailwindV4CssSource(cssSource, sourceOptions, options = {}) {
|
|
1031
1107
|
const sourceBase = require_v4_engine.resolveTailwindV4CssSourceBase(cssSource, sourceOptions.base ?? sourceOptions.projectRoot ?? node_process.default.cwd());
|
|
1032
1108
|
const normalizedCssSource = normalizeTailwindV4CssSourceConfig(cssSource, sourceBase);
|
|
1033
|
-
|
|
1109
|
+
const source = await require_v4_engine.resolveTailwindV4Source(createSingleTailwindV4SourceOptions(sourceOptions, {
|
|
1034
1110
|
base: sourceBase,
|
|
1035
1111
|
css: normalizedCssSource.css
|
|
1036
|
-
}))
|
|
1112
|
+
}));
|
|
1113
|
+
const resolvedEntries = options.includesPreflight === void 0 ? await resolveTailwindV4CssSourceEntries(normalizedCssSource, sourceOptions) : void 0;
|
|
1114
|
+
return withGeneratorSourceMetadata(source, {
|
|
1115
|
+
cssSourceIndex: options.index,
|
|
1116
|
+
includesPreflight: options.includesPreflight ?? resolvedEntries?.includesPreflight,
|
|
1037
1117
|
matchedCssSourceFile: options.matched && typeof normalizedCssSource.file === "string" ? normalizedCssSource.file : void 0,
|
|
1118
|
+
primaryCssSource: options.primary === true || !sourceOptions.cssEntries?.length && options.index === 0 || void 0,
|
|
1038
1119
|
sourceBase,
|
|
1039
1120
|
sourceCss: normalizedCssSource.css
|
|
1040
1121
|
});
|
|
@@ -1063,6 +1144,47 @@ async function resolveCandidateMatchedTailwindV4CssSource(_rawSource, _cssHandle
|
|
|
1063
1144
|
if (runtimeHits === 0) return;
|
|
1064
1145
|
matches.push({
|
|
1065
1146
|
cssSource,
|
|
1147
|
+
includesPreflight: resolved.includesPreflight,
|
|
1148
|
+
index,
|
|
1149
|
+
runtimeHits,
|
|
1150
|
+
totalCandidates: scopedCandidates.size
|
|
1151
|
+
});
|
|
1152
|
+
}));
|
|
1153
|
+
if (matches.length === 0) return;
|
|
1154
|
+
matches.sort((a, b) => b.runtimeHits - a.runtimeHits || b.totalCandidates - a.totalCandidates || a.index - b.index);
|
|
1155
|
+
const best = matches[0];
|
|
1156
|
+
const second = matches[1];
|
|
1157
|
+
if (!best) return;
|
|
1158
|
+
if (second && second.runtimeHits === best.runtimeHits && second.totalCandidates === best.totalCandidates) return;
|
|
1159
|
+
return resolveSingleTailwindV4CssSource(best.cssSource, sourceOptions, {
|
|
1160
|
+
includesPreflight: best.includesPreflight,
|
|
1161
|
+
index: best.index,
|
|
1162
|
+
matched: true,
|
|
1163
|
+
primary: isSameTailwindV4CssSource(best.cssSource, selectionOptions?.cssSources?.[0])
|
|
1164
|
+
});
|
|
1165
|
+
}
|
|
1166
|
+
async function resolveTailwindV4CssEntryEntries(cssEntry) {
|
|
1167
|
+
if (!(0, node_fs.existsSync)(cssEntry)) return;
|
|
1168
|
+
const file = node_path.default.resolve(cssEntry);
|
|
1169
|
+
return require_tailwindcss.resolveTailwindV4EntriesFromCss((0, node_fs.readFileSync)(file, "utf8"), node_path.default.dirname(file));
|
|
1170
|
+
}
|
|
1171
|
+
async function resolveTailwindV4CssEntryIncludesPreflight(cssEntry) {
|
|
1172
|
+
return resolveTailwindV4CssEntryEntries(cssEntry).then((resolved) => resolved?.includesPreflight);
|
|
1173
|
+
}
|
|
1174
|
+
async function resolveCandidateMatchedTailwindV4CssEntry(sourceOptions, selectionOptions) {
|
|
1175
|
+
const cssEntries = sourceOptions.cssEntries;
|
|
1176
|
+
const getSourceCandidatesForEntries = selectionOptions?.getSourceCandidatesForEntries;
|
|
1177
|
+
if (!cssEntries?.length || !getSourceCandidatesForEntries) return;
|
|
1178
|
+
const matches = [];
|
|
1179
|
+
await Promise.all(cssEntries.map(async (cssEntry, index) => {
|
|
1180
|
+
const resolved = await resolveTailwindV4CssEntryEntries(cssEntry);
|
|
1181
|
+
if (resolved?.entries === void 0) return;
|
|
1182
|
+
const scopedCandidates = getSourceCandidatesForEntries(resolved.entries);
|
|
1183
|
+
const runtimeHits = countRuntimeCandidateHits(scopedCandidates, selectionOptions?.runtime);
|
|
1184
|
+
if (runtimeHits === 0) return;
|
|
1185
|
+
matches.push({
|
|
1186
|
+
cssEntry,
|
|
1187
|
+
includesPreflight: resolved.includesPreflight,
|
|
1066
1188
|
index,
|
|
1067
1189
|
runtimeHits,
|
|
1068
1190
|
totalCandidates: scopedCandidates.size
|
|
@@ -1074,10 +1196,13 @@ async function resolveCandidateMatchedTailwindV4CssSource(_rawSource, _cssHandle
|
|
|
1074
1196
|
const second = matches[1];
|
|
1075
1197
|
if (!best) return;
|
|
1076
1198
|
if (second && second.runtimeHits === best.runtimeHits && second.totalCandidates === best.totalCandidates) return;
|
|
1077
|
-
return
|
|
1199
|
+
return resolveTailwindV4CssEntrySource(best.cssEntry, sourceOptions, {
|
|
1200
|
+
includesPreflight: best.includesPreflight,
|
|
1201
|
+
index: best.index
|
|
1202
|
+
});
|
|
1078
1203
|
}
|
|
1079
1204
|
function createTailwindV4CssSourceResolver(sourceOptions, generatorOptions) {
|
|
1080
|
-
return (cssSource) => resolveSingleTailwindV4CssSource(cssSource, sourceOptions).then((source) => generatorOptions?.config ? {
|
|
1205
|
+
return (cssSource, index) => resolveSingleTailwindV4CssSource(cssSource, sourceOptions, { index }).then((source) => generatorOptions?.config ? {
|
|
1081
1206
|
...source,
|
|
1082
1207
|
css: require_v4_engine.prependConfigDirective(source.css, generatorOptions.config)
|
|
1083
1208
|
} : source);
|
|
@@ -1090,11 +1215,19 @@ async function resolveTailwindV4SourceSideEntrySource(resolvedEntrySource, sourc
|
|
|
1090
1215
|
sourceFile: resolvedEntrySource.file
|
|
1091
1216
|
});
|
|
1092
1217
|
const css = createTailwindV4SourceReferenceSource(require_v4_engine.normalizeConfigDirective(require_v4_engine.prependConfigDirective(resolvedEntrySource.css, generatorOptions?.config), config), resolvedSourceOptions);
|
|
1093
|
-
|
|
1218
|
+
const source = await require_v4_engine.resolveTailwindV4Source(createSingleTailwindV4SourceOptions(resolvedSourceOptions, {
|
|
1094
1219
|
base: resolvedEntrySource.base,
|
|
1095
1220
|
css,
|
|
1096
1221
|
cssEntries: [resolvedEntrySource.file]
|
|
1097
|
-
}))
|
|
1222
|
+
}));
|
|
1223
|
+
const cssEntryIndex = sourceOptions.cssEntries?.findIndex((cssEntry) => typeof resolvedEntrySource.file === "string" && node_path.default.resolve(cssEntry.replace(/[?#].*$/, "")) === node_path.default.resolve(resolvedEntrySource.file));
|
|
1224
|
+
const cssSourceIndex = sourceOptions.cssSources?.findIndex((cssSource) => typeof cssSource.file === "string" && typeof resolvedEntrySource.file === "string" && node_path.default.resolve(cssSource.file.replace(/[?#].*$/, "")) === node_path.default.resolve(resolvedEntrySource.file));
|
|
1225
|
+
return withMatchedSourceSideMetadata(source, resolvedEntrySource, {
|
|
1226
|
+
cssEntryIndex,
|
|
1227
|
+
cssSourceIndex,
|
|
1228
|
+
includesPreflight: (await require_tailwindcss.resolveTailwindV4EntriesFromCss(resolvedEntrySource.css, resolvedEntrySource.base))?.includesPreflight,
|
|
1229
|
+
primaryCssSource: cssEntryIndex === 0 || !sourceOptions.cssEntries?.length && cssSourceIndex === 0
|
|
1230
|
+
});
|
|
1098
1231
|
}
|
|
1099
1232
|
async function resolveGeneratorSource(_majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions) {
|
|
1100
1233
|
const base = resolveCssSourceBase(file, cssHandlerOptions);
|
|
@@ -1112,7 +1245,7 @@ async function resolveGeneratorSource(_majorVersion, runtimeState, rawSource, fi
|
|
|
1112
1245
|
sourceFile: sourceOptions.sourceFile ?? resolvePostcssSourceFile(cssHandlerOptions),
|
|
1113
1246
|
...resolveCssHandlerSourceOptions(cssHandlerOptions),
|
|
1114
1247
|
cssEntries: selectionOptions?.cssEntries ?? sourceOptions.cssEntries,
|
|
1115
|
-
cssSources: mergeCssSources(sourceOptions.cssSources, sourceOptions.cssSources?.length ? void 0 : createCssEntrySources(selectionOptions?.cssEntries ?? sourceOptions.cssEntries))
|
|
1248
|
+
cssSources: mergeCssSources(mergeCssSources(sourceOptions.cssSources, selectionOptions?.cssSources), sourceOptions.cssSources?.length || selectionOptions?.cssSources?.length ? void 0 : createCssEntrySources(selectionOptions?.cssEntries ?? sourceOptions.cssEntries))
|
|
1116
1249
|
}) : void 0;
|
|
1117
1250
|
const normalizedSourceOptions = resolvedSourceOptions ? normalizeTailwindV4CssSourceConfigs(resolvedSourceOptions) : void 0;
|
|
1118
1251
|
if (applyEntrySource && !cssHandlerOptions.isMainChunk && !require_v4_engine.hasTailwindRootDirectives(rawSource, { importFallback: generatorOptions?.importFallback ?? false })) {
|
|
@@ -1127,16 +1260,20 @@ async function resolveGeneratorSource(_majorVersion, runtimeState, rawSource, fi
|
|
|
1127
1260
|
const sourceSideCssSource = sourceSideEntrySource?.file && normalizedSourceOptions.cssEntries?.some((cssEntry) => node_path.default.resolve(cssEntry.replace(/[?#].*$/, "")) === node_path.default.resolve(sourceSideEntrySource.file)) ? await resolveTailwindV4SourceSideEntrySource(sourceSideEntrySource, normalizedSourceOptions, generatorOptions, file) : void 0;
|
|
1128
1261
|
if (sourceSideCssSource) return sourceSideCssSource;
|
|
1129
1262
|
const matchedCssEntrySource = normalizedSourceOptions ? await resolveMatchingTailwindV4CssEntry(rawSource, file, normalizedSourceOptions) : void 0;
|
|
1130
|
-
const matchedCssSource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, normalizedSourceOptions) : void 0;
|
|
1263
|
+
const matchedCssSource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, normalizedSourceOptions, selectionOptions) : void 0;
|
|
1264
|
+
const candidateMatchedCssEntrySource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveCandidateMatchedTailwindV4CssEntry(normalizedSourceOptions, selectionOptions) : void 0;
|
|
1131
1265
|
const candidateMatchedCssSource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, normalizedSourceOptions, selectionOptions) : void 0;
|
|
1132
|
-
const singleConfiguredCssSource = normalizedSourceOptions?.cssSources?.length === 1 ? await resolveSingleTailwindV4CssSource(normalizedSourceOptions.cssSources[0], normalizedSourceOptions, {
|
|
1266
|
+
const singleConfiguredCssSource = normalizedSourceOptions?.cssSources?.length === 1 ? await resolveSingleTailwindV4CssSource(normalizedSourceOptions.cssSources[0], normalizedSourceOptions, {
|
|
1267
|
+
index: 0,
|
|
1268
|
+
matched: true
|
|
1269
|
+
}) : void 0;
|
|
1133
1270
|
const configuredCssSource = normalizedSourceOptions && hasConfiguredTailwindV4CssSource(normalizedSourceOptions) && require_v4_engine.hasTailwindGeneratedCssMarkers(rawSource) ? matchedCssSource ?? candidateMatchedCssSource ?? singleConfiguredCssSource ?? await require_v4_engine.resolveTailwindV4Source(normalizedSourceOptions) : void 0;
|
|
1134
1271
|
if (configuredCssSource) return generatorOptions?.config ? {
|
|
1135
1272
|
...configuredCssSource,
|
|
1136
1273
|
css: require_v4_engine.prependConfigDirective(configuredCssSource.css, generatorOptions.config)
|
|
1137
1274
|
} : configuredCssSource;
|
|
1138
1275
|
const mainCssEntrySource = normalizedSourceOptions && cssHandlerOptions.isMainChunk && normalizedSourceOptions.cssEntries?.length === 1 ? await resolveTailwindV4CssEntrySource(normalizedSourceOptions.cssEntries[0], normalizedSourceOptions) : void 0;
|
|
1139
|
-
const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource ?? mainCssEntrySource ?? singleConfiguredCssSource;
|
|
1276
|
+
const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssEntrySource ?? candidateMatchedCssSource ?? mainCssEntrySource ?? singleConfiguredCssSource;
|
|
1140
1277
|
if (preferredCssEntrySource) return generatorOptions?.config ? {
|
|
1141
1278
|
...preferredCssEntrySource,
|
|
1142
1279
|
css: require_v4_engine.prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
|
|
@@ -1192,19 +1329,20 @@ async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, fi
|
|
|
1192
1329
|
} : matchedCssEntrySource, matchedCssEntrySource.__weappTailwindcssMeta?.matchedCssSourceFile, sourceOptions)];
|
|
1193
1330
|
const sourceSideCssSource = await resolveTailwindV4SourceSideEntrySource(canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) ? resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: false }) : void 0, sourceOptions, generatorOptions, file);
|
|
1194
1331
|
if (sourceSideCssSource) return [sourceSideCssSource];
|
|
1195
|
-
const matchedCssSource = await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions);
|
|
1332
|
+
const matchedCssSource = await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions, selectionOptions);
|
|
1333
|
+
const candidateMatchedCssEntrySource = await resolveCandidateMatchedTailwindV4CssEntry(sourceOptions, selectionOptions);
|
|
1196
1334
|
const candidateMatchedCssSource = await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, sourceOptions, selectionOptions);
|
|
1197
|
-
const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource;
|
|
1335
|
+
const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssEntrySource ?? candidateMatchedCssSource;
|
|
1198
1336
|
if (preferredCssEntrySource) return [normalizeResolvedTailwindV4SourceConfig(generatorOptions?.config ? {
|
|
1199
1337
|
...preferredCssEntrySource,
|
|
1200
1338
|
css: require_v4_engine.prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
|
|
1201
1339
|
} : preferredCssEntrySource, preferredCssEntrySource.__weappTailwindcssMeta?.matchedCssSourceFile, sourceOptions)];
|
|
1202
1340
|
if (!sourceOptions.cssEntries || sourceOptions.cssEntries.length <= 1) {
|
|
1203
|
-
if (cssHandlerOptions.isMainChunk && sourceOptions.cssEntries?.length === 1) return [await resolveTailwindV4CssEntrySource(sourceOptions.cssEntries[0], normalizeTailwindV4CssSourceConfigs(sourceOptions)).then((source) => generatorOptions?.config ? {
|
|
1341
|
+
if (cssHandlerOptions.isMainChunk && sourceOptions.cssEntries?.length === 1) return [await resolveTailwindV4CssEntrySource(sourceOptions.cssEntries[0], normalizeTailwindV4CssSourceConfigs(sourceOptions), { index: 0 }).then((source) => generatorOptions?.config ? {
|
|
1204
1342
|
...source,
|
|
1205
1343
|
css: require_v4_engine.prependConfigDirective(source.css, generatorOptions.config)
|
|
1206
1344
|
} : source)];
|
|
1207
|
-
if (sourceOptions.cssSources?.length === 1) return [normalizeResolvedTailwindV4SourceConfig(await createTailwindV4CssSourceResolver(sourceOptions, generatorOptions)(sourceOptions.cssSources[0]), sourceOptions.cssSources[0]?.file, sourceOptions)];
|
|
1345
|
+
if (sourceOptions.cssSources?.length === 1) return [normalizeResolvedTailwindV4SourceConfig(await createTailwindV4CssSourceResolver(sourceOptions, generatorOptions)(sourceOptions.cssSources[0], 0), sourceOptions.cssSources[0]?.file, sourceOptions)];
|
|
1208
1346
|
const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
|
|
1209
1347
|
return resolved ? [resolved] : [];
|
|
1210
1348
|
}
|
|
@@ -1213,7 +1351,7 @@ async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, fi
|
|
|
1213
1351
|
return resolved ? [resolved] : [];
|
|
1214
1352
|
}
|
|
1215
1353
|
const normalizedCssSourceOptions = normalizeTailwindV4CssSourceConfigs(sourceOptions);
|
|
1216
|
-
const cssEntrySources = await Promise.all(sourceOptions.cssEntries.map((cssEntry) => resolveTailwindV4CssEntrySource(cssEntry, normalizedCssSourceOptions).then((source) => generatorOptions?.config ? {
|
|
1354
|
+
const cssEntrySources = await Promise.all(sourceOptions.cssEntries.map((cssEntry, index) => resolveTailwindV4CssEntrySource(cssEntry, normalizedCssSourceOptions, { index }).then((source) => generatorOptions?.config ? {
|
|
1217
1355
|
...source,
|
|
1218
1356
|
css: require_v4_engine.prependConfigDirective(source.css, generatorOptions.config)
|
|
1219
1357
|
} : source)));
|
|
@@ -2003,133 +2141,6 @@ function inheritLegacyUnitConvertedDeclarations(css, legacyCss) {
|
|
|
2003
2141
|
}
|
|
2004
2142
|
}
|
|
2005
2143
|
//#endregion
|
|
2006
|
-
//#region src/bundlers/shared/generator-css/local-imports.ts
|
|
2007
|
-
const REMOTE_IMPORT_RE = /^(?:https?:)?\/\//i;
|
|
2008
|
-
const CSS_STYLE_EXTENSION_RE = /\.(?:css|wxss|acss|ttss|qss|jxss|tyss|scss|sass|less|styl|stylus|pcss|postcss)(?:$|[?#])/i;
|
|
2009
|
-
const SOURCE_STYLE_EXTENSION_RE = /\.(?:css|scss|sass|less|styl|stylus|pcss|postcss)(?:$|[?#])/i;
|
|
2010
|
-
function createCssSourceOrderAppend(base, extra) {
|
|
2011
|
-
if (!base) return extra;
|
|
2012
|
-
if (!extra) return base;
|
|
2013
|
-
if (/\s$/.test(base) || /^\s/.test(extra)) return `${base}${extra}`;
|
|
2014
|
-
return `${base}\n${extra}`;
|
|
2015
|
-
}
|
|
2016
|
-
function isLocalImportRequest(request) {
|
|
2017
|
-
return request.length > 0 && !request.startsWith("#") && !request.startsWith("tailwindcss") && !request.startsWith("weapp-tailwindcss") && !request.startsWith("data:") && !REMOTE_IMPORT_RE.test(request);
|
|
2018
|
-
}
|
|
2019
|
-
function isPureLocalCssImportWrapper(css) {
|
|
2020
|
-
let hasImport = false;
|
|
2021
|
-
try {
|
|
2022
|
-
const root = _weapp_tailwindcss_postcss.postcss.parse(css);
|
|
2023
|
-
for (const node of root.nodes) {
|
|
2024
|
-
if (node.type === "comment") continue;
|
|
2025
|
-
if (node.type !== "atrule" || node.name !== "import") return false;
|
|
2026
|
-
const request = require_v4_engine.parseImportRequest(node.params);
|
|
2027
|
-
if (!request || !isLocalImportRequest(request)) return false;
|
|
2028
|
-
hasImport = true;
|
|
2029
|
-
}
|
|
2030
|
-
} catch {
|
|
2031
|
-
return false;
|
|
2032
|
-
}
|
|
2033
|
-
return hasImport;
|
|
2034
|
-
}
|
|
2035
|
-
function cleanLocalCssImportWrapperTailwindDirectives(css) {
|
|
2036
|
-
let hasLocalImport = false;
|
|
2037
|
-
let hasTailwindDirective = false;
|
|
2038
|
-
try {
|
|
2039
|
-
const root = _weapp_tailwindcss_postcss.postcss.parse(css);
|
|
2040
|
-
for (const node of root.nodes) {
|
|
2041
|
-
if (node.type === "comment") continue;
|
|
2042
|
-
if (node.type === "atrule" && node.name === "import") {
|
|
2043
|
-
const request = require_v4_engine.parseImportRequest(node.params);
|
|
2044
|
-
if (!request || !isLocalImportRequest(request)) return;
|
|
2045
|
-
hasLocalImport = true;
|
|
2046
|
-
continue;
|
|
2047
|
-
}
|
|
2048
|
-
if (node.type === "atrule" && node.name === "source") {
|
|
2049
|
-
hasTailwindDirective = true;
|
|
2050
|
-
continue;
|
|
2051
|
-
}
|
|
2052
|
-
return;
|
|
2053
|
-
}
|
|
2054
|
-
} catch {
|
|
2055
|
-
return;
|
|
2056
|
-
}
|
|
2057
|
-
return hasLocalImport && hasTailwindDirective ? prefixLocalCssImportsWithWebpackIgnore(require_v4_engine.removeTailwindSourceDirectives(css)) : void 0;
|
|
2058
|
-
}
|
|
2059
|
-
function prefixLocalCssImportsWithWebpackIgnore(css) {
|
|
2060
|
-
try {
|
|
2061
|
-
const root = _weapp_tailwindcss_postcss.postcss.parse(css);
|
|
2062
|
-
root.walkAtRules("import", (atRule) => {
|
|
2063
|
-
const request = require_v4_engine.parseImportRequest(atRule.params);
|
|
2064
|
-
if (request && isLocalImportRequest(request)) atRule.raws.before = `${atRule.raws.before ?? ""}/* webpackIgnore: true */\n`;
|
|
2065
|
-
});
|
|
2066
|
-
return root.toString();
|
|
2067
|
-
} catch {
|
|
2068
|
-
return css;
|
|
2069
|
-
}
|
|
2070
|
-
}
|
|
2071
|
-
function splitLocalCssImports(source) {
|
|
2072
|
-
try {
|
|
2073
|
-
const root = _weapp_tailwindcss_postcss.postcss.parse(source);
|
|
2074
|
-
const importRoot = _weapp_tailwindcss_postcss.postcss.root();
|
|
2075
|
-
let changed = false;
|
|
2076
|
-
for (const node of [...root.nodes]) {
|
|
2077
|
-
if (node.type !== "atrule" || node.name !== "import") continue;
|
|
2078
|
-
const request = require_v4_engine.parseImportRequest(node.params);
|
|
2079
|
-
if (!request || !isLocalImportRequest(request)) continue;
|
|
2080
|
-
importRoot.append(node.clone());
|
|
2081
|
-
node.remove();
|
|
2082
|
-
changed = true;
|
|
2083
|
-
}
|
|
2084
|
-
const imports = importRoot.nodes.filter((node) => node.type === "atrule" && node.name === "import").map((node) => `@import ${node.params};`).join("\n");
|
|
2085
|
-
return changed ? {
|
|
2086
|
-
imports,
|
|
2087
|
-
source: root.toString()
|
|
2088
|
-
} : void 0;
|
|
2089
|
-
} catch {
|
|
2090
|
-
return;
|
|
2091
|
-
}
|
|
2092
|
-
}
|
|
2093
|
-
function restoreLocalCssImports(css, imports) {
|
|
2094
|
-
if (!imports?.trim()) return css;
|
|
2095
|
-
return createCssSourceOrderAppend(imports, css);
|
|
2096
|
-
}
|
|
2097
|
-
function splitRequestSuffix(request) {
|
|
2098
|
-
const suffixIndexCandidates = [request.indexOf("?"), request.indexOf("#")].filter((index) => index >= 0);
|
|
2099
|
-
const suffixIndex = suffixIndexCandidates.length > 0 ? Math.min(...suffixIndexCandidates) : -1;
|
|
2100
|
-
if (suffixIndex < 0) return {
|
|
2101
|
-
clean: request,
|
|
2102
|
-
suffix: ""
|
|
2103
|
-
};
|
|
2104
|
-
return {
|
|
2105
|
-
clean: request.slice(0, suffixIndex),
|
|
2106
|
-
suffix: request.slice(suffixIndex)
|
|
2107
|
-
};
|
|
2108
|
-
}
|
|
2109
|
-
function normalizeOutputImportRequest(request, styleOutputExtension) {
|
|
2110
|
-
const normalizedStyleOutputExtension = styleOutputExtension?.startsWith(".") ? styleOutputExtension : styleOutputExtension ? `.${styleOutputExtension}` : void 0;
|
|
2111
|
-
const { clean, suffix } = splitRequestSuffix(request.replace(/\\/g, "/"));
|
|
2112
|
-
return `${clean.replace(/^(?:\.\/)?src\//, "./").replace(SOURCE_STYLE_EXTENSION_RE, normalizedStyleOutputExtension ?? ".css")}${suffix}`;
|
|
2113
|
-
}
|
|
2114
|
-
function rewriteLocalCssImportRequestsForOutput(css, options = {}) {
|
|
2115
|
-
if (!css.includes("@import")) return css;
|
|
2116
|
-
try {
|
|
2117
|
-
const root = _weapp_tailwindcss_postcss.postcss.parse(css);
|
|
2118
|
-
let changed = false;
|
|
2119
|
-
root.walkAtRules("import", (atRule) => {
|
|
2120
|
-
const request = require_v4_engine.parseImportRequest(atRule.params);
|
|
2121
|
-
if (!request || !isLocalImportRequest(request) || !CSS_STYLE_EXTENSION_RE.test(request)) return;
|
|
2122
|
-
const rewritten = normalizeOutputImportRequest(request, options.styleOutputExtension);
|
|
2123
|
-
if (rewritten === request) return;
|
|
2124
|
-
atRule.params = atRule.params.replace(request, rewritten);
|
|
2125
|
-
changed = true;
|
|
2126
|
-
});
|
|
2127
|
-
return changed ? root.toString() : css;
|
|
2128
|
-
} catch {
|
|
2129
|
-
return css;
|
|
2130
|
-
}
|
|
2131
|
-
}
|
|
2132
|
-
//#endregion
|
|
2133
2144
|
//#region src/bundlers/shared/generator-css/user-layer-order.ts
|
|
2134
2145
|
const USER_LAYER_COMPONENTS_START = "/*! weapp-tailwindcss layer components start */";
|
|
2135
2146
|
const USER_LAYER_COMPONENTS_END = "/*! weapp-tailwindcss layer components end */";
|
|
@@ -2327,6 +2338,23 @@ function intersectCandidateSets(left, right) {
|
|
|
2327
2338
|
for (const candidate of small) if (large.has(candidate)) matched.add(candidate);
|
|
2328
2339
|
return matched;
|
|
2329
2340
|
}
|
|
2341
|
+
function parseCssSourceRoot(rawSource) {
|
|
2342
|
+
try {
|
|
2343
|
+
return _weapp_tailwindcss_postcss.postcss.parse(rawSource);
|
|
2344
|
+
} catch {
|
|
2345
|
+
return;
|
|
2346
|
+
}
|
|
2347
|
+
}
|
|
2348
|
+
function cleanLocalCssImportWrapperFromParsedRoot(rawSource, root) {
|
|
2349
|
+
if (!root) return (0, _weapp_tailwindcss_postcss.cleanLocalCssImportWrapperTailwindDirectives)(rawSource);
|
|
2350
|
+
return (0, _weapp_tailwindcss_postcss.cleanLocalCssImportWrapperTailwindDirectivesRoot)(root) ? root.toString() : void 0;
|
|
2351
|
+
}
|
|
2352
|
+
function isPureLocalCssImportWrapperFromParsedRoot(rawSource, root) {
|
|
2353
|
+
return root ? (0, _weapp_tailwindcss_postcss.isPureLocalCssImportWrapperRoot)(root) : (0, _weapp_tailwindcss_postcss.isPureLocalCssImportWrapper)(rawSource);
|
|
2354
|
+
}
|
|
2355
|
+
function splitLocalCssImportsFromParsedRoot(rawSource, root) {
|
|
2356
|
+
return root ? (0, _weapp_tailwindcss_postcss.splitLocalCssImportsRoot)(root) : (0, _weapp_tailwindcss_postcss.splitLocalCssImports)(rawSource);
|
|
2357
|
+
}
|
|
2330
2358
|
function collectCssRuleIdentityMarkers(source) {
|
|
2331
2359
|
const markers = /* @__PURE__ */ new Set();
|
|
2332
2360
|
try {
|
|
@@ -2375,20 +2403,8 @@ async function generateCssByGenerator(options) {
|
|
|
2375
2403
|
const majorVersion = runtimeState.tailwindRuntime.majorVersion;
|
|
2376
2404
|
if (majorVersion !== 4) throw new Error("weapp-tailwindcss 生成管线仅支持 Tailwind CSS v4。");
|
|
2377
2405
|
const effectiveRawSource = stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(require_v4_engine.normalizeTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })));
|
|
2378
|
-
const
|
|
2379
|
-
const
|
|
2380
|
-
const finalizeGeneratorCss = (css, target, finalizeOptions = {}) => {
|
|
2381
|
-
return finalizeWebGeneratorCss(restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, target, majorVersion, opts.cssPreflight, finalizeOptions), localImports), target, generatorOptions.webCompat);
|
|
2382
|
-
};
|
|
2383
|
-
const generatorRawSource = localImportParts?.source ?? effectiveRawSource;
|
|
2384
|
-
const rawUserSource = userRawSource === void 0 ? generatorRawSource : userRawSourceProcessed ? userRawSource : stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(require_v4_engine.normalizeTailwindSourceDirectives(userRawSource, { importFallback: generatorOptions.importFallback })));
|
|
2385
|
-
const userSource = splitLocalCssImports(rawUserSource)?.source ?? rawUserSource;
|
|
2386
|
-
const userCssRawSource = removeTailwindV4GeneratorAtRules(userSource);
|
|
2387
|
-
const generatedUserCssOrderSource = require_v4_engine.hasTailwindGeneratedCss(userSource) ? require_v4_engine.splitTailwindV4GeneratedCssBySourceOrder(userSource, generatorRawSource) : void 0;
|
|
2388
|
-
const generatedUserCssRawSource = generatedUserCssOrderSource ? require_v4_engine.createCssAppend(generatedUserCssOrderSource.before, generatedUserCssOrderSource.after) : require_v4_engine.hasTailwindGeneratedCss(userSource) ? "" : userCssRawSource;
|
|
2389
|
-
const userCssOrderSource = require_v4_engine.GENERATOR_PLACEHOLDER_MARKER_RE.test(userSource) ? userSource : require_v4_engine.hasTailwindGeneratedCss(userSource) ? userSource : generatedUserCssRawSource;
|
|
2390
|
-
const hasDistinctUserRawSource = typeof userRawSource === "string" && normalizeCssSourceForCompare(generatedUserCssRawSource) !== normalizeCssSourceForCompare(generatorRawSource);
|
|
2391
|
-
const cleanedLocalImportWrapper = cleanLocalCssImportWrapperTailwindDirectives(effectiveRawSource);
|
|
2406
|
+
const effectiveRawSourceRoot = parseCssSourceRoot(effectiveRawSource);
|
|
2407
|
+
const cleanedLocalImportWrapper = cleanLocalCssImportWrapperFromParsedRoot(effectiveRawSource, effectiveRawSourceRoot);
|
|
2392
2408
|
if (cleanedLocalImportWrapper !== void 0) return {
|
|
2393
2409
|
css: require_generator.shouldUseMiniProgramCssBranch(generatorBranch) ? (0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(cleanedLocalImportWrapper) : cleanedLocalImportWrapper,
|
|
2394
2410
|
classSet: /* @__PURE__ */ new Set(),
|
|
@@ -2400,7 +2416,20 @@ async function generateCssByGenerator(options) {
|
|
|
2400
2416
|
majorVersion
|
|
2401
2417
|
}
|
|
2402
2418
|
};
|
|
2403
|
-
if (
|
|
2419
|
+
if (isPureLocalCssImportWrapperFromParsedRoot(effectiveRawSource, effectiveRawSourceRoot)) return;
|
|
2420
|
+
const localImportParts = splitLocalCssImportsFromParsedRoot(effectiveRawSource, effectiveRawSourceRoot);
|
|
2421
|
+
const localImports = options.restoreLocalCssImports === false ? void 0 : localImportParts?.imports;
|
|
2422
|
+
const finalizeGeneratorCss = (css, target, finalizeOptions = {}) => {
|
|
2423
|
+
return finalizeWebGeneratorCss((0, _weapp_tailwindcss_postcss.restoreLocalCssImports)(finalizeMiniProgramGeneratorCss(css, target, majorVersion, opts.cssPreflight, finalizeOptions), localImports), target, generatorOptions.webCompat);
|
|
2424
|
+
};
|
|
2425
|
+
const generatorRawSource = localImportParts?.source ?? effectiveRawSource;
|
|
2426
|
+
const rawUserSource = userRawSource === void 0 ? generatorRawSource : userRawSourceProcessed ? userRawSource : stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(require_v4_engine.normalizeTailwindSourceDirectives(userRawSource, { importFallback: generatorOptions.importFallback })));
|
|
2427
|
+
const userSource = (rawUserSource === generatorRawSource ? void 0 : (0, _weapp_tailwindcss_postcss.splitLocalCssImports)(rawUserSource))?.source ?? rawUserSource;
|
|
2428
|
+
const userCssRawSource = removeTailwindV4GeneratorAtRules(userSource);
|
|
2429
|
+
const generatedUserCssOrderSource = require_v4_engine.hasTailwindGeneratedCss(userSource) ? require_v4_engine.splitTailwindV4GeneratedCssBySourceOrder(userSource, generatorRawSource) : void 0;
|
|
2430
|
+
const generatedUserCssRawSource = generatedUserCssOrderSource ? require_v4_engine.createCssAppend(generatedUserCssOrderSource.before, generatedUserCssOrderSource.after) : require_v4_engine.hasTailwindGeneratedCss(userSource) ? "" : userCssRawSource;
|
|
2431
|
+
const userCssOrderSource = require_v4_engine.GENERATOR_PLACEHOLDER_MARKER_RE.test(userSource) ? userSource : require_v4_engine.hasTailwindGeneratedCss(userSource) ? userSource : generatedUserCssRawSource;
|
|
2432
|
+
const hasDistinctUserRawSource = typeof userRawSource === "string" && normalizeCssSourceForCompare(generatedUserCssRawSource) !== normalizeCssSourceForCompare(generatorRawSource);
|
|
2404
2433
|
const hasGeneratedCss = require_v4_engine.hasTailwindGeneratedCss(generatorRawSource);
|
|
2405
2434
|
const hasSourceDirectives = require_v4_engine.hasTailwindSourceDirectives(generatorRawSource, { importFallback: generatorOptions.importFallback });
|
|
2406
2435
|
const hasGeneratedMarkers = require_v4_engine.hasTailwindGeneratedCssMarkers(generatorRawSource);
|
|
@@ -2424,7 +2453,7 @@ async function generateCssByGenerator(options) {
|
|
|
2424
2453
|
});
|
|
2425
2454
|
const runtimeWithCurrentCss = createRuntimeWithCurrentCssCandidates(runtime, currentCssCandidates, isolateCurrentCssCandidates);
|
|
2426
2455
|
const sources = await resolveGeneratorSources(majorVersion, runtimeState, generatorRawSource, file, cssHandlerOptions, generatorOptions, {
|
|
2427
|
-
cssEntries: opts.cssEntries,
|
|
2456
|
+
cssEntries: cssHandlerOptions.sourceOptions?.cssEntries ?? opts.cssEntries,
|
|
2428
2457
|
cssSources: options.cssSources,
|
|
2429
2458
|
getSourceCandidatesForEntries,
|
|
2430
2459
|
runtime: runtimeWithCurrentCss
|
|
@@ -2468,7 +2497,7 @@ async function generateCssByGenerator(options) {
|
|
|
2468
2497
|
debug("tailwind generator result: %s rawBytes=%d cssBytes=%d candidates=%d", file, generated.rawCss.length, generated.css.length, generated.classSet.size);
|
|
2469
2498
|
if ((generated.target !== "weapp" || !hasUserCssLayerBlocks(generatorRawSource)) && typeof options.previousCss === "string" && typeof generated.incrementalCss === "string") {
|
|
2470
2499
|
const incrementalCss = require_v4_engine.stripTailwindBanner(generated.incrementalCss);
|
|
2471
|
-
const finalCss = finalizeWebGeneratorCss(restoreLocalCssImports(incrementalCss.trim().length > 0 ? require_v4_engine.createCssAppend(options.previousCss, finalizeMiniProgramGeneratorCss(incrementalCss, generated.target, majorVersion, opts.cssPreflight, {
|
|
2500
|
+
const finalCss = finalizeWebGeneratorCss((0, _weapp_tailwindcss_postcss.restoreLocalCssImports)(incrementalCss.trim().length > 0 ? require_v4_engine.createCssAppend(options.previousCss, finalizeMiniProgramGeneratorCss(incrementalCss, generated.target, majorVersion, opts.cssPreflight, {
|
|
2472
2501
|
injectPreflight: false,
|
|
2473
2502
|
styleOptions: generatorStyleOptions
|
|
2474
2503
|
})) : options.previousCss, localImports), generated.target, generatorOptions.webCompat);
|
|
@@ -2493,6 +2522,19 @@ async function generateCssByGenerator(options) {
|
|
|
2493
2522
|
const generatedCssSource = generated.target === "web" ? generated.css : require_v4_engine.stripTailwindBanner(generated.css);
|
|
2494
2523
|
const generatedCss = shouldFilterApplyOnlyCss ? filterApplyOnlyGeneratedCss(generatedCssSource, generatorRawSource) : generatedCssSource;
|
|
2495
2524
|
const hasMatchedCssSourceFile = sources.some((source) => source.__weappTailwindcssMeta?.matchedCssSourceFile);
|
|
2525
|
+
const hasExplicitCssSource = sources.some((source) => {
|
|
2526
|
+
const metadata = source.__weappTailwindcssMeta;
|
|
2527
|
+
return metadata?.cssEntryIndex !== void 0 || metadata?.cssSourceIndex !== void 0;
|
|
2528
|
+
});
|
|
2529
|
+
const hasPreflightCssSource = sources.some((source) => source.__weappTailwindcssMeta?.includesPreflight === true);
|
|
2530
|
+
const hasPreflightRawSource = require_tailwindcss.includesTailwindV4PreflightDirective(generatorRawSource);
|
|
2531
|
+
const preflightMode = resolveMiniProgramPreflightModeForGeneratorCss(opts, {
|
|
2532
|
+
cssHandlerOptions,
|
|
2533
|
+
isolateCurrentCssCandidates,
|
|
2534
|
+
localImports,
|
|
2535
|
+
explicitCssSource: hasExplicitCssSource,
|
|
2536
|
+
primaryCssSource: sources.length > 0 && sources.every((source) => source.__weappTailwindcssMeta?.primaryCssSource === true) || hasPreflightCssSource || hasPreflightRawSource
|
|
2537
|
+
});
|
|
2496
2538
|
const orderedExtraCss = require_v4_engine.splitGeneratorPlaceholderCssBySourceOrder(userCssOrderSource, generated.rawCss) ?? (hasMatchedCssSourceFile ? require_v4_engine.splitTailwindV4GeneratedCssBySourceOrder(userCssOrderSource, generated.rawCss) : splitRawSourceByGeneratedCssOrder(userCssOrderSource, generated.rawCss));
|
|
2497
2539
|
const shouldAppendMatchedCssSourceCompat = !hasMatchedCssSourceFile || orderedExtraCss !== void 0;
|
|
2498
2540
|
if (orderedExtraCss) {
|
|
@@ -2540,11 +2582,8 @@ async function generateCssByGenerator(options) {
|
|
|
2540
2582
|
}
|
|
2541
2583
|
} else if (generated.target === "weapp" && shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
|
|
2542
2584
|
const finalCss = finalizeGeneratorCss(css, generated.target, {
|
|
2543
|
-
injectPreflight:
|
|
2544
|
-
|
|
2545
|
-
isolateCurrentCssCandidates,
|
|
2546
|
-
localImports
|
|
2547
|
-
}),
|
|
2585
|
+
injectPreflight: preflightMode.inject,
|
|
2586
|
+
preservePreflight: preflightMode.preserve,
|
|
2548
2587
|
styleOptions: generatorStyleOptions
|
|
2549
2588
|
});
|
|
2550
2589
|
return {
|
|
@@ -2648,11 +2687,8 @@ async function generateCssByGenerator(options) {
|
|
|
2648
2687
|
css = createCssSourceOrderAppend$1(css, missingUserCss);
|
|
2649
2688
|
}
|
|
2650
2689
|
const finalCss = finalizeGeneratorCss(css, generated.target, {
|
|
2651
|
-
injectPreflight:
|
|
2652
|
-
|
|
2653
|
-
isolateCurrentCssCandidates,
|
|
2654
|
-
localImports
|
|
2655
|
-
}),
|
|
2690
|
+
injectPreflight: preflightMode.inject,
|
|
2691
|
+
preservePreflight: preflightMode.preserve,
|
|
2656
2692
|
styleOptions: generatorStyleOptions
|
|
2657
2693
|
});
|
|
2658
2694
|
return {
|
|
@@ -2685,11 +2721,8 @@ async function generateCssByGenerator(options) {
|
|
|
2685
2721
|
css = createCssSourceOrderAppend$1(css, missingUserCss);
|
|
2686
2722
|
}
|
|
2687
2723
|
const finalCss = finalizeGeneratorCss(css, generated.target, {
|
|
2688
|
-
injectPreflight:
|
|
2689
|
-
|
|
2690
|
-
isolateCurrentCssCandidates,
|
|
2691
|
-
localImports
|
|
2692
|
-
}),
|
|
2724
|
+
injectPreflight: preflightMode.inject,
|
|
2725
|
+
preservePreflight: preflightMode.preserve,
|
|
2693
2726
|
styleOptions: generatorStyleOptions
|
|
2694
2727
|
});
|
|
2695
2728
|
return {
|
|
@@ -3618,12 +3651,6 @@ Object.defineProperty(exports, "isCssSourceTraceEnabled", {
|
|
|
3618
3651
|
return isCssSourceTraceEnabled;
|
|
3619
3652
|
}
|
|
3620
3653
|
});
|
|
3621
|
-
Object.defineProperty(exports, "isPureLocalCssImportWrapper", {
|
|
3622
|
-
enumerable: true,
|
|
3623
|
-
get: function() {
|
|
3624
|
-
return isPureLocalCssImportWrapper;
|
|
3625
|
-
}
|
|
3626
|
-
});
|
|
3627
3654
|
Object.defineProperty(exports, "isSourceCandidateRequest", {
|
|
3628
3655
|
enumerable: true,
|
|
3629
3656
|
get: function() {
|
|
@@ -3684,12 +3711,6 @@ Object.defineProperty(exports, "resolveTaskConcurrency", {
|
|
|
3684
3711
|
return resolveTaskConcurrency;
|
|
3685
3712
|
}
|
|
3686
3713
|
});
|
|
3687
|
-
Object.defineProperty(exports, "rewriteLocalCssImportRequestsForOutput", {
|
|
3688
|
-
enumerable: true,
|
|
3689
|
-
get: function() {
|
|
3690
|
-
return rewriteLocalCssImportRequestsForOutput;
|
|
3691
|
-
}
|
|
3692
|
-
});
|
|
3693
3714
|
Object.defineProperty(exports, "runWithConcurrency", {
|
|
3694
3715
|
enumerable: true,
|
|
3695
3716
|
get: function() {
|
|
@@ -3702,12 +3723,6 @@ Object.defineProperty(exports, "scoreTailwindV4CssSourceFileMatch", {
|
|
|
3702
3723
|
return scoreTailwindV4CssSourceFileMatch;
|
|
3703
3724
|
}
|
|
3704
3725
|
});
|
|
3705
|
-
Object.defineProperty(exports, "splitLocalCssImports", {
|
|
3706
|
-
enumerable: true,
|
|
3707
|
-
get: function() {
|
|
3708
|
-
return splitLocalCssImports;
|
|
3709
|
-
}
|
|
3710
|
-
});
|
|
3711
3726
|
Object.defineProperty(exports, "stripTailwindSourceMediaFragments", {
|
|
3712
3727
|
enumerable: true,
|
|
3713
3728
|
get: function() {
|