weapp-tailwindcss 5.2.13 → 5.3.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 (62) hide show
  1. package/README.md +55 -8
  2. package/README.zh-CN.md +64 -0
  3. package/dist/bundlers/rspack/rule-match.d.ts +13 -0
  4. package/dist/bundlers/shared/source-candidates/scan-root.d.ts +1 -1
  5. package/dist/bundlers/shared/source-candidates/types-and-cache.d.ts +2 -0
  6. package/dist/bundlers/vite/generate-bundle/root-style-output.d.ts +7 -0
  7. package/dist/bundlers/vite/shared/create-framework-plugins.d.ts +1 -0
  8. package/dist/bundlers/vite/shared/framework-plugin-order.d.ts +2 -0
  9. package/dist/bundlers/vite/shared/framework-source-scan-session.d.ts +2 -2
  10. package/dist/{transform-BiHG42Rp.cjs → component-local-style-BirkN5f8.cjs} +33 -168
  11. package/dist/{transform-52FLRu-0.js → component-local-style-CFL4ClhS.js} +22 -174
  12. package/dist/generator/index.d.ts +2 -2
  13. package/dist/generator.cjs +7 -0
  14. package/dist/generator.js +2 -2
  15. package/dist/{gulp-DxKLSgXX.cjs → gulp-B0qcNiuP.cjs} +2 -2
  16. package/dist/{gulp-G--cGMcR.js → gulp-D1vDx4H1.js} +1 -1
  17. package/dist/gulp.cjs +1 -1
  18. package/dist/gulp.js +1 -1
  19. package/dist/{hmr-timing-iTua_Z55.js → hmr-timing-Dq1_msos.js} +19 -15
  20. package/dist/{hmr-timing-BtqnyxAO.cjs → hmr-timing-pF6k35pP.cjs} +1 -1
  21. package/dist/index.cjs +3 -3
  22. package/dist/index.js +3 -3
  23. package/dist/{pipeline-helpers-DnYpfbat.cjs → pipeline-helpers-DA5-EzbO.cjs} +1 -1
  24. package/dist/rspack.cjs +124 -7
  25. package/dist/rspack.js +124 -7
  26. package/dist/{source-candidate-scan-signature-Ggn8fzkT.cjs → source-candidate-scan-signature-DGQufJk3.cjs} +1 -1
  27. package/dist/{source-candidate-scan-signature-TKJIs7VF.js → source-candidate-scan-signature-DSsjYtlq.js} +1 -1
  28. package/dist/tailwindcss/candidates.d.ts +2 -2
  29. package/dist/transform-BYhgJszj.cjs +200 -0
  30. package/dist/transform-Ck31voUU.js +201 -0
  31. package/dist/uni-app-x/component-local-style.d.ts +3 -1
  32. package/dist/uni-app-x/transform.d.ts +2 -0
  33. package/dist/uni-app-x/vite/style-request.d.ts +1 -0
  34. package/dist/uni-app-x/vite/web-local-style.d.ts +6 -0
  35. package/dist/{v4-generation-core-D-zVR2mt.cjs → v4-generation-core-BEYGV4eB.cjs} +19 -15
  36. package/dist/{vite-B577QMUl.js → vite-DBgbFsei.js} +240 -82
  37. package/dist/{vite-BFWJAH16.cjs → vite-jftHIupF.cjs} +240 -82
  38. package/dist/vite.cjs +1 -1
  39. package/dist/vite.js +1 -1
  40. package/dist/weapp-tw-css-import-rewrite-loader.cjs +2 -2
  41. package/dist/{webpack-DLJkStre.js → webpack-BSIWFzAA.js} +3 -3
  42. package/dist/{webpack-DTqFKvcE.cjs → webpack-DhwW2cva.cjs} +4 -4
  43. package/dist/webpack.cjs +1 -1
  44. package/dist/webpack.js +1 -1
  45. package/package.json +9 -14
  46. package/README.en.md +0 -17
  47. package/bin/weapp-tailwindcss.cjs +0 -8
  48. package/dist/cli/context.d.ts +0 -3
  49. package/dist/cli/doctor/constants.d.ts +0 -7
  50. package/dist/cli/doctor/types.d.ts +0 -31
  51. package/dist/cli/doctor.d.ts +0 -4
  52. package/dist/cli/helpers/options/format.d.ts +0 -2
  53. package/dist/cli/helpers/options/parse.d.ts +0 -3
  54. package/dist/cli/helpers/options/resolve.d.ts +0 -1
  55. package/dist/cli/helpers/options.d.ts +0 -3
  56. package/dist/cli/helpers.d.ts +0 -4
  57. package/dist/cli/mount-options.d.ts +0 -4
  58. package/dist/cli/types.d.ts +0 -15
  59. package/dist/cli/vscode-entry.d.ts +0 -14
  60. package/dist/cli.cjs +0 -37065
  61. package/dist/cli.d.ts +0 -1
  62. package/dist/cli.js +0 -2298
