dsh-vscode-mode 0.39.0 → 0.41.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 (51) hide show
  1. package/README.md +11 -8
  2. package/lib/client.js +83 -64
  3. package/lib/client.js.map +1 -1
  4. package/lib/index.js +4765 -1886
  5. package/lib/index.js.map +1 -1
  6. package/package.json +1 -1
  7. package/skills/dsh-vscodemode-test-check/SKILL.md +82 -0
  8. package/skills/dsh-vscodemode-ui-kit/SKILL.md +84 -0
  9. package/skills/dsh-vscodemode-ui-kit/fixtures/selftest/spec.json +65 -0
  10. package/skills/dsh-vscodemode-ui-kit/references/detect.md +90 -0
  11. package/skills/dsh-vscodemode-ui-kit/references/lib.md +48 -0
  12. package/skills/dsh-vscodemode-ui-kit/references/questions.md +68 -0
  13. package/skills/dsh-vscodemode-ui-kit/references/spec.md +99 -0
  14. package/skills/dsh-vscodemode-ui-kit/references/verify.md +37 -0
  15. package/skills/dsh-vscodemode-ui-kit/runtime/build.mjs +348 -0
  16. package/skills/dsh-vscodemode-ui-kit/runtime/css/framework.css +398 -0
  17. package/skills/dsh-vscodemode-ui-kit/runtime/js/01-core.js +182 -0
  18. package/skills/dsh-vscodemode-ui-kit/runtime/js/02-state.js +96 -0
  19. package/skills/dsh-vscodemode-ui-kit/runtime/js/03-tree.js +144 -0
  20. package/skills/dsh-vscodemode-ui-kit/runtime/js/04-canvas.js +194 -0
  21. package/skills/dsh-vscodemode-ui-kit/runtime/js/05-inspector.js +241 -0
  22. package/skills/dsh-vscodemode-ui-kit/runtime/js/06-diff.js +52 -0
  23. package/skills/dsh-vscodemode-ui-kit/runtime/js/07-reply.js +71 -0
  24. package/skills/dsh-vscodemode-ui-kit/runtime/js/08-main.js +147 -0
  25. package/skills/dsh-vscodemode-ui-kit/runtime/spec.schema.json +79 -0
  26. package/src/attachmentBytes.ts +84 -0
  27. package/src/client/index.ts +6 -0
  28. package/src/client/openReceipt.ts +5 -2
  29. package/src/client/sidebar/panels/TestCheckPanel.ts +485 -0
  30. package/src/client/sidebar/panels/useTestCheckData.ts +414 -0
  31. package/src/client/sidebar/types.ts +2 -0
  32. package/src/client/styles/editor.css +78 -0
  33. package/src/client/testCheck/TestCheckChip.ts +181 -0
  34. package/src/client/testCheck/TestCheckPanel.ts +339 -0
  35. package/src/client/testCheckPanelState.ts +173 -0
  36. package/src/client/ui/EditorView.ts +69 -6
  37. package/src/htmlPlanAttachments.ts +4 -1
  38. package/src/htmlPlanCommand.ts +4 -62
  39. package/src/index.ts +4 -0
  40. package/src/rpc.ts +3 -0
  41. package/src/shared/rpc.ts +44 -0
  42. package/src/shared/testCheck.ts +759 -0
  43. package/src/shared/testCheckHtml.ts +276 -0
  44. package/src/shared/testCheckPolicyDefault.ts +37 -0
  45. package/src/shared/testCheckSnippets.ts +197 -0
  46. package/src/testCheckCommand.ts +287 -0
  47. package/src/testCheckGuidance.ts +79 -0
  48. package/src/testCheckMode.ts +654 -0
  49. package/src/testCheckPolicy.ts +141 -0
  50. package/src/testCheckRpc.ts +196 -0
  51. package/src/testCheckStore.ts +822 -0
