@yunkersek/dsh-prtsui 0.0.0-stage → 0.1.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.
@@ -0,0 +1,785 @@
1
+ <!doctype html>
2
+ <html lang="zh-CN">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>@yunkersek/dsh-prtsui harness</title>
6
+ <style>
7
+ :root{color-scheme:dark}
8
+ body{margin:0;padding:24px;background:#0f0f10;color:#f0f0f0;font:14px/1.6 -apple-system,"Segoe UI","Microsoft YaHei",sans-serif;--dsw-alias-bg-layer-1:#1a1b1c;--dsw-alias-bg-layer-2:#232425;--dsw-alias-border-l1:#262729;--dsw-alias-border-l2:#2f3133;--dsw-alias-label-primary:#f0f0f0;--dsw-alias-label-secondary:#c9c9c9;--dsw-alias-brand-primary:#18d1ff;--dsw-alias-state-success-primary:#4fd18f;--dsw-alias-state-warn-primary:#ffb340;--dsw-alias-state-error-primary:#ff5c5c;--dsw-alias-state-idle-primary:#5ddcff;--dsw-alias-label-on-color:#04161c}
9
+ h1{font-size:13px;letter-spacing:.16em;text-transform:uppercase;color:#8d8d8d;font-weight:600;margin:0 0 14px}
10
+ pre{background:#141516;padding:10px;border:1px solid #262729;overflow:auto;font-size:11px}
11
+ .col{max-width:760px;display:flex;flex-direction:column;gap:8px}
12
+ </style>
13
+ </head>
14
+ <body>
15
+ <h1>@yunkersek/dsh-prtsui harness</h1>
16
+ <div class="col" id="col"></div>
17
+
18
+ <script>
19
+ window.__errors = []
20
+ window.addEventListener('error', function (e) { window.__errors.push(String(e.message) + ' @ ' + (e.filename || '') + ':' + (e.lineno || 0)) })
21
+ window.__ModuleLoader__ = {
22
+ load(def) {
23
+ try {
24
+ const mod = def.factory((name) => ({}))
25
+ window.__prtsui = mod
26
+ mod.apply({ effect: (fn) => fn() })
27
+ window.__status = 'applied'
28
+ } catch (e) {
29
+ window.__status = 'ERROR ' + (e && (e.stack || e.message))
30
+ }
31
+ },
32
+ }
33
+ </script>
34
+
35
+ <script>
36
+ const SAMPLE = {
37
+ title: "PRTS 内联 UI 自检",
38
+ gap: 10,
39
+ items: [
40
+ { type: "hero", eyebrow: "@yunkersek/dsh-prtsui 0.1.0", title: "围栏 → 卡片", subtitle: "方形直角 · 青色刻度 · 发丝描边" },
41
+ { type: "stats", items: [
42
+ { label: "节点类型", value: 22, hint: "纯 DOM" },
43
+ { label: "外部资产", value: "0 B", hint: "无 CDN", delta: "-8MB" },
44
+ { label: "首屏依赖", value: "host", hint: "宿主 token", delta: "0" },
45
+ ] },
46
+ { type: "callout", tone: "warning", title: "边界", content: "panel:true 与工具行渲染尚未实现,保持内联。" },
47
+ { type: "table", columns: ["能力", "dsh-genui", "@yunkersek/dsh-prtsui"], rows: [
48
+ ["围栏渲染", "React 树", "纯 DOM"],
49
+ ["组件词表", "~40", "22"],
50
+ ["外部资产", "8 MB", "0 B"],
51
+ ], align: ["left", "left", "right"], caption: "对照" },
52
+ { type: "steps", current: 1, steps: [
53
+ { title: "识别围栏", content: "JSON + type 白名单" },
54
+ { title: "挂载组件", content: "MutationObserver 去抖 80ms" },
55
+ { title: "交互回传", content: "[prtsui-action]" },
56
+ ] },
57
+ { type: "chart", kind: "bars", unit: "ms", data: [{ label: "识别", value: 4 }, { label: "解析", value: 7 }, { label: "挂载", value: 12 }] },
58
+ { type: "progress", label: "实施进度", value: 0.62, segments: [{ tone: "ok", value: 40 }, { tone: "brand", value: 22 }, { tone: "pending", value: 38 }] },
59
+ { type: "choices", action: "pick-mode", options: [
60
+ { label: "保持内联", description: "推荐:围栏即卡片" },
61
+ { label: "切回 genui", description: "复杂交互时再启用" },
62
+ ] },
63
+ { type: "list", items: ["tabs / accordion 本地展开", { text: "choices 点击回传", badge: "action", tone: "brand" }] },
64
+ ],
65
+ }
66
+ const pre = document.createElement("pre")
67
+ const code = document.createElement("code")
68
+ code.className = "language-dsh-ui"
69
+ code.textContent = JSON.stringify(SAMPLE)
70
+ pre.append(code)
71
+ document.getElementById("col").prepend(pre)
72
+ </script>
73
+ <script>
74
+ /**
75
+ * @yunkersek/dsh-prtsui — client half (web).
76
+ *
77
+ * Finds ```dsh-ui fenced JSON in the rendered transcript and mounts it as a
78
+ * PRTS-styled DOM tree (prts-design visual language: terminal surfaces, cyan
79
+ * rails, square corners, hairline strokes, uppercase overline labels).
80
+ *
81
+ * Pure DOM on purpose: no react-dom, no runtime assets, no CDN.
82
+ */
83
+ window.__ModuleLoader__.load({
84
+ id: '@yunkersek/dsh-prtsui',
85
+ factory(require) {
86
+ const TYPES = new Set([
87
+ 'text', 'hero', 'callout', 'list', 'table', 'stat', 'stats', 'keyvalue',
88
+ 'steps', 'choices', 'tabs', 'card', 'chart', 'code', 'divider', 'kbd',
89
+ 'badge', 'progress', 'quote', 'compare', 'image', 'accordion',
90
+ ])
91
+
92
+ const CSS = `
93
+ .prtsui{--p-bg:var(--dsw-alias-bg-layer-1,#1a1b1c);--p-bg2:var(--dsw-alias-bg-layer-2,#232425);--p-line:var(--dsw-alias-border-l2,#2f3133);--p-soft:var(--dsw-alias-border-l1,#262729);--p-fg:var(--dsw-alias-label-primary,#f0f0f0);--p-fg2:var(--dsw-alias-label-secondary,#c9c9c9);--p-acc:var(--dsw-alias-brand-primary,#18d1ff);--p-acc2:var(--dsw-alias-state-warn-primary,#ffb340);--p-ok:var(--dsw-alias-state-success-primary,#4fd18f);--p-warn:var(--dsw-alias-state-warn-primary,#ffb340);--p-err:var(--dsw-alias-state-error-primary,#ff5c5c);--p-on:var(--dsw-alias-label-on-color,#04161c);--p-mono:ui-monospace,SFMono-Regular,Consolas,monospace;position:relative;margin:10px 0;border:1px solid var(--p-line);background:var(--p-bg);color:var(--p-fg);font-size:13px;line-height:1.66;border-radius:2px;overflow:hidden}
94
+ .prtsui::before{content:'';position:absolute;left:0;top:0;width:38px;height:2px;background:var(--p-acc);z-index:2}
95
+ .prtsui-banner{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:7px 12px;border-bottom:1px solid var(--p-soft);background:linear-gradient(180deg,color-mix(in srgb,var(--p-acc) 8%,transparent),transparent)}
96
+ .prtsui-banner span{font-size:10px;letter-spacing:.16em;text-transform:uppercase;color:var(--p-fg2)}
97
+ .prtsui-banner i{font:600 10px/1 var(--p-mono);font-style:normal;letter-spacing:.1em;color:var(--p-acc)}
98
+ .prtsui-body{display:flex;flex-direction:column;gap:var(--prtsui-gap,10px);padding:12px}
99
+ .prtsui p{margin:0}
100
+ .prtsui-eyebrow{font-size:10px;letter-spacing:.16em;text-transform:uppercase;color:color-mix(in srgb,var(--p-fg2) 72%,transparent)}
101
+ .prtsui-hero{display:flex;flex-direction:column;gap:4px;padding-bottom:10px;border-bottom:1px solid var(--p-soft)}
102
+ .prtsui-hero h3{margin:0;font-size:20px;line-height:1.24;font-weight:700;letter-spacing:.02em}
103
+ .prtsui-hero small{color:var(--p-fg2);font-size:12px}
104
+ .prtsui-callout{position:relative;padding:9px 12px 9px 14px;background:var(--p-bg2);border-left:3px solid var(--p-info)}
105
+ .prtsui-callout[data-tone=success]{border-left-color:var(--p-ok)}
106
+ .prtsui-callout[data-tone=warning]{border-left-color:var(--p-warn)}
107
+ .prtsui-callout[data-tone=error]{border-left-color:var(--p-err)}
108
+ .prtsui-callout[data-tone=brand]{border-left-color:var(--p-acc)}
109
+ .prtsui-callout b{display:block;margin-bottom:2px;font-size:11px;letter-spacing:.12em;text-transform:uppercase;color:var(--p-fg2);font-weight:600}
110
+ .prtsui-list{margin:0;padding:0;list-style:none;display:flex;flex-direction:column}
111
+ .prtsui-list li{display:flex;gap:9px;padding:4px 0;border-bottom:1px solid var(--p-soft)}
112
+ .prtsui-list li:last-child{border-bottom:0}
113
+ .prtsui-list .idx{flex:none;min-width:18px;font:600 10px/1.9 var(--p-mono);color:color-mix(in srgb,var(--p-acc) 82%,transparent);letter-spacing:.06em}
114
+ .prtsui-list .txt{flex:1}
115
+ .prtsui-list .badge{flex:none}
116
+ .prtsui table{width:100%;border-collapse:collapse;font-size:12px}
117
+ .prtsui caption{caption-side:top;text-align:left;padding-bottom:5px;font-size:10px;letter-spacing:.14em;text-transform:uppercase;color:color-mix(in srgb,var(--p-fg2) 70%,transparent)}
118
+ .prtsui th{text-align:left;font:600 10px/1.6 var(--p-mono);letter-spacing:.12em;text-transform:uppercase;color:var(--p-fg2);padding:0 10px 6px;border-bottom:1px solid var(--p-line);white-space:nowrap}
119
+ .prtsui td{padding:6px 10px;border-bottom:1px solid var(--p-soft);vertical-align:top}
120
+ .prtsui tr:last-child td{border-bottom:0}
121
+ .prtsui td[data-align=right],.prtsui th[data-align=right]{text-align:right;font-variant-numeric:tabular-nums}
122
+ .prtsui td[data-align=center],.prtsui th[data-align=center]{text-align:center}
123
+ .prtsui-stats{display:grid;grid-template-columns:repeat(auto-fit,minmax(120px,1fr));gap:1px;background:var(--p-soft)}
124
+ .prtsui-stat{background:var(--p-bg);padding:9px 11px;display:flex;flex-direction:column;gap:2px}
125
+ .prtsui-stat span{font-size:10px;letter-spacing:.12em;text-transform:uppercase;color:color-mix(in srgb,var(--p-fg2) 76%,transparent)}
126
+ .prtsui-stat strong{font:700 18px/1.2 var(--p-mono);font-variant-numeric:tabular-nums;letter-spacing:.01em}
127
+ .prtsui-stat em{font-style:normal;font-size:11px;color:var(--p-fg2)}
128
+ .prtsui-stat i{font-style:normal;font:600 10px/1 var(--p-mono);letter-spacing:.06em;color:var(--p-ok)}
129
+ .prtsui-stat i[data-neg=true]{color:var(--p-err)}
130
+ .prtsui-kv{display:grid;grid-template-columns:auto 1fr;gap:1px;background:var(--p-soft);border:1px solid var(--p-soft)}
131
+ .prtsui-kv>div{background:var(--p-bg);padding:6px 10px;font-size:12px}
132
+ .prtsui-kv>div:nth-child(odd){color:var(--p-fg2);white-space:nowrap;font-size:11px;letter-spacing:.04em}
133
+ .prtsui-steps{display:flex;flex-direction:column;gap:0}
134
+ .prtsui-step{position:relative;display:flex;gap:10px;padding:0 0 12px 0}
135
+ .prtsui-step:last-child{padding-bottom:0}
136
+ .prtsui-step .dot{flex:none;width:9px;height:9px;margin-top:5px;border:1px solid var(--p-line);background:var(--p-bg);transform:rotate(45deg)}
137
+ .prtsui-step[data-state=done] .dot{border-color:var(--p-ok);background:var(--p-ok)}
138
+ .prtsui-step[data-state=active] .dot{border-color:var(--p-acc);background:color-mix(in srgb,var(--p-acc) 26%,transparent);box-shadow:0 0 0 3px color-mix(in srgb,var(--p-acc) 16%,transparent)}
139
+ .prtsui-step .rail{position:absolute;left:4px;top:16px;bottom:0;width:1px;background:var(--p-soft)}
140
+ .prtsui-step:last-child .rail{display:none}
141
+ .prtsui-step h4{margin:0;font-size:13px;font-weight:600}
142
+ .prtsui-step[data-state=active] h4{color:var(--p-acc)}
143
+ .prtsui-step[data-state=todo] h4{color:var(--p-fg2);font-weight:500}
144
+ .prtsui-step p{margin:2px 0 0;font-size:12px;color:var(--p-fg2)}
145
+ .prtsui-choices{display:flex;flex-direction:column;gap:6px}
146
+ .prtsui-choice{display:flex;align-items:flex-start;gap:9px;width:100%;text-align:left;padding:8px 11px;border:1px solid var(--p-line);border-left:2px solid transparent;background:var(--p-bg2);color:var(--p-fg);font:inherit;font-size:12px;cursor:pointer;border-radius:0;transition:border-color .12s,background .12s}
147
+ .prtsui-choice:hover{border-left-color:var(--p-acc);background:color-mix(in srgb,var(--p-acc) 12%,transparent)}
148
+ .prtsui-choice[data-picked=true]{border-left-color:var(--p-acc);color:var(--p-acc);background:color-mix(in srgb,var(--p-acc) 10%,transparent)}
149
+ .prtsui-choice .mark{flex:none;font:600 10px/1.7 var(--p-mono);color:color-mix(in srgb,var(--p-acc) 84%,transparent)}
150
+ .prtsui-choice small{display:block;color:var(--p-fg2);font-size:11px;margin-top:2px}
151
+ .prtsui-tabs{display:flex;flex-direction:column;gap:10px}
152
+ .prtsui-tabbar{display:flex;gap:2px;border-bottom:1px solid var(--p-soft)}
153
+ .prtsui-tab{appearance:none;border:0;background:none;color:var(--p-fg2);font:inherit;font-size:12px;padding:6px 12px 7px;cursor:pointer;border-bottom:2px solid transparent;margin-bottom:-1px}
154
+ .prtsui-tab:hover{color:var(--p-fg)}
155
+ .prtsui-tab[data-on=true]{color:var(--p-acc);border-bottom-color:var(--p-acc);font-weight:600}
156
+ .prtsui-panel{display:flex;flex-direction:column;gap:10px}
157
+ .prtsui-panel[hidden]{display:none}
158
+ .prtsui-card{border:1px solid var(--p-line);background:var(--p-bg2)}
159
+ .prtsui-card>.head{display:flex;align-items:baseline;gap:8px;padding:7px 11px;border-bottom:1px solid var(--p-soft);flex-wrap:wrap}
160
+ .prtsui-card>.head b{font-size:11px;letter-spacing:.12em;text-transform:uppercase;font-weight:600;color:var(--p-fg2)}
161
+ .prtsui-card>.head strong{font-size:13px;font-weight:600}
162
+ .prtsui-card>.body{padding:10px 11px;display:flex;flex-direction:column;gap:10px}
163
+ .prtsui-chart{display:flex;flex-direction:column;gap:6px}
164
+ .prtsui-chart svg{width:100%;display:block;overflow:visible}
165
+ .prtsui-bars{display:flex;flex-direction:column;gap:5px}
166
+ .prtsui-bar{display:grid;grid-template-columns:minmax(58px,auto) 1fr auto;gap:9px;align-items:center;font-size:11px}
167
+ .prtsui-bar span{color:var(--p-fg2);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
168
+ .prtsui-bar .track{height:8px;background:var(--p-bg2);border:1px solid var(--p-soft);position:relative}
169
+ .prtsui-bar .fill{height:100%;background:var(--p-acc)}
170
+ .prtsui-bar em{font:600 11px/1 var(--p-mono);font-style:normal;font-variant-numeric:tabular-nums;color:var(--p-fg2)}
171
+ .prtsui-legend{display:flex;flex-wrap:wrap;gap:10px;font-size:11px;color:var(--p-fg2)}
172
+ .prtsui-legend i{display:inline-block;width:8px;height:8px;margin-right:5px;vertical-align:middle}
173
+ .prtsui pre.code{margin:0;padding:10px 12px;background:var(--p-bg2);border:1px solid var(--p-soft);overflow:auto;font:12px/1.6 var(--p-mono);color:var(--p-fg)}
174
+ .prtsui-divider{display:flex;align-items:center;gap:10px;color:color-mix(in srgb,var(--p-fg2) 74%,transparent);font-size:10px;letter-spacing:.16em;text-transform:uppercase}
175
+ .prtsui-divider::before,.prtsui-divider::after{content:'';flex:1;height:1px;background:var(--p-soft)}
176
+ .prtsui-kbd{display:inline-flex;gap:4px}
177
+ .prtsui-kbd kbd{font:600 10px/1 var(--p-mono);padding:3px 5px;border:1px solid var(--p-line);border-bottom-width:2px;background:var(--p-bg2);color:var(--p-fg2);border-radius:2px}
178
+ .prtsui-badge{display:inline-flex;align-items:center;padding:1px 6px;border:1px solid var(--p-line);font:600 10px/1.6 var(--p-mono);letter-spacing:.06em;text-transform:uppercase;color:var(--p-fg2);border-radius:0}
179
+ .prtsui-badge[data-tone=brand]{border-color:color-mix(in srgb,var(--p-acc) 54%,transparent);color:var(--p-acc)}
180
+ .prtsui-badge[data-tone=success]{border-color:color-mix(in srgb,var(--p-ok) 54%,transparent);color:var(--p-ok)}
181
+ .prtsui-badge[data-tone=warning]{border-color:color-mix(in srgb,var(--p-warn) 54%,transparent);color:var(--p-warn)}
182
+ .prtsui-badge[data-tone=error]{border-color:color-mix(in srgb,var(--p-err) 54%,transparent);color:var(--p-err)}
183
+ .prtsui-progress{display:flex;flex-direction:column;gap:4px}
184
+ .prtsui-progress .lbl{display:flex;justify-content:space-between;font-size:10px;letter-spacing:.12em;text-transform:uppercase;color:var(--p-fg2)}
185
+ .prtsui-progress .lbl b{font-family:var(--p-mono);letter-spacing:.06em;font-variant-numeric:tabular-nums}
186
+ .prtsui-progress .track{height:8px;background:var(--p-bg2);border:1px solid var(--p-soft);display:flex}
187
+ .prtsui-progress .seg{height:100%}
188
+ .prtsui-progress .seg[data-tone=ok]{background:var(--p-ok)}
189
+ .prtsui-progress .seg[data-tone=brand]{background:var(--p-acc)}
190
+ .prtsui-progress .seg[data-tone=warn]{background:var(--p-warn)}
191
+ .prtsui-progress .seg[data-tone=err]{background:var(--p-err)}
192
+ .prtsui-progress .seg[data-tone=pending]{background:repeating-linear-gradient(-45deg,transparent 0 4px,color-mix(in srgb,var(--p-fg2) 22%,transparent) 4px 8px)}
193
+ .prtsui-quote{margin:0;padding:6px 0 6px 12px;border-left:2px solid var(--p-line);color:var(--p-fg2);font-style:italic}
194
+ .prtsui-quote cite{display:block;margin-top:4px;font-style:normal;font-size:11px;letter-spacing:.06em}
195
+ .prtsui-compare{display:grid;grid-template-columns:1fr 1fr;gap:1px;background:var(--p-soft)}
196
+ .prtsui-compare>div{background:var(--p-bg2);padding:9px 11px;display:flex;flex-direction:column;gap:6px}
197
+ .prtsui-compare b{font-size:10px;letter-spacing:.14em;text-transform:uppercase;color:var(--p-fg2)}
198
+ .prtsui-compare>div:last-child b{color:var(--p-acc)}
199
+ .prtsui figure{margin:0;display:flex;flex-direction:column;gap:5px}
200
+ .prtsui figure img{width:100%;display:block;border:1px solid var(--p-soft)}
201
+ .prtsui figcaption{font-size:11px;color:var(--p-fg2)}
202
+ .prtsui-acc{display:flex;flex-direction:column}
203
+ .prtsui-acc details{border-bottom:1px solid var(--p-soft);padding:6px 0}
204
+ .prtsui-acc summary{cursor:pointer;font-size:12px;font-weight:600;list-style:none;display:flex;gap:8px;align-items:center}
205
+ .prtsui-acc summary::before{content:'+';font:600 11px/1 var(--p-mono);color:var(--p-acc)}
206
+ .prtsui-acc details[open] summary::before{content:'−'}
207
+ .prtsui-acc .inner{padding:8px 0 4px 18px;display:flex;flex-direction:column;gap:10px}
208
+ .prtsui-raw-note{font-size:10px;letter-spacing:.1em;text-transform:uppercase;color:color-mix(in srgb,var(--p-fg2) 60%,transparent)}
209
+ @media (max-width:640px){.prtsui-compare{grid-template-columns:1fr}}
210
+ `
211
+
212
+ // ---------------- helpers ----------------
213
+ function h(tag, cls, text) {
214
+ const el = document.createElement(tag)
215
+ if (cls) el.className = cls
216
+ if (text !== undefined && text !== null) el.textContent = String(text)
217
+ return el
218
+ }
219
+ const s = (v) => (v === undefined || v === null ? '' : String(v))
220
+ const arr = (v) => (Array.isArray(v) ? v : [])
221
+
222
+ function tone(node) {
223
+ const t = s(node.tone).toLowerCase()
224
+ return ['info', 'success', 'warning', 'error', 'brand'].includes(t) ? t : 'info'
225
+ }
226
+
227
+ // ---------------- node renderers ----------------
228
+ const R = {}
229
+
230
+ R.text = (n) => h('p', null, s(n.content ?? n.text))
231
+
232
+ R.hero = (n) => {
233
+ const box = h('div', 'prtsui-hero')
234
+ if (n.eyebrow) box.append(h('div', 'prtsui-eyebrow', n.eyebrow))
235
+ if (n.title) box.append(h('h3', null, n.title))
236
+ if (n.subtitle) box.append(h('small', null, n.subtitle))
237
+ if (n.content) box.append(h('p', null, n.content))
238
+ return box
239
+ }
240
+
241
+ R.callout = (n) => {
242
+ const box = h('div', 'prtsui-callout')
243
+ box.dataset.tone = tone(n)
244
+ if (n.title) box.append(h('b', null, n.title))
245
+ box.append(h('div', null, s(n.content)))
246
+ return box
247
+ }
248
+
249
+ R.list = (n) => {
250
+ const ol = h(n.ordered ? 'ol' : 'ul', 'prtsui-list')
251
+ arr(n.items).forEach((it, i) => {
252
+ const li = h('li')
253
+ li.append(h('span', 'idx', n.ordered ? String(i + 1).padStart(2, '0') : '·'))
254
+ const obj = it && typeof it === 'object' ? it : { text: it }
255
+ const txt = h('span', 'txt', s(obj.text ?? obj.content ?? obj.label))
256
+ li.append(txt)
257
+ if (obj.badge) {
258
+ const b = h('span', 'prtsui-badge', obj.badge)
259
+ if (obj.tone) b.dataset.tone = s(obj.tone).toLowerCase()
260
+ li.append(b)
261
+ }
262
+ ol.append(li)
263
+ })
264
+ return ol
265
+ }
266
+
267
+ R.table = (n) => {
268
+ const table = h('table')
269
+ if (n.caption) table.append(h('caption', null, n.caption))
270
+ const align = arr(n.align)
271
+ const thead = h('thead')
272
+ const hr = h('tr')
273
+ arr(n.columns).forEach((c, i) => {
274
+ const th = h('th', null, c)
275
+ if (align[i]) th.dataset.align = s(align[i])
276
+ hr.append(th)
277
+ })
278
+ thead.append(hr)
279
+ table.append(thead)
280
+ const tbody = h('tbody')
281
+ arr(n.rows).forEach((row) => {
282
+ const tr = h('tr')
283
+ arr(row).forEach((cell, i) => {
284
+ const td = h('td', null, s(cell))
285
+ if (align[i]) td.dataset.align = s(align[i])
286
+ tr.append(td)
287
+ })
288
+ tbody.append(tr)
289
+ })
290
+ table.append(tbody)
291
+ return table
292
+ }
293
+
294
+ function statCard(n) {
295
+ const box = h('div', 'prtsui-stat')
296
+ box.append(h('span', null, s(n.label)))
297
+ box.append(h('strong', null, s(n.value)))
298
+ if (n.hint) box.append(h('em', null, s(n.hint)))
299
+ if (n.delta !== undefined && n.delta !== null) {
300
+ const d = h('i', null, s(n.delta))
301
+ d.dataset.neg = String(n.delta).trim().startsWith('-') ? 'true' : 'false'
302
+ box.append(d)
303
+ }
304
+ return box
305
+ }
306
+
307
+ R.stat = (n) => {
308
+ const wrap = h('div', 'prtsui-stats')
309
+ wrap.append(statCard(n))
310
+ return wrap
311
+ }
312
+
313
+ R.stats = (n) => {
314
+ const wrap = h('div', 'prtsui-stats')
315
+ arr(n.items).forEach((it) => wrap.append(statCard(it || {})))
316
+ return wrap
317
+ }
318
+
319
+ R.keyvalue = (n) => {
320
+ const grid = h('div', 'prtsui-kv')
321
+ arr(n.pairs).forEach((p) => {
322
+ grid.append(h('div', null, s(p.key ?? p.k)))
323
+ grid.append(h('div', null, s(p.value ?? p.v)))
324
+ })
325
+ return grid
326
+ }
327
+
328
+ R.steps = (n) => {
329
+ const wrap = h('div', 'prtsui-steps')
330
+ const current = typeof n.current === 'number' ? n.current : -1
331
+ arr(n.steps).forEach((st, i) => {
332
+ const obj = st && typeof st === 'object' ? st : { title: st }
333
+ const state = s(obj.state) || (current >= 0 ? (i < current ? 'done' : i === current ? 'active' : 'todo') : 'todo')
334
+ const row = h('div', 'prtsui-step')
335
+ row.dataset.state = ['done', 'active', 'todo'].includes(state) ? state : 'todo'
336
+ row.append(h('span', 'dot'))
337
+ row.append(h('span', 'rail'))
338
+ const body = h('div')
339
+ body.append(h('h4', null, s(obj.title)))
340
+ if (obj.content) body.append(h('p', null, s(obj.content)))
341
+ row.append(body)
342
+ wrap.append(row)
343
+ })
344
+ return wrap
345
+ }
346
+
347
+ function dispatch(ctx, action, payload) {
348
+ const text = '[prtsui-action] ' + action + ' ' + JSON.stringify(payload || {})
349
+ try {
350
+ const sessions = ctx && ctx.sessions
351
+ if (!sessions) return
352
+ const ids = (sessions.list && sessions.list.getSnapshot && sessions.list.getSnapshot().ids) || []
353
+ let target = null
354
+ for (const id of ids) {
355
+ try {
356
+ const info = sessions.retainInfo && sessions.retainInfo(id)
357
+ const snap = info && info.getSnapshot && info.getSnapshot()
358
+ if (snap && snap.retainedBy && snap.retainedBy.mainView > 0) { target = id; break }
359
+ } catch { /* ignore */ }
360
+ }
361
+ if (!target) return
362
+ const conv = sessions.scope(target).get('conversation')
363
+ if (conv && typeof conv.send === 'function') conv.send(text)
364
+ } catch (err) {
365
+ console.warn('[prtsui] action failed', err)
366
+ }
367
+ }
368
+
369
+ R.choices = (n, ctx) => {
370
+ const wrap = h('div', 'prtsui-choices')
371
+ const action = n.action ? s(n.action) : ''
372
+ arr(n.options).forEach((opt, i) => {
373
+ const obj = opt && typeof opt === 'object' ? opt : { label: opt }
374
+ const btn = h('button', 'prtsui-choice')
375
+ btn.type = 'button'
376
+ btn.append(h('span', 'mark', action ? '›' : String(i + 1).padStart(2, '0')))
377
+ const body = h('span')
378
+ body.append(h('span', null, s(obj.label)))
379
+ if (obj.description) body.append(h('small', null, s(obj.description)))
380
+ btn.append(body)
381
+ btn.addEventListener('click', () => {
382
+ wrap.querySelectorAll('.prtsui-choice').forEach((el) => { el.dataset.picked = 'false' })
383
+ btn.dataset.picked = 'true'
384
+ if (action) dispatch(ctx, action, { value: obj.value ?? obj.label ?? i, label: obj.label ?? null })
385
+ })
386
+ wrap.append(btn)
387
+ })
388
+ return wrap
389
+ }
390
+
391
+ R.tabs = (n, ctx) => {
392
+ const wrap = h('div', 'prtsui-tabs')
393
+ const bar = h('div', 'prtsui-tabbar')
394
+ const panes = h('div', 'prtsui-panel')
395
+ const panels = []
396
+ arr(n.tabs).forEach((tab, i) => {
397
+ const obj = tab && typeof tab === 'object' ? tab : { label: tab, items: [] }
398
+ const btn = h('button', 'prtsui-tab', s(obj.label))
399
+ btn.type = 'button'
400
+ btn.dataset.on = i === 0 ? 'true' : 'false'
401
+ const pane = h('div', 'prtsui-panel')
402
+ pane.hidden = i !== 0
403
+ arr(obj.items).forEach((child) => {
404
+ const el = renderNode(child, ctx)
405
+ if (el) pane.append(el)
406
+ })
407
+ panels.push({ btn, pane })
408
+ btn.addEventListener('click', () => {
409
+ panels.forEach((p, j) => {
410
+ p.btn.dataset.on = j === i ? 'true' : 'false'
411
+ p.pane.hidden = j !== i
412
+ })
413
+ })
414
+ bar.append(btn)
415
+ })
416
+ wrap.append(bar)
417
+ panels.forEach((p) => wrap.append(p.pane))
418
+ void panes
419
+ return wrap
420
+ }
421
+
422
+ R.card = (n, ctx) => {
423
+ const card = h('div', 'prtsui-card')
424
+ const head = h('div', 'head')
425
+ if (n.eyebrow) head.append(h('b', null, n.eyebrow))
426
+ if (n.title) head.append(h('strong', null, n.title))
427
+ if (head.childNodes.length) card.append(head)
428
+ const body = h('div', 'body')
429
+ arr(n.items).forEach((child) => {
430
+ const el = renderNode(child, ctx)
431
+ if (el) body.append(el)
432
+ })
433
+ card.append(body)
434
+ return card
435
+ }
436
+
437
+ R.chart = (n) => {
438
+ const kind = s(n.kind || 'bars').toLowerCase()
439
+ const data = arr(n.data).map((d) => ({ label: s(d && d.label), value: Number(d && d.value) || 0 }))
440
+ const wrap = h('div', 'prtsui-chart')
441
+ const H = Number(n.height) || 0
442
+ if (kind === 'donut') {
443
+ const total = data.reduce((a, b) => a + b.value, 0) || 1
444
+ const NS = 'http://www.w3.org/2000/svg'
445
+ const svg = document.createElementNS(NS, 'svg')
446
+ svg.setAttribute('viewBox', '0 0 120 120')
447
+ svg.setAttribute('height', String(H || 132))
448
+ const colors = ['var(--p-acc)', 'var(--p-ok)', 'var(--p-warn)', 'var(--p-err)', 'var(--p-info, #5ddcff)', 'color-mix(in srgb,var(--p-fg2) 48%,transparent)']
449
+ let offset = 0
450
+ const toRad = (deg) => (deg - 90) * Math.PI / 180
451
+ data.forEach((d, i) => {
452
+ const frac = d.value / total
453
+ const a0 = offset, a1 = offset + frac * Math.PI * 2
454
+ offset = a1
455
+ const r0 = 34, r1 = 50
456
+ const p = (r, a) => `${(60 + r * Math.cos(a)).toFixed(2)} ${(60 + r * Math.sin(a)).toFixed(2)}`
457
+ if (frac <= 0) return
458
+ const path = document.createElementNS(NS, 'path')
459
+ path.setAttribute('d', `M ${p(r1, toRad(((a0 * 180) / Math.PI)))} A ${r1} ${r1} 0 ${frac > 0.5 ? 1 : 0} 1 ${p(r1, toRad(((a1 * 180) / Math.PI)))} L ${p(r0, toRad(((a1 * 180) / Math.PI)))} A ${r0} ${r0} 0 ${frac > 0.5 ? 1 : 0} 0 ${p(r0, toRad(((a0 * 180) / Math.PI)))} Z`)
460
+ path.setAttribute('fill', colors[i % colors.length])
461
+ path.setAttribute('stroke', 'var(--p-bg)')
462
+ path.setAttribute('stroke-width', '1.5')
463
+ svg.append(path)
464
+ })
465
+ wrap.append(svg)
466
+ const legend = h('div', 'prtsui-legend')
467
+ data.forEach((d, i) => {
468
+ const item = h('span')
469
+ const chip = h('i')
470
+ chip.style.background = colors[i % colors.length]
471
+ item.append(chip, document.createTextNode(`${d.label} ${((d.value / total) * 100).toFixed(1)}%`))
472
+ legend.append(item)
473
+ })
474
+ wrap.append(legend)
475
+ return wrap
476
+ }
477
+ if (kind === 'line') {
478
+ const NS = 'http://www.w3.org/2000/svg'
479
+ const W = 320
480
+ const HH = H || 120
481
+ const max = Math.max(1, ...data.map((d) => d.value))
482
+ const step = data.length > 1 ? W / (data.length - 1) : W
483
+ const pts = data.map((d, i) => `${(i * step).toFixed(2)},${(HH - (d.value / max) * (HH - 12) - 4).toFixed(2)}`)
484
+ const svg = document.createElementNS(NS, 'svg')
485
+ svg.setAttribute('viewBox', `0 0 ${W} ${HH}`)
486
+ svg.setAttribute('height', String(HH))
487
+ const grid = document.createElementNS(NS, 'line')
488
+ grid.setAttribute('x1', '0'); grid.setAttribute('x2', String(W))
489
+ grid.setAttribute('y1', String(HH - 4)); grid.setAttribute('y2', String(HH - 4))
490
+ grid.setAttribute('stroke', 'var(--p-soft)'); grid.setAttribute('stroke-width', '1')
491
+ svg.append(grid)
492
+ const poly = document.createElementNS(NS, 'polyline')
493
+ poly.setAttribute('points', pts.join(' '))
494
+ poly.setAttribute('fill', 'none')
495
+ poly.setAttribute('stroke', 'var(--p-acc)')
496
+ poly.setAttribute('stroke-width', '1.5')
497
+ svg.append(poly)
498
+ data.forEach((d, i) => {
499
+ const c = document.createElementNS(NS, 'circle')
500
+ c.setAttribute('cx', String(i * step)); c.setAttribute('cy', String(HH - (d.value / max) * (HH - 12) - 4))
501
+ c.setAttribute('r', '2.2'); c.setAttribute('fill', 'var(--p-acc)')
502
+ svg.append(c)
503
+ })
504
+ wrap.append(svg)
505
+ const legend = h('div', 'prtsui-legend')
506
+ legend.append(document.createTextNode(`${data[0] ? data[0].label : ''} → ${data[data.length - 1] ? data[data.length - 1].label : ''}${n.unit ? ' · ' + n.unit : ''}`))
507
+ wrap.append(legend)
508
+ return wrap
509
+ }
510
+ const max = Math.max(1, ...data.map((d) => d.value))
511
+ const bars = h('div', 'prtsui-bars')
512
+ data.forEach((d) => {
513
+ const row = h('div', 'prtsui-bar')
514
+ row.append(h('span', null, d.label))
515
+ const track = h('div', 'track')
516
+ const fill = h('div', 'fill')
517
+ fill.style.width = `${Math.max(1.5, (d.value / max) * 100).toFixed(2)}%`
518
+ track.append(fill)
519
+ row.append(track)
520
+ row.append(h('em', null, `${d.value}${n.unit ? ' ' + n.unit : ''}`))
521
+ bars.append(row)
522
+ })
523
+ wrap.append(bars)
524
+ return wrap
525
+ }
526
+
527
+ R.code = (n) => {
528
+ const pre = h('pre', 'code', s(n.content ?? n.code))
529
+ return pre
530
+ }
531
+
532
+ R.divider = (n) => h('div', 'prtsui-divider', s(n.label || ''))
533
+
534
+ R.kbd = (n) => {
535
+ const wrap = h('span', 'prtsui-kbd')
536
+ arr(n.keys).forEach((k) => wrap.append(h('kbd', null, s(k))))
537
+ return wrap
538
+ }
539
+
540
+ R.badge = (n) => {
541
+ const b = h('span', 'prtsui-badge', s(n.content))
542
+ if (n.tone) b.dataset.tone = s(n.tone).toLowerCase()
543
+ return b
544
+ }
545
+
546
+ R.progress = (n) => {
547
+ const wrap = h('div', 'prtsui-progress')
548
+ const label = h('div', 'lbl')
549
+ label.append(h('span', null, s(n.label || '进度')))
550
+ const rawValue = Number(n.value)
551
+ const pct = Math.max(0, Math.min(100, rawValue <= 1 ? rawValue * 100 : rawValue))
552
+ label.append(h('b', null, `${pct.toFixed(1)}%`))
553
+ wrap.append(label)
554
+ const track = h('div', 'track')
555
+ const segs = arr(n.segments)
556
+ if (segs.length) {
557
+ segs.forEach((sg) => {
558
+ const seg = h('div', 'seg')
559
+ seg.dataset.tone = s(sg && sg.tone || 'brand').toLowerCase()
560
+ seg.style.width = `${Number(sg && sg.value) || 0}%`
561
+ track.append(seg)
562
+ })
563
+ } else {
564
+ const seg = h('div', 'seg')
565
+ seg.dataset.tone = s(n.tone || 'brand').toLowerCase()
566
+ seg.style.width = `${pct}%`
567
+ track.append(seg)
568
+ if (pct < 100) {
569
+ const rest = h('div', 'seg')
570
+ rest.dataset.tone = 'pending'
571
+ rest.style.width = `${100 - pct}%`
572
+ track.append(rest)
573
+ }
574
+ }
575
+ wrap.append(track)
576
+ return wrap
577
+ }
578
+
579
+ R.quote = (n) => {
580
+ const q = h('blockquote', 'prtsui-quote')
581
+ q.append(document.createTextNode(s(n.content)))
582
+ if (n.cite) q.append(h('cite', null, `— ${s(n.cite)}`))
583
+ return q
584
+ }
585
+
586
+ R.compare = (n) => {
587
+ const wrap = h('div', 'prtsui-compare')
588
+ for (const key of ['before', 'after']) {
589
+ const side = n[key]
590
+ if (!side) continue
591
+ const col = h('div')
592
+ col.append(h('b', null, s(side.title || (key === 'before' ? 'Before' : 'After'))))
593
+ arr(side.items).forEach((it) => {
594
+ const obj = it && typeof it === 'object' ? it : { text: it }
595
+ col.append(h('span', null, s(obj.text ?? obj.content ?? obj)))
596
+ })
597
+ wrap.append(col)
598
+ }
599
+ return wrap
600
+ }
601
+
602
+ R.image = (n) => {
603
+ const fig = h('figure')
604
+ const img = document.createElement('img')
605
+ img.src = s(n.src)
606
+ img.alt = s(n.alt || '')
607
+ img.loading = 'lazy'
608
+ fig.append(img)
609
+ if (n.caption) fig.append(h('figcaption', null, n.caption))
610
+ return fig
611
+ }
612
+
613
+ R.accordion = (n, ctx) => {
614
+ const wrap = h('div', 'prtsui-acc')
615
+ arr(n.items).forEach((it) => {
616
+ const details = document.createElement('details')
617
+ const summary = document.createElement('summary')
618
+ summary.textContent = s(it && it.title)
619
+ details.append(summary)
620
+ const inner = h('div', 'inner')
621
+ arr(it && it.items).forEach((child) => {
622
+ const el = renderNode(child, ctx)
623
+ if (el) inner.append(el)
624
+ })
625
+ details.append(inner)
626
+ wrap.append(details)
627
+ })
628
+ return wrap
629
+ }
630
+
631
+ function renderNode(node, ctx) {
632
+ if (node === null || node === undefined) return null
633
+ if (typeof node === 'string') return h('p', null, node)
634
+ if (typeof node !== 'object') return h('p', null, s(node))
635
+ const type = s(node.type)
636
+ const fn = R[type]
637
+ if (!fn) return null
638
+ try {
639
+ return fn(node, ctx)
640
+ } catch (err) {
641
+ console.warn('[prtsui] node render failed', type, err)
642
+ return null
643
+ }
644
+ }
645
+
646
+ function parseSpec(raw) {
647
+ const text = String(raw || '').trim()
648
+ if (!text || (text[0] !== '{' && text[0] !== '[')) return null
649
+ let data
650
+ try { data = JSON.parse(text) } catch { return null }
651
+ let items
652
+ if (Array.isArray(data)) items = data
653
+ else if (data && typeof data === 'object' && Array.isArray(data.items)) items = data.items
654
+ else return null
655
+ const known = items.filter((it) => it && typeof it === 'object' && TYPES.has(s(it.type)))
656
+ if (known.length === 0) return null
657
+ if (known.length < items.length && items.length > 1) {
658
+ // a stray non-PRTS key means this is probably ordinary JSON, not a spec
659
+ const unknownRatio = (items.length - known.length) / items.length
660
+ if (unknownRatio > 0.5) return null
661
+ }
662
+ return { root: data, spec: { title: data && data.title ? s(data.title) : '', gap: data && Number(data.gap) || 0, items } }
663
+ }
664
+
665
+ function build(spec, ctx) {
666
+ const root = h('div', 'prtsui')
667
+ if (spec.gap) root.style.setProperty('--prtsui-gap', `${spec.gap}px`)
668
+ if (spec.title) {
669
+ const banner = h('div', 'prtsui-banner')
670
+ banner.append(h('span', null, spec.title))
671
+ banner.append(h('i', null, 'PRTS'))
672
+ root.append(banner)
673
+ }
674
+ const body = h('div', 'prtsui-body')
675
+ spec.items.forEach((node) => {
676
+ const el = renderNode(node, ctx)
677
+ if (el) body.append(el)
678
+ })
679
+ root.append(body)
680
+ return root
681
+ }
682
+
683
+ // ---------------- mounting ----------------
684
+ function textOf(pre) {
685
+ const code = pre.querySelector('code')
686
+ return code ? code.textContent : pre.textContent
687
+ }
688
+
689
+ function isHidden(pre) {
690
+ return pre.dataset.prtsuiMounted === '1'
691
+ }
692
+
693
+ function apply(ctx) {
694
+ const style = document.createElement('style')
695
+ style.dataset.plugin = '@yunkersek/dsh-prtsui'
696
+ style.textContent = CSS
697
+ document.head.append(style)
698
+
699
+ const state = new Map() // pre -> { host, root, sig }
700
+ let sweeping = false
701
+ let timer = null
702
+
703
+ function mount(pre, parsed) {
704
+ const entry = state.get(pre)
705
+ const sig = JSON.stringify(parsed.spec)
706
+ if (entry && entry.sig === sig) return
707
+ const host = entry ? entry.host : h('div', 'prtsui-host')
708
+ host.replaceChildren(build(parsed.spec, ctx))
709
+ if (!entry) {
710
+ pre.parentNode.insertBefore(host, pre)
711
+ pre.dataset.prtsuiMounted = '1'
712
+ pre.style.display = 'none'
713
+ }
714
+ state.set(pre, { host, sig })
715
+ }
716
+
717
+ function sweep() {
718
+ if (sweeping) return
719
+ sweeping = true
720
+ try {
721
+ for (const pre of document.querySelectorAll('pre')) {
722
+ if (pre.closest('.prtsui-host')) continue
723
+ if (pre.dataset.prtsuiSkip === '1') continue
724
+ const raw = textOf(pre)
725
+ const parsed = parseSpec(raw)
726
+ if (!parsed) {
727
+ const entry = state.get(pre)
728
+ if (entry && !String(raw).includes('"items"')) {
729
+ // the fence was edited away: restore the plain code block
730
+ entry.host.remove()
731
+ pre.style.display = ''
732
+ delete pre.dataset.prtsuiMounted
733
+ state.delete(pre)
734
+ }
735
+ continue
736
+ }
737
+ mount(pre, parsed)
738
+ }
739
+ } finally {
740
+ sweeping = false
741
+ }
742
+ }
743
+
744
+ function schedule() {
745
+ if (timer) return
746
+ timer = window.setTimeout(() => { timer = null; sweep() }, 80)
747
+ }
748
+
749
+ const observer = new MutationObserver(() => schedule())
750
+ observer.observe(document.body, { childList: true, subtree: true, characterData: true })
751
+ sweep()
752
+ const interval = window.setInterval(sweep, 2000)
753
+
754
+ return () => {
755
+ observer.disconnect()
756
+ window.clearInterval(interval)
757
+ if (timer) window.clearTimeout(timer)
758
+ for (const [pre, entry] of state.entries()) {
759
+ entry.host.remove()
760
+ pre.style.display = ''
761
+ delete pre.dataset.prtsuiMounted
762
+ }
763
+ state.clear()
764
+ style.remove()
765
+ }
766
+ }
767
+
768
+ return {
769
+ inject: ['sessions'],
770
+ apply(ctx) {
771
+ return ctx.effect(() => apply(ctx), '@yunkersek/dsh-prtsui: fence renderer')
772
+ },
773
+ }
774
+ },
775
+ })
776
+
777
+ </script>
778
+ <script>
779
+ const st = document.createElement('div')
780
+ st.style.cssText = 'position:fixed;left:8px;bottom:8px;z-index:99999;background:#141516;border:1px solid #2f3133;color:#18d1ff;font:11px/1.5 monospace;padding:6px 8px;max-width:96vw;white-space:pre-wrap'
781
+ st.textContent = 'status: ' + (window.__status || 'script did not run') + ' | errors: ' + JSON.stringify(window.__errors || []) + ' | mounted: ' + document.querySelectorAll('.prtsui').length + ' | pres: ' + document.querySelectorAll('pre').length
782
+ document.body.append(st)
783
+ </script>
784
+ </body>
785
+ </html>