package/dist/rspack.js CHANGED
@@ -1,5 +1,110 @@
1
- import { n as weappTailwindcssPackageDir, r as __dirname, t as WeappTailwindcss } from "./webpack-DLJkStre.js";
1
+ import { S as isSourceStyleRequest } from "./hmr-timing-Dq1_msos.js";
2
+ import { n as weappTailwindcssPackageDir, r as __dirname, t as WeappTailwindcss } from "./webpack-BSIWFzAA.js";
2
3
  import path from "node:path";
4
+ //#region src/bundlers/rspack/rule-match.ts
5
+ const STYLE_RULE_PROBES = [
6
+ "weapp-tailwindcss.css",
7
+ "weapp-tailwindcss.module.css",
8
+ "weapp-tailwindcss.wxss",
9
+ "weapp-tailwindcss.acss",
10
+ "weapp-tailwindcss.ttss",
11
+ "weapp-tailwindcss.qss",
12
+ "weapp-tailwindcss.jxss",
13
+ "weapp-tailwindcss.scss",
14
+ "weapp-tailwindcss.module.scss",
15
+ "weapp-tailwindcss.less",
16
+ "weapp-tailwindcss.styl",
17
+ "weapp-tailwindcss.pcss"
18
+ ];
19
+ const SCRIPT_RULE_PROBES = [
20
+ "weapp-tailwindcss.js",
21
+ "weapp-tailwindcss.jsx",
22
+ "weapp-tailwindcss.mjs",
23
+ "weapp-tailwindcss.cjs",
24
+ "weapp-tailwindcss.ts",
25
+ "weapp-tailwindcss.tsx"
26
+ ];
27
+ const STYLE_RESOURCE_QUERY_PROBES = [
28
+ "type=style",
29
+ "type=styles",
30
+ "vue&type=style&index=0&lang.css"
31
+ ];
32
+ function isRegExpLike(value) {
33
+ return value instanceof RegExp;
34
+ }
35
+ function testRegexpMatcher(matcher, input) {
36
+ const lastIndex = matcher.lastIndex;
37
+ matcher.lastIndex = 0;
38
+ const result = matcher.test(input);
39
+ matcher.lastIndex = lastIndex;
40
+ return result;
41
+ }
42
+ function matchesStringCondition(condition, input) {
43
+ if (typeof condition === "string") return input.includes(condition);
44
+ if (isRegExpLike(condition)) return testRegexpMatcher(condition, input);
45
+ }
46
+ function matchesCondition(condition, input) {
47
+ if (Array.isArray(condition)) {
48
+ let hasStaticMatcher = false;
49
+ for (const item of condition) {
50
+ const matched = matchesCondition(item, input);
51
+ if (matched === true) return true;
52
+ hasStaticMatcher || (hasStaticMatcher = matched === false);
53
+ }
54
+ return hasStaticMatcher ? false : void 0;
55
+ }
56
+ if (typeof condition === "object" && condition !== null && !isRegExpLike(condition)) {
57
+ const group = condition;
58
+ if (Array.isArray(group.and)) {
59
+ let hasUnknown = false;
60
+ for (const item of group.and) {
61
+ const matched = matchesCondition(item, input);
62
+ if (matched === false) return false;
63
+ hasUnknown || (hasUnknown = matched === void 0);
64
+ }
65
+ return hasUnknown ? void 0 : true;
66
+ }
67
+ if (Array.isArray(group.or)) return matchesCondition(group.or, input);
68
+ if (group.not !== void 0) {
69
+ const matched = matchesCondition(group.not, input);
70
+ return matched === void 0 ? void 0 : !matched;
71
+ }
72
+ return;
73
+ }
74
+ return matchesStringCondition(condition, input);
75
+ }
76
+ function matchesAnyStringCondition(condition, inputs) {
77
+ let hasStaticMatcher = false;
78
+ for (const input of inputs) {
79
+ const matched = matchesCondition(condition, input);
80
+ if (matched === true) return true;
81
+ hasStaticMatcher || (hasStaticMatcher = matched === false);
82
+ }
83
+ return hasStaticMatcher ? false : void 0;
84
+ }
85
+ function matchesStyleResourceCondition(condition) {
86
+ if (typeof condition === "function") return;
87
+ if (typeof condition === "string" && isSourceStyleRequest(condition)) return true;
88
+ const matched = matchesAnyStringCondition(condition, STYLE_RULE_PROBES);
89
+ return typeof condition === "string" && matched === false ? void 0 : matched;
90
+ }
91
+ function matchesResourceQueryCondition(condition) {
92
+ if (typeof condition === "function") return;
93
+ return matchesAnyStringCondition(condition, STYLE_RESOURCE_QUERY_PROBES);
94
+ }
95
+ function resolveRuleCssMatch(rule) {
96
+ if (matchesAnyStringCondition(rule.include, STYLE_RULE_PROBES) === true) return true;
97
+ if (matchesAnyStringCondition(rule.exclude, STYLE_RULE_PROBES) === true) return false;
98
+ if (matchesStyleResourceCondition(rule.resource) === true) return true;
99
+ if (matchesAnyStringCondition(rule.test, STYLE_RULE_PROBES) === true) return true;
100
+ if (matchesAnyStringCondition(rule.test, SCRIPT_RULE_PROBES) === true) return false;
101
+ if (matchesResourceQueryCondition(rule.resourceQuery) === true) return true;
102
+ if (typeof rule.type === "string") {
103
+ if (rule.type.includes("css") || rule.type.includes("style")) return true;
104
+ if (rule.type.includes("javascript")) return false;
105
+ }
106
+ }
107
+ //#endregion
3
108
  //#region src/bundlers/rspack/index.ts
