weapp-tailwindcss 5.2.14 → 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 (59) 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/vite/generate-bundle/root-style-output.d.ts +7 -0
  5. package/dist/bundlers/vite/shared/create-framework-plugins.d.ts +1 -0
  6. package/dist/bundlers/vite/shared/framework-plugin-order.d.ts +2 -0
  7. package/dist/{transform-BiHG42Rp.cjs → component-local-style-BirkN5f8.cjs} +33 -168
  8. package/dist/{transform-52FLRu-0.js → component-local-style-CFL4ClhS.js} +22 -174
  9. package/dist/generator/index.d.ts +2 -2
  10. package/dist/generator.cjs +7 -0
  11. package/dist/generator.js +2 -2
  12. package/dist/{gulp-DzIR7eO3.cjs → gulp-B0qcNiuP.cjs} +2 -2
  13. package/dist/{gulp-DG6cWPF4.js → gulp-D1vDx4H1.js} +1 -1
  14. package/dist/gulp.cjs +1 -1
  15. package/dist/gulp.js +1 -1
  16. package/dist/{hmr-timing-CoyM6Dg2.js → hmr-timing-Dq1_msos.js} +5 -7
  17. package/dist/{hmr-timing-BIPr9t9m.cjs → hmr-timing-pF6k35pP.cjs} +1 -1
  18. package/dist/index.cjs +3 -3
  19. package/dist/index.js +3 -3
  20. package/dist/{pipeline-helpers-Bp343-ik.cjs → pipeline-helpers-DA5-EzbO.cjs} +1 -1
  21. package/dist/rspack.cjs +124 -7
  22. package/dist/rspack.js +124 -7
  23. package/dist/{source-candidate-scan-signature-J9EW91KX.cjs → source-candidate-scan-signature-DGQufJk3.cjs} +1 -1
  24. package/dist/{source-candidate-scan-signature-BLXoEZN5.js → source-candidate-scan-signature-DSsjYtlq.js} +1 -1
  25. package/dist/tailwindcss/candidates.d.ts +2 -2
  26. package/dist/transform-BYhgJszj.cjs +200 -0
  27. package/dist/transform-Ck31voUU.js +201 -0
  28. package/dist/uni-app-x/component-local-style.d.ts +3 -1
  29. package/dist/uni-app-x/transform.d.ts +2 -0
  30. package/dist/uni-app-x/vite/style-request.d.ts +1 -0
  31. package/dist/uni-app-x/vite/web-local-style.d.ts +6 -0
  32. package/dist/{v4-generation-core-CCnEsAgV.cjs → v4-generation-core-BEYGV4eB.cjs} +5 -7
  33. package/dist/{vite-DNTQV3gN.js → vite-DBgbFsei.js} +184 -64
  34. package/dist/{vite-RJpkDte7.cjs → vite-jftHIupF.cjs} +184 -64
  35. package/dist/vite.cjs +1 -1
  36. package/dist/vite.js +1 -1
  37. package/dist/weapp-tw-css-import-rewrite-loader.cjs +2 -2
  38. package/dist/{webpack-DYoIysDo.js → webpack-BSIWFzAA.js} +3 -3
  39. package/dist/{webpack-BY5y7f0X.cjs → webpack-DhwW2cva.cjs} +4 -4
  40. package/dist/webpack.cjs +1 -1
  41. package/dist/webpack.js +1 -1
  42. package/package.json +9 -14
  43. package/README.en.md +0 -17
  44. package/bin/weapp-tailwindcss.cjs +0 -8
  45. package/dist/cli/context.d.ts +0 -3
  46. package/dist/cli/doctor/constants.d.ts +0 -7
  47. package/dist/cli/doctor/types.d.ts +0 -31
  48. package/dist/cli/doctor.d.ts +0 -4
  49. package/dist/cli/helpers/options/format.d.ts +0 -2
  50. package/dist/cli/helpers/options/parse.d.ts +0 -3
  51. package/dist/cli/helpers/options/resolve.d.ts +0 -1
  52. package/dist/cli/helpers/options.d.ts +0 -3
  53. package/dist/cli/helpers.d.ts +0 -4
  54. package/dist/cli/mount-options.d.ts +0 -4
  55. package/dist/cli/types.d.ts +0 -15
  56. package/dist/cli/vscode-entry.d.ts +0 -14
  57. package/dist/cli.cjs +0 -37065
  58. package/dist/cli.d.ts +0 -1
  59. package/dist/cli.js +0 -2298
