weapp-tailwindcss 5.0.13 → 5.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +1 -1
- package/README.md +1 -1
- package/dist/auto-Ba6hDrse.mjs +13 -0
- package/dist/auto-DtU6f3X6.js +18 -0
- package/dist/bundlers/shared/css-cleanup.d.ts +1 -1
- package/dist/bundlers/shared/generator-css/class-selectors.d.ts +2 -0
- package/dist/bundlers/shared/generator-css/directives.d.ts +2 -1
- package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +10 -6
- package/dist/bundlers/shared/generator-css/local-imports.d.ts +3 -0
- package/dist/bundlers/shared/generator-css/source-resolver/apply-reference.d.ts +3 -0
- package/dist/bundlers/shared/generator-css/source-resolver/matching.d.ts +0 -1
- package/dist/bundlers/shared/generator-css/source-resolver/metadata.d.ts +1 -1
- package/dist/bundlers/shared/generator-css/source-resolver/types.d.ts +3 -3
- package/dist/bundlers/shared/generator-css/source-resolver.d.ts +2 -2
- package/dist/bundlers/shared/generator-css/types.d.ts +13 -1
- package/dist/bundlers/shared/generator-css/user-css.d.ts +5 -1
- package/dist/bundlers/shared/generator-css/validate.d.ts +1 -0
- package/dist/bundlers/shared/run-tasks.d.ts +1 -0
- package/dist/bundlers/shared/v4-generation-core.d.ts +11 -0
- package/dist/bundlers/vite/css-finalizer.d.ts +1 -1
- package/dist/bundlers/vite/css-memory.d.ts +16 -0
- package/dist/bundlers/vite/generate-bundle/candidates.d.ts +0 -1
- package/dist/bundlers/vite/generate-bundle/configured-css-sources.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/css-assets.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/css-output-helpers.d.ts +39 -0
- package/dist/bundlers/vite/generate-bundle/css-output.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/env-flags.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/final-css-assets.d.ts +13 -0
- package/dist/bundlers/vite/generate-bundle/finalize.d.ts +7 -0
- package/dist/bundlers/vite/generate-bundle/html-processing.d.ts +26 -0
- package/dist/bundlers/vite/generate-bundle/js-processing.d.ts +4 -0
- package/dist/bundlers/vite/generate-bundle/memory-debug.d.ts +21 -18
- package/dist/bundlers/vite/generate-bundle/remembered-css-replay.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/remembered-css.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/root-style-output.d.ts +6 -0
- package/dist/bundlers/vite/generate-bundle/runtime-linked-source-memory.d.ts +25 -0
- package/dist/bundlers/vite/generate-bundle/sfc-style-source.d.ts +3 -1
- package/dist/bundlers/vite/generate-bundle/source-candidate-scope.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/source-candidate-source.d.ts +9 -0
- package/dist/bundlers/vite/generate-bundle/tailwind-v4-css-source.d.ts +9 -0
- package/dist/bundlers/vite/generate-bundle/transform-filter.d.ts +15 -0
- package/dist/bundlers/vite/generate-bundle/types.d.ts +2 -1
- package/dist/bundlers/vite/generate-bundle/vite-css-cache.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle.d.ts +2 -1
- package/dist/bundlers/vite/incremental-runtime-class-set/escaped-candidates.d.ts +1 -0
- package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +3 -3
- package/dist/bundlers/vite/plugin-cache.d.ts +15 -0
- package/dist/bundlers/vite/rewrite-css-imports.d.ts +1 -0
- package/dist/bundlers/vite/runtime-class-set.d.ts +5 -4
- package/dist/bundlers/vite/source-candidates/script.d.ts +1 -7
- package/dist/bundlers/vite/source-candidates.d.ts +9 -2
- package/dist/bundlers/vite/source-scan/css-entries.d.ts +2 -6
- package/dist/bundlers/vite/source-scan.d.ts +2 -2
- package/dist/bundlers/vite/uni-app-x-css-options.d.ts +1 -1
- package/dist/bundlers/vite/utils.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +26 -2
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/css-source-resolvers.d.ts +34 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.d.ts +48 -11
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/js-module-graph.d.ts +37 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.d.ts +199 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/source-candidate-cache.d.ts +28 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/source-candidate-refresh.d.ts +11 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +4 -2
- package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +10 -1
- package/dist/bundlers/webpack/shared/css-loader-runtime.d.ts +1 -0
- package/dist/cache/index.d.ts +1 -0
- package/dist/cli/mount-options.d.ts +2 -2
- package/dist/cli.js +138 -444
- package/dist/cli.mjs +134 -440
- package/dist/context/index.d.ts +3 -3
- package/dist/context/style-options.d.ts +5 -1
- package/dist/context/tailwindcss.d.ts +1 -1
- package/dist/{precheck-B0Z8yW7E.js → context-B6hVF7dr.js} +405 -156
- package/dist/{precheck-CRI90iL1.mjs → context-DlpKD7aN.mjs} +377 -141
- package/dist/core.js +15 -12
- package/dist/core.mjs +10 -7
- package/dist/css-macro/index.d.ts +3 -7
- package/dist/css-macro.js +1 -1
- package/dist/css-macro.mjs +1 -1
- package/dist/{defaults-Bqx18S1f.mjs → defaults-BhE26nSw.mjs} +12 -13
- package/dist/{defaults-C_J_kBpw.js → defaults-CmFBmxsr.js} +11 -18
- package/dist/defaults.d.ts +2 -8
- package/dist/defaults.js +1 -2
- package/dist/defaults.mjs +2 -2
- package/dist/generator/index.d.ts +6 -7
- package/dist/generator/options.d.ts +3 -3
- package/dist/generator/types.d.ts +9 -10
- package/dist/generator-6oMJtTDO.js +170 -0
- package/dist/generator-CjzBK7h-.mjs +123 -0
- package/dist/generator.js +10 -16
- package/dist/generator.mjs +3 -3
- package/dist/{gulp-XT8Jc7lH.js → gulp-BtGq6LP9.js} +49 -87
- package/dist/{gulp-DfOQERcV.mjs → gulp-DNU10Vtc.mjs} +42 -80
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{hmr-timing-DQIP_8qP.mjs → hmr-timing-B0KuWDjV.mjs} +1197 -858
- package/dist/{hmr-timing-BMftW7Us.js → hmr-timing-CegXR9O4.js} +1356 -927
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/js/fast-path/oxc.d.ts +4 -0
- package/dist/js/precheck.d.ts +1 -0
- package/dist/postcss.js +3 -4
- package/dist/postcss.mjs +2 -3
- package/dist/presets.js +9 -19
- package/dist/presets.mjs +8 -18
- package/dist/runtime-branch/create-branch.d.ts +2 -0
- package/dist/runtime-branch/generator-target-env.d.ts +4 -0
- package/dist/runtime-branch/index.d.ts +6 -0
- package/dist/runtime-branch/mini-program.d.ts +2 -0
- package/dist/runtime-branch/native-app.d.ts +2 -0
- package/dist/runtime-branch/platform.d.ts +6 -0
- package/dist/runtime-branch/tailwind-version.d.ts +2 -0
- package/dist/runtime-branch/types.d.ts +37 -0
- package/dist/runtime-branch/web.d.ts +2 -0
- package/dist/runtime-branch.d.ts +1 -0
- package/dist/{bundle-state-zQ2MrDdi.mjs → source-candidate-scan-signature-B5af2Ahe.mjs} +187 -17
- package/dist/{bundle-state-CKWeTEhv.js → source-candidate-scan-signature-BKYb9jxa.js} +261 -19
- package/dist/tailwindcss/candidates.d.ts +7 -0
- package/dist/tailwindcss/index.d.ts +2 -2
- package/dist/tailwindcss/runtime/cache.d.ts +6 -6
- package/dist/tailwindcss/runtime-factory.d.ts +12 -0
- package/dist/tailwindcss/runtime-options.d.ts +8 -0
- package/dist/tailwindcss/runtime-types.d.ts +87 -0
- package/dist/tailwindcss/runtime.d.ts +6 -6
- package/dist/tailwindcss/source-scan.d.ts +1 -1
- package/dist/tailwindcss/targets.d.ts +2 -2
- package/dist/tailwindcss/v4/config.d.ts +3 -3
- package/dist/tailwindcss/v4/css-entries.d.ts +1 -0
- package/dist/tailwindcss/v4/css-sources.d.ts +4 -2
- package/dist/tailwindcss/v4/index.d.ts +1 -1
- package/dist/tailwindcss/v4/multi-runtime.d.ts +2 -0
- package/dist/tailwindcss/v4/runtime-factory.d.ts +15 -0
- package/dist/tailwindcss/v4/runtime-options.d.ts +2 -0
- package/dist/tailwindcss/v4-engine/design-system.d.ts +1 -1
- package/dist/tailwindcss/v4-engine/generator/css-compat.d.ts +1 -1
- package/dist/tailwindcss/v4-engine/generator/rpx-candidates.d.ts +3 -3
- package/dist/tailwindcss/v4-engine/generator/scan-sources.d.ts +1 -1
- package/dist/tailwindcss/v4-engine/generator.d.ts +10 -3
- package/dist/tailwindcss/v4-engine/index.d.ts +1 -1
- package/dist/tailwindcss/v4-engine/miniprogram.d.ts +7 -1
- package/dist/tailwindcss/v4-engine/source.d.ts +15 -7
- package/dist/tailwindcss/v4-engine/types.d.ts +17 -10
- package/dist/tailwindcss/version.d.ts +1 -1
- package/dist/tailwindcss-B5mRo0-M.mjs +1423 -0
- package/dist/tailwindcss-dbrbY4cd.js +1528 -0
- package/dist/{transform-DfcEjsZF.mjs → transform-fRBeuuK-.mjs} +2 -2
- package/dist/{transform-YmrmxuF3.js → transform-vLwZpiTE.js} +17 -17
- package/dist/typedoc.export.d.ts +1 -1
- package/dist/types/index.d.ts +16 -17
- package/dist/types/shared.d.ts +1 -1
- package/dist/types/{typedoc-tailwindcss-patch.d.ts → typedoc-tailwindcss-runtime.d.ts} +4 -10
- package/dist/types/user-defined-options/general.d.ts +5 -3
- package/dist/types/user-defined-options/important.d.ts +2 -2
- package/dist/types/user-defined-options/matcher.d.ts +7 -0
- package/dist/uni-app-x/style-asset.d.ts +1 -0
- package/dist/v4-engine-C3qSwQ-e.mjs +2376 -0
- package/dist/v4-engine-ON_oSLfO.js +2752 -0
- package/dist/{vite-DjI09vVN.mjs → vite-CWRooooa.mjs} +1417 -540
- package/dist/{vite-CXHVsHmX.js → vite-w-RkgaTY.js} +1575 -698
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +5665 -4443
- package/dist/weapp-tw-runtime-classset-loader.js +15 -4
- package/dist/webpack-8PaV1gG3.mjs +2334 -0
- package/dist/webpack-CGgBOx9l.js +2346 -0
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +6 -7
- package/dist/auto-CTp6wE5a.js +0 -33
- package/dist/auto-Cl8_hsG6.mjs +0 -22
- package/dist/bundlers/vite/incremental-runtime-class-set/v3-candidates.d.ts +0 -13
- package/dist/bundlers/vite/source-candidates/tailwind-v3-default-extractor.d.ts +0 -1
- package/dist/context/tailwindcss/rax.d.ts +0 -2
- package/dist/generator-CzpArpCL.js +0 -92
- package/dist/generator-ITLd7PTl.mjs +0 -67
- package/dist/tailwindcss/patcher-options.d.ts +0 -8
- package/dist/tailwindcss/patcher.d.ts +0 -12
- package/dist/tailwindcss/runtime-patch.d.ts +0 -5
- package/dist/tailwindcss/v3-engine/generator/cache-key.d.ts +0 -3
- package/dist/tailwindcss/v3-engine/generator/content.d.ts +0 -10
- package/dist/tailwindcss/v3-engine/generator/runtime-ready.d.ts +0 -2
- package/dist/tailwindcss/v3-engine/generator.d.ts +0 -19
- package/dist/tailwindcss/v3-engine/index.d.ts +0 -4
- package/dist/tailwindcss/v3-engine/miniprogram.d.ts +0 -4
- package/dist/tailwindcss/v3-engine/source.d.ts +0 -5
- package/dist/tailwindcss/v3-engine/types.d.ts +0 -61
- package/dist/tailwindcss/v4/multi-patcher.d.ts +0 -2
- package/dist/tailwindcss/v4/patcher-options.d.ts +0 -2
- package/dist/tailwindcss/v4/patcher.d.ts +0 -15
- package/dist/tailwindcss/v4-engine/tailwind-v3-compatibility.d.ts +0 -1
- package/dist/tailwindcss/v4-engine/tailwind-v3-default-colors.d.ts +0 -1
- package/dist/tailwindcss-DTq3uYBK.mjs +0 -556
- package/dist/tailwindcss-DZEwT3C_.js +0 -613
- package/dist/v3-engine-2rrgylhn.js +0 -4686
- package/dist/v3-engine-C6eJ0YzK.mjs +0 -4272
- package/dist/webpack-BcPpnT90.mjs +0 -1184
- package/dist/webpack-CfkUkMXG.js +0 -1196
- /package/dist/tailwindcss/{patcher-resolve.d.ts → runtime-resolve.d.ts} +0 -0
|
@@ -1,4272 +0,0 @@
|
|
|
1
|
-
import { a as transformCssMacroCss, n as hasCssMacroTailwindPlugin, o as withCssMacroStyleOptions, r as hasCssMacroTailwindV4Directive, t as hasCssMacroStyleOptions } from "./auto-Cl8_hsG6.mjs";
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
|
-
import fs, { existsSync, readFileSync, readdirSync, realpathSync, statSync } from "node:fs";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import process from "node:process";
|
|
6
|
-
import { createStyleHandler, postcss, protectDynamicColorMixAlpha, pruneMiniProgramGeneratedCss } from "@weapp-tailwindcss/postcss";
|
|
7
|
-
import { LRUCache } from "lru-cache";
|
|
8
|
-
import * as tailwindcssPatch from "tailwindcss-patch";
|
|
9
|
-
import { TailwindcssPatcher, createTailwindV4Engine, extractRawCandidates, extractSourceCandidates, isBareArbitraryValuesEnabled, loadTailwindV4DesignSystem, resolveBareArbitraryValueCandidate, resolveProjectSourceFiles, resolveTailwindV4Source, resolveTailwindV4SourceFromPatchOptions } from "tailwindcss-patch";
|
|
10
|
-
import { logger } from "@weapp-tailwindcss/logger";
|
|
11
|
-
import { defuOverrideArray } from "@weapp-tailwindcss/shared";
|
|
12
|
-
import { fileURLToPath } from "node:url";
|
|
13
|
-
import _createDebug from "debug";
|
|
14
|
-
import { stat } from "node:fs/promises";
|
|
15
|
-
import micromatch from "micromatch";
|
|
16
|
-
import fg from "fast-glob";
|
|
17
|
-
import { loadConfig } from "tailwindcss-config";
|
|
18
|
-
//#region src/utils/object.ts
|
|
19
|
-
function definedEntries(value) {
|
|
20
|
-
return Object.entries(value).filter(([, item]) => item !== void 0);
|
|
21
|
-
}
|
|
22
|
-
function omitUndefined(value) {
|
|
23
|
-
return Object.fromEntries(definedEntries(value));
|
|
24
|
-
}
|
|
25
|
-
//#endregion
|
|
26
|
-
//#region src/tailwindcss/v3-engine/generator/content.ts
|
|
27
|
-
function isLegacyContentObject$1(value) {
|
|
28
|
-
return typeof value === "object" && value !== null && "files" in value;
|
|
29
|
-
}
|
|
30
|
-
function createRawContentEntries(candidates, sources) {
|
|
31
|
-
const entries = [];
|
|
32
|
-
const candidateContent = [...candidates].join(" ");
|
|
33
|
-
if (candidateContent.length > 0) entries.push({
|
|
34
|
-
raw: candidateContent,
|
|
35
|
-
extension: "html"
|
|
36
|
-
});
|
|
37
|
-
for (const source of sources) entries.push({
|
|
38
|
-
raw: source.content,
|
|
39
|
-
extension: source.extension ?? "html"
|
|
40
|
-
});
|
|
41
|
-
return entries;
|
|
42
|
-
}
|
|
43
|
-
function createChangedContentEntries(candidates, sources) {
|
|
44
|
-
return createRawContentEntries(candidates, sources).map((entry) => ({
|
|
45
|
-
content: entry.raw,
|
|
46
|
-
extension: entry.extension
|
|
47
|
-
}));
|
|
48
|
-
}
|
|
49
|
-
function collectCandidates$1(candidates) {
|
|
50
|
-
return new Set(candidates ?? []);
|
|
51
|
-
}
|
|
52
|
-
function collectApplyCandidatesFromCss(css) {
|
|
53
|
-
if (!css.includes("@apply")) return [];
|
|
54
|
-
const candidates = /* @__PURE__ */ new Set();
|
|
55
|
-
try {
|
|
56
|
-
postcss.parse(css).walkAtRules("apply", (rule) => {
|
|
57
|
-
for (const candidate of rule.params.split(/\s+/)) {
|
|
58
|
-
const normalized = candidate.replace(/!important$/, "").trim();
|
|
59
|
-
if (normalized) candidates.add(normalized);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
} catch {}
|
|
63
|
-
return [...candidates];
|
|
64
|
-
}
|
|
65
|
-
function isTailwindCandidateLayer(params) {
|
|
66
|
-
return params.split(/[,\s]+/).some((layer) => layer === "components" || layer === "utilities");
|
|
67
|
-
}
|
|
68
|
-
function extractClassCandidatesFromSelector(selector, candidates) {
|
|
69
|
-
for (let index = 0; index < selector.length; index++) {
|
|
70
|
-
if (selector[index] !== ".") continue;
|
|
71
|
-
let candidate = "";
|
|
72
|
-
let escaped = false;
|
|
73
|
-
for (let tokenIndex = index + 1; tokenIndex < selector.length; tokenIndex++) {
|
|
74
|
-
const char = selector[tokenIndex];
|
|
75
|
-
if (escaped) {
|
|
76
|
-
candidate += char;
|
|
77
|
-
escaped = false;
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
if (char === "\\") {
|
|
81
|
-
escaped = true;
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
if (char && /[\w-]/.test(char)) {
|
|
85
|
-
candidate += char;
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
if (candidate) candidates.add(candidate);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
function collectLayerCandidatesFromCss(css) {
|
|
94
|
-
if (!css.includes("@layer")) return [];
|
|
95
|
-
const candidates = /* @__PURE__ */ new Set();
|
|
96
|
-
try {
|
|
97
|
-
postcss.parse(css).walkAtRules("layer", (layer) => {
|
|
98
|
-
if (!isTailwindCandidateLayer(layer.params)) return;
|
|
99
|
-
layer.walkRules((rule) => {
|
|
100
|
-
extractClassCandidatesFromSelector(rule.selector, candidates);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
} catch {}
|
|
104
|
-
return [...candidates];
|
|
105
|
-
}
|
|
106
|
-
function mergeGenerateCandidates(source, options) {
|
|
107
|
-
return collectCandidates$1([
|
|
108
|
-
...collectLayerCandidatesFromCss(source.css),
|
|
109
|
-
...collectApplyCandidatesFromCss(source.css),
|
|
110
|
-
...collectCandidates$1(options.candidates)
|
|
111
|
-
]);
|
|
112
|
-
}
|
|
113
|
-
function mergeContent(content, rawEntries) {
|
|
114
|
-
if (isLegacyContentObject$1(content)) return {
|
|
115
|
-
...content,
|
|
116
|
-
relative: content.relative ?? true,
|
|
117
|
-
files: [...[].concat(content.files ?? []), ...rawEntries]
|
|
118
|
-
};
|
|
119
|
-
return {
|
|
120
|
-
relative: true,
|
|
121
|
-
files: [...[].concat(content ?? []), ...rawEntries]
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
function normalizeConfigObject(config) {
|
|
125
|
-
if (!config || typeof config !== "object") return config;
|
|
126
|
-
const maybeDefault = config.default;
|
|
127
|
-
if (maybeDefault && typeof maybeDefault === "object") return maybeDefault;
|
|
128
|
-
return config;
|
|
129
|
-
}
|
|
130
|
-
function hasExplicitContentInput(options) {
|
|
131
|
-
return options.candidates !== void 0 || options.sources !== void 0;
|
|
132
|
-
}
|
|
133
|
-
function createExplicitContentConfig(rawEntries) {
|
|
134
|
-
return {
|
|
135
|
-
relative: true,
|
|
136
|
-
files: rawEntries
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
function createTailwindConfig(source, options) {
|
|
140
|
-
const config = { ...normalizeConfigObject(source.configObject) ?? {} };
|
|
141
|
-
const rawEntries = createRawContentEntries(mergeGenerateCandidates(source, options), options.sources ?? []);
|
|
142
|
-
config.content = hasExplicitContentInput(options) ? createExplicitContentConfig(rawEntries) : mergeContent(config.content, rawEntries);
|
|
143
|
-
return config;
|
|
144
|
-
}
|
|
145
|
-
//#endregion
|
|
146
|
-
//#region src/tailwindcss/v3-engine/generator/cache-key.ts
|
|
147
|
-
function createStableJson$1(value) {
|
|
148
|
-
if (value === void 0) return "undefined";
|
|
149
|
-
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
150
|
-
if (Array.isArray(value)) return `[${value.map((item) => createStableJson$1(item)).join(",")}]`;
|
|
151
|
-
return `{${Object.keys(value).sort().map((key) => {
|
|
152
|
-
const record = value;
|
|
153
|
-
return `${JSON.stringify(key)}:${createStableJson$1(record[key])}`;
|
|
154
|
-
}).join(",")}}`;
|
|
155
|
-
}
|
|
156
|
-
function createDependencyFingerprint$1(files) {
|
|
157
|
-
return files.map((file) => {
|
|
158
|
-
try {
|
|
159
|
-
const stat = fs.statSync(file);
|
|
160
|
-
return `${file}:${stat.size}:${stat.mtimeMs}`;
|
|
161
|
-
} catch {
|
|
162
|
-
return `${file}:missing`;
|
|
163
|
-
}
|
|
164
|
-
}).join("|");
|
|
165
|
-
}
|
|
166
|
-
function createIncrementalGenerateCacheKey$1(source, target, styleOptions, bareArbitraryValues) {
|
|
167
|
-
return [
|
|
168
|
-
source.packageName,
|
|
169
|
-
source.postcssPlugin,
|
|
170
|
-
source.cwd,
|
|
171
|
-
source.config ?? "config:missing",
|
|
172
|
-
createDependencyFingerprint$1(source.dependencies),
|
|
173
|
-
source.css,
|
|
174
|
-
createStableJson$1(normalizeConfigObject(source.configObject)?.content),
|
|
175
|
-
target,
|
|
176
|
-
createStableJson$1(styleOptions),
|
|
177
|
-
createStableJson$1(bareArbitraryValues)
|
|
178
|
-
].join("\0");
|
|
179
|
-
}
|
|
180
|
-
//#endregion
|
|
181
|
-
//#region src/context/workspace.ts
|
|
182
|
-
const IGNORED_WORKSPACE_DIRS = new Set([
|
|
183
|
-
"node_modules",
|
|
184
|
-
".git",
|
|
185
|
-
".hg",
|
|
186
|
-
".svn",
|
|
187
|
-
".turbo",
|
|
188
|
-
".output",
|
|
189
|
-
".next",
|
|
190
|
-
"dist",
|
|
191
|
-
"build"
|
|
192
|
-
]);
|
|
193
|
-
function findWorkspaceRoot(startDir) {
|
|
194
|
-
if (!startDir) return;
|
|
195
|
-
let current = path.resolve(startDir);
|
|
196
|
-
while (true) {
|
|
197
|
-
if (existsSync(path.join(current, "pnpm-workspace.yaml"))) return current;
|
|
198
|
-
const parent = path.dirname(current);
|
|
199
|
-
if (parent === current) return;
|
|
200
|
-
current = parent;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
function findNearestPackageRoot(startDir) {
|
|
204
|
-
if (!startDir) return;
|
|
205
|
-
let current = path.resolve(startDir);
|
|
206
|
-
while (true) {
|
|
207
|
-
if (existsSync(path.join(current, "package.json"))) return current;
|
|
208
|
-
const parent = path.dirname(current);
|
|
209
|
-
if (parent === current) return;
|
|
210
|
-
current = parent;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
function findWorkspacePackageDir(rootDir, packageName) {
|
|
214
|
-
const visited = /* @__PURE__ */ new Set();
|
|
215
|
-
const queue = [path.resolve(rootDir)];
|
|
216
|
-
while (queue.length > 0) {
|
|
217
|
-
const current = queue.shift();
|
|
218
|
-
const normalized = path.normalize(current);
|
|
219
|
-
if (visited.has(normalized)) continue;
|
|
220
|
-
visited.add(normalized);
|
|
221
|
-
try {
|
|
222
|
-
const pkgPath = path.join(normalized, "package.json");
|
|
223
|
-
if (existsSync(pkgPath)) {
|
|
224
|
-
if (JSON.parse(readFileSync(pkgPath, "utf8"))?.name === packageName) return normalized;
|
|
225
|
-
}
|
|
226
|
-
} catch {}
|
|
227
|
-
let entries;
|
|
228
|
-
try {
|
|
229
|
-
entries = readdirSync(normalized, { withFileTypes: true });
|
|
230
|
-
} catch {
|
|
231
|
-
continue;
|
|
232
|
-
}
|
|
233
|
-
for (const entry of entries) {
|
|
234
|
-
if (!entry.isDirectory() || IGNORED_WORKSPACE_DIRS.has(entry.name) || entry.isSymbolicLink?.()) continue;
|
|
235
|
-
queue.push(path.join(normalized, entry.name));
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
//#endregion
|
|
240
|
-
//#region src/utils/options.ts
|
|
241
|
-
function resolveBooleanObjectOption(value, enabledValue) {
|
|
242
|
-
if (!value) return false;
|
|
243
|
-
if (value === true) return enabledValue;
|
|
244
|
-
return value;
|
|
245
|
-
}
|
|
246
|
-
function normalizeStringListOption(value) {
|
|
247
|
-
if (!value) return;
|
|
248
|
-
const values = typeof value === "string" ? [value] : Array.isArray(value) ? value : void 0;
|
|
249
|
-
if (!values) return;
|
|
250
|
-
const normalized = values.map((entry) => typeof entry === "string" ? entry.trim() : "").filter((entry) => entry.length > 0);
|
|
251
|
-
return normalized.length > 0 ? normalized : void 0;
|
|
252
|
-
}
|
|
253
|
-
//#endregion
|
|
254
|
-
//#region src/tailwindcss/patcher-options.ts
|
|
255
|
-
function resolveTailwindcssOptions(options) {
|
|
256
|
-
return options?.tailwindcss ?? options?.tailwind;
|
|
257
|
-
}
|
|
258
|
-
function normalizeExtendLengthUnits(value) {
|
|
259
|
-
if (value === void 0) return;
|
|
260
|
-
const resolved = resolveBooleanObjectOption(value, { enabled: true });
|
|
261
|
-
return resolved && typeof resolved === "object" ? {
|
|
262
|
-
enabled: true,
|
|
263
|
-
...resolved
|
|
264
|
-
} : resolved;
|
|
265
|
-
}
|
|
266
|
-
function normalizeTailwindcssPatcherOptions(options) {
|
|
267
|
-
return options;
|
|
268
|
-
}
|
|
269
|
-
//#endregion
|
|
270
|
-
//#region src/tailwindcss/patcher-resolve.ts
|
|
271
|
-
const GENERIC_RELATIVE_SPECIFIERS = [".", ".."];
|
|
272
|
-
const DEFAULT_TAILWIND_CONFIG_SPECIFIERS = ["stubs/config.full.js", "defaultConfig.js"];
|
|
273
|
-
const TAILWIND_CONFIG_FILES = [
|
|
274
|
-
"tailwind.config.js",
|
|
275
|
-
"tailwind.config.cjs",
|
|
276
|
-
"tailwind.config.mjs",
|
|
277
|
-
"tailwind.config.ts",
|
|
278
|
-
"tailwind.config.cts",
|
|
279
|
-
"tailwind.config.mts"
|
|
280
|
-
];
|
|
281
|
-
function isPathSpecifier(specifier) {
|
|
282
|
-
if (!specifier) return false;
|
|
283
|
-
if (specifier.startsWith("file://")) return true;
|
|
284
|
-
if (path.isAbsolute(specifier)) return true;
|
|
285
|
-
return GENERIC_RELATIVE_SPECIFIERS.some((prefix) => specifier.startsWith(`${prefix}/`) || specifier.startsWith(`${prefix}\\`));
|
|
286
|
-
}
|
|
287
|
-
function resolveModuleFromPaths(specifier, paths) {
|
|
288
|
-
if (!specifier || isPathSpecifier(specifier) || paths.length === 0) return;
|
|
289
|
-
try {
|
|
290
|
-
return createRequire(import.meta.url).resolve(specifier, { paths });
|
|
291
|
-
} catch {
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
function resolveTailwindConfigFallback(packageName, paths) {
|
|
296
|
-
if (!packageName) return;
|
|
297
|
-
for (const suffix of DEFAULT_TAILWIND_CONFIG_SPECIFIERS) {
|
|
298
|
-
const resolved = resolveModuleFromPaths(`${packageName}/${suffix}`, paths);
|
|
299
|
-
if (resolved) return resolved;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
function appendNodeModules(paths, dir) {
|
|
303
|
-
if (!dir) return;
|
|
304
|
-
const nodeModulesDir = path.join(dir, "node_modules");
|
|
305
|
-
if (existsSync(nodeModulesDir)) paths.add(nodeModulesDir);
|
|
306
|
-
}
|
|
307
|
-
function findTailwindConfig(searchRoots) {
|
|
308
|
-
for (const root of searchRoots) for (const file of TAILWIND_CONFIG_FILES) {
|
|
309
|
-
const candidate = path.resolve(root, file);
|
|
310
|
-
if (existsSync(candidate)) return candidate;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
function createDefaultResolvePaths(basedir) {
|
|
314
|
-
const paths = /* @__PURE__ */ new Set();
|
|
315
|
-
let fallbackCandidates = [];
|
|
316
|
-
if (basedir) {
|
|
317
|
-
const resolvedBase = path.resolve(basedir);
|
|
318
|
-
appendNodeModules(paths, resolvedBase);
|
|
319
|
-
fallbackCandidates.push(resolvedBase);
|
|
320
|
-
const packageRoot = findNearestPackageRoot(resolvedBase);
|
|
321
|
-
if (packageRoot) {
|
|
322
|
-
appendNodeModules(paths, packageRoot);
|
|
323
|
-
fallbackCandidates.push(packageRoot);
|
|
324
|
-
}
|
|
325
|
-
const workspaceRoot = findWorkspaceRoot(resolvedBase);
|
|
326
|
-
if (workspaceRoot) {
|
|
327
|
-
appendNodeModules(paths, workspaceRoot);
|
|
328
|
-
fallbackCandidates.push(workspaceRoot);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
const cwd = process.cwd();
|
|
332
|
-
appendNodeModules(paths, cwd);
|
|
333
|
-
try {
|
|
334
|
-
const modulePath = fileURLToPath(import.meta.url);
|
|
335
|
-
const candidate = existsSync(modulePath) && !path.extname(modulePath) ? modulePath : path.dirname(modulePath);
|
|
336
|
-
paths.add(candidate);
|
|
337
|
-
} catch {
|
|
338
|
-
paths.add(import.meta.url);
|
|
339
|
-
}
|
|
340
|
-
if (paths.size === 0) {
|
|
341
|
-
fallbackCandidates = fallbackCandidates.filter(Boolean);
|
|
342
|
-
if (fallbackCandidates.length === 0) fallbackCandidates.push(cwd);
|
|
343
|
-
for (const candidate of fallbackCandidates) paths.add(candidate);
|
|
344
|
-
}
|
|
345
|
-
return [...paths];
|
|
346
|
-
}
|
|
347
|
-
//#endregion
|
|
348
|
-
//#region src/tailwindcss/version.ts
|
|
349
|
-
function normalizeSupportedTailwindcssMajorVersion(version) {
|
|
350
|
-
return version === 3 || version === 4 ? version : void 0;
|
|
351
|
-
}
|
|
352
|
-
function readPackageJson(packageJsonPath) {
|
|
353
|
-
try {
|
|
354
|
-
return JSON.parse(readFileSync(packageJsonPath, "utf8"));
|
|
355
|
-
} catch {
|
|
356
|
-
return;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
function findPackageJsonDeclaringPackage(packageName, base) {
|
|
360
|
-
let current = path.resolve(base);
|
|
361
|
-
while (true) {
|
|
362
|
-
const pkgPath = path.join(current, "package.json");
|
|
363
|
-
if (existsSync(pkgPath)) {
|
|
364
|
-
const pkg = readPackageJson(pkgPath);
|
|
365
|
-
if (readDeclaredPackageVersion(packageName, pkg)) return pkgPath;
|
|
366
|
-
if (pkg?.name !== "weapp-tailwindcss") return;
|
|
367
|
-
}
|
|
368
|
-
const parent = path.dirname(current);
|
|
369
|
-
if (parent === current) return;
|
|
370
|
-
current = parent;
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
function readDeclaredPackageVersion(packageName, pkg) {
|
|
374
|
-
return pkg?.dependencies?.[packageName] ?? pkg?.devDependencies?.[packageName] ?? pkg?.peerDependencies?.[packageName] ?? pkg?.optionalDependencies?.[packageName];
|
|
375
|
-
}
|
|
376
|
-
function readDeclaredPackageMajorVersion(version) {
|
|
377
|
-
const match = version?.match(/(?:^|\D)([34])(?:\.|\b)/);
|
|
378
|
-
return normalizeSupportedTailwindcssMajorVersion(match ? Number(match[1]) : void 0);
|
|
379
|
-
}
|
|
380
|
-
function readInstalledPackageMajorVersion(packageName, base) {
|
|
381
|
-
const packageJsonPath = findPackageJsonDeclaringPackage(packageName, base);
|
|
382
|
-
if (!packageJsonPath) return;
|
|
383
|
-
const declaredVersion = readDeclaredPackageVersion(packageName, readPackageJson(packageJsonPath));
|
|
384
|
-
if (!declaredVersion) return;
|
|
385
|
-
try {
|
|
386
|
-
const pkg = createRequire(packageJsonPath)(`${packageName}/package.json`);
|
|
387
|
-
return normalizeSupportedTailwindcssMajorVersion(Number(pkg.version?.split(".")[0]));
|
|
388
|
-
} catch {
|
|
389
|
-
return readDeclaredPackageMajorVersion(declaredVersion);
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
//#endregion
|
|
393
|
-
//#region src/tailwindcss/patcher.ts
|
|
394
|
-
function createFallbackTailwindcssPatcher() {
|
|
395
|
-
return {
|
|
396
|
-
packageInfo: {
|
|
397
|
-
name: "tailwindcss",
|
|
398
|
-
version: void 0,
|
|
399
|
-
rootPath: "",
|
|
400
|
-
packageJsonPath: "",
|
|
401
|
-
packageJson: {}
|
|
402
|
-
},
|
|
403
|
-
majorVersion: 4,
|
|
404
|
-
async getClassSet() {
|
|
405
|
-
return /* @__PURE__ */ new Set();
|
|
406
|
-
},
|
|
407
|
-
async extract(_options) {
|
|
408
|
-
return {
|
|
409
|
-
classList: [],
|
|
410
|
-
classSet: /* @__PURE__ */ new Set()
|
|
411
|
-
};
|
|
412
|
-
},
|
|
413
|
-
async collectContentTokens() {
|
|
414
|
-
return {
|
|
415
|
-
entries: [],
|
|
416
|
-
filesScanned: 0,
|
|
417
|
-
sources: [],
|
|
418
|
-
skippedFiles: []
|
|
419
|
-
};
|
|
420
|
-
}
|
|
421
|
-
};
|
|
422
|
-
}
|
|
423
|
-
let hasLoggedMissingTailwind = false;
|
|
424
|
-
const TAILWINDCSS_NOT_FOUND_RE = /tailwindcss not found/i;
|
|
425
|
-
const UNABLE_TO_LOCATE_TAILWINDCSS_RE = /unable to locate tailwind css package/i;
|
|
426
|
-
function createTailwindcssPatcher(options) {
|
|
427
|
-
const { basedir, cacheDir, supportCustomLengthUnitsPatch, tailwindcss, tailwindcssPatcherOptions } = options || {};
|
|
428
|
-
const cache = { driver: "memory" };
|
|
429
|
-
const normalizedBasedir = basedir ? path.resolve(basedir) : void 0;
|
|
430
|
-
const cacheRoot = findNearestPackageRoot(normalizedBasedir) ?? normalizedBasedir ?? process.cwd();
|
|
431
|
-
if (cacheDir) if (path.isAbsolute(cacheDir)) cache.dir = cacheDir;
|
|
432
|
-
else if (normalizedBasedir) cache.dir = path.resolve(normalizedBasedir, cacheDir);
|
|
433
|
-
else cache.dir = path.resolve(process.cwd(), cacheDir);
|
|
434
|
-
else cache.dir = path.join(cacheRoot, "node_modules", ".cache", "tailwindcss-patch");
|
|
435
|
-
if (normalizedBasedir) cache.cwd = normalizedBasedir;
|
|
436
|
-
const resolvePaths = createDefaultResolvePaths(cache.cwd ?? normalizedBasedir ?? process.cwd());
|
|
437
|
-
const normalizedUserOptions = normalizeTailwindcssPatcherOptions(tailwindcssPatcherOptions);
|
|
438
|
-
const extendLengthUnits = normalizeExtendLengthUnits(supportCustomLengthUnitsPatch ?? true);
|
|
439
|
-
const baseTailwindOptions = defuOverrideArray(tailwindcss ?? {}, omitUndefined({
|
|
440
|
-
cwd: normalizedBasedir,
|
|
441
|
-
resolve: { paths: resolvePaths }
|
|
442
|
-
}));
|
|
443
|
-
if (!baseTailwindOptions.packageName) baseTailwindOptions.packageName = "tailwindcss";
|
|
444
|
-
if (!baseTailwindOptions.postcssPlugin) baseTailwindOptions.postcssPlugin = "tailwindcss";
|
|
445
|
-
if (typeof baseTailwindOptions.postcssPlugin === "string") {
|
|
446
|
-
const resolvedPlugin = resolveModuleFromPaths(baseTailwindOptions.postcssPlugin, resolvePaths);
|
|
447
|
-
if (resolvedPlugin) baseTailwindOptions.postcssPlugin = resolvedPlugin;
|
|
448
|
-
}
|
|
449
|
-
const baseOptions = omitUndefined({
|
|
450
|
-
projectRoot: normalizedBasedir,
|
|
451
|
-
cache,
|
|
452
|
-
tailwindcss: baseTailwindOptions,
|
|
453
|
-
apply: omitUndefined({
|
|
454
|
-
exposeContext: true,
|
|
455
|
-
extendLengthUnits
|
|
456
|
-
})
|
|
457
|
-
});
|
|
458
|
-
const resolvedOptions = defuOverrideArray(normalizedUserOptions ?? {}, baseOptions);
|
|
459
|
-
const resolvedTailwindOptions = resolvedOptions.tailwindcss;
|
|
460
|
-
if (resolvedTailwindOptions) {
|
|
461
|
-
const existingResolve = resolvedTailwindOptions.resolve ?? {};
|
|
462
|
-
const sourcePaths = Array.isArray(existingResolve.paths) && existingResolve.paths.length > 0 ? [...existingResolve.paths ?? [], ...resolvePaths] : resolvePaths;
|
|
463
|
-
resolvedTailwindOptions.resolve = {
|
|
464
|
-
...existingResolve,
|
|
465
|
-
paths: [...new Set(sourcePaths)]
|
|
466
|
-
};
|
|
467
|
-
logger.debug("Tailwind resolve config %O", {
|
|
468
|
-
packageName: resolvedTailwindOptions.packageName,
|
|
469
|
-
version: resolvedTailwindOptions.version,
|
|
470
|
-
resolve: resolvedTailwindOptions.resolve,
|
|
471
|
-
cwd: resolvedTailwindOptions.cwd
|
|
472
|
-
});
|
|
473
|
-
if (typeof resolvedTailwindOptions.postcssPlugin === "string") {
|
|
474
|
-
const resolvedPlugin = resolveModuleFromPaths(resolvedTailwindOptions.postcssPlugin, resolvedTailwindOptions.resolve?.paths ?? resolvePaths);
|
|
475
|
-
if (resolvedPlugin) resolvedTailwindOptions.postcssPlugin = resolvedPlugin;
|
|
476
|
-
}
|
|
477
|
-
const searchRoots = /* @__PURE__ */ new Set();
|
|
478
|
-
if (resolvedTailwindOptions.cwd) searchRoots.add(resolvedTailwindOptions.cwd);
|
|
479
|
-
for (const resolvePath of resolvedTailwindOptions.resolve?.paths ?? []) {
|
|
480
|
-
const parentDir = path.dirname(resolvePath);
|
|
481
|
-
searchRoots.add(parentDir);
|
|
482
|
-
}
|
|
483
|
-
const configPath = findTailwindConfig(searchRoots);
|
|
484
|
-
if (!resolvedTailwindOptions.config) if (configPath) resolvedTailwindOptions.config = configPath;
|
|
485
|
-
else {
|
|
486
|
-
const fallbackConfig = resolveTailwindConfigFallback(resolvedTailwindOptions.packageName, resolvedTailwindOptions.resolve.paths ?? resolvePaths);
|
|
487
|
-
if (fallbackConfig) resolvedTailwindOptions.config = fallbackConfig;
|
|
488
|
-
}
|
|
489
|
-
if (!resolvedTailwindOptions.cwd && configPath) resolvedTailwindOptions.cwd = path.dirname(configPath);
|
|
490
|
-
resolvedOptions.tailwindcss = resolvedTailwindOptions;
|
|
491
|
-
}
|
|
492
|
-
try {
|
|
493
|
-
return new TailwindcssPatcher(resolvedOptions);
|
|
494
|
-
} catch (error) {
|
|
495
|
-
const searchPaths = resolvedOptions.tailwindcss?.resolve?.paths;
|
|
496
|
-
if (error instanceof Error && TAILWINDCSS_NOT_FOUND_RE.test(error.message)) {
|
|
497
|
-
if (!hasLoggedMissingTailwind) {
|
|
498
|
-
logger.warn("Tailwind CSS 未安装,已跳过 Tailwind 运行时能力。若需使用 Tailwind 能力,请安装 tailwindcss。");
|
|
499
|
-
hasLoggedMissingTailwind = true;
|
|
500
|
-
}
|
|
501
|
-
return createFallbackTailwindcssPatcher();
|
|
502
|
-
}
|
|
503
|
-
if (error instanceof Error && UNABLE_TO_LOCATE_TAILWINDCSS_RE.test(error.message)) logger.error("无法定位 Tailwind CSS 包 \"%s\",已尝试路径: %O", resolvedOptions.tailwindcss?.packageName, searchPaths);
|
|
504
|
-
throw error;
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
//#endregion
|
|
508
|
-
//#region src/debug/index.ts
|
|
509
|
-
const _debug = _createDebug("weapp-tw");
|
|
510
|
-
function createDebug(prefix) {
|
|
511
|
-
const debug = ((formatter, ...args) => {
|
|
512
|
-
return _debug((prefix ?? "") + formatter, ...args);
|
|
513
|
-
});
|
|
514
|
-
Object.defineProperty(debug, "enabled", {
|
|
515
|
-
enumerable: false,
|
|
516
|
-
configurable: false,
|
|
517
|
-
get() {
|
|
518
|
-
return _debug.enabled;
|
|
519
|
-
}
|
|
520
|
-
});
|
|
521
|
-
return debug;
|
|
522
|
-
}
|
|
523
|
-
//#endregion
|
|
524
|
-
//#region src/tailwindcss/source-scan/inline-source.ts
|
|
525
|
-
const NUMERICAL_RANGE_RE = /^(-?\d+)\.\.(-?\d+)(?:\.\.(-?\d+))?$/;
|
|
526
|
-
function segmentTopLevel(input, separator, options = {}) {
|
|
527
|
-
const parts = [];
|
|
528
|
-
const stack = [];
|
|
529
|
-
let lastPos = 0;
|
|
530
|
-
let quote;
|
|
531
|
-
for (let index = 0; index < input.length; index++) {
|
|
532
|
-
const char = input[index];
|
|
533
|
-
if (char === "\\") {
|
|
534
|
-
index += 1;
|
|
535
|
-
continue;
|
|
536
|
-
}
|
|
537
|
-
if (quote) {
|
|
538
|
-
if (char === quote) quote = void 0;
|
|
539
|
-
continue;
|
|
540
|
-
}
|
|
541
|
-
if (char === "\"" || char === "'") {
|
|
542
|
-
quote = char;
|
|
543
|
-
continue;
|
|
544
|
-
}
|
|
545
|
-
if (char === "(") {
|
|
546
|
-
stack.push(")");
|
|
547
|
-
continue;
|
|
548
|
-
}
|
|
549
|
-
if (char === "[") {
|
|
550
|
-
stack.push("]");
|
|
551
|
-
continue;
|
|
552
|
-
}
|
|
553
|
-
if (char === "{") {
|
|
554
|
-
stack.push("}");
|
|
555
|
-
continue;
|
|
556
|
-
}
|
|
557
|
-
if (stack.length > 0 && char === stack[stack.length - 1]) {
|
|
558
|
-
stack.pop();
|
|
559
|
-
continue;
|
|
560
|
-
}
|
|
561
|
-
if (stack.length === 0 && char === separator) {
|
|
562
|
-
const part = input.slice(lastPos, index);
|
|
563
|
-
if (part || options.keepEmpty) parts.push(part);
|
|
564
|
-
lastPos = index + 1;
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
const part = input.slice(lastPos);
|
|
568
|
-
if (part || options.keepEmpty) parts.push(part);
|
|
569
|
-
return parts;
|
|
570
|
-
}
|
|
571
|
-
function isSequence(value) {
|
|
572
|
-
return NUMERICAL_RANGE_RE.test(value);
|
|
573
|
-
}
|
|
574
|
-
function expandSequence(value) {
|
|
575
|
-
const match = value.match(NUMERICAL_RANGE_RE);
|
|
576
|
-
if (!match) return [value];
|
|
577
|
-
const [, start, end, stepValue] = match;
|
|
578
|
-
if (start === void 0 || end === void 0) return [value];
|
|
579
|
-
let step = stepValue ? Number.parseInt(stepValue, 10) : void 0;
|
|
580
|
-
const startNumber = Number.parseInt(start, 10);
|
|
581
|
-
const endNumber = Number.parseInt(end, 10);
|
|
582
|
-
const increasing = startNumber < endNumber;
|
|
583
|
-
if (step === void 0) step = increasing ? 1 : -1;
|
|
584
|
-
if (step === 0) return [];
|
|
585
|
-
if (increasing && step < 0) step = -step;
|
|
586
|
-
if (!increasing && step > 0) step = -step;
|
|
587
|
-
const result = [];
|
|
588
|
-
for (let value = startNumber; increasing ? value <= endNumber : value >= endNumber; value += step) result.push(String(value));
|
|
589
|
-
return result;
|
|
590
|
-
}
|
|
591
|
-
function expandInlineSourceCandidatePattern(pattern) {
|
|
592
|
-
const index = pattern.indexOf("{");
|
|
593
|
-
if (index === -1) return [pattern];
|
|
594
|
-
const prefix = pattern.slice(0, index);
|
|
595
|
-
const rest = pattern.slice(index);
|
|
596
|
-
let depth = 0;
|
|
597
|
-
let endIndex = -1;
|
|
598
|
-
for (let index = 0; index < rest.length; index++) {
|
|
599
|
-
const char = rest[index];
|
|
600
|
-
if (char === "{") depth += 1;
|
|
601
|
-
else if (char === "}") {
|
|
602
|
-
depth -= 1;
|
|
603
|
-
if (depth === 0) {
|
|
604
|
-
endIndex = index;
|
|
605
|
-
break;
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
if (endIndex === -1) return [pattern];
|
|
610
|
-
const inner = rest.slice(1, endIndex);
|
|
611
|
-
const suffix = rest.slice(endIndex + 1);
|
|
612
|
-
const parts = (isSequence(inner) ? expandSequence(inner) : segmentTopLevel(inner, ",", { keepEmpty: true })).flatMap((part) => expandInlineSourceCandidatePattern(part));
|
|
613
|
-
return expandInlineSourceCandidatePattern(suffix).flatMap((suffix) => parts.map((part) => `${prefix}${part}${suffix}`));
|
|
614
|
-
}
|
|
615
|
-
function parseSourceInlineParam(params) {
|
|
616
|
-
let value = params.trim();
|
|
617
|
-
const negated = value.startsWith("not ");
|
|
618
|
-
if (negated) value = value.slice(4).trim();
|
|
619
|
-
if (!value.startsWith("inline(") || !value.endsWith(")")) return;
|
|
620
|
-
const inlineValue = value.slice(7, -1).trim();
|
|
621
|
-
const match = /^(['"])([\s\S]*)\1$/.exec(inlineValue);
|
|
622
|
-
if (!match) return;
|
|
623
|
-
const source = match[2];
|
|
624
|
-
if (source === void 0) return;
|
|
625
|
-
return {
|
|
626
|
-
negated,
|
|
627
|
-
source
|
|
628
|
-
};
|
|
629
|
-
}
|
|
630
|
-
function collectCssInlineSourceCandidates(root) {
|
|
631
|
-
const included = /* @__PURE__ */ new Set();
|
|
632
|
-
const excluded = /* @__PURE__ */ new Set();
|
|
633
|
-
root.walkAtRules("source", (rule) => {
|
|
634
|
-
const parsed = parseSourceInlineParam(rule.params);
|
|
635
|
-
if (!parsed) return;
|
|
636
|
-
const target = parsed.negated ? excluded : included;
|
|
637
|
-
for (const source of segmentTopLevel(parsed.source, " ")) {
|
|
638
|
-
const trimmed = source.trim();
|
|
639
|
-
if (!trimmed) continue;
|
|
640
|
-
for (const candidate of expandInlineSourceCandidatePattern(trimmed)) {
|
|
641
|
-
const normalized = candidate.trim();
|
|
642
|
-
if (normalized) target.add(normalized);
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
});
|
|
646
|
-
for (const candidate of excluded) included.delete(candidate);
|
|
647
|
-
return {
|
|
648
|
-
included,
|
|
649
|
-
excluded
|
|
650
|
-
};
|
|
651
|
-
}
|
|
652
|
-
//#endregion
|
|
653
|
-
//#region src/tailwindcss/source-scan.ts
|
|
654
|
-
const DEFAULT_SOURCE_SCAN_EXTENSIONS = [
|
|
655
|
-
"html",
|
|
656
|
-
"wxml",
|
|
657
|
-
"axml",
|
|
658
|
-
"jxml",
|
|
659
|
-
"ksml",
|
|
660
|
-
"ttml",
|
|
661
|
-
"qml",
|
|
662
|
-
"tyml",
|
|
663
|
-
"xhsml",
|
|
664
|
-
"swan",
|
|
665
|
-
"vue",
|
|
666
|
-
"mpx",
|
|
667
|
-
"js",
|
|
668
|
-
"jsx",
|
|
669
|
-
"ts",
|
|
670
|
-
"tsx"
|
|
671
|
-
];
|
|
672
|
-
const FULL_SOURCE_SCAN_EXTENSIONS = [
|
|
673
|
-
"js",
|
|
674
|
-
"jsx",
|
|
675
|
-
"mjs",
|
|
676
|
-
"cjs",
|
|
677
|
-
"ts",
|
|
678
|
-
"tsx",
|
|
679
|
-
"mts",
|
|
680
|
-
"cts",
|
|
681
|
-
"vue",
|
|
682
|
-
"uvue",
|
|
683
|
-
"nvue",
|
|
684
|
-
"svelte",
|
|
685
|
-
"mpx",
|
|
686
|
-
"html",
|
|
687
|
-
"wxml",
|
|
688
|
-
"axml",
|
|
689
|
-
"jxml",
|
|
690
|
-
"ksml",
|
|
691
|
-
"ttml",
|
|
692
|
-
"qml",
|
|
693
|
-
"tyml",
|
|
694
|
-
"xhsml",
|
|
695
|
-
"swan",
|
|
696
|
-
"css",
|
|
697
|
-
"wxss",
|
|
698
|
-
"acss",
|
|
699
|
-
"jxss",
|
|
700
|
-
"ttss",
|
|
701
|
-
"qss",
|
|
702
|
-
"tyss",
|
|
703
|
-
"scss",
|
|
704
|
-
"sass",
|
|
705
|
-
"less",
|
|
706
|
-
"styl",
|
|
707
|
-
"stylus"
|
|
708
|
-
];
|
|
709
|
-
function createSourceScanPattern(extensions = DEFAULT_SOURCE_SCAN_EXTENSIONS) {
|
|
710
|
-
return `**/*.{${extensions.join(",")}}`;
|
|
711
|
-
}
|
|
712
|
-
const FULL_SOURCE_SCAN_PATTERN = createSourceScanPattern(FULL_SOURCE_SCAN_EXTENSIONS);
|
|
713
|
-
const FULL_SOURCE_SCAN_EXTENSION_RE = new RegExp(`\\.(?:${FULL_SOURCE_SCAN_EXTENSIONS.map((extension) => extension.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|")})$`);
|
|
714
|
-
function toPosixPath(value) {
|
|
715
|
-
return value.split(path.sep).join("/");
|
|
716
|
-
}
|
|
717
|
-
function resolveSourceScanPath(value) {
|
|
718
|
-
const resolved = path.resolve(value);
|
|
719
|
-
try {
|
|
720
|
-
return realpathSync.native(resolved);
|
|
721
|
-
} catch {
|
|
722
|
-
return resolved;
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
function normalizeEntryPattern(entry) {
|
|
726
|
-
return path.isAbsolute(entry.pattern) ? toPosixPath(path.relative(resolveSourceScanPath(entry.base), entry.pattern)) : entry.pattern;
|
|
727
|
-
}
|
|
728
|
-
function isFileMatchedByTailwindSourceEntry(file, entry) {
|
|
729
|
-
const relative = toPosixPath(path.relative(resolveSourceScanPath(entry.base), file));
|
|
730
|
-
return relative && !relative.startsWith("../") && !path.isAbsolute(relative) && micromatch.isMatch(relative, normalizeEntryPattern(entry));
|
|
731
|
-
}
|
|
732
|
-
function isFileExcludedByTailwindSourceEntries(file, entries) {
|
|
733
|
-
if (!entries?.length) return false;
|
|
734
|
-
const resolvedFile = resolveSourceScanPath(file);
|
|
735
|
-
return entries.some((entry) => entry.negated && isFileMatchedByTailwindSourceEntry(resolvedFile, entry));
|
|
736
|
-
}
|
|
737
|
-
function isFileMatchedByTailwindSourceEntries(file, entries) {
|
|
738
|
-
if (!entries?.length) return true;
|
|
739
|
-
const positiveEntries = entries.filter((entry) => !entry.negated);
|
|
740
|
-
const negativeEntries = entries.filter((entry) => entry.negated);
|
|
741
|
-
const resolvedFile = resolveSourceScanPath(file);
|
|
742
|
-
if (positiveEntries.length === 0) return !negativeEntries.some((entry) => isFileMatchedByTailwindSourceEntry(resolvedFile, entry));
|
|
743
|
-
if (!positiveEntries.some((entry) => isFileMatchedByTailwindSourceEntry(resolvedFile, entry))) return false;
|
|
744
|
-
return !negativeEntries.some((entry) => isFileMatchedByTailwindSourceEntry(resolvedFile, entry));
|
|
745
|
-
}
|
|
746
|
-
function createTailwindSourceEntryMatcher(entries) {
|
|
747
|
-
if (!entries?.length) return;
|
|
748
|
-
return (file) => isFileMatchedByTailwindSourceEntries(file, entries);
|
|
749
|
-
}
|
|
750
|
-
function resolveTailwindV4CssSourceBase(source, fallbackBase) {
|
|
751
|
-
if (typeof source.base === "string" && source.base.length > 0) return source.base;
|
|
752
|
-
if (typeof source.file === "string" && source.file.length > 0) return path.dirname(source.file);
|
|
753
|
-
return fallbackBase;
|
|
754
|
-
}
|
|
755
|
-
function parseConfigParam$1(params) {
|
|
756
|
-
const value = params.trim();
|
|
757
|
-
return /^(['"])(.+)\1$/.exec(value)?.[2];
|
|
758
|
-
}
|
|
759
|
-
function isLegacyContentObject(value) {
|
|
760
|
-
return typeof value === "object" && value !== null && "files" in value;
|
|
761
|
-
}
|
|
762
|
-
function normalizeGlobPattern(pattern) {
|
|
763
|
-
return pattern.startsWith("./") ? pattern.slice(2) : pattern;
|
|
764
|
-
}
|
|
765
|
-
function hasGlobMagic(value) {
|
|
766
|
-
return /[*?[\]{}()!+@]/.test(value);
|
|
767
|
-
}
|
|
768
|
-
function splitStaticGlobPrefix(pattern) {
|
|
769
|
-
const segments = normalizeGlobPattern(pattern).split(/[\\/]+/);
|
|
770
|
-
const prefix = [];
|
|
771
|
-
const rest = [];
|
|
772
|
-
let reachedGlob = false;
|
|
773
|
-
for (const segment of segments) {
|
|
774
|
-
if (!reachedGlob && segment && !hasGlobMagic(segment)) {
|
|
775
|
-
prefix.push(segment);
|
|
776
|
-
continue;
|
|
777
|
-
}
|
|
778
|
-
reachedGlob = true;
|
|
779
|
-
rest.push(segment);
|
|
780
|
-
}
|
|
781
|
-
return {
|
|
782
|
-
prefix,
|
|
783
|
-
rest
|
|
784
|
-
};
|
|
785
|
-
}
|
|
786
|
-
function normalizeLegacyContentEntries(content, base, options = {}) {
|
|
787
|
-
if (typeof content === "string") {
|
|
788
|
-
const negated = content.startsWith("!");
|
|
789
|
-
return [{
|
|
790
|
-
base,
|
|
791
|
-
negated,
|
|
792
|
-
pattern: normalizeGlobPattern(negated ? content.slice(1) : content)
|
|
793
|
-
}];
|
|
794
|
-
}
|
|
795
|
-
if (Array.isArray(content)) return content.flatMap((item) => normalizeLegacyContentEntries(item, base, options));
|
|
796
|
-
if (isLegacyContentObject(content)) return normalizeLegacyContentEntries(content.files, content.relative && options.relativeBase ? options.relativeBase : base, options);
|
|
797
|
-
return [];
|
|
798
|
-
}
|
|
799
|
-
async function pathExistsAsDirectory(file) {
|
|
800
|
-
try {
|
|
801
|
-
return (await stat(file)).isDirectory();
|
|
802
|
-
} catch {
|
|
803
|
-
return false;
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
async function resolveTailwindSourceEntry(sourcePath, base, negated, defaultPattern = createSourceScanPattern()) {
|
|
807
|
-
const absoluteSource = path.isAbsolute(sourcePath) ? path.resolve(sourcePath) : path.resolve(base, sourcePath);
|
|
808
|
-
if (await pathExistsAsDirectory(absoluteSource)) return {
|
|
809
|
-
base: absoluteSource,
|
|
810
|
-
negated,
|
|
811
|
-
pattern: normalizeGlobPattern(defaultPattern)
|
|
812
|
-
};
|
|
813
|
-
if (path.isAbsolute(sourcePath)) return {
|
|
814
|
-
base: path.dirname(absoluteSource),
|
|
815
|
-
negated,
|
|
816
|
-
pattern: normalizeGlobPattern(path.basename(absoluteSource))
|
|
817
|
-
};
|
|
818
|
-
const { prefix, rest } = splitStaticGlobPrefix(sourcePath);
|
|
819
|
-
if (prefix.length > 0 && rest.length > 0) return {
|
|
820
|
-
base: path.resolve(base, ...prefix),
|
|
821
|
-
negated,
|
|
822
|
-
pattern: normalizeGlobPattern(rest.join("/"))
|
|
823
|
-
};
|
|
824
|
-
return {
|
|
825
|
-
base,
|
|
826
|
-
negated,
|
|
827
|
-
pattern: normalizeGlobPattern(sourcePath)
|
|
828
|
-
};
|
|
829
|
-
}
|
|
830
|
-
function parseSourceFileParam(params) {
|
|
831
|
-
const value = params.trim();
|
|
832
|
-
if (!value || value === "none" || value.startsWith("inline(")) return;
|
|
833
|
-
const negated = value.startsWith("not ");
|
|
834
|
-
const sourceValue = negated ? value.slice(4).trim() : value;
|
|
835
|
-
if (sourceValue.startsWith("inline(")) return;
|
|
836
|
-
const match = /^(['"])(.+)\1$/.exec(sourceValue);
|
|
837
|
-
return match?.[2] ? {
|
|
838
|
-
negated,
|
|
839
|
-
sourcePath: match[2]
|
|
840
|
-
} : void 0;
|
|
841
|
-
}
|
|
842
|
-
async function resolveCssSourceEntries(root, base, defaultPattern = createSourceScanPattern()) {
|
|
843
|
-
const entries = [];
|
|
844
|
-
const tasks = [];
|
|
845
|
-
root.walkAtRules("source", (rule) => {
|
|
846
|
-
const parsed = parseSourceFileParam(rule.params);
|
|
847
|
-
if (!parsed) return;
|
|
848
|
-
tasks.push(resolveTailwindSourceEntry(parsed.sourcePath, base, parsed.negated, defaultPattern));
|
|
849
|
-
});
|
|
850
|
-
entries.push(...await Promise.all(tasks));
|
|
851
|
-
return entries;
|
|
852
|
-
}
|
|
853
|
-
async function expandTailwindSourceEntries(entries, options = {}) {
|
|
854
|
-
if (entries.length === 0) return [];
|
|
855
|
-
const files = /* @__PURE__ */ new Set();
|
|
856
|
-
const entriesByBase = /* @__PURE__ */ new Map();
|
|
857
|
-
for (const entry of entries) {
|
|
858
|
-
const base = path.resolve(entry.base);
|
|
859
|
-
const group = entriesByBase.get(base) ?? [];
|
|
860
|
-
group.push({
|
|
861
|
-
...entry,
|
|
862
|
-
base
|
|
863
|
-
});
|
|
864
|
-
entriesByBase.set(base, group);
|
|
865
|
-
}
|
|
866
|
-
await Promise.all([...entriesByBase.entries()].map(async ([base, group]) => {
|
|
867
|
-
const ignoredSources = options.ignore?.map((pattern) => ({
|
|
868
|
-
base,
|
|
869
|
-
pattern: normalizeGlobPattern(pattern),
|
|
870
|
-
negated: true
|
|
871
|
-
}));
|
|
872
|
-
const matched = await resolveProjectSourceFiles({
|
|
873
|
-
cwd: base,
|
|
874
|
-
sources: group,
|
|
875
|
-
...ignoredSources === void 0 ? {} : { ignoredSources }
|
|
876
|
-
});
|
|
877
|
-
for (const file of matched) files.add(path.resolve(file));
|
|
878
|
-
}));
|
|
879
|
-
return [...files].filter((file) => !isFileExcludedByTailwindSourceEntries(file, entries));
|
|
880
|
-
}
|
|
881
|
-
//#endregion
|
|
882
|
-
//#region src/tailwindcss/v4-engine/candidates.ts
|
|
883
|
-
const UNSUPPORTED_MINI_PROGRAM_TAILWIND_V4_CANDIDATE_RE = /(?:^|:)(?:group|peer|in|not-in)-[^\s:]*\/|(?:^|:)(?:in|not-in)-\[/;
|
|
884
|
-
function isUnsupportedMiniProgramTailwindV4Candidate(candidate) {
|
|
885
|
-
return UNSUPPORTED_MINI_PROGRAM_TAILWIND_V4_CANDIDATE_RE.test(candidate);
|
|
886
|
-
}
|
|
887
|
-
function filterUnsupportedMiniProgramTailwindV4Candidates(candidates) {
|
|
888
|
-
if (!candidates) return;
|
|
889
|
-
return new Set([...candidates].filter((candidate) => !isUnsupportedMiniProgramTailwindV4Candidate(candidate)));
|
|
890
|
-
}
|
|
891
|
-
//#endregion
|
|
892
|
-
//#region src/tailwindcss/v4-engine/tailwind-v3-default-colors.ts
|
|
893
|
-
const TAILWIND_V3_COLOR_STEPS = [
|
|
894
|
-
"50",
|
|
895
|
-
"100",
|
|
896
|
-
"200",
|
|
897
|
-
"300",
|
|
898
|
-
"400",
|
|
899
|
-
"500",
|
|
900
|
-
"600",
|
|
901
|
-
"700",
|
|
902
|
-
"800",
|
|
903
|
-
"900",
|
|
904
|
-
"950"
|
|
905
|
-
];
|
|
906
|
-
const TAILWIND_V3_COLOR_PALETTE = {
|
|
907
|
-
slate: [
|
|
908
|
-
"#f8fafc",
|
|
909
|
-
"#f1f5f9",
|
|
910
|
-
"#e2e8f0",
|
|
911
|
-
"#cbd5e1",
|
|
912
|
-
"#94a3b8",
|
|
913
|
-
"#64748b",
|
|
914
|
-
"#475569",
|
|
915
|
-
"#334155",
|
|
916
|
-
"#1e293b",
|
|
917
|
-
"#0f172a",
|
|
918
|
-
"#020617"
|
|
919
|
-
],
|
|
920
|
-
gray: [
|
|
921
|
-
"#f9fafb",
|
|
922
|
-
"#f3f4f6",
|
|
923
|
-
"#e5e7eb",
|
|
924
|
-
"#d1d5db",
|
|
925
|
-
"#9ca3af",
|
|
926
|
-
"#6b7280",
|
|
927
|
-
"#4b5563",
|
|
928
|
-
"#374151",
|
|
929
|
-
"#1f2937",
|
|
930
|
-
"#111827",
|
|
931
|
-
"#030712"
|
|
932
|
-
],
|
|
933
|
-
zinc: [
|
|
934
|
-
"#fafafa",
|
|
935
|
-
"#f4f4f5",
|
|
936
|
-
"#e4e4e7",
|
|
937
|
-
"#d4d4d8",
|
|
938
|
-
"#a1a1aa",
|
|
939
|
-
"#71717a",
|
|
940
|
-
"#52525b",
|
|
941
|
-
"#3f3f46",
|
|
942
|
-
"#27272a",
|
|
943
|
-
"#18181b",
|
|
944
|
-
"#09090b"
|
|
945
|
-
],
|
|
946
|
-
neutral: [
|
|
947
|
-
"#fafafa",
|
|
948
|
-
"#f5f5f5",
|
|
949
|
-
"#e5e5e5",
|
|
950
|
-
"#d4d4d4",
|
|
951
|
-
"#a3a3a3",
|
|
952
|
-
"#737373",
|
|
953
|
-
"#525252",
|
|
954
|
-
"#404040",
|
|
955
|
-
"#262626",
|
|
956
|
-
"#171717",
|
|
957
|
-
"#0a0a0a"
|
|
958
|
-
],
|
|
959
|
-
stone: [
|
|
960
|
-
"#fafaf9",
|
|
961
|
-
"#f5f5f4",
|
|
962
|
-
"#e7e5e4",
|
|
963
|
-
"#d6d3d1",
|
|
964
|
-
"#a8a29e",
|
|
965
|
-
"#78716c",
|
|
966
|
-
"#57534e",
|
|
967
|
-
"#44403c",
|
|
968
|
-
"#292524",
|
|
969
|
-
"#1c1917",
|
|
970
|
-
"#0c0a09"
|
|
971
|
-
],
|
|
972
|
-
red: [
|
|
973
|
-
"#fef2f2",
|
|
974
|
-
"#fee2e2",
|
|
975
|
-
"#fecaca",
|
|
976
|
-
"#fca5a5",
|
|
977
|
-
"#f87171",
|
|
978
|
-
"#ef4444",
|
|
979
|
-
"#dc2626",
|
|
980
|
-
"#b91c1c",
|
|
981
|
-
"#991b1b",
|
|
982
|
-
"#7f1d1d",
|
|
983
|
-
"#450a0a"
|
|
984
|
-
],
|
|
985
|
-
orange: [
|
|
986
|
-
"#fff7ed",
|
|
987
|
-
"#ffedd5",
|
|
988
|
-
"#fed7aa",
|
|
989
|
-
"#fdba74",
|
|
990
|
-
"#fb923c",
|
|
991
|
-
"#f97316",
|
|
992
|
-
"#ea580c",
|
|
993
|
-
"#c2410c",
|
|
994
|
-
"#9a3412",
|
|
995
|
-
"#7c2d12",
|
|
996
|
-
"#431407"
|
|
997
|
-
],
|
|
998
|
-
amber: [
|
|
999
|
-
"#fffbeb",
|
|
1000
|
-
"#fef3c7",
|
|
1001
|
-
"#fde68a",
|
|
1002
|
-
"#fcd34d",
|
|
1003
|
-
"#fbbf24",
|
|
1004
|
-
"#f59e0b",
|
|
1005
|
-
"#d97706",
|
|
1006
|
-
"#b45309",
|
|
1007
|
-
"#92400e",
|
|
1008
|
-
"#78350f",
|
|
1009
|
-
"#451a03"
|
|
1010
|
-
],
|
|
1011
|
-
yellow: [
|
|
1012
|
-
"#fefce8",
|
|
1013
|
-
"#fef9c3",
|
|
1014
|
-
"#fef08a",
|
|
1015
|
-
"#fde047",
|
|
1016
|
-
"#facc15",
|
|
1017
|
-
"#eab308",
|
|
1018
|
-
"#ca8a04",
|
|
1019
|
-
"#a16207",
|
|
1020
|
-
"#854d0e",
|
|
1021
|
-
"#713f12",
|
|
1022
|
-
"#422006"
|
|
1023
|
-
],
|
|
1024
|
-
lime: [
|
|
1025
|
-
"#f7fee7",
|
|
1026
|
-
"#ecfccb",
|
|
1027
|
-
"#d9f99d",
|
|
1028
|
-
"#bef264",
|
|
1029
|
-
"#a3e635",
|
|
1030
|
-
"#84cc16",
|
|
1031
|
-
"#65a30d",
|
|
1032
|
-
"#4d7c0f",
|
|
1033
|
-
"#3f6212",
|
|
1034
|
-
"#365314",
|
|
1035
|
-
"#1a2e05"
|
|
1036
|
-
],
|
|
1037
|
-
green: [
|
|
1038
|
-
"#f0fdf4",
|
|
1039
|
-
"#dcfce7",
|
|
1040
|
-
"#bbf7d0",
|
|
1041
|
-
"#86efac",
|
|
1042
|
-
"#4ade80",
|
|
1043
|
-
"#22c55e",
|
|
1044
|
-
"#16a34a",
|
|
1045
|
-
"#15803d",
|
|
1046
|
-
"#166534",
|
|
1047
|
-
"#14532d",
|
|
1048
|
-
"#052e16"
|
|
1049
|
-
],
|
|
1050
|
-
emerald: [
|
|
1051
|
-
"#ecfdf5",
|
|
1052
|
-
"#d1fae5",
|
|
1053
|
-
"#a7f3d0",
|
|
1054
|
-
"#6ee7b7",
|
|
1055
|
-
"#34d399",
|
|
1056
|
-
"#10b981",
|
|
1057
|
-
"#059669",
|
|
1058
|
-
"#047857",
|
|
1059
|
-
"#065f46",
|
|
1060
|
-
"#064e3b",
|
|
1061
|
-
"#022c22"
|
|
1062
|
-
],
|
|
1063
|
-
teal: [
|
|
1064
|
-
"#f0fdfa",
|
|
1065
|
-
"#ccfbf1",
|
|
1066
|
-
"#99f6e4",
|
|
1067
|
-
"#5eead4",
|
|
1068
|
-
"#2dd4bf",
|
|
1069
|
-
"#14b8a6",
|
|
1070
|
-
"#0d9488",
|
|
1071
|
-
"#0f766e",
|
|
1072
|
-
"#115e59",
|
|
1073
|
-
"#134e4a",
|
|
1074
|
-
"#042f2e"
|
|
1075
|
-
],
|
|
1076
|
-
cyan: [
|
|
1077
|
-
"#ecfeff",
|
|
1078
|
-
"#cffafe",
|
|
1079
|
-
"#a5f3fc",
|
|
1080
|
-
"#67e8f9",
|
|
1081
|
-
"#22d3ee",
|
|
1082
|
-
"#06b6d4",
|
|
1083
|
-
"#0891b2",
|
|
1084
|
-
"#0e7490",
|
|
1085
|
-
"#155e75",
|
|
1086
|
-
"#164e63",
|
|
1087
|
-
"#083344"
|
|
1088
|
-
],
|
|
1089
|
-
sky: [
|
|
1090
|
-
"#f0f9ff",
|
|
1091
|
-
"#e0f2fe",
|
|
1092
|
-
"#bae6fd",
|
|
1093
|
-
"#7dd3fc",
|
|
1094
|
-
"#38bdf8",
|
|
1095
|
-
"#0ea5e9",
|
|
1096
|
-
"#0284c7",
|
|
1097
|
-
"#0369a1",
|
|
1098
|
-
"#075985",
|
|
1099
|
-
"#0c4a6e",
|
|
1100
|
-
"#082f49"
|
|
1101
|
-
],
|
|
1102
|
-
blue: [
|
|
1103
|
-
"#eff6ff",
|
|
1104
|
-
"#dbeafe",
|
|
1105
|
-
"#bfdbfe",
|
|
1106
|
-
"#93c5fd",
|
|
1107
|
-
"#60a5fa",
|
|
1108
|
-
"#3b82f6",
|
|
1109
|
-
"#2563eb",
|
|
1110
|
-
"#1d4ed8",
|
|
1111
|
-
"#1e40af",
|
|
1112
|
-
"#1e3a8a",
|
|
1113
|
-
"#172554"
|
|
1114
|
-
],
|
|
1115
|
-
indigo: [
|
|
1116
|
-
"#eef2ff",
|
|
1117
|
-
"#e0e7ff",
|
|
1118
|
-
"#c7d2fe",
|
|
1119
|
-
"#a5b4fc",
|
|
1120
|
-
"#818cf8",
|
|
1121
|
-
"#6366f1",
|
|
1122
|
-
"#4f46e5",
|
|
1123
|
-
"#4338ca",
|
|
1124
|
-
"#3730a3",
|
|
1125
|
-
"#312e81",
|
|
1126
|
-
"#1e1b4b"
|
|
1127
|
-
],
|
|
1128
|
-
violet: [
|
|
1129
|
-
"#f5f3ff",
|
|
1130
|
-
"#ede9fe",
|
|
1131
|
-
"#ddd6fe",
|
|
1132
|
-
"#c4b5fd",
|
|
1133
|
-
"#a78bfa",
|
|
1134
|
-
"#8b5cf6",
|
|
1135
|
-
"#7c3aed",
|
|
1136
|
-
"#6d28d9",
|
|
1137
|
-
"#5b21b6",
|
|
1138
|
-
"#4c1d95",
|
|
1139
|
-
"#2e1065"
|
|
1140
|
-
],
|
|
1141
|
-
purple: [
|
|
1142
|
-
"#faf5ff",
|
|
1143
|
-
"#f3e8ff",
|
|
1144
|
-
"#e9d5ff",
|
|
1145
|
-
"#d8b4fe",
|
|
1146
|
-
"#c084fc",
|
|
1147
|
-
"#a855f7",
|
|
1148
|
-
"#9333ea",
|
|
1149
|
-
"#7e22ce",
|
|
1150
|
-
"#6b21a8",
|
|
1151
|
-
"#581c87",
|
|
1152
|
-
"#3b0764"
|
|
1153
|
-
],
|
|
1154
|
-
fuchsia: [
|
|
1155
|
-
"#fdf4ff",
|
|
1156
|
-
"#fae8ff",
|
|
1157
|
-
"#f5d0fe",
|
|
1158
|
-
"#f0abfc",
|
|
1159
|
-
"#e879f9",
|
|
1160
|
-
"#d946ef",
|
|
1161
|
-
"#c026d3",
|
|
1162
|
-
"#a21caf",
|
|
1163
|
-
"#86198f",
|
|
1164
|
-
"#701a75",
|
|
1165
|
-
"#4a044e"
|
|
1166
|
-
],
|
|
1167
|
-
pink: [
|
|
1168
|
-
"#fdf2f8",
|
|
1169
|
-
"#fce7f3",
|
|
1170
|
-
"#fbcfe8",
|
|
1171
|
-
"#f9a8d4",
|
|
1172
|
-
"#f472b6",
|
|
1173
|
-
"#ec4899",
|
|
1174
|
-
"#db2777",
|
|
1175
|
-
"#be185d",
|
|
1176
|
-
"#9d174d",
|
|
1177
|
-
"#831843",
|
|
1178
|
-
"#500724"
|
|
1179
|
-
],
|
|
1180
|
-
rose: [
|
|
1181
|
-
"#fff1f2",
|
|
1182
|
-
"#ffe4e6",
|
|
1183
|
-
"#fecdd3",
|
|
1184
|
-
"#fda4af",
|
|
1185
|
-
"#fb7185",
|
|
1186
|
-
"#f43f5e",
|
|
1187
|
-
"#e11d48",
|
|
1188
|
-
"#be123c",
|
|
1189
|
-
"#9f1239",
|
|
1190
|
-
"#881337",
|
|
1191
|
-
"#4c0519"
|
|
1192
|
-
]
|
|
1193
|
-
};
|
|
1194
|
-
function createTailwindV3DefaultColorThemeCss() {
|
|
1195
|
-
const declarations = [" --color-black: #000;", " --color-white: #fff;"];
|
|
1196
|
-
for (const [color, values] of Object.entries(TAILWIND_V3_COLOR_PALETTE)) for (let index = 0; index < TAILWIND_V3_COLOR_STEPS.length; index++) declarations.push(` --color-${color}-${TAILWIND_V3_COLOR_STEPS[index]}: ${values[index]};`);
|
|
1197
|
-
return [
|
|
1198
|
-
"@theme {",
|
|
1199
|
-
...declarations,
|
|
1200
|
-
"}"
|
|
1201
|
-
].join("\n");
|
|
1202
|
-
}
|
|
1203
|
-
//#endregion
|
|
1204
|
-
//#region src/tailwindcss/v4-engine/tailwind-v3-compatibility.ts
|
|
1205
|
-
const TAILWIND_V3_COMPATIBILITY_THEME_CSS = [
|
|
1206
|
-
"@theme {",
|
|
1207
|
-
" --default-ring-width: 3px;",
|
|
1208
|
-
" --default-ring-color: var(--color-blue-500, #3b82f6);",
|
|
1209
|
-
" --default-outline-width: 3px;",
|
|
1210
|
-
"",
|
|
1211
|
-
" --shadow-xs: 0 1px rgb(0 0 0 / 0.05);",
|
|
1212
|
-
" --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);",
|
|
1213
|
-
" --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);",
|
|
1214
|
-
" --drop-shadow-xs: 0 1px 1px rgb(0 0 0 / 0.05);",
|
|
1215
|
-
" --drop-shadow-sm: 0 1px 2px rgb(0 0 0 / 0.15);",
|
|
1216
|
-
" --drop-shadow: 0 1px 2px rgb(0 0 0 / 0.1), 0 1px 1px rgb(0 0 0 / 0.06);",
|
|
1217
|
-
"",
|
|
1218
|
-
" --blur-xs: 4px;",
|
|
1219
|
-
" --blur-sm: 4px;",
|
|
1220
|
-
" --blur: 8px;",
|
|
1221
|
-
" --backdrop-blur-xs: 4px;",
|
|
1222
|
-
" --backdrop-blur-sm: 4px;",
|
|
1223
|
-
" --backdrop-blur: 8px;",
|
|
1224
|
-
"",
|
|
1225
|
-
" --radius-xs: 0.125rem;",
|
|
1226
|
-
" --radius-sm: 0.125rem;",
|
|
1227
|
-
" --radius: 0.25rem;",
|
|
1228
|
-
"}",
|
|
1229
|
-
createTailwindV3DefaultColorThemeCss()
|
|
1230
|
-
].join("\n");
|
|
1231
|
-
const TAILWIND_V3_COMPATIBILITY_BASE_CSS = [
|
|
1232
|
-
"*,",
|
|
1233
|
-
"::after,",
|
|
1234
|
-
"::before,",
|
|
1235
|
-
"::backdrop,",
|
|
1236
|
-
"::file-selector-button {",
|
|
1237
|
-
" border-color: var(--color-gray-200, currentcolor);",
|
|
1238
|
-
"}",
|
|
1239
|
-
"",
|
|
1240
|
-
"input::placeholder,",
|
|
1241
|
-
"textarea::placeholder {",
|
|
1242
|
-
" opacity: 1;",
|
|
1243
|
-
" color: var(--color-gray-400, currentcolor);",
|
|
1244
|
-
"}",
|
|
1245
|
-
"",
|
|
1246
|
-
"button:not(:disabled),",
|
|
1247
|
-
"[role=\"button\"]:not(:disabled) {",
|
|
1248
|
-
" cursor: pointer;",
|
|
1249
|
-
"}",
|
|
1250
|
-
"",
|
|
1251
|
-
"dialog {",
|
|
1252
|
-
" margin: auto;",
|
|
1253
|
-
"}"
|
|
1254
|
-
].join("\n");
|
|
1255
|
-
function applyTailwindV3CompatibilityCss(css) {
|
|
1256
|
-
return `${TAILWIND_V3_COMPATIBILITY_THEME_CSS}\n${css}\n${TAILWIND_V3_COMPATIBILITY_BASE_CSS}`;
|
|
1257
|
-
}
|
|
1258
|
-
//#endregion
|
|
1259
|
-
//#region src/tailwindcss/v4-engine/tailwind-v4-default-colors.ts
|
|
1260
|
-
const TAILWIND_V4_COLOR_STEPS = [
|
|
1261
|
-
"50",
|
|
1262
|
-
"100",
|
|
1263
|
-
"200",
|
|
1264
|
-
"300",
|
|
1265
|
-
"400",
|
|
1266
|
-
"500",
|
|
1267
|
-
"600",
|
|
1268
|
-
"700",
|
|
1269
|
-
"800",
|
|
1270
|
-
"900",
|
|
1271
|
-
"950"
|
|
1272
|
-
];
|
|
1273
|
-
const TAILWIND_V4_COLOR_PALETTE = {
|
|
1274
|
-
slate: [
|
|
1275
|
-
"#f8fafc",
|
|
1276
|
-
"#f1f5f9",
|
|
1277
|
-
"#e2e8f0",
|
|
1278
|
-
"#cad5e2",
|
|
1279
|
-
"#90a1b9",
|
|
1280
|
-
"#62748e",
|
|
1281
|
-
"#45556c",
|
|
1282
|
-
"#314158",
|
|
1283
|
-
"#1d293d",
|
|
1284
|
-
"#0f172b",
|
|
1285
|
-
"#020618"
|
|
1286
|
-
],
|
|
1287
|
-
gray: [
|
|
1288
|
-
"#f9fafb",
|
|
1289
|
-
"#f3f4f6",
|
|
1290
|
-
"#e5e7eb",
|
|
1291
|
-
"#d1d5dc",
|
|
1292
|
-
"#99a1af",
|
|
1293
|
-
"#6a7282",
|
|
1294
|
-
"#4a5565",
|
|
1295
|
-
"#364153",
|
|
1296
|
-
"#1e2939",
|
|
1297
|
-
"#101828",
|
|
1298
|
-
"#030712"
|
|
1299
|
-
],
|
|
1300
|
-
zinc: [
|
|
1301
|
-
"#fafafa",
|
|
1302
|
-
"#f4f4f5",
|
|
1303
|
-
"#e4e4e7",
|
|
1304
|
-
"#d4d4d8",
|
|
1305
|
-
"#9f9fa9",
|
|
1306
|
-
"#71717b",
|
|
1307
|
-
"#52525c",
|
|
1308
|
-
"#3f3f46",
|
|
1309
|
-
"#27272a",
|
|
1310
|
-
"#18181b",
|
|
1311
|
-
"#09090b"
|
|
1312
|
-
],
|
|
1313
|
-
neutral: [
|
|
1314
|
-
"#fafafa",
|
|
1315
|
-
"#f5f5f5",
|
|
1316
|
-
"#e5e5e5",
|
|
1317
|
-
"#d4d4d4",
|
|
1318
|
-
"#a1a1a1",
|
|
1319
|
-
"#737373",
|
|
1320
|
-
"#525252",
|
|
1321
|
-
"#404040",
|
|
1322
|
-
"#262626",
|
|
1323
|
-
"#171717",
|
|
1324
|
-
"#0a0a0a"
|
|
1325
|
-
],
|
|
1326
|
-
stone: [
|
|
1327
|
-
"#fafaf9",
|
|
1328
|
-
"#f5f5f4",
|
|
1329
|
-
"#e7e5e4",
|
|
1330
|
-
"#d6d3d1",
|
|
1331
|
-
"#a6a09b",
|
|
1332
|
-
"#79716b",
|
|
1333
|
-
"#57534d",
|
|
1334
|
-
"#44403b",
|
|
1335
|
-
"#292524",
|
|
1336
|
-
"#1c1917",
|
|
1337
|
-
"#0c0a09"
|
|
1338
|
-
],
|
|
1339
|
-
mauve: [
|
|
1340
|
-
"#fafafa",
|
|
1341
|
-
"#f3f1f3",
|
|
1342
|
-
"#e7e4e7",
|
|
1343
|
-
"#d7d0d7",
|
|
1344
|
-
"#a89ea9",
|
|
1345
|
-
"#79697b",
|
|
1346
|
-
"#594c5b",
|
|
1347
|
-
"#463947",
|
|
1348
|
-
"#2a212c",
|
|
1349
|
-
"#1d161e",
|
|
1350
|
-
"#0c090c"
|
|
1351
|
-
],
|
|
1352
|
-
olive: [
|
|
1353
|
-
"#fbfbf9",
|
|
1354
|
-
"#f4f4f0",
|
|
1355
|
-
"#e8e8e3",
|
|
1356
|
-
"#d8d8d0",
|
|
1357
|
-
"#abab9c",
|
|
1358
|
-
"#7c7c67",
|
|
1359
|
-
"#5b5b4b",
|
|
1360
|
-
"#474739",
|
|
1361
|
-
"#2b2b22",
|
|
1362
|
-
"#1d1d16",
|
|
1363
|
-
"#0c0c09"
|
|
1364
|
-
],
|
|
1365
|
-
mist: [
|
|
1366
|
-
"#f9fbfb",
|
|
1367
|
-
"#f1f3f3",
|
|
1368
|
-
"#e3e7e8",
|
|
1369
|
-
"#d0d6d8",
|
|
1370
|
-
"#9ca8ab",
|
|
1371
|
-
"#67787c",
|
|
1372
|
-
"#4b585b",
|
|
1373
|
-
"#394447",
|
|
1374
|
-
"#22292b",
|
|
1375
|
-
"#161b1d",
|
|
1376
|
-
"#090b0c"
|
|
1377
|
-
],
|
|
1378
|
-
taupe: [
|
|
1379
|
-
"#fbfaf9",
|
|
1380
|
-
"#f3f1f1",
|
|
1381
|
-
"#e8e4e3",
|
|
1382
|
-
"#d8d2d0",
|
|
1383
|
-
"#aba09c",
|
|
1384
|
-
"#7c6d67",
|
|
1385
|
-
"#5b4f4b",
|
|
1386
|
-
"#473c39",
|
|
1387
|
-
"#2b2422",
|
|
1388
|
-
"#1d1816",
|
|
1389
|
-
"#0c0a09"
|
|
1390
|
-
],
|
|
1391
|
-
red: [
|
|
1392
|
-
"#fef2f2",
|
|
1393
|
-
"#ffe2e2",
|
|
1394
|
-
"#ffc9c9",
|
|
1395
|
-
"#ffa2a2",
|
|
1396
|
-
"#ff6467",
|
|
1397
|
-
"#fb2c36",
|
|
1398
|
-
"#e7000b",
|
|
1399
|
-
"#c10007",
|
|
1400
|
-
"#9f0712",
|
|
1401
|
-
"#82181a",
|
|
1402
|
-
"#460809"
|
|
1403
|
-
],
|
|
1404
|
-
orange: [
|
|
1405
|
-
"#fff7ed",
|
|
1406
|
-
"#ffedd4",
|
|
1407
|
-
"#ffd6a7",
|
|
1408
|
-
"#ffb86a",
|
|
1409
|
-
"#ff8904",
|
|
1410
|
-
"#ff6900",
|
|
1411
|
-
"#f54900",
|
|
1412
|
-
"#ca3500",
|
|
1413
|
-
"#9f2d00",
|
|
1414
|
-
"#7e2a0c",
|
|
1415
|
-
"#441306"
|
|
1416
|
-
],
|
|
1417
|
-
amber: [
|
|
1418
|
-
"#fffbeb",
|
|
1419
|
-
"#fef3c6",
|
|
1420
|
-
"#fee685",
|
|
1421
|
-
"#ffd230",
|
|
1422
|
-
"#ffb900",
|
|
1423
|
-
"#fe9a00",
|
|
1424
|
-
"#e17100",
|
|
1425
|
-
"#bb4d00",
|
|
1426
|
-
"#973c00",
|
|
1427
|
-
"#7b3306",
|
|
1428
|
-
"#461901"
|
|
1429
|
-
],
|
|
1430
|
-
yellow: [
|
|
1431
|
-
"#fefce8",
|
|
1432
|
-
"#fef9c2",
|
|
1433
|
-
"#fff085",
|
|
1434
|
-
"#ffdf20",
|
|
1435
|
-
"#fdc700",
|
|
1436
|
-
"#f0b100",
|
|
1437
|
-
"#d08700",
|
|
1438
|
-
"#a65f00",
|
|
1439
|
-
"#894b00",
|
|
1440
|
-
"#733e0a",
|
|
1441
|
-
"#432004"
|
|
1442
|
-
],
|
|
1443
|
-
lime: [
|
|
1444
|
-
"#f7fee7",
|
|
1445
|
-
"#ecfcca",
|
|
1446
|
-
"#d8f999",
|
|
1447
|
-
"#bbf451",
|
|
1448
|
-
"#9ae600",
|
|
1449
|
-
"#7ccf00",
|
|
1450
|
-
"#5ea500",
|
|
1451
|
-
"#497d00",
|
|
1452
|
-
"#3c6300",
|
|
1453
|
-
"#35530e",
|
|
1454
|
-
"#192e03"
|
|
1455
|
-
],
|
|
1456
|
-
green: [
|
|
1457
|
-
"#f0fdf4",
|
|
1458
|
-
"#dcfce7",
|
|
1459
|
-
"#b9f8cf",
|
|
1460
|
-
"#7bf1a8",
|
|
1461
|
-
"#05df72",
|
|
1462
|
-
"#00c950",
|
|
1463
|
-
"#00a63e",
|
|
1464
|
-
"#008236",
|
|
1465
|
-
"#016630",
|
|
1466
|
-
"#0d542b",
|
|
1467
|
-
"#032e15"
|
|
1468
|
-
],
|
|
1469
|
-
emerald: [
|
|
1470
|
-
"#ecfdf5",
|
|
1471
|
-
"#d0fae5",
|
|
1472
|
-
"#a4f4cf",
|
|
1473
|
-
"#5ee9b5",
|
|
1474
|
-
"#00d492",
|
|
1475
|
-
"#00bc7d",
|
|
1476
|
-
"#009966",
|
|
1477
|
-
"#007a55",
|
|
1478
|
-
"#006045",
|
|
1479
|
-
"#004f3b",
|
|
1480
|
-
"#002c22"
|
|
1481
|
-
],
|
|
1482
|
-
teal: [
|
|
1483
|
-
"#f0fdfa",
|
|
1484
|
-
"#cbfbf1",
|
|
1485
|
-
"#96f7e4",
|
|
1486
|
-
"#46ecd5",
|
|
1487
|
-
"#00d5be",
|
|
1488
|
-
"#00bba7",
|
|
1489
|
-
"#009689",
|
|
1490
|
-
"#00786f",
|
|
1491
|
-
"#005f5a",
|
|
1492
|
-
"#0b4f4a",
|
|
1493
|
-
"#022f2e"
|
|
1494
|
-
],
|
|
1495
|
-
cyan: [
|
|
1496
|
-
"#ecfeff",
|
|
1497
|
-
"#cefafe",
|
|
1498
|
-
"#a2f4fd",
|
|
1499
|
-
"#53eafd",
|
|
1500
|
-
"#00d3f2",
|
|
1501
|
-
"#00b8db",
|
|
1502
|
-
"#0092b8",
|
|
1503
|
-
"#007595",
|
|
1504
|
-
"#005f78",
|
|
1505
|
-
"#104e64",
|
|
1506
|
-
"#053345"
|
|
1507
|
-
],
|
|
1508
|
-
sky: [
|
|
1509
|
-
"#f0f9ff",
|
|
1510
|
-
"#dff2fe",
|
|
1511
|
-
"#b8e6fe",
|
|
1512
|
-
"#74d4ff",
|
|
1513
|
-
"#00bcff",
|
|
1514
|
-
"#00a6f4",
|
|
1515
|
-
"#0084d1",
|
|
1516
|
-
"#0069a8",
|
|
1517
|
-
"#00598a",
|
|
1518
|
-
"#024a70",
|
|
1519
|
-
"#052f4a"
|
|
1520
|
-
],
|
|
1521
|
-
blue: [
|
|
1522
|
-
"#eff6ff",
|
|
1523
|
-
"#dbeafe",
|
|
1524
|
-
"#bedbff",
|
|
1525
|
-
"#8ec5ff",
|
|
1526
|
-
"#51a2ff",
|
|
1527
|
-
"#2b7fff",
|
|
1528
|
-
"#155dfc",
|
|
1529
|
-
"#1447e6",
|
|
1530
|
-
"#193cb8",
|
|
1531
|
-
"#1c398e",
|
|
1532
|
-
"#162456"
|
|
1533
|
-
],
|
|
1534
|
-
indigo: [
|
|
1535
|
-
"#eef2ff",
|
|
1536
|
-
"#e0e7ff",
|
|
1537
|
-
"#c6d2ff",
|
|
1538
|
-
"#a3b3ff",
|
|
1539
|
-
"#7c86ff",
|
|
1540
|
-
"#615fff",
|
|
1541
|
-
"#4f39f6",
|
|
1542
|
-
"#432dd7",
|
|
1543
|
-
"#372aac",
|
|
1544
|
-
"#312c85",
|
|
1545
|
-
"#1e1a4d"
|
|
1546
|
-
],
|
|
1547
|
-
violet: [
|
|
1548
|
-
"#f5f3ff",
|
|
1549
|
-
"#ede9fe",
|
|
1550
|
-
"#ddd6ff",
|
|
1551
|
-
"#c4b4ff",
|
|
1552
|
-
"#a684ff",
|
|
1553
|
-
"#8e51ff",
|
|
1554
|
-
"#7f22fe",
|
|
1555
|
-
"#7008e7",
|
|
1556
|
-
"#5d0ec0",
|
|
1557
|
-
"#4d179a",
|
|
1558
|
-
"#2f0d68"
|
|
1559
|
-
],
|
|
1560
|
-
purple: [
|
|
1561
|
-
"#faf5ff",
|
|
1562
|
-
"#f3e8ff",
|
|
1563
|
-
"#e9d4ff",
|
|
1564
|
-
"#dab2ff",
|
|
1565
|
-
"#c27aff",
|
|
1566
|
-
"#ad46ff",
|
|
1567
|
-
"#9810fa",
|
|
1568
|
-
"#8200db",
|
|
1569
|
-
"#6e11b0",
|
|
1570
|
-
"#59168b",
|
|
1571
|
-
"#3c0366"
|
|
1572
|
-
],
|
|
1573
|
-
fuchsia: [
|
|
1574
|
-
"#fdf4ff",
|
|
1575
|
-
"#fae8ff",
|
|
1576
|
-
"#f6cfff",
|
|
1577
|
-
"#f4a8ff",
|
|
1578
|
-
"#ed6aff",
|
|
1579
|
-
"#e12afb",
|
|
1580
|
-
"#c800de",
|
|
1581
|
-
"#a800b7",
|
|
1582
|
-
"#8a0194",
|
|
1583
|
-
"#721378",
|
|
1584
|
-
"#4b004f"
|
|
1585
|
-
],
|
|
1586
|
-
pink: [
|
|
1587
|
-
"#fdf2f8",
|
|
1588
|
-
"#fce7f3",
|
|
1589
|
-
"#fccee8",
|
|
1590
|
-
"#fda5d5",
|
|
1591
|
-
"#fb64b6",
|
|
1592
|
-
"#f6339a",
|
|
1593
|
-
"#e60076",
|
|
1594
|
-
"#c6005c",
|
|
1595
|
-
"#a3004c",
|
|
1596
|
-
"#861043",
|
|
1597
|
-
"#510424"
|
|
1598
|
-
],
|
|
1599
|
-
rose: [
|
|
1600
|
-
"#fff1f2",
|
|
1601
|
-
"#ffe4e6",
|
|
1602
|
-
"#ffccd3",
|
|
1603
|
-
"#ffa1ad",
|
|
1604
|
-
"#ff637e",
|
|
1605
|
-
"#ff2056",
|
|
1606
|
-
"#ec003f",
|
|
1607
|
-
"#c70036",
|
|
1608
|
-
"#a50036",
|
|
1609
|
-
"#8b0836",
|
|
1610
|
-
"#4d0218"
|
|
1611
|
-
]
|
|
1612
|
-
};
|
|
1613
|
-
function createTailwindV4DefaultColorThemeCss() {
|
|
1614
|
-
const declarations = [" --color-black: #000;", " --color-white: #fff;"];
|
|
1615
|
-
for (const [color, values] of Object.entries(TAILWIND_V4_COLOR_PALETTE)) for (let index = 0; index < TAILWIND_V4_COLOR_STEPS.length; index++) declarations.push(` --color-${color}-${TAILWIND_V4_COLOR_STEPS[index]}: ${values[index]};`);
|
|
1616
|
-
return [
|
|
1617
|
-
"@theme {",
|
|
1618
|
-
...declarations,
|
|
1619
|
-
"}"
|
|
1620
|
-
].join("\n");
|
|
1621
|
-
}
|
|
1622
|
-
//#endregion
|
|
1623
|
-
//#region src/tailwindcss/v4-engine/generator/css-compat.ts
|
|
1624
|
-
function findLeadingImportInsertionIndex(css) {
|
|
1625
|
-
const importPattern = /(?:^|\n)\s*@import\b[^;]*;/g;
|
|
1626
|
-
let insertionIndex = 0;
|
|
1627
|
-
let match = importPattern.exec(css);
|
|
1628
|
-
while (match !== null) {
|
|
1629
|
-
insertionIndex = match.index + match[0].length;
|
|
1630
|
-
match = importPattern.exec(css);
|
|
1631
|
-
}
|
|
1632
|
-
return insertionIndex;
|
|
1633
|
-
}
|
|
1634
|
-
function applyMiniProgramTailwindV4DefaultColorCss(css) {
|
|
1635
|
-
const themeCss = createTailwindV4DefaultColorThemeCss();
|
|
1636
|
-
const insertionIndex = findLeadingImportInsertionIndex(css);
|
|
1637
|
-
if (insertionIndex === 0) return `${themeCss}\n${css}`;
|
|
1638
|
-
return `${css.slice(0, insertionIndex)}\n${themeCss}\n${css.slice(insertionIndex)}`;
|
|
1639
|
-
}
|
|
1640
|
-
function parseCssImportSpecifier$3(params) {
|
|
1641
|
-
const value = params.trim();
|
|
1642
|
-
const quoted = /^(['"])(.*?)\1/.exec(value);
|
|
1643
|
-
if (quoted) return quoted[2];
|
|
1644
|
-
const url = /^url\(\s*(?:(['"])(.*?)\1|([^'")\s]+))\s*\)/.exec(value);
|
|
1645
|
-
return url?.[2] ?? url?.[3];
|
|
1646
|
-
}
|
|
1647
|
-
function isTailwindCssPreflightImport(params) {
|
|
1648
|
-
const specifier = parseCssImportSpecifier$3(params);
|
|
1649
|
-
return specifier === "tailwindcss/preflight.css" || specifier === "tailwindcss/preflight";
|
|
1650
|
-
}
|
|
1651
|
-
function hasImportLayerOption(params) {
|
|
1652
|
-
return /\blayer(?:\s*\(|\s*$)/.test(params);
|
|
1653
|
-
}
|
|
1654
|
-
function removeUnlayeredTailwindV4PreflightImports(css) {
|
|
1655
|
-
if (!css.includes("preflight")) return css;
|
|
1656
|
-
let root;
|
|
1657
|
-
try {
|
|
1658
|
-
root = postcss.parse(css);
|
|
1659
|
-
} catch {
|
|
1660
|
-
return css;
|
|
1661
|
-
}
|
|
1662
|
-
let changed = false;
|
|
1663
|
-
root.walkAtRules("import", (rule) => {
|
|
1664
|
-
if (isTailwindCssPreflightImport(rule.params) && !hasImportLayerOption(rule.params)) {
|
|
1665
|
-
rule.remove();
|
|
1666
|
-
changed = true;
|
|
1667
|
-
}
|
|
1668
|
-
});
|
|
1669
|
-
return changed ? root.toString() : css;
|
|
1670
|
-
}
|
|
1671
|
-
function hasThemeParent(rule) {
|
|
1672
|
-
let parent = rule.parent;
|
|
1673
|
-
while (parent) {
|
|
1674
|
-
if (parent.type === "atrule" && parent.name === "theme") return true;
|
|
1675
|
-
parent = parent.parent;
|
|
1676
|
-
}
|
|
1677
|
-
return false;
|
|
1678
|
-
}
|
|
1679
|
-
function isVendorPrefixedKeyframes(rule) {
|
|
1680
|
-
return rule.name.startsWith("-") && rule.name.endsWith("keyframes");
|
|
1681
|
-
}
|
|
1682
|
-
function removeUnsupportedThemeVendorKeyframes(css) {
|
|
1683
|
-
if (!css.includes("@theme") || !css.includes("@-")) return css;
|
|
1684
|
-
let root;
|
|
1685
|
-
try {
|
|
1686
|
-
root = postcss.parse(css);
|
|
1687
|
-
} catch {
|
|
1688
|
-
return css;
|
|
1689
|
-
}
|
|
1690
|
-
let changed = false;
|
|
1691
|
-
root.walkAtRules((rule) => {
|
|
1692
|
-
if (isVendorPrefixedKeyframes(rule) && hasThemeParent(rule)) {
|
|
1693
|
-
rule.remove();
|
|
1694
|
-
changed = true;
|
|
1695
|
-
}
|
|
1696
|
-
});
|
|
1697
|
-
return changed ? root.toString() : css;
|
|
1698
|
-
}
|
|
1699
|
-
function createCompatibleSource(source, target, tailwindcssV3Compatibility) {
|
|
1700
|
-
const shouldApplyTailwindV3Compatibility = tailwindcssV3Compatibility ?? target === "weapp";
|
|
1701
|
-
const filteredSourceCss = target === "weapp" ? removeUnlayeredTailwindV4PreflightImports(source.css) : source.css;
|
|
1702
|
-
const compatibleSourceCss = removeUnsupportedThemeVendorKeyframes(shouldApplyTailwindV3Compatibility ? applyTailwindV3CompatibilityCss(filteredSourceCss) : target === "weapp" ? applyMiniProgramTailwindV4DefaultColorCss(filteredSourceCss) : filteredSourceCss);
|
|
1703
|
-
return compatibleSourceCss === source.css ? source : {
|
|
1704
|
-
...source,
|
|
1705
|
-
css: compatibleSourceCss
|
|
1706
|
-
};
|
|
1707
|
-
}
|
|
1708
|
-
//#endregion
|
|
1709
|
-
//#region src/tailwindcss/v4-engine/generator/rpx-candidates.ts
|
|
1710
|
-
const BARE_RPX_TEXT_CANDIDATE_RE = /(^|:)text-\[([-+]?(?:\d+|\d*\.\d+)rpx)\](.*)$/u;
|
|
1711
|
-
const RPX_TEXT_LENGTH_SELECTOR_RE = /text-\\\[length\\:((?:\\[.+-]|[+\-.\d])+rpx)\\\]/g;
|
|
1712
|
-
function normalizeRpxTextCandidate(candidate) {
|
|
1713
|
-
return candidate.replace(BARE_RPX_TEXT_CANDIDATE_RE, "$1text-[length:$2]$3");
|
|
1714
|
-
}
|
|
1715
|
-
function normalizeRpxTextCandidates(candidates) {
|
|
1716
|
-
const normalized = /* @__PURE__ */ new Set();
|
|
1717
|
-
const restoreCandidates = /* @__PURE__ */ new Map();
|
|
1718
|
-
for (const candidate of candidates) {
|
|
1719
|
-
const normalizedCandidate = normalizeRpxTextCandidate(candidate);
|
|
1720
|
-
normalized.add(normalizedCandidate);
|
|
1721
|
-
if (normalizedCandidate !== candidate) restoreCandidates.set(normalizedCandidate, candidate);
|
|
1722
|
-
}
|
|
1723
|
-
return {
|
|
1724
|
-
candidates: normalized,
|
|
1725
|
-
restoreCandidates
|
|
1726
|
-
};
|
|
1727
|
-
}
|
|
1728
|
-
function restoreRpxTextCandidates(candidates, restoreCandidates) {
|
|
1729
|
-
if (restoreCandidates.size === 0) return new Set(candidates);
|
|
1730
|
-
return new Set([...candidates].map((candidate) => restoreCandidates.get(candidate) ?? candidate));
|
|
1731
|
-
}
|
|
1732
|
-
function normalizeCssEscapedRpxSelectorValue(value) {
|
|
1733
|
-
return value.replace(/\\([.+-])/g, "$1");
|
|
1734
|
-
}
|
|
1735
|
-
function restoreRpxTextCssSelectors(css, restoreCandidates) {
|
|
1736
|
-
if (restoreCandidates.size === 0 || !css.includes("text-\\[length\\:")) return css;
|
|
1737
|
-
const restoredValues = new Set([...restoreCandidates.keys()].map((candidate) => {
|
|
1738
|
-
return BARE_RPX_TEXT_CANDIDATE_RE.exec(candidate.replace("[length:", "["))?.[2];
|
|
1739
|
-
}).filter((value) => Boolean(value)));
|
|
1740
|
-
return css.replace(RPX_TEXT_LENGTH_SELECTOR_RE, (match, value) => {
|
|
1741
|
-
return restoredValues.has(normalizeCssEscapedRpxSelectorValue(value)) ? `text-\\[${value}\\]` : match;
|
|
1742
|
-
});
|
|
1743
|
-
}
|
|
1744
|
-
//#endregion
|
|
1745
|
-
//#region src/tailwindcss/v4-engine/generator/scan-sources.ts
|
|
1746
|
-
const TAILWIND_V4_DEFAULT_IGNORED_SOURCE_PATTERNS = [
|
|
1747
|
-
"**/.git/**",
|
|
1748
|
-
"**/.hg/**",
|
|
1749
|
-
"**/.jj/**",
|
|
1750
|
-
"**/.next/**",
|
|
1751
|
-
"**/.parcel-cache/**",
|
|
1752
|
-
"**/.pnpm-store/**",
|
|
1753
|
-
"**/.svelte-kit/**",
|
|
1754
|
-
"**/.svn/**",
|
|
1755
|
-
"**/.turbo/**",
|
|
1756
|
-
"**/.venv/**",
|
|
1757
|
-
"**/.vercel/**",
|
|
1758
|
-
"**/.yarn/**",
|
|
1759
|
-
"**/__pycache__/**",
|
|
1760
|
-
"**/node_modules/**",
|
|
1761
|
-
"**/venv/**",
|
|
1762
|
-
"**/*.less",
|
|
1763
|
-
"**/*.lock",
|
|
1764
|
-
"**/*.sass",
|
|
1765
|
-
"**/*.scss",
|
|
1766
|
-
"**/*.styl",
|
|
1767
|
-
"**/*.log",
|
|
1768
|
-
"**/package-lock.json",
|
|
1769
|
-
"**/pnpm-lock.yaml",
|
|
1770
|
-
"**/bun.lockb",
|
|
1771
|
-
"**/.gitignore",
|
|
1772
|
-
"**/.env",
|
|
1773
|
-
"**/.env.*"
|
|
1774
|
-
];
|
|
1775
|
-
function parseImportSourceParam$1(params) {
|
|
1776
|
-
const match = /\bsource\(\s*(none|(['"])(.*?)\2)\s*\)/.exec(params);
|
|
1777
|
-
if (!match) return;
|
|
1778
|
-
return {
|
|
1779
|
-
none: match[1] === "none",
|
|
1780
|
-
sourcePath: match[3]
|
|
1781
|
-
};
|
|
1782
|
-
}
|
|
1783
|
-
function parseCssImportSpecifier$2(params) {
|
|
1784
|
-
const value = params.trim();
|
|
1785
|
-
const quoted = /^(['"])(.*?)\1/.exec(value);
|
|
1786
|
-
if (quoted) return quoted[2];
|
|
1787
|
-
const url = /^url\(\s*(?:(['"])(.*?)\1|([^'")\s]+))\s*\)/.exec(value);
|
|
1788
|
-
return url?.[2] ?? url?.[3];
|
|
1789
|
-
}
|
|
1790
|
-
function isTailwindCssImport$1(params) {
|
|
1791
|
-
const specifier = parseCssImportSpecifier$2(params);
|
|
1792
|
-
return specifier === "tailwindcss" || specifier?.startsWith("tailwindcss/") || specifier?.replaceAll("\\", "/").endsWith("/tailwindcss/index.css");
|
|
1793
|
-
}
|
|
1794
|
-
function resolveSourceBase$1(base, sourcePath) {
|
|
1795
|
-
return path.isAbsolute(sourcePath) ? sourcePath : path.resolve(base, sourcePath);
|
|
1796
|
-
}
|
|
1797
|
-
function createDefaultIgnoredScanSources(base) {
|
|
1798
|
-
return TAILWIND_V4_DEFAULT_IGNORED_SOURCE_PATTERNS.map((pattern) => ({
|
|
1799
|
-
base,
|
|
1800
|
-
pattern,
|
|
1801
|
-
negated: true
|
|
1802
|
-
}));
|
|
1803
|
-
}
|
|
1804
|
-
function normalizeCssDefinedScanSources(base, entries) {
|
|
1805
|
-
return entries.length > 0 && entries.every((entry) => entry.negated) ? [{
|
|
1806
|
-
base,
|
|
1807
|
-
pattern: "**/*",
|
|
1808
|
-
negated: false
|
|
1809
|
-
}, ...entries] : entries;
|
|
1810
|
-
}
|
|
1811
|
-
async function resolveCssDefinedScanSources(source) {
|
|
1812
|
-
let importSourceBase;
|
|
1813
|
-
let hasSourceNone = false;
|
|
1814
|
-
const from = source.dependencies[0];
|
|
1815
|
-
let root;
|
|
1816
|
-
try {
|
|
1817
|
-
root = postcss.parse(source.css, { from });
|
|
1818
|
-
} catch {
|
|
1819
|
-
return;
|
|
1820
|
-
}
|
|
1821
|
-
root.walkAtRules((rule) => {
|
|
1822
|
-
if (rule.name === "import") {
|
|
1823
|
-
if (!isTailwindCssImport$1(rule.params)) return;
|
|
1824
|
-
const sourceParam = parseImportSourceParam$1(rule.params);
|
|
1825
|
-
if (sourceParam?.none) hasSourceNone = true;
|
|
1826
|
-
if (sourceParam?.sourcePath) importSourceBase = resolveSourceBase$1(source.base, sourceParam.sourcePath);
|
|
1827
|
-
}
|
|
1828
|
-
});
|
|
1829
|
-
const sourcePatterns = await resolveCssSourceEntries(root, source.base, "**/*");
|
|
1830
|
-
if (!importSourceBase) {
|
|
1831
|
-
if (sourcePatterns.length > 0) return [...normalizeCssDefinedScanSources(source.base, sourcePatterns), ...createDefaultIgnoredScanSources(source.base)];
|
|
1832
|
-
if (hasSourceNone) return false;
|
|
1833
|
-
return;
|
|
1834
|
-
}
|
|
1835
|
-
return [
|
|
1836
|
-
await resolveTailwindSourceEntry(".", importSourceBase, false, "**/*"),
|
|
1837
|
-
...sourcePatterns,
|
|
1838
|
-
...createDefaultIgnoredScanSources(importSourceBase)
|
|
1839
|
-
];
|
|
1840
|
-
}
|
|
1841
|
-
async function resolveScanSources(source, scanSources) {
|
|
1842
|
-
if (scanSources !== true) return scanSources;
|
|
1843
|
-
return await resolveCssDefinedScanSources(source) ?? false;
|
|
1844
|
-
}
|
|
1845
|
-
//#endregion
|
|
1846
|
-
//#region src/tailwindcss/v4-engine/miniprogram.ts
|
|
1847
|
-
const defaultStyleHandler$1 = createStyleHandler({
|
|
1848
|
-
cssChildCombinatorReplaceValue: ["view", "text"],
|
|
1849
|
-
cssRemoveHoverPseudoClass: true,
|
|
1850
|
-
isMainChunk: true,
|
|
1851
|
-
majorVersion: 4
|
|
1852
|
-
});
|
|
1853
|
-
const CSS_DECLARATION_URL_RE = /(:\s*)url\(([^\n\r"';[\]{}]*[[\]{}][^\n\r;]*)\)(?=\s*;)/g;
|
|
1854
|
-
function normalizeTailwindV4GeneratedUrlValues(css) {
|
|
1855
|
-
return css.replace(CSS_DECLARATION_URL_RE, (match, prefix, urlValue) => {
|
|
1856
|
-
try {
|
|
1857
|
-
return `${prefix}url("${urlValue.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"")}")`;
|
|
1858
|
-
} catch {
|
|
1859
|
-
return match;
|
|
1860
|
-
}
|
|
1861
|
-
});
|
|
1862
|
-
}
|
|
1863
|
-
async function transformTailwindV4CssToWeapp(css, options) {
|
|
1864
|
-
const protectedCss = protectDynamicColorMixAlpha(normalizeTailwindV4GeneratedUrlValues(hasCssMacroStyleOptions(options) ? await transformCssMacroCss(css, options) : css), { customPropertyValues: options && "customPropertyValues" in options ? options.customPropertyValues : void 0 });
|
|
1865
|
-
const result = await defaultStyleHandler$1(protectedCss.css, {
|
|
1866
|
-
cssChildCombinatorReplaceValue: ["view", "text"],
|
|
1867
|
-
cssRemoveHoverPseudoClass: true,
|
|
1868
|
-
isMainChunk: true,
|
|
1869
|
-
majorVersion: 4,
|
|
1870
|
-
...options
|
|
1871
|
-
});
|
|
1872
|
-
const pruneOptions = { preserveConditionalComments: hasCssMacroStyleOptions(options) };
|
|
1873
|
-
return pruneMiniProgramGeneratedCss(protectedCss.restore(result.css), pruneOptions);
|
|
1874
|
-
}
|
|
1875
|
-
async function transformTailwindV4CssByTarget(css, target, options) {
|
|
1876
|
-
if (target === "weapp") return transformTailwindV4CssToWeapp(css, options);
|
|
1877
|
-
return hasCssMacroStyleOptions(options) ? transformCssMacroCss(css, options) : css;
|
|
1878
|
-
}
|
|
1879
|
-
//#endregion
|
|
1880
|
-
//#region src/tailwindcss/v4-engine/generator.ts
|
|
1881
|
-
const INCREMENTAL_GENERATE_CACHE_MAX$1 = 8;
|
|
1882
|
-
const INCREMENTAL_GENERATE_TASK_CACHE_MAX = 32;
|
|
1883
|
-
const INCREMENTAL_GENERATE_ENTRY_CANDIDATES_MAX$1 = 128;
|
|
1884
|
-
const INCREMENTAL_GENERATE_ENTRY_CSS_BYTES_MAX$1 = 256 * 1024;
|
|
1885
|
-
const incrementalGenerateCache$1 = new LRUCache({ max: INCREMENTAL_GENERATE_CACHE_MAX$1 });
|
|
1886
|
-
const incrementalGenerateTaskCache = new LRUCache({ max: INCREMENTAL_GENERATE_TASK_CACHE_MAX });
|
|
1887
|
-
function collectCandidates(candidates) {
|
|
1888
|
-
return new Set(candidates ?? []);
|
|
1889
|
-
}
|
|
1890
|
-
function hasRemovedCandidates$1(previousCandidates, nextCandidates) {
|
|
1891
|
-
for (const candidate of previousCandidates) if (!nextCandidates.has(candidate)) return true;
|
|
1892
|
-
return false;
|
|
1893
|
-
}
|
|
1894
|
-
function createStableJson(value) {
|
|
1895
|
-
if (value === void 0) return "undefined";
|
|
1896
|
-
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
1897
|
-
if (Array.isArray(value)) return `[${value.map((item) => createStableJson(item)).join(",")}]`;
|
|
1898
|
-
return `{${Object.keys(value).sort().map((key) => {
|
|
1899
|
-
const record = value;
|
|
1900
|
-
return `${JSON.stringify(key)}:${createStableJson(record[key])}`;
|
|
1901
|
-
}).join(",")}}`;
|
|
1902
|
-
}
|
|
1903
|
-
function createDependencyFingerprint(files) {
|
|
1904
|
-
return files.map((file) => {
|
|
1905
|
-
try {
|
|
1906
|
-
const stat = fs.statSync(file);
|
|
1907
|
-
return `${file}:${stat.size}:${stat.mtimeMs}`;
|
|
1908
|
-
} catch {
|
|
1909
|
-
return `${file}:missing`;
|
|
1910
|
-
}
|
|
1911
|
-
}).join("|");
|
|
1912
|
-
}
|
|
1913
|
-
function createIncrementalGenerateCacheKey(source, target, styleOptions, tailwindcssV3Compatibility) {
|
|
1914
|
-
return [
|
|
1915
|
-
source.projectRoot,
|
|
1916
|
-
source.base,
|
|
1917
|
-
createStableJson(source.baseFallbacks),
|
|
1918
|
-
source.css,
|
|
1919
|
-
createDependencyFingerprint(source.dependencies),
|
|
1920
|
-
target,
|
|
1921
|
-
createStableJson(styleOptions),
|
|
1922
|
-
createStableJson(tailwindcssV3Compatibility)
|
|
1923
|
-
].join("\0");
|
|
1924
|
-
}
|
|
1925
|
-
function createIncrementalGenerateTaskCacheKey(cacheKey, requestedCandidates, scanSources) {
|
|
1926
|
-
return [
|
|
1927
|
-
cacheKey,
|
|
1928
|
-
scanSources === true ? "scan:1" : "scan:0",
|
|
1929
|
-
[...requestedCandidates].sort().join("\n")
|
|
1930
|
-
].join("\0");
|
|
1931
|
-
}
|
|
1932
|
-
function runIncrementalGenerateTask(cacheKey, requestedCandidates, scanSources, task) {
|
|
1933
|
-
const taskKey = createIncrementalGenerateTaskCacheKey(cacheKey, requestedCandidates, scanSources);
|
|
1934
|
-
const cachedTask = incrementalGenerateTaskCache.get(taskKey);
|
|
1935
|
-
if (cachedTask) return cachedTask;
|
|
1936
|
-
const promise = task();
|
|
1937
|
-
incrementalGenerateTaskCache.set(taskKey, promise);
|
|
1938
|
-
promise.finally(() => {
|
|
1939
|
-
if (incrementalGenerateTaskCache.get(taskKey) === promise) incrementalGenerateTaskCache.delete(taskKey);
|
|
1940
|
-
});
|
|
1941
|
-
return promise;
|
|
1942
|
-
}
|
|
1943
|
-
function createIncrementalDesignSystemPromise(source, cacheKey) {
|
|
1944
|
-
const promise = loadTailwindV4DesignSystem(source);
|
|
1945
|
-
promise.catch(() => {
|
|
1946
|
-
if (incrementalGenerateCache$1.get(cacheKey)?.designSystemPromise === promise) incrementalGenerateCache$1.delete(cacheKey);
|
|
1947
|
-
});
|
|
1948
|
-
return promise;
|
|
1949
|
-
}
|
|
1950
|
-
function resolveTargetCandidates(candidates, target) {
|
|
1951
|
-
const collected = collectCandidates(candidates);
|
|
1952
|
-
return target === "weapp" ? filterUnsupportedMiniProgramTailwindV4Candidates(collected) : collected;
|
|
1953
|
-
}
|
|
1954
|
-
function collectSeenCandidates(generated, requestedCandidates) {
|
|
1955
|
-
return new Set([
|
|
1956
|
-
...requestedCandidates,
|
|
1957
|
-
...generated.rawCandidates,
|
|
1958
|
-
...generated.classSet
|
|
1959
|
-
]);
|
|
1960
|
-
}
|
|
1961
|
-
function createIncrementalStyleOptions(styleOptions) {
|
|
1962
|
-
return {
|
|
1963
|
-
...styleOptions,
|
|
1964
|
-
isMainChunk: false
|
|
1965
|
-
};
|
|
1966
|
-
}
|
|
1967
|
-
function resolveStyleOptions$1(source, options) {
|
|
1968
|
-
return hasCssMacroTailwindV4Directive(source.css) ? withCssMacroStyleOptions(options) : options;
|
|
1969
|
-
}
|
|
1970
|
-
function collectCustomPropertyValues(css) {
|
|
1971
|
-
const values = /* @__PURE__ */ new Map();
|
|
1972
|
-
try {
|
|
1973
|
-
postcss.parse(css).walkDecls((decl) => {
|
|
1974
|
-
if (decl.prop.startsWith("--")) values.set(decl.prop, decl.value.trim());
|
|
1975
|
-
});
|
|
1976
|
-
} catch {}
|
|
1977
|
-
return values;
|
|
1978
|
-
}
|
|
1979
|
-
function mergeCustomPropertyValues(target, css) {
|
|
1980
|
-
for (const [prop, value] of collectCustomPropertyValues(css)) target.set(prop, value);
|
|
1981
|
-
}
|
|
1982
|
-
function shouldRebuildIncrementalEntry$1(cached, requestedCandidates, missingCandidates) {
|
|
1983
|
-
return cached.seenCandidates.size + missingCandidates.length > INCREMENTAL_GENERATE_ENTRY_CANDIDATES_MAX$1 || cached.css.length > INCREMENTAL_GENERATE_ENTRY_CSS_BYTES_MAX$1 || cached.rawCss.length > INCREMENTAL_GENERATE_ENTRY_CSS_BYTES_MAX$1 || requestedCandidates.size > INCREMENTAL_GENERATE_ENTRY_CANDIDATES_MAX$1;
|
|
1984
|
-
}
|
|
1985
|
-
function seedIncrementalGenerateCache(options) {
|
|
1986
|
-
const cacheKey = createIncrementalGenerateCacheKey(options.compatibleSource, options.target, options.styleOptions, options.tailwindcssV3Compatibility);
|
|
1987
|
-
const customPropertyValues = collectCustomPropertyValues(options.compatibleSource.css);
|
|
1988
|
-
mergeCustomPropertyValues(customPropertyValues, options.generated.css);
|
|
1989
|
-
incrementalGenerateCache$1.set(cacheKey, {
|
|
1990
|
-
seenCandidates: collectSeenCandidates(options.generated, options.requestedCandidates),
|
|
1991
|
-
classSet: new Set(options.generated.classSet),
|
|
1992
|
-
css: options.generated.css,
|
|
1993
|
-
rawCss: options.generated.rawCss,
|
|
1994
|
-
customPropertyValues,
|
|
1995
|
-
designSystemPromise: createIncrementalDesignSystemPromise(options.compatibleSource, cacheKey),
|
|
1996
|
-
dependencies: options.generated.dependencies,
|
|
1997
|
-
sources: options.generated.sources,
|
|
1998
|
-
root: options.generated.root,
|
|
1999
|
-
target: options.generated.target
|
|
2000
|
-
});
|
|
2001
|
-
}
|
|
2002
|
-
function createTailwindV4Engine$1(source) {
|
|
2003
|
-
async function generateOnce(generateSource, options = {}) {
|
|
2004
|
-
const { scanSources = true, styleOptions, tailwindcssV3Compatibility, target = "weapp", ...patchOptions } = options;
|
|
2005
|
-
const resolvedStyleOptions = resolveStyleOptions$1(generateSource, styleOptions);
|
|
2006
|
-
const engine = createTailwindV4Engine(createCompatibleSource(generateSource, target, tailwindcssV3Compatibility));
|
|
2007
|
-
const resolvedScanSources = await resolveScanSources(generateSource, scanSources);
|
|
2008
|
-
const filesystemCandidates = Array.isArray(resolvedScanSources) ? new Set(await extractRawCandidates(resolvedScanSources, { ...patchOptions.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: patchOptions.bareArbitraryValues } })) : void 0;
|
|
2009
|
-
const normalizedCandidates = normalizeRpxTextCandidates(resolveTargetCandidates(new Set([...collectCandidates(patchOptions.candidates), ...filesystemCandidates ?? []]), target));
|
|
2010
|
-
const result = await engine.generate(omitUndefined({
|
|
2011
|
-
scanSources: false,
|
|
2012
|
-
...patchOptions,
|
|
2013
|
-
candidates: normalizedCandidates.candidates
|
|
2014
|
-
}));
|
|
2015
|
-
const rawCss = restoreRpxTextCssSelectors(result.css, normalizedCandidates.restoreCandidates);
|
|
2016
|
-
const css = await transformTailwindV4CssByTarget(rawCss, target, resolvedStyleOptions);
|
|
2017
|
-
return {
|
|
2018
|
-
...result,
|
|
2019
|
-
classSet: restoreRpxTextCandidates(result.classSet, normalizedCandidates.restoreCandidates),
|
|
2020
|
-
rawCandidates: restoreRpxTextCandidates(result.rawCandidates, normalizedCandidates.restoreCandidates),
|
|
2021
|
-
css,
|
|
2022
|
-
rawCss,
|
|
2023
|
-
target
|
|
2024
|
-
};
|
|
2025
|
-
}
|
|
2026
|
-
async function generateWithIncrementalCache(options = {}) {
|
|
2027
|
-
const target = options.target ?? "weapp";
|
|
2028
|
-
const compatibleSource = createCompatibleSource(source, target, options.tailwindcssV3Compatibility);
|
|
2029
|
-
const requestedCandidates = resolveTargetCandidates(options.candidates, target);
|
|
2030
|
-
const styleOptions = resolveStyleOptions$1(source, options.styleOptions);
|
|
2031
|
-
if ((options.sources?.length ?? 0) > 0 || options.bareArbitraryValues !== void 0 || Array.isArray(options.scanSources)) return generateOnce(source, options);
|
|
2032
|
-
const cacheKey = createIncrementalGenerateCacheKey(compatibleSource, target, styleOptions, options.tailwindcssV3Compatibility);
|
|
2033
|
-
if (options.scanSources === true) return runIncrementalGenerateTask(cacheKey, requestedCandidates, options.scanSources, async () => {
|
|
2034
|
-
const generated = await generateOnce(source, options);
|
|
2035
|
-
seedIncrementalGenerateCache({
|
|
2036
|
-
compatibleSource,
|
|
2037
|
-
generated,
|
|
2038
|
-
requestedCandidates,
|
|
2039
|
-
styleOptions: options.styleOptions,
|
|
2040
|
-
tailwindcssV3Compatibility: options.tailwindcssV3Compatibility,
|
|
2041
|
-
target
|
|
2042
|
-
});
|
|
2043
|
-
return generated;
|
|
2044
|
-
});
|
|
2045
|
-
const cached = incrementalGenerateCache$1.get(cacheKey);
|
|
2046
|
-
if (cached) {
|
|
2047
|
-
if (hasRemovedCandidates$1(cached.seenCandidates, requestedCandidates)) return runIncrementalGenerateTask(cacheKey, requestedCandidates, options.scanSources, async () => {
|
|
2048
|
-
const generated = await generateOnce(source, options);
|
|
2049
|
-
seedIncrementalGenerateCache({
|
|
2050
|
-
compatibleSource,
|
|
2051
|
-
generated,
|
|
2052
|
-
requestedCandidates,
|
|
2053
|
-
styleOptions,
|
|
2054
|
-
tailwindcssV3Compatibility: options.tailwindcssV3Compatibility,
|
|
2055
|
-
target
|
|
2056
|
-
});
|
|
2057
|
-
return generated;
|
|
2058
|
-
});
|
|
2059
|
-
const missingCandidates = [...requestedCandidates].filter((candidate) => !cached.seenCandidates.has(candidate));
|
|
2060
|
-
if (missingCandidates.length === 0) return {
|
|
2061
|
-
css: cached.css,
|
|
2062
|
-
rawCss: cached.rawCss,
|
|
2063
|
-
incrementalCss: "",
|
|
2064
|
-
incrementalRawCss: "",
|
|
2065
|
-
classSet: new Set(cached.classSet),
|
|
2066
|
-
rawCandidates: new Set(cached.seenCandidates),
|
|
2067
|
-
dependencies: cached.dependencies,
|
|
2068
|
-
sources: cached.sources,
|
|
2069
|
-
root: cached.root,
|
|
2070
|
-
target: cached.target
|
|
2071
|
-
};
|
|
2072
|
-
if (shouldRebuildIncrementalEntry$1(cached, requestedCandidates, missingCandidates)) return runIncrementalGenerateTask(cacheKey, requestedCandidates, options.scanSources, async () => {
|
|
2073
|
-
const generated = await generateOnce(source, options);
|
|
2074
|
-
seedIncrementalGenerateCache({
|
|
2075
|
-
compatibleSource,
|
|
2076
|
-
generated,
|
|
2077
|
-
requestedCandidates,
|
|
2078
|
-
styleOptions,
|
|
2079
|
-
tailwindcssV3Compatibility: options.tailwindcssV3Compatibility,
|
|
2080
|
-
target
|
|
2081
|
-
});
|
|
2082
|
-
return generated;
|
|
2083
|
-
});
|
|
2084
|
-
return runIncrementalGenerateTask(cacheKey, requestedCandidates, options.scanSources, async () => {
|
|
2085
|
-
const designSystem = await cached.designSystemPromise;
|
|
2086
|
-
const normalizedMissing = normalizeRpxTextCandidates(missingCandidates);
|
|
2087
|
-
const normalizedMissingCandidates = [...normalizedMissing.candidates];
|
|
2088
|
-
const cssByCandidate = designSystem.candidatesToCss(normalizedMissingCandidates);
|
|
2089
|
-
const rawCssParts = [];
|
|
2090
|
-
const classSet = /* @__PURE__ */ new Set();
|
|
2091
|
-
for (let index = 0; index < normalizedMissingCandidates.length; index += 1) {
|
|
2092
|
-
const candidate = normalizedMissingCandidates[index];
|
|
2093
|
-
const css = cssByCandidate[index];
|
|
2094
|
-
if (candidate && typeof css === "string" && css.trim().length > 0) {
|
|
2095
|
-
rawCssParts.push(restoreRpxTextCssSelectors(css, normalizedMissing.restoreCandidates));
|
|
2096
|
-
classSet.add(normalizedMissing.restoreCandidates.get(candidate) ?? candidate);
|
|
2097
|
-
}
|
|
2098
|
-
}
|
|
2099
|
-
const rawCss = rawCssParts.join("\n");
|
|
2100
|
-
const incrementalCss = rawCss.length > 0 ? await transformTailwindV4CssByTarget(rawCss, target, {
|
|
2101
|
-
...createIncrementalStyleOptions(styleOptions),
|
|
2102
|
-
customPropertyValues: cached.customPropertyValues
|
|
2103
|
-
}) : "";
|
|
2104
|
-
for (const candidate of missingCandidates) cached.seenCandidates.add(candidate);
|
|
2105
|
-
for (const className of classSet) cached.classSet.add(className);
|
|
2106
|
-
cached.css = [cached.css, incrementalCss].filter(Boolean).join("\n");
|
|
2107
|
-
cached.rawCss = [cached.rawCss, rawCss].filter(Boolean).join("\n");
|
|
2108
|
-
mergeCustomPropertyValues(cached.customPropertyValues, incrementalCss);
|
|
2109
|
-
return {
|
|
2110
|
-
css: cached.css,
|
|
2111
|
-
rawCss: cached.rawCss,
|
|
2112
|
-
incrementalCss,
|
|
2113
|
-
incrementalRawCss: rawCss,
|
|
2114
|
-
classSet: new Set(cached.classSet),
|
|
2115
|
-
rawCandidates: new Set(cached.seenCandidates),
|
|
2116
|
-
dependencies: cached.dependencies,
|
|
2117
|
-
sources: cached.sources,
|
|
2118
|
-
root: cached.root,
|
|
2119
|
-
target: cached.target
|
|
2120
|
-
};
|
|
2121
|
-
});
|
|
2122
|
-
}
|
|
2123
|
-
return runIncrementalGenerateTask(cacheKey, requestedCandidates, options.scanSources, async () => {
|
|
2124
|
-
const generated = await generateOnce(source, options);
|
|
2125
|
-
seedIncrementalGenerateCache({
|
|
2126
|
-
compatibleSource,
|
|
2127
|
-
generated,
|
|
2128
|
-
requestedCandidates,
|
|
2129
|
-
styleOptions,
|
|
2130
|
-
tailwindcssV3Compatibility: options.tailwindcssV3Compatibility,
|
|
2131
|
-
target
|
|
2132
|
-
});
|
|
2133
|
-
return generated;
|
|
2134
|
-
});
|
|
2135
|
-
}
|
|
2136
|
-
async function generate(options = {}) {
|
|
2137
|
-
return options.incrementalCache ? generateWithIncrementalCache(options) : generateOnce(source, options);
|
|
2138
|
-
}
|
|
2139
|
-
return {
|
|
2140
|
-
source,
|
|
2141
|
-
loadDesignSystem: createTailwindV4Engine(source).loadDesignSystem,
|
|
2142
|
-
validateCandidates: createTailwindV4Engine(source).validateCandidates,
|
|
2143
|
-
generate
|
|
2144
|
-
};
|
|
2145
|
-
}
|
|
2146
|
-
function getTailwindV4IncrementalGenerateCacheStats() {
|
|
2147
|
-
return {
|
|
2148
|
-
max: INCREMENTAL_GENERATE_CACHE_MAX$1,
|
|
2149
|
-
entryCandidatesMax: INCREMENTAL_GENERATE_ENTRY_CANDIDATES_MAX$1,
|
|
2150
|
-
entryCssBytesMax: INCREMENTAL_GENERATE_ENTRY_CSS_BYTES_MAX$1,
|
|
2151
|
-
size: incrementalGenerateCache$1.size,
|
|
2152
|
-
taskMax: INCREMENTAL_GENERATE_TASK_CACHE_MAX,
|
|
2153
|
-
taskSize: incrementalGenerateTaskCache.size,
|
|
2154
|
-
entries: [...incrementalGenerateCache$1.entries()].map(([key, entry]) => ({
|
|
2155
|
-
key,
|
|
2156
|
-
candidates: entry.seenCandidates.size,
|
|
2157
|
-
classSet: entry.classSet.size,
|
|
2158
|
-
cssBytes: entry.css.length,
|
|
2159
|
-
rawCssBytes: entry.rawCss.length
|
|
2160
|
-
})),
|
|
2161
|
-
keys: [...incrementalGenerateCache$1.keys()],
|
|
2162
|
-
taskKeys: [...incrementalGenerateTaskCache.keys()]
|
|
2163
|
-
};
|
|
2164
|
-
}
|
|
2165
|
-
//#endregion
|
|
2166
|
-
//#region src/bundlers/shared/generator-css/config-directive.ts
|
|
2167
|
-
function quoteCssString(value) {
|
|
2168
|
-
return value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"");
|
|
2169
|
-
}
|
|
2170
|
-
function toCssPath(value) {
|
|
2171
|
-
return value.replaceAll("\\", "/");
|
|
2172
|
-
}
|
|
2173
|
-
function prependConfigDirective(css, config) {
|
|
2174
|
-
if (!config || /@config\s+/.test(css)) return css;
|
|
2175
|
-
return `@config "${quoteCssString(toCssPath(config))}";\n${css}`;
|
|
2176
|
-
}
|
|
2177
|
-
function normalizeConfigDirective(css, config) {
|
|
2178
|
-
if (!config || !/@config\s+/.test(css)) return css;
|
|
2179
|
-
return css.replace(/@config\s+(["'])(.+?)\1\s*;?/, `@config "${quoteCssString(toCssPath(config))}";`);
|
|
2180
|
-
}
|
|
2181
|
-
//#endregion
|
|
2182
|
-
//#region src/bundlers/shared/generator-css/markers.ts
|
|
2183
|
-
const TAILWIND_V4_BANNER_RE = /\/\*!\s*tailwindcss v4\./;
|
|
2184
|
-
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)-/;
|
|
2185
|
-
const GENERATOR_PLACEHOLDER_MARKER_RE = /\/\*!\s*weapp-tailwindcss generator-placeholder\s*\*\//i;
|
|
2186
|
-
const GENERATOR_PLACEHOLDER_MARKER_GLOBAL_RE = /\/\*!\s*weapp-tailwindcss generator-placeholder\s*\*\/\s*/gi;
|
|
2187
|
-
const TAILWIND_BANNER_PREFIX_RE = /^\/\*!\s*tailwindcss v[^*]*\*\/\s*/i;
|
|
2188
|
-
const TAILWIND_BANNER_RE = /\/\*!\s*tailwindcss v[^*]*\*\//i;
|
|
2189
|
-
const TAILWIND_BANNER_GLOBAL_RE = /\/\*!\s*tailwindcss v[^*]*\*\/\s*/gi;
|
|
2190
|
-
const VITE_MARKER_RE = /\/\*\$vite\$:[^*]*\*\//g;
|
|
2191
|
-
function createCssAppend(base, extra) {
|
|
2192
|
-
if (!base) return extra;
|
|
2193
|
-
if (!extra) return base;
|
|
2194
|
-
return `${base}\n${extra}`;
|
|
2195
|
-
}
|
|
2196
|
-
function splitTailwindV4GeneratedCssBySourceOrder(rawSource, rawTailwindCss) {
|
|
2197
|
-
const trimmedRaw = rawSource.trim();
|
|
2198
|
-
const trimmedTailwind = rawTailwindCss.trim();
|
|
2199
|
-
if (trimmedRaw === trimmedTailwind) return {
|
|
2200
|
-
before: "",
|
|
2201
|
-
after: ""
|
|
2202
|
-
};
|
|
2203
|
-
if (trimmedTailwind.startsWith(trimmedRaw)) return {
|
|
2204
|
-
before: "",
|
|
2205
|
-
after: ""
|
|
2206
|
-
};
|
|
2207
|
-
const start = rawSource.indexOf(rawTailwindCss);
|
|
2208
|
-
if (start === -1) return;
|
|
2209
|
-
return {
|
|
2210
|
-
before: rawSource.slice(0, start),
|
|
2211
|
-
after: rawSource.slice(start + rawTailwindCss.length)
|
|
2212
|
-
};
|
|
2213
|
-
}
|
|
2214
|
-
function splitGeneratorPlaceholderCssBySourceOrder(rawSource, rawTailwindCss) {
|
|
2215
|
-
const match = GENERATOR_PLACEHOLDER_MARKER_RE.exec(rawSource);
|
|
2216
|
-
if (!match || match.index === void 0) return;
|
|
2217
|
-
let afterStart = match.index + match[0].length;
|
|
2218
|
-
while (/\s/.test(rawSource[afterStart] ?? "")) afterStart++;
|
|
2219
|
-
if (rawTailwindCss && rawSource.slice(afterStart).startsWith(rawTailwindCss)) {
|
|
2220
|
-
afterStart += rawTailwindCss.length;
|
|
2221
|
-
while (/\s/.test(rawSource[afterStart] ?? "")) afterStart++;
|
|
2222
|
-
}
|
|
2223
|
-
return {
|
|
2224
|
-
before: rawSource.slice(0, match.index),
|
|
2225
|
-
after: rawSource.slice(afterStart)
|
|
2226
|
-
};
|
|
2227
|
-
}
|
|
2228
|
-
function splitTailwindGeneratedCssByBanner(rawSource, start) {
|
|
2229
|
-
const match = start === void 0 ? TAILWIND_BANNER_RE.exec(rawSource) : { index: start };
|
|
2230
|
-
if (!match || match.index === void 0) return;
|
|
2231
|
-
return {
|
|
2232
|
-
before: rawSource.slice(0, match.index),
|
|
2233
|
-
after: [...rawSource.slice(match.index).matchAll(VITE_MARKER_RE)].map((item) => item[0]).join("\n")
|
|
2234
|
-
};
|
|
2235
|
-
}
|
|
2236
|
-
function stripTailwindBanner(css) {
|
|
2237
|
-
return css.replace(TAILWIND_BANNER_PREFIX_RE, "");
|
|
2238
|
-
}
|
|
2239
|
-
function stripTailwindBanners(css) {
|
|
2240
|
-
return css.replace(TAILWIND_BANNER_GLOBAL_RE, "");
|
|
2241
|
-
}
|
|
2242
|
-
function stripGeneratorPlaceholderMarkers(css) {
|
|
2243
|
-
return css.replace(GENERATOR_PLACEHOLDER_MARKER_GLOBAL_RE, "");
|
|
2244
|
-
}
|
|
2245
|
-
function hasTailwindGeneratedCss(rawSource) {
|
|
2246
|
-
return TAILWIND_V4_BANNER_RE.test(rawSource);
|
|
2247
|
-
}
|
|
2248
|
-
function hasTailwindGeneratedCssMarkers(rawSource) {
|
|
2249
|
-
return TAILWIND_GENERATED_CSS_MARKER_RE.test(rawSource) || GENERATOR_PLACEHOLDER_MARKER_RE.test(rawSource);
|
|
2250
|
-
}
|
|
2251
|
-
//#endregion
|
|
2252
|
-
//#region src/bundlers/shared/generator-css/directives/fallback.ts
|
|
2253
|
-
const TAILWIND_EXTRACTABLE_DIRECTIVE_RE = /^\s*@(?:import|use|forward|tailwind|config|source|reference|plugin)\b[\s\S]*?(?:;|$)/;
|
|
2254
|
-
const TAILWIND_EXTRACTABLE_LAYER_STATEMENT_RE = /^\s*@layer\s[^;{]+;\s*$/;
|
|
2255
|
-
const TAILWIND_EXTRACTABLE_BLOCK_START_RE = /^\s*@(?:layer|theme|utility|variant|custom-variant|plugin)\b[\s\S]*\{/;
|
|
2256
|
-
function parseImportRequest$1(params) {
|
|
2257
|
-
return /^(?:url\(\s*)?(["']?)([^"')\s]+)\1\s*\)?/.exec(params.trim())?.[2];
|
|
2258
|
-
}
|
|
2259
|
-
function parseConfigRequest$1(params) {
|
|
2260
|
-
return /^(["'])(.+)\1\s*;?$/.exec(params.trim())?.[2];
|
|
2261
|
-
}
|
|
2262
|
-
function isPackageJsonImportRequest$1(request) {
|
|
2263
|
-
return typeof request === "string" && request.startsWith("#");
|
|
2264
|
-
}
|
|
2265
|
-
function isWeappTailwindcssImportRequest$1(request) {
|
|
2266
|
-
return request === "weapp-tailwindcss" || request?.startsWith("weapp-tailwindcss/");
|
|
2267
|
-
}
|
|
2268
|
-
function isTailwindImportRequest$1(request) {
|
|
2269
|
-
return request === "tailwindcss" || request === "tailwindcss4" || request?.startsWith("tailwindcss/") || request?.startsWith("tailwindcss4/");
|
|
2270
|
-
}
|
|
2271
|
-
function normalizeTailwindImportRequest$1(request, options = {}) {
|
|
2272
|
-
if (options.importFallback && isWeappTailwindcssImportRequest$1(request)) return request.replace(/^weapp-tailwindcss/, "tailwindcss");
|
|
2273
|
-
return request;
|
|
2274
|
-
}
|
|
2275
|
-
function replaceImportRequest$1(params, request, replacement) {
|
|
2276
|
-
const index = params.indexOf(request);
|
|
2277
|
-
if (index === -1) return params;
|
|
2278
|
-
return `${params.slice(0, index)}${replacement}${params.slice(index + request.length)}`;
|
|
2279
|
-
}
|
|
2280
|
-
function normalizeTailwindDirectiveLine(line, options = {}) {
|
|
2281
|
-
const trimmed = line.trimStart();
|
|
2282
|
-
if (/^@(?:use|forward)\b/.test(trimmed)) {
|
|
2283
|
-
const request = parseImportRequest$1(trimmed.replace(/^@(?:use|forward)\b/, ""));
|
|
2284
|
-
if (isTailwindImportRequest$1(request) || options.importFallback && isWeappTailwindcssImportRequest$1(request)) {
|
|
2285
|
-
const normalizedRequest = normalizeTailwindImportRequest$1(request, options);
|
|
2286
|
-
return replaceImportRequest$1(line.replace(/^(\s*)@(?:use|forward)\b/, "$1@import"), request, normalizedRequest);
|
|
2287
|
-
}
|
|
2288
|
-
return line;
|
|
2289
|
-
}
|
|
2290
|
-
if (!options.importFallback || !trimmed.startsWith("@import")) return line;
|
|
2291
|
-
const request = parseImportRequest$1(trimmed.replace(/^@import\b/, ""));
|
|
2292
|
-
if (!request || !isWeappTailwindcssImportRequest$1(request)) return line;
|
|
2293
|
-
return replaceImportRequest$1(line, request, request.replace(/^weapp-tailwindcss/, "tailwindcss"));
|
|
2294
|
-
}
|
|
2295
|
-
function extractTailwindDirectiveLines(rawSource, options = {}) {
|
|
2296
|
-
const directives = [];
|
|
2297
|
-
const seenImports = /* @__PURE__ */ new Set();
|
|
2298
|
-
for (const line of stripGeneratorPlaceholderMarkers(rawSource).split(/\r?\n/)) {
|
|
2299
|
-
const trimmed = line.trim();
|
|
2300
|
-
if (!trimmed || trimmed.startsWith("//")) continue;
|
|
2301
|
-
const directive = TAILWIND_EXTRACTABLE_DIRECTIVE_RE.exec(line)?.[0] ?? TAILWIND_EXTRACTABLE_LAYER_STATEMENT_RE.exec(line)?.[0];
|
|
2302
|
-
if (!directive) continue;
|
|
2303
|
-
if (TAILWIND_EXTRACTABLE_BLOCK_START_RE.test(directive)) continue;
|
|
2304
|
-
const normalized = normalizeTailwindDirectiveLine(directive.trimEnd(), options);
|
|
2305
|
-
const normalizedTrimmed = normalized.trim();
|
|
2306
|
-
if (options.removeConfig && normalizedTrimmed.startsWith("@config")) continue;
|
|
2307
|
-
const request = /^@(?:import|use|forward)\b/.test(normalizedTrimmed) ? parseImportRequest$1(normalizedTrimmed.replace(/^@(?:import|use|forward)\b/, "")) : void 0;
|
|
2308
|
-
if (request && !isTailwindImportRequest$1(request) && !isPackageJsonImportRequest$1(request)) continue;
|
|
2309
|
-
if (/^@(?:import|use|forward)\b/.test(normalizedTrimmed) && !request) continue;
|
|
2310
|
-
if (request && isTailwindImportRequest$1(request)) {
|
|
2311
|
-
const key = normalizedTrimmed;
|
|
2312
|
-
if (seenImports.has(key)) continue;
|
|
2313
|
-
seenImports.add(key);
|
|
2314
|
-
}
|
|
2315
|
-
directives.push(normalized);
|
|
2316
|
-
}
|
|
2317
|
-
return directives;
|
|
2318
|
-
}
|
|
2319
|
-
function stripPreprocessorLineComment(line) {
|
|
2320
|
-
let quote;
|
|
2321
|
-
let escaped = false;
|
|
2322
|
-
for (let index = 0; index < line.length; index++) {
|
|
2323
|
-
const char = line[index];
|
|
2324
|
-
if (escaped) {
|
|
2325
|
-
escaped = false;
|
|
2326
|
-
continue;
|
|
2327
|
-
}
|
|
2328
|
-
if (char === "\\") {
|
|
2329
|
-
escaped = true;
|
|
2330
|
-
continue;
|
|
2331
|
-
}
|
|
2332
|
-
if (quote) {
|
|
2333
|
-
if (char === quote) quote = void 0;
|
|
2334
|
-
continue;
|
|
2335
|
-
}
|
|
2336
|
-
if (char === "\"" || char === "'") {
|
|
2337
|
-
quote = char;
|
|
2338
|
-
continue;
|
|
2339
|
-
}
|
|
2340
|
-
if (char === "/" && line[index + 1] === "/" && (index === 0 || /\s/.test(line[index - 1]))) return line.slice(0, index).trimEnd();
|
|
2341
|
-
}
|
|
2342
|
-
return line;
|
|
2343
|
-
}
|
|
2344
|
-
function countBlockBraceDelta(line) {
|
|
2345
|
-
let quote;
|
|
2346
|
-
let escaped = false;
|
|
2347
|
-
let delta = 0;
|
|
2348
|
-
for (let index = 0; index < line.length; index++) {
|
|
2349
|
-
const char = line[index];
|
|
2350
|
-
if (escaped) {
|
|
2351
|
-
escaped = false;
|
|
2352
|
-
continue;
|
|
2353
|
-
}
|
|
2354
|
-
if (char === "\\") {
|
|
2355
|
-
escaped = true;
|
|
2356
|
-
continue;
|
|
2357
|
-
}
|
|
2358
|
-
if (quote) {
|
|
2359
|
-
if (char === quote) quote = void 0;
|
|
2360
|
-
continue;
|
|
2361
|
-
}
|
|
2362
|
-
if (char === "\"" || char === "'") {
|
|
2363
|
-
quote = char;
|
|
2364
|
-
continue;
|
|
2365
|
-
}
|
|
2366
|
-
if (char === "{") delta++;
|
|
2367
|
-
else if (char === "}") delta--;
|
|
2368
|
-
}
|
|
2369
|
-
return delta;
|
|
2370
|
-
}
|
|
2371
|
-
function extractTailwindFallbackBlocks(rawSource) {
|
|
2372
|
-
const blocks = [];
|
|
2373
|
-
let current;
|
|
2374
|
-
let depth = 0;
|
|
2375
|
-
for (const rawLine of stripGeneratorPlaceholderMarkers(rawSource).split(/\r?\n/)) {
|
|
2376
|
-
const line = stripPreprocessorLineComment(rawLine);
|
|
2377
|
-
if (!line.trim()) continue;
|
|
2378
|
-
if (!current) {
|
|
2379
|
-
if (!TAILWIND_EXTRACTABLE_BLOCK_START_RE.test(line)) continue;
|
|
2380
|
-
current = [line];
|
|
2381
|
-
depth = countBlockBraceDelta(line);
|
|
2382
|
-
if (depth <= 0) {
|
|
2383
|
-
blocks.push(current.join("\n"));
|
|
2384
|
-
current = void 0;
|
|
2385
|
-
depth = 0;
|
|
2386
|
-
}
|
|
2387
|
-
continue;
|
|
2388
|
-
}
|
|
2389
|
-
current.push(line);
|
|
2390
|
-
depth += countBlockBraceDelta(line);
|
|
2391
|
-
if (depth <= 0) {
|
|
2392
|
-
blocks.push(current.join("\n"));
|
|
2393
|
-
current = void 0;
|
|
2394
|
-
depth = 0;
|
|
2395
|
-
}
|
|
2396
|
-
}
|
|
2397
|
-
return blocks;
|
|
2398
|
-
}
|
|
2399
|
-
function extractTailwindSourceForPostcssFallback(rawSource, options = {}) {
|
|
2400
|
-
const directives = [...extractTailwindDirectiveLines(rawSource, options), ...extractTailwindFallbackBlocks(rawSource)];
|
|
2401
|
-
return directives.length > 0 ? directives.join("\n") : void 0;
|
|
2402
|
-
}
|
|
2403
|
-
function extractConfigRequestFromSource(rawSource) {
|
|
2404
|
-
for (const line of rawSource.split(/\r?\n/)) {
|
|
2405
|
-
const match = /^\s*@config\b([\s\S]*?)(?:;|$)/.exec(line);
|
|
2406
|
-
const request = match ? parseConfigRequest$1(match[1] ?? "") : void 0;
|
|
2407
|
-
if (request) return request;
|
|
2408
|
-
}
|
|
2409
|
-
}
|
|
2410
|
-
//#endregion
|
|
2411
|
-
//#region src/bundlers/shared/generator-css/directives.ts
|
|
2412
|
-
const TAILWIND_REMOVABLE_SOURCE_DIRECTIVE_NAMES = new Set([
|
|
2413
|
-
"config",
|
|
2414
|
-
"custom-variant",
|
|
2415
|
-
"layer",
|
|
2416
|
-
"plugin",
|
|
2417
|
-
"reference",
|
|
2418
|
-
"source",
|
|
2419
|
-
"tailwind",
|
|
2420
|
-
"theme",
|
|
2421
|
-
"utility",
|
|
2422
|
-
"variant"
|
|
2423
|
-
]);
|
|
2424
|
-
const TAILWIND_ROOT_DIRECTIVE_NAMES = new Set([
|
|
2425
|
-
"config",
|
|
2426
|
-
"custom-variant",
|
|
2427
|
-
"plugin",
|
|
2428
|
-
"source",
|
|
2429
|
-
"tailwind",
|
|
2430
|
-
"theme",
|
|
2431
|
-
"utility",
|
|
2432
|
-
"variant"
|
|
2433
|
-
]);
|
|
2434
|
-
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/;
|
|
2435
|
-
const TAILWIND_V3_SUBPATH_IMPORT_LAYERS = new Map([
|
|
2436
|
-
["tailwindcss/base", "base"],
|
|
2437
|
-
["tailwindcss/components", "components"],
|
|
2438
|
-
["tailwindcss/utilities", "utilities"]
|
|
2439
|
-
]);
|
|
2440
|
-
function parseImportRequest(params) {
|
|
2441
|
-
return /^(?:url\(\s*)?(["']?)([^"')\s]+)\1\s*\)?/.exec(params.trim())?.[2];
|
|
2442
|
-
}
|
|
2443
|
-
function hasLocalCssImport(rawSource) {
|
|
2444
|
-
let found = false;
|
|
2445
|
-
try {
|
|
2446
|
-
postcss.parse(rawSource).walkAtRules("import", (rule) => {
|
|
2447
|
-
const request = parseImportRequest(rule.params);
|
|
2448
|
-
if (request?.startsWith(".") === true || request?.startsWith("/") === true) {
|
|
2449
|
-
found = true;
|
|
2450
|
-
return false;
|
|
2451
|
-
}
|
|
2452
|
-
});
|
|
2453
|
-
} catch {}
|
|
2454
|
-
return found;
|
|
2455
|
-
}
|
|
2456
|
-
function parseConfigRequest(params) {
|
|
2457
|
-
return /^(["'])(.+)\1\s*;?$/.exec(params.trim())?.[2];
|
|
2458
|
-
}
|
|
2459
|
-
function isPackageJsonImportRequest(request) {
|
|
2460
|
-
return typeof request === "string" && request.startsWith("#");
|
|
2461
|
-
}
|
|
2462
|
-
function isWeappTailwindcssImportRequest(request) {
|
|
2463
|
-
return request === "weapp-tailwindcss" || request?.startsWith("weapp-tailwindcss/");
|
|
2464
|
-
}
|
|
2465
|
-
function normalizeTailwindImportRequest(request, options = {}) {
|
|
2466
|
-
if (options.importFallback && isWeappTailwindcssImportRequest(request)) return request.replace(/^weapp-tailwindcss/, "tailwindcss");
|
|
2467
|
-
return request;
|
|
2468
|
-
}
|
|
2469
|
-
function replaceImportRequest(params, request, replacement) {
|
|
2470
|
-
const index = params.indexOf(request);
|
|
2471
|
-
if (index === -1) return params;
|
|
2472
|
-
return `${params.slice(0, index)}${replacement}${params.slice(index + request.length)}`;
|
|
2473
|
-
}
|
|
2474
|
-
function normalizeTailwindImportAtRules(root, options = {}) {
|
|
2475
|
-
if (!options.importFallback) return false;
|
|
2476
|
-
let changed = false;
|
|
2477
|
-
const seenCanonicalImports = /* @__PURE__ */ new Set();
|
|
2478
|
-
root.walkAtRules("import", (node) => {
|
|
2479
|
-
const request = parseImportRequest(node.params);
|
|
2480
|
-
const normalizedRequest = normalizeTailwindImportRequest(request, options);
|
|
2481
|
-
if (!normalizedRequest || !isTailwindImportRequest(normalizedRequest)) return;
|
|
2482
|
-
const normalizedParams = request && normalizedRequest !== request ? replaceImportRequest(node.params, request, normalizedRequest) : node.params;
|
|
2483
|
-
const normalizedKey = normalizedParams.trim();
|
|
2484
|
-
if (seenCanonicalImports.has(normalizedKey)) {
|
|
2485
|
-
node.remove();
|
|
2486
|
-
changed = true;
|
|
2487
|
-
return;
|
|
2488
|
-
}
|
|
2489
|
-
seenCanonicalImports.add(normalizedKey);
|
|
2490
|
-
if (normalizedParams !== node.params) {
|
|
2491
|
-
node.params = normalizedParams;
|
|
2492
|
-
changed = true;
|
|
2493
|
-
}
|
|
2494
|
-
});
|
|
2495
|
-
return changed;
|
|
2496
|
-
}
|
|
2497
|
-
function resolveConfigPath$1(base, configPath) {
|
|
2498
|
-
if (path.isAbsolute(configPath) || isPackageJsonImportRequest(configPath)) return path.isAbsolute(configPath) ? configPath : void 0;
|
|
2499
|
-
return path.resolve(base, configPath);
|
|
2500
|
-
}
|
|
2501
|
-
function normalizeTailwindConfigDirectives(rawSource, base) {
|
|
2502
|
-
return rawSource.replace(/@config\s+(["'])(.+?)\1\s*;?/g, (full, quote, request) => {
|
|
2503
|
-
if (path.isAbsolute(request) || isPackageJsonImportRequest(request)) return full;
|
|
2504
|
-
return `@config ${quote}${path.resolve(base, request).replace(/\\/g, "/")}${quote};`;
|
|
2505
|
-
});
|
|
2506
|
-
}
|
|
2507
|
-
function hasPreprocessorOnlySyntax(rawSource) {
|
|
2508
|
-
return /(?:^|\n)\s*(?:\/\/|\$[\w-]+\s*:|@[\w-]+\s*:|@(?:mixin|include|function|use|forward)\b)/.test(rawSource);
|
|
2509
|
-
}
|
|
2510
|
-
function normalizeTailwindSourceForGenerator(rawSource, options = {}) {
|
|
2511
|
-
return hasPreprocessorOnlySyntax(rawSource) ? extractTailwindSourceForPostcssFallback(rawSource, options) ?? rawSource : rawSource;
|
|
2512
|
-
}
|
|
2513
|
-
function normalizeTailwindV3CssEntrySource(rawSource) {
|
|
2514
|
-
try {
|
|
2515
|
-
const root = postcss.parse(rawSource);
|
|
2516
|
-
let changed = false;
|
|
2517
|
-
root.walkAtRules("import", (node) => {
|
|
2518
|
-
const layer = TAILWIND_V3_SUBPATH_IMPORT_LAYERS.get(parseImportRequest(node.params) ?? "");
|
|
2519
|
-
if (!layer) return;
|
|
2520
|
-
node.replaceWith(postcss.atRule({
|
|
2521
|
-
name: "tailwind",
|
|
2522
|
-
params: layer
|
|
2523
|
-
}));
|
|
2524
|
-
changed = true;
|
|
2525
|
-
});
|
|
2526
|
-
return changed ? root.toString() : rawSource;
|
|
2527
|
-
} catch {
|
|
2528
|
-
return rawSource;
|
|
2529
|
-
}
|
|
2530
|
-
}
|
|
2531
|
-
function normalizeTailwindSourceDirectives(rawSource, options = {}) {
|
|
2532
|
-
if (!options.importFallback) return rawSource;
|
|
2533
|
-
try {
|
|
2534
|
-
const root = postcss.parse(rawSource);
|
|
2535
|
-
return normalizeTailwindImportAtRules(root, options) ? root.toString() : rawSource;
|
|
2536
|
-
} catch {
|
|
2537
|
-
return extractTailwindSourceForPostcssFallback(rawSource, options) ?? rawSource;
|
|
2538
|
-
}
|
|
2539
|
-
}
|
|
2540
|
-
function isTailwindImportRequest(request) {
|
|
2541
|
-
return request === "tailwindcss" || request === "tailwindcss4" || request?.startsWith("tailwindcss/") || request?.startsWith("tailwindcss4/");
|
|
2542
|
-
}
|
|
2543
|
-
function isTailwindImportAtRule(node, options = {}) {
|
|
2544
|
-
if (node.name === "tailwind") return true;
|
|
2545
|
-
if (node.name !== "import" && node.name !== "use" && node.name !== "forward") return false;
|
|
2546
|
-
return isTailwindImportRequest(normalizeTailwindImportRequest(parseImportRequest(node.params), options));
|
|
2547
|
-
}
|
|
2548
|
-
function isTailwindSourceDirective(node, options = {}) {
|
|
2549
|
-
if (node.type !== "atrule") return false;
|
|
2550
|
-
const atRule = node;
|
|
2551
|
-
if (isTailwindImportAtRule(atRule, options)) return true;
|
|
2552
|
-
if (atRule.name === "import" && isPackageJsonImportRequest(parseImportRequest(atRule.params))) return true;
|
|
2553
|
-
if (atRule.name === "layer") return !atRule.nodes || atRule.nodes.length === 0;
|
|
2554
|
-
return TAILWIND_REMOVABLE_SOURCE_DIRECTIVE_NAMES.has(atRule.name);
|
|
2555
|
-
}
|
|
2556
|
-
function hasGeneratedCssArtifacts(rawSource) {
|
|
2557
|
-
return hasTailwindGeneratedCssMarkers(rawSource) && !GENERATOR_PLACEHOLDER_MARKER_RE.test(rawSource);
|
|
2558
|
-
}
|
|
2559
|
-
function isTailwindGenerationDirective(node, options = {}) {
|
|
2560
|
-
if (node.type !== "atrule") return false;
|
|
2561
|
-
const atRule = node;
|
|
2562
|
-
const request = atRule.name === "import" ? parseImportRequest(atRule.params) : atRule.name === "config" || atRule.name === "plugin" || atRule.name === "reference" ? parseConfigRequest(atRule.params) : void 0;
|
|
2563
|
-
return isTailwindImportAtRule(atRule, options) || isPackageJsonImportRequest(request) || atRule.name === "apply" || !options.ignoreLayer && atRule.name === "layer" || atRule.name === "config" || atRule.name === "source";
|
|
2564
|
-
}
|
|
2565
|
-
function removeTailwindSourceDirectives(rawSource, options = {}) {
|
|
2566
|
-
try {
|
|
2567
|
-
const source = hasPreprocessorOnlySyntax(rawSource) ? extractTailwindSourceForPostcssFallback(rawSource, options) : stripGeneratorPlaceholderMarkers(rawSource);
|
|
2568
|
-
if (!source) return "";
|
|
2569
|
-
const root = postcss.parse(source);
|
|
2570
|
-
let removed = false;
|
|
2571
|
-
root.walk((node) => {
|
|
2572
|
-
if (isTailwindSourceDirective(node, options)) {
|
|
2573
|
-
node.remove();
|
|
2574
|
-
removed = true;
|
|
2575
|
-
}
|
|
2576
|
-
});
|
|
2577
|
-
return removed ? root.toString() : source;
|
|
2578
|
-
} catch {
|
|
2579
|
-
return stripGeneratorPlaceholderMarkers(rawSource);
|
|
2580
|
-
}
|
|
2581
|
-
}
|
|
2582
|
-
function hasTailwindSourceDirectives(rawSource, options = {}) {
|
|
2583
|
-
try {
|
|
2584
|
-
if (GENERATOR_PLACEHOLDER_MARKER_RE.test(rawSource)) return true;
|
|
2585
|
-
const root = postcss.parse(rawSource);
|
|
2586
|
-
let found = false;
|
|
2587
|
-
const ignoreLayer = hasGeneratedCssArtifacts(rawSource);
|
|
2588
|
-
root.walk((node) => {
|
|
2589
|
-
if (isTailwindGenerationDirective(node, {
|
|
2590
|
-
...options,
|
|
2591
|
-
ignoreLayer
|
|
2592
|
-
})) {
|
|
2593
|
-
found = true;
|
|
2594
|
-
return false;
|
|
2595
|
-
}
|
|
2596
|
-
});
|
|
2597
|
-
return found;
|
|
2598
|
-
} catch {
|
|
2599
|
-
return extractTailwindDirectiveLines(rawSource, options).length > 0;
|
|
2600
|
-
}
|
|
2601
|
-
}
|
|
2602
|
-
function hasTailwindRootDirectives(rawSource, options = {}) {
|
|
2603
|
-
if (!TAILWIND_ROOT_DIRECTIVE_RE.test(rawSource) && !(options.importFallback && rawSource.includes("weapp-tailwindcss"))) return false;
|
|
2604
|
-
try {
|
|
2605
|
-
const root = postcss.parse(rawSource);
|
|
2606
|
-
let found = false;
|
|
2607
|
-
root.walkAtRules((node) => {
|
|
2608
|
-
const request = node.name === "import" ? parseImportRequest(node.params) : node.name === "config" || node.name === "plugin" ? parseConfigRequest(node.params) : void 0;
|
|
2609
|
-
if (isTailwindImportAtRule(node, options) || isPackageJsonImportRequest(request) || TAILWIND_ROOT_DIRECTIVE_NAMES.has(node.name)) {
|
|
2610
|
-
found = true;
|
|
2611
|
-
return false;
|
|
2612
|
-
}
|
|
2613
|
-
});
|
|
2614
|
-
return found;
|
|
2615
|
-
} catch {
|
|
2616
|
-
return extractTailwindDirectiveLines(rawSource, options).length > 0;
|
|
2617
|
-
}
|
|
2618
|
-
}
|
|
2619
|
-
function hasTailwindApplyDirective(rawSource) {
|
|
2620
|
-
if (!rawSource.includes("@apply")) return false;
|
|
2621
|
-
try {
|
|
2622
|
-
const root = postcss.parse(rawSource);
|
|
2623
|
-
let found = false;
|
|
2624
|
-
root.walkAtRules("apply", () => {
|
|
2625
|
-
found = true;
|
|
2626
|
-
return false;
|
|
2627
|
-
});
|
|
2628
|
-
return found;
|
|
2629
|
-
} catch {
|
|
2630
|
-
return false;
|
|
2631
|
-
}
|
|
2632
|
-
}
|
|
2633
|
-
function resolveCssEntrySource(rawSource, base, options = {}) {
|
|
2634
|
-
try {
|
|
2635
|
-
const root = postcss.parse(rawSource);
|
|
2636
|
-
const normalizedImports = normalizeTailwindImportAtRules(root, options);
|
|
2637
|
-
let found = false;
|
|
2638
|
-
let config;
|
|
2639
|
-
let configRequest;
|
|
2640
|
-
let removedConfig = false;
|
|
2641
|
-
const removeConfig = options.removeConfig ?? true;
|
|
2642
|
-
const ignoreLayer = hasGeneratedCssArtifacts(rawSource);
|
|
2643
|
-
root.walk((node) => {
|
|
2644
|
-
if (isTailwindGenerationDirective(node, {
|
|
2645
|
-
...options,
|
|
2646
|
-
ignoreLayer
|
|
2647
|
-
})) found = true;
|
|
2648
|
-
if (node.type === "atrule" && node.name === "config") {
|
|
2649
|
-
const configPath = parseConfigRequest(node.params);
|
|
2650
|
-
if (configPath && !config) {
|
|
2651
|
-
configRequest = configPath;
|
|
2652
|
-
config = resolveConfigPath$1(base, configPath);
|
|
2653
|
-
}
|
|
2654
|
-
if (removeConfig) {
|
|
2655
|
-
node.remove();
|
|
2656
|
-
removedConfig = true;
|
|
2657
|
-
}
|
|
2658
|
-
}
|
|
2659
|
-
});
|
|
2660
|
-
if (!found) return;
|
|
2661
|
-
if (hasPreprocessorOnlySyntax(rawSource)) {
|
|
2662
|
-
const css = extractTailwindSourceForPostcssFallback(rawSource, {
|
|
2663
|
-
...options,
|
|
2664
|
-
removeConfig
|
|
2665
|
-
});
|
|
2666
|
-
if (css) return {
|
|
2667
|
-
css,
|
|
2668
|
-
config,
|
|
2669
|
-
configRequest,
|
|
2670
|
-
base
|
|
2671
|
-
};
|
|
2672
|
-
}
|
|
2673
|
-
return {
|
|
2674
|
-
css: removedConfig || normalizedImports ? root.toString() : rawSource,
|
|
2675
|
-
config,
|
|
2676
|
-
configRequest,
|
|
2677
|
-
base
|
|
2678
|
-
};
|
|
2679
|
-
} catch {
|
|
2680
|
-
const css = extractTailwindSourceForPostcssFallback(rawSource, options);
|
|
2681
|
-
const configRequest = extractConfigRequestFromSource(rawSource);
|
|
2682
|
-
const config = configRequest ? resolveConfigPath$1(base, configRequest) : void 0;
|
|
2683
|
-
return css ? {
|
|
2684
|
-
css,
|
|
2685
|
-
config,
|
|
2686
|
-
configRequest,
|
|
2687
|
-
base
|
|
2688
|
-
} : void 0;
|
|
2689
|
-
}
|
|
2690
|
-
}
|
|
2691
|
-
//#endregion
|
|
2692
|
-
//#region src/tailwindcss/v4-engine/source.ts
|
|
2693
|
-
const require$1 = createRequire(import.meta.url);
|
|
2694
|
-
function isCssEntryPoint(file) {
|
|
2695
|
-
return typeof file === "string" && path.basename(file) === "index.css" && existsSync(file);
|
|
2696
|
-
}
|
|
2697
|
-
function resolvePackageCssEntryPoint(specifier) {
|
|
2698
|
-
try {
|
|
2699
|
-
const resolved = require$1.resolve(specifier);
|
|
2700
|
-
if (isCssEntryPoint(resolved)) return resolved;
|
|
2701
|
-
} catch {}
|
|
2702
|
-
const packageName = specifier.replace(/\/index\.css$/, "");
|
|
2703
|
-
if (packageName !== "tailwindcss") return;
|
|
2704
|
-
try {
|
|
2705
|
-
const packageJson = require$1.resolve(`${packageName}/package.json`);
|
|
2706
|
-
const cssEntry = path.resolve(path.dirname(packageJson), "index.css");
|
|
2707
|
-
if (isCssEntryPoint(cssEntry)) return cssEntry;
|
|
2708
|
-
} catch {}
|
|
2709
|
-
try {
|
|
2710
|
-
let current = path.dirname(require$1.resolve("tailwindcss-patch"));
|
|
2711
|
-
while (true) {
|
|
2712
|
-
const cssEntry = path.resolve(current, "..", "tailwindcss", "index.css");
|
|
2713
|
-
if (isCssEntryPoint(cssEntry)) return cssEntry;
|
|
2714
|
-
const parent = path.dirname(current);
|
|
2715
|
-
if (parent === current) break;
|
|
2716
|
-
current = parent;
|
|
2717
|
-
}
|
|
2718
|
-
} catch {}
|
|
2719
|
-
}
|
|
2720
|
-
function isPostcssPluginImportTarget(value) {
|
|
2721
|
-
if (!value) return false;
|
|
2722
|
-
return value === "@tailwindcss/postcss" || value.includes("/postcss");
|
|
2723
|
-
}
|
|
2724
|
-
function uniqueDefined(values) {
|
|
2725
|
-
return [...new Set(values.filter((value) => typeof value === "string" && value.length > 0))];
|
|
2726
|
-
}
|
|
2727
|
-
function getProjectRoot$1(patcher) {
|
|
2728
|
-
return patcher.options?.projectRoot ?? process.cwd();
|
|
2729
|
-
}
|
|
2730
|
-
function resolveBase(value, fallback) {
|
|
2731
|
-
return value === void 0 ? fallback : path.isAbsolute(value) ? path.resolve(value) : path.resolve(fallback, value);
|
|
2732
|
-
}
|
|
2733
|
-
function resolveConfigDir(config, projectRoot) {
|
|
2734
|
-
if (!config) return;
|
|
2735
|
-
const configPath = path.isAbsolute(config) ? config : path.resolve(projectRoot, config);
|
|
2736
|
-
return path.dirname(configPath);
|
|
2737
|
-
}
|
|
2738
|
-
function isBarePackageSpecifier(specifier) {
|
|
2739
|
-
return !specifier.startsWith(".") && !specifier.startsWith("/") && !specifier.startsWith("#") && !specifier.includes("\\") && !/^[a-z][a-z\d+.-]*:/i.test(specifier);
|
|
2740
|
-
}
|
|
2741
|
-
function isPackageJsonImportSpecifier(specifier) {
|
|
2742
|
-
return typeof specifier === "string" && specifier.startsWith("#");
|
|
2743
|
-
}
|
|
2744
|
-
function parseCssImportSpecifier$1(params) {
|
|
2745
|
-
const value = params.trim();
|
|
2746
|
-
const quoted = /^(['"])(.*?)\1/.exec(value);
|
|
2747
|
-
if (quoted) {
|
|
2748
|
-
const specifier = quoted[2];
|
|
2749
|
-
if (specifier === void 0) return;
|
|
2750
|
-
return {
|
|
2751
|
-
quote: quoted[1],
|
|
2752
|
-
raw: quoted[0],
|
|
2753
|
-
specifier
|
|
2754
|
-
};
|
|
2755
|
-
}
|
|
2756
|
-
const url = /^url\(\s*(?:(['"])(.*?)\1|([^'")\s]+))\s*\)/.exec(value);
|
|
2757
|
-
if (!url) return;
|
|
2758
|
-
const specifier = url[2] ?? url[3];
|
|
2759
|
-
if (specifier === void 0) return;
|
|
2760
|
-
return {
|
|
2761
|
-
quote: url[1],
|
|
2762
|
-
raw: url[0],
|
|
2763
|
-
specifier
|
|
2764
|
-
};
|
|
2765
|
-
}
|
|
2766
|
-
function quoteCssImportSpecifier(specifier, quote = "\"") {
|
|
2767
|
-
return `${quote}${specifier.replaceAll("\\", "\\\\").replaceAll(quote, `\\${quote}`)}${quote}`;
|
|
2768
|
-
}
|
|
2769
|
-
function createTailwindV4CssImportSpecifierSet(packageName) {
|
|
2770
|
-
const specifiers = new Set(["tailwindcss"]);
|
|
2771
|
-
if (packageName && isBarePackageSpecifier(packageName)) specifiers.add(packageName);
|
|
2772
|
-
return specifiers;
|
|
2773
|
-
}
|
|
2774
|
-
function normalizeTailwindV4CssPackageImports(css, packageName) {
|
|
2775
|
-
if (!css.includes("tailwindcss")) return css;
|
|
2776
|
-
let root;
|
|
2777
|
-
try {
|
|
2778
|
-
root = postcss.parse(css);
|
|
2779
|
-
} catch {
|
|
2780
|
-
return css;
|
|
2781
|
-
}
|
|
2782
|
-
const importSpecifiers = createTailwindV4CssImportSpecifierSet(packageName);
|
|
2783
|
-
let changed = false;
|
|
2784
|
-
root.walkAtRules((rule) => {
|
|
2785
|
-
if (rule.name !== "import" && rule.name !== "reference") return;
|
|
2786
|
-
const parsed = parseCssImportSpecifier$1(rule.params);
|
|
2787
|
-
if (!parsed || !importSpecifiers.has(parsed.specifier)) return;
|
|
2788
|
-
const cssEntryPoint = resolvePackageCssEntryPoint(`${parsed.specifier}/index.css`);
|
|
2789
|
-
if (!cssEntryPoint) return;
|
|
2790
|
-
rule.params = rule.params.replace(parsed.raw, quoteCssImportSpecifier(cssEntryPoint, parsed.quote));
|
|
2791
|
-
changed = true;
|
|
2792
|
-
});
|
|
2793
|
-
return changed ? root.toString() : css;
|
|
2794
|
-
}
|
|
2795
|
-
function normalizeTailwindV4CssSources(cssSources, packageName) {
|
|
2796
|
-
if (!cssSources?.length) return cssSources;
|
|
2797
|
-
let changed = false;
|
|
2798
|
-
const normalizedCssSources = cssSources.map((cssSource) => {
|
|
2799
|
-
if (typeof cssSource.css !== "string") return cssSource;
|
|
2800
|
-
const css = normalizeTailwindV4CssPackageImports(cssSource.css, packageName);
|
|
2801
|
-
if (css === cssSource.css) return cssSource;
|
|
2802
|
-
changed = true;
|
|
2803
|
-
return {
|
|
2804
|
-
...cssSource,
|
|
2805
|
-
css
|
|
2806
|
-
};
|
|
2807
|
-
});
|
|
2808
|
-
return changed ? normalizedCssSources : cssSources;
|
|
2809
|
-
}
|
|
2810
|
-
function normalizeTailwindV4CssEntrySources(cssEntries, packageName) {
|
|
2811
|
-
if (!cssEntries?.length) return;
|
|
2812
|
-
const remainingCssEntries = [];
|
|
2813
|
-
const cssSources = [];
|
|
2814
|
-
for (const cssEntry of cssEntries) {
|
|
2815
|
-
const file = path.resolve(cssEntry);
|
|
2816
|
-
if (!existsSync(file)) {
|
|
2817
|
-
remainingCssEntries.push(cssEntry);
|
|
2818
|
-
continue;
|
|
2819
|
-
}
|
|
2820
|
-
const base = path.dirname(file);
|
|
2821
|
-
const rawCss = readFileSync(file, "utf8");
|
|
2822
|
-
const entrySource = resolveCssEntrySource(rawCss, base, { removeConfig: false });
|
|
2823
|
-
const css = normalizeTailwindV4CssPackageImports(normalizeConfigDirective(rawCss, entrySource?.config && existsSync(entrySource.config) ? entrySource.config : entrySource?.configRequest && !path.isAbsolute(entrySource.configRequest) && !isPackageJsonImportSpecifier(entrySource.configRequest) ? path.resolve(base, entrySource.configRequest) : entrySource?.config), packageName);
|
|
2824
|
-
cssSources.push({
|
|
2825
|
-
file,
|
|
2826
|
-
base,
|
|
2827
|
-
css,
|
|
2828
|
-
dependencies: [file]
|
|
2829
|
-
});
|
|
2830
|
-
}
|
|
2831
|
-
return {
|
|
2832
|
-
cssEntries: remainingCssEntries,
|
|
2833
|
-
cssSources
|
|
2834
|
-
};
|
|
2835
|
-
}
|
|
2836
|
-
function normalizeTailwindV4SourceOptions(options) {
|
|
2837
|
-
if (!options) return options;
|
|
2838
|
-
const css = options.css === void 0 ? void 0 : normalizeTailwindV4CssPackageImports(options.css, options.packageName);
|
|
2839
|
-
const entrySources = normalizeTailwindV4CssEntrySources(options.cssEntries, options.packageName);
|
|
2840
|
-
const cssSources = normalizeTailwindV4CssSources(options.cssSources || entrySources?.cssSources ? [...options.cssSources ?? [], ...entrySources?.cssSources ?? []] : void 0, options.packageName);
|
|
2841
|
-
const cssEntries = entrySources?.cssEntries ?? options.cssEntries;
|
|
2842
|
-
if (css === options.css && cssSources === options.cssSources && cssEntries === options.cssEntries) return options;
|
|
2843
|
-
return {
|
|
2844
|
-
...options,
|
|
2845
|
-
...css === void 0 ? {} : { css },
|
|
2846
|
-
...cssEntries === void 0 ? {} : { cssEntries },
|
|
2847
|
-
...cssSources === void 0 ? {} : { cssSources }
|
|
2848
|
-
};
|
|
2849
|
-
}
|
|
2850
|
-
function resolveTailwindCssImportTarget(patcher) {
|
|
2851
|
-
const configuredPackageName = resolveTailwindcssOptions(patcher.options)?.packageName;
|
|
2852
|
-
if (typeof configuredPackageName === "string" && configuredPackageName.length > 0 && !isPostcssPluginImportTarget(configuredPackageName)) return configuredPackageName;
|
|
2853
|
-
const packageName = patcher.packageInfo?.name;
|
|
2854
|
-
if (typeof packageName === "string" && packageName.length > 0 && !isPostcssPluginImportTarget(packageName)) return packageName;
|
|
2855
|
-
return "tailwindcss";
|
|
2856
|
-
}
|
|
2857
|
-
function readTailwindV4Options(patcher) {
|
|
2858
|
-
return resolveTailwindcssOptions(patcher.options)?.v4 ?? patcher.options?.tailwind?.v4;
|
|
2859
|
-
}
|
|
2860
|
-
function isRawTailwindcssPatchOptions(options) {
|
|
2861
|
-
return Boolean(options && "tailwindcss" in options);
|
|
2862
|
-
}
|
|
2863
|
-
function resolvePatchTailwindV4SourceOptions(patcher) {
|
|
2864
|
-
if (patcher.options) {
|
|
2865
|
-
const projectRoot = getProjectRoot$1(patcher);
|
|
2866
|
-
const tailwindOptions = resolveTailwindcssOptions(patcher.options);
|
|
2867
|
-
const tailwindV4Options = readTailwindV4Options(patcher);
|
|
2868
|
-
const cwd = resolveBase(tailwindOptions?.cwd, projectRoot);
|
|
2869
|
-
const configuredBase = tailwindV4Options?.configuredBase ?? (isRawTailwindcssPatchOptions(patcher.options) ? tailwindV4Options?.base : void 0);
|
|
2870
|
-
const baseFallbacks = uniqueDefined([
|
|
2871
|
-
configuredBase,
|
|
2872
|
-
cwd,
|
|
2873
|
-
projectRoot,
|
|
2874
|
-
resolveConfigDir(tailwindOptions?.config, projectRoot)
|
|
2875
|
-
]);
|
|
2876
|
-
return {
|
|
2877
|
-
projectRoot,
|
|
2878
|
-
cwd,
|
|
2879
|
-
...configuredBase === void 0 ? {} : { base: configuredBase },
|
|
2880
|
-
baseFallbacks,
|
|
2881
|
-
...tailwindV4Options?.css === void 0 ? {} : { css: tailwindV4Options.css },
|
|
2882
|
-
...tailwindV4Options?.cssSources === void 0 ? {} : { cssSources: tailwindV4Options.cssSources },
|
|
2883
|
-
...tailwindV4Options?.cssEntries === void 0 ? {} : { cssEntries: tailwindV4Options.cssEntries },
|
|
2884
|
-
packageName: resolveTailwindCssImportTarget(patcher)
|
|
2885
|
-
};
|
|
2886
|
-
}
|
|
2887
|
-
return {
|
|
2888
|
-
projectRoot: getProjectRoot$1(patcher),
|
|
2889
|
-
packageName: resolveTailwindCssImportTarget(patcher)
|
|
2890
|
-
};
|
|
2891
|
-
}
|
|
2892
|
-
function resolveTailwindV4SourceOptionsFromPatcher(patcher) {
|
|
2893
|
-
const tailwindV4Options = readTailwindV4Options(patcher);
|
|
2894
|
-
return omitUndefined({
|
|
2895
|
-
...resolvePatchTailwindV4SourceOptions(patcher),
|
|
2896
|
-
sources: tailwindV4Options?.sources
|
|
2897
|
-
});
|
|
2898
|
-
}
|
|
2899
|
-
function resolveTailwindV4Source$1(options) {
|
|
2900
|
-
return resolveTailwindV4Source(normalizeTailwindV4SourceOptions(options));
|
|
2901
|
-
}
|
|
2902
|
-
async function resolveTailwindV4SourceFromPatcher(patcher) {
|
|
2903
|
-
return resolveTailwindV4Source$1(resolveTailwindV4SourceOptionsFromPatcher(patcher));
|
|
2904
|
-
}
|
|
2905
|
-
//#endregion
|
|
2906
|
-
//#region src/bundlers/vite/static-config-content.ts
|
|
2907
|
-
function skipWhitespaceAndComments(source, start) {
|
|
2908
|
-
let index = start;
|
|
2909
|
-
while (index < source.length) {
|
|
2910
|
-
const char = source[index];
|
|
2911
|
-
if (/\s/.test(char ?? "")) {
|
|
2912
|
-
index += 1;
|
|
2913
|
-
continue;
|
|
2914
|
-
}
|
|
2915
|
-
if (char === "/" && source[index + 1] === "/") {
|
|
2916
|
-
index += 2;
|
|
2917
|
-
while (index < source.length && source[index] !== "\n") index += 1;
|
|
2918
|
-
continue;
|
|
2919
|
-
}
|
|
2920
|
-
if (char === "/" && source[index + 1] === "*") {
|
|
2921
|
-
index += 2;
|
|
2922
|
-
while (index < source.length && !(source[index] === "*" && source[index + 1] === "/")) index += 1;
|
|
2923
|
-
index = Math.min(index + 2, source.length);
|
|
2924
|
-
continue;
|
|
2925
|
-
}
|
|
2926
|
-
break;
|
|
2927
|
-
}
|
|
2928
|
-
return index;
|
|
2929
|
-
}
|
|
2930
|
-
function readQuotedString(source, start) {
|
|
2931
|
-
const quote = source[start];
|
|
2932
|
-
if (quote !== "\"" && quote !== "'") return;
|
|
2933
|
-
let value = "";
|
|
2934
|
-
for (let index = start + 1; index < source.length; index++) {
|
|
2935
|
-
const char = source[index];
|
|
2936
|
-
if (char === "\\") {
|
|
2937
|
-
const next = source[index + 1];
|
|
2938
|
-
if (next === void 0) return;
|
|
2939
|
-
value += next;
|
|
2940
|
-
index += 1;
|
|
2941
|
-
continue;
|
|
2942
|
-
}
|
|
2943
|
-
if (char === quote) return {
|
|
2944
|
-
end: index + 1,
|
|
2945
|
-
value
|
|
2946
|
-
};
|
|
2947
|
-
value += char;
|
|
2948
|
-
}
|
|
2949
|
-
}
|
|
2950
|
-
function readIdentifier(source, start) {
|
|
2951
|
-
return /^[A-Z_$][\w$]*/i.exec(source.slice(start))?.[0];
|
|
2952
|
-
}
|
|
2953
|
-
function findMatchingBracket(source, start, open, close) {
|
|
2954
|
-
let depth = 0;
|
|
2955
|
-
let quote;
|
|
2956
|
-
for (let index = start; index < source.length; index++) {
|
|
2957
|
-
const char = source[index];
|
|
2958
|
-
if (char === "\\") {
|
|
2959
|
-
index += 1;
|
|
2960
|
-
continue;
|
|
2961
|
-
}
|
|
2962
|
-
if (quote) {
|
|
2963
|
-
if (char === quote) quote = void 0;
|
|
2964
|
-
continue;
|
|
2965
|
-
}
|
|
2966
|
-
if (char === "\"" || char === "'") {
|
|
2967
|
-
quote = char;
|
|
2968
|
-
continue;
|
|
2969
|
-
}
|
|
2970
|
-
if (char === "`") return;
|
|
2971
|
-
if (char === open) {
|
|
2972
|
-
depth += 1;
|
|
2973
|
-
continue;
|
|
2974
|
-
}
|
|
2975
|
-
if (char === close) {
|
|
2976
|
-
depth -= 1;
|
|
2977
|
-
if (depth === 0) return index;
|
|
2978
|
-
}
|
|
2979
|
-
}
|
|
2980
|
-
}
|
|
2981
|
-
function findContentPropertyValue(source) {
|
|
2982
|
-
let index = 0;
|
|
2983
|
-
while (index < source.length) {
|
|
2984
|
-
const nextIndex = source.indexOf("content", index);
|
|
2985
|
-
if (nextIndex === -1) return;
|
|
2986
|
-
const previous = source[nextIndex - 1];
|
|
2987
|
-
const next = source[nextIndex + 7];
|
|
2988
|
-
if (previous && /[\w$]/.test(previous) || next && /[\w$]/.test(next)) {
|
|
2989
|
-
index = nextIndex + 7;
|
|
2990
|
-
continue;
|
|
2991
|
-
}
|
|
2992
|
-
let colonIndex = skipWhitespaceAndComments(source, nextIndex + 7);
|
|
2993
|
-
if (source[colonIndex] !== ":") {
|
|
2994
|
-
index = nextIndex + 7;
|
|
2995
|
-
continue;
|
|
2996
|
-
}
|
|
2997
|
-
colonIndex = skipWhitespaceAndComments(source, colonIndex + 1);
|
|
2998
|
-
return { start: colonIndex };
|
|
2999
|
-
}
|
|
3000
|
-
}
|
|
3001
|
-
function parseStaticContentArray(source, start) {
|
|
3002
|
-
if (source[start] !== "[") return;
|
|
3003
|
-
const value = [];
|
|
3004
|
-
let index = skipWhitespaceAndComments(source, start + 1);
|
|
3005
|
-
while (index < source.length) {
|
|
3006
|
-
if (source[index] === "]") return {
|
|
3007
|
-
end: index + 1,
|
|
3008
|
-
value
|
|
3009
|
-
};
|
|
3010
|
-
const parsed = parseStaticContentValue(source, index);
|
|
3011
|
-
if (!parsed) return;
|
|
3012
|
-
value.push(parsed.value);
|
|
3013
|
-
index = skipWhitespaceAndComments(source, parsed.end);
|
|
3014
|
-
if (source[index] === ",") {
|
|
3015
|
-
index = skipWhitespaceAndComments(source, index + 1);
|
|
3016
|
-
continue;
|
|
3017
|
-
}
|
|
3018
|
-
if (source[index] === "]") continue;
|
|
3019
|
-
return;
|
|
3020
|
-
}
|
|
3021
|
-
}
|
|
3022
|
-
function parseStaticContentObject(source, start) {
|
|
3023
|
-
if (source[start] !== "{") return;
|
|
3024
|
-
const end = findMatchingBracket(source, start, "{", "}");
|
|
3025
|
-
if (end === void 0) return;
|
|
3026
|
-
let index = skipWhitespaceAndComments(source, start + 1);
|
|
3027
|
-
let files;
|
|
3028
|
-
while (index < end) {
|
|
3029
|
-
let key;
|
|
3030
|
-
const quotedKey = readQuotedString(source, index);
|
|
3031
|
-
if (quotedKey) {
|
|
3032
|
-
key = quotedKey.value;
|
|
3033
|
-
index = quotedKey.end;
|
|
3034
|
-
} else {
|
|
3035
|
-
key = readIdentifier(source, index);
|
|
3036
|
-
if (!key) return;
|
|
3037
|
-
index += key.length;
|
|
3038
|
-
}
|
|
3039
|
-
index = skipWhitespaceAndComments(source, index);
|
|
3040
|
-
if (source[index] !== ":") return;
|
|
3041
|
-
index = skipWhitespaceAndComments(source, index + 1);
|
|
3042
|
-
const parsedValue = parseStaticContentValue(source, index);
|
|
3043
|
-
if (!parsedValue) return;
|
|
3044
|
-
if (key === "files") files = parsedValue.value;
|
|
3045
|
-
index = skipWhitespaceAndComments(source, parsedValue.end);
|
|
3046
|
-
if (source[index] === ",") {
|
|
3047
|
-
index = skipWhitespaceAndComments(source, index + 1);
|
|
3048
|
-
continue;
|
|
3049
|
-
}
|
|
3050
|
-
if (index < end) return;
|
|
3051
|
-
}
|
|
3052
|
-
return files === void 0 ? void 0 : {
|
|
3053
|
-
end: end + 1,
|
|
3054
|
-
value: { files }
|
|
3055
|
-
};
|
|
3056
|
-
}
|
|
3057
|
-
function parseStaticContentValue(source, start) {
|
|
3058
|
-
const index = skipWhitespaceAndComments(source, start);
|
|
3059
|
-
const quoted = readQuotedString(source, index);
|
|
3060
|
-
if (quoted) return quoted;
|
|
3061
|
-
if (source[index] === "[") return parseStaticContentArray(source, index);
|
|
3062
|
-
if (source[index] === "{") return parseStaticContentObject(source, index);
|
|
3063
|
-
}
|
|
3064
|
-
function readStaticConfigContent(configPath) {
|
|
3065
|
-
let source;
|
|
3066
|
-
try {
|
|
3067
|
-
source = readFileSync(configPath, "utf8");
|
|
3068
|
-
} catch {
|
|
3069
|
-
return;
|
|
3070
|
-
}
|
|
3071
|
-
const contentProperty = findContentPropertyValue(source);
|
|
3072
|
-
if (!contentProperty) return;
|
|
3073
|
-
return parseStaticContentValue(source, contentProperty.start)?.value;
|
|
3074
|
-
}
|
|
3075
|
-
//#endregion
|
|
3076
|
-
//#region src/bundlers/vite/source-scan/dependencies.ts
|
|
3077
|
-
function addSourceScanDependency(dependencies, file) {
|
|
3078
|
-
if (typeof file === "string" && file.length > 0) dependencies.add(path.resolve(file));
|
|
3079
|
-
}
|
|
3080
|
-
function addSourceScanDependencies(dependencies, files) {
|
|
3081
|
-
for (const file of files ?? []) addSourceScanDependency(dependencies, file);
|
|
3082
|
-
}
|
|
3083
|
-
//#endregion
|
|
3084
|
-
//#region src/bundlers/vite/source-scan/css-entries.ts
|
|
3085
|
-
const VITE_SOURCE_CANDIDATE_PATTERN = FULL_SOURCE_SCAN_PATTERN;
|
|
3086
|
-
const VITE_TAILWIND_CSS_ENTRY_PATTERN = "**/*.{css,less,sass,scss,styl,stylus,pcss,postcss}";
|
|
3087
|
-
const tailwindV4CssEntriesCache = /* @__PURE__ */ new Map();
|
|
3088
|
-
const tailwindConfigCssEntriesCache = /* @__PURE__ */ new Map();
|
|
3089
|
-
function parseImportSourceParam(params) {
|
|
3090
|
-
const match = /\bsource\(\s*(none|(['"])(.*?)\2)\s*\)/.exec(params);
|
|
3091
|
-
if (!match) return;
|
|
3092
|
-
return {
|
|
3093
|
-
none: match[1] === "none",
|
|
3094
|
-
sourcePath: match[3]
|
|
3095
|
-
};
|
|
3096
|
-
}
|
|
3097
|
-
function parseCssImportSpecifier(params) {
|
|
3098
|
-
const value = params.trim();
|
|
3099
|
-
const quoted = /^(['"])(.*?)\1/.exec(value);
|
|
3100
|
-
if (quoted) return quoted[2];
|
|
3101
|
-
const url = /^url\(\s*(?:(['"])(.*?)\1|([^'")\s]+))\s*\)/.exec(value);
|
|
3102
|
-
return url?.[2] ?? url?.[3];
|
|
3103
|
-
}
|
|
3104
|
-
function isTailwindCssImport(params) {
|
|
3105
|
-
const specifier = parseCssImportSpecifier(params);
|
|
3106
|
-
return specifier === "tailwindcss" || specifier?.startsWith("tailwindcss/") || specifier?.replaceAll("\\", "/").endsWith("/tailwindcss/index.css");
|
|
3107
|
-
}
|
|
3108
|
-
function resolveSourceBase(base, sourcePath) {
|
|
3109
|
-
return path.isAbsolute(sourcePath) ? sourcePath : path.resolve(base, sourcePath);
|
|
3110
|
-
}
|
|
3111
|
-
function resolveConfigPath(base, configPath) {
|
|
3112
|
-
if (path.isAbsolute(configPath)) return path.resolve(configPath);
|
|
3113
|
-
return path.resolve(base, configPath);
|
|
3114
|
-
}
|
|
3115
|
-
function createCssEntriesCacheKey(css, base, dependencies) {
|
|
3116
|
-
return JSON.stringify({
|
|
3117
|
-
base: path.resolve(base),
|
|
3118
|
-
css,
|
|
3119
|
-
dependencies
|
|
3120
|
-
});
|
|
3121
|
-
}
|
|
3122
|
-
function createDependencyExcludeEntries(files) {
|
|
3123
|
-
return [...files].map((file) => ({
|
|
3124
|
-
base: path.dirname(file),
|
|
3125
|
-
negated: true,
|
|
3126
|
-
pattern: path.basename(file)
|
|
3127
|
-
}));
|
|
3128
|
-
}
|
|
3129
|
-
async function statConfigDependency(file) {
|
|
3130
|
-
try {
|
|
3131
|
-
const stats = await stat(file);
|
|
3132
|
-
return {
|
|
3133
|
-
file,
|
|
3134
|
-
mtimeMs: stats.mtimeMs,
|
|
3135
|
-
size: stats.size
|
|
3136
|
-
};
|
|
3137
|
-
} catch {
|
|
3138
|
-
return {
|
|
3139
|
-
file,
|
|
3140
|
-
mtimeMs: -1,
|
|
3141
|
-
size: -1
|
|
3142
|
-
};
|
|
3143
|
-
}
|
|
3144
|
-
}
|
|
3145
|
-
async function collectConfigDependencySignatures(root, base) {
|
|
3146
|
-
const configPaths = /* @__PURE__ */ new Set();
|
|
3147
|
-
root.walkAtRules("config", (rule) => {
|
|
3148
|
-
const configPath = parseConfigParam$1(rule.params);
|
|
3149
|
-
if (configPath) configPaths.add(resolveConfigPath(base, configPath));
|
|
3150
|
-
});
|
|
3151
|
-
return Promise.all([...configPaths].sort().map(statConfigDependency));
|
|
3152
|
-
}
|
|
3153
|
-
function mergeTailwindInlineSourceCandidates(allInlineCandidates) {
|
|
3154
|
-
const merged = {
|
|
3155
|
-
included: /* @__PURE__ */ new Set(),
|
|
3156
|
-
excluded: /* @__PURE__ */ new Set()
|
|
3157
|
-
};
|
|
3158
|
-
for (const inlineCandidates of allInlineCandidates) {
|
|
3159
|
-
if (!inlineCandidates) continue;
|
|
3160
|
-
for (const candidate of inlineCandidates.included) if (!merged.excluded.has(candidate)) merged.included.add(candidate);
|
|
3161
|
-
for (const candidate of inlineCandidates.excluded) {
|
|
3162
|
-
merged.excluded.add(candidate);
|
|
3163
|
-
merged.included.delete(candidate);
|
|
3164
|
-
}
|
|
3165
|
-
}
|
|
3166
|
-
return merged.included.size > 0 || merged.excluded.size > 0 ? merged : void 0;
|
|
3167
|
-
}
|
|
3168
|
-
async function resolveConfigContentEntries(root, base) {
|
|
3169
|
-
const configPaths = /* @__PURE__ */ new Set();
|
|
3170
|
-
root.walkAtRules("config", (rule) => {
|
|
3171
|
-
const configPath = parseConfigParam$1(rule.params);
|
|
3172
|
-
if (configPath) configPaths.add(resolveConfigPath(base, configPath));
|
|
3173
|
-
});
|
|
3174
|
-
const entries = [];
|
|
3175
|
-
for (const configPath of configPaths) {
|
|
3176
|
-
const staticContent = readStaticConfigContent(configPath);
|
|
3177
|
-
if (staticContent !== void 0) {
|
|
3178
|
-
entries.push(...normalizeLegacyContentEntries(staticContent, path.dirname(configPath), { relativeBase: path.dirname(configPath) }));
|
|
3179
|
-
continue;
|
|
3180
|
-
}
|
|
3181
|
-
try {
|
|
3182
|
-
const loaded = await loadConfig({
|
|
3183
|
-
config: configPath,
|
|
3184
|
-
cwd: path.dirname(configPath)
|
|
3185
|
-
});
|
|
3186
|
-
entries.push(...normalizeLegacyContentEntries(loaded?.config.content, path.dirname(configPath), { relativeBase: path.dirname(configPath) }));
|
|
3187
|
-
} catch {}
|
|
3188
|
-
}
|
|
3189
|
-
return {
|
|
3190
|
-
dependencies: [...configPaths],
|
|
3191
|
-
entries
|
|
3192
|
-
};
|
|
3193
|
-
}
|
|
3194
|
-
async function resolveTailwindV4EntriesFromCss(css, base) {
|
|
3195
|
-
let root;
|
|
3196
|
-
try {
|
|
3197
|
-
root = postcss.parse(css);
|
|
3198
|
-
} catch {
|
|
3199
|
-
return;
|
|
3200
|
-
}
|
|
3201
|
-
let importSourceBase;
|
|
3202
|
-
let hasSourceNone = false;
|
|
3203
|
-
let hasTailwindCssImport = false;
|
|
3204
|
-
const [sourceEntries, configEntries] = await Promise.all([resolveCssSourceEntries(root, base, VITE_SOURCE_CANDIDATE_PATTERN), resolveConfigContentEntries(root, base)]);
|
|
3205
|
-
const entries = [...configEntries.entries, ...sourceEntries];
|
|
3206
|
-
const hasPositiveEntries = entries.some((entry) => !entry.negated);
|
|
3207
|
-
const inlineCandidates = collectCssInlineSourceCandidates(root);
|
|
3208
|
-
root.walkAtRules("import", (rule) => {
|
|
3209
|
-
if (!isTailwindCssImport(rule.params)) return;
|
|
3210
|
-
hasTailwindCssImport = true;
|
|
3211
|
-
const sourceParam = parseImportSourceParam(rule.params);
|
|
3212
|
-
if (sourceParam?.none) hasSourceNone = true;
|
|
3213
|
-
if (sourceParam?.sourcePath) importSourceBase = resolveSourceBase(base, sourceParam.sourcePath);
|
|
3214
|
-
});
|
|
3215
|
-
if (importSourceBase) return {
|
|
3216
|
-
entries: [{
|
|
3217
|
-
base: importSourceBase,
|
|
3218
|
-
negated: false,
|
|
3219
|
-
pattern: VITE_SOURCE_CANDIDATE_PATTERN
|
|
3220
|
-
}, ...entries],
|
|
3221
|
-
explicit: true,
|
|
3222
|
-
inlineCandidates,
|
|
3223
|
-
dependencies: configEntries.dependencies
|
|
3224
|
-
};
|
|
3225
|
-
if (hasSourceNone) return {
|
|
3226
|
-
entries,
|
|
3227
|
-
explicit: true,
|
|
3228
|
-
inlineCandidates,
|
|
3229
|
-
dependencies: configEntries.dependencies
|
|
3230
|
-
};
|
|
3231
|
-
if (hasPositiveEntries) return {
|
|
3232
|
-
entries,
|
|
3233
|
-
explicit: true,
|
|
3234
|
-
inlineCandidates,
|
|
3235
|
-
dependencies: configEntries.dependencies
|
|
3236
|
-
};
|
|
3237
|
-
if (inlineCandidates.included.size > 0 || inlineCandidates.excluded.size > 0) return {
|
|
3238
|
-
entries: [],
|
|
3239
|
-
explicit: true,
|
|
3240
|
-
inlineCandidates,
|
|
3241
|
-
dependencies: configEntries.dependencies
|
|
3242
|
-
};
|
|
3243
|
-
return hasTailwindCssImport ? {
|
|
3244
|
-
entries,
|
|
3245
|
-
explicit: false,
|
|
3246
|
-
inlineCandidates,
|
|
3247
|
-
dependencies: configEntries.dependencies
|
|
3248
|
-
} : void 0;
|
|
3249
|
-
}
|
|
3250
|
-
async function resolveViteTailwindV4CssDependencies(css, base) {
|
|
3251
|
-
return (await resolveTailwindV4EntriesFromCss(css, base))?.dependencies ?? [];
|
|
3252
|
-
}
|
|
3253
|
-
function collectExistingCssEntries(options) {
|
|
3254
|
-
return [
|
|
3255
|
-
...options.cssEntries ?? [],
|
|
3256
|
-
...options.tailwindcss?.v4?.cssEntries ?? [],
|
|
3257
|
-
...options.tailwindcssPatcherOptions?.tailwindcss?.v4?.cssEntries ?? []
|
|
3258
|
-
].filter((item) => typeof item === "string" && item.length > 0).map((item) => path.resolve(item)).filter((item) => existsSync(item));
|
|
3259
|
-
}
|
|
3260
|
-
async function resolveTailwindV3CssEntryScan(options, patcher) {
|
|
3261
|
-
const cssEntries = collectExistingCssEntries(options);
|
|
3262
|
-
const entries = [];
|
|
3263
|
-
const dependencies = /* @__PURE__ */ new Set();
|
|
3264
|
-
if (cssEntries.length === 0) return {
|
|
3265
|
-
entries,
|
|
3266
|
-
dependencies
|
|
3267
|
-
};
|
|
3268
|
-
const sourceOptions = resolveTailwindV3SourceOptionsFromPatcher(patcher);
|
|
3269
|
-
await Promise.all(cssEntries.map(async (cssEntry) => {
|
|
3270
|
-
addSourceScanDependency(dependencies, cssEntry);
|
|
3271
|
-
let css;
|
|
3272
|
-
try {
|
|
3273
|
-
css = readFileSync(cssEntry, "utf8");
|
|
3274
|
-
} catch {
|
|
3275
|
-
return;
|
|
3276
|
-
}
|
|
3277
|
-
const cssConfigEntries = await resolveTailwindConfigEntriesFromCssCached(css, path.dirname(cssEntry));
|
|
3278
|
-
if (cssConfigEntries) {
|
|
3279
|
-
addSourceScanDependencies(dependencies, cssConfigEntries.dependencies);
|
|
3280
|
-
entries.push(...cssConfigEntries.entries);
|
|
3281
|
-
return;
|
|
3282
|
-
}
|
|
3283
|
-
const source = await resolveTailwindV3Source({
|
|
3284
|
-
...sourceOptions,
|
|
3285
|
-
base: path.dirname(cssEntry),
|
|
3286
|
-
css
|
|
3287
|
-
});
|
|
3288
|
-
addSourceScanDependency(dependencies, source.config);
|
|
3289
|
-
addSourceScanDependencies(dependencies, source.dependencies);
|
|
3290
|
-
entries.push(...normalizeLegacyContentEntries(source.configObject?.content, source.cwd, { relativeBase: source.config ? path.dirname(source.config) : source.cwd }));
|
|
3291
|
-
}));
|
|
3292
|
-
return {
|
|
3293
|
-
entries,
|
|
3294
|
-
dependencies
|
|
3295
|
-
};
|
|
3296
|
-
}
|
|
3297
|
-
async function pathExistsAsFile(file) {
|
|
3298
|
-
try {
|
|
3299
|
-
return (await stat(file)).isFile();
|
|
3300
|
-
} catch {
|
|
3301
|
-
return false;
|
|
3302
|
-
}
|
|
3303
|
-
}
|
|
3304
|
-
async function resolveTailwindV4EntriesFromCssCached(css, base) {
|
|
3305
|
-
let root;
|
|
3306
|
-
try {
|
|
3307
|
-
root = postcss.parse(css);
|
|
3308
|
-
} catch {
|
|
3309
|
-
return;
|
|
3310
|
-
}
|
|
3311
|
-
const cacheKey = createCssEntriesCacheKey(css, base, await collectConfigDependencySignatures(root, base));
|
|
3312
|
-
const cached = tailwindV4CssEntriesCache.get(cacheKey);
|
|
3313
|
-
if (cached) return cached;
|
|
3314
|
-
const task = resolveTailwindV4EntriesFromCss(css, base);
|
|
3315
|
-
tailwindV4CssEntriesCache.set(cacheKey, task);
|
|
3316
|
-
return task;
|
|
3317
|
-
}
|
|
3318
|
-
async function resolveTailwindConfigEntriesFromCssCached(css, base) {
|
|
3319
|
-
let root;
|
|
3320
|
-
try {
|
|
3321
|
-
root = postcss.parse(css);
|
|
3322
|
-
} catch {
|
|
3323
|
-
return;
|
|
3324
|
-
}
|
|
3325
|
-
const dependencies = await collectConfigDependencySignatures(root, base);
|
|
3326
|
-
if (dependencies.length === 0) return;
|
|
3327
|
-
const cacheKey = createCssEntriesCacheKey(css, base, dependencies);
|
|
3328
|
-
const cached = tailwindConfigCssEntriesCache.get(cacheKey);
|
|
3329
|
-
if (cached) return cached;
|
|
3330
|
-
const task = resolveConfigContentEntries(root, base).then((resolved) => {
|
|
3331
|
-
return {
|
|
3332
|
-
entries: [...resolved.entries, ...createDependencyExcludeEntries(resolved.dependencies)],
|
|
3333
|
-
explicit: true,
|
|
3334
|
-
inlineCandidates: {
|
|
3335
|
-
excluded: /* @__PURE__ */ new Set(),
|
|
3336
|
-
included: /* @__PURE__ */ new Set()
|
|
3337
|
-
},
|
|
3338
|
-
dependencies: resolved.dependencies
|
|
3339
|
-
};
|
|
3340
|
-
});
|
|
3341
|
-
tailwindConfigCssEntriesCache.set(cacheKey, task);
|
|
3342
|
-
return task;
|
|
3343
|
-
}
|
|
3344
|
-
async function discoverTailwindV4CssEntries(root, outDir) {
|
|
3345
|
-
const resolvedRoot = path.resolve(root);
|
|
3346
|
-
const ignore = ["**/node_modules/**", "**/.git/**"];
|
|
3347
|
-
const resolvedOutDir = outDir ? path.resolve(resolvedRoot, outDir) : void 0;
|
|
3348
|
-
if (resolvedOutDir) {
|
|
3349
|
-
const relativeOutDir = path.relative(resolvedRoot, resolvedOutDir);
|
|
3350
|
-
if (relativeOutDir && !relativeOutDir.startsWith("..") && !path.isAbsolute(relativeOutDir)) ignore.push(`${relativeOutDir.split(path.sep).join("/")}/**`);
|
|
3351
|
-
}
|
|
3352
|
-
const candidates = await fg(VITE_TAILWIND_CSS_ENTRY_PATTERN, {
|
|
3353
|
-
absolute: true,
|
|
3354
|
-
cwd: resolvedRoot,
|
|
3355
|
-
ignore,
|
|
3356
|
-
onlyFiles: true,
|
|
3357
|
-
unique: true
|
|
3358
|
-
});
|
|
3359
|
-
const entries = [];
|
|
3360
|
-
for (const file of candidates) {
|
|
3361
|
-
if (!await pathExistsAsFile(file)) continue;
|
|
3362
|
-
try {
|
|
3363
|
-
const css = readFileSync(file, "utf8");
|
|
3364
|
-
if (css.includes("tailwindcss") || css.includes("@source") || css.includes("@config")) {
|
|
3365
|
-
if (await resolveTailwindV4EntriesFromCssCached(css, path.dirname(file))) entries.push(file);
|
|
3366
|
-
}
|
|
3367
|
-
} catch {}
|
|
3368
|
-
}
|
|
3369
|
-
return entries;
|
|
3370
|
-
}
|
|
3371
|
-
function collectConfiguredCssSources(options) {
|
|
3372
|
-
return [...options.tailwindcss?.v4?.cssSources ?? [], ...options.tailwindcssPatcherOptions?.tailwindcss?.v4?.cssSources ?? []];
|
|
3373
|
-
}
|
|
3374
|
-
//#endregion
|
|
3375
|
-
//#region src/bundlers/vite/source-scan.ts
|
|
3376
|
-
function createResolvedViteSourceScan(input, dependencies) {
|
|
3377
|
-
return {
|
|
3378
|
-
...input,
|
|
3379
|
-
...dependencies.size > 0 ? { dependencies: [...dependencies].sort() } : {}
|
|
3380
|
-
};
|
|
3381
|
-
}
|
|
3382
|
-
function createMergedCssEntrySourceScanEntries(entries, options) {
|
|
3383
|
-
if (options.sourceCount <= 1) return entries;
|
|
3384
|
-
const positiveEntries = entries.filter((entry) => !entry.negated);
|
|
3385
|
-
return positiveEntries.length > 0 ? positiveEntries : entries;
|
|
3386
|
-
}
|
|
3387
|
-
function createResolvedV4CssScanInput(entries, inlineCandidates, explicit) {
|
|
3388
|
-
return {
|
|
3389
|
-
entries: explicit ? entries : entries.length > 0 ? entries : void 0,
|
|
3390
|
-
explicit,
|
|
3391
|
-
inlineCandidates
|
|
3392
|
-
};
|
|
3393
|
-
}
|
|
3394
|
-
async function resolveViteSourceScanEntries(options, patcher, scanOptions = {}) {
|
|
3395
|
-
if (patcher.majorVersion === 3) {
|
|
3396
|
-
const [source, cssEntryScan] = await Promise.all([resolveTailwindV3SourceFromPatcher(patcher), resolveTailwindV3CssEntryScan(options, patcher)]);
|
|
3397
|
-
const contentEntries = [...normalizeLegacyContentEntries(source.configObject?.content, source.cwd, { relativeBase: source.config ? path.dirname(source.config) : source.cwd }), ...cssEntryScan.entries];
|
|
3398
|
-
const dependencies = /* @__PURE__ */ new Set();
|
|
3399
|
-
addSourceScanDependency(dependencies, source.config);
|
|
3400
|
-
for (const dependency of cssEntryScan.dependencies) dependencies.add(dependency);
|
|
3401
|
-
return contentEntries.length > 0 ? createResolvedViteSourceScan({ entries: contentEntries }, dependencies) : void 0;
|
|
3402
|
-
}
|
|
3403
|
-
if (patcher.majorVersion === 4) {
|
|
3404
|
-
const sourceOptions = resolveTailwindV4SourceOptionsFromPatcher(patcher);
|
|
3405
|
-
const cssEntries = collectExistingCssEntries(options);
|
|
3406
|
-
if (cssEntries.length === 0 && !sourceOptions.css && !sourceOptions.cssSources?.length) {
|
|
3407
|
-
const scanRoot = scanOptions.root;
|
|
3408
|
-
const sourceProjectRoot = sourceOptions.projectRoot;
|
|
3409
|
-
if (scanRoot && sourceProjectRoot && path.resolve(scanRoot) === path.resolve(sourceProjectRoot)) {
|
|
3410
|
-
const discoveredCssEntries = await discoverTailwindV4CssEntries(scanRoot, scanOptions.outDir);
|
|
3411
|
-
cssEntries.push(...discoveredCssEntries);
|
|
3412
|
-
}
|
|
3413
|
-
}
|
|
3414
|
-
const entries = [];
|
|
3415
|
-
const cssInlineCandidates = [];
|
|
3416
|
-
const dependencies = /* @__PURE__ */ new Set();
|
|
3417
|
-
let explicit = false;
|
|
3418
|
-
let readableCssEntryCount = 0;
|
|
3419
|
-
for (const cssEntry of cssEntries) {
|
|
3420
|
-
addSourceScanDependency(dependencies, cssEntry);
|
|
3421
|
-
let css;
|
|
3422
|
-
try {
|
|
3423
|
-
css = readFileSync(cssEntry, "utf8");
|
|
3424
|
-
} catch {
|
|
3425
|
-
continue;
|
|
3426
|
-
}
|
|
3427
|
-
readableCssEntryCount++;
|
|
3428
|
-
const resolved = await resolveTailwindV4EntriesFromCssCached(css, path.dirname(cssEntry));
|
|
3429
|
-
if (resolved) {
|
|
3430
|
-
entries.push(...resolved.entries);
|
|
3431
|
-
cssInlineCandidates.push(resolved.inlineCandidates);
|
|
3432
|
-
addSourceScanDependencies(dependencies, resolved.dependencies);
|
|
3433
|
-
explicit || (explicit = resolved.explicit);
|
|
3434
|
-
}
|
|
3435
|
-
}
|
|
3436
|
-
const inlineCandidates = mergeTailwindInlineSourceCandidates(cssInlineCandidates);
|
|
3437
|
-
const scanEntries = createMergedCssEntrySourceScanEntries(entries, { sourceCount: readableCssEntryCount });
|
|
3438
|
-
if (scanEntries.length > 0 || inlineCandidates || explicit || readableCssEntryCount > 0) return createResolvedViteSourceScan({
|
|
3439
|
-
entries: explicit ? scanEntries : scanEntries.length > 0 ? scanEntries : void 0,
|
|
3440
|
-
explicit,
|
|
3441
|
-
inlineCandidates
|
|
3442
|
-
}, dependencies);
|
|
3443
|
-
if (typeof sourceOptions.css === "string" && sourceOptions.css.length > 0) {
|
|
3444
|
-
const resolved = await resolveTailwindV4EntriesFromCssCached(sourceOptions.css, sourceOptions.base ?? sourceOptions.projectRoot ?? process.cwd());
|
|
3445
|
-
return resolved ? createResolvedViteSourceScan(createResolvedV4CssScanInput(resolved.entries, resolved.inlineCandidates, resolved.explicit), new Set(resolved.dependencies)) : void 0;
|
|
3446
|
-
}
|
|
3447
|
-
const sourceOptionBase = sourceOptions.base ?? sourceOptions.projectRoot ?? process.cwd();
|
|
3448
|
-
const configuredCssSources = collectConfiguredCssSources(options);
|
|
3449
|
-
for (const cssSource of [...configuredCssSources, ...sourceOptions.cssSources ?? []]) {
|
|
3450
|
-
if (typeof cssSource.css !== "string" || cssSource.css.length === 0) continue;
|
|
3451
|
-
addSourceScanDependency(dependencies, cssSource.file);
|
|
3452
|
-
addSourceScanDependencies(dependencies, cssSource.dependencies);
|
|
3453
|
-
const resolved = await resolveTailwindV4EntriesFromCssCached(cssSource.css, resolveTailwindV4CssSourceBase(cssSource, sourceOptionBase));
|
|
3454
|
-
if (resolved) {
|
|
3455
|
-
entries.push(...resolved.entries);
|
|
3456
|
-
cssInlineCandidates.push(resolved.inlineCandidates);
|
|
3457
|
-
addSourceScanDependencies(dependencies, resolved.dependencies);
|
|
3458
|
-
explicit || (explicit = resolved.explicit);
|
|
3459
|
-
}
|
|
3460
|
-
}
|
|
3461
|
-
const cssSourceInlineCandidates = mergeTailwindInlineSourceCandidates(cssInlineCandidates);
|
|
3462
|
-
const cssSourceScanEntries = createMergedCssEntrySourceScanEntries(entries, { sourceCount: (sourceOptions.cssSources?.length ?? 0) + configuredCssSources.length });
|
|
3463
|
-
if (cssSourceScanEntries.length > 0 || cssSourceInlineCandidates || explicit || sourceOptions.cssSources?.length || configuredCssSources.length > 0) return createResolvedViteSourceScan({
|
|
3464
|
-
entries: explicit ? cssSourceScanEntries : cssSourceScanEntries.length > 0 ? cssSourceScanEntries : void 0,
|
|
3465
|
-
explicit,
|
|
3466
|
-
inlineCandidates: cssSourceInlineCandidates
|
|
3467
|
-
}, dependencies);
|
|
3468
|
-
const source = await resolveTailwindV4SourceFromPatcher(patcher);
|
|
3469
|
-
addSourceScanDependency(dependencies, source.file);
|
|
3470
|
-
addSourceScanDependencies(dependencies, source.dependencies);
|
|
3471
|
-
const resolved = await resolveTailwindV4EntriesFromCssCached(source.css, source.base);
|
|
3472
|
-
return resolved ? createResolvedViteSourceScan(createResolvedV4CssScanInput(resolved.entries.length > 0 ? resolved.entries : [], resolved.inlineCandidates, resolved.entries.length > 0 ? resolved.explicit : false), new Set([...dependencies, ...resolved.dependencies])) : void 0;
|
|
3473
|
-
}
|
|
3474
|
-
}
|
|
3475
|
-
function createViteSourceScanMatcher(entries) {
|
|
3476
|
-
if (entries?.length === 0) return;
|
|
3477
|
-
return createTailwindSourceEntryMatcher(entries);
|
|
3478
|
-
}
|
|
3479
|
-
//#endregion
|
|
3480
|
-
//#region src/tailwindcss/runtime/cache.ts
|
|
3481
|
-
const runtimeClassSetCache = /* @__PURE__ */ new WeakMap();
|
|
3482
|
-
const runtimeFileSignatureCache = /* @__PURE__ */ new Map();
|
|
3483
|
-
const runtimeTrackedSourceFilesCache = /* @__PURE__ */ new Map();
|
|
3484
|
-
let runtimeFileSignatureCacheClearTimer;
|
|
3485
|
-
const runtimeSignaturePatchersSymbol = Symbol.for("weapp-tailwindcss.runtimeSignaturePatchers");
|
|
3486
|
-
function getCacheEntry(twPatcher) {
|
|
3487
|
-
let entry = runtimeClassSetCache.get(twPatcher);
|
|
3488
|
-
if (!entry) {
|
|
3489
|
-
entry = {};
|
|
3490
|
-
runtimeClassSetCache.set(twPatcher, entry);
|
|
3491
|
-
}
|
|
3492
|
-
return entry;
|
|
3493
|
-
}
|
|
3494
|
-
function scheduleRuntimeConfigSignatureCacheClear() {
|
|
3495
|
-
if (runtimeFileSignatureCacheClearTimer) return;
|
|
3496
|
-
runtimeFileSignatureCacheClearTimer = setTimeout(() => {
|
|
3497
|
-
runtimeFileSignatureCache.clear();
|
|
3498
|
-
runtimeTrackedSourceFilesCache.clear();
|
|
3499
|
-
runtimeFileSignatureCacheClearTimer = void 0;
|
|
3500
|
-
}, 0);
|
|
3501
|
-
runtimeFileSignatureCacheClearTimer.unref?.();
|
|
3502
|
-
}
|
|
3503
|
-
function getFileSignature(filePath) {
|
|
3504
|
-
const cached = runtimeFileSignatureCache.get(filePath);
|
|
3505
|
-
if (cached !== void 0) return cached;
|
|
3506
|
-
let signature;
|
|
3507
|
-
try {
|
|
3508
|
-
const stats = statSync(filePath);
|
|
3509
|
-
signature = `${filePath}:${stats.size}:${stats.mtimeMs}`;
|
|
3510
|
-
} catch {
|
|
3511
|
-
signature = `${filePath}:missing`;
|
|
3512
|
-
}
|
|
3513
|
-
runtimeFileSignatureCache.set(filePath, signature);
|
|
3514
|
-
scheduleRuntimeConfigSignatureCacheClear();
|
|
3515
|
-
return signature;
|
|
3516
|
-
}
|
|
3517
|
-
function getTailwindTrackedFiles(twPatcher) {
|
|
3518
|
-
const tailwindOptions = resolveTailwindcssOptions(twPatcher.options);
|
|
3519
|
-
const tracked = /* @__PURE__ */ new Set();
|
|
3520
|
-
const configPath = tailwindOptions?.config;
|
|
3521
|
-
if (typeof configPath === "string" && configPath.length > 0) tracked.add(configPath);
|
|
3522
|
-
for (const entry of tailwindOptions?.v4?.cssEntries ?? []) if (typeof entry === "string" && entry.length > 0) tracked.add(entry);
|
|
3523
|
-
for (const source of tailwindOptions?.v4?.cssSources ?? []) {
|
|
3524
|
-
if (typeof source.file === "string" && source.file.length > 0) tracked.add(source.file);
|
|
3525
|
-
for (const dependency of source.dependencies ?? []) if (typeof dependency === "string" && dependency.length > 0) tracked.add(dependency);
|
|
3526
|
-
}
|
|
3527
|
-
return tracked;
|
|
3528
|
-
}
|
|
3529
|
-
function normalizeTrackedSourceSignature(cssEntries, cssSources) {
|
|
3530
|
-
return normalizeSignatureValue({
|
|
3531
|
-
cssEntries: cssEntries?.map((entry) => {
|
|
3532
|
-
if (!existsSync(entry)) return `${entry}:missing`;
|
|
3533
|
-
return getFileSignature(entry);
|
|
3534
|
-
}),
|
|
3535
|
-
cssSources
|
|
3536
|
-
});
|
|
3537
|
-
}
|
|
3538
|
-
async function collectTailwindV4TrackedSourceFiles(twPatcher) {
|
|
3539
|
-
const tailwindOptions = resolveTailwindcssOptions(twPatcher.options);
|
|
3540
|
-
const signature = normalizeTrackedSourceSignature(tailwindOptions?.v4?.cssEntries, tailwindOptions?.v4?.cssSources);
|
|
3541
|
-
const cached = runtimeTrackedSourceFilesCache.get(signature);
|
|
3542
|
-
if (cached) return cached;
|
|
3543
|
-
const files = /* @__PURE__ */ new Set();
|
|
3544
|
-
for (const cssEntry of tailwindOptions?.v4?.cssEntries ?? []) {
|
|
3545
|
-
if (!existsSync(cssEntry)) continue;
|
|
3546
|
-
const resolved = await resolveTailwindV4EntriesFromCssCached(readFileSync(cssEntry, "utf8"), path.dirname(cssEntry));
|
|
3547
|
-
const expanded = resolved?.entries?.length ? await expandTailwindSourceEntries(resolved.entries) : [];
|
|
3548
|
-
for (const file of expanded) files.add(file);
|
|
3549
|
-
}
|
|
3550
|
-
for (const cssSource of tailwindOptions?.v4?.cssSources ?? []) {
|
|
3551
|
-
if (typeof cssSource.css !== "string" || cssSource.css.length === 0) continue;
|
|
3552
|
-
const base = typeof cssSource.file === "string" && cssSource.file.length > 0 ? path.dirname(cssSource.file) : tailwindOptions?.v4?.base ?? tailwindOptions?.cwd ?? twPatcher.options?.projectRoot ?? process.cwd();
|
|
3553
|
-
const resolved = await resolveTailwindV4EntriesFromCssCached(cssSource.css, base);
|
|
3554
|
-
const expanded = resolved?.entries?.length ? await expandTailwindSourceEntries(resolved.entries) : [];
|
|
3555
|
-
for (const file of expanded) files.add(file);
|
|
3556
|
-
}
|
|
3557
|
-
const result = [...files].sort((a, b) => a.localeCompare(b));
|
|
3558
|
-
runtimeTrackedSourceFilesCache.set(signature, result);
|
|
3559
|
-
return result;
|
|
3560
|
-
}
|
|
3561
|
-
function normalizeSignatureValue(value) {
|
|
3562
|
-
if (value == null) return "null";
|
|
3563
|
-
if (typeof value === "string") return value;
|
|
3564
|
-
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
3565
|
-
if (Array.isArray(value)) return `[${value.map((item) => normalizeSignatureValue(item)).join(",")}]`;
|
|
3566
|
-
if (typeof value === "object") return `{${Object.entries(value).filter(([, item]) => item !== void 0).sort(([a], [b]) => a.localeCompare(b)).map(([key, item]) => `${key}:${normalizeSignatureValue(item)}`).join(",")}}`;
|
|
3567
|
-
return String(value);
|
|
3568
|
-
}
|
|
3569
|
-
function readOptionalProperty(value, key) {
|
|
3570
|
-
if (typeof value !== "object" || value === null || !(key in value)) return;
|
|
3571
|
-
return value[key];
|
|
3572
|
-
}
|
|
3573
|
-
function getTailwindOptionsSignature(twPatcher) {
|
|
3574
|
-
const options = twPatcher.options;
|
|
3575
|
-
const tailwindOptions = resolveTailwindcssOptions(options);
|
|
3576
|
-
return normalizeSignatureValue({
|
|
3577
|
-
projectRoot: options?.projectRoot,
|
|
3578
|
-
packageName: tailwindOptions?.packageName,
|
|
3579
|
-
versionHint: readOptionalProperty(tailwindOptions, "versionHint"),
|
|
3580
|
-
cwd: tailwindOptions?.cwd,
|
|
3581
|
-
config: tailwindOptions?.config,
|
|
3582
|
-
v2: tailwindOptions?.v2,
|
|
3583
|
-
v3: tailwindOptions?.v3,
|
|
3584
|
-
v4: {
|
|
3585
|
-
base: tailwindOptions?.v4?.base,
|
|
3586
|
-
configuredBase: readOptionalProperty(tailwindOptions?.v4, "configuredBase"),
|
|
3587
|
-
css: tailwindOptions?.v4?.css,
|
|
3588
|
-
cssEntries: tailwindOptions?.v4?.cssEntries,
|
|
3589
|
-
cssSources: tailwindOptions?.v4?.cssSources,
|
|
3590
|
-
hasUserDefinedSources: readOptionalProperty(tailwindOptions?.v4, "hasUserDefinedSources"),
|
|
3591
|
-
sources: tailwindOptions?.v4?.sources
|
|
3592
|
-
}
|
|
3593
|
-
});
|
|
3594
|
-
}
|
|
3595
|
-
function getRuntimeTargetSignature(twPatcher) {
|
|
3596
|
-
const packageInfo = twPatcher.packageInfo;
|
|
3597
|
-
return [
|
|
3598
|
-
packageInfo?.name ?? "missing",
|
|
3599
|
-
packageInfo?.rootPath ?? "missing",
|
|
3600
|
-
packageInfo?.version ?? "unknown",
|
|
3601
|
-
twPatcher.majorVersion ?? "unknown",
|
|
3602
|
-
getTailwindOptionsSignature(twPatcher)
|
|
3603
|
-
].join(":");
|
|
3604
|
-
}
|
|
3605
|
-
function getNestedPatchers$1(twPatcher) {
|
|
3606
|
-
const nested = twPatcher[runtimeSignaturePatchersSymbol];
|
|
3607
|
-
return Array.isArray(nested) && nested.length > 0 ? nested : void 0;
|
|
3608
|
-
}
|
|
3609
|
-
function getOwnRuntimeClassSetSignature(twPatcher) {
|
|
3610
|
-
const trackedFiles = [...getTailwindTrackedFiles(twPatcher)].sort((a, b) => a.localeCompare(b)).map(getFileSignature);
|
|
3611
|
-
return `${trackedFiles.length > 0 ? trackedFiles.join("|") : "files:missing"}|runtime:${getRuntimeTargetSignature(twPatcher)}`;
|
|
3612
|
-
}
|
|
3613
|
-
function invalidateRuntimeClassSet(twPatcher) {
|
|
3614
|
-
if (!twPatcher) return;
|
|
3615
|
-
const nestedPatchers = getNestedPatchers$1(twPatcher);
|
|
3616
|
-
if (nestedPatchers) for (const patcher of nestedPatchers) invalidateRuntimeClassSet(patcher);
|
|
3617
|
-
for (const trackedFile of getTailwindTrackedFiles(twPatcher)) runtimeFileSignatureCache.delete(trackedFile);
|
|
3618
|
-
runtimeTrackedSourceFilesCache.clear();
|
|
3619
|
-
runtimeClassSetCache.delete(twPatcher);
|
|
3620
|
-
}
|
|
3621
|
-
function getRuntimeClassSetCacheEntry(twPatcher) {
|
|
3622
|
-
return getCacheEntry(twPatcher);
|
|
3623
|
-
}
|
|
3624
|
-
function getRuntimeClassSetSignature(twPatcher) {
|
|
3625
|
-
const nestedPatchers = getNestedPatchers$1(twPatcher);
|
|
3626
|
-
if (nestedPatchers) return nestedPatchers.map(getOwnRuntimeClassSetSignature).sort((a, b) => a.localeCompare(b)).join("||");
|
|
3627
|
-
return getOwnRuntimeClassSetSignature(twPatcher);
|
|
3628
|
-
}
|
|
3629
|
-
async function getRuntimeClassSetSignatureWithSources(twPatcher) {
|
|
3630
|
-
const baseSignature = getRuntimeClassSetSignature(twPatcher);
|
|
3631
|
-
if (twPatcher.majorVersion !== 4) return baseSignature;
|
|
3632
|
-
const trackedSourceFiles = await collectTailwindV4TrackedSourceFiles(twPatcher);
|
|
3633
|
-
if (trackedSourceFiles.length === 0) return baseSignature;
|
|
3634
|
-
return [baseSignature, trackedSourceFiles.map(getFileSignature).join("|")].join("|sources:");
|
|
3635
|
-
}
|
|
3636
|
-
//#endregion
|
|
3637
|
-
//#region src/tailwindcss/runtime-patch.ts
|
|
3638
|
-
const debug = createDebug("[tailwindcss:runtime-patch] ");
|
|
3639
|
-
const require = createRequire(import.meta.url);
|
|
3640
|
-
const runtimePatchPromiseCache = /* @__PURE__ */ new WeakMap();
|
|
3641
|
-
function getNestedPatchers(twPatcher) {
|
|
3642
|
-
const nested = twPatcher[runtimeSignaturePatchersSymbol];
|
|
3643
|
-
return Array.isArray(nested) && nested.length > 0 ? nested : void 0;
|
|
3644
|
-
}
|
|
3645
|
-
function shouldApplyRuntimePatch(twPatcher) {
|
|
3646
|
-
return twPatcher.majorVersion === 3 && typeof twPatcher.patch === "function";
|
|
3647
|
-
}
|
|
3648
|
-
function clearTailwindcssRequireCache(twPatcher) {
|
|
3649
|
-
const rootPath = twPatcher.packageInfo?.rootPath;
|
|
3650
|
-
if (!rootPath) return;
|
|
3651
|
-
const normalizedRoot = path.resolve(rootPath);
|
|
3652
|
-
let count = 0;
|
|
3653
|
-
for (const id of Object.keys(require.cache)) {
|
|
3654
|
-
const normalizedId = path.resolve(id);
|
|
3655
|
-
if (normalizedId === normalizedRoot || normalizedId.startsWith(`${normalizedRoot}${path.sep}`)) {
|
|
3656
|
-
delete require.cache[id];
|
|
3657
|
-
count += 1;
|
|
3658
|
-
}
|
|
3659
|
-
}
|
|
3660
|
-
if (count > 0) debug("clear tailwindcss require cache after runtime patch, count=%d root=%s", count, normalizedRoot);
|
|
3661
|
-
}
|
|
3662
|
-
async function ensureTailwindcssRuntimePatch(twPatcher, options = {}) {
|
|
3663
|
-
const nestedPatchers = getNestedPatchers(twPatcher);
|
|
3664
|
-
if (nestedPatchers) {
|
|
3665
|
-
await Promise.all(nestedPatchers.map((patcher) => ensureTailwindcssRuntimePatch(patcher)));
|
|
3666
|
-
return;
|
|
3667
|
-
}
|
|
3668
|
-
if (!shouldApplyRuntimePatch(twPatcher)) return;
|
|
3669
|
-
const cached = runtimePatchPromiseCache.get(twPatcher);
|
|
3670
|
-
if (cached) {
|
|
3671
|
-
await cached;
|
|
3672
|
-
if (options.clearRequireCache) clearTailwindcssRequireCache(twPatcher);
|
|
3673
|
-
return;
|
|
3674
|
-
}
|
|
3675
|
-
const task = Promise.resolve().then(async () => {
|
|
3676
|
-
debug("apply tailwindcss runtime patch, package=%s version=%s root=%s", twPatcher.packageInfo?.name ?? "tailwindcss", twPatcher.packageInfo?.version ?? "unknown", twPatcher.packageInfo?.rootPath ?? "unknown");
|
|
3677
|
-
await twPatcher.patch?.();
|
|
3678
|
-
if (options.clearRequireCache) clearTailwindcssRequireCache(twPatcher);
|
|
3679
|
-
}).catch((error) => {
|
|
3680
|
-
runtimePatchPromiseCache.delete(twPatcher);
|
|
3681
|
-
throw error;
|
|
3682
|
-
});
|
|
3683
|
-
runtimePatchPromiseCache.set(twPatcher, task);
|
|
3684
|
-
return task;
|
|
3685
|
-
}
|
|
3686
|
-
//#endregion
|
|
3687
|
-
//#region src/tailwindcss/v3-engine/generator/runtime-ready.ts
|
|
3688
|
-
const runtimeReadyPromiseCache = /* @__PURE__ */ new Map();
|
|
3689
|
-
function createRuntimeReadyCacheKey(source, rootPath) {
|
|
3690
|
-
return [
|
|
3691
|
-
source.packageName,
|
|
3692
|
-
source.postcssPlugin,
|
|
3693
|
-
rootPath ?? "missing",
|
|
3694
|
-
source.config ?? "config:missing",
|
|
3695
|
-
source.cwd
|
|
3696
|
-
].join("\0");
|
|
3697
|
-
}
|
|
3698
|
-
function createRuntimeReadyPromise(source) {
|
|
3699
|
-
const patcher = createTailwindcssPatcher({
|
|
3700
|
-
basedir: source.cwd,
|
|
3701
|
-
supportCustomLengthUnitsPatch: true,
|
|
3702
|
-
tailwindcss: {
|
|
3703
|
-
...source.config === void 0 ? {} : { config: source.config },
|
|
3704
|
-
cwd: source.cwd,
|
|
3705
|
-
packageName: source.packageName,
|
|
3706
|
-
postcssPlugin: source.postcssPlugin,
|
|
3707
|
-
version: 3
|
|
3708
|
-
}
|
|
3709
|
-
});
|
|
3710
|
-
const cacheKey = createRuntimeReadyCacheKey(source, patcher.packageInfo?.rootPath);
|
|
3711
|
-
const cached = runtimeReadyPromiseCache.get(cacheKey);
|
|
3712
|
-
if (cached) return cached;
|
|
3713
|
-
const task = ensureTailwindcssRuntimePatch(patcher, { clearRequireCache: true }).catch((error) => {
|
|
3714
|
-
runtimeReadyPromiseCache.delete(cacheKey);
|
|
3715
|
-
throw error;
|
|
3716
|
-
});
|
|
3717
|
-
runtimeReadyPromiseCache.set(cacheKey, task);
|
|
3718
|
-
return task;
|
|
3719
|
-
}
|
|
3720
|
-
//#endregion
|
|
3721
|
-
//#region src/tailwindcss/v3-engine/miniprogram.ts
|
|
3722
|
-
const defaultStyleHandler = createStyleHandler({
|
|
3723
|
-
cssChildCombinatorReplaceValue: ["view", "text"],
|
|
3724
|
-
cssRemoveHoverPseudoClass: true,
|
|
3725
|
-
isMainChunk: true,
|
|
3726
|
-
majorVersion: 3
|
|
3727
|
-
});
|
|
3728
|
-
const MINI_PROGRAM_V3_PREFLIGHT_SELECTORS = new Set([
|
|
3729
|
-
"view,text,:before,:after",
|
|
3730
|
-
"view,text,:after,:before",
|
|
3731
|
-
"view,text,::before,::after",
|
|
3732
|
-
"view,text,::after,::before"
|
|
3733
|
-
]);
|
|
3734
|
-
const V3_PREFLIGHT_RESET_PROPS = new Set([
|
|
3735
|
-
"box-sizing",
|
|
3736
|
-
"border",
|
|
3737
|
-
"border-width",
|
|
3738
|
-
"border-style",
|
|
3739
|
-
"border-color",
|
|
3740
|
-
"margin",
|
|
3741
|
-
"padding"
|
|
3742
|
-
]);
|
|
3743
|
-
function normalizeSelector(selector) {
|
|
3744
|
-
return selector.trim().replace(/\s+/g, "");
|
|
3745
|
-
}
|
|
3746
|
-
function isMiniProgramV3PreflightRule(rule) {
|
|
3747
|
-
return MINI_PROGRAM_V3_PREFLIGHT_SELECTORS.has(normalizeSelector(rule.selector));
|
|
3748
|
-
}
|
|
3749
|
-
function hasResetDeclaration(rule) {
|
|
3750
|
-
let found = false;
|
|
3751
|
-
rule.walkDecls((decl) => {
|
|
3752
|
-
if (V3_PREFLIGHT_RESET_PROPS.has(decl.prop)) found = true;
|
|
3753
|
-
});
|
|
3754
|
-
return found;
|
|
3755
|
-
}
|
|
3756
|
-
function createPreflightDeclarations(cssPreflight) {
|
|
3757
|
-
if (!cssPreflight || typeof cssPreflight !== "object") return [];
|
|
3758
|
-
return Object.entries(cssPreflight).filter((entry) => entry[1] !== false).map(([prop, value]) => postcss.decl({
|
|
3759
|
-
prop,
|
|
3760
|
-
value: value.toString()
|
|
3761
|
-
}));
|
|
3762
|
-
}
|
|
3763
|
-
function ensureMiniProgramV3PreflightReset(css, cssPreflight) {
|
|
3764
|
-
const declarations = createPreflightDeclarations(cssPreflight);
|
|
3765
|
-
if (declarations.length === 0) return css;
|
|
3766
|
-
try {
|
|
3767
|
-
const root = postcss.parse(css);
|
|
3768
|
-
let targetRule;
|
|
3769
|
-
let hasReset = false;
|
|
3770
|
-
root.walkRules((rule) => {
|
|
3771
|
-
if (!isMiniProgramV3PreflightRule(rule)) return;
|
|
3772
|
-
targetRule ?? (targetRule = rule);
|
|
3773
|
-
if (hasResetDeclaration(rule)) hasReset = true;
|
|
3774
|
-
});
|
|
3775
|
-
if (!targetRule || hasReset) return css;
|
|
3776
|
-
targetRule.append(...declarations.map((decl) => decl.clone()));
|
|
3777
|
-
return root.toString();
|
|
3778
|
-
} catch {
|
|
3779
|
-
return css;
|
|
3780
|
-
}
|
|
3781
|
-
}
|
|
3782
|
-
async function transformTailwindV3CssToWeapp(css, options) {
|
|
3783
|
-
const result = await defaultStyleHandler(hasCssMacroStyleOptions(options) ? await transformCssMacroCss(css, options) : css, {
|
|
3784
|
-
cssChildCombinatorReplaceValue: ["view", "text"],
|
|
3785
|
-
cssRemoveHoverPseudoClass: true,
|
|
3786
|
-
isMainChunk: true,
|
|
3787
|
-
majorVersion: 3,
|
|
3788
|
-
...options
|
|
3789
|
-
});
|
|
3790
|
-
const pruneOptions = {
|
|
3791
|
-
preservePreflight: true,
|
|
3792
|
-
preserveConditionalComments: hasCssMacroStyleOptions(options)
|
|
3793
|
-
};
|
|
3794
|
-
return ensureMiniProgramV3PreflightReset(pruneMiniProgramGeneratedCss(result.css, pruneOptions), options?.cssPreflight);
|
|
3795
|
-
}
|
|
3796
|
-
async function transformTailwindV3CssByTarget(css, target, options) {
|
|
3797
|
-
if (target === "weapp") return transformTailwindV3CssToWeapp(css, options);
|
|
3798
|
-
return hasCssMacroStyleOptions(options) ? transformCssMacroCss(css, options) : css;
|
|
3799
|
-
}
|
|
3800
|
-
//#endregion
|
|
3801
|
-
//#region src/tailwindcss/v3-engine/generator.ts
|
|
3802
|
-
const INCREMENTAL_GENERATE_CACHE_MAX = 8;
|
|
3803
|
-
const INCREMENTAL_GENERATE_ENTRY_CANDIDATES_MAX = 128;
|
|
3804
|
-
const INCREMENTAL_GENERATE_ENTRY_CSS_BYTES_MAX = 256 * 1024;
|
|
3805
|
-
const incrementalGenerateCache = new LRUCache({ max: INCREMENTAL_GENERATE_CACHE_MAX });
|
|
3806
|
-
const patchRawStyleGenerator = typeof tailwindcssPatch.generateTailwindV3RawStyle === "function" ? tailwindcssPatch.generateTailwindV3RawStyle : void 0;
|
|
3807
|
-
function isTailwindV3PatchResolutionError(error, packageName) {
|
|
3808
|
-
if (!error || typeof error !== "object") return false;
|
|
3809
|
-
const code = error.code;
|
|
3810
|
-
if (code !== "MODULE_NOT_FOUND" && code !== "ERR_PACKAGE_PATH_NOT_EXPORTED") return false;
|
|
3811
|
-
return String(error.message ?? "").includes(`${packageName}/lib/`);
|
|
3812
|
-
}
|
|
3813
|
-
function normalizeBareArbitraryValueCandidate(candidate, bareArbitraryValues) {
|
|
3814
|
-
return resolveBareArbitraryValueCandidate(candidate, bareArbitraryValues)?.canonicalCandidate ?? candidate;
|
|
3815
|
-
}
|
|
3816
|
-
function normalizeBareArbitraryValueCandidates(candidates, bareArbitraryValues) {
|
|
3817
|
-
const normalized = /* @__PURE__ */ new Set();
|
|
3818
|
-
const restoreCandidates = /* @__PURE__ */ new Map();
|
|
3819
|
-
for (const candidate of candidates) {
|
|
3820
|
-
const normalizedCandidate = normalizeBareArbitraryValueCandidate(candidate, bareArbitraryValues);
|
|
3821
|
-
normalized.add(normalizedCandidate);
|
|
3822
|
-
if (normalizedCandidate !== candidate) restoreCandidates.set(normalizedCandidate, candidate);
|
|
3823
|
-
}
|
|
3824
|
-
return {
|
|
3825
|
-
candidates: normalized,
|
|
3826
|
-
restoreCandidates
|
|
3827
|
-
};
|
|
3828
|
-
}
|
|
3829
|
-
async function collectSourceBareArbitraryValueCandidates(sources, bareArbitraryValues) {
|
|
3830
|
-
if (!isBareArbitraryValuesEnabled(bareArbitraryValues)) return [];
|
|
3831
|
-
const candidates = /* @__PURE__ */ new Set();
|
|
3832
|
-
for (const source of sources ?? []) for (const candidate of await extractSourceCandidates(source.content, source.extension ?? "html", omitUndefined({ bareArbitraryValues }))) if (resolveBareArbitraryValueCandidate(candidate, bareArbitraryValues)) candidates.add(candidate);
|
|
3833
|
-
return [...candidates];
|
|
3834
|
-
}
|
|
3835
|
-
function escapeCssClassSelector(className) {
|
|
3836
|
-
return className.replace(/[^\w-]/g, (char) => `\\${char}`);
|
|
3837
|
-
}
|
|
3838
|
-
function restoreBareArbitraryValueCssSelectors(css, originalCandidates, bareArbitraryValues, escapeClassName) {
|
|
3839
|
-
if (!isBareArbitraryValuesEnabled(bareArbitraryValues)) return css;
|
|
3840
|
-
let restored = css;
|
|
3841
|
-
for (const originalCandidate of originalCandidates) {
|
|
3842
|
-
const canonical = resolveBareArbitraryValueCandidate(originalCandidate, bareArbitraryValues)?.canonicalCandidate;
|
|
3843
|
-
if (canonical) restored = restored.split(`.${escapeClassName(canonical)}`).join(`.${escapeCssClassSelector(originalCandidate)}`);
|
|
3844
|
-
}
|
|
3845
|
-
return restored;
|
|
3846
|
-
}
|
|
3847
|
-
function restoreBareArbitraryValueClassSet(classSet, originalCandidates, bareArbitraryValues) {
|
|
3848
|
-
if (!isBareArbitraryValuesEnabled(bareArbitraryValues)) return new Set(classSet);
|
|
3849
|
-
const restored = new Set(classSet);
|
|
3850
|
-
for (const originalCandidate of originalCandidates) {
|
|
3851
|
-
const canonical = resolveBareArbitraryValueCandidate(originalCandidate, bareArbitraryValues)?.canonicalCandidate;
|
|
3852
|
-
if (canonical && restored.has(canonical)) {
|
|
3853
|
-
restored.delete(canonical);
|
|
3854
|
-
restored.add(originalCandidate);
|
|
3855
|
-
}
|
|
3856
|
-
}
|
|
3857
|
-
return restored;
|
|
3858
|
-
}
|
|
3859
|
-
function collectGeneratedCandidates(context, candidates, restoreCandidates) {
|
|
3860
|
-
const classSet = /* @__PURE__ */ new Set();
|
|
3861
|
-
for (const candidate of candidates) if (context.classCache.has(candidate)) classSet.add(restoreCandidates.get(candidate) ?? candidate);
|
|
3862
|
-
return classSet;
|
|
3863
|
-
}
|
|
3864
|
-
function hasRemovedCandidates(previousCandidates, nextCandidates) {
|
|
3865
|
-
for (const candidate of previousCandidates) if (!nextCandidates.has(candidate)) return true;
|
|
3866
|
-
return false;
|
|
3867
|
-
}
|
|
3868
|
-
function shouldAutoEnableCssMacro(source) {
|
|
3869
|
-
return hasCssMacroTailwindPlugin(normalizeConfigObject(source.configObject)?.plugins);
|
|
3870
|
-
}
|
|
3871
|
-
function resolveStyleOptions(source, options) {
|
|
3872
|
-
return shouldAutoEnableCssMacro(source) ? withCssMacroStyleOptions(options) : options;
|
|
3873
|
-
}
|
|
3874
|
-
function loadTailwindV3Internals(source) {
|
|
3875
|
-
const requireFromProject = createRequire(`${source.cwd}/package.json`);
|
|
3876
|
-
const requireFromRuntime = createRequire(import.meta.url);
|
|
3877
|
-
const requireTailwind = (id) => {
|
|
3878
|
-
try {
|
|
3879
|
-
return requireFromProject(id);
|
|
3880
|
-
} catch {
|
|
3881
|
-
return requireFromRuntime(id);
|
|
3882
|
-
}
|
|
3883
|
-
};
|
|
3884
|
-
const collapseAdjacentRulesModule = requireTailwind(`${source.packageName}/lib/lib/collapseAdjacentRules`);
|
|
3885
|
-
const collapseDuplicateDeclarationsModule = requireTailwind(`${source.packageName}/lib/lib/collapseDuplicateDeclarations`);
|
|
3886
|
-
const escapeClassNameModule = requireTailwind(`${source.packageName}/lib/util/escapeClassName`);
|
|
3887
|
-
const generateRulesModule = requireTailwind(`${source.packageName}/lib/lib/generateRules`);
|
|
3888
|
-
const sharedStateModule = requireTailwind(`${source.packageName}/lib/lib/sharedState`);
|
|
3889
|
-
const setupContextUtils = requireTailwind(`${source.packageName}/lib/lib/setupContextUtils`);
|
|
3890
|
-
const processTailwindFeaturesModule = requireTailwind(`${source.packageName}/lib/processTailwindFeatures`);
|
|
3891
|
-
const resolveDefaultsAtRulesModule = requireTailwind(`${source.packageName}/lib/lib/resolveDefaultsAtRules`);
|
|
3892
|
-
const resolveConfigModule = requireTailwind(`${source.packageName}/lib/public/resolve-config`);
|
|
3893
|
-
const validateConfigModule = requireTailwind(`${source.packageName}/lib/util/validateConfig.js`);
|
|
3894
|
-
return {
|
|
3895
|
-
collapseAdjacentRules: collapseAdjacentRulesModule["default"] ?? collapseAdjacentRulesModule,
|
|
3896
|
-
collapseDuplicateDeclarations: collapseDuplicateDeclarationsModule["default"] ?? collapseDuplicateDeclarationsModule,
|
|
3897
|
-
createContext: setupContextUtils["createContext"],
|
|
3898
|
-
escapeClassName: escapeClassNameModule["default"] ?? escapeClassNameModule,
|
|
3899
|
-
generateRules: generateRulesModule["generateRules"],
|
|
3900
|
-
notOnDemandCandidate: String(sharedStateModule["NOT_ON_DEMAND"] ?? "*"),
|
|
3901
|
-
processTailwindFeatures: processTailwindFeaturesModule["default"] ?? processTailwindFeaturesModule,
|
|
3902
|
-
resolveDefaultsAtRules: resolveDefaultsAtRulesModule["default"] ?? resolveDefaultsAtRulesModule,
|
|
3903
|
-
resolveConfig: resolveConfigModule["default"] ?? resolveConfigModule,
|
|
3904
|
-
validateConfig: validateConfigModule["validateConfig"]
|
|
3905
|
-
};
|
|
3906
|
-
}
|
|
3907
|
-
function isDirectUtilitiesOnlyCss(css) {
|
|
3908
|
-
return css.replace(/\s+/g, "") === "@tailwindutilities;";
|
|
3909
|
-
}
|
|
3910
|
-
function collectClassSet(context) {
|
|
3911
|
-
const classSet = /* @__PURE__ */ new Set();
|
|
3912
|
-
for (const candidate of context.classCache.keys()) if (String(candidate) !== "*") classSet.add(candidate);
|
|
3913
|
-
return classSet;
|
|
3914
|
-
}
|
|
3915
|
-
function collectDependencyMessages(result) {
|
|
3916
|
-
const dependencies = /* @__PURE__ */ new Set();
|
|
3917
|
-
for (const message of result.messages) {
|
|
3918
|
-
const file = message["file"];
|
|
3919
|
-
if (message["type"] === "dependency" && typeof file === "string") dependencies.add(file);
|
|
3920
|
-
}
|
|
3921
|
-
return dependencies;
|
|
3922
|
-
}
|
|
3923
|
-
function sortCandidates(candidates) {
|
|
3924
|
-
return [...candidates].sort((a, z) => {
|
|
3925
|
-
if (a === z) return 0;
|
|
3926
|
-
return a < z ? -1 : 1;
|
|
3927
|
-
});
|
|
3928
|
-
}
|
|
3929
|
-
function createRequestedCandidatesCacheKey(candidates) {
|
|
3930
|
-
return sortCandidates(candidates).join("\n");
|
|
3931
|
-
}
|
|
3932
|
-
function createIncrementalResultsCache() {
|
|
3933
|
-
return new LRUCache({ max: 16 });
|
|
3934
|
-
}
|
|
3935
|
-
function replaceIncrementalEntry(entry, candidates, generated) {
|
|
3936
|
-
if (!generated.context) return;
|
|
3937
|
-
entry.context = generated.context;
|
|
3938
|
-
entry.seenCandidates = new Set(candidates);
|
|
3939
|
-
entry.classSet = new Set(generated.classSet);
|
|
3940
|
-
entry.css = generated.css;
|
|
3941
|
-
entry.rawCss = generated.rawCss;
|
|
3942
|
-
entry.dependencies = generated.dependencies;
|
|
3943
|
-
entry.resultsByCandidates.clear();
|
|
3944
|
-
}
|
|
3945
|
-
function seedIncrementalResult(entry, candidates, result) {
|
|
3946
|
-
entry.resultsByCandidates.set(createRequestedCandidatesCacheKey(candidates), {
|
|
3947
|
-
classSet: new Set(result.classSet),
|
|
3948
|
-
css: result.css,
|
|
3949
|
-
rawCss: result.rawCss,
|
|
3950
|
-
dependencies: result.dependencies
|
|
3951
|
-
});
|
|
3952
|
-
}
|
|
3953
|
-
function createGenerateResultFromCache(cached, result, candidates) {
|
|
3954
|
-
return {
|
|
3955
|
-
css: result.css,
|
|
3956
|
-
rawCss: result.rawCss,
|
|
3957
|
-
incrementalCss: "",
|
|
3958
|
-
incrementalRawCss: "",
|
|
3959
|
-
classSet: new Set(result.classSet),
|
|
3960
|
-
rawCandidates: new Set(candidates),
|
|
3961
|
-
dependencies: result.dependencies,
|
|
3962
|
-
sources: [],
|
|
3963
|
-
root: null,
|
|
3964
|
-
target: cached.target,
|
|
3965
|
-
version: 3
|
|
3966
|
-
};
|
|
3967
|
-
}
|
|
3968
|
-
function shouldRebuildIncrementalEntry(cached, requestedCandidates, missingCandidates) {
|
|
3969
|
-
return cached.seenCandidates.size + missingCandidates.length > INCREMENTAL_GENERATE_ENTRY_CANDIDATES_MAX || cached.css.length > INCREMENTAL_GENERATE_ENTRY_CSS_BYTES_MAX || cached.rawCss.length > INCREMENTAL_GENERATE_ENTRY_CSS_BYTES_MAX || requestedCandidates.size > INCREMENTAL_GENERATE_ENTRY_CANDIDATES_MAX;
|
|
3970
|
-
}
|
|
3971
|
-
function appendUtilityRules(root, context, rules) {
|
|
3972
|
-
const sortedRules = context.offsets.sort(rules);
|
|
3973
|
-
for (const [sort, rule] of sortedRules) {
|
|
3974
|
-
const tailwindRaw = rule.raws.tailwind;
|
|
3975
|
-
if (sort.layer === "utilities" || sort.layer === "variants" && tailwindRaw?.parentLayer === "utilities") root.append(rule.clone());
|
|
3976
|
-
}
|
|
3977
|
-
}
|
|
3978
|
-
function appendDirectUtilityRules(root, context) {
|
|
3979
|
-
appendUtilityRules(root, context, [...context.ruleCache]);
|
|
3980
|
-
}
|
|
3981
|
-
async function generateRawStyleWithPatch(generateSource, candidates, sources) {
|
|
3982
|
-
if (!patchRawStyleGenerator) return;
|
|
3983
|
-
try {
|
|
3984
|
-
return await patchRawStyleGenerator({
|
|
3985
|
-
cwd: generateSource.cwd,
|
|
3986
|
-
packageName: generateSource.packageName,
|
|
3987
|
-
css: generateSource.css,
|
|
3988
|
-
candidates,
|
|
3989
|
-
sources,
|
|
3990
|
-
config: createTailwindConfig(generateSource, {
|
|
3991
|
-
candidates,
|
|
3992
|
-
sources
|
|
3993
|
-
}),
|
|
3994
|
-
directUtilitiesOnly: "auto"
|
|
3995
|
-
});
|
|
3996
|
-
} catch (error) {
|
|
3997
|
-
if (isTailwindV3PatchResolutionError(error, generateSource.packageName)) return;
|
|
3998
|
-
throw error;
|
|
3999
|
-
}
|
|
4000
|
-
}
|
|
4001
|
-
function createTailwindV3Engine(source) {
|
|
4002
|
-
const runtimeReadyPromise = createRuntimeReadyPromise(source);
|
|
4003
|
-
let tailwindInternals;
|
|
4004
|
-
async function generateOnce(generateSource, options = {}) {
|
|
4005
|
-
await runtimeReadyPromise;
|
|
4006
|
-
tailwindInternals ?? (tailwindInternals = loadTailwindV3Internals(source));
|
|
4007
|
-
const internals = tailwindInternals;
|
|
4008
|
-
const { styleOptions, target = "weapp" } = options;
|
|
4009
|
-
const resolvedStyleOptions = resolveStyleOptions(generateSource, styleOptions);
|
|
4010
|
-
const requestedCandidates = mergeGenerateCandidates(generateSource, options);
|
|
4011
|
-
for (const candidate of await collectSourceBareArbitraryValueCandidates(options.sources, options.bareArbitraryValues)) requestedCandidates.add(candidate);
|
|
4012
|
-
const normalizedCandidates = normalizeBareArbitraryValueCandidates(requestedCandidates, options.bareArbitraryValues);
|
|
4013
|
-
const tailwindOptions = {
|
|
4014
|
-
...options,
|
|
4015
|
-
candidates: normalizedCandidates.candidates
|
|
4016
|
-
};
|
|
4017
|
-
const tailwindConfig = internals.validateConfig(internals.resolveConfig(createTailwindConfig(generateSource, tailwindOptions)));
|
|
4018
|
-
const candidates = normalizedCandidates.candidates;
|
|
4019
|
-
const changedContent = createChangedContentEntries(candidates, options.sources ?? []);
|
|
4020
|
-
const root = postcss.parse(generateSource.css, { from: void 0 });
|
|
4021
|
-
const result = {
|
|
4022
|
-
css: "",
|
|
4023
|
-
messages: []
|
|
4024
|
-
};
|
|
4025
|
-
let context;
|
|
4026
|
-
let rawCss;
|
|
4027
|
-
let dependencies;
|
|
4028
|
-
const patchGenerated = await generateRawStyleWithPatch(generateSource, candidates, options.sources ?? []);
|
|
4029
|
-
if (patchGenerated) {
|
|
4030
|
-
context = patchGenerated.context;
|
|
4031
|
-
rawCss = restoreBareArbitraryValueCssSelectors(patchGenerated.css, requestedCandidates, options.bareArbitraryValues, internals.escapeClassName);
|
|
4032
|
-
dependencies = new Set(patchGenerated.dependencies);
|
|
4033
|
-
} else {
|
|
4034
|
-
if (isDirectUtilitiesOnlyCss(generateSource.css)) {
|
|
4035
|
-
context = internals.createContext(tailwindConfig, changedContent, root);
|
|
4036
|
-
internals.generateRules(new Set(sortCandidates([internals.notOnDemandCandidate, ...candidates])), context);
|
|
4037
|
-
root.removeAll();
|
|
4038
|
-
appendDirectUtilityRules(root, context);
|
|
4039
|
-
internals.resolveDefaultsAtRules(context)(root, result);
|
|
4040
|
-
internals.collapseAdjacentRules(context)(root, result);
|
|
4041
|
-
internals.collapseDuplicateDeclarations(context)(root, result);
|
|
4042
|
-
} else {
|
|
4043
|
-
const setupContext = () => {
|
|
4044
|
-
return (currentRoot) => internals.createContext(tailwindConfig, changedContent, currentRoot);
|
|
4045
|
-
};
|
|
4046
|
-
context = await internals.processTailwindFeatures(setupContext)(root, result);
|
|
4047
|
-
}
|
|
4048
|
-
rawCss = restoreBareArbitraryValueCssSelectors(root.toString(), requestedCandidates, options.bareArbitraryValues, internals.escapeClassName);
|
|
4049
|
-
dependencies = collectDependencyMessages(result);
|
|
4050
|
-
}
|
|
4051
|
-
const css = await transformTailwindV3CssByTarget(rawCss, target, resolvedStyleOptions);
|
|
4052
|
-
for (const dependency of generateSource.dependencies) dependencies.add(dependency);
|
|
4053
|
-
const classSet = restoreBareArbitraryValueClassSet(collectClassSet(context), requestedCandidates, options.bareArbitraryValues);
|
|
4054
|
-
return {
|
|
4055
|
-
css,
|
|
4056
|
-
rawCss,
|
|
4057
|
-
context,
|
|
4058
|
-
classSet,
|
|
4059
|
-
rawCandidates: requestedCandidates,
|
|
4060
|
-
dependencies: [...dependencies],
|
|
4061
|
-
sources: [],
|
|
4062
|
-
root: null,
|
|
4063
|
-
target,
|
|
4064
|
-
version: 3
|
|
4065
|
-
};
|
|
4066
|
-
}
|
|
4067
|
-
async function generateIncrementalMissingUtilities(context, candidates, target, styleOptions, bareArbitraryValues) {
|
|
4068
|
-
tailwindInternals ?? (tailwindInternals = loadTailwindV3Internals(source));
|
|
4069
|
-
const internals = tailwindInternals;
|
|
4070
|
-
const root = postcss.root();
|
|
4071
|
-
const result = {
|
|
4072
|
-
css: "",
|
|
4073
|
-
messages: []
|
|
4074
|
-
};
|
|
4075
|
-
const normalizedCandidates = normalizeBareArbitraryValueCandidates(candidates, bareArbitraryValues);
|
|
4076
|
-
const sortedCandidates = sortCandidates(normalizedCandidates.candidates);
|
|
4077
|
-
appendUtilityRules(root, context, internals.generateRules(new Set(sortedCandidates), context));
|
|
4078
|
-
internals.resolveDefaultsAtRules(context)(root, result);
|
|
4079
|
-
internals.collapseAdjacentRules(context)(root, result);
|
|
4080
|
-
internals.collapseDuplicateDeclarations(context)(root, result);
|
|
4081
|
-
const rawCss = restoreBareArbitraryValueCssSelectors(root.toString(), candidates, bareArbitraryValues, internals.escapeClassName);
|
|
4082
|
-
return {
|
|
4083
|
-
css: await transformTailwindV3CssByTarget(rawCss, target, resolveStyleOptions(source, styleOptions)),
|
|
4084
|
-
rawCss,
|
|
4085
|
-
classSet: collectGeneratedCandidates(context, sortedCandidates, normalizedCandidates.restoreCandidates),
|
|
4086
|
-
dependencies: collectDependencyMessages(result)
|
|
4087
|
-
};
|
|
4088
|
-
}
|
|
4089
|
-
async function generateWithIncrementalCache(options = {}) {
|
|
4090
|
-
if ((options.sources?.length ?? 0) > 0) return generateOnce(source, options);
|
|
4091
|
-
const target = options.target ?? "weapp";
|
|
4092
|
-
const requestedCandidates = mergeGenerateCandidates(source, options);
|
|
4093
|
-
if (requestedCandidates.size === 0) return generateOnce(source, options);
|
|
4094
|
-
const styleOptions = resolveStyleOptions(source, options.styleOptions);
|
|
4095
|
-
const cacheKey = createIncrementalGenerateCacheKey$1(source, target, styleOptions, options.bareArbitraryValues);
|
|
4096
|
-
const cached = incrementalGenerateCache.get(cacheKey);
|
|
4097
|
-
if (cached) {
|
|
4098
|
-
if (hasRemovedCandidates(cached.seenCandidates, requestedCandidates)) {
|
|
4099
|
-
const generated = await generateOnce(source, options);
|
|
4100
|
-
replaceIncrementalEntry(cached, requestedCandidates, generated);
|
|
4101
|
-
seedIncrementalResult(cached, requestedCandidates, generated);
|
|
4102
|
-
return generated;
|
|
4103
|
-
}
|
|
4104
|
-
const requestedCacheKey = createRequestedCandidatesCacheKey(requestedCandidates);
|
|
4105
|
-
const cachedResult = cached.resultsByCandidates.get(requestedCacheKey);
|
|
4106
|
-
if (cachedResult) return createGenerateResultFromCache(cached, cachedResult, requestedCandidates);
|
|
4107
|
-
const missingCandidates = [...requestedCandidates].filter((candidate) => !cached.seenCandidates.has(candidate));
|
|
4108
|
-
if (missingCandidates.length === 0) {
|
|
4109
|
-
seedIncrementalResult(cached, requestedCandidates, cached);
|
|
4110
|
-
return createGenerateResultFromCache(cached, cached, requestedCandidates);
|
|
4111
|
-
}
|
|
4112
|
-
if (shouldRebuildIncrementalEntry(cached, requestedCandidates, missingCandidates)) {
|
|
4113
|
-
const generated = await generateOnce(source, options);
|
|
4114
|
-
replaceIncrementalEntry(cached, requestedCandidates, generated);
|
|
4115
|
-
seedIncrementalResult(cached, requestedCandidates, generated);
|
|
4116
|
-
return generated;
|
|
4117
|
-
}
|
|
4118
|
-
const generated = await generateIncrementalMissingUtilities(cached.context, missingCandidates, target, styleOptions, options.bareArbitraryValues);
|
|
4119
|
-
for (const candidate of missingCandidates) cached.seenCandidates.add(candidate);
|
|
4120
|
-
for (const className of generated.classSet) cached.classSet.add(className);
|
|
4121
|
-
cached.css = [cached.css, generated.css].filter(Boolean).join("\n");
|
|
4122
|
-
cached.rawCss = [cached.rawCss, generated.rawCss].filter(Boolean).join("\n");
|
|
4123
|
-
cached.dependencies = [...new Set([...cached.dependencies, ...generated.dependencies])];
|
|
4124
|
-
const result = {
|
|
4125
|
-
css: cached.css,
|
|
4126
|
-
rawCss: cached.rawCss,
|
|
4127
|
-
incrementalCss: generated.css,
|
|
4128
|
-
incrementalRawCss: generated.rawCss,
|
|
4129
|
-
classSet: new Set(cached.classSet),
|
|
4130
|
-
rawCandidates: new Set(cached.seenCandidates),
|
|
4131
|
-
dependencies: cached.dependencies,
|
|
4132
|
-
sources: [],
|
|
4133
|
-
root: null,
|
|
4134
|
-
target: cached.target,
|
|
4135
|
-
version: 3
|
|
4136
|
-
};
|
|
4137
|
-
seedIncrementalResult(cached, requestedCandidates, result);
|
|
4138
|
-
return result;
|
|
4139
|
-
}
|
|
4140
|
-
const generated = await generateOnce(source, options);
|
|
4141
|
-
const resultsByCandidates = createIncrementalResultsCache();
|
|
4142
|
-
const entry = {
|
|
4143
|
-
context: generated.context,
|
|
4144
|
-
seenCandidates: new Set(requestedCandidates),
|
|
4145
|
-
classSet: new Set(generated.classSet),
|
|
4146
|
-
css: generated.css,
|
|
4147
|
-
rawCss: generated.rawCss,
|
|
4148
|
-
dependencies: generated.dependencies,
|
|
4149
|
-
resultsByCandidates,
|
|
4150
|
-
target: generated.target
|
|
4151
|
-
};
|
|
4152
|
-
seedIncrementalResult(entry, requestedCandidates, generated);
|
|
4153
|
-
incrementalGenerateCache.set(cacheKey, entry);
|
|
4154
|
-
return generated;
|
|
4155
|
-
}
|
|
4156
|
-
async function generate(options = {}) {
|
|
4157
|
-
return options.incrementalCache ? generateWithIncrementalCache(options) : generateOnce(source, options);
|
|
4158
|
-
}
|
|
4159
|
-
return {
|
|
4160
|
-
source,
|
|
4161
|
-
async validateCandidates(candidates) {
|
|
4162
|
-
return (await generate({
|
|
4163
|
-
candidates,
|
|
4164
|
-
incrementalCache: true,
|
|
4165
|
-
target: "tailwind"
|
|
4166
|
-
})).classSet;
|
|
4167
|
-
},
|
|
4168
|
-
generate
|
|
4169
|
-
};
|
|
4170
|
-
}
|
|
4171
|
-
function getTailwindV3IncrementalGenerateCacheStats() {
|
|
4172
|
-
return {
|
|
4173
|
-
max: INCREMENTAL_GENERATE_CACHE_MAX,
|
|
4174
|
-
entryCandidatesMax: INCREMENTAL_GENERATE_ENTRY_CANDIDATES_MAX,
|
|
4175
|
-
entryCssBytesMax: INCREMENTAL_GENERATE_ENTRY_CSS_BYTES_MAX,
|
|
4176
|
-
size: incrementalGenerateCache.size,
|
|
4177
|
-
entries: [...incrementalGenerateCache.entries()].map(([key, entry]) => ({
|
|
4178
|
-
key,
|
|
4179
|
-
candidates: entry.seenCandidates.size,
|
|
4180
|
-
classSet: entry.classSet.size,
|
|
4181
|
-
cssBytes: entry.css.length,
|
|
4182
|
-
rawCssBytes: entry.rawCss.length,
|
|
4183
|
-
exactResults: entry.resultsByCandidates.size
|
|
4184
|
-
})),
|
|
4185
|
-
keys: [...incrementalGenerateCache.keys()]
|
|
4186
|
-
};
|
|
4187
|
-
}
|
|
4188
|
-
//#endregion
|
|
4189
|
-
//#region src/tailwindcss/v3-engine/source.ts
|
|
4190
|
-
const DEFAULT_TAILWIND_V3_CSS = [
|
|
4191
|
-
"@tailwind base;",
|
|
4192
|
-
"@tailwind components;",
|
|
4193
|
-
"@tailwind utilities;"
|
|
4194
|
-
].join("\n");
|
|
4195
|
-
function parseConfigParam(params) {
|
|
4196
|
-
const value = params.trim();
|
|
4197
|
-
return /^(['"])(.+)\1$/.exec(value)?.[2];
|
|
4198
|
-
}
|
|
4199
|
-
function resolveOptionalPath(value, base) {
|
|
4200
|
-
if (!value) return;
|
|
4201
|
-
return path.isAbsolute(value) ? value : path.resolve(base, value);
|
|
4202
|
-
}
|
|
4203
|
-
function resolveCssConfig(css, base) {
|
|
4204
|
-
if (!css) return {
|
|
4205
|
-
css,
|
|
4206
|
-
config: void 0
|
|
4207
|
-
};
|
|
4208
|
-
const root = postcss.parse(css);
|
|
4209
|
-
let config;
|
|
4210
|
-
root.walkAtRules("config", (rule) => {
|
|
4211
|
-
const configPath = parseConfigParam(rule.params);
|
|
4212
|
-
if (!configPath) return;
|
|
4213
|
-
if (!config) config = resolveOptionalPath(configPath, base);
|
|
4214
|
-
rule.remove();
|
|
4215
|
-
});
|
|
4216
|
-
return {
|
|
4217
|
-
config,
|
|
4218
|
-
css: root.toString()
|
|
4219
|
-
};
|
|
4220
|
-
}
|
|
4221
|
-
function getProjectRoot(patcher) {
|
|
4222
|
-
return patcher.options?.projectRoot ?? process.cwd();
|
|
4223
|
-
}
|
|
4224
|
-
function normalizeLoadedConfig(config) {
|
|
4225
|
-
if (!config || typeof config !== "object") return config;
|
|
4226
|
-
const maybeDefault = config.default;
|
|
4227
|
-
if (maybeDefault && typeof maybeDefault === "object") return maybeDefault;
|
|
4228
|
-
return config;
|
|
4229
|
-
}
|
|
4230
|
-
function resolveTailwindCssPackageName(patcher) {
|
|
4231
|
-
return resolveTailwindcssOptions(patcher.options)?.packageName ?? patcher.packageInfo?.name ?? "tailwindcss";
|
|
4232
|
-
}
|
|
4233
|
-
async function resolveTailwindV3Source(options = {}) {
|
|
4234
|
-
const projectRoot = options.projectRoot ?? process.cwd();
|
|
4235
|
-
const base = options.base ?? options.cwd ?? projectRoot;
|
|
4236
|
-
const cssConfig = resolveCssConfig(options.css, base);
|
|
4237
|
-
const config = resolveOptionalPath(options.config, base) ?? cssConfig.config;
|
|
4238
|
-
const cwd = options.cwd ?? (config ? path.dirname(config) : projectRoot);
|
|
4239
|
-
const explicitConfigObject = normalizeLoadedConfig(options.configObject);
|
|
4240
|
-
const loaded = await loadConfig(omitUndefined({
|
|
4241
|
-
config,
|
|
4242
|
-
cwd
|
|
4243
|
-
}));
|
|
4244
|
-
return {
|
|
4245
|
-
version: 3,
|
|
4246
|
-
projectRoot,
|
|
4247
|
-
cwd,
|
|
4248
|
-
base,
|
|
4249
|
-
css: cssConfig.css ?? options.css ?? DEFAULT_TAILWIND_V3_CSS,
|
|
4250
|
-
config: loaded?.filepath ?? config,
|
|
4251
|
-
configObject: explicitConfigObject ?? normalizeLoadedConfig(loaded?.config),
|
|
4252
|
-
dependencies: loaded?.filepath ? [loaded.filepath] : [],
|
|
4253
|
-
packageName: options.packageName ?? "tailwindcss",
|
|
4254
|
-
postcssPlugin: options.postcssPlugin ?? options.packageName ?? "tailwindcss"
|
|
4255
|
-
};
|
|
4256
|
-
}
|
|
4257
|
-
function resolveTailwindV3SourceOptionsFromPatcher(patcher) {
|
|
4258
|
-
const projectRoot = getProjectRoot(patcher);
|
|
4259
|
-
const tailwindOptions = resolveTailwindcssOptions(patcher.options);
|
|
4260
|
-
return {
|
|
4261
|
-
projectRoot,
|
|
4262
|
-
cwd: tailwindOptions?.v3?.cwd ?? tailwindOptions?.cwd ?? projectRoot,
|
|
4263
|
-
config: tailwindOptions?.v3?.config ?? tailwindOptions?.config,
|
|
4264
|
-
packageName: resolveTailwindCssPackageName(patcher),
|
|
4265
|
-
postcssPlugin: tailwindOptions?.v3?.postcssPlugin ?? tailwindOptions?.postcssPlugin
|
|
4266
|
-
};
|
|
4267
|
-
}
|
|
4268
|
-
function resolveTailwindV3SourceFromPatcher(patcher) {
|
|
4269
|
-
return resolveTailwindV3Source(resolveTailwindV3SourceOptionsFromPatcher(patcher));
|
|
4270
|
-
}
|
|
4271
|
-
//#endregion
|
|
4272
|
-
export { loadTailwindV4DesignSystem as $, normalizeTailwindSourceDirectives as A, splitGeneratorPlaceholderCssBySourceOrder as B, resolveTailwindV4SourceFromPatcher as C, hasTailwindRootDirectives as D, hasTailwindApplyDirective as E, resolveCssEntrySource as F, stripTailwindBanners as G, splitTailwindV4GeneratedCssBySourceOrder as H, VITE_MARKER_RE as I, createTailwindV4Engine$1 as J, normalizeConfigDirective as K, createCssAppend as L, normalizeTailwindV3CssEntrySource as M, parseImportRequest as N, hasTailwindSourceDirectives as O, removeTailwindSourceDirectives as P, filterUnsupportedMiniProgramTailwindV4Candidates as Q, hasTailwindGeneratedCss as R, resolveTailwindV4SourceFromPatchOptions as S, hasLocalCssImport as T, stripGeneratorPlaceholderMarkers as U, splitTailwindGeneratedCssByBanner as V, stripTailwindBanner as W, transformTailwindV4CssByTarget as X, getTailwindV4IncrementalGenerateCacheStats as Y, transformTailwindV4CssToWeapp as Z, resolveTailwindConfigEntriesFromCssCached as _, getTailwindV3IncrementalGenerateCacheStats as a, toPosixPath as at, resolveViteTailwindV4CssDependencies as b, ensureTailwindcssRuntimePatch as c, readInstalledPackageMajorVersion as ct, getRuntimeClassSetSignatureWithSources as d, normalizeStringListOption as dt, FULL_SOURCE_SCAN_EXTENSION_RE as et, invalidateRuntimeClassSet as f, resolveBooleanObjectOption as ft, discoverTailwindV4CssEntries as g, omitUndefined as gt, resolveViteSourceScanEntries as h, findWorkspaceRoot as ht, createTailwindV3Engine as i, resolveTailwindV4CssSourceBase as it, normalizeTailwindSourceForGenerator as j, normalizeTailwindConfigDirectives as k, getRuntimeClassSetCacheEntry as l, findTailwindConfig as lt, createViteSourceScanMatcher as m, findWorkspacePackageDir as mt, resolveTailwindV3SourceFromPatcher as n, normalizeLegacyContentEntries as nt, transformTailwindV3CssByTarget as o, createDebug as ot, runtimeSignaturePatchersSymbol as p, findNearestPackageRoot as pt, prependConfigDirective as q, resolveTailwindV3SourceOptionsFromPatcher as r, resolveSourceScanPath as rt, transformTailwindV3CssToWeapp as s, createTailwindcssPatcher as st, resolveTailwindV3Source as t, isFileMatchedByTailwindSourceEntries as tt, getRuntimeClassSetSignature as u, resolveTailwindcssOptions as ut, resolveTailwindV4EntriesFromCss as v, resolveTailwindV4SourceOptionsFromPatcher as w, resolveTailwindV4Source$1 as x, resolveTailwindV4EntriesFromCssCached as y, hasTailwindGeneratedCssMarkers as z };
|