4
109
  const CSS_IMPORT_REWRITE_LOADER_NAME = "weapp-tw-css-import-rewrite-loader";
5
110
  const LIGHTNING_CSS_LOADER_NAME = "builtin:lightningcss-loader";
@@ -8,10 +113,20 @@ const POSTCSS_LOADER_NAME = "postcss-loader";
8
113
  function isRuleLike(value) {
9
114
  return typeof value === "object" && value !== null;
10
115
  }
11
- function normalizeUse(use) {
12
- if (Array.isArray(use)) return use;
116
+ function isRspackUseItem(value) {
117
+ return typeof value === "string" || typeof value === "object" && value !== null;
118
+ }
119
+ function normalizeRuleUse(use) {
120
+ if (Array.isArray(use)) return {
121
+ entries: use,
122
+ commit: (entries) => entries
123
+ };
13
124
  if (use === void 0) return;
14
- return [use];
125
+ if (!isRspackUseItem(use)) return;
126
+ return {
127
+ entries: [use],
128
+ commit: (entries) => entries.length === 1 ? entries[0] : entries
129
+ };
15
130
  }
16
131
  function getLoaderName(item) {
17
132
  if (typeof item === "string") return item;
@@ -32,8 +147,10 @@ function resolveCssImportRewriteOptions(options) {
32
147
  return cssImportRewriteLoader === true ? {} : cssImportRewriteLoader;
33
148
  }
34
149
  function patchRuleUse(rule, options) {
35
- let use = normalizeUse(rule.use);
36
- if (!use) return;
150
+ if (resolveRuleCssMatch(rule) === false) return;
151
+ const normalizedUse = normalizeRuleUse(rule.use);
152
+ if (!normalizedUse) return;
153
+ let use = normalizedUse.entries;
37
154
  if (options.removeLightningCssLoader) use = use.filter((item) => !includesLoaderName(item, LIGHTNING_CSS_LOADER_NAME));
38
155
  const cssImportRewriteOptions = resolveCssImportRewriteOptions(options);
39
156
  if (cssImportRewriteOptions) {
@@ -46,7 +163,7 @@ function patchRuleUse(rule, options) {
46
163
  use.splice(fallbackAnchorIndex + 1, 0, loaderEntry);
47
164
  }
48
165
  }
49
- rule.use = use;
166
+ rule.use = normalizedUse.commit(use);
50
167
  }
51
168
  function walkRspackRule(rule, options) {
52
169
  if (!isRuleLike(rule)) return;
@@ -3,7 +3,7 @@ const require_framework = require("./framework.cjs");
3
3
  const require_generator = require("./generator-BXrWA7Sj.cjs");
4
4
  require("./auto-DtU6f3X6.cjs");
5
5
  const require_options = require("./options-DbYws6lr.cjs");
6
- const require_v4_generation_core = require("./v4-generation-core-D-zVR2mt.cjs");
6
+ const require_v4_generation_core = require("./v4-generation-core-BEYGV4eB.cjs");
7
7
  let node_path = require("node:path");
8
8
  node_path = require_rolldown_runtime.__toESM(node_path, 1);
9
9
  let node_module = require("node:module");
@@ -2,7 +2,7 @@ import { detectAppType } from "./framework.js";
2
2
  import { At as toPosixPath } from "./generator-BP4WmgIo.js";
3
3
  import { n as hasCssMacroTailwindV4CustomVariantConditionalComments } from "./auto-2dg_uhEJ.js";
4
4
  import { g as resolveTailwindV4EntriesFromCssCached, i as resolveUniAppXOptions } from "./tailwindcss-C2K-vjJv.js";
5
- import { S as isSourceStyleRequest } from "./hmr-timing-iTua_Z55.js";
5
+ import { S as isSourceStyleRequest } from "./hmr-timing-Dq1_msos.js";
6
6
  import { createRequire } from "node:module";
7
7
  import path from "node:path";
8
8
  import { weappStyleInjector } from "weapp-style-injector/vite";
@@ -7,5 +7,5 @@ export interface SourceCandidateExtractionOptions {
7
7
  extractor?: ((source: string, extension: string) => Promise<Iterable<string>> | Iterable<string>) | undefined;
8
8
  }
9
9
  export declare function extractCandidatesFromSource(source: string, extension: string, options?: SourceCandidateExtractionOptions): Promise<Set<string>>;
10
- export declare function extractTemplateAttributeCandidates(source: string, extension: string, options: SourceCandidateExtractionOptions): Promise<never[] | Set<string>>;
11
- export declare function extractScriptStringCandidates(source: string, extension: string, options: SourceCandidateExtractionOptions): Promise<never[] | Set<string>>;
10
+ export declare function extractTemplateAttributeCandidates(source: string, extension: string, options: SourceCandidateExtractionOptions): Promise<Set<string> | never[]>;
11
+ export declare function extractScriptStringCandidates(source: string, extension: string, options: SourceCandidateExtractionOptions): Promise<Set<string> | never[]>;
@@ -0,0 +1,200 @@
1
+ const require_wxml = require("./wxml-CQmBCjOR.cjs");
2
+ const require_component_local_style = require("./component-local-style-BirkN5f8.cjs");
3
+ let _vue_compiler_dom = require("@vue/compiler-dom");
4
+ //#region src/uni-app-x/transform.ts
5
+ function traverse(node, visitor) {
6
+ visitor(node);
7
+ if (Array.isArray(node.children)) {
8
+ for (const child of node.children) if (child && typeof child === "object" && "type" in child) traverse(child, visitor);
9
+ }
10
+ }
11
+ function updateStaticAttribute(ms, prop, offset, content = prop.value?.content) {
12
+ if (!prop.value) return;
13
+ const start = offset + prop.value.loc.start.offset + 1;
14
+ const end = offset + prop.value.loc.end.offset - 1;
15
+ if (start < end) ms.update(start, end, require_wxml.replaceWxml(content ?? ""));
16
+ }
17
+ function updateStaticAttributeWithLocalStyle(ms, prop, offset, collector, deep, content = prop.value?.content) {
18
+ if (!prop.value) return;
19
+ const start = offset + prop.value.loc.start.offset + 1;
20
+ const end = offset + prop.value.loc.end.offset - 1;
21
+ if (start < end) ms.update(start, end, collector.collectAndRewriteStaticClass(content ?? "", { deep }));
22
+ }
23
+ function updateDirectiveExpression(ms, prop, offset, jsHandler, runtimeSet) {
24
+ if (prop.exp?.type !== _vue_compiler_dom.NodeTypes.SIMPLE_EXPRESSION) return;
25
+ const expression = prop.exp.content;
26
+ const start = offset + prop.exp.loc.start.offset;
27
+ const end = offset + prop.exp.loc.end.offset;
28
+ if (start >= end) return;
29
+ const generated = require_wxml.generateCode(expression, {
30
+ jsHandler,
31
+ runtimeSet,
32
+ wrapExpression: true
33
+ });
34
+ ms.update(start, end, generated);
35
+ }
36
+ function updateDirectiveExpressionWithLocalStyle(ms, prop, offset, jsHandler, collector, deep, runtimeSet) {
37
+ if (prop.exp?.type !== _vue_compiler_dom.NodeTypes.SIMPLE_EXPRESSION) return;
38
+ const expression = prop.exp.content;
39
+ const start = offset + prop.exp.loc.start.offset;
40
+ const end = offset + prop.exp.loc.end.offset;
41
+ if (start >= end) return;
42
+ collector.collectRuntimeClasses(expression, {
43
+ deep,
44
+ wrapExpression: true
45
+ });
46
+ const generated = require_wxml.generateCode(expression, {
47
+ jsHandler,
48
+ runtimeSet,
49
+ wrapExpression: true
50
+ });
51
+ ms.update(start, end, collector.rewriteTransformedCode(generated, { wrapExpression: true }));
52
+ }
53
+ function shouldEnableLocalStyle(id, options) {
54
+ if (options.enableComponentLocalStyle && require_component_local_style.shouldEnableComponentLocalStyle(id)) return true;
55
+ if (options.enablePageLocalStyle && require_component_local_style.shouldEnablePageLocalStyle(id)) return true;
56
+ return false;
57
+ }
58
+ function shouldHandleAttribute(tag, attrName, disabledDefaultTemplateHandler, matchCustomAttribute) {
59
+ const lowerName = attrName.toLowerCase();
60
+ const shouldHandleDefault = !disabledDefaultTemplateHandler && lowerName === "class";
61
+ const shouldHandleCustom = matchCustomAttribute?.(tag, attrName) ?? false;
62
+ return {
63
+ shouldHandleDefault,
64
+ shouldHandleCustom,
65
+ shouldHandle: shouldHandleDefault || shouldHandleCustom
66
+ };
67
+ }
68
+ const defaultCreateJsHandlerOptions = { babelParserOptions: { plugins: ["typescript"] } };
69
+ const UVUE_NVUE_RE = /\.(?:uvue|nvue)(?:\?.*)?$/;
70
+ const SFC_BLOCK_RE = /<(template|script|style)\b([^>]*)>/gi;
71
+ const SCRIPT_SETUP_RE = /(?:^|\s)setup(?:\s|=|$)/;
72
+ const STYLE_SCOPED_RE = /(?:^|\s)scoped(?:\s|=|$)/i;
73
+ function findSfcBlockEnd(code, type, contentStart) {
74
+ const closeTag = new RegExp(`<\\/${type}\\s*>`, "gi");
75
+ if (type !== "template") {
76
+ const match = closeTag.exec(code.slice(contentStart));
77
+ return match ? {
78
+ blockEnd: contentStart + match.index + match[0].length,
79
+ contentEnd: contentStart + match.index
80
+ } : void 0;
81
+ }
82
+ const tag = new RegExp(`<\\/?${type}\\b[^>]*>`, "gi");
83
+ tag.lastIndex = contentStart;
84
+ let depth = 1;
85
+ let match = tag.exec(code);
86
+ while (match) {
87
+ if (match[0].startsWith("</")) depth -= 1;
88
+ else if (!match[0].trimEnd().endsWith("/>")) depth += 1;
89
+ if (depth === 0) return {
90
+ blockEnd: tag.lastIndex,
91
+ contentEnd: match.index
92
+ };
93
+ match = tag.exec(code);
94
+ }
95
+ }
96
+ function parseSfc(code) {
97
+ const descriptor = {
98
+ errors: [],
99
+ styles: []
100
+ };
101
+ for (const match of code.matchAll(SFC_BLOCK_RE)) {
102
+ const type = match[1];
103
+ const attrs = match[2] ?? "";
104
+ const contentStart = (match.index ?? 0) + match[0].length;
105
+ const blockBoundary = findSfcBlockEnd(code, type, contentStart);
106
+ if (!blockBoundary) {
107
+ descriptor.errors.push(/* @__PURE__ */ new Error(`未闭合的 ${type} SFC 块`));
108
+ continue;
109
+ }
110
+ const { contentEnd } = blockBoundary;
111
+ const content = code.slice(contentStart, contentEnd);
112
+ const block = {
113
+ content,
114
+ start: contentStart,
115
+ end: contentEnd,
116
+ attrs
117
+ };
118
+ if (type === "template" && !descriptor.template) {
119
+ try {
120
+ descriptor.template = {
121
+ ...block,
122
+ ast: (0, _vue_compiler_dom.parse)(content)
123
+ };
124
+ } catch (error) {
125
+ descriptor.errors.push(error);
126
+ descriptor.template = block;
127
+ }
128
+ continue;
129
+ }
130
+ if (type === "script") {
131
+ if (SCRIPT_SETUP_RE.test(attrs)) descriptor.scriptSetup ?? (descriptor.scriptSetup = block);
132
+ else descriptor.script ?? (descriptor.script = block);
133
+ continue;
134
+ }
135
+ if (type === "style") descriptor.styles.push(block);
136
+ }
137
+ return descriptor;
138
+ }
139
+ function transformUVue(code, id, jsHandler, runtimeSet, options = {}) {
140
+ if (!UVUE_NVUE_RE.test(id)) return;
141
+ const { customAttributesEntities, disabledDefaultTemplateHandler = false } = options;
142
+ const matchCustomAttribute = require_wxml.createAttributeMatcher(customAttributesEntities);
143
+ const ms = new require_wxml.MagicString(code);
144
+ const descriptor = parseSfc(code);
145
+ const localStyleCollector = shouldEnableLocalStyle(id, options) ? new require_component_local_style.UniAppXComponentLocalStyleCollector(id, runtimeSet) : void 0;
146
+ if (descriptor.errors.length === 0) {
147
+ if (descriptor.template?.ast) {
148
+ const templateOffset = descriptor.template.start;
149
+ traverse(descriptor.template.ast, (node) => {
150
+ if (node.type !== _vue_compiler_dom.NodeTypes.ELEMENT) return;
151
+ const tag = node.tag;
152
+ for (const prop of node.props) if (prop.type === _vue_compiler_dom.NodeTypes.ATTRIBUTE) {
153
+ const { shouldHandle, shouldHandleCustom, shouldHandleDefault } = shouldHandleAttribute(tag, prop.name, disabledDefaultTemplateHandler, matchCustomAttribute);
154
+ if (!shouldHandle) continue;
155
+ if (localStyleCollector) updateStaticAttributeWithLocalStyle(ms, prop, templateOffset, localStyleCollector, options.webCustomAttributeDeep === true && shouldHandleCustom);
156
+ else updateStaticAttribute(ms, prop, templateOffset);
157
+ if (shouldHandleDefault) continue;
158
+ } else if (prop.type === _vue_compiler_dom.NodeTypes.DIRECTIVE && prop.name === "bind" && prop.arg?.type === _vue_compiler_dom.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic) {
159
+ const attrName = prop.arg.content;
160
+ const { shouldHandle, shouldHandleCustom } = shouldHandleAttribute(tag, attrName, disabledDefaultTemplateHandler, matchCustomAttribute);
161
+ if (!shouldHandle) continue;
162
+ if (localStyleCollector) updateDirectiveExpressionWithLocalStyle(ms, prop, templateOffset, jsHandler, localStyleCollector, options.webCustomAttributeDeep === true && shouldHandleCustom, runtimeSet);
163
+ else updateDirectiveExpression(ms, prop, templateOffset, jsHandler, runtimeSet);
164
+ }
165
+ });
166
+ }
167
+ if (descriptor.script) {
168
+ localStyleCollector?.collectRuntimeClasses(descriptor.script.content);
169
+ const { code } = jsHandler(descriptor.script.content, runtimeSet ?? /* @__PURE__ */ new Set(), defaultCreateJsHandlerOptions);
170
+ ms.update(descriptor.script.start, descriptor.script.end, localStyleCollector ? localStyleCollector.rewriteTransformedCode(code) : code);
171
+ }
172
+ if (descriptor.scriptSetup) {
173
+ localStyleCollector?.collectRuntimeClasses(descriptor.scriptSetup.content);
174
+ const { code } = jsHandler(descriptor.scriptSetup.content, runtimeSet ?? /* @__PURE__ */ new Set(), defaultCreateJsHandlerOptions);
175
+ ms.update(descriptor.scriptSetup.start, descriptor.scriptSetup.end, localStyleCollector ? localStyleCollector.rewriteTransformedCode(code) : code);
176
+ }
177
+ if (localStyleCollector?.hasStyles()) {
178
+ const scopedStyle = descriptor.styles.findLast((style) => STYLE_SCOPED_RE.test(style.attrs));
179
+ if (scopedStyle && options.onWebLocalStyleRules) options.onWebLocalStyleRules(localStyleCollector.toStyleRules());
180
+ else if (scopedStyle) {
181
+ const separator = scopedStyle.content.endsWith("\n") ? "" : "\n";
182
+ ms.appendLeft(scopedStyle.end, `${separator}${localStyleCollector.toStyleRules()}`);
183
+ } else ms.append(`\n${localStyleCollector.toStyleBlock()}`);
184
+ }
185
+ }
186
+ const result = {
187
+ code: ms.toString(),
188
+ map: null
189
+ };
190
+ Object.defineProperty(result, "map", {
191
+ configurable: true,
192
+ enumerable: true,
193
+ get() {
194
+ return ms.generateMap();
195
+ }
196
+ });
197
+ return result;
198
+ }
199
+ //#endregion
200
+ exports.transformUVue = transformUVue;
@@ -0,0 +1,201 @@
1
+ import { n as generateCode, p as replaceWxml, r as createAttributeMatcher } from "./wxml-B7OAVpXJ.js";
2
+ import { n as shouldEnableComponentLocalStyle, r as shouldEnablePageLocalStyle, t as UniAppXComponentLocalStyleCollector } from "./component-local-style-CFL4ClhS.js";
3
+ import MagicString from "magic-string";
4
+ import { NodeTypes, parse } from "@vue/compiler-dom";
5
+ //#region src/uni-app-x/transform.ts
6
+ function traverse(node, visitor) {
7
+ visitor(node);
8
+ if (Array.isArray(node.children)) {
9
+ for (const child of node.children) if (child && typeof child === "object" && "type" in child) traverse(child, visitor);
10
+ }
11
+ }
12
+ function updateStaticAttribute(ms, prop, offset, content = prop.value?.content) {
13
+ if (!prop.value) return;
14
+ const start = offset + prop.value.loc.start.offset + 1;
15
+ const end = offset + prop.value.loc.end.offset - 1;
16
+ if (start < end) ms.update(start, end, replaceWxml(content ?? ""));
17
+ }
18
+ function updateStaticAttributeWithLocalStyle(ms, prop, offset, collector, deep, content = prop.value?.content) {
19
+ if (!prop.value) return;
20
+ const start = offset + prop.value.loc.start.offset + 1;
21
+ const end = offset + prop.value.loc.end.offset - 1;
22
+ if (start < end) ms.update(start, end, collector.collectAndRewriteStaticClass(content ?? "", { deep }));
23
+ }
24
+ function updateDirectiveExpression(ms, prop, offset, jsHandler, runtimeSet) {
25
+ if (prop.exp?.type !== NodeTypes.SIMPLE_EXPRESSION) return;
26
+ const expression = prop.exp.content;
27
+ const start = offset + prop.exp.loc.start.offset;
28
+ const end = offset + prop.exp.loc.end.offset;
29
+ if (start >= end) return;
30
+ const generated = generateCode(expression, {
31
+ jsHandler,
32
+ runtimeSet,
33
+ wrapExpression: true
34
+ });
35
+ ms.update(start, end, generated);
36
+ }
37
+ function updateDirectiveExpressionWithLocalStyle(ms, prop, offset, jsHandler, collector, deep, runtimeSet) {
38
+ if (prop.exp?.type !== NodeTypes.SIMPLE_EXPRESSION) return;
39
+ const expression = prop.exp.content;
40
+ const start = offset + prop.exp.loc.start.offset;
41
+ const end = offset + prop.exp.loc.end.offset;
42
+ if (start >= end) return;
43
+ collector.collectRuntimeClasses(expression, {
44
+ deep,
45
+ wrapExpression: true
46
+ });
47
+ const generated = generateCode(expression, {
48
+ jsHandler,
49
+ runtimeSet,
50
+ wrapExpression: true
51
+ });
52
+ ms.update(start, end, collector.rewriteTransformedCode(generated, { wrapExpression: true }));
53
+ }
54
+ function shouldEnableLocalStyle(id, options) {
55
+ if (options.enableComponentLocalStyle && shouldEnableComponentLocalStyle(id)) return true;
56
+ if (options.enablePageLocalStyle && shouldEnablePageLocalStyle(id)) return true;
57
+ return false;
58
+ }
59
+ function shouldHandleAttribute(tag, attrName, disabledDefaultTemplateHandler, matchCustomAttribute) {
60
+ const lowerName = attrName.toLowerCase();
61
+ const shouldHandleDefault = !disabledDefaultTemplateHandler && lowerName === "class";
62
+ const shouldHandleCustom = matchCustomAttribute?.(tag, attrName) ?? false;
63
+ return {
64
+ shouldHandleDefault,
65
+ shouldHandleCustom,
66
+ shouldHandle: shouldHandleDefault || shouldHandleCustom
67
+ };
68
+ }
69
+ const defaultCreateJsHandlerOptions = { babelParserOptions: { plugins: ["typescript"] } };
70
+ const UVUE_NVUE_RE = /\.(?:uvue|nvue)(?:\?.*)?$/;
71
+ const SFC_BLOCK_RE = /<(template|script|style)\b([^>]*)>/gi;
72
+ const SCRIPT_SETUP_RE = /(?:^|\s)setup(?:\s|=|$)/;
73
+ const STYLE_SCOPED_RE = /(?:^|\s)scoped(?:\s|=|$)/i;
74
+ function findSfcBlockEnd(code, type, contentStart) {
75
+ const closeTag = new RegExp(`<\\/${type}\\s*>`, "gi");
76
+ if (type !== "template") {
77
+ const match = closeTag.exec(code.slice(contentStart));
78
+ return match ? {
79
+ blockEnd: contentStart + match.index + match[0].length,
80
+ contentEnd: contentStart + match.index
81
+ } : void 0;
82
+ }
83
+ const tag = new RegExp(`<\\/?${type}\\b[^>]*>`, "gi");
84
+ tag.lastIndex = contentStart;
85
+ let depth = 1;
86
+ let match = tag.exec(code);
87
+ while (match) {
88
+ if (match[0].startsWith("</")) depth -= 1;
89
+ else if (!match[0].trimEnd().endsWith("/>")) depth += 1;
90
+ if (depth === 0) return {
91
+ blockEnd: tag.lastIndex,
92
+ contentEnd: match.index
93
+ };
94
+ match = tag.exec(code);
95
+ }
96
+ }
97
+ function parseSfc(code) {
98
+ const descriptor = {
99
+ errors: [],
100
+ styles: []
101
+ };
102
+ for (const match of code.matchAll(SFC_BLOCK_RE)) {
103
+ const type = match[1];
104
+ const attrs = match[2] ?? "";
105
+ const contentStart = (match.index ?? 0) + match[0].length;
106
+ const blockBoundary = findSfcBlockEnd(code, type, contentStart);
107
+ if (!blockBoundary) {
108
+ descriptor.errors.push(/* @__PURE__ */ new Error(`未闭合的 ${type} SFC 块`));
109
+ continue;
110
+ }
111
+ const { contentEnd } = blockBoundary;
112
+ const content = code.slice(contentStart, contentEnd);
113
+ const block = {
114
+ content,
115
+ start: contentStart,
116
+ end: contentEnd,
117
+ attrs
118
+ };
119
+ if (type === "template" && !descriptor.template) {
120
+ try {
121
+ descriptor.template = {
122
+ ...block,
123
+ ast: parse(content)
124
+ };
125
+ } catch (error) {
126
+ descriptor.errors.push(error);
127
+ descriptor.template = block;
128
+ }
129
+ continue;
130
+ }
131
+ if (type === "script") {
132
+ if (SCRIPT_SETUP_RE.test(attrs)) descriptor.scriptSetup ?? (descriptor.scriptSetup = block);
133
+ else descriptor.script ?? (descriptor.script = block);
134
+ continue;
135
+ }
136
+ if (type === "style") descriptor.styles.push(block);
137
+ }
138
+ return descriptor;
139
+ }
140
+ function transformUVue(code, id, jsHandler, runtimeSet, options = {}) {
141
+ if (!UVUE_NVUE_RE.test(id)) return;
142
+ const { customAttributesEntities, disabledDefaultTemplateHandler = false } = options;
143
+ const matchCustomAttribute = createAttributeMatcher(customAttributesEntities);
144
+ const ms = new MagicString(code);
145
+ const descriptor = parseSfc(code);
146
+ const localStyleCollector = shouldEnableLocalStyle(id, options) ? new UniAppXComponentLocalStyleCollector(id, runtimeSet) : void 0;
147
+ if (descriptor.errors.length === 0) {
148
+ if (descriptor.template?.ast) {
149
+ const templateOffset = descriptor.template.start;
150
+ traverse(descriptor.template.ast, (node) => {
151
+ if (node.type !== NodeTypes.ELEMENT) return;
152
+ const tag = node.tag;
153
+ for (const prop of node.props) if (prop.type === NodeTypes.ATTRIBUTE) {
154
+ const { shouldHandle, shouldHandleCustom, shouldHandleDefault } = shouldHandleAttribute(tag, prop.name, disabledDefaultTemplateHandler, matchCustomAttribute);
155
+ if (!shouldHandle) continue;
156
+ if (localStyleCollector) updateStaticAttributeWithLocalStyle(ms, prop, templateOffset, localStyleCollector, options.webCustomAttributeDeep === true && shouldHandleCustom);
157
+ else updateStaticAttribute(ms, prop, templateOffset);
158
+ if (shouldHandleDefault) continue;
159
+ } else if (prop.type === NodeTypes.DIRECTIVE && prop.name === "bind" && prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic) {
160
+ const attrName = prop.arg.content;
161
+ const { shouldHandle, shouldHandleCustom } = shouldHandleAttribute(tag, attrName, disabledDefaultTemplateHandler, matchCustomAttribute);
162
+ if (!shouldHandle) continue;
163
+ if (localStyleCollector) updateDirectiveExpressionWithLocalStyle(ms, prop, templateOffset, jsHandler, localStyleCollector, options.webCustomAttributeDeep === true && shouldHandleCustom, runtimeSet);
164
+ else updateDirectiveExpression(ms, prop, templateOffset, jsHandler, runtimeSet);
165
+ }
166
+ });
167
+ }
168
+ if (descriptor.script) {
169
+ localStyleCollector?.collectRuntimeClasses(descriptor.script.content);
170
+ const { code } = jsHandler(descriptor.script.content, runtimeSet ?? /* @__PURE__ */ new Set(), defaultCreateJsHandlerOptions);
171
+ ms.update(descriptor.script.start, descriptor.script.end, localStyleCollector ? localStyleCollector.rewriteTransformedCode(code) : code);
172
+ }
173
+ if (descriptor.scriptSetup) {
174
+ localStyleCollector?.collectRuntimeClasses(descriptor.scriptSetup.content);
175
+ const { code } = jsHandler(descriptor.scriptSetup.content, runtimeSet ?? /* @__PURE__ */ new Set(), defaultCreateJsHandlerOptions);
176
+ ms.update(descriptor.scriptSetup.start, descriptor.scriptSetup.end, localStyleCollector ? localStyleCollector.rewriteTransformedCode(code) : code);
177
+ }
178
+ if (localStyleCollector?.hasStyles()) {
179
+ const scopedStyle = descriptor.styles.findLast((style) => STYLE_SCOPED_RE.test(style.attrs));
180
+ if (scopedStyle && options.onWebLocalStyleRules) options.onWebLocalStyleRules(localStyleCollector.toStyleRules());
181
+ else if (scopedStyle) {
182
+ const separator = scopedStyle.content.endsWith("\n") ? "" : "\n";
183
+ ms.appendLeft(scopedStyle.end, `${separator}${localStyleCollector.toStyleRules()}`);
184
+ } else ms.append(`\n${localStyleCollector.toStyleBlock()}`);
185
+ }
186
+ }
187
+ const result = {
188
+ code: ms.toString(),
189
+ map: null
190
+ };
191
+ Object.defineProperty(result, "map", {
192
+ configurable: true,
193
+ enumerable: true,
194
+ get() {
195
+ return ms.generateMap();
196
+ }
197
+ });
198
+ return result;
199
+ }
200
+ //#endregion
201
+ export { transformUVue };
@@ -1,4 +1,5 @@
1
1
  interface RewriteCodeOptions {
2
+ deep?: boolean;
2
3
  wrapExpression?: boolean;
3
4
  }
4
5
  export declare function hasTopLevelVariant(candidate: string): boolean;
@@ -10,10 +11,11 @@ export declare class UniAppXComponentLocalStyleCollector {
10
11
  private aliasByUtility;
11
12
  private aliasByLookup;
12
13
  private classBindingNames;
14
+ private deepUtilities;
13
15
  constructor(fileId: string, runtimeSet?: Set<string> | undefined);
14
16
  private ensureAlias;
15
17
  private rewriteLiteral;
16
- collectAndRewriteStaticClass(literal: string): string;
18
+ collectAndRewriteStaticClass(literal: string, options?: RewriteCodeOptions): string;
17
19
  collectRuntimeClasses(rawSource: string, options?: RewriteCodeOptions): void;
18
20
  rewriteTransformedCode(rawSource: string, options?: RewriteCodeOptions): string;
19
21
  hasStyles(): boolean;
@@ -5,6 +5,8 @@ interface TransformUVueOptions {
5
5
  disabledDefaultTemplateHandler?: boolean;
6
6
  enableComponentLocalStyle?: boolean;
7
7
  enablePageLocalStyle?: boolean;
8
+ webCustomAttributeDeep?: boolean;
9
+ onWebLocalStyleRules?: (rules: string) => void;
8
10
  }
9
11
  export declare function transformUVue(code: string, id: string, jsHandler: JsHandler, runtimeSet?: Set<string>, options?: TransformUVueOptions): undefined | TransformResult;
10
12
  export {};
@@ -1,6 +1,7 @@
1
1
  export declare function isPreprocessorRequest(id: string, lang?: string): boolean;
2
2
  export declare function resolveUniAppXCssTarget(id: string): "uvue" | undefined;
3
3
  export declare function isCssModuleExport(code: string): boolean;
4
+ export declare function normalizeRelativeTailwindReferences(code: string, id: string): string;
4
5
  interface ResolvePreprocessorTransformOptions {
5
6
  isIosPlatform: boolean;
6
7
  isNativeAppStyleTarget: boolean;
@@ -0,0 +1,6 @@
1
+ import type { HmrContext, ModuleNode } from 'vite';
2
+ export declare function createUniAppXWebLocalStyleBridge(isEnabled: () => boolean): {
3
+ appendToStyle(code: string, id: string): string;
4
+ handleHotUpdate(ctx: HmrContext): ModuleNode[] | undefined;
5
+ remember(id: string, rules: string): void;
6
+ };