dsh-vscode-mode 0.40.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.
- package/README.md +11 -8
- package/package.json +1 -1
- package/skills/dsh-vscodemode-ui-kit/SKILL.md +84 -0
- package/skills/dsh-vscodemode-ui-kit/fixtures/selftest/spec.json +65 -0
- package/skills/dsh-vscodemode-ui-kit/references/detect.md +90 -0
- package/skills/dsh-vscodemode-ui-kit/references/lib.md +48 -0
- package/skills/dsh-vscodemode-ui-kit/references/questions.md +68 -0
- package/skills/dsh-vscodemode-ui-kit/references/spec.md +99 -0
- package/skills/dsh-vscodemode-ui-kit/references/verify.md +37 -0
- package/skills/dsh-vscodemode-ui-kit/runtime/build.mjs +348 -0
- package/skills/dsh-vscodemode-ui-kit/runtime/css/framework.css +398 -0
- package/skills/dsh-vscodemode-ui-kit/runtime/js/01-core.js +182 -0
- package/skills/dsh-vscodemode-ui-kit/runtime/js/02-state.js +96 -0
- package/skills/dsh-vscodemode-ui-kit/runtime/js/03-tree.js +144 -0
- package/skills/dsh-vscodemode-ui-kit/runtime/js/04-canvas.js +194 -0
- package/skills/dsh-vscodemode-ui-kit/runtime/js/05-inspector.js +241 -0
- package/skills/dsh-vscodemode-ui-kit/runtime/js/06-diff.js +52 -0
- package/skills/dsh-vscodemode-ui-kit/runtime/js/07-reply.js +71 -0
- package/skills/dsh-vscodemode-ui-kit/runtime/js/08-main.js +147 -0
- package/skills/dsh-vscodemode-ui-kit/runtime/spec.schema.json +79 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/* 07 · 回传:一句人话 + json 代码块,优先走计划签通道,否则复制 */
|
|
2
|
+
(function (UK) {
|
|
3
|
+
'use strict'
|
|
4
|
+
|
|
5
|
+
UK.buildPatch = function () {
|
|
6
|
+
var st = UK.state
|
|
7
|
+
var patch = { v: 1, page: 'design', base: st.baseHash, ops: UK.clone(st.ops) }
|
|
8
|
+
if (st.note) patch.note = st.note
|
|
9
|
+
return patch
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
UK.replyText = function () {
|
|
13
|
+
var st = UK.state
|
|
14
|
+
var head = st.note || ('设计页改了 ' + st.ops.length + ' 处:' + (st.ops.length ? UK.opLabel(st.ops[0]) : '无'))
|
|
15
|
+
return head + '\n\n```json\n' + JSON.stringify(UK.buildPatch(), null, 2) + '\n```\n'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
UK.copyText = function (text) {
|
|
19
|
+
var done = function (ok) {
|
|
20
|
+
UK.flash(ok ? '已复制,粘进对话就行' : '复制失败:手动选中抽屉里的 patch')
|
|
21
|
+
}
|
|
22
|
+
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
23
|
+
navigator.clipboard.writeText(text).then(function () { done(true) }, function () { legacyCopy(text, done) })
|
|
24
|
+
} else {
|
|
25
|
+
legacyCopy(text, done)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function legacyCopy(text, done) {
|
|
30
|
+
try {
|
|
31
|
+
var area = document.createElement('textarea')
|
|
32
|
+
area.value = text
|
|
33
|
+
area.style.position = 'fixed'
|
|
34
|
+
area.style.left = '-9999px'
|
|
35
|
+
document.body.appendChild(area)
|
|
36
|
+
area.select()
|
|
37
|
+
var ok = document.execCommand('copy')
|
|
38
|
+
area.remove()
|
|
39
|
+
done(ok)
|
|
40
|
+
} catch (e) {
|
|
41
|
+
done(false)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
UK.sendReply = function () {
|
|
46
|
+
var text = UK.replyText()
|
|
47
|
+
var sent = false
|
|
48
|
+
try {
|
|
49
|
+
if (window.parent && window.parent !== window) {
|
|
50
|
+
window.parent.postMessage({ source: 'edrv-htmlplan', type: 'respond', text: text }, '*')
|
|
51
|
+
sent = true
|
|
52
|
+
}
|
|
53
|
+
} catch (e) {
|
|
54
|
+
sent = false
|
|
55
|
+
}
|
|
56
|
+
if (sent) {
|
|
57
|
+
UK.flash('已发送到对话输入框')
|
|
58
|
+
return
|
|
59
|
+
}
|
|
60
|
+
UK.copyText(text)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
UK.flash = function (message) {
|
|
64
|
+
var el = document.getElementById('uk-flash')
|
|
65
|
+
if (!el) return
|
|
66
|
+
el.textContent = message
|
|
67
|
+
el.style.opacity = '1'
|
|
68
|
+
clearTimeout(UK.__flashTimer)
|
|
69
|
+
UK.__flashTimer = setTimeout(function () { el.style.opacity = '0' }, 2600)
|
|
70
|
+
}
|
|
71
|
+
})(window.__UIKIT__ = window.__UIKIT__ || {})
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/* 08 · 外壳与启动:三栏、底栏、键盘 */
|
|
2
|
+
(function (UK) {
|
|
3
|
+
'use strict'
|
|
4
|
+
|
|
5
|
+
var hosts = {}
|
|
6
|
+
var started = false
|
|
7
|
+
|
|
8
|
+
UK.renderAll = function () {
|
|
9
|
+
if (!started) return
|
|
10
|
+
UK.renderTree(hosts.tree)
|
|
11
|
+
UK.renderCanvas(hosts.stage)
|
|
12
|
+
UK.renderInspector(hosts.insp)
|
|
13
|
+
UK.renderDiff(hosts.drawer)
|
|
14
|
+
UK.renderBar()
|
|
15
|
+
UK.renderStatusLine()
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
UK.renderBar = function () {
|
|
19
|
+
var st = UK.state
|
|
20
|
+
if (hosts.zoom) hosts.zoom.textContent = Math.round(st.zoom * 100) + '%'
|
|
21
|
+
if (hosts.opcount) hosts.opcount.textContent = String(st.ops.length)
|
|
22
|
+
if (hosts.opcount) hosts.opcount.parentNode.classList.toggle('ui-dirty', st.ops.length > 0)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
UK.renderStatusLine = function () {
|
|
26
|
+
var st = UK.state
|
|
27
|
+
var node = UK.selectedNode()
|
|
28
|
+
var total = (st.spec.nodes || []).length
|
|
29
|
+
if (!hosts.status) return
|
|
30
|
+
hosts.status.textContent = node
|
|
31
|
+
? '已选 ' + node.id + ' · rect ' + (node.rect || []).join(', ') + ' · 共 ' + total + ' 个节点'
|
|
32
|
+
: '未选中 · 共 ' + total + ' 个节点 · 滚轮缩放,空白拖动平移'
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function buildShell(app) {
|
|
36
|
+
var st = UK.state
|
|
37
|
+
var screen = st.spec.screen || { name: '未命名', w: 1080, h: 1920 }
|
|
38
|
+
app.className = 'ui-app'
|
|
39
|
+
|
|
40
|
+
var zoomChip = UK.el('span', { class: 'ui-chip', text: '100%' })
|
|
41
|
+
var opCount = UK.el('b', { text: '0' })
|
|
42
|
+
hosts.zoom = zoomChip
|
|
43
|
+
hosts.opcount = opCount
|
|
44
|
+
|
|
45
|
+
var bar = UK.el('div', { class: 'ui-bar' }, [
|
|
46
|
+
UK.el('span', { class: 'ui-title', text: screen.name || '未命名' }),
|
|
47
|
+
UK.el('span', { class: 'ui-meta', text: screen.w + '×' + screen.h }),
|
|
48
|
+
UK.el('span', { class: 'ui-chip', text: 'base ' + st.baseHash }),
|
|
49
|
+
UK.el('span', { style: { flex: '1' } }),
|
|
50
|
+
UK.el('button', { class: 'ui-btn ui-ghost', text: '−', title: '缩小', onclick: function () { UK.setZoom(st.zoom / 1.2, null) } }),
|
|
51
|
+
zoomChip,
|
|
52
|
+
UK.el('button', { class: 'ui-btn ui-ghost', text: '+', title: '放大', onclick: function () { UK.setZoom(st.zoom * 1.2, null) } }),
|
|
53
|
+
UK.el('button', { class: 'ui-btn', text: '适应', onclick: function () { UK.fit(hosts.stage) } }),
|
|
54
|
+
UK.el('button', {
|
|
55
|
+
class: 'ui-btn', title: '查看改动与 patch',
|
|
56
|
+
onclick: function () { st.drawer = !st.drawer; UK.renderAll() }
|
|
57
|
+
}, ['改动 ', opCount])
|
|
58
|
+
])
|
|
59
|
+
|
|
60
|
+
var tree = UK.el('aside', { class: 'ui-pane ui-tree', id: 'uk-tree' })
|
|
61
|
+
var stage = UK.el('main', { class: 'ui-stage', id: 'uk-stage' })
|
|
62
|
+
var insp = UK.el('aside', { class: 'ui-pane ui-insp', id: 'uk-insp' })
|
|
63
|
+
hosts.tree = tree
|
|
64
|
+
hosts.stage = stage
|
|
65
|
+
hosts.insp = insp
|
|
66
|
+
|
|
67
|
+
var status = UK.el('span', { class: 'ui-status', text: '' })
|
|
68
|
+
hosts.status = status
|
|
69
|
+
var foot = UK.el('div', { class: 'ui-foot' }, [
|
|
70
|
+
status,
|
|
71
|
+
UK.el('span', { class: 'ui-chip', text: '设计页不落盘,提交回传 patch' }),
|
|
72
|
+
UK.el('button', { class: 'ui-btn', text: '撤销全部', onclick: function () { UK.resetOps() } }),
|
|
73
|
+
UK.el('button', { class: 'ui-btn ui-primary', text: '提交改动', onclick: function () { UK.state.drawer = true; UK.renderAll() } })
|
|
74
|
+
])
|
|
75
|
+
|
|
76
|
+
var drawer = UK.el('div', { class: 'ui-drawer', id: 'uk-drawer', hidden: 'hidden' })
|
|
77
|
+
hosts.drawer = drawer
|
|
78
|
+
|
|
79
|
+
var flash = UK.el('div', {
|
|
80
|
+
id: 'uk-flash',
|
|
81
|
+
style: {
|
|
82
|
+
position: 'fixed', left: '50%', bottom: '56px', transform: 'translateX(-50%)',
|
|
83
|
+
background: '#24211d', color: '#fff', padding: '6px 12px', 'border-radius': '6px',
|
|
84
|
+
font: '12px/1.4 system-ui, sans-serif', opacity: '0', transition: 'opacity .18s',
|
|
85
|
+
'pointer-events': 'none', 'z-index': '80'
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
app.appendChild(bar)
|
|
90
|
+
app.appendChild(UK.el('div', { class: 'ui-body' }, [tree, stage, insp]))
|
|
91
|
+
app.appendChild(foot)
|
|
92
|
+
app.appendChild(drawer)
|
|
93
|
+
app.appendChild(flash)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function bindKeys() {
|
|
97
|
+
window.addEventListener('keydown', function (e) {
|
|
98
|
+
var tag = (e.target && e.target.tagName) || ''
|
|
99
|
+
var typing = tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT'
|
|
100
|
+
if (typing) return
|
|
101
|
+
|
|
102
|
+
var node = UK.selectedNode()
|
|
103
|
+
if (e.key === 'Escape') { UK.closeMenu(); UK.select(null); return }
|
|
104
|
+
if ((e.ctrlKey || e.metaKey) && e.key === 'z') {
|
|
105
|
+
e.preventDefault()
|
|
106
|
+
if (UK.state.ops.length) UK.removeOp(UK.state.ops.length - 1)
|
|
107
|
+
return
|
|
108
|
+
}
|
|
109
|
+
if (!node) return
|
|
110
|
+
|
|
111
|
+
if (e.key === 'Delete' || e.key === 'Backspace') {
|
|
112
|
+
e.preventDefault()
|
|
113
|
+
UK.deleteNode(node.id)
|
|
114
|
+
return
|
|
115
|
+
}
|
|
116
|
+
var step = e.shiftKey ? 10 : 1
|
|
117
|
+
var dx = 0, dy = 0
|
|
118
|
+
if (e.key === 'ArrowLeft') dx = -step
|
|
119
|
+
else if (e.key === 'ArrowRight') dx = step
|
|
120
|
+
else if (e.key === 'ArrowUp') dy = -step
|
|
121
|
+
else if (e.key === 'ArrowDown') dy = step
|
|
122
|
+
else return
|
|
123
|
+
e.preventDefault()
|
|
124
|
+
var rect = (node.rect || [0, 0, 4, 4]).slice()
|
|
125
|
+
rect[0] = rect[0] + dx
|
|
126
|
+
rect[1] = rect[1] + dy
|
|
127
|
+
UK.commit({ op: 'set', id: node.id, field: 'rect', value: rect })
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function boot() {
|
|
132
|
+
var app = document.getElementById('app')
|
|
133
|
+
if (!app) return
|
|
134
|
+
if (!window.__UIKIT__ || !UK.state) return
|
|
135
|
+
buildShell(app)
|
|
136
|
+
started = true
|
|
137
|
+
UK.bindStage(hosts.stage)
|
|
138
|
+
bindKeys()
|
|
139
|
+
UK.renderAll()
|
|
140
|
+
requestAnimationFrame(function () {
|
|
141
|
+
UK.fit(hosts.stage)
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', boot)
|
|
146
|
+
else boot()
|
|
147
|
+
})(window.__UIKIT__ = window.__UIKIT__ || {})
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"title": "ui-kit spec v1",
|
|
4
|
+
"type": "object",
|
|
5
|
+
"required": ["v", "screen", "nodes"],
|
|
6
|
+
"additionalProperties": true,
|
|
7
|
+
"properties": {
|
|
8
|
+
"v": { "const": 1 },
|
|
9
|
+
"page": { "enum": ["design", "library"], "default": "design" },
|
|
10
|
+
"hash": { "type": "string", "pattern": "^[0-9a-f]{8}$" },
|
|
11
|
+
"screen": {
|
|
12
|
+
"type": "object",
|
|
13
|
+
"required": ["w", "h"],
|
|
14
|
+
"properties": {
|
|
15
|
+
"name": { "type": "string" },
|
|
16
|
+
"w": { "type": "number", "exclusiveMinimum": 0 },
|
|
17
|
+
"h": { "type": "number", "exclusiveMinimum": 0 }
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"mock": {
|
|
21
|
+
"type": ["object", "null"],
|
|
22
|
+
"required": ["src"],
|
|
23
|
+
"properties": {
|
|
24
|
+
"src": { "type": "string" },
|
|
25
|
+
"w": { "type": "number" },
|
|
26
|
+
"h": { "type": "number" },
|
|
27
|
+
"scale": { "type": "number", "default": 1 }
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"nodes": {
|
|
31
|
+
"type": "array",
|
|
32
|
+
"items": {
|
|
33
|
+
"type": "object",
|
|
34
|
+
"required": ["id", "kind", "rect"],
|
|
35
|
+
"properties": {
|
|
36
|
+
"id": { "type": "string", "pattern": "^[^/][^\\s]*$" },
|
|
37
|
+
"parent": { "type": ["string", "null"] },
|
|
38
|
+
"kind": { "enum": ["group", "text", "image", "sprite", "button", "list", "prefab"] },
|
|
39
|
+
"rect": {
|
|
40
|
+
"type": "array",
|
|
41
|
+
"minItems": 4,
|
|
42
|
+
"maxItems": 4,
|
|
43
|
+
"items": { "type": "number" }
|
|
44
|
+
},
|
|
45
|
+
"anchor": {
|
|
46
|
+
"type": "object",
|
|
47
|
+
"properties": {
|
|
48
|
+
"min": { "type": "array", "minItems": 2, "maxItems": 2, "items": { "type": "number" } },
|
|
49
|
+
"max": { "type": "array", "minItems": 2, "maxItems": 2, "items": { "type": "number" } },
|
|
50
|
+
"pivot": { "type": "array", "minItems": 2, "maxItems": 2, "items": { "type": "number" } }
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"text": {
|
|
54
|
+
"type": "object",
|
|
55
|
+
"required": ["s"],
|
|
56
|
+
"properties": {
|
|
57
|
+
"s": { "type": "string" },
|
|
58
|
+
"size": { "type": "number" },
|
|
59
|
+
"color": { "type": "string" },
|
|
60
|
+
"align": { "enum": ["left", "center", "right"] }
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"bind": { "type": "string" },
|
|
64
|
+
"ref": { "type": "string", "pattern": "^lib:" },
|
|
65
|
+
"params": { "type": "object" },
|
|
66
|
+
"prefab": { "type": "string" },
|
|
67
|
+
"opaque": { "type": "boolean" },
|
|
68
|
+
"src": { "type": "string" }
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"allOf": [
|
|
74
|
+
{
|
|
75
|
+
"if": { "properties": { "page": { "const": "design" } } },
|
|
76
|
+
"then": { "required": ["nodes"] }
|
|
77
|
+
}
|
|
78
|
+
]
|
|
79
|
+
}
|