weapp-tailwindcss 5.0.0-next.8 → 5.0.0

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 (167) hide show
  1. package/README.md +2 -2
  2. package/dist/auto-DEHRmEAx.mjs +200 -0
  3. package/dist/auto-dPpsm6FB.js +238 -0
  4. package/dist/bundle-state-CnaJxkFY.mjs +413 -0
  5. package/dist/bundle-state-DgGEhk_z.js +529 -0
  6. package/dist/bundlers/shared/cache.d.ts +9 -7
  7. package/dist/bundlers/shared/css-cleanup/at-rules.d.ts +1 -2
  8. package/dist/bundlers/shared/css-cleanup.d.ts +1 -3
  9. package/dist/bundlers/shared/css-imports.d.ts +3 -3
  10. package/dist/bundlers/shared/generated-css-marker.d.ts +3 -0
  11. package/dist/bundlers/shared/generator-css/directives.d.ts +12 -3
  12. package/dist/bundlers/shared/generator-css/markers.d.ts +12 -0
  13. package/dist/bundlers/shared/generator-css/source-files.d.ts +9 -6
  14. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +16 -2
  15. package/dist/bundlers/shared/generator-css/user-layer-order.d.ts +10 -0
  16. package/dist/bundlers/shared/generator-css.d.ts +6 -2
  17. package/dist/bundlers/shared/hmr-timing.d.ts +22 -0
  18. package/dist/bundlers/shared/style-requests.d.ts +2 -0
  19. package/dist/bundlers/vite/bundle-state.d.ts +1 -0
  20. package/dist/bundlers/vite/css-finalizer.d.ts +6 -0
  21. package/dist/bundlers/vite/generate-bundle/candidates.d.ts +1 -1
  22. package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +5 -1
  23. package/dist/bundlers/vite/generate-bundle/css-share-scope.d.ts +1 -0
  24. package/dist/bundlers/vite/generate-bundle.d.ts +13 -1
  25. package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +10 -2
  26. package/dist/bundlers/vite/index.d.ts +5 -2
  27. package/dist/bundlers/vite/processed-css-assets.d.ts +32 -0
  28. package/dist/bundlers/vite/rewrite-css-imports.d.ts +8 -5
  29. package/dist/bundlers/vite/runtime-class-set.d.ts +5 -1
  30. package/dist/bundlers/vite/serve-css-generation.d.ts +11 -0
  31. package/dist/bundlers/vite/source-candidates.d.ts +24 -2
  32. package/dist/bundlers/vite/source-scan.d.ts +26 -0
  33. package/dist/bundlers/vite/static-config-content.d.ts +5 -0
  34. package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +5 -0
  35. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +5 -1
  36. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +8 -3
  37. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5.d.ts +1 -1
  38. package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +31 -0
  39. package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +2 -8
  40. package/dist/bundlers/webpack/loaders/weapp-tw-runtime-classset-loader.d.ts +3 -7
  41. package/dist/cache/index.d.ts +6 -6
  42. package/dist/{chunk-8l464Juk.js → chunk-C5U5_Hdc.js} +14 -0
  43. package/dist/cli/context.d.ts +1 -11
  44. package/dist/cli/doctor/types.d.ts +11 -11
  45. package/dist/cli/vscode-entry.d.ts +3 -3
  46. package/dist/cli.js +684 -41
  47. package/dist/cli.mjs +682 -40
  48. package/dist/context/runtime-package-replacements.d.ts +2 -0
  49. package/dist/context/style-options.d.ts +3 -0
  50. package/dist/context/tailwindcss.d.ts +1 -1
  51. package/dist/core.js +1 -2
  52. package/dist/core.mjs +1 -1
  53. package/dist/css-macro/auto.d.ts +11 -0
  54. package/dist/css-macro/constants.d.ts +5 -2
  55. package/dist/css-macro/postcss.d.ts +1 -0
  56. package/dist/css-macro/postcss.js +7 -46
  57. package/dist/css-macro/postcss.mjs +2 -46
  58. package/dist/css-macro.js +16 -7
  59. package/dist/css-macro.mjs +15 -6
  60. package/dist/defaults-8xrgzxFY.mjs +151 -0
  61. package/dist/defaults-zKUH2mDe.js +193 -0
  62. package/dist/defaults.js +6 -150
  63. package/dist/defaults.mjs +1 -143
  64. package/dist/escape.js +10 -2
  65. package/dist/escape.mjs +10 -2
  66. package/dist/generator/options.d.ts +11 -6
  67. package/dist/generator/types.d.ts +3 -3
  68. package/dist/generator--0-ekuVO.js +92 -0
  69. package/dist/generator-B76ovqsv.mjs +67 -0
  70. package/dist/generator.js +12 -12
  71. package/dist/generator.mjs +2 -1
  72. package/dist/gulp.js +163 -40
  73. package/dist/gulp.mjs +155 -32
  74. package/dist/incremental-runtime-class-set-CN6K_97P.js +2366 -0
  75. package/dist/incremental-runtime-class-set-x10M9bn_.mjs +2291 -0
  76. package/dist/index.d.ts +2 -1
  77. package/dist/index.js +17 -5
  78. package/dist/index.mjs +6 -5
  79. package/dist/js/babel/cache-options.d.ts +3 -0
  80. package/dist/js/babel/parse.d.ts +7 -4
  81. package/dist/js/precheck.d.ts +2 -2
  82. package/dist/js/replacement-cache.d.ts +5 -0
  83. package/dist/postcss-C7BMYpEF.mjs +169 -0
  84. package/dist/{postcss-w48mGIhe.mjs → postcss-CR9UCaIK.mjs} +54 -114
  85. package/dist/postcss-CiYLsqZn.js +192 -0
  86. package/dist/{postcss-QIXwT40c.js → postcss-hYimKoN_.js} +60 -121
  87. package/dist/postcss-html-transform.js +1 -1
  88. package/dist/postcss.js +1 -1
  89. package/dist/postcss.mjs +1 -1
  90. package/dist/precheck-BrNwLG2e.mjs +4716 -0
  91. package/dist/precheck-DPtJjZmV.js +4842 -0
  92. package/dist/presets/index.d.ts +1 -0
  93. package/dist/presets/uni-app-x.d.ts +1 -0
  94. package/dist/presets.js +27 -13
  95. package/dist/presets.mjs +25 -13
  96. package/dist/reset.js +1 -1
  97. package/dist/runtime-registry-DpcR3IHI.js +5496 -0
  98. package/dist/shared/mpx.d.ts +1 -0
  99. package/dist/source-candidates-DN1mihlU.mjs +322 -0
  100. package/dist/source-candidates-DSxme_O2.js +335 -0
  101. package/dist/tailwindcss/miniprogram.d.ts +1 -5
  102. package/dist/tailwindcss/remove-unsupported-css.d.ts +1 -2
  103. package/dist/tailwindcss/runtime/cache.d.ts +4 -3
  104. package/dist/tailwindcss/runtime.d.ts +9 -9
  105. package/dist/tailwindcss/source-scan.d.ts +35 -0
  106. package/dist/tailwindcss/v3-engine/types.d.ts +19 -14
  107. package/dist/tailwindcss/v4/css-entries.d.ts +2 -2
  108. package/dist/tailwindcss/v4/patcher.d.ts +1 -1
  109. package/dist/tailwindcss/v4-engine/source.d.ts +2 -2
  110. package/dist/tailwindcss/v4-engine/types.d.ts +18 -5
  111. package/dist/{tailwindcss-C5IgPlQ0.mjs → tailwindcss-DWtPieNE.mjs} +72 -60
  112. package/dist/{tailwindcss-Bu-RWIHx.js → tailwindcss-glCm_d3H.js} +81 -69
  113. package/dist/typedoc.export.d.ts +1 -1
  114. package/dist/types/index.d.ts +51 -41
  115. package/dist/types/shared.d.ts +3 -0
  116. package/dist/types/typedoc-tailwindcss-patch.d.ts +67 -0
  117. package/dist/types/user-defined-options/general.d.ts +25 -22
  118. package/dist/types/user-defined-options/important.d.ts +32 -27
  119. package/dist/types/user-defined-options/lifecycle.d.ts +4 -4
  120. package/dist/types/user-defined-options/matcher.d.ts +6 -6
  121. package/dist/unocss/index.d.ts +2 -0
  122. package/dist/utils/object.d.ts +9 -0
  123. package/dist/utils/options.d.ts +2 -0
  124. package/dist/utils/regex.d.ts +1 -0
  125. package/dist/{utils-BiShvil9.js → utils-D7Ygohep.js} +2 -2
  126. package/dist/{utils-Btw1iOVV.mjs → utils-DsaS975I.mjs} +1 -1
  127. package/dist/v3-engine-D3BMLVAN.js +3712 -0
  128. package/dist/v3-engine-DCxNPBVs.mjs +3417 -0
  129. package/dist/vite-DOprpdH-.mjs +24493 -0
  130. package/dist/vite-Ec0uX6kF.js +24507 -0
  131. package/dist/vite.js +1 -1
  132. package/dist/vite.mjs +1 -1
  133. package/dist/weapp-tw-css-import-rewrite-loader.js +5444 -22
  134. package/dist/weapp-tw-runtime-classset-loader.js +32 -9
  135. package/dist/{webpack-CNV2dx3Q.js → webpack-Ccohlg3A.js} +341 -96
  136. package/dist/{webpack-CT6EEENx.mjs → webpack-DFlZcqAU.mjs} +323 -79
  137. package/dist/webpack.d.ts +1 -3
  138. package/dist/webpack.js +3 -4
  139. package/dist/webpack.mjs +2 -2
  140. package/dist/wxml/utils/codegen/legacy-visitor.d.ts +2 -4
  141. package/package.json +22 -20
  142. package/dist/bundlers/shared/css-cleanup/color-gamut.d.ts +0 -3
  143. package/dist/bundlers/shared/css-cleanup/root-cleanups.d.ts +0 -4
  144. package/dist/bundlers/shared/css-cleanup/selectors.d.ts +0 -8
  145. package/dist/cache-BVAiJV3J.js +0 -502
  146. package/dist/cache-CHs4DXui.mjs +0 -434
  147. package/dist/constants-BoB_6lFw.js +0 -73
  148. package/dist/constants-E_loJC49.mjs +0 -44
  149. package/dist/generator-DKkhJbOg.js +0 -1531
  150. package/dist/generator-UBmfduYg.mjs +0 -1432
  151. package/dist/generator-css-BIapP56i.mjs +0 -1323
  152. package/dist/generator-css-Mksw8PgB.js +0 -1362
  153. package/dist/lightningcss/index.d.ts +0 -8
  154. package/dist/lightningcss/style-handler/options.d.ts +0 -3
  155. package/dist/lightningcss/style-handler/selector-transform.d.ts +0 -10
  156. package/dist/lightningcss/style-handler/selector-utils.d.ts +0 -10
  157. package/dist/lightningcss/style-handler.d.ts +0 -17
  158. package/dist/precheck-B32p-gLI.js +0 -2736
  159. package/dist/precheck-B4RH6ZNN.mjs +0 -2622
  160. package/dist/run-tasks-B50A3pxt.js +0 -128
  161. package/dist/run-tasks-DdNi-hkk.mjs +0 -91
  162. package/dist/runtime-patch-CwN5ya72.mjs +0 -71
  163. package/dist/runtime-patch-D6mBo_KB.js +0 -85
  164. package/dist/vite-BwgRVgxH.mjs +0 -2405
  165. package/dist/vite-DyZuiyap.js +0 -2418
  166. /package/dist/{logger-Bub1jggA.mjs → logger-BNzxZbZj.mjs} +0 -0
  167. /package/dist/{logger-BRy6XPQ2.js → logger-TlKT3xmR.js} +0 -0
