@taptap/maker 0.0.37-beta.4 → 0.0.37-beta.5

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,289 @@
1
+ -- Maker NanoVG data adapter. No Lua source is stored in UI documents.
2
+ -- capture() is an explicit, synchronous development operation; hooks never survive it.
3
+ local M = {}
4
+ local unpack = table.unpack or unpack
5
+ local active = false
6
+ local signatures = {
7
+ save = "", restore = "", beginPath = "", closePath = "", fill = "", stroke = "",
8
+ moveTo = "nn", lineTo = "nn", bezierTo = "nnnnnn", quadTo = "nnnn", arcTo = "nnnnn",
9
+ rect = "nnnn", roundedRect = "nnnnn", roundedRectVarying = "nnnnnnnn",
10
+ circle = "nnn", ellipse = "nnnn", arc = "nnnnnn",
11
+ translate = "nn", scale = "nn", rotate = "n", skewX = "n", skewY = "n", transform = "nnnnnn",
12
+ scissor = "nnnn", intersectScissor = "nnnn",
13
+ fillColor = "c", strokeColor = "c", fillPaint = "p", strokePaint = "p",
14
+ strokeWidth = "n", miterLimit = "n", lineCap = "n", lineJoin = "n", globalAlpha = "n",
15
+ fontSize = "n", fontFace = "s", textAlign = "n", textLetterSpacing = "n", text = "nns", textBox = "nnns",
16
+ }
17
+ local paints = { linearGradient = "nnnncc", radialGradient = "nnnncc", imagePattern = "nnnnnsn" }
18
+
19
+ local function finite(n) return type(n) == "number" and n == n and math.abs(n) < math.huge end
20
+ local function color(value)
21
+ if type(value) == "string" then
22
+ assert((#value == 7 or #value == 9) and value:match("^#%x+$"), "Invalid NanoVG color")
23
+ return { tonumber(value:sub(2, 3), 16), tonumber(value:sub(4, 5), 16),
24
+ tonumber(value:sub(6, 7), 16), #value == 9 and tonumber(value:sub(8, 9), 16) or 255 }
25
+ end
26
+ assert(type(value) == "table" and #value == 4, "Expected RGBA color")
27
+ for i = 1, 4 do assert(finite(value[i]) and value[i] >= 0 and value[i] <= 255, "Invalid color channel") end
28
+ return value
29
+ end
30
+
31
+ local function validateArgs(args, sig)
32
+ assert(type(args) == "table" and #args == #sig, "Invalid NanoVG argument count")
33
+ for i = 1, #sig do
34
+ local kind, value = sig:sub(i, i), args[i]
35
+ if kind == "n" then assert(finite(value), "Expected finite NanoVG number")
36
+ elseif kind == "s" then assert(type(value) == "string", "Expected NanoVG string")
37
+ elseif kind == "c" then color(value)
38
+ else
39
+ assert(type(value) == "table" and paints[value.kind], "Unsupported NanoVG paint")
40
+ validateArgs(value.args, paints[value.kind])
41
+ end
42
+ end
43
+ end
44
+
45
+ local function validate(node)
46
+ assert(type(node) == "table" and node.type == "NanoVG", "Expected NanoVG node")
47
+ validateArgs(node.viewBox, "nnnn")
48
+ assert(node.viewBox[3] > 0 and node.viewBox[4] > 0, "Invalid NanoVG viewBox")
49
+ assert(type(node.commands) == "table" and #node.commands <= 20000, "Too many NanoVG commands")
50
+ local depth = 0
51
+ for _, cmd in ipairs(node.commands) do
52
+ assert(type(cmd) == "table" and signatures[cmd[1]], "Unsupported NanoVG command: " .. tostring(cmd[1]))
53
+ local args = {}; for i = 2, #cmd do args[#args + 1] = cmd[i] end
54
+ validateArgs(args, signatures[cmd[1]])
55
+ if cmd[1] == "textBox" then assert(args[3] > 0, "Text box width must be positive") end
56
+ if cmd[1] == "save" then depth = depth + 1 end
57
+ if cmd[1] == "restore" then depth = depth - 1 end
58
+ assert(depth >= 0 and depth <= 32, "Unbalanced NanoVG state stack (layer limit: 32)")
59
+ end
60
+ assert(depth == 0, "Unbalanced NanoVG state stack")
61
+ end
62
+ M.validate = validate
63
+
64
+ -- opts.images maps existing native image handles to assets-relative resource paths.
65
+ -- opts.fonts maps existing font IDs to names. Unknown APIs/opaque paints fail capture.
66
+ function M.capture(ctx, opts, draw)
67
+ assert(not active, "Nested NanoVG capture is not supported; capture separate named layers")
68
+ assert(type(opts) == "table" and type(draw) == "function", "capture requires options and a draw function")
69
+ local node = { type = "NanoVG", id = opts.id, position = "absolute", left = opts.left or 0,
70
+ top = opts.top or 0, width = opts.width, height = opts.height,
71
+ viewBox = opts.viewBox or { 0, 0, opts.width, opts.height }, commands = {} }
72
+ local originals, colors, paintValues = {}, {}, {}
73
+ local images, fonts = opts.images or {}, opts.fonts or {}
74
+ local depth, failure = 0, nil
75
+ local function remember(op, args)
76
+ assert(#node.commands < 20000, "NanoVG command limit exceeded")
77
+ local cmd = { op }; for _, value in ipairs(args) do cmd[#cmd + 1] = value end
78
+ node.commands[#node.commands + 1] = cmd
79
+ end
80
+ local function capturedColor(value)
81
+ assert(colors[value], "Color was created outside capture; create it inside the draw callback")
82
+ return colors[value]
83
+ end
84
+ local function wrap(name, fn)
85
+ if originals[name] then
86
+ _G[name] = function(...)
87
+ local result = { pcall(fn, ...) }
88
+ if not result[1] then failure = tostring(result[2]); error(failure) end
89
+ return unpack(result, 2)
90
+ end
91
+ end
92
+ end
93
+ for name, fn in pairs(_G) do
94
+ if type(fn) == "function" and name:match("^nvg[A-Z]") then originals[name] = fn end
95
+ end
96
+ assert(originals.nvgSave and originals.nvgRestore and originals.nvgReset, "NanoVG context is unavailable")
97
+ originals.nvgSave(ctx)
98
+ active = true
99
+ -- Refuse unrecorded drawing instead of returning a visually incomplete success.
100
+ for name in pairs(originals) do
101
+ local api = name
102
+ _G[api] = function()
103
+ failure = "Unsupported NanoVG capture API: " .. api
104
+ error(failure)
105
+ end
106
+ end
107
+ for op, sig in pairs(signatures) do
108
+ local operation, signature = op, sig
109
+ local name = "nvg" .. op:sub(1, 1):upper() .. op:sub(2)
110
+ wrap(name, function(vg, ...)
111
+ assert(vg == ctx, "A capture may only use its own NanoVG context")
112
+ local args = { ... }
113
+ for i = 1, #signature do
114
+ local kind = signature:sub(i, i)
115
+ if kind == "c" then args[i] = capturedColor(args[i])
116
+ elseif kind == "p" then
117
+ assert(paintValues[args[i]], "Paint was created outside capture")
118
+ args[i] = paintValues[args[i]]
119
+ end
120
+ end
121
+ validateArgs(args, signature)
122
+ if operation == "save" then assert(depth < 32, "NanoVG stack limit") end
123
+ if operation == "restore" then assert(depth > 0, "Unbalanced NanoVG restore") end
124
+ remember(operation, args)
125
+ local result = originals[name](vg, ...)
126
+ if operation == "save" then depth = depth + 1 end
127
+ if operation == "restore" then depth = depth - 1 end
128
+ return result
129
+ end)
130
+ end
131
+ for _, name in ipairs({ "nvgRGB", "nvgRGBA", "nvgRGBf", "nvgRGBAf" }) do
132
+ local api = name
133
+ wrap(api, function(...)
134
+ local a = { ... }; local factor = api:sub(-1) == "f" and 255 or 1
135
+ local rgba = { a[1] * factor, a[2] * factor, a[3] * factor, a[4] and a[4] * factor or 255 }
136
+ color(rgba)
137
+ local result = originals[api](...); colors[result] = rgba; return result
138
+ end)
139
+ end
140
+ for kind, sig in pairs(paints) do
141
+ local paintKind, signature = kind, sig
142
+ local name = "nvg" .. kind:sub(1, 1):upper() .. kind:sub(2)
143
+ wrap(name, function(vg, ...)
144
+ assert(vg == ctx, "NanoVG context mismatch")
145
+ local args = { ... }
146
+ if paintKind == "imagePattern" then
147
+ assert(images[args[6]], "Image handle requires opts.images mapping")
148
+ args[6] = images[args[6]]
149
+ else args[5] = capturedColor(args[5]); args[6] = capturedColor(args[6]) end
150
+ validateArgs(args, signature)
151
+ local result = originals[name](vg, ...)
152
+ paintValues[result] = { kind = paintKind, args = args }
153
+ return result
154
+ end)
155
+ end
156
+ wrap("nvgFontFaceId", function(vg, id)
157
+ assert(vg == ctx and fonts[id], "Font ID requires opts.fonts mapping")
158
+ remember("fontFace", { fonts[id] }); return originals.nvgFontFaceId(vg, id)
159
+ end)
160
+ for _, name in ipairs({ "nvgImageSize", "nvgTextBounds", "nvgTextMetrics" }) do
161
+ if originals[name] then _G[name] = originals[name] end
162
+ end
163
+ local ok, err = xpcall(function()
164
+ originals.nvgReset(ctx)
165
+ originals.nvgBeginPath(ctx)
166
+ draw()
167
+ assert(not failure, failure)
168
+ validate(node)
169
+ end, function(e) return tostring(e) end)
170
+ for name, fn in pairs(originals) do _G[name] = fn end
171
+ for _ = 1, depth do originals.nvgRestore(ctx) end
172
+ originals.nvgRestore(ctx)
173
+ active = false
174
+ if not ok then error(err) end
175
+ return node
176
+ end
177
+
178
+ local function nativeColor(value) return nvgRGBA(unpack(color(value))) end
179
+ local function multiply(a, b)
180
+ return { a[1]*b[1]+a[3]*b[2], a[2]*b[1]+a[4]*b[2], a[1]*b[3]+a[3]*b[4],
181
+ a[2]*b[3]+a[4]*b[4], a[1]*b[5]+a[3]*b[6]+a[5], a[2]*b[5]+a[4]*b[6]+a[6] }
182
+ end
183
+ local function inverse(m)
184
+ local d = m[1]*m[4]-m[2]*m[3]
185
+ if math.abs(d) < 1e-12 then return nil end
186
+ return { m[4]/d, -m[2]/d, -m[3]/d, m[1]/d,
187
+ (m[3]*m[6]-m[4]*m[5])/d, (m[2]*m[5]-m[1]*m[6])/d }
188
+ end
189
+
190
+ -- Draw a leaf inside the caller's active NanoVG frame. Layout belongs to the caller.
191
+ -- resolveImage(path, ctx) returns a cached native handle; this module owns no resources.
192
+ function M.draw(ctx, node, x, y, width, height, resolveImage, opacity)
193
+ validate(node)
194
+ local view, depth = node.viewBox, 0
195
+ local matrix, clips, stack = { 1, 0, 0, 1, 0, 0 }, {}, {}
196
+ nvgSave(ctx)
197
+ local ok, err = xpcall(function()
198
+ nvgTranslate(ctx, x or node.left or 0, y or node.top or 0)
199
+ nvgScale(ctx, (width or node.width or view[3]) / view[3], (height or node.height or view[4]) / view[4])
200
+ nvgTranslate(ctx, -view[1], -view[2])
201
+ nvgFillColor(ctx, nvgRGBA(255, 255, 255, 255)); nvgStrokeColor(ctx, nvgRGBA(0, 0, 0, 255))
202
+ nvgStrokeWidth(ctx, 1); nvgMiterLimit(ctx, 10); nvgLineCap(ctx, 0); nvgLineJoin(ctx, 4)
203
+ nvgFontSize(ctx, 16); nvgFontFace(ctx, "sans"); nvgTextAlign(ctx, 65)
204
+ nvgTextLetterSpacing(ctx, 0)
205
+ if opacity then nvgGlobalAlpha(ctx, opacity) end
206
+ nvgBeginPath(ctx)
207
+ local function clipped(fn, args)
208
+ if #clips == 0 then fn(ctx, unpack(args)); return end
209
+ local inv = inverse(matrix)
210
+ if not inv then return end
211
+ -- Apply layer scissors at paint time so replacing a local scissor cannot
212
+ -- discard an enclosing Widget/ScrollView clip.
213
+ nvgSave(ctx)
214
+ local painted, problem = pcall(function()
215
+ nvgTransform(ctx, unpack(inv))
216
+ for _, clip in ipairs(clips) do
217
+ local back = inverse(clip.matrix)
218
+ if not back then return end
219
+ nvgTransform(ctx, unpack(clip.matrix))
220
+ nvgIntersectScissor(ctx, unpack(clip.args))
221
+ nvgTransform(ctx, unpack(back))
222
+ end
223
+ nvgTransform(ctx, unpack(matrix))
224
+ fn(ctx, unpack(args))
225
+ end)
226
+ nvgRestore(ctx)
227
+ if not painted then error(problem) end
228
+ end
229
+ for _, cmd in ipairs(node.commands) do
230
+ local op, args = cmd[1], {}
231
+ for i = 2, #cmd do args[#args + 1] = cmd[i] end
232
+ if op == "fillColor" or op == "strokeColor" then args[1] = nativeColor(args[1]) end
233
+ if op == "globalAlpha" then args[1] = args[1] * (opacity or 1) end
234
+ if op == "fillPaint" or op == "strokePaint" then
235
+ local p, a = args[1], {}; for i, value in ipairs(args[1].args) do a[i] = value end
236
+ if p.kind == "imagePattern" then
237
+ assert(resolveImage, "Image paint requires resolveImage(path, ctx)")
238
+ a[6] = resolveImage(a[6], ctx)
239
+ assert(type(a[6]) == "number" and a[6] > 0, "NanoVG image could not be resolved")
240
+ else a[5] = nativeColor(a[5]); a[6] = nativeColor(a[6]) end
241
+ args[1] = _G["nvg" .. p.kind:sub(1, 1):upper() .. p.kind:sub(2)](ctx, unpack(a))
242
+ end
243
+ local fn = _G["nvg" .. op:sub(1, 1):upper() .. op:sub(2)]
244
+ assert(type(fn) == "function", "NanoVG runtime API missing: " .. op)
245
+ if op == "scissor" or op == "intersectScissor" then
246
+ local nextClips = {}
247
+ if op == "intersectScissor" then for i, clip in ipairs(clips) do nextClips[i] = clip end end
248
+ nextClips[#nextClips + 1] = { matrix = matrix, args = args }; clips = nextClips
249
+ elseif op == "fill" or op == "stroke" or op == "text" or op == "textBox" then clipped(fn, args)
250
+ else fn(ctx, unpack(args)) end
251
+ if op == "save" then depth = depth + 1; stack[depth] = { matrix = matrix, clips = clips } end
252
+ if op == "restore" then matrix = stack[depth].matrix; clips = stack[depth].clips; stack[depth] = nil; depth = depth - 1 end
253
+ local t
254
+ if op == "transform" then t = args
255
+ elseif op == "translate" then t = { 1, 0, 0, 1, args[1], args[2] }
256
+ elseif op == "scale" then t = { args[1], 0, 0, args[2], 0, 0 }
257
+ elseif op == "rotate" then
258
+ local c, s = math.cos(args[1]), math.sin(args[1]); t = { c, s, -s, c, 0, 0 }
259
+ elseif op == "skewX" then t = { 1, 0, math.tan(args[1]), 1, 0, 0 }
260
+ elseif op == "skewY" then t = { 1, math.tan(args[1]), 0, 1, 0, 0 } end
261
+ if t then matrix = multiply(matrix, t) end
262
+ end
263
+ end, function(e) return tostring(e) end)
264
+ for _ = 1, depth do nvgRestore(ctx) end
265
+ nvgRestore(ctx)
266
+ if not ok then error(err) end
267
+ end
268
+
269
+ -- Register the node before UI.LoadJSON; reuse the engine's layout, input and transforms.
270
+ function M.register(UI, resolveImage)
271
+ assert(not UI.NanoVG, "UI.NanoVG is already registered")
272
+ local Widget = require("urhox-libs/UI/Core/Widget")
273
+ local Vector = Widget:Extend("NanoVG")
274
+ function Vector:Render(ctx)
275
+ local layout = self:GetAbsoluteLayout()
276
+ local data = { type = "NanoVG", commands = self.props.commands, viewBox = self.props.viewBox }
277
+ local opacity, widget = 1, self
278
+ while widget do
279
+ local a = widget.renderProps_ and widget.renderProps_.opacity or widget.props.opacity or 1
280
+ opacity = opacity * math.max(0, math.min(1, a))
281
+ widget = widget.parent
282
+ end
283
+ M.draw(ctx, data, layout.x, layout.y, layout.w, layout.h, resolveImage, opacity)
284
+ end
285
+ UI.NanoVG = Vector
286
+ return Vector
287
+ end
288
+
289
+ return M
@@ -1,6 +1,74 @@
1
1
  (function (root) {
2
2
  "use strict";
3
- var previewTypes = new Set(["Panel", "Label", "Button"]);
3
+ var previewTypes = new Set(["Panel", "Label", "Button", "NanoVG"]);
4
+ // An allowlist shared by the browser, CLI and standalone document checker.
5
+ var nanoOps = {
6
+ save: "", restore: "", beginPath: "", closePath: "", fill: "", stroke: "",
7
+ moveTo: "nn", lineTo: "nn", bezierTo: "nnnnnn", quadTo: "nnnn", arcTo: "nnnnn",
8
+ rect: "nnnn", roundedRect: "nnnnn", roundedRectVarying: "nnnnnnnn",
9
+ circle: "nnn", ellipse: "nnnn", arc: "nnnnnn",
10
+ translate: "nn", scale: "nn", rotate: "n", skewX: "n", skewY: "n", transform: "nnnnnn",
11
+ scissor: "nnnn", intersectScissor: "nnnn",
12
+ fillColor: "c", strokeColor: "c", fillPaint: "p", strokePaint: "p",
13
+ strokeWidth: "n", miterLimit: "n", lineCap: "n", lineJoin: "n", globalAlpha: "n",
14
+ fontSize: "n", fontFace: "s", textAlign: "n", textLetterSpacing: "n", text: "nns", textBox: "nnns",
15
+ };
16
+ function nanoColor(value) {
17
+ return typeof value === "string" && /^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(value) ||
18
+ Array.isArray(value) && value.length === 4 && value.every(function (n) {
19
+ return typeof n === "number" && Number.isFinite(n) && n >= 0 && n <= 255;
20
+ });
21
+ }
22
+ function checkNanoVG(node, issue, resource) {
23
+ var box = node.viewBox, commands = node.commands, depth = 0;
24
+ if (!Array.isArray(box) || box.length !== 4 || box.some(function (n) {
25
+ return typeof n !== "number" || !Number.isFinite(n);
26
+ }) || box[2] <= 0 || box[3] <= 0) issue("/viewBox", "viewBox 必须是 [x, y, 正宽度, 正高度]。");
27
+ if (!Array.isArray(commands) || commands.length > 20000) {
28
+ issue("/commands", "绘制指令必须是数组,最多 20000 条。"); return;
29
+ }
30
+ function paint(value, at) {
31
+ if (!value || typeof value !== "object" || Array.isArray(value) || typeof value.kind !== "string") return false;
32
+ var signatures = { linearGradient: "nnnncc", radialGradient: "nnnncc", imagePattern: "nnnnnsn" };
33
+ var sig = Object.prototype.hasOwnProperty.call(signatures, value.kind) && signatures[value.kind];
34
+ if (!sig || !args(value.args, sig, at + "/args")) return false;
35
+ if (value.kind === "radialGradient" && (value.args[2] < 0 || value.args[3] <= value.args[2])) return false;
36
+ if (value.kind === "imagePattern") {
37
+ if (value.args[2] <= 0 || value.args[3] <= 0 || value.args[6] < 0 || value.args[6] > 1) return false;
38
+ resource(value.args[5], at + "/args/5");
39
+ }
40
+ return true;
41
+ }
42
+ function args(values, sig, at) {
43
+ return Array.isArray(values) && values.length === sig.length && values.every(function (value, i) {
44
+ var type = sig[i];
45
+ return type === "n" ? typeof value === "number" && Number.isFinite(value) :
46
+ type === "s" ? typeof value === "string" : type === "c" ? nanoColor(value) : paint(value, at + "/" + i);
47
+ });
48
+ }
49
+ commands.forEach(function (command, i) {
50
+ var at = "/commands/" + i;
51
+ if (!Array.isArray(command) || typeof command[0] !== "string" || !Object.prototype.hasOwnProperty.call(nanoOps, command[0]) ||
52
+ !args(command.slice(1), nanoOps[command[0]], at)) {
53
+ issue(at, "不支持的 NanoVG 指令或参数。使用 ui capabilities 查询支持范围。"); return;
54
+ }
55
+ var op = command[0], a = command.slice(1);
56
+ if (op === "save" && ++depth > 32) issue(at, "NanoVG 图层状态栈超过 32 层,需为引擎保留栈空间。");
57
+ if (op === "restore" && --depth < 0) { issue(at, "restore 没有对应的 save。"); depth = 0; }
58
+ if (op === "globalAlpha" && (a[0] < 0 || a[0] > 1)) issue(at, "透明度必须在 0 到 1 之间。");
59
+ if (["strokeWidth", "miterLimit", "fontSize"].includes(op) && a[0] <= 0) issue(at, "值必须大于 0。");
60
+ if (op === "lineCap" && ![0, 1, 2].includes(a[0]) || op === "lineJoin" && ![1, 3, 4].includes(a[0]) ||
61
+ op === "arc" && ![1, 2].includes(a[5])) issue(at, "无效的 NanoVG 枚举值。");
62
+ if (op === "textBox" && a[2] <= 0) issue(at, "文本框宽度必须大于 0。");
63
+ if (op === "textAlign" && ![0, 1, 2, 4].some(function (h) {
64
+ return [0, 8, 16, 32, 64].some(function (v) { return a[0] === h + v; });
65
+ })) issue(at, "文本对齐每个方向最多指定一个 NanoVG 标志。");
66
+ if (op === "circle" && a[2] < 0 || op === "ellipse" && (a[2] < 0 || a[3] < 0) ||
67
+ op === "arc" && a[2] < 0 || op === "arcTo" && a[4] < 0 ||
68
+ op.startsWith("roundedRect") && a.slice(4).some(function (n) { return n < 0; })) issue(at, "半径不能为负数。");
69
+ });
70
+ if (depth) issue("/commands", "save/restore 必须配对。");
71
+ }
4
72
  var lengths = ["width", "height", "minWidth", "minHeight", "maxWidth", "maxHeight",
5
73
  "left", "right", "top", "bottom", "padding", "paddingLeft", "paddingRight",
6
74
  "paddingTop", "paddingBottom", "paddingHorizontal", "paddingVertical",
@@ -94,6 +162,10 @@
94
162
  }
95
163
  });
96
164
  resource(node.backgroundImage, pointer + "/backgroundImage");
165
+ resource(node.pressedBackgroundImage, pointer + "/pressedBackgroundImage");
166
+ if (node.type === "NanoVG") checkNanoVG(node, function (at, message) {
167
+ issue("UI_NANOVG", "error", pointer + at, message);
168
+ }, function (ref, at) { resource(ref, pointer + at); });
97
169
  if (node.component != null) {
98
170
  if (token(node.component)) {
99
171
  parameterized = true;
@@ -128,7 +200,7 @@
128
200
  .concat(options.resourceExists ? [] : ["resource-existence"]),
129
201
  };
130
202
  }
131
- var api = { checkDocument: checkDocument };
203
+ var api = { checkDocument: checkDocument, checkNanoVG: checkNanoVG, nanoOps: nanoOps };
132
204
  if (typeof module !== "undefined" && module.exports) module.exports = api;
133
205
  else root.UrhoxUICheck = api;
134
206
  })(typeof window !== "undefined" ? window : globalThis);
@@ -16,25 +16,74 @@ Maker 是流程入口;自由画布展示分析与切图,脚本按显式布
16
16
  - 已有 UI.json,要调位置或对照:直接打开编辑器,不重新生图或覆盖现有文档。
17
17
  - 只说“做个背包/商店界面”:从上下文找原稿及风格要求;缺少会改变结果的设计意图时再询问。
18
18
 
19
+ 已有 UI 的命令行编辑使用同包 taptap-maker ui:capabilities 查看格式,list 找文档,
20
+ inspect 读取保存版本及 revision,patch 按节点 ID(或 children pointer)批量增删改和移动。
21
+ 先用 --dry-run 检查,再带同一 revision 执行;版本冲突时重读并合并,不强制覆盖。
22
+ check 检查声明和资源,open --no-open 返回控制台 UI 编辑器地址。CLI 不读取网页未保存草稿;
23
+ 网页有草稿时先保留,CLI 写入后通过文档菜单重新从磁盘加载或打开保存版本。
24
+
19
25
  ## 准备
20
26
 
21
27
  读取 Maker 状态并绑定明确的项目目录;沿用对话中已选项目。控制台打开、画布 CLI 和付费生成遵循
22
28
  同包 taptap-maker-local 与工具实际 schema。保持同一 target-dir,不凭全局当前项目推断。
23
29
  打开控制台后用 canvas pages / snapshot 读取当前页面、画布和 revision;通过页面桥接操作和保存,
24
30
  不能直接覆写打开中的画布文件。命令参数先读当前 CLI 的 canvas 帮助。
31
+ 修改卡片显示大小使用 canvas update-nodes,例如 input 为
32
+ `{"nodes":[{"id":"卡片ID","width":800}]}`。图片卡设置 width 或 height 即等比调整另一边,
33
+ 它只改变卡片,不改变图片像素、其它卡片位置或画布缩放;具体范围以 canvas capabilities 为准。
34
+
35
+ 尺寸以图片像素为准,不使用画布卡片的 width/height:inspect 的 imageInfo 是当前图片实际宽高和比例,
36
+ originalImage 是沿引用链取得的原稿坐标基准。去文字、背景准备和整屏标注默认 parameters.aspectRatio=source,
37
+ 跟随原稿;图集保持自己的行列排版。固定比例可用 canvas capabilities 的选项显式覆盖。
38
+ 非常见比例先向用户说明可能影响构图和切图;跟随的比例不被接口支持时,在运行前选择支持的比例,
39
+ 不静默拉伸、裁剪原稿,也不把 9:21 当成已支持的输出。原图尺寸和请求/结果尺寸分别保留。
40
+ 生成记录的 referenceImages、originalImage、parameters.targetSize、resultImageInfo 和 warnings 用于核对;
41
+ submittedPrompt 包含实际发送的参考图尺寸。实际结果比例不符时先核对,不把请求尺寸当成成功结果。
25
42
 
26
43
  有完整 UI 拆解用户模板时优先复用,在新画布替换原稿;没有时用现有图片和资源卡建立同样的流程。
27
44
  旧示例结果只供参考。换原稿后重做识别、布局、素材绑定与网格核对,不能只换首图就沿用旧结果。
28
45
 
46
+ 画布手动添加模板默认关闭识图;CLI 的 canvas run 游戏 UI 分组或图片步骤默认开启识图,
47
+ 保存开关,先完成去文字,再取得去文字图的清单后才继续下游,不依赖 Agent 额外开启。
48
+ 带当前 page-id、canvas-id、revision 和 target-dir 执行;只有用户明确要求无识图对照时,
49
+ 在本次及后续 run 的 input 中显式传 `"recognition":false`,例如
50
+ `{"id":"分组ID","recognition":false}`。仅提前关闭卡片开关不能覆盖 CLI run 的默认值。
51
+ 识图由当前对话 AI 自己完成,不要求配置 TAPTAP_MAKER_VISION_CONFIG 或另一个模型服务。
52
+ 沿用看图 → CLI 写入 → 继续流程:
53
+
54
+ 1. 先 run「去文字设计稿」卡片;分组 run 也会先完成去文字,然后提示当前 AI 识图。
55
+ inspect 确认去文字卡已完成,读取它的 assetPath 和 imageInfo,使用当前模型识别这张去文字图。
56
+ 原设计稿只作为去文字输入,以及美术字独立支线的参考;不能用原稿代替去文字图识别。
57
+ 不能以生图的标框图片代替清单;当前模型无法读取图片时,明确建议切换支持图片输入的模型。
58
+ 2. 逐项记录元素 id、name、category、rect(去文字图像素 x/y/宽/高)、parentId、zIndex、states、cutout。
59
+ category 取 icon/frame/tab/action/shortcut/close/title/panel/art_text/text;普通文字 cutout=false。
60
+ 重复按钮逐个记录,不能漏掉实例。坐标是 AI 识别估计,不能宣称精确测量。
61
+ 3. 用现有 canvas update-nodes 写去文字卡的 uiRecognition.result,自动显示便签并供标框/拆图引用。
62
+ input:`{"nodes":[{"id":"去文字卡ID","uiRecognition":{"enabled":true,"result":{...}}}]}`。
63
+ result 字段:id(新 UUID)、model(实际当前模型名,未知写 unknown)、prompt(本次识别要求)、
64
+ createdAt(ISO 时间)、durationMs(识别耗时,未计时写 0)、sourcePath(assetPath)、sourceSha256
65
+ (去文字图字节的 SHA-256)、width/height(真实像素)、elements(上述元素数组)。
66
+ 重新 inspect 取得 revision 后写入;系统校验去文字图路径、哈希、尺寸、坐标和编号,保存并选用清单。
67
+ 4. inspect 的 recognitionState=ready 且便签 text 有实际编号后,再 run 分组。
68
+ 换模型测试时读取同一去文字图,写入新的 result;历史清单保留,画布「对比」可查看和切换。
69
+ 报错时按具体原因修正,不自动关闭识图跳过。远端生图超时或 unknown 先查询原任务,不盲目重提。
70
+
71
+ 只执行已配置的画布模板时,确认输入和参数后使用分组 run(取得付费授权后传 --allow-paid)。
72
+ 队列按连线自动接续图片与资源卡,资源卡按已保存网格裁切并保存独立 PNG,不必逐张调用。
73
+ 最后一步是内容就绪的资源包卡片;入项目、meta、UI.json 和编辑器属于后续独立任务,
74
+ 仅在用户要求时继续。自动裁切不表示视觉复核通过;缺少网格或结果未知时处理原阻塞后再继续。
75
+
29
76
  ## 执行
30
77
 
31
78
  布局字段、坐标依据、冗余资源和双重对位契约见 [workflow.md](references/workflow.md)。
32
79
 
33
- 1. 在原设计稿上记录稳定元素 ID、绝对像素位置、类型、父级及同级绘制顺序。相似按钮是不同实例,
34
- 可共用同一素材;普通文字保留为 Label,美术字独立提取。先保存布局记录,再生成标框图和切图。
35
- 2. 延续已验证的分层流程:去文字稿;分别标注按钮、图标;美术字仍参考原稿;背景在去文字后再去除前景。
80
+ 1. 先从原设计稿生成去文字稿;再由当前 AI 识别去文字稿,保存稳定元素 ID、该图像素位置、类型、父级及绘制顺序。
81
+ 相似按钮逐个记录,清单通过上述 CLI 写入便签,再用于标框和拆图。重新去文字后必须重新识别。
82
+ 2. 按去文字稿的清单分别标注按钮、图标;背景在去文字后再去除前景。
83
+ 美术字是独立支线:标注和提取始终引用未去文字的原设计稿,不能因去文字清单没有美术字而跳过。
36
84
  提取提示词分开写“参考与目标”“保留”“移除”“输出”。按钮默认/按下态分别生成、统一画布与锚点,
37
85
  图标与按钮底板分离;美术字只保留字形及字效,不带后方底框。
86
+ 后续组装需要的普通文字及原稿布局单独对照原稿补录,不混入去文字切图清单。
38
87
  3. 查看真实结果。透明处理、必要的重新排版要明确使用已有能力或可重复的本地处理,不能把人工修图冒充模板自动能力。
39
88
  用图集预览核对完整边界后确认,再导出独立 PNG;未知远端任务只查原任务,不自动重提。
40
89
  4. 正式素材按 assets/ui/<界面>/images/ 归档;备用图同目录 reserve/ 保留但不入布局。
@@ -56,6 +105,8 @@ Maker 是流程入口;自由画布展示分析与切图,脚本按显式布
56
105
  用当前分发的 CLI 执行 console open --target-dir <项目> --no-open --json,取得真实地址;
57
106
  保留其项目参数,追加 &page=ui-editor&ui=<URL编码的 assets/ 相对 UI 路径>,即可直达文档。
58
107
  控制台已打开时也可进入「UI 编辑器」并刷新文件列表。不要启动独立 UrhoxUIEditor 或 Python 服务。
108
+ 也可直接运行 taptap-maker ui open --target-dir <项目> --file <assets/相对UI路径> --no-open --json,
109
+ 取得含项目与 checkout 身份的直达地址;不要手工拼接另一个项目的 URL。
59
110
 
60
111
  ## 完成检查
61
112
 
@@ -639,7 +639,7 @@ request/correlation ID, reproduction steps, visible Maker tools, client version,
639
639
  Do not include the complete conversation. Send that JSON through stdin, never argv, while running:
640
640
 
641
641
  ```text
642
- npx -y --package @taptap/maker@0.0.37-beta.4 taptap-maker mcp report --ide <client> --target-dir <project> --context-stdin --consent --json
642
+ npx -y --package @taptap/maker@0.0.37-beta.5 taptap-maker mcp report --ide <client> --target-dir <project> --context-stdin --consent --json
643
643
  ```
644
644
 
645
645
  Prefer the active client's exact Maker MCP `command` plus ordered `args`, then append the `mcp