@taptap/maker 0.0.40-beta.3 → 0.0.41-beta.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.
@@ -0,0 +1,95 @@
1
+ # 多分辨率 UI 生成与复核
2
+
3
+ 本说明由 Maker 内置 UI 组装、Bbox 工作流、Lua 转 JSON 三条入口共用。
4
+ 只使用目标项目 UrhoX 已有属性;引擎及其 Skill 不在修改范围。
5
+
6
+ ## 布局与单位
7
+
8
+ - 先区分全屏页面、弹层和独立组件。全屏根用 `width/height: "100%"`;独立组件保持自身尺寸,
9
+ 居中和贴边由使用它的父容器负责。不能把所有 Panel 都改成全屏。
10
+ - 沿用项目 `UI.Init` 的实际缩放策略。`UI.Scale.DEFAULT` 是 DPR 与小屏密度适配,
11
+ 不会自动把高清设计稿像素换成合理的逻辑尺寸。先确定逻辑参考宽高,再统一换算 Bbox、字号、间距。
12
+ 已有 Lua 约束已经是逻辑单位时不再缩放;接入代码只有用户要求接入/修复时才修改。
13
+ - 大厅左右、上下按钮按用途和已有父子分组锚定到安全内容区;按钮内的图标、文字跟随按钮。
14
+ 不把“离屏幕哪边近”当成确定的业务意图,不拆散一组控件。
15
+ - 背景放安全区外,四边 0,按需求选 `cover`(可裁切)或 `contain`(可留白)。
16
+ `SafeAreaView` 默认通过 padding 避让;绝对定位控件放在它的内部普通布局容器里,
17
+ 不假定直接给绝对定位节点套一层 padding 就能避让。Tap 胶囊需要时用 `nativeMenuInset: true`。
18
+ - 居中面板优先用父级 flex 居中;固定尺寸节点可用 50% 定位加负半尺寸 margin。`maxWidth` 不会缩放内部固定坐标,
19
+ 内部应一起改为百分比或 flex。图片可用 `aspectRatio` 从一边推导另一边,避免同时锁死宽高。
20
+ - 列表、背包格子、卡片等重复内容由生成该 UI 的 AI 按场景安排。通常让列表容器随可用空间伸缩,
21
+ 单项保持设计稿中的逻辑尺寸,不把单项 `flexGrow` 成填满剩余空间。内容超出时滚动或换行,
22
+ 不把全部内容压进一屏。排行榜行、文本列表等确需横向铺满的内容可以伸缩,不套用同一套尺寸。
23
+ 动态数量、排序和数据仍留在 Lua;预览中的样例项不代表真实数据。
24
+ - 窄屏文字要检查换行、字号、内容溢出;保留 Label,不把文字烘焙成图片。
25
+ 仅在用户需要换列数、隐藏区域等布局切换时补 Lua;不发明 JSON 媒体查询或断点协议。
26
+
27
+ ## 组装输入
28
+
29
+ `layout.json` 或含 `bbox` 的 `assembly.json` 可增加 `adaptation`:
30
+
31
+ ```json
32
+ {
33
+ "adaptation": {
34
+ "mode": "screen",
35
+ "logicalShortSide": 720,
36
+ "safeArea": true,
37
+ "nativeMenuInset": true,
38
+ "nodes": {
39
+ "E001": {
40
+ "left": null,
41
+ "top": null,
42
+ "right": 24,
43
+ "bottom": 24,
44
+ "width": 120,
45
+ "height": 48,
46
+ "aspectRatio": null,
47
+ "marginLeft": null,
48
+ "marginRight": null,
49
+ "marginTop": null,
50
+ "marginBottom": null
51
+ }
52
+ }
53
+ }
54
+ }
55
+ ```
56
+
57
+ - `mode` 为 `screen` 或 `component`。`component` 只做单位换算和显式节点约束,不套全屏或安全区。
58
+ - `logicalShortSide` 为设计稿短边对应的逻辑长度;省略则不换算。720 只是画布自动组装的初始基准,
59
+ 不是所有项目的强制尺寸。项目已有基准时以项目为准。
60
+ - `nodes` 按现有元素 ID 覆盖最终节点属性,数值已是逻辑单位;`null` 删除自动产生的属性。
61
+ 支持四边、宽高、最小/最大尺寸、padding/margin、字体尺寸、边框尺寸、flex、`aspectRatio`、
62
+ `backgroundFit` 和 `overflow`。不允许通过此处换 ID、图片绑定、类型或 children。
63
+ - 原 Bbox 与纠偏记录仍用设计稿像素,不能因适配覆写原坐标。改变父子分组用现有 layout 层级,
64
+ 已有交付用 `ui inspect / patch` 修改并检查 revision,不重建覆盖用户修改。
65
+ - 未传 `adaptation` 的历史脚本输入保持固定布局。新全屏 UI 应显式传入此配置。
66
+
67
+ 画布自动交付使用 screen、短边 720 和安全区:背景铺满;顶层内容按原稿位置初拟锚点,
68
+ 原有父子分组保持不变。为面板显式提供宽高、最大尺寸或比例覆盖时,内部位置/尺寸按原稿比例跟随父级。
69
+ 跟随只作用于该面板内部坐标。列表项、卡片等需要保持自身尺寸的节点,应在 `adaptation.nodes` 中
70
+ 显式保留宽高,不能依赖名称自动识别,也不能把所有子节点无差别转成百分比。
71
+ 字号不会随面板无限缩小;拥挤内容需调整 flex、换行或滚动,而非盲目整体缩小。
72
+
73
+ `assembly-map.json.adaptation` 记录逻辑参考尺寸、`inferred` 元素和待复核状态。
74
+ 自动锚点只是初稿,已有显式节点覆盖也不等于验收通过。最终 JSON 仅含引擎已有节点属性,
75
+ 不写入 `adaptation`;它是组装输入和记录,不是引擎新协议。
76
+
77
+ ## 编辑器验收
78
+
79
+ 编辑器连接后,优先用同包 CLI 的 `ui layout` 查询实际布局、`ui preview` 导出 PNG;
80
+ 通过 `--device iphone18|ipadpro`、`--orientation` 或 `--width/--height` 切换模拟视口。
81
+ 先查 `ui capabilities` 获取参数。CLI 只渲染保存版本,不动草稿;仍须查看 PNG,不能只凭坐标验收。
82
+ 浏览器用于首次连接、视觉对照和拖动/缩放等交互验证,不用反复点击设备下拉框读取坐标。
83
+
84
+ 1. 对照参考图检查分组、层级和内容。基准对位时在自定义设备中使用逻辑参考宽高、DPR=1、UI 缩放=1。
85
+ 2. 切换 720p、1080p、iPhone 18 Pro、iPad Pro,检查贴边、居中、背景比例、文字溢出;
86
+ 按项目支持范围切换横竖屏,必要时自定义 4:3 / 21:9。720p、1080p、2K、4K 预设的模拟 DPR
87
+ 分别为 1、1.5、2、3,逻辑画幅相同,用于检查不同像素密度,不代表更大逻辑视口;
88
+ 检查更大桌面时用自定义分辨率及实际 DPR,不能仅凭物理分辨率推断 DPR。
89
+ 3. 编辑器默认模拟 `UI.Scale.DEFAULT`;项目用其他策略时,在自定义设备中填入对应缩放值。
90
+ 页面按设备逻辑视口重新布局;固定像素根仍然保持固定大小,不能用整体缩放掩盖它的缺陷。
91
+ 4. 安全区预设是可编辑的模拟值,宿主窗口和 Tap 胶囊并不由手机型号唯一决定。
92
+ 在自定义分辨率中填写物理像素边距与胶囊底边位置,核对 `SafeAreaView` 是否实际避让。
93
+ 5. 拖动/缩放后检查 right/bottom、百分比和 aspectRatio 是否保留,保存重开后再换设备。
94
+ 设备切换本身不修改 JSON。
95
+ 6. 静态检查、编辑器预览、引擎运行分开报告;未运行真机不能宣称全面适配通过。
@@ -65,7 +65,8 @@ design 包含 path(assets/ 相对路径)、sha256、width、height;assets
65
65
  rect 表示整个 PNG 画布的放置范围,不能混用按钮主体边界与含阴影/透明边距的画布边界。