package/dist/index.d.ts CHANGED
@@ -5,4 +5,5 @@ export { weappTailwindcssPostcssPlugin } from './postcss';
5
5
  export type { WeappTailwindcssPostcssPluginOptions } from './postcss';
6
6
  export type * from './types';
7
7
  export { WeappTailwindcss } from './vite';
8
- export { UnifiedWebpackPluginV5, weappTailwindcssPackageDir } from './webpack';
8
+ export { weappTailwindcssPackageDir } from './webpack';
9
+ export { unitConversionComposeRules, unitConversionPresets, } from '@weapp-tailwindcss/postcss';
package/dist/index.js CHANGED
@@ -1,12 +1,24 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_generator = require("./generator-DKkhJbOg.js");
2
+ const require_generator = require("./generator--0-ekuVO.js");
3
3
  const require_gulp = require("./gulp.js");
4
- const require_postcss = require("./postcss-QIXwT40c.js");
5
- const require_vite = require("./vite-DyZuiyap.js");
6
- const require_webpack = require("./webpack-CNV2dx3Q.js");
7
- exports.UnifiedWebpackPluginV5 = require_webpack.UnifiedWebpackPluginV5;
4
+ const require_postcss = require("./postcss-hYimKoN_.js");
5
+ const require_vite = require("./vite-Ec0uX6kF.js");
6
+ const require_webpack = require("./webpack-Ccohlg3A.js");
7
+ let _weapp_tailwindcss_postcss = require("@weapp-tailwindcss/postcss");
8
8
  exports.WeappTailwindcss = require_vite.WeappTailwindcss;
