weapp-tailwindcss 5.0.0 → 5.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{bundle-state-DgGEhk_z.js → bundle-state-Bvj01pW7.js} +35 -3
- package/dist/{bundle-state-CnaJxkFY.mjs → bundle-state-DY3eq4Gz.mjs} +24 -4
- package/dist/bundlers/shared/generated-css-marker.d.ts +6 -0
- package/dist/bundlers/shared/generator-css/directives.d.ts +1 -0
- package/dist/bundlers/shared/generator-css/source-files.d.ts +11 -5
- package/dist/bundlers/shared/generator-css/source-resolver.d.ts +2 -0
- package/dist/bundlers/shared/generator-css.d.ts +1 -0
- package/dist/bundlers/vite/bundle-state.d.ts +5 -1
- package/dist/bundlers/vite/css-finalizer.d.ts +12 -3
- package/dist/bundlers/vite/generate-bundle.d.ts +22 -6
- package/dist/bundlers/vite/processed-css-assets.d.ts +10 -2
- package/dist/bundlers/vite/source-candidates.d.ts +2 -0
- package/dist/bundlers/webpack/loaders/watch-dependencies.d.ts +8 -0
- package/dist/cli.js +1 -0
- package/dist/cli.mjs +1 -0
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/{generator--0-ekuVO.js → generator-Bd1LntD3.js} +1 -1
- package/dist/{generator-B76ovqsv.mjs → generator-DRHWC1t-.mjs} +1 -1
- package/dist/generator.js +2 -2
- package/dist/generator.mjs +2 -2
- package/dist/gulp.js +16 -10
- package/dist/gulp.mjs +14 -8
- package/dist/{incremental-runtime-class-set-CN6K_97P.js → incremental-runtime-class-set-Bl18sFqt.js} +540 -694
- package/dist/{incremental-runtime-class-set-x10M9bn_.mjs → incremental-runtime-class-set-CAEuUesH.mjs} +495 -619
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/{postcss-CR9UCaIK.mjs → postcss-CJrmfXvi.mjs} +4 -4
- package/dist/{postcss-hYimKoN_.js → postcss-DfnqZ4Bm.js} +4 -4
- package/dist/postcss.js +1 -1
- package/dist/postcss.mjs +1 -1
- package/dist/{precheck-DPtJjZmV.js → precheck-Bj5ReSOU.js} +2 -2
- package/dist/{precheck-BrNwLG2e.mjs → precheck-CUr1DYyy.mjs} +2 -2
- package/dist/presets.js +2 -2
- package/dist/presets.mjs +2 -2
- package/dist/{source-candidates-DN1mihlU.mjs → source-candidates-D7b-Jzsx.mjs} +44 -11
- package/dist/{source-candidates-DSxme_O2.js → source-candidates-DQxvGPSw.js} +49 -10
- package/dist/tailwindcss/source-scan.d.ts +3 -1
- package/dist/{tailwindcss-DWtPieNE.mjs → tailwindcss-D5RogwtV.mjs} +14 -49
- package/dist/{tailwindcss-glCm_d3H.js → tailwindcss-jvoYizzX.js} +19 -48
- package/dist/{v3-engine-DCxNPBVs.mjs → v3-engine-BCUGX3gX.mjs} +644 -36
- package/dist/{v3-engine-D3BMLVAN.js → v3-engine-CmIF_gsq.js} +775 -35
- package/dist/{vite-Ec0uX6kF.js → vite-D1ZdgbWa.js} +533 -290
- package/dist/{vite-DOprpdH-.mjs → vite-jBTi5CwO.mjs} +532 -289
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/{runtime-registry-DpcR3IHI.js → watch-dependencies-zwx4EhBn.js} +39 -0
- package/dist/weapp-tw-css-import-rewrite-loader.js +1953 -1630
- package/dist/weapp-tw-runtime-classset-loader.js +6 -6
- package/dist/{webpack-DFlZcqAU.mjs → webpack-CChDqRrl.mjs} +6 -6
- package/dist/{webpack-Ccohlg3A.js → webpack-vk2uqSnK.js} +7 -7
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +2 -2
|
@@ -2,23 +2,23 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
-
const
|
|
5
|
+
const require_watch_dependencies = require("./watch-dependencies-zwx4EhBn.js");
|
|
6
6
|
let node_buffer = require("node:buffer");
|
|
7
7
|
let node_process = require("node:process");
|
|
8
|
-
node_process =
|
|
8
|
+
node_process = require_watch_dependencies.__toESM(node_process);
|
|
9
9
|
let _weapp_tailwindcss_postcss = require("@weapp-tailwindcss/postcss");
|
|
10
|
+
let node_fs = require("node:fs");
|
|
11
|
+
node_fs = require_watch_dependencies.__toESM(node_fs);
|
|
10
12
|
let node_path = require("node:path");
|
|
11
|
-
node_path =
|
|
13
|
+
node_path = require_watch_dependencies.__toESM(node_path);
|
|
12
14
|
let node_util = require("node:util");
|
|
13
15
|
let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared");
|
|
14
16
|
let tailwindcss_patch = require("tailwindcss-patch");
|
|
15
|
-
let node_fs = require("node:fs");
|
|
16
|
-
node_fs = require_runtime_registry.__toESM(node_fs);
|
|
17
17
|
let node_module = require("node:module");
|
|
18
18
|
let _weapp_tailwindcss_logger = require("@weapp-tailwindcss/logger");
|
|
19
19
|
let node_url = require("node:url");
|
|
20
20
|
let debug = require("debug");
|
|
21
|
-
debug =
|
|
21
|
+
debug = require_watch_dependencies.__toESM(debug);
|
|
22
22
|
let node_fs_promises = require("node:fs/promises");
|
|
23
23
|
require("fast-glob");
|
|
24
24
|
let tailwindcss_config = require("tailwindcss-config");
|
|
@@ -26,7 +26,7 @@ require("micromatch");
|
|
|
26
26
|
let _weapp_core_escape = require("@weapp-core/escape");
|
|
27
27
|
require("magic-string");
|
|
28
28
|
let _babel_traverse = require("@babel/traverse");
|
|
29
|
-
_babel_traverse =
|
|
29
|
+
_babel_traverse = require_watch_dependencies.__toESM(_babel_traverse);
|
|
30
30
|
require("@babel/parser");
|
|
31
31
|
require("@babel/types");
|
|
32
32
|
require("@ast-core/escape");
|
|
@@ -365,7 +365,7 @@ function compileCssMacroConditionalComments(css, options) {
|
|
|
365
365
|
const platformTokens = createPlatformTokenSet(resolveCssMacroPlatform(options));
|
|
366
366
|
if (platformTokens.size === 0 || !css.includes("#if")) return css;
|
|
367
367
|
try {
|
|
368
|
-
const root =
|
|
368
|
+
const root = require_watch_dependencies.postcss_default.parse(css);
|
|
369
369
|
const transformContainer = (container) => {
|
|
370
370
|
const stack = [];
|
|
371
371
|
for (const node of [...container.nodes ?? []]) {
|
|
@@ -420,7 +420,7 @@ function hasCssMacroTailwindV4Directive(css) {
|
|
|
420
420
|
if (!css?.includes("css-macro")) return false;
|
|
421
421
|
try {
|
|
422
422
|
let found = false;
|
|
423
|
-
|
|
423
|
+
require_watch_dependencies.postcss_default.parse(css).walkAtRules("plugin", (rule) => {
|
|
424
424
|
if (isCssMacroPluginRequest(parseCssPluginRequest(rule.params))) found = true;
|
|
425
425
|
});
|
|
426
426
|
return found;
|
|
@@ -458,11 +458,21 @@ function hasCssMacroStyleOptions(options) {
|
|
|
458
458
|
return Boolean(options?.[CSS_MACRO_STYLE_OPTIONS_MARKER]);
|
|
459
459
|
}
|
|
460
460
|
async function transformCssMacroCss(css, options) {
|
|
461
|
-
const result = (await
|
|
461
|
+
const result = (await require_watch_dependencies.postcss_default([creator()]).process(css, { from: void 0 })).css;
|
|
462
462
|
return compileCssMacroConditionalComments(result, options);
|
|
463
463
|
}
|
|
464
464
|
//#endregion
|
|
465
465
|
//#region src/context/workspace.ts
|
|
466
|
+
function findWorkspaceRoot(startDir) {
|
|
467
|
+
if (!startDir) return;
|
|
468
|
+
let current = node_path.default.resolve(startDir);
|
|
469
|
+
while (true) {
|
|
470
|
+
if ((0, node_fs.existsSync)(node_path.default.join(current, "pnpm-workspace.yaml"))) return current;
|
|
471
|
+
const parent = node_path.default.dirname(current);
|
|
472
|
+
if (parent === current) return;
|
|
473
|
+
current = parent;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
466
476
|
function findNearestPackageRoot(startDir) {
|
|
467
477
|
if (!startDir) return;
|
|
468
478
|
let current = node_path.default.resolve(startDir);
|
|
@@ -560,6 +570,11 @@ function createDefaultResolvePaths(basedir) {
|
|
|
560
570
|
appendNodeModules(paths, packageRoot);
|
|
561
571
|
fallbackCandidates.push(packageRoot);
|
|
562
572
|
}
|
|
573
|
+
const workspaceRoot = findWorkspaceRoot(resolvedBase);
|
|
574
|
+
if (workspaceRoot) {
|
|
575
|
+
appendNodeModules(paths, workspaceRoot);
|
|
576
|
+
fallbackCandidates.push(workspaceRoot);
|
|
577
|
+
}
|
|
563
578
|
}
|
|
564
579
|
const cwd = node_process.default.cwd();
|
|
565
580
|
appendNodeModules(paths, cwd);
|
|
@@ -611,9 +626,6 @@ function createFallbackTailwindcssPatcher() {
|
|
|
611
626
|
let hasLoggedMissingTailwind = false;
|
|
612
627
|
const TAILWINDCSS_NOT_FOUND_RE = /tailwindcss not found/i;
|
|
613
628
|
const UNABLE_TO_LOCATE_TAILWINDCSS_RE = /unable to locate tailwind css package/i;
|
|
614
|
-
function isTailwindcssV4PackageName(packageName) {
|
|
615
|
-
return packageName === "@tailwindcss/postcss" || packageName === "tailwindcss4" || Boolean(packageName && packageName.includes("tailwindcss4"));
|
|
616
|
-
}
|
|
617
629
|
function createTailwindcssPatcher(options) {
|
|
618
630
|
const { basedir, cacheDir, supportCustomLengthUnitsPatch, tailwindcss, tailwindcssPatcherOptions } = options || {};
|
|
619
631
|
const cache = { driver: "memory" };
|
|
@@ -632,7 +644,7 @@ function createTailwindcssPatcher(options) {
|
|
|
632
644
|
resolve: { paths: resolvePaths }
|
|
633
645
|
}));
|
|
634
646
|
if (!baseTailwindOptions.packageName) baseTailwindOptions.packageName = "tailwindcss";
|
|
635
|
-
if (!baseTailwindOptions.postcssPlugin) baseTailwindOptions.postcssPlugin =
|
|
647
|
+
if (!baseTailwindOptions.postcssPlugin) baseTailwindOptions.postcssPlugin = "tailwindcss";
|
|
636
648
|
if (typeof baseTailwindOptions.postcssPlugin === "string") {
|
|
637
649
|
const resolvedPlugin = resolveModuleFromPaths(baseTailwindOptions.postcssPlugin, resolvePaths);
|
|
638
650
|
if (resolvedPlugin) baseTailwindOptions.postcssPlugin = resolvedPlugin;
|
|
@@ -650,7 +662,7 @@ function createTailwindcssPatcher(options) {
|
|
|
650
662
|
const resolvedTailwindOptions = resolvedOptions.tailwindcss;
|
|
651
663
|
if (resolvedTailwindOptions) {
|
|
652
664
|
const existingResolve = resolvedTailwindOptions.resolve ?? {};
|
|
653
|
-
const sourcePaths = Array.isArray(existingResolve.paths) && existingResolve.paths.length > 0 ? existingResolve.paths : resolvePaths;
|
|
665
|
+
const sourcePaths = Array.isArray(existingResolve.paths) && existingResolve.paths.length > 0 ? [...existingResolve.paths, ...resolvePaths] : resolvePaths;
|
|
654
666
|
resolvedTailwindOptions.resolve = {
|
|
655
667
|
...existingResolve,
|
|
656
668
|
paths: [...new Set(sourcePaths)]
|
|
@@ -936,7 +948,7 @@ function collectCssInlineSourceCandidates(root) {
|
|
|
936
948
|
excluded
|
|
937
949
|
};
|
|
938
950
|
}
|
|
939
|
-
function normalizeLegacyContentEntries(content, base) {
|
|
951
|
+
function normalizeLegacyContentEntries(content, base, options = {}) {
|
|
940
952
|
if (typeof content === "string") {
|
|
941
953
|
const negated = content.startsWith("!");
|
|
942
954
|
return [{
|
|
@@ -945,8 +957,8 @@ function normalizeLegacyContentEntries(content, base) {
|
|
|
945
957
|
pattern: normalizeGlobPattern(negated ? content.slice(1) : content)
|
|
946
958
|
}];
|
|
947
959
|
}
|
|
948
|
-
if (Array.isArray(content)) return content.flatMap((item) => normalizeLegacyContentEntries(item, base));
|
|
949
|
-
if (isLegacyContentObject$1(content)) return normalizeLegacyContentEntries(content.files, base);
|
|
960
|
+
if (Array.isArray(content)) return content.flatMap((item) => normalizeLegacyContentEntries(item, base, options));
|
|
961
|
+
if (isLegacyContentObject$1(content)) return normalizeLegacyContentEntries(content.files, content.relative && options.relativeBase ? options.relativeBase : base, options);
|
|
950
962
|
return [];
|
|
951
963
|
}
|
|
952
964
|
async function pathExistsAsDirectory(file) {
|
|
@@ -1956,7 +1968,7 @@ function resolveStyleOptions$1(source, options) {
|
|
|
1956
1968
|
function collectCustomPropertyValues(css) {
|
|
1957
1969
|
const values = /* @__PURE__ */ new Map();
|
|
1958
1970
|
try {
|
|
1959
|
-
|
|
1971
|
+
require_watch_dependencies.postcss_default.parse(css).walkDecls((decl) => {
|
|
1960
1972
|
if (decl.prop.startsWith("--")) values.set(decl.prop, decl.value.trim());
|
|
1961
1973
|
});
|
|
1962
1974
|
} catch {}
|
|
@@ -1991,9 +2003,10 @@ function parseImportSourceParam$1(params) {
|
|
|
1991
2003
|
};
|
|
1992
2004
|
}
|
|
1993
2005
|
function isTailwindCssImport$1(params) {
|
|
1994
|
-
|
|
2006
|
+
const specifier = parseCssImportSpecifier$2(params);
|
|
2007
|
+
return specifier === "tailwindcss" || specifier?.startsWith("tailwindcss/") || specifier?.replaceAll("\\", "/").endsWith("/tailwindcss/index.css");
|
|
1995
2008
|
}
|
|
1996
|
-
function parseCssImportSpecifier$
|
|
2009
|
+
function parseCssImportSpecifier$2(params) {
|
|
1997
2010
|
const value = params.trim();
|
|
1998
2011
|
const quoted = /^(['"])(.*?)\1/.exec(value);
|
|
1999
2012
|
if (quoted) return quoted[2];
|
|
@@ -2001,7 +2014,7 @@ function parseCssImportSpecifier$1(params) {
|
|
|
2001
2014
|
return url?.[2] ?? url?.[3];
|
|
2002
2015
|
}
|
|
2003
2016
|
function isTailwindCssPreflightImport(params) {
|
|
2004
|
-
const specifier = parseCssImportSpecifier$
|
|
2017
|
+
const specifier = parseCssImportSpecifier$2(params);
|
|
2005
2018
|
return specifier === "tailwindcss/preflight.css" || specifier === "tailwindcss/preflight";
|
|
2006
2019
|
}
|
|
2007
2020
|
function hasImportLayerOption(params) {
|
|
@@ -2011,7 +2024,7 @@ function removeUnlayeredTailwindV4PreflightImports(css) {
|
|
|
2011
2024
|
if (!css.includes("preflight")) return css;
|
|
2012
2025
|
let root;
|
|
2013
2026
|
try {
|
|
2014
|
-
root =
|
|
2027
|
+
root = require_watch_dependencies.postcss_default.parse(css);
|
|
2015
2028
|
} catch {
|
|
2016
2029
|
return css;
|
|
2017
2030
|
}
|
|
@@ -2047,7 +2060,7 @@ async function resolveCssDefinedScanSources(source) {
|
|
|
2047
2060
|
const from = source.dependencies[0];
|
|
2048
2061
|
let root;
|
|
2049
2062
|
try {
|
|
2050
|
-
root =
|
|
2063
|
+
root = require_watch_dependencies.postcss_default.parse(source.css, { from });
|
|
2051
2064
|
} catch {
|
|
2052
2065
|
return;
|
|
2053
2066
|
}
|
|
@@ -2090,7 +2103,7 @@ function removeUnsupportedThemeVendorKeyframes(css) {
|
|
|
2090
2103
|
if (!css.includes("@theme") || !css.includes("@-")) return css;
|
|
2091
2104
|
let root;
|
|
2092
2105
|
try {
|
|
2093
|
-
root =
|
|
2106
|
+
root = require_watch_dependencies.postcss_default.parse(css);
|
|
2094
2107
|
} catch {
|
|
2095
2108
|
return css;
|
|
2096
2109
|
}
|
|
@@ -2236,189 +2249,217 @@ function createTailwindV4Engine(source) {
|
|
|
2236
2249
|
};
|
|
2237
2250
|
}
|
|
2238
2251
|
//#endregion
|
|
2239
|
-
//#region src/
|
|
2240
|
-
function
|
|
2241
|
-
|
|
2242
|
-
return value === "@tailwindcss/postcss" || value.includes("/postcss");
|
|
2252
|
+
//#region src/bundlers/shared/generator-css/config-directive.ts
|
|
2253
|
+
function quoteCssString(value) {
|
|
2254
|
+
return value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"");
|
|
2243
2255
|
}
|
|
2244
|
-
function
|
|
2245
|
-
return
|
|
2256
|
+
function toCssPath(value) {
|
|
2257
|
+
return value.replaceAll("\\", "/");
|
|
2246
2258
|
}
|
|
2247
|
-
function
|
|
2248
|
-
|
|
2259
|
+
function prependConfigDirective(css, config) {
|
|
2260
|
+
if (!config || /@config\s+/.test(css)) return css;
|
|
2261
|
+
return `@config "${quoteCssString(toCssPath(config))}";\n${css}`;
|
|
2249
2262
|
}
|
|
2250
|
-
function
|
|
2251
|
-
|
|
2263
|
+
function normalizeConfigDirective(css, config) {
|
|
2264
|
+
if (!config || !/@config\s+/.test(css)) return css;
|
|
2265
|
+
return css.replace(/@config\s+(["'])(.+?)\1\s*;?/, `@config "${quoteCssString(toCssPath(config))}";`);
|
|
2252
2266
|
}
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2267
|
+
//#endregion
|
|
2268
|
+
//#region src/bundlers/shared/generator-css/markers.ts
|
|
2269
|
+
const TAILWIND_V4_BANNER_RE = /\/\*!\s*tailwindcss v4\./;
|
|
2270
|
+
const TAILWIND_GENERATED_CSS_MARKER_RE = /\/\*!\s*tailwindcss v|@property\s+--tw-|--tw-|:not\(#\\#\)|\.[^,{]*(?:\\:|\\\[|\\#)|(?::host|page|\.tw-root|wx-root-portal-content)[^{]*\{[^}]*--(?:color|spacing|text|font-weight|radius)-/;
|
|
2271
|
+
const GENERATOR_PLACEHOLDER_MARKER_RE = /\/\*!\s*weapp-tailwindcss generator-placeholder\s*\*\//i;
|
|
2272
|
+
const GENERATOR_PLACEHOLDER_MARKER_GLOBAL_RE = /\/\*!\s*weapp-tailwindcss generator-placeholder\s*\*\/\s*/gi;
|
|
2273
|
+
const TAILWIND_BANNER_PREFIX_RE = /^\/\*!\s*tailwindcss v[^*]*\*\/\s*/i;
|
|
2274
|
+
const TAILWIND_BANNER_RE = /\/\*!\s*tailwindcss v[^*]*\*\//i;
|
|
2275
|
+
const TAILWIND_BANNER_GLOBAL_RE = /\/\*!\s*tailwindcss v[^*]*\*\/\s*/gi;
|
|
2276
|
+
const VITE_MARKER_RE = /\/\*\$vite\$:[^*]*\*\//g;
|
|
2277
|
+
function createCssAppend(base, extra) {
|
|
2278
|
+
if (!base) return extra;
|
|
2279
|
+
if (!extra) return base;
|
|
2280
|
+
return `${base}\n${extra}`;
|
|
2257
2281
|
}
|
|
2258
|
-
function
|
|
2259
|
-
|
|
2282
|
+
function splitTailwindV4GeneratedCssBySourceOrder(rawSource, rawTailwindCss) {
|
|
2283
|
+
const trimmedRaw = rawSource.trim();
|
|
2284
|
+
const trimmedTailwind = rawTailwindCss.trim();
|
|
2285
|
+
if (trimmedRaw === trimmedTailwind) return {
|
|
2286
|
+
before: "",
|
|
2287
|
+
after: ""
|
|
2288
|
+
};
|
|
2289
|
+
if (trimmedTailwind.startsWith(trimmedRaw)) return {
|
|
2290
|
+
before: "",
|
|
2291
|
+
after: ""
|
|
2292
|
+
};
|
|
2293
|
+
const start = rawSource.indexOf(rawTailwindCss);
|
|
2294
|
+
if (start === -1) return;
|
|
2295
|
+
return {
|
|
2296
|
+
before: rawSource.slice(0, start),
|
|
2297
|
+
after: rawSource.slice(start + rawTailwindCss.length)
|
|
2298
|
+
};
|
|
2260
2299
|
}
|
|
2261
|
-
function
|
|
2262
|
-
const
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
raw: quoted[0],
|
|
2270
|
-
specifier
|
|
2271
|
-
};
|
|
2300
|
+
function splitGeneratorPlaceholderCssBySourceOrder(rawSource, rawTailwindCss) {
|
|
2301
|
+
const match = GENERATOR_PLACEHOLDER_MARKER_RE.exec(rawSource);
|
|
2302
|
+
if (!match || match.index === void 0) return;
|
|
2303
|
+
let afterStart = match.index + match[0].length;
|
|
2304
|
+
while (/\s/.test(rawSource[afterStart] ?? "")) afterStart++;
|
|
2305
|
+
if (rawTailwindCss && rawSource.slice(afterStart).startsWith(rawTailwindCss)) {
|
|
2306
|
+
afterStart += rawTailwindCss.length;
|
|
2307
|
+
while (/\s/.test(rawSource[afterStart] ?? "")) afterStart++;
|
|
2272
2308
|
}
|
|
2273
|
-
const url = /^url\(\s*(?:(['"])(.*?)\1|([^'")\s]+))\s*\)/.exec(value);
|
|
2274
|
-
if (!url) return;
|
|
2275
|
-
const specifier = url[2] ?? url[3];
|
|
2276
|
-
if (specifier === void 0) return;
|
|
2277
2309
|
return {
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
specifier
|
|
2310
|
+
before: rawSource.slice(0, match.index),
|
|
2311
|
+
after: rawSource.slice(afterStart)
|
|
2281
2312
|
};
|
|
2282
2313
|
}
|
|
2283
|
-
function
|
|
2284
|
-
|
|
2314
|
+
function splitTailwindGeneratedCssByBanner(rawSource, start) {
|
|
2315
|
+
const match = start === void 0 ? TAILWIND_BANNER_RE.exec(rawSource) : { index: start };
|
|
2316
|
+
if (!match || match.index === void 0) return;
|
|
2317
|
+
return {
|
|
2318
|
+
before: rawSource.slice(0, match.index),
|
|
2319
|
+
after: [...rawSource.slice(match.index).matchAll(VITE_MARKER_RE)].map((item) => item[0]).join("\n")
|
|
2320
|
+
};
|
|
2285
2321
|
}
|
|
2286
|
-
function
|
|
2287
|
-
|
|
2288
|
-
if (packageName && isBarePackageSpecifier(packageName)) specifiers.add(packageName);
|
|
2289
|
-
return specifiers;
|
|
2322
|
+
function stripTailwindBanner(css) {
|
|
2323
|
+
return css.replace(TAILWIND_BANNER_PREFIX_RE, "");
|
|
2290
2324
|
}
|
|
2291
|
-
function
|
|
2292
|
-
|
|
2293
|
-
let root;
|
|
2294
|
-
try {
|
|
2295
|
-
root = require_runtime_registry.postcss_default.parse(css);
|
|
2296
|
-
} catch {
|
|
2297
|
-
return css;
|
|
2298
|
-
}
|
|
2299
|
-
const importSpecifiers = createTailwindV4CssImportSpecifierSet(packageName);
|
|
2300
|
-
let changed = false;
|
|
2301
|
-
root.walkAtRules("import", (rule) => {
|
|
2302
|
-
const parsed = parseCssImportSpecifier(rule.params);
|
|
2303
|
-
if (!parsed || !importSpecifiers.has(parsed.specifier)) return;
|
|
2304
|
-
rule.params = rule.params.replace(parsed.raw, quoteCssImportSpecifier(`${parsed.specifier}/index.css`, parsed.quote));
|
|
2305
|
-
changed = true;
|
|
2306
|
-
});
|
|
2307
|
-
return changed ? root.toString() : css;
|
|
2325
|
+
function stripTailwindBanners(css) {
|
|
2326
|
+
return css.replace(TAILWIND_BANNER_GLOBAL_RE, "");
|
|
2308
2327
|
}
|
|
2309
|
-
function
|
|
2310
|
-
|
|
2311
|
-
if (typeof configuredPackageName === "string" && configuredPackageName.length > 0 && !isPostcssPluginImportTarget(configuredPackageName)) return configuredPackageName;
|
|
2312
|
-
const packageName = patcher.packageInfo?.name;
|
|
2313
|
-
if (typeof packageName === "string" && packageName.length > 0 && !isPostcssPluginImportTarget(packageName)) return packageName;
|
|
2314
|
-
return "tailwindcss";
|
|
2328
|
+
function stripGeneratorPlaceholderMarkers(css) {
|
|
2329
|
+
return css.replace(GENERATOR_PLACEHOLDER_MARKER_GLOBAL_RE, "");
|
|
2315
2330
|
}
|
|
2316
|
-
function
|
|
2317
|
-
return
|
|
2331
|
+
function hasTailwindGeneratedCss(rawSource) {
|
|
2332
|
+
return TAILWIND_V4_BANNER_RE.test(rawSource);
|
|
2318
2333
|
}
|
|
2319
|
-
function
|
|
2320
|
-
return
|
|
2334
|
+
function hasTailwindGeneratedCssMarkers(rawSource) {
|
|
2335
|
+
return TAILWIND_GENERATED_CSS_MARKER_RE.test(rawSource) || GENERATOR_PLACEHOLDER_MARKER_RE.test(rawSource);
|
|
2321
2336
|
}
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2337
|
+
//#endregion
|
|
2338
|
+
//#region src/bundlers/shared/generator-css/directives.ts
|
|
2339
|
+
const TAILWIND_REMOVABLE_SOURCE_DIRECTIVE_NAMES = new Set([
|
|
2340
|
+
"config",
|
|
2341
|
+
"custom-variant",
|
|
2342
|
+
"layer",
|
|
2343
|
+
"plugin",
|
|
2344
|
+
"reference",
|
|
2345
|
+
"source",
|
|
2346
|
+
"tailwind",
|
|
2347
|
+
"theme",
|
|
2348
|
+
"utility",
|
|
2349
|
+
"variant"
|
|
2350
|
+
]);
|
|
2351
|
+
const TAILWIND_ROOT_DIRECTIVE_NAMES = new Set([
|
|
2352
|
+
"config",
|
|
2353
|
+
"custom-variant",
|
|
2354
|
+
"plugin",
|
|
2355
|
+
"source",
|
|
2356
|
+
"tailwind",
|
|
2357
|
+
"theme",
|
|
2358
|
+
"utility",
|
|
2359
|
+
"variant"
|
|
2360
|
+
]);
|
|
2361
|
+
const TAILWIND_ROOT_DIRECTIVE_RE = /@(?:import\s+(?:url\(\s*)?["']?tailwindcss4?(?:\/[^"')\s]*)?|(?:use|forward)\s+(?:url\(\s*)?["']?tailwindcss4?(?:\/[^"')\s]*)?|tailwind|config|custom-variant|plugin|source|theme|utility|variant)\b/;
|
|
2362
|
+
const TAILWIND_EXTRACTABLE_DIRECTIVE_RE = /^\s*@(?:import|use|forward|tailwind|config|source|reference|plugin)\b[\s\S]*?(?:;|$)/;
|
|
2363
|
+
const TAILWIND_EXTRACTABLE_LAYER_STATEMENT_RE = /^\s*@layer\s[^;{]+;\s*$/;
|
|
2364
|
+
const TAILWIND_EXTRACTABLE_BLOCK_START_RE = /^\s*@(?:layer|theme|utility|variant|custom-variant)\b[\s\S]*\{/;
|
|
2365
|
+
const TAILWIND_V3_SUBPATH_IMPORT_LAYERS = new Map([
|
|
2366
|
+
["tailwindcss/base", "base"],
|
|
2367
|
+
["tailwindcss/components", "components"],
|
|
2368
|
+
["tailwindcss/utilities", "utilities"]
|
|
2369
|
+
]);
|
|
2370
|
+
function parseImportRequest(params) {
|
|
2371
|
+
return /^(?:url\(\s*)?(["']?)([^"')\s]+)\1\s*\)?/.exec(params.trim())?.[2];
|
|
2350
2372
|
}
|
|
2351
|
-
function
|
|
2352
|
-
|
|
2353
|
-
return omitUndefined({
|
|
2354
|
-
...resolvePatchTailwindV4SourceOptions(patcher),
|
|
2355
|
-
sources: tailwindV4Options?.sources
|
|
2356
|
-
});
|
|
2373
|
+
function parseConfigRequest(params) {
|
|
2374
|
+
return /^(["'])(.+)\1\s*;?$/.exec(params.trim())?.[2];
|
|
2357
2375
|
}
|
|
2358
|
-
function
|
|
2359
|
-
return
|
|
2360
|
-
...options,
|
|
2361
|
-
css: normalizeTailwindV4CssPackageImports(options.css, options.packageName)
|
|
2362
|
-
});
|
|
2376
|
+
function isPackageJsonImportRequest$1(request) {
|
|
2377
|
+
return typeof request === "string" && request.startsWith("#");
|
|
2363
2378
|
}
|
|
2364
|
-
|
|
2365
|
-
return
|
|
2379
|
+
function isWeappTailwindcssImportRequest(request) {
|
|
2380
|
+
return request === "weapp-tailwindcss" || request?.startsWith("weapp-tailwindcss/");
|
|
2366
2381
|
}
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
let index = start;
|
|
2371
|
-
while (index < source.length) {
|
|
2372
|
-
const char = source[index];
|
|
2373
|
-
if (/\s/.test(char ?? "")) {
|
|
2374
|
-
index += 1;
|
|
2375
|
-
continue;
|
|
2376
|
-
}
|
|
2377
|
-
if (char === "/" && source[index + 1] === "/") {
|
|
2378
|
-
index += 2;
|
|
2379
|
-
while (index < source.length && source[index] !== "\n") index += 1;
|
|
2380
|
-
continue;
|
|
2381
|
-
}
|
|
2382
|
-
if (char === "/" && source[index + 1] === "*") {
|
|
2383
|
-
index += 2;
|
|
2384
|
-
while (index < source.length && !(source[index] === "*" && source[index + 1] === "/")) index += 1;
|
|
2385
|
-
index = Math.min(index + 2, source.length);
|
|
2386
|
-
continue;
|
|
2387
|
-
}
|
|
2388
|
-
break;
|
|
2389
|
-
}
|
|
2390
|
-
return index;
|
|
2382
|
+
function normalizeTailwindImportRequest(request, options = {}) {
|
|
2383
|
+
if (options.importFallback && isWeappTailwindcssImportRequest(request)) return request.replace(/^weapp-tailwindcss/, "tailwindcss");
|
|
2384
|
+
return request;
|
|
2391
2385
|
}
|
|
2392
|
-
function
|
|
2393
|
-
const
|
|
2394
|
-
if (
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2386
|
+
function replaceImportRequest(params, request, replacement) {
|
|
2387
|
+
const index = params.indexOf(request);
|
|
2388
|
+
if (index === -1) return params;
|
|
2389
|
+
return `${params.slice(0, index)}${replacement}${params.slice(index + request.length)}`;
|
|
2390
|
+
}
|
|
2391
|
+
function normalizeTailwindImportAtRules(root, options = {}) {
|
|
2392
|
+
if (!options.importFallback) return false;
|
|
2393
|
+
let changed = false;
|
|
2394
|
+
const seenCanonicalImports = /* @__PURE__ */ new Set();
|
|
2395
|
+
root.walkAtRules("import", (node) => {
|
|
2396
|
+
const request = parseImportRequest(node.params);
|
|
2397
|
+
const normalizedRequest = normalizeTailwindImportRequest(request, options);
|
|
2398
|
+
if (!normalizedRequest || !isTailwindImportRequest(normalizedRequest)) return;
|
|
2399
|
+
const normalizedParams = request && normalizedRequest !== request ? replaceImportRequest(node.params, request, normalizedRequest) : node.params;
|
|
2400
|
+
const normalizedKey = normalizedParams.trim();
|
|
2401
|
+
if (seenCanonicalImports.has(normalizedKey)) {
|
|
2402
|
+
node.remove();
|
|
2403
|
+
changed = true;
|
|
2404
|
+
return;
|
|
2404
2405
|
}
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2406
|
+
seenCanonicalImports.add(normalizedKey);
|
|
2407
|
+
if (normalizedParams !== node.params) {
|
|
2408
|
+
node.params = normalizedParams;
|
|
2409
|
+
changed = true;
|
|
2410
|
+
}
|
|
2411
|
+
});
|
|
2412
|
+
return changed;
|
|
2413
|
+
}
|
|
2414
|
+
function normalizeTailwindDirectiveLine(line, options = {}) {
|
|
2415
|
+
const trimmed = line.trimStart();
|
|
2416
|
+
if (/^@(?:use|forward)\b/.test(trimmed)) {
|
|
2417
|
+
const request = parseImportRequest(trimmed.replace(/^@(?:use|forward)\b/, ""));
|
|
2418
|
+
if (isTailwindImportRequest(request) || options.importFallback && isWeappTailwindcssImportRequest(request)) {
|
|
2419
|
+
const normalizedRequest = normalizeTailwindImportRequest(request, options);
|
|
2420
|
+
return replaceImportRequest(line.replace(/^(\s*)@(?:use|forward)\b/, "$1@import"), request, normalizedRequest);
|
|
2421
|
+
}
|
|
2422
|
+
return line;
|
|
2410
2423
|
}
|
|
2424
|
+
if (!options.importFallback || !trimmed.startsWith("@import")) return line;
|
|
2425
|
+
const request = parseImportRequest(trimmed.replace(/^@import\b/, ""));
|
|
2426
|
+
if (!request || !isWeappTailwindcssImportRequest(request)) return line;
|
|
2427
|
+
return replaceImportRequest(line, request, request.replace(/^weapp-tailwindcss/, "tailwindcss"));
|
|
2411
2428
|
}
|
|
2412
|
-
function
|
|
2413
|
-
|
|
2429
|
+
function extractTailwindDirectiveLines(rawSource, options = {}) {
|
|
2430
|
+
const directives = [];
|
|
2431
|
+
const seenImports = /* @__PURE__ */ new Set();
|
|
2432
|
+
for (const line of stripGeneratorPlaceholderMarkers(rawSource).split(/\r?\n/)) {
|
|
2433
|
+
const trimmed = line.trim();
|
|
2434
|
+
if (!trimmed || trimmed.startsWith("//")) continue;
|
|
2435
|
+
const directive = TAILWIND_EXTRACTABLE_DIRECTIVE_RE.exec(line)?.[0] ?? TAILWIND_EXTRACTABLE_LAYER_STATEMENT_RE.exec(line)?.[0];
|
|
2436
|
+
if (!directive) continue;
|
|
2437
|
+
const normalized = normalizeTailwindDirectiveLine(directive.trimEnd(), options);
|
|
2438
|
+
const normalizedTrimmed = normalized.trim();
|
|
2439
|
+
if (options.removeConfig && normalizedTrimmed.startsWith("@config")) continue;
|
|
2440
|
+
const request = /^@(?:import|use|forward)\b/.test(normalizedTrimmed) ? parseImportRequest(normalizedTrimmed.replace(/^@(?:import|use|forward)\b/, "")) : void 0;
|
|
2441
|
+
if (request && !isTailwindImportRequest(request) && !isPackageJsonImportRequest$1(request)) continue;
|
|
2442
|
+
if (/^@(?:import|use|forward)\b/.test(normalizedTrimmed) && !request) continue;
|
|
2443
|
+
if (request && isTailwindImportRequest(request)) {
|
|
2444
|
+
const key = normalizedTrimmed;
|
|
2445
|
+
if (seenImports.has(key)) continue;
|
|
2446
|
+
seenImports.add(key);
|
|
2447
|
+
}
|
|
2448
|
+
directives.push(normalized);
|
|
2449
|
+
}
|
|
2450
|
+
return directives;
|
|
2414
2451
|
}
|
|
2415
|
-
function
|
|
2416
|
-
let depth = 0;
|
|
2452
|
+
function stripPreprocessorLineComment(line) {
|
|
2417
2453
|
let quote;
|
|
2418
|
-
|
|
2419
|
-
|
|
2454
|
+
let escaped = false;
|
|
2455
|
+
for (let index = 0; index < line.length; index++) {
|
|
2456
|
+
const char = line[index];
|
|
2457
|
+
if (escaped) {
|
|
2458
|
+
escaped = false;
|
|
2459
|
+
continue;
|
|
2460
|
+
}
|
|
2420
2461
|
if (char === "\\") {
|
|
2421
|
-
|
|
2462
|
+
escaped = true;
|
|
2422
2463
|
continue;
|
|
2423
2464
|
}
|
|
2424
2465
|
if (quote) {
|
|
@@ -2429,1428 +2470,1500 @@ function findMatchingBracket(source, start, open, close) {
|
|
|
2429
2470
|
quote = char;
|
|
2430
2471
|
continue;
|
|
2431
2472
|
}
|
|
2432
|
-
if (char === "
|
|
2433
|
-
if (char === open) {
|
|
2434
|
-
depth += 1;
|
|
2435
|
-
continue;
|
|
2436
|
-
}
|
|
2437
|
-
if (char === close) {
|
|
2438
|
-
depth -= 1;
|
|
2439
|
-
if (depth === 0) return index;
|
|
2440
|
-
}
|
|
2473
|
+
if (char === "/" && line[index + 1] === "/" && (index === 0 || /\s/.test(line[index - 1]))) return line.slice(0, index).trimEnd();
|
|
2441
2474
|
}
|
|
2475
|
+
return line;
|
|
2442
2476
|
}
|
|
2443
|
-
function
|
|
2444
|
-
let
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
const
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
index = nextIndex + 7;
|
|
2477
|
+
function countBlockBraceDelta(line) {
|
|
2478
|
+
let quote;
|
|
2479
|
+
let escaped = false;
|
|
2480
|
+
let delta = 0;
|
|
2481
|
+
for (let index = 0; index < line.length; index++) {
|
|
2482
|
+
const char = line[index];
|
|
2483
|
+
if (escaped) {
|
|
2484
|
+
escaped = false;
|
|
2452
2485
|
continue;
|
|
2453
2486
|
}
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
index = nextIndex + 7;
|
|
2487
|
+
if (char === "\\") {
|
|
2488
|
+
escaped = true;
|
|
2457
2489
|
continue;
|
|
2458
2490
|
}
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
}
|
|
2462
|
-
}
|
|
2463
|
-
function parseStaticContentArray(source, start) {
|
|
2464
|
-
if (source[start] !== "[") return;
|
|
2465
|
-
const value = [];
|
|
2466
|
-
let index = skipWhitespaceAndComments(source, start + 1);
|
|
2467
|
-
while (index < source.length) {
|
|
2468
|
-
if (source[index] === "]") return {
|
|
2469
|
-
end: index + 1,
|
|
2470
|
-
value
|
|
2471
|
-
};
|
|
2472
|
-
const parsed = parseStaticContentValue(source, index);
|
|
2473
|
-
if (!parsed) return;
|
|
2474
|
-
value.push(parsed.value);
|
|
2475
|
-
index = skipWhitespaceAndComments(source, parsed.end);
|
|
2476
|
-
if (source[index] === ",") {
|
|
2477
|
-
index = skipWhitespaceAndComments(source, index + 1);
|
|
2491
|
+
if (quote) {
|
|
2492
|
+
if (char === quote) quote = void 0;
|
|
2478
2493
|
continue;
|
|
2479
2494
|
}
|
|
2480
|
-
if (
|
|
2481
|
-
|
|
2495
|
+
if (char === "\"" || char === "'") {
|
|
2496
|
+
quote = char;
|
|
2497
|
+
continue;
|
|
2498
|
+
}
|
|
2499
|
+
if (char === "{") delta++;
|
|
2500
|
+
else if (char === "}") delta--;
|
|
2482
2501
|
}
|
|
2502
|
+
return delta;
|
|
2483
2503
|
}
|
|
2484
|
-
function
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
}
|
|
2501
|
-
index = skipWhitespaceAndComments(source, index);
|
|
2502
|
-
if (source[index] !== ":") return;
|
|
2503
|
-
index = skipWhitespaceAndComments(source, index + 1);
|
|
2504
|
-
const parsedValue = parseStaticContentValue(source, index);
|
|
2505
|
-
if (!parsedValue) return;
|
|
2506
|
-
if (key === "files") files = parsedValue.value;
|
|
2507
|
-
index = skipWhitespaceAndComments(source, parsedValue.end);
|
|
2508
|
-
if (source[index] === ",") {
|
|
2509
|
-
index = skipWhitespaceAndComments(source, index + 1);
|
|
2504
|
+
function extractTailwindFallbackBlocks(rawSource) {
|
|
2505
|
+
const blocks = [];
|
|
2506
|
+
let current;
|
|
2507
|
+
let depth = 0;
|
|
2508
|
+
for (const rawLine of stripGeneratorPlaceholderMarkers(rawSource).split(/\r?\n/)) {
|
|
2509
|
+
const line = stripPreprocessorLineComment(rawLine);
|
|
2510
|
+
if (!line.trim()) continue;
|
|
2511
|
+
if (!current) {
|
|
2512
|
+
if (!TAILWIND_EXTRACTABLE_BLOCK_START_RE.test(line)) continue;
|
|
2513
|
+
current = [line];
|
|
2514
|
+
depth = countBlockBraceDelta(line);
|
|
2515
|
+
if (depth <= 0) {
|
|
2516
|
+
blocks.push(current.join("\n"));
|
|
2517
|
+
current = void 0;
|
|
2518
|
+
depth = 0;
|
|
2519
|
+
}
|
|
2510
2520
|
continue;
|
|
2511
2521
|
}
|
|
2512
|
-
|
|
2522
|
+
current.push(line);
|
|
2523
|
+
depth += countBlockBraceDelta(line);
|
|
2524
|
+
if (depth <= 0) {
|
|
2525
|
+
blocks.push(current.join("\n"));
|
|
2526
|
+
current = void 0;
|
|
2527
|
+
depth = 0;
|
|
2528
|
+
}
|
|
2513
2529
|
}
|
|
2514
|
-
return
|
|
2515
|
-
end: end + 1,
|
|
2516
|
-
value: { files }
|
|
2517
|
-
};
|
|
2530
|
+
return blocks;
|
|
2518
2531
|
}
|
|
2519
|
-
function
|
|
2520
|
-
const
|
|
2521
|
-
|
|
2522
|
-
if (quoted) return quoted;
|
|
2523
|
-
if (source[index] === "[") return parseStaticContentArray(source, index);
|
|
2524
|
-
if (source[index] === "{") return parseStaticContentObject(source, index);
|
|
2532
|
+
function extractTailwindSourceForPostcssFallback(rawSource, options = {}) {
|
|
2533
|
+
const directives = [...extractTailwindDirectiveLines(rawSource, options), ...extractTailwindFallbackBlocks(rawSource)];
|
|
2534
|
+
return directives.length > 0 ? directives.join("\n") : void 0;
|
|
2525
2535
|
}
|
|
2526
|
-
function
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
return;
|
|
2536
|
+
function extractConfigRequestFromSource(rawSource) {
|
|
2537
|
+
for (const line of rawSource.split(/\r?\n/)) {
|
|
2538
|
+
const match = /^\s*@config\b([\s\S]*?)(?:;|$)/.exec(line);
|
|
2539
|
+
const request = match ? parseConfigRequest(match[1] ?? "") : void 0;
|
|
2540
|
+
if (request) return request;
|
|
2532
2541
|
}
|
|
2533
|
-
const contentProperty = findContentPropertyValue(source);
|
|
2534
|
-
if (!contentProperty) return;
|
|
2535
|
-
return parseStaticContentValue(source, contentProperty.start)?.value;
|
|
2536
2542
|
}
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
function parseImportSourceParam(params) {
|
|
2541
|
-
const match = /\bsource\(\s*(none|(['"])(.*?)\2)\s*\)/.exec(params);
|
|
2542
|
-
if (!match) return;
|
|
2543
|
-
return {
|
|
2544
|
-
none: match[1] === "none",
|
|
2545
|
-
sourcePath: match[3]
|
|
2546
|
-
};
|
|
2543
|
+
function resolveConfigPath$1(base, configPath) {
|
|
2544
|
+
if (node_path.default.isAbsolute(configPath) || isPackageJsonImportRequest$1(configPath)) return node_path.default.isAbsolute(configPath) ? configPath : void 0;
|
|
2545
|
+
return node_path.default.resolve(base, configPath);
|
|
2547
2546
|
}
|
|
2548
|
-
function
|
|
2549
|
-
return
|
|
2547
|
+
function hasPreprocessorOnlySyntax(rawSource) {
|
|
2548
|
+
return /(?:^|\n)\s*(?:\/\/|\$[\w-]+\s*:|@[\w-]+\s*:|@(?:mixin|include|function|use|forward)\b)/.test(rawSource);
|
|
2550
2549
|
}
|
|
2551
|
-
function
|
|
2552
|
-
return
|
|
2550
|
+
function normalizeTailwindSourceForGenerator(rawSource, options = {}) {
|
|
2551
|
+
return hasPreprocessorOnlySyntax(rawSource) ? extractTailwindSourceForPostcssFallback(rawSource, options) ?? rawSource : rawSource;
|
|
2553
2552
|
}
|
|
2554
|
-
function
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
if (configPath) configPaths.add(resolveConfigPath(base, configPath));
|
|
2571
|
-
});
|
|
2572
|
-
const entries = [];
|
|
2573
|
-
for (const configPath of configPaths) {
|
|
2574
|
-
const staticContent = readStaticConfigContent(configPath);
|
|
2575
|
-
if (staticContent !== void 0) {
|
|
2576
|
-
entries.push(...normalizeLegacyContentEntries(staticContent, node_path.default.dirname(configPath)));
|
|
2577
|
-
continue;
|
|
2578
|
-
}
|
|
2579
|
-
try {
|
|
2580
|
-
const loaded = await (0, tailwindcss_config.loadConfig)({
|
|
2581
|
-
config: configPath,
|
|
2582
|
-
cwd: node_path.default.dirname(configPath)
|
|
2583
|
-
});
|
|
2584
|
-
entries.push(...normalizeLegacyContentEntries(loaded?.config.content, node_path.default.dirname(configPath)));
|
|
2585
|
-
} catch {}
|
|
2553
|
+
function normalizeTailwindV3CssEntrySource(rawSource) {
|
|
2554
|
+
try {
|
|
2555
|
+
const root = require_watch_dependencies.postcss_default.parse(rawSource);
|
|
2556
|
+
let changed = false;
|
|
2557
|
+
root.walkAtRules("import", (node) => {
|
|
2558
|
+
const layer = TAILWIND_V3_SUBPATH_IMPORT_LAYERS.get(parseImportRequest(node.params) ?? "");
|
|
2559
|
+
if (!layer) return;
|
|
2560
|
+
node.replaceWith(require_watch_dependencies.postcss_default.atRule({
|
|
2561
|
+
name: "tailwind",
|
|
2562
|
+
params: layer
|
|
2563
|
+
}));
|
|
2564
|
+
changed = true;
|
|
2565
|
+
});
|
|
2566
|
+
return changed ? root.toString() : rawSource;
|
|
2567
|
+
} catch {
|
|
2568
|
+
return rawSource;
|
|
2586
2569
|
}
|
|
2587
|
-
return {
|
|
2588
|
-
dependencies: [...configPaths],
|
|
2589
|
-
entries
|
|
2590
|
-
};
|
|
2591
2570
|
}
|
|
2592
|
-
|
|
2593
|
-
|
|
2571
|
+
function normalizeTailwindSourceDirectives(rawSource, options = {}) {
|
|
2572
|
+
if (!options.importFallback) return rawSource;
|
|
2594
2573
|
try {
|
|
2595
|
-
root =
|
|
2574
|
+
const root = require_watch_dependencies.postcss_default.parse(rawSource);
|
|
2575
|
+
return normalizeTailwindImportAtRules(root, options) ? root.toString() : rawSource;
|
|
2596
2576
|
} catch {
|
|
2597
|
-
return;
|
|
2577
|
+
return extractTailwindSourceForPostcssFallback(rawSource, options) ?? rawSource;
|
|
2598
2578
|
}
|
|
2599
|
-
let importSourceBase;
|
|
2600
|
-
let hasSourceNone = false;
|
|
2601
|
-
let hasTailwindCssImport = false;
|
|
2602
|
-
const [sourceEntries, configEntries] = await Promise.all([resolveCssSourceEntries(root, base, VITE_SOURCE_CANDIDATE_PATTERN), resolveConfigContentEntries(root, base)]);
|
|
2603
|
-
const entries = [...configEntries.entries, ...sourceEntries];
|
|
2604
|
-
const hasPositiveEntries = entries.some((entry) => !entry.negated);
|
|
2605
|
-
const inlineCandidates = collectCssInlineSourceCandidates(root);
|
|
2606
|
-
root.walkAtRules("import", (rule) => {
|
|
2607
|
-
if (!isTailwindCssImport(rule.params)) return;
|
|
2608
|
-
hasTailwindCssImport = true;
|
|
2609
|
-
const sourceParam = parseImportSourceParam(rule.params);
|
|
2610
|
-
if (sourceParam?.none) hasSourceNone = true;
|
|
2611
|
-
if (sourceParam?.sourcePath) importSourceBase = resolveSourceBase(base, sourceParam.sourcePath);
|
|
2612
|
-
});
|
|
2613
|
-
if (importSourceBase) return {
|
|
2614
|
-
entries: [{
|
|
2615
|
-
base: importSourceBase,
|
|
2616
|
-
negated: false,
|
|
2617
|
-
pattern: VITE_SOURCE_CANDIDATE_PATTERN
|
|
2618
|
-
}, ...entries],
|
|
2619
|
-
explicit: true,
|
|
2620
|
-
inlineCandidates,
|
|
2621
|
-
dependencies: configEntries.dependencies
|
|
2622
|
-
};
|
|
2623
|
-
if (hasSourceNone) return {
|
|
2624
|
-
entries,
|
|
2625
|
-
explicit: true,
|
|
2626
|
-
inlineCandidates,
|
|
2627
|
-
dependencies: configEntries.dependencies
|
|
2628
|
-
};
|
|
2629
|
-
if (hasPositiveEntries) return {
|
|
2630
|
-
entries,
|
|
2631
|
-
explicit: true,
|
|
2632
|
-
inlineCandidates,
|
|
2633
|
-
dependencies: configEntries.dependencies
|
|
2634
|
-
};
|
|
2635
|
-
if (inlineCandidates.included.size > 0 || inlineCandidates.excluded.size > 0) return {
|
|
2636
|
-
entries: [],
|
|
2637
|
-
explicit: true,
|
|
2638
|
-
inlineCandidates,
|
|
2639
|
-
dependencies: configEntries.dependencies
|
|
2640
|
-
};
|
|
2641
|
-
return hasTailwindCssImport ? {
|
|
2642
|
-
entries,
|
|
2643
|
-
explicit: false,
|
|
2644
|
-
inlineCandidates,
|
|
2645
|
-
dependencies: configEntries.dependencies
|
|
2646
|
-
} : void 0;
|
|
2647
|
-
}
|
|
2648
|
-
//#endregion
|
|
2649
|
-
//#region src/tailwindcss/runtime/cache.ts
|
|
2650
|
-
const runtimeSignaturePatchersSymbol = Symbol.for("weapp-tailwindcss.runtimeSignaturePatchers");
|
|
2651
|
-
//#endregion
|
|
2652
|
-
//#region src/tailwindcss/runtime-patch.ts
|
|
2653
|
-
const debug$2 = createDebug("[tailwindcss:runtime-patch] ");
|
|
2654
|
-
const require$1 = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
2655
|
-
const runtimePatchPromiseCache = /* @__PURE__ */ new WeakMap();
|
|
2656
|
-
function getNestedPatchers(twPatcher) {
|
|
2657
|
-
const nested = twPatcher[runtimeSignaturePatchersSymbol];
|
|
2658
|
-
return Array.isArray(nested) && nested.length > 0 ? nested : void 0;
|
|
2659
|
-
}
|
|
2660
|
-
function shouldApplyRuntimePatch(twPatcher) {
|
|
2661
|
-
return twPatcher.majorVersion === 3 && typeof twPatcher.patch === "function";
|
|
2662
2579
|
}
|
|
2663
|
-
function
|
|
2664
|
-
|
|
2665
|
-
if (!rootPath) return;
|
|
2666
|
-
const normalizedRoot = node_path.default.resolve(rootPath);
|
|
2667
|
-
let count = 0;
|
|
2668
|
-
for (const id of Object.keys(require$1.cache)) {
|
|
2669
|
-
const normalizedId = node_path.default.resolve(id);
|
|
2670
|
-
if (normalizedId === normalizedRoot || normalizedId.startsWith(`${normalizedRoot}${node_path.default.sep}`)) {
|
|
2671
|
-
delete require$1.cache[id];
|
|
2672
|
-
count += 1;
|
|
2673
|
-
}
|
|
2674
|
-
}
|
|
2675
|
-
if (count > 0) debug$2("clear tailwindcss require cache after runtime patch, count=%d root=%s", count, normalizedRoot);
|
|
2580
|
+
function isTailwindImportRequest(request) {
|
|
2581
|
+
return request === "tailwindcss" || request === "tailwindcss4" || request?.startsWith("tailwindcss/") || request?.startsWith("tailwindcss4/");
|
|
2676
2582
|
}
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
if (
|
|
2680
|
-
|
|
2681
|
-
return;
|
|
2682
|
-
}
|
|
2683
|
-
if (!shouldApplyRuntimePatch(twPatcher)) return;
|
|
2684
|
-
const cached = runtimePatchPromiseCache.get(twPatcher);
|
|
2685
|
-
if (cached) {
|
|
2686
|
-
await cached;
|
|
2687
|
-
if (options.clearRequireCache) clearTailwindcssRequireCache(twPatcher);
|
|
2688
|
-
return;
|
|
2689
|
-
}
|
|
2690
|
-
const task = Promise.resolve().then(async () => {
|
|
2691
|
-
debug$2("apply tailwindcss runtime patch, package=%s version=%s root=%s", twPatcher.packageInfo?.name ?? "tailwindcss", twPatcher.packageInfo?.version ?? "unknown", twPatcher.packageInfo?.rootPath ?? "unknown");
|
|
2692
|
-
await twPatcher.patch?.();
|
|
2693
|
-
if (options.clearRequireCache) clearTailwindcssRequireCache(twPatcher);
|
|
2694
|
-
}).catch((error) => {
|
|
2695
|
-
runtimePatchPromiseCache.delete(twPatcher);
|
|
2696
|
-
throw error;
|
|
2697
|
-
});
|
|
2698
|
-
runtimePatchPromiseCache.set(twPatcher, task);
|
|
2699
|
-
return task;
|
|
2583
|
+
function isTailwindImportAtRule(node, options = {}) {
|
|
2584
|
+
if (node.name === "tailwind") return true;
|
|
2585
|
+
if (node.name !== "import" && node.name !== "use" && node.name !== "forward") return false;
|
|
2586
|
+
return isTailwindImportRequest(normalizeTailwindImportRequest(parseImportRequest(node.params), options));
|
|
2700
2587
|
}
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
const
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
});
|
|
2709
|
-
const MINI_PROGRAM_V3_PREFLIGHT_SELECTORS = new Set([
|
|
2710
|
-
"view,text,:before,:after",
|
|
2711
|
-
"view,text,:after,:before",
|
|
2712
|
-
"view,text,::before,::after",
|
|
2713
|
-
"view,text,::after,::before"
|
|
2714
|
-
]);
|
|
2715
|
-
const V3_PREFLIGHT_RESET_PROPS = new Set([
|
|
2716
|
-
"box-sizing",
|
|
2717
|
-
"border",
|
|
2718
|
-
"border-width",
|
|
2719
|
-
"border-style",
|
|
2720
|
-
"border-color",
|
|
2721
|
-
"margin",
|
|
2722
|
-
"padding"
|
|
2723
|
-
]);
|
|
2724
|
-
function normalizeSelector(selector) {
|
|
2725
|
-
return selector.trim().replace(/\s+/g, "");
|
|
2588
|
+
function isTailwindSourceDirective(node, options = {}) {
|
|
2589
|
+
if (node.type !== "atrule") return false;
|
|
2590
|
+
const atRule = node;
|
|
2591
|
+
if (isTailwindImportAtRule(atRule, options)) return true;
|
|
2592
|
+
if (atRule.name === "import" && isPackageJsonImportRequest$1(parseImportRequest(atRule.params))) return true;
|
|
2593
|
+
if (atRule.name === "layer") return !atRule.nodes || atRule.nodes.length === 0;
|
|
2594
|
+
return TAILWIND_REMOVABLE_SOURCE_DIRECTIVE_NAMES.has(atRule.name);
|
|
2726
2595
|
}
|
|
2727
|
-
function
|
|
2728
|
-
return
|
|
2596
|
+
function hasGeneratedCssArtifacts(rawSource) {
|
|
2597
|
+
return hasTailwindGeneratedCssMarkers(rawSource) && !GENERATOR_PLACEHOLDER_MARKER_RE.test(rawSource);
|
|
2729
2598
|
}
|
|
2730
|
-
function
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
return found;
|
|
2599
|
+
function isTailwindGenerationDirective(node, options = {}) {
|
|
2600
|
+
if (node.type !== "atrule") return false;
|
|
2601
|
+
const atRule = node;
|
|
2602
|
+
const request = atRule.name === "import" ? parseImportRequest(atRule.params) : atRule.name === "config" || atRule.name === "plugin" || atRule.name === "reference" ? parseConfigRequest(atRule.params) : void 0;
|
|
2603
|
+
return isTailwindImportAtRule(atRule, options) || isPackageJsonImportRequest$1(request) || atRule.name === "apply" || !options.ignoreLayer && atRule.name === "layer" || atRule.name === "config" || atRule.name === "source";
|
|
2736
2604
|
}
|
|
2737
|
-
function
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2605
|
+
function removeTailwindSourceDirectives(rawSource, options = {}) {
|
|
2606
|
+
try {
|
|
2607
|
+
const source = hasPreprocessorOnlySyntax(rawSource) ? extractTailwindSourceForPostcssFallback(rawSource, options) : stripGeneratorPlaceholderMarkers(rawSource);
|
|
2608
|
+
if (!source) return "";
|
|
2609
|
+
const root = require_watch_dependencies.postcss_default.parse(source);
|
|
2610
|
+
let removed = false;
|
|
2611
|
+
root.walk((node) => {
|
|
2612
|
+
if (isTailwindSourceDirective(node, options)) {
|
|
2613
|
+
node.remove();
|
|
2614
|
+
removed = true;
|
|
2615
|
+
}
|
|
2616
|
+
});
|
|
2617
|
+
return removed ? root.toString() : source;
|
|
2618
|
+
} catch {
|
|
2619
|
+
return stripGeneratorPlaceholderMarkers(rawSource);
|
|
2620
|
+
}
|
|
2743
2621
|
}
|
|
2744
|
-
function
|
|
2745
|
-
const declarations = createPreflightDeclarations(cssPreflight);
|
|
2746
|
-
if (declarations.length === 0) return css;
|
|
2622
|
+
function hasTailwindSourceDirectives(rawSource, options = {}) {
|
|
2747
2623
|
try {
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
let
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2624
|
+
if (GENERATOR_PLACEHOLDER_MARKER_RE.test(rawSource)) return true;
|
|
2625
|
+
const root = require_watch_dependencies.postcss_default.parse(rawSource);
|
|
2626
|
+
let found = false;
|
|
2627
|
+
const ignoreLayer = hasGeneratedCssArtifacts(rawSource);
|
|
2628
|
+
root.walk((node) => {
|
|
2629
|
+
if (isTailwindGenerationDirective(node, {
|
|
2630
|
+
...options,
|
|
2631
|
+
ignoreLayer
|
|
2632
|
+
})) {
|
|
2633
|
+
found = true;
|
|
2634
|
+
return false;
|
|
2635
|
+
}
|
|
2755
2636
|
});
|
|
2756
|
-
|
|
2757
|
-
targetRule.append(...declarations.map((decl) => decl.clone()));
|
|
2758
|
-
return root.toString();
|
|
2637
|
+
return found;
|
|
2759
2638
|
} catch {
|
|
2760
|
-
return
|
|
2639
|
+
return extractTailwindDirectiveLines(rawSource, options).length > 0;
|
|
2761
2640
|
}
|
|
2762
2641
|
}
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2642
|
+
function hasTailwindRootDirectives(rawSource, options = {}) {
|
|
2643
|
+
if (!TAILWIND_ROOT_DIRECTIVE_RE.test(rawSource) && !(options.importFallback && rawSource.includes("weapp-tailwindcss"))) return false;
|
|
2644
|
+
try {
|
|
2645
|
+
const root = require_watch_dependencies.postcss_default.parse(rawSource);
|
|
2646
|
+
let found = false;
|
|
2647
|
+
root.walkAtRules((node) => {
|
|
2648
|
+
const request = node.name === "import" ? parseImportRequest(node.params) : node.name === "config" || node.name === "plugin" ? parseConfigRequest(node.params) : void 0;
|
|
2649
|
+
if (isTailwindImportAtRule(node, options) || isPackageJsonImportRequest$1(request) || TAILWIND_ROOT_DIRECTIVE_NAMES.has(node.name)) {
|
|
2650
|
+
found = true;
|
|
2651
|
+
return false;
|
|
2652
|
+
}
|
|
2653
|
+
});
|
|
2654
|
+
return found;
|
|
2655
|
+
} catch {
|
|
2656
|
+
return extractTailwindDirectiveLines(rawSource, options).length > 0;
|
|
2657
|
+
}
|
|
2776
2658
|
}
|
|
2777
|
-
|
|
2778
|
-
if (
|
|
2779
|
-
|
|
2659
|
+
function hasTailwindApplyDirective(rawSource) {
|
|
2660
|
+
if (!rawSource.includes("@apply")) return false;
|
|
2661
|
+
try {
|
|
2662
|
+
const root = require_watch_dependencies.postcss_default.parse(rawSource);
|
|
2663
|
+
let found = false;
|
|
2664
|
+
root.walkAtRules("apply", () => {
|
|
2665
|
+
found = true;
|
|
2666
|
+
return false;
|
|
2667
|
+
});
|
|
2668
|
+
return found;
|
|
2669
|
+
} catch {
|
|
2670
|
+
return false;
|
|
2671
|
+
}
|
|
2672
|
+
}
|
|
2673
|
+
function resolveCssEntrySource(rawSource, base, options = {}) {
|
|
2674
|
+
try {
|
|
2675
|
+
const root = require_watch_dependencies.postcss_default.parse(rawSource);
|
|
2676
|
+
const normalizedImports = normalizeTailwindImportAtRules(root, options);
|
|
2677
|
+
let found = false;
|
|
2678
|
+
let config;
|
|
2679
|
+
let configRequest;
|
|
2680
|
+
let removedConfig = false;
|
|
2681
|
+
const removeConfig = options.removeConfig ?? true;
|
|
2682
|
+
const ignoreLayer = hasGeneratedCssArtifacts(rawSource);
|
|
2683
|
+
root.walk((node) => {
|
|
2684
|
+
if (isTailwindGenerationDirective(node, {
|
|
2685
|
+
...options,
|
|
2686
|
+
ignoreLayer
|
|
2687
|
+
})) found = true;
|
|
2688
|
+
if (node.type === "atrule" && node.name === "config") {
|
|
2689
|
+
const configPath = parseConfigRequest(node.params);
|
|
2690
|
+
if (configPath && !config) {
|
|
2691
|
+
configRequest = configPath;
|
|
2692
|
+
config = resolveConfigPath$1(base, configPath);
|
|
2693
|
+
}
|
|
2694
|
+
if (removeConfig) {
|
|
2695
|
+
node.remove();
|
|
2696
|
+
removedConfig = true;
|
|
2697
|
+
}
|
|
2698
|
+
}
|
|
2699
|
+
});
|
|
2700
|
+
if (!found) return;
|
|
2701
|
+
if (hasPreprocessorOnlySyntax(rawSource)) {
|
|
2702
|
+
const css = extractTailwindSourceForPostcssFallback(rawSource, {
|
|
2703
|
+
...options,
|
|
2704
|
+
removeConfig
|
|
2705
|
+
});
|
|
2706
|
+
if (css) return {
|
|
2707
|
+
css,
|
|
2708
|
+
config,
|
|
2709
|
+
configRequest,
|
|
2710
|
+
base
|
|
2711
|
+
};
|
|
2712
|
+
}
|
|
2713
|
+
return {
|
|
2714
|
+
css: removedConfig || normalizedImports ? root.toString() : rawSource,
|
|
2715
|
+
config,
|
|
2716
|
+
configRequest,
|
|
2717
|
+
base
|
|
2718
|
+
};
|
|
2719
|
+
} catch {
|
|
2720
|
+
const css = extractTailwindSourceForPostcssFallback(rawSource, options);
|
|
2721
|
+
const configRequest = extractConfigRequestFromSource(rawSource);
|
|
2722
|
+
const config = configRequest ? resolveConfigPath$1(base, configRequest) : void 0;
|
|
2723
|
+
return css ? {
|
|
2724
|
+
css,
|
|
2725
|
+
config,
|
|
2726
|
+
configRequest,
|
|
2727
|
+
base
|
|
2728
|
+
} : void 0;
|
|
2729
|
+
}
|
|
2780
2730
|
}
|
|
2781
2731
|
//#endregion
|
|
2782
|
-
//#region src/tailwindcss/
|
|
2783
|
-
const
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
return typeof value === "object" && value !== null && "files" in value;
|
|
2732
|
+
//#region src/tailwindcss/v4-engine/source.ts
|
|
2733
|
+
const require$2 = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
2734
|
+
function isCssEntryPoint(file) {
|
|
2735
|
+
return typeof file === "string" && node_path.default.basename(file) === "index.css" && (0, node_fs.existsSync)(file);
|
|
2787
2736
|
}
|
|
2788
|
-
function
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2737
|
+
function resolvePackageCssEntryPoint(specifier) {
|
|
2738
|
+
try {
|
|
2739
|
+
const resolved = require$2.resolve(specifier);
|
|
2740
|
+
if (isCssEntryPoint(resolved)) return resolved;
|
|
2741
|
+
} catch {}
|
|
2742
|
+
const packageName = specifier.replace(/\/index\.css$/, "");
|
|
2743
|
+
if (packageName !== "tailwindcss") return;
|
|
2744
|
+
try {
|
|
2745
|
+
const packageJson = require$2.resolve(`${packageName}/package.json`);
|
|
2746
|
+
const cssEntry = node_path.default.resolve(node_path.default.dirname(packageJson), "index.css");
|
|
2747
|
+
if (isCssEntryPoint(cssEntry)) return cssEntry;
|
|
2748
|
+
} catch {}
|
|
2749
|
+
try {
|
|
2750
|
+
let current = node_path.default.dirname(require$2.resolve("tailwindcss-patch"));
|
|
2751
|
+
while (true) {
|
|
2752
|
+
const cssEntry = node_path.default.resolve(current, "..", "tailwindcss", "index.css");
|
|
2753
|
+
if (isCssEntryPoint(cssEntry)) return cssEntry;
|
|
2754
|
+
const parent = node_path.default.dirname(current);
|
|
2755
|
+
if (parent === current) break;
|
|
2756
|
+
current = parent;
|
|
2757
|
+
}
|
|
2758
|
+
} catch {}
|
|
2800
2759
|
}
|
|
2801
|
-
function
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
extension: entry.extension
|
|
2805
|
-
}));
|
|
2760
|
+
function isPostcssPluginImportTarget(value) {
|
|
2761
|
+
if (!value) return false;
|
|
2762
|
+
return value === "@tailwindcss/postcss" || value.includes("/postcss");
|
|
2806
2763
|
}
|
|
2807
|
-
function
|
|
2808
|
-
return new Set(
|
|
2764
|
+
function uniqueDefined(values) {
|
|
2765
|
+
return [...new Set(values.filter((value) => typeof value === "string" && value.length > 0))];
|
|
2809
2766
|
}
|
|
2810
|
-
function
|
|
2811
|
-
return
|
|
2767
|
+
function getProjectRoot$1(patcher) {
|
|
2768
|
+
return patcher.options?.projectRoot ?? node_process.default.cwd();
|
|
2812
2769
|
}
|
|
2813
|
-
function
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2770
|
+
function resolveBase(value, fallback) {
|
|
2771
|
+
return value === void 0 ? fallback : node_path.default.isAbsolute(value) ? node_path.default.resolve(value) : node_path.default.resolve(fallback, value);
|
|
2772
|
+
}
|
|
2773
|
+
function resolveConfigDir(config, projectRoot) {
|
|
2774
|
+
if (!config) return;
|
|
2775
|
+
const configPath = node_path.default.isAbsolute(config) ? config : node_path.default.resolve(projectRoot, config);
|
|
2776
|
+
return node_path.default.dirname(configPath);
|
|
2777
|
+
}
|
|
2778
|
+
function isBarePackageSpecifier(specifier) {
|
|
2779
|
+
return !specifier.startsWith(".") && !specifier.startsWith("/") && !specifier.includes("\\") && !/^[a-z][a-z\d+.-]*:/i.test(specifier);
|
|
2780
|
+
}
|
|
2781
|
+
function parseCssImportSpecifier$1(params) {
|
|
2782
|
+
const value = params.trim();
|
|
2783
|
+
const quoted = /^(['"])(.*?)\1/.exec(value);
|
|
2784
|
+
if (quoted) {
|
|
2785
|
+
const specifier = quoted[2];
|
|
2786
|
+
if (specifier === void 0) return;
|
|
2787
|
+
return {
|
|
2788
|
+
quote: quoted[1],
|
|
2789
|
+
raw: quoted[0],
|
|
2790
|
+
specifier
|
|
2791
|
+
};
|
|
2820
2792
|
}
|
|
2793
|
+
const url = /^url\(\s*(?:(['"])(.*?)\1|([^'")\s]+))\s*\)/.exec(value);
|
|
2794
|
+
if (!url) return;
|
|
2795
|
+
const specifier = url[2] ?? url[3];
|
|
2796
|
+
if (specifier === void 0) return;
|
|
2821
2797
|
return {
|
|
2822
|
-
|
|
2823
|
-
|
|
2798
|
+
quote: url[1],
|
|
2799
|
+
raw: url[0],
|
|
2800
|
+
specifier
|
|
2824
2801
|
};
|
|
2825
2802
|
}
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
const candidates = /* @__PURE__ */ new Set();
|
|
2829
|
-
for (const source of sources ?? []) for (const candidate of await (0, tailwindcss_patch.extractSourceCandidates)(source.content, source.extension ?? "html", { bareArbitraryValues })) if ((0, tailwindcss_patch.resolveBareArbitraryValueCandidate)(candidate, bareArbitraryValues)) candidates.add(candidate);
|
|
2830
|
-
return [...candidates];
|
|
2803
|
+
function quoteCssImportSpecifier(specifier, quote = "\"") {
|
|
2804
|
+
return `${quote}${specifier.replaceAll("\\", "\\\\").replaceAll(quote, `\\${quote}`)}${quote}`;
|
|
2831
2805
|
}
|
|
2832
|
-
function
|
|
2833
|
-
|
|
2806
|
+
function createTailwindV4CssImportSpecifierSet(packageName) {
|
|
2807
|
+
const specifiers = new Set(["tailwindcss"]);
|
|
2808
|
+
if (packageName && isBarePackageSpecifier(packageName)) specifiers.add(packageName);
|
|
2809
|
+
return specifiers;
|
|
2834
2810
|
}
|
|
2835
|
-
function
|
|
2836
|
-
if (!
|
|
2837
|
-
let
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2811
|
+
function normalizeTailwindV4CssPackageImports(css, packageName) {
|
|
2812
|
+
if (!css.includes("tailwindcss")) return css;
|
|
2813
|
+
let root;
|
|
2814
|
+
try {
|
|
2815
|
+
root = require_watch_dependencies.postcss_default.parse(css);
|
|
2816
|
+
} catch {
|
|
2817
|
+
return css;
|
|
2841
2818
|
}
|
|
2842
|
-
|
|
2819
|
+
const importSpecifiers = createTailwindV4CssImportSpecifierSet(packageName);
|
|
2820
|
+
let changed = false;
|
|
2821
|
+
root.walkAtRules("import", (rule) => {
|
|
2822
|
+
const parsed = parseCssImportSpecifier$1(rule.params);
|
|
2823
|
+
if (!parsed || !importSpecifiers.has(parsed.specifier)) return;
|
|
2824
|
+
const cssEntryPoint = resolvePackageCssEntryPoint(`${parsed.specifier}/index.css`);
|
|
2825
|
+
if (!cssEntryPoint) return;
|
|
2826
|
+
rule.params = rule.params.replace(parsed.raw, quoteCssImportSpecifier(cssEntryPoint, parsed.quote));
|
|
2827
|
+
changed = true;
|
|
2828
|
+
});
|
|
2829
|
+
return changed ? root.toString() : css;
|
|
2843
2830
|
}
|
|
2844
|
-
function
|
|
2845
|
-
if (!
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2831
|
+
function normalizeTailwindV4CssSources(cssSources, packageName) {
|
|
2832
|
+
if (!cssSources?.length) return cssSources;
|
|
2833
|
+
let changed = false;
|
|
2834
|
+
const normalizedCssSources = cssSources.map((cssSource) => {
|
|
2835
|
+
if (typeof cssSource.css !== "string") return cssSource;
|
|
2836
|
+
const css = normalizeTailwindV4CssPackageImports(cssSource.css, packageName);
|
|
2837
|
+
if (css === cssSource.css) return cssSource;
|
|
2838
|
+
changed = true;
|
|
2839
|
+
return {
|
|
2840
|
+
...cssSource,
|
|
2841
|
+
css
|
|
2842
|
+
};
|
|
2843
|
+
});
|
|
2844
|
+
return changed ? normalizedCssSources : cssSources;
|
|
2845
|
+
}
|
|
2846
|
+
function normalizeTailwindV4CssEntrySources(cssEntries, packageName) {
|
|
2847
|
+
if (!cssEntries?.length) return;
|
|
2848
|
+
const remainingCssEntries = [];
|
|
2849
|
+
const cssSources = [];
|
|
2850
|
+
for (const cssEntry of cssEntries) {
|
|
2851
|
+
const file = node_path.default.resolve(cssEntry);
|
|
2852
|
+
if (!(0, node_fs.existsSync)(file)) {
|
|
2853
|
+
remainingCssEntries.push(cssEntry);
|
|
2854
|
+
continue;
|
|
2852
2855
|
}
|
|
2856
|
+
const base = node_path.default.dirname(file);
|
|
2857
|
+
const rawCss = (0, node_fs.readFileSync)(file, "utf8");
|
|
2858
|
+
const css = normalizeTailwindV4CssPackageImports(normalizeConfigDirective(rawCss, resolveCssEntrySource(rawCss, base, { removeConfig: false })?.config), packageName);
|
|
2859
|
+
cssSources.push({
|
|
2860
|
+
file,
|
|
2861
|
+
base,
|
|
2862
|
+
css,
|
|
2863
|
+
dependencies: [file]
|
|
2864
|
+
});
|
|
2853
2865
|
}
|
|
2854
|
-
return
|
|
2866
|
+
return {
|
|
2867
|
+
cssEntries: remainingCssEntries,
|
|
2868
|
+
cssSources
|
|
2869
|
+
};
|
|
2855
2870
|
}
|
|
2856
|
-
function
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2871
|
+
function normalizeTailwindV4SourceOptions(options) {
|
|
2872
|
+
if (!options) return options;
|
|
2873
|
+
const css = options.css === void 0 ? void 0 : normalizeTailwindV4CssPackageImports(options.css, options.packageName);
|
|
2874
|
+
const entrySources = normalizeTailwindV4CssEntrySources(options.cssEntries, options.packageName);
|
|
2875
|
+
const cssSources = normalizeTailwindV4CssSources(options.cssSources || entrySources?.cssSources ? [...options.cssSources ?? [], ...entrySources?.cssSources ?? []] : void 0, options.packageName);
|
|
2876
|
+
const cssEntries = entrySources?.cssEntries ?? options.cssEntries;
|
|
2877
|
+
if (css === options.css && cssSources === options.cssSources && cssEntries === options.cssEntries) return options;
|
|
2878
|
+
return {
|
|
2879
|
+
...options,
|
|
2880
|
+
...css === void 0 ? {} : { css },
|
|
2881
|
+
...cssEntries === void 0 ? {} : { cssEntries },
|
|
2882
|
+
...cssSources === void 0 ? {} : { cssSources }
|
|
2883
|
+
};
|
|
2860
2884
|
}
|
|
2861
|
-
function
|
|
2862
|
-
|
|
2863
|
-
return
|
|
2885
|
+
function resolveTailwindCssImportTarget(patcher) {
|
|
2886
|
+
const configuredPackageName = resolveTailwindcssOptions(patcher.options)?.packageName;
|
|
2887
|
+
if (typeof configuredPackageName === "string" && configuredPackageName.length > 0 && !isPostcssPluginImportTarget(configuredPackageName)) return configuredPackageName;
|
|
2888
|
+
const packageName = patcher.packageInfo?.name;
|
|
2889
|
+
if (typeof packageName === "string" && packageName.length > 0 && !isPostcssPluginImportTarget(packageName)) return packageName;
|
|
2890
|
+
return "tailwindcss";
|
|
2864
2891
|
}
|
|
2865
|
-
function
|
|
2866
|
-
|
|
2867
|
-
const candidates = /* @__PURE__ */ new Set();
|
|
2868
|
-
try {
|
|
2869
|
-
require_runtime_registry.postcss_default.parse(css).walkAtRules("apply", (rule) => {
|
|
2870
|
-
for (const candidate of rule.params.split(/\s+/)) {
|
|
2871
|
-
const normalized = candidate.replace(/!important$/, "").trim();
|
|
2872
|
-
if (normalized) candidates.add(normalized);
|
|
2873
|
-
}
|
|
2874
|
-
});
|
|
2875
|
-
} catch {}
|
|
2876
|
-
return [...candidates];
|
|
2892
|
+
function readTailwindV4Options(patcher) {
|
|
2893
|
+
return resolveTailwindcssOptions(patcher.options)?.v4 ?? patcher.options?.tailwind?.v4;
|
|
2877
2894
|
}
|
|
2878
|
-
function
|
|
2879
|
-
return
|
|
2895
|
+
function isRawTailwindcssPatchOptions(options) {
|
|
2896
|
+
return Boolean(options && "tailwindcss" in options);
|
|
2880
2897
|
}
|
|
2881
|
-
function
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
}
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2898
|
+
function resolvePatchTailwindV4SourceOptions(patcher) {
|
|
2899
|
+
if (patcher.options) {
|
|
2900
|
+
const projectRoot = getProjectRoot$1(patcher);
|
|
2901
|
+
const tailwindOptions = resolveTailwindcssOptions(patcher.options);
|
|
2902
|
+
const tailwindV4Options = readTailwindV4Options(patcher);
|
|
2903
|
+
const cwd = resolveBase(tailwindOptions?.cwd, projectRoot);
|
|
2904
|
+
const configuredBase = tailwindV4Options?.configuredBase ?? (isRawTailwindcssPatchOptions(patcher.options) ? tailwindV4Options?.base : void 0);
|
|
2905
|
+
const baseFallbacks = uniqueDefined([
|
|
2906
|
+
configuredBase,
|
|
2907
|
+
cwd,
|
|
2908
|
+
projectRoot,
|
|
2909
|
+
resolveConfigDir(tailwindOptions?.config, projectRoot)
|
|
2910
|
+
]);
|
|
2911
|
+
return {
|
|
2912
|
+
projectRoot,
|
|
2913
|
+
cwd,
|
|
2914
|
+
...configuredBase === void 0 ? {} : { base: configuredBase },
|
|
2915
|
+
baseFallbacks,
|
|
2916
|
+
...tailwindV4Options?.css === void 0 ? {} : { css: tailwindV4Options.css },
|
|
2917
|
+
...tailwindV4Options?.cssSources === void 0 ? {} : { cssSources: tailwindV4Options.cssSources },
|
|
2918
|
+
...tailwindV4Options?.cssEntries === void 0 ? {} : { cssEntries: tailwindV4Options.cssEntries },
|
|
2919
|
+
packageName: resolveTailwindCssImportTarget(patcher)
|
|
2920
|
+
};
|
|
2904
2921
|
}
|
|
2905
|
-
}
|
|
2906
|
-
function collectLayerCandidatesFromCss(css) {
|
|
2907
|
-
if (!css.includes("@layer")) return [];
|
|
2908
|
-
const candidates = /* @__PURE__ */ new Set();
|
|
2909
|
-
try {
|
|
2910
|
-
require_runtime_registry.postcss_default.parse(css).walkAtRules("layer", (layer) => {
|
|
2911
|
-
if (!isTailwindCandidateLayer(layer.params)) return;
|
|
2912
|
-
layer.walkRules((rule) => {
|
|
2913
|
-
extractClassCandidatesFromSelector(rule.selector, candidates);
|
|
2914
|
-
});
|
|
2915
|
-
});
|
|
2916
|
-
} catch {}
|
|
2917
|
-
return [...candidates];
|
|
2918
|
-
}
|
|
2919
|
-
function mergeGenerateCandidates(source, options) {
|
|
2920
|
-
return collectCandidates([
|
|
2921
|
-
...collectLayerCandidatesFromCss(source.css),
|
|
2922
|
-
...collectApplyCandidatesFromCss(source.css),
|
|
2923
|
-
...collectCandidates(options.candidates)
|
|
2924
|
-
]);
|
|
2925
|
-
}
|
|
2926
|
-
function mergeContent(content, rawEntries) {
|
|
2927
|
-
if (isLegacyContentObject(content)) return {
|
|
2928
|
-
...content,
|
|
2929
|
-
relative: content.relative ?? true,
|
|
2930
|
-
files: [...[].concat(content.files ?? []), ...rawEntries]
|
|
2931
|
-
};
|
|
2932
|
-
return {
|
|
2933
|
-
relative: true,
|
|
2934
|
-
files: [...[].concat(content ?? []), ...rawEntries]
|
|
2935
|
-
};
|
|
2936
|
-
}
|
|
2937
|
-
function normalizeConfigObject(config) {
|
|
2938
|
-
if (!config || typeof config !== "object") return config;
|
|
2939
|
-
const maybeDefault = config.default;
|
|
2940
|
-
if (maybeDefault && typeof maybeDefault === "object") return maybeDefault;
|
|
2941
|
-
return config;
|
|
2942
|
-
}
|
|
2943
|
-
function hasExplicitContentInput(options) {
|
|
2944
|
-
return options.candidates !== void 0 || options.sources !== void 0;
|
|
2945
|
-
}
|
|
2946
|
-
function createExplicitContentConfig(rawEntries) {
|
|
2947
2922
|
return {
|
|
2948
|
-
|
|
2949
|
-
|
|
2923
|
+
projectRoot: getProjectRoot$1(patcher),
|
|
2924
|
+
packageName: resolveTailwindCssImportTarget(patcher)
|
|
2950
2925
|
};
|
|
2951
2926
|
}
|
|
2952
|
-
function
|
|
2953
|
-
const
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2927
|
+
function resolveTailwindV4SourceOptionsFromPatcher(patcher) {
|
|
2928
|
+
const tailwindV4Options = readTailwindV4Options(patcher);
|
|
2929
|
+
return omitUndefined({
|
|
2930
|
+
...resolvePatchTailwindV4SourceOptions(patcher),
|
|
2931
|
+
sources: tailwindV4Options?.sources
|
|
2932
|
+
});
|
|
2957
2933
|
}
|
|
2958
|
-
function
|
|
2959
|
-
return
|
|
2934
|
+
function resolveTailwindV4Source(options) {
|
|
2935
|
+
return (0, tailwindcss_patch.resolveTailwindV4Source)(normalizeTailwindV4SourceOptions(options));
|
|
2960
2936
|
}
|
|
2961
|
-
function
|
|
2962
|
-
return
|
|
2937
|
+
async function resolveTailwindV4SourceFromPatcher(patcher) {
|
|
2938
|
+
return resolveTailwindV4Source(resolveTailwindV4SourceOptionsFromPatcher(patcher));
|
|
2963
2939
|
}
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2940
|
+
//#endregion
|
|
2941
|
+
//#region src/bundlers/vite/static-config-content.ts
|
|
2942
|
+
function skipWhitespaceAndComments(source, start) {
|
|
2943
|
+
let index = start;
|
|
2944
|
+
while (index < source.length) {
|
|
2945
|
+
const char = source[index];
|
|
2946
|
+
if (/\s/.test(char ?? "")) {
|
|
2947
|
+
index += 1;
|
|
2948
|
+
continue;
|
|
2972
2949
|
}
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
const generateRulesModule = requireTailwind(`${source.packageName}/lib/lib/generateRules`);
|
|
2978
|
-
const sharedStateModule = requireTailwind(`${source.packageName}/lib/lib/sharedState`);
|
|
2979
|
-
const setupContextUtils = requireTailwind(`${source.packageName}/lib/lib/setupContextUtils`);
|
|
2980
|
-
const processTailwindFeaturesModule = requireTailwind(`${source.packageName}/lib/processTailwindFeatures`);
|
|
2981
|
-
const resolveDefaultsAtRulesModule = requireTailwind(`${source.packageName}/lib/lib/resolveDefaultsAtRules`);
|
|
2982
|
-
const resolveConfigModule = requireTailwind(`${source.packageName}/lib/public/resolve-config`);
|
|
2983
|
-
const validateConfigModule = requireTailwind(`${source.packageName}/lib/util/validateConfig.js`);
|
|
2984
|
-
return {
|
|
2985
|
-
collapseAdjacentRules: collapseAdjacentRulesModule["default"] ?? collapseAdjacentRulesModule,
|
|
2986
|
-
collapseDuplicateDeclarations: collapseDuplicateDeclarationsModule["default"] ?? collapseDuplicateDeclarationsModule,
|
|
2987
|
-
createContext: setupContextUtils["createContext"],
|
|
2988
|
-
escapeClassName: escapeClassNameModule["default"] ?? escapeClassNameModule,
|
|
2989
|
-
generateRules: generateRulesModule["generateRules"],
|
|
2990
|
-
notOnDemandCandidate: String(sharedStateModule["NOT_ON_DEMAND"] ?? "*"),
|
|
2991
|
-
processTailwindFeatures: processTailwindFeaturesModule["default"] ?? processTailwindFeaturesModule,
|
|
2992
|
-
resolveDefaultsAtRules: resolveDefaultsAtRulesModule["default"] ?? resolveDefaultsAtRulesModule,
|
|
2993
|
-
resolveConfig: resolveConfigModule["default"] ?? resolveConfigModule,
|
|
2994
|
-
validateConfig: validateConfigModule["validateConfig"]
|
|
2995
|
-
};
|
|
2996
|
-
}
|
|
2997
|
-
function createStableJson$1(value) {
|
|
2998
|
-
if (value === void 0) return "undefined";
|
|
2999
|
-
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
3000
|
-
if (Array.isArray(value)) return `[${value.map((item) => createStableJson$1(item)).join(",")}]`;
|
|
3001
|
-
return `{${Object.keys(value).sort().map((key) => {
|
|
3002
|
-
const record = value;
|
|
3003
|
-
return `${JSON.stringify(key)}:${createStableJson$1(record[key])}`;
|
|
3004
|
-
}).join(",")}}`;
|
|
3005
|
-
}
|
|
3006
|
-
function createDependencyFingerprint(files) {
|
|
3007
|
-
return files.map((file) => {
|
|
3008
|
-
try {
|
|
3009
|
-
const stat = node_fs.default.statSync(file);
|
|
3010
|
-
return `${file}:${stat.size}:${stat.mtimeMs}`;
|
|
3011
|
-
} catch {
|
|
3012
|
-
return `${file}:missing`;
|
|
2950
|
+
if (char === "/" && source[index + 1] === "/") {
|
|
2951
|
+
index += 2;
|
|
2952
|
+
while (index < source.length && source[index] !== "\n") index += 1;
|
|
2953
|
+
continue;
|
|
3013
2954
|
}
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
source.config ?? "config:missing",
|
|
3022
|
-
createDependencyFingerprint(source.dependencies),
|
|
3023
|
-
source.css,
|
|
3024
|
-
createStableJson$1(normalizeConfigObject(source.configObject)?.content),
|
|
3025
|
-
target,
|
|
3026
|
-
createStableJson$1(styleOptions),
|
|
3027
|
-
createStableJson$1(bareArbitraryValues)
|
|
3028
|
-
].join("\0");
|
|
3029
|
-
}
|
|
3030
|
-
function createRuntimeReadyCacheKey(source, rootPath) {
|
|
3031
|
-
return [
|
|
3032
|
-
source.packageName,
|
|
3033
|
-
source.postcssPlugin,
|
|
3034
|
-
rootPath ?? "missing",
|
|
3035
|
-
source.config ?? "config:missing",
|
|
3036
|
-
source.cwd
|
|
3037
|
-
].join("\0");
|
|
3038
|
-
}
|
|
3039
|
-
function isDirectUtilitiesOnlyCss(css) {
|
|
3040
|
-
return css.replace(/\s+/g, "") === "@tailwindutilities;";
|
|
3041
|
-
}
|
|
3042
|
-
function collectClassSet(context) {
|
|
3043
|
-
const classSet = /* @__PURE__ */ new Set();
|
|
3044
|
-
for (const candidate of context.classCache.keys()) if (String(candidate) !== "*") classSet.add(candidate);
|
|
3045
|
-
return classSet;
|
|
3046
|
-
}
|
|
3047
|
-
function collectDependencyMessages(result) {
|
|
3048
|
-
const dependencies = /* @__PURE__ */ new Set();
|
|
3049
|
-
for (const message of result.messages) {
|
|
3050
|
-
const file = message["file"];
|
|
3051
|
-
if (message["type"] === "dependency" && typeof file === "string") dependencies.add(file);
|
|
2955
|
+
if (char === "/" && source[index + 1] === "*") {
|
|
2956
|
+
index += 2;
|
|
2957
|
+
while (index < source.length && !(source[index] === "*" && source[index + 1] === "/")) index += 1;
|
|
2958
|
+
index = Math.min(index + 2, source.length);
|
|
2959
|
+
continue;
|
|
2960
|
+
}
|
|
2961
|
+
break;
|
|
3052
2962
|
}
|
|
3053
|
-
return
|
|
3054
|
-
}
|
|
3055
|
-
function sortCandidates(candidates) {
|
|
3056
|
-
return [...candidates].sort((a, z) => {
|
|
3057
|
-
if (a === z) return 0;
|
|
3058
|
-
return a < z ? -1 : 1;
|
|
3059
|
-
});
|
|
2963
|
+
return index;
|
|
3060
2964
|
}
|
|
3061
|
-
function
|
|
3062
|
-
const
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
2965
|
+
function readQuotedString(source, start) {
|
|
2966
|
+
const quote = source[start];
|
|
2967
|
+
if (quote !== "\"" && quote !== "'") return;
|
|
2968
|
+
let value = "";
|
|
2969
|
+
for (let index = start + 1; index < source.length; index++) {
|
|
2970
|
+
const char = source[index];
|
|
2971
|
+
if (char === "\\") {
|
|
2972
|
+
const next = source[index + 1];
|
|
2973
|
+
if (next === void 0) return;
|
|
2974
|
+
value += next;
|
|
2975
|
+
index += 1;
|
|
2976
|
+
continue;
|
|
2977
|
+
}
|
|
2978
|
+
if (char === quote) return {
|
|
2979
|
+
end: index + 1,
|
|
2980
|
+
value
|
|
2981
|
+
};
|
|
2982
|
+
value += char;
|
|
3066
2983
|
}
|
|
3067
2984
|
}
|
|
3068
|
-
function
|
|
3069
|
-
|
|
2985
|
+
function readIdentifier(source, start) {
|
|
2986
|
+
return /^[A-Z_$][\w$]*/i.exec(source.slice(start))?.[0];
|
|
3070
2987
|
}
|
|
3071
|
-
function
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
postcssPlugin: source.postcssPlugin,
|
|
3080
|
-
version: 3
|
|
2988
|
+
function findMatchingBracket(source, start, open, close) {
|
|
2989
|
+
let depth = 0;
|
|
2990
|
+
let quote;
|
|
2991
|
+
for (let index = start; index < source.length; index++) {
|
|
2992
|
+
const char = source[index];
|
|
2993
|
+
if (char === "\\") {
|
|
2994
|
+
index += 1;
|
|
2995
|
+
continue;
|
|
3081
2996
|
}
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
2997
|
+
if (quote) {
|
|
2998
|
+
if (char === quote) quote = void 0;
|
|
2999
|
+
continue;
|
|
3000
|
+
}
|
|
3001
|
+
if (char === "\"" || char === "'") {
|
|
3002
|
+
quote = char;
|
|
3003
|
+
continue;
|
|
3004
|
+
}
|
|
3005
|
+
if (char === "`") return;
|
|
3006
|
+
if (char === open) {
|
|
3007
|
+
depth += 1;
|
|
3008
|
+
continue;
|
|
3009
|
+
}
|
|
3010
|
+
if (char === close) {
|
|
3011
|
+
depth -= 1;
|
|
3012
|
+
if (depth === 0) return index;
|
|
3013
|
+
}
|
|
3014
|
+
}
|
|
3092
3015
|
}
|
|
3093
|
-
function
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
const
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
}
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3016
|
+
function findContentPropertyValue(source) {
|
|
3017
|
+
let index = 0;
|
|
3018
|
+
while (index < source.length) {
|
|
3019
|
+
const nextIndex = source.indexOf("content", index);
|
|
3020
|
+
if (nextIndex === -1) return;
|
|
3021
|
+
const previous = source[nextIndex - 1];
|
|
3022
|
+
const next = source[nextIndex + 7];
|
|
3023
|
+
if (previous && /[\w$]/.test(previous) || next && /[\w$]/.test(next)) {
|
|
3024
|
+
index = nextIndex + 7;
|
|
3025
|
+
continue;
|
|
3026
|
+
}
|
|
3027
|
+
let colonIndex = skipWhitespaceAndComments(source, nextIndex + 7);
|
|
3028
|
+
if (source[colonIndex] !== ":") {
|
|
3029
|
+
index = nextIndex + 7;
|
|
3030
|
+
continue;
|
|
3031
|
+
}
|
|
3032
|
+
colonIndex = skipWhitespaceAndComments(source, colonIndex + 1);
|
|
3033
|
+
return { start: colonIndex };
|
|
3034
|
+
}
|
|
3035
|
+
}
|
|
3036
|
+
function parseStaticContentArray(source, start) {
|
|
3037
|
+
if (source[start] !== "[") return;
|
|
3038
|
+
const value = [];
|
|
3039
|
+
let index = skipWhitespaceAndComments(source, start + 1);
|
|
3040
|
+
while (index < source.length) {
|
|
3041
|
+
if (source[index] === "]") return {
|
|
3042
|
+
end: index + 1,
|
|
3043
|
+
value
|
|
3116
3044
|
};
|
|
3117
|
-
|
|
3118
|
-
if (
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3045
|
+
const parsed = parseStaticContentValue(source, index);
|
|
3046
|
+
if (!parsed) return;
|
|
3047
|
+
value.push(parsed.value);
|
|
3048
|
+
index = skipWhitespaceAndComments(source, parsed.end);
|
|
3049
|
+
if (source[index] === ",") {
|
|
3050
|
+
index = skipWhitespaceAndComments(source, index + 1);
|
|
3051
|
+
continue;
|
|
3052
|
+
}
|
|
3053
|
+
if (source[index] === "]") continue;
|
|
3054
|
+
return;
|
|
3055
|
+
}
|
|
3056
|
+
}
|
|
3057
|
+
function parseStaticContentObject(source, start) {
|
|
3058
|
+
if (source[start] !== "{") return;
|
|
3059
|
+
const end = findMatchingBracket(source, start, "{", "}");
|
|
3060
|
+
if (end === void 0) return;
|
|
3061
|
+
let index = skipWhitespaceAndComments(source, start + 1);
|
|
3062
|
+
let files;
|
|
3063
|
+
while (index < end) {
|
|
3064
|
+
let key;
|
|
3065
|
+
const quotedKey = readQuotedString(source, index);
|
|
3066
|
+
if (quotedKey) {
|
|
3067
|
+
key = quotedKey.value;
|
|
3068
|
+
index = quotedKey.end;
|
|
3126
3069
|
} else {
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
context = await internals.processTailwindFeatures(setupContext)(root, result);
|
|
3070
|
+
key = readIdentifier(source, index);
|
|
3071
|
+
if (!key) return;
|
|
3072
|
+
index += key.length;
|
|
3131
3073
|
}
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
sources: [],
|
|
3145
|
-
root: null,
|
|
3146
|
-
target,
|
|
3147
|
-
version: 3
|
|
3148
|
-
};
|
|
3074
|
+
index = skipWhitespaceAndComments(source, index);
|
|
3075
|
+
if (source[index] !== ":") return;
|
|
3076
|
+
index = skipWhitespaceAndComments(source, index + 1);
|
|
3077
|
+
const parsedValue = parseStaticContentValue(source, index);
|
|
3078
|
+
if (!parsedValue) return;
|
|
3079
|
+
if (key === "files") files = parsedValue.value;
|
|
3080
|
+
index = skipWhitespaceAndComments(source, parsedValue.end);
|
|
3081
|
+
if (source[index] === ",") {
|
|
3082
|
+
index = skipWhitespaceAndComments(source, index + 1);
|
|
3083
|
+
continue;
|
|
3084
|
+
}
|
|
3085
|
+
if (index < end) return;
|
|
3149
3086
|
}
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
classSet: collectGeneratedCandidates(context, sortedCandidates, normalizedCandidates.restoreCandidates),
|
|
3169
|
-
dependencies: collectDependencyMessages(result)
|
|
3170
|
-
};
|
|
3087
|
+
return files === void 0 ? void 0 : {
|
|
3088
|
+
end: end + 1,
|
|
3089
|
+
value: { files }
|
|
3090
|
+
};
|
|
3091
|
+
}
|
|
3092
|
+
function parseStaticContentValue(source, start) {
|
|
3093
|
+
const index = skipWhitespaceAndComments(source, start);
|
|
3094
|
+
const quoted = readQuotedString(source, index);
|
|
3095
|
+
if (quoted) return quoted;
|
|
3096
|
+
if (source[index] === "[") return parseStaticContentArray(source, index);
|
|
3097
|
+
if (source[index] === "{") return parseStaticContentObject(source, index);
|
|
3098
|
+
}
|
|
3099
|
+
function readStaticConfigContent(configPath) {
|
|
3100
|
+
let source;
|
|
3101
|
+
try {
|
|
3102
|
+
source = (0, node_fs.readFileSync)(configPath, "utf8");
|
|
3103
|
+
} catch {
|
|
3104
|
+
return;
|
|
3171
3105
|
}
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
incrementalCss: generated.css,
|
|
3218
|
-
incrementalRawCss: generated.rawCss,
|
|
3219
|
-
classSet: new Set(cached.classSet),
|
|
3220
|
-
rawCandidates: new Set(cached.seenCandidates),
|
|
3221
|
-
dependencies: cached.dependencies,
|
|
3222
|
-
sources: [],
|
|
3223
|
-
root: null,
|
|
3224
|
-
target: cached.target,
|
|
3225
|
-
version: 3
|
|
3226
|
-
};
|
|
3106
|
+
const contentProperty = findContentPropertyValue(source);
|
|
3107
|
+
if (!contentProperty) return;
|
|
3108
|
+
return parseStaticContentValue(source, contentProperty.start)?.value;
|
|
3109
|
+
}
|
|
3110
|
+
//#endregion
|
|
3111
|
+
//#region src/bundlers/vite/source-scan.ts
|
|
3112
|
+
const VITE_SOURCE_CANDIDATE_PATTERN = FULL_SOURCE_SCAN_PATTERN;
|
|
3113
|
+
function parseImportSourceParam(params) {
|
|
3114
|
+
const match = /\bsource\(\s*(none|(['"])(.*?)\2)\s*\)/.exec(params);
|
|
3115
|
+
if (!match) return;
|
|
3116
|
+
return {
|
|
3117
|
+
none: match[1] === "none",
|
|
3118
|
+
sourcePath: match[3]
|
|
3119
|
+
};
|
|
3120
|
+
}
|
|
3121
|
+
function parseCssImportSpecifier(params) {
|
|
3122
|
+
const value = params.trim();
|
|
3123
|
+
const quoted = /^(['"])(.*?)\1/.exec(value);
|
|
3124
|
+
if (quoted) return quoted[2];
|
|
3125
|
+
const url = /^url\(\s*(?:(['"])(.*?)\1|([^'")\s]+))\s*\)/.exec(value);
|
|
3126
|
+
return url?.[2] ?? url?.[3];
|
|
3127
|
+
}
|
|
3128
|
+
function isTailwindCssImport(params) {
|
|
3129
|
+
const specifier = parseCssImportSpecifier(params);
|
|
3130
|
+
return specifier === "tailwindcss" || specifier?.startsWith("tailwindcss/") || specifier?.replaceAll("\\", "/").endsWith("/tailwindcss/index.css");
|
|
3131
|
+
}
|
|
3132
|
+
function resolveSourceBase(base, sourcePath) {
|
|
3133
|
+
return node_path.default.isAbsolute(sourcePath) ? sourcePath : node_path.default.resolve(base, sourcePath);
|
|
3134
|
+
}
|
|
3135
|
+
function resolveConfigPath(base, configPath) {
|
|
3136
|
+
if (node_path.default.isAbsolute(configPath)) return node_path.default.resolve(configPath);
|
|
3137
|
+
return node_path.default.resolve(base, configPath);
|
|
3138
|
+
}
|
|
3139
|
+
async function resolveConfigContentEntries(root, base) {
|
|
3140
|
+
const configPaths = /* @__PURE__ */ new Set();
|
|
3141
|
+
root.walkAtRules("config", (rule) => {
|
|
3142
|
+
const configPath = parseConfigParam$1(rule.params);
|
|
3143
|
+
if (configPath) configPaths.add(resolveConfigPath(base, configPath));
|
|
3144
|
+
});
|
|
3145
|
+
const entries = [];
|
|
3146
|
+
for (const configPath of configPaths) {
|
|
3147
|
+
const staticContent = readStaticConfigContent(configPath);
|
|
3148
|
+
if (staticContent !== void 0) {
|
|
3149
|
+
entries.push(...normalizeLegacyContentEntries(staticContent, node_path.default.dirname(configPath), { relativeBase: node_path.default.dirname(configPath) }));
|
|
3150
|
+
continue;
|
|
3227
3151
|
}
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3152
|
+
try {
|
|
3153
|
+
const loaded = await (0, tailwindcss_config.loadConfig)({
|
|
3154
|
+
config: configPath,
|
|
3155
|
+
cwd: node_path.default.dirname(configPath)
|
|
3156
|
+
});
|
|
3157
|
+
entries.push(...normalizeLegacyContentEntries(loaded?.config.content, node_path.default.dirname(configPath), { relativeBase: node_path.default.dirname(configPath) }));
|
|
3158
|
+
} catch {}
|
|
3159
|
+
}
|
|
3160
|
+
return {
|
|
3161
|
+
dependencies: [...configPaths],
|
|
3162
|
+
entries
|
|
3163
|
+
};
|
|
3164
|
+
}
|
|
3165
|
+
async function resolveTailwindV4EntriesFromCss(css, base) {
|
|
3166
|
+
let root;
|
|
3167
|
+
try {
|
|
3168
|
+
root = require_watch_dependencies.postcss_default.parse(css);
|
|
3169
|
+
} catch {
|
|
3170
|
+
return;
|
|
3171
|
+
}
|
|
3172
|
+
let importSourceBase;
|
|
3173
|
+
let hasSourceNone = false;
|
|
3174
|
+
let hasTailwindCssImport = false;
|
|
3175
|
+
const [sourceEntries, configEntries] = await Promise.all([resolveCssSourceEntries(root, base, VITE_SOURCE_CANDIDATE_PATTERN), resolveConfigContentEntries(root, base)]);
|
|
3176
|
+
const entries = [...configEntries.entries, ...sourceEntries];
|
|
3177
|
+
const hasPositiveEntries = entries.some((entry) => !entry.negated);
|
|
3178
|
+
const inlineCandidates = collectCssInlineSourceCandidates(root);
|
|
3179
|
+
root.walkAtRules("import", (rule) => {
|
|
3180
|
+
if (!isTailwindCssImport(rule.params)) return;
|
|
3181
|
+
hasTailwindCssImport = true;
|
|
3182
|
+
const sourceParam = parseImportSourceParam(rule.params);
|
|
3183
|
+
if (sourceParam?.none) hasSourceNone = true;
|
|
3184
|
+
if (sourceParam?.sourcePath) importSourceBase = resolveSourceBase(base, sourceParam.sourcePath);
|
|
3185
|
+
});
|
|
3186
|
+
if (importSourceBase) return {
|
|
3187
|
+
entries: [{
|
|
3188
|
+
base: importSourceBase,
|
|
3189
|
+
negated: false,
|
|
3190
|
+
pattern: VITE_SOURCE_CANDIDATE_PATTERN
|
|
3191
|
+
}, ...entries],
|
|
3192
|
+
explicit: true,
|
|
3193
|
+
inlineCandidates,
|
|
3194
|
+
dependencies: configEntries.dependencies
|
|
3195
|
+
};
|
|
3196
|
+
if (hasSourceNone) return {
|
|
3197
|
+
entries,
|
|
3198
|
+
explicit: true,
|
|
3199
|
+
inlineCandidates,
|
|
3200
|
+
dependencies: configEntries.dependencies
|
|
3201
|
+
};
|
|
3202
|
+
if (hasPositiveEntries) return {
|
|
3203
|
+
entries,
|
|
3204
|
+
explicit: true,
|
|
3205
|
+
inlineCandidates,
|
|
3206
|
+
dependencies: configEntries.dependencies
|
|
3207
|
+
};
|
|
3208
|
+
if (inlineCandidates.included.size > 0 || inlineCandidates.excluded.size > 0) return {
|
|
3209
|
+
entries: [],
|
|
3210
|
+
explicit: true,
|
|
3211
|
+
inlineCandidates,
|
|
3212
|
+
dependencies: configEntries.dependencies
|
|
3213
|
+
};
|
|
3214
|
+
return hasTailwindCssImport ? {
|
|
3215
|
+
entries,
|
|
3216
|
+
explicit: false,
|
|
3217
|
+
inlineCandidates,
|
|
3218
|
+
dependencies: configEntries.dependencies
|
|
3219
|
+
} : void 0;
|
|
3220
|
+
}
|
|
3221
|
+
//#endregion
|
|
3222
|
+
//#region src/tailwindcss/runtime/cache.ts
|
|
3223
|
+
const runtimeSignaturePatchersSymbol = Symbol.for("weapp-tailwindcss.runtimeSignaturePatchers");
|
|
3224
|
+
//#endregion
|
|
3225
|
+
//#region src/tailwindcss/runtime-patch.ts
|
|
3226
|
+
const debug$2 = createDebug("[tailwindcss:runtime-patch] ");
|
|
3227
|
+
const require$1 = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
3228
|
+
const runtimePatchPromiseCache = /* @__PURE__ */ new WeakMap();
|
|
3229
|
+
function getNestedPatchers(twPatcher) {
|
|
3230
|
+
const nested = twPatcher[runtimeSignaturePatchersSymbol];
|
|
3231
|
+
return Array.isArray(nested) && nested.length > 0 ? nested : void 0;
|
|
3232
|
+
}
|
|
3233
|
+
function shouldApplyRuntimePatch(twPatcher) {
|
|
3234
|
+
return twPatcher.majorVersion === 3 && typeof twPatcher.patch === "function";
|
|
3235
|
+
}
|
|
3236
|
+
function clearTailwindcssRequireCache(twPatcher) {
|
|
3237
|
+
const rootPath = twPatcher.packageInfo?.rootPath;
|
|
3238
|
+
if (!rootPath) return;
|
|
3239
|
+
const normalizedRoot = node_path.default.resolve(rootPath);
|
|
3240
|
+
let count = 0;
|
|
3241
|
+
for (const id of Object.keys(require$1.cache)) {
|
|
3242
|
+
const normalizedId = node_path.default.resolve(id);
|
|
3243
|
+
if (normalizedId === normalizedRoot || normalizedId.startsWith(`${normalizedRoot}${node_path.default.sep}`)) {
|
|
3244
|
+
delete require$1.cache[id];
|
|
3245
|
+
count += 1;
|
|
3246
|
+
}
|
|
3247
|
+
}
|
|
3248
|
+
if (count > 0) debug$2("clear tailwindcss require cache after runtime patch, count=%d root=%s", count, normalizedRoot);
|
|
3249
|
+
}
|
|
3250
|
+
async function ensureTailwindcssRuntimePatch(twPatcher, options = {}) {
|
|
3251
|
+
const nestedPatchers = getNestedPatchers(twPatcher);
|
|
3252
|
+
if (nestedPatchers) {
|
|
3253
|
+
await Promise.all(nestedPatchers.map((patcher) => ensureTailwindcssRuntimePatch(patcher)));
|
|
3254
|
+
return;
|
|
3239
3255
|
}
|
|
3240
|
-
|
|
3241
|
-
|
|
3256
|
+
if (!shouldApplyRuntimePatch(twPatcher)) return;
|
|
3257
|
+
const cached = runtimePatchPromiseCache.get(twPatcher);
|
|
3258
|
+
if (cached) {
|
|
3259
|
+
await cached;
|
|
3260
|
+
if (options.clearRequireCache) clearTailwindcssRequireCache(twPatcher);
|
|
3261
|
+
return;
|
|
3242
3262
|
}
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
};
|
|
3263
|
+
const task = Promise.resolve().then(async () => {
|
|
3264
|
+
debug$2("apply tailwindcss runtime patch, package=%s version=%s root=%s", twPatcher.packageInfo?.name ?? "tailwindcss", twPatcher.packageInfo?.version ?? "unknown", twPatcher.packageInfo?.rootPath ?? "unknown");
|
|
3265
|
+
await twPatcher.patch?.();
|
|
3266
|
+
if (options.clearRequireCache) clearTailwindcssRequireCache(twPatcher);
|
|
3267
|
+
}).catch((error) => {
|
|
3268
|
+
runtimePatchPromiseCache.delete(twPatcher);
|
|
3269
|
+
throw error;
|
|
3270
|
+
});
|
|
3271
|
+
runtimePatchPromiseCache.set(twPatcher, task);
|
|
3272
|
+
return task;
|
|
3254
3273
|
}
|
|
3255
3274
|
//#endregion
|
|
3256
|
-
//#region src/tailwindcss/v3-engine/
|
|
3257
|
-
const
|
|
3258
|
-
"
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3275
|
+
//#region src/tailwindcss/v3-engine/miniprogram.ts
|
|
3276
|
+
const defaultStyleHandler = (0, _weapp_tailwindcss_postcss.createStyleHandler)({
|
|
3277
|
+
cssChildCombinatorReplaceValue: ["view", "text"],
|
|
3278
|
+
cssRemoveHoverPseudoClass: true,
|
|
3279
|
+
isMainChunk: true,
|
|
3280
|
+
majorVersion: 3
|
|
3281
|
+
});
|
|
3282
|
+
const MINI_PROGRAM_V3_PREFLIGHT_SELECTORS = new Set([
|
|
3283
|
+
"view,text,:before,:after",
|
|
3284
|
+
"view,text,:after,:before",
|
|
3285
|
+
"view,text,::before,::after",
|
|
3286
|
+
"view,text,::after,::before"
|
|
3287
|
+
]);
|
|
3288
|
+
const V3_PREFLIGHT_RESET_PROPS = new Set([
|
|
3289
|
+
"box-sizing",
|
|
3290
|
+
"border",
|
|
3291
|
+
"border-width",
|
|
3292
|
+
"border-style",
|
|
3293
|
+
"border-color",
|
|
3294
|
+
"margin",
|
|
3295
|
+
"padding"
|
|
3296
|
+
]);
|
|
3297
|
+
function normalizeSelector(selector) {
|
|
3298
|
+
return selector.trim().replace(/\s+/g, "");
|
|
3265
3299
|
}
|
|
3266
|
-
function
|
|
3267
|
-
|
|
3268
|
-
return node_path.default.isAbsolute(value) ? value : node_path.default.resolve(base, value);
|
|
3300
|
+
function isMiniProgramV3PreflightRule(rule) {
|
|
3301
|
+
return MINI_PROGRAM_V3_PREFLIGHT_SELECTORS.has(normalizeSelector(rule.selector));
|
|
3269
3302
|
}
|
|
3270
|
-
function
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
};
|
|
3275
|
-
const root = require_runtime_registry.postcss_default.parse(css);
|
|
3276
|
-
let config;
|
|
3277
|
-
root.walkAtRules("config", (rule) => {
|
|
3278
|
-
const configPath = parseConfigParam(rule.params);
|
|
3279
|
-
if (!configPath) return;
|
|
3280
|
-
if (!config) config = resolveOptionalPath(configPath, base);
|
|
3281
|
-
rule.remove();
|
|
3303
|
+
function hasResetDeclaration(rule) {
|
|
3304
|
+
let found = false;
|
|
3305
|
+
rule.walkDecls((decl) => {
|
|
3306
|
+
if (V3_PREFLIGHT_RESET_PROPS.has(decl.prop)) found = true;
|
|
3282
3307
|
});
|
|
3283
|
-
return
|
|
3284
|
-
|
|
3285
|
-
|
|
3308
|
+
return found;
|
|
3309
|
+
}
|
|
3310
|
+
function createPreflightDeclarations(cssPreflight) {
|
|
3311
|
+
if (!cssPreflight || typeof cssPreflight !== "object") return [];
|
|
3312
|
+
return Object.entries(cssPreflight).filter((entry) => entry[1] !== false).map(([prop, value]) => require_watch_dependencies.postcss_default.decl({
|
|
3313
|
+
prop,
|
|
3314
|
+
value: value.toString()
|
|
3315
|
+
}));
|
|
3316
|
+
}
|
|
3317
|
+
function ensureMiniProgramV3PreflightReset(css, cssPreflight) {
|
|
3318
|
+
const declarations = createPreflightDeclarations(cssPreflight);
|
|
3319
|
+
if (declarations.length === 0) return css;
|
|
3320
|
+
try {
|
|
3321
|
+
const root = require_watch_dependencies.postcss_default.parse(css);
|
|
3322
|
+
let targetRule;
|
|
3323
|
+
let hasReset = false;
|
|
3324
|
+
root.walkRules((rule) => {
|
|
3325
|
+
if (!isMiniProgramV3PreflightRule(rule)) return;
|
|
3326
|
+
targetRule ??= rule;
|
|
3327
|
+
if (hasResetDeclaration(rule)) hasReset = true;
|
|
3328
|
+
});
|
|
3329
|
+
if (!targetRule || hasReset) return css;
|
|
3330
|
+
targetRule.append(...declarations.map((decl) => decl.clone()));
|
|
3331
|
+
return root.toString();
|
|
3332
|
+
} catch {
|
|
3333
|
+
return css;
|
|
3334
|
+
}
|
|
3335
|
+
}
|
|
3336
|
+
async function transformTailwindV3CssToWeapp(css, options) {
|
|
3337
|
+
const result = await defaultStyleHandler(hasCssMacroStyleOptions(options) ? await transformCssMacroCss(css, options) : css, {
|
|
3338
|
+
cssChildCombinatorReplaceValue: ["view", "text"],
|
|
3339
|
+
cssRemoveHoverPseudoClass: true,
|
|
3340
|
+
isMainChunk: true,
|
|
3341
|
+
majorVersion: 3,
|
|
3342
|
+
...options
|
|
3343
|
+
});
|
|
3344
|
+
const pruneOptions = {
|
|
3345
|
+
preservePreflight: true,
|
|
3346
|
+
preserveConditionalComments: hasCssMacroStyleOptions(options)
|
|
3286
3347
|
};
|
|
3348
|
+
return ensureMiniProgramV3PreflightReset((0, _weapp_tailwindcss_postcss.pruneMiniProgramGeneratedCss)(result.css, pruneOptions), options?.cssPreflight);
|
|
3287
3349
|
}
|
|
3288
|
-
function
|
|
3289
|
-
|
|
3350
|
+
async function transformTailwindV3CssByTarget(css, target, options) {
|
|
3351
|
+
if (target === "weapp") return transformTailwindV3CssToWeapp(css, options);
|
|
3352
|
+
return hasCssMacroStyleOptions(options) ? transformCssMacroCss(css, options) : css;
|
|
3290
3353
|
}
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3354
|
+
//#endregion
|
|
3355
|
+
//#region src/tailwindcss/v3-engine/generator.ts
|
|
3356
|
+
const runtimeReadyPromiseCache = /* @__PURE__ */ new Map();
|
|
3357
|
+
const incrementalGenerateCache = /* @__PURE__ */ new Map();
|
|
3358
|
+
function isLegacyContentObject(value) {
|
|
3359
|
+
return typeof value === "object" && value !== null && "files" in value;
|
|
3296
3360
|
}
|
|
3297
|
-
function
|
|
3298
|
-
|
|
3361
|
+
function createRawContentEntries(candidates, sources) {
|
|
3362
|
+
const entries = [];
|
|
3363
|
+
const candidateContent = [...candidates].join(" ");
|
|
3364
|
+
if (candidateContent.length > 0) entries.push({
|
|
3365
|
+
raw: candidateContent,
|
|
3366
|
+
extension: "html"
|
|
3367
|
+
});
|
|
3368
|
+
for (const source of sources) entries.push({
|
|
3369
|
+
raw: source.content,
|
|
3370
|
+
extension: source.extension ?? "html"
|
|
3371
|
+
});
|
|
3372
|
+
return entries;
|
|
3299
3373
|
}
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
const config = resolveOptionalPath(options.config, base) ?? cssConfig.config;
|
|
3305
|
-
const cwd = options.cwd ?? (config ? node_path.default.dirname(config) : projectRoot);
|
|
3306
|
-
const loaded = await (0, tailwindcss_config.loadConfig)(omitUndefined({
|
|
3307
|
-
config,
|
|
3308
|
-
cwd
|
|
3374
|
+
function createChangedContentEntries(candidates, sources) {
|
|
3375
|
+
return createRawContentEntries(candidates, sources).map((entry) => ({
|
|
3376
|
+
content: entry.raw,
|
|
3377
|
+
extension: entry.extension
|
|
3309
3378
|
}));
|
|
3310
|
-
return {
|
|
3311
|
-
version: 3,
|
|
3312
|
-
projectRoot,
|
|
3313
|
-
cwd,
|
|
3314
|
-
base,
|
|
3315
|
-
css: cssConfig.css ?? options.css ?? DEFAULT_TAILWIND_V3_CSS,
|
|
3316
|
-
config: loaded?.filepath ?? config,
|
|
3317
|
-
configObject: normalizeLoadedConfig(loaded?.config),
|
|
3318
|
-
dependencies: loaded?.filepath ? [loaded.filepath] : [],
|
|
3319
|
-
packageName: options.packageName ?? "tailwindcss",
|
|
3320
|
-
postcssPlugin: options.postcssPlugin ?? options.packageName ?? "tailwindcss"
|
|
3321
|
-
};
|
|
3322
3379
|
}
|
|
3323
|
-
function
|
|
3324
|
-
|
|
3325
|
-
|
|
3380
|
+
function collectCandidates(candidates) {
|
|
3381
|
+
return new Set(candidates ?? []);
|
|
3382
|
+
}
|
|
3383
|
+
function normalizeBareArbitraryValueCandidate(candidate, bareArbitraryValues) {
|
|
3384
|
+
return (0, tailwindcss_patch.resolveBareArbitraryValueCandidate)(candidate, bareArbitraryValues)?.canonicalCandidate ?? candidate;
|
|
3385
|
+
}
|
|
3386
|
+
function normalizeBareArbitraryValueCandidates(candidates, bareArbitraryValues) {
|
|
3387
|
+
const normalized = /* @__PURE__ */ new Set();
|
|
3388
|
+
const restoreCandidates = /* @__PURE__ */ new Map();
|
|
3389
|
+
for (const candidate of candidates) {
|
|
3390
|
+
const normalizedCandidate = normalizeBareArbitraryValueCandidate(candidate, bareArbitraryValues);
|
|
3391
|
+
normalized.add(normalizedCandidate);
|
|
3392
|
+
if (normalizedCandidate !== candidate) restoreCandidates.set(normalizedCandidate, candidate);
|
|
3393
|
+
}
|
|
3326
3394
|
return {
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
config: tailwindOptions?.v3?.config ?? tailwindOptions?.config,
|
|
3330
|
-
packageName: resolveTailwindCssPackageName(patcher),
|
|
3331
|
-
postcssPlugin: tailwindOptions?.v3?.postcssPlugin ?? tailwindOptions?.postcssPlugin
|
|
3395
|
+
candidates: normalized,
|
|
3396
|
+
restoreCandidates
|
|
3332
3397
|
};
|
|
3333
3398
|
}
|
|
3334
|
-
function
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
const explicitGeneratorTargetEnvKeys = ["WEAPP_TW_TARGET", "WEAPP_TAILWINDCSS_TARGET"];
|
|
3340
|
-
const uniWebPlatformEnvKeys = ["UNI_PLATFORM", "UNI_UTS_PLATFORM"];
|
|
3341
|
-
const mpxWebPlatformEnvKeys = ["MPX_CLI_MODE", "MPX_CURRENT_TARGET_MODE"];
|
|
3342
|
-
function getEnvValue(key) {
|
|
3343
|
-
return typeof node_process.default === "undefined" ? void 0 : node_process.default.env[key];
|
|
3399
|
+
async function collectSourceBareArbitraryValueCandidates(sources, bareArbitraryValues) {
|
|
3400
|
+
if (!(0, tailwindcss_patch.isBareArbitraryValuesEnabled)(bareArbitraryValues)) return [];
|
|
3401
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
3402
|
+
for (const source of sources ?? []) for (const candidate of await (0, tailwindcss_patch.extractSourceCandidates)(source.content, source.extension ?? "html", { bareArbitraryValues })) if ((0, tailwindcss_patch.resolveBareArbitraryValueCandidate)(candidate, bareArbitraryValues)) candidates.add(candidate);
|
|
3403
|
+
return [...candidates];
|
|
3344
3404
|
}
|
|
3345
|
-
function
|
|
3346
|
-
return
|
|
3405
|
+
function escapeCssClassSelector(className) {
|
|
3406
|
+
return className.replace(/[^\w-]/g, (char) => `\\${char}`);
|
|
3347
3407
|
}
|
|
3348
|
-
function
|
|
3349
|
-
|
|
3350
|
-
|
|
3408
|
+
function restoreBareArbitraryValueCssSelectors(css, originalCandidates, bareArbitraryValues, escapeClassName) {
|
|
3409
|
+
if (!(0, tailwindcss_patch.isBareArbitraryValuesEnabled)(bareArbitraryValues)) return css;
|
|
3410
|
+
let restored = css;
|
|
3411
|
+
for (const originalCandidate of originalCandidates) {
|
|
3412
|
+
const canonical = (0, tailwindcss_patch.resolveBareArbitraryValueCandidate)(originalCandidate, bareArbitraryValues)?.canonicalCandidate;
|
|
3413
|
+
if (canonical) restored = restored.split(`.${escapeClassName(canonical)}`).join(`.${escapeCssClassSelector(originalCandidate)}`);
|
|
3414
|
+
}
|
|
3415
|
+
return restored;
|
|
3351
3416
|
}
|
|
3352
|
-
function
|
|
3353
|
-
|
|
3354
|
-
|
|
3417
|
+
function restoreBareArbitraryValueClassSet(classSet, originalCandidates, bareArbitraryValues) {
|
|
3418
|
+
if (!(0, tailwindcss_patch.isBareArbitraryValuesEnabled)(bareArbitraryValues)) return new Set(classSet);
|
|
3419
|
+
const restored = new Set(classSet);
|
|
3420
|
+
for (const originalCandidate of originalCandidates) {
|
|
3421
|
+
const canonical = (0, tailwindcss_patch.resolveBareArbitraryValueCandidate)(originalCandidate, bareArbitraryValues)?.canonicalCandidate;
|
|
3422
|
+
if (canonical && restored.has(canonical)) {
|
|
3423
|
+
restored.delete(canonical);
|
|
3424
|
+
restored.add(originalCandidate);
|
|
3425
|
+
}
|
|
3426
|
+
}
|
|
3427
|
+
return restored;
|
|
3355
3428
|
}
|
|
3356
|
-
function
|
|
3357
|
-
|
|
3429
|
+
function collectGeneratedCandidates(context, candidates, restoreCandidates) {
|
|
3430
|
+
const classSet = /* @__PURE__ */ new Set();
|
|
3431
|
+
for (const candidate of candidates) if (context.classCache.has(candidate)) classSet.add(restoreCandidates.get(candidate) ?? candidate);
|
|
3432
|
+
return classSet;
|
|
3358
3433
|
}
|
|
3359
|
-
function
|
|
3360
|
-
|
|
3434
|
+
function hasRemovedCandidates(previousCandidates, nextCandidates) {
|
|
3435
|
+
for (const candidate of previousCandidates) if (!nextCandidates.has(candidate)) return true;
|
|
3436
|
+
return false;
|
|
3361
3437
|
}
|
|
3362
|
-
function
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3438
|
+
function collectApplyCandidatesFromCss(css) {
|
|
3439
|
+
if (!css.includes("@apply")) return [];
|
|
3440
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
3441
|
+
try {
|
|
3442
|
+
require_watch_dependencies.postcss_default.parse(css).walkAtRules("apply", (rule) => {
|
|
3443
|
+
for (const candidate of rule.params.split(/\s+/)) {
|
|
3444
|
+
const normalized = candidate.replace(/!important$/, "").trim();
|
|
3445
|
+
if (normalized) candidates.add(normalized);
|
|
3446
|
+
}
|
|
3447
|
+
});
|
|
3448
|
+
} catch {}
|
|
3449
|
+
return [...candidates];
|
|
3369
3450
|
}
|
|
3370
|
-
function
|
|
3371
|
-
|
|
3372
|
-
if (options == null) return {
|
|
3373
|
-
target,
|
|
3374
|
-
importFallback: true,
|
|
3375
|
-
tailwindcssV3Compatibility: target === "weapp",
|
|
3376
|
-
bareArbitraryValues: void 0
|
|
3377
|
-
};
|
|
3378
|
-
return {
|
|
3379
|
-
target,
|
|
3380
|
-
config: options.config,
|
|
3381
|
-
styleOptions: options.styleOptions,
|
|
3382
|
-
importFallback: options.importFallback ?? true,
|
|
3383
|
-
tailwindcssV3Compatibility: options.tailwindcssV3Compatibility ?? target === "weapp",
|
|
3384
|
-
bareArbitraryValues: options.bareArbitraryValues
|
|
3385
|
-
};
|
|
3451
|
+
function isTailwindCandidateLayer(params) {
|
|
3452
|
+
return params.split(/[,\s]+/).some((layer) => layer === "components" || layer === "utilities");
|
|
3386
3453
|
}
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3454
|
+
function extractClassCandidatesFromSelector(selector, candidates) {
|
|
3455
|
+
for (let index = 0; index < selector.length; index++) {
|
|
3456
|
+
if (selector[index] !== ".") continue;
|
|
3457
|
+
let candidate = "";
|
|
3458
|
+
let escaped = false;
|
|
3459
|
+
for (let tokenIndex = index + 1; tokenIndex < selector.length; tokenIndex++) {
|
|
3460
|
+
const char = selector[tokenIndex];
|
|
3461
|
+
if (escaped) {
|
|
3462
|
+
candidate += char;
|
|
3463
|
+
escaped = false;
|
|
3464
|
+
continue;
|
|
3465
|
+
}
|
|
3466
|
+
if (char === "\\") {
|
|
3467
|
+
escaped = true;
|
|
3468
|
+
continue;
|
|
3469
|
+
}
|
|
3470
|
+
if (char && /[\w-]/.test(char)) {
|
|
3471
|
+
candidate += char;
|
|
3472
|
+
continue;
|
|
3473
|
+
}
|
|
3474
|
+
break;
|
|
3475
|
+
}
|
|
3476
|
+
if (candidate) candidates.add(candidate);
|
|
3477
|
+
}
|
|
3391
3478
|
}
|
|
3392
|
-
function
|
|
3393
|
-
|
|
3479
|
+
function collectLayerCandidatesFromCss(css) {
|
|
3480
|
+
if (!css.includes("@layer")) return [];
|
|
3481
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
3482
|
+
try {
|
|
3483
|
+
require_watch_dependencies.postcss_default.parse(css).walkAtRules("layer", (layer) => {
|
|
3484
|
+
if (!isTailwindCandidateLayer(layer.params)) return;
|
|
3485
|
+
layer.walkRules((rule) => {
|
|
3486
|
+
extractClassCandidatesFromSelector(rule.selector, candidates);
|
|
3487
|
+
});
|
|
3488
|
+
});
|
|
3489
|
+
} catch {}
|
|
3490
|
+
return [...candidates];
|
|
3394
3491
|
}
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
const TAILWIND_BANNER_PREFIX_RE = /^\/\*!\s*tailwindcss v[^*]*\*\/\s*/i;
|
|
3402
|
-
const TAILWIND_BANNER_RE = /\/\*!\s*tailwindcss v[^*]*\*\//i;
|
|
3403
|
-
const TAILWIND_BANNER_GLOBAL_RE = /\/\*!\s*tailwindcss v[^*]*\*\/\s*/gi;
|
|
3404
|
-
const VITE_MARKER_RE = /\/\*\$vite\$:[^*]*\*\//g;
|
|
3405
|
-
function createCssAppend(base, extra) {
|
|
3406
|
-
if (!base) return extra;
|
|
3407
|
-
if (!extra) return base;
|
|
3408
|
-
return `${base}\n${extra}`;
|
|
3492
|
+
function mergeGenerateCandidates(source, options) {
|
|
3493
|
+
return collectCandidates([
|
|
3494
|
+
...collectLayerCandidatesFromCss(source.css),
|
|
3495
|
+
...collectApplyCandidatesFromCss(source.css),
|
|
3496
|
+
...collectCandidates(options.candidates)
|
|
3497
|
+
]);
|
|
3409
3498
|
}
|
|
3410
|
-
function
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
after: ""
|
|
3416
|
-
};
|
|
3417
|
-
if (trimmedTailwind.startsWith(trimmedRaw)) return {
|
|
3418
|
-
before: "",
|
|
3419
|
-
after: ""
|
|
3499
|
+
function mergeContent(content, rawEntries) {
|
|
3500
|
+
if (isLegacyContentObject(content)) return {
|
|
3501
|
+
...content,
|
|
3502
|
+
relative: content.relative ?? true,
|
|
3503
|
+
files: [...[].concat(content.files ?? []), ...rawEntries]
|
|
3420
3504
|
};
|
|
3421
|
-
const start = rawSource.indexOf(rawTailwindCss);
|
|
3422
|
-
if (start === -1) return;
|
|
3423
3505
|
return {
|
|
3424
|
-
|
|
3425
|
-
|
|
3506
|
+
relative: true,
|
|
3507
|
+
files: [...[].concat(content ?? []), ...rawEntries]
|
|
3426
3508
|
};
|
|
3427
3509
|
}
|
|
3428
|
-
function
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
if (rawTailwindCss && rawSource.slice(afterStart).startsWith(rawTailwindCss)) {
|
|
3434
|
-
afterStart += rawTailwindCss.length;
|
|
3435
|
-
while (/\s/.test(rawSource[afterStart] ?? "")) afterStart++;
|
|
3436
|
-
}
|
|
3437
|
-
return {
|
|
3438
|
-
before: rawSource.slice(0, match.index),
|
|
3439
|
-
after: rawSource.slice(afterStart)
|
|
3440
|
-
};
|
|
3510
|
+
function normalizeConfigObject(config) {
|
|
3511
|
+
if (!config || typeof config !== "object") return config;
|
|
3512
|
+
const maybeDefault = config.default;
|
|
3513
|
+
if (maybeDefault && typeof maybeDefault === "object") return maybeDefault;
|
|
3514
|
+
return config;
|
|
3441
3515
|
}
|
|
3442
|
-
function
|
|
3443
|
-
|
|
3444
|
-
|
|
3516
|
+
function hasExplicitContentInput(options) {
|
|
3517
|
+
return options.candidates !== void 0 || options.sources !== void 0;
|
|
3518
|
+
}
|
|
3519
|
+
function createExplicitContentConfig(rawEntries) {
|
|
3445
3520
|
return {
|
|
3446
|
-
|
|
3447
|
-
|
|
3521
|
+
relative: true,
|
|
3522
|
+
files: rawEntries
|
|
3448
3523
|
};
|
|
3449
3524
|
}
|
|
3450
|
-
function
|
|
3451
|
-
|
|
3525
|
+
function createTailwindConfig(source, options) {
|
|
3526
|
+
const config = { ...normalizeConfigObject(source.configObject) ?? {} };
|
|
3527
|
+
const rawEntries = createRawContentEntries(mergeGenerateCandidates(source, options), options.sources ?? []);
|
|
3528
|
+
config.content = hasExplicitContentInput(options) ? createExplicitContentConfig(rawEntries) : mergeContent(config.content, rawEntries);
|
|
3529
|
+
return config;
|
|
3452
3530
|
}
|
|
3453
|
-
function
|
|
3454
|
-
return
|
|
3531
|
+
function shouldAutoEnableCssMacro(source) {
|
|
3532
|
+
return hasCssMacroTailwindPlugin(normalizeConfigObject(source.configObject)?.plugins);
|
|
3455
3533
|
}
|
|
3456
|
-
function
|
|
3457
|
-
return
|
|
3534
|
+
function resolveStyleOptions(source, options) {
|
|
3535
|
+
return shouldAutoEnableCssMacro(source) ? withCssMacroStyleOptions(options) : options;
|
|
3458
3536
|
}
|
|
3459
|
-
function
|
|
3460
|
-
|
|
3537
|
+
function loadTailwindV3Internals(source) {
|
|
3538
|
+
const requireFromProject = (0, node_module.createRequire)(`${source.cwd}/package.json`);
|
|
3539
|
+
const requireFromRuntime = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
3540
|
+
const requireTailwind = (id) => {
|
|
3541
|
+
try {
|
|
3542
|
+
return requireFromProject(id);
|
|
3543
|
+
} catch {
|
|
3544
|
+
return requireFromRuntime(id);
|
|
3545
|
+
}
|
|
3546
|
+
};
|
|
3547
|
+
const collapseAdjacentRulesModule = requireTailwind(`${source.packageName}/lib/lib/collapseAdjacentRules`);
|
|
3548
|
+
const collapseDuplicateDeclarationsModule = requireTailwind(`${source.packageName}/lib/lib/collapseDuplicateDeclarations`);
|
|
3549
|
+
const escapeClassNameModule = requireTailwind(`${source.packageName}/lib/util/escapeClassName`);
|
|
3550
|
+
const generateRulesModule = requireTailwind(`${source.packageName}/lib/lib/generateRules`);
|
|
3551
|
+
const sharedStateModule = requireTailwind(`${source.packageName}/lib/lib/sharedState`);
|
|
3552
|
+
const setupContextUtils = requireTailwind(`${source.packageName}/lib/lib/setupContextUtils`);
|
|
3553
|
+
const processTailwindFeaturesModule = requireTailwind(`${source.packageName}/lib/processTailwindFeatures`);
|
|
3554
|
+
const resolveDefaultsAtRulesModule = requireTailwind(`${source.packageName}/lib/lib/resolveDefaultsAtRules`);
|
|
3555
|
+
const resolveConfigModule = requireTailwind(`${source.packageName}/lib/public/resolve-config`);
|
|
3556
|
+
const validateConfigModule = requireTailwind(`${source.packageName}/lib/util/validateConfig.js`);
|
|
3557
|
+
return {
|
|
3558
|
+
collapseAdjacentRules: collapseAdjacentRulesModule["default"] ?? collapseAdjacentRulesModule,
|
|
3559
|
+
collapseDuplicateDeclarations: collapseDuplicateDeclarationsModule["default"] ?? collapseDuplicateDeclarationsModule,
|
|
3560
|
+
createContext: setupContextUtils["createContext"],
|
|
3561
|
+
escapeClassName: escapeClassNameModule["default"] ?? escapeClassNameModule,
|
|
3562
|
+
generateRules: generateRulesModule["generateRules"],
|
|
3563
|
+
notOnDemandCandidate: String(sharedStateModule["NOT_ON_DEMAND"] ?? "*"),
|
|
3564
|
+
processTailwindFeatures: processTailwindFeaturesModule["default"] ?? processTailwindFeaturesModule,
|
|
3565
|
+
resolveDefaultsAtRules: resolveDefaultsAtRulesModule["default"] ?? resolveDefaultsAtRulesModule,
|
|
3566
|
+
resolveConfig: resolveConfigModule["default"] ?? resolveConfigModule,
|
|
3567
|
+
validateConfig: validateConfigModule["validateConfig"]
|
|
3568
|
+
};
|
|
3461
3569
|
}
|
|
3462
|
-
function
|
|
3463
|
-
|
|
3570
|
+
function createStableJson$1(value) {
|
|
3571
|
+
if (value === void 0) return "undefined";
|
|
3572
|
+
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
3573
|
+
if (Array.isArray(value)) return `[${value.map((item) => createStableJson$1(item)).join(",")}]`;
|
|
3574
|
+
return `{${Object.keys(value).sort().map((key) => {
|
|
3575
|
+
const record = value;
|
|
3576
|
+
return `${JSON.stringify(key)}:${createStableJson$1(record[key])}`;
|
|
3577
|
+
}).join(",")}}`;
|
|
3464
3578
|
}
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
"
|
|
3474
|
-
"tailwind",
|
|
3475
|
-
"theme",
|
|
3476
|
-
"utility",
|
|
3477
|
-
"variant"
|
|
3478
|
-
]);
|
|
3479
|
-
const TAILWIND_ROOT_DIRECTIVE_NAMES = new Set([
|
|
3480
|
-
"config",
|
|
3481
|
-
"custom-variant",
|
|
3482
|
-
"plugin",
|
|
3483
|
-
"source",
|
|
3484
|
-
"tailwind",
|
|
3485
|
-
"theme",
|
|
3486
|
-
"utility",
|
|
3487
|
-
"variant"
|
|
3488
|
-
]);
|
|
3489
|
-
const TAILWIND_ROOT_DIRECTIVE_RE = /@(?:import\s+(?:url\(\s*)?["']?tailwindcss4?(?:\/[^"')\s]*)?|(?:use|forward)\s+(?:url\(\s*)?["']?tailwindcss4?(?:\/[^"')\s]*)?|tailwind|config|custom-variant|plugin|source|theme|utility|variant)\b/;
|
|
3490
|
-
const TAILWIND_EXTRACTABLE_DIRECTIVE_RE = /^\s*@(?:import|use|forward|tailwind|config|source|reference|plugin)\b[\s\S]*?(?:;|$)/;
|
|
3491
|
-
const TAILWIND_EXTRACTABLE_LAYER_STATEMENT_RE = /^\s*@layer\s[^;{]+;\s*$/;
|
|
3492
|
-
const TAILWIND_EXTRACTABLE_BLOCK_START_RE = /^\s*@(?:layer|theme|utility|variant|custom-variant)\b[\s\S]*\{/;
|
|
3493
|
-
const TAILWIND_V3_SUBPATH_IMPORT_LAYERS = new Map([
|
|
3494
|
-
["tailwindcss/base", "base"],
|
|
3495
|
-
["tailwindcss/components", "components"],
|
|
3496
|
-
["tailwindcss/utilities", "utilities"]
|
|
3497
|
-
]);
|
|
3498
|
-
function parseImportRequest(params) {
|
|
3499
|
-
return /^(?:url\(\s*)?(["']?)([^"')\s]+)\1\s*\)?/.exec(params.trim())?.[2];
|
|
3579
|
+
function createDependencyFingerprint(files) {
|
|
3580
|
+
return files.map((file) => {
|
|
3581
|
+
try {
|
|
3582
|
+
const stat = node_fs.default.statSync(file);
|
|
3583
|
+
return `${file}:${stat.size}:${stat.mtimeMs}`;
|
|
3584
|
+
} catch {
|
|
3585
|
+
return `${file}:missing`;
|
|
3586
|
+
}
|
|
3587
|
+
}).join("|");
|
|
3500
3588
|
}
|
|
3501
|
-
function
|
|
3502
|
-
return
|
|
3589
|
+
function createIncrementalGenerateCacheKey(source, target, styleOptions, bareArbitraryValues) {
|
|
3590
|
+
return [
|
|
3591
|
+
source.packageName,
|
|
3592
|
+
source.postcssPlugin,
|
|
3593
|
+
source.cwd,
|
|
3594
|
+
source.config ?? "config:missing",
|
|
3595
|
+
createDependencyFingerprint(source.dependencies),
|
|
3596
|
+
source.css,
|
|
3597
|
+
createStableJson$1(normalizeConfigObject(source.configObject)?.content),
|
|
3598
|
+
target,
|
|
3599
|
+
createStableJson$1(styleOptions),
|
|
3600
|
+
createStableJson$1(bareArbitraryValues)
|
|
3601
|
+
].join("\0");
|
|
3503
3602
|
}
|
|
3504
|
-
function
|
|
3505
|
-
return
|
|
3603
|
+
function createRuntimeReadyCacheKey(source, rootPath) {
|
|
3604
|
+
return [
|
|
3605
|
+
source.packageName,
|
|
3606
|
+
source.postcssPlugin,
|
|
3607
|
+
rootPath ?? "missing",
|
|
3608
|
+
source.config ?? "config:missing",
|
|
3609
|
+
source.cwd
|
|
3610
|
+
].join("\0");
|
|
3506
3611
|
}
|
|
3507
|
-
function
|
|
3508
|
-
return
|
|
3612
|
+
function isDirectUtilitiesOnlyCss(css) {
|
|
3613
|
+
return css.replace(/\s+/g, "") === "@tailwindutilities;";
|
|
3509
3614
|
}
|
|
3510
|
-
function
|
|
3511
|
-
|
|
3512
|
-
|
|
3615
|
+
function collectClassSet(context) {
|
|
3616
|
+
const classSet = /* @__PURE__ */ new Set();
|
|
3617
|
+
for (const candidate of context.classCache.keys()) if (String(candidate) !== "*") classSet.add(candidate);
|
|
3618
|
+
return classSet;
|
|
3513
3619
|
}
|
|
3514
|
-
function
|
|
3515
|
-
const
|
|
3516
|
-
|
|
3517
|
-
|
|
3620
|
+
function collectDependencyMessages(result) {
|
|
3621
|
+
const dependencies = /* @__PURE__ */ new Set();
|
|
3622
|
+
for (const message of result.messages) {
|
|
3623
|
+
const file = message["file"];
|
|
3624
|
+
if (message["type"] === "dependency" && typeof file === "string") dependencies.add(file);
|
|
3625
|
+
}
|
|
3626
|
+
return dependencies;
|
|
3518
3627
|
}
|
|
3519
|
-
function
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
const
|
|
3529
|
-
if (
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3628
|
+
function sortCandidates(candidates) {
|
|
3629
|
+
return [...candidates].sort((a, z) => {
|
|
3630
|
+
if (a === z) return 0;
|
|
3631
|
+
return a < z ? -1 : 1;
|
|
3632
|
+
});
|
|
3633
|
+
}
|
|
3634
|
+
function appendUtilityRules(root, context, rules) {
|
|
3635
|
+
const sortedRules = context.offsets.sort(rules);
|
|
3636
|
+
for (const [sort, rule] of sortedRules) {
|
|
3637
|
+
const tailwindRaw = rule.raws.tailwind;
|
|
3638
|
+
if (sort.layer === "utilities" || sort.layer === "variants" && tailwindRaw?.parentLayer === "utilities") root.append(rule.clone());
|
|
3639
|
+
}
|
|
3640
|
+
}
|
|
3641
|
+
function appendDirectUtilityRules(root, context) {
|
|
3642
|
+
appendUtilityRules(root, context, [...context.ruleCache]);
|
|
3643
|
+
}
|
|
3644
|
+
function createRuntimeReadyPromise(source) {
|
|
3645
|
+
const patcher = createTailwindcssPatcher({
|
|
3646
|
+
basedir: source.cwd,
|
|
3647
|
+
supportCustomLengthUnitsPatch: true,
|
|
3648
|
+
tailwindcss: {
|
|
3649
|
+
...source.config === void 0 ? {} : { config: source.config },
|
|
3650
|
+
cwd: source.cwd,
|
|
3651
|
+
packageName: source.packageName,
|
|
3652
|
+
postcssPlugin: source.postcssPlugin,
|
|
3653
|
+
version: 3
|
|
3538
3654
|
}
|
|
3539
3655
|
});
|
|
3540
|
-
|
|
3656
|
+
const cacheKey = createRuntimeReadyCacheKey(source, patcher.packageInfo?.rootPath);
|
|
3657
|
+
const cached = runtimeReadyPromiseCache.get(cacheKey);
|
|
3658
|
+
if (cached) return cached;
|
|
3659
|
+
const task = ensureTailwindcssRuntimePatch(patcher, { clearRequireCache: true }).catch((error) => {
|
|
3660
|
+
runtimeReadyPromiseCache.delete(cacheKey);
|
|
3661
|
+
throw error;
|
|
3662
|
+
});
|
|
3663
|
+
runtimeReadyPromiseCache.set(cacheKey, task);
|
|
3664
|
+
return task;
|
|
3541
3665
|
}
|
|
3542
|
-
function
|
|
3543
|
-
const
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3666
|
+
function createTailwindV3Engine(source) {
|
|
3667
|
+
const runtimeReadyPromise = createRuntimeReadyPromise(source);
|
|
3668
|
+
let tailwindInternals;
|
|
3669
|
+
async function generateOnce(generateSource, options = {}) {
|
|
3670
|
+
await runtimeReadyPromise;
|
|
3671
|
+
tailwindInternals ??= loadTailwindV3Internals(source);
|
|
3672
|
+
const internals = tailwindInternals;
|
|
3673
|
+
const { styleOptions, target = "weapp" } = options;
|
|
3674
|
+
const resolvedStyleOptions = resolveStyleOptions(generateSource, styleOptions);
|
|
3675
|
+
const requestedCandidates = mergeGenerateCandidates(generateSource, options);
|
|
3676
|
+
for (const candidate of await collectSourceBareArbitraryValueCandidates(options.sources, options.bareArbitraryValues)) requestedCandidates.add(candidate);
|
|
3677
|
+
const normalizedCandidates = normalizeBareArbitraryValueCandidates(requestedCandidates, options.bareArbitraryValues);
|
|
3678
|
+
const tailwindOptions = {
|
|
3679
|
+
...options,
|
|
3680
|
+
candidates: normalizedCandidates.candidates
|
|
3681
|
+
};
|
|
3682
|
+
const tailwindConfig = internals.validateConfig(internals.resolveConfig(createTailwindConfig(generateSource, tailwindOptions)));
|
|
3683
|
+
const candidates = normalizedCandidates.candidates;
|
|
3684
|
+
const changedContent = createChangedContentEntries(candidates, options.sources ?? []);
|
|
3685
|
+
const root = require_watch_dependencies.postcss_default.parse(generateSource.css, { from: void 0 });
|
|
3686
|
+
const result = {
|
|
3687
|
+
css: "",
|
|
3688
|
+
messages: []
|
|
3689
|
+
};
|
|
3690
|
+
let context;
|
|
3691
|
+
if (isDirectUtilitiesOnlyCss(generateSource.css)) {
|
|
3692
|
+
context = internals.createContext(tailwindConfig, changedContent, root);
|
|
3693
|
+
internals.generateRules(new Set(sortCandidates([internals.notOnDemandCandidate, ...candidates])), context);
|
|
3694
|
+
root.removeAll();
|
|
3695
|
+
appendDirectUtilityRules(root, context);
|
|
3696
|
+
internals.resolveDefaultsAtRules(context)(root, result);
|
|
3697
|
+
internals.collapseAdjacentRules(context)(root, result);
|
|
3698
|
+
internals.collapseDuplicateDeclarations(context)(root, result);
|
|
3699
|
+
} else {
|
|
3700
|
+
const setupContext = () => {
|
|
3701
|
+
return (currentRoot) => internals.createContext(tailwindConfig, changedContent, currentRoot);
|
|
3702
|
+
};
|
|
3703
|
+
context = await internals.processTailwindFeatures(setupContext)(root, result);
|
|
3549
3704
|
}
|
|
3550
|
-
|
|
3705
|
+
const rawCss = restoreBareArbitraryValueCssSelectors(root.toString(), requestedCandidates, options.bareArbitraryValues, internals.escapeClassName);
|
|
3706
|
+
const css = await transformTailwindV3CssByTarget(rawCss, target, resolvedStyleOptions);
|
|
3707
|
+
const dependencies = collectDependencyMessages(result);
|
|
3708
|
+
for (const dependency of generateSource.dependencies) dependencies.add(dependency);
|
|
3709
|
+
const classSet = restoreBareArbitraryValueClassSet(collectClassSet(context), requestedCandidates, options.bareArbitraryValues);
|
|
3710
|
+
return {
|
|
3711
|
+
css,
|
|
3712
|
+
rawCss,
|
|
3713
|
+
context,
|
|
3714
|
+
classSet,
|
|
3715
|
+
rawCandidates: requestedCandidates,
|
|
3716
|
+
dependencies: [...dependencies],
|
|
3717
|
+
sources: [],
|
|
3718
|
+
root: null,
|
|
3719
|
+
target,
|
|
3720
|
+
version: 3
|
|
3721
|
+
};
|
|
3551
3722
|
}
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
const
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
const
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3723
|
+
async function generateIncrementalMissingUtilities(context, candidates, target, styleOptions, bareArbitraryValues) {
|
|
3724
|
+
tailwindInternals ??= loadTailwindV3Internals(source);
|
|
3725
|
+
const internals = tailwindInternals;
|
|
3726
|
+
const root = require_watch_dependencies.postcss_default.root();
|
|
3727
|
+
const result = {
|
|
3728
|
+
css: "",
|
|
3729
|
+
messages: []
|
|
3730
|
+
};
|
|
3731
|
+
const normalizedCandidates = normalizeBareArbitraryValueCandidates(candidates, bareArbitraryValues);
|
|
3732
|
+
const sortedCandidates = sortCandidates(normalizedCandidates.candidates);
|
|
3733
|
+
appendUtilityRules(root, context, internals.generateRules(new Set(sortedCandidates), context));
|
|
3734
|
+
internals.resolveDefaultsAtRules(context)(root, result);
|
|
3735
|
+
internals.collapseAdjacentRules(context)(root, result);
|
|
3736
|
+
internals.collapseDuplicateDeclarations(context)(root, result);
|
|
3737
|
+
const rawCss = restoreBareArbitraryValueCssSelectors(root.toString(), candidates, bareArbitraryValues, internals.escapeClassName);
|
|
3738
|
+
return {
|
|
3739
|
+
css: await transformTailwindV3CssByTarget(rawCss, target, resolveStyleOptions(source, styleOptions)),
|
|
3740
|
+
rawCss,
|
|
3741
|
+
classSet: collectGeneratedCandidates(context, sortedCandidates, normalizedCandidates.restoreCandidates),
|
|
3742
|
+
dependencies: collectDependencyMessages(result)
|
|
3743
|
+
};
|
|
3744
|
+
}
|
|
3745
|
+
async function generateWithIncrementalCache(options = {}) {
|
|
3746
|
+
if ((options.sources?.length ?? 0) > 0) return generateOnce(source, options);
|
|
3747
|
+
const target = options.target ?? "weapp";
|
|
3748
|
+
const requestedCandidates = mergeGenerateCandidates(source, options);
|
|
3749
|
+
if (requestedCandidates.size === 0) return generateOnce(source, options);
|
|
3750
|
+
const styleOptions = resolveStyleOptions(source, options.styleOptions);
|
|
3751
|
+
const cacheKey = createIncrementalGenerateCacheKey(source, target, styleOptions, options.bareArbitraryValues);
|
|
3752
|
+
const cached = incrementalGenerateCache.get(cacheKey);
|
|
3753
|
+
if (cached) {
|
|
3754
|
+
if (hasRemovedCandidates(cached.seenCandidates, requestedCandidates)) {
|
|
3755
|
+
const generated = await generateOnce(source, options);
|
|
3756
|
+
incrementalGenerateCache.set(cacheKey, {
|
|
3757
|
+
context: generated.context,
|
|
3758
|
+
seenCandidates: new Set(requestedCandidates),
|
|
3759
|
+
classSet: new Set(generated.classSet),
|
|
3760
|
+
css: generated.css,
|
|
3761
|
+
rawCss: generated.rawCss,
|
|
3762
|
+
dependencies: generated.dependencies,
|
|
3763
|
+
target: generated.target
|
|
3764
|
+
});
|
|
3765
|
+
return generated;
|
|
3766
|
+
}
|
|
3767
|
+
const missingCandidates = [...requestedCandidates].filter((candidate) => !cached.seenCandidates.has(candidate));
|
|
3768
|
+
if (missingCandidates.length === 0) return {
|
|
3769
|
+
css: cached.css,
|
|
3770
|
+
rawCss: cached.rawCss,
|
|
3771
|
+
incrementalCss: "",
|
|
3772
|
+
incrementalRawCss: "",
|
|
3773
|
+
classSet: new Set(cached.classSet),
|
|
3774
|
+
rawCandidates: new Set(cached.seenCandidates),
|
|
3775
|
+
dependencies: cached.dependencies,
|
|
3776
|
+
sources: [],
|
|
3777
|
+
root: null,
|
|
3778
|
+
target: cached.target,
|
|
3779
|
+
version: 3
|
|
3780
|
+
};
|
|
3781
|
+
const generated = await generateIncrementalMissingUtilities(cached.context, missingCandidates, target, styleOptions, options.bareArbitraryValues);
|
|
3782
|
+
for (const candidate of missingCandidates) cached.seenCandidates.add(candidate);
|
|
3783
|
+
for (const className of generated.classSet) cached.classSet.add(className);
|
|
3784
|
+
cached.css = [cached.css, generated.css].filter(Boolean).join("\n");
|
|
3785
|
+
cached.rawCss = [cached.rawCss, generated.rawCss].filter(Boolean).join("\n");
|
|
3786
|
+
cached.dependencies = [...new Set([...cached.dependencies, ...generated.dependencies])];
|
|
3787
|
+
return {
|
|
3788
|
+
css: cached.css,
|
|
3789
|
+
rawCss: cached.rawCss,
|
|
3790
|
+
incrementalCss: generated.css,
|
|
3791
|
+
incrementalRawCss: generated.rawCss,
|
|
3792
|
+
classSet: new Set(cached.classSet),
|
|
3793
|
+
rawCandidates: new Set(cached.seenCandidates),
|
|
3794
|
+
dependencies: cached.dependencies,
|
|
3795
|
+
sources: [],
|
|
3796
|
+
root: null,
|
|
3797
|
+
target: cached.target,
|
|
3798
|
+
version: 3
|
|
3799
|
+
};
|
|
3575
3800
|
}
|
|
3576
|
-
|
|
3801
|
+
const generated = await generateOnce(source, options);
|
|
3802
|
+
incrementalGenerateCache.set(cacheKey, {
|
|
3803
|
+
context: generated.context,
|
|
3804
|
+
seenCandidates: new Set(requestedCandidates),
|
|
3805
|
+
classSet: new Set(generated.classSet),
|
|
3806
|
+
css: generated.css,
|
|
3807
|
+
rawCss: generated.rawCss,
|
|
3808
|
+
dependencies: generated.dependencies,
|
|
3809
|
+
target: generated.target
|
|
3810
|
+
});
|
|
3811
|
+
return generated;
|
|
3577
3812
|
}
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
function stripPreprocessorLineComment(line) {
|
|
3581
|
-
let quote;
|
|
3582
|
-
let escaped = false;
|
|
3583
|
-
for (let index = 0; index < line.length; index++) {
|
|
3584
|
-
const char = line[index];
|
|
3585
|
-
if (escaped) {
|
|
3586
|
-
escaped = false;
|
|
3587
|
-
continue;
|
|
3588
|
-
}
|
|
3589
|
-
if (char === "\\") {
|
|
3590
|
-
escaped = true;
|
|
3591
|
-
continue;
|
|
3592
|
-
}
|
|
3593
|
-
if (quote) {
|
|
3594
|
-
if (char === quote) quote = void 0;
|
|
3595
|
-
continue;
|
|
3596
|
-
}
|
|
3597
|
-
if (char === "\"" || char === "'") {
|
|
3598
|
-
quote = char;
|
|
3599
|
-
continue;
|
|
3600
|
-
}
|
|
3601
|
-
if (char === "/" && line[index + 1] === "/" && (index === 0 || /\s/.test(line[index - 1]))) return line.slice(0, index).trimEnd();
|
|
3813
|
+
async function generate(options = {}) {
|
|
3814
|
+
return options.incrementalCache ? generateWithIncrementalCache(options) : generateOnce(source, options);
|
|
3602
3815
|
}
|
|
3603
|
-
return
|
|
3816
|
+
return {
|
|
3817
|
+
source,
|
|
3818
|
+
async validateCandidates(candidates) {
|
|
3819
|
+
return (await generate({
|
|
3820
|
+
candidates,
|
|
3821
|
+
incrementalCache: true,
|
|
3822
|
+
target: "tailwind"
|
|
3823
|
+
})).classSet;
|
|
3824
|
+
},
|
|
3825
|
+
generate
|
|
3826
|
+
};
|
|
3604
3827
|
}
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
if (char === "\\") {
|
|
3616
|
-
escaped = true;
|
|
3617
|
-
continue;
|
|
3618
|
-
}
|
|
3619
|
-
if (quote) {
|
|
3620
|
-
if (char === quote) quote = void 0;
|
|
3621
|
-
continue;
|
|
3622
|
-
}
|
|
3623
|
-
if (char === "\"" || char === "'") {
|
|
3624
|
-
quote = char;
|
|
3625
|
-
continue;
|
|
3626
|
-
}
|
|
3627
|
-
if (char === "{") delta++;
|
|
3628
|
-
else if (char === "}") delta--;
|
|
3629
|
-
}
|
|
3630
|
-
return delta;
|
|
3828
|
+
//#endregion
|
|
3829
|
+
//#region src/tailwindcss/v3-engine/source.ts
|
|
3830
|
+
const DEFAULT_TAILWIND_V3_CSS = [
|
|
3831
|
+
"@tailwind base;",
|
|
3832
|
+
"@tailwind components;",
|
|
3833
|
+
"@tailwind utilities;"
|
|
3834
|
+
].join("\n");
|
|
3835
|
+
function parseConfigParam(params) {
|
|
3836
|
+
const value = params.trim();
|
|
3837
|
+
return /^(['"])(.+)\1$/.exec(value)?.[2];
|
|
3631
3838
|
}
|
|
3632
|
-
function
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
let depth = 0;
|
|
3636
|
-
for (const rawLine of stripGeneratorPlaceholderMarkers(rawSource).split(/\r?\n/)) {
|
|
3637
|
-
const line = stripPreprocessorLineComment(rawLine);
|
|
3638
|
-
if (!line.trim()) continue;
|
|
3639
|
-
if (!current) {
|
|
3640
|
-
if (!TAILWIND_EXTRACTABLE_BLOCK_START_RE.test(line)) continue;
|
|
3641
|
-
current = [line];
|
|
3642
|
-
depth = countBlockBraceDelta(line);
|
|
3643
|
-
if (depth <= 0) {
|
|
3644
|
-
blocks.push(current.join("\n"));
|
|
3645
|
-
current = void 0;
|
|
3646
|
-
depth = 0;
|
|
3647
|
-
}
|
|
3648
|
-
continue;
|
|
3649
|
-
}
|
|
3650
|
-
current.push(line);
|
|
3651
|
-
depth += countBlockBraceDelta(line);
|
|
3652
|
-
if (depth <= 0) {
|
|
3653
|
-
blocks.push(current.join("\n"));
|
|
3654
|
-
current = void 0;
|
|
3655
|
-
depth = 0;
|
|
3656
|
-
}
|
|
3657
|
-
}
|
|
3658
|
-
return blocks;
|
|
3839
|
+
function resolveOptionalPath(value, base) {
|
|
3840
|
+
if (!value) return;
|
|
3841
|
+
return node_path.default.isAbsolute(value) ? value : node_path.default.resolve(base, value);
|
|
3659
3842
|
}
|
|
3660
|
-
function
|
|
3661
|
-
|
|
3662
|
-
|
|
3843
|
+
function resolveCssConfig(css, base) {
|
|
3844
|
+
if (!css) return {
|
|
3845
|
+
css,
|
|
3846
|
+
config: void 0
|
|
3847
|
+
};
|
|
3848
|
+
const root = require_watch_dependencies.postcss_default.parse(css);
|
|
3849
|
+
let config;
|
|
3850
|
+
root.walkAtRules("config", (rule) => {
|
|
3851
|
+
const configPath = parseConfigParam(rule.params);
|
|
3852
|
+
if (!configPath) return;
|
|
3853
|
+
if (!config) config = resolveOptionalPath(configPath, base);
|
|
3854
|
+
rule.remove();
|
|
3855
|
+
});
|
|
3856
|
+
return {
|
|
3857
|
+
config,
|
|
3858
|
+
css: root.toString()
|
|
3859
|
+
};
|
|
3663
3860
|
}
|
|
3664
|
-
function
|
|
3665
|
-
|
|
3666
|
-
const match = /^\s*@config\b([\s\S]*?)(?:;|$)/.exec(line);
|
|
3667
|
-
const request = match ? parseConfigRequest(match[1] ?? "") : void 0;
|
|
3668
|
-
if (request) return request;
|
|
3669
|
-
}
|
|
3861
|
+
function getProjectRoot(patcher) {
|
|
3862
|
+
return patcher.options?.projectRoot ?? node_process.default.cwd();
|
|
3670
3863
|
}
|
|
3671
|
-
function
|
|
3672
|
-
|
|
3864
|
+
function normalizeLoadedConfig(config) {
|
|
3865
|
+
if (!config || typeof config !== "object") return config;
|
|
3866
|
+
const maybeDefault = config.default;
|
|
3867
|
+
if (maybeDefault && typeof maybeDefault === "object") return maybeDefault;
|
|
3868
|
+
return config;
|
|
3673
3869
|
}
|
|
3674
|
-
function
|
|
3675
|
-
return
|
|
3870
|
+
function resolveTailwindCssPackageName(patcher) {
|
|
3871
|
+
return resolveTailwindcssOptions(patcher.options)?.packageName ?? patcher.packageInfo?.name ?? "tailwindcss";
|
|
3676
3872
|
}
|
|
3677
|
-
function
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3873
|
+
async function resolveTailwindV3Source(options = {}) {
|
|
3874
|
+
const projectRoot = options.projectRoot ?? node_process.default.cwd();
|
|
3875
|
+
const base = options.base ?? options.cwd ?? projectRoot;
|
|
3876
|
+
const cssConfig = resolveCssConfig(options.css, base);
|
|
3877
|
+
const config = resolveOptionalPath(options.config, base) ?? cssConfig.config;
|
|
3878
|
+
const cwd = options.cwd ?? (config ? node_path.default.dirname(config) : projectRoot);
|
|
3879
|
+
const loaded = await (0, tailwindcss_config.loadConfig)(omitUndefined({
|
|
3880
|
+
config,
|
|
3881
|
+
cwd
|
|
3882
|
+
}));
|
|
3883
|
+
return {
|
|
3884
|
+
version: 3,
|
|
3885
|
+
projectRoot,
|
|
3886
|
+
cwd,
|
|
3887
|
+
base,
|
|
3888
|
+
css: cssConfig.css ?? options.css ?? DEFAULT_TAILWIND_V3_CSS,
|
|
3889
|
+
config: loaded?.filepath ?? config,
|
|
3890
|
+
configObject: normalizeLoadedConfig(loaded?.config),
|
|
3891
|
+
dependencies: loaded?.filepath ? [loaded.filepath] : [],
|
|
3892
|
+
packageName: options.packageName ?? "tailwindcss",
|
|
3893
|
+
postcssPlugin: options.postcssPlugin ?? options.packageName ?? "tailwindcss"
|
|
3894
|
+
};
|
|
3694
3895
|
}
|
|
3695
|
-
function
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3896
|
+
function resolveTailwindV3SourceOptionsFromPatcher(patcher) {
|
|
3897
|
+
const projectRoot = getProjectRoot(patcher);
|
|
3898
|
+
const tailwindOptions = resolveTailwindcssOptions(patcher.options);
|
|
3899
|
+
return {
|
|
3900
|
+
projectRoot,
|
|
3901
|
+
cwd: tailwindOptions?.v3?.cwd ?? tailwindOptions?.cwd ?? projectRoot,
|
|
3902
|
+
config: tailwindOptions?.v3?.config ?? tailwindOptions?.config,
|
|
3903
|
+
packageName: resolveTailwindCssPackageName(patcher),
|
|
3904
|
+
postcssPlugin: tailwindOptions?.v3?.postcssPlugin ?? tailwindOptions?.postcssPlugin
|
|
3905
|
+
};
|
|
3703
3906
|
}
|
|
3704
|
-
function
|
|
3705
|
-
return
|
|
3907
|
+
function resolveTailwindV3SourceFromPatcher(patcher) {
|
|
3908
|
+
return resolveTailwindV3Source(resolveTailwindV3SourceOptionsFromPatcher(patcher));
|
|
3706
3909
|
}
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3910
|
+
//#endregion
|
|
3911
|
+
//#region src/generator/options.ts
|
|
3912
|
+
const explicitGeneratorTargetEnvKeys = ["WEAPP_TW_TARGET", "WEAPP_TAILWINDCSS_TARGET"];
|
|
3913
|
+
const uniWebPlatformEnvKeys = ["UNI_PLATFORM", "UNI_UTS_PLATFORM"];
|
|
3914
|
+
const mpxWebPlatformEnvKeys = ["MPX_CLI_MODE", "MPX_CURRENT_TARGET_MODE"];
|
|
3915
|
+
function getEnvValue(key) {
|
|
3916
|
+
return typeof node_process.default === "undefined" ? void 0 : node_process.default.env[key];
|
|
3711
3917
|
}
|
|
3712
|
-
function
|
|
3713
|
-
|
|
3714
|
-
const atRule = node;
|
|
3715
|
-
if (isTailwindImportAtRule(atRule, options)) return true;
|
|
3716
|
-
if (atRule.name === "import" && isPackageJsonImportRequest$1(parseImportRequest(atRule.params))) return true;
|
|
3717
|
-
if (atRule.name === "layer") return !atRule.nodes || atRule.nodes.length === 0;
|
|
3718
|
-
return TAILWIND_REMOVABLE_SOURCE_DIRECTIVE_NAMES.has(atRule.name);
|
|
3918
|
+
function normalizeGeneratorTargetValue(value) {
|
|
3919
|
+
return value === "weapp" || value === "web" || value === "tailwind" ? value : void 0;
|
|
3719
3920
|
}
|
|
3720
|
-
function
|
|
3721
|
-
|
|
3921
|
+
function isUniWebPlatform(value) {
|
|
3922
|
+
const normalized = value?.trim().toLowerCase();
|
|
3923
|
+
return normalized === "h5" || normalized?.startsWith("web") === true;
|
|
3722
3924
|
}
|
|
3723
|
-
function
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3925
|
+
function isUniAppWebViewPlatform(value) {
|
|
3926
|
+
const normalized = value?.trim().toLowerCase();
|
|
3927
|
+
return normalized === "app" || normalized === "app-plus";
|
|
3928
|
+
}
|
|
3929
|
+
function isUniNativeAppPlatform(value) {
|
|
3930
|
+
return (value?.trim().toLowerCase())?.startsWith("app-") === true;
|
|
3728
3931
|
}
|
|
3729
|
-
function
|
|
3730
|
-
|
|
3731
|
-
const source = hasPreprocessorOnlySyntax(rawSource) ? extractTailwindSourceForPostcssFallback(rawSource, options) : stripGeneratorPlaceholderMarkers(rawSource);
|
|
3732
|
-
if (!source) return "";
|
|
3733
|
-
const root = require_runtime_registry.postcss_default.parse(source);
|
|
3734
|
-
let removed = false;
|
|
3735
|
-
root.walk((node) => {
|
|
3736
|
-
if (isTailwindSourceDirective(node, options)) {
|
|
3737
|
-
node.remove();
|
|
3738
|
-
removed = true;
|
|
3739
|
-
}
|
|
3740
|
-
});
|
|
3741
|
-
return removed ? root.toString() : source;
|
|
3742
|
-
} catch {
|
|
3743
|
-
return stripGeneratorPlaceholderMarkers(rawSource);
|
|
3744
|
-
}
|
|
3932
|
+
function isMpxWebPlatform(value) {
|
|
3933
|
+
return value?.trim().toLowerCase() === "web";
|
|
3745
3934
|
}
|
|
3746
|
-
function
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
let found = false;
|
|
3751
|
-
const ignoreLayer = hasGeneratedCssArtifacts(rawSource);
|
|
3752
|
-
root.walk((node) => {
|
|
3753
|
-
if (isTailwindGenerationDirective(node, {
|
|
3754
|
-
...options,
|
|
3755
|
-
ignoreLayer
|
|
3756
|
-
})) {
|
|
3757
|
-
found = true;
|
|
3758
|
-
return false;
|
|
3759
|
-
}
|
|
3760
|
-
});
|
|
3761
|
-
return found;
|
|
3762
|
-
} catch {
|
|
3763
|
-
return extractTailwindDirectiveLines(rawSource, options).length > 0;
|
|
3935
|
+
function inferGeneratorTargetFromEnv() {
|
|
3936
|
+
for (const key of explicitGeneratorTargetEnvKeys) {
|
|
3937
|
+
const target = normalizeGeneratorTargetValue(getEnvValue(key));
|
|
3938
|
+
if (target !== void 0) return target;
|
|
3764
3939
|
}
|
|
3940
|
+
if (uniWebPlatformEnvKeys.some((key) => isUniWebPlatform(getEnvValue(key))) || isUniAppWebViewPlatform(getEnvValue("UNI_PLATFORM")) && !isUniNativeAppPlatform(getEnvValue("UNI_UTS_PLATFORM")) || mpxWebPlatformEnvKeys.some((key) => isMpxWebPlatform(getEnvValue(key))) || getEnvValue("TARO_ENV") === "h5") return "web";
|
|
3941
|
+
return "weapp";
|
|
3765
3942
|
}
|
|
3766
|
-
function
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
}
|
|
3943
|
+
function normalizeWeappTailwindcssGeneratorOptions(options) {
|
|
3944
|
+
const target = options?.target ?? inferGeneratorTargetFromEnv();
|
|
3945
|
+
if (options == null) return {
|
|
3946
|
+
target,
|
|
3947
|
+
importFallback: true,
|
|
3948
|
+
tailwindcssV3Compatibility: target === "weapp",
|
|
3949
|
+
bareArbitraryValues: void 0
|
|
3950
|
+
};
|
|
3951
|
+
return {
|
|
3952
|
+
target,
|
|
3953
|
+
config: options.config,
|
|
3954
|
+
styleOptions: options.styleOptions,
|
|
3955
|
+
importFallback: options.importFallback ?? true,
|
|
3956
|
+
tailwindcssV3Compatibility: options.tailwindcssV3Compatibility ?? target === "weapp",
|
|
3957
|
+
bareArbitraryValues: options.bareArbitraryValues
|
|
3958
|
+
};
|
|
3782
3959
|
}
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
let found = false;
|
|
3788
|
-
root.walkAtRules("apply", () => {
|
|
3789
|
-
found = true;
|
|
3790
|
-
return false;
|
|
3791
|
-
});
|
|
3792
|
-
return found;
|
|
3793
|
-
} catch {
|
|
3794
|
-
return false;
|
|
3795
|
-
}
|
|
3960
|
+
//#endregion
|
|
3961
|
+
//#region src/generator/index.ts
|
|
3962
|
+
function isTailwindV3Source(source) {
|
|
3963
|
+
return "version" in source && source.version === 3;
|
|
3796
3964
|
}
|
|
3797
|
-
function
|
|
3798
|
-
|
|
3799
|
-
const root = require_runtime_registry.postcss_default.parse(rawSource);
|
|
3800
|
-
const normalizedImports = normalizeTailwindImportAtRules(root, options);
|
|
3801
|
-
let found = false;
|
|
3802
|
-
let config;
|
|
3803
|
-
let configRequest;
|
|
3804
|
-
let removedConfig = false;
|
|
3805
|
-
const removeConfig = options.removeConfig ?? true;
|
|
3806
|
-
const ignoreLayer = hasGeneratedCssArtifacts(rawSource);
|
|
3807
|
-
root.walk((node) => {
|
|
3808
|
-
if (isTailwindGenerationDirective(node, {
|
|
3809
|
-
...options,
|
|
3810
|
-
ignoreLayer
|
|
3811
|
-
})) found = true;
|
|
3812
|
-
if (node.type === "atrule" && node.name === "config") {
|
|
3813
|
-
const configPath = parseConfigRequest(node.params);
|
|
3814
|
-
if (configPath && !config) {
|
|
3815
|
-
configRequest = configPath;
|
|
3816
|
-
config = isPackageJsonImportRequest$1(configPath) ? void 0 : node_path.default.isAbsolute(configPath) ? configPath : node_path.default.resolve(base, configPath);
|
|
3817
|
-
}
|
|
3818
|
-
if (removeConfig) {
|
|
3819
|
-
node.remove();
|
|
3820
|
-
removedConfig = true;
|
|
3821
|
-
}
|
|
3822
|
-
}
|
|
3823
|
-
});
|
|
3824
|
-
if (!found) return;
|
|
3825
|
-
if (hasPreprocessorOnlySyntax(rawSource)) {
|
|
3826
|
-
const css = extractTailwindSourceForPostcssFallback(rawSource, {
|
|
3827
|
-
...options,
|
|
3828
|
-
removeConfig
|
|
3829
|
-
});
|
|
3830
|
-
if (css) return {
|
|
3831
|
-
css,
|
|
3832
|
-
config,
|
|
3833
|
-
configRequest,
|
|
3834
|
-
base
|
|
3835
|
-
};
|
|
3836
|
-
}
|
|
3837
|
-
return {
|
|
3838
|
-
css: removedConfig || normalizedImports ? root.toString() : rawSource,
|
|
3839
|
-
config,
|
|
3840
|
-
configRequest,
|
|
3841
|
-
base
|
|
3842
|
-
};
|
|
3843
|
-
} catch {
|
|
3844
|
-
const css = extractTailwindSourceForPostcssFallback(rawSource, options);
|
|
3845
|
-
const configRequest = extractConfigRequestFromSource(rawSource);
|
|
3846
|
-
const config = configRequest && !isPackageJsonImportRequest$1(configRequest) ? node_path.default.isAbsolute(configRequest) ? configRequest : node_path.default.resolve(base, configRequest) : void 0;
|
|
3847
|
-
return css ? {
|
|
3848
|
-
css,
|
|
3849
|
-
config,
|
|
3850
|
-
configRequest,
|
|
3851
|
-
base
|
|
3852
|
-
} : void 0;
|
|
3853
|
-
}
|
|
3965
|
+
function createWeappTailwindcssGenerator(source) {
|
|
3966
|
+
return isTailwindV3Source(source) ? createTailwindV3Engine(source) : createTailwindV4Engine(source);
|
|
3854
3967
|
}
|
|
3855
3968
|
//#endregion
|
|
3856
3969
|
//#region src/wxml/shared.ts
|
|
@@ -4135,7 +4248,7 @@ function collectGeneratedSelectors(css) {
|
|
|
4135
4248
|
if (cached) return cached;
|
|
4136
4249
|
const selectors = /* @__PURE__ */ new Set();
|
|
4137
4250
|
try {
|
|
4138
|
-
|
|
4251
|
+
require_watch_dependencies.postcss_default.parse(css).walkRules((rule) => {
|
|
4139
4252
|
if (isCustomPropertyOnlyRule(rule) && !isPseudoContentInitRule(rule) && !hasUtilityClassSelector(rule.selector)) return;
|
|
4140
4253
|
for (const selector of getRuleCompatSelectorKeys(rule)) selectors.add(selector);
|
|
4141
4254
|
});
|
|
@@ -4148,7 +4261,7 @@ function collectGeneratedSelectors(css) {
|
|
|
4148
4261
|
function collectGeneratedDeclarationPropsBySelector(generatedCss, selectors) {
|
|
4149
4262
|
const propsBySelector = /* @__PURE__ */ new Map();
|
|
4150
4263
|
try {
|
|
4151
|
-
|
|
4264
|
+
require_watch_dependencies.postcss_default.parse(generatedCss).walkRules((rule) => {
|
|
4152
4265
|
const matchedSelectors = getRuleCompatSelectorKeys(rule).filter((selector) => selectors.has(selector));
|
|
4153
4266
|
if (matchedSelectors.length === 0) return;
|
|
4154
4267
|
const props = /* @__PURE__ */ new Set();
|
|
@@ -4170,7 +4283,7 @@ function removeGeneratedSelectorCompatCss(css, generatedCss) {
|
|
|
4170
4283
|
const generatedSelectors = collectGeneratedSelectors(generatedCss);
|
|
4171
4284
|
if (generatedSelectors.size === 0) return css;
|
|
4172
4285
|
try {
|
|
4173
|
-
const root =
|
|
4286
|
+
const root = require_watch_dependencies.postcss_default.parse(css);
|
|
4174
4287
|
let removed = false;
|
|
4175
4288
|
root.walkRules((rule) => {
|
|
4176
4289
|
if (isPseudoContentInitRule(rule)) {
|
|
@@ -4198,7 +4311,7 @@ function collectDedupedPostTransformCompatCss(css, generatedCss) {
|
|
|
4198
4311
|
const generatedDeclarationPropsBySelector = collectGeneratedDeclarationPropsBySelector(generatedCss, generatedSelectors);
|
|
4199
4312
|
const preservedNodes = [];
|
|
4200
4313
|
try {
|
|
4201
|
-
const root =
|
|
4314
|
+
const root = require_watch_dependencies.postcss_default.parse(css);
|
|
4202
4315
|
root.each((node) => {
|
|
4203
4316
|
if (node.type === "rule") {
|
|
4204
4317
|
const nodeSelectors = getRuleCompatSelectorKeys(node);
|
|
@@ -4227,7 +4340,7 @@ function collectDedupedPostTransformCompatCss(css, generatedCss) {
|
|
|
4227
4340
|
preservedNodes.push(node.clone());
|
|
4228
4341
|
});
|
|
4229
4342
|
if (preservedNodes.length === root.nodes.length) return css;
|
|
4230
|
-
const nextRoot =
|
|
4343
|
+
const nextRoot = require_watch_dependencies.postcss_default.root();
|
|
4231
4344
|
nextRoot.append(preservedNodes);
|
|
4232
4345
|
return nextRoot.toString();
|
|
4233
4346
|
} catch {
|
|
@@ -4240,75 +4353,112 @@ function removeDuplicatedViteMarkers(css, baseCss) {
|
|
|
4240
4353
|
return css.replace(VITE_MARKER_RE, "");
|
|
4241
4354
|
}
|
|
4242
4355
|
//#endregion
|
|
4243
|
-
//#region src/bundlers/shared/generator-css/config-directive.ts
|
|
4244
|
-
function quoteCssString(value) {
|
|
4245
|
-
return value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"");
|
|
4246
|
-
}
|
|
4247
|
-
function toCssPath(value) {
|
|
4248
|
-
return value.replaceAll("\\", "/");
|
|
4249
|
-
}
|
|
4250
|
-
function prependConfigDirective(css, config) {
|
|
4251
|
-
if (!config || /@config\s+/.test(css)) return css;
|
|
4252
|
-
return `@config "${quoteCssString(toCssPath(config))}";\n${css}`;
|
|
4253
|
-
}
|
|
4254
|
-
function normalizeConfigDirective(css, config) {
|
|
4255
|
-
if (!config || !/@config\s+/.test(css)) return css;
|
|
4256
|
-
return css.replace(/@config\s+(["'])(.+?)\1\s*;?/, `@config "${quoteCssString(toCssPath(config))}";`);
|
|
4257
|
-
}
|
|
4258
|
-
//#endregion
|
|
4259
4356
|
//#region src/bundlers/shared/generator-css/source-files.ts
|
|
4260
|
-
const SOURCE_STYLE_EXTENSIONS = [
|
|
4261
|
-
".vue",
|
|
4262
|
-
".uvue",
|
|
4263
|
-
".nvue",
|
|
4264
|
-
".css",
|
|
4265
|
-
".scss",
|
|
4266
|
-
".sass",
|
|
4267
|
-
".less",
|
|
4268
|
-
".styl",
|
|
4269
|
-
".stylus",
|
|
4270
|
-
".wxss",
|
|
4271
|
-
".acss",
|
|
4272
|
-
".jxss",
|
|
4273
|
-
".ttss",
|
|
4274
|
-
".qss"
|
|
4275
|
-
];
|
|
4276
4357
|
const SFC_STYLE_BLOCK_RE = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
|
|
4277
4358
|
function stripStyleExtension(file) {
|
|
4278
|
-
|
|
4359
|
+
const normalized = file.replace(/[?#].*$/, "");
|
|
4360
|
+
const ext = node_path.default.extname(normalized);
|
|
4361
|
+
return ext ? normalized.slice(0, -ext.length) : normalized;
|
|
4279
4362
|
}
|
|
4280
|
-
function
|
|
4281
|
-
|
|
4363
|
+
function normalizeMatchPath$1(file) {
|
|
4364
|
+
return file.split(node_path.default.sep).join("/");
|
|
4365
|
+
}
|
|
4366
|
+
function isPathWithinRoot$1(file, root) {
|
|
4367
|
+
const relative = node_path.default.relative(root, file);
|
|
4368
|
+
return Boolean(relative) && !relative.startsWith("..") && !node_path.default.isAbsolute(relative);
|
|
4369
|
+
}
|
|
4370
|
+
function countCommonSuffixSegments(a, b) {
|
|
4371
|
+
const aSegments = a.split("/").filter(Boolean);
|
|
4372
|
+
const bSegments = b.split("/").filter(Boolean);
|
|
4373
|
+
let count = 0;
|
|
4374
|
+
while (count < aSegments.length && count < bSegments.length && aSegments[aSegments.length - 1 - count] === bSegments[bSegments.length - 1 - count]) count++;
|
|
4375
|
+
return count;
|
|
4376
|
+
}
|
|
4377
|
+
function collectOutputMatchBases(file, sourceOptions) {
|
|
4378
|
+
const normalizedFile = file.replace(/[?#].*$/, "");
|
|
4379
|
+
const roots = [
|
|
4380
|
+
sourceOptions.outputRoot,
|
|
4282
4381
|
sourceOptions.projectRoot,
|
|
4283
|
-
sourceOptions.cwd
|
|
4284
|
-
node_process.default.cwd()
|
|
4382
|
+
sourceOptions.cwd
|
|
4285
4383
|
].filter((item) => typeof item === "string" && item.length > 0);
|
|
4286
|
-
const
|
|
4287
|
-
const
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
for (const outputRoot of outputRoots) {
|
|
4291
|
-
const relative = node_path.default.relative(outputRoot, absoluteFile);
|
|
4292
|
-
if (!relative || relative.startsWith("..") || node_path.default.isAbsolute(relative)) continue;
|
|
4293
|
-
relativeFiles.add(relative);
|
|
4294
|
-
}
|
|
4384
|
+
const bases = /* @__PURE__ */ new Set();
|
|
4385
|
+
const addBase = (candidate) => {
|
|
4386
|
+
const stripped = normalizeMatchPath$1(stripStyleExtension(candidate));
|
|
4387
|
+
if (stripped.length > 0) bases.add(stripped);
|
|
4295
4388
|
};
|
|
4296
|
-
|
|
4297
|
-
|
|
4298
|
-
|
|
4299
|
-
|
|
4300
|
-
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
|
|
4389
|
+
addBase(normalizedFile);
|
|
4390
|
+
if (node_path.default.isAbsolute(normalizedFile)) for (const root of roots) {
|
|
4391
|
+
const normalizedRoot = node_path.default.resolve(root);
|
|
4392
|
+
if (isPathWithinRoot$1(normalizedFile, normalizedRoot)) addBase(node_path.default.relative(normalizedRoot, normalizedFile));
|
|
4393
|
+
}
|
|
4394
|
+
else for (const root of roots) addBase(node_path.default.resolve(root, normalizedFile));
|
|
4395
|
+
return bases;
|
|
4396
|
+
}
|
|
4397
|
+
function isMatchingSourceStyleFile(file, sourceFile, sourceOptions) {
|
|
4398
|
+
const outputBases = collectOutputMatchBases(file, sourceOptions);
|
|
4399
|
+
const normalizedSourceFile = sourceFile.replace(/[?#].*$/, "");
|
|
4400
|
+
const sourceBases = /* @__PURE__ */ new Set();
|
|
4401
|
+
const addSourceBase = (candidate) => {
|
|
4402
|
+
const stripped = normalizeMatchPath$1(stripStyleExtension(candidate));
|
|
4403
|
+
if (stripped.length > 0) sourceBases.add(stripped);
|
|
4404
|
+
};
|
|
4405
|
+
addSourceBase(normalizedSourceFile);
|
|
4406
|
+
if (node_path.default.isAbsolute(normalizedSourceFile)) for (const root of [sourceOptions.projectRoot, sourceOptions.cwd]) {
|
|
4407
|
+
if (!root) continue;
|
|
4408
|
+
const normalizedRoot = node_path.default.resolve(root);
|
|
4409
|
+
if (isPathWithinRoot$1(normalizedSourceFile, normalizedRoot)) addSourceBase(node_path.default.relative(normalizedRoot, normalizedSourceFile));
|
|
4410
|
+
}
|
|
4411
|
+
for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase || outputBase.endsWith(`/${sourceBase}`) || sourceBase.endsWith(`/${outputBase}`) || countCommonSuffixSegments(outputBase, sourceBase) >= 2) return true;
|
|
4412
|
+
return false;
|
|
4413
|
+
}
|
|
4414
|
+
function scoreMatchingSourceStyleFile(file, sourceFile, sourceOptions) {
|
|
4415
|
+
const outputBases = collectOutputMatchBases(file, sourceOptions);
|
|
4416
|
+
const normalizedSourceFile = sourceFile.replace(/[?#].*$/, "");
|
|
4417
|
+
const sourceBases = /* @__PURE__ */ new Set();
|
|
4418
|
+
const addSourceBase = (candidate) => {
|
|
4419
|
+
const stripped = normalizeMatchPath$1(stripStyleExtension(candidate));
|
|
4420
|
+
if (stripped.length > 0) sourceBases.add(stripped);
|
|
4421
|
+
};
|
|
4422
|
+
addSourceBase(normalizedSourceFile);
|
|
4423
|
+
if (node_path.default.isAbsolute(normalizedSourceFile)) for (const root of [sourceOptions.projectRoot, sourceOptions.cwd]) {
|
|
4424
|
+
if (!root) continue;
|
|
4425
|
+
const normalizedRoot = node_path.default.resolve(root);
|
|
4426
|
+
if (isPathWithinRoot$1(normalizedSourceFile, normalizedRoot)) addSourceBase(node_path.default.relative(normalizedRoot, normalizedSourceFile));
|
|
4427
|
+
}
|
|
4428
|
+
let bestScore = 0;
|
|
4429
|
+
for (const outputBase of outputBases) for (const sourceBase of sourceBases) {
|
|
4430
|
+
const commonSuffixSegments = countCommonSuffixSegments(outputBase, sourceBase);
|
|
4431
|
+
if (outputBase === sourceBase) bestScore = Math.max(bestScore, 1e5 + outputBase.length);
|
|
4432
|
+
else if (outputBase.endsWith(`/${sourceBase}`)) bestScore = Math.max(bestScore, 5e4 + sourceBase.length);
|
|
4433
|
+
else if (sourceBase.endsWith(`/${outputBase}`)) bestScore = Math.max(bestScore, 1e3 + outputBase.length);
|
|
4434
|
+
else if (commonSuffixSegments >= 2) bestScore = Math.max(bestScore, 100 + commonSuffixSegments);
|
|
4435
|
+
}
|
|
4436
|
+
return bestScore;
|
|
4437
|
+
}
|
|
4438
|
+
function collectMatchedConfiguredSourceFiles(file, sourceOptions) {
|
|
4439
|
+
const matches = [...(sourceOptions.cssSources ?? []).map((cssSource) => cssSource.file), ...sourceOptions.cssEntries ?? []].filter((sourceFile) => typeof sourceFile === "string" && node_path.default.isAbsolute(sourceFile)).map((sourceFile) => node_path.default.resolve(sourceFile.replace(/[?#].*$/, ""))).filter((sourceFile, index, files) => files.indexOf(sourceFile) === index).map((sourceFile) => ({
|
|
4440
|
+
sourceFile,
|
|
4441
|
+
score: scoreMatchingSourceStyleFile(file, sourceFile, sourceOptions)
|
|
4442
|
+
})).filter((match) => match.score > 0).sort((a, b) => b.score - a.score);
|
|
4443
|
+
const bestScore = matches[0]?.score ?? 0;
|
|
4444
|
+
return matches.filter((match) => match.score === bestScore).map((match) => match.sourceFile);
|
|
4445
|
+
}
|
|
4446
|
+
function hasConfiguredSourceFiles(sourceOptions) {
|
|
4447
|
+
return Boolean(sourceOptions.cssEntries?.length) || Boolean(sourceOptions.cssSources?.some((cssSource) => typeof cssSource.file === "string" && cssSource.file.length > 0));
|
|
4448
|
+
}
|
|
4449
|
+
function createSourceStylePathCandidates(file, sourceOptions) {
|
|
4304
4450
|
const candidates = /* @__PURE__ */ new Set();
|
|
4305
|
-
|
|
4306
|
-
if (
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4451
|
+
const addCandidate = (candidate) => {
|
|
4452
|
+
if (candidate && node_path.default.isAbsolute(candidate)) candidates.add(candidate.replace(/[?#].*$/, ""));
|
|
4453
|
+
};
|
|
4454
|
+
const matchedConfiguredSourceFiles = collectMatchedConfiguredSourceFiles(file, sourceOptions);
|
|
4455
|
+
if (matchedConfiguredSourceFiles.length === 1) addCandidate(matchedConfiguredSourceFiles[0]);
|
|
4456
|
+
else if (matchedConfiguredSourceFiles.length === 0) for (const cssSource of sourceOptions.cssSources ?? []) {
|
|
4457
|
+
const sourceFile = cssSource.file;
|
|
4458
|
+
if (typeof sourceFile === "string" && node_path.default.isAbsolute(sourceFile) && isMatchingSourceStyleFile(file, sourceFile, sourceOptions)) addCandidate(sourceFile);
|
|
4311
4459
|
}
|
|
4460
|
+
if (hasConfiguredSourceFiles(sourceOptions)) return [...candidates];
|
|
4461
|
+
if (!hasConfiguredSourceFiles(sourceOptions)) addCandidate(sourceOptions.sourceFile);
|
|
4312
4462
|
return [...candidates];
|
|
4313
4463
|
}
|
|
4314
4464
|
function extractStyleDirectiveSources(source) {
|
|
@@ -4354,6 +4504,24 @@ function resolvePostcssSourceFile(cssHandlerOptions) {
|
|
|
4354
4504
|
function resolveCssHandlerSourceOptions(cssHandlerOptions) {
|
|
4355
4505
|
return cssHandlerOptions.sourceOptions;
|
|
4356
4506
|
}
|
|
4507
|
+
function createCssEntrySources(cssEntries) {
|
|
4508
|
+
return cssEntries?.filter((entry) => typeof entry === "string" && entry.length > 0 && node_path.default.isAbsolute(entry)).map((entry) => ({ file: node_path.default.resolve(entry) }));
|
|
4509
|
+
}
|
|
4510
|
+
function mergeCssSources(cssSources, cssEntrySources) {
|
|
4511
|
+
const merged = [];
|
|
4512
|
+
const seenFiles = /* @__PURE__ */ new Set();
|
|
4513
|
+
const addSource = (cssSource) => {
|
|
4514
|
+
const file = typeof cssSource.file === "string" && cssSource.file.length > 0 ? node_path.default.resolve(cssSource.file) : void 0;
|
|
4515
|
+
if (file) {
|
|
4516
|
+
if (seenFiles.has(file)) return;
|
|
4517
|
+
seenFiles.add(file);
|
|
4518
|
+
}
|
|
4519
|
+
merged.push(cssSource);
|
|
4520
|
+
};
|
|
4521
|
+
for (const cssSource of cssSources ?? []) addSource(cssSource);
|
|
4522
|
+
for (const cssSource of cssEntrySources ?? []) addSource(cssSource);
|
|
4523
|
+
return merged.length > 0 ? merged : void 0;
|
|
4524
|
+
}
|
|
4357
4525
|
function createSingleTailwindV4SourceOptions(sourceOptions, options) {
|
|
4358
4526
|
return omitUndefined({
|
|
4359
4527
|
projectRoot: sourceOptions.projectRoot,
|
|
@@ -4363,6 +4531,27 @@ function createSingleTailwindV4SourceOptions(sourceOptions, options) {
|
|
|
4363
4531
|
css: options.css
|
|
4364
4532
|
});
|
|
4365
4533
|
}
|
|
4534
|
+
async function resolveTailwindV4CssEntrySource(cssEntry, sourceOptions) {
|
|
4535
|
+
const { cssEntries: _cssEntries, cssSources: _cssSources, ...singleEntrySourceOptions } = sourceOptions;
|
|
4536
|
+
if (!(0, node_fs.existsSync)(cssEntry)) return resolveTailwindV4Source({
|
|
4537
|
+
...omitUndefined(singleEntrySourceOptions),
|
|
4538
|
+
cssEntries: [cssEntry]
|
|
4539
|
+
});
|
|
4540
|
+
const css = (0, node_fs.readFileSync)(cssEntry, "utf8");
|
|
4541
|
+
const base = node_path.default.dirname(node_path.default.resolve(cssEntry));
|
|
4542
|
+
const entrySource = resolveCssEntrySource(css, base, { removeConfig: false });
|
|
4543
|
+
const config = resolveExistingConfigPath(entrySource?.config, entrySource?.configRequest, cssEntry, sourceOptions);
|
|
4544
|
+
return withGeneratorSourceMetadata(await resolveTailwindV4Source({
|
|
4545
|
+
...omitUndefined(singleEntrySourceOptions),
|
|
4546
|
+
base,
|
|
4547
|
+
css: normalizeConfigDirective(css, config),
|
|
4548
|
+
cssEntries: [cssEntry]
|
|
4549
|
+
}), {
|
|
4550
|
+
matchedCssSourceFile: cssEntry,
|
|
4551
|
+
sourceBase: base,
|
|
4552
|
+
sourceCss: css
|
|
4553
|
+
});
|
|
4554
|
+
}
|
|
4366
4555
|
function resolveCssSourceBase(file, cssHandlerOptions) {
|
|
4367
4556
|
const normalized = (resolvePostcssFromOption(cssHandlerOptions) ?? file).replace(/[?#].*$/, "");
|
|
4368
4557
|
return node_path.default.dirname(node_path.default.resolve(normalized));
|
|
@@ -4372,24 +4561,30 @@ function resolveExistingConfigPath(config, configRequest, file, sourceOptions) {
|
|
|
4372
4561
|
if (!configRequest || node_path.default.isAbsolute(configRequest)) return sourceOptions.config;
|
|
4373
4562
|
const outputDir = node_path.default.dirname(file.replace(/[?#].*$/, ""));
|
|
4374
4563
|
const baseCandidates = [
|
|
4564
|
+
sourceOptions.sourceFile ? node_path.default.dirname(sourceOptions.sourceFile.replace(/[?#].*$/, "")) : void 0,
|
|
4565
|
+
node_path.default.isAbsolute(outputDir) ? outputDir : void 0,
|
|
4375
4566
|
sourceOptions.projectRoot,
|
|
4376
|
-
sourceOptions.cwd
|
|
4377
|
-
node_process.default.cwd()
|
|
4567
|
+
sourceOptions.cwd
|
|
4378
4568
|
].filter((item) => typeof item === "string" && item.length > 0);
|
|
4569
|
+
const seenCandidates = /* @__PURE__ */ new Set();
|
|
4570
|
+
const configCandidates = [];
|
|
4571
|
+
const addConfigCandidate = (candidate) => {
|
|
4572
|
+
if (!candidate) return;
|
|
4573
|
+
const normalized = node_path.default.resolve(candidate);
|
|
4574
|
+
if (seenCandidates.has(normalized)) return;
|
|
4575
|
+
seenCandidates.add(normalized);
|
|
4576
|
+
configCandidates.push(normalized);
|
|
4577
|
+
};
|
|
4379
4578
|
for (const base of baseCandidates) {
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
node_path.default.resolve(base, "src", configRequest),
|
|
4383
|
-
node_path.default.resolve(base, outputDir, configRequest),
|
|
4384
|
-
node_path.default.resolve(base, "src", outputDir, configRequest)
|
|
4385
|
-
];
|
|
4386
|
-
for (const candidate of candidates) if ((0, node_fs.existsSync)(candidate)) return candidate;
|
|
4579
|
+
addConfigCandidate(node_path.default.resolve(base, configRequest));
|
|
4580
|
+
if (!node_path.default.isAbsolute(outputDir)) addConfigCandidate(node_path.default.resolve(base, outputDir, configRequest));
|
|
4387
4581
|
}
|
|
4582
|
+
for (const candidate of configCandidates) if ((0, node_fs.existsSync)(candidate)) return candidate;
|
|
4388
4583
|
return sourceOptions.config;
|
|
4389
4584
|
}
|
|
4390
|
-
function canResolveSourceSideCssEntry(file, cssHandlerOptions) {
|
|
4585
|
+
function canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) {
|
|
4391
4586
|
const from = resolvePostcssFromOption(cssHandlerOptions);
|
|
4392
|
-
if (!from || !node_path.default.isAbsolute(from)) return node_path.default.isAbsolute(file);
|
|
4587
|
+
if (!from || !node_path.default.isAbsolute(from)) return node_path.default.isAbsolute(file) || Boolean(sourceOptions?.sourceFile) || Boolean(sourceOptions?.cssSources?.length);
|
|
4393
4588
|
return true;
|
|
4394
4589
|
}
|
|
4395
4590
|
function shouldResolveSourceSideCssEntry(rawSource) {
|
|
@@ -4398,6 +4593,9 @@ function shouldResolveSourceSideCssEntry(rawSource) {
|
|
|
4398
4593
|
function shouldPreferTailwindV3SourceSideEntry(rawSource, sourceSideEntrySource) {
|
|
4399
4594
|
return Boolean(sourceSideEntrySource) && !hasTailwindSourceDirectives(rawSource, { importFallback: true });
|
|
4400
4595
|
}
|
|
4596
|
+
function shouldPreferResolvedSourceSideEntry(cssEntrySource, sourceSideEntrySource) {
|
|
4597
|
+
return Boolean(sourceSideEntrySource?.config) && Boolean(cssEntrySource?.configRequest) && (!cssEntrySource?.config || !(0, node_fs.existsSync)(cssEntrySource.config));
|
|
4598
|
+
}
|
|
4401
4599
|
function normalizeCssSourceForCompare(css) {
|
|
4402
4600
|
return stripGeneratorPlaceholderMarkers(stripTailwindBanners(css)).trim();
|
|
4403
4601
|
}
|
|
@@ -4413,38 +4611,119 @@ function getOutputFileWithoutExtension(file) {
|
|
|
4413
4611
|
function normalizeMatchPath(file) {
|
|
4414
4612
|
return file.split(node_path.default.sep).join("/");
|
|
4415
4613
|
}
|
|
4416
|
-
function
|
|
4417
|
-
const
|
|
4418
|
-
|
|
4419
|
-
|
|
4420
|
-
|
|
4614
|
+
function isPathWithinRoot(file, root) {
|
|
4615
|
+
const relative = node_path.default.relative(root, file);
|
|
4616
|
+
return Boolean(relative) && !relative.startsWith("..") && !node_path.default.isAbsolute(relative);
|
|
4617
|
+
}
|
|
4618
|
+
function collectCssSourceMatchBases(file, roots) {
|
|
4619
|
+
const normalizedFile = file.replace(/[?#].*$/, "");
|
|
4620
|
+
const bases = /* @__PURE__ */ new Set();
|
|
4621
|
+
const addBase = (candidate) => {
|
|
4622
|
+
const base = normalizeMatchPath(getOutputFileWithoutExtension(candidate));
|
|
4623
|
+
if (base.length > 0) {
|
|
4624
|
+
bases.add(base);
|
|
4625
|
+
const withoutWorkspaceSegment = base.replace(/^(?:src|dist)\//, "");
|
|
4626
|
+
if (withoutWorkspaceSegment !== base && withoutWorkspaceSegment.length > 0) bases.add(withoutWorkspaceSegment);
|
|
4627
|
+
}
|
|
4628
|
+
};
|
|
4629
|
+
addBase(normalizedFile);
|
|
4630
|
+
const resolvedRoots = roots.filter((root) => typeof root === "string" && root.length > 0).map((root) => node_path.default.resolve(root));
|
|
4631
|
+
if (node_path.default.isAbsolute(normalizedFile)) {
|
|
4632
|
+
for (const root of resolvedRoots) if (isPathWithinRoot(normalizedFile, root)) addBase(node_path.default.relative(root, normalizedFile));
|
|
4633
|
+
} else for (const root of resolvedRoots) addBase(node_path.default.resolve(root, normalizedFile));
|
|
4634
|
+
return bases;
|
|
4635
|
+
}
|
|
4636
|
+
function hasMatchingCssSourceBase(outputBases, sourceBases) {
|
|
4637
|
+
for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase || outputBase.endsWith(`/${sourceBase}`) || sourceBase.endsWith(`/${outputBase}`)) return true;
|
|
4638
|
+
return false;
|
|
4639
|
+
}
|
|
4640
|
+
function isMatchingTailwindV4CssSourceFile(file, cssSourceFile, sourceOptions) {
|
|
4641
|
+
return hasMatchingCssSourceBase(collectCssSourceMatchBases(file, [
|
|
4642
|
+
sourceOptions.outputRoot,
|
|
4643
|
+
sourceOptions.projectRoot,
|
|
4644
|
+
sourceOptions.cwd
|
|
4645
|
+
]), collectCssSourceMatchBases(cssSourceFile, [sourceOptions.projectRoot, sourceOptions.cwd]));
|
|
4421
4646
|
}
|
|
4422
|
-
function
|
|
4423
|
-
const
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4647
|
+
function scoreTailwindV4CssSourceFileMatch(file, cssSourceFile, sourceOptions) {
|
|
4648
|
+
const outputBases = collectCssSourceMatchBases(file, [
|
|
4649
|
+
sourceOptions.outputRoot,
|
|
4650
|
+
sourceOptions.projectRoot,
|
|
4651
|
+
sourceOptions.cwd
|
|
4652
|
+
]);
|
|
4653
|
+
const sourceBases = collectCssSourceMatchBases(cssSourceFile, [sourceOptions.projectRoot, sourceOptions.cwd]);
|
|
4654
|
+
let bestScore = 0;
|
|
4655
|
+
for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase) bestScore = Math.max(bestScore, 1e5 + outputBase.length);
|
|
4656
|
+
else if (outputBase.endsWith(`/${sourceBase}`)) bestScore = Math.max(bestScore, 5e4 + sourceBase.length);
|
|
4657
|
+
else if (sourceBase.endsWith(`/${outputBase}`)) bestScore = Math.max(bestScore, 1e3 + outputBase.length);
|
|
4658
|
+
return bestScore;
|
|
4428
4659
|
}
|
|
4429
4660
|
function resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) {
|
|
4430
4661
|
const cssEntries = sourceOptions.cssEntries;
|
|
4431
4662
|
if (!cssEntries?.length) return;
|
|
4432
4663
|
const normalizedRawSource = normalizeCssSourceForCompare(rawSource);
|
|
4433
4664
|
const outputStem = getOutputFileStem(file);
|
|
4434
|
-
const
|
|
4435
|
-
if (!(0, node_fs.existsSync)(cssEntry)) return
|
|
4665
|
+
const matches = cssEntries.map((cssEntry) => {
|
|
4666
|
+
if (!(0, node_fs.existsSync)(cssEntry)) return;
|
|
4436
4667
|
try {
|
|
4437
|
-
|
|
4438
|
-
|
|
4668
|
+
const entrySource = (0, node_fs.readFileSync)(cssEntry, "utf8");
|
|
4669
|
+
const pathScore = scoreTailwindV4CssSourceFileMatch(file, cssEntry, sourceOptions);
|
|
4670
|
+
if (normalizeCssSourceForCompare(entrySource) === normalizedRawSource) return {
|
|
4671
|
+
cssEntry,
|
|
4672
|
+
score: 1e6 + pathScore
|
|
4673
|
+
};
|
|
4674
|
+
if (pathScore > 0) return {
|
|
4675
|
+
cssEntry,
|
|
4676
|
+
score: pathScore
|
|
4677
|
+
};
|
|
4678
|
+
if (cssEntries.length === 1 && outputStem.length > 0 && getOutputFileStem(cssEntry) === outputStem) return {
|
|
4679
|
+
cssEntry,
|
|
4680
|
+
score: 1
|
|
4681
|
+
};
|
|
4682
|
+
return;
|
|
4439
4683
|
} catch {
|
|
4440
|
-
return
|
|
4684
|
+
return;
|
|
4441
4685
|
}
|
|
4442
|
-
});
|
|
4686
|
+
}).filter((match) => Boolean(match)).sort((a, b) => b.score - a.score);
|
|
4687
|
+
const bestScore = matches[0]?.score;
|
|
4688
|
+
const matchingEntry = bestScore && matches.filter((match) => match.score === bestScore).length === 1 ? matches[0]?.cssEntry : void 0;
|
|
4443
4689
|
if (!matchingEntry) return;
|
|
4444
|
-
return
|
|
4445
|
-
|
|
4446
|
-
|
|
4690
|
+
return resolveTailwindV4CssEntrySource(matchingEntry, sourceOptions);
|
|
4691
|
+
}
|
|
4692
|
+
function normalizeTailwindV4CssSourceConfig(cssSource, sourceBase) {
|
|
4693
|
+
if (typeof cssSource.css !== "string" || cssSource.css.length === 0 || !cssSource.css.includes("@config")) return cssSource;
|
|
4694
|
+
const entrySource = resolveCssEntrySource(cssSource.css, sourceBase, { removeConfig: false });
|
|
4695
|
+
if (!entrySource?.config) return cssSource;
|
|
4696
|
+
return {
|
|
4697
|
+
...cssSource,
|
|
4698
|
+
css: normalizeConfigDirective(cssSource.css, entrySource.config)
|
|
4699
|
+
};
|
|
4700
|
+
}
|
|
4701
|
+
function hydrateTailwindV4CssSource(cssSource) {
|
|
4702
|
+
if (typeof cssSource.css === "string" && cssSource.css.length > 0) return cssSource;
|
|
4703
|
+
if (typeof cssSource.file !== "string" || !(0, node_fs.existsSync)(cssSource.file)) return cssSource;
|
|
4704
|
+
const file = node_path.default.resolve(cssSource.file);
|
|
4705
|
+
return {
|
|
4706
|
+
...cssSource,
|
|
4707
|
+
file,
|
|
4708
|
+
base: cssSource.base ?? node_path.default.dirname(file),
|
|
4709
|
+
css: (0, node_fs.readFileSync)(file, "utf8"),
|
|
4710
|
+
dependencies: [...new Set([...cssSource.dependencies ?? [], file])]
|
|
4711
|
+
};
|
|
4712
|
+
}
|
|
4713
|
+
function normalizeTailwindV4CssSourceConfigs(sourceOptions) {
|
|
4714
|
+
if (!sourceOptions.cssSources?.length) return sourceOptions;
|
|
4715
|
+
const sourceBaseFallback = sourceOptions.base ?? sourceOptions.projectRoot ?? node_process.default.cwd();
|
|
4716
|
+
let changed = false;
|
|
4717
|
+
const cssSources = sourceOptions.cssSources.map((cssSource) => {
|
|
4718
|
+
const hydratedCssSource = hydrateTailwindV4CssSource(cssSource);
|
|
4719
|
+
const normalizedCssSource = normalizeTailwindV4CssSourceConfig(hydratedCssSource, resolveTailwindV4CssSourceBase(hydratedCssSource, sourceBaseFallback));
|
|
4720
|
+
changed ||= normalizedCssSource !== cssSource;
|
|
4721
|
+
return normalizedCssSource;
|
|
4447
4722
|
});
|
|
4723
|
+
return changed ? {
|
|
4724
|
+
...sourceOptions,
|
|
4725
|
+
cssSources
|
|
4726
|
+
} : sourceOptions;
|
|
4448
4727
|
}
|
|
4449
4728
|
async function resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions) {
|
|
4450
4729
|
const cssSources = sourceOptions.cssSources;
|
|
@@ -4454,11 +4733,11 @@ async function resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOpt
|
|
|
4454
4733
|
const matchingSource = cssSources.find((cssSource) => {
|
|
4455
4734
|
if (typeof cssSource.css !== "string" || cssSource.css.length === 0) return false;
|
|
4456
4735
|
if (sourceFile && typeof cssSource.file === "string" && node_path.default.resolve(sourceFile) === node_path.default.resolve(cssSource.file)) return true;
|
|
4457
|
-
if (typeof cssSource.file === "string" && isMatchingTailwindV4CssSourceFile(file, cssSource.file)) return true;
|
|
4736
|
+
if (typeof cssSource.file === "string" && isMatchingTailwindV4CssSourceFile(file, cssSource.file, sourceOptions)) return true;
|
|
4458
4737
|
return normalizeCssSourceForCompare(cssSource.css) === normalizedRawSource;
|
|
4459
4738
|
});
|
|
4460
4739
|
if (!matchingSource) return;
|
|
4461
|
-
return resolveSingleTailwindV4CssSource(matchingSource, sourceOptions);
|
|
4740
|
+
return resolveSingleTailwindV4CssSource(matchingSource, sourceOptions, { matched: true });
|
|
4462
4741
|
}
|
|
4463
4742
|
function tryResolveTailwindV4SourceOptions(runtimeState) {
|
|
4464
4743
|
try {
|
|
@@ -4470,16 +4749,16 @@ function tryResolveTailwindV4SourceOptions(runtimeState) {
|
|
|
4470
4749
|
function hasConfiguredTailwindV4CssSource(sourceOptions) {
|
|
4471
4750
|
return Boolean(sourceOptions?.css) || Boolean(sourceOptions?.cssSources?.length);
|
|
4472
4751
|
}
|
|
4473
|
-
async function resolveSingleTailwindV4CssSource(cssSource, sourceOptions) {
|
|
4474
|
-
const
|
|
4752
|
+
async function resolveSingleTailwindV4CssSource(cssSource, sourceOptions, options = {}) {
|
|
4753
|
+
const sourceBase = resolveTailwindV4CssSourceBase(cssSource, sourceOptions.base ?? sourceOptions.projectRoot ?? node_process.default.cwd());
|
|
4754
|
+
const normalizedCssSource = normalizeTailwindV4CssSourceConfig(cssSource, sourceBase);
|
|
4755
|
+
return withGeneratorSourceMetadata(await resolveTailwindV4Source({
|
|
4475
4756
|
...omitUndefined(sourceOptions),
|
|
4476
|
-
cssSources: [
|
|
4477
|
-
})
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
sourceBase: resolveTailwindV4CssSourceBase(cssSource, sourceBaseFallback),
|
|
4482
|
-
sourceCss: cssSource.css
|
|
4757
|
+
cssSources: [normalizedCssSource]
|
|
4758
|
+
}), {
|
|
4759
|
+
matchedCssSourceFile: options.matched && typeof normalizedCssSource.file === "string" ? normalizedCssSource.file : void 0,
|
|
4760
|
+
sourceBase,
|
|
4761
|
+
sourceCss: normalizedCssSource.css
|
|
4483
4762
|
});
|
|
4484
4763
|
}
|
|
4485
4764
|
async function resolveTailwindV4CssSourceEntries(cssSource, sourceOptions) {
|
|
@@ -4493,10 +4772,10 @@ function countRuntimeCandidateHits(candidates, runtime) {
|
|
|
4493
4772
|
for (const candidate of candidates) if (runtime.has(candidate)) hits += 1;
|
|
4494
4773
|
return hits;
|
|
4495
4774
|
}
|
|
4496
|
-
async function resolveCandidateMatchedTailwindV4CssSource(_rawSource,
|
|
4775
|
+
async function resolveCandidateMatchedTailwindV4CssSource(_rawSource, _cssHandlerOptions, sourceOptions, selectionOptions) {
|
|
4497
4776
|
const cssSources = sourceOptions.cssSources;
|
|
4498
4777
|
const getSourceCandidatesForEntries = selectionOptions?.getSourceCandidatesForEntries;
|
|
4499
|
-
if (!
|
|
4778
|
+
if (!cssSources?.length || !getSourceCandidatesForEntries) return;
|
|
4500
4779
|
const matches = [];
|
|
4501
4780
|
await Promise.all(cssSources.map(async (cssSource, index) => {
|
|
4502
4781
|
const resolved = await resolveTailwindV4CssSourceEntries(cssSource, sourceOptions);
|
|
@@ -4517,13 +4796,10 @@ async function resolveCandidateMatchedTailwindV4CssSource(_rawSource, cssHandler
|
|
|
4517
4796
|
const second = matches[1];
|
|
4518
4797
|
if (!best) return;
|
|
4519
4798
|
if (second && second.runtimeHits === best.runtimeHits && second.totalCandidates === best.totalCandidates) return;
|
|
4520
|
-
return resolveSingleTailwindV4CssSource(best.cssSource, sourceOptions);
|
|
4799
|
+
return resolveSingleTailwindV4CssSource(best.cssSource, sourceOptions, { matched: true });
|
|
4521
4800
|
}
|
|
4522
4801
|
function createTailwindV4CssSourceResolver(sourceOptions, generatorOptions) {
|
|
4523
|
-
return (cssSource) =>
|
|
4524
|
-
...omitUndefined(sourceOptions),
|
|
4525
|
-
cssSources: [cssSource]
|
|
4526
|
-
}).then((source) => generatorOptions?.config ? {
|
|
4802
|
+
return (cssSource) => resolveSingleTailwindV4CssSource(cssSource, sourceOptions).then((source) => generatorOptions?.config ? {
|
|
4527
4803
|
...source,
|
|
4528
4804
|
css: prependConfigDirective(source.css, generatorOptions.config)
|
|
4529
4805
|
} : source);
|
|
@@ -4544,6 +4820,15 @@ function withGeneratorSourceMetadata(source, metadata) {
|
|
|
4544
4820
|
__weappTailwindcssMeta: metadata
|
|
4545
4821
|
};
|
|
4546
4822
|
}
|
|
4823
|
+
function resolveTailwindV3SourceEntries(source) {
|
|
4824
|
+
if (!("version" in source) || source.version !== 3) return;
|
|
4825
|
+
const entries = normalizeLegacyContentEntries(source.configObject?.content, source.cwd, { relativeBase: source.config ? node_path.default.dirname(source.config) : source.cwd });
|
|
4826
|
+
return entries.length > 0 ? entries : void 0;
|
|
4827
|
+
}
|
|
4828
|
+
function withTailwindV3SourceMetadata(source) {
|
|
4829
|
+
const sourceEntries = resolveTailwindV3SourceEntries(source);
|
|
4830
|
+
return sourceEntries ? withGeneratorSourceMetadata(source, { sourceEntries }) : source;
|
|
4831
|
+
}
|
|
4547
4832
|
function withMatchedSourceSideMetadata(source, resolvedEntrySource) {
|
|
4548
4833
|
return resolvedEntrySource.file ? withGeneratorSourceMetadata(source, {
|
|
4549
4834
|
matchedCssSourceFile: resolvedEntrySource.file,
|
|
@@ -4566,43 +4851,52 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
|
|
|
4566
4851
|
const mergedSourceOptions = omitUndefined({
|
|
4567
4852
|
...sourceOptions,
|
|
4568
4853
|
config: generatorOptions?.config ?? sourceOptions.config,
|
|
4569
|
-
|
|
4854
|
+
sourceFile: resolvePostcssSourceFile(cssHandlerOptions),
|
|
4855
|
+
...resolveCssHandlerSourceOptions(cssHandlerOptions),
|
|
4856
|
+
cssEntries: selectionOptions?.cssEntries,
|
|
4857
|
+
cssSources: createCssEntrySources(selectionOptions?.cssEntries)
|
|
4570
4858
|
});
|
|
4571
4859
|
const applyEntrySource = hasTailwindApplyDirective(rawSource) ? {
|
|
4572
4860
|
base,
|
|
4573
4861
|
css: rawSource
|
|
4574
4862
|
} : void 0;
|
|
4575
|
-
const sourceSideEntrySource = canResolveSourceSideCssEntry(file, cssHandlerOptions) ? resolveSourceSideCssEntrySource(file, mergedSourceOptions, { removeConfig: true }) : void 0;
|
|
4576
|
-
const
|
|
4577
|
-
|
|
4578
|
-
if (
|
|
4863
|
+
const sourceSideEntrySource = canResolveSourceSideCssEntry(file, cssHandlerOptions, mergedSourceOptions) ? resolveSourceSideCssEntrySource(file, mergedSourceOptions, { removeConfig: true }) : void 0;
|
|
4864
|
+
const shouldPreferSourceSideEntry = shouldPreferResolvedSourceSideEntry(cssEntrySource, sourceSideEntrySource);
|
|
4865
|
+
const resolvedEntrySource = shouldResolveSourceSideCssEntry(rawSource) ? shouldPreferSourceSideEntry ? sourceSideEntrySource ?? cssEntrySource ?? applyEntrySource : cssEntrySource ?? applyEntrySource ?? sourceSideEntrySource : shouldPreferTailwindV3SourceSideEntry(rawSource, sourceSideEntrySource) || shouldPreferSourceSideEntry ? sourceSideEntrySource ?? cssEntrySource ?? applyEntrySource : cssEntrySource ?? applyEntrySource ?? sourceSideEntrySource;
|
|
4866
|
+
if (!resolvedEntrySource) return withTailwindV3SourceMetadata(await (generatorOptions?.config ? resolveTailwindV3Source(mergedSourceOptions) : resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher)));
|
|
4867
|
+
if (cssEntrySource && !sourceSideEntrySource && !applyEntrySource && !hasTailwindRootDirectives(rawSource, { importFallback: true })) return withTailwindV3SourceMetadata(await (generatorOptions?.config ? resolveTailwindV3Source(mergedSourceOptions) : resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher)));
|
|
4579
4868
|
const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, omitUndefined(mergedSourceOptions));
|
|
4580
|
-
|
|
4869
|
+
const sourceWithMetadata = withTailwindV3SourceMetadata(await resolveTailwindV3Source({
|
|
4581
4870
|
...mergedSourceOptions,
|
|
4582
4871
|
base: resolvedEntrySource.base,
|
|
4583
4872
|
css: normalizeTailwindV3CssEntrySource(resolvedEntrySource.css),
|
|
4584
4873
|
...config ? { config } : {}
|
|
4874
|
+
}));
|
|
4875
|
+
return withGeneratorSourceMetadata(sourceWithMetadata, {
|
|
4876
|
+
...sourceWithMetadata.__weappTailwindcssMeta,
|
|
4877
|
+
matchedCssSourceFile: resolvedEntrySource.file
|
|
4585
4878
|
});
|
|
4586
4879
|
}
|
|
4587
4880
|
const sourceOptions = tryResolveTailwindV4SourceOptions(runtimeState);
|
|
4588
4881
|
const resolvedSourceOptions = sourceOptions ? omitUndefined({
|
|
4589
4882
|
...sourceOptions,
|
|
4590
|
-
|
|
4883
|
+
sourceFile: resolvePostcssSourceFile(cssHandlerOptions),
|
|
4884
|
+
...resolveCssHandlerSourceOptions(cssHandlerOptions),
|
|
4885
|
+
cssEntries: selectionOptions?.cssEntries ?? sourceOptions.cssEntries,
|
|
4886
|
+
cssSources: mergeCssSources(sourceOptions.cssSources, sourceOptions.cssSources?.length ? void 0 : createCssEntrySources(selectionOptions?.cssEntries ?? sourceOptions.cssEntries))
|
|
4591
4887
|
}) : void 0;
|
|
4592
|
-
const
|
|
4593
|
-
const
|
|
4594
|
-
const
|
|
4595
|
-
const
|
|
4596
|
-
const
|
|
4888
|
+
const normalizedSourceOptions = resolvedSourceOptions ? normalizeTailwindV4CssSourceConfigs(resolvedSourceOptions) : void 0;
|
|
4889
|
+
const shouldPreferSourceSideEntry = shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder")) && (sourceOptions?.cssEntries?.length ?? 0) <= 1;
|
|
4890
|
+
const sourceSideEntrySource = normalizedSourceOptions && shouldPreferSourceSideEntry && canResolveSourceSideCssEntry(file, cssHandlerOptions, normalizedSourceOptions) ? resolveSourceSideCssEntrySource(file, normalizedSourceOptions, { removeConfig: false }) : void 0;
|
|
4891
|
+
const matchedCssEntrySource = normalizedSourceOptions ? await resolveMatchingTailwindV4CssEntry(rawSource, file, normalizedSourceOptions) : void 0;
|
|
4892
|
+
const matchedCssSource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, normalizedSourceOptions) : void 0;
|
|
4893
|
+
const candidateMatchedCssSource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, normalizedSourceOptions, selectionOptions) : void 0;
|
|
4894
|
+
const configuredCssSource = normalizedSourceOptions && hasConfiguredTailwindV4CssSource(normalizedSourceOptions) && hasTailwindGeneratedCssMarkers(rawSource) ? matchedCssSource ?? candidateMatchedCssSource ?? await resolveTailwindV4Source(normalizedSourceOptions) : void 0;
|
|
4597
4895
|
if (configuredCssSource) return generatorOptions?.config ? {
|
|
4598
4896
|
...configuredCssSource,
|
|
4599
4897
|
css: prependConfigDirective(configuredCssSource.css, generatorOptions.config)
|
|
4600
4898
|
} : configuredCssSource;
|
|
4601
|
-
const
|
|
4602
|
-
const mainCssEntrySource = sourceOptions && cssHandlerOptions.isMainChunk && sourceOptions.cssEntries?.length === 1 ? await resolveTailwindV4Source({
|
|
4603
|
-
...omitUndefined(sourceOptions),
|
|
4604
|
-
cssEntries: [sourceOptions.cssEntries[0]]
|
|
4605
|
-
}) : void 0;
|
|
4899
|
+
const mainCssEntrySource = normalizedSourceOptions && cssHandlerOptions.isMainChunk && normalizedSourceOptions.cssEntries?.length === 1 ? await resolveTailwindV4CssEntrySource(normalizedSourceOptions.cssEntries[0], normalizedSourceOptions) : void 0;
|
|
4606
4900
|
const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource ?? mainCssEntrySource;
|
|
4607
4901
|
if (preferredCssEntrySource) return generatorOptions?.config ? {
|
|
4608
4902
|
...preferredCssEntrySource,
|
|
@@ -4616,11 +4910,12 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
|
|
|
4616
4910
|
css: prependConfigDirective(source.css, generatorOptions.config)
|
|
4617
4911
|
} : source;
|
|
4618
4912
|
}
|
|
4619
|
-
if (sourceSideEntrySource &&
|
|
4913
|
+
if (sourceSideEntrySource && normalizedSourceOptions) return resolveTailwindV4SourceSideEntrySource(sourceSideEntrySource, normalizedSourceOptions, generatorOptions, file);
|
|
4620
4914
|
const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, resolvedSourceOptions ?? {});
|
|
4621
|
-
const
|
|
4622
|
-
|
|
4623
|
-
|
|
4915
|
+
const sourceBase = resolvedEntrySource === cssEntrySource && config ? node_path.default.dirname(config) : resolvedEntrySource.base;
|
|
4916
|
+
const css = createTailwindV4ApplyReferenceSource(normalizeConfigDirective(prependConfigDirective(resolvedEntrySource.css, generatorOptions?.config), config), normalizedSourceOptions ?? {});
|
|
4917
|
+
return resolveTailwindV4Source(createSingleTailwindV4SourceOptions(normalizedSourceOptions ?? {}, {
|
|
4918
|
+
base: sourceBase,
|
|
4624
4919
|
css
|
|
4625
4920
|
}));
|
|
4626
4921
|
}
|
|
@@ -4635,18 +4930,23 @@ async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, fi
|
|
|
4635
4930
|
}
|
|
4636
4931
|
let sourceOptions;
|
|
4637
4932
|
try {
|
|
4933
|
+
const sourceOptionsFromPatcher = resolveTailwindV4SourceOptionsFromPatcher(runtimeState.twPatcher);
|
|
4934
|
+
const cssEntries = selectionOptions?.cssEntries ?? sourceOptionsFromPatcher.cssEntries;
|
|
4638
4935
|
sourceOptions = omitUndefined({
|
|
4639
|
-
...
|
|
4640
|
-
|
|
4936
|
+
...sourceOptionsFromPatcher,
|
|
4937
|
+
sourceFile: resolvePostcssSourceFile(cssHandlerOptions),
|
|
4938
|
+
...resolveCssHandlerSourceOptions(cssHandlerOptions),
|
|
4939
|
+
cssEntries,
|
|
4940
|
+
cssSources: mergeCssSources(sourceOptionsFromPatcher.cssSources, sourceOptionsFromPatcher.cssSources?.length ? void 0 : createCssEntrySources(cssEntries))
|
|
4641
4941
|
});
|
|
4642
4942
|
} catch {
|
|
4643
4943
|
const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
|
|
4644
4944
|
return resolved ? [resolved] : [];
|
|
4645
4945
|
}
|
|
4646
|
-
const matchedCssEntrySource =
|
|
4946
|
+
const matchedCssEntrySource = sourceOptions ? await resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) : void 0;
|
|
4647
4947
|
const matchedCssSource = await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions);
|
|
4648
4948
|
const candidateMatchedCssSource = await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, sourceOptions, selectionOptions);
|
|
4649
|
-
const sourceSideCssSource = await resolveTailwindV4SourceSideEntrySource(shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder")) ? resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: false }) : void 0, sourceOptions, generatorOptions, file);
|
|
4949
|
+
const sourceSideCssSource = await resolveTailwindV4SourceSideEntrySource((shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder")) && (sourceOptions.cssEntries?.length ?? 0) <= 1) && canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) ? resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: false }) : void 0, sourceOptions, generatorOptions, file);
|
|
4650
4950
|
const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource;
|
|
4651
4951
|
if (sourceSideCssSource) return [sourceSideCssSource];
|
|
4652
4952
|
if (preferredCssEntrySource) return [generatorOptions?.config ? {
|
|
@@ -4654,14 +4954,20 @@ async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, fi
|
|
|
4654
4954
|
css: prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
|
|
4655
4955
|
} : preferredCssEntrySource];
|
|
4656
4956
|
if (!sourceOptions.cssEntries || sourceOptions.cssEntries.length <= 1) {
|
|
4957
|
+
if (cssHandlerOptions.isMainChunk && sourceOptions.cssEntries?.length === 1) return [await resolveTailwindV4CssEntrySource(sourceOptions.cssEntries[0], normalizeTailwindV4CssSourceConfigs(sourceOptions)).then((source) => generatorOptions?.config ? {
|
|
4958
|
+
...source,
|
|
4959
|
+
css: prependConfigDirective(source.css, generatorOptions.config)
|
|
4960
|
+
} : source)];
|
|
4657
4961
|
if (sourceOptions.cssSources?.length === 1) return [await createTailwindV4CssSourceResolver(sourceOptions, generatorOptions)(sourceOptions.cssSources[0])];
|
|
4658
4962
|
const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
|
|
4659
4963
|
return resolved ? [resolved] : [];
|
|
4660
4964
|
}
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
}
|
|
4965
|
+
if (cssHandlerOptions.isMainChunk && !cssEntrySource && !hasTailwindGeneratedCss(rawSource) && !hasTailwindGeneratedCssMarkers(rawSource) && !hasTailwindSourceDirectives(rawSource, { importFallback: generatorOptions?.importFallback ?? false }) && !rawSource.includes("weapp-tailwindcss generator-placeholder") && !hasConfiguredTailwindV4CssSource(sourceOptions)) {
|
|
4966
|
+
const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
|
|
4967
|
+
return resolved ? [resolved] : [];
|
|
4968
|
+
}
|
|
4969
|
+
const normalizedCssSourceOptions = normalizeTailwindV4CssSourceConfigs(sourceOptions);
|
|
4970
|
+
const cssEntrySources = await Promise.all(sourceOptions.cssEntries.map((cssEntry) => resolveTailwindV4CssEntrySource(cssEntry, normalizedCssSourceOptions).then((source) => generatorOptions?.config ? {
|
|
4665
4971
|
...source,
|
|
4666
4972
|
css: prependConfigDirective(source.css, generatorOptions.config)
|
|
4667
4973
|
} : source)));
|
|
@@ -4669,8 +4975,9 @@ async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, fi
|
|
|
4669
4975
|
return [...cssEntrySources, ...cssSources];
|
|
4670
4976
|
}
|
|
4671
4977
|
async function resolveGeneratorSourceEntries(source, runtimeState) {
|
|
4672
|
-
if (!("css" in source) || !("base" in source) || !("baseFallbacks" in source)) return;
|
|
4673
4978
|
const sourceMetadata = source.__weappTailwindcssMeta;
|
|
4979
|
+
if (sourceMetadata?.sourceEntries) return sourceMetadata.sourceEntries;
|
|
4980
|
+
if (!("css" in source) || !("base" in source) || !("baseFallbacks" in source)) return;
|
|
4674
4981
|
const resolved = await resolveTailwindV4EntriesFromCss(sourceMetadata?.sourceCss ?? source.css, sourceMetadata?.sourceBase ?? source.base);
|
|
4675
4982
|
if (resolved?.entries.length || !resolved?.explicit && !sourceMetadata?.matchedCssSourceFile || !runtimeState) return resolved?.entries;
|
|
4676
4983
|
const matchingCssSource = tryResolveTailwindV4SourceOptions(runtimeState)?.cssSources?.find((cssSource) => {
|
|
@@ -4786,7 +5093,7 @@ function countUnclosedBlocks(source) {
|
|
|
4786
5093
|
}
|
|
4787
5094
|
function closeTrailingUnclosedBlocks(source) {
|
|
4788
5095
|
try {
|
|
4789
|
-
|
|
5096
|
+
require_watch_dependencies.postcss_default.parse(source);
|
|
4790
5097
|
return source;
|
|
4791
5098
|
} catch (error) {
|
|
4792
5099
|
if (error.reason !== "Unclosed block") return source;
|
|
@@ -4796,7 +5103,7 @@ function closeTrailingUnclosedBlocks(source) {
|
|
|
4796
5103
|
}
|
|
4797
5104
|
function removeTailwindApplyRules(rawSource) {
|
|
4798
5105
|
try {
|
|
4799
|
-
const root =
|
|
5106
|
+
const root = require_watch_dependencies.postcss_default.parse(rawSource);
|
|
4800
5107
|
let removed = false;
|
|
4801
5108
|
root.walkAtRules("apply", (rule) => {
|
|
4802
5109
|
const parent = rule.parent;
|
|
@@ -4888,7 +5195,7 @@ const CSS_LENGTH_UNIT_RE = /(?:^|[\s(,])[-+]?(?:\d+|\d*\.\d+)(?:px|rem)\b/i;
|
|
|
4888
5195
|
const RPX_UNIT_RE = /(?:^|[\s(,])[-+]?(?:\d+|\d*\.\d+)rpx\b/i;
|
|
4889
5196
|
function createLegacyDeclarationValueMap(css) {
|
|
4890
5197
|
const values = /* @__PURE__ */ new Map();
|
|
4891
|
-
|
|
5198
|
+
require_watch_dependencies.postcss_default.parse(css).walkRules((rule) => {
|
|
4892
5199
|
if (!rule.selectors || rule.selectors.length === 0) return;
|
|
4893
5200
|
for (const selector of rule.selectors) {
|
|
4894
5201
|
const normalizedSelectors = normalizeCompatSelectors(selector);
|
|
@@ -4903,7 +5210,7 @@ function inheritLegacyUnitConvertedDeclarations(css, legacyCss) {
|
|
|
4903
5210
|
try {
|
|
4904
5211
|
const legacyValues = createLegacyDeclarationValueMap(legacyCss);
|
|
4905
5212
|
if (legacyValues.size === 0) return css;
|
|
4906
|
-
const root =
|
|
5213
|
+
const root = require_watch_dependencies.postcss_default.parse(css);
|
|
4907
5214
|
let changed = false;
|
|
4908
5215
|
root.walkRules((rule) => {
|
|
4909
5216
|
if (!rule.selectors || rule.selectors.length === 0) return;
|
|
@@ -5003,11 +5310,12 @@ function finalizeMiniProgramGeneratorCss(css, target, majorVersion, cssPreflight
|
|
|
5003
5310
|
});
|
|
5004
5311
|
}
|
|
5005
5312
|
function mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtime, options) {
|
|
5006
|
-
if (
|
|
5313
|
+
if (options.isolateCssSource && options.currentCssCandidates?.length) return new Set([...scopedRuntime, ...options.currentCssCandidates]);
|
|
5314
|
+
if (runtime.size === 0 || !options.cssHandlerOptions.isMainChunk || options.matchedCssSourceFile || options.isolateCssSource && scopedRuntime.size === 0) return scopedRuntime;
|
|
5007
5315
|
return new Set([...scopedRuntime, ...runtime]);
|
|
5008
5316
|
}
|
|
5009
|
-
function
|
|
5010
|
-
return Boolean(source.__weappTailwindcssMeta?.matchedCssSourceFile
|
|
5317
|
+
function shouldIsolateScopedCssSource(source, sourceEntries) {
|
|
5318
|
+
return sourceEntries !== void 0 && Boolean(source.__weappTailwindcssMeta?.matchedCssSourceFile || sourceEntries.length > 0);
|
|
5011
5319
|
}
|
|
5012
5320
|
function shouldScanTailwindV4Sources(majorVersion, target, generatorRuntime, isolateCssSource) {
|
|
5013
5321
|
if (majorVersion !== 4 || isolateCssSource) return false;
|
|
@@ -5039,7 +5347,7 @@ function isLocalImportRequest(request) {
|
|
|
5039
5347
|
}
|
|
5040
5348
|
function isCommentOnlyCss(source) {
|
|
5041
5349
|
try {
|
|
5042
|
-
const root =
|
|
5350
|
+
const root = require_watch_dependencies.postcss_default.parse(source);
|
|
5043
5351
|
return root.nodes.length > 0 && root.nodes.every((node) => node.type === "comment");
|
|
5044
5352
|
} catch {
|
|
5045
5353
|
return false;
|
|
@@ -5053,7 +5361,7 @@ function stripLeadingTailwindSourceMediaCloseFragment(source) {
|
|
|
5053
5361
|
}
|
|
5054
5362
|
function stripUnmatchedTailwindSourceMediaCloseFragments(source) {
|
|
5055
5363
|
try {
|
|
5056
|
-
|
|
5364
|
+
require_watch_dependencies.postcss_default.parse(source);
|
|
5057
5365
|
return source;
|
|
5058
5366
|
} catch {
|
|
5059
5367
|
return stripLeadingTailwindSourceMediaCloseFragment(source).replace(/\s*\}\s*$/, "");
|
|
@@ -5081,9 +5389,9 @@ function splitUserCssLayerBlocks(source) {
|
|
|
5081
5389
|
rest: source
|
|
5082
5390
|
};
|
|
5083
5391
|
try {
|
|
5084
|
-
const root =
|
|
5085
|
-
const layerRoot =
|
|
5086
|
-
const restRoot =
|
|
5392
|
+
const root = require_watch_dependencies.postcss_default.parse(source);
|
|
5393
|
+
const layerRoot = require_watch_dependencies.postcss_default.root();
|
|
5394
|
+
const restRoot = require_watch_dependencies.postcss_default.root();
|
|
5087
5395
|
for (const node of root.nodes) (node.type === "atrule" && node.name === "layer" && node.nodes?.length ? layerRoot : restRoot).append(node.clone());
|
|
5088
5396
|
return {
|
|
5089
5397
|
layer: layerRoot.toString(),
|
|
@@ -5100,7 +5408,7 @@ function hasUserCssLayerBlocks(source) {
|
|
|
5100
5408
|
if (!source.includes("@layer")) return false;
|
|
5101
5409
|
try {
|
|
5102
5410
|
let hasLayerBlock = false;
|
|
5103
|
-
|
|
5411
|
+
require_watch_dependencies.postcss_default.parse(source).walkAtRules("layer", (node) => {
|
|
5104
5412
|
if (node.nodes?.length) hasLayerBlock = true;
|
|
5105
5413
|
});
|
|
5106
5414
|
return hasLayerBlock;
|
|
@@ -5111,7 +5419,7 @@ function hasUserCssLayerBlocks(source) {
|
|
|
5111
5419
|
function collectUserLayerSelectors(source) {
|
|
5112
5420
|
const selectors = /* @__PURE__ */ new Set();
|
|
5113
5421
|
try {
|
|
5114
|
-
|
|
5422
|
+
require_watch_dependencies.postcss_default.parse(source).walkRules((rule) => {
|
|
5115
5423
|
for (const selector of rule.selectors ?? [rule.selector]) {
|
|
5116
5424
|
const normalized = selector.trim();
|
|
5117
5425
|
if (normalized) selectors.add(normalized);
|
|
@@ -5133,8 +5441,8 @@ function extractGeneratedCssForUserLayerSelectors(css, userLayerSource) {
|
|
|
5133
5441
|
rest: css
|
|
5134
5442
|
};
|
|
5135
5443
|
try {
|
|
5136
|
-
const root =
|
|
5137
|
-
const layerRoot =
|
|
5444
|
+
const root = require_watch_dependencies.postcss_default.parse(css);
|
|
5445
|
+
const layerRoot = require_watch_dependencies.postcss_default.root();
|
|
5138
5446
|
const selectorList = [...selectors];
|
|
5139
5447
|
root.walkRules((rule) => {
|
|
5140
5448
|
if ((rule.selectors ?? [rule.selector]).some((selector) => selectorList.some((userSelector) => matchesUserLayerSelector(selector.trim(), userSelector)))) {
|
|
@@ -5170,7 +5478,7 @@ async function transformGeneratorUserCss(source, options) {
|
|
|
5170
5478
|
function isPureLocalCssImportWrapper(css) {
|
|
5171
5479
|
let hasImport = false;
|
|
5172
5480
|
try {
|
|
5173
|
-
const root =
|
|
5481
|
+
const root = require_watch_dependencies.postcss_default.parse(css);
|
|
5174
5482
|
for (const node of root.nodes) {
|
|
5175
5483
|
if (node.type === "comment") continue;
|
|
5176
5484
|
if (node.type !== "atrule" || node.name !== "import") return false;
|
|
@@ -5187,7 +5495,7 @@ function cleanLocalCssImportWrapperTailwindDirectives(css) {
|
|
|
5187
5495
|
let hasLocalImport = false;
|
|
5188
5496
|
let hasTailwindDirective = false;
|
|
5189
5497
|
try {
|
|
5190
|
-
const root =
|
|
5498
|
+
const root = require_watch_dependencies.postcss_default.parse(css);
|
|
5191
5499
|
for (const node of root.nodes) {
|
|
5192
5500
|
if (node.type === "comment") continue;
|
|
5193
5501
|
if (node.type === "atrule" && node.name === "import") {
|
|
@@ -5209,7 +5517,7 @@ function cleanLocalCssImportWrapperTailwindDirectives(css) {
|
|
|
5209
5517
|
}
|
|
5210
5518
|
function prefixLocalCssImportsWithWebpackIgnore(css) {
|
|
5211
5519
|
try {
|
|
5212
|
-
const root =
|
|
5520
|
+
const root = require_watch_dependencies.postcss_default.parse(css);
|
|
5213
5521
|
root.walkAtRules("import", (atRule) => {
|
|
5214
5522
|
const request = parseImportRequest(atRule.params);
|
|
5215
5523
|
if (request && isLocalImportRequest(request)) atRule.raws.before = `${atRule.raws.before ?? ""}/* webpackIgnore: true */\n`;
|
|
@@ -5242,22 +5550,30 @@ async function generateCssByGenerator(options) {
|
|
|
5242
5550
|
if (!SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0) || !shouldGenerateCurrentCss || majorVersion === 3 && !hasSourceDirectives && !hasGeneratedCss && !hasGeneratedMarkers) return;
|
|
5243
5551
|
try {
|
|
5244
5552
|
await runtimeState.readyPromise;
|
|
5245
|
-
const currentCssCandidates = majorVersion === 4 ? await (0, tailwindcss_patch.extractSourceCandidates)(effectiveRawSource, "css", { bareArbitraryValues: generatorOptions.bareArbitraryValues }) : [];
|
|
5553
|
+
const currentCssCandidates = majorVersion === 4 ? await (0, tailwindcss_patch.extractSourceCandidates)(effectiveRawSource, "css", { ...generatorOptions.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: generatorOptions.bareArbitraryValues } }) : [];
|
|
5246
5554
|
const runtimeWithCurrentCss = currentCssCandidates.length > 0 ? new Set([...runtime, ...currentCssCandidates]) : runtime;
|
|
5247
5555
|
const sources = await resolveGeneratorSources(majorVersion, runtimeState, effectiveRawSource, file, cssHandlerOptions, generatorOptions, {
|
|
5556
|
+
cssEntries: opts.cssEntries,
|
|
5248
5557
|
getSourceCandidatesForEntries,
|
|
5249
5558
|
runtime: runtimeWithCurrentCss
|
|
5250
5559
|
});
|
|
5251
5560
|
const generatorStyleOptions = resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorOptions.styleOptions);
|
|
5252
5561
|
const configuredContainerCompat = hasConfiguredContainerCompatSources(sources);
|
|
5253
|
-
const generatedResults = await Promise.all(sources.map(async (source) => {
|
|
5562
|
+
const generatedResults = (await Promise.all(sources.map(async (source) => {
|
|
5254
5563
|
const generator = createWeappTailwindcssGenerator(source);
|
|
5255
|
-
const sourceEntries = getSourceCandidatesForEntries && majorVersion === 4 ? await resolveGeneratorSourceEntries(source, runtimeState) : void 0;
|
|
5564
|
+
const sourceEntries = getSourceCandidatesForEntries && (majorVersion === 3 || majorVersion === 4) ? await resolveGeneratorSourceEntries(source, runtimeState) : void 0;
|
|
5256
5565
|
const scopedRuntime = sourceEntries ? getSourceCandidatesForEntries?.(sourceEntries) : void 0;
|
|
5257
|
-
const isolateCssSource =
|
|
5566
|
+
const isolateCssSource = shouldIsolateScopedCssSource(source, sourceEntries);
|
|
5567
|
+
const matchedCssSourceFile = Boolean(source.__weappTailwindcssMeta?.matchedCssSourceFile);
|
|
5568
|
+
if (options.deferEmptyScopedCssSource && isolateCssSource && scopedRuntime?.size === 0 && currentCssCandidates.length === 0 && !cssHandlerOptions.isMainChunk) {
|
|
5569
|
+
debug("defer empty scoped css source generation: %s", file);
|
|
5570
|
+
return;
|
|
5571
|
+
}
|
|
5258
5572
|
const sourceRuntime = scopedRuntime && (scopedRuntime.size > 0 || isolateCssSource) ? mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtimeWithCurrentCss, {
|
|
5573
|
+
currentCssCandidates,
|
|
5259
5574
|
cssHandlerOptions,
|
|
5260
|
-
isolateCssSource
|
|
5575
|
+
isolateCssSource,
|
|
5576
|
+
matchedCssSourceFile
|
|
5261
5577
|
}) : runtimeWithCurrentCss;
|
|
5262
5578
|
const generatorRuntime = majorVersion === 4 && generatorOptions.target === "weapp" ? filterUnsupportedMiniProgramTailwindV4Candidates(sourceRuntime) : sourceRuntime;
|
|
5263
5579
|
return generator.generate({
|
|
@@ -5269,7 +5585,7 @@ async function generateCssByGenerator(options) {
|
|
|
5269
5585
|
tailwindcssV3Compatibility: generatorOptions.tailwindcssV3Compatibility,
|
|
5270
5586
|
target: generatorOptions.target
|
|
5271
5587
|
});
|
|
5272
|
-
}));
|
|
5588
|
+
}))).filter((item) => Boolean(item));
|
|
5273
5589
|
const firstGenerated = generatedResults[0];
|
|
5274
5590
|
if (!firstGenerated) return;
|
|
5275
5591
|
const incrementalCssResults = generatedResults.map((item) => item.incrementalCss).filter((css) => typeof css === "string");
|
|
@@ -5297,6 +5613,7 @@ async function generateCssByGenerator(options) {
|
|
|
5297
5613
|
}
|
|
5298
5614
|
const hasMatchedCssSourceFile = sources.some((source) => source.__weappTailwindcssMeta?.matchedCssSourceFile);
|
|
5299
5615
|
const orderedExtraCss = hasMatchedCssSourceFile ? splitTailwindV4GeneratedCssBySourceOrder(effectiveRawSource, generated.rawCss) : splitRawSourceByGeneratedCssOrder(effectiveRawSource, generated.rawCss);
|
|
5616
|
+
const shouldAppendMatchedCssSourceCompat = !hasMatchedCssSourceFile || orderedExtraCss !== void 0;
|
|
5300
5617
|
if (orderedExtraCss) {
|
|
5301
5618
|
let css = stripTailwindBanner(generated.css);
|
|
5302
5619
|
if (generated.target === "weapp") css = inheritLegacyUnitConvertedDeclarations(css, effectiveRawSource);
|
|
@@ -5322,11 +5639,11 @@ async function generateCssByGenerator(options) {
|
|
|
5322
5639
|
const userCss = await transformGeneratorUserCss(effectiveRawSource, userCssOptions);
|
|
5323
5640
|
css = createCssSourceOrderAppend(css, userCss);
|
|
5324
5641
|
}
|
|
5325
|
-
if (generated.target === "weapp") {
|
|
5642
|
+
if (generated.target === "weapp" && shouldAppendMatchedCssSourceCompat) {
|
|
5326
5643
|
if (shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
|
|
5327
5644
|
css = await appendLegacyCompatCss(css, effectiveRawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
5328
5645
|
css = await appendLegacyContainerCompatCss(css, effectiveRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
5329
|
-
}
|
|
5646
|
+
} else if (generated.target === "weapp" && shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
|
|
5330
5647
|
return {
|
|
5331
5648
|
css: finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight),
|
|
5332
5649
|
target: generated.target,
|
|
@@ -5358,6 +5675,17 @@ async function generateCssByGenerator(options) {
|
|
|
5358
5675
|
}
|
|
5359
5676
|
}
|
|
5360
5677
|
if (hasMatchedCssSourceFile || generated.target === "web") {
|
|
5678
|
+
if (hasMatchedCssSourceFile && generated.target === "weapp" && !hasGeneratedCss && !hasGeneratedMarkers) {
|
|
5679
|
+
const userCss = await transformGeneratorUserCss(effectiveRawSource, {
|
|
5680
|
+
generatorTarget: generated.target,
|
|
5681
|
+
generatorStyleOptions,
|
|
5682
|
+
cssUserHandlerOptions,
|
|
5683
|
+
styleHandler,
|
|
5684
|
+
importFallback: generatorOptions.importFallback
|
|
5685
|
+
});
|
|
5686
|
+
css = createCssSourceOrderAppend(css, userCss);
|
|
5687
|
+
}
|
|
5688
|
+
if (hasMatchedCssSourceFile && generated.target === "weapp") css = await appendLegacyContainerCompatCss(css, effectiveRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
5361
5689
|
if (shouldAppendWebBundleCssFallback(generated.target, {
|
|
5362
5690
|
hasSourceDirectives,
|
|
5363
5691
|
hasMatchedCssSourceFile
|
|
@@ -5394,7 +5722,7 @@ async function generateCssByGenerator(options) {
|
|
|
5394
5722
|
//#endregion
|
|
5395
5723
|
//#region src/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.ts
|
|
5396
5724
|
function resolveLoaderOptions(options) {
|
|
5397
|
-
const runtime =
|
|
5725
|
+
const runtime = require_watch_dependencies.getWebpackLoaderRuntime(options?.tailwindcssImportRewriteRuntimeKey)?.cssImportRewrite;
|
|
5398
5726
|
return runtime ? {
|
|
5399
5727
|
...options,
|
|
5400
5728
|
tailwindcssImportRewrite: runtime
|
|
@@ -5416,17 +5744,12 @@ function applyCssImportRewrite(source, options) {
|
|
|
5416
5744
|
function isPackageJsonImportRequest(request) {
|
|
5417
5745
|
return request.startsWith("#");
|
|
5418
5746
|
}
|
|
5419
|
-
function
|
|
5420
|
-
if (!rootContext) return (0, _weapp_tailwindcss_shared.ensurePosix)(configPath);
|
|
5421
|
-
const relative = (0, _weapp_tailwindcss_shared.ensurePosix)(node_path.default.relative(rootContext, configPath));
|
|
5422
|
-
return relative.startsWith(".") ? relative : `./${relative}`;
|
|
5423
|
-
}
|
|
5424
|
-
function normalizeCssConfigDirectives(source, resourcePath, rootContext) {
|
|
5747
|
+
function normalizeCssConfigDirectives(source, resourcePath) {
|
|
5425
5748
|
if (!resourcePath) return source;
|
|
5426
5749
|
const base = node_path.default.dirname(resourcePath);
|
|
5427
5750
|
return source.replace(/@config\s+(["'])(.+?)\1\s*;?/g, (full, quote, request) => {
|
|
5428
5751
|
if (node_path.default.isAbsolute(request) || isPackageJsonImportRequest(request)) return full;
|
|
5429
|
-
return `@config ${quote}${
|
|
5752
|
+
return `@config ${quote}${(0, _weapp_tailwindcss_shared.ensurePosix)(node_path.default.resolve(base, request))}${quote};`;
|
|
5430
5753
|
});
|
|
5431
5754
|
}
|
|
5432
5755
|
function createCssHandlerOptions(options, majorVersion, file, appType) {
|
|
@@ -5445,7 +5768,7 @@ async function generateCssForWebpackPipeline(source, loaderContext, options) {
|
|
|
5445
5768
|
await runtimeState.readyPromise;
|
|
5446
5769
|
const runtime = await getRuntimeSet();
|
|
5447
5770
|
const file = loaderContext.resourcePath;
|
|
5448
|
-
const normalizedSource = normalizeCssConfigDirectives(source, file
|
|
5771
|
+
const normalizedSource = normalizeCssConfigDirectives(source, file);
|
|
5449
5772
|
const cssHandlerOptions = createCssHandlerOptions(compilerOptions, runtimeState.twPatcher.majorVersion, file, rewriteOptions.appType);
|
|
5450
5773
|
const generated = await generateCssByGenerator({
|
|
5451
5774
|
opts: compilerOptions,
|
|
@@ -5463,7 +5786,7 @@ async function generateCssForWebpackPipeline(source, loaderContext, options) {
|
|
|
5463
5786
|
});
|
|
5464
5787
|
if (!generated) return;
|
|
5465
5788
|
rewriteOptions.markGeneratedCssSource?.(file);
|
|
5466
|
-
for (const dependency of generated.dependencies)
|
|
5789
|
+
for (const dependency of generated.dependencies) require_watch_dependencies.registerWebpackWatchFile(loaderContext, dependency);
|
|
5467
5790
|
return `${createBundlerGeneratedCssMarker("webpack", file)}\n${generated.css}`;
|
|
5468
5791
|
}
|
|
5469
5792
|
function transformCssImportRewriteSource(source, options) {
|
|
@@ -5483,11 +5806,11 @@ const WeappTwCssImportRewriteLoader = function(source) {
|
|
|
5483
5806
|
const hasTailwindRoot = typeof input === "string" && hasTailwindRootDirectives(input, { importFallback: true });
|
|
5484
5807
|
const registerTask = hasTailwindRoot ? opt?.tailwindcssImportRewrite?.registerCssSource?.({
|
|
5485
5808
|
file: this.resourcePath,
|
|
5486
|
-
css: normalizeCssConfigDirectives(normalizeTailwindSourceForGenerator(input, { importFallback: true }), this.resourcePath
|
|
5809
|
+
css: normalizeCssConfigDirectives(normalizeTailwindSourceForGenerator(input, { importFallback: true }), this.resourcePath)
|
|
5487
5810
|
}) : void 0;
|
|
5488
5811
|
const transform = () => {
|
|
5489
5812
|
const transformed = transformCssImportRewriteSource(source, opt);
|
|
5490
|
-
if (typeof transformed === "string") return normalizeCssConfigDirectives(transformed, this.resourcePath
|
|
5813
|
+
if (typeof transformed === "string") return normalizeCssConfigDirectives(transformed, this.resourcePath);
|
|
5491
5814
|
return transformed;
|
|
5492
5815
|
};
|
|
5493
5816
|
const generate = hasTailwindRoot && opt?.tailwindcssImportRewrite?.compilerOptions && opt.tailwindcssImportRewrite.runtimeState && opt.tailwindcssImportRewrite.getRuntimeSet ? async () => {
|