weapp-tailwindcss 5.0.0-next.11 → 5.0.0-next.14

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.
Files changed (77) hide show
  1. package/dist/{bundle-state-BrtFgX-A.mjs → bundle-state-BOBbxYzQ.mjs} +3 -2
  2. package/dist/{bundle-state-BRkhpjio.js → bundle-state-CxtGmT4t.js} +3 -2
  3. package/dist/bundlers/shared/css-cleanup.d.ts +6 -1
  4. package/dist/bundlers/shared/generator-css/source-files.d.ts +9 -6
  5. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +16 -2
  6. package/dist/bundlers/shared/generator-css.d.ts +4 -0
  7. package/dist/bundlers/shared/hmr-timing.d.ts +18 -1
  8. package/dist/bundlers/vite/bundle-state.d.ts +1 -0
  9. package/dist/bundlers/vite/css-finalizer.d.ts +2 -0
  10. package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +5 -1
  11. package/dist/bundlers/vite/generate-bundle/css-share-scope.d.ts +1 -0
  12. package/dist/bundlers/vite/generate-bundle.d.ts +8 -1
  13. package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +1 -0
  14. package/dist/bundlers/vite/runtime-class-set.d.ts +4 -1
  15. package/dist/bundlers/vite/source-candidates.d.ts +11 -0
  16. package/dist/bundlers/vite/source-scan.d.ts +18 -1
  17. package/dist/bundlers/vite/static-config-content.d.ts +5 -0
  18. package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +5 -0
  19. package/dist/cli.js +486 -18
  20. package/dist/cli.mjs +484 -17
  21. package/dist/core.js +1 -1
  22. package/dist/core.mjs +1 -1
  23. package/dist/defaults-B1igPF_e.mjs +150 -0
  24. package/dist/defaults-IHhYxNeU.js +193 -0
  25. package/dist/defaults.js +6 -150
  26. package/dist/defaults.mjs +1 -143
  27. package/dist/generator-C9H44wEF.mjs +32 -0
  28. package/dist/generator-CRORPkpW.js +55 -0
  29. package/dist/generator.js +12 -11
  30. package/dist/generator.mjs +2 -1
  31. package/dist/gulp.js +49 -13
  32. package/dist/gulp.mjs +46 -10
  33. package/dist/{incremental-runtime-class-set-CBMefNHQ.js → incremental-runtime-class-set-B4EXHHii.js} +512 -103
  34. package/dist/{incremental-runtime-class-set-DaS2yw5c.mjs → incremental-runtime-class-set-DoKrMrEh.mjs} +491 -88
  35. package/dist/index.js +4 -4
  36. package/dist/index.mjs +4 -4
  37. package/dist/js/babel/cache-options.d.ts +3 -0
  38. package/dist/js/babel/parse.d.ts +7 -4
  39. package/dist/{postcss-xZDiTRII.mjs → postcss-BFxu5_cs.mjs} +19 -8
  40. package/dist/{postcss-Bs-RbNzK.js → postcss-CZE8k8oP.js} +59 -53
  41. package/dist/{postcss-BdcRlSpp.js → postcss-Vqn4IlO3.js} +30 -19
  42. package/dist/postcss.js +1 -1
  43. package/dist/postcss.mjs +1 -1
  44. package/dist/{precheck-D5eEdqeH.js → precheck-CZHcFX8k.js} +65 -25
  45. package/dist/{precheck-DtBGFS-n.mjs → precheck-DCresEiu.mjs} +57 -17
  46. package/dist/presets.js +4 -4
  47. package/dist/presets.mjs +2 -2
  48. package/dist/source-candidates-BvbvkIPP.js +274 -0
  49. package/dist/source-candidates-CK70jGo7.mjs +259 -0
  50. package/dist/tailwindcss/runtime/cache.d.ts +1 -0
  51. package/dist/tailwindcss/v3-engine/types.d.ts +3 -0
  52. package/dist/tailwindcss/v4-engine/types.d.ts +8 -0
  53. package/dist/{tailwindcss-DGM8lHUj.mjs → tailwindcss-7k0LFa12.mjs} +8 -3
  54. package/dist/{tailwindcss-B78nj6n7.js → tailwindcss-CN0K7G-l.js} +20 -15
  55. package/dist/types/index.d.ts +7 -1
  56. package/dist/types/user-defined-options/general.d.ts +2 -0
  57. package/dist/v3-engine-D61eilBl.mjs +3208 -0
  58. package/dist/v3-engine-DwV1E6rX.js +3461 -0
  59. package/dist/{vite-C8S1wfyQ.mjs → vite-DCmKrTo0.mjs} +378 -540
  60. package/dist/{vite-BEj9JOOA.js → vite-DJ0P9Hrp.js} +383 -548
  61. package/dist/vite.js +1 -1
  62. package/dist/vite.mjs +1 -1
  63. package/dist/weapp-tw-css-import-rewrite-loader.js +29 -9
  64. package/dist/weapp-tw-runtime-classset-loader.js +1 -1
  65. package/dist/{webpack-Dm1IXTIh.js → webpack-8y4NOMnT.js} +39 -22
  66. package/dist/{webpack-ZGIKKpFf.mjs → webpack-CbO4jjkH.mjs} +35 -18
  67. package/dist/webpack.js +1 -1
  68. package/dist/webpack.mjs +1 -1
  69. package/package.json +3 -3
  70. package/dist/cache-B_9E7FxF.js +0 -517
  71. package/dist/cache-DEDxBMIw.mjs +0 -443
  72. package/dist/generator-CahkD2vq.mjs +0 -1469
  73. package/dist/generator-Ck1Dd1V0.js +0 -1568
  74. package/dist/runtime-patch-CqB-A4zA.js +0 -85
  75. package/dist/runtime-patch-DGKsVkiG.mjs +0 -71
  76. package/dist/source-scan-CIVTa3Cj.js +0 -297
  77. package/dist/source-scan-CJ0y0XBj.mjs +0 -258