66
66
  先裁透明留白或统一状态画布,再记录资源尺寸和哈希;默认/按下态要检查主体锚点是否一致。
67
67
  切图若发生形变,坐标记录不会自动修复形变,应选择备用或在编辑器调整,不宣称完全无误差。
68
- 当前工具只组装固定坐标的静态 UI,不处理旋转/缩放节点、动态列表、百分比和响应式布局。
68
+ 默认输入保留固定坐标行为;完整页面通过可选 adaptation 输出响应式布局,
69
+ 格式和验收见[多分辨率适配](responsive.md)。不处理动态列表或原始旋转/缩放节点的自动还原。
69
70
 
70
71
  纠偏 JSON 的 version=1,layoutSha256 为解析后 layout 对象 JSON.stringify 的 SHA-256;
71
72
  review 包含 designSha256 与 evidence(实际对照截图路径),adjustments 每项为
@@ -25,6 +25,13 @@ export interface UiAssemblyBbox {
25
25
  texts: Array<{ id: string; [key: string]: unknown }>;
26
26
  }
27
27
  export interface UiAssemblyInput {
28
+ adaptation?: {
29
+ mode: 'screen' | 'component';
30
+ logicalShortSide?: number;
31
+ safeArea?: boolean;
32
+ nativeMenuInset?: boolean;
33
+ nodes?: Record<string, Record<string, string | number | null>>;
34
+ };
28
35
  screen?: { name: string; key: string };
29
36
  bbox: UiAssemblyBbox;
30
37
  assets: UiAssemblyAsset[];
@@ -2131,6 +2131,183 @@ import fs from "node:fs";
2131
2131
  import path from "node:path";
2132
2132
  var digest = (value) => createHash("sha256").update(value).digest("hex");
2133
2133
  var layoutDigest = (layout) => digest(JSON.stringify(layout));
2134
+ var responsiveLengths = [
2135
+ "left",
2136
+ "right",
2137
+ "top",
2138
+ "bottom",
2139
+ "width",
2140
+ "height",
2141
+ "minWidth",
2142
+ "maxWidth",
2143
+ "minHeight",
2144
+ "maxHeight",
2145
+ "margin",
2146
+ "marginLeft",
2147
+ "marginRight",
2148
+ "marginTop",
2149
+ "marginBottom",
2150
+ "padding",
2151
+ "paddingLeft",
2152
+ "paddingRight",
2153
+ "paddingTop",
2154
+ "paddingBottom",
2155
+ "paddingHorizontal",
2156
+ "paddingVertical",
2157
+ "gap",
2158
+ "flexBasis",
2159
+ "fontSize",
2160
+ "borderRadius",
2161
+ "borderWidth"
2162
+ ];
2163
+ var responsiveEnums = {
2164
+ position: ["absolute", "relative"],
2165
+ flexDirection: ["row", "column", "row-reverse", "column-reverse"],
2166
+ justifyContent: [
2167
+ "flex-start",
2168
+ "center",
2169
+ "flex-end",
2170
+ "space-between",
2171
+ "space-around",
2172
+ "space-evenly"
2173
+ ],
2174
+ alignItems: ["flex-start", "center", "flex-end", "stretch", "baseline"],
2175
+ alignSelf: ["auto", "flex-start", "center", "flex-end", "stretch", "baseline"],
2176
+ flexWrap: ["nowrap", "wrap", "wrap-reverse"],
2177
+ backgroundFit: ["fill", "contain", "cover", "sliced"],
2178
+ overflow: ["visible", "hidden", "scroll"]
2179
+ };
2180
+ function adaptLayout(ui, layout) {
2181
+ const config = layout.adaptation;
2182
+ if (config === void 0) return null;
2183
+ assert(config && ["screen", "component"].includes(config.mode), "Invalid adaptation mode");
2184
+ const shortSide = Math.min(layout.design.width, layout.design.height);
2185
+ const logicalShortSide = config.logicalShortSide ?? shortSide;
2186
+ assert(Number.isFinite(logicalShortSide) && logicalShortSide > 0, "Invalid logicalShortSide");
2187
+ for (const key of ["safeArea", "nativeMenuInset"])
2188
+ assert(
2189
+ config[key] === void 0 || typeof config[key] === "boolean",
2190
+ "Invalid adaptation " + key
2191
+ );
2192
+ const factor = logicalShortSide / shortSide;
2193
+ const reference = { width: layout.design.width * factor, height: layout.design.height * factor };
2194
+ const nodes = /* @__PURE__ */ new Map();
2195
+ const visit = (node) => {
2196
+ nodes.set(node.id, node);
2197
+ for (const key of responsiveLengths)
2198
+ if (typeof node[key] === "number") node[key] = Math.round(node[key] * factor * 1e3) / 1e3;
2199
+ node.children?.forEach(visit);
2200
+ };
2201
+ visit(ui);
2202
+ const overrides = config.nodes ?? {};
2203
+ assert(
2204
+ overrides && typeof overrides === "object" && !Array.isArray(overrides),
2205
+ "Invalid adaptation nodes"
2206
+ );
2207
+ for (const [id, props] of Object.entries(overrides)) {
2208
+ assert(
2209
+ nodes.has(id) && props && typeof props === "object" && !Array.isArray(props),
2210
+ "Unknown adaptation node: " + id
2211
+ );
2212
+ for (const [key, value] of Object.entries(props)) {
2213
+ const length = responsiveLengths.includes(key);
2214
+ const numeric = ["aspectRatio", "flexGrow", "flexShrink"].includes(key);
2215
+ const values = Object.hasOwn(responsiveEnums, key) ? responsiveEnums[key] : void 0;
2216
+ assert(length || numeric || values, "Unsupported adaptation property: " + key);
2217
+ if (value === null) continue;
2218
+ assert(
2219
+ length ? typeof value === "number" && Number.isFinite(value) || typeof value === "string" && /^(auto|-?\d+(?:\.\d+)?%)$/.test(value) : numeric ? Number.isFinite(value) && value >= (key === "aspectRatio" ? 1e-6 : 0) : values.includes(value),
2220
+ "Invalid adaptation property: " + id + "." + key
2221
+ );
2222
+ }
2223
+ }
2224
+ const inferred = [];
2225
+ const percent = (value, total) => Math.round(value / total * 1e6) / 1e4 + "%";
2226
+ function proportionalChildren(node, width, height) {
2227
+ for (const child of node.children || []) {
2228
+ const childWidth = child.width, childHeight = child.height;
2229
+ for (const key of ["left", "width"])
2230
+ if (typeof child[key] === "number") child[key] = percent(child[key], width);
2231
+ for (const key of ["top", "height"])
2232
+ if (typeof child[key] === "number") child[key] = percent(child[key], height);
2233
+ proportionalChildren(child, childWidth, childHeight);
2234
+ }
2235
+ }
2236
+ function anchor(node, start, end, size, extent) {
2237
+ const offset = node[start] || 0, length = node[size];
2238
+ const centerOffset = offset + length / 2 - extent / 2;
2239
+ if (Math.abs(centerOffset) <= extent * 0.1) {
2240
+ node[start] = "50%";
2241
+ node[start === "left" ? "marginLeft" : "marginTop"] = offset - extent / 2;
2242
+ } else if (centerOffset > 0) {
2243
+ node[end] = extent - offset - length;
2244
+ delete node[start];
2245
+ }
2246
+ }
2247
+ if (config.mode === "screen") {
2248
+ ui.width = "100%";
2249
+ ui.height = "100%";
2250
+ const content = [], backgrounds = [];
2251
+ for (const node of ui.children || []) {
2252
+ if (node.id === "background" && node.backgroundImage) {
2253
+ Object.assign(node, { left: 0, top: 0, right: 0, bottom: 0 });
2254
+ delete node.width;
2255
+ delete node.height;
2256
+ backgrounds.push(node);
2257
+ continue;
2258
+ }
2259
+ anchor(node, "left", "right", "width", reference.width);
2260
+ anchor(node, "top", "bottom", "height", reference.height);
2261
+ if (overrides[node.id] && ["width", "height", "aspectRatio", "maxWidth", "maxHeight"].some(
2262
+ (key) => Object.hasOwn(overrides[node.id], key)
2263
+ ))
2264
+ proportionalChildren(node, node.width, node.height);
2265
+ const explicit = overrides[node.id] || {};
2266
+ if (!["left", "right"].some((key) => Object.hasOwn(explicit, key)) || !["top", "bottom"].some((key) => Object.hasOwn(explicit, key)))
2267
+ inferred.push(node.id);
2268
+ content.push(node);
2269
+ }
2270
+ if (config.safeArea !== false) {
2271
+ const uniqueId = (base) => {
2272
+ let id = base, index = 1;
2273
+ while (nodes.has(id)) id = base + "_" + index++;
2274
+ nodes.set(id, null);
2275
+ return id;
2276
+ };
2277
+ ui.children = [
2278
+ ...backgrounds,
2279
+ {
2280
+ type: "SafeAreaView",
2281
+ id: uniqueId("safe_area"),
2282
+ position: "absolute",
2283
+ left: 0,
2284
+ top: 0,
2285
+ right: 0,
2286
+ bottom: 0,
2287
+ nativeMenuInset: config.nativeMenuInset === true,
2288
+ children: [
2289
+ {
2290
+ type: "Panel",
2291
+ id: uniqueId("safe_content"),
2292
+ flexGrow: 1,
2293
+ minWidth: 0,
2294
+ minHeight: 0,
2295
+ children: content
2296
+ }
2297
+ ]
2298
+ }
2299
+ ];
2300
+ }
2301
+ }
2302
+ for (const [id, props] of Object.entries(overrides)) {
2303
+ const node = nodes.get(id);
2304
+ for (const [key, value] of Object.entries(props)) {
2305
+ if (value === null) delete node[key];
2306
+ else node[key] = value;
2307
+ }
2308
+ }
2309
+ return { mode: config.mode, reference, inferred, review: "pending" };
2310
+ }
2134
2311
  var geometryFields = [
2135
2312
  "id",
2136
2313
  "type",
@@ -2341,6 +2518,7 @@ function assemble(layout, correction = null) {
2341
2518
  }
2342
2519
  const ui = build(root, null, null, 0);
2343
2520
  assert.equal(visited.size, elements.size, "Disconnected or cyclic elements");
2521
+ const adaptation = adaptLayout(ui, layout);
2344
2522
  return {
2345
2523
  ui,
2346
2524
  report: {
@@ -2353,7 +2531,8 @@ function assemble(layout, correction = null) {
2353
2531
  assetId,
2354
2532
  instances: instances.size
2355
2533
  })),
2356
- placements
2534
+ placements,
2535
+ ...adaptation ? { adaptation } : {}
2357
2536
  }
2358
2537
  };
