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.
- package/README.md +55 -8
- package/README.zh-CN.md +64 -0
- package/dist/bundlers/rspack/rule-match.d.ts +13 -0
- package/dist/bundlers/shared/source-candidates/scan-root.d.ts +1 -1
- package/dist/bundlers/shared/source-candidates/types-and-cache.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/root-style-output.d.ts +7 -0
- package/dist/bundlers/vite/shared/create-framework-plugins.d.ts +1 -0
- package/dist/bundlers/vite/shared/framework-plugin-order.d.ts +2 -0
- package/dist/bundlers/vite/shared/framework-source-scan-session.d.ts +2 -2
- package/dist/{transform-BiHG42Rp.cjs → component-local-style-BirkN5f8.cjs} +33 -168
- package/dist/{transform-52FLRu-0.js → component-local-style-CFL4ClhS.js} +22 -174
- package/dist/generator/index.d.ts +2 -2
- package/dist/generator.cjs +7 -0
- package/dist/generator.js +2 -2
- package/dist/{gulp-DxKLSgXX.cjs → gulp-B0qcNiuP.cjs} +2 -2
- package/dist/{gulp-G--cGMcR.js → gulp-D1vDx4H1.js} +1 -1
- package/dist/gulp.cjs +1 -1
- package/dist/gulp.js +1 -1
- package/dist/{hmr-timing-iTua_Z55.js → hmr-timing-Dq1_msos.js} +19 -15
- package/dist/{hmr-timing-BtqnyxAO.cjs → hmr-timing-pF6k35pP.cjs} +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.js +3 -3
- package/dist/{pipeline-helpers-DnYpfbat.cjs → pipeline-helpers-DA5-EzbO.cjs} +1 -1
- package/dist/rspack.cjs +124 -7
- package/dist/rspack.js +124 -7
- package/dist/{source-candidate-scan-signature-Ggn8fzkT.cjs → source-candidate-scan-signature-DGQufJk3.cjs} +1 -1
- package/dist/{source-candidate-scan-signature-TKJIs7VF.js → source-candidate-scan-signature-DSsjYtlq.js} +1 -1
- package/dist/tailwindcss/candidates.d.ts +2 -2
- package/dist/transform-BYhgJszj.cjs +200 -0
- package/dist/transform-Ck31voUU.js +201 -0
- package/dist/uni-app-x/component-local-style.d.ts +3 -1
- package/dist/uni-app-x/transform.d.ts +2 -0
- package/dist/uni-app-x/vite/style-request.d.ts +1 -0
- package/dist/uni-app-x/vite/web-local-style.d.ts +6 -0
- package/dist/{v4-generation-core-D-zVR2mt.cjs → v4-generation-core-BEYGV4eB.cjs} +19 -15
- package/dist/{vite-B577QMUl.js → vite-DBgbFsei.js} +240 -82
- package/dist/{vite-BFWJAH16.cjs → vite-jftHIupF.cjs} +240 -82
- package/dist/vite.cjs +1 -1
- package/dist/vite.js +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.cjs +2 -2
- package/dist/{webpack-DLJkStre.js → webpack-BSIWFzAA.js} +3 -3
- package/dist/{webpack-DTqFKvcE.cjs → webpack-DhwW2cva.cjs} +4 -4
- package/dist/webpack.cjs +1 -1
- package/dist/webpack.js +1 -1
- package/package.json +9 -14
- package/README.en.md +0 -17
- package/bin/weapp-tailwindcss.cjs +0 -8
- package/dist/cli/context.d.ts +0 -3
- package/dist/cli/doctor/constants.d.ts +0 -7
- package/dist/cli/doctor/types.d.ts +0 -31
- package/dist/cli/doctor.d.ts +0 -4
- package/dist/cli/helpers/options/format.d.ts +0 -2
- package/dist/cli/helpers/options/parse.d.ts +0 -3
- package/dist/cli/helpers/options/resolve.d.ts +0 -1
- package/dist/cli/helpers/options.d.ts +0 -3
- package/dist/cli/helpers.d.ts +0 -4
- package/dist/cli/mount-options.d.ts +0 -4
- package/dist/cli/types.d.ts +0 -15
- package/dist/cli/vscode-entry.d.ts +0 -14
- package/dist/cli.cjs +0 -37065
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +0 -2298
package/README.md
CHANGED
|
@@ -1,17 +1,64 @@
|
|
|
1
1
|
# weapp-tailwindcss
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> English | [简体中文](./README.zh-CN.md)
|
|
4
4
|
|
|
5
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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)
|
package/README.zh-CN.md
ADDED
|
@@ -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;
|
|
@@ -7,6 +7,6 @@ interface ResolveSourceCandidateScanFilesOptions {
|
|
|
7
7
|
root: string;
|
|
8
8
|
}
|
|
9
9
|
type SourceCandidateEligibilityRoot = Omit<ResolveSourceCandidateScanFilesOptions, 'filter'>;
|
|
10
|
-
export declare function createSourceCandidateEligibilityMatcher(roots: SourceCandidateEligibilityRoot[]): (file: string) => boolean;
|
|
10
|
+
export declare function createSourceCandidateEligibilityMatcher(roots: SourceCandidateEligibilityRoot[], eligibleFiles?: Iterable<string>): (file: string) => boolean;
|
|
11
11
|
export declare function resolveSourceCandidateScanFiles(options: ResolveSourceCandidateScanFilesOptions): Promise<string[]>;
|
|
12
12
|
export {};
|
|
@@ -10,6 +10,7 @@ export interface SourceCandidateStore {
|
|
|
10
10
|
syncFile: (id: string) => Promise<void>;
|
|
11
11
|
syncCurrentSource: (id: string, source: string) => Promise<SourceCandidateChange>;
|
|
12
12
|
syncCurrentFile: (id: string) => Promise<SourceCandidateChange>;
|
|
13
|
+
resolveScanFiles: (options: ScanSourceCandidateRootOptions) => Promise<string[]>;
|
|
13
14
|
scanRoot: (options: ScanSourceCandidateRootOptions) => Promise<void>;
|
|
14
15
|
syncInline: (inlineCandidates: TailwindInlineSourceCandidates | undefined) => void;
|
|
15
16
|
remove: (id: string) => SourceCandidateChange;
|
|
@@ -50,6 +51,7 @@ export interface ScanSourceCandidateRootOptions {
|
|
|
50
51
|
outDir?: string | undefined;
|
|
51
52
|
entries?: TailwindSourceEntry[] | undefined;
|
|
52
53
|
explicit?: boolean | undefined;
|
|
54
|
+
onFilesResolved?: ((files: string[]) => void) | undefined;
|
|
53
55
|
}
|
|
54
56
|
export interface SourceCandidateCollectorOptions {
|
|
55
57
|
bareArbitraryValues?: IArbitraryValues['bareArbitraryValues'] | 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>;
|
|
@@ -2,7 +2,7 @@ import type { HmrContext } from 'vite';
|
|
|
2
2
|
import type { createViteCssMemory } from '../css-memory.js';
|
|
3
3
|
import type { createViteRuntimeClassSet } from '../runtime-class-set.js';
|
|
4
4
|
import type { createSourceCandidateCollector } from '../source-candidates.js';
|
|
5
|
-
import type { createViteHmrCandidateState } from './framework-hmr-candidate-state.js';
|
|
5
|
+
import type { createViteHmrCandidateState, ViteSourceCandidateChange } from './framework-hmr-candidate-state.js';
|
|
6
6
|
type SourceCandidateCollector = ReturnType<typeof createSourceCandidateCollector>;
|
|
7
7
|
type CssMemory = ReturnType<typeof createViteCssMemory>;
|
|
8
8
|
type RuntimeState = ReturnType<typeof createViteRuntimeClassSet>['runtimeState'];
|
|
@@ -36,7 +36,7 @@ export declare function createFrameworkSourceScanSession(options: FrameworkSourc
|
|
|
36
36
|
sync: (syncOptions?: {
|
|
37
37
|
force?: boolean;
|
|
38
38
|
}) => Promise<void>;
|
|
39
|
-
syncChangedFile: (id: string, sourceOverride?: string) =>
|
|
39
|
+
syncChangedFile: (id: string, sourceOverride?: string) => Promise<ViteSourceCandidateChange | undefined>;
|
|
40
40
|
waitForPendingSyncs: () => Promise<void>;
|
|
41
41
|
};
|
|
42
42
|
export {};
|
|
@@ -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
|
-
|
|
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))
|
|
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
|
-
|
|
286
|
-
lines.push(
|
|
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
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
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
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
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
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
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
|
-
|
|
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
|
+
});
|