9
9
  exports.createPlugins = require_gulp.createPlugins;
10
10
  exports.createWeappTailwindcssGenerator = require_generator.createWeappTailwindcssGenerator;
11
+ Object.defineProperty(exports, "unitConversionComposeRules", {
12
+ enumerable: true,
13
+ get: function() {
14
+ return _weapp_tailwindcss_postcss.unitConversionComposeRules;
15
+ }
16
+ });
17
+ Object.defineProperty(exports, "unitConversionPresets", {
18
+ enumerable: true,
19
+ get: function() {
20
+ return _weapp_tailwindcss_postcss.unitConversionPresets;
21
+ }
22
+ });
11
23
  exports.weappTailwindcssPackageDir = require_webpack.weappTailwindcssPackageDir;
12
24
  exports.weappTailwindcssPostcssPlugin = require_postcss.weappTailwindcssPostcssPlugin;
package/dist/index.mjs CHANGED
@@ -1,6 +1,7 @@
1
- import { t as createWeappTailwindcssGenerator } from "./generator-UBmfduYg.mjs";
1
+ import { t as createWeappTailwindcssGenerator } from "./generator-B76ovqsv.mjs";
2
2
  import { WeappTailwindcss as createPlugins } from "./gulp.mjs";
3
- import { t as weappTailwindcssPostcssPlugin } from "./postcss-w48mGIhe.mjs";
4
- import { t as WeappTailwindcss } from "./vite-BwgRVgxH.mjs";
5
- import { n as weappTailwindcssPackageDir, t as UnifiedWebpackPluginV5 } from "./webpack-CT6EEENx.mjs";
6
- export { UnifiedWebpackPluginV5, WeappTailwindcss, createPlugins, createWeappTailwindcssGenerator, weappTailwindcssPackageDir, weappTailwindcssPostcssPlugin };
3
+ import { t as weappTailwindcssPostcssPlugin } from "./postcss-CR9UCaIK.mjs";
4
+ import { t as WeappTailwindcss } from "./vite-DOprpdH-.mjs";
5
+ import { n as weappTailwindcssPackageDir } from "./webpack-DFlZcqAU.mjs";
6
+ import { unitConversionComposeRules, unitConversionPresets } from "@weapp-tailwindcss/postcss";
7
+ export { WeappTailwindcss, createPlugins, createWeappTailwindcssGenerator, unitConversionComposeRules, unitConversionPresets, weappTailwindcssPackageDir, weappTailwindcssPostcssPlugin };
@@ -0,0 +1,3 @@
1
+ export declare const DEFAULT_PARSE_CACHE_MAX_ENTRIES = 128;
2
+ export declare const DEFAULT_PARSE_CACHE_MAX_SOURCE_LENGTH = 50000;
3
+ export declare const HARD_PARSE_CACHE_MAX_ENTRIES = 1024;
@@ -1,9 +1,12 @@
1
1
  import type { ParseResult, ParserOptions } from '@babel/parser';
2
2
  import type { File } from '@babel/types';
3
3
  import { LRUCache } from 'lru-cache';
4
+ export type BabelParseOptions = ParserOptions & {
5
+ cache?: boolean | undefined;
6
+ cacheKey?: string | undefined;
7
+ cacheMaxEntries?: number | undefined;
8
+ cacheMaxSourceLength?: number | undefined;
9
+ };
4
10
  export declare const parseCache: LRUCache<string, ParseResult<File>>;
5
11
  export declare function genCacheKey(source: string, options: any): string;
