@jboltai/tokui 0.1.2 → 0.1.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jboltai/tokui",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "TokUI — Zero-dependency streaming UI description & rendering framework for AI chat. Describe UI with a tiny DSL, stream over SSE, render to real DOM incrementally.",
5
5
  "keywords": [
6
6
  "tokui",
@@ -89,7 +89,7 @@
89
89
  "typecheck": "tsc",
90
90
  "coverage": "c8 --include='src/**/*.js' --exclude='src/server/**' npm run test:all",
91
91
  "server": "node demo/server/sse-server.js",
92
- "demo:sync": "npm run build && cp dist/tokui.umd.js dist/tokui.css demo/lib/",
92
+ "demo:sync": "npm run build && cp dist/tokui.umd.js dist/tokui.css demo/lib/ && perl -i -ne 'print unless m{^//# sourceMappingURL=}' demo/lib/tokui.umd.js && cp src/server/tokui-builder.js demo/server/tokui-builder.js",
93
93
  "dev": "vite",
94
94
  "build": "vite build --mode lib",
95
95
  "build:lib": "vite build --mode lib",
@@ -36,8 +36,9 @@ class TokUIBuilder {
36
36
  let val = String(v);
37
37
  // 转义值中的双引号
38
38
  val = val.replace(/"/g, '\\"');
39
- // 值含空格、引号、换行符或 ] 时用双引号包裹
40
- if (val.includes(' ') || val.includes('"') || val.includes('\n') || val.includes(']')) {
39
+ // opt 简写值含 : ; 分隔符,必须强制双引号(parser 引号感知整串作字面值);
40
+ // 其余含空格/引号/换行/] 的值同样需引号
41
+ if (k === 'opt' || val.includes(' ') || val.includes('"') || val.includes('\n') || val.includes(']')) {
41
42
  return `${k}:"${val}"`;
42
43
  }
43
44
  return `${k}:${val}`;
@@ -228,13 +229,26 @@ class TokUIBuilder {
228
229
  /** 自定义选择器 */
229
230
  picker(attrs) { return this._open('picker', attrs); }
230
231
  /** 下拉选择框 */
231
- select(attrs) { return this._open('select', attrs); }
232
+ select(attrs) {
233
+ return attrs && attrs.opt
234
+ ? this._selfClosing('select', null, attrs)
235
+ : this._open('select', attrs);
236
+ }
232
237
  /** 选项 */
233
238
  opt(attrs) { return this._selfClosing('opt', null, attrs); }
234
239
  /** 单选按钮组 */
235
- radio(attrs) { return this._open('radio', attrs); }
240
+ radio(attrs) {
241
+ return attrs && attrs.opt
242
+ ? this._selfClosing('radio', null, attrs)
243
+ : this._open('radio', attrs);
244
+ }
236
245
  /** 复选框 */
237
- checkbox(attrs) { return this._selfClosing('checkbox', null, attrs); }
246
+ checkbox(attrs) {
247
+ // 简写 opt:"..." → 自闭合;多选容器 multi → _open;单布尔 → 自闭合
248
+ if (attrs && attrs.opt) return this._selfClosing('checkbox', null, attrs);
249
+ if (attrs && attrs.multi !== undefined) return this._open('checkbox', attrs);
250
+ return this._selfClosing('checkbox', null, attrs);
251
+ }
238
252
  /** 开关组件(方法名 switcher 避开 JS 关键字) */
239
253
  switcher(attrs) { return this._selfClosing('switch', null, attrs); }
240
254
  /** 多行文本框 */
@@ -355,6 +369,10 @@ class TokUIBuilder {
355
369
 
356
370
  /** Empty 空状态(自闭合) */
357
371
  empty(attrs) { return this._selfClosing('empty', null, attrs); }
372
+ /** Code128 条形码:tx 数据 / l 标签 / s 尺寸(sm/md/lg) */
373
+ barcode(attrs) { return this._selfClosing('barcode', null, attrs); }
374
+ /** QR 二维码:tx 数据 / l 标签 / s 尺寸 / ec 纠错级(L/M/Q/H) */
375
+ qrcode(attrs) { return this._selfClosing('qrcode', null, attrs); }
358
376
  /** Result 结果页(自闭合) */
359
377
  result(attrs) { return this._selfClosing('result', null, attrs); }
360
378
  /** Stat 统计数值(自闭合) */