@@ -0,0 +1,398 @@
1
+ /* ui-kit framework.css —— 单文件内联,不依赖外部字体与图片 */
2
+ :root {
3
+ --uk-bg: #fbfaf6;
4
+ --uk-bg-sunk: #efece4;
5
+ --uk-line: #d9d3c6;
6
+ --uk-line-soft: #e7e2d6;
7
+ --uk-ink: #24211d;
8
+ --uk-ink-dim: #6b6459;
9
+ --uk-accent: #2f7de1;
10
+ --uk-accent-soft: rgba(47, 125, 225, 0.12);
11
+ --uk-warn: #b8581c;
12
+ --uk-ok: #2f7a3f;
13
+ --uk-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Cascadia Mono", monospace;
14
+ color-scheme: light;
15
+ }
16
+
17
+ * { box-sizing: border-box; }
18
+
19
+ html, body {
20
+ margin: 0;
21
+ height: 100%;
22
+ background: #e9e5da;
23
+ color: var(--uk-ink);
24
+ font: 13px/1.5 system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
25
+ -webkit-font-smoothing: antialiased;
26
+ }
27
+
28
+ button, input, select, textarea { font: inherit; color: inherit; }
29
+ button { cursor: pointer; }
30
+
31
+ /* ── 外壳 ─────────────────────────────────────────────── */
32
+
33
+ .ui-app {
34
+ position: fixed;
35
+ inset: 0;
36
+ display: grid;
37
+ grid-template-rows: 42px minmax(0, 1fr) 38px;
38
+ background: var(--uk-bg);
39
+ }
40
+
41
+ .ui-bar {
42
+ display: flex;
43
+ align-items: center;
44
+ gap: 10px;
45
+ padding: 0 12px;
46
+ border-bottom: 1px solid var(--uk-line);
47
+ background: var(--uk-bg-sunk);
48
+ min-width: 0;
49
+ }
50
+
51
+ .ui-bar .ui-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
52
+ .ui-bar .ui-meta { color: var(--uk-ink-dim); font-size: 12px; white-space: nowrap; }
53
+ .ui-spacer { flex: 1; }
54
+
55
+ .ui-chip {
56
+ padding: 2px 7px;
57
+ border: 1px solid var(--uk-line);
58
+ border-radius: 99px;
59
+ background: #fff;
60
+ color: var(--uk-ink-dim);
61
+ font-size: 11px;
62
+ white-space: nowrap;
63
+ }
64
+
65
+ .ui-btn {
66
+ padding: 4px 10px;
67
+ border: 1px solid var(--uk-line);
68
+ border-radius: 6px;
69
+ background: #fff;
70
+ font-size: 12px;
71
+ }
72
+ .ui-btn:hover { border-color: #bfb7a6; }
73
+ .ui-btn:active { transform: translateY(0.5px); }
74
+ .ui-btn[disabled] { opacity: 0.45; cursor: default; }
75
+ .ui-btn.ui-primary { background: var(--uk-accent); border-color: var(--uk-accent); color: #fff; }
76
+ .ui-btn.ui-ghost { background: transparent; border-color: transparent; color: var(--uk-ink-dim); padding: 3px 6px; }
77
+ .ui-btn.ui-ghost:hover { background: #ece7db; color: var(--uk-ink); }
78
+
79
+ .ui-body {
80
+ display: grid;
81
+ grid-template-columns: 262px minmax(0, 1fr) 330px;
82
+ min-height: 0;
83
+ }
84
+
85
+ .ui-pane {
86
+ min-height: 0;
87
+ overflow: auto;
88
+ background: var(--uk-bg);
89
+ border-right: 1px solid var(--uk-line);
90
+ }
91
+ .ui-pane.ui-insp { border-right: 0; border-left: 1px solid var(--uk-line); }
92
+
93
+ .ui-pane-head {
94
+ position: sticky;
95
+ top: 0;
96
+ z-index: 2;
97
+ display: flex;
98
+ align-items: center;
99
+ gap: 6px;
100
+ padding: 7px 10px;
101
+ border-bottom: 1px solid var(--uk-line-soft);
102
+ background: var(--uk-bg);
103
+ font-size: 11px;
104
+ letter-spacing: 0.04em;
105
+ color: var(--uk-ink-dim);
106
+ text-transform: uppercase;
107
+ }
108
+
109
+ /* ── 树 ───────────────────────────────────────────────── */
110
+
111
+ .ui-tree { padding: 4px 6px 16px; }
112
+
113
+ .ui-row {
114
+ display: flex;
115
+ align-items: center;
116
+ gap: 6px;
117
+ height: 24px;
118
+ padding-right: 6px;
119
+ border-radius: 5px;
120
+ white-space: nowrap;
121
+ cursor: default;
122
+ user-select: none;
123
+ }
124
+ .ui-row:hover { background: #f1ede3; }
125
+ .ui-row.sel { background: var(--uk-accent-soft); box-shadow: inset 0 0 0 1px rgba(47, 125, 225, 0.35); }
126
+ .ui-row .ui-caret { width: 12px; text-align: center; color: var(--uk-ink-dim); font-size: 10px; }
127
+ .ui-row .ui-name { overflow: hidden; text-overflow: ellipsis; }
128
+ .ui-row .ui-kind {
129
+ margin-left: auto;
130
+ color: var(--uk-ink-dim);
131
+ font-size: 10px;
132
+ padding: 0 4px;
133
+ border-radius: 3px;
134
+ background: #ece7db;
135
+ }
136
+ .ui-row.sel .ui-kind { background: #fff; }
137
+ .ui-row .ui-binddot { width: 5px; height: 5px; border-radius: 50%; background: var(--uk-accent); }
138
+
139
+ /* ── 画布 ─────────────────────────────────────────────── */
140
+
141
+ .ui-stage {
142
+ position: relative;
143
+ min-height: 0;
144
+ overflow: hidden;
145
+ background:
146
+ repeating-conic-gradient(#e2ddcf 0% 25%, #e9e5da 0% 50%) 0 0 / 18px 18px;
147
+ cursor: default;
148
+ }
149
+ .ui-stage.panning { cursor: grabbing; }
150
+
151
+ .ui-canvas {
152
+ position: absolute;
153
+ left: 0;
154
+ top: 0;
155
+ transform-origin: 0 0;
156
+ background: #fff;
157
+ box-shadow: 0 2px 18px rgba(60, 50, 30, 0.18);
158
+ }
159
+ .ui-canvas > img { display: block; width: 100%; height: 100%; object-fit: fill; }
160
+ .ui-canvas > .ui-empty {
161
+ display: flex;
162
+ flex-direction: column;
163
+ align-items: center;
164
+ justify-content: center;
165
+ gap: 6px;
166
+ width: 100%;
167
+ height: 100%;
168
+ color: #8d8371;
169
+ background: repeating-linear-gradient(0deg, #efece4 0 1px, transparent 1px 24px),
170
+ repeating-linear-gradient(90deg, #efece4 0 1px, transparent 1px 24px),
171
+ #faf8f2;
172
+ font-size: 13px;
173
+ }
174
+
175
+ .ui-nodes { position: absolute; inset: 0; }
176
+
177
+ .ui-node {
178
+ position: absolute;
179
+ border: 1px solid rgba(120, 110, 90, 0.22);
180
+ border-radius: 1px;
181
+ }
182
+ .ui-node:hover { border-color: rgba(47, 125, 225, 0.6); background: rgba(47, 125, 225, 0.04); }
183
+ .ui-node.sel { border-color: var(--uk-accent); background: var(--uk-accent-soft); }
184
+ .ui-node.sel::after {
185
+ content: '';
186
+ position: absolute;
187
+ inset: -2px;
188
+ border: 1px solid rgba(47, 125, 225, 0.35);
189
+ pointer-events: none;
190
+ }
191
+ .ui-node.opaque { border-style: dashed; border-color: rgba(120, 110, 90, 0.5); }
192
+ .ui-node .ui-node-tag {
193
+ position: absolute;
194
+ left: 0;
195
+ top: -17px;
196
+ padding: 1px 5px;
197
+ border-radius: 3px;
198
+ background: var(--uk-accent);
199
+ color: #fff;
200
+ font: 10px/1.35 var(--uk-mono);
201
+ white-space: nowrap;
202
+ pointer-events: none;
203
+ }
204
+ .ui-node .ui-node-text { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
205
+
206
+ .ui-handle {
207
+ position: absolute;
208
+ width: 7px;
209
+ height: 7px;
210
+ background: #fff;
211
+ border: 1.5px solid var(--uk-accent);
212
+ border-radius: 1px;
213
+ }
214
+ .ui-handle.nw { left: -4px; top: -4px; cursor: nwse-resize; }
215
+ .ui-handle.n { left: calc(50% - 3.5px); top: -4px; cursor: ns-resize; }
216
+ .ui-handle.ne { right: -4px; top: -4px; cursor: nesw-resize; }
217
+ .ui-handle.w { left: -4px; top: calc(50% - 3.5px); cursor: ew-resize; }
218
+ .ui-handle.e { right: -4px; top: calc(50% - 3.5px); cursor: ew-resize; }
219
+ .ui-handle.sw { left: -4px; bottom: -4px; cursor: nesw-resize; }
220
+ .ui-handle.s { left: calc(50% - 3.5px); bottom: -4px; cursor: ns-resize; }
221
+ .ui-handle.se { right: -4px; bottom: -4px; cursor: nwse-resize; }
222
+
223
+ /* ── 属性 ─────────────────────────────────────────────── */
224
+
225
+ .ui-insp { padding-bottom: 24px; }
226
+ .ui-group { padding: 10px 12px; border-bottom: 1px solid var(--uk-line-soft); }
227
+ .ui-group h4 {
228
+ margin: 0 0 8px;
229
+ font-size: 11px;
230
+ letter-spacing: 0.05em;
231
+ color: var(--uk-ink-dim);
232
+ text-transform: uppercase;
233
+ font-weight: 600;
234
+ }
235
+
236
+ .ui-id {
237
+ font: 11px/1.45 var(--uk-mono);
238
+ color: var(--uk-ink);
239
+ word-break: break-all;
240
+ padding: 4px 6px;
241
+ border-radius: 4px;
242
+ background: #f3efe6;
243
+ }
244
+
245
+ .ui-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
246
+ .ui-grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
247
+ .ui-field { display: grid; gap: 3px; }
248
+ .ui-field > label { font-size: 10.5px; color: var(--uk-ink-dim); }
249
+ .ui-field > input, .ui-field > select, .ui-field > textarea {
250
+ width: 100%;
251
+ padding: 4px 6px;
252
+ border: 1px solid var(--uk-line);
253
+ border-radius: 5px;
254
+ background: #fff;
255
+ font-size: 12px;
256
+ }
257
+ .ui-field > input[type="number"] { font-family: var(--uk-mono); }
258
+ .ui-field > textarea { resize: vertical; min-height: 56px; line-height: 1.45; }
259
+ .ui-field > input:focus, .ui-field > select:focus, .ui-field > textarea:focus {
260
+ outline: 2px solid var(--uk-accent-soft);
261
+ border-color: var(--uk-accent);
262
+ }
263
+
264
+ .ui-preset {
265
+ display: grid;
266
+ grid-template-columns: repeat(3, 1fr);
267
+ gap: 3px;
268
+ width: 66px;
269
+ }
270
+ .ui-preset button {
271
+ height: 18px;
272
+ border: 1px solid var(--uk-line);
273
+ border-radius: 3px;
274
+ background: #fff;
275
+ padding: 0;
276
+ }
277
+ .ui-preset button:hover { border-color: var(--uk-accent); }
278
+
279
+ .ui-hint { color: var(--uk-ink-dim); font-size: 11px; }
280
+ .ui-empty-note { padding: 22px 14px; color: var(--uk-ink-dim); font-size: 12px; text-align: center; }
281
+
282
+ /* ── 改动抽屉 ──────────────────────────────────────────── */
283
+
284
+ .ui-drawer {
285
+ position: fixed;
286
+ right: 0;
287
+ bottom: 38px;
288
+ z-index: 30;
289
+ display: flex;
290
+ flex-direction: column;
291
+ width: min(560px, 92vw);
292
+ max-height: min(62vh, 560px);
293
+ border: 1px solid var(--uk-line);
294
+ border-right: 0;
295
+ border-bottom: 0;
296
+ border-radius: 10px 0 0 0;
297
+ background: var(--uk-bg);
298
+ box-shadow: -6px -6px 24px rgba(60, 50, 30, 0.16);
299
+ }
300
+ .ui-drawer[hidden] { display: none; }
301
+ .ui-drawer-head {
302
+ display: flex;
303
+ align-items: center;
304
+ gap: 8px;
305
+ padding: 8px 12px;
306
+ border-bottom: 1px solid var(--uk-line-soft);
307
+ font-size: 12px;
308
+ color: var(--uk-ink-dim);
309
+ }
310
+ .ui-ops { overflow: auto; padding: 4px 6px; min-height: 40px; }
311
+ .ui-op {
312
+ display: flex;
313
+ align-items: baseline;
314
+ gap: 8px;
315
+ padding: 4px 6px;
316
+ border-radius: 5px;
317
+ font-size: 12px;
318
+ }
319
+ .ui-op:hover { background: #f1ede3; }
320
+ .ui-op .ui-op-kind {
321
+ flex: none;
322
+ width: 54px;
323
+ font: 10px/1.6 var(--uk-mono);
324
+ color: #fff;
325
+ text-align: center;
326
+ border-radius: 3px;
327
+ background: #8b8375;
328
+ }
329
+ .ui-op .ui-op-kind.set { background: var(--uk-accent); }
330
+ .ui-op .ui-op-kind.add { background: var(--uk-ok); }
331
+ .ui-op .ui-op-kind.del { background: #a53434; }
332
+ .ui-op .ui-op-kind.use { background: #7a5bb5; }
333
+ .ui-op .ui-op-kind.extract { background: var(--uk-warn); }
334
+ .ui-op .ui-op-body { min-width: 0; word-break: break-all; font-family: var(--uk-mono); font-size: 11px; }
335
+ .ui-op .ui-op-x { margin-left: auto; border: 0; background: transparent; color: var(--uk-ink-dim); }
336
+ .ui-drawer-foot { padding: 8px 12px; border-top: 1px solid var(--uk-line-soft); display: grid; gap: 6px; }
337
+ .ui-drawer textarea { width: 100%; min-height: 42px; resize: vertical; padding: 5px 7px; border: 1px solid var(--uk-line); border-radius: 6px; }
338
+ .ui-patch {
339
+ margin: 0;
340
+ max-height: 168px;
341
+ overflow: auto;
342
+ padding: 8px;
343
+ border: 1px solid var(--uk-line);
344
+ border-radius: 6px;
345
+ background: #f5f2ea;
346
+ font: 11px/1.5 var(--uk-mono);
347
+ white-space: pre-wrap;
348
+ word-break: break-all;
349
+ }
350
+
351
+ /* ── 底栏 ─────────────────────────────────────────────── */
352
+
353
+ .ui-foot {
354
+ display: flex;
355
+ align-items: center;
356
+ gap: 10px;
357
+ padding: 0 12px;
358
+ border-top: 1px solid var(--uk-line);
359
+ background: var(--uk-bg-sunk);
360
+ font-size: 12px;
361
+ color: var(--uk-ink-dim);
362
+ }
363
+ .ui-foot .ui-status { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
364
+ .ui-foot .ui-dirty { color: var(--uk-warn); }
365
+
366
+ /* ── 右键菜单 ─────────────────────────────────────────── */
367
+
368
+ .ui-menu {
369
+ position: fixed;
370
+ z-index: 60;
371
+ min-width: 148px;
372
+ padding: 4px;
373
+ border: 1px solid var(--uk-line);
374
+ border-radius: 8px;
375
+ background: #fff;
376
+ box-shadow: 0 6px 22px rgba(60, 50, 30, 0.2);
377
+ }
378
+ .ui-menu button {
379
+ display: block;
380
+ width: 100%;
381
+ padding: 6px 10px;
382
+ border: 0;
383
+ border-radius: 5px;
384
+ background: transparent;
385
+ text-align: left;
386
+ font-size: 12px;
387
+ }
388
+ .ui-menu button:hover { background: #f1ede3; }
389
+ .ui-menu hr { margin: 4px 6px; border: 0; border-top: 1px solid var(--uk-line-soft); }
390
+
391
+ @media (max-width: 900px) {
392
+ .ui-body { grid-template-columns: 200px minmax(0, 1fr) 260px; }
393
+ }
394
+ @media (max-width: 680px) {
395
+ .ui-body { grid-template-columns: minmax(0, 1fr); }
396
+ .ui-pane.ui-tree { display: none; }
397
+ .ui-pane.ui-insp { position: fixed; right: 0; top: 42px; bottom: 38px; width: 260px; z-index: 20; }
398
+ }
@@ -0,0 +1,182 @@
1
+ /* 01 · 核心工具:DOM 构造、hash、点路径、节点树、patch 应用 */
2
+ (function (UK) {
3
+ 'use strict'
4
+
5
+ function cssName(name) {
6
+ return name.indexOf('-') >= 0 ? name : name.replace(/[A-Z]/g, function (m) { return '-' + m.toLowerCase() })
7
+ }
8
+
9
+ UK.el = function (tag, attrs, children) {
10
+ var node = document.createElement(tag)
11
+ if (attrs) {
12
+ Object.keys(attrs).forEach(function (k) {
13
+ var v = attrs[k]
14
+ if (v == null || v === false) return
15
+ if (k === 'class') node.className = v
16
+ else if (k === 'text') node.textContent = v
17
+ else if (k === 'html') node.innerHTML = v
18
+ else if (k === 'style' && typeof v === 'object') {
19
+ Object.keys(v).forEach(function (name) {
20
+ if (v[name] == null || v[name] === '') return
21
+ node.style.setProperty(cssName(name), String(v[name]))
22
+ })
23
+ } else if (k.slice(0, 2) === 'on') node.addEventListener(k.slice(2).toLowerCase(), v)
24
+ else node.setAttribute(k, v === true ? '' : v)
25
+ })
26
+ }
27
+ ;[].concat(children || []).forEach(function (c) {
28
+ if (c == null || c === false) return
29
+ node.appendChild(typeof c === 'string' ? document.createTextNode(c) : c)
30
+ })
31
+ return node
32
+ }
33
+
34
+ UK.clone = function (v) { return JSON.parse(JSON.stringify(v)) }
35
+
36
+ /* ── hash:与 build.mjs 完全一致 ── */
37
+
38
+ UK.canonical = function canon(v) {
39
+ if (v === null || typeof v !== 'object') return JSON.stringify(v)
40
+ if (Array.isArray(v)) return '[' + v.map(canon).join(',') + ']'
41
+ return '{' + Object.keys(v).filter(function (k) { return v[k] !== undefined }).sort()
42
+ .map(function (k) { return JSON.stringify(k) + ':' + canon(v[k]) }).join(',') + '}'
43
+ }
44
+
45
+ UK.fnv1a = function (s) {
46
+ var h = 0x811c9dc5
47
+ for (var i = 0; i < s.length; i++) {
48
+ h ^= s.charCodeAt(i)
49
+ h = Math.imul(h, 0x01000193) >>> 0
50
+ }
51
+ return ('0000000' + h.toString(16)).slice(-8)
52
+ }
53
+
54
+ UK.hashSpec = function (spec) {
55
+ var copy = UK.clone(spec)
56
+ delete copy.hash
57
+ return UK.fnv1a(UK.canonical(copy))
58
+ }
59
+
60
+ /* ── 点路径 ── */
61
+
62
+ UK.getPath = function (obj, path) {
63
+ return String(path).split('.').reduce(function (cur, key) {
64
+ return cur == null ? undefined : cur[key]
65
+ }, obj)
66
+ }
67
+
68
+ UK.setPath = function (obj, path, value) {
69
+ var keys = String(path).split('.')
70
+ var last = keys.pop()
71
+ var cur = obj
72
+ for (var i = 0; i < keys.length; i++) {
73
+ var k = keys[i]
74
+ if (cur[k] == null || typeof cur[k] !== 'object') cur[k] = {}
75
+ cur = cur[k]
76
+ }
77
+ cur[last] = value
78
+ return obj
79
+ }
80
+
81
+ /* ── 节点索引与树 ── */
82
+
83
+ UK.index = function (spec) {
84
+ var byId = {}
85
+ ;(spec.nodes || []).forEach(function (n, i) { if (n && n.id) { byId[n.id] = n; n.__i = i } })
86
+ return byId
87
+ }
88
+
89
+ UK.childrenOf = function (spec, id) {
90
+ return (spec.nodes || []).filter(function (n) { return n && n.parent === id })
91
+ }
92
+
93
+ UK.descendantsOf = function (spec, id) {
94
+ var out = []
95
+ var walk = function (pid) {
96
+ UK.childrenOf(spec, pid).forEach(function (n) { out.push(n); walk(n.id) })
97
+ }
98
+ walk(id)
99
+ return out
100
+ }
101
+
102
+ /** 节点在屏幕坐标系里的矩形(相对画布原点) */
103
+ UK.absRect = function (spec, node) {
104
+ var byId = UK.index(spec)
105
+ var x = 0, y = 0, cur = node, guard = 0
106
+ while (cur && guard++ < 64) {
107
+ x += cur.rect ? Number(cur.rect[0]) || 0 : 0
108
+ y += cur.rect ? Number(cur.rect[1]) || 0 : 0
109
+ cur = cur.parent ? byId[cur.parent] : null
110
+ }
111
+ return [x, y, Number(node.rect[2]) || 0, Number(node.rect[3]) || 0]
112
+ }
113
+
114
+ UK.depthOf = function (spec, node) {
115
+ var byId = UK.index(spec)
116
+ var d = 0, p = node.parent
117
+ while (p && byId[p] && d < 64) { d++; p = byId[p].parent }
118
+ return d
119
+ }
120
+
121
+ /* ── 应用 ops(只改结构的四种;extract/scope/ask 只作记录) ── */
122
+
123
+ var STRUCT_OPS = { set: 1, add: 1, del: 1, use: 1 }
124
+
125
+ UK.isStructOp = function (op) { return !!STRUCT_OPS[op && op.op] }
126
+
127
+ UK.applyOps = function (baseSpec, ops) {
128
+ var spec = UK.clone(baseSpec)
129
+ delete spec.hash
130
+ ;(ops || []).forEach(function (op) {
131
+ if (!UK.isStructOp(op)) return
132
+ var byId = UK.index(spec)
133
+ if (op.op === 'set') {
134
+ var target = byId[op.id]
135
+ if (target) UK.setPath(target, op.field, UK.clone(op.value))
136
+ } else if (op.op === 'add') {
137
+ if (!op.node || !op.node.id || byId[op.node.id]) return
138
+ var node = UK.clone(op.node)
139
+ node.parent = op.parent != null ? op.parent : node.parent
140
+ if (!node.rect) node.rect = [8, 8, 120, 40]
141
+ if (!node.kind) node.kind = 'group'
142
+ spec.nodes = spec.nodes || []
143
+ spec.nodes.push(node)
144
+ } else if (op.op === 'del') {
145
+ var dead = {}
146
+ dead[op.id] = 1
147
+ UK.descendantsOf(spec, op.id).forEach(function (n) { dead[n.id] = 1 })
148
+ spec.nodes = (spec.nodes || []).filter(function (n) { return !dead[n.id] })
149
+ } else if (op.op === 'use') {
150
+ var used = byId[op.node]
151
+ if (used) {
152
+ var deadIds = {}
153
+ UK.childrenOf(spec, used.id).forEach(function (n) { deadIds[n.id] = 1 })
154
+ spec.nodes = (spec.nodes || []).filter(function (n) { return !deadIds[n.id] })
155
+ var ver = op.version == null ? '' : '@' + op.version
156
+ used.ref = 'lib:' + op.lib + ver
157
+ if (op.kind) used.kind = op.kind
158
+ }
159
+ }
160
+ })
161
+ return spec
162
+ }
163
+
164
+ UK.opLabel = function (op) {
165
+ if (!op || !op.op) return '?'
166
+ if (op.op === 'set') return op.id + ' · ' + op.field + ' = ' + short(op.value)
167
+ if (op.op === 'add') return (op.node && op.node.id) + ' ↳ ' + (op.parent || 'root')
168
+ if (op.op === 'del') return op.id
169
+ if (op.op === 'use') return op.node + ' ← lib:' + op.lib + (op.version ? '@' + op.version : '')
170
+ if (op.op === 'extract') return op.node + ' → ' + ((op.meta && op.meta.name) || '新条目')
171
+ if (op.op === 'scope') return (op.ids || []).join(', ')
172
+ if (op.op === 'ask') return op.id + ' = ' + op.answer
173
+ return op.op
174
+ }
175
+
176
+ function short(v) {
177
+ var s = typeof v === 'string' ? v : JSON.stringify(v)
178
+ if (s == null) return String(v)
179
+ return s.length > 46 ? s.slice(0, 43) + '…' : s
180
+ }
181
+ UK.short = short
182
+ })(window.__UIKIT__ = window.__UIKIT__ || {})
@@ -0,0 +1,96 @@
1
+ /* 02 · 状态:只读 ui-spec,所有交互记成 ops,再从 base 重放 */
2
+ (function (UK) {
3
+ 'use strict'
4
+
5
+ function readSpec() {
6
+ var block = document.getElementById('ui-spec')
7
+ if (!block) throw new Error('页面里没有 ui-spec 块')
8
+ return JSON.parse(block.textContent)
9
+ }
10
+
11
+ var initial = readSpec()
12
+ var baseHash = initial.hash || UK.hashSpec(initial)
13
+
14
+ UK.state = {
15
+ baseSpec: (function () { var s = UK.clone(initial); delete s.hash; return s })(),
16
+ baseHash: baseHash,
17
+ spec: UK.clone(initial),
18
+ ops: [],
19
+ selected: null,
20
+ scope: [],
21
+ note: '',
22
+ zoom: 1,
23
+ pan: { x: 0, y: 0 },
24
+ drawer: false,
25
+ filter: ''
26
+ }
27
+
28
+ UK.selectedNode = function () {
29
+ var st = UK.state
30
+ if (!st.selected) return null
31
+ return UK.index(st.spec)[st.selected] || null
32
+ }
33
+
34
+ UK.notify = function () {
35
+ if (UK.renderAll) UK.renderAll()
36
+ }
37
+
38
+ UK.rebuild = function () {
39
+ var st = UK.state
40
+ st.spec = UK.applyOps(st.baseSpec, st.ops)
41
+ st.spec.hash = st.baseHash
42
+ var alive = UK.index(st.spec)
43
+ if (st.selected && !alive[st.selected]) st.selected = null
44
+ }
45
+
46
+ UK.commit = function (op) {
47
+ if (!op) return
48
+ UK.state.ops.push(op)
49
+ UK.rebuild()
50
+ UK.notify()
51
+ }
52
+
53
+ UK.removeOp = function (i) {
54
+ UK.state.ops.splice(i, 1)
55
+ UK.rebuild()
56
+ UK.notify()
57
+ }
58
+
59
+ UK.resetOps = function () {
60
+ UK.state.ops = []
61
+ UK.rebuild()
62
+ UK.notify()
63
+ }
64
+
65
+ UK.select = function (id) {
66
+ UK.state.selected = id || null
67
+ if (UK.revealInTree) UK.revealInTree(UK.state.selected)
68
+ UK.notify()
69
+ }
70
+
71
+ UK.setZoom = function (zoom, anchor) {
72
+ var st = UK.state
73
+ var next = Math.min(4, Math.max(0.1, zoom))
74
+ if (anchor) {
75
+ var world = { x: (anchor.x - st.pan.x) / st.zoom, y: (anchor.y - st.pan.y) / st.zoom }
76
+ st.pan.x = anchor.x - world.x * next
77
+ st.pan.y = anchor.y - world.y * next
78
+ }
79
+ st.zoom = next
80
+ UK.notify()
81
+ }
82
+
83
+ UK.fit = function (host) {
84
+ var st = UK.state
85
+ var screen = st.spec.screen || { w: 1080, h: 1920 }
86
+ var box = host.getBoundingClientRect()
87
+ if (!box.width || !box.height) return
88
+ var z = Math.min(box.width / screen.w, box.height / screen.h) * 0.92
89
+ st.zoom = Math.min(4, Math.max(0.1, z))
90
+ st.pan.x = (box.width - screen.w * st.zoom) / 2
91
+ st.pan.y = (box.height - screen.h * st.zoom) / 2
92
+ UK.notify()
93
+ }
94
+
95
+ UK.dirty = function () { return UK.state.ops.length > 0 }
96
+ })(window.__UIKIT__ = window.__UIKIT__ || {})