6
- export declare function babelParse(code: string, opts?: (ParserOptions & {
7
- cache?: boolean;
8
- cacheKey?: string;
9
- })): ParseResult<File>;
12
+ export declare function babelParse(code: string, opts?: BabelParseOptions): ParseResult<File>;
@@ -1,2 +1,2 @@
1
- import type { CreateJsHandlerOptions } from '../types';
2
- export declare function shouldSkipJsTransform(rawSource: string, options?: CreateJsHandlerOptions): boolean;
1
+ import type { IJsHandlerOptions } from '../types';
2
+ export declare function shouldSkipJsTransform(rawSource: string, options?: IJsHandlerOptions): boolean;
@@ -0,0 +1,5 @@
1
+ import type { IJsHandlerOptions } from '../types';
2
+ type EscapeMap = NonNullable<IJsHandlerOptions['escapeMap']>;
3
+ export declare function getReplacementCacheStore(escapeMap?: EscapeMap): Map<string, string>;
4
+ export declare function getReplacement(candidate: string, escapeMap: EscapeMap | undefined, store?: Map<string, string>): string;
5
+ export {};
@@ -0,0 +1,169 @@
1
+ //#region src/css-macro/constants.ts
2
+ const queryKey = "weapp-tw-platform";
3
+ const ifdefAtRule = "weapp-tw-ifdef";
4
+ const ifndefAtRule = "weapp-tw-ifndef";
5
+ function quoteAtRuleParam(value) {
6
+ return `"${value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"")}"`;
7
+ }
8
+ function createConditionalAtRule(value) {
9
+ return `@${ifdefAtRule} ${quoteAtRuleParam(value)}{&}`;
10
+ }
11
+ function createNegativeConditionalAtRule(value) {
12
+ return `@${ifndefAtRule} ${quoteAtRuleParam(value)}{&}`;
13
+ }
14
+ const UNESCAPED_UNDERSCORE_RE = /(?<!\\)_/g;
15
+ const WHITESPACE_RE = /\s+/g;
16
+ const LOGICAL_OPERATOR_RE = /\s*(\|\||&&)\s*/g;
17
+ function normalComment(text) {
18
+ if (typeof text === "string") {
19
+ const normalized = text.replaceAll(UNESCAPED_UNDERSCORE_RE, " ").replaceAll(WHITESPACE_RE, " ").trim();
20
+ if (normalized.includes("\\")) return normalized;
21
+ return normalized.replaceAll(LOGICAL_OPERATOR_RE, " $1 ").replaceAll(WHITESPACE_RE, " ").trim();
22
+ }
23
+ return text;
24
+ }
25
+ function ifdef(text) {
26
+ return {
27
+ start: `#ifdef ${normalComment(text)}`,
28
+ end: `#endif`
29
+ };
30
+ }
31
+ function ifndef(text) {
32
+ return {
33
+ start: `#ifndef ${normalComment(text)}`,
34
+ end: `#endif`
35
+ };
36
+ }
37
+ const QUERY_KEY_REGEX = new RegExp(`\\(\\s*${queryKey}\\s*:\\s*"([^)]*)"\\)`, "g");
38
+ function matchCustomPropertyFromValue(str, cb) {
39
+ let index = 0;
40
+ QUERY_KEY_REGEX.lastIndex = 0;
41
+ let arr = QUERY_KEY_REGEX.exec(str);
42
+ while (arr !== null) {
43
+ cb(arr, index);
44
+ index++;
45
+ arr = QUERY_KEY_REGEX.exec(str);
46
+ }
47
+ }
48
+ function parseConditionalAtRuleParam(params) {
49
+ const value = params.trim();
50
+ const quoted = /^(['"])((?:\\.|(?!\1).)*)\1/.exec(value);
51
+ if (!quoted) return value;
52
+ return quoted[2]?.replaceAll(/\\(["'\\])/g, "$1") ?? "";
53
+ }
54
+ //#endregion
55
+ //#region src/css-macro/postcss.ts
56
+ const IFDEF_ENDIF_RE = /#(?:ifn?def|endif)/;
57
+ const CONDITIONAL_COMMENT_SPACING = " ";
58
+ const CSS_MACRO_POSTCSS_PLUGIN_NAME = "postcss-weapp-tw-css-macro-plugin";
59
+ const creator = () => {
60
+ return {
61
+ postcssPlugin: CSS_MACRO_POSTCSS_PLUGIN_NAME,
62
+ prepare() {
63
+ function replaceAtRuleWithConditionalComments(atRule, helper, comment) {
64
+ const hasPreviousNode = Boolean(atRule.prev());
65
+ const clonedNodes = (atRule.nodes ?? []).map((node) => node.clone());
66
+ const startComment = helper.comment({
67
+ raws: {
68
+ left: CONDITIONAL_COMMENT_SPACING,
69
+ right: CONDITIONAL_COMMENT_SPACING
70
+ },
71
+ text: comment.start
72
+ });
73
+ const endComment = helper.comment({
74
+ raws: {
75
+ left: CONDITIONAL_COMMENT_SPACING,
76
+ right: CONDITIONAL_COMMENT_SPACING
77
+ },
78
+ text: comment.end
79
+ });
80
+ const nextNodes = [
81
+ startComment,
82
+ ...clonedNodes,
83
+ endComment
84
+ ];
85
+ atRule.replaceWith(nextNodes);
86
+ startComment.raws.before = hasPreviousNode ? "\n" : "";
87
+ startComment.raws["after"] = "\n";
88
+ if (clonedNodes[0]) clonedNodes[0].raws.before = "\n";
89
+ endComment.raws.before = "\n";
90
+ endComment.raws["after"] = "\n";
91
+ const nextNode = endComment?.next();
92
+ if (nextNode) nextNode.raws.before = "\n";
93
+ }
94
+ function replaceNestedAtRuleWithConditionalRule(atRule, helper, comment) {
95
+ if (atRule.parent?.type !== "rule") return false;
96
+ const parentRule = atRule.parent;
97
+ const clonedNodes = (atRule.nodes ?? []).map((node) => node.clone());
98
+ const conditionalRule = parentRule.clone();
99
+ conditionalRule.removeAll();
100
+ conditionalRule.append(...clonedNodes);
101
+ const startComment = helper.comment({
102
+ raws: {
103
+ left: CONDITIONAL_COMMENT_SPACING,
104
+ right: CONDITIONAL_COMMENT_SPACING
105
+ },
106
+ text: comment.start
107
+ });
108
+ const endComment = helper.comment({
109
+ raws: {
110
+ left: CONDITIONAL_COMMENT_SPACING,
111
+ right: CONDITIONAL_COMMENT_SPACING
112
+ },
113
+ text: comment.end
114
+ });
115
+ const nextNodes = [
116
+ startComment,
117
+ conditionalRule,
118
+ endComment
119
+ ];
120
+ const hasPreviousNode = Boolean(parentRule.prev());
121
+ atRule.remove();
122
+ if ((parentRule.nodes?.length ?? 0) === 0) parentRule.replaceWith(nextNodes);
123
+ else parentRule.after(nextNodes);
124
+ startComment.raws.before = hasPreviousNode ? "\n" : "";
125
+ startComment.raws["after"] = "\n";
126
+ conditionalRule.raws.before = "\n";
127
+ endComment.raws.before = "\n";
128
+ endComment.raws["after"] = "\n";
129
+ const nextNode = endComment.next();
130
+ if (nextNode) nextNode.raws.before = "\n";
131
+ return true;
132
+ }
133
+ return {
134
+ AtRule(atRule, helper) {
135
+ if (atRule.name === "weapp-tw-ifdef" || atRule.name === "weapp-tw-ifndef") {
136
+ const text = parseConditionalAtRuleParam(atRule.params);
137
+ const comment = atRule.name === "weapp-tw-ifndef" ? ifndef(text) : ifdef(text);
138
+ if (replaceNestedAtRuleWithConditionalRule(atRule, helper, comment)) return;
139
+ replaceAtRuleWithConditionalComments(atRule, helper, comment);
140
+ return;
141
+ }
142
+ if (atRule.name === "media") {
143
+ const values = [];
144
+ matchCustomPropertyFromValue(atRule.params, (arr) => {
145
+ const value = arr[1];
146
+ if (value) values.push(value);
147
+ });
148
+ if (values.length > 0) {
149
+ const isNegative = atRule.params.includes("not");
150
+ const text = values.join(" ");
151
+ const comment = isNegative ? ifndef(text) : ifdef(text);
152
+ if (replaceNestedAtRuleWithConditionalRule(atRule, helper, comment)) return;
153
+ replaceAtRuleWithConditionalComments(atRule, helper, comment);
154
+ }
155
+ }
156
+ },
157
+ CommentExit(comment) {
158
+ if (IFDEF_ENDIF_RE.test(comment.text)) {
159
+ comment.raws.left = CONDITIONAL_COMMENT_SPACING;
160
+ comment.raws.right = CONDITIONAL_COMMENT_SPACING;
161
+ }
162
+ }
163
+ };
164
+ }
165
+ };
166
+ };
167
+ creator.postcss = true;
168
+ //#endregion
169
+ export { createNegativeConditionalAtRule as i, creator as n, createConditionalAtRule as r, CSS_MACRO_POSTCSS_PLUGIN_NAME as t };
@@ -1,12 +1,11 @@
1
- import { o as readInstalledPackageMajorVersion } from "./cache-CHs4DXui.mjs";
2
- import { a as resolveTailwindV4Source$1, i as normalizeWeappTailwindcssGeneratorOptions, p as resolveTailwindV3Source, t as createWeappTailwindcssGenerator } from "./generator-UBmfduYg.mjs";
1
+ import { A as collectCssInlineSourceCandidates, F as parseConfigParam, H as readInstalledPackageMajorVersion, I as resolveCssSourceEntries, M as expandTailwindSourceEntries, O as DEFAULT_SOURCE_SCAN_EXTENSIONS, P as normalizeLegacyContentEntries, j as createSourceScanPattern, t as resolveTailwindV3Source, y as resolveTailwindV4Source$1 } from "./v3-engine-DCxNPBVs.mjs";
2
+ import { i as normalizeWeappTailwindcssGeneratorOptions, t as createWeappTailwindcssGenerator } from "./generator-B76ovqsv.mjs";
3
3
  import postcss from "postcss";
4
- import path from "node:path";
4
+ import { extractRawCandidatesWithPositions, extractValidCandidates } from "tailwindcss-patch";
5
5
  import process from "node:process";
6
- import { extractValidCandidates } from "tailwindcss-patch";
6
+ import path from "node:path";
7
+ import { readFile } from "node:fs/promises";
7
8
  import { loadConfig } from "tailwindcss-config";
8
- import { readFile, stat } from "node:fs/promises";
9
- import fg from "fast-glob";
10
9
  //#region src/postcss/config-directive.ts
11
10
  function quoteCssString(value) {
12
11
  return value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"");
@@ -61,85 +60,10 @@ function addSourceDependencyMessages(result, files) {
61
60
  }
62
61
  //#endregion
63
62
  //#region src/postcss/source-files.ts
64
- const POSTCSS_SOURCE_PATTERN = `**/*.{${[
65
- "html",
66
- "wxml",
67
- "axml",
68
- "jxml",
69
- "ksml",
70
- "ttml",
71
- "qml",
72
- "tyml",
73
- "xhsml",
74
- "swan",
75
- "vue",
76
- "mpx",
77
- "js",
78
- "jsx",
79
- "ts",
80
- "tsx"
81
- ].join(",")}}`;
82
- function parseLocalSourceParam(params) {
83
- const value = params.trim();
84
- if (!value || value === "none" || value.startsWith("not ") || value.startsWith("inline(")) return;
85
- return /^(['"])(.+)\1$/.exec(value)?.[2];
86
- }
87
- function parseConfigParam(params) {
88
- const value = params.trim();
89
- return /^(['"])(.+)\1$/.exec(value)?.[2];
90
- }
91
- function parseSourceFileParam(params) {
92
- const value = params.trim();
93
- if (!value || value === "none" || value.startsWith("inline(")) return;
94
- const negated = value.startsWith("not ");
95
- const sourceValue = negated ? value.slice(4).trim() : value;
96
- const match = /^(['"])(.+)\1$/.exec(sourceValue);
97
- return match?.[2] ? {
98
- negated,
99
- sourcePath: match[2]
100
- } : void 0;
101
- }
63
+ const POSTCSS_SOURCE_PATTERN = createSourceScanPattern(DEFAULT_SOURCE_SCAN_EXTENSIONS);
102
64
  function getSourceExtension(file) {
103
65
  return path.extname(file).slice(1) || void 0;
104
66
  }
105
- async function pathExistsAsDirectory(file) {
106
- try {
107
- return (await stat(file)).isDirectory();
108
- } catch {
109
- return false;
110
- }
111
- }
112
- async function expandLocalSourceFiles(sourcePath, base) {
113
- const absoluteSource = path.isAbsolute(sourcePath) ? sourcePath : path.resolve(base, sourcePath);
114
- if (await pathExistsAsDirectory(absoluteSource)) return fg(POSTCSS_SOURCE_PATTERN, {
115
- absolute: true,
116
- cwd: absoluteSource,
117
- onlyFiles: true
118
- });
119
- return fg(sourcePath, {
120
- absolute: true,
121
- cwd: base,
122
- onlyFiles: true
123
- });
124
- }
125
- async function resolveTailwindSourceEntry(sourcePath, base, negated) {
126
- const absoluteSource = path.isAbsolute(sourcePath) ? path.resolve(sourcePath) : path.resolve(base, sourcePath);
127
- if (await pathExistsAsDirectory(absoluteSource)) return {
128
- base: absoluteSource,
129
- negated,
130
- pattern: POSTCSS_SOURCE_PATTERN
131
- };
132
- if (path.isAbsolute(sourcePath)) return {
133
- base: path.dirname(absoluteSource),
134
- negated,
135
- pattern: path.basename(absoluteSource)
136
- };
137
- return {
138
- base,
139
- negated,
140
- pattern: sourcePath
141
- };
142
- }
143
67
  function collectConfigPaths(root, base) {
144
68
  const configPaths = [];
145
69
  root.walkAtRules("config", (rule) => {
@@ -148,65 +72,81 @@ function collectConfigPaths(root, base) {
148
72
  });
149
73
  return [...new Set(configPaths)];
150
74
  }
151
- function normalizeContentFiles(content) {
152
- if (typeof content === "string") return [content];
153
- if (Array.isArray(content)) return content.flatMap((item) => normalizeContentFiles(item));
154
- if (typeof content === "object" && content !== null && "files" in content) return normalizeContentFiles(content.files);
155
- return [];
75
+ function resolveOptionConfigPath(config, base) {
76
+ if (!config) return;
77
+ return path.isAbsolute(config) ? config : path.resolve(base, config);
156
78
  }
157
- async function collectConfigContentFiles(root, base) {
158
- const configPaths = collectConfigPaths(root, base);
79
+ async function collectConfigContentFiles(root, base, options) {
80
+ const configPaths = [...new Set([...resolveOptionConfigPath(options.config, base) ? [resolveOptionConfigPath(options.config, base)] : [], ...collectConfigPaths(root, base)])];
159
81
  const files = [];
160
82
  for (const configPath of configPaths) {
161
- const contentFiles = normalizeContentFiles((await loadConfig({
83
+ const contentEntries = normalizeLegacyContentEntries((await loadConfig({
162
84
  config: configPath,
163
85
  cwd: path.dirname(configPath)
164
- }))?.config.content);
165
- for (const contentFile of contentFiles) files.push(...await expandLocalSourceFiles(contentFile, path.dirname(configPath)));
86
+ }))?.config.content, path.dirname(configPath));
87
+ files.push(...await expandTailwindSourceEntries(contentEntries));
166
88
  }
167
89
  return {
168
90
  configPaths,
169
91
  files: [...new Set(files)]
170
92
  };
171
93
  }
94
+ async function collectConfiguredContentEntries(root, base, options) {
95
+ const configPath = resolveOptionConfigPath(options.generator?.config ?? options.config, base) ?? collectConfigPaths(root, base)[0];
96
+ if (!configPath) return [];
97
+ const resolvedConfigPath = path.isAbsolute(configPath) ? configPath : path.resolve(base, configPath);
98
+ return normalizeLegacyContentEntries((await loadConfig({
99
+ config: resolvedConfigPath,
100
+ cwd: path.dirname(resolvedConfigPath)
101
+ }))?.config.content, path.dirname(resolvedConfigPath));
102
+ }
103
+ async function collectRawCandidatesFromSourceEntries(sourceEntries) {
104
+ const candidates = /* @__PURE__ */ new Set();
105
+ const files = await expandTailwindSourceEntries(sourceEntries);
106
+ await Promise.all(files.map(async (file) => {
107
+ const matches = await extractRawCandidatesWithPositions(await readFile(file, "utf8"), getSourceExtension(file));
108
+ for (const match of matches) {
109
+ const candidate = match?.rawCandidate;
110
+ if (typeof candidate === "string" && candidate.length > 0) candidates.add(candidate);
111
+ }
112
+ }));
113
+ return candidates;
114
+ }
172
115
  async function collectAutoTailwindCandidates(root, result, options) {
173
116
  if (options.scanSources === false) return /* @__PURE__ */ new Set();
174
117
  const base = resolvePostcssBase(result, options);
175
118
  const projectRoot = resolvePostcssProjectRoot(result, options);
176
- const sourceEntryTasks = [];
177
- if (!root.toString().includes("source(none)")) sourceEntryTasks.push(Promise.resolve({
119
+ const sourceEntries = [];
120
+ const hasSourceNone = root.toString().includes("source(none)");
121
+ const inlineCandidates = collectCssInlineSourceCandidates(root);
122
+ const configuredContentEntries = options.version === 3 ? await collectConfiguredContentEntries(root, base, options) : [];
123
+ if (configuredContentEntries.length > 0) sourceEntries.push(...configuredContentEntries);
124
+ else if (!hasSourceNone) sourceEntries.push({
178
125
  base,
179
126
  negated: false,
180
127
  pattern: POSTCSS_SOURCE_PATTERN
181
- }));
182
- root.walkAtRules("source", (rule) => {
183
- const parsed = parseSourceFileParam(rule.params);
184
- if (!parsed) return;
185
- sourceEntryTasks.push(resolveTailwindSourceEntry(parsed.sourcePath, base, parsed.negated));
186
128
  });
187
- const sourceEntries = await Promise.all(sourceEntryTasks);
188
- if (sourceEntries.length === 0) return /* @__PURE__ */ new Set();
189
- const candidates = await extractValidCandidates({
129
+ sourceEntries.push(...await resolveCssSourceEntries(root, base, POSTCSS_SOURCE_PATTERN));
130
+ const candidates = sourceEntries.length === 0 ? [] : options.version === 3 ? await collectRawCandidatesFromSourceEntries(sourceEntries) : await extractValidCandidates({
190
131
  base,
191
132
  css: root.toString(),
192
133
  cwd: projectRoot,
193
134
  sources: sourceEntries
194
135
  });
195
- return new Set(candidates);
136
+ return new Set([...[...candidates].filter((candidate) => !inlineCandidates.excluded.has(candidate)), ...inlineCandidates.included]);
196
137
  }
197
138
  async function collectPostcssLocalSources(root, result, options) {
198
139
  const base = resolvePostcssBase(result, options);
199
- const sourcePaths = [];
200
- root.walkAtRules("source", (rule) => {
201
- const sourcePath = parseLocalSourceParam(rule.params);
202
- if (sourcePath) sourcePaths.push(sourcePath);
203
- });
204
- const configContentFiles = await collectConfigContentFiles(root, base);
205
- const files = [...new Set((await Promise.all(sourcePaths.map((sourcePath) => expandLocalSourceFiles(sourcePath, base)))).flat().concat(configContentFiles.files))];
206
- const sources = await Promise.all(files.map(async (file) => ({
207
- content: await readFile(file, "utf8"),
208
- extension: getSourceExtension(file)
209
- })));
140
+ const sourceEntries = await resolveCssSourceEntries(root, base, POSTCSS_SOURCE_PATTERN);
141
+ const configContentFiles = await collectConfigContentFiles(root, base, options);
142
+ const files = [...new Set([...await expandTailwindSourceEntries(sourceEntries), ...configContentFiles.files])];
143
+ const sources = await Promise.all(files.map(async (file) => {
144
+ const extension = getSourceExtension(file);
145
+ return {
146
+ content: await readFile(file, "utf8"),
147
+ ...extension === void 0 ? {} : { extension }
148
+ };
149
+ }));
210
150
  return {
211
151
  files: [...files, ...configContentFiles.configPaths],
212
152
  sources
@@ -0,0 +1,192 @@
1
+ //#region src/css-macro/constants.ts
2
+ const queryKey = "weapp-tw-platform";
3
+ const ifdefAtRule = "weapp-tw-ifdef";
4
+ const ifndefAtRule = "weapp-tw-ifndef";
5
+ function quoteAtRuleParam(value) {
6
+ return `"${value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"")}"`;
7
+ }
8
+ function createConditionalAtRule(value) {
9
+ return `@${ifdefAtRule} ${quoteAtRuleParam(value)}{&}`;
10
+ }
11
+ function createNegativeConditionalAtRule(value) {
12
+ return `@${ifndefAtRule} ${quoteAtRuleParam(value)}{&}`;
13
+ }
14
+ const UNESCAPED_UNDERSCORE_RE = /(?<!\\)_/g;
15
+ const WHITESPACE_RE = /\s+/g;
16
+ const LOGICAL_OPERATOR_RE = /\s*(\|\||&&)\s*/g;
17
+ function normalComment(text) {
18
+ if (typeof text === "string") {
19
+ const normalized = text.replaceAll(UNESCAPED_UNDERSCORE_RE, " ").replaceAll(WHITESPACE_RE, " ").trim();
20
+ if (normalized.includes("\\")) return normalized;
21
+ return normalized.replaceAll(LOGICAL_OPERATOR_RE, " $1 ").replaceAll(WHITESPACE_RE, " ").trim();
22
+ }
23
+ return text;
24
+ }
25
+ function ifdef(text) {
26
+ return {
27
+ start: `#ifdef ${normalComment(text)}`,
28
+ end: `#endif`
29
+ };
30
+ }
31
+ function ifndef(text) {
32
+ return {
33
+ start: `#ifndef ${normalComment(text)}`,
34
+ end: `#endif`
35
+ };
36
+ }
37
+ const QUERY_KEY_REGEX = new RegExp(`\\(\\s*${queryKey}\\s*:\\s*"([^)]*)"\\)`, "g");
38
+ function matchCustomPropertyFromValue(str, cb) {
39
+ let index = 0;
40
+ QUERY_KEY_REGEX.lastIndex = 0;
41
+ let arr = QUERY_KEY_REGEX.exec(str);
42
+ while (arr !== null) {
43
+ cb(arr, index);
44
+ index++;
45
+ arr = QUERY_KEY_REGEX.exec(str);
46
+ }
47
+ }
48
+ function parseConditionalAtRuleParam(params) {
49
+ const value = params.trim();
50
+ const quoted = /^(['"])((?:\\.|(?!\1).)*)\1/.exec(value);
51
+ if (!quoted) return value;
52
+ return quoted[2]?.replaceAll(/\\(["'\\])/g, "$1") ?? "";
53
+ }
54
+ //#endregion
55
+ //#region src/css-macro/postcss.ts
56
+ const IFDEF_ENDIF_RE = /#(?:ifn?def|endif)/;
57
+ const CONDITIONAL_COMMENT_SPACING = " ";
58
+ const CSS_MACRO_POSTCSS_PLUGIN_NAME = "postcss-weapp-tw-css-macro-plugin";
59
+ const creator = () => {
60
+ return {
61
+ postcssPlugin: CSS_MACRO_POSTCSS_PLUGIN_NAME,
62
+ prepare() {
63
+ function replaceAtRuleWithConditionalComments(atRule, helper, comment) {
64
+ const hasPreviousNode = Boolean(atRule.prev());
65
+ const clonedNodes = (atRule.nodes ?? []).map((node) => node.clone());
66
+ const startComment = helper.comment({
67
+ raws: {
68
+ left: CONDITIONAL_COMMENT_SPACING,
69
+ right: CONDITIONAL_COMMENT_SPACING
70
+ },
71
+ text: comment.start
72
+ });
73
+ const endComment = helper.comment({
74
+ raws: {
75
+ left: CONDITIONAL_COMMENT_SPACING,
76
+ right: CONDITIONAL_COMMENT_SPACING
77
+ },
78
+ text: comment.end
79
+ });
80
+ const nextNodes = [
81
+ startComment,
82
+ ...clonedNodes,
83
+ endComment
84
+ ];
85
+ atRule.replaceWith(nextNodes);
86
+ startComment.raws.before = hasPreviousNode ? "\n" : "";
87
+ startComment.raws["after"] = "\n";
88
+ if (clonedNodes[0]) clonedNodes[0].raws.before = "\n";
89
+ endComment.raws.before = "\n";
90
+ endComment.raws["after"] = "\n";
91
+ const nextNode = endComment?.next();
92
+ if (nextNode) nextNode.raws.before = "\n";
93
+ }
94
+ function replaceNestedAtRuleWithConditionalRule(atRule, helper, comment) {
95
+ if (atRule.parent?.type !== "rule") return false;
96
+ const parentRule = atRule.parent;
97
+ const clonedNodes = (atRule.nodes ?? []).map((node) => node.clone());
98
+ const conditionalRule = parentRule.clone();
99
+ conditionalRule.removeAll();
100
+ conditionalRule.append(...clonedNodes);
101
+ const startComment = helper.comment({
102
+ raws: {
103
+ left: CONDITIONAL_COMMENT_SPACING,
104
+ right: CONDITIONAL_COMMENT_SPACING
105
+ },
106
+ text: comment.start
107
+ });
108
+ const endComment = helper.comment({
109
+ raws: {
110
+ left: CONDITIONAL_COMMENT_SPACING,
111
+ right: CONDITIONAL_COMMENT_SPACING
112
+ },
113
+ text: comment.end
114
+ });
115
+ const nextNodes = [
116
+ startComment,
117
+ conditionalRule,
118
+ endComment
119
+ ];
120
+ const hasPreviousNode = Boolean(parentRule.prev());
121
+ atRule.remove();
122
+ if ((parentRule.nodes?.length ?? 0) === 0) parentRule.replaceWith(nextNodes);
123
+ else parentRule.after(nextNodes);
124
+ startComment.raws.before = hasPreviousNode ? "\n" : "";
125
+ startComment.raws["after"] = "\n";
126
+ conditionalRule.raws.before = "\n";
127
+ endComment.raws.before = "\n";
128
+ endComment.raws["after"] = "\n";
129
+ const nextNode = endComment.next();
130
+ if (nextNode) nextNode.raws.before = "\n";
131
+ return true;
132
+ }
133
+ return {
134
+ AtRule(atRule, helper) {
135
+ if (atRule.name === "weapp-tw-ifdef" || atRule.name === "weapp-tw-ifndef") {
136
+ const text = parseConditionalAtRuleParam(atRule.params);
137
+ const comment = atRule.name === "weapp-tw-ifndef" ? ifndef(text) : ifdef(text);
138
+ if (replaceNestedAtRuleWithConditionalRule(atRule, helper, comment)) return;
139
+ replaceAtRuleWithConditionalComments(atRule, helper, comment);
140
+ return;
141
+ }
142
+ if (atRule.name === "media") {
143
+ const values = [];
144
+ matchCustomPropertyFromValue(atRule.params, (arr) => {
145
+ const value = arr[1];
146
+ if (value) values.push(value);
147
+ });
148
+ if (values.length > 0) {
149
+ const isNegative = atRule.params.includes("not");
150
+ const text = values.join(" ");
151
+ const comment = isNegative ? ifndef(text) : ifdef(text);
152
+ if (replaceNestedAtRuleWithConditionalRule(atRule, helper, comment)) return;
153
+ replaceAtRuleWithConditionalComments(atRule, helper, comment);
154
+ }
155
+ }
156
+ },
157
+ CommentExit(comment) {
158
+ if (IFDEF_ENDIF_RE.test(comment.text)) {
159
+ comment.raws.left = CONDITIONAL_COMMENT_SPACING;
160
+ comment.raws.right = CONDITIONAL_COMMENT_SPACING;
161
+ }
162
+ }
163
+ };
164
+ }
165
+ };
166
+ };
167
+ creator.postcss = true;
168
+ //#endregion
169
+ Object.defineProperty(exports, "CSS_MACRO_POSTCSS_PLUGIN_NAME", {
170
+ enumerable: true,
171
+ get: function() {
172
+ return CSS_MACRO_POSTCSS_PLUGIN_NAME;
173
+ }
174
+ });
175
+ Object.defineProperty(exports, "createConditionalAtRule", {
176
+ enumerable: true,
177
+ get: function() {
178
+ return createConditionalAtRule;
179
+ }
180
+ });
181
+ Object.defineProperty(exports, "createNegativeConditionalAtRule", {
182
+ enumerable: true,
183
+ get: function() {
184
+ return createNegativeConditionalAtRule;
185
+ }
186
+ });
187
+ Object.defineProperty(exports, "creator", {
188
+ enumerable: true,
189
+ get: function() {
190
+ return creator;
191
+ }
192
+ });