package/README.md CHANGED
@@ -1,17 +1,64 @@
1
1
  # weapp-tailwindcss
2
2
 
3
- > 简体中文 | [English](./README.en.md)
3
+ > English | [简体中文](./README.zh-CN.md)
4
4
 
5
- 这个包是把 Tailwind CSS 带到小程序生态的核心入口,负责类名转译、CSS 兼容、框架构建适配和 Tailwind v4 支持。
5
+ Bring Tailwind CSS to every platform. `weapp-tailwindcss` is the core compiler and build integration layer for delivering utility-first styles to Web, mini programs, and native cross-platform runtimes.
6
6
 
7
- ## 官网
7
+ ## What it provides
8
8
 
9
- 更多接入方式、配置说明和框架示例见 [weapp-tailwindcss 官方文档](https://tw.icebreaker.top)。
9
+ - Tailwind CSS v4 generation through a shared compiler boundary.
10
+ - Vite, Webpack, Rspack, Gulp, PostCSS, and Node.js integration points.
11
+ - Precise class transformation based on the generated Tailwind candidate set.
12
+ - CSS compatibility transforms for WeChat, Alipay, ByteDance, QQ, and other mini-program style environments.
13
+ - Shared generation foundations for React Native, Expo, ReactLynx, and Rspeedy integrations.
10
14
 
11
- Tailwind CSS 4 项目中,入口 CSS 需要同时满足两点:在项目里被实际引入,并通过 `cssEntries` 显式传给插件用于稳定识别。`cssEntries` 应使用项目根目录解析出的绝对路径;它不是替代 import 的开关。
15
+ ## Choose an integration
12
16
 
13
- ## 运行环境
17
+ | Target | Recommended entry |
18
+ | --- | --- |
19
+ | Web / H5 | `weapp-tailwindcss/vite`, Webpack/Rspack integration, or `@weapp-tailwindcss/cli` |
20
+ | uni-app / uni-app x | Vite or Webpack integration selected by the framework build chain |
21
+ | Taro / Mpx / native mini programs | Vite, Webpack, Rspack, or Gulp integration |
22
+ | React Native / Expo | `@weapp-tailwindcss/react-native` |
23
+ | ReactLynx / Rspeedy | `@weapp-tailwindcss/lynx` |
14
24
 
15
- `weapp-tailwindcss@5.2.0` 开始,需要 Node.js `>=22.12.0`。该版本默认支持从 CommonJS 加载 ESM。
25
+ Start with the [installation guide](https://tw.icebreaker.top/docs/quick-start/install) or select a framework from the [documentation website](https://tw.icebreaker.top/).
16
26
 
17
- 通过 HBuilderX 使用 `uni-app` 或 `uni-app x` 时,还需要 HBuilderX `>=5.11`。旧版 HBuilderX 的内置 Node 可能无法加载当前依赖中的 ESM 模块。
27
+ ## Tailwind CSS 4 entry
28
+
29
+ Your CSS entry must be imported by the application build graph. Configure `cssEntries` with absolute paths resolved from the project root when stable entry discovery is required, but do not treat it as a replacement for importing the CSS file.
30
+
31
+ ```css
32
+ @import "tailwindcss";
33
+ @source "./src";
34
+ ```
35
+
36
+ Tailwind generation remains owned by `weapp-tailwindcss`. Do not add `@tailwindcss/vite` or `@tailwindcss/postcss` as a second generator in the same build.
37
+
38
+ ## CLI
39
+
40
+ Install the independently published CLI together with this package and Tailwind CSS:
41
+
42
+ ```bash
43
+ pnpm add -D @weapp-tailwindcss/cli weapp-tailwindcss tailwindcss
44
+ pnpm exec weapp-tw -i src/input.css -o dist/output.css --watch
45
+ ```
46
+
47
+ The CLI generates Web CSS by default. `--target weapp` performs CSS-only mini-program compatibility conversion; complete WXML, JavaScript, and WXSS projects still require a bundler integration. Watch mode uses `@parcel/watcher` native events by default and supports explicit polling with `--poll`.
48
+
49
+ See the [CLI guide](https://tw.icebreaker.top/docs/tools/weapp-tw-cli) for source maps, stdin/stdout, watch mode, and `canonicalize`.
50
+
51
+ ## Runtime requirements
52
+
53
+ - Node.js `^22.18.0 || >=24.11.0` for the current release line.
54
+ - HBuilderX `>=5.11` when using uni-app or uni-app x through HBuilderX.
55
+
56
+ ## Community and support
57
+
58
+ - [Documentation](https://tw.icebreaker.top/)
59
+ - [GitHub Issues](https://github.com/sonofmagic/weapp-tailwindcss/issues)
60
+ - [GitHub Discussions](https://github.com/sonofmagic/weapp-tailwindcss/discussions)
61
+
62
+ ## License
63
+
64
+ [MIT](../../LICENSE)
@@ -0,0 +1,64 @@
1
+ # weapp-tailwindcss
2
+
3
+ > [English](./README.md) | 简体中文
4
+
5
+ 把 Tailwind CSS 的原子化开发体验带到全端。`weapp-tailwindcss` 是面向 Web、小程序与原生跨端运行时的核心编译器和构建集成层。
6
+
7
+ ## 核心能力
8
+
9
+ - 通过统一编译边界生成 Tailwind CSS v4 样式。
10
+ - 提供 Vite、Webpack、Rspack、Gulp、PostCSS 与 Node.js 接入入口。
11
+ - 基于 Tailwind 已生成候选集合精确转换 class,避免误伤业务字符串。
12
+ - 处理微信、支付宝、抖音、QQ 等小程序样式环境的 CSS 兼容差异。
13
+ - 为 React Native、Expo、ReactLynx 与 Rspeedy 集成提供共享生成基础。
14
+
15
+ ## 选择接入方式
16
+
17
+ | 目标 | 推荐入口 |
18
+ | --- | --- |
19
+ | Web / H5 | `weapp-tailwindcss/vite`、Webpack/Rspack 集成或 `@weapp-tailwindcss/cli` |
20
+ | uni-app / uni-app x | 按框架构建链选择 Vite 或 Webpack 集成 |
21
+ | Taro / Mpx / 原生小程序 | Vite、Webpack、Rspack 或 Gulp 集成 |
22
+ | React Native / Expo | `@weapp-tailwindcss/react-native` |
23
+ | ReactLynx / Rspeedy | `@weapp-tailwindcss/lynx` |
24
+
25
+ 从[安装指南](https://tw.icebreaker.top/zh-cn/docs/quick-start/install)开始,或在[中文官网](https://tw.icebreaker.top/zh-cn/)按框架选择接入方式。
26
+
27
+ ## Tailwind CSS 4 入口
28
+
29
+ CSS 入口必须被应用构建图实际引入。需要稳定识别入口时,通过 `cssEntries` 配置从项目根目录解析出的绝对路径,但不要把它当成 CSS import 的替代品。
30
+
31
+ ```css
32
+ @import "tailwindcss";
33
+ @source "./src";
34
+ ```
35
+
36
+ Tailwind 样式生成统一由 `weapp-tailwindcss` 接管,同一构建中不要再叠加 `@tailwindcss/vite` 或 `@tailwindcss/postcss` 作为第二套生成器。
37
+
38
+ ## CLI
39
+
40
+ 独立 CLI 需要与本包和 Tailwind CSS 一起安装:
41
+
42
+ ```bash
43
+ pnpm add -D @weapp-tailwindcss/cli weapp-tailwindcss tailwindcss
44
+ pnpm exec weapp-tw -i src/input.css -o dist/output.css --watch
45
+ ```
46
+
47
+ CLI 默认生成 Web CSS。`--target weapp` 只进行小程序 CSS 兼容转换;完整 WXML、JavaScript 与 WXSS 项目仍需使用构建器集成。watch 默认使用 `@parcel/watcher` 原生事件,也可以通过 `--poll` 显式切换轮询。
48
+
49
+ source map、stdin/stdout、watch 与 `canonicalize` 的完整用法见 [CLI 指南](https://tw.icebreaker.top/zh-cn/docs/tools/weapp-tw-cli)。
50
+
51
+ ## 运行环境
52
+
53
+ - 当前版本需要 Node.js `^22.18.0 || >=24.11.0`。
54
+ - 通过 HBuilderX 使用 uni-app 或 uni-app x 时需要 HBuilderX `>=5.11`。
55
+
56
+ ## 社区与支持
57
+
58
+ - [官方文档](https://tw.icebreaker.top)
59
+ - [GitHub Issues](https://github.com/sonofmagic/weapp-tailwindcss/issues)
60
+ - [技术交流群](https://tw.icebreaker.top/zh-cn/docs/community/group)
61
+
62
+ ## License
63
+
64
+ [MIT](../../LICENSE)
@@ -0,0 +1,13 @@
1
+ export interface RspackRuleLike {
2
+ exclude?: unknown;
3
+ include?: unknown;
4
+ oneOf?: unknown[];
5
+ resource?: unknown;
6
+ resourceQuery?: unknown;
7
+ rules?: unknown[];
8
+ test?: unknown;
9
+ type?: unknown;
10
+ use?: unknown;
11
+ [key: string]: unknown;
12
+ }
13
+ export declare function resolveRuleCssMatch(rule: RspackRuleLike): boolean | undefined;
@@ -41,4 +41,11 @@ export declare function restoreFrameworkRootMiniProgramImportShellAssets(bundle:
41
41
  shouldKeep: (file: string, css: string) => boolean | undefined;
42
42
  targetByFile: ReadonlyMap<string, string>;
43
43
  }): number;
44
+ export declare function linkFrameworkRootStyleToRuntimeEntry(bundle: OutputBundle, options: {
45
+ debug?: ((format: string, ...args: unknown[]) => void) | undefined;
46
+ matchesCss: (file: string) => boolean;
47
+ onUpdate?: ((file: string, oldVal: string, newVal: string) => void) | undefined;
48
+ recordCssAssetResult?: ((file: string, css: string) => void) | undefined;
49
+ targetByFile: ReadonlyMap<string, string>;
50
+ }): 1 | 0;
44
51
  export declare function shouldMoveRootMiniProgramStyleToImportShellOrigin(enabled: boolean | undefined): enabled is true;
@@ -18,6 +18,7 @@ export interface ViteFrameworkBranchContext {
18
18
  getExtraPluginPlatform?: () => ViteFrameworkExtraPluginPlatform;
19
19
  styleInjectorDelegate: ViteStyleInjectorDelegateFactory;
20
20
  isRuntimeClassSetFeatureEnabled?: (context: ViteFrameworkRuntimeFeatureContext) => boolean;
21
+ sourceCandidatesBeforeExtraPlugin?: (plugin: Plugin) => boolean;
21
22
  }
22
23
  export interface ViteFrameworkExtraPluginContext {
23
24
  customAttributesEntities: ReturnType<typeof toCustomAttributesEntities>;
@@ -0,0 +1,2 @@
1
+ import type { Plugin } from 'vite';
2
+ export declare function orderFrameworkSourceCandidatePlugins(extraPlugins: Plugin[], rewritePlugins: Plugin[], sourceCandidatesPlugin: Plugin, beforeExtraPlugin?: (plugin: Plugin) => boolean): Plugin<any>[];
@@ -1,7 +1,6 @@
1
1
  const require_object = require("./object-DbHtAXRk.cjs");
2
2
  const require_wxml = require("./wxml-CQmBCjOR.cjs");
3
3
  let _tailwindcss_mangle_engine = require("@tailwindcss-mangle/engine");
4
- let _vue_compiler_dom = require("@vue/compiler-dom");
5
4
  //#region src/uni-app-x/component-local-style-binding.ts
6
5
  const OPTIONS_CLASS_SECTIONS = /* @__PURE__ */ new Set(["computed", "methods"]);
7
6
  function readStaticName(path) {
@@ -120,6 +119,10 @@ function extractLiteralValue(path) {
120
119
  function createAlias(fileId, utility, index) {
121
120
  return `wtu-${createStableHash(`${fileId}:${utility}`)}-${index.toString(36)}`;
122
121
  }
122
+ function serializeApplyUtility(utility) {
123
+ if (!utility.endsWith("!") || utility.endsWith("\\!")) return utility;
124
+ return `${utility.slice(0, -1)}#{'!'}`;
125
+ }
123
126
  function isRuntimeCandidate(candidate, runtimeSet) {
124
127
  if (!runtimeSet || runtimeSet.size === 0) return false;
125
128
  return runtimeSet.has(candidate) || runtimeSet.has(require_wxml.replaceWxml(candidate));
@@ -179,6 +182,7 @@ var UniAppXComponentLocalStyleCollector = class {
179
182
  require_object._defineProperty(this, "aliasByUtility", /* @__PURE__ */ new Map());
180
183
  require_object._defineProperty(this, "aliasByLookup", /* @__PURE__ */ new Map());
181
184
  require_object._defineProperty(this, "classBindingNames", /* @__PURE__ */ new Set());
185
+ require_object._defineProperty(this, "deepUtilities", /* @__PURE__ */ new Set());
182
186
  }
183
187
  ensureAlias(utility) {
184
188
  const cached = this.aliasByUtility.get(utility);
@@ -199,8 +203,12 @@ var UniAppXComponentLocalStyleCollector = class {
199
203
  }
200
204
  return rewritten;
201
205
  }
202
- collectAndRewriteStaticClass(literal) {
203
- return this.rewriteLiteral(literal);
206
+ collectAndRewriteStaticClass(literal, options = {}) {
207
+ const rewritten = this.rewriteLiteral(literal);
208
+ if (options.deep) {
209
+ for (const candidate of (0, _tailwindcss_mangle_engine.splitCandidateTokens)(literal)) if (this.aliasByUtility.has(candidate)) this.deepUtilities.add(candidate);
210
+ }
211
+ return rewritten;
204
212
  }
205
213
  collectRuntimeClasses(rawSource, options = {}) {
206
214
  const wrapped = options.wrapExpression ? `${EXPRESSION_WRAPPER_PREFIX}${rawSource}${EXPRESSION_WRAPPER_SUFFIX}` : rawSource;
@@ -218,7 +226,10 @@ var UniAppXComponentLocalStyleCollector = class {
218
226
  const classContext = options.wrapExpression || require_wxml.isClassContextLiteralPath(path) || isClassBindingLiteralPath(path, classBindingRoots);
219
227
  for (const candidate of candidates) {
220
228
  if (!candidate || !classContext || !isRuntimeCandidate(candidate, this.runtimeSet)) continue;
221
- if (!hasTopLevelVariant(candidate)) this.ensureAlias(candidate);
229
+ if (!hasTopLevelVariant(candidate)) {
230
+ this.ensureAlias(candidate);
231
+ if (options.deep) this.deepUtilities.add(candidate);
232
+ }
222
233
  }
223
234
  }
224
235
  } catch {}
@@ -282,176 +293,30 @@ var UniAppXComponentLocalStyleCollector = class {
282
293
  if (!this.hasStyles()) return "";
283
294
  const lines = [];
284
295
  for (const [utility, alias] of this.aliasByUtility) {
285
- lines.push(`.${alias} {`);
286
- lines.push(` @apply ${utility};`);
296
+ const selector = this.deepUtilities.has(utility) ? `.${alias}, :deep(.${alias})` : `.${alias}`;
297
+ lines.push(`${selector} {`);
298
+ lines.push(` @apply ${serializeApplyUtility(utility)};`);
287
299
  lines.push("}");
288
300
  }
289
301
  return `${lines.join("\n")}\n`;
290
302
  }
291
303
  };
292
304
  //#endregion
293
- //#region src/uni-app-x/transform.ts
294
- function traverse(node, visitor) {
295
- visitor(node);
296
- if (Array.isArray(node.children)) {
297
- for (const child of node.children) if (child && typeof child === "object" && "type" in child) traverse(child, visitor);
305
+ Object.defineProperty(exports, "UniAppXComponentLocalStyleCollector", {
306
+ enumerable: true,
307
+ get: function() {
308
+ return UniAppXComponentLocalStyleCollector;
298
309
  }
299
- }
300
- function updateStaticAttribute(ms, prop, offset, content = prop.value?.content) {
301
- if (!prop.value) return;
302
- const start = offset + prop.value.loc.start.offset + 1;
303
- const end = offset + prop.value.loc.end.offset - 1;
304
- if (start < end) ms.update(start, end, require_wxml.replaceWxml(content ?? ""));
305
- }
306
- function updateStaticAttributeWithLocalStyle(ms, prop, offset, collector, content = prop.value?.content) {
307
- if (!prop.value) return;
308
- const start = offset + prop.value.loc.start.offset + 1;
309
- const end = offset + prop.value.loc.end.offset - 1;
310
- if (start < end) ms.update(start, end, collector.collectAndRewriteStaticClass(content ?? ""));
311
- }
312
- function updateDirectiveExpression(ms, prop, offset, jsHandler, runtimeSet) {
313
- if (prop.exp?.type !== _vue_compiler_dom.NodeTypes.SIMPLE_EXPRESSION) return;
314
- const expression = prop.exp.content;
315
- const start = offset + prop.exp.loc.start.offset;
316
- const end = offset + prop.exp.loc.end.offset;
317
- if (start >= end) return;
318
- const generated = require_wxml.generateCode(expression, {
319
- jsHandler,
320
- runtimeSet,
321
- wrapExpression: true
322
- });
323
- ms.update(start, end, generated);
324
- }
325
- function updateDirectiveExpressionWithLocalStyle(ms, prop, offset, jsHandler, collector, runtimeSet) {
326
- if (prop.exp?.type !== _vue_compiler_dom.NodeTypes.SIMPLE_EXPRESSION) return;
327
- const expression = prop.exp.content;
328
- const start = offset + prop.exp.loc.start.offset;
329
- const end = offset + prop.exp.loc.end.offset;
330
- if (start >= end) return;
331
- collector.collectRuntimeClasses(expression, { wrapExpression: true });
332
- const generated = require_wxml.generateCode(expression, {
333
- jsHandler,
334
- runtimeSet,
335
- wrapExpression: true
336
- });
337
- ms.update(start, end, collector.rewriteTransformedCode(generated, { wrapExpression: true }));
338
- }
339
- function shouldEnableLocalStyle(id, options) {
340
- if (options.enableComponentLocalStyle && shouldEnableComponentLocalStyle(id)) return true;
341
- if (options.enablePageLocalStyle && shouldEnablePageLocalStyle(id)) return true;
342
- return false;
343
- }
344
- function shouldHandleAttribute(tag, attrName, disabledDefaultTemplateHandler, matchCustomAttribute) {
345
- const lowerName = attrName.toLowerCase();
346
- const shouldHandleDefault = !disabledDefaultTemplateHandler && lowerName === "class";
347
- const shouldHandleCustom = matchCustomAttribute?.(tag, attrName) ?? false;
348
- return {
349
- shouldHandleDefault,
350
- shouldHandleCustom,
351
- shouldHandle: shouldHandleDefault || shouldHandleCustom
352
- };
353
- }
354
- const defaultCreateJsHandlerOptions = { babelParserOptions: { plugins: ["typescript"] } };
355
- const UVUE_NVUE_RE = /\.(?:uvue|nvue)(?:\?.*)?$/;
356
- const SFC_BLOCK_RE = /<(template|script|style)\b([^>]*)>([\s\S]*?)<\/\1>/gi;
357
- const SCRIPT_SETUP_RE = /(?:^|\s)setup(?:\s|=|$)/;
358
- const STYLE_SCOPED_RE = /(?:^|\s)scoped(?:\s|=|$)/i;
359
- function parseSfc(code) {
360
- const descriptor = {
361
- errors: [],
362
- styles: []
363
- };
364
- for (const match of code.matchAll(SFC_BLOCK_RE)) {
365
- const type = match[1];
366
- const attrs = match[2] ?? "";
367
- const content = match[3] ?? "";
368
- const full = match[0];
369
- const contentStart = (match.index ?? 0) + full.indexOf(">") + 1;
370
- const block = {
371
- content,
372
- start: contentStart,
373
- end: contentStart + content.length,
374
- attrs
375
- };
376
- if (type === "template" && !descriptor.template) {
377
- try {
378
- descriptor.template = {
379
- ...block,
380
- ast: (0, _vue_compiler_dom.parse)(content)
381
- };
382
- } catch (error) {
383
- descriptor.errors.push(error);
384
- descriptor.template = block;
385
- }
386
- continue;
387
- }
388
- if (type === "script") {
389
- if (SCRIPT_SETUP_RE.test(attrs)) descriptor.scriptSetup ?? (descriptor.scriptSetup = block);
390
- else descriptor.script ?? (descriptor.script = block);
391
- continue;
392
- }
393
- if (type === "style") descriptor.styles.push(block);
310
+ });
311
+ Object.defineProperty(exports, "shouldEnableComponentLocalStyle", {
312
+ enumerable: true,
313
+ get: function() {
314
+ return shouldEnableComponentLocalStyle;
394
315
  }
395
- return descriptor;
396
- }
397
- function transformUVue(code, id, jsHandler, runtimeSet, options = {}) {
398
- if (!UVUE_NVUE_RE.test(id)) return;
399
- const { customAttributesEntities, disabledDefaultTemplateHandler = false } = options;
400
- const matchCustomAttribute = require_wxml.createAttributeMatcher(customAttributesEntities);
401
- const ms = new require_wxml.MagicString(code);
402
- const descriptor = parseSfc(code);
403
- const localStyleCollector = shouldEnableLocalStyle(id, options) ? new UniAppXComponentLocalStyleCollector(id, runtimeSet) : void 0;
404
- if (descriptor.errors.length === 0) {
405
- if (descriptor.template?.ast) {
406
- const templateOffset = descriptor.template.start;
407
- traverse(descriptor.template.ast, (node) => {
408
- if (node.type !== _vue_compiler_dom.NodeTypes.ELEMENT) return;
409
- const tag = node.tag;
410
- for (const prop of node.props) if (prop.type === _vue_compiler_dom.NodeTypes.ATTRIBUTE) {
411
- const { shouldHandle, shouldHandleDefault } = shouldHandleAttribute(tag, prop.name, disabledDefaultTemplateHandler, matchCustomAttribute);
412
- if (!shouldHandle) continue;
413
- if (shouldHandleDefault && localStyleCollector) updateStaticAttributeWithLocalStyle(ms, prop, templateOffset, localStyleCollector);
414
- else updateStaticAttribute(ms, prop, templateOffset);
415
- if (shouldHandleDefault) continue;
416
- } else if (prop.type === _vue_compiler_dom.NodeTypes.DIRECTIVE && prop.name === "bind" && prop.arg?.type === _vue_compiler_dom.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic) {
417
- const attrName = prop.arg.content;
418
- const { shouldHandle } = shouldHandleAttribute(tag, attrName, disabledDefaultTemplateHandler, matchCustomAttribute);
419
- if (!shouldHandle) continue;
420
- if (attrName.toLowerCase() === "class" && localStyleCollector) updateDirectiveExpressionWithLocalStyle(ms, prop, templateOffset, jsHandler, localStyleCollector, runtimeSet);
421
- else updateDirectiveExpression(ms, prop, templateOffset, jsHandler, runtimeSet);
422
- }
423
- });
424
- }
425
- if (descriptor.script) {
426
- localStyleCollector?.collectRuntimeClasses(descriptor.script.content);
427
- const { code } = jsHandler(descriptor.script.content, runtimeSet ?? /* @__PURE__ */ new Set(), defaultCreateJsHandlerOptions);
428
- ms.update(descriptor.script.start, descriptor.script.end, localStyleCollector ? localStyleCollector.rewriteTransformedCode(code) : code);
429
- }
430
- if (descriptor.scriptSetup) {
431
- localStyleCollector?.collectRuntimeClasses(descriptor.scriptSetup.content);
432
- const { code } = jsHandler(descriptor.scriptSetup.content, runtimeSet ?? /* @__PURE__ */ new Set(), defaultCreateJsHandlerOptions);
433
- ms.update(descriptor.scriptSetup.start, descriptor.scriptSetup.end, localStyleCollector ? localStyleCollector.rewriteTransformedCode(code) : code);
434
- }
435
- if (localStyleCollector?.hasStyles()) {
436
- const scopedStyle = descriptor.styles.findLast((style) => STYLE_SCOPED_RE.test(style.attrs));
437
- if (scopedStyle) {
438
- const separator = scopedStyle.content.endsWith("\n") ? "" : "\n";
439
- ms.appendLeft(scopedStyle.end, `${separator}${localStyleCollector.toStyleRules()}`);
440
- } else ms.append(`\n${localStyleCollector.toStyleBlock()}`);
441
- }
316
+ });
317
+ Object.defineProperty(exports, "shouldEnablePageLocalStyle", {
318
+ enumerable: true,
319
+ get: function() {
320
+ return shouldEnablePageLocalStyle;
442
321
  }
443
- const result = {
444
- code: ms.toString(),
445
- map: null
446
- };
447
- Object.defineProperty(result, "map", {
448
- configurable: true,
449
- enumerable: true,
450
- get() {
451
- return ms.generateMap();
452
- }
453
- });
454
- return result;
455
- }
456
- //#endregion
457
- exports.transformUVue = transformUVue;
322
+ });