weapp-tailwindcss 5.1.15 → 5.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundlers/gulp/shared/create-native-framework-plugins/cache-state.d.ts +71 -0
- package/dist/bundlers/gulp/shared/create-native-framework-plugins/file-transforms.d.ts +43 -0
- package/dist/bundlers/gulp/shared/create-native-framework-plugins.d.ts +2 -2
- package/dist/bundlers/shared/framework-postcss.d.ts +14 -0
- package/dist/bundlers/shared/generator-css/generation-helpers/preflight.d.ts +18 -0
- package/dist/bundlers/shared/generator-css/generation-helpers/results.d.ts +25 -0
- package/dist/bundlers/shared/generator-css/generation-helpers/runtime-isolation.d.ts +30 -0
- package/dist/bundlers/shared/generator-css/generation-helpers/source-order.d.ts +2 -0
- package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +4 -72
- package/dist/bundlers/shared/generator-css/legacy-compat.d.ts +3 -1
- package/dist/bundlers/shared/generator-css/pipeline/deferred-output.d.ts +14 -0
- package/dist/bundlers/shared/generator-css/pipeline/execution.d.ts +12 -0
- package/dist/bundlers/shared/generator-css/pipeline/fallback-output.d.ts +12 -0
- package/dist/bundlers/shared/generator-css/pipeline/ordered-output.d.ts +25 -0
- package/dist/bundlers/shared/generator-css/pipeline.d.ts +2 -0
- package/dist/bundlers/shared/generator-css/result-helpers.d.ts +6 -0
- package/dist/bundlers/shared/generator-css/scoped-rules.d.ts +1 -0
- package/dist/bundlers/shared/generator-css/source-resolver/configuration.d.ts +33 -0
- package/dist/bundlers/shared/generator-css/source-resolver/resolve-source.d.ts +4 -0
- package/dist/bundlers/shared/generator-css/source-resolver/resolve-sources.d.ts +4 -0
- package/dist/bundlers/shared/generator-css/source-resolver/single-source.d.ts +16 -0
- package/dist/bundlers/shared/generator-css/source-resolver/source-entries.d.ts +3 -0
- package/dist/bundlers/shared/generator-css/source-resolver/source-matching.d.ts +5 -0
- package/dist/bundlers/shared/generator-css/source-resolver.d.ts +3 -6
- package/dist/bundlers/shared/generator-css/user-css/apply-only.d.ts +9 -0
- package/dist/bundlers/shared/generator-css/user-css/at-rules.d.ts +3 -0
- package/dist/bundlers/shared/generator-css/user-css/generated-cleanup.d.ts +4 -0
- package/dist/bundlers/shared/generator-css/user-css/source-fragments.d.ts +9 -0
- package/dist/bundlers/shared/generator-css/user-css/transform.d.ts +10 -0
- package/dist/bundlers/shared/generator-css/user-css/user-layers.d.ts +15 -0
- package/dist/bundlers/shared/generator-css/user-css.d.ts +5 -33
- package/dist/bundlers/shared/generator-css.d.ts +1 -2
- package/dist/bundlers/shared/v4-generation-core.d.ts +3 -0
- package/dist/bundlers/vite/css-finalizer/options.d.ts +54 -0
- package/dist/bundlers/vite/css-finalizer/plugin.d.ts +3 -0
- package/dist/bundlers/vite/css-finalizer.d.ts +1 -43
- package/dist/bundlers/vite/generate-bundle/finalize/bundle.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/finalize/root-import-shell.d.ts +69 -0
- package/dist/bundlers/vite/generate-bundle/finalize.d.ts +2 -70
- package/dist/bundlers/vite/generate-bundle-runtime.d.ts +6 -0
- package/dist/bundlers/vite/generate-bundle.d.ts +1 -1
- package/dist/bundlers/vite/processed-css-assets/cleanup.d.ts +12 -0
- package/dist/bundlers/vite/processed-css-assets/collector.d.ts +4 -0
- package/dist/bundlers/vite/processed-css-assets/coverage.d.ts +34 -0
- package/dist/bundlers/vite/processed-css-assets/injection-plan.d.ts +42 -0
- package/dist/bundlers/vite/processed-css-assets/markers-imports.d.ts +89 -0
- package/dist/bundlers/vite/processed-css-assets/style-files.d.ts +3 -0
- package/dist/bundlers/vite/processed-css-assets.d.ts +4 -71
- package/dist/bundlers/vite/rewrite-css-imports.d.ts +1 -0
- package/dist/bundlers/vite/serve-css-generation.d.ts +1 -0
- package/dist/bundlers/vite/shared/create-framework-plugins-runtime.d.ts +2 -0
- package/dist/bundlers/vite/shared/create-framework-plugins.d.ts +4 -4
- package/dist/bundlers/vite/source-candidates/collector.d.ts +8 -0
- package/dist/bundlers/vite/source-candidates/store.d.ts +2 -0
- package/dist/bundlers/vite/source-candidates/types-and-cache.d.ts +69 -0
- package/dist/bundlers/vite/source-candidates.d.ts +4 -68
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/finalize-assets.d.ts +2 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/generated-css-result.d.ts +3 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/generated-css-task.d.ts +2 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/html-js-tasks.d.ts +5 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/finalize.d.ts +30 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/generated-css.d.ts +8 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/memory-trace.d.ts +78 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/preflight-runtime.d.ts +43 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/resources.d.ts +30 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/runtime-candidates.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/sources.d.ts +28 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/user-css-markers.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/user-css.d.ts +21 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.d.ts +9 -219
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/processed-css-task.d.ts +4 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +4 -0
- package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +5 -0
- package/dist/bundlers/webpack/shared/create-framework-plugin/plugin.d.ts +20 -0
- package/dist/bundlers/webpack/shared/create-framework-plugin/watch-output.d.ts +13 -0
- package/dist/bundlers/webpack/shared/create-framework-plugin.d.ts +3 -21
- package/dist/cli.js +14 -18
- package/dist/cli.mjs +14 -18
- package/dist/{context-VeFq_8vW.js → context-BtLIID4m.js} +3 -3
- package/dist/{context-BgGWVAmN.mjs → context-JzwzSX36.mjs} +3 -3
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/{generator-CEnUsjed.js → generator-B91GhUJQ.js} +636 -505
- package/dist/{generator-CEo920So.mjs → generator-Bv7myuhY.mjs} +556 -431
- package/dist/generator.js +1 -1
- package/dist/generator.mjs +1 -1
- package/dist/{gulp-DP71z1jG.mjs → gulp-CKSklPlH.mjs} +217 -186
- package/dist/{gulp-3m1dAiig.js → gulp-Q1wITegn.js} +217 -186
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{hmr-timing-1aS6--U7.mjs → hmr-timing-BXg7nI8N.mjs} +3411 -3276
- package/dist/{hmr-timing-B8p4f0ca.js → hmr-timing-CMPaWn9P.js} +3425 -3278
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/postcss.js +1 -1
- package/dist/postcss.mjs +1 -1
- package/dist/presets.js +1 -1
- package/dist/presets.mjs +1 -1
- package/dist/rspack.js +1 -1
- package/dist/rspack.mjs +1 -1
- package/dist/shared/mpx-plugin-owner.d.ts +2 -0
- package/dist/{source-candidate-scan-signature-BAahhiwb.js → source-candidate-scan-signature-BKZZk_e6.js} +144 -4
- package/dist/{source-candidate-scan-signature-Cf7259PR.mjs → source-candidate-scan-signature-CtK-mB_C.mjs} +127 -4
- package/dist/tailwindcss/v4-engine/generator/cache-stats.d.ts +26 -0
- package/dist/tailwindcss/v4-engine/generator/engine.d.ts +2 -0
- package/dist/tailwindcss/v4-engine/generator/incremental-cache.d.ts +52 -0
- package/dist/tailwindcss/v4-engine/generator.d.ts +2 -28
- package/dist/{tailwindcss-KBYPJ2DW.js → tailwindcss-B4phC0kB.js} +2 -2
- package/dist/{tailwindcss-xs704TRw.mjs → tailwindcss-BTcXX8Ka.mjs} +2 -2
- package/dist/{vite-nXZEiwG0.mjs → vite-BwQWl9ft.mjs} +806 -692
- package/dist/{vite-DUVjMduj.js → vite-DhVnXvAQ.js} +805 -691
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-generation-loader.js +1 -1
- package/dist/{weapp-tw-css-import-rewrite-loader-DNk0IxAt.js → weapp-tw-css-import-rewrite-loader-B0tVkJLH.js} +2410 -2084
- package/dist/weapp-tw-css-import-rewrite-loader.js +1 -1
- package/dist/weapp-tw-runtime-classset-loader.js +10 -4
- package/dist/{webpack-C_UUFRgj.mjs → webpack-Bo1QrFPf.mjs} +1387 -1114
- package/dist/{webpack-nppysF4B.js → webpack-kh78iMSS.js} +1386 -1113
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +9 -7
|
@@ -66,6 +66,217 @@ function filterUnsupportedMiniProgramTailwindV4Candidates(candidates) {
|
|
|
66
66
|
return new Set([...candidates].filter((candidate) => !isUnsupportedMiniProgramTailwindV4Candidate(candidate)));
|
|
67
67
|
}
|
|
68
68
|
//#endregion
|
|
69
|
+
//#region src/tailwindcss/v4-engine/generator/rpx-candidates.ts
|
|
70
|
+
const RPX_LENGTH_UTILITY_PATTERN = String.raw`text|border(?:-[trblxyse])?|bg|outline|ring`;
|
|
71
|
+
const BARE_RPX_LENGTH_CANDIDATE_RE = new RegExp(String.raw`(^|:)(!?)(${RPX_LENGTH_UTILITY_PATTERN})-\[([-+]?(?:\d+|\d*\.\d+)rpx)\](.*)$`, "u");
|
|
72
|
+
const BARE_RPX_LENGTH_HINT_CANDIDATE_RE = new RegExp(String.raw`(?:^|:)!?(${RPX_LENGTH_UTILITY_PATTERN})-\[length:([-+]?(?:\d+|\d*\.\d+)rpx)\].*$`, "u");
|
|
73
|
+
const RPX_LENGTH_SELECTOR_RE = new RegExp(String.raw`(${RPX_LENGTH_UTILITY_PATTERN})-\\\[length\\:((?:\\[.+-]|[+\-.\d])+rpx)\\\]`, "g");
|
|
74
|
+
function normalizeRpxLengthCandidate(candidate) {
|
|
75
|
+
return candidate.replace(BARE_RPX_LENGTH_CANDIDATE_RE, (_match, prefix, important, utility, value, suffix) => {
|
|
76
|
+
return `${prefix}${important}${utility}-[length:${value}]${suffix}`;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function normalizeRpxLengthCandidates(candidates) {
|
|
80
|
+
const normalized = /* @__PURE__ */ new Set();
|
|
81
|
+
const restoreCandidates = /* @__PURE__ */ new Map();
|
|
82
|
+
for (const candidate of candidates) {
|
|
83
|
+
const normalizedCandidate = normalizeRpxLengthCandidate(candidate);
|
|
84
|
+
normalized.add(normalizedCandidate);
|
|
85
|
+
if (normalizedCandidate !== candidate) restoreCandidates.set(normalizedCandidate, candidate);
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
candidates: normalized,
|
|
89
|
+
restoreCandidates
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function restoreRpxLengthCandidates(candidates, restoreCandidates) {
|
|
93
|
+
if (restoreCandidates.size === 0) return new Set(candidates);
|
|
94
|
+
return new Set([...candidates].map((candidate) => restoreCandidates.get(candidate) ?? candidate));
|
|
95
|
+
}
|
|
96
|
+
function normalizeCssEscapedRpxSelectorValue(value) {
|
|
97
|
+
return value.replace(/\\([.+-])/g, "$1");
|
|
98
|
+
}
|
|
99
|
+
function restoreRpxLengthCssSelectors(css, restoreCandidates) {
|
|
100
|
+
if (restoreCandidates.size === 0 || !css.includes("\\[length\\:")) return css;
|
|
101
|
+
const restoredUtilities = new Set([...restoreCandidates.keys()].map((candidate) => {
|
|
102
|
+
const match = BARE_RPX_LENGTH_HINT_CANDIDATE_RE.exec(candidate);
|
|
103
|
+
return match ? `${match[1]}:${match[2]}` : void 0;
|
|
104
|
+
}).filter((value) => Boolean(value)));
|
|
105
|
+
return css.replace(RPX_LENGTH_SELECTOR_RE, (match, utility, value) => {
|
|
106
|
+
return restoredUtilities.has(`${utility}:${normalizeCssEscapedRpxSelectorValue(value)}`) ? `${utility}-\\[${value}\\]` : match;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
const INCREMENTAL_GENERATE_ENTRY_CANDIDATES_MAX = 12e3;
|
|
110
|
+
const INCREMENTAL_GENERATE_ENTRY_CSS_BYTES_MAX = 2 * 1024 * 1024;
|
|
111
|
+
const incrementalGenerateCache = new lru_cache.LRUCache({ max: 8 });
|
|
112
|
+
const incrementalGenerateTaskCache = new lru_cache.LRUCache({ max: 32 });
|
|
113
|
+
function collectCandidates(candidates) {
|
|
114
|
+
return new Set(candidates ?? []);
|
|
115
|
+
}
|
|
116
|
+
function hasRemovedCandidates(previousCandidates, nextCandidates) {
|
|
117
|
+
for (const candidate of previousCandidates) if (!nextCandidates.has(candidate)) return true;
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
function createStableJson(value) {
|
|
121
|
+
if (value === void 0) return "undefined";
|
|
122
|
+
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
123
|
+
if (Array.isArray(value)) return `[${value.map((item) => createStableJson(item)).join(",")}]`;
|
|
124
|
+
return `{${Object.keys(value).sort().map((key) => {
|
|
125
|
+
const record = value;
|
|
126
|
+
return `${JSON.stringify(key)}:${createStableJson(record[key])}`;
|
|
127
|
+
}).join(",")}}`;
|
|
128
|
+
}
|
|
129
|
+
function createDependencyFingerprint(files) {
|
|
130
|
+
return files.map((file) => {
|
|
131
|
+
try {
|
|
132
|
+
const stat = node_fs.default.statSync(file);
|
|
133
|
+
return `${file}:${stat.size}:${stat.mtimeMs}`;
|
|
134
|
+
} catch {
|
|
135
|
+
return `${file}:missing`;
|
|
136
|
+
}
|
|
137
|
+
}).join("|");
|
|
138
|
+
}
|
|
139
|
+
function createIncrementalGenerateCacheKey(source, target, styleOptions) {
|
|
140
|
+
return [
|
|
141
|
+
source.projectRoot,
|
|
142
|
+
source.base,
|
|
143
|
+
createStableJson(source.baseFallbacks),
|
|
144
|
+
source.css,
|
|
145
|
+
createDependencyFingerprint(source.dependencies),
|
|
146
|
+
target,
|
|
147
|
+
createStableJson(styleOptions)
|
|
148
|
+
].join("\0");
|
|
149
|
+
}
|
|
150
|
+
function createIncrementalGenerateTaskCacheKey(cacheKey, requestedCandidates, scanSources) {
|
|
151
|
+
return [
|
|
152
|
+
cacheKey,
|
|
153
|
+
scanSources === true ? "scan:1" : "scan:0",
|
|
154
|
+
[...requestedCandidates].sort().join("\n")
|
|
155
|
+
].join("\0");
|
|
156
|
+
}
|
|
157
|
+
function runIncrementalGenerateTask(cacheKey, requestedCandidates, scanSources, task) {
|
|
158
|
+
const taskKey = createIncrementalGenerateTaskCacheKey(cacheKey, requestedCandidates, scanSources);
|
|
159
|
+
const cachedTask = incrementalGenerateTaskCache.get(taskKey);
|
|
160
|
+
if (cachedTask) return cachedTask;
|
|
161
|
+
const promise = task();
|
|
162
|
+
incrementalGenerateTaskCache.set(taskKey, promise);
|
|
163
|
+
promise.finally(() => {
|
|
164
|
+
if (incrementalGenerateTaskCache.get(taskKey) === promise) incrementalGenerateTaskCache.delete(taskKey);
|
|
165
|
+
});
|
|
166
|
+
return promise;
|
|
167
|
+
}
|
|
168
|
+
function createIncrementalDesignSystemPromise(source, cacheKey) {
|
|
169
|
+
const promise = (0, _tailwindcss_mangle_engine.loadTailwindV4DesignSystem)(source);
|
|
170
|
+
promise.catch(() => {
|
|
171
|
+
if (incrementalGenerateCache.get(cacheKey)?.designSystemPromise === promise) incrementalGenerateCache.delete(cacheKey);
|
|
172
|
+
});
|
|
173
|
+
return promise;
|
|
174
|
+
}
|
|
175
|
+
function resolveTargetCandidates(candidates, target) {
|
|
176
|
+
const collected = collectCandidates(candidates);
|
|
177
|
+
return target === "weapp" ? filterUnsupportedMiniProgramTailwindV4Candidates(collected) : collected;
|
|
178
|
+
}
|
|
179
|
+
function collectSeenCandidates(generated) {
|
|
180
|
+
return new Set(generated.classSet);
|
|
181
|
+
}
|
|
182
|
+
function shouldDelegateWebSourceScanToTailwind(target, scanSources) {
|
|
183
|
+
return target === "web" && scanSources !== false;
|
|
184
|
+
}
|
|
185
|
+
function createIncrementalStyleOptions(styleOptions) {
|
|
186
|
+
return {
|
|
187
|
+
...styleOptions,
|
|
188
|
+
isMainChunk: false
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
function resolveStyleOptions(source, options) {
|
|
192
|
+
return (0, _weapp_tailwindcss_postcss.hasCssMacroTailwindV4Source)(source.css) ? (0, _weapp_tailwindcss_postcss.withCssMacroStyleOptions)(options) : options;
|
|
193
|
+
}
|
|
194
|
+
function collectCustomPropertyValues(css) {
|
|
195
|
+
const values = /* @__PURE__ */ new Map();
|
|
196
|
+
try {
|
|
197
|
+
_weapp_tailwindcss_postcss.postcss.parse(css).walkDecls((decl) => {
|
|
198
|
+
if (decl.prop.startsWith("--")) values.set(decl.prop, decl.value.trim());
|
|
199
|
+
});
|
|
200
|
+
} catch {}
|
|
201
|
+
return values;
|
|
202
|
+
}
|
|
203
|
+
function mergeCustomPropertyValues(target, css) {
|
|
204
|
+
for (const [prop, value] of collectCustomPropertyValues(css)) target.set(prop, value);
|
|
205
|
+
}
|
|
206
|
+
function createStableTextSignature(input) {
|
|
207
|
+
let hash = 2166136261;
|
|
208
|
+
for (let i = 0; i < input.length; i++) {
|
|
209
|
+
hash ^= input.charCodeAt(i);
|
|
210
|
+
hash = Math.imul(hash, 16777619);
|
|
211
|
+
}
|
|
212
|
+
return (hash >>> 0).toString(36);
|
|
213
|
+
}
|
|
214
|
+
function summarizeIncrementalCacheKey(key) {
|
|
215
|
+
return {
|
|
216
|
+
keyHash: createStableTextSignature(key),
|
|
217
|
+
keyBytes: key.length
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
function shouldRebuildIncrementalEntry(cached, requestedCandidates, missingCandidates) {
|
|
221
|
+
return cached.seenCandidates.size + missingCandidates.length > 12e3 || cached.css.length > 2097152 || cached.rawCss.length > 2097152 || requestedCandidates.size > 12e3;
|
|
222
|
+
}
|
|
223
|
+
function shouldAdmitIncrementalEntry(requestedCandidates, generated) {
|
|
224
|
+
return requestedCandidates.size <= 12e3 && generated.css.length <= 2097152 && generated.rawCss.length <= 2097152;
|
|
225
|
+
}
|
|
226
|
+
function seedIncrementalGenerateCache(options) {
|
|
227
|
+
if (!shouldAdmitIncrementalEntry(options.requestedCandidates, options.generated)) return false;
|
|
228
|
+
const cacheKey = createIncrementalGenerateCacheKey(options.compatibleSource, options.target, options.styleOptions);
|
|
229
|
+
const customPropertyValues = collectCustomPropertyValues(options.compatibleSource.css);
|
|
230
|
+
mergeCustomPropertyValues(customPropertyValues, options.generated.css);
|
|
231
|
+
incrementalGenerateCache.set(cacheKey, {
|
|
232
|
+
seenCandidates: collectSeenCandidates(options.generated),
|
|
233
|
+
classSet: new Set(options.generated.classSet),
|
|
234
|
+
css: options.generated.css,
|
|
235
|
+
rawCss: options.generated.rawCss,
|
|
236
|
+
customPropertyValues,
|
|
237
|
+
designSystemPromise: createIncrementalDesignSystemPromise(options.compatibleSource, cacheKey),
|
|
238
|
+
dependencies: options.generated.dependencies,
|
|
239
|
+
sources: options.generated.sources,
|
|
240
|
+
root: options.generated.root,
|
|
241
|
+
target: options.generated.target
|
|
242
|
+
});
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
function shouldNormalizeRpxLengthCandidatesForTarget(target, styleOptions) {
|
|
246
|
+
if (target !== "web") return true;
|
|
247
|
+
return styleOptions?.appType === "uni-app-vite" || shouldUseWebGeneratorTargetFromEnv();
|
|
248
|
+
}
|
|
249
|
+
function normalizeTargetRpxLengthCandidates(candidates, target, styleOptions) {
|
|
250
|
+
return shouldNormalizeRpxLengthCandidatesForTarget(target, styleOptions) ? normalizeRpxLengthCandidates(candidates) : {
|
|
251
|
+
candidates: new Set(candidates),
|
|
252
|
+
restoreCandidates: /* @__PURE__ */ new Map()
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function resolveGeneratedSourcePatterns(generatedSources, scanSources) {
|
|
256
|
+
return Array.isArray(scanSources) ? scanSources : generatedSources;
|
|
257
|
+
}
|
|
258
|
+
//#endregion
|
|
259
|
+
//#region src/tailwindcss/v4-engine/generator/cache-stats.ts
|
|
260
|
+
function getTailwindV4IncrementalGenerateCacheStats() {
|
|
261
|
+
return {
|
|
262
|
+
max: 8,
|
|
263
|
+
entryCandidatesMax: INCREMENTAL_GENERATE_ENTRY_CANDIDATES_MAX,
|
|
264
|
+
entryCssBytesMax: INCREMENTAL_GENERATE_ENTRY_CSS_BYTES_MAX,
|
|
265
|
+
size: incrementalGenerateCache.size,
|
|
266
|
+
taskMax: 32,
|
|
267
|
+
taskSize: incrementalGenerateTaskCache.size,
|
|
268
|
+
entries: [...incrementalGenerateCache.entries()].map(([key, entry]) => ({
|
|
269
|
+
...summarizeIncrementalCacheKey(key),
|
|
270
|
+
candidates: entry.seenCandidates.size,
|
|
271
|
+
classSet: entry.classSet.size,
|
|
272
|
+
cssBytes: entry.css.length,
|
|
273
|
+
rawCssBytes: entry.rawCss.length
|
|
274
|
+
})),
|
|
275
|
+
keys: [...incrementalGenerateCache.keys()].map(summarizeIncrementalCacheKey),
|
|
276
|
+
taskKeys: [...incrementalGenerateTaskCache.keys()].map(summarizeIncrementalCacheKey)
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
//#endregion
|
|
69
280
|
//#region src/tailwindcss/v4-engine/css-macro-source.ts
|
|
70
281
|
function resolveCssMacroTailwindV4Source(source) {
|
|
71
282
|
const css = (0, _weapp_tailwindcss_postcss.transformCssMacroTailwindV4Source)(source.css);
|
|
@@ -75,6 +286,56 @@ function resolveCssMacroTailwindV4Source(source) {
|
|
|
75
286
|
};
|
|
76
287
|
}
|
|
77
288
|
//#endregion
|
|
289
|
+
//#region src/tailwindcss/v4-engine/miniprogram.ts
|
|
290
|
+
const defaultStyleHandler = (0, _weapp_tailwindcss_postcss.createStyleHandler)({
|
|
291
|
+
cssChildCombinatorReplaceValue: ["view", "text"],
|
|
292
|
+
cssRemoveHoverPseudoClass: true,
|
|
293
|
+
isMainChunk: true,
|
|
294
|
+
majorVersion: 4
|
|
295
|
+
});
|
|
296
|
+
const CSS_DECLARATION_URL_RE = /(:\s*)url\(([^\n\r"';[\]{}]*[[\]{}][^\n\r;]*)\)(?=\s*;)/g;
|
|
297
|
+
function normalizeTailwindV4GeneratedUrlValues(css) {
|
|
298
|
+
return css.replace(CSS_DECLARATION_URL_RE, (match, prefix, urlValue) => {
|
|
299
|
+
try {
|
|
300
|
+
return `${prefix}url("${urlValue.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"")}")`;
|
|
301
|
+
} catch {
|
|
302
|
+
return match;
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
async function transformTailwindV4CssToWeapp(css, options) {
|
|
307
|
+
const protectedCss = (0, _weapp_tailwindcss_postcss.protectDynamicColorMixAlpha)(normalizeTailwindV4GeneratedUrlValues((0, _weapp_tailwindcss_postcss.hasCssMacroStyleOptions)(options) ? await (0, _weapp_tailwindcss_postcss.transformCssMacroCss)(css, options) : css), { customPropertyValues: options && "customPropertyValues" in options ? options.customPropertyValues : void 0 });
|
|
308
|
+
const result = await defaultStyleHandler(protectedCss.css, {
|
|
309
|
+
cssChildCombinatorReplaceValue: ["view", "text"],
|
|
310
|
+
cssRemoveHoverPseudoClass: true,
|
|
311
|
+
isMainChunk: true,
|
|
312
|
+
majorVersion: 4,
|
|
313
|
+
...options
|
|
314
|
+
});
|
|
315
|
+
const pruneOptions = {
|
|
316
|
+
preservePreflight: true,
|
|
317
|
+
preserveConditionalComments: (0, _weapp_tailwindcss_postcss.hasCssMacroStyleOptions)(options)
|
|
318
|
+
};
|
|
319
|
+
return (0, _weapp_tailwindcss_postcss.pruneMiniProgramGeneratedCss)(protectedCss.restore(result.css), pruneOptions);
|
|
320
|
+
}
|
|
321
|
+
function transformTailwindV4WebRpxCss(css) {
|
|
322
|
+
if (!css.includes("rpx")) return css;
|
|
323
|
+
try {
|
|
324
|
+
const root = _weapp_tailwindcss_postcss.postcss.parse(css);
|
|
325
|
+
return (0, _weapp_tailwindcss_postcss.normalizeTailwindcssWebRpxDeclarations)(root, { majorVersion: 4 }) ? root.toString() : css;
|
|
326
|
+
} catch {
|
|
327
|
+
return css;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
function shouldTransformWebRpxCss(options) {
|
|
331
|
+
return options?.appType === "uni-app-vite" || shouldUseWebGeneratorTargetFromEnv();
|
|
332
|
+
}
|
|
333
|
+
async function transformTailwindV4CssByTarget(css, target, options) {
|
|
334
|
+
if (target === "weapp") return transformTailwindV4CssToWeapp(css, options);
|
|
335
|
+
const resolvedWebCss = await ((0, _weapp_tailwindcss_postcss.hasCssMacroStyleOptions)(options) ? (0, _weapp_tailwindcss_postcss.transformCssMacroCss)(css, options) : css);
|
|
336
|
+
return shouldTransformWebRpxCss(options) ? transformTailwindV4WebRpxCss(resolvedWebCss) : resolvedWebCss;
|
|
337
|
+
}
|
|
338
|
+
//#endregion
|
|
78
339
|
//#region src/tailwindcss/v4-engine/tailwind-v4-default-colors.ts
|
|
79
340
|
const TAILWIND_V4_COLOR_STEPS = [
|
|
80
341
|
"50",
|
|
@@ -561,47 +822,6 @@ function createCompatibleSource(source, target) {
|
|
|
561
822
|
};
|
|
562
823
|
}
|
|
563
824
|
//#endregion
|
|
564
|
-
//#region src/tailwindcss/v4-engine/generator/rpx-candidates.ts
|
|
565
|
-
const RPX_LENGTH_UTILITY_PATTERN = String.raw`text|border(?:-[trblxyse])?|bg|outline|ring`;
|
|
566
|
-
const BARE_RPX_LENGTH_CANDIDATE_RE = new RegExp(String.raw`(^|:)(!?)(${RPX_LENGTH_UTILITY_PATTERN})-\[([-+]?(?:\d+|\d*\.\d+)rpx)\](.*)$`, "u");
|
|
567
|
-
const BARE_RPX_LENGTH_HINT_CANDIDATE_RE = new RegExp(String.raw`(?:^|:)!?(${RPX_LENGTH_UTILITY_PATTERN})-\[length:([-+]?(?:\d+|\d*\.\d+)rpx)\].*$`, "u");
|
|
568
|
-
const RPX_LENGTH_SELECTOR_RE = new RegExp(String.raw`(${RPX_LENGTH_UTILITY_PATTERN})-\\\[length\\:((?:\\[.+-]|[+\-.\d])+rpx)\\\]`, "g");
|
|
569
|
-
function normalizeRpxLengthCandidate(candidate) {
|
|
570
|
-
return candidate.replace(BARE_RPX_LENGTH_CANDIDATE_RE, (_match, prefix, important, utility, value, suffix) => {
|
|
571
|
-
return `${prefix}${important}${utility}-[length:${value}]${suffix}`;
|
|
572
|
-
});
|
|
573
|
-
}
|
|
574
|
-
function normalizeRpxLengthCandidates(candidates) {
|
|
575
|
-
const normalized = /* @__PURE__ */ new Set();
|
|
576
|
-
const restoreCandidates = /* @__PURE__ */ new Map();
|
|
577
|
-
for (const candidate of candidates) {
|
|
578
|
-
const normalizedCandidate = normalizeRpxLengthCandidate(candidate);
|
|
579
|
-
normalized.add(normalizedCandidate);
|
|
580
|
-
if (normalizedCandidate !== candidate) restoreCandidates.set(normalizedCandidate, candidate);
|
|
581
|
-
}
|
|
582
|
-
return {
|
|
583
|
-
candidates: normalized,
|
|
584
|
-
restoreCandidates
|
|
585
|
-
};
|
|
586
|
-
}
|
|
587
|
-
function restoreRpxLengthCandidates(candidates, restoreCandidates) {
|
|
588
|
-
if (restoreCandidates.size === 0) return new Set(candidates);
|
|
589
|
-
return new Set([...candidates].map((candidate) => restoreCandidates.get(candidate) ?? candidate));
|
|
590
|
-
}
|
|
591
|
-
function normalizeCssEscapedRpxSelectorValue(value) {
|
|
592
|
-
return value.replace(/\\([.+-])/g, "$1");
|
|
593
|
-
}
|
|
594
|
-
function restoreRpxLengthCssSelectors(css, restoreCandidates) {
|
|
595
|
-
if (restoreCandidates.size === 0 || !css.includes("\\[length\\:")) return css;
|
|
596
|
-
const restoredUtilities = new Set([...restoreCandidates.keys()].map((candidate) => {
|
|
597
|
-
const match = BARE_RPX_LENGTH_HINT_CANDIDATE_RE.exec(candidate);
|
|
598
|
-
return match ? `${match[1]}:${match[2]}` : void 0;
|
|
599
|
-
}).filter((value) => Boolean(value)));
|
|
600
|
-
return css.replace(RPX_LENGTH_SELECTOR_RE, (match, utility, value) => {
|
|
601
|
-
return restoredUtilities.has(`${utility}:${normalizeCssEscapedRpxSelectorValue(value)}`) ? `${utility}-\\[${value}\\]` : match;
|
|
602
|
-
});
|
|
603
|
-
}
|
|
604
|
-
//#endregion
|
|
605
825
|
//#region src/tailwindcss/source-scan.ts
|
|
606
826
|
const DEFAULT_SOURCE_SCAN_EXTENSIONS = [
|
|
607
827
|
"html",
|
|
@@ -932,239 +1152,38 @@ async function resolveCssDefinedScanSources(source) {
|
|
|
932
1152
|
root = _weapp_tailwindcss_postcss.postcss.parse(source.css, { from });
|
|
933
1153
|
} catch {
|
|
934
1154
|
return;
|
|
935
|
-
}
|
|
936
|
-
root.walkAtRules((rule) => {
|
|
937
|
-
if (rule.name === "import") {
|
|
938
|
-
if (!isTailwindCssImport(rule.params)) return;
|
|
939
|
-
hasTailwindImport = true;
|
|
940
|
-
const sourceParam = parseImportSourceParam(rule.params);
|
|
941
|
-
if (sourceParam?.none) hasSourceNone = true;
|
|
942
|
-
if (sourceParam?.sourcePath) importSourceBase = resolveSourceBase(source.base, sourceParam.sourcePath);
|
|
943
|
-
}
|
|
944
|
-
});
|
|
945
|
-
const sourcePatterns = await resolveCssSourceEntries(root, source.base, "**/*");
|
|
946
|
-
if (!importSourceBase) {
|
|
947
|
-
if (sourcePatterns.length > 0) return [...normalizeCssDefinedScanSources(source.base, sourcePatterns), ...createDefaultIgnoredScanSources(source.base)];
|
|
948
|
-
if (hasSourceNone) return false;
|
|
949
|
-
if (hasTailwindImport) {
|
|
950
|
-
const defaultBase = resolveDefaultSourceBase(source);
|
|
951
|
-
return [await resolveTailwindSourceEntry(".", defaultBase, false, "**/*"), ...createDefaultIgnoredScanSources(defaultBase)];
|
|
952
|
-
}
|
|
953
|
-
return;
|
|
954
|
-
}
|
|
955
|
-
return [
|
|
956
|
-
await resolveTailwindSourceEntry(".", importSourceBase, false, "**/*"),
|
|
957
|
-
...sourcePatterns,
|
|
958
|
-
...createDefaultIgnoredScanSources(importSourceBase)
|
|
959
|
-
];
|
|
960
|
-
}
|
|
961
|
-
async function resolveScanSources(source, scanSources) {
|
|
962
|
-
if (scanSources !== true) return scanSources;
|
|
963
|
-
return await resolveCssDefinedScanSources(source) ?? false;
|
|
964
|
-
}
|
|
965
|
-
//#endregion
|
|
966
|
-
//#region src/tailwindcss/v4-engine/miniprogram.ts
|
|
967
|
-
const defaultStyleHandler = (0, _weapp_tailwindcss_postcss.createStyleHandler)({
|
|
968
|
-
cssChildCombinatorReplaceValue: ["view", "text"],
|
|
969
|
-
cssRemoveHoverPseudoClass: true,
|
|
970
|
-
isMainChunk: true,
|
|
971
|
-
majorVersion: 4
|
|
972
|
-
});
|
|
973
|
-
const CSS_DECLARATION_URL_RE = /(:\s*)url\(([^\n\r"';[\]{}]*[[\]{}][^\n\r;]*)\)(?=\s*;)/g;
|
|
974
|
-
function normalizeTailwindV4GeneratedUrlValues(css) {
|
|
975
|
-
return css.replace(CSS_DECLARATION_URL_RE, (match, prefix, urlValue) => {
|
|
976
|
-
try {
|
|
977
|
-
return `${prefix}url("${urlValue.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"")}")`;
|
|
978
|
-
} catch {
|
|
979
|
-
return match;
|
|
980
|
-
}
|
|
981
|
-
});
|
|
982
|
-
}
|
|
983
|
-
async function transformTailwindV4CssToWeapp(css, options) {
|
|
984
|
-
const protectedCss = (0, _weapp_tailwindcss_postcss.protectDynamicColorMixAlpha)(normalizeTailwindV4GeneratedUrlValues((0, _weapp_tailwindcss_postcss.hasCssMacroStyleOptions)(options) ? await (0, _weapp_tailwindcss_postcss.transformCssMacroCss)(css, options) : css), { customPropertyValues: options && "customPropertyValues" in options ? options.customPropertyValues : void 0 });
|
|
985
|
-
const result = await defaultStyleHandler(protectedCss.css, {
|
|
986
|
-
cssChildCombinatorReplaceValue: ["view", "text"],
|
|
987
|
-
cssRemoveHoverPseudoClass: true,
|
|
988
|
-
isMainChunk: true,
|
|
989
|
-
majorVersion: 4,
|
|
990
|
-
...options
|
|
991
|
-
});
|
|
992
|
-
const pruneOptions = {
|
|
993
|
-
preservePreflight: true,
|
|
994
|
-
preserveConditionalComments: (0, _weapp_tailwindcss_postcss.hasCssMacroStyleOptions)(options)
|
|
995
|
-
};
|
|
996
|
-
return (0, _weapp_tailwindcss_postcss.pruneMiniProgramGeneratedCss)(protectedCss.restore(result.css), pruneOptions);
|
|
997
|
-
}
|
|
998
|
-
function transformTailwindV4WebRpxCss(css) {
|
|
999
|
-
if (!css.includes("rpx")) return css;
|
|
1000
|
-
try {
|
|
1001
|
-
const root = _weapp_tailwindcss_postcss.postcss.parse(css);
|
|
1002
|
-
return (0, _weapp_tailwindcss_postcss.normalizeTailwindcssWebRpxDeclarations)(root, { majorVersion: 4 }) ? root.toString() : css;
|
|
1003
|
-
} catch {
|
|
1004
|
-
return css;
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
function shouldTransformWebRpxCss(options) {
|
|
1008
|
-
return options?.appType === "uni-app-vite" || shouldUseWebGeneratorTargetFromEnv();
|
|
1009
|
-
}
|
|
1010
|
-
async function transformTailwindV4CssByTarget(css, target, options) {
|
|
1011
|
-
if (target === "weapp") return transformTailwindV4CssToWeapp(css, options);
|
|
1012
|
-
const resolvedWebCss = await ((0, _weapp_tailwindcss_postcss.hasCssMacroStyleOptions)(options) ? (0, _weapp_tailwindcss_postcss.transformCssMacroCss)(css, options) : css);
|
|
1013
|
-
return shouldTransformWebRpxCss(options) ? transformTailwindV4WebRpxCss(resolvedWebCss) : resolvedWebCss;
|
|
1014
|
-
}
|
|
1015
|
-
//#endregion
|
|
1016
|
-
//#region src/tailwindcss/v4-engine/generator.ts
|
|
1017
|
-
const INCREMENTAL_GENERATE_CACHE_MAX = 8;
|
|
1018
|
-
const INCREMENTAL_GENERATE_TASK_CACHE_MAX = 32;
|
|
1019
|
-
const INCREMENTAL_GENERATE_ENTRY_CANDIDATES_MAX = 12e3;
|
|
1020
|
-
const INCREMENTAL_GENERATE_ENTRY_CSS_BYTES_MAX = 2 * 1024 * 1024;
|
|
1021
|
-
const incrementalGenerateCache = new lru_cache.LRUCache({ max: INCREMENTAL_GENERATE_CACHE_MAX });
|
|
1022
|
-
const incrementalGenerateTaskCache = new lru_cache.LRUCache({ max: INCREMENTAL_GENERATE_TASK_CACHE_MAX });
|
|
1023
|
-
function collectCandidates(candidates) {
|
|
1024
|
-
return new Set(candidates ?? []);
|
|
1025
|
-
}
|
|
1026
|
-
function hasRemovedCandidates(previousCandidates, nextCandidates) {
|
|
1027
|
-
for (const candidate of previousCandidates) if (!nextCandidates.has(candidate)) return true;
|
|
1028
|
-
return false;
|
|
1029
|
-
}
|
|
1030
|
-
function createStableJson(value) {
|
|
1031
|
-
if (value === void 0) return "undefined";
|
|
1032
|
-
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
1033
|
-
if (Array.isArray(value)) return `[${value.map((item) => createStableJson(item)).join(",")}]`;
|
|
1034
|
-
return `{${Object.keys(value).sort().map((key) => {
|
|
1035
|
-
const record = value;
|
|
1036
|
-
return `${JSON.stringify(key)}:${createStableJson(record[key])}`;
|
|
1037
|
-
}).join(",")}}`;
|
|
1038
|
-
}
|
|
1039
|
-
function createDependencyFingerprint(files) {
|
|
1040
|
-
return files.map((file) => {
|
|
1041
|
-
try {
|
|
1042
|
-
const stat = node_fs.default.statSync(file);
|
|
1043
|
-
return `${file}:${stat.size}:${stat.mtimeMs}`;
|
|
1044
|
-
} catch {
|
|
1045
|
-
return `${file}:missing`;
|
|
1046
|
-
}
|
|
1047
|
-
}).join("|");
|
|
1048
|
-
}
|
|
1049
|
-
function createIncrementalGenerateCacheKey(source, target, styleOptions) {
|
|
1050
|
-
return [
|
|
1051
|
-
source.projectRoot,
|
|
1052
|
-
source.base,
|
|
1053
|
-
createStableJson(source.baseFallbacks),
|
|
1054
|
-
source.css,
|
|
1055
|
-
createDependencyFingerprint(source.dependencies),
|
|
1056
|
-
target,
|
|
1057
|
-
createStableJson(styleOptions)
|
|
1058
|
-
].join("\0");
|
|
1059
|
-
}
|
|
1060
|
-
function createIncrementalGenerateTaskCacheKey(cacheKey, requestedCandidates, scanSources) {
|
|
1061
|
-
return [
|
|
1062
|
-
cacheKey,
|
|
1063
|
-
scanSources === true ? "scan:1" : "scan:0",
|
|
1064
|
-
[...requestedCandidates].sort().join("\n")
|
|
1065
|
-
].join("\0");
|
|
1066
|
-
}
|
|
1067
|
-
function runIncrementalGenerateTask(cacheKey, requestedCandidates, scanSources, task) {
|
|
1068
|
-
const taskKey = createIncrementalGenerateTaskCacheKey(cacheKey, requestedCandidates, scanSources);
|
|
1069
|
-
const cachedTask = incrementalGenerateTaskCache.get(taskKey);
|
|
1070
|
-
if (cachedTask) return cachedTask;
|
|
1071
|
-
const promise = task();
|
|
1072
|
-
incrementalGenerateTaskCache.set(taskKey, promise);
|
|
1073
|
-
promise.finally(() => {
|
|
1074
|
-
if (incrementalGenerateTaskCache.get(taskKey) === promise) incrementalGenerateTaskCache.delete(taskKey);
|
|
1075
|
-
});
|
|
1076
|
-
return promise;
|
|
1077
|
-
}
|
|
1078
|
-
function createIncrementalDesignSystemPromise(source, cacheKey) {
|
|
1079
|
-
const promise = (0, _tailwindcss_mangle_engine.loadTailwindV4DesignSystem)(source);
|
|
1080
|
-
promise.catch(() => {
|
|
1081
|
-
if (incrementalGenerateCache.get(cacheKey)?.designSystemPromise === promise) incrementalGenerateCache.delete(cacheKey);
|
|
1082
|
-
});
|
|
1083
|
-
return promise;
|
|
1084
|
-
}
|
|
1085
|
-
function resolveTargetCandidates(candidates, target) {
|
|
1086
|
-
const collected = collectCandidates(candidates);
|
|
1087
|
-
return target === "weapp" ? filterUnsupportedMiniProgramTailwindV4Candidates(collected) : collected;
|
|
1088
|
-
}
|
|
1089
|
-
function collectSeenCandidates(generated) {
|
|
1090
|
-
return new Set(generated.classSet);
|
|
1091
|
-
}
|
|
1092
|
-
function shouldDelegateWebSourceScanToTailwind(target, scanSources) {
|
|
1093
|
-
return target === "web" && scanSources !== false;
|
|
1094
|
-
}
|
|
1095
|
-
function createIncrementalStyleOptions(styleOptions) {
|
|
1096
|
-
return {
|
|
1097
|
-
...styleOptions,
|
|
1098
|
-
isMainChunk: false
|
|
1099
|
-
};
|
|
1100
|
-
}
|
|
1101
|
-
function resolveStyleOptions(source, options) {
|
|
1102
|
-
return (0, _weapp_tailwindcss_postcss.hasCssMacroTailwindV4Source)(source.css) ? (0, _weapp_tailwindcss_postcss.withCssMacroStyleOptions)(options) : options;
|
|
1103
|
-
}
|
|
1104
|
-
function collectCustomPropertyValues(css) {
|
|
1105
|
-
const values = /* @__PURE__ */ new Map();
|
|
1106
|
-
try {
|
|
1107
|
-
_weapp_tailwindcss_postcss.postcss.parse(css).walkDecls((decl) => {
|
|
1108
|
-
if (decl.prop.startsWith("--")) values.set(decl.prop, decl.value.trim());
|
|
1109
|
-
});
|
|
1110
|
-
} catch {}
|
|
1111
|
-
return values;
|
|
1112
|
-
}
|
|
1113
|
-
function mergeCustomPropertyValues(target, css) {
|
|
1114
|
-
for (const [prop, value] of collectCustomPropertyValues(css)) target.set(prop, value);
|
|
1115
|
-
}
|
|
1116
|
-
function createStableTextSignature(input) {
|
|
1117
|
-
let hash = 2166136261;
|
|
1118
|
-
for (let i = 0; i < input.length; i++) {
|
|
1119
|
-
hash ^= input.charCodeAt(i);
|
|
1120
|
-
hash = Math.imul(hash, 16777619);
|
|
1121
|
-
}
|
|
1122
|
-
return (hash >>> 0).toString(36);
|
|
1123
|
-
}
|
|
1124
|
-
function summarizeIncrementalCacheKey(key) {
|
|
1125
|
-
return {
|
|
1126
|
-
keyHash: createStableTextSignature(key),
|
|
1127
|
-
keyBytes: key.length
|
|
1128
|
-
};
|
|
1129
|
-
}
|
|
1130
|
-
function shouldRebuildIncrementalEntry(cached, requestedCandidates, missingCandidates) {
|
|
1131
|
-
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;
|
|
1132
|
-
}
|
|
1133
|
-
function shouldAdmitIncrementalEntry(requestedCandidates, generated) {
|
|
1134
|
-
return requestedCandidates.size <= INCREMENTAL_GENERATE_ENTRY_CANDIDATES_MAX && generated.css.length <= INCREMENTAL_GENERATE_ENTRY_CSS_BYTES_MAX && generated.rawCss.length <= INCREMENTAL_GENERATE_ENTRY_CSS_BYTES_MAX;
|
|
1135
|
-
}
|
|
1136
|
-
function seedIncrementalGenerateCache(options) {
|
|
1137
|
-
if (!shouldAdmitIncrementalEntry(options.requestedCandidates, options.generated)) return false;
|
|
1138
|
-
const cacheKey = createIncrementalGenerateCacheKey(options.compatibleSource, options.target, options.styleOptions);
|
|
1139
|
-
const customPropertyValues = collectCustomPropertyValues(options.compatibleSource.css);
|
|
1140
|
-
mergeCustomPropertyValues(customPropertyValues, options.generated.css);
|
|
1141
|
-
incrementalGenerateCache.set(cacheKey, {
|
|
1142
|
-
seenCandidates: collectSeenCandidates(options.generated),
|
|
1143
|
-
classSet: new Set(options.generated.classSet),
|
|
1144
|
-
css: options.generated.css,
|
|
1145
|
-
rawCss: options.generated.rawCss,
|
|
1146
|
-
customPropertyValues,
|
|
1147
|
-
designSystemPromise: createIncrementalDesignSystemPromise(options.compatibleSource, cacheKey),
|
|
1148
|
-
dependencies: options.generated.dependencies,
|
|
1149
|
-
sources: options.generated.sources,
|
|
1150
|
-
root: options.generated.root,
|
|
1151
|
-
target: options.generated.target
|
|
1152
|
-
});
|
|
1153
|
-
return true;
|
|
1154
|
-
}
|
|
1155
|
-
function shouldNormalizeRpxLengthCandidatesForTarget(target, styleOptions) {
|
|
1156
|
-
if (target !== "web") return true;
|
|
1157
|
-
return styleOptions?.appType === "uni-app-vite" || shouldUseWebGeneratorTargetFromEnv();
|
|
1158
|
-
}
|
|
1159
|
-
function normalizeTargetRpxLengthCandidates(candidates, target, styleOptions) {
|
|
1160
|
-
return shouldNormalizeRpxLengthCandidatesForTarget(target, styleOptions) ? normalizeRpxLengthCandidates(candidates) : {
|
|
1161
|
-
candidates: new Set(candidates),
|
|
1162
|
-
restoreCandidates: /* @__PURE__ */ new Map()
|
|
1163
|
-
};
|
|
1155
|
+
}
|
|
1156
|
+
root.walkAtRules((rule) => {
|
|
1157
|
+
if (rule.name === "import") {
|
|
1158
|
+
if (!isTailwindCssImport(rule.params)) return;
|
|
1159
|
+
hasTailwindImport = true;
|
|
1160
|
+
const sourceParam = parseImportSourceParam(rule.params);
|
|
1161
|
+
if (sourceParam?.none) hasSourceNone = true;
|
|
1162
|
+
if (sourceParam?.sourcePath) importSourceBase = resolveSourceBase(source.base, sourceParam.sourcePath);
|
|
1163
|
+
}
|
|
1164
|
+
});
|
|
1165
|
+
const sourcePatterns = await resolveCssSourceEntries(root, source.base, "**/*");
|
|
1166
|
+
if (!importSourceBase) {
|
|
1167
|
+
if (sourcePatterns.length > 0) return [...normalizeCssDefinedScanSources(source.base, sourcePatterns), ...createDefaultIgnoredScanSources(source.base)];
|
|
1168
|
+
if (hasSourceNone) return false;
|
|
1169
|
+
if (hasTailwindImport) {
|
|
1170
|
+
const defaultBase = resolveDefaultSourceBase(source);
|
|
1171
|
+
return [await resolveTailwindSourceEntry(".", defaultBase, false, "**/*"), ...createDefaultIgnoredScanSources(defaultBase)];
|
|
1172
|
+
}
|
|
1173
|
+
return;
|
|
1174
|
+
}
|
|
1175
|
+
return [
|
|
1176
|
+
await resolveTailwindSourceEntry(".", importSourceBase, false, "**/*"),
|
|
1177
|
+
...sourcePatterns,
|
|
1178
|
+
...createDefaultIgnoredScanSources(importSourceBase)
|
|
1179
|
+
];
|
|
1164
1180
|
}
|
|
1165
|
-
function
|
|
1166
|
-
|
|
1181
|
+
async function resolveScanSources(source, scanSources) {
|
|
1182
|
+
if (scanSources !== true) return scanSources;
|
|
1183
|
+
return await resolveCssDefinedScanSources(source) ?? false;
|
|
1167
1184
|
}
|
|
1185
|
+
//#endregion
|
|
1186
|
+
//#region src/tailwindcss/v4-engine/generator/engine.ts
|
|
1168
1187
|
function createTailwindV4Engine(source) {
|
|
1169
1188
|
async function generateOnce(generateSource, options = {}) {
|
|
1170
1189
|
const { scanSources = true, styleOptions, target = "weapp", ...patchOptions } = options;
|
|
@@ -1309,25 +1328,6 @@ function createTailwindV4Engine(source) {
|
|
|
1309
1328
|
generate
|
|
1310
1329
|
};
|
|
1311
1330
|
}
|
|
1312
|
-
function getTailwindV4IncrementalGenerateCacheStats() {
|
|
1313
|
-
return {
|
|
1314
|
-
max: INCREMENTAL_GENERATE_CACHE_MAX,
|
|
1315
|
-
entryCandidatesMax: INCREMENTAL_GENERATE_ENTRY_CANDIDATES_MAX,
|
|
1316
|
-
entryCssBytesMax: INCREMENTAL_GENERATE_ENTRY_CSS_BYTES_MAX,
|
|
1317
|
-
size: incrementalGenerateCache.size,
|
|
1318
|
-
taskMax: INCREMENTAL_GENERATE_TASK_CACHE_MAX,
|
|
1319
|
-
taskSize: incrementalGenerateTaskCache.size,
|
|
1320
|
-
entries: [...incrementalGenerateCache.entries()].map(([key, entry]) => ({
|
|
1321
|
-
...summarizeIncrementalCacheKey(key),
|
|
1322
|
-
candidates: entry.seenCandidates.size,
|
|
1323
|
-
classSet: entry.classSet.size,
|
|
1324
|
-
cssBytes: entry.css.length,
|
|
1325
|
-
rawCssBytes: entry.rawCss.length
|
|
1326
|
-
})),
|
|
1327
|
-
keys: [...incrementalGenerateCache.keys()].map(summarizeIncrementalCacheKey),
|
|
1328
|
-
taskKeys: [...incrementalGenerateTaskCache.keys()].map(summarizeIncrementalCacheKey)
|
|
1329
|
-
};
|
|
1330
|
-
}
|
|
1331
1331
|
//#endregion
|
|
1332
1332
|
//#region src/bundlers/shared/generator-css/config-directive.ts
|
|
1333
1333
|
function quoteCssString(value) {
|
|
@@ -1729,64 +1729,345 @@ function hasTailwindApplyDirective(rawSource) {
|
|
|
1729
1729
|
}
|
|
1730
1730
|
function resolveCssEntrySource(rawSource, base, options = {}) {
|
|
1731
1731
|
try {
|
|
1732
|
-
const root = _weapp_tailwindcss_postcss.postcss.parse(rawSource);
|
|
1733
|
-
const normalizedImports = normalizeTailwindImportAtRules(root, options);
|
|
1734
|
-
let found = false;
|
|
1735
|
-
let config;
|
|
1736
|
-
let configRequest;
|
|
1737
|
-
let removedConfig = false;
|
|
1738
|
-
const removeConfig = options.removeConfig ?? true;
|
|
1739
|
-
const ignoreLayer = hasGeneratedCssArtifacts(rawSource);
|
|
1740
|
-
root.walk((node) => {
|
|
1741
|
-
if (isTailwindGenerationDirective(node, {
|
|
1742
|
-
...options,
|
|
1743
|
-
ignoreLayer
|
|
1744
|
-
})) found = true;
|
|
1745
|
-
if (node.type === "atrule" && node.name === "config") {
|
|
1746
|
-
const configPath = parseConfigRequest(node.params);
|
|
1747
|
-
if (configPath && !config) {
|
|
1748
|
-
configRequest = configPath;
|
|
1749
|
-
config = resolveConfigPath(base, configPath);
|
|
1750
|
-
}
|
|
1751
|
-
if (removeConfig) {
|
|
1752
|
-
node.remove();
|
|
1753
|
-
removedConfig = true;
|
|
1754
|
-
}
|
|
1755
|
-
}
|
|
1732
|
+
const root = _weapp_tailwindcss_postcss.postcss.parse(rawSource);
|
|
1733
|
+
const normalizedImports = normalizeTailwindImportAtRules(root, options);
|
|
1734
|
+
let found = false;
|
|
1735
|
+
let config;
|
|
1736
|
+
let configRequest;
|
|
1737
|
+
let removedConfig = false;
|
|
1738
|
+
const removeConfig = options.removeConfig ?? true;
|
|
1739
|
+
const ignoreLayer = hasGeneratedCssArtifacts(rawSource);
|
|
1740
|
+
root.walk((node) => {
|
|
1741
|
+
if (isTailwindGenerationDirective(node, {
|
|
1742
|
+
...options,
|
|
1743
|
+
ignoreLayer
|
|
1744
|
+
})) found = true;
|
|
1745
|
+
if (node.type === "atrule" && node.name === "config") {
|
|
1746
|
+
const configPath = parseConfigRequest(node.params);
|
|
1747
|
+
if (configPath && !config) {
|
|
1748
|
+
configRequest = configPath;
|
|
1749
|
+
config = resolveConfigPath(base, configPath);
|
|
1750
|
+
}
|
|
1751
|
+
if (removeConfig) {
|
|
1752
|
+
node.remove();
|
|
1753
|
+
removedConfig = true;
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
});
|
|
1757
|
+
if (!found) return;
|
|
1758
|
+
if (hasPreprocessorOnlySyntax(rawSource)) {
|
|
1759
|
+
const css = extractTailwindSourceForPostcssFallback(rawSource, {
|
|
1760
|
+
...options,
|
|
1761
|
+
removeConfig
|
|
1762
|
+
});
|
|
1763
|
+
if (css) return {
|
|
1764
|
+
css,
|
|
1765
|
+
config,
|
|
1766
|
+
configRequest,
|
|
1767
|
+
base
|
|
1768
|
+
};
|
|
1769
|
+
}
|
|
1770
|
+
return {
|
|
1771
|
+
css: removedConfig || normalizedImports ? root.toString() : rawSource,
|
|
1772
|
+
config,
|
|
1773
|
+
configRequest,
|
|
1774
|
+
base
|
|
1775
|
+
};
|
|
1776
|
+
} catch {
|
|
1777
|
+
const css = extractTailwindSourceForPostcssFallback(rawSource, options);
|
|
1778
|
+
const configRequest = extractConfigRequestFromSource(rawSource);
|
|
1779
|
+
const config = configRequest ? resolveConfigPath(base, configRequest) : void 0;
|
|
1780
|
+
return css ? {
|
|
1781
|
+
css,
|
|
1782
|
+
config,
|
|
1783
|
+
configRequest,
|
|
1784
|
+
base
|
|
1785
|
+
} : void 0;
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
//#endregion
|
|
1789
|
+
//#region src/bundlers/shared/generator-css/scoped-rules.ts
|
|
1790
|
+
const VUE_SCOPED_SELECTOR_RE = /\.data-v-[\w-]+|\[data-v-[^\]]+\]/g;
|
|
1791
|
+
function normalizeGeneratedSelector$1(selector) {
|
|
1792
|
+
return selector.replace(/:not\(#\\#\)/g, "").trim();
|
|
1793
|
+
}
|
|
1794
|
+
function normalizeVueScopedSelector(selector) {
|
|
1795
|
+
let scoped = false;
|
|
1796
|
+
return {
|
|
1797
|
+
normalized: normalizeGeneratedSelector$1(selector).replace(VUE_SCOPED_SELECTOR_RE, () => {
|
|
1798
|
+
scoped = true;
|
|
1799
|
+
return "";
|
|
1800
|
+
}).trim(),
|
|
1801
|
+
scoped
|
|
1802
|
+
};
|
|
1803
|
+
}
|
|
1804
|
+
function normalizeCssComparableValue(value) {
|
|
1805
|
+
const normalizeUnquotedSegment = (segment) => segment.replace(/(^|[^\w.-])(-?)0+\.(\d+)/g, "$1$2.$3");
|
|
1806
|
+
let result = "";
|
|
1807
|
+
let segmentStart = 0;
|
|
1808
|
+
let index = 0;
|
|
1809
|
+
while (index < value.length) {
|
|
1810
|
+
const quote = value[index];
|
|
1811
|
+
if (quote !== "\"" && quote !== "'") {
|
|
1812
|
+
index++;
|
|
1813
|
+
continue;
|
|
1814
|
+
}
|
|
1815
|
+
result += normalizeUnquotedSegment(value.slice(segmentStart, index));
|
|
1816
|
+
const stringStart = index;
|
|
1817
|
+
index++;
|
|
1818
|
+
while (index < value.length) {
|
|
1819
|
+
if (value[index] === "\\") {
|
|
1820
|
+
index += 2;
|
|
1821
|
+
continue;
|
|
1822
|
+
}
|
|
1823
|
+
if (value[index] === quote) {
|
|
1824
|
+
index++;
|
|
1825
|
+
break;
|
|
1826
|
+
}
|
|
1827
|
+
index++;
|
|
1828
|
+
}
|
|
1829
|
+
result += value.slice(stringStart, index);
|
|
1830
|
+
segmentStart = index;
|
|
1831
|
+
}
|
|
1832
|
+
return result + normalizeUnquotedSegment(value.slice(segmentStart));
|
|
1833
|
+
}
|
|
1834
|
+
function createCssNodeSignature(node) {
|
|
1835
|
+
if (node.type === "decl") return JSON.stringify([
|
|
1836
|
+
"decl",
|
|
1837
|
+
node.prop,
|
|
1838
|
+
normalizeCssComparableValue(node.value),
|
|
1839
|
+
node.important
|
|
1840
|
+
]);
|
|
1841
|
+
if (node.type === "atrule") return JSON.stringify([
|
|
1842
|
+
"atrule",
|
|
1843
|
+
node.name,
|
|
1844
|
+
normalizeCssComparableValue(node.params),
|
|
1845
|
+
node.nodes?.map(createCssNodeSignature) ?? null
|
|
1846
|
+
]);
|
|
1847
|
+
if (node.type === "rule") return JSON.stringify([
|
|
1848
|
+
"rule",
|
|
1849
|
+
node.selector,
|
|
1850
|
+
node.nodes?.map(createCssNodeSignature) ?? null
|
|
1851
|
+
]);
|
|
1852
|
+
if (node.type === "comment") return JSON.stringify(["comment", node.text]);
|
|
1853
|
+
return node.toString();
|
|
1854
|
+
}
|
|
1855
|
+
function createRuleBodySignature(rule) {
|
|
1856
|
+
return JSON.stringify(rule.nodes?.map(createCssNodeSignature) ?? []);
|
|
1857
|
+
}
|
|
1858
|
+
function createRuleAtRuleContextSignature(rule) {
|
|
1859
|
+
const context = [];
|
|
1860
|
+
let parent = rule.parent;
|
|
1861
|
+
while (parent && parent.type !== "root" && parent.type !== "document") {
|
|
1862
|
+
if (parent.type === "atrule") context.unshift(JSON.stringify([parent.name, parent.params]));
|
|
1863
|
+
parent = parent.parent;
|
|
1864
|
+
}
|
|
1865
|
+
return JSON.stringify(context);
|
|
1866
|
+
}
|
|
1867
|
+
function createScopedRuleCoverageKey(rule, selector) {
|
|
1868
|
+
return JSON.stringify([
|
|
1869
|
+
createRuleAtRuleContextSignature(rule),
|
|
1870
|
+
createRuleBodySignature(rule),
|
|
1871
|
+
selector
|
|
1872
|
+
]);
|
|
1873
|
+
}
|
|
1874
|
+
function removeUnscopedRulesCoveredByScopedRules(root) {
|
|
1875
|
+
const scopedCoverage = /* @__PURE__ */ new Set();
|
|
1876
|
+
root.walkRules((rule) => {
|
|
1877
|
+
for (const selector of rule.selectors ?? [rule.selector]) {
|
|
1878
|
+
const normalized = normalizeVueScopedSelector(selector);
|
|
1879
|
+
if (normalized.scoped && normalized.normalized) scopedCoverage.add(createScopedRuleCoverageKey(rule, normalized.normalized));
|
|
1880
|
+
}
|
|
1881
|
+
});
|
|
1882
|
+
if (scopedCoverage.size === 0) return;
|
|
1883
|
+
root.walkRules((rule) => {
|
|
1884
|
+
const normalizedSelectors = (rule.selectors ?? [rule.selector]).map(normalizeVueScopedSelector);
|
|
1885
|
+
if (normalizedSelectors.some((selector) => selector.scoped || !selector.normalized) || !normalizedSelectors.every((selector) => scopedCoverage.has(createScopedRuleCoverageKey(rule, selector.normalized)))) return;
|
|
1886
|
+
rule.remove();
|
|
1887
|
+
});
|
|
1888
|
+
}
|
|
1889
|
+
function preferScopedGeneratedCssRules(css) {
|
|
1890
|
+
if (!css.includes("data-v-")) return css;
|
|
1891
|
+
try {
|
|
1892
|
+
const root = _weapp_tailwindcss_postcss.postcss.parse(css);
|
|
1893
|
+
removeUnscopedRulesCoveredByScopedRules(root);
|
|
1894
|
+
root.walkAtRules((rule) => {
|
|
1895
|
+
if (rule.nodes !== void 0 && rule.nodes.length === 0) rule.remove();
|
|
1896
|
+
});
|
|
1897
|
+
return root.toString();
|
|
1898
|
+
} catch {
|
|
1899
|
+
return css;
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
//#endregion
|
|
1903
|
+
//#region src/bundlers/shared/generator-css/user-css/user-layers.ts
|
|
1904
|
+
function splitUserCssLayerBlocks(source) {
|
|
1905
|
+
if (!source.includes("@layer")) return {
|
|
1906
|
+
layer: "",
|
|
1907
|
+
rest: source
|
|
1908
|
+
};
|
|
1909
|
+
try {
|
|
1910
|
+
const root = _weapp_tailwindcss_postcss.postcss.parse(source);
|
|
1911
|
+
const layerRoot = _weapp_tailwindcss_postcss.postcss.root();
|
|
1912
|
+
const restRoot = _weapp_tailwindcss_postcss.postcss.root();
|
|
1913
|
+
for (const node of root.nodes) (node.type === "atrule" && node.name === "layer" && node.nodes?.length ? layerRoot : restRoot).append(node.clone());
|
|
1914
|
+
return {
|
|
1915
|
+
layer: layerRoot.toString(),
|
|
1916
|
+
rest: restRoot.toString()
|
|
1917
|
+
};
|
|
1918
|
+
} catch {
|
|
1919
|
+
return {
|
|
1920
|
+
layer: source,
|
|
1921
|
+
rest: ""
|
|
1922
|
+
};
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
function hasUserCssLayerBlocks(source) {
|
|
1926
|
+
if (!source.includes("@layer")) return false;
|
|
1927
|
+
try {
|
|
1928
|
+
let hasLayerBlock = false;
|
|
1929
|
+
_weapp_tailwindcss_postcss.postcss.parse(source).walkAtRules("layer", (node) => {
|
|
1930
|
+
if (node.nodes?.length) hasLayerBlock = true;
|
|
1931
|
+
});
|
|
1932
|
+
return hasLayerBlock;
|
|
1933
|
+
} catch {
|
|
1934
|
+
return true;
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
function collectUserLayerSelectors(source) {
|
|
1938
|
+
const selectors = /* @__PURE__ */ new Set();
|
|
1939
|
+
try {
|
|
1940
|
+
_weapp_tailwindcss_postcss.postcss.parse(source).walkRules((rule) => {
|
|
1941
|
+
for (const selector of rule.selectors ?? [rule.selector]) {
|
|
1942
|
+
const normalized = selector.trim();
|
|
1943
|
+
if (normalized) selectors.add(normalized);
|
|
1944
|
+
}
|
|
1945
|
+
});
|
|
1946
|
+
} catch {}
|
|
1947
|
+
return selectors;
|
|
1948
|
+
}
|
|
1949
|
+
function matchesUserLayerSelector(selector, userLayerSelector) {
|
|
1950
|
+
if (selector === userLayerSelector) return true;
|
|
1951
|
+
if (!selector.startsWith(userLayerSelector)) return false;
|
|
1952
|
+
const next = selector[userLayerSelector.length];
|
|
1953
|
+
return next === ":" || next === "[";
|
|
1954
|
+
}
|
|
1955
|
+
function extractGeneratedCssForUserLayerSelectors(css, userLayerSource) {
|
|
1956
|
+
const selectors = collectUserLayerSelectors(userLayerSource);
|
|
1957
|
+
if (selectors.size === 0) return {
|
|
1958
|
+
layer: "",
|
|
1959
|
+
rest: css
|
|
1960
|
+
};
|
|
1961
|
+
try {
|
|
1962
|
+
const root = _weapp_tailwindcss_postcss.postcss.parse(css);
|
|
1963
|
+
const layerRoot = _weapp_tailwindcss_postcss.postcss.root();
|
|
1964
|
+
const selectorList = [...selectors];
|
|
1965
|
+
root.walkRules((rule) => {
|
|
1966
|
+
if ((rule.selectors ?? [rule.selector]).some((selector) => selectorList.some((userSelector) => matchesUserLayerSelector(selector.trim(), userSelector)))) {
|
|
1967
|
+
layerRoot.append(rule.clone());
|
|
1968
|
+
rule.remove();
|
|
1969
|
+
}
|
|
1970
|
+
});
|
|
1971
|
+
return {
|
|
1972
|
+
layer: layerRoot.toString(),
|
|
1973
|
+
rest: root.toString()
|
|
1974
|
+
};
|
|
1975
|
+
} catch {
|
|
1976
|
+
return {
|
|
1977
|
+
layer: "",
|
|
1978
|
+
rest: css
|
|
1979
|
+
};
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
function normalizeGeneratedSelector(selector) {
|
|
1983
|
+
return selector.replace(/:not\(#\\#\)/g, "").trim();
|
|
1984
|
+
}
|
|
1985
|
+
function collectApplyOnlySourceSelectors(source) {
|
|
1986
|
+
const selectors = /* @__PURE__ */ new Set();
|
|
1987
|
+
try {
|
|
1988
|
+
_weapp_tailwindcss_postcss.postcss.parse(source).walkRules((rule) => {
|
|
1989
|
+
if (!rule.nodes?.some((node) => node.type === "atrule" && node.name === "apply")) return;
|
|
1990
|
+
for (const selector of rule.selectors ?? [rule.selector]) {
|
|
1991
|
+
const normalized = normalizeGeneratedSelector(selector);
|
|
1992
|
+
if (normalized) selectors.add(normalized);
|
|
1993
|
+
}
|
|
1994
|
+
});
|
|
1995
|
+
} catch {}
|
|
1996
|
+
return selectors;
|
|
1997
|
+
}
|
|
1998
|
+
function hasOnlyApplyBackedSourceRules(source) {
|
|
1999
|
+
let hasApplyRule = false;
|
|
2000
|
+
let hasNonApplyRule = false;
|
|
2001
|
+
try {
|
|
2002
|
+
_weapp_tailwindcss_postcss.postcss.parse(source).walkRules((rule) => {
|
|
2003
|
+
if (rule.nodes?.some((node) => node.type === "atrule" && node.name === "apply")) hasApplyRule = true;
|
|
2004
|
+
else hasNonApplyRule = true;
|
|
2005
|
+
});
|
|
2006
|
+
} catch {
|
|
2007
|
+
return false;
|
|
2008
|
+
}
|
|
2009
|
+
return hasApplyRule && !hasNonApplyRule;
|
|
2010
|
+
}
|
|
2011
|
+
function removeCssComments(css) {
|
|
2012
|
+
return css.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
2013
|
+
}
|
|
2014
|
+
function isEmptyCustomVariantBlock(rule) {
|
|
2015
|
+
if (rule.name !== "custom-variant") return false;
|
|
2016
|
+
if (!/^[\w-]+$/.test(rule.params.trim())) return false;
|
|
2017
|
+
if (rule.nodes === void 0) return true;
|
|
2018
|
+
return rule.nodes.every((node) => node.type === "comment");
|
|
2019
|
+
}
|
|
2020
|
+
//#endregion
|
|
2021
|
+
//#region src/bundlers/shared/generator-css/user-css/apply-only.ts
|
|
2022
|
+
function normalizeEmptyTailwindCustomVariants(css) {
|
|
2023
|
+
if (!css.includes("@custom-variant")) return css;
|
|
2024
|
+
try {
|
|
2025
|
+
const root = _weapp_tailwindcss_postcss.postcss.parse(css);
|
|
2026
|
+
let changed = false;
|
|
2027
|
+
root.walkAtRules("custom-variant", (rule) => {
|
|
2028
|
+
if (!isEmptyCustomVariantBlock(rule)) return;
|
|
2029
|
+
rule.remove();
|
|
2030
|
+
changed = true;
|
|
1756
2031
|
});
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
2032
|
+
return changed ? root.toString() : css;
|
|
2033
|
+
} catch {
|
|
2034
|
+
return css;
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
function filterApplyOnlyGeneratedCss(css, source, options = {}) {
|
|
2038
|
+
const selectors = collectApplyOnlySourceSelectors(source);
|
|
2039
|
+
if (selectors.size === 0) return css;
|
|
2040
|
+
const selectorList = [...selectors];
|
|
2041
|
+
const preserveVariables = options.preserveVariables !== false;
|
|
2042
|
+
try {
|
|
2043
|
+
const root = _weapp_tailwindcss_postcss.postcss.parse(css);
|
|
2044
|
+
root.walkRules((rule) => {
|
|
2045
|
+
const isApplySelector = (rule.selectors ?? [rule.selector]).some((selector) => {
|
|
2046
|
+
const normalized = normalizeGeneratedSelector(selector);
|
|
2047
|
+
return selectorList.some((sourceSelector) => {
|
|
2048
|
+
if (normalized === sourceSelector) return true;
|
|
2049
|
+
if (!normalized.startsWith(sourceSelector)) return false;
|
|
2050
|
+
const next = normalized[sourceSelector.length];
|
|
2051
|
+
return next === ":" || next === "[" || next === ".";
|
|
2052
|
+
});
|
|
1762
2053
|
});
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
return
|
|
1771
|
-
css: removedConfig || normalizedImports ? root.toString() : rawSource,
|
|
1772
|
-
config,
|
|
1773
|
-
configRequest,
|
|
1774
|
-
base
|
|
1775
|
-
};
|
|
2054
|
+
const isVariableRule = rule.nodes?.some((node) => node.type === "decl" && node.prop.startsWith("--"));
|
|
2055
|
+
if (!isApplySelector && (!preserveVariables || !isVariableRule)) rule.remove();
|
|
2056
|
+
});
|
|
2057
|
+
root.walkAtRules((rule) => {
|
|
2058
|
+
if (rule.nodes !== void 0 && rule.nodes.length === 0) rule.remove();
|
|
2059
|
+
});
|
|
2060
|
+
const filteredCss = root.toString();
|
|
2061
|
+
return removeCssComments(options.preferScopedRules ? preferScopedGeneratedCssRules(filteredCss) : filteredCss).trim();
|
|
1776
2062
|
} catch {
|
|
1777
|
-
|
|
1778
|
-
const configRequest = extractConfigRequestFromSource(rawSource);
|
|
1779
|
-
const config = configRequest ? resolveConfigPath(base, configRequest) : void 0;
|
|
1780
|
-
return css ? {
|
|
1781
|
-
css,
|
|
1782
|
-
config,
|
|
1783
|
-
configRequest,
|
|
1784
|
-
base
|
|
1785
|
-
} : void 0;
|
|
2063
|
+
return css;
|
|
1786
2064
|
}
|
|
1787
2065
|
}
|
|
2066
|
+
function shouldFilterApplyOnlyGeneratedCss(_majorVersion, target, source, options) {
|
|
2067
|
+
return (target === "weapp" || target === "web") && hasTailwindApplyDirective(source) && !hasTailwindRootDirectives(source) && !options.hasGeneratedCss && !options.hasGeneratedMarkers && collectApplyOnlySourceSelectors(source).size > 0 && hasOnlyApplyBackedSourceRules(source);
|
|
2068
|
+
}
|
|
1788
2069
|
//#endregion
|
|
1789
|
-
//#region src/bundlers/shared/generator-css/user-css.ts
|
|
2070
|
+
//#region src/bundlers/shared/generator-css/user-css/generated-cleanup.ts
|
|
1790
2071
|
const TAILWIND_V4_GENERATOR_AT_RULES = /* @__PURE__ */ new Set([
|
|
1791
2072
|
"config",
|
|
1792
2073
|
"custom-variant",
|
|
@@ -1890,6 +2171,8 @@ function removeTailwindV4GeneratedUserCssArtifacts(source) {
|
|
|
1890
2171
|
return source;
|
|
1891
2172
|
}
|
|
1892
2173
|
}
|
|
2174
|
+
//#endregion
|
|
2175
|
+
//#region src/bundlers/shared/generator-css/user-css/at-rules.ts
|
|
1893
2176
|
function removeTailwindSourceMediaBlocks(source) {
|
|
1894
2177
|
let next = source;
|
|
1895
2178
|
let changed = false;
|
|
@@ -2046,6 +2329,8 @@ function removeTailwindApplyAtRules(source) {
|
|
|
2046
2329
|
return source;
|
|
2047
2330
|
}
|
|
2048
2331
|
}
|
|
2332
|
+
//#endregion
|
|
2333
|
+
//#region src/bundlers/shared/generator-css/user-css/source-fragments.ts
|
|
2049
2334
|
function removeTailwindV4GeneratorAtRules(source) {
|
|
2050
2335
|
try {
|
|
2051
2336
|
const root = _weapp_tailwindcss_postcss.postcss.parse(source);
|
|
@@ -2167,168 +2452,8 @@ function stripUnmatchedTailwindSourceMediaCloseFragments(source) {
|
|
|
2167
2452
|
return stripLeadingTailwindSourceMediaCloseFragment(source).replace(/\s*\}\s*$/, "");
|
|
2168
2453
|
}
|
|
2169
2454
|
}
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
layer: "",
|
|
2173
|
-
rest: source
|
|
2174
|
-
};
|
|
2175
|
-
try {
|
|
2176
|
-
const root = _weapp_tailwindcss_postcss.postcss.parse(source);
|
|
2177
|
-
const layerRoot = _weapp_tailwindcss_postcss.postcss.root();
|
|
2178
|
-
const restRoot = _weapp_tailwindcss_postcss.postcss.root();
|
|
2179
|
-
for (const node of root.nodes) (node.type === "atrule" && node.name === "layer" && node.nodes?.length ? layerRoot : restRoot).append(node.clone());
|
|
2180
|
-
return {
|
|
2181
|
-
layer: layerRoot.toString(),
|
|
2182
|
-
rest: restRoot.toString()
|
|
2183
|
-
};
|
|
2184
|
-
} catch {
|
|
2185
|
-
return {
|
|
2186
|
-
layer: source,
|
|
2187
|
-
rest: ""
|
|
2188
|
-
};
|
|
2189
|
-
}
|
|
2190
|
-
}
|
|
2191
|
-
function hasUserCssLayerBlocks(source) {
|
|
2192
|
-
if (!source.includes("@layer")) return false;
|
|
2193
|
-
try {
|
|
2194
|
-
let hasLayerBlock = false;
|
|
2195
|
-
_weapp_tailwindcss_postcss.postcss.parse(source).walkAtRules("layer", (node) => {
|
|
2196
|
-
if (node.nodes?.length) hasLayerBlock = true;
|
|
2197
|
-
});
|
|
2198
|
-
return hasLayerBlock;
|
|
2199
|
-
} catch {
|
|
2200
|
-
return true;
|
|
2201
|
-
}
|
|
2202
|
-
}
|
|
2203
|
-
function collectUserLayerSelectors(source) {
|
|
2204
|
-
const selectors = /* @__PURE__ */ new Set();
|
|
2205
|
-
try {
|
|
2206
|
-
_weapp_tailwindcss_postcss.postcss.parse(source).walkRules((rule) => {
|
|
2207
|
-
for (const selector of rule.selectors ?? [rule.selector]) {
|
|
2208
|
-
const normalized = selector.trim();
|
|
2209
|
-
if (normalized) selectors.add(normalized);
|
|
2210
|
-
}
|
|
2211
|
-
});
|
|
2212
|
-
} catch {}
|
|
2213
|
-
return selectors;
|
|
2214
|
-
}
|
|
2215
|
-
function matchesUserLayerSelector(selector, userLayerSelector) {
|
|
2216
|
-
if (selector === userLayerSelector) return true;
|
|
2217
|
-
if (!selector.startsWith(userLayerSelector)) return false;
|
|
2218
|
-
const next = selector[userLayerSelector.length];
|
|
2219
|
-
return next === ":" || next === "[";
|
|
2220
|
-
}
|
|
2221
|
-
function extractGeneratedCssForUserLayerSelectors(css, userLayerSource) {
|
|
2222
|
-
const selectors = collectUserLayerSelectors(userLayerSource);
|
|
2223
|
-
if (selectors.size === 0) return {
|
|
2224
|
-
layer: "",
|
|
2225
|
-
rest: css
|
|
2226
|
-
};
|
|
2227
|
-
try {
|
|
2228
|
-
const root = _weapp_tailwindcss_postcss.postcss.parse(css);
|
|
2229
|
-
const layerRoot = _weapp_tailwindcss_postcss.postcss.root();
|
|
2230
|
-
const selectorList = [...selectors];
|
|
2231
|
-
root.walkRules((rule) => {
|
|
2232
|
-
if ((rule.selectors ?? [rule.selector]).some((selector) => selectorList.some((userSelector) => matchesUserLayerSelector(selector.trim(), userSelector)))) {
|
|
2233
|
-
layerRoot.append(rule.clone());
|
|
2234
|
-
rule.remove();
|
|
2235
|
-
}
|
|
2236
|
-
});
|
|
2237
|
-
return {
|
|
2238
|
-
layer: layerRoot.toString(),
|
|
2239
|
-
rest: root.toString()
|
|
2240
|
-
};
|
|
2241
|
-
} catch {
|
|
2242
|
-
return {
|
|
2243
|
-
layer: "",
|
|
2244
|
-
rest: css
|
|
2245
|
-
};
|
|
2246
|
-
}
|
|
2247
|
-
}
|
|
2248
|
-
function normalizeGeneratedSelector(selector) {
|
|
2249
|
-
return selector.replace(/:not\(#\\#\)/g, "").trim();
|
|
2250
|
-
}
|
|
2251
|
-
function collectApplyOnlySourceSelectors(source) {
|
|
2252
|
-
const selectors = /* @__PURE__ */ new Set();
|
|
2253
|
-
try {
|
|
2254
|
-
_weapp_tailwindcss_postcss.postcss.parse(source).walkRules((rule) => {
|
|
2255
|
-
if (!rule.nodes?.some((node) => node.type === "atrule" && node.name === "apply")) return;
|
|
2256
|
-
for (const selector of rule.selectors ?? [rule.selector]) {
|
|
2257
|
-
const normalized = normalizeGeneratedSelector(selector);
|
|
2258
|
-
if (normalized) selectors.add(normalized);
|
|
2259
|
-
}
|
|
2260
|
-
});
|
|
2261
|
-
} catch {}
|
|
2262
|
-
return selectors;
|
|
2263
|
-
}
|
|
2264
|
-
function hasOnlyApplyBackedSourceRules(source) {
|
|
2265
|
-
let hasApplyRule = false;
|
|
2266
|
-
let hasNonApplyRule = false;
|
|
2267
|
-
try {
|
|
2268
|
-
_weapp_tailwindcss_postcss.postcss.parse(source).walkRules((rule) => {
|
|
2269
|
-
if (rule.nodes?.some((node) => node.type === "atrule" && node.name === "apply")) hasApplyRule = true;
|
|
2270
|
-
else hasNonApplyRule = true;
|
|
2271
|
-
});
|
|
2272
|
-
} catch {
|
|
2273
|
-
return false;
|
|
2274
|
-
}
|
|
2275
|
-
return hasApplyRule && !hasNonApplyRule;
|
|
2276
|
-
}
|
|
2277
|
-
function removeCssComments(css) {
|
|
2278
|
-
return css.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
2279
|
-
}
|
|
2280
|
-
function isEmptyCustomVariantBlock(rule) {
|
|
2281
|
-
if (rule.name !== "custom-variant") return false;
|
|
2282
|
-
if (!/^[\w-]+$/.test(rule.params.trim())) return false;
|
|
2283
|
-
if (rule.nodes === void 0) return true;
|
|
2284
|
-
return rule.nodes.every((node) => node.type === "comment");
|
|
2285
|
-
}
|
|
2286
|
-
function normalizeEmptyTailwindCustomVariants(css) {
|
|
2287
|
-
if (!css.includes("@custom-variant")) return css;
|
|
2288
|
-
try {
|
|
2289
|
-
const root = _weapp_tailwindcss_postcss.postcss.parse(css);
|
|
2290
|
-
let changed = false;
|
|
2291
|
-
root.walkAtRules("custom-variant", (rule) => {
|
|
2292
|
-
if (!isEmptyCustomVariantBlock(rule)) return;
|
|
2293
|
-
rule.remove();
|
|
2294
|
-
changed = true;
|
|
2295
|
-
});
|
|
2296
|
-
return changed ? root.toString() : css;
|
|
2297
|
-
} catch {
|
|
2298
|
-
return css;
|
|
2299
|
-
}
|
|
2300
|
-
}
|
|
2301
|
-
function filterApplyOnlyGeneratedCss(css, source, options = {}) {
|
|
2302
|
-
const selectors = collectApplyOnlySourceSelectors(source);
|
|
2303
|
-
if (selectors.size === 0) return css;
|
|
2304
|
-
const selectorList = [...selectors];
|
|
2305
|
-
const preserveVariables = options.preserveVariables !== false;
|
|
2306
|
-
try {
|
|
2307
|
-
const root = _weapp_tailwindcss_postcss.postcss.parse(css);
|
|
2308
|
-
root.walkRules((rule) => {
|
|
2309
|
-
const isApplySelector = (rule.selectors ?? [rule.selector]).some((selector) => {
|
|
2310
|
-
const normalized = normalizeGeneratedSelector(selector);
|
|
2311
|
-
return selectorList.some((sourceSelector) => {
|
|
2312
|
-
if (normalized === sourceSelector) return true;
|
|
2313
|
-
if (!normalized.startsWith(sourceSelector)) return false;
|
|
2314
|
-
const next = normalized[sourceSelector.length];
|
|
2315
|
-
return next === ":" || next === "[" || next === ".";
|
|
2316
|
-
});
|
|
2317
|
-
});
|
|
2318
|
-
const isVariableRule = rule.nodes?.some((node) => node.type === "decl" && node.prop.startsWith("--"));
|
|
2319
|
-
if (!isApplySelector && (!preserveVariables || !isVariableRule)) rule.remove();
|
|
2320
|
-
});
|
|
2321
|
-
root.walkAtRules((rule) => {
|
|
2322
|
-
if (rule.nodes !== void 0 && rule.nodes.length === 0) rule.remove();
|
|
2323
|
-
});
|
|
2324
|
-
return removeCssComments(root.toString()).trim();
|
|
2325
|
-
} catch {
|
|
2326
|
-
return css;
|
|
2327
|
-
}
|
|
2328
|
-
}
|
|
2329
|
-
function shouldFilterApplyOnlyGeneratedCss(_majorVersion, target, source, options) {
|
|
2330
|
-
return (target === "weapp" || target === "web") && hasTailwindApplyDirective(source) && !hasTailwindRootDirectives(source) && !options.hasGeneratedCss && !options.hasGeneratedMarkers && collectApplyOnlySourceSelectors(source).size > 0 && hasOnlyApplyBackedSourceRules(source);
|
|
2331
|
-
}
|
|
2455
|
+
//#endregion
|
|
2456
|
+
//#region src/bundlers/shared/generator-css/user-css/transform.ts
|
|
2332
2457
|
async function transformGeneratorUserCss(source, options) {
|
|
2333
2458
|
if (source.trim().length === 0) return "";
|
|
2334
2459
|
if (options.processed) return stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(removeTailwindV4GeneratorAtRules(options.generatorTarget === "weapp" ? removeTailwindV4GeneratedUserCssArtifacts(unwrapMiniProgramCascadeLayers(removeProcessedMiniProgramUnsupportedCss(source, {
|
|
@@ -3214,6 +3339,12 @@ Object.defineProperty(exports, "parseImportRequest", {
|
|
|
3214
3339
|
return parseImportRequest;
|
|
3215
3340
|
}
|
|
3216
3341
|
});
|
|
3342
|
+
Object.defineProperty(exports, "preferScopedGeneratedCssRules", {
|
|
3343
|
+
enumerable: true,
|
|
3344
|
+
get: function() {
|
|
3345
|
+
return preferScopedGeneratedCssRules;
|
|
3346
|
+
}
|
|
3347
|
+
});
|
|
3217
3348
|
Object.defineProperty(exports, "prependConfigDirective", {
|
|
3218
3349
|
enumerable: true,
|
|
3219
3350
|
get: function() {
|