uxml-preview 0.5.1 → 0.6.1
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/CHANGELOG.md +181 -4
- package/README.ja.md +84 -0
- package/README.ko.md +84 -0
- package/README.md +46 -502
- package/README.zh-CN.md +84 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +1575 -1299
- package/dist/layout/yoga.d.ts +11 -0
- package/dist/model/types.d.ts +18 -4
- package/dist/render/css-map.d.ts +15 -0
- package/dist/render/fonts.d.ts +21 -0
- package/dist/render/measure.d.ts +9 -0
- package/dist/render/paint.d.ts +5 -0
- package/dist/render/values.d.ts +2 -0
- package/dist/render/visibility.d.ts +20 -0
- package/dist/style/registry.d.ts +5 -1
- package/dist/style/resolve.d.ts +9 -2
- package/package.json +4 -2
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# uxml-preview
|
|
2
|
+
|
|
3
|
+
*[English](https://github.com/ReuHomi/uxml-preview/blob/main/README.md) · [한국어](https://github.com/ReuHomi/uxml-preview/blob/main/README.ko.md) · [日本語](https://github.com/ReuHomi/uxml-preview/blob/main/README.ja.md) · 简体中文*
|
|
4
|
+
|
|
5
|
+
**无需 Unity 编辑器,即可在浏览器中渲染 Unity UI Toolkit 的 UXML/USS——由 UI Toolkit 自身使用的
|
|
6
|
+
Yoga 引擎负责布局,并与 Unity 实测结果进行了比对验证。**
|
|
7
|
+
|
|
8
|
+
[](https://reuhomi.github.io/uxml-preview/)
|
|
9
|
+
|
|
10
|
+
### ▶ [打开在线体验 (Playground)](https://reuhomi.github.io/uxml-preview/)
|
|
11
|
+
|
|
12
|
+
粘贴你自己的 `.uxml` 和 `.uss`,或直接打开示例。所有内容都不会上传,完全在页面本地
|
|
13
|
+
运行。
|
|
14
|
+
|
|
15
|
+
[](https://github.com/ReuHomi/uxml-preview/actions/workflows/ci.yml)
|
|
16
|
+
[](https://github.com/ReuHomi/uxml-preview/actions/workflows/pages.yml)
|
|
17
|
+
[](https://github.com/ReuHomi/uxml-preview/blob/main/LICENSE)
|
|
18
|
+
|
|
19
|
+
## 验证方式
|
|
20
|
+
|
|
21
|
+
- **坐标:** 在包含完整界面在内的 40 个布局用例中,660 / 676 个元素坐标值与 Unity 6000.0.40f1 完全一致。[查看全部差异明细 →](https://github.com/ReuHomi/uxml-preview/blob/main/docs/accuracy.en.md) 在 Unity 6.3(6000.3.25f1)中重新导出这批用例后,所有布局结果均与当天导出的 6000.0.40f1 结果一致。[6.3 重新测量结果 →](https://github.com/ReuHomi/uxml-preview/blob/main/docs/accuracy.en.md#unity-63-lts-re-measurement-2026-10-15)
|
|
22
|
+
- **文本:** 在真实浏览器中绘制,并与 Unity 6000.3.25f1 逐个 Label 进行比对——行数 92 / 92、高度 84 / 92、宽度 92 / 92(误差在 1px 或 1% 以内)。所有高度存在差异的用例,均是使用了不含韩文字符的拉丁字体 Inter 来排版韩文或混排文本;此时 Unity 会改用回退字体绘制,而本预览工具会针对该情况发出明确警告。[文本测试集 →](https://github.com/ReuHomi/uxml-preview/blob/main/docs/accuracy.en.md#text-cohort-separate-set-measured-2026-10-16)
|
|
23
|
+
- **Unity 版本:** 基准版本为 Unity 6.3 LTS。某项属性是否属于 USS,依据 Unity 官方属性表(截至 6.6)判定;6.7 在推出 LTS 版本之前暂不支持。[支持范围 →](https://github.com/ReuHomi/uxml-preview/blob/main/docs/supported.en.md)
|
|
24
|
+
- **不一致之处会明确报告,绝不静默忽略。** 遇到不支持的控件、属性或值时,工具会返回警告并说明原因;对于已实测的情况,还会一并告知 Unity 的实际处理方式。[警告说明 →](https://github.com/ReuHomi/uxml-preview/blob/main/docs/api.en.md#warnings)
|
|
25
|
+
|
|
26
|
+
## 三种使用方式
|
|
27
|
+
|
|
28
|
+
| 使用场景 | 推荐方案 |
|
|
29
|
+
|---|---|
|
|
30
|
+
| **设计界面** | 使用浏览器中的[在线体验](https://reuhomi.github.io/uxml-preview/),或在项目文件旁使用 [UXML Preview for VS Code](https://github.com/ReuHomi/vscode-uxml-preview) |
|
|
31
|
+
| **让 AI 智能体编写 UI** | [uxml-author](https://github.com/ReuHomi/uxml-author) —— 编写 UXML/USS、调用本库渲染并先验证结果再交付的技能(Skill) |
|
|
32
|
+
| **构建工具** | 直接使用本库:`npm install uxml-preview`,详见 [API 文档](https://github.com/ReuHomi/uxml-preview/blob/main/docs/api.en.md) |
|
|
33
|
+
|
|
34
|
+
## 安装
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm install uxml-preview
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
工具链需要 Node 22 或更高版本;渲染需要 DOM 环境(浏览器,或在测试中使用 happy-dom /
|
|
41
|
+
jsdom)。
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { loadLayoutEngine, parse, render, serialize } from 'uxml-preview';
|
|
45
|
+
|
|
46
|
+
await loadLayoutEngine(); // Yoga 基于 WebAssembly:预先加载一次即可
|
|
47
|
+
|
|
48
|
+
const doc = parse(uxmlText, ussText); // 文本 → 模型
|
|
49
|
+
const view = render(doc, container, { // 模型 → 画面
|
|
50
|
+
size: { width: 1280, height: 720 }, // 面板尺寸,而非窗口尺寸
|
|
51
|
+
resolveAsset: (path, form) => myAssetUrl(path, form), // project://… → URL,不存在则返回 null
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
for (const w of view.warnings) console.log(w.reason ?? w.kind, w.message);
|
|
55
|
+
|
|
56
|
+
view.dispose(); // Yoga 节点不会被垃圾回收,需手动释放
|
|
57
|
+
const { uxml, uss } = serialize(doc); // 若未修改,输出与输入字节级完全一致
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## 文档
|
|
61
|
+
|
|
62
|
+
- [USS 不是 CSS](https://github.com/ReuHomi/uxml-preview/blob/main/docs/uss-vs-css.md)(英文) — 导致迁移过来的样式表显示异常的各项差异,均附有示例
|
|
63
|
+
- [支持范围](https://github.com/ReuHomi/uxml-preview/blob/main/docs/supported.en.md)(英文) — 控件、属性、状态、版本,以及各项的验证程度
|
|
64
|
+
- [精度说明](https://github.com/ReuHomi/uxml-preview/blob/main/docs/accuracy.en.md)(英文) — 所有数据、测量方法及全部已知差异
|
|
65
|
+
- [API](https://github.com/ReuHomi/uxml-preview/blob/main/docs/api.en.md)(英文) — `parse`、`render`、`serialize`、钩子(Hooks)、警告、`classifyVisibility`
|
|
66
|
+
- [更新日志](https://github.com/ReuHomi/uxml-preview/blob/main/CHANGELOG.md)(英文)
|
|
67
|
+
- [视觉比对](https://github.com/ReuHomi/uxml-preview/blob/main/docs/visual-check.md)(韩文) — 将色彩与质感同 Unity 并排对比的单次记录(2026-08)
|
|
68
|
+
|
|
69
|
+
## 开发
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pnpm install
|
|
73
|
+
pnpm dev # 在本地启动在线体验页面(Playground)
|
|
74
|
+
pnpm test # 无需浏览器或 Unity 即可运行的全部测试
|
|
75
|
+
pnpm test:text # 文本测试集,在真实 Chromium 中运行(见 docs/accuracy.en.md)
|
|
76
|
+
pnpm build
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
复现 Unity 侧的基准数据需要安装 Unity,具体步骤见
|
|
80
|
+
[精度说明](https://github.com/ReuHomi/uxml-preview/blob/main/docs/accuracy.en.md#producing-the-ground-truth)。
|
|
81
|
+
|
|
82
|
+
## 许可证
|
|
83
|
+
|
|
84
|
+
Apache-2.0
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { NodeId, UxmlDocument, Warning } from './model/types';
|
|
2
|
+
import { ComputedStyle, ResolveResult } from './style/resolve';
|
|
2
3
|
import { LayoutBox, MeasureText } from './layout/yoga';
|
|
4
|
+
import { ResolveFont } from './render/fonts';
|
|
3
5
|
/**
|
|
4
6
|
* uxml-preview — public API surface.
|
|
5
7
|
*
|
|
@@ -12,6 +14,8 @@ export { collectDependencies, expandTemplates, TEMPLATE_DEPTH_LIMIT } from './te
|
|
|
12
14
|
export type { TemplateExpansion, TemplateResolver } from './template/expand';
|
|
13
15
|
export { loadLayoutEngine, isLayoutEngineReady, liveNodeCount } from './layout/yoga';
|
|
14
16
|
export type { LayoutBox, MeasureText, TextContext, TextMetrics } from './layout/yoga';
|
|
17
|
+
export type { FaceInfo } from './render/measure';
|
|
18
|
+
export { textHeight, EDITOR_DEFAULT_FACE_INFO } from './render/measure';
|
|
15
19
|
export { createDefaultMeasureText } from './render/measure';
|
|
16
20
|
export { NODE_ATTRIBUTE, PART_ATTRIBUTE, PART_OWNER_ATTRIBUTE } from './render/paint';
|
|
17
21
|
export { supportedControlNames } from './controls/registry';
|
|
@@ -72,6 +76,8 @@ export declare function serialize(doc: UxmlDocument): {
|
|
|
72
76
|
uss: string;
|
|
73
77
|
};
|
|
74
78
|
export interface RenderOptions {
|
|
79
|
+
/** Resolves font assets once per distinct path and form in each render. */
|
|
80
|
+
resolveFont?: ResolveFont;
|
|
75
81
|
/**
|
|
76
82
|
* Resolves Unity asset references to something a browser can load.
|
|
77
83
|
*
|
|
@@ -118,7 +124,15 @@ export interface RenderOptions {
|
|
|
118
124
|
*/
|
|
119
125
|
states?: Readonly<Record<string, readonly string[]>>;
|
|
120
126
|
}
|
|
127
|
+
export { classifyVisibility } from './render/visibility';
|
|
128
|
+
export type { Visibility } from './render/visibility';
|
|
121
129
|
export interface RenderResult {
|
|
130
|
+
/** Expanded document used for rendering, separate from the source AST. */
|
|
131
|
+
document?: UxmlDocument;
|
|
132
|
+
/** Computed styles keyed by rendered element id. */
|
|
133
|
+
styles?: ReadonlyMap<NodeId, ComputedStyle>;
|
|
134
|
+
/** Computed control part styles keyed by owner id and part name. */
|
|
135
|
+
partStyles?: ResolveResult['partStyles'];
|
|
122
136
|
/**
|
|
123
137
|
* Everything the renderer could not honour: unsupported controls, properties,
|
|
124
138
|
* selectors and units, plus unresolved assets. Distinct from
|