2359
2538
  }
@@ -2504,6 +2683,7 @@ function layoutFromBbox(input) {
2504
2683
  coordinateSpace: "design-pixels",
2505
2684
  rectBasis: "asset-canvas",
2506
2685
  provenance: "recognition",
2686
+ ...input.adaptation ? { adaptation: input.adaptation } : {},
2507
2687
  ...input.screen || bbox.screen ? { screen: input.screen || bbox.screen } : {},
2508
2688
  design: { ...bbox.design },
2509
2689
  assets: input.assets,
@@ -120,7 +120,7 @@ request/correlation ID, reproduction steps, visible Maker tools, client version,
120
120
  Do not include the complete conversation. Send that JSON through stdin, never argv, while running:
121
121
 
122
122
  ```text
123
- npx -y --package @taptap/maker@0.0.40-beta.3 taptap-maker mcp report --ide <client> --target-dir <project> --context-stdin --consent --json
123
+ npx -y --package @taptap/maker@0.0.41-beta.1 taptap-maker mcp report --ide <client> --target-dir <project> --context-stdin --consent --json
124
124
  ```
125
125
 
126
126
  Prefer the active client's exact Maker MCP `command` plus ordered `args`, then append the `mcp
@@ -223,6 +223,13 @@ If the cause is unclear, inspect `cloud-status` and, as needed, `cloud-diff` usi
223
223
  `--target-dir`. If cloud changes need committing to recover the push, use `cloud-commit` once,
224
224
  then `git sync` and retry the original Maker submit/build operation. If cloud state is clean or
225
225
  the error identifies another cause, address that cause instead of repeatedly syncing or committing.
226
+ When a push is rejected by the cloud, always show the user the original remote error
227
+ (`failure.stderr`/`stdout`) instead of a paraphrase. Only the project owner can `cloud-commit`;
228
+ collaborators should ask the owner (or 塔拉拉 in the Maker web editor) to commit cloud changes.
229
+ If the error looks like a Git lock (`index.lock`, "another git process", "锁"), the usual cause is
230
+ 塔拉拉 (the Maker web agent) developing in the cloud at the same time as local work. Tell the user
231
+ this, suggest letting 塔拉拉 finish/stop and commit its cloud changes first, then retry later. Do not
232
+ delete lock files and do not loop `push`/`sync`/`cloud-commit`; the local commit is preserved.
226
233
  `cloud_workspace_blocked` means
227
234
  the automatic cloud commit did not finish (follow `next_action`); `merge_conflict` means resolve
228
235
  `conflict_files`, commit, and retry; `auth` means refreshing PAT;