@@ -1,1469 +0,0 @@
1
- import { a as createTailwindcssPatcher, c as resolveTailwindcssOptions, l as omitUndefined } from "./cache-DEDxBMIw.mjs";
2
- import { t as ensureTailwindcssRuntimePatch } from "./runtime-patch-DGKsVkiG.mjs";
3
- import { createRequire } from "node:module";
4
- import postcss from "postcss";
5
- import path from "node:path";
6
- import process from "node:process";
7
- import { createTailwindV4Engine, loadTailwindV4DesignSystem, resolveTailwindV4Source, resolveTailwindV4SourceFromPatchOptions } from "tailwindcss-patch";
8
- import { createStyleHandler, protectDynamicColorMixAlpha } from "@weapp-tailwindcss/postcss";
9
- import { loadConfig } from "tailwindcss-config";
10
- //#region src/tailwindcss/remove-unsupported-css.ts
11
- /**
12
- * 移除小程序不支持的 cascade layer 语法,同时保留 layer 内的实际规则。
13
- */
14
- function removeUnsupportedCascadeLayers(root) {
15
- root.walkAtRules("layer", (atRule) => {
16
- if (!atRule.nodes || atRule.nodes.length === 0) {
17
- atRule.remove();
18
- return;
19
- }
20
- atRule.replaceWith(...atRule.nodes);
21
- });
22
- }
23
- //#endregion
24
- //#region src/tailwindcss/miniprogram.ts
25
- const DEFAULT_WEAPP_VARIABLE_SCOPE = "page,.tw-root,wx-root-portal-content,:host";
26
- const CLASS_SELECTOR_RE = /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i;
27
- const PSEUDO_CONTENT_SELECTOR_RE = /^(?:::before|::after|:before|:after)(?:,(?:::before|::after|:before|:after))*$/;
28
- const MINI_PROGRAM_PREFLIGHT_SELECTORS = new Set([
29
- "*",
30
- "view",
31
- "text",
32
- ":before",
33
- ":after",
34
- "::before",
35
- "::after"
36
- ]);
37
- const PREFLIGHT_RESET_PROPS = new Set([
38
- "box-sizing",
39
- "border",
40
- "border-width",
41
- "border-style",
42
- "border-color",
43
- "margin",
44
- "padding"
45
- ]);
46
- function hasClassSelector(selector) {
47
- return CLASS_SELECTOR_RE.test(selector);
48
- }
49
- function normalizeSelector$1(selector) {
50
- return selector.trim().replace(/\s+/g, "");
51
- }
52
- function getRuleSelectors(rule) {
53
- return rule.selector.split(",").map(normalizeSelector$1).filter(Boolean);
54
- }
55
- function isCustomPropertyRule(rule) {
56
- let hasDeclaration = false;
57
- let allCustomProperties = true;
58
- rule.walkDecls((decl) => {
59
- hasDeclaration = true;
60
- if (!decl.prop.startsWith("--")) allCustomProperties = false;
61
- });
62
- return hasDeclaration && allCustomProperties;
63
- }
64
- function isPseudoContentInitRule(rule) {
65
- const selector = rule.selector.replace(/\s+/g, "");
66
- if (!PSEUDO_CONTENT_SELECTOR_RE.test(selector)) return false;
67
- let hasDeclaration = false;
68
- let onlyContentVariable = true;
69
- rule.walkDecls((decl) => {
70
- hasDeclaration = true;
71
- if (decl.prop !== "--tw-content") onlyContentVariable = false;
72
- });
73
- return hasDeclaration && onlyContentVariable;
74
- }
75
- function isMiniProgramPreflightRule(rule) {
76
- const selectors = getRuleSelectors(rule);
77
- if (selectors.length === 0 || !selectors.every((selector) => MINI_PROGRAM_PREFLIGHT_SELECTORS.has(selector)) || !selectors.some((selector) => selector === "*" || selector === ":before" || selector === ":after" || selector === "::before" || selector === "::after")) return false;
78
- let hasTailwindVariable = false;
79
- let hasResetProp = false;
80
- rule.walkDecls((decl) => {
81
- if (decl.prop.startsWith("--tw-")) hasTailwindVariable = true;
82
- if (PREFLIGHT_RESET_PROPS.has(decl.prop)) hasResetProp = true;
83
- });
84
- return hasTailwindVariable || hasResetProp;
85
- }
86
- function isKeyframesRule(rule) {
87
- let parent = rule.parent;
88
- while (parent) {
89
- if (parent.type === "atrule" && parent.name.endsWith("keyframes")) return true;
90
- parent = parent.parent;
91
- }
92
- return false;
93
- }
94
- /**
95
- * 裁剪 Tailwind 生成 CSS 中面向浏览器的 classless 规则。
96
- *
97
- * 生成模式面向小程序时只需要保留业务 utility 与 Tailwind 变量初始化;
98
- * 浏览器元素 reset、表单伪元素等 classless 规则不适合直接输出到小程序。
99
- */
100
- function pruneMiniProgramGeneratedCss(css, options = {}) {
101
- const root = postcss.parse(css);
102
- root.walkComments((comment) => {
103
- comment.remove();
104
- });
105
- removeUnsupportedCascadeLayers(root);
106
- root.walkAtRules("supports", (atRule) => {
107
- atRule.remove();
108
- });
109
- root.walkRules((rule) => {
110
- if (isKeyframesRule(rule)) return;
111
- if (hasClassSelector(rule.selector)) return;
112
- if (isPseudoContentInitRule(rule)) return;
113
- if (options.preservePreflight && isMiniProgramPreflightRule(rule)) return;
114
- if (isCustomPropertyRule(rule)) {
115
- rule.selector = DEFAULT_WEAPP_VARIABLE_SCOPE;
116
- return;
117
- }
118
- rule.remove();
119
- });
120
- root.walkAtRules((atRule) => {
121
- if (!atRule.nodes || atRule.nodes.length === 0) atRule.remove();
122
- });
123
- return root.toString();
124
- }
125
- //#endregion
126
- //#region src/tailwindcss/v3-engine/miniprogram.ts
127
- const defaultStyleHandler$1 = createStyleHandler({
128
- cssChildCombinatorReplaceValue: ["view", "text"],
129
- cssRemoveHoverPseudoClass: true,
130
- isMainChunk: true,
131
- majorVersion: 3
132
- });
133
- const MINI_PROGRAM_V3_PREFLIGHT_SELECTOR = "view,text,::before,::after";
134
- const V3_PREFLIGHT_RESET_PROPS = new Set([
135
- "box-sizing",
136
- "border",
137
- "border-width",
138
- "border-style",
139
- "border-color",
140
- "margin",
141
- "padding"
142
- ]);
143
- function normalizeSelector(selector) {
144
- return selector.trim().replace(/\s+/g, "");
145
- }
146
- function isMiniProgramV3PreflightRule(rule) {
147
- return normalizeSelector(rule.selector) === MINI_PROGRAM_V3_PREFLIGHT_SELECTOR;
148
- }
149
- function hasResetDeclaration(rule) {
150
- let found = false;
151
- rule.walkDecls((decl) => {
152
- if (V3_PREFLIGHT_RESET_PROPS.has(decl.prop)) found = true;
153
- });
154
- return found;
155
- }
156
- function createPreflightDeclarations(cssPreflight) {
157
- if (!cssPreflight || typeof cssPreflight !== "object") return [];
158
- return Object.entries(cssPreflight).filter((entry) => entry[1] !== false).map(([prop, value]) => postcss.decl({
159
- prop,
160
- value: value.toString()
161
- }));
162
- }
163
- function ensureMiniProgramV3PreflightReset(css, cssPreflight) {
164
- const declarations = createPreflightDeclarations(cssPreflight);
165
- if (declarations.length === 0) return css;
166
- try {
167
- const root = postcss.parse(css);
168
- let targetRule;
169
- let hasReset = false;
170
- root.walkRules((rule) => {
171
- if (!isMiniProgramV3PreflightRule(rule)) return;
172
- targetRule ?? (targetRule = rule);
173
- if (hasResetDeclaration(rule)) hasReset = true;
174
- });
175
- if (!targetRule || hasReset) return css;
176
- targetRule.append(...declarations.map((decl) => decl.clone()));
177
- return root.toString();
178
- } catch {
179
- return css;
180
- }
181
- }
182
- async function transformTailwindV3CssToWeapp(css, options) {
183
- return ensureMiniProgramV3PreflightReset(pruneMiniProgramGeneratedCss((await defaultStyleHandler$1(css, {
184
- cssChildCombinatorReplaceValue: ["view", "text"],
185
- cssRemoveHoverPseudoClass: true,
186
- isMainChunk: true,
187
- majorVersion: 3,
188
- ...options
189
- })).css, { preservePreflight: true }), options?.cssPreflight);
190
- }
191
- async function transformTailwindV3CssByTarget(css, target, options) {
192
- return target === "weapp" ? transformTailwindV3CssToWeapp(css, options) : css;
193
- }
194
- //#endregion
195
- //#region src/tailwindcss/v3-engine/generator.ts
196
- function isLegacyContentObject(value) {
197
- return typeof value === "object" && value !== null && "files" in value;
198
- }
199
- function createRawContentEntries(candidates, sources) {
200
- const entries = [];
201
- const candidateContent = [...candidates].join(" ");
202
- if (candidateContent.length > 0) entries.push({
203
- raw: candidateContent,
204
- extension: "html"
205
- });
206
- for (const source of sources) entries.push({
207
- raw: source.content,
208
- extension: source.extension ?? "html"
209
- });
210
- return entries;
211
- }
212
- function mergeContent(content, rawEntries) {
213
- if (isLegacyContentObject(content)) return {
214
- ...content,
215
- relative: content.relative ?? true,
216
- files: [...[].concat(content.files ?? []), ...rawEntries]
217
- };
218
- return {
219
- relative: true,
220
- files: [...[].concat(content ?? []), ...rawEntries]
221
- };
222
- }
223
- function normalizeConfigObject(config) {
224
- if (!config || typeof config !== "object") return config;
225
- const maybeDefault = config.default;
226
- if (maybeDefault && typeof maybeDefault === "object") return maybeDefault;
227
- return config;
228
- }
229
- function createTailwindConfig(source, options) {
230
- const config = { ...normalizeConfigObject(source.configObject) ?? {} };
231
- const rawEntries = createRawContentEntries(options.candidates ?? [], options.sources ?? []);
232
- config.content = mergeContent(config.content, rawEntries);
233
- return config;
234
- }
235
- function loadTailwindcssPlugin(source) {
236
- const requireFromProject = createRequire(`${source.cwd}/package.json`);
237
- const requireFromRuntime = createRequire(import.meta.url);
238
- let plugin;
239
- try {
240
- plugin = requireFromProject(source.postcssPlugin);
241
- } catch {
242
- plugin = requireFromRuntime(source.postcssPlugin);
243
- }
244
- return typeof plugin === "function" ? plugin : plugin.default;
245
- }
246
- function collectClassSet(plugin) {
247
- const classSet = /* @__PURE__ */ new Set();
248
- for (const context of plugin.contextRef?.value ?? []) for (const candidate of context.classCache?.keys() ?? []) if (String(candidate) !== "*") classSet.add(candidate);
249
- return classSet;
250
- }
251
- function collectDependencyMessages(result) {
252
- const dependencies = /* @__PURE__ */ new Set();
253
- for (const message of result.messages) {
254
- const file = message["file"];
255
- if (message.type === "dependency" && typeof file === "string") dependencies.add(file);
256
- }
257
- return dependencies;
258
- }
259
- function createRuntimeReadyPromise(source) {
260
- return ensureTailwindcssRuntimePatch(createTailwindcssPatcher({
261
- basedir: source.cwd,
262
- supportCustomLengthUnitsPatch: true,
263
- tailwindcss: {
264
- ...source.config === void 0 ? {} : { config: source.config },
265
- cwd: source.cwd,
266
- packageName: source.packageName,
267
- postcssPlugin: source.postcssPlugin,
268
- version: 3
269
- }
270
- }), { clearRequireCache: true });
271
- }
272
- function createTailwindV3Engine(source) {
273
- const runtimeReadyPromise = createRuntimeReadyPromise(source);
274
- async function generate(options = {}) {
275
- await runtimeReadyPromise;
276
- const { styleOptions, target = "weapp" } = options;
277
- const tailwindcss = loadTailwindcssPlugin(source);
278
- const result = await postcss([tailwindcss(createTailwindConfig(source, options))]).process(source.css, { from: void 0 });
279
- const rawCss = result.css;
280
- const css = await transformTailwindV3CssByTarget(rawCss, target, styleOptions);
281
- const dependencies = collectDependencyMessages(result);
282
- for (const dependency of source.dependencies) dependencies.add(dependency);
283
- return {
284
- css,
285
- rawCss,
286
- classSet: collectClassSet(tailwindcss),
287
- rawCandidates: new Set(options.candidates ?? []),
288
- dependencies: [...dependencies],
289
- sources: [],
290
- root: null,
291
- target,
292
- version: 3
293
- };
294
- }
295
- return {
296
- source,
297
- async validateCandidates(candidates) {
298
- return (await generate({
299
- candidates,
300
- target: "tailwind"
301
- })).classSet;
302
- },
303
- generate
304
- };
305
- }
306
- //#endregion
307
- //#region src/tailwindcss/v3-engine/source.ts
308
- const DEFAULT_TAILWIND_V3_CSS = [
309
- "@tailwind base;",
310
- "@tailwind components;",
311
- "@tailwind utilities;"
312
- ].join("\n");
313
- function parseConfigParam(params) {
314
- const value = params.trim();
315
- return /^(['"])(.+)\1$/.exec(value)?.[2];
316
- }
317
- function resolveOptionalPath(value, base) {
318
- if (!value) return;
319
- return path.isAbsolute(value) ? value : path.resolve(base, value);
320
- }
321
- function resolveCssConfig(css, base) {
322
- if (!css) return {
323
- css,
324
- config: void 0
325
- };
326
- const root = postcss.parse(css);
327
- let config;
328
- root.walkAtRules("config", (rule) => {
329
- const configPath = parseConfigParam(rule.params);
330
- if (!configPath) return;
331
- if (!config) config = resolveOptionalPath(configPath, base);
332
- rule.remove();
333
- });
334
- return {
335
- config,
336
- css: root.toString()
337
- };
338
- }
339
- function getProjectRoot$1(patcher) {
340
- return patcher.options?.projectRoot ?? process.cwd();
341
- }
342
- function normalizeLoadedConfig(config) {
343
- if (!config || typeof config !== "object") return config;
344
- const maybeDefault = config.default;
345
- if (maybeDefault && typeof maybeDefault === "object") return maybeDefault;
346
- return config;
347
- }
348
- function resolveTailwindCssPackageName(patcher) {
349
- return resolveTailwindcssOptions(patcher.options)?.packageName ?? patcher.packageInfo?.name ?? "tailwindcss";
350
- }
351
- async function resolveTailwindV3Source(options = {}) {
352
- const projectRoot = options.projectRoot ?? process.cwd();
353
- const base = options.base ?? options.cwd ?? projectRoot;
354
- const cssConfig = resolveCssConfig(options.css, base);
355
- const config = resolveOptionalPath(options.config, base) ?? cssConfig.config;
356
- const cwd = options.cwd ?? (config ? path.dirname(config) : projectRoot);
357
- const loaded = await loadConfig(omitUndefined({
358
- config,
359
- cwd
360
- }));
361
- return {
362
- version: 3,
363
- projectRoot,
364
- cwd,
365
- base,
366
- css: cssConfig.css ?? options.css ?? DEFAULT_TAILWIND_V3_CSS,
367
- config: loaded?.filepath ?? config,
368
- configObject: normalizeLoadedConfig(loaded?.config),
369
- dependencies: loaded?.filepath ? [loaded.filepath] : [],
370
- packageName: options.packageName ?? "tailwindcss",
371
- postcssPlugin: options.postcssPlugin ?? options.packageName ?? "tailwindcss"
372
- };
373
- }
374
- function resolveTailwindV3SourceOptionsFromPatcher(patcher) {
375
- const projectRoot = getProjectRoot$1(patcher);
376
- const tailwindOptions = resolveTailwindcssOptions(patcher.options);
377
- return {
378
- projectRoot,
379
- cwd: tailwindOptions?.v3?.cwd ?? tailwindOptions?.cwd ?? projectRoot,
380
- config: tailwindOptions?.v3?.config ?? tailwindOptions?.config,
381
- packageName: resolveTailwindCssPackageName(patcher),
382
- postcssPlugin: tailwindOptions?.v3?.postcssPlugin ?? tailwindOptions?.postcssPlugin
383
- };
384
- }
385
- function resolveTailwindV3SourceFromPatcher(patcher) {
386
- return resolveTailwindV3Source(resolveTailwindV3SourceOptionsFromPatcher(patcher));
387
- }
388
- //#endregion
389
- //#region src/tailwindcss/v4-engine/candidates.ts
390
- const UNSUPPORTED_MINI_PROGRAM_TAILWIND_V4_CANDIDATE_RE = /(?:^|:)(?:group|peer|in|not-in)-[^\s:]*\/|(?:^|:)(?:in|not-in)-\[/;
391
- function isUnsupportedMiniProgramTailwindV4Candidate(candidate) {
392
- return UNSUPPORTED_MINI_PROGRAM_TAILWIND_V4_CANDIDATE_RE.test(candidate);
393
- }
394
- function filterUnsupportedMiniProgramTailwindV4Candidates(candidates) {
395
- if (!candidates) return;
396
- return new Set([...candidates].filter((candidate) => !isUnsupportedMiniProgramTailwindV4Candidate(candidate)));
397
- }
398
- //#endregion
399
- //#region src/tailwindcss/v4-engine/miniprogram.ts
400
- const defaultStyleHandler = createStyleHandler({
401
- cssChildCombinatorReplaceValue: ["view", "text"],
402
- cssRemoveHoverPseudoClass: true,
403
- isMainChunk: true,
404
- majorVersion: 4
405
- });
406
- const CSS_DECLARATION_URL_RE = /(:\s*)url\(([^\n\r"';[\]{}]*[[\]{}][^\n\r;]*)\)(?=\s*;)/g;
407
- function normalizeTailwindV4GeneratedUrlValues(css) {
408
- return css.replace(CSS_DECLARATION_URL_RE, (match, prefix, urlValue) => {
409
- try {
410
- return `${prefix}url("${urlValue.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"")}")`;
411
- } catch {
412
- return match;
413
- }
414
- });
415
- }
416
- async function transformTailwindV4CssToWeapp(css, options) {
417
- const protectedCss = protectDynamicColorMixAlpha(normalizeTailwindV4GeneratedUrlValues(css));
418
- const result = await defaultStyleHandler(protectedCss.css, {
419
- cssChildCombinatorReplaceValue: ["view", "text"],
420
- cssRemoveHoverPseudoClass: true,
421
- isMainChunk: true,
422
- majorVersion: 4,
423
- ...options
424
- });
425
- return pruneMiniProgramGeneratedCss(protectedCss.restore(result.css));
426
- }
427
- async function transformTailwindV4CssByTarget(css, target, options) {
428
- return target === "weapp" ? transformTailwindV4CssToWeapp(css, options) : css;
429
- }
430
- //#endregion
431
- //#region src/tailwindcss/v4-engine/tailwind-v3-default-colors.ts
432
- const TAILWIND_V3_COLOR_STEPS = [
433
- "50",
434
- "100",
435
- "200",
436
- "300",
437
- "400",
438
- "500",
439
- "600",
440
- "700",
441
- "800",
442
- "900",
443
- "950"
444
- ];
445
- const TAILWIND_V3_COLOR_PALETTE = {
446
- slate: [
447
- "#f8fafc",
448
- "#f1f5f9",
449
- "#e2e8f0",
450
- "#cbd5e1",
451
- "#94a3b8",
452
- "#64748b",
453
- "#475569",
454
- "#334155",
455
- "#1e293b",
456
- "#0f172a",
457
- "#020617"
458
- ],
459
- gray: [
460
- "#f9fafb",
461
- "#f3f4f6",
462
- "#e5e7eb",
463
- "#d1d5db",
464
- "#9ca3af",
465
- "#6b7280",
466
- "#4b5563",
467
- "#374151",
468
- "#1f2937",
469
- "#111827",
470
- "#030712"
471
- ],
472
- zinc: [
473
- "#fafafa",
474
- "#f4f4f5",
475
- "#e4e4e7",
476
- "#d4d4d8",
477
- "#a1a1aa",
478
- "#71717a",
479
- "#52525b",
480
- "#3f3f46",
481
- "#27272a",
482
- "#18181b",
483
- "#09090b"
484
- ],
485
- neutral: [
486
- "#fafafa",
487
- "#f5f5f5",
488
- "#e5e5e5",
489
- "#d4d4d4",
490
- "#a3a3a3",
491
- "#737373",
492
- "#525252",
493
- "#404040",
494
- "#262626",
495
- "#171717",
496
- "#0a0a0a"
497
- ],
498
- stone: [
499
- "#fafaf9",
500
- "#f5f5f4",
501
- "#e7e5e4",
502
- "#d6d3d1",
503
- "#a8a29e",
504
- "#78716c",
505
- "#57534e",
506
- "#44403c",
507
- "#292524",
508
- "#1c1917",
509
- "#0c0a09"
510
- ],
511
- red: [
512
- "#fef2f2",
513
- "#fee2e2",
514
- "#fecaca",
515
- "#fca5a5",
516
- "#f87171",
517
- "#ef4444",
518
- "#dc2626",
519
- "#b91c1c",
520
- "#991b1b",
521
- "#7f1d1d",
522
- "#450a0a"
523
- ],
524
- orange: [
525
- "#fff7ed",
526
- "#ffedd5",
527
- "#fed7aa",
528
- "#fdba74",
529
- "#fb923c",
530
- "#f97316",
531
- "#ea580c",
532
- "#c2410c",
533
- "#9a3412",
534
- "#7c2d12",
535
- "#431407"
536
- ],
537
- amber: [
538
- "#fffbeb",
539
- "#fef3c7",
540
- "#fde68a",
541
- "#fcd34d",
542
- "#fbbf24",
543
- "#f59e0b",
544
- "#d97706",
545
- "#b45309",
546
- "#92400e",
547
- "#78350f",
548
- "#451a03"
549
- ],
550
- yellow: [
551
- "#fefce8",
552
- "#fef9c3",
553
- "#fef08a",
554
- "#fde047",
555
- "#facc15",
556
- "#eab308",
557
- "#ca8a04",
558
- "#a16207",
559
- "#854d0e",
560
- "#713f12",
561
- "#422006"
562
- ],
563
- lime: [
564
- "#f7fee7",
565
- "#ecfccb",
566
- "#d9f99d",
567
- "#bef264",
568
- "#a3e635",
569
- "#84cc16",
570
- "#65a30d",
571
- "#4d7c0f",
572
- "#3f6212",
573
- "#365314",
574
- "#1a2e05"
575
- ],
576
- green: [
577
- "#f0fdf4",
578
- "#dcfce7",
579
- "#bbf7d0",
580
- "#86efac",
581
- "#4ade80",
582
- "#22c55e",
583
- "#16a34a",
584
- "#15803d",
585
- "#166534",
586
- "#14532d",
587
- "#052e16"
588
- ],
589
- emerald: [
590
- "#ecfdf5",
591
- "#d1fae5",
592
- "#a7f3d0",
593
- "#6ee7b7",
594
- "#34d399",
595
- "#10b981",
596
- "#059669",
597
- "#047857",
598
- "#065f46",
599
- "#064e3b",
600
- "#022c22"
601
- ],
602
- teal: [
603
- "#f0fdfa",
604
- "#ccfbf1",
605
- "#99f6e4",
606
- "#5eead4",
607
- "#2dd4bf",
608
- "#14b8a6",
609
- "#0d9488",
610
- "#0f766e",
611
- "#115e59",
612
- "#134e4a",
613
- "#042f2e"
614
- ],
615
- cyan: [
616
- "#ecfeff",
617
- "#cffafe",
618
- "#a5f3fc",
619
- "#67e8f9",
620
- "#22d3ee",
621
- "#06b6d4",
622
- "#0891b2",
623
- "#0e7490",
624
- "#155e75",
625
- "#164e63",
626
- "#083344"
627
- ],
628
- sky: [
629
- "#f0f9ff",
630
- "#e0f2fe",
631
- "#bae6fd",
632
- "#7dd3fc",
633
- "#38bdf8",
634
- "#0ea5e9",
635
- "#0284c7",
636
- "#0369a1",
637
- "#075985",
638
- "#0c4a6e",
639
- "#082f49"
640
- ],
641
- blue: [
642
- "#eff6ff",
643
- "#dbeafe",
644
- "#bfdbfe",
645
- "#93c5fd",
646
- "#60a5fa",
647
- "#3b82f6",
648
- "#2563eb",
649
- "#1d4ed8",
650
- "#1e40af",
651
- "#1e3a8a",
652
- "#172554"
653
- ],
654
- indigo: [
655
- "#eef2ff",
656
- "#e0e7ff",
657
- "#c7d2fe",
658
- "#a5b4fc",
659
- "#818cf8",
660
- "#6366f1",
661
- "#4f46e5",
662
- "#4338ca",
663
- "#3730a3",
664
- "#312e81",
665
- "#1e1b4b"
666
- ],
667
- violet: [
668
- "#f5f3ff",
669
- "#ede9fe",
670
- "#ddd6fe",
671
- "#c4b5fd",
672
- "#a78bfa",
673
- "#8b5cf6",
674
- "#7c3aed",
675
- "#6d28d9",
676
- "#5b21b6",
677
- "#4c1d95",
678
- "#2e1065"
679
- ],
680
- purple: [
681
- "#faf5ff",
682
- "#f3e8ff",
683
- "#e9d5ff",
684
- "#d8b4fe",
685
- "#c084fc",
686
- "#a855f7",
687
- "#9333ea",
688
- "#7e22ce",
689
- "#6b21a8",
690
- "#581c87",
691
- "#3b0764"
692
- ],
693
- fuchsia: [
694
- "#fdf4ff",
695
- "#fae8ff",
696
- "#f5d0fe",
697
- "#f0abfc",
698
- "#e879f9",
699
- "#d946ef",
700
- "#c026d3",
701
- "#a21caf",
702
- "#86198f",
703
- "#701a75",
704
- "#4a044e"
705
- ],
706
- pink: [
707
- "#fdf2f8",
708
- "#fce7f3",
709
- "#fbcfe8",
710
- "#f9a8d4",
711
- "#f472b6",
712
- "#ec4899",
713
- "#db2777",
714
- "#be185d",
715
- "#9d174d",
716
- "#831843",
717
- "#500724"
718
- ],
719
- rose: [
720
- "#fff1f2",
721
- "#ffe4e6",
722
- "#fecdd3",
723
- "#fda4af",
724
- "#fb7185",
725
- "#f43f5e",
726
- "#e11d48",
727
- "#be123c",
728
- "#9f1239",
729
- "#881337",
730
- "#4c0519"
731
- ]
732
- };
733
- function createTailwindV3DefaultColorThemeCss() {
734
- const declarations = [" --color-black: #000;", " --color-white: #fff;"];
735
- 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]};`);
736
- return [
737
- "@theme {",
738
- ...declarations,
739
- "}"
740
- ].join("\n");
741
- }
742
- //#endregion
743
- //#region src/tailwindcss/v4-engine/tailwind-v3-compatibility.ts
744
- const TAILWIND_V3_COMPATIBILITY_THEME_CSS = [
745
- "@theme {",
746
- " --default-ring-width: 3px;",
747
- " --default-ring-color: var(--color-blue-500, #3b82f6);",
748
- " --default-outline-width: 3px;",
749
- "",
750
- " --shadow-xs: 0 1px rgb(0 0 0 / 0.05);",
751
- " --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);",
752
- " --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);",
753
- " --drop-shadow-xs: 0 1px 1px rgb(0 0 0 / 0.05);",
754
- " --drop-shadow-sm: 0 1px 2px rgb(0 0 0 / 0.15);",
755
- " --drop-shadow: 0 1px 2px rgb(0 0 0 / 0.1), 0 1px 1px rgb(0 0 0 / 0.06);",
756
- "",
757
- " --blur-xs: 4px;",
758
- " --blur-sm: 4px;",
759
- " --blur: 8px;",
760
- " --backdrop-blur-xs: 4px;",
761
- " --backdrop-blur-sm: 4px;",
762
- " --backdrop-blur: 8px;",
763
- "",
764
- " --radius-xs: 0.125rem;",
765
- " --radius-sm: 0.125rem;",
766
- " --radius: 0.25rem;",
767
- "}",
768
- createTailwindV3DefaultColorThemeCss()
769
- ].join("\n");
770
- const TAILWIND_V3_COMPATIBILITY_BASE_CSS = [
771
- "*,",
772
- "::after,",
773
- "::before,",
774
- "::backdrop,",
775
- "::file-selector-button {",
776
- " border-color: var(--color-gray-200, currentcolor);",
777
- "}",
778
- "",
779
- "input::placeholder,",
780
- "textarea::placeholder {",
781
- " opacity: 1;",
782
- " color: var(--color-gray-400, currentcolor);",
783
- "}",
784
- "",
785
- "button:not(:disabled),",
786
- "[role=\"button\"]:not(:disabled) {",
787
- " cursor: pointer;",
788
- "}",
789
- "",
790
- "dialog {",
791
- " margin: auto;",
792
- "}"
793
- ].join("\n");
794
- function applyTailwindV3CompatibilityCss(css) {
795
- return `${TAILWIND_V3_COMPATIBILITY_THEME_CSS}\n${css}\n${TAILWIND_V3_COMPATIBILITY_BASE_CSS}`;
796
- }
797
- //#endregion
798
- //#region src/tailwindcss/v4-engine/tailwind-v4-default-colors.ts
799
- const TAILWIND_V4_COLOR_STEPS = [
800
- "50",
801
- "100",
802
- "200",
803
- "300",
804
- "400",
805
- "500",
806
- "600",
807
- "700",
808
- "800",
809
- "900",
810
- "950"
811
- ];
812
- const TAILWIND_V4_COLOR_PALETTE = {
813
- slate: [
814
- "#f8fafc",
815
- "#f1f5f9",
816
- "#e2e8f0",
817
- "#cad5e2",
818
- "#90a1b9",
819
- "#62748e",
820
- "#45556c",
821
- "#314158",
822
- "#1d293d",
823
- "#0f172b",
824
- "#020618"
825
- ],
826
- gray: [
827
- "#f9fafb",
828
- "#f3f4f6",
829
- "#e5e7eb",
830
- "#d1d5dc",
831
- "#99a1af",
832
- "#6a7282",
833
- "#4a5565",
834
- "#364153",
835
- "#1e2939",
836
- "#101828",
837
- "#030712"
838
- ],
839
- zinc: [
840
- "#fafafa",
841
- "#f4f4f5",
842
- "#e4e4e7",
843
- "#d4d4d8",
844
- "#9f9fa9",
845
- "#71717b",
846
- "#52525c",
847
- "#3f3f46",
848
- "#27272a",
849
- "#18181b",
850
- "#09090b"
851
- ],
852
- neutral: [
853
- "#fafafa",
854
- "#f5f5f5",
855
- "#e5e5e5",
856
- "#d4d4d4",
857
- "#a1a1a1",
858
- "#737373",
859
- "#525252",
860
- "#404040",
861
- "#262626",
862
- "#171717",
863
- "#0a0a0a"
864
- ],
865
- stone: [
866
- "#fafaf9",
867
- "#f5f5f4",
868
- "#e7e5e4",
869
- "#d6d3d1",
870
- "#a6a09b",
871
- "#79716b",
872
- "#57534d",
873
- "#44403b",
874
- "#292524",
875
- "#1c1917",
876
- "#0c0a09"
877
- ],
878
- mauve: [
879
- "#fafafa",
880
- "#f3f1f3",
881
- "#e7e4e7",
882
- "#d7d0d7",
883
- "#a89ea9",
884
- "#79697b",
885
- "#594c5b",
886
- "#463947",
887
- "#2a212c",
888
- "#1d161e",
889
- "#0c090c"
890
- ],
891
- olive: [
892
- "#fbfbf9",
893
- "#f4f4f0",
894
- "#e8e8e3",
895
- "#d8d8d0",
896
- "#abab9c",
897
- "#7c7c67",
898
- "#5b5b4b",
899
- "#474739",
900
- "#2b2b22",
901
- "#1d1d16",
902
- "#0c0c09"
903
- ],
904
- mist: [
905
- "#f9fbfb",
906
- "#f1f3f3",
907
- "#e3e7e8",
908
- "#d0d6d8",
909
- "#9ca8ab",
910
- "#67787c",
911
- "#4b585b",
912
- "#394447",
913
- "#22292b",
914
- "#161b1d",
915
- "#090b0c"
916
- ],
917
- taupe: [
918
- "#fbfaf9",
919
- "#f3f1f1",
920
- "#e8e4e3",
921
- "#d8d2d0",
922
- "#aba09c",
923
- "#7c6d67",
924
- "#5b4f4b",
925
- "#473c39",
926
- "#2b2422",
927
- "#1d1816",
928
- "#0c0a09"
929
- ],
930
- red: [
931
- "#fef2f2",
932
- "#ffe2e2",
933
- "#ffc9c9",
934
- "#ffa2a2",
935
- "#ff6467",
936
- "#fb2c36",
937
- "#e7000b",
938
- "#c10007",
939
- "#9f0712",
940
- "#82181a",
941
- "#460809"
942
- ],
943
- orange: [
944
- "#fff7ed",
945
- "#ffedd4",
946
- "#ffd6a7",
947
- "#ffb86a",
948
- "#ff8904",
949
- "#ff6900",
950
- "#f54900",
951
- "#ca3500",
952
- "#9f2d00",
953
- "#7e2a0c",
954
- "#441306"
955
- ],
956
- amber: [
957
- "#fffbeb",
958
- "#fef3c6",
959
- "#fee685",
960
- "#ffd230",
961
- "#ffb900",
962
- "#fe9a00",
963
- "#e17100",
964
- "#bb4d00",
965
- "#973c00",
966
- "#7b3306",
967
- "#461901"
968
- ],
969
- yellow: [
970
- "#fefce8",
971
- "#fef9c2",
972
- "#fff085",
973
- "#ffdf20",
974
- "#fdc700",
975
- "#f0b100",
976
- "#d08700",
977
- "#a65f00",
978
- "#894b00",
979
- "#733e0a",
980
- "#432004"
981
- ],
982
- lime: [
983
- "#f7fee7",
984
- "#ecfcca",
985
- "#d8f999",
986
- "#bbf451",
987
- "#9ae600",
988
- "#7ccf00",
989
- "#5ea500",
990
- "#497d00",
991
- "#3c6300",
992
- "#35530e",
993
- "#192e03"
994
- ],
995
- green: [
996
- "#f0fdf4",
997
- "#dcfce7",
998
- "#b9f8cf",
999
- "#7bf1a8",
1000
- "#05df72",
1001
- "#00c950",
1002
- "#00a63e",
1003
- "#008236",
1004
- "#016630",
1005
- "#0d542b",
1006
- "#032e15"
1007
- ],
1008
- emerald: [
1009
- "#ecfdf5",
1010
- "#d0fae5",
1011
- "#a4f4cf",
1012
- "#5ee9b5",
1013
- "#00d492",
1014
- "#00bc7d",
1015
- "#009966",
1016
- "#007a55",
1017
- "#006045",
1018
- "#004f3b",
1019
- "#002c22"
1020
- ],
1021
- teal: [
1022
- "#f0fdfa",
1023
- "#cbfbf1",
1024
- "#96f7e4",
1025
- "#46ecd5",
1026
- "#00d5be",
1027
- "#00bba7",
1028
- "#009689",
1029
- "#00786f",
1030
- "#005f5a",
1031
- "#0b4f4a",
1032
- "#022f2e"
1033
- ],
1034
- cyan: [
1035
- "#ecfeff",
1036
- "#cefafe",
1037
- "#a2f4fd",
1038
- "#53eafd",
1039
- "#00d3f2",
1040
- "#00b8db",
1041
- "#0092b8",
1042
- "#007595",
1043
- "#005f78",
1044
- "#104e64",
1045
- "#053345"
1046
- ],
1047
- sky: [
1048
- "#f0f9ff",
1049
- "#dff2fe",
1050
- "#b8e6fe",
1051
- "#74d4ff",
1052
- "#00bcff",
1053
- "#00a6f4",
1054
- "#0084d1",
1055
- "#0069a8",
1056
- "#00598a",
1057
- "#024a70",
1058
- "#052f4a"
1059
- ],
1060
- blue: [
1061
- "#eff6ff",
1062
- "#dbeafe",
1063
- "#bedbff",
1064
- "#8ec5ff",
1065
- "#51a2ff",
1066
- "#2b7fff",
1067
- "#155dfc",
1068
- "#1447e6",
1069
- "#193cb8",
1070
- "#1c398e",
1071
- "#162456"
1072
- ],
1073
- indigo: [
1074
- "#eef2ff",
1075
- "#e0e7ff",
1076
- "#c6d2ff",
1077
- "#a3b3ff",
1078
- "#7c86ff",
1079
- "#615fff",
1080
- "#4f39f6",
1081
- "#432dd7",
1082
- "#372aac",
1083
- "#312c85",
1084
- "#1e1a4d"
1085
- ],
1086
- violet: [
1087
- "#f5f3ff",
1088
- "#ede9fe",
1089
- "#ddd6ff",
1090
- "#c4b4ff",
1091
- "#a684ff",
1092
- "#8e51ff",
1093
- "#7f22fe",
1094
- "#7008e7",
1095
- "#5d0ec0",
1096
- "#4d179a",
1097
- "#2f0d68"
1098
- ],
1099
- purple: [
1100
- "#faf5ff",
1101
- "#f3e8ff",
1102
- "#e9d4ff",
1103
- "#dab2ff",
1104
- "#c27aff",
1105
- "#ad46ff",
1106
- "#9810fa",
1107
- "#8200db",
1108
- "#6e11b0",
1109
- "#59168b",
1110
- "#3c0366"
1111
- ],
1112
- fuchsia: [
1113
- "#fdf4ff",
1114
- "#fae8ff",
1115
- "#f6cfff",
1116
- "#f4a8ff",
1117
- "#ed6aff",
1118
- "#e12afb",
1119
- "#c800de",
1120
- "#a800b7",
1121
- "#8a0194",
1122
- "#721378",
1123
- "#4b004f"
1124
- ],
1125
- pink: [
1126
- "#fdf2f8",
1127
- "#fce7f3",
1128
- "#fccee8",
1129
- "#fda5d5",
1130
- "#fb64b6",
1131
- "#f6339a",
1132
- "#e60076",
1133
- "#c6005c",
1134
- "#a3004c",
1135
- "#861043",
1136
- "#510424"
1137
- ],
1138
- rose: [
1139
- "#fff1f2",
1140
- "#ffe4e6",
1141
- "#ffccd3",
1142
- "#ffa1ad",
1143
- "#ff637e",
1144
- "#ff2056",
1145
- "#ec003f",
1146
- "#c70036",
1147
- "#a50036",
1148
- "#8b0836",
1149
- "#4d0218"
1150
- ]
1151
- };
1152
- function createTailwindV4DefaultColorThemeCss() {
1153
- const declarations = [" --color-black: #000;", " --color-white: #fff;"];
1154
- 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]};`);
1155
- return [
1156
- "@theme {",
1157
- ...declarations,
1158
- "}"
1159
- ].join("\n");
1160
- }
1161
- //#endregion
1162
- //#region src/tailwindcss/v4-engine/generator.ts
1163
- function findLeadingImportInsertionIndex(css) {
1164
- const importPattern = /(?:^|\n)\s*@import\b[^;]*;/g;
1165
- let insertionIndex = 0;
1166
- let match = importPattern.exec(css);
1167
- while (match !== null) {
1168
- insertionIndex = match.index + match[0].length;
1169
- match = importPattern.exec(css);
1170
- }
1171
- return insertionIndex;
1172
- }
1173
- function applyMiniProgramTailwindV4DefaultColorCss(css) {
1174
- const themeCss = createTailwindV4DefaultColorThemeCss();
1175
- const insertionIndex = findLeadingImportInsertionIndex(css);
1176
- if (insertionIndex === 0) return `${themeCss}\n${css}`;
1177
- return `${css.slice(0, insertionIndex)}\n${themeCss}\n${css.slice(insertionIndex)}`;
1178
- }
1179
- function parseImportSourceParam(params) {
1180
- const match = /\bsource\(\s*(none|(['"])(.*?)\2)\s*\)/.exec(params);
1181
- if (!match) return;
1182
- return {
1183
- none: match[1] === "none",
1184
- sourcePath: match[3]
1185
- };
1186
- }
1187
- function isTailwindCssImport(params) {
1188
- return /^\s*(['"])tailwindcss(?:\/[^'"]*)?\1/.test(params);
1189
- }
1190
- function parseCssImportSpecifier$1(params) {
1191
- const value = params.trim();
1192
- const quoted = /^(['"])(.*?)\1/.exec(value);
1193
- if (quoted) return quoted[2];
1194
- const url = /^url\(\s*(?:(['"])(.*?)\1|([^'")\s]+))\s*\)/.exec(value);
1195
- return url?.[2] ?? url?.[3];
1196
- }
1197
- function isTailwindCssPreflightImport(params) {
1198
- const specifier = parseCssImportSpecifier$1(params);
1199
- return specifier === "tailwindcss/preflight.css" || specifier === "tailwindcss/preflight";
1200
- }
1201
- function hasImportLayerOption(params) {
1202
- return /\blayer(?:\s*\(|\s*$)/.test(params);
1203
- }
1204
- function removeUnlayeredTailwindV4PreflightImports(css) {
1205
- if (!css.includes("preflight")) return css;
1206
- let root;
1207
- try {
1208
- root = postcss.parse(css);
1209
- } catch {
1210
- return css;
1211
- }
1212
- let changed = false;
1213
- root.walkAtRules("import", (rule) => {
1214
- if (isTailwindCssPreflightImport(rule.params) && !hasImportLayerOption(rule.params)) {
1215
- rule.remove();
1216
- changed = true;
1217
- }
1218
- });
1219
- return changed ? root.toString() : css;
1220
- }
1221
- function parseSourceFileParam(params) {
1222
- const value = params.trim();
1223
- if (!value || value === "none" || value.startsWith("inline(")) return;
1224
- const negated = value.startsWith("not ");
1225
- const sourceValue = negated ? value.slice(4).trim() : value;
1226
- if (sourceValue.startsWith("inline(")) return;
1227
- const match = /^(['"])(.+)\1$/.exec(sourceValue);
1228
- return match?.[2] ? {
1229
- negated,
1230
- pattern: match[2]
1231
- } : void 0;
1232
- }
1233
- function resolveSourceBase(base, sourcePath) {
1234
- return path.isAbsolute(sourcePath) ? sourcePath : path.resolve(base, sourcePath);
1235
- }
1236
- function resolveCssDefinedScanSources(source) {
1237
- let importSourceBase;
1238
- let hasSourceNone = false;
1239
- const sourcePatterns = [];
1240
- const from = source.dependencies[0];
1241
- let root;
1242
- try {
1243
- root = postcss.parse(source.css, { from });
1244
- } catch {
1245
- return;
1246
- }
1247
- root.walkAtRules((rule) => {
1248
- if (rule.name === "import") {
1249
- if (!isTailwindCssImport(rule.params)) return;
1250
- const sourceParam = parseImportSourceParam(rule.params);
1251
- if (sourceParam?.none) hasSourceNone = true;
1252
- if (sourceParam?.sourcePath) importSourceBase = resolveSourceBase(source.base, sourceParam.sourcePath);
1253
- return;
1254
- }
1255
- if (rule.name !== "source") return;
1256
- const sourcePattern = parseSourceFileParam(rule.params);
1257
- if (!sourcePattern) return;
1258
- sourcePatterns.push({
1259
- base: source.base,
1260
- negated: sourcePattern.negated,
1261
- pattern: sourcePattern.pattern
1262
- });
1263
- });
1264
- if (!importSourceBase) {
1265
- if (hasSourceNone) return sourcePatterns.length > 0 ? sourcePatterns : false;
1266
- return;
1267
- }
1268
- return [{
1269
- base: importSourceBase,
1270
- negated: false,
1271
- pattern: "**/*"
1272
- }, ...sourcePatterns];
1273
- }
1274
- function resolveScanSources(source, scanSources) {
1275
- if (scanSources !== true) return scanSources;
1276
- return resolveCssDefinedScanSources(source) ?? scanSources;
1277
- }
1278
- function hasThemeParent(rule) {
1279
- let parent = rule.parent;
1280
- while (parent) {
1281
- if (parent.type === "atrule" && parent.name === "theme") return true;
1282
- parent = parent.parent;
1283
- }
1284
- return false;
1285
- }
1286
- function isVendorPrefixedKeyframes(rule) {
1287
- return rule.name.startsWith("-") && rule.name.endsWith("keyframes");
1288
- }
1289
- function removeUnsupportedThemeVendorKeyframes(css) {
1290
- if (!css.includes("@theme") || !css.includes("@-")) return css;
1291
- let root;
1292
- try {
1293
- root = postcss.parse(css);
1294
- } catch {
1295
- return css;
1296
- }
1297
- let changed = false;
1298
- root.walkAtRules((rule) => {
1299
- if (isVendorPrefixedKeyframes(rule) && hasThemeParent(rule)) {
1300
- rule.remove();
1301
- changed = true;
1302
- }
1303
- });
1304
- return changed ? root.toString() : css;
1305
- }
1306
- function createTailwindV4Engine$1(source) {
1307
- async function generate(options = {}) {
1308
- const { scanSources = true, styleOptions, tailwindcssV3Compatibility, target = "weapp", ...patchOptions } = options;
1309
- const shouldApplyTailwindV3Compatibility = tailwindcssV3Compatibility ?? target === "weapp";
1310
- const filteredSourceCss = target === "weapp" ? removeUnlayeredTailwindV4PreflightImports(source.css) : source.css;
1311
- const compatibleSourceCss = removeUnsupportedThemeVendorKeyframes(shouldApplyTailwindV3Compatibility ? applyTailwindV3CompatibilityCss(filteredSourceCss) : target === "weapp" ? applyMiniProgramTailwindV4DefaultColorCss(filteredSourceCss) : filteredSourceCss);
1312
- const candidates = target === "weapp" ? filterUnsupportedMiniProgramTailwindV4Candidates(patchOptions.candidates) : patchOptions.candidates;
1313
- const result = await createTailwindV4Engine(compatibleSourceCss === source.css ? source : {
1314
- ...source,
1315
- css: compatibleSourceCss
1316
- }).generate(omitUndefined({
1317
- scanSources: resolveScanSources(source, scanSources),
1318
- ...patchOptions,
1319
- candidates
1320
- }));
1321
- const rawCss = result.css;
1322
- const css = await transformTailwindV4CssByTarget(rawCss, target, styleOptions);
1323
- return {
1324
- ...result,
1325
- css,
1326
- rawCss,
1327
- target
1328
- };
1329
- }
1330
- return {
1331
- source,
1332
- loadDesignSystem: createTailwindV4Engine(source).loadDesignSystem,
1333
- validateCandidates: createTailwindV4Engine(source).validateCandidates,
1334
- generate
1335
- };
1336
- }
1337
- //#endregion
1338
- //#region src/tailwindcss/v4-engine/source.ts
1339
- function isPostcssPluginImportTarget(value) {
1340
- if (!value) return false;
1341
- return value === "@tailwindcss/postcss" || value.includes("/postcss");
1342
- }
1343
- function uniqueDefined(values) {
1344
- return [...new Set(values.filter((value) => typeof value === "string" && value.length > 0))];
1345
- }
1346
- function getProjectRoot(patcher) {
1347
- return patcher.options?.projectRoot ?? process.cwd();
1348
- }
1349
- function readConfiguredV4Base(tailwindOptions) {
1350
- const v4 = tailwindOptions?.v4;
1351
- if (typeof v4 !== "object" || v4 === null) return;
1352
- return v4.configuredBase;
1353
- }
1354
- function isBarePackageSpecifier(specifier) {
1355
- return !specifier.startsWith(".") && !specifier.startsWith("/") && !specifier.includes("\\") && !/^[a-z][a-z\d+.-]*:/i.test(specifier);
1356
- }
1357
- function parseCssImportSpecifier(params) {
1358
- const value = params.trim();
1359
- const quoted = /^(['"])(.*?)\1/.exec(value);
1360
- if (quoted) {
1361
- const specifier = quoted[2];
1362
- if (specifier === void 0) return;
1363
- return {
1364
- quote: quoted[1],
1365
- raw: quoted[0],
1366
- specifier
1367
- };
1368
- }
1369
- const url = /^url\(\s*(?:(['"])(.*?)\1|([^'")\s]+))\s*\)/.exec(value);
1370
- if (!url) return;
1371
- const specifier = url[2] ?? url[3];
1372
- if (specifier === void 0) return;
1373
- return {
1374
- quote: url[1],
1375
- raw: url[0],
1376
- specifier
1377
- };
1378
- }
1379
- function quoteCssImportSpecifier(specifier, quote = "\"") {
1380
- return `${quote}${specifier.replaceAll("\\", "\\\\").replaceAll(quote, `\\${quote}`)}${quote}`;
1381
- }
1382
- function createTailwindV4CssImportSpecifierSet(packageName) {
1383
- const specifiers = new Set(["tailwindcss"]);
1384
- if (packageName && isBarePackageSpecifier(packageName)) specifiers.add(packageName);
1385
- return specifiers;
1386
- }
1387
- function normalizeTailwindV4CssPackageImports(css, packageName) {
1388
- if (!css.includes("tailwindcss")) return css;
1389
- let root;
1390
- try {
1391
- root = postcss.parse(css);
1392
- } catch {
1393
- return css;
1394
- }
1395
- const importSpecifiers = createTailwindV4CssImportSpecifierSet(packageName);
1396
- let changed = false;
1397
- root.walkAtRules("import", (rule) => {
1398
- const parsed = parseCssImportSpecifier(rule.params);
1399
- if (!parsed || !importSpecifiers.has(parsed.specifier)) return;
1400
- rule.params = rule.params.replace(parsed.raw, quoteCssImportSpecifier(`${parsed.specifier}/index.css`, parsed.quote));
1401
- changed = true;
1402
- });
1403
- return changed ? root.toString() : css;
1404
- }
1405
- function resolveTailwindCssImportTarget(patcher) {
1406
- const configuredPackageName = resolveTailwindcssOptions(patcher.options)?.packageName;
1407
- if (typeof configuredPackageName === "string" && configuredPackageName.length > 0 && !isPostcssPluginImportTarget(configuredPackageName)) return configuredPackageName;
1408
- const packageName = patcher.packageInfo?.name;
1409
- if (typeof packageName === "string" && packageName.length > 0 && !isPostcssPluginImportTarget(packageName)) return packageName;
1410
- return "tailwindcss";
1411
- }
1412
- function resolveTailwindV4SourceOptionsFromPatcher(patcher) {
1413
- const projectRoot = getProjectRoot(patcher);
1414
- const tailwindOptions = resolveTailwindcssOptions(patcher.options);
1415
- const configDir = tailwindOptions?.config ? path.dirname(tailwindOptions.config) : void 0;
1416
- const configuredBase = readConfiguredV4Base(tailwindOptions);
1417
- const hasCssEntries = Boolean(tailwindOptions?.v4?.cssEntries?.length);
1418
- return omitUndefined({
1419
- projectRoot,
1420
- base: configuredBase ?? (hasCssEntries ? void 0 : tailwindOptions?.v4?.base),
1421
- baseFallbacks: uniqueDefined([tailwindOptions?.cwd, configDir]),
1422
- css: tailwindOptions?.v4?.css,
1423
- cssSources: tailwindOptions?.v4?.cssSources,
1424
- cssEntries: tailwindOptions?.v4?.cssEntries,
1425
- sources: tailwindOptions?.v4?.sources,
1426
- packageName: resolveTailwindCssImportTarget(patcher)
1427
- });
1428
- }
1429
- function resolveTailwindV4Source$1(options) {
1430
- return resolveTailwindV4Source(options?.css === void 0 ? options : {
1431
- ...options,
1432
- css: normalizeTailwindV4CssPackageImports(options.css, options.packageName)
1433
- });
1434
- }
1435
- async function resolveTailwindV4SourceFromPatcher(patcher) {
1436
- return resolveTailwindV4Source$1(resolveTailwindV4SourceOptionsFromPatcher(patcher));
1437
- }
1438
- //#endregion
1439
- //#region src/generator/options.ts
1440
- function normalizeWeappTailwindcssGeneratorOptions(options) {
1441
- if (options == null) return {
1442
- target: "weapp",
1443
- importFallback: true,
1444
- tailwindcssV3Compatibility: true
1445
- };
1446
- return {
1447
- target: options.target ?? "weapp",
1448
- config: options.config,
1449
- styleOptions: options.styleOptions,
1450
- importFallback: options.importFallback ?? true,
1451
- tailwindcssV3Compatibility: options.tailwindcssV3Compatibility ?? (options.target ?? "weapp") === "weapp"
1452
- };
1453
- }
1454
- //#endregion
1455
- //#region src/generator/index.ts
1456
- function isTailwindV3Source(source) {
1457
- return "version" in source && source.version === 3;
1458
- }
1459
- function createWeappTailwindcssGenerator(source) {
1460
- return isTailwindV3Source(source) ? createTailwindV3Engine(source) : createTailwindV4Engine$1(source);
1461
- }
1462
- async function resolveTailwindSourceFromPatcher(patcher) {
1463
- return patcher.majorVersion === 3 ? resolveTailwindV3SourceFromPatcher(patcher) : resolveTailwindV4SourceFromPatcher(patcher);
1464
- }
1465
- async function createWeappTailwindcssGeneratorFromPatcher(patcher) {
1466
- return createWeappTailwindcssGenerator(await resolveTailwindSourceFromPatcher(patcher));
1467
- }
1468
- //#endregion
1469
- export { transformTailwindV3CssToWeapp as _, resolveTailwindV4Source$1 as a, resolveTailwindV4SourceOptionsFromPatcher as c, filterUnsupportedMiniProgramTailwindV4Candidates as d, loadTailwindV4DesignSystem as f, transformTailwindV3CssByTarget as g, resolveTailwindV3SourceOptionsFromPatcher as h, normalizeWeappTailwindcssGeneratorOptions as i, transformTailwindV4CssByTarget as l, resolveTailwindV3SourceFromPatcher as m, createWeappTailwindcssGeneratorFromPatcher as n, resolveTailwindV4SourceFromPatchOptions as o, resolveTailwindV3Source as p, resolveTailwindSourceFromPatcher as r, resolveTailwindV4SourceFromPatcher as s, createWeappTailwindcssGenerator as t, transformTailwindV4CssToWeapp as u, removeUnsupportedCascadeLayers as v };